ExpandAssessEntryTapeDataImportService.java 7.4 KB

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