Administrator
2023-06-19 49588f5a462ae7425e7eb030438a35fd80c246fa
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package com.gk.firework.Domain.Vo;
 
import com.gk.firework.Domain.SaleOrderInfo;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.Utils.BeanUtils;
import com.gk.firework.Domain.Utils.StringUtils;
 
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
 
import static com.gk.firework.Domain.Vo.EntryUtils.RK_ENTRY;
import static com.gk.firework.Domain.Vo.EntryUtils.TH_ENTRY;
 
/**
 * @author : jingjy
 * @date : 2021/3/19 8:48
 * 公共处理方法
 */
public class FireworkDeal {
    public static final int DIRECTION_ITEM = 10;
    public static final int DIRECTION_INSIDE = 19;
    public static final int DIRECTION_OUTSIDE = 22;
    private static final String RETAIL_ORDER = "1";
    private static final String GROUP_ORDER = "2";
    private static final String NORMAL_DELIVERY = "1";
    public static final String OTHER_DELIVERY = "2";
    public static final String MODULE_ENTRY = "入库";
    public static final String MODULE_DELIVERY = "出库";
    private static final String MODULE_SALE = "销售";
 
 
    public static DirectionDetail dealDirectionCode(String direction){
 
        DirectionDetail directionDetail = new DirectionDetail();
 
        if (StringUtils.isBlank(direction)){
            return directionDetail;
        }
        int length = direction.length();
        if (length != DIRECTION_INSIDE && length != DIRECTION_OUTSIDE ){
            return directionDetail;
        }
 
        directionDetail.setOriginalCode(direction);
        directionDetail.setLength(length);
        String itemCode = direction.substring(0,10);
        String dateCode = direction.substring(10,14);
        String serialNo = direction.substring(14,19);
        if (length == DIRECTION_OUTSIDE){
            String boxNo = direction.substring(19,22);
            directionDetail.setBoxNo(boxNo);
        }
 
        directionDetail.setItemCode(itemCode);
        directionDetail.setDateCode(dateCode);
        directionDetail.setSerialNo(serialNo);
 
        return directionDetail;
    }
 
    public static boolean is22Characters(String direction){
        return !StringUtils.isBlank(direction) && direction.length() == 22;
    }
 
    public static boolean is19Characters(String direction){
        return !StringUtils.isBlank(direction) && direction.length() == 19;
    }
 
    /**
     * 判断字符串是否流向码
     * @param direction 流向码
     * @return true:不是流向码
     */
    public static boolean isNotDirectionCode(String direction){
        return !is19Characters(direction) && !is22Characters(direction);
    }
 
    /**
     * 通过22位流向码获取一批19位流向码
     * @param dire 流向码
     * @param detailFirst 首个流向码详情
     * @param detailLast  尾个流向码详情
     * @param productVos  获取的一批19位码详情
     * @param productVo   产品详情
     */
    public static void getProductVos(String dire, DirectionDetail detailFirst, DirectionDetail detailLast, List<ProductVo> productVos, ProductVo productVo) {
        for (int i = Integer.parseInt(detailFirst.getSerialNo());i < Integer.parseInt(detailLast.getSerialNo())+Integer.parseInt(detailLast.getBoxNo());i++){
            ProductVo productVoCopy = BeanUtils.copy(productVo, ProductVo.class);
            productVoCopy.setDirectionCode(dire.substring(0, 14) + String.format("%05d", i));
            productVos.add(productVoCopy);
        }
    }
 
    public static Map<String,List<ProductCodeVo>> getProductCodeVoList(ProductCodeVo productCodeVo) {
        List<ProductCodeVo> productCodeVoList = new ArrayList<>();
        List<ProductCodeVo> printCodeVoList = new ArrayList<>();
        DirectionDetail detailDetail = dealDirectionCode(productCodeVo.getOriginalcode());
        for (int i = Integer.parseInt(detailDetail.getSerialNo());i < Integer.parseInt(detailDetail.getSerialNo())+Integer.parseInt(detailDetail.getBoxNo());i++){
            ProductCodeVo productVoCopy = BeanUtils.copy(productCodeVo, ProductCodeVo.class);
            productVoCopy.setItemcode(productCodeVo.getOriginalcode().substring(0, 14) + String.format("%05d", i));
            productCodeVoList.add(productVoCopy);
        }
 
        ProductCodeVo productVoCopy = new ProductCodeVo();
        printCodeVoList.addAll(productCodeVoList);
        if (productCodeVoList.size() > 0 && productCodeVoList.size() % 2 == 0) {
            //2个空行
            printCodeVoList.add(productVoCopy);
            printCodeVoList.add(productVoCopy);
        } else if (productCodeVoList.size() > 0 && productCodeVoList.size() % 2 == 1) {
            //3个空行
            printCodeVoList.add(productVoCopy);
            printCodeVoList.add(productVoCopy);
            printCodeVoList.add(productVoCopy);
        }
 
        productCodeVoList.add(productVoCopy);
 
 
        HashMap<String,List<ProductCodeVo>> result = new HashMap<>();
        result.put("productCodeVoList", productCodeVoList);
        result.put("printCodeVoList", printCodeVoList);
        return result;
    }
 
