Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
742be1d163
|
@ -0,0 +1,134 @@
|
|||
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);
|
||||
}
|
||||
int allHomeCount = 0;
|
||||
for (DynamicObject entry : dynamicObjectCollection) {
|
||||
allHomeCount += entry.getInt("zcgj_kccbdaycount");
|
||||
}
|
||||
this.getModel().setValue("zcgj_kccbdays",allHomeCount);
|
||||
this.getView().updateView("zcgj_homeentity");
|
||||
}
|
||||
}
|
||||
super.propertyChanged(e);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(EventObject e) {
|
||||
super.registerListener(e);
|
||||
//监听工具栏按钮点击事件
|
||||
//this.addItemClickListeners("zcgj_hometoolbarap");
|
||||
}
|
||||
|
||||
@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");
|
||||
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; // 因为差值是天数之间的差,包含开始日期
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package zcgj.zcdev.zcdev.fs.plugin.form;
|
|||
|
||||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
|
||||
|
@ -23,7 +24,12 @@ public class ContractbillContractpartyDefaultPlugin extends AbstractBillPlugIn
|
|||
Long currentOrgId = RequestContext.get().getOrgId();
|
||||
//当前所在的组织是属于矿山下的
|
||||
if(OrgCheckUtils.isKS(currentOrgId)){
|
||||
this.getModel().setValue("contractparty",mainOrgId);
|
||||
Object company = this.getModel().getValue("costcompany");//核算组织
|
||||
if(company!=null){
|
||||
DynamicObject companyObj = (DynamicObject)company;
|
||||
this.getModel().setValue("contractparty",companyObj);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,318 @@
|
|||
package zcgj.zcdev.zcdev.fs.plugin.operate;
|
||||
|
||||
import kd.bos.algo.DataSet;
|
||||
import kd.bos.algo.Row;
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.ExtendedDataEntity;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||
import kd.bos.entity.validate.AbstractValidator;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||
import kd.bos.util.StringUtils;
|
||||
import zcgj.zcdev.zcdev.fs.plugin.form.OrgCheckUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 费用报销单往来家居检查操作
|
||||
*/
|
||||
public class DailyreimbursHomeCheckOp extends AbstractOperationServicePlugIn {
|
||||
private static final String prefix ="zcgj";
|
||||
@Override
|
||||
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||
super.onPreparePropertys(e);
|
||||
e.getFieldKeys().add("zcgj_is_home");
|
||||
e.getFieldKeys().add("applier");
|
||||
e.getFieldKeys().add("zcgj_homeentity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||
super.onAddValidators(e);
|
||||
Long currentUserId = UserServiceHelper.getCurrentUserId();
|
||||
// 当前用户所属组织
|
||||
Long mainOrgId = UserServiceHelper.getUserMainOrgId(currentUserId);
|
||||
//当前切换选择的组织
|
||||
Long currentOrgId = RequestContext.get().getOrgId();
|
||||
//当前所在的组织是属于矿山下的
|
||||
if(OrgCheckUtils.isKS(currentOrgId)){
|
||||
e.getValidators().add(new ValidatorExt());
|
||||
}
|
||||
}
|
||||
|
||||
class ValidatorExt extends AbstractValidator {
|
||||
@Override
|
||||
public void validate() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
||||
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
|
||||
Map<Long,Map<String,Object>> allMap = new HashMap<>();
|
||||
//当前提交的探亲单据id集合
|
||||
Map<Long,List<Long>> currentBillIdListMap = new HashMap<>();
|
||||
|
||||
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
||||
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
||||
long aLong = dataEntity.getLong("id");
|
||||
//获取报销人
|
||||
DynamicObject applier = dataEntity.getDynamicObject("applier");
|
||||
long applierId = applier.getLong("id");
|
||||
//获取申请日期
|
||||
//Date bizdate = dataEntity.getDate( "bizdate");
|
||||
//获取是否探亲
|
||||
//如果是探亲,则进行逻辑判断
|
||||
boolean isHome = dataEntity.getBoolean(prefix + "_is_home");
|
||||
|
||||
//判断是否来往家居地
|
||||
if(isHome){
|
||||
//获取当前人的往来家居地配置
|
||||
QFilter[] visitSetFilterArray = new QFilter[1];
|
||||
visitSetFilterArray[0] = new QFilter(prefix+"_user", QCP.equals, applierId);
|
||||
DataSet homeDataSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
prefix+"_user_home_conf",
|
||||
"id,zcgj_month_times as monthTime",
|
||||
visitSetFilterArray, null
|
||||
);
|
||||
int monthTime = 0;
|
||||
for (Row row : homeDataSet) {
|
||||
monthTime = row.getInteger("monthTime");
|
||||
}
|
||||
if(monthTime != 0){
|
||||
DynamicObjectCollection tripentry = dataEntity.getDynamicObjectCollection("zcgj_homeentity");//oa流程分录
|
||||
Map<String,Integer> homeentityCountMap = new HashMap<>();
|
||||
int i = 1;
|
||||
boolean isOk=true;
|
||||
for (DynamicObject dynamicObject : tripentry) {
|
||||
Date bxmonth = dynamicObject.getDate("zcgj_bxmonth");
|
||||
String yearMonth = dateFormat.format(bxmonth);
|
||||
|
||||
String bxmonthStr = dateFormat.format(bxmonth);
|
||||
String startdateStr = dateFormat.format(dynamicObject.getDate("zcgj_startdate"));
|
||||
String enddateStr = dateFormat.format(dynamicObject.getDate("zcgj_enddate"));
|
||||
isOk = checkBelongMonth(bxmonthStr, startdateStr, enddateStr);
|
||||
if(!isOk){
|
||||
this.addFatalErrorMessage(extendedDataEntity, String.format("当前单据中往来居家明细的第%d行,往返日期不在报销归属月中!",i));
|
||||
}
|
||||
// 更新统计次数
|
||||
homeentityCountMap.put(yearMonth, homeentityCountMap.getOrDefault(yearMonth, 0) + 1);
|
||||
i++;
|
||||
}
|
||||
// 输出结果
|
||||
for (Map.Entry<String, Integer> entry : homeentityCountMap.entrySet()) {
|
||||
if(entry.getValue() > monthTime){
|
||||
String message = String.format("当前单据在%s月中提交了%d次往来居家,往来居家次数超限,限制每月%d次!",entry.getKey(),entry.getValue() ,monthTime);
|
||||
isOk= false;
|
||||
this.addFatalErrorMessage(extendedDataEntity, message);
|
||||
}
|
||||
//System.out.println(entry.getKey() + ": " + entry.getValue() + " 次");
|
||||
}
|
||||
if(isOk){
|
||||
for (DynamicObject dynamicObject : tripentry) {
|
||||
Date bxmonth = dynamicObject.getDate("zcgj_bxmonth");
|
||||
DataSet tripreimbursebill = getTripreimbursebill(bxmonth, applierId);
|
||||
//已用次数
|
||||
int goHomeCount = 0;
|
||||
StringBuilder trSb = new StringBuilder();
|
||||
for (Row row : tripreimbursebill) {
|
||||
goHomeCount++;
|
||||
String billno = row.getString("billno");
|
||||
/*String bxmonthStr = dateFormat.format(row.getDate("bxmonth"));
|
||||
String startdateStr = dateFormat.format(row.getDate("startdate"));
|
||||
String enddateStr = dateFormat.format(row.getDate("enddate"));
|
||||
boolean b = checkBelongMonth(bxmonthStr, startdateStr, enddateStr);*/
|
||||
trSb.append(billno).append(";");
|
||||
}
|
||||
DataSet dailyreimbursebill = getDailyreimbursebill(bxmonth, applierId);
|
||||
StringBuilder daSb = new StringBuilder();
|
||||
for (Row row : dailyreimbursebill) {
|
||||
goHomeCount++;
|
||||
String billno = row.getString("billno");
|
||||
/* String bxmonthStr = dateFormat.format(row.getDate("bxmonth"));
|
||||
String startdateStr = dateFormat.format(row.getDate("startdate"));
|
||||
String enddateStr = dateFormat.format(row.getDate("enddate"));
|
||||
boolean b = checkBelongMonth(bxmonthStr, startdateStr, enddateStr);*/
|
||||
daSb.append(billno).append(";");
|
||||
}
|
||||
|
||||
if(goHomeCount >= monthTime){
|
||||
int monthVal = getFirstDayOfMonth(bxmonth).getMonth().getValue();
|
||||
String message = String.format("请知悉:您每月共有%d次往来家居地报销次数,在%d月中已进行过%d次来往家居地报销。",monthTime,monthVal,goHomeCount);
|
||||
if(!StringUtils.isBlank(trSb.toString())){
|
||||
message+="已提交的差旅报销单:【"+trSb.toString()+"】 ";
|
||||
}
|
||||
if(!StringUtils.isBlank(daSb.toString())){
|
||||
message+="已提交的费用报销单:【"+daSb.toString()+"】 ";
|
||||
}
|
||||
this.addFatalErrorMessage(extendedDataEntity, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断归属月份是否与开始时间或结束时间的月份相同
|
||||
public static boolean checkBelongMonth(String belongMonth, String startDate, String endDate) {
|
||||
// 比较归属月份是否与开始时间或结束时间的月份相同
|
||||
return belongMonth.equals(startDate) || belongMonth.equals(endDate);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取差旅费报销单
|
||||
*
|
||||
* @param bxmonth
|
||||
* @param applierId
|
||||
* @return
|
||||
*/
|
||||
public DataSet getTripreimbursebill(Date bxmonth, long applierId) {
|
||||
//查询非暂存、废弃的数据
|
||||
List<String> billStatuslist = new ArrayList<>();
|
||||
billStatuslist.add("B");
|
||||
billStatuslist.add("C");
|
||||
billStatuslist.add("D");
|
||||
billStatuslist.add("E");
|
||||
billStatuslist.add("F");
|
||||
billStatuslist.add("G");
|
||||
LocalDate firstDayOfMonth = getFirstDayOfMonth(bxmonth);
|
||||
LocalDate lastDayOfMonth = getLastDayOfMonth(bxmonth);
|
||||
QFilter[] filterArray = new QFilter[5];
|
||||
//查询申请人下的今年的探亲差旅单据
|
||||
filterArray[0] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDayOfMonth);
|
||||
filterArray[1] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDayOfMonth);
|
||||
filterArray[2] = new QFilter("applier", QCP.equals, applierId);
|
||||
filterArray[3] = new QFilter(prefix + "_is_include_home", QCP.equals, true);
|
||||
filterArray[4] = new QFilter("billstatus", QCP.in, billStatuslist);
|
||||
DataSet dateSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
"er_tripreimbursebill",
|
||||
"id,billno,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",
|
||||
filterArray, null
|
||||
);
|
||||
return dateSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取费用报销单
|
||||
*
|
||||
* @param bxmonth
|
||||
* @param applierId
|
||||
* @return
|
||||
*/
|
||||
public DataSet getDailyreimbursebill(Date bxmonth, long applierId) {
|
||||
//查询非暂存、废弃的数据
|
||||
List<String> billStatuslist = new ArrayList<>();
|
||||
billStatuslist.add("B");
|
||||
billStatuslist.add("C");
|
||||
billStatuslist.add("D");
|
||||
billStatuslist.add("E");
|
||||
billStatuslist.add("F");
|
||||
billStatuslist.add("G");
|
||||
|
||||
LocalDate firstDayOfMonth = getFirstDayOfMonth(bxmonth);
|
||||
LocalDate lastDayOfMonth = getLastDayOfMonth(bxmonth);
|
||||
QFilter[] filterArray = new QFilter[5];
|
||||
//查询申请人下的今年的探亲差旅单据
|
||||
filterArray[0] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDayOfMonth);
|
||||
filterArray[1] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDayOfMonth);
|
||||
filterArray[2] = new QFilter("applier", QCP.equals, applierId);
|
||||
filterArray[3] = new QFilter(prefix + "_is_home", QCP.equals, true);
|
||||
filterArray[4] = new QFilter("billstatus", QCP.in, billStatuslist);
|
||||
DataSet dateSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
"er_dailyreimbursebill",
|
||||
"id,billno,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",
|
||||
filterArray, null
|
||||
);
|
||||
return dateSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 java.util.Date 转换为 java.time.LocalDate
|
||||
* @param date java.util.Date
|
||||
* @return java.time.LocalDate
|
||||
*/
|
||||
public static LocalDate dateToLocalDate(Date date) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("日期不能为 null");
|
||||
}
|
||||
return date.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在年份的第一天
|
||||
* @param date java.util.Date
|
||||
* @return java.util.Date
|
||||
*/
|
||||
public static Date getFirstDayOfYear(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
LocalDate firstDayOfYear = LocalDate.of(localDate.getYear(), Month.JANUARY, 1);
|
||||
return Date.from(firstDayOfYear.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在年份的最后一天
|
||||
* @param date java.util.Date
|
||||
* @return java.util.Date
|
||||
*/
|
||||
public static Date getLastDayOfYear(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
LocalDate lastDayOfYear = LocalDate.of(localDate.getYear(), Month.DECEMBER, 31);
|
||||
return Date.from(lastDayOfYear.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在月份的第一天
|
||||
* @param date 指定日期
|
||||
* @return LocalDate 所在月份的第一天
|
||||
*/
|
||||
public static LocalDate getFirstDayOfMonth(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
return localDate.with(TemporalAdjusters.firstDayOfMonth());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在月份的最后一天
|
||||
* @param date 指定日期
|
||||
* @return LocalDate 所在月份的最后一天
|
||||
*/
|
||||
public static LocalDate getLastDayOfMonth(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
return localDate.with(TemporalAdjusters.lastDayOfMonth());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年限-1年前的第一天
|
||||
* @param date 指定日期
|
||||
* @param years 年限值
|
||||
* @return LocalDate 年限-1年前的第一天
|
||||
*/
|
||||
public static LocalDate getFirstDayYearsAgo(LocalDate date, int years) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("日期不能为空");
|
||||
}
|
||||
if (years < 1) {
|
||||
throw new IllegalArgumentException("年限值必须大于等于 1");
|
||||
}
|
||||
return LocalDate.of(date.getYear() - (years - 1), Month.JANUARY, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -75,24 +75,23 @@ public class DailyreimbursVisitCheckOp extends AbstractOperationServicePlugIn {
|
|||
//获取报销人
|
||||
DynamicObject applier = dataEntity.getDynamicObject("applier");
|
||||
long applierId = applier.getLong("id");
|
||||
//获取休假开始时间
|
||||
Date startTime = dataEntity.getDate(prefix + "_holiday_start_time");
|
||||
//获取休假结束时间
|
||||
Date endTime = dataEntity.getDate(prefix + "_holiday_end_time");
|
||||
//获取休假天数
|
||||
Integer days = dataEntity.getInt(prefix + "_holiday_days");
|
||||
//获取申请日期
|
||||
Date bizdate = dataEntity.getDate( "bizdate");
|
||||
//Date bizdate = dataEntity.getDate( "bizdate");
|
||||
//获取是否探亲
|
||||
//如果是探亲,则进行逻辑判断
|
||||
boolean isVisit = dataEntity.getBoolean(prefix + "_is_visit");
|
||||
boolean isHome = dataEntity.getBoolean(prefix + "_is_home");
|
||||
//探亲类型 1:探望父母,2:探望配偶
|
||||
String visitType = dataEntity.getString(prefix + "_visit_type");
|
||||
|
||||
//判断是否探亲
|
||||
if(isVisit){
|
||||
|
||||
//获取休假开始时间
|
||||
Date startTime = dataEntity.getDate(prefix + "_holiday_start_time");
|
||||
//获取休假结束时间
|
||||
Date endTime = dataEntity.getDate(prefix + "_holiday_end_time");
|
||||
//获取休假天数
|
||||
Integer days = dataEntity.getInt(prefix + "_holiday_days");
|
||||
//探亲类型 1:探望父母,2:探望配偶
|
||||
String visitType = dataEntity.getString(prefix + "_visit_type");
|
||||
//获取当前人的探亲假配置
|
||||
QFilter[] visitSetFilterArray = new QFilter[1];
|
||||
visitSetFilterArray[0] = new QFilter(prefix+"_user", QCP.equals, applierId);
|
||||
|
@ -260,54 +259,6 @@ public class DailyreimbursVisitCheckOp extends AbstractOperationServicePlugIn {
|
|||
return;
|
||||
}
|
||||
}
|
||||
//判断是否来往家居地
|
||||
if(isHome){
|
||||
//获取当前人的往来家居地配置
|
||||
QFilter[] visitSetFilterArray = new QFilter[1];
|
||||
visitSetFilterArray[0] = new QFilter(prefix+"_user", QCP.equals, applierId);
|
||||
DataSet homeDataSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
prefix+"_user_home_conf",
|
||||
"id,zcgj_month_times as monthTime",
|
||||
visitSetFilterArray, null
|
||||
);
|
||||
Integer monthTime = null;
|
||||
for (Row row : homeDataSet) {
|
||||
monthTime = row.getInteger("monthTime");
|
||||
}
|
||||
|
||||
|
||||
//获取申请人在月份的单据量
|
||||
LocalDate firstDayOfMonth = getFirstDayOfMonth(bizdate);
|
||||
LocalDate lastDayOfMonth = getLastDayOfMonth(bizdate);
|
||||
QFilter[] filterArray = new QFilter[4];
|
||||
//查询申请人下的今年的探亲差旅单据
|
||||
filterArray[0] = new QFilter("bizdate", QCP.large_equals, firstDayOfMonth);
|
||||
filterArray[1] = new QFilter("bizdate", QCP.less_equals, lastDayOfMonth);
|
||||
filterArray[2] = new QFilter("applier", QCP.equals, applierId);
|
||||
filterArray[3] = new QFilter(prefix+"_is_home", QCP.equals, true);
|
||||
DataSet dateSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
"er_dailyreimbursebill",
|
||||
"id,billno,zcgj_holiday_start_time as startTime,zcgj_holiday_end_time as endTime,zcgj_is_home as ishome,",
|
||||
filterArray, null
|
||||
);
|
||||
int goHomeCount = 0;
|
||||
for (Row row : dateSet) {
|
||||
Boolean ishome = row.getBoolean("ishome");
|
||||
System.out.println(row.getString("billno"));
|
||||
if(ishome){
|
||||
goHomeCount++;
|
||||
}
|
||||
}
|
||||
if(monthTime != null && monthTime != 0){
|
||||
int monthVal = firstDayOfMonth.getMonth().getValue();
|
||||
String message = String.format("请知悉:您每月共有%d次往来家居地报销次数,在%d月中已进行过%d次来往家居地报销。",monthTime,monthVal,goHomeCount);
|
||||
//this.getView().showSuccessNotification(message);
|
||||
this.addMessage(extendedDataEntity, message);
|
||||
}
|
||||
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,316 @@
|
|||
package zcgj.zcdev.zcdev.fs.plugin.operate;
|
||||
|
||||
import kd.bos.algo.DataSet;
|
||||
import kd.bos.algo.Row;
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.ExtendedDataEntity;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||
import kd.bos.entity.validate.AbstractValidator;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||
import kd.bos.util.StringUtils;
|
||||
import zcgj.zcdev.zcdev.fs.plugin.form.OrgCheckUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 差旅报销单往来家居检查操作
|
||||
*/
|
||||
public class TripreimbursebillIsHomeCheckOp extends AbstractOperationServicePlugIn {
|
||||
private static final String prefix ="zcgj";
|
||||
@Override
|
||||
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||
super.onPreparePropertys(e);
|
||||
e.getFieldKeys().add("zcgj_is_include_home");
|
||||
e.getFieldKeys().add("applier");
|
||||
e.getFieldKeys().add("zcgj_homeentity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||
super.onAddValidators(e);
|
||||
Long currentUserId = UserServiceHelper.getCurrentUserId();
|
||||
// 当前用户所属组织
|
||||
Long mainOrgId = UserServiceHelper.getUserMainOrgId(currentUserId);
|
||||
//当前切换选择的组织
|
||||
Long currentOrgId = RequestContext.get().getOrgId();
|
||||
//当前所在的组织是属于矿山下的
|
||||
if(OrgCheckUtils.isKS(currentOrgId)){
|
||||
e.getValidators().add(new ValidatorExt());
|
||||
}
|
||||
}
|
||||
|
||||
class ValidatorExt extends AbstractValidator {
|
||||
@Override
|
||||
public void validate() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
||||
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
|
||||
Map<Long,Map<String,Object>> allMap = new HashMap<>();
|
||||
//当前提交的探亲单据id集合
|
||||
Map<Long,List<Long>> currentBillIdListMap = new HashMap<>();
|
||||
|
||||
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
||||
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
||||
long aLong = dataEntity.getLong("id");
|
||||
//获取报销人
|
||||
DynamicObject applier = dataEntity.getDynamicObject("applier");
|
||||
long applierId = applier.getLong("id");
|
||||
//获取申请日期
|
||||
//Date bizdate = dataEntity.getDate( "bizdate");
|
||||
//获取是否探亲
|
||||
//如果是探亲,则进行逻辑判断
|
||||
boolean isHome = dataEntity.getBoolean(prefix + "_is_include_home");
|
||||
|
||||
//判断是否来往家居地
|
||||
if(isHome){
|
||||
//获取当前人的往来家居地配置
|
||||
QFilter[] visitSetFilterArray = new QFilter[1];
|
||||
visitSetFilterArray[0] = new QFilter(prefix+"_user", QCP.equals, applierId);
|
||||
DataSet homeDataSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
prefix+"_user_home_conf",
|
||||
"id,zcgj_month_times as monthTime",
|
||||
visitSetFilterArray, null
|
||||
);
|
||||
int monthTime = 0;
|
||||
for (Row row : homeDataSet) {
|
||||
monthTime = row.getInteger("monthTime");
|
||||
}
|
||||
if(monthTime != 0){
|
||||
DynamicObjectCollection tripentry = dataEntity.getDynamicObjectCollection("zcgj_homeentity");//oa流程分录
|
||||
Map<String,Integer> homeentityCountMap = new HashMap<>();
|
||||
int i = 1;
|
||||
boolean isOk=true;
|
||||
for (DynamicObject dynamicObject : tripentry) {
|
||||
Date bxmonth = dynamicObject.getDate("zcgj_bxmonth");
|
||||
String yearMonth = dateFormat.format(bxmonth);
|
||||
|
||||
String bxmonthStr = dateFormat.format(bxmonth);
|
||||
String startdateStr = dateFormat.format(dynamicObject.getDate("zcgj_startdate"));
|
||||
String enddateStr = dateFormat.format(dynamicObject.getDate("zcgj_enddate"));
|
||||
isOk = checkBelongMonth(bxmonthStr, startdateStr, enddateStr);
|
||||
if(!isOk){
|
||||
this.addFatalErrorMessage(extendedDataEntity, String.format("当前单据中往来居家明细的第%d行,往返日期不在报销归属月中!",i));
|
||||
}
|
||||
// 更新统计次数
|
||||
homeentityCountMap.put(yearMonth, homeentityCountMap.getOrDefault(yearMonth, 0) + 1);
|
||||
i++;
|
||||
}
|
||||
// 输出结果
|
||||
for (Map.Entry<String, Integer> entry : homeentityCountMap.entrySet()) {
|
||||
if(entry.getValue() > monthTime){
|
||||
String message = String.format("当前单据在%s月中提交了%d次往来居家,往来居家次数超限,限制每月%d次!",entry.getKey(),entry.getValue() ,monthTime);
|
||||
isOk= false;
|
||||
this.addFatalErrorMessage(extendedDataEntity, message);
|
||||
}
|
||||
//System.out.println(entry.getKey() + ": " + entry.getValue() + " 次");
|
||||
}
|
||||
if(isOk){
|
||||
for (DynamicObject dynamicObject : tripentry) {
|
||||
Date bxmonth = dynamicObject.getDate("zcgj_bxmonth");
|
||||
DataSet tripreimbursebill = getTripreimbursebill(bxmonth, applierId);
|
||||
//已用次数
|
||||
int goHomeCount = 0;
|
||||
StringBuilder trSb = new StringBuilder();
|
||||
for (Row row : tripreimbursebill) {
|
||||
goHomeCount++;
|
||||
String billno = row.getString("billno");
|
||||
/*String bxmonthStr = dateFormat.format(row.getDate("bxmonth"));
|
||||
String startdateStr = dateFormat.format(row.getDate("startdate"));
|
||||
String enddateStr = dateFormat.format(row.getDate("enddate"));
|
||||
boolean b = checkBelongMonth(bxmonthStr, startdateStr, enddateStr);*/
|
||||
trSb.append(billno).append(";");
|
||||
}
|
||||
DataSet dailyreimbursebill = getDailyreimbursebill(bxmonth, applierId);
|
||||
StringBuilder daSb = new StringBuilder();
|
||||
for (Row row : dailyreimbursebill) {
|
||||
goHomeCount++;
|
||||
String billno = row.getString("billno");
|
||||
/* String bxmonthStr = dateFormat.format(row.getDate("bxmonth"));
|
||||
String startdateStr = dateFormat.format(row.getDate("startdate"));
|
||||
String enddateStr = dateFormat.format(row.getDate("enddate"));
|
||||
boolean b = checkBelongMonth(bxmonthStr, startdateStr, enddateStr);*/
|
||||
daSb.append(billno).append(";");
|
||||
}
|
||||
|
||||
if(goHomeCount >= monthTime){
|
||||
int monthVal = getFirstDayOfMonth(bxmonth).getMonth().getValue();
|
||||
String message = String.format("请知悉:您每月共有%d次往来家居地报销次数,在%d月中已进行过%d次来往家居地报销。",monthTime,monthVal,goHomeCount);
|
||||
if(!StringUtils.isBlank(trSb.toString())){
|
||||
message+="已提交的差旅报销单:【"+trSb.toString()+"】 ";
|
||||
}
|
||||
if(!StringUtils.isBlank(daSb.toString())){
|
||||
message+="已提交的费用报销单:【"+daSb.toString()+"】 ";
|
||||
}
|
||||
this.addFatalErrorMessage(extendedDataEntity, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断归属月份是否与开始时间或结束时间的月份相同
|
||||
public static boolean checkBelongMonth(String belongMonth, String startDate, String endDate) {
|
||||
// 比较归属月份是否与开始时间或结束时间的月份相同
|
||||
return belongMonth.equals(startDate) || belongMonth.equals(endDate);
|
||||
|
||||
}
|
||||
/**
|
||||
* 获取差旅费报销单
|
||||
* @param bxmonth
|
||||
* @param applierId
|
||||
* @return
|
||||
*/
|
||||
public DataSet getTripreimbursebill(Date bxmonth,long applierId){
|
||||
//查询非暂存、废弃的数据
|
||||
List<String> billStatuslist = new ArrayList<>();
|
||||
billStatuslist.add("B");
|
||||
billStatuslist.add("C");
|
||||
billStatuslist.add("D");
|
||||
billStatuslist.add("E");
|
||||
billStatuslist.add("F");
|
||||
billStatuslist.add("G");
|
||||
LocalDate firstDayOfMonth = getFirstDayOfMonth(bxmonth);
|
||||
LocalDate lastDayOfMonth = getLastDayOfMonth(bxmonth);
|
||||
QFilter[] filterArray = new QFilter[5];
|
||||
//查询申请人下的今年的探亲差旅单据
|
||||
filterArray[0] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDayOfMonth);
|
||||
filterArray[1] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDayOfMonth);
|
||||
filterArray[2] = new QFilter("applier", QCP.equals, applierId);
|
||||
filterArray[3] = new QFilter(prefix+"_is_include_home", QCP.equals, true);
|
||||
filterArray[4] = new QFilter("billstatus", QCP.in, billStatuslist);
|
||||
DataSet dateSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
"er_tripreimbursebill",
|
||||
"id,billno,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",
|
||||
filterArray, null
|
||||
);
|
||||
return dateSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取费用报销单
|
||||
* @param bxmonth
|
||||
* @param applierId
|
||||
* @return
|
||||
*/
|
||||
public DataSet getDailyreimbursebill(Date bxmonth,long applierId){
|
||||
//查询非暂存、废弃的数据
|
||||
List<String> billStatuslist = new ArrayList<>();
|
||||
billStatuslist.add("B");
|
||||
billStatuslist.add("C");
|
||||
billStatuslist.add("D");
|
||||
billStatuslist.add("E");
|
||||
billStatuslist.add("F");
|
||||
billStatuslist.add("G");
|
||||
|
||||
LocalDate firstDayOfMonth = getFirstDayOfMonth(bxmonth);
|
||||
LocalDate lastDayOfMonth = getLastDayOfMonth(bxmonth);
|
||||
QFilter[] filterArray = new QFilter[5];
|
||||
//查询申请人下的今年的探亲差旅单据
|
||||
filterArray[0] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDayOfMonth);
|
||||
filterArray[1] = new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDayOfMonth);
|
||||
filterArray[2] = new QFilter("applier", QCP.equals, applierId);
|
||||
filterArray[3] = new QFilter(prefix+"_is_home", QCP.equals, true);
|
||||
filterArray[4] = new QFilter("billstatus", QCP.in, billStatuslist);
|
||||
DataSet dateSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
"er_dailyreimbursebill",
|
||||
"id,billno,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",
|
||||
filterArray, null
|
||||
);
|
||||
return dateSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 java.util.Date 转换为 java.time.LocalDate
|
||||
* @param date java.util.Date
|
||||
* @return java.time.LocalDate
|
||||
*/
|
||||
public static LocalDate dateToLocalDate(Date date) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("日期不能为 null");
|
||||
}
|
||||
return date.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在年份的第一天
|
||||
* @param date java.util.Date
|
||||
* @return java.util.Date
|
||||
*/
|
||||
public static Date getFirstDayOfYear(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
LocalDate firstDayOfYear = LocalDate.of(localDate.getYear(), Month.JANUARY, 1);
|
||||
return Date.from(firstDayOfYear.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在年份的最后一天
|
||||
* @param date java.util.Date
|
||||
* @return java.util.Date
|
||||
*/
|
||||
public static Date getLastDayOfYear(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
LocalDate lastDayOfYear = LocalDate.of(localDate.getYear(), Month.DECEMBER, 31);
|
||||
return Date.from(lastDayOfYear.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在月份的第一天
|
||||
* @param date 指定日期
|
||||
* @return LocalDate 所在月份的第一天
|
||||
*/
|
||||
public static LocalDate getFirstDayOfMonth(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
return localDate.with(TemporalAdjusters.firstDayOfMonth());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在月份的最后一天
|
||||
* @param date 指定日期
|
||||
* @return LocalDate 所在月份的最后一天
|
||||
*/
|
||||
public static LocalDate getLastDayOfMonth(Date date) {
|
||||
LocalDate localDate = dateToLocalDate(date);
|
||||
return localDate.with(TemporalAdjusters.lastDayOfMonth());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年限-1年前的第一天
|
||||
* @param date 指定日期
|
||||
* @param years 年限值
|
||||
* @return LocalDate 年限-1年前的第一天
|
||||
*/
|
||||
public static LocalDate getFirstDayYearsAgo(LocalDate date, int years) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("日期不能为空");
|
||||
}
|
||||
if (years < 1) {
|
||||
throw new IllegalArgumentException("年限值必须大于等于 1");
|
||||
}
|
||||
return LocalDate.of(date.getYear() - (years - 1), Month.JANUARY, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package zcgj.zcdev.zcdev.fs.plugin.report;
|
||||
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.entity.datamodel.IDataModel;
|
||||
import kd.bos.entity.datamodel.events.PackageDataEvent;
|
||||
import kd.bos.entity.report.FilterInfo;
|
||||
import kd.bos.entity.report.ReportQueryParam;
|
||||
import kd.bos.report.events.CellStyleRule;
|
||||
import kd.bos.report.plugin.AbstractReportFormPlugin;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 职员出差天数统计台账
|
||||
* 报表格式化插件
|
||||
*/
|
||||
public class EmpTravelRptListPlugin extends AbstractReportFormPlugin implements Plugin {
|
||||
|
||||
private static final String DEV_KEY="zcgj";
|
||||
private static final String MERGECOLUM= DEV_KEY+"_username";//合并单元格字段
|
||||
//预算与汇总报表上的所有字段
|
||||
private static final String[] FIELDS={
|
||||
DEV_KEY+"_user", DEV_KEY+"_username",
|
||||
DEV_KEY+"_january",DEV_KEY+"_february",DEV_KEY+"_march",DEV_KEY+"_april",
|
||||
DEV_KEY+"_may", DEV_KEY+"_june", DEV_KEY+"_july",DEV_KEY+"_august",
|
||||
DEV_KEY+"_september",DEV_KEY+"_october",DEV_KEY+"_november",DEV_KEY+"_december",
|
||||
DEV_KEY+"_total"
|
||||
};
|
||||
|
||||
@Override
|
||||
public void setMergeColums(List<String> columns) {
|
||||
columns.add(MERGECOLUM);
|
||||
super.setMergeColums(columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packageData(PackageDataEvent packageDataEvent) {
|
||||
super.packageData(packageDataEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initDefaultQueryParam(ReportQueryParam queryParam) {
|
||||
super.initDefaultQueryParam(queryParam);
|
||||
IDataModel model = this.getModel();
|
||||
//获取当前登陆人所在组织
|
||||
long orgId = RequestContext.get().getOrgId();
|
||||
model.setValue("zcgj_query_org",orgId);
|
||||
model.setValue("zcgj_query_year",new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyQuery(ReportQueryParam queryParam) {
|
||||
FilterInfo filter = queryParam.getFilter();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (filter.getValue("zcgj_query_org") == null){
|
||||
this.getView().showTipNotification("请选择查询组织!");
|
||||
return false;
|
||||
}
|
||||
if (filter.getValue("zcgj_query_year") == null){
|
||||
this.getView().showTipNotification("请选择查询年度!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setCellStyleRules(List<CellStyleRule> cellStyleRules) {
|
||||
for (String field : FIELDS) {
|
||||
CellStyleRule cellStyleRule = new CellStyleRule();
|
||||
cellStyleRule.setFieldKey(field);// 字段标识
|
||||
cellStyleRule.setForeColor("#666666");// 前景色
|
||||
cellStyleRule.setBackgroundColor("#ffc000");// 背景色
|
||||
cellStyleRule.setDegree(100);// 透明度
|
||||
cellStyleRule.setCondition(DEV_KEY+"_username = '合计'");// 前置条件,值与表达式计算器一致
|
||||
cellStyleRules.add(cellStyleRule);
|
||||
}
|
||||
super.setCellStyleRules(cellStyleRules);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置过滤排序列
|
||||
*
|
||||
* @param allColumns 报表列
|
||||
*/
|
||||
/*@Override
|
||||
public void setSortAndFilter(List<SortAndFilterEvent> allColumns) {
|
||||
super.setSortAndFilter(allColumns);
|
||||
for (SortAndFilterEvent ent : allColumns) {
|
||||
ent.setFilter(true);
|
||||
ent.setSort(true);
|
||||
}
|
||||
}*/
|
||||
}
|
|
@ -0,0 +1,347 @@
|
|||
package zcgj.zcdev.zcdev.fs.plugin.report;
|
||||
|
||||
import kd.bos.algo.*;
|
||||
import kd.bos.algo.input.CollectionInput;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.report.AbstractReportListDataPlugin;
|
||||
import kd.bos.entity.report.FilterItemInfo;
|
||||
import kd.bos.entity.report.ReportQueryParam;
|
||||
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.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 职员出差天数统计台账
|
||||
* 报表取数插件
|
||||
*/
|
||||
public class EmpTravelRptQueryPlugin extends AbstractReportListDataPlugin {
|
||||
private static final Log logger = LogFactory.getLog(EmpTravelRptQueryPlugin.class);
|
||||
|
||||
private static final String DEV_KEY="zcgj";
|
||||
|
||||
@Override
|
||||
public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable {
|
||||
List<FilterItemInfo> filters = reportQueryParam.getFilter().getFilterItems();
|
||||
Set<Long> applierId = new HashSet<>();
|
||||
Long orgId = null;
|
||||
Date queryYear = null;
|
||||
boolean istax = false;
|
||||
for (FilterItemInfo filterItem : filters) {
|
||||
switch (filterItem.getPropName()) {
|
||||
case DEV_KEY+"_query_users":
|
||||
DynamicObjectCollection users = (DynamicObjectCollection)filterItem.getValue();
|
||||
if(users != null){
|
||||
for (DynamicObject user : users) {
|
||||
applierId.add(Long.valueOf(String.valueOf(user.getPkValue())));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DEV_KEY+"_query_year":
|
||||
queryYear = filterItem.getDate();
|
||||
break;
|
||||
case DEV_KEY+"_query_org":
|
||||
orgId = (filterItem.getValue() == null) ? null :Long.valueOf(String.valueOf(((DynamicObject) filterItem.getValue()).getPkValue()));
|
||||
break;
|
||||
case DEV_KEY+"_query_istax":
|
||||
istax = filterItem.getBoolean();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 报表字段及数据类型
|
||||
String[] FIELDS = {
|
||||
DEV_KEY+"_user", DEV_KEY+"_username",
|
||||
DEV_KEY+"_january",DEV_KEY+"_february",DEV_KEY+"_march",DEV_KEY+"_april",
|
||||
DEV_KEY+"_may", DEV_KEY+"_june", DEV_KEY+"_july",DEV_KEY+"_august",
|
||||
DEV_KEY+"_september",DEV_KEY+"_october",DEV_KEY+"_november",DEV_KEY+"_december",
|
||||
DEV_KEY+"_total"
|
||||
};
|
||||
DataType[] DATATYPES = {
|
||||
DataType.LongType,DataType.StringType,
|
||||
DataType.StringType, DataType.StringType,DataType.StringType,DataType.IntegerType,
|
||||
DataType.StringType, DataType.StringType, DataType.StringType,DataType.StringType,
|
||||
DataType.StringType, DataType.StringType, DataType.StringType,DataType.StringType,
|
||||
DataType.StringType
|
||||
};
|
||||
// 初始化 DataSet
|
||||
RowMeta rowMeta = RowMetaFactory.createRowMeta(FIELDS, DATATYPES);
|
||||
Collection<Object[]> coll = new ArrayList<>();
|
||||
CollectionInput inputs = new CollectionInput(rowMeta, coll);
|
||||
DataSet resultDataSet = Algo.create(this.getClass().getName()).createDataSet(inputs);
|
||||
|
||||
if(orgId==null || queryYear == null){
|
||||
return resultDataSet;
|
||||
}
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
//获取公司下的所有人
|
||||
List<Long> orgIds = new ArrayList<>();
|
||||
orgIds.add(orgId);
|
||||
List<Long> allUsersOfOrg = UserServiceHelper.getAllUsersOfOrg(orgIds);
|
||||
if(!applierId.isEmpty()){
|
||||
//通过查询用户过滤组织下的人
|
||||
allUsersOfOrg = allUsersOfOrg.stream().filter(applierId::contains).collect(Collectors.toList());
|
||||
}
|
||||
LocalDate localDate = dateToLocalDate(queryYear);
|
||||
int year = localDate.getYear();
|
||||
Set<Long> userSet = new HashSet<>();
|
||||
// 用 Map 来按照报销人、单据编号、费用发生日期分组
|
||||
Map<String, ExpenseReport> reportMap = new LinkedHashMap<>();
|
||||
Map<Long,Map<Integer,Integer>> userMonthDaysMap = new HashMap<>();
|
||||
for (Long userId : allUsersOfOrg) {
|
||||
Map<Integer,Integer> monthDaysMap = null;
|
||||
if(userMonthDaysMap.containsKey(userId)){
|
||||
monthDaysMap = userMonthDaysMap.get(userId);
|
||||
}else{
|
||||
monthDaysMap = new HashMap<>();
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
monthDaysMap.put(i,0);
|
||||
}
|
||||
userMonthDaysMap.put(userId,monthDaysMap);
|
||||
}
|
||||
|
||||
DataSet tripreimbursebill = getTripreimbursebill(queryYear, userId);
|
||||
for (Row row : tripreimbursebill) {
|
||||
String billno = row.getString("billno");
|
||||
int kccbdays = row.getInteger("kccbdays");//扣除餐补天数(周六日、节假日)
|
||||
|
||||
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"));
|
||||
monthDaysMap.put(bxmonth.getMonth().getValue(),
|
||||
monthDaysMap.getOrDefault(bxmonth.getMonth().getValue(), 0) + homedaycount);
|
||||
|
||||
}
|
||||
|
||||
DataSet dailyreimbursebill = getDailyreimbursebill(queryYear, userId);
|
||||
for (Row row : dailyreimbursebill) {
|
||||
String billno = row.getString("billno");
|
||||
int kccbdays = row.getInteger("kccbdays");//扣除餐补天数(周六日、节假日)
|
||||
|
||||
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"));
|
||||
monthDaysMap.put(bxmonth.getMonth().getValue(),
|
||||
monthDaysMap.getOrDefault(bxmonth.getMonth().getValue(), 0) + homedaycount);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (Long userId : userMonthDaysMap.keySet()) {
|
||||
Map<Integer, Integer> integerIntegerMap = userMonthDaysMap.get(userId);
|
||||
Map<String, Object> userInfoByID = UserServiceHelper.getUserInfoByID(userId);
|
||||
String username = String.valueOf(userInfoByID.get("name"));//报销人
|
||||
Object [] tempData = new Object [FIELDS.length];
|
||||
|
||||
tempData[0] = userId;
|
||||
tempData[1] = username;
|
||||
int index = 2;
|
||||
int totalDays = 0;
|
||||
for (int i = 1; i <=12 ; i++) {
|
||||
totalDays += integerIntegerMap.get(i);
|
||||
tempData[index] = integerIntegerMap.get(i) == 0 ?null:integerIntegerMap.get(i)+"";
|
||||
index++;
|
||||
}
|
||||
//如果总天数不为0的
|
||||
if(totalDays!=0){
|
||||
tempData[14] = totalDays;
|
||||
coll.add(tempData);
|
||||
}
|
||||
}
|
||||
|
||||
return resultDataSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取差旅费报销单
|
||||
*
|
||||
* @param applierId
|
||||
* @return
|
||||
*/
|
||||
public DataSet getTripreimbursebill(Date queryYear,Long applierId) {
|
||||
LocalDate localDate = dateToLocalDate(queryYear);
|
||||
LocalDate firstDay = getFirstDayOfYear(localDate.getYear());
|
||||
LocalDate lastDay = getLastDayOfYear(localDate.getYear());
|
||||
//查询非暂存、废弃的数据
|
||||
List<String> billStatuslist = new ArrayList<>();
|
||||
//billStatuslist.add("A"); //暂存
|
||||
//billStatuslist.add("B"); //已提交
|
||||
//billStatuslist.add("C"); //审核中
|
||||
//billStatuslist.add("D"); //审核未通过
|
||||
billStatuslist.add("E"); //审核通过
|
||||
billStatuslist.add("F"); //等待付款
|
||||
billStatuslist.add("G"); //已付款
|
||||
//billStatuslist.add("H"); //废弃
|
||||
billStatuslist.add("I"); //关闭
|
||||
//查询申请人下的今年的探亲差旅单据
|
||||
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("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDay));
|
||||
searchFilterList.add(new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDay));
|
||||
DataSet dateSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
"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_homedaycount as homedaycount",
|
||||
searchFilterList.toArray(new QFilter [] {}), null
|
||||
);
|
||||
return dateSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取费用报销单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DataSet getDailyreimbursebill(Date queryYear,Long applierId) {
|
||||
LocalDate localDate = dateToLocalDate(queryYear);
|
||||
LocalDate firstDay = getFirstDayOfYear(localDate.getYear());
|
||||
LocalDate lastDay = getLastDayOfYear(localDate.getYear());
|
||||
//查询非暂存、废弃的数据
|
||||
List<String> billStatuslist = new ArrayList<>();
|
||||
//billStatuslist.add("A"); //暂存
|
||||
//billStatuslist.add("B"); //已提交
|
||||
//billStatuslist.add("C"); //审核中
|
||||
//billStatuslist.add("D"); //审核未通过
|
||||
billStatuslist.add("E"); //审核通过
|
||||
billStatuslist.add("F"); //等待付款
|
||||
billStatuslist.add("G"); //已付款
|
||||
//billStatuslist.add("H"); //废弃
|
||||
billStatuslist.add("I"); //关闭
|
||||
|
||||
List<QFilter> searchFilterList = new ArrayList<>();
|
||||
//查询申请人下的今年的探亲差旅单据
|
||||
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("zcgj_homeentity.zcgj_bxmonth", QCP.large_equals, firstDay));
|
||||
searchFilterList.add(new QFilter("zcgj_homeentity.zcgj_bxmonth", QCP.less_equals, lastDay));
|
||||
DataSet dateSet = QueryServiceHelper.queryDataSet(
|
||||
this.getClass().getName(),
|
||||
"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_homedaycount as homedaycount",
|
||||
searchFilterList.toArray(new QFilter [] {}), null
|
||||
);
|
||||
return dateSet;
|
||||
}
|
||||
|
||||
public boolean skip(Date startDate, Date endDate) throws Exception{
|
||||
// 日期格式化
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
// 使用 Calendar 类进行日期操作
|
||||
Calendar startCalendar = Calendar.getInstance();
|
||||
Calendar endCalendar = Calendar.getInstance();
|
||||
|
||||
startCalendar.setTime(startDate);
|
||||
endCalendar.setTime(endDate);
|
||||
|
||||
// 特殊情况处理:如果开始日期是周五且结束日期是周一,跳过统计
|
||||
if (startCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY &&
|
||||
endCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 计算开始日期和结束日期之间的天数
|
||||
public static int calculateDaysBetween(Date startDate, Date endDate) throws Exception {
|
||||
// 日期格式化
|
||||
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; // 因为差值是天数之间的差,包含开始日期
|
||||
}
|
||||
|
||||
// 计算工作日天数
|
||||
public static int calculateWorkdays(Date startDate, Date endDate) throws Exception {
|
||||
// 使用 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 LocalDate getFirstDayOfYear(int year) {
|
||||
return LocalDate.of(year, 1, 1);
|
||||
}
|
||||
|
||||
// 获取某年份的最后一天
|
||||
public static LocalDate getLastDayOfYear(int year) {
|
||||
return LocalDate.of(year, 12, 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 java.util.Date 转换为 java.time.LocalDate
|
||||
* @param date java.util.Date
|
||||
* @return java.time.LocalDate
|
||||
*/
|
||||
public static LocalDate dateToLocalDate(Date date) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("日期不能为 null");
|
||||
}
|
||||
return date.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue