fix(3.2.0) Dashboard对应mapper函数少参数,用于条件判断

* style: 格式化mysql的SQL文件
* style: 格式化mysql的mapper.xml文件
* fix: Dashboard对应mapper函数少参数,用于条件判断
* fix: `job_summary`表缺`system_task_type`字段
This commit is contained in:
dhb52 2024-03-29 05:37:55 +00:00 committed by byteblogs168
parent 035f468749
commit 8c58aca247
14 changed files with 236 additions and 213 deletions

View File

@ -413,6 +413,7 @@ CREATE TABLE `job_summary`
`namespace_id` VARCHAR(64) NOT NULL DEFAULT '764d604ec6fc45f68cd92514c40e9e1a' COMMENT '命名空间id',
`group_name` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '组名称',
`business_id` bigint NOT NULL COMMENT '业务id (job_id或workflow_id)',
`system_task_type` tinyint(4) NOT NULL DEFAULT '3' COMMENT '任务类型 3、JOB任务 4、WORKFLOW任务',
`trigger_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '统计时间',
`success_num` int NOT NULL DEFAULT '0' COMMENT '执行成功-日志数量',
`fail_num` int NOT NULL DEFAULT '0' COMMENT '执行失败-日志数量',

View File

@ -4,7 +4,6 @@ import com.aizuda.easy.retry.template.datasource.persistence.dataobject.Dashboar
import com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO;
import com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardRetryLineResponseDO;
import com.aizuda.easy.retry.template.datasource.persistence.po.Job;
import com.aizuda.easy.retry.template.datasource.persistence.po.JobNotifyConfig;
import com.aizuda.easy.retry.template.datasource.persistence.po.JobSummary;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -13,7 +12,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -28,9 +26,9 @@ public interface JobSummaryMapper extends BaseMapper<JobSummary> {
IPage<DashboardRetryLineResponseDO.Task> jobTaskList(@Param("ew") Wrapper<Job> wrapper, Page<Object> page);
List<DashboardLineResponseDO> jobLineList(@Param("ew") Wrapper<JobSummary> wrapper);
List<DashboardLineResponseDO> jobLineList(String dateFormat, @Param("ew") Wrapper<JobSummary> wrapper);
List<DashboardRetryLineResponseDO.Rank> dashboardRank(@Param("ew") Wrapper<JobSummary> wrapper);
List<DashboardRetryLineResponseDO.Rank> dashboardRank(Integer systemTaskType, @Param("ew") Wrapper<JobSummary> wrapper);
DashboardCardResponseDO.JobTask toJobTask(@Param("ew") Wrapper<JobSummary> wrapper);
}

View File

@ -32,7 +32,7 @@ public interface RetrySummaryMapper extends BaseMapper<RetrySummary> {
IPage<DashboardRetryLineResponseDO.Task> retryTaskList(@Param("ew") Wrapper<SceneConfig> wrapper, Page<Object> page);
List<DashboardLineResponseDO> retryLineList(@Param("ew") Wrapper<RetrySummary> wrapper);
List<DashboardLineResponseDO> retryLineList(String type, @Param("ew") Wrapper<RetrySummary> wrapper);
List<DashboardRetryLineResponseDO.Rank> dashboardRank(@Param("ew") Wrapper<RetrySummary> wrapper);
}

View File

@ -27,17 +27,16 @@
</resultMap>
<update id="updateBatchNextTriggerAtById" parameterType="java.util.List">
update job rt,
UPDATE job rt,
(
<foreach collection="list" item="item" index="index" separator=" union all ">
select
#{item.nextTriggerAt} as next_trigger_at,
#{item.id} as id
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.nextTriggerAt} AS next_trigger_at,
#{item.id} AS id
</foreach>
) tt
set
rt.next_trigger_at = tt.next_trigger_at
where rt.id = tt.id
SET rt.next_trigger_at = tt.next_trigger_at
WHERE rt.id = tt.id
</update>
</mapper>

View File

@ -20,8 +20,7 @@
</resultMap>
<insert id="insertOrUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO
job_summary (namespace_id, group_name, business_id, trigger_at, system_task_type,
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=",">
@ -41,24 +40,24 @@
)
</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`)
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>
<select id="jobLineList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardLineResponseDO">
SELECT
DATE_FORMAT(trigger_at, #{dateFormat}) AS createDt,
ifnull(SUM(success_num), 0) AS success,
ifnull(SUM(stop_num), 0) AS stop,
ifnull(SUM(cancel_num), 0) AS cancel,
ifnull(SUM(fail_num), 0) AS fail,
ifnull(SUM(success_num + fail_num + stop_num + cancel_num), 0) AS total
IFNULL(SUM(success_num), 0) AS success,
IFNULL(SUM(stop_num), 0) AS stop,
IFNULL(SUM(cancel_num), 0) AS cancel,
IFNULL(SUM(fail_num), 0) AS fail,
IFNULL(SUM(success_num + fail_num + stop_num + cancel_num), 0) AS total
FROM job_summary
${ew.customSqlSegment}
GROUP BY DATE_FORMAT(trigger_at, #{dateFormat})
@ -67,11 +66,11 @@
<select id="toJobTask"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$JobTask">
SELECT
ifnull(sum(success_num), 0) AS successNum,
ifnull(sum(stop_num), 0) AS stopNum,
ifnull(sum(cancel_num), 0) AS cancelNum,
ifnull(sum(fail_num), 0) AS failNum,
ifnull(sum(success_num + fail_num + stop_num + cancel_num), 0) AS totalNum
IFNULL(SUM(success_num), 0) AS successNum,
IFNULL(SUM(stop_num), 0) AS stopNum,
IFNULL(SUM(cancel_num), 0) AS cancelNum,
IFNULL(SUM(fail_num), 0) AS failNum,
IFNULL(SUM(success_num + fail_num + stop_num + cancel_num), 0) AS totalNum
FROM job_summary
${ew.customSqlSegment}
</select>
@ -85,17 +84,19 @@
<if test="systemTaskType == 4">
CONCAT(group_name, '/', (SELECT workflow_name FROM workflow WHERE id = business_id)) name,
</if>
SUM(fail_num) AS total FROM job_summary
SUM(fail_num) AS total
FROM job_summary
${ew.customSqlSegment}
HAVING total > 0
ORDER BY total DESC LIMIT 10
ORDER BY total DESC
LIMIT 10
</select>
<select id="jobTaskList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardRetryLineResponseDO$Task">
SELECT group_name AS groupName,
SUM(CASE WHEN (job_status = 1) THEN 1 ELSE 0 END) AS run,
count(*) AS total
COUNT(*) AS total
FROM job
${ew.customSqlSegment}
GROUP BY namespace_id, group_name

View File

@ -15,19 +15,30 @@
<result column="task_type" jdbcType="TINYINT" property="taskType"/>
<result column="create_dt" jdbcType="TIMESTAMP" property="createDt" />
</resultMap>
<sql id="Base_Column_List">
id, unique_id, group_name, scene_name, idempotent_id, biz_no, executor_name, args_str, ext_attrs, create_dt, task_type
</sql>
<insert id="insertBatch">
insert into retry_dead_letter (namespace_id, unique_id, group_name, scene_name,
INSERT INTO retry_dead_letter (namespace_id, unique_id, group_name, scene_name,
idempotent_id, biz_no, executor_name, args_str,
ext_attrs, create_dt
)
values
VALUES
<foreach collection="retryDeadLetters" item="retryDeadLetter" separator=",">
(#{retryDeadLetter.namespaceId,jdbcType=VARCHAR}, #{retryDeadLetter.uniqueId,jdbcType=VARCHAR}, #{retryDeadLetter.groupName,jdbcType=VARCHAR}, #{retryDeadLetter.sceneName,jdbcType=VARCHAR},
#{retryDeadLetter.idempotentId,jdbcType=VARCHAR}, #{retryDeadLetter.bizNo,jdbcType=VARCHAR}, #{retryDeadLetter.executorName,jdbcType=VARCHAR}, #{retryDeadLetter.argsStr,jdbcType=VARCHAR},
#{retryDeadLetter.extAttrs,jdbcType=VARCHAR}, #{retryDeadLetter.createDt,jdbcType=TIMESTAMP})
(
#{retryDeadLetter.namespaceId,jdbcType=VARCHAR},
#{retryDeadLetter.uniqueId,jdbcType=VARCHAR},
#{retryDeadLetter.groupName,jdbcType=VARCHAR},
#{retryDeadLetter.sceneName,jdbcType=VARCHAR},
#{retryDeadLetter.idempotentId,jdbcType=VARCHAR},
#{retryDeadLetter.bizNo,jdbcType=VARCHAR},
#{retryDeadLetter.executorName,jdbcType=VARCHAR},
#{retryDeadLetter.argsStr,jdbcType=VARCHAR},
#{retryDeadLetter.extAttrs,jdbcType=VARCHAR},
#{retryDeadLetter.createDt,jdbcType=TIMESTAMP}
)
</foreach>
</insert>

View File

@ -41,8 +41,7 @@
<select id="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,
IFNULL(SUM(finish_num), 0) AS finishNum,
IFNULL(SUM(max_count_num), 0) AS maxCountNum,
IFNULL(SUM(suspend_num), 0) AS suspendNum,
@ -53,8 +52,11 @@
<select id="retryTaskBarList"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardCardResponseDO$RetryTask">
SELECT
trigger_at, running_num, finish_num, max_count_num, suspend_num
SELECT trigger_at,
running_num,
finish_num,
max_count_num,
suspend_num
FROM retry_summary
${ew.customSqlSegment}
LIMIT 7
@ -93,13 +95,13 @@
<select id="dashboardRank"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.DashboardRetryLineResponseDO$Rank">
SELECT
CONCAT(group_name, '/', scene_name) `name`,
SELECT CONCAT(group_name, '/', scene_name) `name`,
SUM(running_num + finish_num + max_count_num + suspend_num) AS total
FROM retry_summary
${ew.customSqlSegment}
HAVING total > 0
ORDER BY total DESC LIMIT 10
ORDER BY total DESC
LIMIT 10
</select>
<select id="retryTaskList"

View File

@ -17,8 +17,7 @@
<result column="create_dt" jdbcType="TIMESTAMP" property="createDt"/>
</resultMap>
<sql id="Base_Column_List">
id
, unique_id, group_name, scene_name, idempotent_id, biz_no, executor_name, args_str, ext_attrs, retry_status,
id, unique_id, group_name, scene_name, idempotent_id, biz_no, executor_name, args_str, ext_attrs, retry_status,
create_dt, task_type, namespace_id
</sql>

View File

@ -42,8 +42,7 @@
#{item.id} AS id
</foreach>
) tt
SET
jlm.message = tt.message, jlm.log_num = tt.log_num
SET jlm.message = tt.message, jlm.log_num = tt.log_num
WHERE jlm.id = tt.id
</update>

View File

@ -32,16 +32,15 @@
</foreach>
</insert>
<update id="updateBatchNextTriggerAtById" parameterType="java.util.List">
update retry_task_${partition} rt,
UPDATE retry_task_${partition} rt,
(
<foreach collection="list" item="item" index="index" separator=" union all ">
select
#{item.nextTriggerAt} as next_trigger_at,
#{item.id} as id
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.nextTriggerAt} AS next_trigger_at,
#{item.id} AS id
</foreach>
) tt
set
rt.next_trigger_at = tt.next_trigger_at
where rt.id = tt.id
SET rt.next_trigger_at = tt.next_trigger_at
WHERE rt.id = tt.id
</update>
</mapper>

View File

@ -15,25 +15,39 @@
<result column="create_dt" jdbcType="TIMESTAMP" property="createDt" />
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt" />
</resultMap>
<sql id="Base_Column_List">
id, namespace_id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt
</sql>
<insert id="insertOrUpdate" 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)
values
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})
(
#{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>
ON DUPLICATE KEY UPDATE
expire_at = values(`expire_at`)
expire_at = VALUES(`expire_at`)
</insert>
<select id="countActivePod"
resultType="com.aizuda.easy.retry.template.datasource.persistence.dataobject.ActivePodQuantityResponseDO">
SELECT node_type as nodeType, count(*) as total
from server_node
SELECT
node_type AS nodeType,
COUNT(*) AS total
FROM server_node
${ew.customSqlSegment}
</select>
</mapper>

View File

@ -15,19 +15,18 @@
<result column="deleted" property="deleted" />
<result column="ext_attrs" property="extAttrs" />
</resultMap>
<update id="updateBatchNextTriggerAtById" parameterType="java.util.List">
update workflow rt,
UPDATE workflow rt,
(
<foreach collection="list" item="item" index="index" separator=" union all ">
select
#{item.nextTriggerAt} as next_trigger_at,
#{item.id} as id
<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
SELECT
#{item.nextTriggerAt} AS next_trigger_at,
#{item.id} AS id
</foreach>
) tt
set
rt.next_trigger_at = tt.next_trigger_at
where rt.id = tt.id
SET rt.next_trigger_at = tt.next_trigger_at
WHERE rt.id = tt.id
</update>
</mapper>

View File

@ -9,6 +9,7 @@ import com.aizuda.easy.retry.common.core.util.NetUtil;
import com.aizuda.easy.retry.common.log.EasyRetryLog;
import com.aizuda.easy.retry.server.common.dto.DistributeInstance;
import com.aizuda.easy.retry.server.common.dto.ServerNodeExtAttrs;
import com.aizuda.easy.retry.server.common.enums.DashboardLineEnum;
import com.aizuda.easy.retry.server.common.enums.SyetemTaskTypeEnum;
import com.aizuda.easy.retry.server.common.enums.SystemModeEnum;
import com.aizuda.easy.retry.server.common.register.ServerRegister;
@ -164,10 +165,10 @@ public class DashBoardServiceImpl implements DashBoardService {
LocalDateTime endDateTime = dateTypeEnum.getEndTime().apply(StrUtil.isNotBlank(endTime) ? LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null);
LambdaQueryWrapper<RetrySummary> wrapper1 = new LambdaQueryWrapper<RetrySummary>()
.in(CollUtil.isNotEmpty(groupNames), RetrySummary::getGroupName, groupNames)
.eq(StrUtil.isNotBlank(groupName), RetrySummary::getGroupName, groupNames)
.eq(StrUtil.isNotBlank(groupName), RetrySummary::getGroupName, groupName)
.eq(RetrySummary::getNamespaceId, namespaceId)
.between(RetrySummary::getTriggerAt, startDateTime, endDateTime);
List<DashboardLineResponseDO> dashboardRetryLinkeResponseDOList = retrySummaryMapper.retryLineList(wrapper1);
List<DashboardLineResponseDO> dashboardRetryLinkeResponseDOList = retrySummaryMapper.retryLineList(type, wrapper1);
List<DashboardLineResponseVO> dashboardLineResponseVOList = DispatchQuantityResponseVOConverter.INSTANCE.toDashboardLineResponseVO(dashboardRetryLinkeResponseDOList);
dateTypeEnum.getConsumer().accept(dashboardLineResponseVOList);
dashboardLineResponseVOList.sort(Comparator.comparing(a -> a.getCreateDt()));
@ -221,7 +222,7 @@ public class DashBoardServiceImpl implements DashBoardService {
.eq(JobSummary::getSystemTaskType, systemTaskType)
.eq(JobSummary::getNamespaceId, namespaceId)
.between(JobSummary::getTriggerAt, startDateTime, endDateTime);
List<DashboardLineResponseDO> dashboardLineResponseDOList = jobSummaryMapper.jobLineList(queryWrapper);
List<DashboardLineResponseDO> dashboardLineResponseDOList = jobSummaryMapper.jobLineList(DashboardLineEnum.modeOf(type).getDateFormat(), queryWrapper);
List<DashboardLineResponseVO> dashboardLineResponseVOList = DispatchQuantityResponseVOConverter.INSTANCE.toDashboardLineResponseVO(dashboardLineResponseDOList);
dateTypeEnum.getConsumer().accept(dashboardLineResponseVOList);
dashboardLineResponseVOList.sort(Comparator.comparing(a -> a.getCreateDt()));
@ -235,7 +236,7 @@ public class DashBoardServiceImpl implements DashBoardService {
.eq(JobSummary::getSystemTaskType, systemTaskType)
.eq(JobSummary::getNamespaceId, namespaceId)
.groupBy(JobSummary::getNamespaceId, JobSummary::getGroupName, JobSummary::getBusinessId);
List<DashboardRetryLineResponseDO.Rank> rankList = jobSummaryMapper.dashboardRank(wrapper);
List<DashboardRetryLineResponseDO.Rank> rankList = jobSummaryMapper.dashboardRank(systemTaskType, wrapper);
List<DashboardRetryLineResponseVO.Rank> ranks = SceneQuantityRankResponseVOConverter.INSTANCE.toDashboardRetryLineResponseVORank(rankList);
dashboardRetryLineResponseVO.setRankList(ranks);
return dashboardRetryLineResponseVO;