gtsoft-snail-job-server/easy-retry-datasource/easy-retry-sqlserver-datasource/src/main/resources/sqlserver/mapper/RetrySummaryMapper.xml

145 lines
6.3 KiB
XML
Raw Normal View History

<?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.aizuda.easy.retry.template.datasource.persistence.mapper.RetrySummaryMapper">
<resultMap id="BaseResultMap" type="com.aizuda.easy.retry.template.datasource.persistence.po.RetrySummary">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="namespace_id" jdbcType="TINYINT" property="namespaceId"/>
<result column="group_name" jdbcType="TINYINT" property="groupName"/>
<result column="scene_name" jdbcType="TINYINT" property="sceneName"/>
<result column="trigger_at" jdbcType="TIMESTAMP" property="triggerAt"/>
<result column="running_num" jdbcType="TINYINT" property="runningNum"/>
<result column="finish_num" jdbcType="TINYINT" property="finishNum"/>
<result column="max_count_num" jdbcType="VARCHAR" property="maxCountNum"/>
<result column="suspend_num" jdbcType="TINYINT" property="suspendNum"/>
<result column="create_dt" jdbcType="TIMESTAMP" property="createDt"/>
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap>
<insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO job_summary (namespace_id, group_name, business_id, trigger_at, system_task_type,
success_num,fail_num,fail_reason,stop_num,stop_reason, cancel_num,cancel_reason)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.namespaceId},
#{item.groupName},
#{item.businessId},
#{item.triggerAt},
#{item.systemTaskType},
#{item.successNum},
#{item.failNum},
#{item.failReason},
#{item.stopNum},
#{item.stopReason},
#{item.cancelNum},
#{item.cancelReason}
)
</foreach>
</insert>
<update id="batchUpdate" parameterType="java.util.List">
UPDATE job_summary
SET success_num = src.success_num,
fail_num = src.fail_num,
fail_reason = src.fail_reason,
stop_num = src.stop_num,
stop_reason = src.stop_reason,
cancel_num = src.cancel_num,
cancel_reason = src.cancel_reason
FROM job_summary AS dest
JOIN (
<foreach collection="list" item="item" index="index" separator="UNION ALL">
SELECT
#{item.successNum} AS success_num,
#{item.failNum} AS fail_num,
#{item.failReason} AS fail_reason,
#{item.stopNum} AS stop_num,
#{item.stopReason} AS stop_reason,
#{item.cancelNum} AS cancel_num,
#{item.cancelReason} AS cancel_reason,
#{item.triggerAt} AS trigger_at,
#{item.businessId} AS business_id
</foreach>
) AS src
ON (dest.trigger_at = src.trigger_at AND dest.business_id = src.business_id)
</update>
<select id="retryTask"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask">
SELECT
ISNULL(SUM(running_num), 0) AS runningNum,
ISNULL(SUM(finish_num), 0) AS finishNum,
ISNULL(SUM(max_count_num), 0) AS maxCountNum,
ISNULL(SUM(suspend_num), 0) AS suspendNum,
ISNULL(SUM(running_num + finish_num + max_count_num + suspend_num), 0) AS totalNum
FROM retry_summary
${ew.customSqlSegment}
</select>
<select id="retryTaskBarList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask">
SELECT TOP 7
trigger_at,
running_num,
finish_num,
max_count_num,
suspend_num
FROM retry_summary
${ew.customSqlSegment}
</select>
<select id="retryLineList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO">
SELECT
createDt,
ISNULL(SUM(finish_num), 0) AS successNum,
ISNULL(SUM(running_num), 0) AS runningNum,
ISNULL(SUM(max_count_num), 0) AS maxCountNum,
ISNULL(SUM(suspend_num), 0) AS suspendNum,
ISNULL(SUM(finish_num + running_num + max_count_num + suspend_num), 0) AS total
FROM (
SELECT
FORMAT(create_dt, #{dateFormat}) AS createDt,
finish_num,
running_num,
max_count_num,
suspend_num
FROM retry_summary
${ew.customSqlSegment}
) AS subquery
GROUP BY createDt
</select>
<select id="dashboardRank"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardRetryLineResponseDO$Rank">
SELECT TOP 10
CONCAT(group_name, '/', scene_name) AS name,
SUM(running_num + finish_num + max_count_num + suspend_num) AS total
FROM retry_summary
${ew.customSqlSegment}
HAVING SUM(running_num + finish_num + max_count_num + suspend_num) > 0
ORDER BY total DESC
</select>
<!-- SQL Server GROUP BY 的分页必须 ORDER BY xxx -->
<select id="retryTaskList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardRetryLineResponseDO$Task">
SELECT
group_name AS groupName,
SUM(CASE WHEN (scene_status = 1) THEN 1 ELSE 0 END) AS run,
COUNT(*) AS total
FROM scene_config
${ew.customSqlSegment}
GROUP BY namespace_id, group_name
ORDER BY group_name
</select>
<!-- 用于 retryTaskList 分页的 自定义 COUNT,
SQL Server SELECT COUNT(*) FROM (... ORDER BY group_name) 会报错 -->
<select id="sqlServer_jobTaskList_Count" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT group_name)
FROM scene_config
${ew.customSqlSegment}
</select>
</mapper>