package com.sw.mes.sectionMes.controller;

import com.alibaba.fastjson.JSON;
import com.sw.mes.core.annotation.Jinko;
import com.sw.mes.core.api.system.YbFeignClients;
import com.sw.mes.core.dto.sectionMes.FbInformationReceptionDto;
import com.sw.mes.core.dto.sectionMes.ReturnMaterialFeedBackDto;
import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.sectionMes.service.MESOutputService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author lf
 * @description
 * @date 2024/2/1 9:21
 */
@RestController
@RequestMapping("/mes/out")
@Slf4j
@Api(description = "切片MES数据请求接口")
@Jinko(value = "切片MES对接请求接口控制器", author = "liangfeng")
public class MESOutputController {
    @Autowired
    private MESOutputService mesOutputService;

    @Autowired
    private YbFeignClients ybFeignClients;

    @ApiOperation(value = "方棒信息接收")
    @PostMapping("/fbInformationReception")
    public Result fbInformationReception(@RequestBody @Valid List<FbInformationReceptionDto> data) {
        try {
            mesOutputService.fbInformationReception(data);
        } catch (Exception e) {
            log.error("error_in_fbInformationReception", e);
            return ResultGenerator.fail(e.getMessage());
        }
        return ResultGenerator.success();
    }

    @ApiOperation(value = "退料反馈")
    @PostMapping("/returnMaterialFeedBack")
    public Result returnMaterialFeedBack(@RequestBody @Valid List<ReturnMaterialFeedBackDto> data) {
        try {
            mesOutputService.returnMaterialFeedBack(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.fail(e.getMessage());
        }
        return ResultGenerator.success();
    }

    @ApiOperation("测试方棒信息接收")
    @PostMapping("/test/fbInformationReception")
    public Result testFbInformationReception() {
        ArrayList<FbInformationReceptionDto> list = new ArrayList<>();
        FbInformationReceptionDto dto = new FbInformationReceptionDto();
        dto.setSiliconRodNo("123");
        dto.setCrystalPullingBinds("123");
        list.add(dto);
        Result result = ybFeignClients.fbInformationReception(list);
        System.out.println(JSON.toJSONString(result));
        return ResultGenerator.success();
    }

    @ApiOperation("测试退料反馈")
    @PostMapping("/test/returnMaterialFeedBack")
    public Result testReturnMaterialFeedBack() {
        ArrayList<ReturnMaterialFeedBackDto> list = new ArrayList<>();
        ReturnMaterialFeedBackDto dto = new ReturnMaterialFeedBackDto();
        dto.setSiliconRodNo("123");
        dto.setCrystalPullingBinds("123");
        list.add(dto);
        Result result = ybFeignClients.returnMaterialFeedBack(list);
        System.out.println(JSON.toJSONString(result));
        return ResultGenerator.success();
    }
}
