From 0cf80417f9463a2c076c1aa0c4c98ecaf4f41314 Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Wed, 17 Jan 2024 16:00:46 +0800 Subject: [PATCH] =?UTF-8?q?feta=20=E8=A7=A6=E5=8F=91=E5=99=A8=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=AC=A1=E6=95=B0=E7=BB=9F=E8=AE=A1=E3=80=81=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E5=99=A8=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG-BETA.md | 4 + .../controller}/CacheManageController.java | 2 +- .../controller/TriggerTokenController.java | 85 +++++++ .../jpom/model/user/TriggerTokenLogBean.java | 10 + .../dromara/jpom/service/ITriggerToken.java | 10 + .../service/user/TriggerTokenLogServer.java | 55 +++++ .../resources/sql-view/alter.all.v1.4.csv | 1 + .../dromara/jpom/db/BaseDbCommonService.java | 6 + web-vue/src/api/trigger-token.ts | 25 +++ web-vue/src/pages/system/cache.vue | 11 +- web-vue/src/pages/system/trigger-token.vue | 209 ++++++++++++++++++ 11 files changed, 414 insertions(+), 4 deletions(-) rename modules/server/src/main/java/org/dromara/jpom/{controller/system => func/system/controller}/CacheManageController.java (99%) create mode 100644 modules/server/src/main/java/org/dromara/jpom/func/system/controller/TriggerTokenController.java create mode 100644 web-vue/src/api/trigger-token.ts create mode 100644 web-vue/src/pages/system/trigger-token.vue diff --git a/CHANGELOG-BETA.md b/CHANGELOG-BETA.md index 74643b53f..57928ca97 100644 --- a/CHANGELOG-BETA.md +++ b/CHANGELOG-BETA.md @@ -2,6 +2,10 @@ ## 2.11.1.2-beta +### 🐣 新增功能 + +1. 【server】新增 触发器调用次数统计、触发器统一管理 + ### 🐞 解决BUG、优化功能 1. 【all】优化 机器状态新增:资源监控异常(资源监控异常不影响功能使用) diff --git a/modules/server/src/main/java/org/dromara/jpom/controller/system/CacheManageController.java b/modules/server/src/main/java/org/dromara/jpom/func/system/controller/CacheManageController.java similarity index 99% rename from modules/server/src/main/java/org/dromara/jpom/controller/system/CacheManageController.java rename to modules/server/src/main/java/org/dromara/jpom/func/system/controller/CacheManageController.java index 0c60ab3dc..a1587f51c 100644 --- a/modules/server/src/main/java/org/dromara/jpom/controller/system/CacheManageController.java +++ b/modules/server/src/main/java/org/dromara/jpom/func/system/controller/CacheManageController.java @@ -20,7 +20,7 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.dromara.jpom.controller.system; +package org.dromara.jpom.func.system.controller; import cn.hutool.cache.impl.CacheObj; import cn.hutool.cache.impl.LFUCache; diff --git a/modules/server/src/main/java/org/dromara/jpom/func/system/controller/TriggerTokenController.java b/modules/server/src/main/java/org/dromara/jpom/func/system/controller/TriggerTokenController.java new file mode 100644 index 000000000..5a3a8ef60 --- /dev/null +++ b/modules/server/src/main/java/org/dromara/jpom/func/system/controller/TriggerTokenController.java @@ -0,0 +1,85 @@ +package org.dromara.jpom.func.system.controller; + +import cn.hutool.core.bean.BeanUtil; +import cn.keepbx.jpom.IJsonMessage; +import cn.keepbx.jpom.model.BaseIdModel; +import cn.keepbx.jpom.model.JsonMessage; +import com.alibaba.fastjson2.JSONObject; +import org.dromara.jpom.model.PageResultDto; +import org.dromara.jpom.model.user.TriggerTokenLogBean; +import org.dromara.jpom.permission.ClassFeature; +import org.dromara.jpom.permission.Feature; +import org.dromara.jpom.permission.MethodFeature; +import org.dromara.jpom.permission.SystemPermission; +import org.dromara.jpom.service.ITriggerToken; +import org.dromara.jpom.service.user.TriggerTokenLogServer; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * @author bwcx_jzy + * @since 24/1/17 017 + */ +@RestController +@RequestMapping(value = "system/trigger") +@Feature(cls = ClassFeature.SYSTEM_CACHE) +@SystemPermission +public class TriggerTokenController { + + private final TriggerTokenLogServer triggerTokenLogServer; + + public TriggerTokenController(TriggerTokenLogServer triggerTokenLogServer) { + this.triggerTokenLogServer = triggerTokenLogServer; + } + + @GetMapping(value = "all-type", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(method = MethodFeature.LIST) + public IJsonMessage> allType() { + List jsonObjects = triggerTokenLogServer.allType(); + return JsonMessage.success("", jsonObjects); + } + + @GetMapping(value = "delete", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(method = MethodFeature.LIST) + public IJsonMessage delete(String id) { + triggerTokenLogServer.delete(id); + return JsonMessage.success("删除成功"); + } + + /** + * 分页列表 + * + * @return json + */ + @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(method = MethodFeature.LIST) + public IJsonMessage> list(HttpServletRequest request) { + PageResultDto listPage = triggerTokenLogServer.listPage(request); + listPage.each(triggerTokenLogBean -> { + String type = triggerTokenLogBean.getType(); + ITriggerToken byType = triggerTokenLogServer.getByType(type); + if (byType == null) { + triggerTokenLogBean.setDataName("ERROR:类型不存在" + type); + } else { + BaseIdModel byKey = byType.getByKey(triggerTokenLogBean.getDataId()); + if (byKey == null) { + triggerTokenLogBean.setDataName("ERROR:关联数据丢失"); + } else { + Object name = BeanUtil.getProperty(byKey, "name"); + if (name == null) { + triggerTokenLogBean.setDataName("ERROR:关联数据名称不存在"); + } else { + triggerTokenLogBean.setDataName(name.toString()); + } + } + } + }); + return JsonMessage.success("", listPage); + } +} diff --git a/modules/server/src/main/java/org/dromara/jpom/model/user/TriggerTokenLogBean.java b/modules/server/src/main/java/org/dromara/jpom/model/user/TriggerTokenLogBean.java index 613d9dca2..ffb1246ed 100644 --- a/modules/server/src/main/java/org/dromara/jpom/model/user/TriggerTokenLogBean.java +++ b/modules/server/src/main/java/org/dromara/jpom/model/user/TriggerTokenLogBean.java @@ -22,6 +22,7 @@ */ package org.dromara.jpom.model.user; +import cn.hutool.core.annotation.PropIgnore; import lombok.Data; import lombok.EqualsAndHashCode; import org.dromara.jpom.db.TableName; @@ -55,6 +56,11 @@ public class TriggerTokenLogBean extends BaseDbModel { * 关联数据ID */ private String dataId; + /** + * 关联数据名称 + */ + @PropIgnore + private String dataName; /** * 用户ID @@ -62,4 +68,8 @@ public class TriggerTokenLogBean extends BaseDbModel { * @see UserModel#getId() */ private String userId; + /** + * 触发次数 + */ + private Integer triggerCount; } diff --git a/modules/server/src/main/java/org/dromara/jpom/service/ITriggerToken.java b/modules/server/src/main/java/org/dromara/jpom/service/ITriggerToken.java index 8608bfee4..28d6e0f37 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/ITriggerToken.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/ITriggerToken.java @@ -22,6 +22,8 @@ */ package org.dromara.jpom.service; +import cn.keepbx.jpom.model.BaseIdModel; + /** * 带有触发器 token 相关实现服务 * @@ -37,6 +39,13 @@ public interface ITriggerToken { */ String typeName(); + /** + * 数据描述 + * + * @return 描述 + */ + String getDataDesc(); + /** * 判断是否存在 * @@ -45,4 +54,5 @@ public interface ITriggerToken { */ boolean exists(String dataId); + BaseIdModel getByKey(String keyValue); } diff --git a/modules/server/src/main/java/org/dromara/jpom/service/user/TriggerTokenLogServer.java b/modules/server/src/main/java/org/dromara/jpom/service/user/TriggerTokenLogServer.java index 6e948ab4f..5f5def74f 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/user/TriggerTokenLogServer.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/user/TriggerTokenLogServer.java @@ -22,14 +22,17 @@ */ package org.dromara.jpom.service.user; +import cn.hutool.core.collection.CollStreamUtil; import cn.hutool.core.date.BetweenFormatter; import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.SystemClock; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.db.Entity; import cn.hutool.db.Page; import cn.keepbx.jpom.event.ISystemTask; +import com.alibaba.fastjson2.JSONObject; import lombok.extern.slf4j.Slf4j; import org.dromara.jpom.model.PageResultDto; import org.dromara.jpom.model.user.TriggerTokenLogBean; @@ -41,6 +44,8 @@ import org.springframework.util.Assert; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * @author bwcx_jzy @@ -52,11 +57,58 @@ public class TriggerTokenLogServer extends BaseDbService im private final UserService userService; private final List triggerTokens; + private final Map triggerTokenMap; public TriggerTokenLogServer(UserService userService, List triggerTokens) { this.userService = userService; this.triggerTokens = triggerTokens; + triggerTokenMap = CollStreamUtil.toMap(triggerTokens, ITriggerToken::typeName, iTriggerToken -> iTriggerToken); + } + + /** + * 获取类型 + * + * @param type 类型名称 + * @return 接口 + */ + public ITriggerToken getByType(String type) { + return MapUtil.get(triggerTokenMap, type, ITriggerToken.class); + } + + /** + * 删除触发器 + * + * @param id Id + */ + public void delete(String id) { + TriggerTokenLogBean tokenLogBean = this.getByKey(id); + if (tokenLogBean == null) { + return; + } + ITriggerToken token = triggerTokens.stream() + .filter(iTriggerToken -> StrUtil.equals(iTriggerToken.typeName(), tokenLogBean.getType())) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("没有对应的触发器类型:" + tokenLogBean.getType())); + String sql = "update " + tokenLogBean.getType() + " set triggerToken='' where id=?"; + this.execute(sql, tokenLogBean.getDataId()); + this.delByKey(id); + } + + /** + * 获取所有类型 + * + * @return list + */ + public List allType() { + return triggerTokens.stream() + .map(iTriggerToken -> { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", iTriggerToken.typeName()); + jsonObject.put("desc", iTriggerToken.getDataDesc()); + return jsonObject; + }) + .collect(Collectors.toList()); } /** @@ -84,6 +136,9 @@ public class TriggerTokenLogServer extends BaseDbService im if (userModel != null && StrUtil.equals(type, tokenLogBean.getType())) { boolean demoUser = userModel.isDemoUser(); Assert.state(!demoUser, "当前用户触发器不可用"); + // 修改触发次数 + String sql = "update " + this.getTableName() + " set triggerCount=ifnull(triggerCount,0)+1 where id=?"; + int execute = this.execute(sql, tokenLogBean.getId()); return userModel; } } diff --git a/modules/server/src/main/resources/sql-view/alter.all.v1.4.csv b/modules/server/src/main/resources/sql-view/alter.all.v1.4.csv index 4a4a40e5c..aa0df83e7 100644 --- a/modules/server/src/main/resources/sql-view/alter.all.v1.4.csv +++ b/modules/server/src/main/resources/sql-view/alter.all.v1.4.csv @@ -13,3 +13,4 @@ ADD,NODE_INFO,jpomScriptCount,Integer,,,jpom脚本数, ALTER,STATIC_FILE_STORAGE,parentAbsolutePath,String,300,,父级文件路径,false ALTER,STATIC_FILE_STORAGE,absolutePath,String,300,,文件路径,false ALTER,STATIC_FILE_STORAGE,name,String,100,,文件名,false +ADD,TRIGGER_TOKEN_LOG,triggerCount,Integer,,,触发次数 diff --git a/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java b/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java index 13778a60d..880799832 100644 --- a/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java +++ b/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java @@ -83,6 +83,12 @@ public abstract class BaseDbCommonService { this.tableName = annotation.value(); } + public String getDataDesc() { + TableName annotation = tClass.getAnnotation(TableName.class); + Assert.notNull(annotation, "请配置 table Name"); + return annotation.name(); + } + protected DataSource getDataSource() { DSFactory dsFactory = StorageServiceFactory.get().getDsFactory(); return dsFactory.getDataSource(); diff --git a/web-vue/src/api/trigger-token.ts b/web-vue/src/api/trigger-token.ts new file mode 100644 index 000000000..653a4e267 --- /dev/null +++ b/web-vue/src/api/trigger-token.ts @@ -0,0 +1,25 @@ +import axios from './config' + +export function triggerTokenList(data) { + return axios({ + url: '/system/trigger/list', + method: 'post', + data: data + }) +} + +export function triggerTokenAllType(data) { + return axios({ + url: '/system/trigger/all-type', + method: 'get', + params: data + }) +} + +export function triggerTokenDelete(data) { + return axios({ + url: '/system/trigger/delete', + method: 'get', + params: data + }) +} diff --git a/web-vue/src/pages/system/cache.vue b/web-vue/src/pages/system/cache.vue index 60d2521b3..4ff306194 100644 --- a/web-vue/src/pages/system/cache.vue +++ b/web-vue/src/pages/system/cache.vue @@ -149,18 +149,23 @@ --> - + + + + +