ExpandAssessKHRImportService.java 9.7 KB

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