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

import cn.estsh.i3plus.ext.mes.api.base.IPersonCheckDetailService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesPersonCheckDetail;
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 + "/person-check-data")
public class PersonCheckController {
    public static final Logger LOGGER = LoggerFactory.getLogger(PersonCheckController.class);

    @Autowired
    private IPersonCheckDetailService personCheckDetailService;


    @GetMapping(value = "/person-check-detail/query")
    @ApiOperation(value = "人员点检报表查询", notes = "人员点检报表查询")
    public ResultBean queryProcessCheckByPager(MesPersonCheckDetail personCheckDetail, Pager pager) {
        try {
            personCheckDetail.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success().setListPager(personCheckDetailService.queryPersonCheckDetailByPager(personCheckDetail,pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 班组确认
     *
     * @param ids
     * @param shiftGroupCheck
     * @return
     */
    @PutMapping("/shift-group-check/update")
    @ApiOperation(value = "班组确认")
    public ResultBean shiftGroupCheckUpdate(String[] ids, Integer shiftGroupCheck) {
        try {
            return ResultBean.success("班组确认成功").setResultObject(this.personCheckDetailService.updateShiftGroupCheck(ids, shiftGroupCheck))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 品质确认
     *
     * @param ids
     * @param qualityCheck
     * @return
     */
    @PutMapping("/quality-check/update")
    @ApiOperation(value = "品质确认")
    public ResultBean qualityCheckUpdate(String[] ids, Integer qualityCheck) {
        try {
            return ResultBean.success("品质确认成功").setResultObject(this.personCheckDetailService.updateQualityCheck(ids, qualityCheck))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
