From b84e9aabb0e3515e3e8eeb579e3cbf7435a70775 Mon Sep 17 00:00:00 2001 From: junjun Date: Tue, 24 May 2022 10:01:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/chart/components/shape-attr/ColorSelector.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/chart/components/shape-attr/ColorSelector.vue b/frontend/src/views/chart/components/shape-attr/ColorSelector.vue index 8c61867fb3..33a7063acc 100644 --- a/frontend/src/views/chart/components/shape-attr/ColorSelector.vue +++ b/frontend/src/views/chart/components/shape-attr/ColorSelector.vue @@ -3,14 +3,14 @@
- +
-
+
{{ $t('chart.system_case') }} From 292ecf16d58d89261561df87bc5c90229b69f2a9 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Tue, 24 May 2022 10:06:32 +0800 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=E6=89=B9=E9=87=8F=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E8=AE=B0=E5=BD=95=E6=89=80=E6=9C=89=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/store/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index b11a992a94..89d65a6ab5 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -611,9 +611,9 @@ const data = { } }) - // if (type && type === 'mix') { - // type = type + '-' + allTypes - // } + if (type && type === 'mix') { + type = type + '-' + allTypes + } // Assembly history settings 'customAttr' & 'customStyle' state.batchOptChartInfo = { 'mode': 'batchOpt', From e94cd85d17e304da9f91fb640c217337b4f4b5e6 Mon Sep 17 00:00:00 2001 From: junjun Date: Tue, 24 May 2022 17:37:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=E8=A7=86=E5=9B=BE=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E9=85=8D=E7=BD=AE=E9=A1=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/chart/components/shape-attr/LabelSelector.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/views/chart/components/shape-attr/LabelSelector.vue b/frontend/src/views/chart/components/shape-attr/LabelSelector.vue index 7724de194e..e0b280c850 100644 --- a/frontend/src/views/chart/components/shape-attr/LabelSelector.vue +++ b/frontend/src/views/chart/components/shape-attr/LabelSelector.vue @@ -17,7 +17,7 @@ - + From 8152848c43e6385ad87848c71bc72ff7585b118b Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 24 May 2022 17:55:53 +0800 Subject: [PATCH 4/5] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=AE=A1?= =?UTF-8?q?=E8=AE=A1=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/aop/DeLogAnnotationHandler.java | 9 +- .../commons/utils/CustomCellWriteUtil.java | 70 ++++++++++++++ .../io/dataease/commons/utils/DeLogUtils.java | 91 +++++++++++++++++++ .../dataset/DataSetGroupController.java | 15 ++- .../dataset/DataSetTableController.java | 9 ++ .../dataset/request/DeleteGroupRequest.java | 15 +++ .../controller/sys/request/LogTypeItem.java | 14 +++ .../java/io/dataease/dto/log/LogExcel.java | 20 ++++ .../java/io/dataease/ext/ExtSysLogMapper.xml | 33 +++++-- .../dataease/plugins/server/XAuthServer.java | 45 ++++++++- .../service/dataset/DataSetGroupService.java | 4 + .../service/dataset/DataSetTableService.java | 13 +++ .../service/panel/PanelGroupService.java | 30 +++++- .../service/panel/PanelLinkService.java | 17 ++++ .../dataease/service/panel/ShareService.java | 66 +++++++++++++- .../dataease/service/sys/log/LogManager.java | 66 ++++++++++++-- .../dataease/service/sys/log/LogService.java | 37 ++++++++ .../resources/i18n/messages_en_US.properties | 15 +-- .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + frontend/src/api/dataset/dataset.js | 7 +- frontend/src/api/system/log.js | 3 +- frontend/src/icons/svg/log.svg | 1 + frontend/src/lang/en.js | 11 ++- frontend/src/lang/tw.js | 11 ++- frontend/src/styles/index.scss | 3 + frontend/src/views/dataset/group/Group.vue | 9 +- frontend/src/views/system/log/index.vue | 14 ++- frontend/src/views/system/user/index.vue | 1 - 29 files changed, 582 insertions(+), 49 deletions(-) create mode 100644 backend/src/main/java/io/dataease/commons/utils/CustomCellWriteUtil.java create mode 100644 backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java create mode 100644 backend/src/main/java/io/dataease/controller/dataset/request/DeleteGroupRequest.java create mode 100644 backend/src/main/java/io/dataease/controller/sys/request/LogTypeItem.java create mode 100644 backend/src/main/java/io/dataease/dto/log/LogExcel.java create mode 100644 frontend/src/icons/svg/log.svg diff --git a/backend/src/main/java/io/dataease/auth/aop/DeLogAnnotationHandler.java b/backend/src/main/java/io/dataease/auth/aop/DeLogAnnotationHandler.java index 503e60bc20..37c4840082 100644 --- a/backend/src/main/java/io/dataease/auth/aop/DeLogAnnotationHandler.java +++ b/backend/src/main/java/io/dataease/auth/aop/DeLogAnnotationHandler.java @@ -4,6 +4,7 @@ package io.dataease.auth.aop; import io.dataease.auth.annotation.DeLog; import io.dataease.commons.constants.SysLogConstants; import io.dataease.commons.utils.AopUtils; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.controller.ResultHolder; import io.dataease.dto.SysLogDTO; import io.dataease.dto.log.FolderItem; @@ -84,7 +85,7 @@ public class DeLogAnnotationHandler { items.add(folderItem); sysLogDTO.setPositions(items); }else { - List parentsAndSelf = parents(bottomPositionValue.toString(), sourcetype); + List parentsAndSelf = logManager.parentsAndSelf(bottomPositionValue.toString(), sourcetype); sysLogDTO.setPositions(parentsAndSelf); } @@ -98,7 +99,7 @@ public class DeLogAnnotationHandler { SysLogConstants.SOURCE_TYPE targetType = deLog.targetType(); Object bottomTargetValue = AopUtils.getParamValue(targetArg, targetKey, 0); if (ObjectUtils.isNotEmpty(bottomTargetValue)) { - List parentsAndSelf = parents(bottomTargetValue.toString(), targetType); + List parentsAndSelf = logManager.parentsAndSelf(bottomTargetValue.toString(), targetType); sysLogDTO.setRemarks(parentsAndSelf); } } @@ -136,9 +137,7 @@ public class DeLogAnnotationHandler { return deLog; } - public List parents(String value, SysLogConstants.SOURCE_TYPE type) { - return logManager.parentsAndSelf(value, type); - } + } diff --git a/backend/src/main/java/io/dataease/commons/utils/CustomCellWriteUtil.java b/backend/src/main/java/io/dataease/commons/utils/CustomCellWriteUtil.java new file mode 100644 index 0000000000..4db4009779 --- /dev/null +++ b/backend/src/main/java/io/dataease/commons/utils/CustomCellWriteUtil.java @@ -0,0 +1,70 @@ +package io.dataease.commons.utils; + +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.Head; +import com.alibaba.excel.util.CollectionUtils; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; +import org.apache.poi.ss.usermodel.Cell; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * excel自适应列宽 + */ +public class CustomCellWriteUtil extends AbstractColumnWidthStyleStrategy { + private static final int MAX_COLUMN_WIDTH = 255; + private Map> CACHE = new HashMap(8); + + public CustomCellWriteUtil() { + } + + protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { + boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList); + if (needSetWidth) { + Map maxColumnWidthMap = (Map) CACHE.get(writeSheetHolder.getSheetNo()); + if (maxColumnWidthMap == null) { + maxColumnWidthMap = new HashMap(16); + CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); + } + + Integer columnWidth = this.dataLength(cellDataList, cell, isHead); + if (columnWidth >= 0) { + if (columnWidth > 255) { + columnWidth = 255; + } + Integer maxColumnWidth = (Integer) ((Map) maxColumnWidthMap).get(cell.getColumnIndex()); + if (maxColumnWidth == null || columnWidth > maxColumnWidth) { + ((Map) maxColumnWidthMap).put(cell.getColumnIndex(), columnWidth); + writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 7250); + } + } + } + } + + private Integer dataLength(List cellDataList, Cell cell, Boolean isHead) { + if (isHead) { + return cell.getStringCellValue().getBytes().length; + } else { + CellData cellData = (CellData) cellDataList.get(0); + CellDataTypeEnum type = cellData.getType(); + if (type == null) { + return -1; + } else { + switch (type) { + case STRING: + return cellData.getStringValue().getBytes().length; + case BOOLEAN: + return cellData.getBooleanValue().toString().getBytes().length; + case NUMBER: + return cellData.getNumberValue().toString().getBytes().length; + default: + return -1; + } + } + } + } +} diff --git a/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java b/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java new file mode 100644 index 0000000000..7aa24b6f5f --- /dev/null +++ b/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java @@ -0,0 +1,91 @@ +package io.dataease.commons.utils; + +import io.dataease.commons.constants.SysLogConstants; +import io.dataease.dto.SysLogDTO; +import io.dataease.dto.log.FolderItem; +import io.dataease.service.sys.log.LogManager; +import io.dataease.service.sys.log.LogService; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static io.dataease.commons.constants.SysLogConstants.OPERATE_TYPE; +import static io.dataease.commons.constants.SysLogConstants.SOURCE_TYPE; + +@Component +public class DeLogUtils { + + + private static LogManager logManager; + + private static LogService logService; + + @Autowired + public void setLogManager(LogManager logManager) { + DeLogUtils.logManager = logManager; + } + + @Autowired + 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 ) { + 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 { + List parentsAndSelf = logManager.justParents(sourceIdValue.toString(), sourcetype); + sysLogDTO.setPositions(parentsAndSelf); + } + return sysLogDTO; + } + + 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()); + sysLogDTO.setSourceId(sourceIdValue.toString()); + FolderItem sourceInfo = logManager.nameWithId(sourceIdValue.toString(), sourcetype.getValue()); + if (ObjectUtils.isEmpty(sourceInfo)) { + return null; + } + sysLogDTO.setSourceName(sourceInfo.getName()); + + if (ObjectUtils.isNotEmpty(positionId)) { + if (sourcetype == SysLogConstants.SOURCE_TYPE.DATASOURCE) { + FolderItem folderItem = logManager.dsTypeInfo(positionId.toString()); + List items = new ArrayList<>(); + items.add(folderItem); + sysLogDTO.setPositions(items); + }else { + List parentsAndSelf = logManager.parentsAndSelf(positionId.toString(), sourcetype); + sysLogDTO.setPositions(parentsAndSelf); + } + } + + if (ObjectUtils.isNotEmpty(targetId)) { + List parentsAndSelf = logManager.parentsAndSelf(targetId.toString(), target_type); + sysLogDTO.setRemarks(parentsAndSelf); + } + return sysLogDTO; + } + + public static void save(SysLogDTO sysLogDTO) { + Optional.ofNullable(sysLogDTO).ifPresent(logService::saveLog); + } + + public static void save(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetype, Object sourceIdValue, Object positionId, Object targetId, SOURCE_TYPE target_type) { + SysLogDTO sysLogDTO = buildLog(operatetype, sourcetype, sourceIdValue, positionId, targetId, target_type); + Optional.ofNullable(sysLogDTO).ifPresent(logService::saveLog); + } + + +} diff --git a/backend/src/main/java/io/dataease/controller/dataset/DataSetGroupController.java b/backend/src/main/java/io/dataease/controller/dataset/DataSetGroupController.java index c08389bb77..7379928d79 100644 --- a/backend/src/main/java/io/dataease/controller/dataset/DataSetGroupController.java +++ b/backend/src/main/java/io/dataease/controller/dataset/DataSetGroupController.java @@ -1,10 +1,13 @@ package io.dataease.controller.dataset; import com.github.xiaoymin.knife4j.annotations.ApiSupport; +import io.dataease.auth.annotation.DeLog; import io.dataease.auth.annotation.DePermission; import io.dataease.auth.annotation.DePermissions; import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.constants.ResourceAuthLevel; +import io.dataease.commons.constants.SysLogConstants; +import io.dataease.controller.dataset.request.DeleteGroupRequest; import io.dataease.controller.request.dataset.DataSetGroupRequest; import io.dataease.dto.dataset.DataSetGroupDTO; import io.dataease.plugins.common.base.domain.DatasetGroup; @@ -57,9 +60,15 @@ public class DataSetGroupController { @DePermission(type = DePermissionType.DATASET, level = ResourceAuthLevel.DATASET_LEVEL_MANAGE) @ApiOperation("删除") - @PostMapping("/delete/{id}") - public void tree(@PathVariable String id) throws Exception { - dataSetGroupService.delete(id); + @PostMapping("/delete") + @DeLog( + operatetype = SysLogConstants.OPERATE_TYPE.DELETE, + sourcetype = SysLogConstants.SOURCE_TYPE.DATASET, + positionIndex = 0,positionKey = "pid", + value = "id" + ) + public void tree(@RequestBody DeleteGroupRequest request) throws Exception { + dataSetGroupService.delete(request.getId()); } @ApiIgnore diff --git a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java index 2911cfcc73..b42ff15fb9 100644 --- a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java +++ b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java @@ -1,10 +1,12 @@ package io.dataease.controller.dataset; import com.github.xiaoymin.knife4j.annotations.ApiSupport; +import io.dataease.auth.annotation.DeLog; import io.dataease.auth.annotation.DePermission; import io.dataease.auth.annotation.DePermissions; import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.constants.ResourceAuthLevel; +import io.dataease.commons.constants.SysLogConstants; import io.dataease.controller.request.dataset.DataSetTableRequest; import io.dataease.controller.response.DataSetDetail; import io.dataease.dto.dataset.DataSetTableDTO; @@ -65,6 +67,13 @@ public class DataSetTableController { }, logical = Logical.AND) @ApiOperation("修改") @PostMapping("alter") + @DeLog( + operatetype = SysLogConstants.OPERATE_TYPE.MODIFY, + sourcetype = SysLogConstants.SOURCE_TYPE.DATASET, + value = "id", + positionIndex = 0, + positionKey = "sceneId" + ) public void alter(@RequestBody DataSetTableRequest request) throws Exception { dataSetTableService.alter(request); } diff --git a/backend/src/main/java/io/dataease/controller/dataset/request/DeleteGroupRequest.java b/backend/src/main/java/io/dataease/controller/dataset/request/DeleteGroupRequest.java new file mode 100644 index 0000000000..7df4b1d1b4 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/dataset/request/DeleteGroupRequest.java @@ -0,0 +1,15 @@ +package io.dataease.controller.dataset.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class DeleteGroupRequest implements Serializable { + + @ApiModelProperty(value = "ID",required = true) + private String id; + @ApiModelProperty(value = "PID",required = true) + private String pid; +} diff --git a/backend/src/main/java/io/dataease/controller/sys/request/LogTypeItem.java b/backend/src/main/java/io/dataease/controller/sys/request/LogTypeItem.java new file mode 100644 index 0000000000..943ff03388 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/sys/request/LogTypeItem.java @@ -0,0 +1,14 @@ +package io.dataease.controller.sys.request; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class LogTypeItem implements Serializable { + + private List parentIds; + + private String typeValue; +} diff --git a/backend/src/main/java/io/dataease/dto/log/LogExcel.java b/backend/src/main/java/io/dataease/dto/log/LogExcel.java new file mode 100644 index 0000000000..a2eba8363b --- /dev/null +++ b/backend/src/main/java/io/dataease/dto/log/LogExcel.java @@ -0,0 +1,20 @@ +package io.dataease.dto.log; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +@Data +public class LogExcel { + + @ExcelProperty(value = {"optype"}, index = 0) + private String optype; + + @ExcelProperty(value = {"detail"}, index = 1) + private String detail; + + @ExcelProperty(value = {"user"}, index = 2) + private String user; + + @ExcelProperty(value = {"time"}, index = 3) + private String time; +} diff --git a/backend/src/main/java/io/dataease/ext/ExtSysLogMapper.xml b/backend/src/main/java/io/dataease/ext/ExtSysLogMapper.xml index a4786de7b9..bd0b9fad2c 100644 --- a/backend/src/main/java/io/dataease/ext/ExtSysLogMapper.xml +++ b/backend/src/main/java/io/dataease/ext/ExtSysLogMapper.xml @@ -37,13 +37,28 @@ id, name - from dataset_group - - id in - - #{id} - - + from ( + select id, name from dataset_group + + id in + + #{id} + + + + union all + + select id, name from dataset_table + + id in + + #{id} + + + + ) dataset + + @@ -54,6 +69,10 @@ #{id} + ORDER BY FIELD(id, + + #{id} + diff --git a/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java b/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java index c33b437605..556e16e9ff 100644 --- a/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java +++ b/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java @@ -2,8 +2,11 @@ package io.dataease.plugins.server; import io.dataease.auth.api.dto.CurrentUserDto; import io.dataease.commons.constants.AuthConstants; +import io.dataease.commons.constants.SysLogConstants; import io.dataease.commons.utils.AuthUtils; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.controller.handler.annotation.I18n; +import io.dataease.dto.SysLogDTO; import io.dataease.listener.util.CacheUtils; import io.dataease.plugins.config.SpringContextUtil; import io.dataease.plugins.xpack.auth.dto.request.XpackBaseTreeRequest; @@ -86,11 +89,51 @@ public class XAuthServer { } else { CacheUtils.remove(authCacheKey, request.getAuthTargetType() + request.getAuthTarget()); } - } + + SysLogConstants.OPERATE_TYPE operateType = SysLogConstants.OPERATE_TYPE.AUTHORIZE; + if (1 == request.getAuthDetail().getPrivilegeValue()) { + operateType = SysLogConstants.OPERATE_TYPE.UNAUTHORIZE; + } + + SysLogConstants.SOURCE_TYPE sourceType = sourceType(request.getAuthSourceType()); + + SysLogConstants.SOURCE_TYPE tarType = tarType(request.getAuthTargetType()); + SysLogDTO sysLogDTO = DeLogUtils.buildLog(operateType, sourceType, request.getAuthSource(), request.getAuthTarget(), tarType); + DeLogUtils.save(sysLogDTO); }); } + private SysLogConstants.SOURCE_TYPE sourceType(String sourceType) { + if (StringUtils.equals("link", sourceType)) { + return SysLogConstants.SOURCE_TYPE.DATASOURCE; + } + if (StringUtils.equals("menu", sourceType)) { + return SysLogConstants.SOURCE_TYPE.DATASOURCE; + } + if (StringUtils.equals("dataset", sourceType)) { + return SysLogConstants.SOURCE_TYPE.DATASET; + } + if (StringUtils.equals("panel", sourceType)) { + return SysLogConstants.SOURCE_TYPE.PANEL; + } + return null; + } + + private SysLogConstants.SOURCE_TYPE tarType(String targetType) { + if (StringUtils.equals("user", targetType)) { + return SysLogConstants.SOURCE_TYPE.USER; + } + if (StringUtils.equals("role", targetType)) { + return SysLogConstants.SOURCE_TYPE.ROLE; + } + if (StringUtils.equals("dept", targetType)) { + return SysLogConstants.SOURCE_TYPE.DEPT; + } + + return null; + } + private String getAuthCacheKey(XpackSysAuthRequest request) { if (CollectionUtils.isEmpty(cacheTypes)) { cacheTypes.add("link"); diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java index 6e8202dc57..28ff78c646 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java @@ -1,6 +1,8 @@ package io.dataease.service.dataset; import io.dataease.auth.annotation.DeCleaner; +import io.dataease.commons.constants.SysLogConstants; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.ext.ExtDataSetGroupMapper; import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.DePermissionType; @@ -55,12 +57,14 @@ public class DataSetGroupService { datasetGroup.setCreateBy(AuthUtils.getUser().getUsername()); datasetGroup.setCreateTime(System.currentTimeMillis()); datasetGroupMapper.insert(datasetGroup); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, SysLogConstants.SOURCE_TYPE.DATASET, datasetGroup.getId(), datasetGroup.getPid(), null, null); String userName = AuthUtils.getUser().getUsername(); // 清理权限缓存 CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME); sysAuthService.copyAuth(datasetGroup.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASET); } else { datasetGroupMapper.updateByPrimaryKeySelective(datasetGroup); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, SysLogConstants.SOURCE_TYPE.DATASET, datasetGroup.getId(), datasetGroup.getPid(), null, null); } DataSetGroupDTO dataSetGroupDTO = new DataSetGroupDTO(); BeanUtils.copyBean(dataSetGroupDTO, datasetGroup); diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index a7339ea79c..b2bbf4200d 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import io.dataease.auth.annotation.DeCleaner; import io.dataease.auth.api.dto.CurrentUserDto; +import io.dataease.dto.SysLogDTO; import io.dataease.ext.ExtDataSetGroupMapper; import io.dataease.ext.ExtDataSetTableMapper; import io.dataease.ext.UtilMapper; @@ -178,6 +179,7 @@ public class DataSetTableService { sysAuthService.copyAuth(sheetTable.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASET); saveExcelTableField(sheetTable.getId(), excelSheetDataList.get(0).getFields(), true); datasetIdList.add(sheetTable.getId()); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); } datasetIdList.forEach(datasetId -> { commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetId, "all_scope", "初始导入", @@ -208,12 +210,14 @@ public class DataSetTableService { sysAuthService.copyAuth(sheetTable.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASET); saveExcelTableField(sheetTable.getId(), sheet.getFields(), true); datasetIdList.add(sheetTable.getId()); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); } datasetIdList.forEach(datasetId -> { commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetId, "all_scope", "初始导入", null, datasetIdList)); }); + } return; } @@ -253,6 +257,7 @@ public class DataSetTableService { commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetTable.getId(), "add_scope", "追加", null, Arrays.asList(datasetTable.getId()))); } + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); } @DeCleaner(value = DePermissionType.DATASET, key = "sceneId") @@ -268,6 +273,8 @@ public class DataSetTableService { datasetTable.setCreateBy(AuthUtils.getUser().getUsername()); datasetTable.setCreateTime(System.currentTimeMillis()); int insert = datasetTableMapper.insert(datasetTable); + + // 清理权限缓存 CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME); sysAuthService.copyAuth(datasetTable.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASET); @@ -276,6 +283,7 @@ public class DataSetTableService { if (insert == 1) { saveTableField(datasetTable); extractData(datasetTable); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); } } else { int update = datasetTableMapper.updateByPrimaryKeySelective(datasetTable); @@ -287,6 +295,7 @@ public class DataSetTableService { || StringUtils.equalsIgnoreCase(datasetTable.getType(), "union")) { saveTableField(datasetTable); } + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); } } } @@ -300,6 +309,7 @@ public class DataSetTableService { public void delete(String id) throws Exception { DatasetTable table = datasetTableMapper.selectByPrimaryKey(id); + SysLogDTO sysLogDTO = DeLogUtils.buildLog(SysLogConstants.OPERATE_TYPE.DELETE, SysLogConstants.SOURCE_TYPE.DATASET, table.getId(), table.getSceneId(), null, null); datasetTableMapper.deleteByPrimaryKey(id); dataSetTableFieldsService.deleteByTableId(id); // 删除同步任务 @@ -311,6 +321,7 @@ public class DataSetTableService { if (table.getMode() == 1) { deleteDorisTable(id, table); } + DeLogUtils.save(sysLogDTO); } catch (Exception e) { e.printStackTrace(); } @@ -1771,6 +1782,8 @@ public class DataSetTableService { } else { datasetTableIncrementalConfigMapper.updateByPrimaryKey(datasetTableIncrementalConfig); } + DatasetTable datasetTable = get(datasetTableIncrementalConfig.getTableId()); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); checkColumes(datasetTableIncrementalConfig); } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java index bb7b734cce..f35e301426 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import io.dataease.auth.annotation.DeCleaner; import io.dataease.commons.constants.*; import io.dataease.commons.utils.AuthUtils; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.commons.utils.LogUtil; import io.dataease.commons.utils.TreeUtils; import io.dataease.controller.request.authModel.VAuthModelRequest; @@ -12,6 +13,7 @@ import io.dataease.controller.request.panel.PanelGroupBaseInfoRequest; import io.dataease.controller.request.panel.PanelGroupRequest; import io.dataease.controller.request.panel.PanelViewDetailsRequest; import io.dataease.dto.PanelGroupExtendDataDTO; +import io.dataease.dto.SysLogDTO; import io.dataease.dto.authModel.VAuthModelDTO; import io.dataease.dto.chart.ChartViewDTO; import io.dataease.dto.dataset.DataSetTableDTO; @@ -28,6 +30,7 @@ import io.dataease.service.dataset.DataSetTableService; import io.dataease.service.staticResource.StaticResourceService; import io.dataease.service.sys.SysAuthService; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.*; @@ -55,6 +58,8 @@ public class PanelGroupService { private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + private final SysLogConstants.SOURCE_TYPE sourceType = SysLogConstants.SOURCE_TYPE.PANEL; + private final static String DATA_URL_TITLE = "data:image/jpeg;base64,"; @Resource private PanelGroupMapper panelGroupMapper; @@ -128,6 +133,7 @@ public class PanelGroupService { // 清理权限缓存 clearPermissionCache(); sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, sourceType, panelId, request.getPid(), null, null); } else if ("toDefaultPanel".equals(request.getOptType())) { // 转存为默认仪表板 panelId = UUID.randomUUID().toString(); PanelGroupWithBLOBs newDefaultPanel = panelGroupMapper.selectByPrimaryKey(request.getId()); @@ -144,11 +150,19 @@ public class PanelGroupService { // 清理权限缓存 clearPermissionCache(); sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, sourceType, panelId, PanelConstants.PANEL_GATHER_DEFAULT_PANEL, null, null); } else if ("copy".equals(request.getOptType())) { panelId = this.panelGroupCopy(request, null, true); // 清理权限缓存 clearPermissionCache(); sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL); + if (StringUtils.isBlank(request.getPid())) { + PanelGroupWithBLOBs panel = panelGroupMapper.selectByPrimaryKey(request.getId()); + if (ObjectUtils.isNotEmpty(panel)) { + request.setPid(panel.getPid()); + } + } + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, sourceType, panelId, request.getPid(), null, null); } else if ("move".equals(request.getOptType())) { PanelGroupWithBLOBs panelInfo = panelGroupMapper.selectByPrimaryKey(request.getId()); if (panelInfo.getPid().equalsIgnoreCase(request.getPid())) { @@ -163,6 +177,7 @@ public class PanelGroupService { record.setId(request.getId()); record.setPid(request.getPid()); panelGroupMapper.updateByPrimaryKeySelective(record); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, sourceType, request.getId(), panelInfo.getPid(), request.getPid(), sourceType); } else { // 更新 @@ -170,6 +185,14 @@ public class PanelGroupService { checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_UPDATE, request.getId(), request.getNodeType()); } panelGroupMapper.updateByPrimaryKeySelective(request); + if (StringUtils.isBlank(request.getPid())) { + PanelGroupWithBLOBs panel = panelGroupMapper.selectByPrimaryKey(request.getId()); + if (ObjectUtils.isNotEmpty(panel)) { + request.setPid(panel.getPid()); + } + } + + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, sourceType, request.getId(), request.getPid(), null, sourceType); } //带有权限的返回 @@ -202,7 +225,8 @@ public class PanelGroupService { public void deleteCircle(String id) { Assert.notNull(id, "id cannot be null"); sysAuthService.checkTreeNoManageCount("panel", id); - + PanelGroupWithBLOBs panel = panelGroupMapper.selectByPrimaryKey(id); + SysLogDTO sysLogDTO = DeLogUtils.buildLog(SysLogConstants.OPERATE_TYPE.DELETE, sourceType, panel.getId(), panel.getPid(), null, null); //清理view 和 view cache extPanelGroupMapper.deleteCircleView(id); extPanelGroupMapper.deleteCircleViewCache(id); @@ -218,6 +242,10 @@ public class PanelGroupService { extPanelLinkJumpMapper.deleteJumpTargetViewInfoWithPanel(id); extPanelLinkJumpMapper.deleteJumpInfoWithPanel(id); extPanelLinkJumpMapper.deleteJumpWithPanel(id); + + DeLogUtils.save(sysLogDTO); + + } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java b/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java index a3c978cfeb..0d9283abfd 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java @@ -3,8 +3,10 @@ package io.dataease.service.panel; import io.dataease.auth.config.RsaProperties; import io.dataease.auth.util.JWTUtils; import io.dataease.auth.util.RsaUtil; +import io.dataease.commons.constants.SysLogConstants; import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.CodingUtil; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.commons.utils.ServletUtils; import io.dataease.controller.request.panel.link.EnablePwdRequest; import io.dataease.controller.request.panel.link.LinkRequest; @@ -59,6 +61,13 @@ public class PanelLinkService { PanelLinkMapping mapping = new PanelLinkMapping(); mapping.setUuid(CodingUtil.shortUuid()); panelLinkMappingMapper.updateByExampleSelective(mapping, example); + PanelGroupWithBLOBs panel = panelGroupMapper.selectByPrimaryKey(request.getResourceId()); + + SysLogConstants.OPERATE_TYPE operateType = SysLogConstants.OPERATE_TYPE.CREATELINK; + if (!request.isValid()) { + operateType = SysLogConstants.OPERATE_TYPE.DELETELINK; + } + DeLogUtils.save(operateType, SysLogConstants.SOURCE_TYPE.PANEL, panel.getId(), panel.getPid(), null, null) ; } private PanelLinkExample example(String panelLinkId, Long userId) { @@ -72,6 +81,8 @@ public class PanelLinkService { po.setResourceId(request.getResourceId()); po.setEnablePwd(request.isEnablePwd()); mapper.updateByExampleSelective(po, example(request.getResourceId(), AuthUtils.getUser().getUserId())); + PanelGroupWithBLOBs panel = panelGroupMapper.selectByPrimaryKey(request.getResourceId()); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFYLINK, SysLogConstants.SOURCE_TYPE.PANEL, panel.getId(), panel.getPid(), null, null) ; } public void password(PasswordRequest request) { @@ -79,11 +90,17 @@ public class PanelLinkService { po.setResourceId(request.getResourceId()); po.setPwd(request.getPassword()); mapper.updateByExampleSelective(po, example(request.getResourceId(), AuthUtils.getUser().getUserId())); + + + PanelGroupWithBLOBs panel = panelGroupMapper.selectByPrimaryKey(request.getResourceId()); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFYLINK, SysLogConstants.SOURCE_TYPE.PANEL, panel.getId(), panel.getPid(), null, null) ; } public void overTime(OverTimeRequest request) { request.setUserId(AuthUtils.getUser().getUserId()); extPanelLinkMapper.updateOverTime(request); + PanelGroupWithBLOBs panel = panelGroupMapper.selectByPrimaryKey(request.getResourceId()); + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFYLINK, SysLogConstants.SOURCE_TYPE.PANEL, panel.getId(), panel.getPid(), null, null) ; } private PanelLink findOne(String resourceId) { diff --git a/backend/src/main/java/io/dataease/service/panel/ShareService.java b/backend/src/main/java/io/dataease/service/panel/ShareService.java index 4155a4bf7f..d840f10c48 100644 --- a/backend/src/main/java/io/dataease/service/panel/ShareService.java +++ b/backend/src/main/java/io/dataease/service/panel/ShareService.java @@ -3,6 +3,8 @@ package io.dataease.service.panel; import com.google.gson.Gson; import io.dataease.auth.api.dto.CurrentRoleDto; import io.dataease.auth.api.dto.CurrentUserDto; +import io.dataease.commons.constants.SysLogConstants; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.ext.ExtPanelShareMapper; import io.dataease.commons.model.AuthURD; import io.dataease.commons.utils.AuthUtils; @@ -126,11 +128,61 @@ public class ShareService { extPanelShareMapper.batchInsert(addShares, AuthUtils.getUser().getUsername()); } + PanelGroup panelGroup = panelGroupMapper.selectByPrimaryKey(panelGroupId); + + if (CollectionUtils.isNotEmpty(addAuthURD.getUserIds())) { + addAuthURD.getUserIds().forEach(id -> { + if (CollectionUtils.isEmpty(sharedAuthURD.getUserIds()) || !sharedAuthURD.getUserIds().contains(id)) { + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.SHARE, SysLogConstants.SOURCE_TYPE.PANEL, panelGroupId, panelGroup.getPid(), id, SysLogConstants.SOURCE_TYPE.USER); + } + }); + } + if (CollectionUtils.isNotEmpty(addAuthURD.getRoleIds())) { + addAuthURD.getRoleIds().forEach(id -> { + if (CollectionUtils.isEmpty(sharedAuthURD.getRoleIds()) || !sharedAuthURD.getRoleIds().contains(id)) { + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.SHARE, SysLogConstants.SOURCE_TYPE.PANEL, panelGroupId, panelGroup.getPid(), id, SysLogConstants.SOURCE_TYPE.ROLE); + } + }); + } + if (CollectionUtils.isNotEmpty(addAuthURD.getDeptIds())) { + addAuthURD.getDeptIds().forEach(id -> { + if (CollectionUtils.isEmpty(sharedAuthURD.getDeptIds()) || !sharedAuthURD.getDeptIds().contains(id)) { + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.SHARE, SysLogConstants.SOURCE_TYPE.PANEL, panelGroupId, panelGroup.getPid(), id, SysLogConstants.SOURCE_TYPE.DEPT); + } + }); + } + + if (CollectionUtils.isNotEmpty(sharedAuthURD.getUserIds())) { + sharedAuthURD.getUserIds().forEach(id -> { + if (CollectionUtils.isEmpty(addAuthURD.getUserIds()) || !addAuthURD.getUserIds().contains(id)) { + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.UNSHARE, SysLogConstants.SOURCE_TYPE.PANEL, panelGroupId, panelGroup.getPid(), id, SysLogConstants.SOURCE_TYPE.USER); + } + }); + } + + if (CollectionUtils.isNotEmpty(sharedAuthURD.getRoleIds())) { + sharedAuthURD.getRoleIds().forEach(id -> { + if (CollectionUtils.isEmpty(addAuthURD.getRoleIds()) || !addAuthURD.getRoleIds().contains(id)) { + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.UNSHARE, SysLogConstants.SOURCE_TYPE.PANEL, panelGroupId, panelGroup.getPid(), id, SysLogConstants.SOURCE_TYPE.ROLE); + } + }); + } + if (CollectionUtils.isNotEmpty(sharedAuthURD.getDeptIds())) { + sharedAuthURD.getDeptIds().forEach(id -> { + if (CollectionUtils.isEmpty(addAuthURD.getDeptIds()) || !addAuthURD.getDeptIds().contains(id)) { + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.UNSHARE, SysLogConstants.SOURCE_TYPE.PANEL, panelGroupId, panelGroup.getPid(), id, SysLogConstants.SOURCE_TYPE.DEPT); + } + }); + } + + + + // 以上是业务代码 // 下面是消息发送 Set addUserIdSet = AuthUtils.userIdsByURD(addAuthURD); Set redUserIdSet = AuthUtils.userIdsByURD(sharedAuthURD); - PanelGroup panelGroup = panelGroupMapper.selectByPrimaryKey(panelGroupId); + CurrentUserDto user = AuthUtils.getUser(); Gson gson = new Gson(); String msg = panelGroup.getName(); @@ -343,7 +395,19 @@ public class ShareService { @Transactional public void removeShares(PanelShareRemoveRequest removeRequest) { String panelId = removeRequest.getPanelId(); + PanelGroup panelGroup = panelGroupMapper.selectByPrimaryKey(panelId); + extPanelShareMapper.removeShares(removeRequest); + + SysLogConstants.SOURCE_TYPE targetType = SysLogConstants.SOURCE_TYPE.USER; + if (removeRequest.getType() == 1) { + targetType = SysLogConstants.SOURCE_TYPE.ROLE; + }else if (removeRequest.getType() == 2) { + targetType = SysLogConstants.SOURCE_TYPE.DEPT; + } + + DeLogUtils.save(SysLogConstants.OPERATE_TYPE.UNSHARE, SysLogConstants.SOURCE_TYPE.PANEL, panelId, panelGroup.getPid(), removeRequest.getTargetId(), targetType); + AuthURD sharedAuthURD = new AuthURD(); List removeIds = new ArrayList(){{add(removeRequest.getTargetId());}}; buildRedAuthURD(removeRequest.getType(), removeIds, sharedAuthURD); 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 36f9ce3d3e..254a719c28 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 @@ -4,9 +4,11 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import io.dataease.commons.constants.SysLogConstants; import io.dataease.commons.utils.AuthUtils; +import io.dataease.controller.sys.request.LogTypeItem; import io.dataease.dto.log.FolderItem; import io.dataease.ext.ExtSysLogMapper; import io.dataease.i18n.Translator; +import io.dataease.plugins.common.base.domain.Datasource; import io.dataease.plugins.common.base.domain.SysLogWithBLOBs; import io.dataease.plugins.common.dto.datasource.DataSourceType; import io.dataease.service.datasource.DatasourceService; @@ -17,6 +19,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -66,26 +69,33 @@ public class LogManager { public String remarkInfo(SysLogWithBLOBs vo) { String remakrk = null; if ((remakrk = vo.getRemark()) != null) { + String targetTypeName = null; List targetInfos = gson.fromJson(remakrk, type); - String target = targetInfos.stream().map(item -> { + if (CollectionUtils.isNotEmpty(targetInfos)) { + String template = targetInfos.stream().map(folderItem -> folderItem.getName()).collect(Collectors.joining("/")); + FolderItem item = targetInfos.get(0); Integer targetType = item.getType(); - String targetTypeName = SysLogConstants.sourceTypeName(targetType); - return String.format(format, targetTypeName, item.getName()); - }).collect(Collectors.joining("/")); - return target; + targetTypeName = SysLogConstants.sourceTypeName(targetType); + targetTypeName = Translator.get(targetTypeName); + return String.format(format, targetTypeName, template); + } } return ""; } - public List parentsAndSelf(String id, SysLogConstants.SOURCE_TYPE type) { - Integer value = type.getValue(); + + + private LogTypeItem parentIds(String id, Integer value) { + LogTypeItem result = new LogTypeItem(); String typeValue = ""; + Boolean reversed = false; switch (value) { case 2: typeValue = "dataset"; break; case 3: typeValue = "panel"; + reversed = true; break; case 7: typeValue = "dept"; @@ -96,14 +106,47 @@ public class LogManager { List ids = new ArrayList<>(); if (StringUtils.isNotBlank(typeValue)) { ids.addAll(AuthUtils.parentResources(id, typeValue)); - }else { - ids.add(id); + if (reversed) { + Collections.reverse(ids); + } } + result.setParentIds(ids); + result.setTypeValue(typeValue); + return result; + } + + + private List parentInfos(List ids, Integer value){ List folderItems = extSysLogMapper.idAndName(ids, value); + if (value == 3) { + folderItems.forEach(item -> { + if (StringUtils.equals("i18n_panel_list", item.getName())) { + item.setName(Translator.get(item.getName())); + } + }); + } folderItems.forEach(item -> item.setType(value)); return folderItems; } + public List justParents(String id, SysLogConstants.SOURCE_TYPE type) { + + Integer value = type.getValue(); + LogTypeItem typeItem = parentIds(id, value); + List ids = typeItem.getParentIds(); + ids = ids.stream().filter(item -> !StringUtils.equals(id, item)).collect(Collectors.toList()); + return parentInfos(ids, value); + } + + public List parentsAndSelf(String id, SysLogConstants.SOURCE_TYPE type) { + Integer value = type.getValue(); + LogTypeItem logTypeItem = parentIds(id, value); + if (CollectionUtils.isEmpty(logTypeItem.getParentIds())) { + logTypeItem.getParentIds().add(id); + } + return parentInfos(logTypeItem.getParentIds(), value); + } + public FolderItem nameWithId(String id, Integer type) { List ids = new ArrayList<>(); ids.add(id); @@ -129,5 +172,10 @@ public class LogManager { return folderItem; } + public FolderItem dsTypeInfoById(String dsId) { + Datasource datasource = datasourceService.get(dsId); + return dsTypeInfo(datasource.getType()); + } + } 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 e29ee15d7d..d456bae5d8 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 @@ -1,21 +1,28 @@ package io.dataease.service.sys.log; +import cn.hutool.core.date.DateUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.write.metadata.WriteSheet; import com.google.gson.Gson; import io.dataease.auth.api.dto.CurrentUserDto; import io.dataease.commons.constants.SysLogConstants; import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.BeanUtils; +import io.dataease.commons.utils.CustomCellWriteUtil; import io.dataease.controller.sys.base.BaseGridRequest; import io.dataease.controller.sys.base.ConditionEntity; import io.dataease.dto.SysLogDTO; import io.dataease.dto.SysLogGridDTO; import io.dataease.dto.log.FolderItem; +import io.dataease.dto.log.LogExcel; import io.dataease.ext.ExtSysLogMapper; import io.dataease.ext.query.GridExample; import io.dataease.i18n.Translator; import io.dataease.plugins.common.base.domain.SysLogWithBLOBs; import io.dataease.plugins.common.base.mapper.SysLogMapper; +import mondrian.olap.fun.vba.Excel; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -23,8 +30,13 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -142,7 +154,32 @@ public class LogService { } public void exportExcel(HttpServletResponse response) throws Exception{ + BaseGridRequest request = new BaseGridRequest(); + GridExample gridExample = request.convertExample(); + List lists = extSysLogMapper.query(gridExample); + List excels = lists.stream().map(item -> { + LogExcel logExcel = new LogExcel(); + String operateTypeName = SysLogConstants.operateTypeName(item.getOperateType()); + String sourceTypeName = SysLogConstants.sourceTypeName(item.getSourceType()); + logExcel.setOptype(Translator.get(operateTypeName) + " " + Translator.get(sourceTypeName)); + logExcel.setDetail(logManager.detailInfo(item)); + logExcel.setUser(item.getNickName()); + logExcel.setTime(DateUtil.formatDateTime(new Date(item.getTime()))); + return logExcel; + }).collect(Collectors.toList()); + // 导出时候会出现中⽂⽆法识别问题,需要转码 + String name = "log.xlsx"; + String fileName = new String(name.getBytes("gb2312"),"ISO8859-1"); + response.setContentType("application/vnd.ms-excel;chartset=utf-8"); + response.setHeader("Content-Disposition","attachment;filename=" + fileName); + //调⽤⼯具类 + ExcelWriter writer = EasyExcel.write(response.getOutputStream()).build(); + WriteSheet sheet = EasyExcel.writerSheet(0,"sheet").head(LogExcel.class).registerWriteHandler(new CustomCellWriteUtil()).build(); + writer.write(excels,sheet); + writer.finish(); // 使⽤完毕之后要关闭 } + + } diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index a548ee5173..cd97a61f7a 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -129,6 +129,7 @@ i18n_wrong_tel=Wrong tel format i18n_wrong_email=Wrong email format i18n_wrong_name_format=Wrong name format +日志管理=Log OPERATE_TYPE_CREATE=Create OPERATE_TYPE_MODIFY=Modify @@ -141,10 +142,10 @@ OPERATE_TYPE_CREATELINK=Create Link OPERATE_TYPE_DELETELINK=Delete Link OPERATE_TYPE_MODIFYLINK=Modify Link -SOURCE_TYPE_DATASOURCE=数据源 -SOURCE_TYPE_DATASET=数据集 -SOURCE_TYPE_PANEL=仪表板 -SOURCE_TYPE_VIEW=视图 -SOURCE_TYPE_USER=用户 -SOURCE_TYPE_DEPT=组织 -SOURCE_TYPE_ROLE=角色 +SOURCE_TYPE_DATASOURCE=DATASOURCE +SOURCE_TYPE_DATASET=DATASET +SOURCE_TYPE_PANEL=PANEL +SOURCE_TYPE_VIEW=VIEW +SOURCE_TYPE_USER=USER +SOURCE_TYPE_DEPT=ORG +SOURCE_TYPE_ROLE=ROLE diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 5cfced746a..adf3cf2567 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -128,6 +128,7 @@ i18n_wrong_tel=电话格式错误 i18n_wrong_email=邮箱格式错误 i18n_wrong_name_format=姓名格式错误 +日志管理=审计日志 OPERATE_TYPE_CREATE=创建 OPERATE_TYPE_MODIFY=修改 OPERATE_TYPE_DELETE=删除 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 09448cd130..4baaeb4359 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -129,6 +129,7 @@ i18n_wrong_tel=電話格式錯誤 i18n_wrong_email=郵箱格式錯誤 i18n_wrong_name_format=姓名格式錯誤 +日志管理=審計日誌 OPERATE_TYPE_CREATE=創建 OPERATE_TYPE_MODIFY=修改 OPERATE_TYPE_DELETE=刪除 diff --git a/frontend/src/api/dataset/dataset.js b/frontend/src/api/dataset/dataset.js index 2f620748da..50ed906bbc 100644 --- a/frontend/src/api/dataset/dataset.js +++ b/frontend/src/api/dataset/dataset.js @@ -26,11 +26,12 @@ export function addGroup(data) { }) } -export function delGroup(groupId) { +export function delGroup(data) { return request({ - url: '/dataset/group/delete/' + groupId, + url: '/dataset/group/delete', loading: true, - method: 'post' + method: 'post', + data }) } diff --git a/frontend/src/api/system/log.js b/frontend/src/api/system/log.js index f91e5547d3..1857b14b74 100644 --- a/frontend/src/api/system/log.js +++ b/frontend/src/api/system/log.js @@ -21,6 +21,7 @@ export function exportExcel() { return request({ url: '/api/log/export', method: 'post', - loading: true + loading: true, + responseType: 'blob' }) } diff --git a/frontend/src/icons/svg/log.svg b/frontend/src/icons/svg/log.svg new file mode 100644 index 0000000000..6a43ef5010 --- /dev/null +++ b/frontend/src/icons/svg/log.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 76d5c9a5ea..60fc62b068 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1328,7 +1328,7 @@ export default { sql_ds_union_error: 'Direct connect SQL dataset can not be union', api_data: 'API dataset' }, - driver:{ + driver: { driver: 'Driver', please_choose_driver: 'Please choose driver', mgm: 'Driver', @@ -2040,6 +2040,15 @@ export default { user: 'User', passwd: 'Password' }, + log: { + title: 'Operate Log', + optype: 'Operate Type', + detail: 'Detail', + user: 'User', + time: 'Time', + export: 'Export', + search_by_key: 'Search by key' + }, plugin_style: { border: 'Border' } diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 866cb49c7e..1d912df2fe 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1328,7 +1328,7 @@ export default { sql_ds_union_error: '直連模式下SQL數據集,不支持關聯', api_data: 'API 數據集' }, - driver:{ + driver: { driver: '驅動', please_choose_driver: '青選擇驅動', mgm: '驅動管理', @@ -2051,6 +2051,15 @@ export default { user: '用戶名', passwd: '密碼' }, + log: { + title: '操作日誌', + optype: '操作類型', + detail: '操作詳情', + user: '操作用戶', + time: '操作時間', + export: '導出', + search_by_key: '搜索詳情' + }, plugin_style: { border: '边框' } diff --git a/frontend/src/styles/index.scss b/frontend/src/styles/index.scss index b71acf0da5..fe27ea6c07 100644 --- a/frontend/src/styles/index.scss +++ b/frontend/src/styles/index.scss @@ -829,4 +829,7 @@ div:focus { } .fu-operator-component__operator { display: none !important; +} +.fu-operator-component__label { + width: 100px !important; } \ No newline at end of file diff --git a/frontend/src/views/dataset/group/Group.vue b/frontend/src/views/dataset/group/Group.vue index 6ab89471b9..5f31e07346 100644 --- a/frontend/src/views/dataset/group/Group.vue +++ b/frontend/src/views/dataset/group/Group.vue @@ -232,7 +232,7 @@ import { loadTable, getScene, addGroup, delGroup, delTable, post, isKettleRunnin import GroupMoveSelector from './GroupMoveSelector' import DsMoveSelector from './DsMoveSelector' import { queryAuthModel } from '@/api/authModel/authModel' -import {engineMode} from "@/api/system/engine"; +import { engineMode } from '@/api/system/engine' export default { name: 'Group', @@ -461,7 +461,8 @@ export default { cancelButtonText: this.$t('dataset.cancel'), type: 'warning' }).then(() => { - delGroup(data.id).then(response => { + const param = { id: data.id, pid: data.pid } + delGroup(param).then(response => { this.$message({ type: 'success', message: this.$t('dataset.delete_success'), @@ -476,9 +477,9 @@ export default { deleteTable(data) { let confirm_delete_msg = '' - if(data.modelInnerType === 'union' || data.modelInnerType === 'custom'){ + if (data.modelInnerType === 'union' || data.modelInnerType === 'custom') { confirm_delete_msg = this.$t('dataset.confirm_delete') - }else { + } else { confirm_delete_msg = this.$t('dataset.confirm_delete_msg') } this.$confirm(confirm_delete_msg, this.$t('dataset.tips'), { diff --git a/frontend/src/views/system/log/index.vue b/frontend/src/views/system/log/index.vue index 1553d97f08..fe3e93b194 100644 --- a/frontend/src/views/system/log/index.vue +++ b/frontend/src/views/system/log/index.vue @@ -4,7 +4,6 @@ v-loading="$store.getters.loadingMap[$store.getters.currentPath]" :data="data" :columns="columns" - local-key="logGrid" :search-config="searchConfig" :pagination-config="paginationConfig" @select="select" @@ -15,13 +14,13 @@ {{ $t('log.export') }} - + - +