package com.sw.mes.fls.controller;

import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.fls.dto.*;
import com.sw.mes.fls.service.FlsToMesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author: GaoXinJian
 * @Date: 2022-01-11 14:51
 */
@RestController
@Api(description = "Fls调用Mes接口")
@RequestMapping("/flsToMesController")
@Validated
public class FlsToMesController {
    @Autowired
    private FlsToMesService flsToMesService;

    @ApiOperation(value = "画线数据请求接口")
    @GetMapping(value = "getPaintingLineInfo")
    public Result getPaintingLineInfo(@ApiParam(value = "送验车编号") @RequestParam String code) {
        List<PaintingLineInfoDto> result=new ArrayList();
        PaintingLineInfoDto paintingLineInfoDto=new PaintingLineInfoDto();
        result.add(paintingLineInfoDto);
        return ResultGenerator.success(result);
    }

    @ApiOperation(value = "绑定接收信息上传")
    @PostMapping(value = "bindingInfo")
    public Result bindingInfo( @RequestBody BindingInfoDto bindingInfoDto) {

        return ResultGenerator.success();
    }

    @ApiOperation(value = "样片检测数据上传接口")
    @PostMapping(value = "sampleInfo")
    public Result sampleInfo(@RequestBody SampleInfoDto sampleInfoDto) {

        return ResultGenerator.success();
    }

    @ApiOperation(value = "样片类别请求接口")
    @GetMapping(value = "getSampleType")
    public Result getSampleType(@ApiParam(value = "托盘号") @RequestParam String code) {
        SampleTypeDto sampleTypeDto=new SampleTypeDto();
        return ResultGenerator.success(sampleTypeDto);
    }

    @ApiOperation(value = "头尾料类别请求接口")
    @PostMapping(value = "getHeadTailMaterialType")
    public Result getHeadTailMaterialType(@ApiParam(value = "托盘号") @RequestParam String code) {

        return ResultGenerator.success();
    }


    @ApiOperation(value = "绑定信息上传接口（切方工序方棒与托盘绑定）")
    @PostMapping(value = "bindingFbwithTray")
    public Result bindingFbwithTray(@RequestBody BiddingFbWithTrayDto biddingFbWithTrayDto) {

        return flsToMesService.bindingFbwithTray(biddingFbWithTrayDto);
    }




    @ApiOperation(value = "托盘转移")
    @PostMapping(value = "palletTransfer")
    public Result palletTransfer(@Valid @RequestBody PalletTransferDto palletTransferDto) {

        return flsToMesService.palletTransfer(palletTransferDto);
    }




    @ApiOperation(value = "方棒进入分选口接口，fls调用")
    @PostMapping(value = "/fbSizing")
    public Result fbSizing(@RequestBody FbSizingDto fbSizingDto) {
//        return flsToMesService.fbSizing(fbSizingDto);
        return flsToMesService.fbSizingV2(fbSizingDto);
    }

    @ApiOperation(value = "打托信息上传接口（打托完成报告）")
    @PostMapping(value = "productAssemblyInfoUpload")
    public Result productAssemblyInfoUpload(@RequestBody ProductAssemblyInfoDto productAssemblyInfoDto) {

        // todo 临时注释
//        return flsToMesService.productAssemblyInfoUpload(productAssemblyInfoDto);
        return ResultGenerator.success();
    }

    @ApiOperation(value = "设备加工能力下发fls / 通过晶棒编号，找到合适加工能力的加工设备")
    @PostMapping(value = "/getDeviceBySectionNo")
    public Result<DeviceAbilityDto> getDeviceBySectionNo(@RequestBody @Valid SectionNoDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        DeviceAbilityDto deviceAbility = flsToMesService.getDeviceBySectionNo(dto.getSectionNo());
        return ResultGenerator.success(deviceAbility);
    }

    @ApiOperation(value = "磨倒设备加工能力下发fls : 通过晶棒编号，找到合适加工能力的磨倒加工设备")
    @PostMapping(value = "/getMdDeviceBySectionNo")
    public Result<DeviceAbilityDto> getMdDeviceBySectionNo(@RequestBody @Valid SectionNoDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        DeviceAbilityDto deviceAbility = flsToMesService.getMdDeviceBySectionNo(dto.getSectionNo());
        return ResultGenerator.success(deviceAbility);
    }

    @ApiOperation(value = "开方设备加工能力下发fls / 通过车号，找到合适加工能力的加工设备")
    @PostMapping(value = "/getDeviceByBranchCode")
    public Result<List<DeviceAbilityDto>> getDeviceByBranchCode(@RequestBody @Valid BranchCodeDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        List<DeviceAbilityDto> deviceAbility = flsToMesService.getDeviceByBranchCode(dto.getBranchCode());
        return ResultGenerator.success(deviceAbility);
    }

}
