ExpandAssessEntryTapeDataImportService.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.kingdee.eas.custom.expandassess.service;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.metadata.entity.*;
  5. import com.kingdee.eas.common.EASBizException;
  6. import com.kingdee.eas.custom.expandassess.*;
  7. import com.kingdee.eas.custom.expandassess.app.AssessRatingEnum;
  8. import com.kingdee.eas.custom.expandassess.app.ExpandStatusEunm;
  9. import com.kingdee.eas.custom.performancenew.app.scoreEnum;
  10. import com.kingdee.eas.framework.CoreBaseInfo;
  11. import com.kingdee.eas.util.app.ContextUtil;
  12. import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseColumnInfo;
  13. import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseImportService;
  14. import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseRowInfo;
  15. import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException;
  16. import com.kingdee.shr.ml.util.SHRServerResource;
  17. import com.kingdee.util.StringUtils;
  18. import org.apache.poi.ss.usermodel.Cell;
  19. import org.apache.poi.xssf.usermodel.XSSFRow;
  20. import org.apache.poi.xssf.usermodel.XSSFSheet;
  21. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  22. import java.math.BigDecimal;
  23. import java.util.HashMap;
  24. import java.util.Iterator;
  25. import java.util.Map;
  26. /**
  27. * @author qingwu
  28. * @date 2024/5/17
  29. * @apiNote 拓展人员考核 专员修改模板导入
  30. */
  31. public class ExpandAssessEntryTapeDataImportService extends BaseImportService {
  32. private static final SelectorItemCollection SIC = new SelectorItemCollection();
  33. static {
  34. SIC.add("adminorg.name");
  35. SIC.add("assessor.name");
  36. SIC.add("principal.name");
  37. SIC.add("threshold");
  38. SIC.add("target");
  39. SIC.add("challenge");
  40. SIC.add("checkRate");
  41. SIC.add("remark");
  42. }
  43. @Override
  44. protected void submitData(CoreBaseInfo coreBaseInfo) throws ImportException {
  45. try {
  46. IExpandAssessEntry iExpandAssessEntry = ExpandAssessEntryFactory.getLocalInstance(getContext());
  47. ExpandAssessEntryInfo expandAssessEntryInfo = (ExpandAssessEntryInfo) coreBaseInfo;
  48. ExpandStatusEunm asseStatus = expandAssessEntryInfo.getAsseStatus();
  49. SelectorItemCollection updateSic = getUpdateSic(asseStatus);
  50. iExpandAssessEntry.updatePartial(coreBaseInfo, updateSic);
  51. } catch (EASBizException var4) {
  52. ImportException importException = new ImportException(var4.getMessage(getContext().getLocale()), (Throwable) var4);
  53. throw importException;
  54. } catch (BOSException var5) {
  55. ImportException importException = new ImportException(SHRServerResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "save_fails_bos", getContext()), (Throwable) var5);
  56. throw importException;
  57. } catch (Exception var6) {
  58. ImportException importException = new ImportException(SHRServerResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "save_submit_fails", getContext()), var6);
  59. throw importException;
  60. }
  61. }
  62. /**
  63. * 模板生成完成后执行内容
  64. *
  65. * @param columnInfoMap
  66. * @param wb
  67. * @param sheet
  68. */
  69. @Override
  70. public void completeGenerateExcel(Map<String, BaseColumnInfo> columnInfoMap, XSSFWorkbook wb, XSSFSheet sheet) {
  71. Context ctx = getContext();
  72. String parentId = getCustomParam("parentId");
  73. if (StringUtils.isEmpty(parentId)) {
  74. throw new RuntimeException("拓展人员考核周期ID不可为空!!");
  75. }
  76. int beginRow = 4;
  77. try {
  78. //当前登录员工id
  79. String currentPersonId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  80. //过滤当前周期状态为已启用排序评分人等于登录人的数据
  81. FilterInfo filterInfo = new FilterInfo();
  82. FilterItemCollection filterItems = filterInfo.getFilterItems();
  83. filterItems.add(new FilterItemInfo("parent.id", parentId));
  84. //SorterItemCollection sorterItemCollection = new SorterItemCollection();
  85. //sorterItemCollection.add(new SorterItemInfo("rankings"));
  86. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, SIC, null);
  87. IExpandAssessEntry iExpandAssessEntry = ExpandAssessEntryFactory.getLocalInstance(getContext());
  88. //绩效考核分录实体
  89. ExpandAssessEntryCollection entryCollection = iExpandAssessEntry.getExpandAssessEntryCollection(entityViewInfo);
  90. Map<Integer, String> columnIndexMap = getColumnIndexFn(columnInfoMap);
  91. int fillColumnCount = columnInfoMap.size();
  92. for (int i = 0; i < entryCollection.size(); i++) {
  93. XSSFRow xSSFRow = sheet.createRow(i + beginRow);
  94. ExpandAssessEntryInfo expandAssessEntryInfo = entryCollection.get(i);
  95. for (int j = 0; j < fillColumnCount; j++) {
  96. String value = null;
  97. Cell createCell = xSSFRow.createCell(j);
  98. String columnName = columnIndexMap.get(Integer.valueOf(j));
  99. Object obj = expandAssessEntryInfo.get(columnName);
  100. if (obj != null) {
  101. if (obj instanceof CoreBaseInfo) {
  102. CoreBaseInfo coreBaseInfo = (CoreBaseInfo) expandAssessEntryInfo.get(columnName);
  103. //value = coreBaseInfo.get("number") + "##" + coreBaseInfo.get("name");
  104. value = (String) coreBaseInfo.get("name");
  105. } else if (obj instanceof BigDecimal) {
  106. BigDecimal bigDecimal = (BigDecimal) obj;
  107. value = bigDecimal.setScale(2).toPlainString();
  108. } else {
  109. if ("checkRate".equals(columnName)) {
  110. value = AssessRatingEnum.getEnum((String) obj).getAlias();
  111. } else {
  112. value = obj.toString();
  113. }
  114. }
  115. }
  116. createCell.setCellValue(value);
  117. }
  118. }
  119. } catch (BOSException e) {
  120. e.printStackTrace();
  121. throw new RuntimeException(e);
  122. }
  123. }
  124. protected Map<Integer, String> getColumnIndexFn(Map<String, BaseColumnInfo> columnInfoMap) {
  125. Map<Integer, String> columnIndexMap = new HashMap<>();
  126. Iterator<String> keys = columnInfoMap.keySet().iterator();
  127. int var4 = 0;
  128. while (keys.hasNext()) {
  129. String key = keys.next();
  130. columnIndexMap.put(Integer.valueOf(var4++), key);
  131. }
  132. return columnIndexMap;
  133. }
  134. @Override
  135. protected String getPKSelectString(BaseRowInfo row) {
  136. String pkSelectString = super.getPKSelectString(row);
  137. String parentId = getCustomParam("parentId");
  138. if (StringUtils.isEmpty(parentId)) {
  139. throw new RuntimeException("拓展人员考核周期ID不可为空!!");
  140. }
  141. return pkSelectString + " and parent.id ='" + parentId + "'";
  142. }
  143. public SelectorItemCollection getUpdateSic(ExpandStatusEunm asseStatus) {
  144. SelectorItemCollection updateSic = new SelectorItemCollection();
  145. updateSic.add("remark");
  146. updateSic.add("checkRate");
  147. if (asseStatus == ExpandStatusEunm.UNSTART) {
  148. updateSic.add("assessor");
  149. updateSic.add("adminOrg");
  150. updateSic.add("threshold");
  151. updateSic.add("target");
  152. updateSic.add("challenge");
  153. updateSic.add("principal");
  154. }
  155. return updateSic;
  156. }
  157. }