ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
package jnpf.base.util;
 
import cn.hutool.core.util.ObjectUtil;
import jnpf.model.visualJson.FieLdsModel;
import jnpf.model.visualJson.config.ConfigModel;
import jnpf.util.*;
import jnpf.util.visiual.JnpfKeyConsts;
 
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 在线开发公用
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2021/7/28
 */
public class FormPublicUtils {
 
    /**
     * 递归控件,除子表外控件全部提到同级
     * 取子集,子表不外提
     *
     * @return
     */
    public static void recursionFieldsExceptChild(List<FieLdsModel> allFields, List<FieLdsModel> fieLdsModelList) {
        for (FieLdsModel fieLdsModel : fieLdsModelList) {
            ConfigModel config = fieLdsModel.getConfig();
            String jnpfKey = config.getJnpfKey();
            if (JnpfKeyConsts.CHILD_TABLE.equals(jnpfKey)) {
                allFields.add(fieLdsModel);
                continue;
            } else {
                if (config.getChildren() != null) {
                    recursionFieldsExceptChild(allFields, config.getChildren());
                } else {
                    if (jnpfKey == null) {
                        continue;
                    }
                    allFields.add(fieLdsModel);
                }
            }
        }
    }
 
    /**
     * 转换时间格式
     *
     * @param time
     * @return
     */
    public static String getTimeFormat(String time) {
        String result;
        switch (time.length()) {
            case 16:
                result = time + ":00";
                break;
            case 19:
                result = time;
                break;
            case 21:
                result = time.substring(0, time.length() - 2);
                break;
            case 10:
                result = time + " 00:00:00";
                break;
            case 8:
                result = "2000-01-01 " + time;
                break;
            case 7:
                result = time + "-01 00:00:00";
                break;
            case 4:
                result = time + "-01-01 00:00:00";
                break;
            default:
                result = "";
                break;
        }
        return result;
    }
 
    public static String getLastTimeFormat(String time) {
        String result;
        switch (time.length()) {
            case 16:
                result = time + ":00";
                break;
            case 19:
                result = time;
                break;
            case 10:
                result = time + " 23:59:59";
                break;
            case 8:
                result = "2000-01-01 " + time;
                break;
            case 7:
                //获取月份最后一天
                String[] split = time.split("-");
                Calendar cale = Calendar.getInstance();
                cale.set(Calendar.YEAR, Integer.valueOf(split[0]));//赋值年份
                cale.set(Calendar.MONTH, Integer.valueOf(split[1]) - 1);//赋值月份
                int lastDay = cale.getActualMaximum(Calendar.DAY_OF_MONTH);//获取月最大天数
                cale.set(Calendar.DAY_OF_MONTH, lastDay);//设置日历中月份的最大天数
                cale.set(Calendar.HOUR_OF_DAY, 23);
                cale.set(Calendar.SECOND, 59);
                cale.set(Calendar.MINUTE, 59);
                result = DateUtil.daFormatHHMMSS(cale.getTime().getTime());
                break;
            case 4:
                result = time + "-12-31 23:59:59";
                break;
            default:
                result = "";
                break;
        }
        return result;
    }
 
