Merge 推送至业务 #17
40
src/main/java/com/jsl/oa/config/startup/PermissionList.java
Normal file
40
src/main/java/com/jsl/oa/config/startup/PermissionList.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package com.jsl.oa.config.startup;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class PermissionList {
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public static class PermissionVO {
|
||||||
|
private final String name;
|
||||||
|
private final String desc;
|
||||||
|
}
|
||||||
|
private final ArrayList<PermissionList.PermissionVO> permissionList = new ArrayList<>();
|
||||||
|
private final ArrayList<PermissionList.PermissionVO> permissionPrincipal = new ArrayList<>();
|
||||||
|
private final ArrayList<PermissionList.PermissionVO> permissionDeveloper = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
public PermissionList() {
|
||||||
|
permissionList.add(new PermissionVO("auth:logout", "账户登出"));
|
||||||
|
permissionList.add(new PermissionVO("auth:change_password", "修改密码"));
|
||||||
|
permissionList.add(new PermissionVO("info:get_header_image", "获取头部图片"));
|
||||||
|
permissionList.add(new PermissionVO("info:edit_header_image", "编辑头部图片"));
|
||||||
|
permissionList.add(new PermissionVO("info:delete_header_image", "删除头部图片"));
|
||||||
|
|
||||||
|
permissionPrincipal.add(new PermissionVO("auth:logout", "账户登出"));
|
||||||
|
permissionPrincipal.add(new PermissionVO("auth:change_password", "修改密码"));
|
||||||
|
permissionPrincipal.add(new PermissionVO("info:get_header_image", "获取头部图片"));
|
||||||
|
permissionPrincipal.add(new PermissionVO("info:edit_header_image", "编辑头部图片"));
|
||||||
|
permissionPrincipal.add(new PermissionVO("info:delete_header_image", "删除头部图片"));
|
||||||
|
|
||||||
|
permissionDeveloper.add(new PermissionVO("auth:logout", "账户登出"));
|
||||||
|
permissionDeveloper.add(new PermissionVO("auth:change_password", "修改密码"));
|
||||||
|
permissionDeveloper.add(new PermissionVO("info:get_header_image", "获取头部图片"));
|
||||||
|
permissionDeveloper.add(new PermissionVO("info:edit_header_image", "编辑头部图片"));
|
||||||
|
permissionDeveloper.add(new PermissionVO("info:delete_header_image", "删除头部图片"));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.jsl.oa.config.startup;
|
package com.jsl.oa.config.startup;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
@ -11,6 +12,7 @@ import org.springframework.util.FileCopyUtils;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -76,4 +78,17 @@ public class PrepareData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkPermission(String roleName, ArrayList<PermissionList.PermissionVO> permissions) {
|
||||||
|
ArrayList<String> newPermissions = new ArrayList<>();
|
||||||
|
permissions.forEach(it -> newPermissions.add(it.getName()));
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String getPermissionString = gson.toJson(newPermissions);
|
||||||
|
log.debug("[Preparation] 更新角色 {} 权限", roleName);
|
||||||
|
jdbcTemplate.update(
|
||||||
|
"UPDATE organize_oa.oa_role SET permissions = ? WHERE role_name = ?",
|
||||||
|
getPermissionString,
|
||||||
|
roleName
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import java.util.HashMap;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class StartupConfiguration {
|
public class StartupConfiguration {
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
private final PermissionList getPermission = new PermissionList();
|
||||||
private PrepareData prepareData;
|
private PrepareData prepareData;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -78,20 +79,49 @@ public class StartupConfiguration {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Order(3)
|
||||||
|
public CommandLineRunner permissionDataPreparation() {
|
||||||
|
return args -> {
|
||||||
|
log.info("[Preparation] 系统进行权限表完整性检查");
|
||||||
|
getPermission.getPermissionList().forEach(permissionVO -> {
|
||||||
|
try {
|
||||||
|
jdbcTemplate.queryForObject(
|
||||||
|
"SELECT id FROM organize_oa.oa_permissions WHERE name = ?",
|
||||||
|
Long.class,
|
||||||
|
permissionVO.getName()
|
||||||
|
);
|
||||||
|
} catch (DataAccessException e) {
|
||||||
|
log.debug("[Preparation] 缺失 {} 权限,正在创建", permissionVO.getName());
|
||||||
|
jdbcTemplate.update(
|
||||||
|
"INSERT INTO organize_oa.oa_permissions (name, description) VALUES (?,?)",
|
||||||
|
permissionVO.getName(),
|
||||||
|
permissionVO.getDesc()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对数据表进行完整性检查
|
* 对数据表进行完整性检查
|
||||||
* <hr/>
|
* <hr/>
|
||||||
* 对数据表进行完整性检查,检查数据表是否有数据缺失等信息
|
* 对数据表进行完整性检查,检查数据表是否有数据缺失等信息
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@Order(3)
|
@Order(4)
|
||||||
public CommandLineRunner roleDataPreparation() {
|
public CommandLineRunner roleDataPreparation() {
|
||||||
return args -> {
|
return args -> {
|
||||||
log.info("[Preparation] 系统进行数据表完整性检查");
|
log.info("[Preparation] 系统进行角色表完整性检查");
|
||||||
// 检查角色信息是否完整
|
// 检查角色信息是否完整
|
||||||
prepareData.checkRole("console", "超级管理员");
|
prepareData.checkRole("console", "超级管理员");
|
||||||
prepareData.checkRole("principal", "负责人");
|
prepareData.checkRole("principal", "负责人");
|
||||||
prepareData.checkRole("developer", "开发者");
|
prepareData.checkRole("developer", "开发者");
|
||||||
|
|
||||||
|
// 对权限的检查
|
||||||
|
prepareData.checkPermission("console", getPermission.getPermissionList());
|
||||||
|
prepareData.checkPermission("principal", getPermission.getPermissionPrincipal());
|
||||||
|
prepareData.checkPermission("developer", getPermission.getPermissionDeveloper());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +132,7 @@ public class StartupConfiguration {
|
|||||||
* 账户。
|
* 账户。
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@Order(4)
|
@Order(5)
|
||||||
public CommandLineRunner defaultConsoleDataPreparation() {
|
public CommandLineRunner defaultConsoleDataPreparation() {
|
||||||
return args -> {
|
return args -> {
|
||||||
log.info("[Preparation] 系统进行默认超级管理员信息检查");
|
log.info("[Preparation] 系统进行默认超级管理员信息检查");
|
||||||
@ -162,7 +192,7 @@ public class StartupConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Order(5)
|
@Order(6)
|
||||||
public CommandLineRunner prepareDefaultConfigData(Gson gson) {
|
public CommandLineRunner prepareDefaultConfigData(Gson gson) {
|
||||||
return args -> {
|
return args -> {
|
||||||
// 检查加密密钥是否存在
|
// 检查加密密钥是否存在
|
||||||
@ -209,7 +239,7 @@ public class StartupConfiguration {
|
|||||||
* 准备安全密钥,用于加密解密等操作
|
* 准备安全密钥,用于加密解密等操作
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@Order(6)
|
@Order(7)
|
||||||
public CommandLineRunner prepareKey() {
|
public CommandLineRunner prepareKey() {
|
||||||
return args -> {
|
return args -> {
|
||||||
log.info("[Preparation] 系统进行安全密钥准备");
|
log.info("[Preparation] 系统进行安全密钥准备");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jsl.oa.controllers;
|
package com.jsl.oa.controllers;
|
||||||
|
|
||||||
|
import com.jsl.oa.annotations.NeedPermission;
|
||||||
import com.jsl.oa.model.vodata.UserChangePasswordVO;
|
import com.jsl.oa.model.vodata.UserChangePasswordVO;
|
||||||
import com.jsl.oa.model.vodata.UserForgetPasswordVO;
|
import com.jsl.oa.model.vodata.UserForgetPasswordVO;
|
||||||
import com.jsl.oa.model.vodata.UserLoginVO;
|
import com.jsl.oa.model.vodata.UserLoginVO;
|
||||||
@ -146,6 +147,7 @@ public class AuthController {
|
|||||||
* @since v1.1.0
|
* @since v1.1.0
|
||||||
*/
|
*/
|
||||||
@GetMapping("/auth/logout")
|
@GetMapping("/auth/logout")
|
||||||
|
@NeedPermission("auth:logout")
|
||||||
public BaseResponse authLogout(HttpServletRequest request) {
|
public BaseResponse authLogout(HttpServletRequest request) {
|
||||||
return authService.authLogout(request);
|
return authService.authLogout(request);
|
||||||
}
|
}
|
||||||
@ -162,6 +164,7 @@ public class AuthController {
|
|||||||
* @since v1.1.0
|
* @since v1.1.0
|
||||||
*/
|
*/
|
||||||
@PutMapping("/auth/password")
|
@PutMapping("/auth/password")
|
||||||
|
@NeedPermission("auth:change_password")
|
||||||
public BaseResponse authChangePassword(
|
public BaseResponse authChangePassword(
|
||||||
@RequestBody @Validated UserChangePasswordVO userChangePasswordVO,
|
@RequestBody @Validated UserChangePasswordVO userChangePasswordVO,
|
||||||
@NotNull BindingResult bindingResult,
|
@NotNull BindingResult bindingResult,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jsl.oa.controllers;
|
package com.jsl.oa.controllers;
|
||||||
|
|
||||||
|
import com.jsl.oa.annotations.NeedPermission;
|
||||||
import com.jsl.oa.model.vodata.business.info.CarouselVO;
|
import com.jsl.oa.model.vodata.business.info.CarouselVO;
|
||||||
import com.jsl.oa.services.InfoService;
|
import com.jsl.oa.services.InfoService;
|
||||||
import com.jsl.oa.utils.BaseResponse;
|
import com.jsl.oa.utils.BaseResponse;
|
||||||
@ -41,6 +42,7 @@ public class InfoController {
|
|||||||
* @return 图片信息
|
* @return 图片信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("/info/header-image/get")
|
@GetMapping("/info/header-image/get")
|
||||||
|
@NeedPermission("info:get_header_image")
|
||||||
public BaseResponse infoGetHeaderImage(@RequestParam(required = false) Integer id) {
|
public BaseResponse infoGetHeaderImage(@RequestParam(required = false) Integer id) {
|
||||||
return infoService.getHeaderImage(id);
|
return infoService.getHeaderImage(id);
|
||||||
}
|
}
|
||||||
@ -54,6 +56,7 @@ public class InfoController {
|
|||||||
* @return 编辑结果
|
* @return 编辑结果
|
||||||
*/
|
*/
|
||||||
@PutMapping("/info/header-image/edit")
|
@PutMapping("/info/header-image/edit")
|
||||||
|
@NeedPermission("info:edit_header_image")
|
||||||
public BaseResponse infoEditHeaderImage(
|
public BaseResponse infoEditHeaderImage(
|
||||||
@RequestBody @Validated CarouselVO carouselVO,
|
@RequestBody @Validated CarouselVO carouselVO,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
@ -79,6 +82,7 @@ public class InfoController {
|
|||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/info/header-image/del")
|
@DeleteMapping("/info/header-image/del")
|
||||||
|
@NeedPermission("info:delete_header_image")
|
||||||
public BaseResponse infoDelHeaderImage(@RequestParam Integer id, HttpServletRequest request) {
|
public BaseResponse infoDelHeaderImage(@RequestParam Integer id, HttpServletRequest request) {
|
||||||
return infoService.delHeaderImage(request, id);
|
return infoService.delHeaderImage(request, id);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user