PerfEvaluObjectService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. package com.kingdee.eas.hr.perf.service;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  5. import com.kingdee.bos.ctrl.swing.StringUtils;
  6. import com.kingdee.bos.metadata.entity.*;
  7. import com.kingdee.bos.metadata.query.util.CompareType;
  8. import com.kingdee.eas.basedata.person.IPerson;
  9. import com.kingdee.eas.basedata.person.PersonCollection;
  10. import com.kingdee.eas.basedata.person.PersonFactory;
  11. import com.kingdee.eas.basedata.person.PersonInfo;
  12. import com.kingdee.eas.common.EASBizException;
  13. import com.kingdee.eas.hr.ats.AtsUtil;
  14. import com.kingdee.eas.hr.perf.utils.PerfEvaObjectBeanUtils;
  15. import com.kingdee.eas.hr.perf.utils.PerfEvaObjectUtils;
  16. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  17. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  18. import com.kingdee.shr.perfweb.app.base.evalfile.IPerfFile;
  19. import com.kingdee.shr.perfweb.app.base.evalfile.PerfFileCollection;
  20. import com.kingdee.shr.perfweb.app.base.evalfile.PerfFileFactory;
  21. import com.kingdee.shr.perfweb.app.base.evalfile.PerfFileInfo;
  22. import com.kingdee.shr.perfweb.app.base.evalplan.*;
  23. import com.kingdee.shr.perfweb.app.exception.SHRPerfWebBizException;
  24. import org.apache.log4j.Logger;
  25. import java.time.Year;
  26. import java.util.*;
  27. /**
  28. * @author qingwu
  29. * @date 2024/12/18
  30. * @apiNote
  31. */
  32. public class PerfEvaluObjectService implements IHRMsfService {
  33. private static Logger logger =
  34. Logger.getLogger(PerfEvaluObjectService.class);
  35. @Override
  36. public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
  37. String billId = (String) map.get("billId");
  38. String day = (String) map.get("day");
  39. Map result = new HashMap();
  40. try {
  41. addPerfEvaObject(context, billId == null ? "" : billId, day == null ? 0 : Integer.parseInt(day));
  42. } catch (SHRWebException e) {
  43. e.printStackTrace();
  44. throw new RuntimeException(e);
  45. }
  46. //result.put("map", map);
  47. result.put("code", "200");
  48. result.put("msg", "操作成功");
  49. return result;
  50. }
  51. /**
  52. * @param ctx
  53. * @param employeeNumbers 用工关系编码 多个用逗号隔开
  54. * @param day
  55. * @throws BOSException
  56. * @throws SHRWebException
  57. * @throws EASBizException
  58. */
  59. public void addPerfEvaObject(Context ctx, String employeeNumbers, int day) throws BOSException, SHRWebException {
  60. //人员
  61. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  62. //考核周期
  63. IPerfPeriod iPerfPeriod = PerfPeriodFactory.getLocalInstance(ctx);
  64. if (StringUtils.isEmpty(employeeNumbers)) {
  65. employeeNumbers = "SY01,QY02,QY03,WB03,PQ03,LS01,SX01,FP01,WB01,QY01";
  66. }
  67. Set<String> employeeNumberset = AtsUtil.toSet(employeeNumbers);
  68. //查询在职的所有人员
  69. SelectorItemCollection sic = new SelectorItemCollection();
  70. sic.add("id");
  71. sic.add("name");
  72. sic.add("number");
  73. sic.add("employeeType.id");
  74. sic.add("employeeType.name");
  75. sic.add("employeeType.number");
  76. FilterInfo filterInfo = new FilterInfo();
  77. FilterItemCollection filterItems = filterInfo.getFilterItems();
  78. filterItems.add(new FilterItemInfo("employeeType.number", employeeNumberset, CompareType.INCLUDE));
  79. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
  80. PersonCollection personCollection = iPerson.getPersonCollection(entityViewInfo);
  81. logger.error("personCollection.size--" + personCollection.size());
  82. Set personSet = new HashSet();
  83. StringBuilder sb = new StringBuilder();
  84. for (int i = 0; i < personCollection.size(); i++) {
  85. PersonInfo personInfo = personCollection.get(i);
  86. String personId = personInfo.getId().toString();
  87. String personName = personInfo.getName();
  88. personSet.add(personId);
  89. sb.append(personName).append(",");
  90. }
  91. sb = deleteCharAt(sb);
  92. //绩效考核档案 获取绩效档案id建立员工考核计划
  93. IPerfFile iPerfFile = PerfFileFactory.getLocalInstance(ctx);
  94. FilterInfo perfFileFilterInfo = new FilterInfo();
  95. perfFileFilterInfo.getFilterItems().add(new FilterItemInfo("person", personSet, CompareType.INCLUDE));
  96. EntityViewInfo perfFileEntityViewInfo = EntityViewInfo.getInstance(perfFileFilterInfo, null, null);
  97. PerfFileCollection perfFileCollection = iPerfFile.getPerfFileCollection(perfFileEntityViewInfo);
  98. logger.error("perfFileCollection.size--" + perfFileCollection.size());
  99. if (perfFileCollection.size() <= 0) {
  100. throw new ShrWebBizException("[" + sb.toString() + "]这些人员还未生成员工绩效档案,请维护!");
  101. }
  102. //员工档案人员
  103. Set perfFileSet = new HashSet();
  104. for (int i = 0; i < perfFileCollection.size(); i++) {
  105. PerfFileInfo perfFileInfo = perfFileCollection.get(i);
  106. String perfFileId = perfFileInfo.getId().toString();
  107. perfFileSet.add(perfFileId);
  108. }
  109. //获取当前年的考核周期
  110. int year = Year.now().getValue();
  111. PerfPeriodInfo perfPeriodInfo = null;
  112. try {
  113. perfPeriodInfo = iPerfPeriod.getPerfPeriodInfo("where timePeriod = '" + year + "' and name = '公司年度绩效目标_周期" + year + "年'");
  114. } catch (EASBizException e) {
  115. throw new RuntimeException("未查询到公司年度绩效目标_周期" + year + "年考核计划");
  116. }
  117. PerfPlanInfo perfPlan = perfPeriodInfo.getPerfPlan();
  118. String planId = perfPlan.getId().toString();
  119. String periodId = perfPeriodInfo.getId().toString();
  120. checkPeriod(periodId);
  121. String hrOrgUnit = "00000000-0000-0000-0000-000000000000CCE7AED4";
  122. PerfPlanInfo info = null;
  123. try {
  124. info = PerfPlanFactory.getRemoteInstance().getPerfPlanInfo("where id = '" + planId + "'");
  125. } catch (Exception var10) {
  126. var10.printStackTrace();
  127. throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.GETPERFPLANERR)).getMessage());
  128. }
  129. //通过考核周期获取评估对象
  130. IPerfEvaObject iPerfEvaObject = PerfEvaObjectFactory.getLocalInstance(ctx);
  131. PerfEvaObjectCollection perfEvaObjectCollection = iPerfEvaObject.getPerfEvaObjectCollection("where period = '" + planId + "'");
  132. //评估对象里面的员工档案ID
  133. Set perfEvaPerFileSet = new HashSet();
  134. for (int i = 0; i < perfEvaObjectCollection.size(); i++) {
  135. PerfEvaObjectInfo perfEvaObjectInfo = perfEvaObjectCollection.get(i);
  136. PerfFileInfo perfFile = perfEvaObjectInfo.getPerfFile();
  137. String perfFileId = perfFile.getId().toString();
  138. perfEvaPerFileSet.add(perfFileId);
  139. }
  140. logger.error("perfFileSet--" + perfFileSet);
  141. logger.error("perfEvaPerFileSet--" + perfEvaPerFileSet);
  142. //对比去除考核计划已经存在的人员
  143. perfFileSet.removeAll(perfEvaPerFileSet);
  144. logger.error("perfFileSet--removeAll--" + perfFileSet);
  145. //最后需要保存的员工绩效档案ID
  146. StringJoiner jperfFileJiner = new StringJoiner(",");
  147. for (Object perfFileId : perfFileSet) {
  148. jperfFileJiner.add(perfFileId.toString());
  149. }
  150. PerfEvaObjectUtils perfEvaObjectUtils = new PerfEvaObjectUtils();
  151. perfEvaObjectUtils.addFromPerfFile(ctx, jperfFileJiner.toString(), periodId, hrOrgUnit, info);
  152. }
  153. public static void checkPeriod(String period) throws SHRWebException {
  154. if (org.apache.commons.lang.StringUtils.isEmpty(period)) {
  155. throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.PERFPERIODNOTEXIST)).getMessage());
  156. } else {
  157. PerfPeriodInfo info = null;
  158. try {
  159. info = PerfPeriodFactory.getRemoteInstance().getPerfPeriodInfo("where id = '" + period + "'");
  160. } catch (Exception var3) {
  161. logger.error(var3.toString());
  162. throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.GETPERIODDATAERR)).getMessage());
  163. }
  164. if (info.getEvaPeriodStatus().getValue() == 100) {
  165. throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.OPERATENOTALLOWEDASPERIODISEND)).getMessage());
  166. }
  167. }
  168. }
  169. //public void addPerfEvaObject(Context ctx, String billid, int day) throws BOSException, SHRWebException, EASBizException {
  170. // logger.error("addPerfEvaObject----");
  171. // StringBuilder perfFiles = new StringBuilder();//考勤档案id
  172. //
  173. // // 获取当前日期
  174. // LocalDate currentDate = LocalDate.now();
  175. // LocalDate threeDaysBefore = null;
  176. // if (day != 0) {
  177. // // 获取当前日期前三天的日期
  178. // threeDaysBefore = currentDate.minusDays(day);
  179. // } else {
  180. // threeDaysBefore = currentDate.minusDays(3);
  181. // }
  182. // logger.error("addPerfEvaObject----1");
  183. //
  184. // //入职单 获取最近入职人员 通过人员id去查询绩效档案id
  185. // IEmpEnrollBizBillEntry iEmpEnrollBizBillEntry = EmpEnrollBizBillEntryFactory.getLocalInstance(ctx);
  186. // SelectorItemCollection sic = new SelectorItemCollection();
  187. // sic.add("bizDate");
  188. // sic.add("empname");
  189. // sic.add("person.id");
  190. // sic.add("person.number");
  191. // sic.add("person.name");
  192. // FilterInfo empEnrollFilterInfo = new FilterInfo();
  193. // empEnrollFilterInfo.getFilterItems().add(new FilterItemInfo("bizDate", threeDaysBefore.toString(), CompareType.GREATER_EQUALS));
  194. // EntityViewInfo empEnrollEntityViewInfo = EntityViewInfo.getInstance(empEnrollFilterInfo, null, null);
  195. // EmpEnrollBizBillEntryCollection empEnrollBizBillEntryCollection = iEmpEnrollBizBillEntry.getEmpEnrollBizBillEntryCollection(empEnrollEntityViewInfo);
  196. // logger.error("addPerfEvaObject----2");
  197. // Set set = new HashSet();
  198. // StringBuilder sb = new StringBuilder();
  199. // for (int i = 0; i < empEnrollBizBillEntryCollection.size(); i++) {
  200. // EmpEnrollBizBillEntryInfo empEnrollBizBillEntryInfo = empEnrollBizBillEntryCollection.get(i);
  201. // String empName = empEnrollBizBillEntryInfo.getEmpName();
  202. // PersonInfo person = empEnrollBizBillEntryInfo.getPerson();
  203. // set.add(person.getId());
  204. // sb.append(empName).append(",");
  205. // }
  206. // logger.error("addPerfEvaObject----3");
  207. // sb = deleteCharAt(sb);
  208. // //绩效考核档案 获取绩效档案id建立员工考核计划
  209. // IPerfFile iPerfFile = PerfFileFactory.getLocalInstance(ctx);
  210. // FilterInfo perfFileFilterInfo = new FilterInfo();
  211. // perfFileFilterInfo.getFilterItems().add(new FilterItemInfo("person", set, CompareType.INCLUDE));
  212. // EntityViewInfo perfFileEntityViewInfo = EntityViewInfo.getInstance(perfFileFilterInfo, null, null);
  213. // PerfFileCollection perfFileCollection = iPerfFile.getPerfFileCollection(perfFileEntityViewInfo);
  214. // if (perfFileCollection.size() <= 0) {
  215. // throw new ShrWebBizException("[" + sb.toString() + "]这些人员还未生成员工绩效档案,请维护!");
  216. // }
  217. // if (!StringUtils.isEmpty(billid)) {
  218. // perfFiles.append(billid);
  219. // } else {
  220. // for (int i = 0; i < perfFileCollection.size(); i++) {
  221. // PerfFileInfo perfFileInfo = perfFileCollection.get(i);
  222. // perfFiles.append(perfFileInfo.getId().toString()).append(",");
  223. // }
  224. // perfFiles = deleteCharAt(perfFiles);
  225. // }
  226. // //考核周期 下面是执行添加操作
  227. // IPerfPeriod iPerfPeriod = PerfPeriodFactory.getLocalInstance(ctx);
  228. // //获取当前年
  229. // int year = Year.now().getValue();
  230. // PerfPeriodInfo perfPeriodInfo = iPerfPeriod.getPerfPeriodInfo("where timePeriod = '" + year + "' and name = '公司年度绩效目标_周期" + year + "年'");
  231. // PerfPlanInfo perfPlan = perfPeriodInfo.getPerfPlan();
  232. // String planId = perfPlan.getId().toString();
  233. // String periodId = perfPeriodInfo.getId().toString();
  234. // String addModel = "0";
  235. // String hrOrgUnit = "00000000-0000-0000-0000-000000000000CCE7AED4";
  236. // checkPeriod(periodId);
  237. // PerfPlanInfo info = null;
  238. // logger.error("addPerfEvaObject----4");
  239. // try {
  240. // info = PerfPlanFactory.getRemoteInstance().getPerfPlanInfo("where id = '" + planId + "'");
  241. // } catch (Exception var10) {
  242. // var10.printStackTrace();
  243. // logger.error(var10.toString());
  244. // throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.GETPERFPLANERR)).getMessage());
  245. // }
  246. // logger.error("addPerfEvaObject----5" + addModel);
  247. // if ("0".equals(addModel)) {
  248. // logger.error("addFromPerfFile----" + info.getId());
  249. // this.addFromPerfFile(ctx, perfFiles.toString(), periodId, hrOrgUnit, info);
  250. // }
  251. //}
  252. //
  253. public StringBuilder deleteCharAt(StringBuilder sb) {
  254. if (sb.length() > 0) {
  255. sb.deleteCharAt(sb.lastIndexOf(","));
  256. }
  257. return sb;
  258. }
  259. }