报销调整插件

This commit is contained in:
zhangzhiguo 2024-11-27 13:59:06 +08:00
parent d7472caefa
commit cfae1e292f
5 changed files with 556 additions and 0 deletions

View File

@ -0,0 +1,64 @@
package zcgj.zcdev.zcdev.fs.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.operate.Save;
import kd.bos.entity.operate.Submit;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import java.text.SimpleDateFormat;
/**
* 单据界面插件
* 人员年度预算单界面插件
*/
public class AnnualBudgetPlugin extends AbstractBillPlugIn implements Plugin {
//开发商标识
private static final String prefix ="zcgj";
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
Object source = args.getSource();
if((args.getSource() instanceof Submit) || (args.getSource() instanceof Save)){
String operateKey = null;
// 根据类型进行安全转换
if (source instanceof Submit) {
operateKey = ((Submit) source).getOperateKey();
} else if (source instanceof Save) {
operateKey = ((Save) source).getOperateKey();
}
//重写返回的数据
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
if("submit".equals(operateKey) || "save".equals(operateKey)){
BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter();
if(bsp.getStatus()== OperationStatus.ADDNEW){
IDataModel model = this.getModel();
Object year = model.getValue(prefix+"_year");
DynamicObject user = (DynamicObject)model.getValue(prefix+"_user");
long userId = user.getLong("id");
QFilter[] filterArray = new QFilter[2];
filterArray[0] = new QFilter(prefix+"_user", QCP.equals, userId);
filterArray[1] = new QFilter(prefix+"_year", QCP.equals, year);
DynamicObject[] logsToApprove = BusinessDataServiceHelper.load(prefix+"_annual_budget", "id",filterArray );
if(logsToApprove!=null && logsToApprove.length>0){
String formattedDate = dateFormat.format(year);
String message = String.format("当前员工%s年度预算已存在", formattedDate);
this.getView().showErrorNotification(message);
//取消提交操作
args.setCancel(true);
}
}
}
}
super.beforeDoOperation(args);
}
}

View File

