浏览代码

feat(wtc): 新增加班单假期校验逻辑

- 新增假期基础资料 nckd_holidayforot 的定义与使用
- 实现加班单提交时判断是否在假期范围内
- 增加假期范围内加班天数超限逻辑处理
- 按条件自动切换休息日或节假日加班类型
- 提供获取假期、加班天数及加班类型的工具方法
Tyx 1 天之前
父节点
当前提交
cc9d59923b

+ 95 - 0
code/base/nckd-jxccl-base-helper/src/main/java/nckd/jxccl/base/wtc/helper/WTCHelper.java

@@ -0,0 +1,95 @@
+package nckd.jxccl.base.wtc.helper;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
+import nckd.jxccl.base.common.constant.FormConstant;
+import nckd.jxccl.base.orm.helper.QFilterCommonHelper;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Tyx 2025-11-28
+ * 考勤帮助类
+ */
+public class WTCHelper {
+
+    private static final Log logger = LogFactory.getLog(WTCHelper.class);
+    public static final HRBaseServiceHelper HOLIDAYFOROT_HELPER = new HRBaseServiceHelper("nckd_holidayforot");
+    public static final HRBaseServiceHelper OTBILL_HELPER = new HRBaseServiceHelper("wtom_overtimeapplybill");
+    public static final HRBaseServiceHelper OTTYPE_HELPER = new HRBaseServiceHelper("wtbd_ottype");
+    /**
+     * 根据组织ID列表获取关键岗位信息
+     * @param orgIds 组织ID列表
+     * @return
+     */
+    public static List<Long> getKeyPositionByOrg (List<Long> orgIds) {
+        QFilter filter = new QFilter("nckd_iskeypos", QCP.equals, "1");
+        filter.and(QFilterCommonHelper.getCurrentVersionFilter());
+        filter.and("adminorg.id", QCP.in, orgIds);
+        HRBaseServiceHelper helper = new HRBaseServiceHelper(FormConstant.HBPM_POSITIONHR);
+        DynamicObjectCollection positions = helper.queryOriginalCollection("id", filter.toArray());
+        return positions.stream().map(position -> position.getLong("id")).collect(Collectors.toList());
+    }
+
+    /**
+     * 根据考勤档案ID获取二级单位编码
+     * @param attFileId
+     */
+    public static String getSecondOrgNumberByAttFileId (Long attFileId) {
+        QFilter filter = new QFilter ("id", QCP.equals, attFileId);
+        String selectFields = "adminorg.nckd_secondorg.number";
+        return null;
+    }
+
+    /**
+     * 根据加班归属日期获取假期
+     *
+     * @return
+     */
+    public static DynamicObject getHolidayByOtDutyDate (Date otDutyDate) {
+        QFilter filter = new QFilter("nckd_startdate", QCP.less_equals, otDutyDate);
+        filter.and("nckd_enddate", QCP.large_equals, otDutyDate);
+        DynamicObject dyn = HOLIDAYFOROT_HELPER.queryOriginalOne("name, nckd_startdate, nckd_enddate, nckd_holidays", filter.toArray());
+        return dyn;
+    }
+
+    /**
+     * 根据起止日期+考勤档案+排除ID获取加班日期的天数
+     * 如果加班单为yyyy-MM-dd 18:00:00 至 yyyy-MM-dd 19:00:00,不管实际加班小时,计作一天
+     *
+     * @param startDate
+     * @param endDate
+     * @param attfileId
+     * @param billId
+     * @return
+     */
+    public static int getOTDays(Date startDate, Date endDate, Long attfileId, Long billId) {
+        QFilter filter = new QFilter("attfile.id", QCP.equals, attfileId);
+        filter.and("id", QCP.not_equals, billId);
+        filter.and("sdentry.otdutydate", QCP.large_equals, startDate);
+        filter.and("sdentry.otdutydate", QCP.less_equals, endDate);
+        DynamicObjectCollection cols = OTBILL_HELPER.queryOriginalCollection("id,sdentry.otdutydate", filter.toArray());
+        Set<Date> dateSet = cols.stream().map(dyn -> dyn.getDate("sdentry.otdutydate")).collect(Collectors.toSet());
+        return dateSet.size();
+    }
+
+    /**
+     * 获取加班类型
+     * @param number 加班类型编码
+     * @return
+     */
+    public static DynamicObject getSdOtType (String number) {
+        QFilter filter = new QFilter("number", QCP.equals, number);
+        return OTTYPE_HELPER.loadOne(filter.toArray());
+    }
+
+
+}

