From 485f13a90766d53b91b3b67124d54157c94afbba Mon Sep 17 00:00:00 2001 From: lihao Date: Thu, 19 Jun 2025 10:39:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E6=8D=AE=E6=97=A5=E6=9C=9F=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baseinfo/BillDateCheckListener.java | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 uapbd/src/private/nc/impl/bd/material/baseinfo/BillDateCheckListener.java diff --git a/uapbd/src/private/nc/impl/bd/material/baseinfo/BillDateCheckListener.java b/uapbd/src/private/nc/impl/bd/material/baseinfo/BillDateCheckListener.java new file mode 100644 index 0000000..3e4f338 --- /dev/null +++ b/uapbd/src/private/nc/impl/bd/material/baseinfo/BillDateCheckListener.java @@ -0,0 +1,104 @@ +package nc.impl.bd.material.baseinfo; + +import nc.bs.businessevent.IBusinessEvent; +import nc.bs.businessevent.IBusinessListener; +import nc.bs.businessevent.bd.BDCommonEvent; +import nc.bs.ic.general.businessevent.ICGeneralCommonEvent; +import nc.vo.ic.m45.entity.PurchaseInBodyVO; +import nc.vo.ic.m45.entity.PurchaseInHeadVO; +import nc.vo.ic.m45.entity.PurchaseInVO; +import nc.vo.ic.m4c.entity.SaleOutVO; +import nc.vo.ic.m4d.entity.MaterialOutVO; +import nc.vo.pub.AggregatedValueObject; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDate; + +import java.util.Calendar; +import java.util.Date; + +public class BillDateCheckListener implements IBusinessListener { + + public void doAction(IBusinessEvent event) throws BusinessException { + ICGeneralCommonEvent.ICGeneralCommonUserObj obj = (ICGeneralCommonEvent.ICGeneralCommonUserObj)event.getUserObject(); + AggregatedValueObject[] newBillVOs = (AggregatedValueObject[])obj.getNewObjects(); + if (newBillVOs == null) { + newBillVOs = (AggregatedValueObject[])obj.getOldObjects(); + } +// AggregatedValueObject[] oldBillVOs = (AggregatedValueObject[])obj.getOldObjects(); + //检查日期是否符合 每月24日后在系统做单据的时候,对未改系统日期到次月1日制单的情况,增加提示来提醒更改单据日期,否则无法保存,更改的日期不能超过当月24日后10天。 +// "1001".equals(event.getEventType()) + for(int i = 0; i < newBillVOs.length; ++i) { + Object newObj = newBillVOs[i]; + if (newObj instanceof PurchaseInVO) { + PurchaseInVO newVO = (PurchaseInVO)newObj; + UFDate billDate = newVO.getHead().getDbilldate(); + + Date currentDate = new Date(); + Date billDateObj = billDate.toDate(); + if (!this.validateBillDate(billDateObj,currentDate)) { + throw new BusinessException("当前日期已过当月24号,必须在下月制单且单据日期必须超过当月24号后10天"); + } + }else if(newObj instanceof SaleOutVO){ + SaleOutVO newVO = (SaleOutVO)newObj; + UFDate billDate = newVO.getHead().getDbilldate(); + +// Date currentDate = new Date(2025,6,25); + Date currentDate = new Date(); + Date billDateObj = billDate.toDate(); + + if (!this.validateBillDate(billDateObj,currentDate)) { + throw new BusinessException("当前日期已过当月24号,必须在下月制单且单据日期必须超过当月24号后10天"); + } + + }else if(newObj instanceof MaterialOutVO){ + MaterialOutVO newVO = (MaterialOutVO)newObj; + UFDate billDate = newVO.getHead().getDbilldate(); + + Date currentDate = new Date(); + Date billDateObj = billDate.toDate(); + if (!this.validateBillDate(billDateObj,currentDate)) { + throw new BusinessException("当前日期已过当月24号,必须在下月制单且单据日期必须超过当月24号后10天"); + } + } + } + + } + + + public boolean validateBillDate(Date billDateObj, Date currentDate) { + Calendar currentCal = Calendar.getInstance(); + currentCal.setTime(currentDate); + + Calendar billCal = Calendar.getInstance(); + billCal.setTime(billDateObj); + + // 获取当前日期的月份和日 + int currentDay = currentCal.get(Calendar.DAY_OF_MONTH); + int currentMonth = currentCal.get(Calendar.MONTH); + int currentYear = currentCal.get(Calendar.YEAR); + + // 只有当当前日期是25号到月底时才需要校验 + if (currentDay >= 15) { + // 1. 计算本月24号+10天的最大允许日期 + Calendar maxDateCal = Calendar.getInstance(); + maxDateCal.set(currentYear, currentMonth, 24); // 本月24号 + maxDateCal.add(Calendar.DATE, 10); // 24号+10天 + + // 2. 计算下个月1号的最小允许日期 + Calendar minDateCal = Calendar.getInstance(); + minDateCal.set(currentYear, currentMonth, 1); // 本月1号 + minDateCal.add(Calendar.MONTH, 1); // 下个月1号 + + // 3. 检查单据日期是否在下个月范围内 + boolean isNextMonth = billCal.get(Calendar.MONTH) == minDateCal.get(Calendar.MONTH) && + billCal.get(Calendar.YEAR) == minDateCal.get(Calendar.YEAR); + + // 4. 检查单据日期是否在允许范围内(下个月1号 至 本月24号+10天) + if (!isNextMonth || billCal.after(maxDateCal) || billCal.before(minDateCal)) { + return false; + } + } + + return true; + } +}