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.IQManageService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesOrderJob;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesQManageTaskDetail;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
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.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 = "Q管理作业")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN+ "/q-data")
public class QManageController extends MesPcnBaseController {

    @Autowired
    private IMesOrderJobService mesOrderJobService;

    @Autowired
    private IQManageService qManageService;

    /**
     * 查询单据作业
     *
     * @param mesOrderJob
     * @return
     */
    @GetMapping(value = "/mes-order-job/find")
    @ApiOperation(value = "查询单据作业")
    public ResultBean findMesOrderJob(MesOrderJob mesOrderJob) {
        try {
            return ResultBean.success("查询成功").setResultList(mesOrderJobService.findMesOrderJob(mesOrderJob))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 查询MES_Q管理作业明细
     *
     * @param mesQManageTaskDetail
     * @return
     */
    @GetMapping(value = "/mes-q-manage-task-detail/find")
    @ApiOperation(value = "查询MES_Q管理作业明细")
    public ResultBean findMesQManageTaskDetail(MesQManageTaskDetail mesQManageTaskDetail) {
        try {
            return ResultBean.success("查询成功").setResultList(qManageService.findMesQManageTaskDetail(mesQManageTaskDetail))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 修改明细数据
     *
     * @param mesQManageTaskDetail
     * @return
     */
    @PutMapping(value = "/mes-q-manage-task-detail/update")
    @ApiOperation(value = "修改明细数据")
    public ResultBean updateMesQManageTaskDetail(MesQManageTaskDetail mesQManageTaskDetail, String userName) {
        try {
            qManageService.updateMesQManageTaskDetail(mesQManageTaskDetail, userName);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
