Skip to content

Commit 342bb06

Browse files
authored
增加登录用户上下文接口,无需硬编码写死,格式化部分代码 (opentiny#198)
* fix published page history query method * 统一版权注释,增加登录用户的上下文接口,解决硬编码问题
1 parent 7f8b7e1 commit 342bb06

File tree

21 files changed

+281
-68
lines changed

21 files changed

+281
-68
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2023 - present TinyEngine Authors.
3+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4+
*
5+
* Use of this source code is governed by an MIT-style license.
6+
*
7+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*/
11+
12+
package com.tinyengine.it.config.context;
13+
14+
import com.tinyengine.it.common.context.LoginUserContext;
15+
16+
/**
17+
* 默认的登录用户Context实现
18+
*/
19+
public class DefaultLoginUserContext implements LoginUserContext {
20+
@Override
21+
public String getTenantId() {
22+
return "1";
23+
}
24+
25+
@Override
26+
public String getLoginUserId() {
27+
return "1";
28+
}
29+
30+
@Override
31+
public String getRenterId() {
32+
return "1";
33+
}
34+
35+
@Override
36+
public int getAppId() {
37+
return 1;
38+
}
39+
40+
@Override
41+
public int getPlatformId() {
42+
return 1;
43+
}
44+
}

base/src/main/java/com/tinyengine/it/common/base/PageQueryVo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* Copyright (c) 2023 - present TinyEngine Authors.
33
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
* <p>
4+
*
55
* Use of this source code is governed by an MIT-style license.
6-
* <p>
6+
*
77
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
88
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
1011
*/
1112

1213
package com.tinyengine.it.common.base;
@@ -23,6 +24,7 @@ public class PageQueryVo<T> {
2324
* 最大分页数量
2425
*/
2526
public static final int PAGESIZE_MAX = 200;
27+
2628
/**
2729
* 默认分页数量
2830
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) 2023 - present TinyEngine Authors.
3+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4+
* <p>
5+
* Use of this source code is governed by an MIT-style license.
6+
* <p>
7+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*/
11+
12+
package com.tinyengine.it.common.context;
13+
14+
/**
15+
* 保存用户信息的上下文
16+
* 由集成方自行实现接口
17+
*/
18+
public interface LoginUserContext {
19+
/**
20+
* 返回当前用户所诉的业务租户信息
21+
* @return 租户ID
22+
*/
23+
public String getTenantId();
24+
25+
/**
26+
* 返回当前用户信息
27+
* @return 用户ID
28+
*/
29+
public String getLoginUserId();
30+
31+
/**
32+
* 返回当前用户所属业务租户信息
33+
* @return 业务租户ID
34+
*/
35+
public String getRenterId();
36+
37+
/**
38+
* 返回当前应用信息
39+
* @return 应用ID
40+
*/
41+
public int getAppId();
42+
43+
/**
44+
* 返回当前设计器信息
45+
* @return 设计器ID
46+
*/
47+
public int getPlatformId();
48+
}

base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
package com.tinyengine.it.common.handler;
1414

1515
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
16+
import com.tinyengine.it.common.context.LoginUserContext;
1617

1718
import lombok.extern.slf4j.Slf4j;
1819

1920
import org.apache.ibatis.reflection.MetaObject;
21+
import org.springframework.beans.factory.annotation.Autowired;
2022
import org.springframework.stereotype.Component;
2123

2224
import java.time.LocalDateTime;
@@ -29,15 +31,17 @@
2931
@Component
3032
@Slf4j
3133
public class MyMetaObjectHandler implements MetaObjectHandler {
34+
@Autowired
35+
private LoginUserContext loginUserContext;
36+
3237
@Override
3338
public void insertFill(MetaObject metaObject) {
3439
this.setFieldValByName("createdTime", LocalDateTime.now(), metaObject);
3540
this.setFieldValByName("lastUpdatedTime", LocalDateTime.now(), metaObject);
36-
this.setFieldValByName("createdBy", "1", metaObject);
37-
this.setFieldValByName("lastUpdatedBy", "1", metaObject);
38-
this.setFieldValByName("tenantId", "1", metaObject);
39-
this.setFieldValByName("renterId", "1", metaObject);
40-
this.setFieldValByName("siteId", "1", metaObject);
41+
this.setFieldValByName("createdBy", loginUserContext.getLoginUserId(), metaObject);
42+
this.setFieldValByName("lastUpdatedBy", loginUserContext.getLoginUserId(), metaObject);
43+
this.setFieldValByName("tenantId", loginUserContext.getTenantId(), metaObject);
44+
this.setFieldValByName("renterId", loginUserContext.getRenterId(), metaObject);
4145
}
4246

4347
@Override
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright (c) 2023 - present TinyEngine Authors.
3+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4+
* <p>
5+
* Use of this source code is governed by an MIT-style license.
6+
* <p>
7+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*/
11+
12+
package com.tinyengine.it.common.utils;
13+
14+
import java.lang.reflect.Field;
15+
16+
/**
17+
* 测试工工具类
18+
*/
19+
public class TestUtil {
20+
/**
21+
* 设置私有字段的属性值
22+
*
23+
* @param obj 对象
24+
* @param field 字段名
25+
* @param value 值
26+
* @throws NoSuchFieldException 异常
27+
* @throws IllegalAccessException 异常
28+
*/
29+
public static void setPrivateValue(Object obj, String field, Object value)
30+
throws NoSuchFieldException, IllegalAccessException {
31+
Field declaredField = obj.getClass().getDeclaredField(field);
32+
declaredField.setAccessible(true);
33+
declaredField.set(obj, value);
34+
}
35+
}

base/src/main/java/com/tinyengine/it/controller/PageController.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/**
22
* Copyright (c) 2023 - present TinyEngine Authors.
33
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
*
4+
* <p>
55
* Use of this source code is governed by an MIT-style license.
6-
*
6+
* <p>
77
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
88
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10-
*
1110
*/
1211

1312
package com.tinyengine.it.controller;
@@ -71,8 +70,8 @@ public class PageController {
7170
* @return allpage
7271
*/
7372
@Operation(summary = "获取页面列表", description = "获取页面列表", parameters = {
74-
@Parameter(name = "aid", description = "appId")}, responses = {
75-
@ApiResponse(responseCode = "200", description = "返回信息",
73+
@Parameter(name = "aid", description = "appId")}, responses = {
74+
@ApiResponse(responseCode = "200", description = "返回信息",
7675
content = @Content(mediaType = "application/json",
7776
schema = @Schema(implementation = Page.class))),
7877
@ApiResponse(responseCode = "400", description = "请求失败")})
@@ -207,8 +206,8 @@ public Result<PreviewDto> previewData(@ModelAttribute PreviewParam previewParam)
207206
@ApiResponse(responseCode = "400", description = "请求失败")})
208207
@SystemControllerLog(description = "页面发布")
209208
@PostMapping("/pages/deploy")
210-
public Result<Integer> pageDeploy(@RequestBody PageHistory pageHistory) {
211-
Integer result = pageHistoryService.createPageHistory(pageHistory);
212-
return Result.success(result);
209+
public Result<PageHistory> pageDeploy(@RequestBody PageHistory pageHistory) {
210+
pageHistoryService.createPageHistory(pageHistory);
211+
return Result.success(pageHistory);
213212
}
214213
}

base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* Copyright (c) 2023 - present TinyEngine Authors.
33
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
* <p>
4+
*
55
* Use of this source code is governed by an MIT-style license.
6-
* <p>
6+
*
77
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
88
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
1011
*/
1112

1213
package com.tinyengine.it.mapper;

base/src/main/java/com/tinyengine/it/mapper/PageHistoryMapper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* Copyright (c) 2023 - present TinyEngine Authors.
33
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
* <p>
4+
*
55
* Use of this source code is governed by an MIT-style license.
6-
* <p>
6+
*
77
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
88
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
1011
*/
1112

1213
package com.tinyengine.it.mapper;
@@ -85,10 +86,10 @@ public interface PageHistoryMapper extends BaseMapper<PageHistory> {
8586
/**
8687
* 查询发布的页面记录
8788
*
88-
* @param iPage the iPage
89+
* @param iPage the iPage
8990
* @param pageHistoryVo the pageQueryVo
9091
* @return page history
9192
*/
9293
IPage<PublishedPageVo> findLatestPublishPage(IPage<PublishedPageVo> iPage,
93-
@Param("pageHistory") PublishedPageVo pageHistoryVo);
94+
@Param("pageHistory") PublishedPageVo pageHistoryVo);
9495
}

base/src/main/java/com/tinyengine/it/model/dto/PageHistoryVo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* Copyright (c) 2023 - present TinyEngine Authors.
33
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
* <p>
4+
*
55
* Use of this source code is governed by an MIT-style license.
6-
* <p>
6+
*
77
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
88
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
1011
*/
1112

1213
package com.tinyengine.it.model.dto;

base/src/main/java/com/tinyengine/it/model/dto/PublishedPageVo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* Copyright (c) 2023 - present TinyEngine Authors.
33
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
* <p>
4+
*
55
* Use of this source code is governed by an MIT-style license.
6-
* <p>
6+
*
77
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
88
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
1011
*/
1112

1213
package com.tinyengine.it.model.dto;
@@ -25,6 +26,7 @@
2526
@Getter
2627
public class PublishedPageVo {
2728
private Integer refId;
29+
2830
/**
2931
* 名称
3032
*/

0 commit comments

Comments
 (0)