+ 4 - 2
code/wtc/nckd-jxccl-wtc/src/main/java/nckd/jxccl/wtc/wtabm/web/common/constant/WtcConstant.java

@@ -44,14 +44,16 @@ public class WtcConstant {
 
     /* 考勤项目-旷工天数编码*/
     public static final String ABSENT_NUMBER = "EX_1140_S";
-
     /* 打卡记录 */
     public static final HRBaseServiceHelper PUNCHCARDDATA_HELPER = new HRBaseServiceHelper("wtis_punchcarddata");
     /* 调度作业 */
     public static final HRBaseServiceHelper JOB_HELPER = new HRBaseServiceHelper("sch_job");
     /* 运行日志 */
     public static final HRBaseServiceHelper TASK_HELPER = new HRBaseServiceHelper("sch_task");
-
     /* 考勤档案 */
     public static final HRBaseServiceHelper ATTFILEBASE_HELPER = new HRBaseServiceHelper("wtp_attfilebase");
+    /* 假期(二开基础资料-加班使用) */
+    public static final HRBaseServiceHelper HOLIDAYFOROT_HELPER = new HRBaseServiceHelper("nckd_holidayforot");
+    /* 加班类型-休息日加班 */
+    public static String OTTYPE_1020S = "1020_S";
 }

+ 63 - 0
code/wtc/nckd-jxccl-wtc/src/main/java/nckd/jxccl/wtc/wtom/opplugin/web/otapplybill/OtApplyCheckHolidayOp.java

@@ -0,0 +1,63 @@
+package nckd.jxccl.wtc.wtom.opplugin.web.otapplybill;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.PreparePropertysEventArgs;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.sdk.plugin.Plugin;
+import nckd.jxccl.base.wtc.helper.WTCHelper;
+import nckd.jxccl.wtc.wtabm.web.common.constant.WtcConstant;
+
+import java.util.Date;
+
+/**
+ * Tyx 2025-12-02 <br/>
+ * 加班单校验假期操作插件 <br/>
+ * 1、新建假期基础资料 nckd_holidayforot <br/>
+ * 2、加班单提交判断是否在假期范围内 <br/>
+ * 3、如果是则判断假期范围内的加班天数是否超过节假日天数,如果超过,则按休息日加班提交,否则按节假日加班提交 <br/>
+ */
+public class OtApplyCheckHolidayOp extends AbstractOperationServicePlugIn implements Plugin {
+
+    @Override
+    public void onPreparePropertys(PreparePropertysEventArgs e) {
+        super.onPreparePropertys(e);
+    }
+
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+        super.beginOperationTransaction(e);
+        DynamicObject[] bills = e.getDataEntities();
+        for(DynamicObject bill : bills) {
+            // 考勤档案
+            DynamicObject attFile = bill.getDynamicObject("attfile");
+            // 单据ID
+            Long billId = bill.getLong("id");
+            // 分录
+            DynamicObjectCollection entryCols = bill.getDynamicObjectCollection("sdentry");
+            for(DynamicObject entry : entryCols) {
+                // 加班归属日期
+                Date otDutyDate = entry.getDate("otdutydate");
+                DynamicObject holidayDyn = WTCHelper.getHolidayByOtDutyDate(otDutyDate);
+                if(holidayDyn == null)
+                    continue;
+                // 如果查询到在假期范围内,则查询假期范围内总共请了多少天,排除本张加班单
+                Date startDate = holidayDyn.getDate("nckd_startdate");
+                Date endDate = holidayDyn.getDate("nckd_enddate");
+                // 已加班天数
+                int otDays = WTCHelper.getOTDays(startDate, endDate, attFile.getLong("id"), billId);
+                // 当前单据加班天数
+                int curOtDays = 1;
+                // 如果已加班天数 + 当前单据加班天数 > 假期天数,则按休息日加班提交,否则按节假日加班提交
+                if(otDays + curOtDays > holidayDyn.getInt("nckd_holidays")) {
+                    DynamicObject otType = WTCHelper.getSdOtType(WtcConstant.OTTYPE_1020S);
+                    entry.set("sdottype", otType);
+                }
+                else {
+
+                }
+            }
+        }
+    }
+}