From f565fbc09724992d53ec6632c3e5d1de3325f328 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期四, 11 一月 2024 17:33:44 +0800 Subject: [PATCH] 1. 调整返回接口的异常捕获类为自定义异常类; 2. 修改AreaVo类中时间参数的类型; 3. 新增文档生成任务类型,并新增文档后台生成任务逻辑; --- src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt | 29 +++++++++++++++-------------- 1 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt b/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt index 72423b9..a7c6250 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt @@ -1,5 +1,6 @@ package cn.flightfeather.supervision.common.executor +import cn.flightfeather.supervision.common.exception.ResponseErrorException import org.springframework.stereotype.Component import java.time.LocalDateTime import java.util.concurrent.ConcurrentHashMap @@ -20,13 +21,13 @@ /** * 鏂板浠诲姟 */ - @Throws(IllegalStateException::class) + @Throws(ResponseErrorException::class) fun newTask(type: BgTaskType, id: String, name: String, task: () -> Boolean): BgTask { if (!taskCollection.containsKey(type)) { taskCollection[type] = ConcurrentHashMap<String, BgTask>() } val taskSet = taskCollection[type]!! - if (taskSet.containsKey(id)) throw IllegalStateException("鏃犳硶鍒涘缓浠诲姟锛� 浠诲姟[${name}]鐨刬d閲嶅") + if (taskSet.containsKey(id)) throw ResponseErrorException("鏃犳硶鍒涘缓浠诲姟锛� 浠诲姟[${name}]鐨刬d閲嶅") val t = BgTask(type, id, name, task) taskSet[id] = t return t @@ -35,20 +36,20 @@ /** * 寮�濮嬩换鍔� */ - @Throws(IllegalStateException::class) + @Throws(ResponseErrorException::class) fun startTask(type: BgTaskType, id: String): BgTask { - val taskSet = taskCollection[type] ?: throw throw IllegalStateException("鏃犳硶寮�鍚换鍔★紝璇ヤ换鍔$被鍨媅${type.des}]涓嶅瓨鍦�") - val t = taskSet[id] ?: throw IllegalStateException("鏃犳硶寮�鍚换鍔★紝璇ヤ换鍔${id}]涓嶅瓨鍦�") + val taskSet = taskCollection[type] ?: throw throw ResponseErrorException("鏃犳硶寮�鍚换鍔★紝璇ヤ换鍔$被鍨媅${type.des}]涓嶅瓨鍦�") + val t = taskSet[id] ?: throw ResponseErrorException("鏃犳硶寮�鍚换鍔★紝璇ヤ换鍔${id}]涓嶅瓨鍦�") return startTask(t) } - @Throws(IllegalStateException::class) + @Throws(ResponseErrorException::class) fun startTask(task: BgTask): BgTask { if (task.taskStatus.status != TaskStatus.WAITING) { if (task.taskStatus.status == TaskStatus.RUNNING) { - throw IllegalStateException("鏃犳硶寮�鍚换鍔★紝浠诲姟[${task.name}]姝e湪鎵ц") + throw ResponseErrorException("鏃犳硶寮�鍚换鍔★紝浠诲姟[${task.name}]姝e湪鎵ц") } else { - throw IllegalStateException("鏃犳硶寮�鍚换鍔★紝浠诲姟[${task.name}]宸茬粨鏉�") + throw ResponseErrorException("鏃犳硶寮�鍚换鍔★紝浠诲姟[${task.name}]宸茬粨鏉�") } } else { task.ready() @@ -60,7 +61,7 @@ /** * 鏂板骞跺紑濮嬩换鍔� */ - @Throws(IllegalStateException::class) + @Throws(ResponseErrorException::class) fun startNewTask(type: BgTaskType, id: String, name: String, task: () -> Boolean): BgTask { val t = newTask(type, id, name, task) return startTask(t) @@ -95,11 +96,11 @@ /** * 寮哄埗鍏抽棴浠诲姟 */ - @Throws(IllegalStateException::class) + @Throws(ResponseErrorException::class) fun shutDownTask(type: BgTaskType, id: String?): List<BgTaskStatus?> { - val taskMap = taskCollection[type] ?: throw IllegalStateException("鏃犳硶鍏抽棴浠诲姟锛屼换鍔$被鍨媅${type.des}]鏈垱寤�") + val taskMap = taskCollection[type] ?: throw ResponseErrorException("鏃犳硶鍏抽棴浠诲姟锛屼换鍔$被鍨媅${type.des}]鏈垱寤�") return if (id != null) { - val task = taskMap[id] ?: throw IllegalStateException("鏃犳硶鍏抽棴浠诲姟锛屼换鍔${id}]涓嶅瓨鍦�") + val task = taskMap[id] ?: throw ResponseErrorException("鏃犳硶鍏抽棴浠诲姟锛屼换鍔${id}]涓嶅瓨鍦�") task.shutdown() listOf(task.taskStatus) } else { @@ -112,11 +113,11 @@ } } - @Throws(IllegalStateException::class) + @Throws(ResponseErrorException::class) fun removeTask(type: BgTaskType, id: String): Boolean { val statusList = shutDownTask(type, id) if (statusList.isNotEmpty()) { - val s = statusList.first() ?: throw IllegalStateException("鏃犳硶绉婚櫎浠诲姟锛屼换鍔′笉瀛樺湪") + val s = statusList.first() ?: throw ResponseErrorException("鏃犳硶绉婚櫎浠诲姟锛屼换鍔′笉瀛樺湪") taskCollection[s.type]?.remove(s.id) return true } -- Gitblit v1.9.3