CenterLeaderRelationImportService.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.kingdee.eas.custom.attendanceexception.service;
  2. import com.kingdee.bos.Context;
  3. import com.kingdee.bos.metadata.entity.*;
  4. import com.kingdee.eas.custom.attendanceexception.*;
  5. import com.kingdee.eas.framework.CoreBaseInfo;
  6. import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseColumnInfo;
  7. import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseImportService;
  8. import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException;
  9. import com.kingdee.util.StringUtils;
  10. import org.apache.poi.ss.usermodel.Cell;
  11. import org.apache.poi.ss.usermodel.Row;
  12. import org.apache.poi.xssf.usermodel.XSSFSheet;
  13. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  14. import java.util.*;
  15. /**
  16. * @Description 中心负责人关系表导入业务实现类
  17. * @Date 2025/4/15 18:28
  18. * @Created by Heyuan
  19. */
  20. public class CenterLeaderRelationImportService extends BaseImportService {
  21. /**
  22. * 模板下载时携带数据
  23. *
  24. * @param columnInfoMap
  25. * @param wb
  26. * @param sheet
  27. */
  28. @Override
  29. public void completeGenerateExcel(Map<String, BaseColumnInfo> columnInfoMap,
  30. XSSFWorkbook wb,
  31. XSSFSheet sheet) {
  32. Context ctx = this.getContext();
  33. int beginRow = 4;//数据生成开始行数
  34. //隐藏第一列
  35. //sheet.setColumnHidden(0, true);
  36. try {
  37. ICenterLeaderRelation iCenterLeaderRelation = CenterLeaderRelationFactory.getLocalInstance(ctx);
  38. SelectorItemCollection sic = getSelectorItemCollection(columnInfoMap);
  39. SorterItemCollection sortItems = new SorterItemCollection();
  40. sortItems.add(new SorterItemInfo("department.sortCode"));
  41. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(null, sic, sortItems);
  42. //查询中心负责人关系表
  43. CenterLeaderRelationCollection relationCollection = iCenterLeaderRelation.getCenterLeaderRelationCollection(entityViewInfo);
  44. //获取字段
  45. Map<Integer, String> columnIndexMap = this.getColumnIndexFn(columnInfoMap);
  46. int fillColumnCount = columnInfoMap.size();
  47. for (int j = 0; j < relationCollection.size(); j++) {
  48. Row row = sheet.createRow(beginRow++);
  49. //中心负责人关系表
  50. CenterLeaderRelationInfo relationInfo = relationCollection.get(j);
  51. //分录
  52. CenterLeaderRelationEntryCollection entrys = relationInfo.getEntry();
  53. for (int k = 0; k < fillColumnCount; ++k) {
  54. Object obj = null;
  55. Cell createCell = row.createCell(k);
  56. String columnName = columnIndexMap.get(k);
  57. String value = null;
  58. if (columnName.startsWith("person")) {
  59. String num = columnName.replace("person", "");
  60. if (!StringUtils.isEmpty(num)) {
  61. Integer index = Integer.valueOf(num);
  62. if (index > entrys.size()) {
  63. value = "";
  64. } else {
  65. CenterLeaderRelationEntryInfo entryInfo = entrys.get(index - 1);
  66. obj = entryInfo.getPerson();
  67. }
  68. } else {
  69. continue;
  70. }
  71. } else {
  72. obj = relationInfo.get(columnName);
  73. }
  74. if (obj != null) {
  75. if (obj instanceof CoreBaseInfo) {
  76. CoreBaseInfo coreBaseInfo = (CoreBaseInfo) obj;
  77. value = coreBaseInfo.get("number") + "##" + coreBaseInfo.get("name");
  78. } else {
  79. value = obj.toString();
  80. }
  81. }
  82. createCell.setCellValue(value);
  83. }
  84. }
  85. } catch (Exception e) {
  86. if (e.getMessage().contains("fetched too much rows")) {
  87. throw new ImportException("查询的数据量超出限制!请联系系统管理员修改配置,或者减少下载的数据量。");
  88. } else {
  89. e.printStackTrace();
  90. throw new ImportException(e.getMessage());
  91. }
  92. }
  93. }
  94. /**
  95. * 将列对象数据转化成Map集合
  96. *
  97. * @param columnInfoMap
  98. * @return
  99. */
  100. protected Map<Integer, String> getColumnIndexFn(Map<String, BaseColumnInfo> columnInfoMap) {
  101. Map<Integer, String> columnIndexMap = new HashMap();
  102. Iterator<String> keys = columnInfoMap.keySet().iterator();
  103. int var4 = 0;
  104. while (keys.hasNext()) {
  105. String key = keys.next();
  106. columnIndexMap.put(var4++, key);
  107. }
  108. return columnIndexMap;
  109. }
  110. /**
  111. *
  112. *
  113. * @param columnInfoMap
  114. * @return
  115. */
  116. protected SelectorItemCollection getSelectorItemCollection(Map<String, BaseColumnInfo> columnInfoMap) {
  117. SelectorItemCollection sic = new SelectorItemCollection();
  118. for (String key : columnInfoMap.keySet()) {
  119. BaseColumnInfo columnInfo = columnInfoMap.get(key);
  120. if (!columnInfo.isCustomField() && !columnInfo.isDynamicColumn()) {
  121. String supplierEntityName = columnInfo.getSupplierEntityName();
  122. if (DataType.OBJECTVALUE.equals(columnInfo.getPropDataType())
  123. || !StringUtils.isEmpty(supplierEntityName)) {
  124. sic.add(key + ".*");
  125. } else {
  126. sic.add(key);
  127. }
  128. }
  129. }
  130. sic.add("Entry.person.number");
  131. sic.add("Entry.person.name");
  132. return sic;
  133. }
  134. }