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

import cn.estsh.i3plus.ext.mes.api.base.IProjectTourConfirmService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesProjectTourDetail;
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 + "/project-tour-data")
public class ProjectTourConfirmController {
    public static final Logger LOGGER = LoggerFactory.getLogger(ProjectTourConfirmController.class);

    @Autowired
    private IProjectTourConfirmService projectTourConfirmService;


    @GetMapping(value = "/query")
    @ApiOperation(value = "工程巡回确认报表查询", notes = "工程巡回确认报表查询")
    public ResultBean queryProcessCheckByPager(MesProjectTourDetail projectTourDetail, Pager pager) {
        try {
            projectTourDetail.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success().setListPager(projectTourConfirmService.queryProjectTourDetailByPager(projectTourDetail,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.projectTourConfirmService.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.projectTourConfirmService.updateQualityCheck(ids, qualityCheck))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PutMapping("update")
    @ApiOperation(value = "编辑")
    public ResultBean updateProjectTourDetail(@RequestBody MesProjectTourDetail projectTourDetail) {
        try {
            return ResultBean.success("编辑").setResultObject(this.projectTourConfirmService.updateProjectTourDetail(projectTourDetail))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
