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

import cn.estsh.i3plus.ext.mes.pcn.api.base.IBomTakeEffectService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.BomTakeEffectModel;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
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 xiangming.liao
 * @date 2021年03月27日 15:32
 */
@RestController
@Api(tags = "Bom生效接口")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/bom-take-effect")
public class BomTakeEffectController {
    @Autowired
    private IBomTakeEffectService bomTakeEffectService;

    @GetMapping("/produce-sn/by-sn/query")
    @ApiOperation(value = "通过条码查询产品条码信息")
    public ResultBean queryProduceSnBySn(String productSn, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultObject(bomTakeEffectService.queryProduceSnBySn(productSn, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping("/wms-bom-total/by-part-no/query")
    @ApiOperation(value = "通过父级物料查询WmsBomTotal信息")
    public ResultBean queryWmsBomTotalByPartNo(String partNo, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultList(bomTakeEffectService.queryWmsBomTotalByPartNo(partNo, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping("/effect")
    @ApiOperation(value = "BOM生效")
    public ResultBean doEffect(@RequestBody BomTakeEffectModel bomTakeEffectModel) {
        try {
            bomTakeEffectService.doEffect(bomTakeEffectModel);
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
