package com.sw.mes.mcs.controller;

import com.alibaba.fastjson.JSONObject;
import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.mcs.dto.*;
import com.sw.mes.mcs.service.MesToMcsService;
import com.sw.mes.mcs.utils.ResultDto;
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 java.util.List;


/**
 * @Author: GaoXinJian
 * @Date: 2022-01-12 10:03
 */
@RestController
@RequestMapping("/mesToMcsController")
@Slf4j
@Api(description = "mes与mcs通信接口")
public class MesToMcsController {
    @Autowired
    MesToMcsService mesToMcsService;

    @ApiOperation(value = "方棒绑定信息下发接口")
    @PostMapping("/squareBinding")
    public Result squareBinding(@RequestBody SquareBindingDto squareBindingDto) {
        ResultDto resultDto=mesToMcsService.squareBinding(squareBindingDto);
        if (resultDto.getStatus() == 100) {
            return ResultGenerator.success(resultDto.getMessage(), resultDto.getData());
        } else {
            return ResultGenerator.message(Integer.valueOf(resultDto.getStatus()),resultDto.getMessage(),resultDto.getData());
        }
    }

    @ApiOperation(value = "方棒评级结果下发")
    @PostMapping("/squareRank")
    public Result squareRank(@RequestBody SquareRankDto squareRankDto) {
        ResultDto resultDto = mesToMcsService.squareRank(squareRankDto);
        if (resultDto.getStatus() == 100) {
            return ResultGenerator.success(resultDto.getMessage(), resultDto.getData());
        } else {
            return ResultGenerator.message(Integer.valueOf(resultDto.getStatus()), resultDto.getMessage(), resultDto.getData());
        }
    }

    @ApiOperation(value = "不检测方棒-PDA下发给mcs")
    @PostMapping("/noDetection")
    public Result noDetection(@RequestBody NoDetectionDto noDetectionDto) {
//        ResultDto resultDto=mesToMcsService.noDetection(noDetectionDto);
//        if (resultDto.getStatus() == 100) {
//            return ResultGenerator.success(resultDto.getMessage(), resultDto.getData());
//        } else {
//            return ResultGenerator.message(Integer.valueOf(resultDto.getStatus()),resultDto.getMessage(),resultDto.getData());
//        }
        return ResultGenerator.success();
    }
}
