feat(3.2.0): inserOrUpdate的改造, 数据库适配

This commit is contained in:
dhb52 2024-03-31 16:13:39 +08:00
parent 31b317a3b1
commit 2eb6324990
16 changed files with 558 additions and 428 deletions

View File

@ -19,9 +19,8 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO INSERT INTO job_summary (namespace_id, group_name, business_id, trigger_at, system_task_type,
job_summary (namespace_id, group_name, business_id, trigger_at,
success_num,fail_num,fail_reason,stop_num,stop_reason, cancel_num,cancel_reason) success_num,fail_num,fail_reason,stop_num,stop_reason, cancel_num,cancel_reason)
VALUES VALUES
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
@ -40,26 +39,46 @@
#{item.cancelReason} #{item.cancelReason}
) )
</foreach> </foreach>
ON DUPLICATE KEY UPDATE
success_num = values(`success_num`),
fail_num = values(`fail_num`),
fail_reason = values(`fail_reason`),
stop_num = values(`stop_num`),
stop_reason = values(`stop_reason`),
cancel_num = values(`cancel_num`),
cancel_reason = values(`cancel_reason`)
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List">
UPDATE job_summary rt,
(
<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>
) tt
SET
rt.success_num = tt.success_num,
rt.fail_num = tt.fail_num,
rt.fail_reason = tt.fail_reason,
rt.stop_num = tt.stop_num,
rt.stop_reason = tt.stop_reason,
rt.cancel_num = tt.cancel_num,
rt.cancel_reason = tt.cancel_reason
WHERE rt.trigger_at = tt.trigger_at
AND rt.business_id = tt.business_id
</update>
<select id="jobLineList" <select id="jobLineList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO">
SELECT SELECT
DATE_FORMAT(trigger_at, #{dateFormat}) AS createDt, DATE_FORMAT(trigger_at, #{dateFormat}) AS createDt,
ifnull(SUM(success_num), 0) AS success, IFNULL(SUM(success_num), 0) AS success,
ifnull(SUM(fail_num), 0) AS failNum, IFNULL(SUM(fail_num), 0) AS failNum,
ifnull(SUM(stop_num), 0) AS stop, IFNULL(SUM(stop_num), 0) AS stop,
ifnull(SUM(cancel_num), 0) AS cancel, IFNULL(SUM(cancel_num), 0) AS cancel,
ifnull(SUM(fail_num + stop_num + cancel_num), 0) AS fail, IFNULL(SUM(fail_num + stop_num + cancel_num), 0) AS fail,
ifnull(SUM(success_num + fail_num + stop_num + cancel_num), 0) AS total IFNULL(SUM(success_num + fail_num + stop_num + cancel_num), 0) AS total
FROM job_summary FROM job_summary
${ew.customSqlSegment} ${ew.customSqlSegment}
GROUP BY DATE_FORMAT(trigger_at, #{dateFormat}) GROUP BY DATE_FORMAT(trigger_at, #{dateFormat})
@ -67,11 +86,11 @@
<select id="toJobTask" <select id="toJobTask"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$JobTask"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$JobTask">
SELECT ifnull(sum(success_num), 0) AS successNum, SELECT IFNULL(sum(success_num), 0) AS successNum,
ifnull(sum(stop_num), 0) AS stopNum, IFNULL(sum(stop_num), 0) AS stopNum,
ifnull(sum(cancel_num), 0) AS cancelNum, IFNULL(sum(cancel_num), 0) AS cancelNum,
ifnull(sum(fail_num), 0) AS failNum, IFNULL(sum(fail_num), 0) AS failNum,
ifnull(sum(success_num + fail_num + stop_num + cancel_num), 0) AS totalNum IFNULL(sum(success_num + fail_num + stop_num + cancel_num), 0) AS totalNum
FROM job_summary FROM job_summary
${ew.customSqlSegment} ${ew.customSqlSegment}
</select> </select>

View File

@ -15,10 +15,9 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO INSERT INTO retry_summary (namespace_id, group_name, scene_name, trigger_at,
retry_summary (namespace_id, group_name, scene_name, trigger_at, running_num, finish_num, max_count_num, running_num, finish_num, max_count_num, suspend_num)
suspend_num)
VALUES VALUES
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
( (
@ -32,13 +31,33 @@
#{item.suspendNum} #{item.suspendNum}
) )
</foreach> </foreach>
ON DUPLICATE KEY UPDATE
running_num = values(`running_num`),
finish_num = values(`finish_num`),
max_count_num = values(`max_count_num`),
suspend_num = values(`suspend_num`)
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List">
UPDATE retry_summary rt,
(
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.runningNum} AS running_num,
#{item.finishNum} AS finish_num,
#{item.maxCountNum} AS max_count_num,
#{item.suspendNum} AS suspend_num,
#{item.triggerAt} AS trigger_at,
#{item.sceneName} AS scene_name,
#{item.namespaceId} AS namespace_id,
#{item.groupName} AS group_name
</foreach>
) tt
SET rt.running_num = tt.running_num,
rt.finish_num = tt.finish_num,
rt.max_count_num = tt.max_count_num,
rt.suspend_num = tt.suspend_num
WHERE rt.trigger_at = tt.trigger_at
AND rt.group_name = tt.group_name
AND rt.namespace_id = tt.namespace_id
AND rt.scene_name = tt.scene_name
</update>
<select id="retryTask" <select id="retryTask"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask">
SELECT ifnull(sum(running_num), 0) AS runningNum, SELECT ifnull(sum(running_num), 0) AS runningNum,

View File

@ -17,18 +17,43 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt
</sql> </sql>
<insert id="insertOrUpdate" parameterType="com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode" useGeneratedKeys="true" keyProperty="id">
insert into server_node (namespace_id, group_name, host_id, host_ip, host_port, <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO server_node (namespace_id, group_name, host_id, host_ip, host_port,
expire_at, node_type, ext_attrs, context_path, create_dt) expire_at, node_type, ext_attrs, context_path, create_dt)
values VALUES
<foreach collection="records" item="item" index="index" separator=","> <foreach collection="records" item="item" index="index" separator=",">
(#{item.namespaceId,jdbcType=VARCHAR}, #{item.groupName,jdbcType=VARCHAR}, #{item.hostId,jdbcType=VARCHAR}, #{item.hostIp,jdbcType=VARCHAR}, (
#{item.hostPort,jdbcType=INTEGER}, #{item.expireAt,jdbcType=TIMESTAMP}, #{item.nodeType,jdbcType=TINYINT}, #{item.namespaceId,jdbcType=VARCHAR},
#{item.extAttrs,jdbcType=VARCHAR}, #{item.contextPath,jdbcType=VARCHAR}, #{item.createDt,jdbcType=TIMESTAMP}) #{item.groupName,jdbcType=VARCHAR},
#{item.hostId,jdbcType=VARCHAR},
#{item.hostIp,jdbcType=VARCHAR},
#{item.hostPort,jdbcType=INTEGER},
#{item.expireAt,jdbcType=TIMESTAMP},
#{item.nodeType,jdbcType=TINYINT},
#{item.extAttrs,jdbcType=VARCHAR},
#{item.contextPath,jdbcType=VARCHAR},
#{item.createDt,jdbcType=TIMESTAMP}
)
</foreach> </foreach>
ON DUPLICATE KEY UPDATE
expire_at = values(`expire_at`)
</insert> </insert>
<update id="batchUpdateExpireAt" parameterType="java.util.List">
UPDATE server_node rt,
(
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.expireAt} AS expire_at,
#{item.contextPath} AS context_path,
#{item.hostId} AS host_id,
#{item.hostIp} AS host_ip
</foreach>
) tt
SET rt.expire_at = tt.expire_at,
rt.context_path = tt.context_path
WHERE rt.host_id = tt.host_id and rt.host_ip = tt.host_ip
</update>
<select id="countActivePod" resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO"> <select id="countActivePod" resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO">
SELECT node_type as nodeType, count(*) as total SELECT node_type as nodeType, count(*) as total
from server_node from server_node

