增加删除功能

This commit is contained in:
wuweihua
2026-10-10 13:52:28 +08:00
parent fab2ec7d9c
commit eeaea52c17
8 changed files with 144 additions and 4 deletions
@@ -174,6 +174,9 @@ public class BmsProductServiceImpl implements IBmsProductService
return 0;
}
List<String> codesNoRemain = new ArrayList<>();
List<Long> deletableIds = new ArrayList<>();
List<String> notPendingTips = new ArrayList<>();
List<BmsProduct> toReopen = new ArrayList<>();
for (Long id : productIds)
{
BmsProduct p = productMapper.selectBmsProductById(id);
@@ -181,14 +184,46 @@ public class BmsProductServiceImpl implements IBmsProductService
{
continue;
}
String liveStatus = resolveStoredStatus(p.getEffectiveDate(), p.getExpireDate());
if (!BmsProduct.STATUS_PENDING.equals(liveStatus))
{
String tip = p.getProductCode();
if (p.getEffectiveDate() != null)
{
tip = tip + "(" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(p.getEffectiveDate()) + ")";
}
notPendingTips.add(tip);
continue;
}
if (p.getProductId() != null)
{
countryMapper.deleteByProductId(p.getProductId());
}
countryMapper.deleteByProductCodeAndEffectiveDate(p.getProductCode(), p.getEffectiveDate());
codesNoRemain.add(p.getProductCode());
deletableIds.add(p.getProductId());
if (p.getEffectiveDate() != null)
{
toReopen.add(p);
}
}
int rows = productMapper.deleteBmsProductByIds(productIds);
if (!notPendingTips.isEmpty())
{
throw new ServiceException(MessageUtils.message("price.product.delete.pendingOnly",
String.join("\u3001", notPendingTips)));
}
if (deletableIds.isEmpty())
{
return 0;
}
int rows = productMapper.deleteBmsProductByIds(deletableIds.toArray(new Long[0]));
for (BmsProduct p : toReopen)
{
productMapper.reopenExpiredByProductCodeAndExpireDate(p.getProductCode(), p.getEffectiveDate());
countryMapper.reopenExpiredByProductCodeAndExpireDate(p.getProductCode(), p.getEffectiveDate());
}
productMapper.refreshStatusByDates();
countryMapper.refreshStatusByDates();
List<String> orphanCodes = new ArrayList<>();
for (String code : codesNoRemain)
{