1.报销单发票日期和关联申请审核日期校验

This commit is contained in:
zhangzhiguo 2025-06-16 10:40:38 +08:00
parent fab05e56c7
commit 430132a78a
1 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,111 @@
package zcgj.zcdev.zcdev.fs.plugin.operate;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
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.servicehelper.user.UserServiceHelper;
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 报销单发票日期和关联申请审核日期校验
*/
public class ReimbursementInvoiceDateCkOp extends AbstractOperationServicePlugIn {
@Override
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("costcompany");
//e.getFieldKeys().add("accountentry");
e.getFieldKeys().add("writeoffapply");
e.getFieldKeys().add("invoiceentry");
}
@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");
//获取申请日期
Object costcompanyObj = dataEntity.get("costcompany");
Object costdeptObj = dataEntity.get("costdept");
if(costcompanyObj!=null && costdeptObj != null){
DynamicObject costcompany = (DynamicObject)costcompanyObj;
long costcompanyId = costcompany.getLong("id");
if(OrgCheckUtils.isKS(costcompanyId)){
DynamicObjectCollection writeoffapply = dataEntity.getDynamicObjectCollection("writeoffapply");
if(writeoffapply!=null&&writeoffapply.size()==1){
DynamicObject writeoffapplyObj = writeoffapply.get(0);
Date zcgjGlsqAuditdate = writeoffapplyObj.getDate("zcgj_glsq_auditdate");
DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");
Map<String,LocalDate> invoiceDateMap = new HashMap<>();
for (DynamicObject invoiceentryObject : invoiceentry) {
if (invoiceentryObject.getDate("invoicedate") != null && invoiceentryObject.getString("invoiceno") != null &&
!StringUtils.isEmpty(invoiceentryObject.getString("invoiceno"))) {
invoiceDateMap.put(invoiceentryObject.getString("invoiceno"),dateToLocalDate(invoiceentryObject.getDate("invoicedate")));
}
}
for (String invoiceno : invoiceDateMap.keySet()) {
LocalDate invoiceDate = invoiceDateMap.get(invoiceno);
if (invoiceDate.isBefore(dateToLocalDate(zcgjGlsqAuditdate))) {
// System.out.println("date1 比 date2 早");
this.addFatalErrorMessage(extendedDataEntity, String.format("发票号码为:%s的发票开票日期不能早于关联申请的审核时间",invoiceno));
}
}
}
}
}
}
}
}
/**
* java.util.Date 转换为 java.time.LocalDate
* @param date java.util.Date
* @return java.time.LocalDate
*/
public static LocalDate dateToLocalDate(Date date) {
return date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}
}