package com.sw.mes.itemclean.clean.controller;


import com.sw.mes.core.annotation.Jinko;
import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.itemclean.clean.domain.MaterialStoreSignBox;
import com.sw.mes.itemclean.clean.dto.*;
import com.sw.mes.itemclean.clean.dto.auto.*;
import com.sw.mes.itemclean.clean.service.MaterialCleanToAutoService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@Jinko(author = "yyl", value = "清洗自动化交互接口")
@RestController
@RequestMapping("/clean/materialCleanToAuto")
@Slf4j
@Api(tags = "清洗自动化接口")
public class MaterialCleanToAutoController {
    @Autowired
    ModelMapper modelMapper;
    @Autowired
    private MaterialCleanToAutoService materialCleanToAutoService;


    @Jinko(author = "yyl", value = "自动化-通过余料批次号或分选后pp号,获取分选后料箱物料信息接口")
    @ApiOperation(value = "自动化-通过余料批次号或分选后pp号,获取分选后料箱物料信息接口")
    @PostMapping("/getUnpackingInfoByProductBatchNo")
    public Result<IOTResponseUnpackingDto> getUnpackingInfoByProductBatchNo(@RequestBody @Valid @ApiParam(value = "Dto对象") IOTRequestUnpackingDto iotRequestUnpackingDto) {
        IOTResponseUnpackingDto iotResponseUnpackingDto = materialCleanToAutoService.getUnpackingInfoByProductBatchNo(iotRequestUnpackingDto);
        return ResultGenerator.success(iotResponseUnpackingDto);
    }

    @Jinko(author = "yyl", value = "自动化-清洗上料绑定接口")
    @ApiOperation(value = "自动化-清洗上料绑定接口")
    @PostMapping("/materialCleaningUp")
    public Result materialCleaningUp(@RequestBody @Valid @ApiParam(value = "Dto对象") IOTRequestMaterialCleaningUpDto iotRequestMaterialCleaningUpDto) {
        materialCleanToAutoService.materialCleaningUp(iotRequestMaterialCleaningUpDto);
        return ResultGenerator.success();
    }

    @Jinko(author = "yyl", value = "自动化-清洗下料异常(MES只负责接收,无实际业务意义)")
    @ApiOperation(value = "自动化-清洗下料异常")
    @PostMapping("/materialCleaningErrorDown")
    public Result materialCleaningErrorDown(@RequestBody @Valid @ApiParam(value = "Dto对象") IOTRequestMaterialCleaningErrorDownDto iotRequestMaterialCleaningErrorDownDto) {
        //通过切面入参直接记录到系统日志,无其他业务
        materialCleanToAutoService.materialCleaningErrorDown(iotRequestMaterialCleaningErrorDownDto);
        return ResultGenerator.success();
    }

    @Jinko(author = "yyl", value = "自动化-破碎上料(包含清洗下料业务)")
    @ApiOperation(value = "自动化-破碎上料")
    @PostMapping("/materialCleaningDownAndBrokenUp")
    public Result<IOTResponseBrokenUpDto> materialCleaningDownAndBrokenUp(@RequestBody @Valid @ApiParam(value = "Dto对象") IOTRequestMaterialBrokenUpDto iotRequestMaterialBrokenUpDto) {
        IOTResponseBrokenUpDto iotResponseBrokenUpDto = materialCleanToAutoService.materialCleaningDownAndBrokenUp(iotRequestMaterialBrokenUpDto);
        return ResultGenerator.success(iotResponseBrokenUpDto);
    }

    @Jinko(author = "yyl", value = "自动化-破碎下料装盒")
    @ApiOperation(value = "自动化-破碎下料装盒")
    @PostMapping("/materialBrokenDownToPackaging")
    public Result materialBrokenDownToPackaging(@RequestBody @Valid @ApiParam(value = "Dto对象") IOTRequestMaterialBrokenDownDto iotRequestMaterialBrokenDownDto) {
        materialCleanToAutoService.materialBrokenDownToPackaging(iotRequestMaterialBrokenDownDto);
        return ResultGenerator.success();
    }

    @Jinko(author = "yyl", value = "自动化-成品入库")
    @ApiOperation(value = "自动化-成品入库")
    @PostMapping("/autoGroupStore")
    public Result autoGroupStore(@RequestBody @Valid @ApiParam(value = "Dto对象") IOTRequestMaterialGroupStoreDto iotRequestMaterialGroupStoreDto) {
        materialCleanToAutoService.autoGroupStore(iotRequestMaterialGroupStoreDto);
        return ResultGenerator.success();
    }

    @Jinko(author = "yyl", value = "自动化-满托呼叫AGV")
    @ApiOperation(value = "自动化-满托呼叫AGV")
    @GetMapping("/groupCallAgvById/{id}")
    public Result groupCallAgvById(@PathVariable @ApiParam(value = "组托id") Integer id) {
        materialCleanToAutoService.groupCallAgvById(id);
        return ResultGenerator.success();
    }

    @Jinko(author = "yyl", value = "自动化-原生多晶-通过余料批次号,自动分选并破碎上料接口")
    @ApiOperation(value = "自动化-原生多晶-通过余料批次号,自动分选并破碎上料接口")
    @PostMapping("/getBrokenUpByProductBatchNo")
    public Result<IOTResponseBrokenUpDto> getBrokenUpByProductBatchNo(@RequestBody @Valid @ApiParam(value = "Dto对象") IOTRequestUnpackingToBreakDto iotRequestUnpackingToBreakDto) {
        IOTResponseBrokenUpDto iotResponseBrokenUpDto = materialCleanToAutoService.getBrokenUpByProductBatchNo(iotRequestUnpackingToBreakDto);
        return ResultGenerator.success(iotResponseBrokenUpDto);
    }

    public MaterialStoreSignBoxDto toLazyDto(MaterialStoreSignBox entity) {
        return modelMapper.map(entity, MaterialStoreSignBoxDto.class);
    }

    public MaterialStoreSignBoxDto toEagerDto(MaterialStoreSignBox entity) {
        MaterialStoreSignBoxDto dto = modelMapper.map(entity, MaterialStoreSignBoxDto.class);
        return dto;
    }

    public MaterialStoreSignBox fromDto(MaterialStoreSignBoxDto dto) {
        return modelMapper.map(dto, MaterialStoreSignBox.class);
    }

    public MaterialStoreSignBox fromDto(MaterialStoreSignBoxFromWarehouseDto dto) {
        return modelMapper.map(dto, MaterialStoreSignBox.class);
    }
}