View File

@ -40,6 +40,7 @@
) )
</foreach> </foreach>
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List"> <update id="batchUpdate" parameterType="java.util.List">
UPDATE job_summary rt, UPDATE job_summary rt,
( (
@ -56,15 +57,15 @@
#{item.businessId} AS business_id #{item.businessId} AS business_id
</foreach> </foreach>
) tt ) tt
SET SET rt.success_num = tt.success_num,
rt.success_num = tt.success_num,
rt.fail_num = tt.fail_num, rt.fail_num = tt.fail_num,
rt.fail_reason = tt.fail_reason, rt.fail_reason = tt.fail_reason,
rt.stop_num = tt.stop_num, rt.stop_num = tt.stop_num,
rt.stop_reason = tt.stop_reason, rt.stop_reason = tt.stop_reason,
rt.cancel_num = tt.cancel_num, rt.cancel_num = tt.cancel_num,
rt.cancel_reason = tt.cancel_reason rt.cancel_reason = tt.cancel_reason
WHERE rt.trigger_at = tt.trigger_at and rt.business_id = tt.business_id WHERE rt.trigger_at = tt.trigger_at
AND rt.business_id = tt.business_id
</update> </update>
<select id="jobLineList" <select id="jobLineList"

View File

@ -33,6 +33,7 @@
) )
</foreach> </foreach>
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List"> <update id="batchUpdate" parameterType="java.util.List">
UPDATE retry_summary rt, UPDATE retry_summary rt,
( (
@ -48,15 +49,14 @@
#{item.groupName} AS group_name #{item.groupName} AS group_name
</foreach> </foreach>
) tt ) tt
SET SET rt.running_num = tt.running_num,
rt.running_num = tt.running_num,
rt.finish_num = tt.finish_num, rt.finish_num = tt.finish_num,
rt.max_count_num = tt.max_count_num, rt.max_count_num = tt.max_count_num,
rt.suspend_num = tt.suspend_num rt.suspend_num = tt.suspend_num
WHERE rt.trigger_at = tt.trigger_at WHERE rt.trigger_at = tt.trigger_at
and rt.group_name = tt.group_name AND rt.group_name = tt.group_name
and rt.namespace_id = tt.namespace_id AND rt.namespace_id = tt.namespace_id
and rt.scene_name = tt.scene_name AND rt.scene_name = tt.scene_name
</update> </update>
<select id="retryTask" <select id="retryTask"

View File

@ -17,8 +17,8 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id id, namespace_id, group_name, context_path, host_id, host_ip, host_port,
, namespace_id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt expire_at, node_type,create_dt,update_dt
</sql> </sql>
<insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
@ -40,6 +40,7 @@
) )
</foreach> </foreach>
</insert> </insert>
<update id="batchUpdateExpireAt" parameterType="java.util.List"> <update id="batchUpdateExpireAt" parameterType="java.util.List">
UPDATE server_node rt, UPDATE server_node rt,
( (
@ -51,13 +52,17 @@
#{item.hostIp} AS host_ip #{item.hostIp} AS host_ip
</foreach> </foreach>
) tt ) tt
SET rt.expire_at = tt.expire_at, rt.context_path = tt.context_path, SET rt.expire_at = tt.expire_at,
WHERE rt.host_id = tt.host_id and rt.host_ip = tt.host_ip rt.context_path = tt.context_path
WHERE rt.host_id = tt.host_id
AND rt.host_ip = tt.host_ip
</update> </update>
<select id="countActivePod" <select id="countActivePod"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO">
SELECT node_type AS nodeType, SELECT node_type AS nodeType,
COUNT(*) AS total COUNT(*) AS total
FROM server_node ${ew.customSqlSegment} FROM server_node
${ew.customSqlSegment}
</select> </select>
</mapper> </mapper>

View File

