ExpandAssessKHRImportService.java 8.9 KB

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