|
|
@@ -24,6 +24,7 @@ import com.sundot.airport.system.mapper.SysUserMapper;
|
|
24
|
24
|
import com.sundot.airport.system.mapper.SysPostMapper;
|
|
25
|
25
|
import com.sundot.airport.system.mapper.BasePositionMapper;
|
|
26
|
26
|
import org.apache.poi.ss.usermodel.*;
|
|
|
27
|
+import cn.hutool.core.bean.BeanUtil;
|
|
27
|
28
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
28
|
29
|
import org.springframework.stereotype.Service;
|
|
29
|
30
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
@@ -559,6 +560,32 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
559
|
560
|
o.setCreateBy(username);
|
|
560
|
561
|
list.add(o);
|
|
561
|
562
|
}
|
|
|
563
|
+
|
|
|
564
|
+ // 如果被测试人员字段包含多个名称,拆分成多条记录
|
|
|
565
|
+ list = splitRowsByMultiName(
|
|
|
566
|
+ list,
|
|
|
567
|
+ LedgerSecurityTest::getTestedName,
|
|
|
568
|
+ LedgerSecurityTest::setTestedName,
|
|
|
569
|
+ obj -> copyObject(obj, LedgerSecurityTest.class)
|
|
|
570
|
+ );
|
|
|
571
|
+
|
|
|
572
|
+ // 重新为拆分后的记录填充组织信息和ID
|
|
|
573
|
+ for (LedgerSecurityTest o : list) {
|
|
|
574
|
+ String testedName = o.getTestedName();
|
|
|
575
|
+ if (testedName != null && !testedName.trim().isEmpty()) {
|
|
|
576
|
+ Map<String, Object> orgInfo = resolveOrgInfoByNameWithCache(testedName);
|
|
|
577
|
+ if (!orgInfo.isEmpty()) {
|
|
|
578
|
+ o.setTestedId((Long) orgInfo.get("userId"));
|
|
|
579
|
+ o.setDeptId((Long) orgInfo.get("deptId"));
|
|
|
580
|
+ o.setDeptName((String) orgInfo.get("deptName"));
|
|
|
581
|
+ o.setTeamId((Long) orgInfo.get("teamId"));
|
|
|
582
|
+ o.setTeamName((String) orgInfo.get("teamName"));
|
|
|
583
|
+ o.setGroupId((Long) orgInfo.get("groupId"));
|
|
|
584
|
+ o.setGroupName((String) orgInfo.get("groupName"));
|
|
|
585
|
+ }
|
|
|
586
|
+ }
|
|
|
587
|
+ }
|
|
|
588
|
+
|
|
562
|
589
|
securityTestService.batchInsert(list);
|
|
563
|
590
|
return list.size();
|
|
564
|
591
|
}
|
|
|
@@ -1531,4 +1558,93 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
1531
|
1558
|
private void clearImportCache() {
|
|
1532
|
1559
|
this.importCache = null;
|
|
1533
|
1560
|
}
|
|
|
1561
|
+
|
|
|
1562
|
+ // ════════════════════════════════════════════════════════════════
|
|
|
1563
|
+ // 通用工具方法:根据多名称字段拆分数据行
|
|
|
1564
|
+ // ════════════════════════════════════════════════════════════════
|
|
|
1565
|
+
|
|
|
1566
|
+ /**
|
|
|
1567
|
+ * 根据名称字段拆分数据行
|
|
|
1568
|
+ * 如果名称字段包含多个人员(用逗号、顿号、分号等分隔),则将一条数据拆分成多条
|
|
|
1569
|
+ *
|
|
|
1570
|
+ * @param nameField 名称字段的值
|
|
|
1571
|
+ * @return 拆分后的名称列表
|
|
|
1572
|
+ */
|
|
|
1573
|
+ private List<String> splitNames(String nameField) {
|
|
|
1574
|
+ if (nameField == null || nameField.trim().isEmpty()) {
|
|
|
1575
|
+ return Collections.singletonList(nameField);
|
|
|
1576
|
+ }
|
|
|
1577
|
+
|
|
|
1578
|
+ String trimmed = nameField.trim();
|
|
|
1579
|
+
|
|
|
1580
|
+ // 支持的分隔符:中文逗号、英文逗号、中文顿号、中文分号、英文分号、竖线
|
|
|
1581
|
+ String[] names = trimmed.split("[,,、;;|]");
|
|
|
1582
|
+
|
|
|
1583
|
+ List<String> result = new ArrayList<>();
|
|
|
1584
|
+ for (String name : names) {
|
|
|
1585
|
+ String trimmedName = name.trim();
|
|
|
1586
|
+ if (!trimmedName.isEmpty()) {
|
|
|
1587
|
+ result.add(trimmedName);
|
|
|
1588
|
+ }
|
|
|
1589
|
+ }
|
|
|
1590
|
+
|
|
|
1591
|
+ // 如果没有拆分出任何名称,返回原始值
|
|
|
1592
|
+ return result.isEmpty() ? Collections.singletonList(trimmed) : result;
|
|
|
1593
|
+ }
|
|
|
1594
|
+
|
|
|
1595
|
+ /**
|
|
|
1596
|
+ * 通用方法:根据指定名称字段拆分对象列表
|
|
|
1597
|
+ * 适用于所有需要根据多名称字段拆分数据的场景
|
|
|
1598
|
+ *
|
|
|
1599
|
+ * @param sourceList 原始对象列表
|
|
|
1600
|
+ * @param nameGetter 获取名称字段的方法引用
|
|
|
1601
|
+ * @param nameSetter 设置名称字段的方法引用
|
|
|
1602
|
+ * @param copier 对象复制器,用于复制对象
|
|
|
1603
|
+ * @param <T> 对象类型
|
|
|
1604
|
+ * @return 拆分后的对象列表
|
|
|
1605
|
+ */
|
|
|
1606
|
+ private <T> List<T> splitRowsByMultiName(
|
|
|
1607
|
+ List<T> sourceList,
|
|
|
1608
|
+ java.util.function.Function<T, String> nameGetter,
|
|
|
1609
|
+ java.util.function.BiConsumer<T, String> nameSetter,
|
|
|
1610
|
+ java.util.function.Function<T, T> copier) {
|
|
|
1611
|
+
|
|
|
1612
|
+ List<T> result = new ArrayList<>();
|
|
|
1613
|
+
|
|
|
1614
|
+ for (T source : sourceList) {
|
|
|
1615
|
+ String nameField = nameGetter.apply(source);
|
|
|
1616
|
+ List<String> names = splitNames(nameField);
|
|
|
1617
|
+
|
|
|
1618
|
+ if (names.size() == 1) {
|
|
|
1619
|
+ // 只有一个名称,直接添加
|
|
|
1620
|
+ result.add(source);
|
|
|
1621
|
+ } else {
|
|
|
1622
|
+ // 多个名称,拆分成多条记录
|
|
|
1623
|
+ for (String name : names) {
|
|
|
1624
|
+ T copy = copier.apply(source);
|
|
|
1625
|
+ nameSetter.accept(copy, name);
|
|
|
1626
|
+ result.add(copy);
|
|
|
1627
|
+ }
|
|
|
1628
|
+ }
|
|
|
1629
|
+ }
|
|
|
1630
|
+
|
|
|
1631
|
+ return result;
|
|
|
1632
|
+ }
|
|
|
1633
|
+
|
|
|
1634
|
+ /**
|
|
|
1635
|
+ * 通用对象复制方法(使用 Hutool BeanUtil)
|
|
|
1636
|
+ * 优势:
|
|
|
1637
|
+ * 1. 支持深拷贝,避免引用问题
|
|
|
1638
|
+ * 2. 自动类型转换,更灵活
|
|
|
1639
|
+ * 3. 性能更好
|
|
|
1640
|
+ * 4. 可以忽略 null 值
|
|
|
1641
|
+ *
|
|
|
1642
|
+ * @param source 源对象
|
|
|
1643
|
+ * @param targetClass 目标对象类型
|
|
|
1644
|
+ * @param <T> 对象类型
|
|
|
1645
|
+ * @return 复制后的新对象
|
|
|
1646
|
+ */
|
|
|
1647
|
+ private <T> T copyObject(T source, Class<T> targetClass) {
|
|
|
1648
|
+ return BeanUtil.toBean(source, targetClass);
|
|
|
1649
|
+ }
|
|
1534
|
1650
|
}
|