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


import cn.estsh.i3plus.ext.mes.pcn.api.base.IConsistencyAffirmRecordService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesConsistencyAffirmRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProjectTourDetail;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.WorkOrderInfoModel;
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.boot.auth.AuthUtil;
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.*;

/**
 * @Author: xiangming.liao
 * @CreateDate: 2021/02/03
 * @Description:
 **/
@RestController
@Api(tags = "一致性确认记录作业")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/consistency-affirm-record-task")
public class ConsistencyAffirmRecordController {
    public static final Logger LOGGER = LoggerFactory.getLogger(ConsistencyAffirmRecordController.class);

    @Autowired
    private IConsistencyAffirmRecordService consistencyAffirmRecordService;


    @PostMapping(value = "/insert")
    @ApiOperation(value = "产生一致性确认记录", notes = "产生一致性确认记录")
    public ResultBean insertConsistencyAffirmRecord(@RequestBody WorkOrderInfoModel workOrderInfoModel) {
        try {
            consistencyAffirmRecordService.insertConsistencyAffirmRecord(workOrderInfoModel);
            return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException imppException) {
            LOGGER.error(imppException.getErrorMsg() + "：{}", imppException.getErrorDetail(), imppException);
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 查询人员点检作业明细
     *
     * @param orderNo
     * @param organizeCode
     * @return
     */
    @GetMapping(value = "/query")
    @ApiOperation(value = "查询一致性确认记录明细")
    public ResultBean queryConsistencyAffirmRecord(String orderNo, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultList(consistencyAffirmRecordService.queryConsistencyAffirmRecord(orderNo, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * @param consistencyAffirmRecord
     * @return
     */
    @PutMapping(value = "/update")
    @ApiOperation(value = "一致性确认记录作业")
    public ResultBean updateConsistencyAffirmRecord(MesConsistencyAffirmRecord consistencyAffirmRecord) {
        try {
            consistencyAffirmRecordService.updateConsistencyAffirmRecord(consistencyAffirmRecord);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * @param consistencyAffirmRecord
     * @return
     */
    @PutMapping(value = "/memo/update")
    @ApiOperation(value = "输入备注")
    public ResultBean updateConsistencyAffirmRecordMemo(MesConsistencyAffirmRecord consistencyAffirmRecord) {
        try {
            consistencyAffirmRecordService.updateConsistencyAffirmRecordMemo(consistencyAffirmRecord);
            return ResultBean.success("修改成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
