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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesConfigService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesWorkOrderService;
import cn.estsh.i3plus.ext.mes.pcn.api.job.IMesWorkOrderOfflineRestoreService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob.MesReportNoSortJob;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob.MesReportWorkByPreDayJob;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
import cn.estsh.i3plus.pojo.mes.bean.MesShift;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
import cn.estsh.i3plus.pojo.mes.repository.MesProductionRecordRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesShiftRepository;
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.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping(MesCommonConstant.MES_YANFEN + "/test")
public class TestController {

    @Autowired
    private MesReportNoSortJob mesReportNoSortJob;

    @Autowired
    private MesReportWorkByPreDayJob mesReportWorkByPreDayJob;

    @Autowired
    private IMesWorkOrderService workOrderService;

    @Autowired
    private MesProductionRecordRepository productionRecordRao;

    @Autowired
    private MesShiftRepository mesShiftRepository;

    @Autowired
    private IMesConfigService configService;

    @Autowired
    private IMesWorkOrderOfflineRestoreService workOrderOfflineRestoreService;

    @GetMapping("/reportWorkByPreDayJob")
    @ApiOperation(value = "查询设备交互")
    public ResultBean queryReworkTaskByPager(String organizeCode) {
      return  null;
    }

    @GetMapping("/reportOrder")
    @ApiOperation(value = "报工")
    public void reportOrder() {
        mesReportNoSortJob.executeMesJob(null, null);

    }

    @GetMapping("/reportOrder1")
    @ApiOperation(value = "报工")
    public void reportOrder1() {
        mesReportWorkByPreDayJob.executeMesJob(null, null);

    }

    @GetMapping("/MesReportSortJob")
    @ApiOperation(value = "排序工单汇报")
    public void doMesReportSortJob(String organizeCode,Integer pageSize,String userName) {
        workOrderService.doMesWorkOrderSortReport(organizeCode,pageSize,userName);
    }

    @GetMapping("/testInsert")
    @ApiOperation(value = "批量")
    public void testInsert() {
        //testService.insertList();

    }

    @PostMapping("/testRestoreWorkOrderOfflineData")
    @ApiOperation(value = "补录离线生产工单数据JOB")
    public ResultBean testRestoreWorkOrderOfflineData(@RequestBody Map<String, String> paramMap) {
        try {
            workOrderOfflineRestoreService.doRestoreWorkOrderOfflineData(paramMap);
            return ResultBean.success("操作成功");
        } catch (ImppBusiException imppException) {
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
