|
|
@@ -1,13 +1,20 @@
|
|
|
package nckd.xtpoc.fi.app.plugin.validate;
|
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
import kd.bos.entity.ExtendedDataEntity;
|
|
|
import kd.bos.entity.validate.AbstractValidator;
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* Tyx 费用报销单+付款单校验器
|
|
|
@@ -26,9 +33,89 @@ public class DailyReimBurseBillValidator extends AbstractValidator {
|
|
|
String msg = "申请日期所在期间已关账,不允许" + this.getOperationName();
|
|
|
this.addErrorMessage(dataEntity, msg);
|
|
|
}
|
|
|
+
|
|
|
+ //判断申请单发生日期与本单发生日期是否一致
|
|
|
+ checkDateDiff(dataEntity, bill);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查报销单与申请单之间的日期差异
|
|
|
+ * @param dataEntity 扩展数据实体
|
|
|
+ * @param bill 动态对象,包含报销单信息
|
|
|
+ */
|
|
|
+ private void checkDateDiff(ExtendedDataEntity dataEntity, DynamicObject bill) {
|
|
|
+ //附件数
|
|
|
+ int attachmentCount = bill.getInt("attachmentcount");
|
|
|
+ //费用分录
|
|
|
+ DynamicObjectCollection expenseEntryEntity = bill.getDynamicObjectCollection("expenseentryentity");
|
|
|
+ if (expenseEntryEntity.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //关联申请分录
|
|
|
+ DynamicObjectCollection writeOffApply = bill.getDynamicObjectCollection("writeoffapply");
|
|
|
+ if (writeOffApply.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> sourceApplyBillId = writeOffApply.stream()
|
|
|
+ .map(e -> Long.valueOf(e.getString("sourceapplybillid")))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //根据申请单id查询申请单
|
|
|
+ Map<Object, DynamicObject> erDailyApplyMap = BusinessDataServiceHelper.loadFromCache(sourceApplyBillId.toArray(new Long[0]), "er_dailyapplybil");
|
|
|
+
|
|
|
+
|
|
|
+ for (DynamicObject entry : expenseEntryEntity) {
|
|
|
+ Date entryDate = entry.getDate("happendate");
|
|
|
+ if(entryDate == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //费用项目字段
|
|
|
+ String expenseItem = entry.getString("expenseitem.number");
|
|
|
+
|
|
|
+ //遍历查询关联申请分录
|
|
|
+ for (DynamicObject apply : writeOffApply) {
|
|
|
+ String expenseApply = apply.getString("expenseitemfield.number");
|
|
|
+ long sourceEntryId = apply.getLong("sourceapplyentryid");
|
|
|
+ Long sourceBillId = apply.getLong("sourceapplybillid");
|
|
|
+
|
|
|
+ //分录对象
|
|
|
+ List<DynamicObject> entryApply = erDailyApplyMap.get(sourceBillId)
|
|
|
+ .getDynamicObjectCollection("expenseentryentity")
|
|
|
+ .stream()
|
|
|
+ .filter(e -> e.getLong("id") == sourceEntryId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if(entryApply.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //费用项目相同的分录比较
|
|
|
+ if(expenseApply.equals(expenseItem)) {
|
|
|
+ Date applyDate = entryApply.get(0).getDate("happendate");
|
|
|
+ if (applyDate == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //发生时间不同,并且附件数为0情况下
|
|
|
+ if (!isSameDate(entryDate, applyDate) && attachmentCount == 0) {
|
|
|
+ String msg = "报销单时间不等于申请单费用发生时间,请进行确认,并上传附件说明。";
|
|
|
+ this.addErrorMessage(dataEntity, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean isSameDate(Date date1, Date date2) {
|
|
|
+ if (date1 == null || date2 == null) return false;
|
|
|
+
|
|
|
+ Calendar cal1 = Calendar.getInstance();
|
|
|
+ cal1.setTime(date1);
|
|
|
+ Calendar cal2 = Calendar.getInstance();
|
|
|
+ cal2.setTime(date2);
|
|
|
+
|
|
|
+ return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
|
|
+ cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
|
|
|
+ cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 根据时间判断是否存在关账的账期管理
|