@ -19,42 +19,11 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="false" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false" keyProperty="id">
MERGE INTO job_summary dest INSERT INTO job_summary (namespace_id, group_name, business_id, trigger_at, system_task_type,
USING ( success_num,fail_num,fail_reason,stop_num,stop_reason, cancel_num,cancel_reason)
<foreach collection="list" item="item" separator=" UNION ALL "> <foreach collection="list" item="item" separator=" UNION ALL ">
SELECT SELECT
#{item.namespaceId} AS namespace_id,
#{item.groupName} AS group_name,
#{item.businessId} AS business_id,
#{item.triggerAt} AS trigger_at,
#{item.systemTaskType} AS system_task_type,
#{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
FROM DUAL
</foreach>
) src
ON (dest.business_id = src.business_id AND dest.trigger_at = src.trigger_at AND dest.system_task_type = src.system_task_type)
WHEN MATCHED THEN
UPDATE SET
dest.success_num = src.success_num,
dest.fail_num = src.fail_num,
dest.fail_reason = src.fail_reason,
dest.stop_num = src.stop_num,
dest.stop_reason = src.stop_reason,
dest.cancel_num = src.cancel_num,
dest.cancel_reason = src.cancel_reason
WHEN NOT MATCHED THEN
INSERT (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.namespaceId},
#{item.groupName}, #{item.groupName},
#{item.businessId}, #{item.businessId},
@ -67,10 +36,25 @@
#{item.stopReason}, #{item.stopReason},
#{item.cancelNum}, #{item.cancelNum},
#{item.cancelReason} #{item.cancelReason}
) FROM DUAL
</foreach> </foreach>
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="BEGIN" separator=";" close=";END;">
UPDATE job_summary
SET success_num = #{item.successNum},
fail_num = #{item.failNum},
fail_reason = #{item.failReason},
stop_num = #{item.stopNum},
stop_reason = #{item.stopReason},
cancel_num = #{item.cancelNum},
cancel_reason = #{item.cancelReason}
WHERE trigger_at = #{item.triggerAt}
AND business_id = #{item.businessId}
</foreach>
</update>
<select id="jobLineList" <select id="jobLineList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO">
SELECT SELECT

View File

@ -15,38 +15,11 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="false" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false" keyProperty="id">
MERGE INTO retry_summary dest INSERT INTO retry_summary (namespace_id, group_name, scene_name, trigger_at,
USING ( running_num, finish_num, max_count_num, suspend_num)
<foreach collection="list" item="item" separator="UNION ALL"> <foreach collection="list" item="item" separator="UNION ALL">
SELECT SELECT
#{item.namespaceId} AS namespace_id,
#{item.groupName} AS group_name,
#{item.sceneName} AS scene_name,
#{item.triggerAt} AS trigger_at,
#{item.runningNum} AS running_num,
#{item.finishNum} AS finish_num,
#{item.maxCountNum} AS max_count_num,
#{item.suspendNum AS suspend_num}
FROM DUAL
</foreach>
) src
ON (dest.namespace_id = src.namespace_id
AND dest.group_name = src.group_name
AND dest.scene_name = src.scene_name
AND dest.trigger_at = src.trigger_at)
WHEN MATCHED THEN
UPDATE SET
dest.running_num = src.running_num,
dest.finish_num = src.finish_num,
dest.max_count_num = src.max_count_num,
dest.suspend_num = src.suspend_num
WHEN NOT MATCHED THEN
INSERT (namespace_id, group_name, scene_name, trigger_at,
running_num, finish_num, max_count_num, suspend_num)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.namespaceId}, #{item.namespaceId},
#{item.groupName}, #{item.groupName},
#{item.sceneName}, #{item.sceneName},
@ -55,10 +28,24 @@
#{item.finishNum}, #{item.finishNum},
#{item.maxCountNum}, #{item.maxCountNum},
#{item.suspendNum} #{item.suspendNum}
) FROM DUAL
</foreach> </foreach>
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="BEGIN" separator=";" close=";END;">
UPDATE retry_summary
SET running_num = #{item.runningNum},
finish_num = #{item.finishNum},
max_count_num = #{item.maxCountNum},
suspend_num = #{item.suspendNum}
WHERE trigger_at = #{item.triggerAt}
AND group_name = #{item.groupName}
AND namespace_id = #{item.namespaceId}
AND scene_name = #{item.sceneName}
</foreach>
</update>
<select id="retryTask" <select id="retryTask"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask">
SELECT COALESCE(sum(running_num), 0) AS runningNum, SELECT COALESCE(sum(running_num), 0) AS runningNum,
@ -75,8 +62,7 @@
SELECT * SELECT *
FROM FROM
( (
SELECT SELECT trigger_at, running_num, finish_num, max_count_num, suspend_num
trigger_at, running_num, finish_num, max_count_num, suspend_num
FROM retry_summary FROM retry_summary
${ew.customSqlSegment} ${ew.customSqlSegment}
) )

