yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
package com.qianwen.smartman.modules.system.service.impl;
 
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.core.tool.utils.StringUtil;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.DncConstant;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.modules.cps.entity.Employee;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.cps.vo.HierarchyVO;
import com.qianwen.smartman.modules.system.constant.FieldConstant;
import com.qianwen.smartman.modules.system.convert.CustomTemplateFieldConvert;
import com.qianwen.smartman.modules.system.dto.CustomTemplateColumnDTO;
import com.qianwen.smartman.modules.system.entity.CustomTemplate;
import com.qianwen.smartman.modules.system.entity.CustomTemplateField;
import com.qianwen.smartman.modules.system.entity.CustomTemplateFieldOption;
import com.qianwen.smartman.modules.system.entity.CustomTemplateFieldRelation;
import com.qianwen.smartman.modules.system.enums.ConfigTypeEnum;
import com.qianwen.smartman.modules.system.enums.CustomFieldTypeEnums;
import com.qianwen.smartman.modules.system.mapper.CustomTemplateFieldMapper;
import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldOptionService;
import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldRelationService;
import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldService;
import com.qianwen.smartman.modules.system.service.ICustomTemplateService;
import com.qianwen.smartman.modules.system.vo.CustomFieldRelationInfoVO;
import com.qianwen.smartman.modules.system.vo.CustomFieldRelationListVO;
import com.qianwen.smartman.modules.system.vo.CustomFieldRelationSelectVO;
import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldColumnVO;
import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldListVO;
import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldSubmitVO;
import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldUpdateVO;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
 
@Service
public class CustomTemplateFieldServiceImpl extends BaseServiceImpl<CustomTemplateFieldMapper, CustomTemplateField> implements ICustomTemplateFieldService {
    @Autowired
    private ICustomTemplateFieldOptionService customTemplateFieldOptionService;
    @Autowired
    @Lazy
    private ICustomTemplateService customTemplateService;
    @Autowired
    private CustomTemplateFieldMapper customTemplateFieldMapper;
    @Autowired
    private ICustomTemplateFieldRelationService customTemplateFieldRelationService;
    @Autowired
    private IEmployeeService employeeService;
    public static final List<Integer> CUSTOM_FIELD_TYPE_LIST = Arrays.asList(CustomFieldTypeEnums.SELECT.getType(), CustomFieldTypeEnums.MULTI_SELECT.getType(), CustomFieldTypeEnums.DROP_DOWN.getType(), CustomFieldTypeEnums.CASCADE_SELECT.getType());
    @Autowired
    private BladeRedis bladeRedis;
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    @Transactional(rollbackFor = {Exception.class})
    public CustomTemplateField saveField(CustomTemplateFieldSubmitVO customTemplateFieldSubmitVO) {
        if (checkNameIsExist(customTemplateFieldSubmitVO.getId(), customTemplateFieldSubmitVO.getFieldName(), customTemplateFieldSubmitVO.getBusinessType())) {
            throw new ServiceException(MessageUtils.message("template.field.name.already.exist", new Object[0]));
        }
        CustomTemplateField customTemplateField = CustomTemplateFieldConvert.INSTANCE.convert(customTemplateFieldSubmitVO);
        Integer fieldType = customTemplateFieldSubmitVO.getFieldType();
        if (CUSTOM_FIELD_TYPE_LIST.contains(fieldType) && Func.isNotEmpty(customTemplateFieldSubmitVO.getPropertyJson())) {
            JSONObject propertyJson = JSONUtil.parseObj(customTemplateField.getPropertyJson());
            List<CustomTemplateFieldOption> customTemplateFieldOptions = optionFieldJsonToBean(propertyJson, customTemplateField.getId());
            this.customTemplateFieldOptionService.saveBatch(customTemplateFieldOptions);
            propertyJson.remove(FieldConstant.OPTION_NAME);
            if (fieldType.equals(CustomFieldTypeEnums.SELECT.getType()) || fieldType.equals(CustomFieldTypeEnums.MULTI_SELECT.getType())) {
                Map<String, String> optionMap =  customTemplateFieldOptions.stream().collect(Collectors.toMap(c -> {
                    return c.getKey() +  ":" + c.getValue();
                }, c2 -> {
                    return String.valueOf(c2.getId());
                }));
                Object vaStr = fieldType.equals(CustomFieldTypeEnums.SELECT.getType()) ? handlerSelectValue(customTemplateField.getPropertyJson(), optionMap) : handlerMultiValue(customTemplateField.getPropertyJson(), optionMap);
                propertyJson.put(FieldConstant.SELECT_OPTION, vaStr);
            }
            customTemplateField.setPropertyJson(propertyJson.toString());
        }
        save(customTemplateField);
        return customTemplateField;
    }
 
