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

import cn.estsh.i3plus.ext.mes.api.base.IFourMConfirmService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesFourMConfirm;
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.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.*;

/**
 * @author yumingxing
 * @version 1.0
 * @date 2021/2/2 15:51
 **/
@RestController
@Api(tags = "4M确认")
@RequestMapping(CommonConstWords.BASE_URL_MES + "/four-m-confirm")
public class FourMConfirmController {

    @Autowired
    private IFourMConfirmService fourMConfirmService;


    /**
     * 插入
     *
     * @param fourMConfirm mes自动
     * @return {@link ResultBean}
     */
    @PostMapping(value = "/insert")
    @ApiOperation(value = "新增")
    public ResultBean insert(@RequestBody MesFourMConfirm fourMConfirm) {
        try {
            return ResultBean.success("新增成功").setResultObject(fourMConfirmService.insert(fourMConfirm))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 修改单据规则
     *
     * @param fourMConfirm mes部分自动降落
     * @return {@link ResultBean}
     */
    @PutMapping(value = "/update")
    @ApiOperation(value = "修改")
    public ResultBean update(@RequestBody MesFourMConfirm fourMConfirm) {
        try {
            return ResultBean.success("修改成功").setResultObject(fourMConfirmService.update(fourMConfirm))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 根据ID启用或禁用单据规则
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping(value = "/status-update")
    @ApiOperation(value = "根据ID启用或禁用")
    public ResultBean updateOrderIsValidById(long id, Integer status) {
        try {
            return ResultBean.success("根据ID启用或禁用").setResultObject(fourMConfirmService.updateIsValidById(id, status))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 查询分页
     *
     * @param fourMConfirm mes自动
     * @param pager        寻呼机
     * @return {@link ResultBean}
     */
    @GetMapping(value = "/query")
    @ApiOperation(value = "查询分页")
    public ResultBean queryOrderRule(MesFourMConfirm fourMConfirm, Pager pager) {
        try {
            return ResultBean.success("查询成功").setListPager(fourMConfirmService.queryByPager(fourMConfirm, pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }


}
