客户超额消息通知
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
<?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.notify.mapper.NotifyMapper">
|
||||
|
||||
<!-- ================= 规则 ================= -->
|
||||
<resultMap id="NotifyRuleResult" type="com.bms.notify.domain.NotifyRule">
|
||||
<id property="ruleId" column="rule_id" />
|
||||
<result property="ruleName" column="rule_name" />
|
||||
<result property="eventType" column="event_type" />
|
||||
<result property="status" column="status" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="NotifyRuleTargetResult" type="com.bms.notify.domain.NotifyRuleTarget">
|
||||
<id property="targetId" column="target_id" />
|
||||
<result property="ruleId" column="rule_id" />
|
||||
<result property="targetType" column="target_type" />
|
||||
<result property="refId" column="ref_id" />
|
||||
<result property="refName" column="ref_name" />
|
||||
<result property="createTime" column="create_time" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectRuleList" parameterType="com.bms.notify.domain.NotifyRule" resultMap="NotifyRuleResult">
|
||||
select rule_id, rule_name, event_type, status, remark, create_by, create_time, update_by, update_time
|
||||
from sys_notify_rule
|
||||
where del_flag = '0'
|
||||
<if test="ruleName != null and ruleName != ''"> and rule_name like concat('%', #{ruleName}, '%')</if>
|
||||
<if test="eventType != null and eventType != ''"> and event_type = #{eventType}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
order by rule_id desc
|
||||
</select>
|
||||
|
||||
<select id="selectRuleById" resultMap="NotifyRuleResult">
|
||||
select rule_id, rule_name, event_type, status, remark, create_by, create_time, update_by, update_time, del_flag
|
||||
from sys_notify_rule
|
||||
where rule_id = #{ruleId} and del_flag = '0'
|
||||
</select>
|
||||
|
||||
<insert id="insertRule" parameterType="com.bms.notify.domain.NotifyRule" useGeneratedKeys="true" keyProperty="ruleId">
|
||||
insert into sys_notify_rule (rule_name, event_type, status, remark, create_by, create_time)
|
||||
values (#{ruleName}, #{eventType}, #{status}, #{remark}, #{createBy}, sysdate())
|
||||
</insert>
|
||||
|
||||
<update id="updateRule" parameterType="com.bms.notify.domain.NotifyRule">
|
||||
update sys_notify_rule
|
||||
<set>
|
||||
<if test="ruleName != null">rule_name = #{ruleName},</if>
|
||||
<if test="eventType != null">event_type = #{eventType},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
update_by = #{updateBy},
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where rule_id = #{ruleId} and del_flag = '0'
|
||||
</update>
|
||||
|
||||
<update id="deleteRuleByIds">
|
||||
update sys_notify_rule
|
||||
set del_flag = '2', update_by = #{updateBy}, update_time = sysdate()
|
||||
where rule_id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</update>
|
||||
|
||||
<select id="countEnabledRules" resultType="int">
|
||||
select count(1) from sys_notify_rule
|
||||
where del_flag = '0' and status = '0'
|
||||
<if test="eventType != null and eventType != ''"> and event_type = #{eventType}</if>
|
||||
</select>
|
||||
|
||||
<!-- ================= 规则对象 ================= -->
|
||||
<select id="selectTargetsByRuleId" resultMap="NotifyRuleTargetResult">
|
||||
select target_id, rule_id, target_type, ref_id, ref_name, create_time
|
||||
from sys_notify_rule_target
|
||||
where rule_id = #{ruleId}
|
||||
order by target_type, ref_id
|
||||
</select>
|
||||
|
||||
<select id="selectTargetsByRuleIds" resultMap="NotifyRuleTargetResult">
|
||||
select target_id, rule_id, target_type, ref_id, ref_name, create_time
|
||||
from sys_notify_rule_target
|
||||
where rule_id in
|
||||
<foreach collection="ruleIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
order by rule_id, target_type, ref_id
|
||||
</select>
|
||||
|
||||
<insert id="insertTarget" parameterType="com.bms.notify.domain.NotifyRuleTarget" useGeneratedKeys="true" keyProperty="targetId">
|
||||
insert into sys_notify_rule_target (rule_id, target_type, ref_id, ref_name, create_time)
|
||||
values (#{ruleId}, #{targetType}, #{refId}, #{refName}, sysdate())
|
||||
</insert>
|
||||
|
||||
<delete id="deleteTargetsByRuleId">
|
||||
delete from sys_notify_rule_target where rule_id = #{ruleId}
|
||||
</delete>
|
||||
|
||||
<select id="countEnabledUser" resultType="int">
|
||||
select count(1) from sys_user
|
||||
where user_id = #{userId} and status = '0' and del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="countEnabledRole" resultType="int">
|
||||
select count(1) from sys_role
|
||||
where role_id = #{roleId} and status = '0' and del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectRecipientUserIds" resultType="long">
|
||||
select distinct u.user_id
|
||||
from sys_user u
|
||||
where u.status = '0' and u.del_flag = '0'
|
||||
and (
|
||||
u.user_id in (
|
||||
select t.ref_id from sys_notify_rule_target t
|
||||
join sys_notify_rule r on r.rule_id = t.rule_id
|
||||
where t.target_type = 'USER' and r.del_flag = '0' and r.status = '0'
|
||||
<if test="eventType != null and eventType != ''"> and r.event_type = #{eventType}</if>
|
||||
)
|
||||
or u.user_id in (
|
||||
select ur.user_id from sys_user_role ur
|
||||
where ur.role_id in (
|
||||
select t.ref_id from sys_notify_rule_target t
|
||||
join sys_notify_rule r on r.rule_id = t.rule_id
|
||||
where t.target_type = 'ROLE' and r.del_flag = '0' and r.status = '0'
|
||||
<if test="eventType != null and eventType != ''"> and r.event_type = #{eventType}</if>
|
||||
)
|
||||
)
|
||||
)
|
||||
</select>
|
||||
|
||||
<!-- ================= 消息与接收 ================= -->
|
||||
<resultMap id="NotifyMessageResult" type="com.bms.notify.domain.NotifyMessage">
|
||||
<id property="messageId" column="message_id" />
|
||||
<result property="eventType" column="event_type" />
|
||||
<result property="title" column="title" />
|
||||
<result property="content" column="content" />
|
||||
<result property="customerId" column="customer_id" />
|
||||
<result property="customerCode" column="customer_code" />
|
||||
<result property="customerName" column="customer_name" />
|
||||
<result property="overdueAmount" column="overdue_amount" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="receiveCount" column="receive_count" />
|
||||
<result property="readCount" column="read_count" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectMessageList" parameterType="com.bms.notify.domain.NotifyMessage" resultMap="NotifyMessageResult">
|
||||
select m.message_id, m.event_type, m.title, m.content, m.customer_id, m.customer_code,
|
||||
m.customer_name, m.overdue_amount, m.create_by, m.create_time,
|
||||
(select count(1) from sys_notify_receive rv where rv.message_id = m.message_id) as receive_count,
|
||||
(select count(1) from sys_notify_receive rv where rv.message_id = m.message_id and rv.read_flag = '1') as read_count
|
||||
from sys_notify_message m
|
||||
<where>
|
||||
<if test="eventType != null and eventType != ''"> and m.event_type = #{eventType}</if>
|
||||
<if test="customerName != null and customerName != ''"> and m.customer_name like concat('%', #{customerName}, '%')</if>
|
||||
<if test="title != null and title != ''"> and m.title like concat('%', #{title}, '%')</if>
|
||||
</where>
|
||||
order by m.message_id desc
|
||||
</select>
|
||||
|
||||
<select id="selectMessageById" resultMap="NotifyMessageResult">
|
||||
select m.message_id, m.event_type, m.title, m.content, m.customer_id, m.customer_code,
|
||||
m.customer_name, m.overdue_amount, m.create_by, m.create_time,
|
||||
(select count(1) from sys_notify_receive rv where rv.message_id = m.message_id) as receive_count,
|
||||
(select count(1) from sys_notify_receive rv where rv.message_id = m.message_id and rv.read_flag = '1') as read_count
|
||||
from sys_notify_message m
|
||||
where m.message_id = #{messageId}
|
||||
</select>
|
||||
|
||||
<insert id="insertMessage" parameterType="com.bms.notify.domain.NotifyMessage" useGeneratedKeys="true" keyProperty="messageId">
|
||||
insert into sys_notify_message (event_type, title, content, customer_id, customer_code,
|
||||
customer_name, overdue_amount, create_by, create_time)
|
||||
values (#{eventType}, #{title}, #{content}, #{customerId}, #{customerCode},
|
||||
#{customerName}, #{overdueAmount}, #{createBy}, sysdate())
|
||||
</insert>
|
||||
|
||||
<insert id="insertReceive" parameterType="com.bms.notify.domain.NotifyReceive">
|
||||
insert ignore into sys_notify_receive (message_id, user_id, read_flag, popup_flag, create_time)
|
||||
values (#{messageId}, #{userId}, '0', 'N', sysdate())
|
||||
</insert>
|
||||
|
||||
<resultMap id="NotifyReceiveResult" type="com.bms.notify.domain.NotifyReceive">
|
||||
<id property="receiveId" column="receive_id" />
|
||||
<result property="messageId" column="message_id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="readFlag" column="read_flag" />
|
||||
<result property="readTime" column="read_time" />
|
||||
<result property="popupFlag" column="popup_flag" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="title" column="title" />
|
||||
<result property="content" column="content" />
|
||||
<result property="eventType" column="event_type" />
|
||||
<result property="customerName" column="customer_name" />
|
||||
<result property="customerCode" column="customer_code" />
|
||||
<result property="overdueAmount" column="overdue_amount" />
|
||||
<result property="nickName" column="nick_name" />
|
||||
<result property="userName" column="user_name" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectReceivesByMessageId" resultMap="NotifyReceiveResult">
|
||||
select rv.receive_id, rv.message_id, rv.user_id, rv.read_flag, rv.read_time, rv.popup_flag, rv.create_time,
|
||||
u.nick_name, u.user_name
|
||||
from sys_notify_receive rv
|
||||
left join sys_user u on u.user_id = rv.user_id
|
||||
where rv.message_id = #{messageId}
|
||||
order by rv.read_flag asc, rv.receive_id asc
|
||||
</select>
|
||||
|
||||
<!-- ================= 扫描日志 ================= -->
|
||||
<select id="selectScanLogStatus" resultType="string">
|
||||
select last_status from sys_notify_scan_log
|
||||
where event_type = #{eventType} and customer_id = #{customerId}
|
||||
</select>
|
||||
|
||||
<select id="selectScanLogNotifyDate" resultType="java.util.Date">
|
||||
select last_notify_date from sys_notify_scan_log
|
||||
where event_type = #{eventType} and customer_id = #{customerId}
|
||||
</select>
|
||||
|
||||
<insert id="insertScanLog">
|
||||
insert into sys_notify_scan_log (event_type, customer_id, last_status, last_notify_date, update_time)
|
||||
values (#{eventType}, #{customerId}, #{status},
|
||||
<choose><when test="notify">curdate()</when><otherwise>null</otherwise></choose>,
|
||||
sysdate())
|
||||
</insert>
|
||||
|
||||
<update id="updateScanLog">
|
||||
update sys_notify_scan_log
|
||||
set last_status = #{status},
|
||||
last_notify_date = <choose><when test="notify">curdate()</when><otherwise>last_notify_date</otherwise></choose>,
|
||||
update_time = sysdate()
|
||||
where event_type = #{eventType} and customer_id = #{customerId}
|
||||
</update>
|
||||
|
||||
<update id="resetNormalForCustomers">
|
||||
update sys_notify_scan_log
|
||||
set last_status = 'NORMAL', update_time = sysdate()
|
||||
where event_type = #{eventType} and last_status = 'OVERDUE'
|
||||
<if test="customerIds != null and customerIds.size() > 0">
|
||||
and customer_id not in
|
||||
<foreach collection="customerIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<!-- 当前超额客户:CNY账户,可用额度=余额+当日有效信用额度+当日有效临时额度 < 0 -->
|
||||
<resultMap id="OverdueCustomerResult" type="com.bms.notify.domain.NotifyOverdueCustomer">
|
||||
<id property="customerId" column="customer_id" />
|
||||
<result property="customerCode" column="customer_code" />
|
||||
<result property="customerName" column="customer_name" />
|
||||
<result property="isEnable" column="is_enable" />
|
||||
<result property="balance" column="balance" />
|
||||
<result property="available" column="available" />
|
||||
<result property="overdueAmount" column="overdue_amount" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectOverdueCustomers" resultMap="OverdueCustomerResult">
|
||||
select t.customer_id, t.customer_code, t.customer_name, t.is_enable, t.balance, t.available,
|
||||
(0 - t.available) as overdue_amount
|
||||
from (
|
||||
select ca.customer_id, c.customer_code, c.customer_name, c.is_enable, ca.balance,
|
||||
(
|
||||
ca.balance
|
||||
+ case when (ca.credit_effective_date is null or ca.credit_effective_date <= curdate())
|
||||
and (ca.credit_expire_date is null or ca.credit_expire_date >= curdate())
|
||||
then ifnull(ca.total_credit, 0) else 0 end
|
||||
+ case when (ca.extra_effective_date is null or ca.extra_effective_date <= curdate())
|
||||
and (ca.extra_expire_date is null or ca.extra_expire_date >= curdate())
|
||||
then ifnull(ca.extra_credit, 0) else 0 end
|
||||
) as available
|
||||
from ctr_customer_account ca
|
||||
join ctr_customer c on c.customer_id = ca.customer_id and c.del_flag = '0'
|
||||
where ca.currency = 'CNY' and ca.del_flag = '0'
|
||||
) t
|
||||
where t.available < 0
|
||||
order by t.available asc
|
||||
</select>
|
||||
|
||||
<!-- ================= 我的消息 ================= -->
|
||||
<select id="selectPopupReceives" resultMap="NotifyReceiveResult">
|
||||
select rv.receive_id, rv.message_id, rv.user_id, rv.read_flag, rv.read_time, rv.popup_flag, rv.create_time,
|
||||
m.title, m.content, m.event_type, m.customer_name, m.customer_code, m.overdue_amount
|
||||
from sys_notify_receive rv
|
||||
join sys_notify_message m on m.message_id = rv.message_id
|
||||
where rv.user_id = #{userId} and rv.popup_flag = 'N'
|
||||
order by rv.receive_id desc
|
||||
</select>
|
||||
|
||||
<update id="markPopupShown">
|
||||
update sys_notify_receive set popup_flag = 'Y'
|
||||
where user_id = #{userId} and popup_flag = 'N'
|
||||
</update>
|
||||
|
||||
<select id="selectMineList" resultMap="NotifyReceiveResult">
|
||||
select rv.receive_id, rv.message_id, rv.user_id, rv.read_flag, rv.read_time, rv.popup_flag, rv.create_time,
|
||||
m.title, m.content, m.event_type, m.customer_name, m.customer_code, m.overdue_amount
|
||||
from sys_notify_receive rv
|
||||
join sys_notify_message m on m.message_id = rv.message_id
|
||||
where rv.user_id = #{userId}
|
||||
<if test="readFlag != null and readFlag != ''"> and rv.read_flag = #{readFlag}</if>
|
||||
order by rv.receive_id desc
|
||||
</select>
|
||||
|
||||
<select id="countUnread" resultType="int">
|
||||
select count(1) from sys_notify_receive
|
||||
where user_id = #{userId} and read_flag = '0'
|
||||
</select>
|
||||
|
||||
<update id="markRead">
|
||||
update sys_notify_receive
|
||||
set read_flag = '1', read_time = sysdate()
|
||||
where receive_id = #{receiveId} and user_id = #{userId} and read_flag = '0'
|
||||
</update>
|
||||
|
||||
<update id="markAllRead">
|
||||
update sys_notify_receive
|
||||
set read_flag = '1', read_time = sysdate()
|
||||
where user_id = #{userId} and read_flag = '0'
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user