    private String handlerSelectValue(String propertyJson, Map<String, String> optionMap) {
        JSONObject json = JSONUtil.parseObj(propertyJson);
        String selectOption = json.getStr(FieldConstant.SELECT_OPTION);
        List<OptionBean> optionBeans = json.getJSONArray(FieldConstant.OPTION_NAME).toList(OptionBean.class);
        return getOptionIdByDefaultValue(selectOption, optionBeans, optionMap);
    }
 
    private String getOptionIdByDefaultValue(String defaultValue, List<OptionBean> optionBeans, Map<String, String> optionMap) {
        for (OptionBean option : optionBeans) {
            if (option.getValue().equals(defaultValue)) {
                return optionMap.get(option.getValue() +  ":" + option.getLabel());
            }
        }
        return "";
    }
 
    private List<String> handlerMultiValue(String propertyJson, Map<String, String> optionMap) {
        JSONObject json = JSONUtil.parseObj(propertyJson);
        JSONArray selectOptions = json.getJSONArray(FieldConstant.SELECT_OPTION);
        List<OptionBean> optionBeans = json.getJSONArray(FieldConstant.OPTION_NAME).toList(OptionBean.class);
        List<String> optionIds = new ArrayList<>();
        selectOptions.forEach(op -> {
            optionIds.add(getOptionIdByDefaultValue(String.valueOf(op), optionBeans, optionMap));
        });
        return optionIds;
    }
 
    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/service/impl/CustomTemplateFieldServiceImpl$OptionBean.class */
    public static class OptionBean {
        private String label;
        private String value;
        private List<OptionBean> children;
 
        /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/service/impl/CustomTemplateFieldServiceImpl$OptionBean$OptionBeanBuilder.class */
        public static class OptionBeanBuilder {
            private String label;
            private String value;
            private List<OptionBean> children;
 
            OptionBeanBuilder() {
            }
 
            public OptionBeanBuilder label(final String label) {
                this.label = label;
                return this;
            }
 
            public OptionBeanBuilder value(final String value) {
                this.value = value;
                return this;
            }
 
            public OptionBeanBuilder children(final List<OptionBean> children) {
                this.children = children;
                return this;
            }
 
            public OptionBean build() {
                return new OptionBean(this.label, this.value, this.children);
            }
 
            public String toString() {
                return "CustomTemplateFieldServiceImpl.OptionBean.OptionBeanBuilder(label=" + this.label + ", value=" + this.value + ", children=" + this.children + ")";
            }
        }
 
        public void setLabel(final String label) {
            this.label = label;
        }
 
        public void setValue(final String value) {
            this.value = value;
        }
 
        public void setChildren(final List<OptionBean> children) {
            this.children = children;
        }
 
        public boolean equals(final Object o) {
            if (o == this) {
                return true;
            }
            if (o instanceof OptionBean) {
                OptionBean other = (OptionBean) o;
                if (other.canEqual(this)) {
                    Object this$label = getLabel();
                    Object other$label = other.getLabel();
                    if (this$label == null) {
                        if (other$label != null) {
                            return false;
                        }
                    } else if (!this$label.equals(other$label)) {
                        return false;
                    }
                    Object this$value = getValue();
                    Object other$value = other.getValue();
                    if (this$value == null) {
                        if (other$value != null) {
                            return false;
                        }
                    } else if (!this$value.equals(other$value)) {
                        return false;
                    }
                    Object this$children = getChildren();
                    Object other$children = other.getChildren();
                    return this$children == null ? other$children == null : this$children.equals(other$children);
                }
                return false;
            }
            return false;
        }
 
