cheng
2023-12-12 c64c9f6fb38f65be99b827c1af8d3c3852f68ba4
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package cn.stylefeng.guns.plcserver.opc.unit;
 
import org.apache.commons.lang3.StringUtils;
 
import java.util.Calendar;
 
public class SFCCodeTool {
 
    public static String marketAreaCode = ""; //市场区域编码
    public static String softwareVersionCode = ""; //软件版本编码
    public static String productCompanyCode = ""; //产品公司编码
    public static String RunningWaterNumber = "0000"; //流水号
    public static String SerialNumbers = "0000"; //序列号
 /*   public static String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份
    public static String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份
    public static String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期*/
 
 
    //头部拼接
    public static String C1_36V_HEAD_STRING = "T19000E001";//T1标识产品型号MTB、90表示产品扭矩、00表示 36V 6V3W、E表示国家(这里是欧洲,其他的待定)、001表示软件基础版
    public static String C1_48V_HEAD_STRING = "T19000E001";//T1标识产品型号MTB、90表示产品扭矩、00表示 36V 6V3W、E表示国家(这里是欧洲,其他的待定)、001表示软件基础版
    public static String T1_36V_HEAD_STRING = "T19000E001";//T1标识产品型号MTB、90表示产品扭矩、00表示 36V 6V3W、E表示国家(这里是欧洲,其他的待定)、001表示软件基础版
    public static String T1_48V_HEAD_STRING = "T19000E001";//T1标识产品型号MTB、90表示产品扭矩、00表示 36V 6V3W、E表示国家(这里是欧洲,其他的待定)、001表示软件基础版
 
    public static String CENTER_STRING = "A1";//中间拼接
 
    public static String TAIL_STRING = "";//尾部拼接
 
    public static void main(String[] args){
        createCodingRulesSFC("1","1","1");
    }
    /**
     * 单体编号追溯
     * @param softwareVersionCode 软件版本编码(型号+扭矩+差异款+国家地区+软件版本)
     *  @param productCompanyCode 生产基地编码(生产基地代码+产线代码)
     *  @param serialNumbers 序列号
     * @return
     */
 
    public static String createCodingRulesSFC(String softwareVersionCode,String productCompanyCode,String serialNumbers){
        Calendar calendar = Calendar.getInstance();
        String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份
        String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份
        String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期
        StringBuffer result = new StringBuffer();
 
        String headString = "";
       /* if("".equals(productCode)){
            headString = C1_36V_HEAD_STRING;
        }else if ("".equals(productCode)){
            headString = C1_48V_HEAD_STRING;
        }else if ("".equals(productCode)){
            headString = C1_48V_HEAD_STRING;
        }else if ("".equals(productCode)){
            headString = C1_48V_HEAD_STRING;
        }else {
            return "";
        }*/
 
 
        result.append(softwareVersionCode);//产品型号
        result.append(Years.substring(Years.length()-2));//年
        result.append(replaceMonths(Months));
        result.append(Dates);//日
        result.append(productCompanyCode);//班次
        result.append(serialNumbers);//序列号
        result.append("B");//产线
 
        return  result.toString();
    }
 
    public static String replaceMonths(String months){
        String result = "";
        switch(months) {
            case "01":
                result = "A";
                break;
            case "02":
                result = "B";
                break;
            case "03":
                result = "C";
                break;
            case "04":
                result = "D";
                break;
            case "05":
                result = "E";
                break;
            case "06":
                result = "F";
                break;
            case "07":
                result = "G";
                break;
            case "08":
                result = "H";
                break;
            case "09":
                result = "I";
                break;
            case "10":
                result = "J";
                break;
            case "11":
                result = "K";
                break;
            case "12":
                result = "L";
                break;
            default:
               result = "";
        }
 
        return result;
    }
}