From cee3debf85d3f41e03b1de338e00e8a2f7a92cc3 Mon Sep 17 00:00:00 2001 From: zhangzhiguo Date: Thu, 2 Jan 2025 15:29:05 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E8=81=8C=E5=91=98=E5=87=BA?= =?UTF-8?q?=E5=B7=AE=E5=A4=A9=E6=95=B0=E7=BB=9F=E8=AE=A1=E5=8F=B0=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/form/AutoCalWorkingDaysPlugin.java | 133 ++++++++++++++++++ .../report/EmpTravelRptQueryPlugin.java | 30 ++-- 2 files changed, 145 insertions(+), 18 deletions(-) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AutoCalWorkingDaysPlugin.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AutoCalWorkingDaysPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AutoCalWorkingDaysPlugin.java new file mode 100644 index 0000000..424a1b8 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AutoCalWorkingDaysPlugin.java @@ -0,0 +1,133 @@ +package zcgj.zcdev.zcdev.fs.plugin.form; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.form.ConfirmCallBackListener; +import kd.bos.form.MessageBoxOptions; +import kd.bos.form.control.events.BeforeItemClickEvent; +import kd.bos.form.control.events.ItemClickEvent; +import kd.sdk.plugin.Plugin; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.EventObject; + +public class AutoCalWorkingDaysPlugin extends AbstractBillPlugIn implements Plugin { + + @Override + public void propertyChanged(PropertyChangedArgs e) { + String name = e.getProperty().getName(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + if(name.equals("zcgj_startdate") ||name.equals("zcgj_enddate")){ + ChangeData[] changeSet = e.getChangeSet(); + //获取分录 + DynamicObject dataEntity = this.getModel().getDataEntity(true); + DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("zcgj_homeentity"); + DynamicObject dynamicObject = dynamicObjectCollection.get(changeSet[0].getRowIndex()); + Date zcgjStartdate = dynamicObject.getDate("zcgj_startdate"); + Date zcgjEnddate = dynamicObject.getDate("zcgj_enddate"); + if(zcgjEnddate!=null){ + int workDays = calculateWorkdays(zcgjStartdate, zcgjEnddate); + int allDays = calculateDaysBetween(zcgjStartdate, zcgjEnddate); + dynamicObject.set("zcgj_homedaycount",workDays); + int day = allDays - workDays; + if(day>=0&&workDays>0){ + dynamicObject.set("zcgj_kccbdaycount",day); + }else{ + dynamicObject.set("zcgj_kccbdaycount",0); + } + getView().updateView(); + int allHomeCount = 0; + for (DynamicObject entry : dynamicObjectCollection) { + allHomeCount += entry.getInt("zcgj_kccbdaycount"); + } + this.getModel().setValue("zcgj_kccbdays",allHomeCount); + getView().updateView(); + } + } + super.propertyChanged(e); + } + + @Override + public void registerListener(EventObject e) { + super.registerListener(e); +//监听工具栏按钮点击事件 + this.addItemClickListeners("zcgj_hometoolbarap"); + this.addClickListeners("advcontoolbarap"); + } + + @Override + public void itemClick(ItemClickEvent evt) { + super.itemClick(evt); + if (evt.getItemKey().equals("zcgj_delhome")) { + //获取分录 + DynamicObject dataEntity = this.getModel().getDataEntity(); + DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("zcgj_homeentity"); + getView().updateView(); + int allHomeCount = 0; + for (DynamicObject entry : dynamicObjectCollection) { + allHomeCount += entry.getInt("zcgj_kccbdaycount"); + } + this.getModel().setValue("zcgj_kccbdays",allHomeCount); + getView().updateView(); + } + } + + // 计算工作日天数 + public static int calculateWorkdays(Date startDate, Date endDate) { + // 使用 Calendar 类进行日期操作 + Calendar startCalendar = Calendar.getInstance(); + Calendar endCalendar = Calendar.getInstance(); + + startCalendar.setTime(startDate); + endCalendar.setTime(endDate); + + // 特殊情况处理:如果开始日期是周五且结束日期是周一,返回0 + if (startCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY && + endCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) { + return 0; + } + + // 计算工作日天数 + int workdays = 0; + + // 从开始日期到结束日期遍历 + while (!startCalendar.after(endCalendar)) { + int dayOfWeek = startCalendar.get(Calendar.DAY_OF_WEEK); + // 只统计周一到周五(排除周六和周日) + if (dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY) { + workdays++; + } + startCalendar.add(Calendar.DAY_OF_MONTH, 1); // 移动到下一天 + } + + return workdays; + } + + // 计算开始日期和结束日期之间的天数 + public static int calculateDaysBetween(Date startDate, Date endDate) { + // 日期格式化 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + // 使用 Calendar 类来处理日期 + Calendar startCalendar = Calendar.getInstance(); + Calendar endCalendar = Calendar.getInstance(); + + startCalendar.setTime(startDate); + endCalendar.setTime(endDate); + + // 计算两个日期之间的天数差 + long startMillis = startCalendar.getTimeInMillis(); + long endMillis = endCalendar.getTimeInMillis(); + + // 计算天数差,注意加1天因为天数是区间的数量(包含开始日期) + long diffMillis = endMillis - startMillis; + int diffDays = (int) (diffMillis / (24 * 60 * 60 * 1000)); + + return diffDays + 1; // 因为差值是天数之间的差,包含开始日期 + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/report/EmpTravelRptQueryPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/report/EmpTravelRptQueryPlugin.java index 8a346f6..6e40875 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/report/EmpTravelRptQueryPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/report/EmpTravelRptQueryPlugin.java @@ -120,15 +120,12 @@ public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin { String startdateStr = dateFormat.format(row.getDate("startdate"));// String enddateStr = dateFormat.format(row.getDate("enddate")); String bxmonthStr = dateFormat.format(row.getDate("bxmonth"));//归属月份 + int homedaycount = row.getInteger("homedaycount");//工作天日数 LocalDate bxmonth = dateToLocalDate(row.getDate("bxmonth")); - if(!skip(row.getDate("startdate"), row.getDate("enddate"))){ - int days = calculateDaysBetween(row.getDate("startdate"), row.getDate("enddate")); - if(days >= kccbdays){ - monthDaysMap.put(bxmonth.getMonth().getValue(), - monthDaysMap.getOrDefault(bxmonth.getMonth().getValue(), 0) + (days-kccbdays)); - } - } + monthDaysMap.put(bxmonth.getMonth().getValue(), + monthDaysMap.getOrDefault(bxmonth.getMonth().getValue(), 0) + homedaycount); + } DataSet dailyreimbursebill = getDailyreimbursebill(queryYear, userId); @@ -139,15 +136,12 @@ public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin { String startdateStr = dateFormat.format(row.getDate("startdate"));// String enddateStr = dateFormat.format(row.getDate("enddate")); String bxmonthStr = dateFormat.format(row.getDate("bxmonth"));//归属月份 + int homedaycount = row.getInteger("homedaycount");//工作天日数 LocalDate bxmonth = dateToLocalDate(row.getDate("bxmonth")); - if(!skip(row.getDate("startdate"), row.getDate("enddate"))){ - int days = calculateDaysBetween(row.getDate("startdate"), row.getDate("enddate")); - if(days >= kccbdays){ - monthDaysMap.put(bxmonth.getMonth().getValue(), - monthDaysMap.getOrDefault(bxmonth.getMonth().getValue(), 0) + (days-kccbdays)); - } - } + monthDaysMap.put(bxmonth.getMonth().getValue(), + monthDaysMap.getOrDefault(bxmonth.getMonth().getValue(), 0) + homedaycount); + } System.out.println(); } @@ -201,7 +195,7 @@ public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin { List searchFilterList = new ArrayList<>(); searchFilterList.add(new QFilter("applier", QCP.equals, applierId)); searchFilterList.add(new QFilter( "zcgj_is_include_home", QCP.equals, true)); - //searchFilterList.add(new QFilter("billstatus", QCP.in, billStatuslist)); + searchFilterList.add(new QFilter("billstatus", QCP.in, billStatuslist)); searchFilterList.add( new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDay)); searchFilterList.add(new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDay)); DataSet dateSet = QueryServiceHelper.queryDataSet( @@ -209,7 +203,7 @@ public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin { "er_tripreimbursebill", "id,billno,zcgj_kccbdays as kccbdays,zcgj_homeentity,zcgj_homeentity.zcgj_bxmonth as bxmonth," + "zcgj_homeentity.zcgj_startdate as startdate,zcgj_homeentity.zcgj_enddate as enddate," + - "zcgj_homeentity.zcgj_homebz as homebz", + "zcgj_homeentity.zcgj_homebz as homebz,zcgj_homedaycount as homedaycount", searchFilterList.toArray(new QFilter [] {}), null ); return dateSet; @@ -240,7 +234,7 @@ public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin { //查询申请人下的今年的探亲差旅单据 searchFilterList.add(new QFilter("applier", QCP.equals, applierId)); searchFilterList.add(new QFilter( "zcgj_is_home", QCP.equals, true)); - //searchFilterList.add(new QFilter("billstatus", QCP.in, billStatuslist)); + searchFilterList.add(new QFilter("billstatus", QCP.in, billStatuslist)); searchFilterList.add( new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDay)); searchFilterList.add(new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDay)); DataSet dateSet = QueryServiceHelper.queryDataSet( @@ -248,7 +242,7 @@ public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin { "er_dailyreimbursebill", "id,billno,zcgj_kccbdays as kccbdays,zcgj_homeentity,zcgj_homeentity.zcgj_bxmonth as bxmonth," + "zcgj_homeentity.zcgj_startdate as startdate,zcgj_homeentity.zcgj_enddate as enddate," + - "zcgj_homeentity.zcgj_homebz as homebz", + "zcgj_homeentity.zcgj_homebz as homebz,zcgj_homedaycount as homedaycount", searchFilterList.toArray(new QFilter [] {}), null ); return dateSet;