zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.service.impl;
 
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.beans.RedisBean;
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.beans.SysSourceDataBean;
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.beans.SysSourceDateParamBean;
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.service.MonitoringServiceI;
import com.shlanbao.tzsc.utils.tools.RedisUtil;
import com.shlanbao.tzsc.utils.tools.StringUtil;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
 
import java.util.*;
 
@Service
public class MonitoringServiceImpl implements MonitoringServiceI {
 
    /**
     * 查询源数据信息
     * @author sunzhen
     * @create 2019年9月16日下午15:30:05
     * @param
     * @throws Exception
     */
    @Override
    public DataGrid getAllDatas(SysSourceDateParamBean sourceDateParamBean) {
        //总记录数
        long total=0;
        //存放源数据bean的list
        List<RedisBean> lastRows = new ArrayList<>();
        RedisBean bean=null;
 
        Map<String,String> map = RedisUtil.getMap(sourceDateParamBean.getName());
        Set<String> keys = map.keySet();
        for(String key : keys){
            bean = new RedisBean();
            bean.setKey(key);
            bean.setValue(map.get(key));
            lastRows.add(bean);
        }
        total=lastRows.size();
 
        return new DataGrid(lastRows, total);
    }
 
    /**
     * 查询源数据列表信息
     * @author sunzhen
     * @create 2019年9月16日下午15:30:05
     * @param
     * @throws Exception
     */
    @Override
    public DataGrid querySourceDateList(SysSourceDateParamBean sourceDateParamBean) {
        //从Redis中获取所有的key值
        Set<String> keys = RedisUtil.keys("*");
        System.out.println(keys);
 
        //总记录数
        long total=0;
        //存放源数据bean的list
        List<SysSourceDataBean> lastRows = new ArrayList<SysSourceDataBean>();
        SysSourceDataBean bean = null;
 
        //遍历所有的key值赋值到bean中并存放到lastRows中去
        for (String key : keys) {
            //筛选符合查询条件的key值
            if(checkEqpType(key,sourceDateParamBean.getEqpType())&&key.contains(sourceDateParamBean.getName())){
                bean = new SysSourceDataBean();
                bean.setName(key);
                bean.setDes(codeParsing(key));
                lastRows.add(bean);
            }
        }
        total=lastRows.size();
 
        return new DataGrid(lastRows, total);
    }
 
    /**
     * 将key值的解释从符号转换成中文
     * @param key
     * @return
     */
    private String codeParsing(String key) {
        /*
            目前有以下几种种类:
                -----------4位数字-------------
                1.  1101
                    2101
                    1401
                -----------4位数字+1个字母-------------
                2.  1102C
                3.  1102J
                4.  1102M
                5.  1202G
                6.  1401F
                7.  1401Z
                8.  1502X
                -----------3位数字+2个字母-------------
                9.  101CC
                    102CC
                -----------其他-------------
                10. converted-preview-pdf-file
                11. converted-preview-pdfimgs-file
                12. outputInput
                13. shift
                14. workorder
                15. \xAC\xED\x00\x05t\x00\x04123M
 
         */
        String des="";
        switch(key.length()){
            case 4:
 
                switch(key.substring(0,1)){
                    case "1":
                        des+="早班"+key.substring(2,4)+"号";
                        des = parseEqpName(key, des, 1, 2);
                        return des;
                    case "2":
                        des+="中班"+key.substring(2,4)+"号";
                        des = parseEqpName(key, des, 1, 2);
                        return des;
                    case "3":
                        des+="晚班"+key.substring(2,4)+"号";
                        des = parseEqpName(key, des, 1, 2);
                        return des;
                }
 
                break;
            case 5:
 
                if(key.endsWith("CC")){ //先对以CC结尾的key进行筛选,因为下面有以C结尾的情况
 
                    des+=key.substring(1,3)+"号";
                    des = parseEqpName(key, des, 0, 1);
                    des+="辅料转换系数";
                    return des;
 
                }else{ //这里shift会进来,但下面会筛选掉
                    String str = key.substring(4, 5);
                    if(str.equals("C")|| str.equals("J")|| str.equals("M")
                            || str.equals("Z")|| str.equals("F")|| str.equals("G")||
                            str.equals("X")){
 
                        switch(key.substring(0,1)){
                            case "1":
                                des+="早班"+key.substring(2,4)+"号";
                                des = parseEqpName(key, des, 1, 2);
                                des+= str;
                                return des;
                            case "2":
                                des+="中班"+key.substring(2,4)+"号";
                                des = parseEqpName(key, des, 1, 2);
                                des+= str;
                                return des;
                            case "3":
                                des+="晚班"+key.substring(2,4)+"号";
                                des = parseEqpName(key, des, 1, 2);
                                des+= str;
                                return des;
                        }
                    }
                }
 
                break;
            default:
                return "暂无信息";
        }
 
        return "暂无信息";
    }
 