@ -0,0 +1,340 @@
package zcgj.zcdev.zcdev.fs.plugin.form;
import kd.bos.algo.DataSet;
import kd.bos.algo.Row;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.operate.Submit;
import kd.bos.form.events.BeforeDoOperationEventArgs;
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.sdk.plugin.Plugin;
import zcgj.zcdev.zcdev.fs.plugin.task.WorkTask;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
/**
* 费用报销单探亲检查插件
*/
public class DailyreimbursPlugin extends AbstractBillPlugIn implements Plugin {
private static final Log log = LogFactory.getLog(DailyreimbursPlugin.class);
//开发商标识
private static final String prefix ="zcgj";
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
try{
if((args.getSource() instanceof Submit) ){
Submit source = (Submit)args.getSource();
if(source.getOperateKey().equals("submit") ){
IDataModel model = this.getModel();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
//报销人
DynamicObject applier = (DynamicObject)this.getModel().getValue("applier");
long applierId = applier.getLong("id");
//获取休假开始时间
Date startTime = (Date)model.getValue(prefix + "_holiday_start_time");
Date endTime = (Date)model.getValue(prefix + "_holiday_end_time");
//获取是否探亲
//如果时探亲则进行逻辑判断
Boolean isVisit = (Boolean)model.getValue(prefix+"_is_visit");
if(isVisit){
//探亲类型 1探望父母2探望配偶
String visitType = (String)model.getValue(prefix + "_visit_type");
//获取当前人的探亲假配置
QFilter[] visitSetFilterArray = new QFilter[1];
visitSetFilterArray[0] = new QFilter(prefix+"_user", QCP.equals, applierId);
DynamicObject dynamicObject = QueryServiceHelper.queryOne( prefix+"_user_visit_set",
"id,zcgj_visit_times as visitTime,zcgj_visit_days as visitDays,zcgj_married_status as marriedStatus," +
"zcgj_married_parents_year as marriedParentsYear,zcgj_married_parents_time as marriedParentsTime," +
"zcgj_married_spouse_year as marriedSpouseYear,zcgj_married_spouse_time as marriedSpouseTime," +
"zcgj_unmarried_parents_y as unmarriedParentsYear,zcgj_unmarried_parents_t as unmarriedParentsTime",visitSetFilterArray);
if(dynamicObject == null){
this.getView().showErrorNotification("请设置人员探亲配置信息!");
//取消提交操作
args.setCancel(true);
return;
}
//探亲次数
int visitTime = 0;
//探亲年限
int visitYear = 0;
//总年探亲天数
int visitDays =dynamicObject.getInt("visitDays");
//婚姻状况1已婚2未婚
int marriedStatus =dynamicObject.getInt("marriedStatus");
//已婚探望父母年限
int marriedParentsYear =dynamicObject.getInt("marriedParentsYear");
//已婚探望父母次数
int marriedParentsTime =dynamicObject.getInt("marriedParentsTime");
//已婚探望配偶年限
int marriedSpouseYear =dynamicObject.getInt("marriedSpouseYear");
//已婚探望配偶次数
int marriedSpouseTime =dynamicObject.getInt("marriedSpouseTime");
//未婚探望父母年限
int unmarriedParentsYear =dynamicObject.getInt("unmarriedParentsYear");
//未婚探望父母次数
int unmarriedParentsTime =dynamicObject.getInt("unmarriedParentsTime");
if(visitDays == 0 ){
this.getView().showErrorNotification("人员探亲配置探亲假天数为空!");
//取消提交操作
args.setCancel(true);
return;
}
if(marriedStatus == 1 ){ // 已婚
if(marriedParentsYear == 0 ){
this.getView().showErrorNotification("人员探亲配置已婚探望父母年限为空!");
//取消提交操作
args.setCancel(true);
return;
}
if(marriedParentsTime == 0 ){
this.getView().showErrorNotification("人员探亲配置已婚探望父母次数为空!");
//取消提交操作
args.setCancel(true);
return;
}
if(marriedSpouseYear == 0 ){
this.getView().showErrorNotification("人员探亲配置已婚探望配偶年限为空!");
//取消提交操作
args.setCancel(true);
return;
}
if(marriedSpouseTime == 0 ){
this.getView().showErrorNotification("人员探亲配置已婚探望配偶次数为空!");
//取消提交操作
args.setCancel(true);
return;
}
//如果是探望父母
if("1".equals(visitType)){
visitYear = marriedParentsYear;
visitTime = marriedParentsTime;
}else
//如果是探望配偶
if("2".equals(visitType)){
visitTime = marriedSpouseTime;
visitYear = marriedSpouseYear;
}
}else if (marriedStatus == 2) { // 未婚
if(!"1".equals(visitType)){
this.getView().showErrorNotification("未婚状态下探亲类型只能选择探望父母!");
//取消提交操作
args.setCancel(true);
return;
}
if(unmarriedParentsYear == 0 ){
this.getView().showErrorNotification("人员探亲配置未婚探望父母年限为空!");
//取消提交操作
args.setCancel(true);
return;
}
if(unmarriedParentsTime == 0 ){
this.getView().showErrorNotification("人员探亲配置未婚探望父母次数为空!");
//取消提交操作
args.setCancel(true);
return;
}
visitTime = unmarriedParentsTime;
visitYear = unmarriedParentsYear;
}
Date firstDayOfYear = getFirstDayOfYear(startTime);
//年限开始时间
LocalDate firstDayYearsAgo = getFirstDayYearsAgo(dateToLocalDate(startTime), visitYear);
Date lastDayOfYear = getLastDayOfYear(startTime);
// 查询条件
QFilter[] filterArray = new QFilter[4];
//查询申请人下的今年的探亲差旅单据
filterArray[0] = new QFilter(prefix+"_holiday_start_time", QCP.large_equals, firstDayOfYear);
filterArray[1] = new QFilter(prefix+"_holiday_start_time", QCP.less_equals, lastDayOfYear);
filterArray[2] = new QFilter("applier", QCP.equals, applierId);
filterArray[3] = new QFilter(prefix+"_is_visit", 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",
filterArray, null
);
//使用请假总天数
long allHolidayCount = 0;
//使用请假总次数
int holidayCount = 0;
for (Row itemRow : dateSet) {
String string = itemRow.getString("billno");
Date startTimeVal = itemRow.getDate("startTime");
Date endTimeVal = itemRow.getDate("endTime");
long dayCount = ChronoUnit.DAYS.between(dateToLocalDate(startTimeVal), dateToLocalDate(endTimeVal));
allHolidayCount+=dayCount;
holidayCount++;
System.out.println(string);
}
//剩余次数
int remainderTimes = visitTime-holidayCount;
//剩余天数
long remainderDays = visitDays-allHolidayCount;
//判断剩余天数和本次请假天数
long nowDays = ChronoUnit.DAYS.between(dateToLocalDate(startTime),dateToLocalDate(endTime))+1;
String message = String.format("您在%s年到%s年中已用%d次探亲休假剩余%d次探亲休假已用%d天探亲天数剩余%d天探亲天数。本次休假天数%d天。"
,firstDayYearsAgo.getYear(),dateFormat.format(startTime),holidayCount,remainderTimes,
allHolidayCount,remainderDays,nowDays);
if((remainderTimes > 0) && (remainderDays >= 0) &&((remainderDays - nowDays) >=0)){
this.getView().showTipNotification(message);
}else{
this.getView().showErrorNotification("探亲次数或探亲天数不足!"+message);
//取消提交操作
args.setCancel(true);
return;
}
}
//判断是否来往家居地
Boolean isHome = (Boolean)model.getValue(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
);
Integer monthTime = null;
for (Row row : homeDataSet) {
monthTime = row.getInteger("monthTime");
}
//获取申请日期
Date bizdate = (Date)model.getValue( "bizdate");
//获取申请人在月份的单据量
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.getView().showTipNotification(message);
}
}
}
}
super.beforeDoOperation(args);
}catch (Exception e){
log.error(e.getMessage());
this.getView().showErrorNotification("系统异常");
}
}
/**
* 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

@ -0,0 +1,43 @@
package zcgj.zcdev.zcdev.fs.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.operate.Submit;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.sdk.plugin.Plugin;
import java.text.SimpleDateFormat;
/**
* 报销单附件控制插件
* 差旅报销费用报销对公报销
*/
public class ReimbursementCheckAttachmentPlugin extends AbstractBillPlugIn implements Plugin {
//开发商标识
private static final String prefix ="zcgj";
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
//zcgj_attachmentcount
Object source = args.getSource();
if(args.getSource() instanceof Submit){
// 根据类型进行安全转换
String operateKey = ((Submit) source).getOperateKey();
//重写返回的数据
if("submit".equals(operateKey)){
//提交时校验附件是否必填
IDataModel model = this.getModel();
int attachmentcount = Integer.parseInt(model.getValue(prefix+"_attachmentcount")+"");
if(attachmentcount == 0){
this.getView().showErrorNotification("请上传附件");
//取消提交操作
args.setCancel(true);
}
}
}
super.beforeDoOperation(args);
}
}

