package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.busi.jx;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.ITorqueManageCheckService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProcessTorqueManageTaskDetail;
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.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.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: xinwang.yi
 * @CreateDate: 2023/10/10 15:37
 * @Description:
 **/
@RestController
@Api(tags = "扭矩管理点检")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/torque-manage-check")
public class TorqueManageCheckController extends MesPcnBaseController {
    public static final Logger LOGGER = LoggerFactory.getLogger(TorqueManageCheckController.class);

    @Autowired
    private ITorqueManageCheckService personCheckDetailService;


    /**
     * 查询扭矩管理点检作业明细
     *
     * @param torqueManageTaskDetail
     * @return
     */
    @GetMapping(value = "/detail/query")
    @ApiOperation(value = "查询扭矩管理点检作业明细")
    public ResultBean queryProcessTorqueManageTaskDetailCheckDetail(MesProcessTorqueManageTaskDetail torqueManageTaskDetail, Pager pager) {
        try {
            return ResultBean.success("查询成功").setListPager(personCheckDetailService.queryTorqueManageCheckDetail(torqueManageTaskDetail, pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 修改明细数据
     *
     * @param personCheckDetail
     * @return
     */
    @PutMapping(value = "/detail/update")
    @ApiOperation(value = "修改明细数据")
    public ResultBean updateMesQManageTaskDetail(MesProcessTorqueManageTaskDetail torqueManageTaskDetail) {
        try {
            personCheckDetailService.updateTorqueManageCheckDetail(torqueManageTaskDetail);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 修改顶部明细数据
     *
     * @param personCheckDetail
     * @return
     */
    @PutMapping(value = "/detail/update-top-data")
    @ApiOperation(value = "根据单号修改明细数据中扭矩规格值和管理NO")
    public ResultBean updateTopMesQManageTaskDetail(MesProcessTorqueManageTaskDetail torqueManageTaskDetail) {
        try {
            personCheckDetailService.updateTopTorqueManageCheckDetail(torqueManageTaskDetail);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 通过单据编号查询工位
     *
     * @param orderNo
     * @param organizeCode
     * @return
     */
    @GetMapping("/cell/query")
    @ApiOperation(value = "通过单据编号查询工位")
    public ResultBean queryCellByOrderNo(String orderNo, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultList(this.personCheckDetailService.queryCellByOrderNo(orderNo, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
