增加软删除

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
@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="effectiveDate" column="effective_date" />
<result property="expireDate" column="expire_date" />
<result property="status" column="status" />
<result property="isDel" column="is_del" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="effectStatus" column="status" />
@@ -33,13 +34,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.zone_id, c.zone_code, c.zone_name,
c.weight_min, c.weight_max,
c.freight_price, c.registration_fee, c.size_limit, c.last_mile, c.lead_time,
c.effective_date, c.expire_date, c.status, c.create_time, c.update_time
c.effective_date, c.expire_date, c.status, c.is_del, c.create_time, c.update_time
from product_country c
</sql>
<select id="selectBmsProductCountryList" parameterType="BmsProductCountry" resultMap="BmsProductCountryResult">
<include refid="selectVo"/>
<where>
and ifnull(c.is_del, '0') = '0'
<if test="productId != null">
AND c.product_id = #{productId}
</if>
@@ -85,12 +87,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max,
freight_price, registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, create_time
effective_date, expire_date, status, is_del, create_time
) values (
#{productId}, #{productCode}, #{countryName}, #{countryCode}, #{zoneId}, #{zoneCode}, #{zoneName},
#{weightMin}, #{weightMax},
#{freightPrice}, #{registrationFee}, #{sizeLimit}, #{lastMile}, #{leadTime},
#{effectiveDate}, #{expireDate}, IFNULL(#{status}, '0'), sysdate()
#{effectiveDate}, #{expireDate}, IFNULL(#{status}, '0'), IFNULL(#{isDel}, '0'), sysdate()
)
</insert>
@@ -132,33 +134,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where detail_id = #{detailId}
</update>
<delete id="deleteByProductId" parameterType="Long">
delete from product_country where product_id = #{productId}
</delete>
<update id="deleteByProductId" parameterType="Long">
update product_country
set is_del = '1', update_time = sysdate()
where product_id = #{productId}
and ifnull(is_del, '0') = '0'
</update>
<delete id="deleteByProductCode" parameterType="String">
delete from product_country where product_code = #{productCode}
</delete>
<update id="deleteByProductCode" parameterType="String">
update product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
</update>
<delete id="deleteByProductCodes">
delete from product_country where product_code in
<update id="deleteByProductCodes">
update product_country
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and product_code in
<foreach item="code" collection="array" open="(" separator="," close=")">
#{code}
</foreach>
</delete>
</update>
<delete id="deleteByProductCodeAndEffectiveDate">
delete from product_country
<update id="deleteByProductCodeAndEffectiveDate">
update product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
)
</delete>
</update>
<select id="selectMaxOpenEffectiveDate" resultType="java.util.Date">
select max(effective_date) from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
</select>
@@ -167,6 +181,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
</update>
@@ -176,6 +191,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
</update>
@@ -184,6 +200,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<choose>
@@ -203,21 +220,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
</update>
<delete id="deleteOpenByProductCodeAndEffectiveDate">
delete from product_country
<update id="deleteOpenByProductCodeAndEffectiveDate">
update product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
)
</delete>
</update>
<delete id="deleteOpenByProductCodeAndCountryOnDate">
delete from product_country
<update id="deleteOpenByProductCodeAndCountryOnDate">
update product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (
(#{effectiveDate} is null and effective_date is null)
@@ -231,11 +253,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and country_name = #{countryName}
</otherwise>
</choose>
</delete>
</update>
<select id="selectMatchByProductCountryWeight" resultMap="BmsProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
and ifnull(c.is_del, '0') = '0'
and c.weight_min &lt;= #{weight}
and c.weight_max &gt;= #{weight}
<choose>
@@ -272,6 +295,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(1)
from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and zone_code is not null and zone_code &lt;&gt; ''
<choose>
<when test="countryCode != null and countryCode != ''">
@@ -296,6 +320,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectOpenByProductCode" resultMap="BmsProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
and ifnull(c.is_del, '0') = '0'
and c.expire_date is null
order by c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
</select>
@@ -304,14 +329,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into product_country (
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, create_time
effective_date, expire_date, status, is_del, create_time
)
select
#{productId}, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
#{effectiveDate}, null, IFNULL(#{status}, '0'), sysdate()
#{effectiveDate}, null, IFNULL(#{status}, '0'), '0', sysdate()
from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{effectiveDate})
order by detail_id asc
@@ -16,6 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="effectiveDate" column="effective_date" />
<result property="expireDate" column="expire_date" />
<result property="status" column="status" />
<result property="isDel" column="is_del" />
<result property="sourceSheet" column="source_sheet" />
<result property="pefId" column="pef_id" />
<result property="remark" column="remark" />
@@ -30,28 +31,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectBmsProductVo">
select p.product_id, p.product_code, p.product_name, p.service_level, p.cargo_attr,
p.dest_region, p.update_note, p.tax_mode, p.effective_date, p.expire_date, p.status,
p.dest_region, p.update_note, p.tax_mode, p.effective_date, p.expire_date, p.status, p.is_del,
p.source_sheet, p.pef_id, p.remark, p.tms_id, p.created_by, p.create_time, p.updated_by, p.update_time,
(select count(distinct c.country_name) from product_country c
where c.product_id = p.product_id
where ifnull(c.is_del, '0') = '0'
and (c.product_id = p.product_id
or (c.product_id is null and c.product_code = p.product_code
and (
(p.effective_date is null and c.effective_date is null)
or c.effective_date = p.effective_date
))
)))
) as country_count,
(select count(*) from prc_surcharge_rel r where r.product_id = p.product_id and r.price_type = 'PRODUCT') as surcharge_count
(select count(*) from prc_surcharge_rel r
inner join prc_surcharge s on s.sc_id = r.sc_id and ifnull(s.is_del, '0') = '0'
where ifnull(r.is_del, '0') = '0'
and r.product_id = p.product_id and r.price_type = 'PRODUCT') as surcharge_count
from product p
</sql>
<select id="selectBmsProductById" parameterType="Long" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_id = #{productId}
and ifnull(p.is_del, '0') = '0'
</select>
<select id="selectBmsProductByCode" parameterType="String" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_code = #{productCode}
and ifnull(p.is_del, '0') = '0'
order by p.effective_date desc, p.product_id desc
limit 1
</select>
@@ -59,6 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBmsProductByCodeAndDate" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_code = #{productCode}
and ifnull(p.is_del, '0') = '0'
<choose>
<when test="effectiveDate != null">
AND p.effective_date = #{effectiveDate}
@@ -73,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectEffectiveBmsProductByCode" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_code = #{productCode}
and ifnull(p.is_del, '0') = '0'
and (p.effective_date is null or #{bizDate} is null or p.effective_date &lt;= #{bizDate})
and (p.expire_date is null or #{bizDate} is null or p.expire_date &gt; #{bizDate})
order by p.effective_date desc, p.product_id desc
@@ -82,6 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBmsProductList" parameterType="BmsProduct" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
<where>
and ifnull(p.is_del, '0') = '0'
<if test="productCode != null and productCode != ''">
AND p.product_code like concat('%', #{productCode}, '%')
</if>
@@ -139,6 +149,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="effectiveDate != null">effective_date,</if>
<if test="expireDate != null">expire_date,</if>
<if test="status != null and status != ''">status,</if>
is_del,
<if test="sourceSheet != null">source_sheet,</if>
<if test="pefId != null">pef_id,</if>
<if test="remark != null">remark,</if>
@@ -156,6 +167,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="effectiveDate != null">#{effectiveDate},</if>
<if test="expireDate != null">#{expireDate},</if>
<if test="status != null and status != ''">#{status},</if>
ifnull(#{isDel}, '0'),
<if test="sourceSheet != null">#{sourceSheet},</if>
<if test="pefId != null">#{pefId},</if>
<if test="remark != null">#{remark},</if>
@@ -188,18 +200,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where product_id = #{productId}
</update>
<delete id="deleteBmsProductByIds" parameterType="Long">
delete from product where product_id in
<update id="deleteBmsProductByIds" parameterType="Long">
update product
set is_del = '1',
update_time = sysdate()
where ifnull(is_del, '0') = '0'
and product_id in
<foreach item="productId" collection="array" open="(" separator="," close=")">
#{productId}
</foreach>
</delete>
</update>
<update id="expireOpenByProductCode">
update product
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<if test="excludeId != null">
@@ -212,6 +229,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
</update>
@@ -222,6 +240,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
</update>
</mapper>
@@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="effectiveDate" column="effective_date" />
<result property="expireDate" column="expire_date" />
<result property="status" column="status" />
<result property="isDel" column="is_del" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="effectStatus" column="status" />
@@ -33,13 +34,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.zone_id, c.zone_code, c.zone_name,
c.weight_min, c.weight_max,
c.freight_price, c.registration_fee, c.size_limit, c.last_mile, c.lead_time,
c.effective_date, c.expire_date, c.status, c.create_time, c.update_time
c.effective_date, c.expire_date, c.status, c.is_del, c.create_time, c.update_time
from redline_product_country c
</sql>
<select id="selectBmsRedlineProductCountryList" parameterType="BmsRedlineProductCountry" resultMap="BmsRedlineProductCountryResult">
<include refid="selectVo"/>
<where>
and ifnull(c.is_del, '0') = '0'
<if test="productId != null">
AND c.product_id = #{productId}
</if>
@@ -85,12 +87,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max,
freight_price, registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, create_time
effective_date, expire_date, status, is_del, create_time
) values (
#{productId}, #{productCode}, #{countryName}, #{countryCode}, #{zoneId}, #{zoneCode}, #{zoneName},
#{weightMin}, #{weightMax},
#{freightPrice}, #{registrationFee}, #{sizeLimit}, #{lastMile}, #{leadTime},
#{effectiveDate}, #{expireDate}, IFNULL(#{status}, '0'), sysdate()
#{effectiveDate}, #{expireDate}, IFNULL(#{status}, '0'), IFNULL(#{isDel}, '0'), sysdate()
)
</insert>
@@ -132,41 +134,63 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where detail_id = #{detailId}
</update>
<delete id="deleteByProductId" parameterType="Long">
delete from redline_product_country where product_id = #{productId}
</delete>
<update id="deleteByProductId" parameterType="Long">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_id = #{productId}
and ifnull(is_del, '0') = '0'
</update>
<delete id="deleteByProductCode" parameterType="String">
delete from redline_product_country where product_code = #{productCode}
</delete>
<update id="deleteByProductCode" parameterType="String">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
</update>
<delete id="deleteByProductCodes">
delete from redline_product_country where product_code in
<update id="deleteByProductCodes">
update redline_product_country
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and product_code in
<foreach item="code" collection="array" open="(" separator="," close=")">
#{code}
</foreach>
</delete>
</update>
<delete id="deleteByProductCodeAndEffectiveDate">
delete from redline_product_country
<update id="deleteByProductCodeAndEffectiveDate">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
)
</delete>
</update>
<select id="selectMaxOpenEffectiveDate" resultType="java.util.Date">
select max(effective_date) from redline_product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
</select>
<update id="reopenExpiredByProductCodeAndExpireDate">
update redline_product_country
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
</update>
<update id="expireOpenByProductCode">
update redline_product_country
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
</update>
@@ -176,6 +200,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<choose>
@@ -195,21 +220,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
</update>
<delete id="deleteOpenByProductCodeAndEffectiveDate">
delete from redline_product_country
<update id="deleteOpenByProductCodeAndEffectiveDate">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
)
</delete>
</update>
<delete id="deleteOpenByProductCodeAndCountryOnDate">
delete from redline_product_country
<update id="deleteOpenByProductCodeAndCountryOnDate">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (
(#{effectiveDate} is null and effective_date is null)
@@ -223,11 +253,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and country_name = #{countryName}
</otherwise>
</choose>
</delete>
</update>
<select id="selectMatchByProductCountryWeight" resultMap="BmsRedlineProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
and ifnull(c.is_del, '0') = '0'
and c.weight_min &lt;= #{weight}
and c.weight_max &gt;= #{weight}
<choose>
@@ -264,6 +295,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(1)
from redline_product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and zone_code is not null and zone_code &lt;&gt; ''
<choose>
<when test="countryCode != null and countryCode != ''">
@@ -288,6 +320,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectOpenByProductCode" resultMap="BmsRedlineProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
and ifnull(c.is_del, '0') = '0'
and c.expire_date is null
order by c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
</select>
@@ -296,14 +329,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into redline_product_country (
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, create_time
effective_date, expire_date, status, is_del, create_time
)
select
#{productId}, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
#{effectiveDate}, null, IFNULL(#{status}, '0'), sysdate()
#{effectiveDate}, null, IFNULL(#{status}, '0'), '0', sysdate()
from redline_product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{effectiveDate})
order by detail_id asc
@@ -16,6 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="effectiveDate" column="effective_date" />
<result property="expireDate" column="expire_date" />
<result property="status" column="status" />
<result property="isDel" column="is_del" />
<result property="sourceSheet" column="source_sheet" />
<result property="pefId" column="pef_id" />
<result property="remark" column="remark" />
@@ -30,28 +31,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectBmsRedlineProductVo">
select p.product_id, p.product_code, p.product_name, p.service_level, p.cargo_attr,
p.dest_region, p.update_note, p.tax_mode, p.effective_date, p.expire_date, p.status,
p.dest_region, p.update_note, p.tax_mode, p.effective_date, p.expire_date, p.status, p.is_del,
p.source_sheet, p.pef_id, p.remark, p.tms_id, p.created_by, p.create_time, p.updated_by, p.update_time,
(select count(distinct c.country_name) from redline_product_country c
where c.product_id = p.product_id
where ifnull(c.is_del, '0') = '0'
and (c.product_id = p.product_id
or (c.product_id is null and c.product_code = p.product_code
and (
(p.effective_date is null and c.effective_date is null)
or c.effective_date = p.effective_date
))
)))
) as country_count,
(select count(*) from prc_surcharge_rel r where r.product_id = p.product_id and r.price_type = 'REDLINE') as surcharge_count
(select count(*) from prc_surcharge_rel r
inner join prc_surcharge s on s.sc_id = r.sc_id and ifnull(s.is_del, '0') = '0'
where ifnull(r.is_del, '0') = '0'
and r.product_id = p.product_id and r.price_type = 'REDLINE') as surcharge_count
from redline_product p
</sql>
<select id="selectBmsRedlineProductById" parameterType="Long" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_id = #{productId}
and ifnull(p.is_del, '0') = '0'
</select>
<select id="selectBmsRedlineProductByCode" parameterType="String" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_code = #{productCode}
and ifnull(p.is_del, '0') = '0'
order by p.effective_date desc, p.product_id desc
limit 1
</select>
@@ -59,6 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBmsRedlineProductByCodeAndDate" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_code = #{productCode}
and ifnull(p.is_del, '0') = '0'
<choose>
<when test="effectiveDate != null">
AND p.effective_date = #{effectiveDate}
@@ -73,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectEffectiveBmsRedlineProductByCode" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_code = #{productCode}
and ifnull(p.is_del, '0') = '0'
and (p.effective_date is null or #{bizDate} is null or p.effective_date &lt;= #{bizDate})
and (p.expire_date is null or #{bizDate} is null or p.expire_date &gt; #{bizDate})
order by p.effective_date desc, p.product_id desc
@@ -82,6 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBmsRedlineProductList" parameterType="BmsRedlineProduct" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
<where>
and ifnull(p.is_del, '0') = '0'
<if test="productCode != null and productCode != ''">
AND p.product_code like concat('%', #{productCode}, '%')
</if>
@@ -139,6 +149,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="effectiveDate != null">effective_date,</if>
<if test="expireDate != null">expire_date,</if>
<if test="status != null and status != ''">status,</if>
is_del,
<if test="sourceSheet != null">source_sheet,</if>
<if test="pefId != null">pef_id,</if>
<if test="remark != null">remark,</if>
@@ -156,6 +167,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="effectiveDate != null">#{effectiveDate},</if>
<if test="expireDate != null">#{expireDate},</if>
<if test="status != null and status != ''">#{status},</if>
ifnull(#{isDel}, '0'),
<if test="sourceSheet != null">#{sourceSheet},</if>
<if test="pefId != null">#{pefId},</if>
<if test="remark != null">#{remark},</if>
@@ -166,7 +178,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert>
<update id="updateBmsRedlineProduct" parameterType="BmsRedlineProduct">
update product
update redline_product
<set>
<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
<if test="productName != null and productName != ''">product_name = #{productName},</if>
@@ -188,18 +200,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where product_id = #{productId}
</update>
<delete id="deleteBmsRedlineProductByIds" parameterType="Long">
delete from redline_product where product_id in
<update id="deleteBmsRedlineProductByIds" parameterType="Long">
update redline_product
set is_del = '1',
update_time = sysdate()
where ifnull(is_del, '0') = '0'
and product_id in
<foreach item="productId" collection="array" open="(" separator="," close=")">
#{productId}
</foreach>
</delete>
</update>
<update id="reopenExpiredByProductCodeAndExpireDate">
update redline_product
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
</update>
<update id="expireOpenByProductCode">
update product
update redline_product
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<if test="excludeId != null">
@@ -208,12 +234,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<update id="refreshStatusByDates">
update product
update redline_product
set status = case
when expire_date is not null and expire_date &lt;= now() then '2'
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
</update>
</mapper>
@@ -51,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
f.content_type, f.file_extension, f.oss_id, f.sheet_names, f.remark,
f.created_by, f.create_time, f.updated_by, f.update_time
from prc_price_excel_file f
inner join product p on p.pef_id = f.pef_id
inner join product p on p.pef_id = f.pef_id and ifnull(p.is_del, '0') = '0'
where p.product_code = #{productCode}
and p.pef_id is not null
order by f.effective_time desc, f.pef_id desc
@@ -119,7 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
f.content_type, f.file_extension, f.oss_id, f.sheet_names, f.remark,
f.created_by, f.create_time, f.updated_by, f.update_time
from prc_price_excel_file f
inner join redline_product p on p.pef_id = f.pef_id
inner join redline_product p on p.pef_id = f.pef_id and ifnull(p.is_del, '0') = '0'
where p.product_code = #{productCode}
and p.pef_id is not null
order by f.effective_time desc, f.pef_id desc
@@ -57,7 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.registration_fee as base_registration_fee,
d.discount_value, d.round_mode, d.pr_id, d.effective_date, d.expire_date, d.create_time, d.update_time
from prc_price_set_detail d
left join product_country c on c.detail_id = d.product_country_id
left join product_country c on c.detail_id = d.product_country_id and ifnull(c.is_del, '0') = '0'
<where>
<if test="priceSetId != null">
AND d.price_set_id = #{priceSetId}
@@ -166,9 +166,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
inner join product p on p.product_id = c.product_id
<where>
and p.status = '1'
and ifnull(p.is_del, '0') = '0'
and ifnull(c.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
and ifnull(c.status, '1') &lt;&gt; '2'
<choose>
@@ -226,9 +229,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
inner join product p on p.product_id = c.product_id
<where>
and p.status = '1'
and ifnull(p.is_del, '0') = '0'
and ifnull(c.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
and ifnull(c.status, '1') &lt;&gt; '2'
<choose>
@@ -259,9 +265,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from product p
<where>
and p.status = '1'
and ifnull(p.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
</where>
order by p.product_code asc
@@ -121,9 +121,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sysdate()
from product p
where p.status = '1'
and ifnull(p.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
order by p.product_code asc
</insert>
@@ -146,9 +148,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
null as update_time
from product p
where p.status = '1'
and ifnull(p.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
order by p.product_code asc
</select>
@@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="currency" column="currency" />
<result property="roundMode" column="round_mode" />
<result property="ssCode" column="ss_code" />
<result property="isDel" column="is_del" />
<result property="countryCode" column="country_code" />
<result property="scNote" column="sc_note" />
<result property="tmsId" column="tms_id" />
@@ -23,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectPrcSurchargeVo">
select sc_id, sc_name, fee_type, charge_type, charge_value, currency, round_mode, ss_code,
select sc_id, sc_name, fee_type, charge_type, charge_value, currency, round_mode, ss_code, is_del,
country_code, sc_note, tms_id, created_by, create_time, updated_by, update_time
from prc_surcharge
</sql>
@@ -31,11 +32,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectPrcSurchargeById" parameterType="Long" resultMap="PrcSurchargeResult">
<include refid="selectPrcSurchargeVo"/>
where sc_id = #{scId}
and ifnull(is_del, '0') = '0'
</select>
<select id="selectPrcSurchargeList" parameterType="PrcSurcharge" resultMap="PrcSurchargeResult">
<include refid="selectPrcSurchargeVo"/>
<where>
and ifnull(is_del, '0') = '0'
<if test="scName != null and scName != ''">
AND sc_name like concat('%', #{scName}, '%')
</if>
@@ -76,6 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="currency != null and currency != ''">currency,</if>
<if test="roundMode != null and roundMode != ''">round_mode,</if>
<if test="ssCode != null and ssCode != ''">ss_code,</if>
is_del,
<if test="countryCode != null">country_code,</if>
<if test="scNote != null">sc_note,</if>
<if test="tmsId != null">tms_id,</if>
@@ -89,6 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="currency != null and currency != ''">#{currency},</if>
<if test="roundMode != null and roundMode != ''">#{roundMode},</if>
<if test="ssCode != null and ssCode != ''">#{ssCode},</if>
ifnull(#{isDel}, '0'),
<if test="countryCode != null">#{countryCode},</if>
<if test="scNote != null">#{scNote},</if>
<if test="tmsId != null">#{tmsId},</if>
@@ -101,7 +106,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateSsCodeByIds">
update prc_surcharge
set ss_code = #{ssCode}, updated_by = #{operator}, update_time = sysdate()
where sc_id in
where ifnull(is_del, '0') = '0'
and sc_id in
<foreach item="scId" collection="scIds" open="(" separator="," close=")">
#{scId}
</foreach>
@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="detailId" column="detail_id" />
<result property="priceType" column="price_type" />
<result property="countryCode" column="country_code" />
<result property="isDel" column="is_del" />
<result property="scName" column="sc_name" />
<result property="feeType" column="fee_type" />
<result property="chargeType" column="charge_type" />
@@ -31,20 +32,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectPrcSurchargeRelVo">
select r.rel_id, r.sc_id, r.product_id, r.product_code, r.detail_id,
r.price_type, r.country_code,
r.price_type, r.country_code, r.is_del,
r.created_by, r.create_time, r.updated_by, r.update_time,
s.sc_name, s.fee_type, s.charge_type, s.charge_value, s.currency,
s.round_mode, s.ss_code, s.sc_note,
ifnull(c.country_name, rc.country_name) as country_name, ifnull(c.weight_min, rc.weight_min) as weight_min, ifnull(c.weight_max, rc.weight_max) as weight_max
from prc_surcharge_rel r
join prc_surcharge s on s.sc_id = r.sc_id
left join product_country c on c.detail_id = r.detail_id and r.price_type = 'PRODUCT'
left join redline_product_country rc on rc.detail_id = r.detail_id and r.price_type = 'REDLINE'
join prc_surcharge s on s.sc_id = r.sc_id and ifnull(s.is_del, '0') = '0'
left join product_country c on c.detail_id = r.detail_id and r.price_type = 'PRODUCT' and ifnull(c.is_del, '0') = '0'
left join redline_product_country rc on rc.detail_id = r.detail_id and r.price_type = 'REDLINE' and ifnull(rc.is_del, '0') = '0'
</sql>
<select id="selectPrcSurchargeRelList" parameterType="PrcSurchargeRel" resultMap="PrcSurchargeRelResult">
<include refid="selectPrcSurchargeRelVo"/>
<where>
and ifnull(r.is_del, '0') = '0'
<if test="productId != null">
AND r.product_id = #{productId}
</if>
@@ -69,7 +71,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectByDetailIdsAndPriceType" resultMap="PrcSurchargeRelResult">
<include refid="selectPrcSurchargeRelVo"/>
where r.price_type = #{priceType}
where ifnull(r.is_del, '0') = '0'
and r.price_type = #{priceType}
and r.detail_id in
<foreach item="id" collection="detailIds" open="(" separator="," close=")">
#{id}
@@ -79,55 +82,66 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertPrcSurchargeRel" parameterType="PrcSurchargeRel" useGeneratedKeys="true" keyProperty="relId">
insert into prc_surcharge_rel (
sc_id, product_id, product_code, detail_id, price_type, country_code,
sc_id, product_id, product_code, detail_id, price_type, country_code, is_del,
<if test="createBy != null and createBy != ''">created_by,</if>
create_time
) values (
#{scId}, #{productId}, #{productCode}, #{detailId},
#{priceType}, #{countryCode},
#{priceType}, #{countryCode}, ifnull(#{isDel}, '0'),
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<delete id="deletePrcSurchargeRelByIds" parameterType="Long">
delete from prc_surcharge_rel where rel_id in
<update id="deletePrcSurchargeRelByIds" parameterType="Long">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and rel_id in
<foreach item="relId" collection="array" open="(" separator="," close=")">
#{relId}
</foreach>
</delete>
</update>
<delete id="deleteRelByProductCodes">
delete from prc_surcharge_rel where product_code in
<update id="deleteRelByProductCodes">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and price_type = 'PRODUCT'
and product_code in
<foreach item="code" collection="array" open="(" separator="," close=")">
#{code}
</foreach>
and price_type = 'PRODUCT'
</delete>
</update>
<delete id="deleteByDetailIdsAndPriceType">
delete from prc_surcharge_rel
where price_type = #{priceType}
<update id="deleteByDetailIdsAndPriceType">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and price_type = #{priceType}
and detail_id in
<foreach item="id" collection="detailIds" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</update>
<delete id="deleteByProductIdsAndPriceType">
delete from prc_surcharge_rel
where price_type = #{priceType}
<update id="deleteByProductIdsAndPriceType">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and price_type = #{priceType}
and product_id in
<foreach item="id" collection="productIds" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</update>
<!-- 附加费版本化编辑后,产品关联重指向新记录 -->
<update id="rebindRelScId">
update prc_surcharge_rel
set sc_id = #{newScId}, updated_by = #{operator}, update_time = sysdate()
where sc_id = #{oldScId}
where ifnull(is_del, '0') = '0'
and sc_id = #{oldScId}
</update>
</mapper>