1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 (StringUtils.equals(orderType, OrderType.OUTSOURCE_INCOMING.getValue())
                || StringUtils.equals(orderType, OrderType.OUTSOURCE_SUBCONTRACT.getValue())) {
            return StringUtils.equals(resolve(orderType, materialProp), OrderType.WG.getValue()) ? 0 : 1;
        }
        return typeSource;
    }
}