java-retail-app/bd-business/bd-business-sale/src/main/resources/mapper/activity/pick/AcPickMapper.xml

281 lines
9.9 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.hzs.activity.pick.mapper.AcPickMapper">
<!-- 更新提货数量 -->
<update id="addQuantityByActivity">
update AC_PICK ap
set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY + #{quantity},
<if test="receiveTime != null">
ap.RECEIVE_TIME = #{receiveTime},
</if>
<choose>
<when test="pkPostage != null">
ap.IS_FREE_MAIL = 1,
ap.PK_POSTAGE = #{pkPostage},
</when>
<otherwise>
ap.PK_POSTAGE = 0,
</otherwise>
</choose>
ap.pk_modified = #{pkModified},
ap.modified_time = sysdate
where ap.del_flag = 0
and ap.PICK_TYPE = #{pickType}
<if test="pkBaseConfig != null">
and ap.PK_BASE_CONFIG = #{pkBaseConfig}
</if>
and ap.PK_DATA_ID = #{pkDataId}
and ap.PK_MEMBER = #{pkMember}
and ap.USABLE_QUANTITY + #{quantity} > 0
</update>
<!-- 根据会员和活动类型回退使用数量 -->
<update id="updatePickUsableByMemberAndActivityType">
update ac_pick ap
set ap.modified_time = sysdate,
ap.pk_modified = #{pkModified},
ap.usable_quantity = ap.usable_quantity - #{quantity}
where ap.del_flag = 0
and ap.pk_member = #{pkMember}
and ap.pick_type = #{pickType}
<if test="null != pkBaseConfig">
and ap.pk_base_config = #{pkBaseConfig}
</if>
<if test="null != pkDataId">
and ap.pk_data_id = #{pkDataId}
</if>
and ap.usable_quantity - #{quantity} >= 0
</update>
<!-- 根据主键更新提货数据 -->
<update id="updatePickByPkId">
update AC_PICK ap
set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY + #{acPick.usableQuantity},
<if test="null != acPick.receiveTime">
ap.receive_time = #{acPick.receiveTime},
</if>
<if test="null != acPick.isFreeMail">
ap.is_free_mail = #{acPick.isFreeMail},
<choose>
<when test="1 == acPick.isFreeMail">
<!-- 不包邮,需要更新邮费模板 -->
ap.pk_postage = #{acPick.pkPostage},
</when>
<otherwise>
<!-- 包邮,清空运费模板 -->
ap.pk_postage = null,
</otherwise>
</choose>
</if>
<if test="null != acPick.baseQuantity">
ap.BASE_QUANTITY = #{acPick.baseQuantity},
</if>
ap.pk_modified = #{acPick.pkModified},
ap.modified_time = sysdate
where ap.del_flag = 0
and ap.PK_ID = #{acPick.pkId}
</update>
<!-- 删除充值提货卡-->
<update id="removePickByPkId">
update AC_PICK ap
set ap.del_flag = 1,
ap.pk_modified = #{acPick.pkModified},
ap.modified_time = sysdate
where ap.del_flag = 0
and ap.PK_ID = #{acPick.pkId}
</update>
<!-- 查询提货列表 -->
<select id="queryList" resultType="com.hzs.common.domain.activity.pick.ext.AcPickExt">
SELECT ap.*,
cm.member_code,
cm.member_name,
nvl(bp.retail_price, 0) retail_price,
bp.product_name || nvl2(ap.specs_name, '(' || ap.specs_name || ')', '') AS product_name,
abc.act_name
FROM AC_PICK ap
INNER JOIN cu_member cm ON cm.pk_id = ap.pk_member
LEFT JOIN bd_product bp ON bp.pk_id = ap.pk_data_id AND ap.pick_type in (0, 1, 5, 7, 8)
left join ac_base_config abc on abc.pk_id = ap.pk_base_id
WHERE ap.del_flag = 0
and ap.pk_country = #{pkCountry}
<if test="param.pkMember != null ">
and ap.pk_member=#{param.pkMember}
</if>
<if test="param.memberCode != null and param.memberCode != ''">
and cm.member_code like #{param.memberCode} || '%'
</if>
<if test="param.memberName != null and param.memberName != ''">
and cm.member_name like #{param.memberName} || '%'
</if>
<if test="param.pickType != null">
and ap.pick_type = #{param.pickType}
</if>
<if test="param.creationTime != null">
and ap.creation_time >= #{param.creationTime[0]}
and #{param.creationTime[1]} >= ap.creation_time
</if>
<if test="param.modifiedTime != null">
and ap.modified_time >= #{param.modifiedTime[0]}
and #{param.modifiedTime[1]} >= ap.modified_time
</if>
<if test="param.receiveTime != null">
and ap.receive_time >= #{param.receiveTime[0]}
and #{param.receiveTime[1]} >= ap.receive_time
</if>
order by ap.creation_time desc
</select>
<!-- 查询提货详情 -->
<select id="queryDetail" resultType="com.hzs.common.domain.activity.pick.ext.AcPickExt">
select ap.*,
cm.member_code,
cm.member_name,
case
when ap.pick_type = 0 then
(select bp.product_name
from bd_product bp
where bp.pk_id = PK_DATA_ID)
end product_name
from AC_PICK ap
inner join cu_member cm
on cm.pk_id = ap.pk_member
where ap.del_flag = 0
and ap.pk_id = #{pkId}
and ap.pk_country = #{pkCountry}
</select>
<!-- 会员提货列表 -->
<select id="pickList" resultType="com.hzs.activity.pick.vo.ApiPickListVO">
<!-- 提货产品、分公司产品 -->
select ap.pk_id,
ap.pick_type,
case
when ap.pick_cover is not null then
ap.pick_cover
else
(select bp.cover from bd_product bp where bp.pk_id = ap.pk_data_id)
end pick_cover,
ap.usable_quantity,
ap.receive_time,
0 pick_flag,
1 IS_WHOLE,
ap.base_quantity,
ap.creation_time
from AC_PICK ap
inner join bd_product bp
on bp.pk_id = ap.pk_data_id
where ap.del_flag = 0
and ap.pk_country = #{pkCountry}
and ap.pk_member = #{pkMember}
and ap.pick_type in (0, 20)
and ap.usable_quantity > 0
and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd') >= to_char(sysdate, 'yyyy-mm-dd'))
<!-- 迁移抽奖、新抽奖 -->
union all
select ap.pk_id,
ap.pick_type,
case
when ap.pick_cover is not null then
ap.pick_cover
else
(select bp.cover from bd_product bp where bp.pk_id = ap.pk_data_id)
end pick_cover,
ap.usable_quantity,
ap.receive_time,
0 pick_flag,
0 IS_WHOLE,
ap.base_quantity,
ap.creation_time
from AC_PICK ap
where ap.del_flag = 0
and ap.pk_country = #{pkCountry}
and ap.pk_member = #{pkMember}
and ap.pick_type in (1, 17)
and ap.usable_quantity > 0
and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd hh24:mi:ss') >= to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss'))
<!-- 消费赠送、直推赠送 -->
union all
select ap.pk_id,
ap.pick_type,
ap.pick_cover,
ap.usable_quantity,
ap.receive_time,
0 pick_flag,
nvl(apuc.is_whole, 1) is_whole,
ap.base_quantity,
ap.creation_time
from AC_PICK ap
left join AC_PICK_UP_CONFIG apuc
on apuc.pk_base_id = ap.pk_base_config
and apuc.del_flag = 0
where ap.del_flag = 0
and ap.pk_country = #{pkCountry}
and ap.pk_member = #{pkMember}
and ap.pick_type in (12, 13, 14, 15)
and ap.usable_quantity > 0
and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd') >= to_char(sysdate, 'yyyy-mm-dd'))
<!-- 排序 -->
order by creation_time
</select>
<!-- 批量处理提货数据 -->
<update id="batchSaveOrUpdatePick">
merge into AC_PICK ap
using (
<foreach collection="pickList" item="items" separator=" union all ">
select #{items.pkMember} pk_member,
#{items.pickType} pick_type,
#{items.pkDataId} pk_data_id,
#{items.specsName} specs_name,
#{items.specsNameId} specs_name_id,
#{items.usableQuantity} usable_quantity,
#{items.baseQuantity} base_quantity,
#{items.pkCreator} pk_creator
from dual
</foreach>
) tmp
on (tmp.pk_member = ap.pk_member and tmp.pick_type = ap.pick_type and tmp.pk_data_id = ap.pk_data_id
and tmp.specs_name = ap.specs_name and ap.specs_name_id = ap.specs_name_id and tmp.base_quantity = ap.base_quantity)
WHEN NOT MATCHED THEN
insert
(pk_id,
pk_member,
pick_type,
pk_data_id,
specs_name,
specs_name_id,
usable_quantity,
pk_creator,
base_quantity)
values (ac_pick_seq.nextval,
tmp.pk_member,
tmp.pick_type,
tmp.pk_data_id,
tmp.specs_name,
tmp.specs_name_id,
tmp.usable_quantity,
tmp.pk_creator,
tmp.base_quantity)
WHEN MATCHED THEN
update set ap.usable_quantity = ap.usable_quantity + tmp.usable_quantity
</update>
<!-- 根据ID更新会员提货数据 -->
<update id="updateMemberPickById">
update ac_pick ap
set ap.usable_quantity = ap.usable_quantity + #{quantity},
ap.used_quantity = ap.used_quantity - #{quantity},
ap.modified_time = sysdate
where ap.del_flag = 0
<if test="pkMember != null">
and ap.pk_member = #{pkMember}
</if>
and ap.pk_id = #{pkId}
and ap.usable_quantity + #{quantity} >= 0
</update>
</mapper>