package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.report;


import cn.estsh.i3plus.ext.mes.pcn.api.report.IMesCimSeresReportService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.seres.MesCimSeresJisQueue;
import cn.estsh.i3plus.pojo.mes.bean.seres.MesCimSeresSrmRunSheetJis;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Api("赛力斯报表")
@RestController
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesCimSeresReport")
public class MesCimSeresReportController {

    @Autowired
    private IMesCimSeresReportService mesCimSeresReportService;

    @ApiOperation(value = "赛力斯JIS单接收日志", notes = "赛力斯JIS单接收日志")
    @GetMapping("/query-srm-sun-sheet-jis-log")
    public ResultBean querySrmSunSheetJisLogByPager(Integer status, String docNo, String partClassCode,
                                                    String partClassName, Pager pager){
        try {
            ListPager<MesCimSeresSrmRunSheetJis> queryResultListPager =
                    mesCimSeresReportService.querySrmSunSheetJisLogByPager(status, docNo, partClassCode, partClassName, pager);
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setListPager(queryResultListPager);
        } catch (ImppBusiException e) {
            return ResultBean.fail(e);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @ApiOperation(value = "赛力斯JIS单转正常", notes = "赛力斯JIS单转正常")
    @PostMapping("/srm-sun-sheet-jis-normal")
    public ResultBean doSrmSunSheetJisNormal(@RequestBody Long[] idArray) {
        try {
            List<Long> idList = Arrays.asList(idArray);
            mesCimSeresReportService.doSrmSunSheetJisNormal(idList);
            return ResultBean.success("执行成功");
        } catch (ImppBusiException e) {
            return ResultBean.fail(e);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @ApiOperation(value = "赛力斯JIS队列接收日志", notes = "赛力斯JIS队列接收日志")
    @GetMapping("/query-jis-queue-log")
    public ResultBean queryJisQueueLogByPager(Integer checkStatus, String vin, String materielCode,
                                              String partClassCode, String partClassName, Pager pager){
        try {
            ListPager<MesCimSeresJisQueue> queryResultListPager =
                    mesCimSeresReportService.queryJisQueueLogByPager(checkStatus, vin, materielCode, partClassCode,
                            partClassName, pager);
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setListPager(queryResultListPager);
        } catch (ImppBusiException e) {
            return ResultBean.fail(e);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @ApiOperation(value = "赛力斯JIS队列转正常", notes = "赛力斯JIS队列转正常")
    @PostMapping("/jis-queue-normal")
    public ResultBean doJisQueueNormal(@RequestBody Long[] idArray) {
        try {
            List<Long> idList = Arrays.asList(idArray);
            mesCimSeresReportService.doJisQueueNormal(idList);
            return ResultBean.success("执行成功");
        } catch (ImppBusiException e) {
            return ResultBean.fail(e);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
