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
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
package jnpf.base.service.impl;
 
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import jnpf.base.ActionResult;
import jnpf.base.entity.*;
import jnpf.base.mapper.*;
import jnpf.base.model.module.*;
import jnpf.base.service.DbLinkService;
import jnpf.base.service.ModuleService;
import jnpf.base.service.SuperServiceImpl;
import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil;
import jnpf.constant.CodeConst;
import jnpf.constant.FileTypeConstant;
import jnpf.constant.JnpfConst;
import jnpf.constant.MsgCode;
import jnpf.database.util.DbTypeUtil;
import jnpf.database.util.TenantDataSourceUtil;
import jnpf.emnus.ModuleTypeEnum;
import jnpf.exception.DataException;
import jnpf.file.FileApi;
import jnpf.model.ExportModel;
import jnpf.model.tenant.TenantAuthorizeModel;
import jnpf.permission.util.CodeNumUtil;
import jnpf.util.*;
import jnpf.util.context.RequestContext;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 系统功能
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月27日 上午9:18
 */
@Service
public class ModuleServiceImpl extends SuperServiceImpl<ModuleMapper, ModuleEntity> implements ModuleService {
    @Autowired
    private FileApi fileExport;
    @Autowired
    private ConfigValueUtil configValueUtil;
    @Autowired
    private DbLinkService dbLinkService;
 
    @Autowired
    private ModuleDataAuthorizeMapper moduleDataAuthorizeMapper;
    @Autowired
    private ModuleButtonMapper buttonMapper;
    @Autowired
    private ModuleColumnMapper columnMapper;
    @Autowired
    private ModuleFormMapper formMapper;
    @Autowired
    private ModuleDataAuthorizeSchemeMapper schemeMapper;
    @Autowired
    private ModuleDataAuthorizeMapper authorizeMapper;
    @Autowired
    private SystemMapper systemMapper;
    @Autowired
    private ModuleDataMapper moduleDataMapper;
 
    @Override
    public List<ModuleEntity> getList(MenuListModel param) {
        String appCode = param.getAppCode();
        SystemEntity systemEntity = systemMapper.getInfoByEnCode(param.getAppCode());
        String systemId = systemEntity.getId();
        // 定义变量判断是否需要使用修改时间倒序
        boolean flag = false;
        QueryWrapper<ModuleEntity> queryWrapper = new QueryWrapper<>();
        if (JnpfConst.MAIN_SYSTEM_CODE.equals(appCode) && param.isRelease()) {
            queryWrapper.lambda().eq(ModuleEntity::getCategory, JnpfConst.WEB);
            queryWrapper.lambda().eq(ModuleEntity::getSystemId, systemId);
            queryWrapper.lambda().select(ModuleEntity::getId);
            List<String> workModuleIds = this.list(queryWrapper).stream().map(ModuleEntity::getId).collect(Collectors.toList());
            // 重新定义一个查询对象
            queryWrapper = new QueryWrapper<>();
            if (!workModuleIds.isEmpty()) {
                queryWrapper.lambda().notIn(ModuleEntity::getId, workModuleIds);
            }
        }
        // 如果是主系统且不是管理员菜单需要去分级里面获取
 
        List<String> collect = new ArrayList<>();
        // 根据系统id获取功能
        if (!"0".equals(systemId)) {
            collect = param.getModuleList().stream().filter(t -> t.getSystemId().equals(systemId)).map(ModuleModel::getId).collect(Collectors.toList());
        } else {
            collect = param.getModuleList().stream().map(ModuleModel::getId).distinct().collect(Collectors.toList());
        }
        collect.add("");
        List<List<String>> lists = Lists.partition(collect, 1000);
        queryWrapper.lambda().and(t -> {
            for (List<String> list : lists) {
                t.in(ModuleEntity::getId, list).or();
            }
        });
        if (!StringUtil.isEmpty(param.getCategory())) {
            queryWrapper.lambda().eq(ModuleEntity::getCategory, param.getCategory());
        }
        if (!StringUtil.isEmpty(param.getKeyword())) {
            flag = true;
            queryWrapper.lambda().and(t -> t.like(ModuleEntity::getFullName, param.getKeyword())
                    .or().like(ModuleEntity::getEnCode, param.getKeyword())
                    .or().like(ModuleEntity::getUrlAddress, param.getKeyword())
            );
        }
        if (param.getType() != null) {
            flag = true;
            queryWrapper.lambda().eq(ModuleEntity::getType, param.getType());
        }
        if (param.getEnabledMark() != null) {
            flag = true;
            queryWrapper.lambda().eq(ModuleEntity::getEnabledMark, param.getEnabledMark());
        }
        if (StringUtil.isNotEmpty(param.getParentId())) {
            queryWrapper.lambda().eq(ModuleEntity::getParentId, param.getParentId());
        }
        queryWrapper.lambda().orderByAsc(ModuleEntity::getSortCode)
                .orderByDesc(ModuleEntity::getCreatorTime);
        if (flag) {
            queryWrapper.lambda().orderByDesc(ModuleEntity::getLastModifyTime);
        }
        // 移除工作流程菜单
        List<String> moduleCode = new ArrayList<>();
        moduleCode.addAll(JnpfConst.MODULE_CODE);
        moduleCode.addAll(JnpfConst.TEAMWORK_MODULE);
        queryWrapper.lambda().notIn(ModuleEntity::getEnCode, moduleCode);
        return this.list(queryWrapper);
    }
 
