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

import cn.estsh.i3plus.ext.mes.api.base.IExteriorScratchProofDetailService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesExteriorScratchProofDetail;
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.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xiangming.liao
 * @CreateDate: 2021/03/12
 * @Description:
 **/
@RestController
@Api(tags = "外观防划伤明细报表")
@RequestMapping(CommonConstWords.BASE_URL_MES + "/exterior-scratch-proof-detail-report")
public class ExteriorScratchProofDetailController {
    public static final Logger LOGGER = LoggerFactory.getLogger(ExteriorScratchProofDetailController.class);

    @Autowired
    private IExteriorScratchProofDetailService exteriorScratchProofDetailService;


    @GetMapping(value = "/query")
    @ApiOperation(value = "外观防划伤明细报表查询", notes = "外观防划伤明细报表查询")
    public ResultBean queryExteriorScratchProofDetailByPager(MesExteriorScratchProofDetail exteriorScratchProofDetail, Pager pager) {
        try {
            exteriorScratchProofDetail.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success().setListPager(exteriorScratchProofDetailService.queryExteriorScratchProofDetailByPager(exteriorScratchProofDetail,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.exteriorScratchProofDetailService.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.exteriorScratchProofDetailService.updateQualityCheck(ids, qualityCheck))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
