到货单制单日期校验

This commit is contained in:
lihao 2025-10-21 18:45:03 +08:00
parent 509fab347d
commit 6dbe4d310f
1 changed files with 116 additions and 93 deletions

View File

@ -6,6 +6,7 @@
package nc.impl.pu.m23.maintain.rule;
import nc.bs.framework.common.NCLocator;
import nc.bs.trade.business.HYPubBO;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.pubitf.so.m30.api.ISaleOrderQueryAPI;
import nc.vo.pu.m21.entity.OrderItemVO;
@ -18,6 +19,7 @@ import nc.vo.so.m30.entity.SaleOrderBVO;
import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class CheckBillDateRule implements IRule<ArriveVO> {
@ -35,8 +37,13 @@ public class CheckBillDateRule implements IRule<ArriveVO> {
if (vo == null || vo.getHVO() == null) {
throw new BusinessException("到货单主信息不能为空");
}
Date arriveMakeDate = null != vo.getHVO().getDmakedate() ? vo.getHVO().getDmakedate().toDate(): new Date() ;
// 只校验箱变
HYPubBO hybo = new HYPubBO();
String org = hybo.findColValue("org_adminorg", "pk_adminorg", " code = 'C030' ") + "";
if(!vo.getHVO().getPk_org().equals(org)){
continue;
}
Date arriveMakeDate = null != vo.getHVO().getDbilldate() ? vo.getHVO().getDbilldate().toDate(): new Date() ;
// 校验制单日期是否存在
if (arriveMakeDate == null) {
throw new BusinessException("到货单制单日期不能为空");
@ -90,10 +97,10 @@ public class CheckBillDateRule implements IRule<ArriveVO> {
Date earliestAllowedDate = addDays(expectArriveDate, -3);
// 2. 判断规则
boolean isTooEarly = arriveMakeDate.before(earliestAllowedDate);
boolean isTooLate = arriveMakeDate.after(expectArriveDate);
boolean isTooEarly =clearTime(arriveMakeDate).before(clearTime(earliestAllowedDate));
// boolean isTooLate = arriveMakeDate.after(expectArriveDate);
if (isTooEarly || isTooLate) {
// if (isTooEarly || isTooLate) {
String errorMsg;
if (isTooEarly) {
errorMsg = String.format(
@ -104,15 +111,15 @@ public class CheckBillDateRule implements IRule<ArriveVO> {
o.getHVO().getVbillcode(),
orderItem.getCrowno()
);
} else { // isTooLate
errorMsg = String.format(
"到货单制单日期(%s)晚于采购订单预计到货时间(%s),不符合提前到货规则,不允许保存。订单编号:%s明细行号%s",
formatDate(arriveMakeDate),
formatDate(expectArriveDate),
o.getHVO().getVbillcode(),
orderItem.getCrowno()
);
}
// } else { // isTooLate
// errorMsg = String.format(
// "到货单制单日期(%s)晚于采购订单预计到货时间(%s),不符合提前到货规则,不允许保存。订单编号:%s明细行号%s",
// formatDate(arriveMakeDate),
// formatDate(expectArriveDate),
// o.getHVO().getVbillcode(),
// orderItem.getCrowno()
// );
// }
throw new BusinessException(errorMsg);
}
break; // 找到匹配明细后退出循环
@ -160,6 +167,22 @@ public class CheckBillDateRule implements IRule<ArriveVO> {
return DATE_FORMATTER.format(date);
}
}
/**
* 清除日期中的时间部分只保留年月日
*/
private static Date clearTime(Date date) {
if (date == null) {
return null;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
// 将时间部分设置为0
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
}