1.费用报销单和差旅报销单增加往来居家校验

This commit is contained in:
zhangzhiguo 2024-12-31 15:14:51 +08:00
parent a609a1a37a
commit 2fc98ac060
3 changed files with 640 additions and 58 deletions

View File

@ -0,0 +1,315 @@
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);
}
}

View File

@ -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++;
}
}

View File

@ -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);
}
}