# v2.3.1 升级至 v2.4.0

# 组件更改说明

该升级指南以v2.3.1版本为基准,更早的版本请先参考之前版本的升级文档。

diboot v2.4.x是基于spring boot 2.6的版本。

将diboot所有的组件版本号替换至2.4.0的最新版本,然后按照下述内容进行相关更改即可。

# diboot-core 内核

  • com.diboot.core.vo 包下的 KeyValue 替换为了 LabelValue;其属性名 key 更改为了 label

  • BaseService 移除了 getKeyValueMap,并且将 getKeyValueList 更名为 getLabelValueList

    • 使用了 getKeyValueMap 可替换为 BeanUtils.convertLabelValueList2Map(baseService.getLabelValueList(queryWrapper));
  • @ProtectField 默认值调整为不做任何处理;使用了该注解且为指定相应策略的现在需要自行指定策略(原默认策略仍保留,手动指定即可)

    • encryptor() : 加密策略,默认为 DoNothingEncryptStrategy.class,不做任何处理;可替换为自定义的IEncryptStrategy实现类。
      • 提供了默认加密策略 DefaultEncryptStrategy ,需自行指定。
    • mask() : 脱敏策略,默认为 DoNothingMaskStrategy.class,不做任何处理;可按需替换为自定义的IMaskStrategy实现类。
      • 提供了默认脱敏策略 DefaultMaskStrategy,需自行指定。
  • DictionaryController 移除 /common/attachMore 接口

  • 新增CommonController

/**
 * 公共 Controller
 */
@RestController
@RequestMapping("/common")
public class CommonController extends BaseController {

  /**
   * 获取附加属性的通用Options接口,用于初始化前端下拉框选项。
   * <p>
   * 如数据量过大,请调用通用Options过滤接口:{@link #attachMoreFilter(AttachMoreDTO, String, String)}
   *
   * @param attachMoreDTOList 关联数据列表
   * @return Options集合
   */
  @PostMapping("/attachMore")
  public JsonResult<Map<String, List<LabelValue>>> attachMore(@Valid @RequestBody ValidList<AttachMoreDTO> attachMoreDTOList) {
    return JsonResult.OK(super.attachMoreRelatedData(attachMoreDTOList));
  }

