From a41cf922d4114486cb5b9391664a8d7d8ff8234a Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 8 Nov 2022 12:47:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=97=A5=E5=BF=97):=20=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/service/impl/ShiroServiceImpl.java | 1 + .../commons/constants/SysLogConstants.java | 3 +- .../io/dataease/commons/utils/DeLogUtils.java | 14 ++++---- .../controller/panel/api/LinkApi.java | 10 +++++- .../controller/panel/server/LinkServer.java | 18 ++++++++++ .../panel/link/LinkViewLogRequest.java | 12 +++++++ .../dataease/service/sys/log/LogManager.java | 35 ++++++++++--------- .../dataease/service/sys/log/LogService.java | 12 +++++++ .../main/resources/db/migration/V44__1.17.sql | 4 +++ .../resources/i18n/messages_en_US.properties | 5 +++ .../resources/i18n/messages_zh_CN.properties | 5 +++ .../resources/i18n/messages_zh_TW.properties | 5 +++ frontend/src/api/link/index.js | 9 +++++ frontend/src/views/link/view/index.vue | 14 +++++++- frontend/src/views/system/log/index.vue | 2 +- 15 files changed, 121 insertions(+), 28 deletions(-) create mode 100644 backend/src/main/java/io/dataease/controller/request/panel/link/LinkViewLogRequest.java create mode 100644 backend/src/main/resources/db/migration/V44__1.17.sql diff --git a/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java index 0fd46ef9a90..c90acdab05a 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java @@ -118,6 +118,7 @@ public Map loadFilterChainDefinitionMap() { filterChainDefinitionMap.put("/api/link/resourceDetail/**", "link"); filterChainDefinitionMap.put("/api/link/viewDetail/**", "link"); + filterChainDefinitionMap.put("/api/link/viewLog", "link"); filterChainDefinitionMap.put("/panel/group/exportDetails", ANON); filterChainDefinitionMap.put("/dataset/field/linkMultFieldValues", "link"); filterChainDefinitionMap.put("/dataset/field/linkMappingFieldValues", "link"); diff --git a/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java b/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java index 9a6489ddc87..2c309f8f096 100644 --- a/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java +++ b/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java @@ -37,6 +37,7 @@ public enum OPERATE_TYPE { UNBIND(17, "OPERATE_TYPE_UNBIND"); private Integer value; private String name; + OPERATE_TYPE(Integer value, String name) { this.value = value; this.name = name; @@ -62,7 +63,7 @@ public enum SOURCE_TYPE { DATASET(2, "SOURCE_TYPE_DATASET"), PANEL(3, "SOURCE_TYPE_PANEL"), VIEW(4, "SOURCE_TYPE_VIEW"), - /*LINK(5, "SOURCE_TYPE_LINK"),*/ + LINK(5, "SOURCE_TYPE_LINK"), USER(6, "SOURCE_TYPE_USER"), DEPT(7, "SOURCE_TYPE_DEPT"), ROLE(8, "SOURCE_TYPE_ROLE"), diff --git a/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java b/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java index d996a2d7f47..89f58261e29 100644 --- a/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java +++ b/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java @@ -34,14 +34,14 @@ public void setLogService(LogService logService) { DeLogUtils.logService = logService; } - public static SysLogDTO buildLog(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetype, Object sourceIdValue, Object targetId, SOURCE_TYPE target_type ) { + public static SysLogDTO buildLog(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetype, Object sourceIdValue, Object targetId, SOURCE_TYPE target_type) { SysLogDTO sysLogDTO = buildLog(operatetype, sourcetype, sourceIdValue, null, targetId, target_type); if (sourcetype == SysLogConstants.SOURCE_TYPE.DATASOURCE) { FolderItem folderItem = logManager.dsTypeInfoById(sourceIdValue.toString()); List items = new ArrayList<>(); items.add(folderItem); sysLogDTO.setPositions(items); - }else { + } else { List parentsAndSelf = logManager.justParents(sourceIdValue.toString(), sourcetype); sysLogDTO.setPositions(parentsAndSelf); } @@ -66,7 +66,7 @@ public static SysLogDTO buildBindRoleUserLog(Long positionId, Long userId, OPERA return sysLogDTO; } - public static SysLogDTO buildLog(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetype, Object sourceIdValue, Object positionId, Object targetId, SOURCE_TYPE target_type ) { + public static SysLogDTO buildLog(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetype, Object sourceIdValue, Object positionId, Object targetId, SOURCE_TYPE target_type) { SysLogDTO sysLogDTO = new SysLogDTO(); sysLogDTO.setOperateType(operatetype.getValue()); sysLogDTO.setSourceType(sourcetype.getValue()); @@ -83,14 +83,14 @@ public static SysLogDTO buildLog(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetyp List items = new ArrayList<>(); items.add(folderItem); sysLogDTO.setPositions(items); - }else { - if(sourcetype == SOURCE_TYPE.DRIVER_FILE){ + } else { + if (sourcetype == SOURCE_TYPE.DRIVER_FILE) { List parentsAndSelf = logManager.parentsAndSelf(positionId.toString(), SOURCE_TYPE.DRIVER); sysLogDTO.setPositions(parentsAndSelf); - }else if(sourcetype == SOURCE_TYPE.VIEW){ + } else if (sourcetype == SOURCE_TYPE.VIEW || sourcetype == SOURCE_TYPE.LINK) { List parentsAndSelf = logManager.parentsAndSelf(positionId.toString(), SOURCE_TYPE.PANEL); sysLogDTO.setPositions(parentsAndSelf); - }else { + } else { List parentsAndSelf = logManager.parentsAndSelf(positionId.toString(), sourcetype); sysLogDTO.setPositions(parentsAndSelf); } diff --git a/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java b/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java index 158e0abacab..a27b37eae3d 100644 --- a/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java +++ b/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java @@ -4,12 +4,14 @@ import io.dataease.auth.annotation.DePermission; import io.dataease.commons.constants.DePermissionType; import io.dataease.controller.request.chart.ChartExtRequest; +import io.dataease.controller.request.panel.PanelViewLogRequest; import io.dataease.controller.request.panel.link.*; import io.dataease.dto.panel.link.GenerateDto; import io.dataease.dto.panel.link.ValidateDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; import java.util.Map; @@ -58,9 +60,15 @@ public interface LinkApi { @ApiOperation("视图详细信息") @PostMapping("/viewDetail/{viewId}/{panelId}") Object viewDetail(@PathVariable("viewId") String viewId, @PathVariable("panelId") String panelId, - @RequestBody ChartExtRequest requestList) throws Exception; + @RequestBody ChartExtRequest requestList) throws Exception; @ApiOperation("压缩链接") @PostMapping("/shortUrl") String shortUrl(@RequestBody Map param); + + @ApiIgnore + @PostMapping("/viewLog") + void viewLinkLog(@RequestBody LinkViewLogRequest request); + + } diff --git a/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java b/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java index d927a86b16f..2e0be45aec3 100644 --- a/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java +++ b/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java @@ -3,6 +3,9 @@ import com.auth0.jwt.JWT; import com.auth0.jwt.interfaces.DecodedJWT; import io.dataease.auth.filter.F2CLinkFilter; +import io.dataease.commons.constants.SysLogConstants; +import io.dataease.commons.utils.DeLogUtils; +import io.dataease.plugins.common.base.domain.PanelGroupWithBLOBs; import io.dataease.plugins.common.base.domain.PanelLink; import io.dataease.controller.panel.api.LinkApi; import io.dataease.controller.request.chart.ChartExtRequest; @@ -111,4 +114,19 @@ public String shortUrl(Map param) { String resourceId = param.get("resourceId"); return panelLinkService.getShortUrl(resourceId); } + + @Override + public void viewLinkLog(LinkViewLogRequest request) { + String panelId = request.getPanelId(); + Boolean mobile = request.getMobile(); + Long userId = request.getUserId(); + SysLogConstants.OPERATE_TYPE operateType = SysLogConstants.OPERATE_TYPE.PC_VIEW; + if (ObjectUtils.isNotEmpty(mobile) && mobile) { + operateType = SysLogConstants.OPERATE_TYPE.MB_VIEW; + } + if (ObjectUtils.isEmpty(userId)) return; + PanelGroupWithBLOBs panelGroupWithBLOBs = panelLinkService.resourceInfo(panelId); + String pid = panelGroupWithBLOBs.getPid(); + DeLogUtils.save(operateType, SysLogConstants.SOURCE_TYPE.LINK, panelId, pid, userId, SysLogConstants.SOURCE_TYPE.USER); + } } diff --git a/backend/src/main/java/io/dataease/controller/request/panel/link/LinkViewLogRequest.java b/backend/src/main/java/io/dataease/controller/request/panel/link/LinkViewLogRequest.java new file mode 100644 index 00000000000..6844c5a49d2 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/request/panel/link/LinkViewLogRequest.java @@ -0,0 +1,12 @@ +package io.dataease.controller.request.panel.link; + +import io.dataease.controller.request.panel.PanelViewLogRequest; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class LinkViewLogRequest extends PanelViewLogRequest implements Serializable { + + private Long userId; +} diff --git a/backend/src/main/java/io/dataease/service/sys/log/LogManager.java b/backend/src/main/java/io/dataease/service/sys/log/LogManager.java index 3ee86d0cfb3..975a48bf73c 100644 --- a/backend/src/main/java/io/dataease/service/sys/log/LogManager.java +++ b/backend/src/main/java/io/dataease/service/sys/log/LogManager.java @@ -28,15 +28,12 @@ public class LogManager { protected static final String contentFormat = "【%s】"; - protected static final String positionFormat = "在【%s】"; - - protected static final String format = "给%s【%s】"; protected Gson gson = new Gson(); - protected Type type = new TypeToken>() {}.getType(); - + protected Type type = new TypeToken>() { + }.getType(); @Resource @@ -47,26 +44,28 @@ public class LogManager { public String detailInfo(SysLogWithBLOBs vo) { - String sourceName = vo.getSourceName(); String position = null; String operateTypeName = SysLogConstants.operateTypeName(vo.getOperateType()); operateTypeName = Translator.get(operateTypeName); String sourceTypeName = SysLogConstants.sourceTypeName(vo.getSourceType()); sourceTypeName = Translator.get(sourceTypeName); - String result = operateTypeName + sourceTypeName + String.format(contentFormat, sourceName) + remarkInfo(vo); - + String result = operateTypeName + sourceTypeName + String.format(contentFormat, vo.getSourceName()); + if (vo.getSourceType() != SysLogConstants.SOURCE_TYPE.LINK.getValue()) { + result += remarkInfo(vo, false); + } if ((position = vo.getPosition()) != null) { List folderItems = gson.fromJson(position, type); String template = folderItems.stream().map(folderItem -> folderItem.getName()).collect(Collectors.joining("/")); - String positionResult = String.format(positionFormat, template); - return positionResult + result; + String positionResult = String.format(Translator.get("I18N_LOG_FORMAT_POSITION"), template); + result = positionResult + result; + } + if (vo.getSourceType() == SysLogConstants.SOURCE_TYPE.LINK.getValue()) { + result = remarkInfo(vo, true) + result; } return result; } - - - public String remarkInfo(SysLogWithBLOBs vo) { + public String remarkInfo(SysLogWithBLOBs vo, Boolean isPrefix) { String remakrk = null; if ((remakrk = vo.getRemark()) != null) { String targetTypeName = null; @@ -77,14 +76,16 @@ public String remarkInfo(SysLogWithBLOBs vo) { Integer targetType = item.getType(); targetTypeName = SysLogConstants.sourceTypeName(targetType); targetTypeName = Translator.get(targetTypeName); - return String.format(format, targetTypeName, template); + if (isPrefix) { + return String.format(Translator.get("I18N_LOG_FORMAT_PREFIX"), targetTypeName, template); + } + return String.format(Translator.get("I18N_LOG_FORMAT"), targetTypeName, template); } } return ""; } - private LogTypeItem parentIds(String id, Integer value) { LogTypeItem result = new LogTypeItem(); String typeValue = ""; @@ -119,7 +120,7 @@ private LogTypeItem parentIds(String id, Integer value) { } - private List parentInfos(List ids, Integer value){ + private List parentInfos(List ids, Integer value) { List folderItems = extSysLogMapper.idAndName(ids, value); if (value == 3) { folderItems.forEach(item -> { @@ -164,7 +165,7 @@ public FolderItem dsTypeInfo(String typeId) { ArrayList dataSourceTypes = new ArrayList<>(datasourceService.types()); String name = null; for (int i = 0; i < dataSourceTypes.size(); i++) { - if (dataSourceTypes.get(i).getType().equals(typeId)){ + if (dataSourceTypes.get(i).getType().equals(typeId)) { name = dataSourceTypes.get(i).getName(); break; } diff --git a/backend/src/main/java/io/dataease/service/sys/log/LogService.java b/backend/src/main/java/io/dataease/service/sys/log/LogService.java index c668c57e395..42ed5ebe0c5 100644 --- a/backend/src/main/java/io/dataease/service/sys/log/LogService.java +++ b/backend/src/main/java/io/dataease/service/sys/log/LogService.java @@ -46,6 +46,8 @@ public class LogService { // 仪表板的额外操作 分享以及公共链接 private static Integer[] panel_ext_ope = {4, 5, 8, 9, 10}; + private static Integer[] link_ext_ope = {13, 14}; + // 驱动文件操作 上传, 删除 private static Integer[] driver_file_ope = {11, 3}; @@ -247,6 +249,16 @@ public List types() { results.add(folderItem); } + for (int i = 0; i < link_ext_ope.length; i++) { + SysLogConstants.SOURCE_TYPE sourceType = SysLogConstants.SOURCE_TYPE.LINK; + FolderItem folderItem = new FolderItem(); + folderItem.setId(link_ext_ope[i] + "-" + sourceType.getValue()); + String operateTypeName = SysLogConstants.operateTypeName(link_ext_ope[i]); + String sourceTypeName = sourceType.getName(); + folderItem.setName(Translator.get(operateTypeName) + Translator.get(sourceTypeName)); + results.add(folderItem); + } + FolderItem userLogin = new FolderItem(); SysLogConstants.OPERATE_TYPE operateTypeLogin = SysLogConstants.OPERATE_TYPE.LOGIN; SysLogConstants.SOURCE_TYPE sourceTypeLogin = SysLogConstants.SOURCE_TYPE.USER; diff --git a/backend/src/main/resources/db/migration/V44__1.17.sql b/backend/src/main/resources/db/migration/V44__1.17.sql new file mode 100644 index 00000000000..833626b0044 --- /dev/null +++ b/backend/src/main/resources/db/migration/V44__1.17.sql @@ -0,0 +1,4 @@ +ALTER TABLE `sys_log` + CHANGE COLUMN `user_id` `user_id` BIGINT NULL COMMENT '操作人', + CHANGE COLUMN `login_name` `login_name` VARCHAR (255) NULL COMMENT '登录账号', + CHANGE COLUMN `nick_name` `nick_name` VARCHAR (255) NULL COMMENT '姓名'; \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index a3faecf6ecc..951dca55a63 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -167,6 +167,7 @@ SOURCE_TYPE_ROLE=ROLE SOURCE_TYPE_DRIVER=DRIVER SOURCE_TYPE_DRIVER_FILE=DRIVER FILE SOURCE_TYPE_MENU=MENU +SOURCE_TYPE_LINK=PUBLIC LINK I18N_OPERATE_TYPE=Operation type I18N_DETAIL=Operation details I18N_USER=Operator @@ -241,3 +242,7 @@ I18N_APP_NO_DATASOURCE=This panel don't have datasource I18N_APP_ONE_DATASOURCE_TIPS=This panel should have only one datasource I18N_PROHIBIT_SCANNING_TO_CREATE_USER=Prohibit scanning code to create user +I18N_LOG_FORMAT_POSITION=IN\u3010%s\u3011 +I18N_LOG_FORMAT=TO %s\u3010%s\u3011 +I18N_LOG_FORMAT_PREFIX=With authority of %s\u3010%s\u3011 + diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 329af67e3d9..6ec5cc20640 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -167,6 +167,7 @@ SOURCE_TYPE_ROLE=\u89D2\u8272 SOURCE_TYPE_DRIVER=\u9A71\u52A8 SOURCE_TYPE_DRIVER_FILE=\u9A71\u52A8\u6587\u4EF6 SOURCE_TYPE_MENU=\u83DC\u5355 +SOURCE_TYPE_LINK=\u516C\u5171\u94FE\u63A5 I18N_OPERATE_TYPE=\u64CD\u4F5C\u7C7B\u578B I18N_DETAIL=\u64CD\u4F5C\u8BE6\u60C5 I18N_USER=\u64CD\u4F5C\u4EBA @@ -241,3 +242,7 @@ I18N_APP_NO_DATASOURCE=\u6CA1\u6709\u627E\u5230\u6570\u636E\u6E90 I18N_APP_ONE_DATASOURCE_TIPS=\u8BE5\u4EEA\u8868\u677F\u53EA\u80FD\u5B58\u5728\u4E00\u4E2A\u6570\u636E\u6E90 I18N_PROHIBIT_SCANNING_TO_CREATE_USER=\u7981\u6B62\u626B\u7801\u521B\u5EFA\u7528\u6237\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\uFF01 +I18N_LOG_FORMAT_POSITION=\u5728\u3010%s\u3011 +I18N_LOG_FORMAT=\u7ED9%s\u3010%s\u3011 +I18N_LOG_FORMAT_PREFIX=\u4EE5%s\u3010%s\u3011\u6743\u9650 + diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 1bfea658024..0f0c6d30f2b 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -167,6 +167,7 @@ SOURCE_TYPE_ROLE=\u89D2\u8272 SOURCE_TYPE_DRIVER=\u9A45\u52D5 SOURCE_TYPE_DRIVER_FILE=\u9A45\u52D5\u6587\u4EF6 SOURCE_TYPE_MENU=\u83DC\u55AE +SOURCE_TYPE_LINK=\u516C\u5171\u93C8\u63A5 I18N_DRIVER_NOT_DELETE=\u4F7F\u7528\u4E2D\u7684\u9A45\u52D5\u4E0D\u5141\u8A31\u5220\u9664 I18N_DRIVER_REPEAT_NAME=\u540D\u7A31\u91CD\u8907 I18N_DRIVER_NOT_FOUND=\u672A\u627E\u5230\u9A45\u52D5 @@ -236,3 +237,7 @@ I18N_APP_ERROR_DATASET=\u5100\u8868\u677F\u4E2D\u4E0D\u80FD\u5B58\u5728API\u6578 I18N_APP_NO_DATASOURCE=\u6C92\u6709\u627E\u5230\u6578\u64DA\u6E90 I18N_APP_ONE_DATASOURCE_TIPS=\u8A72\u5100\u8868\u677F\u53EA\u80FD\u5B58\u5728\u4E00\u500B\u6578\u64DA\u6E90 I18N_PROHIBIT_SCANNING_TO_CREATE_USER=\u7981\u6B62\u6383\u78BC\u5275\u5EFA\u7528\u6236\uFF0C\u8ACB\u806F\u7CFB\u7BA1\u7406\u54E1\uFF01 + +I18N_LOG_FORMAT_POSITION=\u5728\u3010%s\u3011 +I18N_LOG_FORMAT=\u7D66%s\u3010%s\u3011 +I18N_LOG_FORMAT_PREFIX=\u4EE5%s\u3010%s\u3011\u6B0A\u9650 diff --git a/frontend/src/api/link/index.js b/frontend/src/api/link/index.js index eaa5133cfac..1b25ae68221 100644 --- a/frontend/src/api/link/index.js +++ b/frontend/src/api/link/index.js @@ -50,6 +50,15 @@ export function switchEnablePwd(data) { }) } +export function viewLinkLog(data) { + return request({ + url: 'api/link/viewLog', + method: 'post', + loading: true, + data + }) +} + export function loadGenerate(resourceId) { return request({ url: 'api/link/currentGenerate/' + resourceId, diff --git a/frontend/src/views/link/view/index.vue b/frontend/src/views/link/view/index.vue index 2dbbc1cafb0..4c4e66ccd63 100644 --- a/frontend/src/views/link/view/index.vue +++ b/frontend/src/views/link/view/index.vue @@ -10,7 +10,8 @@