1.增加职员出差天数统计台账

This commit is contained in:
zhangzhiguo 2025-01-02 15:29:05 +08:00
parent 6d981ff250
commit cee3debf85
2 changed files with 145 additions and 18 deletions

View File

@ -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; // 因为差值是天数之间的差包含开始日期
}
}

View File

@ -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.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.getOrDefault(bxmonth.getMonth().getValue(), 0) + homedaycount);
}
System.out.println();
}
@ -201,7 +195,7 @@ public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin {
List<QFilter> 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;