    public static List<ProductCodeVo> getBatchProductCodeList(ProductCodeVo productCodeVo,Integer needBlank) {
        List<ProductCodeVo> productCodeVoList = new ArrayList<>();
        List<ProductCodeVo> printCodeVoList = new ArrayList<>();
        DirectionDetail detailDetail = dealDirectionCode(productCodeVo.getOriginalcode());
        for (int i = Integer.parseInt(detailDetail.getSerialNo());i < Integer.parseInt(detailDetail.getSerialNo())+Integer.parseInt(detailDetail.getBoxNo());i++){
            ProductCodeVo productVoCopy = BeanUtils.copy(productCodeVo, ProductCodeVo.class);
            productVoCopy.setItemcode(productCodeVo.getOriginalcode().substring(0, 14) + String.format("%05d", i));
            productCodeVoList.add(productVoCopy);
        }
 
        ProductCodeVo productVoCopy = new ProductCodeVo();
        printCodeVoList.addAll(productCodeVoList);
 
        if (productCodeVoList.size() > 0 && productCodeVoList.size() % 2 == 0 && needBlank == 1) {
            //2个空行
            printCodeVoList.add(productVoCopy);
            printCodeVoList.add(productVoCopy);
        } else if (productCodeVoList.size() > 0 && productCodeVoList.size() % 2 == 1) {
            //1个空行
            printCodeVoList.add(productVoCopy);
        }
 
        productCodeVoList.add(productVoCopy);
 
        return printCodeVoList;
    }
 
    public static void setProductVosAttribute(ProductVo productVo){
        if (productVo != null){
            DirectionDetail directionDetail = dealDirectionCode(productVo.getDirectionCode());
            productVo.setItemCode(directionDetail.getItemCode());
            productVo.setBoxNo(directionDetail.getBoxNo());
            productVo.setSerialNo(directionDetail.getSerialNo());
            productVo.setDateCode(directionDetail.getDateCode());
        }
    }
 
    /**
     * 生成OrderCode
     */
    /*public static String generateOrderCode(String module, String type, Date date){
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String orderCode = dateFormat.format(date);
        orderCode += (int)(Math.random()*1000);
        switch (module) {
            case MODULE_ENTRY:
                if (type.equals(RK_ENTRY)) {
                    orderCode = "RK-" + orderCode;
                } else if (type.equals(TH_ENTRY)) {
                    orderCode = "TH-" + orderCode;
                }
                break;
            case MODULE_DELIVERY:
                if (type.equals(NORMAL_DELIVERY)) {
                    orderCode = "ND-" + orderCode;
                } else {
                    orderCode = "OD-" + orderCode;
                }
                break;
            case MODULE_SALE:
                if (type.equals(RETAIL_ORDER)) {
                    orderCode = "RO-" + orderCode;
                } else if (type.equals(GROUP_ORDER)) {
                    orderCode = "GO-" + orderCode;
                }
                break;
            default:
        }
 
        return orderCode;
    }*/
 
    /**
     * 身份证中间数字加密
     * @param idCardNum 身份证号
     * @return 加密后的身份证号
     */
    public static String hideIdCardNum(String idCardNum){
        if (StringUtils.isBlank(idCardNum)){
            return idCardNum;
        }
        String begin = idCardNum.substring(0,6);
        String end = idCardNum.substring(idCardNum.length()-6);
        String mid = "******";
        return begin+mid+end;
    }
 
    /**
     * 根据单个含药量,返回一位编码
     * 0    x<1
     * 1    1≤x<2
     * 2    2≤x<3
     * 3    3≤x<4
     * 4    4≤x<5
     * 5    5≤x<6
     * 6    6≤x<7
     * 7    7≤x<8
     * 8    8≤x<9
     * 9    9≤x<10
     * A    10≤x<20
     * B    20≤x<30
     * C    30≤x<40
     * D    40≤x≤50
     * E    50<x<100
     * F    100≤x<200
     * G    200≤x<500
     * H    500≤x<1000
     * I    定义中不含I
     * J    1000≤x≤1200
     * K    1200<x≤3000
     * L    3000<x≤8000
     */
    public static String getBitCode(float x){
 
        String bitCode = "";
        if (x < 1){
            bitCode = "0";
        }else if (1<=x && x<2){
            bitCode = "1";
        }else if (x>=2 && x<3){
            bitCode = "2";
        }else if (x>=3 && x<4){
            bitCode = "3";
        }else if (x>=4 && x<5){
            bitCode = "4";
        }else if (x>=5 && x<6){
            bitCode = "5";
        }else if (x>=6 && x<7){
            bitCode = "6";
        }else if (x>=7 && x<8){
            bitCode = "7";
        }else if (x>=8 && x<9){
            bitCode = "8";
        }else if (x>=9 && x<10){
            bitCode = "9";
        }else if (x>=10 && x<20){
            bitCode = "A";
        }else if (x>=20 && x<30){
            bitCode = "B";
        }else if (x>=30 && x<40){
            bitCode = "C";
        }else if (x>=40 && x<=50){
            bitCode = "D";
        }else if (x>50 && x<100){
            bitCode = "E";
        }else if (x>=100 && x<200){
            bitCode = "F";
        }else if (x>=200 && x<500){
            bitCode = "G";
        }else if (x>=500 && x<1000){
            bitCode = "H";
        }else if (x>=1000 && x<=1200){
            bitCode = "J";
        }else if (x>1200 && x<=3000){
            bitCode = "K";
        }else if (x>3000 && x<=8000){
            bitCode = "L";
        }
        return bitCode;
    }
}