        protected boolean canEqual(final Object other) {
            return other instanceof OptionBean;
        }
 
        public int hashCode() {
            Object $label = getLabel();
            int result = (1 * 59) + ($label == null ? 43 : $label.hashCode());
            Object $value = getValue();
            int result2 = (result * 59) + ($value == null ? 43 : $value.hashCode());
            Object $children = getChildren();
            return (result2 * 59) + ($children == null ? 43 : $children.hashCode());
        }
 
        public String toString() {
            return "CustomTemplateFieldServiceImpl.OptionBean(label=" + getLabel() + ", value=" + getValue() + ", children=" + getChildren() + ")";
        }
 
        OptionBean(final String label, final String value, final List<OptionBean> children) {
            this.label = label;
            this.value = value;
            this.children = children;
        }
 
        public static OptionBeanBuilder builder() {
            return new OptionBeanBuilder();
        }
 
        public String getLabel() {
            return this.label;
        }
 
        public String getValue() {
            return this.value;
        }
 
        public List<OptionBean> getChildren() {
            return this.children;
        }
    }
 
    private List<CustomTemplateFieldOption> optionFieldJsonToBean(JSONObject propertyJson, Long fieldId) {
        Snowflake snowflake = IdUtil.getSnowflake(1L, 1L);
        JSONArray optionArray = propertyJson.getJSONArray(FieldConstant.OPTION_NAME);
        if (optionArray.isEmpty()) {
            return new ArrayList<>();
        }
        return parseOptionJsonToBean(optionArray, fieldId, snowflake, FieldConstant.PARENT_ID);
    }
 
