Skip to content

Commit

Permalink
feat(日志): 公共链接增加日志
Browse files Browse the repository at this point in the history
  • Loading branch information
fit2cloud-chenyw committed Nov 8, 2022
1 parent 4f3a171 commit a41cf92
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public Map<String, String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"),
Expand Down
14 changes: 7 additions & 7 deletions backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<FolderItem> items = new ArrayList<>();
items.add(folderItem);
sysLogDTO.setPositions(items);
}else {
} else {
List<FolderItem> parentsAndSelf = logManager.justParents(sourceIdValue.toString(), sourcetype);
sysLogDTO.setPositions(parentsAndSelf);
}
Expand All @@ -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());
Expand All @@ -83,14 +83,14 @@ public static SysLogDTO buildLog(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetyp
List<FolderItem> items = new ArrayList<>();
items.add(folderItem);
sysLogDTO.setPositions(items);
}else {
if(sourcetype == SOURCE_TYPE.DRIVER_FILE){
} else {
if (sourcetype == SOURCE_TYPE.DRIVER_FILE) {
List<FolderItem> 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<FolderItem> parentsAndSelf = logManager.parentsAndSelf(positionId.toString(), SOURCE_TYPE.PANEL);
sysLogDTO.setPositions(parentsAndSelf);
}else {
} else {
List<FolderItem> parentsAndSelf = logManager.parentsAndSelf(positionId.toString(), sourcetype);
sysLogDTO.setPositions(parentsAndSelf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, String> param);

@ApiIgnore
@PostMapping("/viewLog")
void viewLinkLog(@RequestBody LinkViewLogRequest request);


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,4 +114,19 @@ public String shortUrl(Map<String, String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
35 changes: 18 additions & 17 deletions backend/src/main/java/io/dataease/service/sys/log/LogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<FolderItem>>() {}.getType();

protected Type type = new TypeToken<List<FolderItem>>() {
}.getType();


@Resource
Expand All @@ -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<FolderItem> 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;
Expand All @@ -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 = "";
Expand Down Expand Up @@ -119,7 +120,7 @@ private LogTypeItem parentIds(String id, Integer value) {
}


private List<FolderItem> parentInfos(List<String> ids, Integer value){
private List<FolderItem> parentInfos(List<String> ids, Integer value) {
List<FolderItem> folderItems = extSysLogMapper.idAndName(ids, value);
if (value == 3) {
folderItems.forEach(item -> {
Expand Down Expand Up @@ -164,7 +165,7 @@ public FolderItem dsTypeInfo(String typeId) {
ArrayList<DataSourceType> 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;
}
Expand Down
12 changes: 12 additions & 0 deletions backend/src/main/java/io/dataease/service/sys/log/LogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -247,6 +249,16 @@ public List<FolderItem> 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;
Expand Down
4 changes: 4 additions & 0 deletions backend/src/main/resources/db/migration/V44__1.17.sql
Original file line number Diff line number Diff line change
@@ -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 '姓名';
5 changes: 5 additions & 0 deletions backend/src/main/resources/i18n/messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

5 changes: 5 additions & 0 deletions backend/src/main/resources/i18n/messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

5 changes: 5 additions & 0 deletions backend/src/main/resources/i18n/messages_zh_TW.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions frontend/src/api/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/views/link/view/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
</template>

<script>
import { loadResource } from '@/api/link'
import { loadResource, viewLinkLog } from '@/api/link'
import { isMobile } from '@/utils/index'
import { uuid } from 'vue-uuid'
import Preview from '@/components/canvas/components/editor/Preview'
import { getPanelAllLinkageInfo } from '@/api/panel/linkage'
Expand Down Expand Up @@ -50,8 +51,19 @@ export default {
created() {
this.show = false
this.setPanelInfo()
this.viewLog()
},
methods: {
viewLog() {
const param = {
panelId: this.resourceId,
userId: this.user,
mobile: !!isMobile()
}
viewLinkLog(param).then(res => {
})
},
setPanelInfo() {
loadResource(this.resourceId).then(res => {
this.show = false
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/system/log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
show-overflow-tooltip
prop="opType"
:label="$t('log.optype')"
width="140"
width="160"
>
<template #default="{ row }">
<span>{{ row.opType + row.sourceType }}</span>
Expand Down

0 comments on commit a41cf92

Please sign in to comment.