增加删除功能
This commit is contained in:
@@ -112,6 +112,7 @@ price.zone.countryCode.empty=国家编码不能为空,请检查 region.country
|
||||
# 产品导入 BmsProduct
|
||||
price.product.codeDate.exists=同一产品代码与生效日期已存在,不能覆盖历史数据
|
||||
price.product.effectiveDate.empty=生效日期不能为空
|
||||
price.product.delete.pendingOnly=仅待生效产品可删除,以下不符合:{0}
|
||||
price.product.import.effEmpty=缺少生效日期,已跳过
|
||||
price.product.import.effRequired=请选择生效时间
|
||||
price.product.import.fileEmpty=上传文件不能为空
|
||||
|
||||
@@ -39,6 +39,11 @@ public interface BmsProductCountryMapper
|
||||
@Param("productCode") String productCode,
|
||||
@Param("newEffectiveDate") Date newEffectiveDate);
|
||||
|
||||
/** After deleting a pending version: reopen country 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 BmsProductMapper
|
||||
@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();
|
||||
}
|
||||
|
||||
+36
-1
@@ -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)
|
||||
{
|
||||
|
||||
@@ -171,6 +171,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
and (effective_date is null or effective_date < #{newEffectiveDate})
|
||||
</update>
|
||||
|
||||
<update id="reopenExpiredByProductCodeAndExpireDate">
|
||||
update product_country
|
||||
set expire_date = null,
|
||||
update_time = sysdate()
|
||||
where product_code = #{productCode}
|
||||
and expire_date = #{expireDate}
|
||||
</update>
|
||||
|
||||
<update id="expireOpenByProductCodeAndCountry">
|
||||
update product_country
|
||||
set expire_date = #{newEffectiveDate},
|
||||
|
||||
@@ -207,6 +207,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<update id="reopenExpiredByProductCodeAndExpireDate">
|
||||
update product
|
||||
set expire_date = null,
|
||||
update_time = sysdate()
|
||||
where product_code = #{productCode}
|
||||
and expire_date = #{expireDate}
|
||||
</update>
|
||||
|
||||
<update id="refreshStatusByDates">
|
||||
update product
|
||||
set status = case
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
-- Add product batch-delete button permission (idempotent)
|
||||
SET @menuId := (
|
||||
SELECT menu_id FROM sys_menu
|
||||
WHERE perms = 'price:product:list' OR component LIKE '%price/basic/product%'
|
||||
ORDER BY menu_id ASC LIMIT 1
|
||||
);
|
||||
|
||||
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time)
|
||||
SELECT '产品删除', @menuId, 6, '', '', 1, 0, 'F', '0', '0', 'price:product:remove', '#', 'admin', sysdate()
|
||||
WHERE @menuId IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'price:product:remove');
|
||||
Reference in New Issue
Block a user