Files
BMS/bms-back/bms-system/src/main/resources/mapper/price/PrcPriceSetVersionMapper.xml
T
2026-10-28 18:10:10 +08:00

213 lines
9.7 KiB
XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.price.mapper.PrcPriceSetVersionMapper">
<resultMap type="PrcPriceSetVersion" id="PrcPriceSetVersionResult">
<id property="psvId" column="psv_id" />
<result property="priceSetId" column="price_set_id" />
<result property="priceType" column="price_type" />
<result property="versionNo" column="version_no" />
<result property="versionSeq" column="version_seq" />
<result property="effectiveTime" column="effective_time" />
<result property="expireTime" column="expire_time" />
<result property="status" column="status" />
<result property="priceBuildMode" column="price_build_mode"/>
<result property="isDel" column="is_del" />
<result property="createBy" column="created_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="updated_by" />
<result property="updateTime" column="update_time" />
<result property="productCount" column="product_count" />
<result property="detailCount" column="detail_count" />
</resultMap>
<sql id="selectPrcPriceSetVersionVo">
select psv_id, price_set_id, price_type, version_no, version_seq, effective_time, expire_time, status,
price_build_mode, is_del, created_by, create_time, updated_by, update_time
from prc_price_set_version
</sql>
<select id="selectPrcPriceSetVersionById" parameterType="Long" resultMap="PrcPriceSetVersionResult">
<include refid="selectPrcPriceSetVersionVo"/>
where psv_id = #{psvId}
</select>
<select id="selectPrcPriceSetVersionList" parameterType="PrcPriceSetVersion" resultMap="PrcPriceSetVersionResult">
<include refid="selectPrcPriceSetVersionVo"/>
<where>
and ifnull(is_del, '0') = '0'
<if test="priceSetId != null">
AND price_set_id = #{priceSetId}
</if>
<if test="priceSetId == null and priceType != null and priceType != '' and priceType != 'SALES'">
AND price_set_id is null
</if>
<if test="priceType != null and priceType != ''">
AND price_type = #{priceType}
</if>
<if test="versionNo != null and versionNo != ''">
AND version_no = #{versionNo}
</if>
<if test="status != null and status != ''">
AND status = #{status}
</if>
</where>
order by version_seq desc
</select>
<select id="selectCatalogVersionList" parameterType="PrcPriceSetVersion" resultMap="PrcPriceSetVersionResult">
select v.psv_id, v.price_set_id, v.price_type, v.version_no, v.version_seq,
v.effective_time, v.expire_time, v.status, v.price_build_mode, v.is_del,
v.created_by, v.create_time, v.updated_by, v.update_time,
(select count(1) from prc_price_set_product p
where p.psv_id = v.psv_id and ifnull(p.is_del, '0') = '0') as product_count,
(select count(1) from prc_price_set_detail d
where d.psv_id = v.psv_id and ifnull(d.is_del, '0') = '0') as detail_count
from prc_price_set_version v
where v.price_set_id is null
and v.price_type = #{priceType}
and ifnull(v.is_del, '0') = '0'
<choose>
<when test="statusGroup != null and statusGroup == 'pending'">
and v.status in ('0', '3')
</when>
<when test="statusGroup != null and statusGroup == 'expired'">
and v.status = '2'
</when>
<when test="statusGroup != null and statusGroup == 'effect'">
and v.status = '1'
</when>
<when test="status != null and status != ''">
and v.status = #{status}
</when>
</choose>
order by v.version_seq desc, v.psv_id desc
</select>
<select id="selectMaxVersionSeq" resultType="java.lang.Integer">
select max(version_seq) from prc_price_set_version
where price_type = 'SALES' and price_set_id = #{priceSetId}
</select>
<select id="selectMaxVersionSeqByType" resultType="java.lang.Integer">
select max(version_seq) from prc_price_set_version
where price_type = #{priceType}
<choose>
<when test="priceSetId != null">
and price_set_id = #{priceSetId}
</when>
<otherwise>
and price_set_id is null
</otherwise>
</choose>
</select>
<insert id="insertPrcPriceSetVersion" parameterType="PrcPriceSetVersion" useGeneratedKeys="true" keyProperty="psvId">
insert into prc_price_set_version (
<if test="priceSetId != null">price_set_id,</if>
<if test="priceType != null and priceType != ''">price_type,</if>
<if test="versionNo != null and versionNo != ''">version_no,</if>
<if test="versionSeq != null">version_seq,</if>
<if test="effectiveTime != null">effective_time,</if>
<if test="expireTime != null">expire_time,</if>
<if test="status != null and status != ''">status,</if>
<if test="priceBuildMode != null and priceBuildMode != ''">price_build_mode,</if>
<if test="createBy != null and createBy != ''">created_by,</if>
create_time
) values (
<if test="priceSetId != null">#{priceSetId},</if>
<if test="priceType != null and priceType != ''">#{priceType},</if>
<if test="versionNo != null and versionNo != ''">#{versionNo},</if>
<if test="versionSeq != null">#{versionSeq},</if>
<if test="effectiveTime != null">#{effectiveTime},</if>
<if test="expireTime != null">#{expireTime},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="priceBuildMode != null and priceBuildMode != ''">#{priceBuildMode},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updatePrcPriceSetVersion" parameterType="PrcPriceSetVersion">
update prc_price_set_version
<set>
<if test="priceType != null and priceType != ''">price_type = #{priceType},</if>
<if test="versionNo != null and versionNo != ''">version_no = #{versionNo},</if>
<if test="versionSeq != null">version_seq = #{versionSeq},</if>
<if test="effectiveTime != null">effective_time = #{effectiveTime},</if>
expire_time = #{expireTime},
<if test="status != null and status != ''">status = #{status},</if>
<if test="priceBuildMode != null and priceBuildMode != ''">price_build_mode = #{priceBuildMode},</if>
<if test="updateBy != null and updateBy != ''">updated_by = #{updateBy},</if>
update_time = sysdate()
</set>
where psv_id = #{psvId}
</update>
<delete id="deletePrcPriceSetVersionByIds" parameterType="Long">
delete from prc_price_set_version where psv_id in
<foreach item="psvId" collection="array" open="(" separator="," close=")">
#{psvId}
</foreach>
</delete>
<delete id="deletePrcPriceSetVersionByPriceSetId" parameterType="Long">
delete from prc_price_set_version where price_set_id = #{priceSetId} and price_type = 'SALES'
</delete>
<select id="selectPriceSetIds" resultType="Long">
select distinct price_set_id from prc_price_set_version where price_set_id is not null
</select>
<select id="selectActiveByPriceSetAt" resultMap="PrcPriceSetVersionResult">
<include refid="selectPrcPriceSetVersionVo"/>
where price_type = 'SALES'
and price_set_id = #{priceSetId}
and ifnull(is_del, '0') = '0'
and effective_time is not null
and effective_time &lt;= #{asOf}
and (expire_time is null or expire_time &gt; #{asOf})
order by effective_time desc, version_seq desc, psv_id desc
limit 1
</select>
<select id="selectActiveByTypeAt" resultMap="PrcPriceSetVersionResult">
<include refid="selectPrcPriceSetVersionVo"/>
where price_type = #{priceType}
and price_set_id is null
and ifnull(is_del, '0') = '0'
and effective_time is not null
and effective_time &lt;= #{asOf}
and (expire_time is null or expire_time &gt; #{asOf})
order by effective_time desc, version_seq desc, psv_id desc
limit 1
</select>
<update id="softDeleteById">
update prc_price_set_version
set is_del = '1',
<if test="updateBy != null and updateBy != ''">updated_by = #{updateBy},</if>
update_time = sysdate()
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
</update>
<update id="refreshCatalogStatusByDates">
update prc_price_set_version
set status = case
when expire_time is not null and expire_time &lt;= now() then '2'
when effective_time is not null and effective_time &gt; now() then '3'
when effective_time is null then '0'
else '1'
end,
update_time = sysdate()
where price_type = #{priceType}
and price_set_id is null
and ifnull(is_del, '0') = '0'
and status in ('0','1','2','3')
</update>
</mapper>