View File

@ -0,0 +1,57 @@
package zcgj.zcdev.zcdev.fs.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.operate.Save;
import kd.bos.entity.operate.Submit;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import java.text.SimpleDateFormat;
/**
* 来往家居地配置界面插件
*/
public class UserHomeConfPlugin extends AbstractBillPlugIn implements Plugin {
//开发商标识
private static final String prefix ="zcgj";
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
Object source = args.getSource();
if((args.getSource() instanceof Submit) || (args.getSource() instanceof Save)){
String operateKey = null;
// 根据类型进行安全转换
if (source instanceof Submit) {
operateKey = ((Submit) source).getOperateKey();
} else if (source instanceof Save) {
operateKey = ((Save) source).getOperateKey();
}
//重写返回的数据
if("submit".equals(operateKey) || "save".equals(operateKey)){
BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter();
if(bsp.getStatus()== OperationStatus.ADDNEW){
IDataModel model = this.getModel();
DynamicObject user = (DynamicObject)model.getValue(prefix+"_user");
long userId = user.getLong("id");
QFilter[] filterArray = new QFilter[1];
filterArray[0] = new QFilter(prefix+"_user", QCP.equals, userId);
DynamicObject[] logsToApprove = BusinessDataServiceHelper.load(prefix+"_user_home_conf", "id",filterArray );
if(logsToApprove!=null && logsToApprove.length>0){
this.getView().showErrorNotification("当前员工的配置已存在");
//取消提交操作
args.setCancel(true);
}
}
}
}
super.beforeDoOperation(args);
}
}

View File

@ -0,0 +1,52 @@
package zcgj.zcdev.zcdev.fs.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.operate.Save;
import kd.bos.entity.operate.Submit;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
/**
* 人员探亲配置界面插件
*/
public class UserVisitSetPlugin extends AbstractBillPlugIn implements Plugin {
//开发商标识
private static final String prefix ="zcgj";
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
Object source = args.getSource();
if((args.getSource() instanceof Submit) || (args.getSource() instanceof Save)){
String operateKey = null;
// 根据类型进行安全转换
if (source instanceof Submit) {
operateKey = ((Submit) source).getOperateKey();
} else if (source instanceof Save) {
operateKey = ((Save) source).getOperateKey();
}
if("submit".equals(operateKey) || "save".equals(operateKey)){
BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter();
if(bsp.getStatus()!=OperationStatus.ADDNEW){
DynamicObject user = (DynamicObject)this.getModel().getValue(prefix+"_user");
long userId = user.getLong("id");
QFilter[] filterArray = new QFilter[1];
filterArray[0] = new QFilter(prefix+"_user", QCP.equals, userId);
DynamicObject[] logsToApprove = BusinessDataServiceHelper.load(prefix+"_user_visit_set", "id",filterArray );
if(logsToApprove!=null && logsToApprove.length>0){
this.getView().showErrorNotification("无法添加,当前员工的配置信息已存在");
//取消提交操作
args.setCancel(true);
}
}
}
}
super.beforeDoOperation(args);
}
}