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

import com.energy.manage.common.base.Page;
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.windenginemill.WindEngineMillCodeDto;
import com.energy.manage.service.domain.dto.windenginemill.WindEngineMillCreateDto;
import com.energy.manage.service.domain.dto.windenginemill.WindEngineMillDto;
import com.energy.manage.service.domain.dto.windenginemill.WindEngineMillPageDto;
import com.energy.manage.service.domain.vo.windenginemill.WindEngineMillPageVo;
import com.energy.manage.service.domain.vo.windenginemill.WindEngineMillVo;
import com.energy.manage.service.service.windenginemill.WindEngineMillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@Api(value = "WindEngineMillController", tags = "风机机型管理接口")
@RequestMapping(value = "/api/wind/engine/mill")
public class WindEngineMillController extends BaseServiceController {

    @Autowired
    private WindEngineMillService windEngineMillService;

    @UserLoginToken
    @PostMapping(value = "/createEngineMill")
    @ApiOperation(value = "手动创建机型信息")
    public ResultResp createEngineMill(@RequestBody @Valid WindEngineMillCreateDto windEngineMillCreateDto) {
        if(!windEngineMillService.verificationData(windEngineMillCreateDto.getMachineTypeCode(),windEngineMillCreateDto.getManufacturerCode())){
            return ResultResp.FAIL("该厂商对应机型已经存在！");
        }
        windEngineMillCreateDto.setCreateBy(getUserId());
        boolean flg = windEngineMillService.createEngineMill(windEngineMillCreateDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }

    @Deprecated
    @UserLoginToken
    @PostMapping(value = "/windEngineMillImportData")
    @ApiOperation(value = "导入机型信息")
    public ResultResp windEngineMillImportData(@RequestPart MultipartFile file) {

        boolean flg = windEngineMillService.windEngineMillImportData(file);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


    @UserLoginToken
    @PostMapping(value = "/windEngineMillPage")
    @ApiOperation(value = "分页查询机型信息")
    public ResultResp<Page<WindEngineMillPageVo>> windEngineMillPage(@RequestBody WindEngineMillPageDto windEngineMillPageDto) {
        Page<WindEngineMillPageVo> page = windEngineMillService.windEngineMillPage(windEngineMillPageDto);
        return  ResultResp.SUCCESS(page);
    }


    @UserLoginToken
    @PostMapping(value = "/delWindEngineMill")
    @ApiOperation(value = "删除机型")
    public ResultResp delWindEngineMill(@RequestBody @Valid WindEngineMillCodeDto windEngineMillCodeDto) {

        boolean flg = windEngineMillService.delWindEngineMill(windEngineMillCodeDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


    @UserLoginToken
    @PostMapping(value = "/getWindEngineMillPageVo")
    @ApiOperation(value = "查询机型对象")
    public ResultResp<WindEngineMillPageVo> getWindEngineMillPageVo(@RequestBody @Valid WindEngineMillCodeDto windEngineMillCodeDto) {

        WindEngineMillPageVo windEngineMillPageVo = windEngineMillService.getWindEngineMillPageVo(windEngineMillCodeDto);
        return  ResultResp.SUCCESS(windEngineMillPageVo) ;
    }

    @UserLoginToken
    @PostMapping(value = "/getWindEngineMillList")
    @ApiOperation(value = "查询机型集合")
    public ResultResp<List<WindEngineMillVo>> getWindEngineMillList() {
        List<WindEngineMillVo> list = windEngineMillService.getWindEngineMillList();
        return  ResultResp.SUCCESS(list) ;
    }


    @UserLoginToken
    @PostMapping(value = "/updateWindEngineMill")
    @ApiOperation(value = "更新机型")
    public ResultResp updateWindEngineMill(@RequestBody @Valid WindEngineMillDto windEngineMillDto) {
        if(StringUtils.isEmpty(windEngineMillDto.getMillTypeCode())){
            return ResultResp.NOTNULLPARAM();
        }
        boolean flg = windEngineMillService.updateWindEngineMill(windEngineMillDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }












}
