修改套餐规则

This commit is contained in:
wuweihua
2026-10-28 18:10:10 +08:00
parent 2bd417b84e
commit 8ed7b3146b
21 changed files with 536 additions and 411 deletions
@@ -546,16 +546,29 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
throw new ServiceException(MessageUtils.message("price.set.version.notExists"));
}
// Draft and pending versions may be deleted; effect/expired cannot.
if (!VER_DRAFT.equals(version.getStatus()) && !VER_PENDING.equals(version.getStatus()))
if ("1".equals(version.getIsDel()))
{
throw new ServiceException(MessageUtils.message("price.set.version.notExists"));
}
// Draft / pending: hard delete; EFFECT: soft delete then reopen previous via refreshVersionStatus
if (!VER_DRAFT.equals(version.getStatus())
&& !VER_PENDING.equals(version.getStatus())
&& !VER_EFFECT.equals(version.getStatus()))
{
throw new ServiceException(MessageUtils.message("price.set.version.delete.statusNotAllowed"));
}
requireSet(version.getPriceSetId());
// Draft / pending only reach here: hard-delete children with the version row
wipeVersionChildren(psvId, version.getStatus());
int rows = versionMapper.deletePrcPriceSetVersionByIds(new Long[] { psvId });
// Rechain expire_time / status for remaining versions (e.g. reopen previous effect window)
int rows;
if (VER_EFFECT.equals(version.getStatus()))
{
rows = versionMapper.softDeleteById(psvId, updateBy);
}
else
{
rows = versionMapper.deletePrcPriceSetVersionByIds(new Long[] { psvId });
}
// Rechain expire_time / status for remaining versions (reopen previous effect window)
refreshVersionStatus(version.getPriceSetId());
return rows;
}
@@ -193,8 +193,9 @@ public class CatalogVersionSupport
}
/**
* Hard-delete draft/pending catalog version with products, details,
* surcharge links and excel attachments.
* Delete catalog version:
* - draft / pending: hard-delete version + children + excel
* - effect: soft-delete version + products + details (+ surcharge rel)
*/
public int deleteDraftVersion(Long psvId)
{
@@ -204,9 +205,17 @@ public class CatalogVersionSupport
throw new ServiceException("版本不存在");
}
assertCatalogType(ver.getPriceType());
if ("1".equals(ver.getIsDel()))
{
throw new ServiceException("版本已删除");
}
if (STATUS_EFFECT.equals(ver.getStatus()))
{
return softDeleteEffectVersion(ver);
}
if (!STATUS_DRAFT.equals(ver.getStatus()) && !STATUS_PENDING.equals(ver.getStatus()))
{
throw new ServiceException("仅草稿或待生效版本可以删除");
throw new ServiceException("仅草稿、待生效或已生效版本可以删除");
}
surchargeRelMapper.physicalDeleteByPsvId(psvId);
detailMapper.physicalDeleteByPsvId(psvId);
@@ -215,6 +224,89 @@ public class CatalogVersionSupport
return versionMapper.deletePrcPriceSetVersionByIds(new Long[] { psvId });
}
/**
* Soft-delete EFFECT version with products and details,
* then reopen the previous version as EFFECT (clear expire_time;
* product/detail expire cleared via syncEffect).
*/
private int softDeleteEffectVersion(PrcPriceSetVersion ver)
{
Long psvId = ver.getPsvId();
String priceType = ver.getPriceType();
surchargeRelMapper.softDeleteByPsvId(psvId);
detailMapper.deletePrcPriceSetDetailByPsvId(psvId);
productMapper.deleteByPsvId(psvId);
int rows = versionMapper.softDeleteById(psvId, null);
PrcPriceSetVersion prev = findPreviousVersionToRestore(ver);
if (prev != null)
{
prev.setExpireTime(null);
prev.setStatus(STATUS_EFFECT);
versionMapper.updatePrcPriceSetVersion(prev);
}
refreshCatalogStatuses(priceType);
return rows;
}
/**
* Previous catalog version (highest version_seq below deleted) that can become EFFECT again.
* Prefers expired/effect rows that already had an effective_time.
*/
private PrcPriceSetVersion findPreviousVersionToRestore(PrcPriceSetVersion deleted)
{
if (deleted == null || deleted.getPriceType() == null)
{
return null;
}
PrcPriceSetVersion q = new PrcPriceSetVersion();
q.setPriceType(deleted.getPriceType());
List<PrcPriceSetVersion> list = versionMapper.selectPrcPriceSetVersionList(q);
if (list == null || list.isEmpty())
{
return null;
}
int curSeq = deleted.getVersionSeq() == null ? 0 : deleted.getVersionSeq().intValue();
PrcPriceSetVersion best = null;
int bestSeq = Integer.MIN_VALUE;
Date now = new Date();
for (PrcPriceSetVersion v : list)
{
if (v == null || v.getPsvId() == null)
{
continue;
}
if (deleted.getPsvId() != null && deleted.getPsvId().equals(v.getPsvId()))
{
continue;
}
if (v.getEffectiveTime() == null)
{
continue;
}
// Skip future pending drafts: they are not "previous" effective windows
if (STATUS_PENDING.equals(v.getStatus()) && v.getEffectiveTime().after(now))
{
continue;
}
if (STATUS_DRAFT.equals(v.getStatus()))
{
continue;
}
int seq = v.getVersionSeq() == null ? 0 : v.getVersionSeq().intValue();
if (seq >= curSeq)
{
continue;
}
if (seq > bestSeq)
{
bestSeq = seq;
best = v;
}
}
return best;
}
/** Current draft version (status=0), or null. */
public PrcPriceSetVersion currentDraft(String priceType)
{
@@ -222,7 +314,10 @@ public class CatalogVersionSupport
return drafts.isEmpty() ? null : drafts.get(0);
}
/** Draft/pending catalog version that can accept preview apply / edit. */
/**
* Catalog version that can accept preview apply / Excel attach / edit.
* Same as sales force-edit: draft, pending, and effect are writable.
*/
public PrcPriceSetVersion requireEditableCatalogVersion(Long psvId, String priceType)
{
PrcPriceSetVersion ver = versionMapper.selectPrcPriceSetVersionById(psvId);
@@ -235,9 +330,15 @@ public class CatalogVersionSupport
{
throw new ServiceException("版本类型不匹配");
}
if (!STATUS_DRAFT.equals(ver.getStatus()) && !STATUS_PENDING.equals(ver.getStatus()))
if ("1".equals(ver.getIsDel()))
{
throw new ServiceException("仅草稿或待生效版本可以编辑");
throw new ServiceException("版本已删除");
}
if (!STATUS_DRAFT.equals(ver.getStatus())
&& !STATUS_PENDING.equals(ver.getStatus())
&& !STATUS_EFFECT.equals(ver.getStatus()))
{
throw new ServiceException("仅草稿、待生效或已生效版本可以编辑");
}
return ver;
}