java-base-app/bd-business/bd-business-member/src/main/resources/mapper/member/empty/CuMemberEmptyCodeMapper.xml

59 lines
2.3 KiB
XML
Raw Normal View History

2025-04-24 19:02:08 +08:00
<?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.member.empty.mapper.CuMemberEmptyCodeMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.hzs.common.domain.member.empty.CuMemberEmptyCode">
<id column="PK_ID" property="pkId"/>
<result column="PK_COUNTRY" property="pkCountry"/>
<result column="PK_CREATOR" property="pkCreator"/>
<result column="CREATION_TIME" property="creationTime"/>
<result column="PK_MODIFIED" property="pkModified"/>
<result column="MODIFIED_TIME" property="modifiedTime"/>
<result column="DEL_FLAG" property="delFlag"/>
<result column="BATCH_CODE" property="batchCode"/>
<result column="MEMBER_CODE" property="memberCode"/>
<result column="IS_USED" property="isUsed"/>
</resultMap>
<!-- 查询最新的编号 -->
<select id="queryLastCode" resultType="string">
select max(cme.BATCH_CODE) code
from CU_MEMBER_EMPTY_CODE cme
</select>
<!-- 批量插入会员编号 -->
<insert id="insertBatch">
insert into CU_MEMBER_EMPTY_CODE
(PK_ID, BATCH_CODE, MEMBER_CODE, IS_USED, PK_COUNTRY, PK_CREATOR)
select CU_MEMBER_EMPTY_CODE_SEQ.Nextval, tmp.*
from (
<foreach collection="memberCodeList" item="item" separator=" union ">
select
#{item.batchCode} BATCH_CODE,
#{item.memberCode} MEMBER_CODE,
#{item.isUsed} IS_USED,
#{item.pkCountry} PK_COUNTRY,
#{item.pkCreator} PK_CREATOR
from dual
</foreach>
) tmp
</insert>
<!-- 清除会员编号占用数据 -->
<update id="clearMemberEmptyCode">
update CU_MEMBER_EMPTY_CODE cmec
set cmec.del_flag = 1,
cmec.modified_time = sysdate
where cmec.pk_id in
(select cmec.pk_id
from CU_MEMBER_EMPTY_CODE cmec
left join cu_member cm
on cm.member_code = cmec.member_code
where cmec.del_flag = 0
and cm.pk_id is null
and sysdate - 7 >= cmec.creation_time)
</update>
</mapper>