    /**
     * 判断时间是否在设置范围内
     *
     * @param swapDataVo
     * @param format
     * @param value
     * @param data
     * @param jnpfKey
     * @return
     */
    public static boolean dateTimeCondition(FieLdsModel swapDataVo, String format, Object value, Map<String, Object> data, String jnpfKey) {
        long valueTimeLong;
        //输入值转long
        if (value instanceof String) {
            valueTimeLong = cn.hutool.core.date.DateUtil.parse(String.valueOf(value), format).getTime();
        } else {
            //输入值按格式补全
            String timeFormat = getTimeFormat(String.valueOf(value));
            valueTimeLong = DateUtil.stringToDate(timeFormat).getTime();
        }
        boolean timeHasRangeError = false;
        //开始时间判断
        if (swapDataVo.getConfig().getStartTimeRule()) {
            String startTimeValue = swapDataVo.getConfig().getStartTimeValue();
            String startTimeType = swapDataVo.getConfig().getStartTimeType();
            String startTimeTarget = swapDataVo.getConfig().getStartTimeTarget();
            String startTimeRelationField = swapDataVo.getConfig().getStartRelationField();
            //根据类型获取开始时间戳
            long startTimeLong = getDateTimeLong(data, jnpfKey, startTimeValue, startTimeType, startTimeTarget, startTimeRelationField, format);
            if (startTimeLong != 0 && valueTimeLong < startTimeLong) {
                timeHasRangeError = true;
            }
        }
        //结束时间判断
        if (swapDataVo.getConfig().getEndTimeRule()) {
            String endTimeValue = swapDataVo.getConfig().getEndTimeValue();
            String endTimeType = swapDataVo.getConfig().getEndTimeType();
            String endTimeTarget = swapDataVo.getConfig().getEndTimeTarget();
            String endTimeRelationField = swapDataVo.getConfig().getEndRelationField();
            //根据类型获取开始时间戳
            long endTimeLong = getDateTimeLong(data, jnpfKey, endTimeValue, endTimeType, endTimeTarget, endTimeRelationField, format);
            if (endTimeLong != 0 && valueTimeLong > endTimeLong) {
                timeHasRangeError = true;
            }
        }
        return timeHasRangeError;
    }
 