View File

@ -19,40 +19,36 @@
id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt
</sql> </sql>
<insert id="insertOrUpdate" parameterType="com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode" <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false" keyProperty="id">
useGeneratedKeys="false" keyProperty="id"> <!-- useGeneratedKeys="false" 否则报错ORA-00933: SQL command not properly ended -->
MERGE INTO server_node dest INSERT INTO server_node (namespace_id, group_name, host_id, host_ip, host_port,
USING( expire_at, node_type, ext_attrs, context_path, create_dt)
<foreach collection="records" item="item" index="index" separator=" UNION ALL "> <foreach collection="records" item="item" index="index" separator=" UNION ">
SELECT SELECT
#{item.namespaceId,jdbcType=VARCHAR} AS namespace_id, #{item.namespaceId,jdbcType=VARCHAR},
#{item.groupName,jdbcType=VARCHAR} AS group_name, #{item.groupName,jdbcType=VARCHAR},
#{item.hostId,jdbcType=VARCHAR} AS host_id, #{item.hostId,jdbcType=VARCHAR},
#{item.hostIp,jdbcType=VARCHAR} AS host_ip, #{item.hostIp,jdbcType=VARCHAR},
#{item.hostPort,jdbcType=INTEGER} AS host_port, #{item.hostPort,jdbcType=INTEGER},
#{item.expireAt,jdbcType=TIMESTAMP} AS expire_at, #{item.expireAt,jdbcType=TIMESTAMP},
#{item.nodeType,jdbcType=TINYINT} AS node_type, #{item.nodeType,jdbcType=TINYINT},
#{item.extAttrs,jdbcType=VARCHAR} AS ext_attrs, #{item.extAttrs,jdbcType=VARCHAR},
#{item.contextPath,jdbcType=VARCHAR} AS context_path, #{item.contextPath,jdbcType=VARCHAR},
#{item.createDt,jdbcType=TIMESTAMP} AS create_dt #{item.createDt,jdbcType=TIMESTAMP}
FROM DUAL FROM DUAL
</foreach> </foreach>
) src
ON( dest.host_id = src.host_id AND dest.host_ip = src.host_ip)
WHEN MATCHED THEN
UPDATE SET expire_at = src.expire_at
WHEN NOT MATCHED THEN
INSERT (namespace_id, group_name, host_id, host_ip, host_port,
expire_at, node_type, ext_attrs, context_path, create_dt)
VALUES
<foreach collection="records" item="item" index="index" separator=",">
(#{item.namespaceId,jdbcType=VARCHAR}, #{item.groupName,jdbcType=VARCHAR}, #{item.hostId,jdbcType=VARCHAR}, #{item.hostIp,jdbcType=VARCHAR},
#{item.hostPort,jdbcType=INTEGER}, #{item.expireAt,jdbcType=TIMESTAMP}, #{item.nodeType,jdbcType=TINYINT},
#{item.extAttrs,jdbcType=VARCHAR}, #{item.contextPath,jdbcType=VARCHAR}, #{item.createDt,jdbcType=TIMESTAMP})
</foreach>
</insert> </insert>
<update id="batchUpdateExpireAt" parameterType="java.util.List">
<foreach collection="list" item="item" open="BEGIN" separator=";" close=";END;">
UPDATE server_node
SET expire_at = #{item.expireAt},
context_path = #{item.contextPath}
WHERE host_id = #{item.hostId}
AND host_ip = #{item.hostIp}
</foreach>
</update>
<select id="countActivePod" <select id="countActivePod"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO">
SELECT SELECT

View File

@ -19,9 +19,8 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO INSERT INTO job_summary (namespace_id, group_name, business_id, trigger_at, system_task_type,
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) success_num,fail_num,fail_reason,stop_num,stop_reason, cancel_num,cancel_reason)
VALUES VALUES
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
@ -40,16 +39,35 @@
#{item.cancelReason} #{item.cancelReason}
) )
</foreach> </foreach>
ON CONFLICT (business_id, trigger_at, system_task_type) DO UPDATE
SET success_num = EXCLUDED.success_num,
fail_num = EXCLUDED.fail_num,
fail_reason = EXCLUDED.fail_reason,
stop_num = EXCLUDED.stop_num,
stop_reason = EXCLUDED.stop_reason,
cancel_num = EXCLUDED.cancel_num,
cancel_reason = EXCLUDED.cancel_reason
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List">
UPDATE job_summary AS rt
SET success_num = tt.success_num,
fail_num = tt.fail_num,
fail_reason = tt.fail_reason,
stop_num = tt.stop_num,
stop_reason = tt.stop_reason,
cancel_num = tt.cancel_num,
cancel_reason = tt.cancel_reason
FROM (
<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 tt
WHERE rt.trigger_at = tt.trigger_at
AND rt.business_id = tt.business_id
</update>
<select id="jobLineList" <select id="jobLineList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO">
SELECT SELECT

View File

@ -15,10 +15,9 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO INSERT INTO retry_summary (namespace_id, group_name, scene_name, trigger_at,
retry_summary (namespace_id, group_name, scene_name, trigger_at, running_num, finish_num, max_count_num, running_num, finish_num, max_count_num, suspend_num)
suspend_num)
VALUES VALUES
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
( (
@ -32,13 +31,33 @@
#{item.suspendNum} #{item.suspendNum}
) )
</foreach> </foreach>
ON CONFLICT (namespace_id, group_name, scene_name, trigger_at) DO UPDATE
SET running_num = EXCLUDED.running_num,
finish_num = EXCLUDED.finish_num,
max_count_num = EXCLUDED.max_count_num,
suspend_num = EXCLUDED.suspend_num
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List">
UPDATE retry_summary AS rt
SET running_num = tt.running_num,
finish_num = tt.finish_num,
max_count_num = tt.max_count_num,
suspend_num = tt.suspend_num
FROM (
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.runningNum} AS running_num,
#{item.finishNum} AS finish_num,
#{item.maxCountNum} AS max_count_num,
#{item.suspendNum} AS suspend_num,
#{item.triggerAt} AS trigger_at,
#{item.sceneName} AS scene_name,
#{item.namespaceId} AS namespace_id,
#{item.groupName} AS group_name
</foreach>
) AS tt
WHERE rt.trigger_at = tt.trigger_at
AND rt.group_name = tt.group_name
AND rt.namespace_id = tt.namespace_id
AND rt.scene_name = tt.scene_name
</update>
<select id="retryTask" <select id="retryTask"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask">
SELECT COALESCE(sum(running_num), 0) AS runningNum, SELECT COALESCE(sum(running_num), 0) AS runningNum,

