ExpandAssessFZRImportService.java 9.5 KB

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