    /**
     * 根据类型获取时间戳
     *
     * @param data
     * @param jnpfKey
     * @param timeValue
     * @param timeType
     * @param timeTarget
     * @return
     */
    public static long getDateTimeLong(Map<String, Object> data, String jnpfKey, String timeValue, String timeType, String timeTarget,
                                       String stringimeRelationField, String format) {
        if (StringUtil.isEmpty(timeValue)) {
            timeValue = "0";
        }
        long startTimeLong = 0;
        //当前格式的当前时间戳
        long timestampInMillis = new Date().getTime();
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            String s = sdf.format(new Date());
            timestampInMillis = sdf.parse(s).getTime();
        } catch (ParseException e) {
        }
        switch (timeType) {
            case "1"://特定时间
                if (JnpfKeyConsts.DATE.equals(jnpfKey)) {
                    startTimeLong = Long.parseLong(timeValue);
                } else {
                    String newDateStr = DateUtil.daFormat(new Date()) + " " + timeValue + (timeValue.length() > 6 ? "" : ":00");
                    startTimeLong = DateUtil.stringToDate(newDateStr).getTime();
                }
                break;
            case "2"://表单字段
                if (stringimeRelationField != null) {
                    String fieldValue = "";
                    if (stringimeRelationField.toLowerCase().contains(JnpfKeyConsts.CHILD_TABLE_PREFIX)) {//子
                        String[] split = stringimeRelationField.split("-");
                        fieldValue = data.get(split[1]) != null ? data.get(split[1]).toString() : "";
                    } else {//主副
                        Map<String, Object> mainAndMast = data.get("mainAndMast") != null ? JsonUtil.entityToMap(data.get("mainAndMast")) : data;
                        fieldValue = mainAndMast.get(stringimeRelationField) != null ? mainAndMast.get(stringimeRelationField).toString() : "";
                    }
                    if (StringUtil.isNotEmpty(fieldValue)) {
                        String timeFormat = getTimeFormat(fieldValue);
                        startTimeLong = cn.hutool.core.date.DateUtil.parse(timeFormat, "yyyy-MM-dd HH:mm:ss").getTime();
                    }
                }
                break;
            case "3"://填写当前时间
                startTimeLong = timestampInMillis;
                break;
            case "4"://当前时间前
                Calendar caledel = Calendar.getInstance();
                caledel.setTimeInMillis(timestampInMillis);
                if (JnpfKeyConsts.DATE.equals(jnpfKey)) {
                    switch (timeTarget) {
                        case "1"://年
                            caledel.set(Calendar.YEAR, caledel.get(Calendar.YEAR) - Integer.valueOf(timeValue));//赋值年份
                            break;
                        case "2"://月
                            caledel.set(Calendar.MONTH, caledel.get(Calendar.MONTH) - Integer.valueOf(timeValue));
                            break;
                        case "3"://日
                            caledel.set(Calendar.DAY_OF_MONTH, caledel.get(Calendar.DAY_OF_MONTH) - Integer.valueOf(timeValue));
                            break;
                    }
                } else {
                    switch (timeTarget) {
                        case "1"://时
                            caledel.set(Calendar.HOUR_OF_DAY, caledel.get(Calendar.HOUR_OF_DAY) - Integer.valueOf(timeValue));
                            break;
                        case "2"://分
                            caledel.set(Calendar.MINUTE, caledel.get(Calendar.MINUTE) - Integer.valueOf(timeValue));
                            break;
                        case "3"://秒
                            caledel.set(Calendar.SECOND, caledel.get(Calendar.SECOND) - Integer.valueOf(timeValue));
                            break;
                    }
                }
                startTimeLong = caledel.getTime().getTime();
                break;
            case "5"://当前时间后
                Calendar cale = Calendar.getInstance();
                cale.setTimeInMillis(timestampInMillis);
                if (JnpfKeyConsts.DATE.equals(jnpfKey)) {
                    switch (timeTarget) {
                        case "1"://年
                            cale.set(Calendar.YEAR, cale.get(Calendar.YEAR) + Integer.valueOf(timeValue));//赋值年份
                            break;
                        case "2"://月
                            cale.set(Calendar.MONTH, cale.get(Calendar.MONTH) + Integer.valueOf(timeValue));
                            break;
                        case "3"://日
                            cale.set(Calendar.DAY_OF_MONTH, cale.get(Calendar.DAY_OF_MONTH) + Integer.valueOf(timeValue));
                            break;
                    }
                } else {
                    switch (timeTarget) {
                        case "1"://时
                            cale.set(Calendar.HOUR_OF_DAY, cale.get(Calendar.HOUR_OF_DAY) + Integer.valueOf(timeValue));
                            break;
                        case "2"://分
                            cale.set(Calendar.MINUTE, cale.get(Calendar.MINUTE) + Integer.valueOf(timeValue));
                            break;
                        case "3"://秒
                            cale.set(Calendar.SECOND, cale.get(Calendar.SECOND) + Integer.valueOf(timeValue));
                            break;
                    }
                }
                startTimeLong = cale.getTime().getTime();
                break;
            default:
                break;
        }
        return startTimeLong;
    }
 
    /**
     * 字符串转数组
     *
     * @param value 值
     * @return
     */
    public static Object getDataConversion(Object value) {
        if (value instanceof Integer || value instanceof Long || value instanceof Float || value instanceof Double || value instanceof BigDecimal)
            return value;
        Object dataValue = getDataConversion(null, value, false, "/");
        return dataValue;
    }
 
    /**
     * 字符串转数组
     *
     * @param redis 转换对象
     * @param value 值
     * @return
     */
    public static Object getDataConversion(Map<String, Object> redis, Object value, boolean isMultiple, String separator) {
        Object dataValue = value;
        boolean iszhuanhuan = redis != null;
        try {
            List<List> list = JsonUtil.getJsonToList(String.valueOf(value), List.class);
            dataValue = list;
            if (iszhuanhuan) {
                //一级分隔符
                StringJoiner joiner = new StringJoiner(",");
                for (List listChild : list) {
                    StringJoiner aa = new StringJoiner(separator);
                    for (Object object : listChild) {
                        String value1 = redis.get(String.valueOf(object)) != null ? String.valueOf(redis.get(String.valueOf(object))) : "";
                        if (StringUtil.isNotEmpty(value1)) {
                            aa.add(value1);
                        }
                    }
                    joiner.add(aa.toString());
                }
                dataValue = joiner.toString();
            }
        } catch (Exception e) {
            try {
                List<String> list = JsonUtil.getJsonToList(String.valueOf(value), String.class);
                dataValue = list;
                if (iszhuanhuan) {
                    if (isMultiple) {//一级分隔符
                        separator = ",";
                    }
                    StringJoiner joiner = new StringJoiner(separator);
                    for (Object listChild : list) {
                        String value1 = redis.get(String.valueOf(listChild)) != null ? String.valueOf(redis.get(String.valueOf(listChild))) : "";
                        if (StringUtil.isNotEmpty(value1)) {
                            joiner.add(value1);
                        }
                    }
                    dataValue = joiner.toString();
                }
            } catch (Exception e1) {
                dataValue = String.valueOf(value);
                if (iszhuanhuan) {
                    dataValue = redis.get(String.valueOf(value)) != null ? String.valueOf(redis.get(String.valueOf(value))) : "";
                }
            }
        }
        return dataValue;
    }
 
    /**
     * 给列表数据添加id
     *
     * @param dataList
     * @param key
     */
    public static List<Map<String, Object>> addIdToList(List<Map<String, Object>> dataList, String key) {
        return dataList.stream().map(data -> {
            data.put(FlowFormConstant.ID, data.get(key));
            String flwoId = null;
            if (data.get(TableFeildsEnum.FLOWID.getField()) != null) {
                flwoId = String.valueOf(data.get(TableFeildsEnum.FLOWID.getField()));
            }
            if (data.get(TableFeildsEnum.FLOWID.getField().toUpperCase()) != null) {
                flwoId = String.valueOf(data.get(TableFeildsEnum.FLOWID.getField().toUpperCase()));
            }
            data.put(FlowFormConstant.FLOWID, flwoId);
            String flowTaskId = null;
            if (data.get(TableFeildsEnum.FLOWTASKID.getField()) != null) {
                flowTaskId = String.valueOf(data.get(TableFeildsEnum.FLOWTASKID.getField()));
            }
            if (data.get(TableFeildsEnum.FLOWTASKID.getField().toUpperCase()) != null) {
                flowTaskId = String.valueOf(data.get(TableFeildsEnum.FLOWTASKID.getField().toUpperCase()));
            }
            data.put(FlowFormConstant.FLOWTASKID, flowTaskId);
 
            return data;
        }).collect(Collectors.toList());
    }
 
    /**
     * 关联表单获取原字段数据(数据类型也要转换)
     *
     * @param dataMap
     * @param jnpfKey
     * @param obj
     * @param vModel
     */
    public static void relationGetJnpfId(Map<String, Object> dataMap, String jnpfKey, Object obj, String vModel) {
        String vModeljnpfId = vModel + "_jnpfId";
        switch (jnpfKey) {
            case JnpfKeyConsts.CREATETIME:
            case JnpfKeyConsts.MODIFYTIME:
            case JnpfKeyConsts.DATE:
                Long dateTime = DateTimeFormatConstant.getDateObjToLong(dataMap.get(vModel));
                dataMap.put(vModeljnpfId, dateTime != null ? dateTime : dataMap.get(vModel));
                break;
            case JnpfKeyConsts.CHILD_TABLE:
                break;
            case JnpfKeyConsts.SWITCH:
            case JnpfKeyConsts.SLIDER:
            case JnpfKeyConsts.RATE:
            case JnpfKeyConsts.CALCULATE:
            case JnpfKeyConsts.NUM_INPUT:
                dataMap.put(vModeljnpfId, ObjectUtil.isNotEmpty(obj) ? new BigDecimal(String.valueOf(obj)) : dataMap.get(vModel));
                break;
            default:
                dataMap.put(vModeljnpfId, obj);
                break;
        }
        if (JnpfKeyConsts.getArraysKey().contains(jnpfKey) && obj != null) {
            String o = String.valueOf(obj);
            try {
                List<List> jsonToList = JsonUtil.getJsonToList(o, List.class);
                List<Object> res = new ArrayList<>();
                for (List listChild : jsonToList) {
                    List<Object> res2 = new ArrayList<>();
                    for (Object object : listChild) {
                        if (object != null && StringUtil.isNotEmpty(String.valueOf(object))) {
                            res2.add(object);
                        }
                    }
                    res.add(res2);
                }
                dataMap.put(vModeljnpfId, res);
            } catch (Exception e) {
                try {
                    List<Object> jsonToList = JsonUtil.getJsonToList(o, Object.class);
                    dataMap.put(vModeljnpfId, jsonToList);
                } catch (Exception e1) {
                }
            }
        }
    }
}