    @DSTransactional
    @Override
    public void create(ModuleEntity entity) {
        this.setAutoEnCode(entity);
        this.baseMapper.create(entity);
    }
 
    @Override
    public boolean update(String id, ModuleEntity entity) {
        entity.setId(id);
        this.setAutoEnCode(entity);
        entity.setLastModifyTime(DateUtil.getNowDate());
        return this.updateById(entity);
    }
 
    @DSTransactional
    @Override
    public void delete(ModuleEntity entity) {
        this.removeById(entity.getId());
        buttonMapper.deleteByModuleId(entity.getId());
        QueryWrapper<ModuleColumnEntity> columnWrapper = new QueryWrapper<>();
        columnWrapper.lambda().eq(ModuleColumnEntity::getModuleId, entity.getId());
        columnMapper.deleteByModuleId(entity.getId());
        QueryWrapper<ModuleDataAuthorizeEntity> dataWrapper = new QueryWrapper<>();
        dataWrapper.lambda().eq(ModuleDataAuthorizeEntity::getModuleId, entity.getId());
        moduleDataAuthorizeMapper.deleteByModuleId(entity.getId());
        QueryWrapper<ModuleFormEntity> formWrapper = new QueryWrapper<>();
        formWrapper.lambda().eq(ModuleFormEntity::getModuleId, entity.getId());
        formMapper.deleteByModuleId(entity.getId());
        QueryWrapper<ModuleDataAuthorizeSchemeEntity> schemeWrapper = new QueryWrapper<>();
        schemeWrapper.lambda().eq(ModuleDataAuthorizeSchemeEntity::getModuleId, entity.getId());
        schemeMapper.deleteByModuleId(entity.getId());
        QueryWrapper<ModuleDataEntity> moduleDataWrapper = new QueryWrapper<>();
        moduleDataWrapper.lambda().eq(ModuleDataEntity::getModuleId, entity.getId());
        moduleDataMapper.deleteByModuleId(entity.getId());
    }
 
    @Override
    public ModuleEntity getInfo(String id) {
        return this.baseMapper.getInfo(id);
    }
 
    @Override
    public List<ModuleEntity> getList(boolean filterFlowWork, List<String> moduleAuthorize, List<String> moduleUrlAddressAuthorize) {
        return this.baseMapper.getList(filterFlowWork, moduleAuthorize, moduleUrlAddressAuthorize);
    }
 
    @Override
    public List<ModuleEntity> getList() {
        return this.baseMapper.getList();
    }
 