    private List<CustomTemplateFieldOption> parseOptionJsonToBean(JSONArray parentArray, Long fieldId, Snowflake snowflake, Long parentId) {
        List<CustomTemplateFieldOption> result = new ArrayList<>();
        List<String> tempList = new ArrayList<>();
        Iterator it = parentArray.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            long id = snowflake.nextId();
            JSONObject valueObj = (JSONObject) obj;
            JSONArray children = valueObj.getJSONArray(FieldConstant.CHILDREN_NAME);
            CustomTemplateFieldOption customTemplateFieldOption = new CustomTemplateFieldOption();
            customTemplateFieldOption.setId(Long.valueOf(id));
            customTemplateFieldOption.setFieldId(fieldId);
            customTemplateFieldOption.setValue(valueObj.getStr(FieldConstant.OPTION_LABEL));
            customTemplateFieldOption.setKey(valueObj.getStr(FieldConstant.OPTION_KEY));
            customTemplateFieldOption.setParentId(parentId);
            if (tempList.contains(customTemplateFieldOption.getValue())) {
                throw new ServiceException(MessageUtils.message("template.field.option.already.exist", new Object[0]));
            }
            tempList.add(customTemplateFieldOption.getValue());
            result.add(customTemplateFieldOption);
            if (CollectionUtil.isNotEmpty(children)) {
                result.addAll(parseOptionJsonToBean(children, fieldId, snowflake, Long.valueOf(id)));
            }
        }
        return result;
    }
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    @Transactional
    public CustomTemplateField updateField(CustomTemplateFieldUpdateVO fieldSubmitVO) {
        if (checkNameIsExist(fieldSubmitVO.getId(), fieldSubmitVO.getFieldName(), fieldSubmitVO.getBusinessType())) {
            throw new ServiceException(MessageUtils.message("template.field.name.already.exist", new Object[0]));
        }
        CustomTemplateField customTemplateField = CustomTemplateFieldConvert.INSTANCE.convertUpdateVO(fieldSubmitVO);
        updateById(customTemplateField);
        CustomTemplateField field = (CustomTemplateField) getById(fieldSubmitVO.getId());
        this.bladeRedis.del(FieldConstant.getFieldCacheKey(field.getFieldCode(), field.getBusinessType()));
        return field;
    }
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    public R removeFields(List<Long> ids) {
        if (!checkRemove(ids)) {
            throw new ServiceException(MessageUtils.message("template.field.use.not.remove", new Object[0]));
        }
        List<CustomTemplateField> fields = list(Wrappers.<CustomTemplateField>lambdaQuery().in(CustomTemplateField::getId, ids).in((ids.size() != 1), CustomTemplateField::getFieldType, CUSTOM_FIELD_TYPE_LIST));
        /*
        List<CustomTemplateField> fields = list(((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, ids)).in(ids.size() != 1, (v0) -> {
            return v0.getFieldType();
        }, CUSTOM_FIELD_TYPE_LIST));*/
        if (CollectionUtil.isNotEmpty(fields)) {
            this.customTemplateFieldOptionService.remove(Wrappers.<CustomTemplateFieldOption>lambdaQuery().in(CustomTemplateFieldOption::getFieldId, ids)); 
            /*
            this.customTemplateFieldOptionService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getFieldId();
            }, ids));*/
        }
        fields.forEach(field -> {
            this.bladeRedis.del(FieldConstant.getFieldCacheKey(field.getFieldCode(), field.getBusinessType()));
        });
        return R.status(removeByIds(ids));
    }
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    public CustomFieldRelationSelectVO getSelectBox(Long templateId, Integer configType) {
        CustomTemplate customTemplate = this.customTemplateService.getOne(Wrappers.<CustomTemplate>lambdaQuery().eq(CustomTemplate::getId, templateId));
        /*
        CustomTemplate customTemplate = (CustomTemplate) this.customTemplateService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getId();
        }, templateId));*/
        List<CustomTemplateColumnDTO> columnDTOList = fieldsOptionBeanToJson(CustomTemplateFieldConvert.INSTANCE.convertColumn(this.customTemplateFieldMapper.getSelectBox(customTemplate.getBusinessType(), templateId, configType)));
        List<CustomFieldRelationInfoVO> result = CustomTemplateFieldConvert.INSTANCE.convertRelationInfos(columnDTOList);
        CustomFieldRelationSelectVO customFieldRelationSelectVO = new CustomFieldRelationSelectVO();
        if (Func.isNotEmpty(result)) {
            Map<Integer, List<CustomFieldRelationInfoVO>> groupResult =  result.stream().collect(Collectors.groupingBy((v0) -> {
                return v0.getSystemField();
            }));
            customFieldRelationSelectVO.setCustomFieldList(groupResult.get(0));
            List<CustomFieldRelationInfoVO> customFieldRelationInfoVOS = groupResult.get(1);
            if (Func.equals(ConfigTypeEnum.ORDER_PAGE.getCode(), configType)) {
                customFieldRelationInfoVOS.forEach(item -> {
                    item.setSysFieldMust(CommonConstant.DEACTIVATE);
                });
            }
            customFieldRelationSelectVO.setSystemFieldList(customFieldRelationInfoVOS);
        }
        return customFieldRelationSelectVO;
    }
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    public CustomFieldRelationListVO listField(Long templateId, Integer configType) {
        List<CustomTemplateFieldListVO> customTemplateFieldListVOS = this.customTemplateFieldMapper.listField(templateId, configType);
        CustomFieldRelationListVO customFieldRelationListVO = new CustomFieldRelationListVO();
        if (Func.isNotEmpty(customTemplateFieldListVOS)) {
            Map<Integer, List<CustomTemplateFieldListVO>> groupResult = customTemplateFieldListVOS.stream().collect(Collectors.groupingBy((v0) -> {
                return v0.getSystemField();
            }));
            customFieldRelationListVO.setCustomFieldList(groupResult.get(0));
            customFieldRelationListVO.setSystemFieldList(groupResult.get(1));
        }
        return customFieldRelationListVO;
    }
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    public CustomTemplateField findFieldById(Long id) {
        CustomTemplateField customTemplateField = (CustomTemplateField) getById(id);
        if (Func.isNull(customTemplateField)) {
            return new CustomTemplateField();
        }
        optionFieldHandler(customTemplateField);
        return customTemplateField;
    }
 
    private void optionFieldHandler(CustomTemplateField customTemplateField) {
        if (!CUSTOM_FIELD_TYPE_LIST.contains(customTemplateField.getFieldType())) {
            return;
        }
        List<CustomTemplateFieldOption> templateFieldOptions = this.customTemplateFieldOptionService.list(Wrappers.<CustomTemplateFieldOption>lambdaQuery().eq(CustomTemplateFieldOption::getFieldId, customTemplateField.getId()));
        /*
        List<CustomTemplateFieldOption> templateFieldOptions = this.customTemplateFieldOptionService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getFieldId();
        }, customTemplateField.getId()));*/
        if (CollectionUtil.isEmpty(templateFieldOptions)) {
            return;
        }
        String jsonHandler = optionFieldBeanToJson(templateFieldOptions, customTemplateField.getPropertyJson());
        customTemplateField.setPropertyJson(jsonHandler);
    }
 
    /* JADX WARN: Multi-variable type inference failed */
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    public Object fieldCheck(Integer businessType, String fieldCode, String value) {
        String[] split;
        CustomTemplateField customTemplateField = getField(fieldCode, businessType);
        if (Func.isEmpty(customTemplateField)) {
            throw new RuntimeException("扩展字段不存在");
        }
        Integer fieldType = customTemplateField.getFieldType();
        String propJson = customTemplateField.getPropertyJson();
        if (Func.isEmpty(value)) {
            if (fieldType.equals(CustomFieldTypeEnums.MULTI_SELECT.getType()) || fieldType.equals(CustomFieldTypeEnums.CASCADE_SELECT.getType())) {
                return new ArrayList<>();
            }
            return "";
        }
        Object result = value;
        com.alibaba.fastjson.JSONObject propObject = com.alibaba.fastjson.JSONObject.parseObject(propJson);
        if (fieldType.equals(CustomFieldTypeEnums.INPUT.getType())) {
            Integer maxlength = propObject.getInteger("maxlength");
            if (value.length() > maxlength.intValue()) {
                throw new RuntimeException(customTemplateField.getFieldName() + "超出长度");
            }
            String formatName = propObject.getString("formatName");
            if (formatName.equals("mobile")) {
                if (!Pattern.matches("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", value)) {
                    throw new RuntimeException(customTemplateField.getFieldName() + "手机号码不匹配");
                }
            } else if (formatName.equals("telephone")) {
                Boolean flag = Boolean.valueOf(Pattern.matches("^[0][1-9]{2,3}-[0-9]{5,10}$", value) || Pattern.matches("^[1-9]{1}[0-9]{5,8}$", value));
                if (!flag.booleanValue()) {
                    throw new RuntimeException(customTemplateField.getFieldName() + "电话号码不匹配");
                }
            } else if (formatName.equals("email") && !Pattern.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", value)) {
                throw new RuntimeException(customTemplateField.getFieldName() + "邮箱不匹配");
            }
        } else if (fieldType.equals(CustomFieldTypeEnums.DIGITAL_INPUT.getType())) {
            if (!Pattern.matches("-?[0-9]+.?[0-9]{0,}", value)) {
                throw new RuntimeException(customTemplateField.getFieldName() + "非数字");
            }
            Float floatValue = Float.valueOf(value);
            Integer rangeMin = propObject.getInteger("rangeMin");
            Integer rangeMax = propObject.getInteger("rangeMax");
            Integer saveDecimalNum = propObject.getInteger(FieldConstant.SAVE_DECIMAL_NUM);
            if (floatValue.floatValue() > rangeMax.intValue() || floatValue.floatValue() < rangeMin.intValue()) {
                throw new RuntimeException(customTemplateField.getFieldName() + "不在限定数值范围内");
            }
            if (value.contains(DncConstant.POINT)) {
                result = BigDecimal.valueOf(floatValue.floatValue()).setScale(saveDecimalNum.intValue(), 1).toString();
            }
        } else if (fieldType.equals(CustomFieldTypeEnums.MULTI_TEXT.getType())) {
            Integer maxlength2 = propObject.getInteger("maxlength");
            if (value.length() > maxlength2.intValue()) {
                throw new RuntimeException(customTemplateField.getFieldName() + "超出长度");
            }
        } else if (fieldType.equals(CustomFieldTypeEnums.DATE.getType())) {
            com.alibaba.fastjson.JSONObject valObject = propObject.getJSONObject("val");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(valObject.getString(FieldConstant.NUM_FORMAT));
            try {
                simpleDateFormat.parse(value);
            } catch (ParseException e) {
                throw new RuntimeException(customTemplateField.getFieldName() + "时间格式错误");
            }
        } else if (fieldType.equals(CustomFieldTypeEnums.SELECT.getType())) {
            if (Func.isEmpty(customTemplateField)) {
                throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在");
            }
            Map<String, CustomTemplateFieldOption> transMap = customTemplateField.getOptionList().stream().collect(Collectors.toMap((v0) -> {
                return v0.getValue();
            }, o -> {
                return o;
            }));
            if (transMap.containsKey(value)) {
                result = String.valueOf(transMap.get(value).getId());
            } else {
                throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在");
            }
        } else if (fieldType.equals(CustomFieldTypeEnums.MULTI_SELECT.getType())) {
            if (Func.isEmpty(customTemplateField)) {
                throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在");
            }
            Map<String, CustomTemplateFieldOption> transMap2 =  customTemplateField.getOptionList().stream().collect(Collectors.toMap((v0) -> {
                return v0.getValue();
            }, o2 -> {
                return o2;
            }));
            List<String> optionIds = new ArrayList<>();
            if (value.contains(",")) {
                for (String split2 : value.split(",")) {
                    if (transMap2.containsKey(split2)) {
                        optionIds.add(String.valueOf(transMap2.get(split2).getId()));
                    } else {
                        throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在");
                    }
                }
            } else if (transMap2.containsKey(value)) {
                optionIds.add(String.valueOf(transMap2.get(value).getId()));
            } else {
                throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在");
            }
            result = optionIds;
        } else if (fieldType.equals(CustomFieldTypeEnums.DROP_DOWN.getType())) {
            if (Func.isEmpty(customTemplateField)) {
                throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在");
            }
            Map<String, CustomTemplateFieldOption> transMap3 = customTemplateField.getOptionList().stream().collect(Collectors.toMap((v0) -> {
                return v0.getValue();
            }, o3 -> {
                return o3;
            }));
            if (transMap3.containsKey(value)) {
                result = String.valueOf(transMap3.get(value).getId());
            } else {
                throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在");
            }
        } else if (fieldType.equals(CustomFieldTypeEnums.CASCADE_SELECT.getType())) {
            Boolean flag2 = Boolean.valueOf(!value.contains(",") || value.startsWith(",") || value.endsWith(",") || value.length() < 3);
            if (flag2.booleanValue()) {
                throw new RuntimeException(customTemplateField.getFieldName() + "级联选择器需按逗号分隔填入两个值");
            }
            if (Func.isEmpty(customTemplateField)) {
                throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在");
            }
            List<CustomTemplateFieldOption> customTemplateFieldOptions = customTemplateField.getOptionList();
            Map<String, CustomTemplateFieldOption> parentMap = customTemplateFieldOptions.stream().filter(o4 -> {
                return o4.getParentId().equals(0L);
            }).collect(Collectors.toMap((v0) -> {
                return v0.getValue();
            }, o5 -> {
                return o5;
            }));
            List<String> optionIds2 = new ArrayList<>();
            String[] values = value.split(",");
            if (parentMap.containsKey(values[0])) {
                CustomTemplateFieldOption pCustomTemplateFieldOption = parentMap.get(values[0]);
                optionIds2.add(String.valueOf(pCustomTemplateFieldOption.getId()));
                Map<String, CustomTemplateFieldOption> childMap = customTemplateFieldOptions.stream().filter(o6 -> {
                    return o6.getParentId().equals(pCustomTemplateFieldOption.getId());
                }).collect(Collectors.toMap((v0) -> {
                    return v0.getValue();
                }, o7 -> {
                    return o7;
                }));
                if (childMap.containsKey(values[1])) {
                    optionIds2.add(String.valueOf(childMap.get(values[1]).getId()));
                    result = optionIds2;
                } else {
                    throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在");
                }
            } else {
                throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在");
            }
        } else if (fieldType.equals(CustomFieldTypeEnums.BUSINESS.getType())) {
            Employee employee = this.employeeService.getOne(Wrappers.<Employee>lambdaQuery().eq(Employee::getJobNumber, value));
            /*
            Employee employee = (Employee) this.employeeService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getJobNumber();
            }, value));*/
            if (Func.isEmpty(employee)) {
                throw new RuntimeException(customTemplateField.getFieldName() + "员工不存在");
            }
            HierarchyVO employeeHierarchy = this.employeeService.getEmployeeHierarchy(employee.getId());
            result = StringUtil.join(employeeHierarchy.getIdList(), ",");
        }
        return result;
    }
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    public CustomTemplateField getField(String fieldCode, Integer busType) {
        Object cacheObj = this.bladeRedis.get(FieldConstant.getFieldCacheKey(fieldCode, busType));
        if (Func.isNotEmpty(cacheObj)) {
            return (CustomTemplateField) Convert.convert(CustomTemplateField.class, cacheObj);
        }
        if (Func.isEmpty(fieldCode)) {
            return null;
        }
        CustomTemplateField customTemplateField = getOne(Wrappers.<CustomTemplateField>lambdaQuery().eq(CustomTemplateField::getFieldCode, fieldCode).eq(CustomTemplateField::getBusinessType, busType));
        /*
        CustomTemplateField customTemplateField = (CustomTemplateField) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getFieldCode();
        }, fieldCode)).eq((v0) -> {
            return v0.getBusinessType();
        }, busType));*/
        if (Func.isEmpty(customTemplateField)) {
            customTemplateField = new CustomTemplateField(1);
        }
        if (CUSTOM_FIELD_TYPE_LIST.contains(customTemplateField.getFieldType())) {
            optionFieldHandler(customTemplateField);
            List<CustomTemplateFieldOption> templateFieldOptions = this.customTemplateFieldOptionService.list(Wrappers.<CustomTemplateFieldOption>lambdaQuery().eq(CustomTemplateFieldOption::getFieldId, customTemplateField.getId()));
            /*
            List<CustomTemplateFieldOption> templateFieldOptions = this.customTemplateFieldOptionService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getFieldId();
            }, customTemplateField.getId()));*/
            customTemplateField.setOptionList(templateFieldOptions);
        }
        this.bladeRedis.setEx(FieldConstant.getFieldCacheKey(fieldCode, busType), customTemplateField, FieldConstant.CACHE_TIMEOUT);
        return customTemplateField;
    }
 
    @Override // org.springblade.modules.system.service.ICustomTemplateFieldService
    public List<CustomTemplateFieldColumnVO> getColumns(Long templateId, Integer configType) {
        List<CustomTemplateColumnDTO> result = this.customTemplateFieldMapper.getColumns(templateId, configType);
        editPageMustFieldHandler(result, templateId, configType);
        fieldsOptionBeanToJson(result);
        return CustomTemplateFieldConvert.INSTANCE.convertColumns(result);
    }
 
    private void editPageMustFieldHandler(List<CustomTemplateColumnDTO> result, Long templateId, Integer configType) {
        if (!ConfigTypeEnum.EDIT_PAGE.getCode().equals(configType)) {
            return;
        }
        List<CustomTemplateColumnDTO> addList = this.customTemplateFieldMapper.getColumns(templateId, ConfigTypeEnum.NEW_PAGE.getCode());
        Map<String, CustomTemplateColumnDTO> tempMap = (Map) addList.stream().collect(Collectors.toMap((v0) -> {
            return v0.getFieldCode();
        }, o -> {
            return o;
        }, (o2, n) -> {
            return o2;
        }));
        result.forEach(r -> {
            CustomTemplateColumnDTO customTemplateColumnDTO = (CustomTemplateColumnDTO) tempMap.get(r.getFieldCode());
            if (Func.isEmpty(customTemplateColumnDTO)) {
                return;
            }
            r.setMustField(customTemplateColumnDTO.getMustField());
        });
        System.out.println("---");
    }
 
    private List<CustomTemplateColumnDTO> fieldsOptionBeanToJson(List<CustomTemplateColumnDTO> result) {
        if (Func.isEmpty(result)) {
            return result;
        }
        List<CustomTemplateColumnDTO> optionFields = result.stream().filter(field -> {
            return CUSTOM_FIELD_TYPE_LIST.contains(field.getFieldType());
        }).collect(Collectors.toList());
        if (Func.isEmpty(optionFields)) {
            return result;
        }
        List<Long> ids = optionFields.stream().map((v0) -> {
            return v0.getFieldId();
        }).collect(Collectors.toList());
        List<CustomTemplateFieldOption> templateFieldOptions = this.customTemplateFieldOptionService.list(Wrappers.<CustomTemplateFieldOption>lambdaQuery().in(CustomTemplateFieldOption::getFieldId, ids));
        /*
        List<CustomTemplateFieldOption> templateFieldOptions = this.customTemplateFieldOptionService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getFieldId();
        }, ids));*/
        Map<Long, List<CustomTemplateFieldOption>> optionMap = templateFieldOptions.stream().collect(Collectors.groupingBy((v0) -> {
            return v0.getFieldId();
        }));
        result.forEach(field2 -> {
            List<CustomTemplateFieldOption> customTemplateFieldOptions = optionMap.get(field2.getFieldId());
            if (CollectionUtil.isEmpty(customTemplateFieldOptions)) {
                return;
            }
            field2.setOptionList(customTemplateFieldOptions);
            String fieldJsonHandler = optionFieldBeanToJson(customTemplateFieldOptions, field2.getPropertyJson());
            field2.setPropertyJson(fieldJsonHandler);
        });
        return result;
    }
 
    private String optionFieldBeanToJson(List<CustomTemplateFieldOption> customTemplateFields, String propertyJsonStr) {
        if (Func.isEmpty(customTemplateFields)) {
            return "";
        }
        JSONObject propertyJson = JSONUtil.parseObj(propertyJsonStr);
        List<OptionBean> optionBeanList = parseOptionBeanToJson(customTemplateFields, FieldConstant.PARENT_ID);
        propertyJson.put(FieldConstant.OPTION_NAME, new JSONArray(optionBeanList));
        return propertyJson.toString();
    }
 
    private static List<OptionBean> parseOptionBeanToJson(List<CustomTemplateFieldOption> options, Long parentId) {
        List<OptionBean> result = new ArrayList<>();
        List<CustomTemplateFieldOption> parentOptions = options.stream().filter(o -> {
            return o.getParentId().equals(parentId);
        }).collect(Collectors.toList());
        if (CollectionUtil.isEmpty(parentOptions)) {
            return null;
        }
        parentOptions.forEach(option -> {
            OptionBean optionBean = OptionBean.builder().label(option.getValue()).value(String.valueOf(option.getId())).children(parseOptionBeanToJson(options, option.getId())).build();
            result.add(optionBean);
        });
        return result;
    }
 
    private boolean checkNameIsExist(Long id, String name, Integer businessType) {
        List<CustomTemplateField> result = this.baseMapper.selectList(Wrappers.<CustomTemplateField>query().lambda()
                .eq(Func.isNotEmpty(AuthUtil.getTenantId()), CustomTemplateField::getTenantId, AuthUtil.getTenantId())
                .eq(Func.isNotBlank(name), CustomTemplateField::getFieldName, name)
                .eq(Func.isNotEmpty(businessType), CustomTemplateField::getBusinessType, businessType)
                .ne(Func.isNotEmpty(id), CustomTemplateField::getId, id));
        /*
        List<CustomTemplateField> result = ((CustomTemplateFieldMapper) this.baseMapper).selectList(Wrappers.query().lambda().eq(Func.isNotEmpty(AuthUtil.getTenantId()), (v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId()).eq(Func.isNotBlank(name), (v0) -> {
            return v0.getFieldName();
        }, name).eq(Func.isNotEmpty(businessType), (v0) -> {
            return v0.getBusinessType();
        }, businessType).ne(Func.isNotEmpty(id), (v0) -> {
            return v0.getId();
        }, id));*/
        return result != null && result.size() > 0;
    }
 
    private boolean checkRemove(List<Long> ids) {
        long count = this.customTemplateFieldRelationService.count(Wrappers.<CustomTemplateFieldRelation>lambdaQuery().in(CustomTemplateFieldRelation::getFieldId, ids));
        /*
        long count = this.customTemplateFieldRelationService.count((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getFieldId();
        }, ids));*/
        return count <= 0;
    }
}