|
@@ -0,0 +1,120 @@
|
|
|
|
|
+package nckd.jxccl.opmc.pm.task;
|
|
|
|
|
+
|
|
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
|
+import kd.bos.exception.KDException;
|
|
|
|
|
+import kd.bos.logging.Log;
|
|
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
|
+import kd.bos.schedule.executor.AbstractTask;
|
|
|
|
|
+import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
|
|
+import kd.sdk.plugin.Plugin;
|
|
|
|
|
+import nckd.jxccl.base.common.constant.FormConstant;
|
|
|
|
|
+import nckd.jxccl.base.common.utils.ConvertUtil;
|
|
|
|
|
+import nckd.jxccl.base.common.utils.DateUtil;
|
|
|
|
|
+import nckd.jxccl.base.common.utils.QueryFieldBuilder;
|
|
|
|
|
+import nckd.jxccl.base.orm.helper.QFilterCommonHelper;
|
|
|
|
|
+import nckd.jxccl.opmc.pm.common.PerfManagerFormConstant;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 每月一号根据获取前两月的晋升数据,生成新的三年考评周期
|
|
|
|
|
+ * @author W.Y.C
|
|
|
|
|
+ * @date 2025/11/26 21:51
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ */
|
|
|
|
|
+public class PromotionCycleGeneratorTask extends AbstractTask implements Plugin {
|
|
|
|
|
+
|
|
|
|
|
+ private static final Log logger = LogFactory.getLog(PromotionCycleGeneratorTask.class);
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
|
|
|
|
+ //hdm_transferapply
|
|
|
|
|
+
|
|
|
|
|
+ //先查询由调动单生成的考核周期
|
|
|
|
|
+ QueryFieldBuilder perfManagerQueryFieldBuilder = QueryFieldBuilder.create()
|
|
|
|
|
+ .add(FormConstant.SOURCEDATA);
|
|
|
|
|
+ QFilter perfManagerFilter = new QFilter(FormConstant.SOURCEDATA, QCP.is_notnull, null)
|
|
|
|
|
+ //只查询数据来源:调动(晋升)
|
|
|
|
|
+ .and(FormConstant.INITDATASOURCE,QCP.equals,"3");
|
|
|
|
|
+ DynamicObjectCollection perfManagerQuery = QueryServiceHelper.query(PerfManagerFormConstant.PERFMANAGER_ENTITYID, perfManagerQueryFieldBuilder.buildSelect(), new QFilter[]{perfManagerFilter});
|
|
|
|
|
+ List<Long> sourcedataList = perfManagerQuery.stream()
|
|
|
|
|
+ .map(obj -> obj.getLong(FormConstant.SOURCEDATA))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ //查询N月前的所有调动单
|
|
|
|
|
+ QueryFieldBuilder transferApplyQueryFieldBuilder = QueryFieldBuilder.create()
|
|
|
|
|
+ //调出岗位
|
|
|
|
|
+ .addIdNumberName("bb_po_position")
|
|
|
|
|
+ .addIdNumberName("bb_po_position","nckd_mgtlvldtl")
|
|
|
|
|
+ //调入岗位
|
|
|
|
|
+ .addIdNumberName("aposition")
|
|
|
|
|
+ .addIdNumberName("aposition","nckd_mgtlvldtl")
|
|
|
|
|
+ //调动人员
|
|
|
|
|
+ .addIdNumberName("bb_em_tid");
|
|
|
|
|
+
|
|
|
|
|
+ Integer month = ConvertUtil.toInt(map.get("month"));
|
|
|
|
|
+ LocalDateTime now = DateUtil.now();
|
|
|
|
|
+ // 计算基准日期:N个月前(例如当前11月,N=2,则基准日期为9月)
|
|
|
|
|
+ LocalDateTime monthsAgo = now.minusMonths(month);
|
|
|
|
|
+ // 设置查询时间范围:
|
|
|
|
|
+ // 开始时间:基准日期往前推6个月的第一天(9月往前推6个月=3月,取3月1日)
|
|
|
|
|
+ // 结束时间:基准日期所在月的第一天(9月,取9月1日)
|
|
|
|
|
+ // 目的:查询近6+N个月范围内的调动数据,确保每次查询不是全表查询。每次限制6个月范围的数据
|
|
|
|
|
+ LocalDateTime startDate = DateUtil.beginOfMonth(DateUtil.minusMonths(monthsAgo,6));
|
|
|
|
|
+ LocalDateTime endDate = DateUtil.beginOfMonth(monthsAgo);
|
|
|
|
|
+ QFilter transferApplyFilter = QFilterCommonHelper.getBillStatusFilter()
|
|
|
|
|
+ .and("b_effectivedate", QCP.large_equals, DateUtil.toDate(startDate))
|
|
|
|
|
+ .and("b_effectivedate", QCP.less_equals, DateUtil.toDate(endDate))
|
|
|
|
|
+ .and(FormConstant.ID_KEY, QCP.not_in, sourcedataList);
|
|
|
|
|
+ DynamicObjectCollection transferApplyFilterQuery = QueryServiceHelper.query(FormConstant.HDM_TRANSFERAPPLY, transferApplyQueryFieldBuilder.buildSelect(), new QFilter[]{transferApplyFilter});
|
|
|
|
|
+
|
|
|
|
|
+ //查询管理层级细项(由于管理层级细项的排序号在第三级,只能再查一次)
|
|
|
|
|
+ List<Long> mgtLvldtlIdList = new ArrayList<>();
|
|
|
|
|
+ for (DynamicObject transferApply : transferApplyFilterQuery) {
|
|
|
|
|
+ mgtLvldtlIdList.add(transferApply.getLong(String.join(".", "bb_po_position", "nckd_mgtlvldtl", FormConstant.ID_KEY)));
|
|
|
|
|
+ mgtLvldtlIdList.add(transferApply.getLong(String.join(".", "aposition", "nckd_mgtlvldtl", FormConstant.ID_KEY)));
|
|
|
|
|
+ }
|
|
|
|
|
+ DynamicObjectCollection mgtlvldtlQuery = QueryServiceHelper.query("nckd_hbss_mgtlvldtl",
|
|
|
|
|
+ QueryFieldBuilder.create().add(FormConstant.ID_KEY).add(FormConstant.NAME_KEY).add(FormConstant.NUMBER_KEY).add(FormConstant.NCKD_SORTNUM).buildSelect() ,
|
|
|
|
|
+ new QFilter[]{QFilterCommonHelper.getIdInFilter(mgtLvldtlIdList)});
|
|
|
|
|
+ Map<Long, DynamicObject> mgtLvldtlMap = mgtlvldtlQuery.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ obj -> obj.getLong(FormConstant.ID_KEY),
|
|
|
|
|
+ obj -> obj
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ for (DynamicObject transferApply : transferApplyFilterQuery) {
|
|
|
|
|
+ //调出岗位管理层级细项
|
|
|
|
|
+ String outPositionName = transferApply.getString(String.join(".", "bb_po_position", "nckd_mgtlvldtl", FormConstant.NAME_KEY));
|
|
|
|
|
+ long outMgtLvldtlId = transferApply.getLong(String.join(".", "bb_po_position", "nckd_mgtlvldtl", FormConstant.ID_KEY));
|
|
|
|
|
+ DynamicObject outMgtLvldtl = mgtLvldtlMap.get(outMgtLvldtlId);
|
|
|
|
|
+ int outIndex = -1;
|
|
|
|
|
+ if(outMgtLvldtl != null){
|
|
|
|
|
+ outIndex = outMgtLvldtl.getInt(FormConstant.NCKD_SORTNUM);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ logger.warn("调出岗位【{}】管理层级细项不存在,跳过此条处理:", outPositionName);
|
|
|
|
|
+ }
|
|
|
|
|
+ //调入岗位管理层级细项
|
|
|
|
|
+ String inPositionName = transferApply.getString(String.join(".", "aposition", "nckd_mgtlvldtl", FormConstant.NAME_KEY));
|
|
|
|
|
+ long inMgtLvldtlId = transferApply.getLong(String.join(".", "aposition", "nckd_mgtlvldtl", FormConstant.ID_KEY));
|
|
|
|
|
+ DynamicObject inMgtLvldtl = mgtLvldtlMap.get(inMgtLvldtlId);
|
|
|
|
|
+ int inIndex = -1;
|
|
|
|
|
+ if(outMgtLvldtl != null){
|
|
|
|
|
+ inIndex = inMgtLvldtl.getInt(FormConstant.NCKD_SORTNUM);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ logger.warn("调入岗位【{}】管理层级细项不存在,跳过此条处理:", inPositionName);
|
|
|
|
|
+ }
|
|
|
|
|
+// if()
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+}
|