优化套餐新建版本的逻辑

This commit is contained in:
wuweihua
2026-10-28 22:09:30 +08:00
parent 786feec859
commit 56340d0ea0
7 changed files with 177 additions and 47 deletions
@@ -205,6 +205,7 @@ price.bill.fee.idRequired=费用ID不能为空
price.set.version.effectiveTime.empty=版本生效时间不能为空
price.set.version.effectiveTime.beforePrev=生效时间不能早于上一版本的生效时间
price.set.version.effectiveTime.hitBoundary=生效时间不能与已有版本的生效时间或失效时间相同
price.set.version.notExists=套餐版本不存在
price.set.version.activate.statusNotAllowed=仅草稿或待生效版本可设置生效时间
price.set.version.delete.statusNotAllowed=仅草稿、待生效或已生效版本可删除
@@ -401,10 +401,20 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
throw new ServiceException(MessageUtils.message("price.set.edit.stopped"));
}
Date prevEffective = findPrevVersionEffectiveTime(version);
if (prevEffective != null && effectiveTime.before(prevEffective))
boolean importFresh = "IMPORT_FRESH".equalsIgnoreCase(StringUtils.trim(version.getPriceBuildMode()));
if (importFresh)
{
throw new ServiceException(MessageUtils.message("price.set.version.effectiveTime.beforePrev"));
// May start inside a prior version window; forbid equal to any other version's eff/exp.
// refreshVersionStatus then sets B.expire=A.eff, A.expire=B.oldExpire and syncs children.
validateImportFreshActivateTime(version, effectiveTime);
}
else
{
Date prevEffective = findPrevVersionEffectiveTime(version);
if (prevEffective != null && effectiveTime.before(prevEffective))
{
throw new ServiceException(MessageUtils.message("price.set.version.effectiveTime.beforePrev"));
}
}
// Set schedule; refreshVersionStatus decides PENDING(3) vs EFFECT(1) and chains expire_time
version.setEffectiveTime(effectiveTime);
@@ -415,6 +425,41 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
return 1;
}
/**
* IMPORT_FRESH activate: allow effective time earlier than prev-by-seq (incl. inside prior window B).
* Must not equal any other timed version's effectiveTime or expireTime.
*/
private void validateImportFreshActivateTime(PrcPriceSetVersion version, Date effectiveTime)
{
if (version == null || version.getPriceSetId() == null || effectiveTime == null)
{
return;
}
PrcPriceSetVersion q = new PrcPriceSetVersion();
q.setPriceSetId(version.getPriceSetId());
q.setPriceType(com.bms.price.domain.PriceType.SALES);
List<PrcPriceSetVersion> list = versionMapper.selectPrcPriceSetVersionList(q);
if (list == null || list.isEmpty())
{
return;
}
for (PrcPriceSetVersion v : list)
{
if (v == null)
{
continue;
}
if (version.getPsvId() != null && version.getPsvId().equals(v.getPsvId()))
{
continue;
}
if (sameTime(v.getEffectiveTime(), effectiveTime) || sameTime(v.getExpireTime(), effectiveTime))
{
throw new ServiceException(MessageUtils.message("price.set.version.effectiveTime.hitBoundary"));
}
}
}
/** Previous version (lower version_seq) effective_time; null if none. */
private Date findPrevVersionEffectiveTime(PrcPriceSetVersion version)
{