View File

@ -17,19 +17,44 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt
</sql> </sql>
<insert id="insertOrUpdate" parameterType="com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode"
useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO server_node (namespace_id, group_name, host_id, host_ip, host_port, INSERT INTO server_node (namespace_id, group_name, host_id, host_ip, host_port,
expire_at, node_type, ext_attrs, context_path, create_dt) expire_at, node_type, ext_attrs, context_path, create_dt)
VALUES VALUES
<foreach collection="records" item="item" index="index" separator=","> <foreach collection="records" item="item" index="index" separator=",">
(#{item.namespaceId,jdbcType=VARCHAR}, #{item.groupName,jdbcType=VARCHAR}, #{item.hostId,jdbcType=VARCHAR}, #{item.hostIp,jdbcType=VARCHAR}, (
#{item.hostPort,jdbcType=INTEGER}, #{item.expireAt,jdbcType=TIMESTAMP}, #{item.nodeType,jdbcType=TINYINT}, #{item.namespaceId,jdbcType=VARCHAR},
#{item.extAttrs,jdbcType=VARCHAR}, #{item.contextPath,jdbcType=VARCHAR}, #{item.createDt,jdbcType=TIMESTAMP}) #{item.groupName,jdbcType=VARCHAR},
#{item.hostId,jdbcType=VARCHAR},
#{item.hostIp,jdbcType=VARCHAR},
#{item.hostPort,jdbcType=INTEGER},
#{item.expireAt,jdbcType=TIMESTAMP},
#{item.nodeType,jdbcType=TINYINT},
#{item.extAttrs,jdbcType=VARCHAR},
#{item.contextPath,jdbcType=VARCHAR},
#{item.createDt,jdbcType=TIMESTAMP}
)
</foreach> </foreach>
ON CONFLICT (host_id, host_ip) DO UPDATE SET expire_at = EXCLUDED.expire_at
</insert> </insert>
<update id="batchUpdateExpireAt" parameterType="java.util.List">
UPDATE server_node AS rt
SET expire_at = tt.expire_at,
context_path = tt.context_path
FROM (
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.expireAt} AS expire_at,
#{item.contextPath} AS context_path,
#{item.hostId} AS host_id,
#{item.hostIp} AS host_ip
</foreach>
) AS tt
WHERE rt.host_id = tt.host_id
AND rt.host_ip = tt.host_ip
</update>
<select id="countActivePod" <select id="countActivePod"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO">
SELECT node_type as nodeType, count(*) as total SELECT node_type as nodeType, count(*) as total

