package com.ruoyi.inspect.service; import com.ruoyi.common.enums.OrderType; import com.ruoyi.framework.exception.ErrorException; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; /** * 外协订单复用的原有业务流程。 */ @Service public class OutsourceOrderFlowService { /** 按已约定的物料属性字典键值分流,同时校验委外加工属性。 */ public String resolve(String orderType, String materialProp) { if (StringUtils.equals(orderType, OrderType.OUTSOURCE_INCOMING.getValue())) { return OrderType.RAW.getValue(); } if (StringUtils.equals(orderType, OrderType.OUTSOURCE_SUBCONTRACT.getValue())) { if (StringUtils.equals(materialProp, "半成品")) { return OrderType.RAW.getValue(); } if (StringUtils.equals(materialProp, "成品")) { return OrderType.WG.getValue(); } throw new ErrorException("委外加工的物料属性只能为半成品或成品"); } return orderType; } /** 外协订单按实际流程确定下单来源,其他订单保留原来源。 */ public Integer resolveTypeSource(String orderType, String materialProp, Integer typeSource) { if (isOutsource(orderType)) { return StringUtils.equals(resolve(orderType, materialProp), OrderType.WG.getValue()) ? 0 : 1; } return typeSource; } public boolean isOutsource(String orderType) { return OrderType.OUTSOURCE_INCOMING.getValue().equals(orderType) || OrderType.OUTSOURCE_SUBCONTRACT.getValue().equals(orderType); } }