123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- package com.kingdee.eas.hr.perf.service;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.bsf.service.app.IHRMsfService;
- import com.kingdee.bos.ctrl.swing.StringUtils;
- import com.kingdee.bos.metadata.entity.*;
- import com.kingdee.bos.metadata.query.util.CompareType;
- import com.kingdee.eas.basedata.person.IPerson;
- import com.kingdee.eas.basedata.person.PersonCollection;
- import com.kingdee.eas.basedata.person.PersonFactory;
- import com.kingdee.eas.basedata.person.PersonInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.hr.ats.AtsUtil;
- import com.kingdee.eas.hr.perf.utils.PerfEvaObjectBeanUtils;
- import com.kingdee.eas.hr.perf.utils.PerfEvaObjectUtils;
- import com.kingdee.shr.base.syssetting.exception.SHRWebException;
- import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
- import com.kingdee.shr.perfweb.app.base.evalfile.IPerfFile;
- import com.kingdee.shr.perfweb.app.base.evalfile.PerfFileCollection;
- import com.kingdee.shr.perfweb.app.base.evalfile.PerfFileFactory;
- import com.kingdee.shr.perfweb.app.base.evalfile.PerfFileInfo;
- import com.kingdee.shr.perfweb.app.base.evalplan.*;
- import com.kingdee.shr.perfweb.app.exception.SHRPerfWebBizException;
- import org.apache.log4j.Logger;
- import java.time.Year;
- import java.util.*;
- /**
- * @author qingwu
- * @date 2024/12/18
- * @apiNote
- */
- public class PerfEvaluObjectService implements IHRMsfService {
- private static Logger logger =
- Logger.getLogger(PerfEvaluObjectService.class);
- @Override
- public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
- String billId = (String) map.get("billId");
- String day = (String) map.get("day");
- Map result = new HashMap();
- try {
- addPerfEvaObject(context, billId == null ? "" : billId, day == null ? 0 : Integer.parseInt(day));
- } catch (SHRWebException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- //result.put("map", map);
- result.put("code", "200");
- result.put("msg", "操作成功");
- return result;
- }
- /**
- * @param ctx
- * @param employeeNumbers 用工关系编码 多个用逗号隔开
- * @param day
- * @throws BOSException
- * @throws SHRWebException
- * @throws EASBizException
- */
- public void addPerfEvaObject(Context ctx, String employeeNumbers, int day) throws BOSException, SHRWebException {
- //人员
- IPerson iPerson = PersonFactory.getLocalInstance(ctx);
- //考核周期
- IPerfPeriod iPerfPeriod = PerfPeriodFactory.getLocalInstance(ctx);
- if (StringUtils.isEmpty(employeeNumbers)) {
- employeeNumbers = "SY01,QY02,QY03,WB03,PQ03,LS01,SX01,FP01,WB01,QY01";
- }
- Set<String> employeeNumberset = AtsUtil.toSet(employeeNumbers);
- //查询在职的所有人员
- SelectorItemCollection sic = new SelectorItemCollection();
- sic.add("id");
- sic.add("name");
- sic.add("number");
- sic.add("employeeType.id");
- sic.add("employeeType.name");
- sic.add("employeeType.number");
- FilterInfo filterInfo = new FilterInfo();
- FilterItemCollection filterItems = filterInfo.getFilterItems();
- filterItems.add(new FilterItemInfo("employeeType.number", employeeNumberset, CompareType.INCLUDE));
- EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
- PersonCollection personCollection = iPerson.getPersonCollection(entityViewInfo);
- logger.error("personCollection.size--" + personCollection.size());
- Set personSet = new HashSet();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < personCollection.size(); i++) {
- PersonInfo personInfo = personCollection.get(i);
- String personId = personInfo.getId().toString();
- String personName = personInfo.getName();
- personSet.add(personId);
- sb.append(personName).append(",");
- }
- sb = deleteCharAt(sb);
- //绩效考核档案 获取绩效档案id建立员工考核计划
- IPerfFile iPerfFile = PerfFileFactory.getLocalInstance(ctx);
- FilterInfo perfFileFilterInfo = new FilterInfo();
- perfFileFilterInfo.getFilterItems().add(new FilterItemInfo("person", personSet, CompareType.INCLUDE));
- EntityViewInfo perfFileEntityViewInfo = EntityViewInfo.getInstance(perfFileFilterInfo, null, null);
- PerfFileCollection perfFileCollection = iPerfFile.getPerfFileCollection(perfFileEntityViewInfo);
- logger.error("perfFileCollection.size--" + perfFileCollection.size());
- if (perfFileCollection.size() <= 0) {
- throw new ShrWebBizException("[" + sb.toString() + "]这些人员还未生成员工绩效档案,请维护!");
- }
- //员工档案人员
- Set perfFileSet = new HashSet();
- for (int i = 0; i < perfFileCollection.size(); i++) {
- PerfFileInfo perfFileInfo = perfFileCollection.get(i);
- String perfFileId = perfFileInfo.getId().toString();
- perfFileSet.add(perfFileId);
- }
- //获取当前年的考核周期
- int year = Year.now().getValue();
- PerfPeriodInfo perfPeriodInfo = null;
- try {
- perfPeriodInfo = iPerfPeriod.getPerfPeriodInfo("where timePeriod = '" + year + "' and name = '公司年度绩效目标_周期" + year + "年'");
- } catch (EASBizException e) {
- throw new RuntimeException("未查询到公司年度绩效目标_周期" + year + "年考核计划");
- }
- PerfPlanInfo perfPlan = perfPeriodInfo.getPerfPlan();
- String planId = perfPlan.getId().toString();
- String periodId = perfPeriodInfo.getId().toString();
- checkPeriod(periodId);
- String hrOrgUnit = "00000000-0000-0000-0000-000000000000CCE7AED4";
- PerfPlanInfo info = null;
- try {
- info = PerfPlanFactory.getRemoteInstance().getPerfPlanInfo("where id = '" + planId + "'");
- } catch (Exception var10) {
- var10.printStackTrace();
- throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.GETPERFPLANERR)).getMessage());
- }
- //通过考核周期获取评估对象
- IPerfEvaObject iPerfEvaObject = PerfEvaObjectFactory.getLocalInstance(ctx);
- PerfEvaObjectCollection perfEvaObjectCollection = iPerfEvaObject.getPerfEvaObjectCollection("where period = '" + planId + "'");
- //评估对象里面的员工档案ID
- Set perfEvaPerFileSet = new HashSet();
- for (int i = 0; i < perfEvaObjectCollection.size(); i++) {
- PerfEvaObjectInfo perfEvaObjectInfo = perfEvaObjectCollection.get(i);
- PerfFileInfo perfFile = perfEvaObjectInfo.getPerfFile();
- String perfFileId = perfFile.getId().toString();
- perfEvaPerFileSet.add(perfFileId);
- }
- logger.error("perfFileSet--" + perfFileSet);
- logger.error("perfEvaPerFileSet--" + perfEvaPerFileSet);
- //对比去除考核计划已经存在的人员
- perfFileSet.removeAll(perfEvaPerFileSet);
- logger.error("perfFileSet--removeAll--" + perfFileSet);
- //最后需要保存的员工绩效档案ID
- StringJoiner jperfFileJiner = new StringJoiner(",");
- for (Object perfFileId : perfFileSet) {
- jperfFileJiner.add(perfFileId.toString());
- }
- PerfEvaObjectUtils perfEvaObjectUtils = new PerfEvaObjectUtils();
- perfEvaObjectUtils.addFromPerfFile(ctx, jperfFileJiner.toString(), periodId, hrOrgUnit, info);
- }
- public static void checkPeriod(String period) throws SHRWebException {
- if (org.apache.commons.lang.StringUtils.isEmpty(period)) {
- throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.PERFPERIODNOTEXIST)).getMessage());
- } else {
- PerfPeriodInfo info = null;
- try {
- info = PerfPeriodFactory.getRemoteInstance().getPerfPeriodInfo("where id = '" + period + "'");
- } catch (Exception var3) {
- logger.error(var3.toString());
- throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.GETPERIODDATAERR)).getMessage());
- }
- if (info.getEvaPeriodStatus().getValue() == 100) {
- throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.OPERATENOTALLOWEDASPERIODISEND)).getMessage());
- }
- }
- }
- //public void addPerfEvaObject(Context ctx, String billid, int day) throws BOSException, SHRWebException, EASBizException {
- // logger.error("addPerfEvaObject----");
- // StringBuilder perfFiles = new StringBuilder();//考勤档案id
- //
- // // 获取当前日期
- // LocalDate currentDate = LocalDate.now();
- // LocalDate threeDaysBefore = null;
- // if (day != 0) {
- // // 获取当前日期前三天的日期
- // threeDaysBefore = currentDate.minusDays(day);
- // } else {
- // threeDaysBefore = currentDate.minusDays(3);
- // }
- // logger.error("addPerfEvaObject----1");
- //
- // //入职单 获取最近入职人员 通过人员id去查询绩效档案id
- // IEmpEnrollBizBillEntry iEmpEnrollBizBillEntry = EmpEnrollBizBillEntryFactory.getLocalInstance(ctx);
- // SelectorItemCollection sic = new SelectorItemCollection();
- // sic.add("bizDate");
- // sic.add("empname");
- // sic.add("person.id");
- // sic.add("person.number");
- // sic.add("person.name");
- // FilterInfo empEnrollFilterInfo = new FilterInfo();
- // empEnrollFilterInfo.getFilterItems().add(new FilterItemInfo("bizDate", threeDaysBefore.toString(), CompareType.GREATER_EQUALS));
- // EntityViewInfo empEnrollEntityViewInfo = EntityViewInfo.getInstance(empEnrollFilterInfo, null, null);
- // EmpEnrollBizBillEntryCollection empEnrollBizBillEntryCollection = iEmpEnrollBizBillEntry.getEmpEnrollBizBillEntryCollection(empEnrollEntityViewInfo);
- // logger.error("addPerfEvaObject----2");
- // Set set = new HashSet();
- // StringBuilder sb = new StringBuilder();
- // for (int i = 0; i < empEnrollBizBillEntryCollection.size(); i++) {
- // EmpEnrollBizBillEntryInfo empEnrollBizBillEntryInfo = empEnrollBizBillEntryCollection.get(i);
- // String empName = empEnrollBizBillEntryInfo.getEmpName();
- // PersonInfo person = empEnrollBizBillEntryInfo.getPerson();
- // set.add(person.getId());
- // sb.append(empName).append(",");
- // }
- // logger.error("addPerfEvaObject----3");
- // sb = deleteCharAt(sb);
- // //绩效考核档案 获取绩效档案id建立员工考核计划
- // IPerfFile iPerfFile = PerfFileFactory.getLocalInstance(ctx);
- // FilterInfo perfFileFilterInfo = new FilterInfo();
- // perfFileFilterInfo.getFilterItems().add(new FilterItemInfo("person", set, CompareType.INCLUDE));
- // EntityViewInfo perfFileEntityViewInfo = EntityViewInfo.getInstance(perfFileFilterInfo, null, null);
- // PerfFileCollection perfFileCollection = iPerfFile.getPerfFileCollection(perfFileEntityViewInfo);
- // if (perfFileCollection.size() <= 0) {
- // throw new ShrWebBizException("[" + sb.toString() + "]这些人员还未生成员工绩效档案,请维护!");
- // }
- // if (!StringUtils.isEmpty(billid)) {
- // perfFiles.append(billid);
- // } else {
- // for (int i = 0; i < perfFileCollection.size(); i++) {
- // PerfFileInfo perfFileInfo = perfFileCollection.get(i);
- // perfFiles.append(perfFileInfo.getId().toString()).append(",");
- // }
- // perfFiles = deleteCharAt(perfFiles);
- // }
- // //考核周期 下面是执行添加操作
- // IPerfPeriod iPerfPeriod = PerfPeriodFactory.getLocalInstance(ctx);
- // //获取当前年
- // int year = Year.now().getValue();
- // PerfPeriodInfo perfPeriodInfo = iPerfPeriod.getPerfPeriodInfo("where timePeriod = '" + year + "' and name = '公司年度绩效目标_周期" + year + "年'");
- // PerfPlanInfo perfPlan = perfPeriodInfo.getPerfPlan();
- // String planId = perfPlan.getId().toString();
- // String periodId = perfPeriodInfo.getId().toString();
- // String addModel = "0";
- // String hrOrgUnit = "00000000-0000-0000-0000-000000000000CCE7AED4";
- // checkPeriod(periodId);
- // PerfPlanInfo info = null;
- // logger.error("addPerfEvaObject----4");
- // try {
- // info = PerfPlanFactory.getRemoteInstance().getPerfPlanInfo("where id = '" + planId + "'");
- // } catch (Exception var10) {
- // var10.printStackTrace();
- // logger.error(var10.toString());
- // throw new ShrWebBizException((new SHRPerfWebBizException(SHRPerfWebBizException.GETPERFPLANERR)).getMessage());
- // }
- // logger.error("addPerfEvaObject----5" + addModel);
- // if ("0".equals(addModel)) {
- // logger.error("addFromPerfFile----" + info.getId());
- // this.addFromPerfFile(ctx, perfFiles.toString(), periodId, hrOrgUnit, info);
- // }
- //}
- //
- public StringBuilder deleteCharAt(StringBuilder sb) {
- if (sb.length() > 0) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- return sb;
- }
- }
|