View File

@ -28,14 +28,15 @@
<update id="updateBatchNextTriggerAtById" parameterType="java.util.List"> <update id="updateBatchNextTriggerAtById" parameterType="java.util.List">
UPDATE job UPDATE job
SET job.next_trigger_at = src.next_trigger_at SET next_trigger_at = src.next_trigger_at
FROM job FROM job AS dest
JOIN ( JOIN (
<foreach collection="list" item="item" index="index" separator=" UNION ALL "> <foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT SELECT
#{item.nextTriggerAt} AS next_trigger_at, #{item.nextTriggerAt} AS next_trigger_at,
#{item.id} AS id #{item.id} AS id
</foreach> </foreach>
) AS src ON job.id = src.id; ) AS src
ON (dest.id = src.id)
</update> </update>
</mapper> </mapper>

View File

@ -19,9 +19,9 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
MERGE INTO job_summary AS target INSERT INTO job_summary (namespace_id, group_name, business_id, trigger_at, system_task_type,
USING ( success_num,fail_num,fail_reason,stop_num,stop_reason, cancel_num,cancel_reason)
VALUES VALUES
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
( (
@ -39,27 +39,35 @@
#{item.cancelReason} #{item.cancelReason}
) )
</foreach> </foreach>
) AS source (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)
ON target.namespace_id = source.namespace_id
AND target.business_id = source.business_id
WHEN MATCHED THEN
UPDATE SET
target.success_num = source.success_num,
target.fail_num = source.fail_num,
target.fail_reason = source.fail_reason,
target.stop_num = source.stop_num,
target.stop_reason = source.stop_reason,
target.cancel_num = source.cancel_num,
target.cancel_reason = source.cancel_reason
WHEN NOT MATCHED THEN
INSERT (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 (source.namespace_id, source.group_name, source.business_id, source.trigger_at, source.system_task_type,
source.success_num, source.fail_num, source.fail_reason, source.stop_num, source.stop_reason,
source.cancel_num, source.cancel_reason);
</insert> </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="jobLineList" <select id="jobLineList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO">
SELECT SELECT

View File

@ -15,41 +15,55 @@
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt"/>
</resultMap> </resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
MERGE INTO retry_summary AS target INSERT INTO job_summary (namespace_id, group_name, business_id, trigger_at, system_task_type,
USING ( success_num,fail_num,fail_reason,stop_num,stop_reason, cancel_num,cancel_reason)
VALUES VALUES
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
( (
#{item.namespaceId}, #{item.namespaceId},
#{item.groupName}, #{item.groupName},
#{item.sceneName}, #{item.businessId},
#{item.triggerAt}, #{item.triggerAt},
#{item.runningNum}, #{item.systemTaskType},
#{item.finishNum}, #{item.successNum},
#{item.maxCountNum}, #{item.failNum},
#{item.suspendNum} #{item.failReason},
#{item.stopNum},
#{item.stopReason},
#{item.cancelNum},
#{item.cancelReason}
) )
</foreach> </foreach>
) AS source (namespace_id, group_name, scene_name, trigger_at,
running_num, finish_num, max_count_num, suspend_num)
ON target.namespace_id = source.namespace_id
AND target.group_name = source.group_name
AND target.scene_name = source.scene_name
AND target.trigger_at = source.trigger_at
WHEN MATCHED THEN
UPDATE SET
target.running_num = source.running_num,
target.finish_num = source.finish_num,
target.max_count_num = source.max_count_num,
target.suspend_num = source.suspend_num
WHEN NOT MATCHED THEN
INSERT (namespace_id, group_name, scene_name, trigger_at,
running_num, finish_num, max_count_num, suspend_num)
VALUES (source.namespace_id, source.group_name, source.scene_name, source.trigger_at,
source.running_num, source.finish_num, source.max_count_num, source.suspend_num);
</insert> </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" <select id="retryTask"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask">
SELECT SELECT

View File

@ -20,33 +20,43 @@
id, namespace_id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt id, namespace_id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt
</sql> </sql>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
MERGE INTO server_node AS target INSERT INTO server_node (namespace_id, group_name, host_id, host_ip, host_port,
USING ( expire_at, node_type, ext_attrs, context_path, create_dt)
VALUES VALUES
<foreach collection="records" item="item" index="index" separator=","> <foreach collection="records" item="item" index="index" separator=",">
( (
#{item.namespaceId,jdbcType=VARCHAR}, #{item.groupName,jdbcType=VARCHAR}, #{item.namespaceId,jdbcType=VARCHAR},
#{item.hostId,jdbcType=VARCHAR}, #{item.hostIp,jdbcType=VARCHAR}, #{item.hostPort,jdbcType=INTEGER}, #{item.groupName,jdbcType=VARCHAR},
#{item.expireAt,jdbcType=TIMESTAMP}, #{item.nodeType,jdbcType=TINYINT}, #{item.extAttrs,jdbcType=VARCHAR}, #{item.hostId,jdbcType=VARCHAR},
#{item.contextPath,jdbcType=VARCHAR}, #{item.createDt,jdbcType=TIMESTAMP} #{item.hostIp,jdbcType=VARCHAR},
#{item.hostPort,jdbcType=INTEGER},
#{item.expireAt,jdbcType=TIMESTAMP},
#{item.nodeType,jdbcType=TINYINT},
#{item.extAttrs,jdbcType=VARCHAR},
#{item.contextPath,jdbcType=VARCHAR},
#{item.createDt,jdbcType=TIMESTAMP}
) )
</foreach> </foreach>
) AS source (namespace_id, group_name, host_id, host_ip, host_port,
expire_at, node_type, ext_attrs, context_path, create_dt)
ON target.namespace_id = source.namespace_id
AND target.group_name = source.group_name
AND target.host_id = source.host_id
WHEN MATCHED THEN
UPDATE SET
target.expire_at = source.expire_at, target.update_dt = GETDATE()
WHEN NOT MATCHED THEN
INSERT (namespace_id, group_name, host_id, host_ip, host_port,
expire_at, node_type, ext_attrs, context_path, create_dt, update_dt)
VALUES (source.namespace_id, source.group_name, source.host_id, source.host_ip, source.host_port,
source.expire_at, source.node_type, source.ext_attrs, source.context_path, source.create_dt, GETDATE());
</insert> </insert>
<update id="batchUpdateExpireAt" parameterType="java.util.List">
UPDATE server_node
SET expire_at = src.expire_at,
context_path = src.context_path
FROM server_node AS dest
JOIN (
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.expireAt} AS expire_at,
#{item.contextPath} AS context_path,
#{item.hostId} AS host_id,
#{item.hostIp} AS host_ip
</foreach>
) AS src
ON (dest.host_id = src.host_id AND dest.host_ip = src.host_ip)
</update>
<select id="countActivePod" <select id="countActivePod"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO"> resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO">
SELECT SELECT