增加软删除

This commit is contained in:
wuweihua
2026-10-12 09:52:24 +08:00
parent 5aba8af49d
commit d08485d738
25 changed files with 561 additions and 101 deletions
@@ -31,7 +31,12 @@ public class BmsProduct extends BaseEntity
public static final String STATUS_PENDING = "0";
public static final String STATUS_ACTIVE = "1";
public static final String STATUS_EXPIRED = "2";
/** 0未删除 1已删除 */
public static final String IS_DEL_NO = "0";
public static final String IS_DEL_YES = "1";
private String status;
/** 0未删除 1已删除 */
private String isDel;
private String sourceSheet;
/** FK prc_price_excel_file.pef_id */
private Long pefId;
@@ -40,6 +40,10 @@ public class BmsProductCountry implements Serializable
private Date expireDate;
/** 0 pending, 1 active, 2 expired */
private String status;
/** 0未删除 1已删除 */
public static final String IS_DEL_NO = "0";
public static final String IS_DEL_YES = "1";
private String isDel;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -31,7 +31,12 @@ public class BmsRedlineProduct extends BaseEntity
public static final String STATUS_PENDING = "0";
public static final String STATUS_ACTIVE = "1";
public static final String STATUS_EXPIRED = "2";
/** 0未删除 1已删除 */
public static final String IS_DEL_NO = "0";
public static final String IS_DEL_YES = "1";
private String status;
/** 0未删除 1已删除 */
private String isDel;
private String sourceSheet;
/** FK prc_price_excel_file.pef_id */
private Long pefId;
@@ -38,6 +38,10 @@ public class BmsRedlineProductCountry implements Serializable
private Date expireDate;
/** 0 pending, 1 active, 2 expired */
private String status;
/** 0未删除 1已删除 */
public static final String IS_DEL_NO = "0";
public static final String IS_DEL_YES = "1";
private String isDel;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -24,6 +24,10 @@ public class PrcSurcharge extends BaseEntity
private String roundMode;
/** on / of */
private String ssCode;
/** 0未删除 1已删除 */
public static final String IS_DEL_NO = "0";
public static final String IS_DEL_YES = "1";
private String isDel;
private String countryCode;
private String scNote;
private Long tmsId;
@@ -37,6 +37,10 @@ public class PrcSurchargeRel extends BaseEntity
private String priceType;
/** 适用国家ISO2(空=全部),rel 表字段 */
private String countryCode;
/** 0未删除 1已删除 */
public static final String IS_DEL_NO = "0";
public static final String IS_DEL_YES = "1";
private String isDel;
/** 附加费冗余展示字段 */
private String scName;
@@ -23,10 +23,13 @@ public interface BmsProductCountryMapper
/** Import overlay: update price/zone/attrs on matched country row */
public int updateBmsProductCountryImport(BmsProductCountry country);
/** Soft delete by product_id */
public int deleteByProductId(Long productId);
/** Soft delete by product_code */
public int deleteByProductCode(String productCode);
/** Soft delete by product_code + effective_date */
public int deleteByProductCodeAndEffectiveDate(
@Param("productCode") String productCode,
@Param("effectiveDate") Date effectiveDate);
@@ -31,6 +31,7 @@ public interface BmsProductMapper
public int updateBmsProduct(BmsProduct product);
/** Soft delete: set del_flag = 2 */
public int deleteBmsProductByIds(Long[] productIds);
/** Close previous open versions: expire_date = newEffectiveDate */
@@ -39,6 +39,11 @@ public interface BmsRedlineProductCountryMapper
@Param("productCode") String productCode,
@Param("newEffectiveDate") Date newEffectiveDate);
/** After deleting a pending version: reopen rows closed at that effective date */
public int reopenExpiredByProductCodeAndExpireDate(
@Param("productCode") String productCode,
@Param("expireDate") Date expireDate);
/**
* Close open rows for one product + country where effective_date < newEffectiveDate.
* Match by country_code when present, otherwise country_name.
@@ -39,6 +39,11 @@ public interface BmsRedlineProductMapper
@Param("newEffectiveDate") Date newEffectiveDate,
@Param("excludeId") Long excludeId);
/** After deleting a pending version: reopen rows closed at that effective date */
public int reopenExpiredByProductCodeAndExpireDate(
@Param("productCode") String productCode,
@Param("expireDate") Date expireDate);
/** Recompute status from effective_date / expire_date vs today */
public int refreshStatusByDates();
}
@@ -174,6 +174,9 @@ public class BmsRedlineProductServiceImpl implements IBmsRedlineProductService
{
return 0;
}
List<Long> deletableIds = new ArrayList<Long>();
List<String> notPendingTips = new ArrayList<String>();
List<BmsRedlineProduct> toReopen = new ArrayList<BmsRedlineProduct>();
List<Long> relProductIds = new ArrayList<Long>();
for (Long id : productIds)
{
@@ -182,19 +185,51 @@ public class BmsRedlineProductServiceImpl implements IBmsRedlineProductService
{
continue;
}
String liveStatus = resolveStoredStatus(p.getEffectiveDate(), p.getExpireDate());
if (!BmsRedlineProduct.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());
relProductIds.add(p.getProductId());
}
countryMapper.deleteByProductCodeAndEffectiveDate(p.getProductCode(), p.getEffectiveDate());
deletableIds.add(p.getProductId());
if (p.getEffectiveDate() != null)
{
toReopen.add(p);
}
}
if (!notPendingTips.isEmpty())
{
throw new ServiceException(MessageUtils.message("price.redline.delete.pendingOnly",
String.join("\u3001", notPendingTips)));
}
if (deletableIds.isEmpty())
{
return 0;
}
if (!relProductIds.isEmpty())
{
// REDLINE rels bind redline_product.product_id (not shared with product catalog)
surchargeRelMapper.deleteByProductIdsAndPriceType(relProductIds, PrcSurchargeRel.PRICE_TYPE_REDLINE);
}
return productMapper.deleteBmsRedlineProductByIds(productIds);
int rows = productMapper.deleteBmsRedlineProductByIds(deletableIds.toArray(new Long[0]));
for (BmsRedlineProduct p : toReopen)
{
productMapper.reopenExpiredByProductCodeAndExpireDate(p.getProductCode(), p.getEffectiveDate());
countryMapper.reopenExpiredByProductCodeAndExpireDate(p.getProductCode(), p.getEffectiveDate());
}
productMapper.refreshStatusByDates();
countryMapper.refreshStatusByDates();
return rows;
}
@Override