package com.energy.manage.service.controller.powerwordcriterion;

import com.energy.manage.common.base.Page;
import com.energy.manage.common.enums.IdPrefixEnum;
import com.energy.manage.common.reponse.ResultResp;
import com.energy.manage.service.config.annotations.UserLoginToken;
import com.energy.manage.service.controller.base.BaseServiceController;
import com.energy.manage.service.domain.dto.powerwordcontract.PowerWordContractDelDto;
import com.energy.manage.service.domain.dto.powerwordcontract.PowerWordContractDto;
import com.energy.manage.service.domain.dto.powerwordcontract.PowerWordContractExcelDto;
import com.energy.manage.service.domain.dto.powerwordcontract.PowerWordContractPageDto;
import com.energy.manage.service.domain.dto.powerwordcriterion.PowerWordCriterionDelDto;
import com.energy.manage.service.domain.dto.powerwordcriterion.PowerWordCriterionDto;
import com.energy.manage.service.domain.dto.powerwordcriterion.PowerWordCriterionExcelDto;
import com.energy.manage.service.domain.dto.powerwordcriterion.PowerWordCriterionPageDto;
import com.energy.manage.service.domain.vo.powerwordcontract.PowerWordContractPageVo;
import com.energy.manage.service.domain.vo.powerwordcriterion.PowerWordCriterionPageVo;
import com.energy.manage.service.service.powerwordcriterion.PowerWordCriterionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Slf4j
@RestController
@CrossOrigin
@Api(value = "PowerWordCriterionController", tags = "标准功率曲线接口")
@RequestMapping(value = "/api/powerword/criterion")
public class PowerWordCriterionController extends BaseServiceController {

    @Autowired
    private PowerWordCriterionService powerWordCriterionService;


    @UserLoginToken
    @PostMapping(value = "/powerWordCriterionImportData")
    @ApiOperation(value = " 同步标准功率,（机型编号导入功率曲线）")
    public ResultResp powerWordCriterionImportData(@RequestPart MultipartFile file,
                                                   @RequestParam("millTypeCode") String millTypeCode) {
        if(!millTypeCode.contains(IdPrefixEnum.WIND_EILL_NUMBER.getCode())){
            return ResultResp.FAIL("风场编号不正确，请确认数据！");
        }
        PowerWordCriterionExcelDto powerWordCriterionExcelDto = new PowerWordCriterionExcelDto();
        powerWordCriterionExcelDto.setMillTypeCode(millTypeCode);
        powerWordCriterionExcelDto.setCreateBy(getUserId());
        return powerWordCriterionService.powerWordCriterionImportData(file, powerWordCriterionExcelDto);
    }


    @UserLoginToken
    @PostMapping(value = "/powerWordCriterionPage")
    @ApiOperation(value = " 同步标准功率曲线分页查询")
    public ResultResp<Page<PowerWordCriterionPageVo>> powerWordCriterionPage(@RequestBody PowerWordCriterionPageDto powerWordCriterionPageDto) {
        Page<PowerWordCriterionPageVo> page = powerWordCriterionService.powerWordCriterionPage(powerWordCriterionPageDto);
        return ResultResp.SUCCESS(page);
    }


    @UserLoginToken
    @PostMapping(value = "/delpowerWordCriterion")
    @ApiOperation(value = " 删除风机标准功率曲线")
    public ResultResp delpowerWordCriterion(@RequestBody PowerWordCriterionDelDto powerWordCriterionDelDto) {

        boolean flg = powerWordCriterionService.delpowerWordCriterion(powerWordCriterionDelDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


    @UserLoginToken
    @PostMapping(value = "/updatePowerWordCriterion")
    @ApiOperation(value = "编辑标准功率曲线")
    public ResultResp updatePowerWordCriterion(@RequestBody PowerWordCriterionDto powerWordCriterionDto) {
        boolean flg = powerWordCriterionService.updatePowerWordCriterion(powerWordCriterionDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


}