    private String parseEqpName(String key, String des, int start, int end) {
        switch(key.substring(start,end)){
            case "1":
                des+="卷烟机组";
                break;
            case "2":
                des+="包装机组";
                break;
            case "3":
                des+="装箱机组";
                break;
            case "4":
                des+="成型机组";
                break;
            case "5":
                des+="发射机组";
                break;
            case "6":
                des+="提升机组";
                break;
        }
        return des;
    }
 
    /**
     * 检查key值是否属于eqpType的机器类型
     * @param key key值为被检查的值
     * @param eqpType 机器类型为匹配的条件
     * @return
     */
    public boolean checkEqpType(String key,String eqpType){
        /*
            目前有以下几种种类:
                -----------4位数字-------------
                1.  1101
                    2101
                    1401
                -----------4位数字+1个字母-------------
                2.  1102C
                3.  1102J
                4.  1102M
                5.  1202G
                6.  1401F
                7.  1401Z
                8.  1502X
                -----------3位数字+2个字母-------------
                9.  101CC
                    102CC
                -----------其他-------------
                10. converted-preview-pdf-file
                11. converted-preview-pdfimgs-file
                12. outputInput
                13. shift
                14. workorder
                15. \xAC\xED\x00\x05t\x00\x04123M
 
         */
 
        // 当机器类型为空时则满足所有任何条件,返回true
        if(!StringUtil.notNull(eqpType)){
            return true;
        }
 
        //1. 首先根据机器类别筛选,分为六种类型:卷烟机、包装机、装封箱机、发射机、成型机、提升机
        //2. 然后根据key值的长度进行筛选,分为两种情况:key值长度=4、key值长度=5
        //3. 当key值长度=5时还分两种情况:以CC结尾的、不以CC结尾的
        //4. 最后根据不同的情况,用key值中的某一位与代表机器类型的值进行匹配
        switch(eqpType){
            case "卷烟机":
 
                switch (key.length()){
                    case 4:
                        if(key.charAt(1)=='1') return true;
                    case 5:
                        if(key.endsWith("CC")){
                            if(key.charAt(0)=='1') return true;
                        }else{
                            if(key.charAt(1)=='1') return true;
                        }
                }
 
                return false;
            case "包装机":
 
                switch (key.length()){
                    case 4:
                        if(key.charAt(1)=='2') return true;
                    case 5:
                        if(key.endsWith("CC")){
                            if(key.charAt(0)=='2') return true;
                        }else{
                            if(key.charAt(1)=='2') return true;
                        }
                }
 
                return false;
            case "装封箱机":
 
                switch (key.length()){
                    case 4:
                        if(key.charAt(1)=='3') return true;
                    case 5:
                        if(key.endsWith("CC")){
                            if(key.charAt(0)=='3') return true;
                        }else{
                            if(key.charAt(1)=='3') return true;
                        }
                }
 
                return false;
            case "发射机":
 
                switch (key.length()){
                    case 4:
                        if(key.charAt(1)=='5') return true;
                    case 5:
                        if(key.endsWith("CC")){
                            if(key.charAt(0)=='5') return true;
                        }else{
                            if(key.charAt(1)=='5') return true;
                        }
                }
 
                return false;
            case "成型机":
 
                switch (key.length()){
                    case 4:
                        if(key.charAt(1)=='4') return true;
                    case 5:
                        if(key.endsWith("CC")){
                            if(key.charAt(0)=='4') return true;
                        }else{
                            if(key.charAt(1)=='4') return true;
                        }
                }
 
                return false;
            case "提升机":
 
                switch (key.length()){
                    case 4:
                        if(key.charAt(1)=='6') return true;
                    case 5:
                        if(key.endsWith("CC")){
                            if(key.charAt(0)=='6') return true;
                        }else{
                            if(key.charAt(1)=='6') return true;
                        }
                }
 
                return false;
        }
 
        return false;
    }
 
}