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

import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesOrderJobService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IPersonCheckDetailService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IQManageService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesOrderJob;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesPersonCheckDetail;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesQManageTaskDetail;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesPcnBaseController;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/19 15:37
 * @Description:
 **/
@RestController
@Api(tags = "人员点检")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/process-check-data")
public class PersonCheckController extends MesPcnBaseController {
    public static final Logger LOGGER = LoggerFactory.getLogger(PersonCheckController.class);

    @Autowired
    private IPersonCheckDetailService personCheckDetailService;


    /**
     * 查询人员点检作业明细
     *
     * @param personCheckDetail
     * @return
     */
    @GetMapping(value = "/process-check/query")
    @ApiOperation(value = "查询人员点检作业明细")
    public ResultBean queryPersonCheckDetail(MesPersonCheckDetail personCheckDetail) {
        try {
            return ResultBean.success("查询成功").setResultObject(personCheckDetailService.queryPersonCheckDetail(personCheckDetail))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 修改明细数据
     *
     * @param personCheckDetail
     * @return
     */
    @PutMapping(value = "/process-check/update")
    @ApiOperation(value = "修改明细数据")
    public ResultBean updateMesQManageTaskDetail(MesPersonCheckDetail personCheckDetail) {
        try {
            personCheckDetailService.updatePersonCheckDetail(personCheckDetail);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 关闭人员点检详情
     *
     * @param personCheckDetail
     * @return
     */
    @PutMapping(value = "/process-check/close")
    @ApiOperation(value = "关闭人员点检详情")
    public ResultBean updatePersonCheckClose(MesPersonCheckDetail personCheckDetail) {
        try {
            personCheckDetailService.updatePersonCheckClose(personCheckDetail);
            return ResultBean.success("关闭人员点检详情")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
    /**
     * 工位录入作业人员
     *
     * @param personCheckDetail
     * @return
     */
    @PutMapping(value = "task-user/update")
    @ApiOperation(value = "工位录入作业人员")
    public ResultBean updateTaskUserByCell(MesPersonCheckDetail personCheckDetail) {
        try {
            personCheckDetailService.updateTaskUserByCell(personCheckDetail);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
    /**
     * 通过单据编号查询工位
     *
     * @param orderNo
     * @param organizeCode
     * @return
     */
    @GetMapping("part-check/cell/query")
    @ApiOperation(value = "通过单据编号查询工位")
    public ResultBean queryCellByOrderNo(String orderNo, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultList(this.personCheckDetailService.queryCellByOrderNo(orderNo, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
