Files
TimiServerAPI/src/main/resources/mapper/timi-server/gao/GaoCustomerFollowUpReminderMapper.xml
T

103 lines
3.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.imyeyu.api.modules.gao.mapper.GaoCustomerFollowUpReminderMapper">
<sql id="queryWhere">
`r`.`deleted_at` IS NULL
<if test="page.storeId != null and page.storeId != ''">
AND `r`.`store_id` = #{page.storeId}
</if>
<if test="page.customerId != null and page.customerId != ''">
AND `r`.`customer_id` = #{page.customerId}
</if>
<if test="page.responsibleUserId != null and page.responsibleUserId != ''">
AND `r`.`responsible_user_id` = #{page.responsibleUserId}
</if>
<if test="page.status != null">
AND `r`.`status` = #{page.status}
</if>
<if test="page.beginRemindAt != null">
AND `r`.`remind_at` &gt;= #{page.beginRemindAt}
</if>
<if test="page.endRemindAt != null">
AND `r`.`remind_at` &lt;= #{page.endRemindAt}
</if>
</sql>
<select id="countByQuery" resultType="long">
SELECT COUNT(1)
FROM `gao_customer_follow_up_reminder` `r`
WHERE <include refid="queryWhere"/>
</select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerFollowUpReminder">
SELECT `r`.*
FROM `gao_customer_follow_up_reminder` `r`
WHERE <include refid="queryWhere"/>
ORDER BY `r`.`remind_at` ASC, `r`.`created_at` ASC, `r`.`id` ASC
LIMIT #{page.offset}, #{page.limit}
</select>
<select id="selectPendingSmsByRange" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerFollowUpReminder">
SELECT *
FROM `gao_customer_follow_up_reminder`
WHERE `status` = 'PENDING'
AND `deleted_at` IS NULL
AND `sms_notify_enabled` = 1
AND `sms_notify_detail_id` IS NULL
AND `remind_at` &gt;= #{beginAt}
AND `remind_at` &lt; #{endAt}
ORDER BY `store_id`, `responsible_user_id`, `remind_at`, `created_at`, `id`
FOR UPDATE
</select>
<update id="complete">
UPDATE `gao_customer_follow_up_reminder`
SET `status` = 'COMPLETED',
`updated_by` = #{updatedBy},
`completed_by` = #{completedBy},
`completed_at` = #{completedAt},
`updated_at` = #{completedAt}
WHERE `id` = #{id}
AND `status` = 'PENDING'
AND `deleted_at` IS NULL
</update>
<update id="bindSmsNotifyDetailId">
UPDATE `gao_customer_follow_up_reminder`
SET `sms_notify_detail_id` = #{smsNotifyDetailId},
`updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
WHERE `id` IN
<foreach collection="idList" item="id" separator="," open="(" close=")">
#{id}
</foreach>
AND `status` = 'PENDING'
AND `deleted_at` IS NULL
AND `sms_notify_enabled` = 1
AND `sms_notify_detail_id` IS NULL
</update>
<select id="selectBirthdayCandidate" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
SELECT `c`.`id`, `c`.`store_id`, `c`.`name`, `c`.`birthdate`, `c`.`birthdate_calendar`
FROM `gao_customer` `c`
WHERE `c`.`deleted_at` IS NULL
AND `c`.`birthdate` IS NOT NULL
AND `c`.`store_id` IN
<foreach collection="storeIdList" item="storeId" separator="," open="(" close=")">
#{storeId}
</foreach>
</select>
<!-- 幂等键冲突说明:uk_gao_customer_follow_up_reminder_source 兜底同门店同客户同来源键只允许一条 -->
<insert id="insertIgnore">
INSERT IGNORE INTO `gao_customer_follow_up_reminder` (
`id`, `store_id`, `customer_id`, `responsible_user_id`, `content`, `remind_at`,
`status`, `source`, `source_key`, `metadata`,
`internal_notify_enabled`, `sms_notify_enabled`, `created_by`, `created_at`
) VALUES (
#{id}, #{storeId}, #{customerId}, #{responsibleUserId}, #{content}, #{remindAt},
#{status}, #{source}, #{sourceKey}, #{metadata},
#{internalNotifyEnabled}, #{smsNotifyEnabled}, #{createdBy}, #{createdAt}
)
</insert>
</mapper>