  /**
   * 获取附加属性的通用Options过滤接口,用于前端下拉框选择远程搜索 或 异步加载(树|级联)数据。
   * <p>
   * 适用于数据量大时远程过滤获取选项数据,或分层级获取数据
   *
   * @param attachMoreDTO
   * @param parentType
   * @param parentValue
   * @return
   */
  @PostMapping({"/attachMoreFilter", "/attachMoreFilter/{parentValue}", "/attachMoreFilter/{parentType}/{parentValue}"})
  public JsonResult<List<LabelValue>> attachMoreFilter(@Valid @RequestBody AttachMoreDTO attachMoreDTO,
                                                       @PathVariable(value = "parentValue", required = false) String parentValue,
                                                       @PathVariable(value = "parentType", required = false) String parentType) {
    return JsonResult.OK(super.attachMoreRelatedData(attachMoreDTO, parentValue, parentType));
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

# diboot-iam 权限体系

  • 修改com.XX.controller.iam.AuthTokenController
    @Autowired
-   private IamUserService iamUserService;
+   private IamUserRoleService iamUserRoleService;


    public JsonResult getUserInfo(){
        Map<String, Object> data = new HashMap<>();
        // 获取当前登录用户对象
-       IamUser currentUser = IamSecurityUtils.getCurrentUser();
+       BaseLoginUser currentUser = IamSecurityUtils.getCurrentUser();
        if(currentUser == null){
            return JsonResult.OK();
        }
        data.put("name", currentUser.getDisplayName());
        // 角色权限数据
-       IamRoleVO roleVO = iamUserService.buildRoleVo4FrontEnd(currentUser);
-       data.put("role", roleVO);
+       data.put("role", iamUserRoleService.buildRoleVo4FrontEnd(currentUser));

        return JsonResult.OK(data);
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  • 接口替换
// IamResourcePermissionController

	@GetMapping("/attachMore")
    public JsonResult attachMore(ModelMap modelMap) throws Exception{
        // 获取关联表数据IamResourcePermission的树状列表
        List<IamResourcePermissionListVO> menuList = iamResourcePermissionService.getViewObjectList(
            Wrappers.<IamResourcePermission>lambdaQuery().eq(IamResourcePermission::getDisplayType, Cons.RESOURCE_PERMISSION_DISPLAY_TYPE.MENU.name()),
            null,
            IamResourcePermissionListVO.class
        );
        modelMap.put("menuTree", BeanUtils.buildTree(menuList));
        return JsonResult.OK(modelMap);
    }


// MessageTemplateController

	@GetMapping("/attachMore")
    public JsonResult attachMore(ModelMap modelMap) throws Exception {
        // 加载模版变量
        modelMap.put("templateVariableList", messageTemplateService.getTemplateVariableList());
        return JsonResult.OK(modelMap);
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  • 接口移除 IamXXXController 中无用接口
    • @GetMapping("/attachMore")
      • IamLoginTraceController
      • IamOrgController
      • IamUserController
    • @GetMapping("KvList")
      • IamRoleController
      • IamPositionController

# diboot-file 文件组件

  • 如果依赖了文件组件,手动执行以下SQL更新数据结构(以下为MySQL脚本,其他库请自行转换):
ALTER TABLE upload_file ADD COLUMN create_by    bigint      default 0 COMMENT '创建人' AFTER is_deleted;
ALTER TABLE upload_file MODIFY COLUMN create_time  timestamp   default CURRENT_TIMESTAMP not null comment '创建时间' AFTER create_by;
1
2

Excel导入功能接口如下调整

    // 预览
    @PostMapping("/preview")
    public JsonResult preview(@RequestParam("file") MultipartFile file, @RequestParam Map<String, Object> params) throws Exception {
        return super.excelPreview(file, Entity.class, params); // Entity 为相应实体
    }
    
    // 预览保存
    @PostMapping("/previewSave")
    public JsonResult previewSave(@RequestParam Map<String, Object> params) throws Exception {
        return super.excelPreviewSave(params);
    }

    // 直接导入
    @PostMapping("/upload")
    public JsonResult upload(@RequestParam("file") MultipartFile file, @RequestParam Map<String, Object> params) throws Exception {
        return super.uploadExcelFile(file, Entity.class, params);
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# swagger 相关

从v2.4.0版本开始 devtools生成的swagger注解升级为swagger v3,接口文档组件基于springdoc。 如果之前已经使用了springfox,需要将springfox依赖删除,添加springdoc依赖,如下:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>${latest.version}</version>
</dependency>
1
2
3
4
5

具体差异请参考文档: Spring Boot 集成 SpringDoc Swagger 3

# diboot-mobile 移动端组件

mobile的controller请参照如下进行改动,另配置文件中WxMaMemberAuthServiceWxMpMemberAuthService直接删除即可

  • WxMpAuthTokenController调整
public class WxMpAuthTokenController extends BaseController {
    @Autowired(required=false)
    private WxMpAuthService wxMpAuthService;
    
    @GetMapping("/auth/buildOAuthUrl")
    public JsonResult buildOAuthUrl4mp(@RequestParam(value = "url") String url) throws Exception {
        return JsonResult.OK(wxMpAuthService.buildOAuthUrl4mp(url));
    }

    @GetMapping("/auth/apply")
    public JsonResult apply(@RequestParam(value = "code") String code, @RequestParam(value = "state") String state) throws Exception {
        return JsonResult.OK(wxMpAuthService.applyToken(code, state));
    }
    
     /**
     * 登陆后绑定授权
     * @param code
     * @param state
     * @return
     * @throws Exception
     */
    @GetMapping("/bindMp")
    public JsonResult bindMp(@RequestParam(value = "code") String code, @RequestParam(value = "state") String state) throws Exception {
        return JsonResult.OK(wxMpAuthService.bindWxMp(code, state));
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  • WxMaAuthTokenController调整
public class WxMaAuthTokenController extends BaseController {

    @Autowired(required=false)
    private WxMaAuthService wxMaAuthService;
    
    @PostMapping("/auth/login")
    public JsonResult<String> login(@RequestBody MobileCredential credential) throws Exception {
        credential.setUserTypeClass(IamMember.class);
        String authToken = AuthServiceFactory
                .getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name())
                .applyToken(credential);
        return JsonResult.OK(authToken);
    }
    
    @GetMapping("/auth/getSessionInfo")
    public JsonResult getSessionInfo(String code) throws Exception {
        return JsonResult.OK(wxMaAuthService.getSessionInfo(code));
    }
    
    @PostMapping("/auth/getAndSaveWxMember")
    public JsonResult getAndSaveWxMember(@RequestBody WxMemberDTO wxInfoDTO) throws Exception {
        return JsonResult.OK(wxMaAuthService.getAndSaveWxMember(wxInfoDTO));
    }
        
     /**
     * 登陆后绑定授权
     * @param code
     * @param state
     * @return
     * @throws Exception
     */
    @PostMapping("/bindMa")
    public JsonResult bindMa(@RequestBody WxMemberDTO wxInfoDTO) throws Exception {
        return JsonResult.OK(wxMaAuthService.bindWxMa(wxInfoDTO));
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  • H5TokenController调整
@RequestMapping("/h5")
public class H5AuthTokenController extends BaseController {

    /**
    * 用户登录获取token
    * @param credential
    * @return
    * @throws Exception
    */
    @PostMapping("/auth/login")
    public JsonResult login(@RequestBody PwdCredential credential) throws Exception{
        credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.PWD.name()).setUserTypeClass(IamMember.class);
        String authtoken = AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.PWD.name()).applyToken(credential);
        return JsonResult.OK(authtoken);
    }

    /**
    * 注销/退出
    * @return
    * @throws Exception
    */
	@Log(businessObj = "LoginUser", operation = "退出")
    @PostMapping("/logout")
    public JsonResult logout() throws Exception{
        IamSecurityUtils.logout();
        return JsonResult.OK();
    }

    /**
    * 获取用户信息
    * @return
    */
    @GetMapping("/userInfo")
    public JsonResult getUserInfo(){
        // 获取当前登录用户对象
        Object currentUser = IamSecurityUtils.getCurrentUser();
        if(currentUser == null){
            return JsonResult.OK();
        }
        return JsonResult.OK(currentUser);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# 前端升级说明

  • diboot-antd-admin前端调整

升级前请下载diboot-antd-admin 2.4.0 (opens new window)源码包,以下升级流程将依赖此包。

  • diboot-element-admin前端调整

升级前请下载diboot-element-admin 2.4.0 (opens new window)源码包,以下升级流程将依赖此包。

  • 对比新旧版本的相关页面及代码,替换或合并至本地。

  • 需要全局替换修改的点,按照以下指定规则和内容进行全局替换

说明:移了 KvList 概念,将其替换为了 Options,其内部对象属性名 v 改为了 value 、 k 改为了 label;以及将attachMoreList中对象的 key 属性更名为 label

注:该替换方案同时适用于diboot-element-admindiboot-antd-admin

【 大小写匹配 + 整词匹配 】

"kv
"item

{{ kv.
{{ item.

.k
.label

.v
.value

# excel 导出组件名称位置调整
@/components/diboot/components/import/ExcelImport
@/components/diboot/components/excel/import


【 大小写配置 + 正则匹配 】

:data(K|-k)v(L|-l)ist=
:options=

more(.*)KvList
more$1Options

target\: \'(\w*)\'\,\n([ ]*)  key: '(\w{1,})',\n
target\: \'$1\'\,\n$2  label: '$3',\n
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29