    @Override
    public List<ModuleEntity> getListTenant() {
        String urlAddress = null;
        try {
            if (!DbTypeUtil.checkOracle(dbLinkService.getResource("0"))) {
                urlAddress = "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this.baseMapper.getListTenant(urlAddress);
    }
 
    @Override
    public List<ModuleEntity> getListByParentId(String id) {
        return this.baseMapper.getListByParentId(id);
    }
 
    @Override
    public ModuleEntity getInfo(String id, String systemId) {
        return this.baseMapper.getInfo(id, systemId);
    }
 
    @Override
    public ModuleEntity getInfo(String id, String systemId, String parentId) {
        return this.baseMapper.getInfo(id, systemId, parentId);
    }
 
    @Override
    public boolean isExistByFullName(ModuleEntity entity, String category, String systemId) {
        return this.baseMapper.isExistByFullName(entity, category, systemId);
    }
 
    @Override
    public boolean isExistByEnCode(ModuleEntity entity, String category, String systemId) {
        return this.baseMapper.isExistByEnCode(entity, category, systemId);
    }
 
    @Override
    public boolean isExistByAddress(ModuleEntity entity, String category, String systemId) {
        return this.baseMapper.isExistByAddress(entity, category, systemId);
    }
 
    @Override
    public void deleteBySystemId(String systemId) {
        this.baseMapper.deleteBySystemId(systemId);
    }
 
    @Override
    public DownloadVO exportData(String id) {
        //获取信息转model
        ModuleEntity moduleEntity = getInfo(id);
        List<ModuleButtonEntity> buttonServiceList = buttonMapper.getListByModuleIds(id);
        List<ModuleColumnEntity> columnServiceList = columnMapper.getList(id);
        List<ModuleDataAuthorizeSchemeEntity> schemeServiceList = schemeMapper.getList(id);
        List<ModuleDataAuthorizeEntity> authorizeServiceList = authorizeMapper.getList(id);
        List<ModuleFormEntity> formList = formMapper.getList(id);
        ModuleExportModel exportModel = new ModuleExportModel();
        exportModel.setModuleEntity(moduleEntity);
        exportModel.setButtonEntityList(buttonServiceList);
        exportModel.setColumnEntityList(columnServiceList);
        exportModel.setFormEntityList(formList);
        exportModel.setSchemeEntityList(schemeServiceList);
        exportModel.setAuthorizeEntityList(authorizeServiceList);
        //导出文件
        DownloadVO downloadVO = fileExport.exportFile(new ExportModel(exportModel, FileTypeConstant.TEMPORARY, UserProvider.getUser().getId(), moduleEntity.getFullName(), ModuleTypeEnum.SYSTEM_MODULE.getTableName()));
        return downloadVO;
    }
 
    @Override
    @DSTransactional
    public ActionResult importData(ModuleExportModel exportModel, Integer type) throws DataException {
        try {
            boolean isAdd = ObjectUtil.equal(type, 1);
            StringBuilder message = new StringBuilder();
            ModuleEntity moduleEntity = exportModel.getModuleEntity();
            StringJoiner stringJoiner = new StringJoiner("、");
            if (getInfo(moduleEntity.getId()) != null) {
                stringJoiner.add("ID");
            }
            String id = moduleEntity.getId();
            moduleEntity.setId(null);
            if (isExistByEnCode(moduleEntity, moduleEntity.getCategory(), moduleEntity.getSystemId())) {
                stringJoiner.add("编码");
            }
            if (isExistByFullName(moduleEntity, moduleEntity.getCategory(), moduleEntity.getSystemId())) {
                stringJoiner.add("名称");
            }
            if (isExistByAddress(moduleEntity, moduleEntity.getCategory(), moduleEntity.getSystemId())) {
                stringJoiner.add("路由地址");
            }
            moduleEntity.setId(id);
            if (stringJoiner.length() > 0) {
                if (isAdd) {
                    String copyNum = UUID.randomUUID().toString().substring(0, 5);
                    moduleEntity.setFullName(moduleEntity.getFullName() + ".副本" + copyNum);
                    moduleEntity.setEnCode(moduleEntity.getEnCode() + copyNum);
                    moduleEntity.setId(RandomUtil.uuId());
                    this.setIgnoreLogicDelete().removeById(moduleEntity);
                    this.setIgnoreLogicDelete().saveOrUpdate(moduleEntity);
                }
            } else {
                this.setIgnoreLogicDelete().removeById(moduleEntity);
                this.setIgnoreLogicDelete().saveOrUpdate(moduleEntity);
            }
            if (stringJoiner.length() > 0) {
                message.append(stringJoiner.toString()).append("重复;");
            }
            StringJoiner exceptionMessage = new StringJoiner("、");
            StringJoiner IDMessage = new StringJoiner("、");
            StringJoiner fullNameMessage = new StringJoiner("、");
            StringJoiner enCodeMessage = new StringJoiner("、");
            //按钮
            List<ModuleButtonEntity> buttonEntityList = JsonUtil.getJsonToList(exportModel.getButtonEntityList(), ModuleButtonEntity.class);
            //新ID映射
            Map<String, String> idConvert = new HashMap<>(buttonEntityList.size(), 1);
            if (isAdd) {
                buttonEntityList.forEach(button -> idConvert.put(button.getId(), RandomUtil.uuId()));
            }
            for (ModuleButtonEntity buttonEntity : buttonEntityList) {
                if (buttonMapper.getInfo(buttonEntity.getId()) != null) {
                    IDMessage.add(buttonEntity.getId());
                }
                if (buttonMapper.isExistByFullName(moduleEntity.getId(), buttonEntity.getFullName(), null)) {
                    fullNameMessage.add(buttonEntity.getFullName());
                }
                if (buttonMapper.isExistByEnCode(moduleEntity.getId(), buttonEntity.getEnCode(), null)) {
                    enCodeMessage.add(buttonEntity.getEnCode());
                }
                if (isAdd) {
                    buttonEntity.setId(idConvert.get(buttonEntity.getId()));
                    buttonEntity.setModuleId(moduleEntity.getId());
                    if (idConvert.containsKey(buttonEntity.getParentId())) {
                        buttonEntity.setParentId(idConvert.get(buttonEntity.getParentId()));
                    }
                    if (fullNameMessage.length() > 0 || enCodeMessage.length() > 0) {
                        String copyNum = UUID.randomUUID().toString().substring(0, 5);
                        buttonEntity.setFullName(buttonEntity.getFullName() + ".副本" + copyNum);
                        buttonEntity.setEnCode(buttonEntity.getEnCode() + copyNum);
                    }
                    buttonMapper.setIgnoreLogicDelete().insertOrUpdate(buttonEntity);
                } else if (IDMessage.length() == 0 && fullNameMessage.length() == 0 && enCodeMessage.length() == 0) {
                    buttonMapper.setIgnoreLogicDelete().deleteById(buttonEntity);
                    buttonEntity.setModuleId(moduleEntity.getId());
                    buttonMapper.setIgnoreLogicDelete().insertOrUpdate(buttonEntity);
                }
            }
            tmpMessage("buttonEntityList:", message, exceptionMessage, IDMessage, fullNameMessage, enCodeMessage);
            //列表
            List<ModuleColumnEntity> columnEntityList = JsonUtil.getJsonToList(exportModel.getColumnEntityList(), ModuleColumnEntity.class);
            for (ModuleColumnEntity columnEntity : columnEntityList) {
                if (columnMapper.getInfo(columnEntity.getId()) != null) {
                    IDMessage.add(columnEntity.getId());
                }
                if (columnMapper.isExistByFullName(moduleEntity.getId(), columnEntity.getFullName(), null)) {
                    fullNameMessage.add(columnEntity.getFullName());
                }
                if (columnMapper.isExistByEnCode(moduleEntity.getId(), columnEntity.getEnCode(), null)) {
                    enCodeMessage.add(columnEntity.getEnCode());
                }
                if (isAdd) {
                    columnEntity.setId(RandomUtil.uuId());
                    columnEntity.setModuleId(moduleEntity.getId());
                    if (fullNameMessage.length() > 0 || enCodeMessage.length() > 0) {
                        String copyNum = UUID.randomUUID().toString().substring(0, 5);
                        columnEntity.setFullName(columnEntity.getFullName() + ".副本" + copyNum);
                        columnEntity.setEnCode(columnEntity.getEnCode() + copyNum);
                    }
                    columnMapper.setIgnoreLogicDelete().insertOrUpdate(columnEntity);
                } else if (IDMessage.length() == 0 && fullNameMessage.length() == 0 && enCodeMessage.length() == 0) {
                    columnMapper.setIgnoreLogicDelete().deleteById(columnEntity);
                    columnEntity.setModuleId(moduleEntity.getId());
                    columnMapper.setIgnoreLogicDelete().insertOrUpdate(columnEntity);
                }
            }
            tmpMessage("columnEntityList:", message, exceptionMessage, IDMessage, fullNameMessage, enCodeMessage);
            //表单
            List<ModuleFormEntity> formEntityList = JsonUtil.getJsonToList(exportModel.getFormEntityList(), ModuleFormEntity.class);
            for (ModuleFormEntity formEntity : formEntityList) {
                if (formMapper.getInfo(formEntity.getId()) != null) {
                    IDMessage.add(formEntity.getId());
                }
                if (formMapper.isExistByFullName(moduleEntity.getId(), formEntity.getFullName(), null)) {
                    fullNameMessage.add(formEntity.getFullName());
                }
                if (formMapper.isExistByEnCode(moduleEntity.getId(), formEntity.getEnCode(), null)) {
                    enCodeMessage.add(formEntity.getEnCode());
                }
                if (isAdd) {
                    formEntity.setId(RandomUtil.uuId());
                    formEntity.setModuleId(moduleEntity.getId());
                    if (fullNameMessage.length() > 0 || enCodeMessage.length() > 0) {
                        String copyNum = UUID.randomUUID().toString().substring(0, 5);
                        formEntity.setFullName(formEntity.getFullName() + ".副本" + copyNum);
                        formEntity.setEnCode(formEntity.getEnCode() + copyNum);
                    }
                    formMapper.setIgnoreLogicDelete().insertOrUpdate(formEntity);
                } else if (IDMessage.length() == 0 && fullNameMessage.length() == 0 && enCodeMessage.length() == 0) {
                    formMapper.setIgnoreLogicDelete().deleteById(formEntity);
                    formEntity.setModuleId(moduleEntity.getId());
                    formMapper.setIgnoreLogicDelete().insertOrUpdate(formEntity);
                }
            }
            tmpMessage("formEntityList:", message, exceptionMessage, IDMessage, fullNameMessage, enCodeMessage);
            //数据权限
            Map<String, String> authorizeId = new HashMap<>(16);
            List<ModuleDataAuthorizeEntity> authorizeEntityList = JsonUtil.getJsonToList(exportModel.getAuthorizeEntityList(), ModuleDataAuthorizeEntity.class);
            for (ModuleDataAuthorizeEntity authorizeEntity : authorizeEntityList) {
                if (authorizeMapper.getInfo(authorizeEntity.getId()) != null) {
                    IDMessage.add(authorizeEntity.getId());
                }
                if (authorizeMapper.isExistByFullName(moduleEntity.getId(), authorizeEntity.getFullName(), null)) {
                    fullNameMessage.add(authorizeEntity.getFullName());
                }
                if (authorizeMapper.isExistByEnCode(moduleEntity.getId(), authorizeEntity.getEnCode(), null)) {
                    enCodeMessage.add(authorizeEntity.getEnCode());
                }
                if (isAdd) {
                    authorizeEntity.setId(RandomUtil.uuId());
                    authorizeEntity.setModuleId(moduleEntity.getId());
                    if (fullNameMessage.length() > 0 || enCodeMessage.length() > 0) {
                        String copyNum = UUID.randomUUID().toString().substring(0, 5);
                        authorizeEntity.setFullName(authorizeEntity.getFullName() + ".副本" + copyNum);
                        authorizeEntity.setEnCode(authorizeEntity.getEnCode() + copyNum);
                    }
                    authorizeMapper.setIgnoreLogicDelete().insertOrUpdate(authorizeEntity);
                    authorizeId.put(authorizeEntity.getId(), authorizeEntity.getId());
                } else if (IDMessage.length() == 0 && fullNameMessage.length() == 0 && enCodeMessage.length() == 0) {
                    authorizeMapper.setIgnoreLogicDelete().deleteById(authorizeEntity);
                    authorizeEntity.setModuleId(moduleEntity.getId());
                    authorizeMapper.setIgnoreLogicDelete().insertOrUpdate(authorizeEntity);
                }
            }
            tmpMessage("authorizeEntityList:", message, exceptionMessage, IDMessage, fullNameMessage, enCodeMessage);
            //数据权限方案
            List<ModuleDataAuthorizeSchemeEntity> schemeEntityList = JsonUtil.getJsonToList(exportModel.getSchemeEntityList(), ModuleDataAuthorizeSchemeEntity.class);
            for (ModuleDataAuthorizeSchemeEntity schemeEntity : schemeEntityList) {
                if (schemeMapper.getInfo(schemeEntity.getId()) != null) {
                    IDMessage.add(schemeEntity.getId());
                }
                if (schemeMapper.isExistByFullName(null, schemeEntity.getFullName(), moduleEntity.getId())) {
                    fullNameMessage.add(schemeEntity.getFullName());
                }
                if (schemeMapper.isExistByEnCode(null, schemeEntity.getEnCode(), moduleEntity.getId())) {
                    enCodeMessage.add(schemeEntity.getEnCode());
                }
                if (isAdd) {
                    schemeEntity.setId(RandomUtil.uuId());
                    schemeEntity.setModuleId(moduleEntity.getId());
                    String conditionJson = schemeEntity.getConditionJson();
                    if (StringUtil.isNotEmpty(conditionJson)) {
                        for (String oldId : authorizeId.keySet()) {
                            conditionJson = conditionJson.replaceAll(oldId, authorizeId.get(oldId));
                        }
                    }
                    if (fullNameMessage.length() > 0 || enCodeMessage.length() > 0) {
                        String copyNum = UUID.randomUUID().toString().substring(0, 5);
                        schemeEntity.setFullName(schemeEntity.getFullName() + ".副本" + copyNum);
                        schemeEntity.setEnCode(schemeEntity.getEnCode() + copyNum);
                    }
                    schemeMapper.setIgnoreLogicDelete().insertOrUpdate(schemeEntity);
                } else if (IDMessage.length() == 0 && fullNameMessage.length() == 0 && enCodeMessage.length() == 0) {
                    schemeMapper.setIgnoreLogicDelete().deleteById(schemeEntity);
                    schemeEntity.setModuleId(moduleEntity.getId());
                    schemeMapper.setIgnoreLogicDelete().insertOrUpdate(schemeEntity);
                }
            }
            tmpMessage("schemeEntityList:", message, exceptionMessage, IDMessage, fullNameMessage, enCodeMessage);
            if (ObjectUtil.equal(type, 0) && message.length() > 0) {
                return ActionResult.fail(message.toString().substring(0, message.lastIndexOf(";")));
            }
            return ActionResult.success(MsgCode.IMP001.get());
        } catch (Exception e) {
            e.printStackTrace();
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new DataException(e.getMessage());
        } finally {
            this.clearIgnoreLogicDelete();
            buttonMapper.clearIgnoreLogicDelete();
            columnMapper.clearIgnoreLogicDelete();
            formMapper.clearIgnoreLogicDelete();
            authorizeMapper.clearIgnoreLogicDelete();
            schemeMapper.clearIgnoreLogicDelete();
        }
    }
 
    private void tmpMessage(String moduleType, StringBuilder message, StringJoiner exceptionMessage, StringJoiner IDMessage, StringJoiner fullNameMessage, StringJoiner enCodeMessage) {
        if (IDMessage.length() > 0) {
            exceptionMessage.add("ID(" + IDMessage.toString() + ")重复");
        }
        if (enCodeMessage.length() > 0) {
            exceptionMessage.add("编码(" + enCodeMessage.toString() + ")重复");
        }
        if (fullNameMessage.length() > 0) {
            exceptionMessage.add("名称(" + fullNameMessage.toString() + ")重复");
        }
        if (exceptionMessage.length() > 0) {
            message.append(moduleType + exceptionMessage.toString()).append(";");
            exceptionMessage = new StringJoiner("、");
            IDMessage = new StringJoiner("、");
            fullNameMessage = new StringJoiner("、");
            enCodeMessage = new StringJoiner("、");
        }
    }
 
    @Override
    @DSTransactional
    public List<ModuleEntity> getModuleList(String visualId) {
        return this.baseMapper.getModuleList(visualId);
    }
 
    @Override
    public List<ModuleEntity> getModuleBySystemIds(List<String> ids, List<String> moduleAuthorize, List<String> moduleUrlAddressAuthorize, Integer type) {
        return this.baseMapper.getModuleBySystemIds(ids, moduleAuthorize, moduleUrlAddressAuthorize, type);
    }
 
    @Override
    public List<ModuleEntity> getModuleByIds(List<String> ids) {
        return this.baseMapper.getModuleByIds(ids);
    }
 
    @Override
    public List<ModuleEntity> getListByEnCode(List<String> enCodeList) {
        return this.baseMapper.getListByEnCode(enCodeList);
    }
 
    @Override
    public List<ModuleEntity> findModuleAdmin(int mark, String id, List<String> moduleAuthorize, List<String> moduleUrlAddressAuthorize) {
        return this.baseMapper.findModuleAdmin(mark, id, moduleAuthorize, moduleUrlAddressAuthorize);
    }
 
    @Override
    public void getParentModule(List<ModuleEntity> data, Map<String, ModuleEntity> moduleEntityMap) {
        data.forEach(t -> {
            ModuleEntity moduleEntity = t;
            while (moduleEntity != null) {
                if (!moduleEntityMap.containsKey(moduleEntity.getId())) {
                    moduleEntityMap.put(moduleEntity.getId(), moduleEntity);
                }
                moduleEntity = this.getInfo(moduleEntity.getParentId());
            }
        });
    }
 
    @Override
    public List<ModuleEntity> getListByUrlAddress(List<String> ids, List<String> urlAddressList) {
        return this.baseMapper.getListByUrlAddress(ids, urlAddressList);
    }
 
    @Override
    public ModuleNameVO getModuleNameList(String visualId) {
        Map<String, SystemEntity> sysMap = systemMapper.getList().stream().collect(Collectors.toMap(SystemEntity::getId, t -> t));
        ModuleNameVO moduleNameVO = new ModuleNameVO();
        List<ModuleEntity> moduleList = this.getModuleList(visualId);
        QueryWrapper<ModuleEntity> moduleWrapper = new QueryWrapper<>();
//        moduleWrapper.s(ModuleEntity::getId,ModuleEntity::getParentId,ModuleEntity::getSystemId,ModuleEntity::getFullName);
        List<ModuleEntity> listAll = this.list(moduleWrapper);
        if (moduleList.size() > 0) {
            List<ModuleEntity> pcList = moduleList.stream().filter(module -> "web".equalsIgnoreCase(module.getCategory())).collect(Collectors.toList());
            List<ModuleEntity> appList = moduleList.stream().filter(module -> "app".equalsIgnoreCase(module.getCategory())).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(pcList)) {
                moduleNameVO.setPcIds(pcList.stream().map(ModuleEntity::getId).collect(Collectors.toList()));
                StringJoiner joiner = new StringJoiner(";");
                for (ModuleEntity moduleEntity : pcList) {
                    List<String> aa = new ArrayList<>();
                    getName(moduleEntity.getId(), listAll, aa, sysMap);
                    Collections.reverse(aa);
                    joiner.add(aa.stream().collect(Collectors.joining("/")));
                    moduleNameVO.setPcNames(joiner.toString());
                }
            }
            if (CollectionUtils.isNotEmpty(appList)) {
                moduleNameVO.setAppIds(appList.stream().map(ModuleEntity::getId).collect(Collectors.toList()));
                StringJoiner joiner = new StringJoiner(";");
                for (ModuleEntity moduleEntity : appList) {
                    List<String> aa = new ArrayList<>();
                    getName(moduleEntity.getId(), listAll, aa, sysMap);
                    Collections.reverse(aa);
                    joiner.add(aa.stream().collect(Collectors.joining("/")));
                    moduleNameVO.setAppNames(joiner.toString());
                }
            }
        }
        return moduleNameVO;
    }
 
    private void getName(String id, List<ModuleEntity> listAll, List<String> str, Map<String, SystemEntity> sysMap) {
        for (ModuleEntity item : listAll) {
            if (item.getId().equals(id)) {
                str.add(item.getFullName());
                if (StringUtil.isNotEmpty(item.getParentId())) {
                    if (Objects.equals("-1", item.getParentId())) {
                        SystemEntity info = sysMap.get(item.getSystemId());
                        if (info != null) {
                            str.add(info.getFullName());
                        }
                    } else {
                        getName(item.getParentId(), listAll, str, sysMap);
                    }
                }
            }
        }
    }
 
    @Override
    public List<ModuleSelectorVo> getFormMenuList(ModulePagination pagination) {
        return this.baseMapper.getFormMenuList(pagination);
    }
 
    /**
     * 获取应用菜单列表
     *
     * @return
     */
    @Override
    public List<MenuSelectAllVO> getSystemMenu(Integer type, List<Integer> webType, List<String> categorys) {
        List<String> moduleAuthorize = new ArrayList<>();
        List<String> moduleUrlAddressAuthorize = new ArrayList<>();
        if (configValueUtil.isMultiTenancy()) {
            TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
            moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
            moduleUrlAddressAuthorize = tenantAuthorizeModel.getUrlAddressList();
        }
        SystemEntity infoByEnCode = systemMapper.getInfoByEnCode(RequestContext.getAppCode());
        List<ModuleEntity> menuList = this.getList(false, moduleAuthorize, moduleUrlAddressAuthorize)
                .stream().filter(t -> Objects.equals(infoByEnCode.getId(), t.getSystemId())).collect(Collectors.toList());
 
        List<MenuSelectAllVO> menuvo = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(menuList)) {
            for (ModuleEntity item : menuList) {
                String propertyJson = item.getPropertyJson();
                PropertyJsonModel pjm = JsonUtil.getJsonToBean(propertyJson, PropertyJsonModel.class);
                if (Objects.equals(type, item.getType()) && webType.contains(pjm.getWebType())
                        && categorys.contains(item.getCategory().toLowerCase())) {
                    menuvo.add(JsonUtil.getJsonToBean(item, MenuSelectAllVO.class));
                }
            }
        }
        return menuvo;
    }
 
    @Override
    public List<ModuleSelectorVo> getPageList(ModulePagination pagination) {
        return this.baseMapper.getPageList(pagination);
    }
 
    @Override
    public void setAutoEnCode(ModuleEntity entity) {
        String codePre = "";
        SystemEntity info = systemMapper.getInfo(entity.getSystemId());
        if (info != null && JnpfConst.MAIN_SYSTEM_CODE.equals(info.getEnCode())) {
            codePre = CodeConst.XTCD;
        } else {
            codePre = CodeConst.YYCD;
        }
        // 自动生成编码
        if (StringUtil.isEmpty(entity.getEnCode())) {
            final String codePreF = codePre;
            entity.setEnCode(CodeNumUtil.getCodeFunction(codePreF, code -> {
                entity.setEnCode(code);
                return this.isExistByEnCode(entity, entity.getCategory(), entity.getSystemId());
            }));
        }
    }
}