cmvr-wms/ruoyi-project/src/main/resources/mapper/project/manage/PmEventMapper.xml

71 lines
4.3 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">
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
<!--suppress SqlNoDataSourceInspection -->
<mapper namespace="com.ruoyi.project.manage.mapper.PmEventMapper">
<select id="selectNotifications" resultType="java.util.LinkedHashMap">
SELECT n.id,n.project_id AS projectId,p.id AS sourceProjectId,n.iteration_id AS iterationId,n.work_item_id AS workItemId,n.message,n.created_at AS createdAt
FROM pm_collab_notification n JOIN pm_collab_project e ON e.id=n.project_id JOIN project_info p ON p.id=e.source_project_id
WHERE n.user_id=#{userId} AND p.del_flag='0'
AND (n.iteration_id IS NULL OR EXISTS(SELECT 1 FROM pm_collab_iteration i WHERE i.id=n.iteration_id AND i.project_id=n.project_id AND i.deleted=false))
AND (p.creator_user_id=#{userId} OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=e.source_project_id AND m.user_id=#{userId}))
ORDER BY n.id DESC LIMIT 100
</select>
<select id="selectPendingEvents" resultType="java.util.LinkedHashMap">
SELECT id FROM pm_collab_outbox WHERE delivered_at IS NULL AND next_attempt_at&lt;=#{now} ORDER BY id LIMIT 50
</select>
<update id="scheduleRetry">
UPDATE pm_collab_outbox SET attempts=attempts+1,next_attempt_at=#{now} + LEAST(3600,POW(2,LEAST(attempts+1,12))) * 1000000 WHERE id=#{eventId} AND delivered_at IS NULL
</update>
<select id="selectEventProject" resultType="java.util.LinkedHashMap">
SELECT o.project_id,p.source_project_id FROM pm_collab_outbox o JOIN pm_collab_project p ON p.id=o.project_id WHERE o.id=#{eventId} AND o.delivered_at IS NULL
</select>
<select id="selectEventForUpdate" resultType="java.util.LinkedHashMap">
SELECT * FROM pm_collab_outbox WHERE id=#{eventId} AND delivered_at IS NULL FOR UPDATE SKIP LOCKED
</select>
<update id="insertRecipientNotifications">
INSERT IGNORE INTO pm_collab_notification(event_id,user_id,project_id,iteration_id,work_item_id,message,created_at)
SELECT #{eventId},u.user_id,#{projectId},(SELECT iteration_id FROM pm_collab_outbox WHERE id=#{eventId}),#{itemId},#{message},#{createdAt}
FROM sys_user u JOIN pm_collab_project e ON e.id=#{projectId} JOIN project_info p ON p.id=e.source_project_id
WHERE u.status='0' AND u.del_flag='0' AND p.del_flag='0'
AND (u.user_id=p.creator_user_id OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=e.source_project_id AND m.user_id=u.user_id))
</update>
<update id="markDelivered">
UPDATE pm_collab_outbox SET delivered_at=#{deliveredAt} WHERE id=#{eventId}
</update>
<insert id="insertEventRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
INSERT INTO pm_collab_outbox
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="values.containsKey('project_id')">project_id,</if>
<if test="values.containsKey('iteration_id')">iteration_id,</if>
<if test="values.containsKey('work_item_id')">work_item_id,</if>
<if test="values.containsKey('event_type')">event_type,</if>
<if test="values.containsKey('payload')">payload,</if>
<if test="values.containsKey('attempts')">attempts,</if>
<if test="values.containsKey('next_attempt_at')">next_attempt_at,</if>
<if test="values.containsKey('delivered_at')">delivered_at,</if>
<if test="values.containsKey('created_at')">created_at,</if>
</trim>
VALUES
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="values.containsKey('project_id')">#{values.project_id},</if>
<if test="values.containsKey('iteration_id')">#{values.iteration_id},</if>
<if test="values.containsKey('work_item_id')">#{values.work_item_id},</if>
<if test="values.containsKey('event_type')">#{values.event_type},</if>
<if test="values.containsKey('payload')">#{values.payload},</if>
<if test="values.containsKey('attempts')">#{values.attempts},</if>
<if test="values.containsKey('next_attempt_at')">#{values.next_attempt_at},</if>
<if test="values.containsKey('delivered_at')">#{values.delivered_at},</if>
<if test="values.containsKey('created_at')">#{values.created_at},</if>
</trim>
</insert>
</mapper>