From 430132a78a5016b1400245608c6569479fcacb5a Mon Sep 17 00:00:00 2001 From: zhangzhiguo Date: Mon, 16 Jun 2025 10:40:38 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8A=A5=E9=94=80=E5=8D=95=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=92=8C=E5=85=B3=E8=81=94=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E6=97=A5=E6=9C=9F=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operate/ReimbursementInvoiceDateCkOp.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/ReimbursementInvoiceDateCkOp.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/ReimbursementInvoiceDateCkOp.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/ReimbursementInvoiceDateCkOp.java new file mode 100644 index 0000000..d9d0a65 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/ReimbursementInvoiceDateCkOp.java @@ -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> allMap = new HashMap<>(); + //当前提交的探亲单据id集合 + Map> 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 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(); + } +}