refactor(cutejava-system):重构系统模块代码
- 更新了多个控制器、Mapper接口和Redis DAO的命名 - 优化了部分方法名称,提高了代码可读性 - 移除了冗余代码,简化了部分逻辑
This commit is contained in:
+2
-2
@@ -9,7 +9,7 @@ import cn.odboy.core.dal.model.system.SystemUserInfoVo;
|
||||
import cn.odboy.core.dal.model.system.SystemUserJwtVo;
|
||||
import cn.odboy.core.dal.model.system.SystemUserLoginArgs;
|
||||
import cn.odboy.core.dal.redis.system.SystemRedisKey;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineInfoDAO;
|
||||
import cn.odboy.core.framework.permission.core.SecurityHelper;
|
||||
import cn.odboy.core.framework.permission.core.handler.TokenProvider;
|
||||
import cn.odboy.core.framework.permission.core.handler.UserDetailsHandler;
|
||||
@@ -50,7 +50,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@Api(tags = "系统:系统授权接口")
|
||||
public class SystemAuthController {
|
||||
private final RedisHelper redisHelper;
|
||||
private final SystemUserOnlineDAO onlineUserService;
|
||||
private final SystemUserOnlineInfoDAO onlineUserService;
|
||||
private final TokenProvider tokenProvider;
|
||||
private final AppProperties properties;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
+3
-3
@@ -28,9 +28,9 @@ public class SystemDictDetailController {
|
||||
|
||||
@ApiOperation("查询字典详情")
|
||||
@GetMapping
|
||||
public ResponseEntity<CsResultVo<List<SystemDictDetailTb>>> queryDictDetailListByArgs(QuerySystemDictDetailArgs criteria) {
|
||||
public ResponseEntity<CsResultVo<List<SystemDictDetailTb>>> selectDictDetailByArgs(QuerySystemDictDetailArgs criteria) {
|
||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(systemDictDetailService.queryDictDetailListByArgs(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemDictDetailService.queryDictDetailByArgs(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询多个字典详情")
|
||||
@@ -39,7 +39,7 @@ public class SystemDictDetailController {
|
||||
String[] names = dictName.split("[,,]");
|
||||
Map<String, List<SystemDictDetailTb>> dictMap = new HashMap<>(16);
|
||||
for (String name : names) {
|
||||
dictMap.put(name, systemDictDetailService.queryDictDetailListByName(name));
|
||||
dictMap.put(name, systemDictDetailService.queryDictDetailByName(name));
|
||||
}
|
||||
return new ResponseEntity<>(dictMap, HttpStatus.OK);
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,13 +27,13 @@ public class SystemEmailController {
|
||||
@ApiOperation("查询配置")
|
||||
@PostMapping(value = "/queryEmailConfig")
|
||||
public ResponseEntity<SystemEmailConfigTb> queryEmailConfig() {
|
||||
return new ResponseEntity<>(systemEmailService.getEmailConfig(), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemEmailService.getLastEmailConfig(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("配置邮件")
|
||||
@PostMapping(value = "/modifyEmailConfig")
|
||||
public ResponseEntity<Void> modifyEmailConfig(@Validated @RequestBody SystemEmailConfigTb emailConfig) throws Exception {
|
||||
systemEmailService.modifyEmailConfigOnPassChange(emailConfig);
|
||||
systemEmailService.modifyEmailConfig(emailConfig);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ public class SystemJobController {
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('job:list')")
|
||||
public void exportJob(HttpServletResponse response, QuerySystemJobArgs criteria) throws IOException {
|
||||
systemJobService.downloadJobExcel(systemJobService.queryJobList(criteria), response);
|
||||
systemJobService.exportJobExcel(systemJobService.queryJobByArgs(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("查询岗位")
|
||||
@@ -40,7 +40,7 @@ public class SystemJobController {
|
||||
@PreAuthorize("@el.check('job:list','user:list')")
|
||||
public ResponseEntity<CsResultVo<List<SystemJobTb>>> queryJob(QuerySystemJobArgs criteria) {
|
||||
Page<SystemJobTb> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(systemJobService.queryJobPage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemJobService.queryJobByArgs(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("新增岗位")
|
||||
|
||||
+2
-2
@@ -34,14 +34,14 @@ public class SystemLocalStorageController {
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public ResponseEntity<CsResultVo<List<SystemLocalStorageTb>>> queryFile(QuerySystemLocalStorageArgs criteria) {
|
||||
Page<SystemLocalStorageTb> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(localStorageService.queryLocalStoragePage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(localStorageService.queryLocalStorage(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public void exportFile(HttpServletResponse response, QuerySystemLocalStorageArgs criteria) throws IOException {
|
||||
localStorageService.downloadExcel(localStorageService.queryLocalStorageList(criteria), response);
|
||||
localStorageService.exportLocalStorageExcel(localStorageService.queryLocalStorage(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("上传文件")
|
||||
|
||||
+2
-3
@@ -18,13 +18,12 @@ import java.util.Map;
|
||||
@Api(tags = "系统-服务监控管理")
|
||||
@RequestMapping("/api/monitor")
|
||||
public class SystemMonitorController {
|
||||
|
||||
private final SystemMonitorService serverService;
|
||||
private final SystemMonitorService systemMonitorService;
|
||||
|
||||
@PostMapping(value = "/queryServerMonitorInfo")
|
||||
@ApiOperation("查询服务监控")
|
||||
@PreAuthorize("@el.check('monitor:list')")
|
||||
public ResponseEntity<Map<String, Object>> queryServerMonitorInfo() {
|
||||
return new ResponseEntity<>(serverService.queryServerMonitorInfo(), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemMonitorService.queryServerMonitorInfo(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -2,7 +2,7 @@ package cn.odboy.core.controller.system;
|
||||
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.model.system.SystemUserOnlineVo;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineInfoDAO;
|
||||
import cn.odboy.util.DesEncryptUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -24,20 +24,20 @@ import java.util.Set;
|
||||
@RequestMapping("/auth/online")
|
||||
@Api(tags = "系统:在线用户管理")
|
||||
public class SystemOnlineController {
|
||||
private final SystemUserOnlineDAO systemUserOnlineDAO;
|
||||
private final SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
|
||||
|
||||
@ApiOperation("查询在线用户")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<CsResultVo<List<SystemUserOnlineVo>>> queryOnlineUser(String username, Pageable pageable) {
|
||||
return new ResponseEntity<>(systemUserOnlineDAO.queryUserOnlineModelPage(username, pageable), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemUserOnlineInfoDAO.queryUserOnlineModelPage(username, pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check()")
|
||||
public void exportOnlineUser(HttpServletResponse response, String username) throws IOException {
|
||||
systemUserOnlineDAO.downloadUserOnlineModelExcel(systemUserOnlineDAO.queryUserOnlineModelListByUsername(username), response);
|
||||
systemUserOnlineInfoDAO.downloadUserOnlineModelExcel(systemUserOnlineInfoDAO.queryUserOnlineModelListByUsername(username), response);
|
||||
}
|
||||
|
||||
@ApiOperation("踢出用户")
|
||||
@@ -47,7 +47,7 @@ public class SystemOnlineController {
|
||||
for (String token : keys) {
|
||||
// 解密Key
|
||||
token = DesEncryptUtil.desDecrypt(token);
|
||||
systemUserOnlineDAO.logoutByToken(token);
|
||||
systemUserOnlineInfoDAO.logoutByToken(token);
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
+4
-4
@@ -38,7 +38,7 @@ public class SystemQiniuController {
|
||||
@ApiOperation("查询七牛云存储配置")
|
||||
@PostMapping(value = "/queryQiniuConfig")
|
||||
public ResponseEntity<SystemQiniuConfigTb> queryQiniuConfig() {
|
||||
return new ResponseEntity<>(qiNiuConfigService.queryQiniuConfig(), HttpStatus.OK);
|
||||
return new ResponseEntity<>(qiNiuConfigService.getLastQiniuConfig(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("配置七牛云存储")
|
||||
@@ -52,14 +52,14 @@ public class SystemQiniuController {
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
public void exportQiNiu(HttpServletResponse response, QuerySystemQiniuArgs criteria) throws IOException {
|
||||
qiniuContentService.downloadExcel(qiniuContentService.queryQiniuContentList(criteria), response);
|
||||
qiniuContentService.exportQiniuContentExcel(qiniuContentService.queryQiniuContentByArgs(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("查询文件")
|
||||
@GetMapping
|
||||
public ResponseEntity<CsResultVo<List<SystemQiniuContentTb>>> queryQiNiu(QuerySystemQiniuArgs criteria) {
|
||||
Page<SystemQiniuContentTb> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(qiniuContentService.queryQiniuContentPage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(qiniuContentService.queryQiniuContentByArgs(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("上传文件")
|
||||
@@ -84,7 +84,7 @@ public class SystemQiniuController {
|
||||
@GetMapping(value = "/createFilePreviewUrl/{id}")
|
||||
public ResponseEntity<Map<String, Object>> createFilePreviewUrl(@PathVariable Long id) {
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
map.put("url", qiniuContentService.createFilePreviewUrl(qiniuContentService.getById(id)));
|
||||
map.put("url", qiniuContentService.createFilePreviewUrl(qiniuContentService.getQiniuContentById(id)));
|
||||
return new ResponseEntity<>(map, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
+7
-8
@@ -31,7 +31,6 @@ import java.util.Set;
|
||||
@RequestMapping("/api/jobs")
|
||||
@Api(tags = "系统:定时任务管理")
|
||||
public class SystemQuartzJobController {
|
||||
private static final String ENTITY_NAME = "quartzJob";
|
||||
private final SystemQuartzJobService systemQuartzJobService;
|
||||
|
||||
@ApiOperation("查询定时任务")
|
||||
@@ -39,21 +38,21 @@ public class SystemQuartzJobController {
|
||||
@PreAuthorize("@el.check('timing:list')")
|
||||
public ResponseEntity<CsResultVo<List<SystemQuartzJobTb>>> queryQuartzJob(QuerySystemQuartzJobArgs criteria) {
|
||||
Page<SystemQuartzJobTb> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(systemQuartzJobService.queryQuartzJobPage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemQuartzJobService.queryQuartzJobByArgs(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("导出任务数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('timing:list')")
|
||||
public void exportQuartzJob(HttpServletResponse response, QuerySystemQuartzJobArgs criteria) throws IOException {
|
||||
systemQuartzJobService.downloadQuartzJobExcel(systemQuartzJobService.queryQuartzJobList(criteria), response);
|
||||
systemQuartzJobService.exportQuartzJobExcel(systemQuartzJobService.queryQuartzJobByArgs(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("导出日志数据")
|
||||
@GetMapping(value = "/logs/download")
|
||||
@PreAuthorize("@el.check('timing:list')")
|
||||
public void exportQuartzJobLog(HttpServletResponse response, QuerySystemQuartzJobArgs criteria) throws IOException {
|
||||
systemQuartzJobService.downloadQuartzLogExcel(systemQuartzJobService.queryQuartzLogList(criteria), response);
|
||||
systemQuartzJobService.exportQuartzLogExcel(systemQuartzJobService.queryQuartzLogByArgs(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("查询任务执行日志")
|
||||
@@ -61,7 +60,7 @@ public class SystemQuartzJobController {
|
||||
@PreAuthorize("@el.check('timing:list')")
|
||||
public ResponseEntity<CsResultVo<List<SystemQuartzLogTb>>> queryQuartzJobLog(QuerySystemQuartzJobArgs criteria) {
|
||||
Page<SystemQuartzLogTb> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(systemQuartzJobService.queryQuartzLogPage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemQuartzJobService.queryQuartzLogByArgs(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("新增定时任务")
|
||||
@@ -69,7 +68,7 @@ public class SystemQuartzJobController {
|
||||
@PreAuthorize("@el.check('timing:add')")
|
||||
public ResponseEntity<Void> createQuartzJob(@Validated @RequestBody SystemQuartzJobTb resources) {
|
||||
if (resources.getId() != null) {
|
||||
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
||||
throw new BadRequestException("无效参数id");
|
||||
}
|
||||
// 验证Bean是不是合法的,合法的定时任务 Bean 需要用 @Service 定义
|
||||
checkBean(resources.getBeanName());
|
||||
@@ -91,7 +90,7 @@ public class SystemQuartzJobController {
|
||||
@PostMapping(value = "/switchQuartzJobStatus/{id}")
|
||||
@PreAuthorize("@el.check('timing:edit')")
|
||||
public ResponseEntity<Void> switchQuartzJobStatus(@PathVariable Long id) {
|
||||
systemQuartzJobService.switchQuartzJobStatus(systemQuartzJobService.getById(id));
|
||||
systemQuartzJobService.switchQuartzJobStatus(systemQuartzJobService.getQuartzJobById(id));
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ public class SystemQuartzJobController {
|
||||
@PostMapping(value = "/startQuartzJob/{id}")
|
||||
@PreAuthorize("@el.check('timing:edit')")
|
||||
public ResponseEntity<Void> startQuartzJob(@PathVariable Long id) {
|
||||
systemQuartzJobService.startQuartzJob(systemQuartzJobService.getById(id));
|
||||
systemQuartzJobService.startQuartzJob(systemQuartzJobService.getQuartzJobById(id));
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -37,21 +37,21 @@ public class SystemRoleController {
|
||||
@PostMapping(value = "/queryRoleById")
|
||||
@PreAuthorize("@el.check('roles:list')")
|
||||
public ResponseEntity<SystemRoleTb> queryRoleById(@RequestBody SystemRoleTb args) {
|
||||
return new ResponseEntity<>(systemRoleService.queryRoleById(args.getId()), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemRoleService.getRoleById(args.getId()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("导出角色数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('role:list')")
|
||||
public void exportRole(HttpServletResponse response, QuerySystemRoleArgs criteria) throws IOException {
|
||||
systemRoleService.downloadRoleExcel(systemRoleService.queryRoleList(criteria), response);
|
||||
systemRoleService.exportRoleExcel(systemRoleService.queryRoleByArgs(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("返回全部的角色")
|
||||
@PostMapping(value = "/queryRoleList")
|
||||
@PostMapping(value = "/selectAllRole")
|
||||
@PreAuthorize("@el.check('roles:list','user:add','user:edit')")
|
||||
public ResponseEntity<List<SystemRoleTb>> queryRoleList() {
|
||||
return new ResponseEntity<>(systemRoleService.queryRoleList(), HttpStatus.OK);
|
||||
public ResponseEntity<List<SystemRoleTb>> selectAllRole() {
|
||||
return new ResponseEntity<>(systemRoleService.queryAllRole(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询角色")
|
||||
@@ -59,7 +59,7 @@ public class SystemRoleController {
|
||||
@PreAuthorize("@el.check('roles:list')")
|
||||
public ResponseEntity<CsResultVo<List<SystemRoleTb>>> queryRolePage(QuerySystemRoleArgs criteria) {
|
||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return new ResponseEntity<>(systemRoleService.queryRolePage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(systemRoleService.queryRoleByArgs(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("获取用户级别")
|
||||
@@ -90,7 +90,7 @@ public class SystemRoleController {
|
||||
@PostMapping(value = "/modifyBindMenuById")
|
||||
@PreAuthorize("@el.check('roles:edit')")
|
||||
public ResponseEntity<Void> modifyBindMenuById(@RequestBody SystemRoleTb resources) {
|
||||
SystemRoleTb role = systemRoleService.getById(resources.getId());
|
||||
SystemRoleTb role = systemRoleService.getRoleById(resources.getId());
|
||||
checkRoleLevels(role.getLevel());
|
||||
systemRoleService.modifyBindMenuById(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
@@ -101,7 +101,7 @@ public class SystemRoleController {
|
||||
@PreAuthorize("@el.check('roles:del')")
|
||||
public ResponseEntity<Void> removeRoleByIds(@RequestBody Set<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
SystemRoleTb role = systemRoleService.getById(id);
|
||||
SystemRoleTb role = systemRoleService.getRoleById(id);
|
||||
checkRoleLevels(role.getLevel());
|
||||
}
|
||||
// 验证是否被用户关联
|
||||
@@ -116,7 +116,7 @@ public class SystemRoleController {
|
||||
* @return /
|
||||
*/
|
||||
private int checkRoleLevels(Integer level) {
|
||||
List<Integer> levels = systemRoleService.queryRoleListByUsersId(SecurityHelper.getCurrentUserId()).stream().map(SystemRoleTb::getLevel).collect(Collectors.toList());
|
||||
List<Integer> levels = systemRoleService.queryRoleByUsersId(SecurityHelper.getCurrentUserId()).stream().map(SystemRoleTb::getLevel).collect(Collectors.toList());
|
||||
int min = Collections.min(levels);
|
||||
if (level != null) {
|
||||
if (level < min) {
|
||||
|
||||
+11
-7
@@ -7,19 +7,23 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 部门 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemDeptMapper extends BaseMapper<SystemDeptTb> {
|
||||
List<SystemDeptTb> queryDeptListByArgs(@Param("criteria") QuerySystemDeptArgs criteria);
|
||||
List<SystemDeptTb> selectDeptByArgs(@Param("criteria") QuerySystemDeptArgs criteria);
|
||||
|
||||
List<SystemDeptTb> queryDeptListByPid(@Param("pid") Long pid);
|
||||
List<SystemDeptTb> selectDeptByPid(@Param("pid") Long pid);
|
||||
|
||||
int getDeptCountByPid(@Param("pid") Long pid);
|
||||
int countDeptByPid(@Param("pid") Long pid);
|
||||
|
||||
List<SystemDeptTb> queryDeptListByPidIsNull();
|
||||
List<SystemDeptTb> selectDeptByPidIsNull();
|
||||
|
||||
Set<SystemDeptTb> queryDeptSetByRoleId(@Param("roleId") Long roleId);
|
||||
List<SystemDeptTb> selectDeptByRoleId(@Param("roleId") Long roleId);
|
||||
|
||||
void updateSubCountById(@Param("count") Integer count, @Param("id") Long id);
|
||||
void updateDeptSubCountById(@Param("count") Integer count, @Param("id") Long id);
|
||||
}
|
||||
|
||||
+5
@@ -5,6 +5,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
/**
|
||||
* 邮件配置 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemEmailConfigMapper extends BaseMapper<SystemEmailConfigTb> {
|
||||
}
|
||||
|
||||
+6
-1
@@ -8,9 +8,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 职位 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemJobMapper extends BaseMapper<SystemJobTb> {
|
||||
SystemJobTb getJobByName(@Param("name") String name);
|
||||
|
||||
IPage<SystemJobTb> queryJobPageByArgs(@Param("criteria") QuerySystemJobArgs criteria, Page<SystemJobTb> page);
|
||||
IPage<SystemJobTb> selectJobByArgs(@Param("criteria") QuerySystemJobArgs criteria, Page<SystemJobTb> page);
|
||||
}
|
||||
|
||||
+6
-1
@@ -8,7 +8,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 本地存储记录 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemLocalStorageMapper extends BaseMapper<SystemLocalStorageTb> {
|
||||
IPage<SystemLocalStorageTb> queryLocalStoragePageByArgs(@Param("criteria") QuerySystemLocalStorageArgs criteria, Page<SystemLocalStorageTb> page);
|
||||
IPage<SystemLocalStorageTb> selectLocalStorageByArgs(@Param("criteria") QuerySystemLocalStorageArgs criteria, Page<SystemLocalStorageTb> page);
|
||||
}
|
||||
|
||||
+12
-6
@@ -10,22 +10,28 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemMenuMapper extends BaseMapper<SystemMenuTb> {
|
||||
|
||||
List<SystemMenuTb> queryMenuListByArgs(@Param("criteria") QuerySystemMenuArgs criteria);
|
||||
List<SystemMenuTb> selectMenuByArgs(@Param("criteria") QuerySystemMenuArgs criteria);
|
||||
|
||||
LinkedHashSet<SystemMenuTb> queryMenuSetByRoleIdsAndType(@Param("roleIds") Set<Long> roleIds, @Param("type") Integer type);
|
||||
LinkedHashSet<SystemMenuTb> selectMenuByRoleIdsAndType(@Param("roleIds") Set<Long> roleIds, @Param("type") Integer type);
|
||||
|
||||
List<SystemMenuTb> queryMenuListByPidIsNullOrderByMenuSort();
|
||||
List<SystemMenuTb> selectMenuByPidIsNullOrderByMenuSort();
|
||||
|
||||
List<SystemMenuTb> queryMenuListByPidOrderByMenuSort(@Param("pid") Long pid);
|
||||
List<SystemMenuTb> selectMenuByPidOrderByMenuSort(@Param("pid") Long pid);
|
||||
|
||||
SystemMenuTb getMenuByTitle(@Param("title") String title);
|
||||
|
||||
SystemMenuTb getMenuByComponentName(@Param("name") String name);
|
||||
|
||||
Integer getMenuCountByPid(@Param("pid") Long pid);
|
||||
Integer countMenuByPid(@Param("pid") Long pid);
|
||||
|
||||
void updateSubCntByMenuId(@Param("count") int count, @Param("menuId") Long menuId);
|
||||
void updateMenuSubCntByMenuId(@Param("count") int count, @Param("menuId") Long menuId);
|
||||
}
|
||||
|
||||
+5
@@ -5,6 +5,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
/**
|
||||
* 七牛云配置表 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemQiniuConfigMapper extends BaseMapper<SystemQiniuConfigTb> {
|
||||
}
|
||||
|
||||
+6
-2
@@ -8,10 +8,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
||||
/**
|
||||
* 七牛云存储记录 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemQiniuContentMapper extends BaseMapper<SystemQiniuContentTb> {
|
||||
SystemQiniuContentTb getQiniuContentByName(@Param("name") String name);
|
||||
|
||||
IPage<SystemQiniuContentTb> queryQiniuContentPageByArgs(@Param("criteria") QuerySystemQiniuArgs criteria, Page<SystemQiniuContentTb> page);
|
||||
IPage<SystemQiniuContentTb> selectQiniuContentByArgs(@Param("criteria") QuerySystemQiniuArgs criteria, Page<SystemQiniuContentTb> page);
|
||||
}
|
||||
|
||||
+7
-2
@@ -10,9 +10,14 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemQuartzJobMapper extends BaseMapper<SystemQuartzJobTb> {
|
||||
IPage<SystemQuartzJobTb> queryQuartzJobPageByArgs(@Param("criteria") QuerySystemQuartzJobArgs criteria, Page<SystemQuartzJobTb> page);
|
||||
IPage<SystemQuartzJobTb> selectQuartzJobByArgs(@Param("criteria") QuerySystemQuartzJobArgs criteria, Page<SystemQuartzJobTb> page);
|
||||
|
||||
List<SystemQuartzJobTb> queryActiveQuartzJobList();
|
||||
List<SystemQuartzJobTb> selectAllEnableQuartzJob();
|
||||
}
|
||||
|
||||
+6
-1
@@ -9,7 +9,12 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
||||
/**
|
||||
* 定时任务日志 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemQuartzLogMapper extends BaseMapper<SystemQuartzLogTb> {
|
||||
IPage<SystemQuartzLogTb> queryQuartzLogPageByArgs(@Param("criteria") QuerySystemQuartzJobArgs criteria, Page<SystemQuartzLogTb> page);
|
||||
IPage<SystemQuartzLogTb> selectQuartzLogByArgs(@Param("criteria") QuerySystemQuartzJobArgs criteria, Page<SystemQuartzLogTb> page);
|
||||
}
|
||||
|
||||
+7
-4
@@ -6,11 +6,14 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 角色部门关联 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemRoleDeptMapper {
|
||||
void insertBatchWithRoleId(@Param("depts") Set<SystemDeptTb> depts, @Param("roleId") Long roleId);
|
||||
void batchInsertRoleDept(@Param("depts") Set<SystemDeptTb> depts, @Param("roleId") Long roleId);
|
||||
|
||||
void deleteByRoleId(@Param("roleId") Long roleId);
|
||||
|
||||
void deleteByRoleIds(@Param("roleIds") Set<Long> roleIds);
|
||||
void batchDeleteRoleDept(@Param("roleIds") Set<Long> roleIds);
|
||||
}
|
||||
|
||||
+11
-6
@@ -9,21 +9,26 @@ import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 角色 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemRoleMapper extends BaseMapper<SystemRoleTb> {
|
||||
List<SystemRoleTb> queryRoleList();
|
||||
List<SystemRoleTb> selectAllRole();
|
||||
|
||||
List<SystemRoleTb> queryRoleListByArgs(@Param("criteria") QuerySystemRoleArgs criteria);
|
||||
List<SystemRoleTb> selectRoleByArgs(@Param("criteria") QuerySystemRoleArgs criteria);
|
||||
|
||||
Long getRoleCountByArgs(@Param("criteria") QuerySystemRoleArgs criteria);
|
||||
Long countRoleByArgs(@Param("criteria") QuerySystemRoleArgs criteria);
|
||||
|
||||
SystemRoleTb getRoleByName(@Param("name") String name);
|
||||
|
||||
SystemRoleTb getRoleById(@Param("roleId") Long roleId);
|
||||
|
||||
List<SystemRoleTb> queryRoleListByUserId(@Param("userId") Long userId);
|
||||
List<SystemRoleTb> selectRoleByUserId(@Param("userId") Long userId);
|
||||
|
||||
int getRoleCountByDeptIds(@Param("deptIds") Set<Long> deptIds);
|
||||
Integer countRoleByDeptIds(@Param("deptIds") Set<Long> deptIds);
|
||||
|
||||
List<SystemRoleTb> queryRoleListByMenuId(@Param("menuId") Long menuId);
|
||||
List<SystemRoleTb> selectRoleByMenuId(@Param("menuId") Long menuId);
|
||||
}
|
||||
|
||||
+9
-4
@@ -7,13 +7,18 @@ import org.apache.ibatis.annotations.Param;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* 角色菜单关联 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemRoleMenuMapper {
|
||||
void insertBatchWithRoleId(@Param("menus") Set<SystemMenuTb> menus, @Param("roleId") Long roleId);
|
||||
void batchInsertRoleMenu(@Param("menus") Set<SystemMenuTb> menus, @Param("roleId") Long roleId);
|
||||
|
||||
void deleteByRoleId(@Param("roleId") Long roleId);
|
||||
void batchDeleteRoleMenu(@Param("roleIds") Set<Long> roleIds);
|
||||
|
||||
void deleteByRoleIds(@Param("roleIds") Set<Long> roleIds);
|
||||
void deleteRoleMenuByRoleId(@Param("roleId") Long roleId);
|
||||
|
||||
void deleteByMenuId(@Param("menuId") Long menuId);
|
||||
void deleteRoleMenuByMenuId(@Param("menuId") Long menuId);
|
||||
}
|
||||
|
||||
+7
-4
@@ -6,11 +6,14 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户职位关联 Mapper
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemUserJobMapper {
|
||||
void insertBatchWithUserId(@Param("jobs") Set<SystemJobTb> jobs, @Param("userId") Long userId);
|
||||
void batchInsertUserJob(@Param("jobs") Set<SystemJobTb> jobs, @Param("userId") Long userId);
|
||||
|
||||
void deleteByUserId(@Param("userId") Long userId);
|
||||
|
||||
void deleteByUserIds(@Param("userIds") Set<Long> userIds);
|
||||
void batchDeleteUserJob(@Param("userIds") Set<Long> userIds);
|
||||
}
|
||||
|
||||
+12
-14
@@ -8,16 +8,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Mapper
|
||||
public interface SystemUserMapper extends BaseMapper<SystemUserTb> {
|
||||
|
||||
Long getUserCountByArgs(@Param("criteria") QuerySystemUserArgs criteria);
|
||||
|
||||
IPage<SystemUserTb> queryUserPageByArgs(@Param("criteria") QuerySystemUserArgs criteria, Page<SystemUserTb> page);
|
||||
IPage<SystemUserTb> selectUserByArgs(@Param("criteria") QuerySystemUserArgs criteria, Page<SystemUserTb> page);
|
||||
|
||||
SystemUserTb getUserByUsername(@Param("username") String username);
|
||||
|
||||
@@ -25,21 +21,23 @@ public interface SystemUserMapper extends BaseMapper<SystemUserTb> {
|
||||
|
||||
SystemUserTb getUserByPhone(@Param("phone") String phone);
|
||||
|
||||
void updatePasswordByUsername(@Param("username") String username, @Param("password") String password, @Param("lastPasswordResetTime") Date lastPasswordResetTime);
|
||||
List<SystemUserTb> selectUserByRoleId(@Param("roleId") Long roleId);
|
||||
|
||||
void updateEmailByUsername(@Param("username") String username, @Param("email") String email);
|
||||
List<SystemUserTb> selectUserByDeptId(@Param("deptId") Long deptId);
|
||||
|
||||
List<SystemUserTb> queryUserListByRoleId(@Param("roleId") Long roleId);
|
||||
List<SystemUserTb> selectUserByMenuId(@Param("menuId") Long menuId);
|
||||
|
||||
List<SystemUserTb> queryUserListByDeptId(@Param("deptId") Long deptId);
|
||||
Long countUserByJobIds(@Param("jobIds") Set<Long> jobIds);
|
||||
|
||||
List<SystemUserTb> queryUserListByMenuId(@Param("menuId") Long menuId);
|
||||
Long countUserByDeptIds(@Param("deptIds") Set<Long> deptIds);
|
||||
|
||||
int getUserCountByJobIds(@Param("jobIds") Set<Long> jobIds);
|
||||
Long countUserByRoleIds(@Param("roleIds") Set<Long> roleIds);
|
||||
|
||||
int getUserCountByDeptIds(@Param("deptIds") Set<Long> deptIds);
|
||||
Long countUserByArgs(@Param("criteria") QuerySystemUserArgs criteria);
|
||||
|
||||
int getUserCountByRoleIds(@Param("roleIds") Set<Long> roleIds);
|
||||
void updateUserPasswordByUsername(@Param("username") String username, @Param("password") String password);
|
||||
|
||||
void updatePasswordByUserIds(@Param("pwd") String password, @Param("userIds") Set<Long> userIds);
|
||||
void updateUserEmailByUsername(@Param("username") String username, @Param("email") String email);
|
||||
|
||||
void batchUpdatePassword(@Param("pwd") String password, @Param("userIds") Set<Long> userIds);
|
||||
}
|
||||
|
||||
+2
-4
@@ -8,9 +8,7 @@ import java.util.Set;
|
||||
|
||||
@Mapper
|
||||
public interface SystemUserRoleMapper {
|
||||
void insertBatchWithUserId(@Param("roles") Set<SystemRoleTb> roles, @Param("userId") Long userId);
|
||||
void batchInsertUserRole(@Param("roles") Set<SystemRoleTb> roles, @Param("userId") Long userId);
|
||||
|
||||
void deleteByUserId(@Param("userId") Long userId);
|
||||
|
||||
void deleteByUserIds(@Param("userIds") Set<Long> userIds);
|
||||
void batchDeleteUserRole(@Param("userIds") Set<Long> userIds);
|
||||
}
|
||||
|
||||
+7
-16
@@ -4,18 +4,17 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.odboy.core.dal.model.system.SystemUserJwtVo;
|
||||
import cn.odboy.redis.RedisHelper;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 用户缓存管理
|
||||
*/
|
||||
@Component
|
||||
public class SystemUserJwtDAO {
|
||||
@Resource
|
||||
private RedisHelper redisHelper;
|
||||
@RequiredArgsConstructor
|
||||
public class SystemUserInfoDAO {
|
||||
private final RedisHelper redisHelper;
|
||||
|
||||
/**
|
||||
* 添加缓存到Redis
|
||||
@@ -23,10 +22,7 @@ public class SystemUserJwtDAO {
|
||||
* @param userName 用户名
|
||||
*/
|
||||
@Async
|
||||
|
||||
public void saveUserJwtModelByUserName(String userName, SystemUserJwtVo user) {
|
||||
// 转小写
|
||||
userName = StringUtil.lowerCase(userName);
|
||||
public void saveUserLoginInfoByUserName(String userName, SystemUserJwtVo user) {
|
||||
if (StringUtil.isNotEmpty(userName)) {
|
||||
// 添加数据, 避免数据同时过期(2小时左右)
|
||||
long time = 7200 + RandomUtil.randomInt(900, 1800);
|
||||
@@ -41,10 +37,7 @@ public class SystemUserJwtDAO {
|
||||
* @param userName 用户名
|
||||
*/
|
||||
@Async
|
||||
|
||||
public void cleanUserJwtModelCacheByUsername(String userName) {
|
||||
// 转小写
|
||||
userName = StringUtil.lowerCase(userName);
|
||||
public void deleteUserLoginInfoByUserName(String userName) {
|
||||
if (StringUtil.isNotEmpty(userName)) {
|
||||
// 清除数据
|
||||
redisHelper.del(SystemRedisKey.USER_INFO + userName);
|
||||
@@ -58,9 +51,7 @@ public class SystemUserJwtDAO {
|
||||
* @return UserJwtVo
|
||||
*/
|
||||
|
||||
public SystemUserJwtVo queryUserJwtModelByUsername(String username) {
|
||||
// 转小写
|
||||
username = StringUtil.lowerCase(username);
|
||||
public SystemUserJwtVo getUserLoginInfoByUserName(String username) {
|
||||
if (StringUtil.isNotEmpty(username)) {
|
||||
// 获取数据
|
||||
return redisHelper.get(SystemRedisKey.USER_INFO + username, SystemUserJwtVo.class);
|
||||
+5
-5
@@ -10,7 +10,7 @@ import cn.odboy.util.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -19,9 +19,9 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class SystemUserOnlineDAO {
|
||||
public class SystemUserOnlineInfoDAO {
|
||||
private final AppProperties properties;
|
||||
private final TokenProvider tokenProvider;
|
||||
private final RedisHelper redisHelper;
|
||||
@@ -114,8 +114,8 @@ public class SystemUserOnlineDAO {
|
||||
|
||||
public CsResultVo<List<SystemUserOnlineVo>> queryUserOnlineModelPage(String username, Pageable pageable) {
|
||||
List<SystemUserOnlineVo> onlineUserList = queryUserOnlineModelListByUsername(username);
|
||||
List<SystemUserOnlineVo> paging = PageUtil.softPaging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserList);
|
||||
return PageUtil.toPage(paging, onlineUserList.size());
|
||||
List<SystemUserOnlineVo> paging = CsPageUtil.softPaging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserList);
|
||||
return CsPageUtil.toPage(paging, onlineUserList.size());
|
||||
}
|
||||
|
||||
/**
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package cn.odboy.core.framework.permission.config;
|
||||
|
||||
import cn.odboy.constant.RequestMethodEnum;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineInfoDAO;
|
||||
import cn.odboy.core.framework.permission.core.handler.JwtAccessDeniedHandler;
|
||||
import cn.odboy.core.framework.permission.core.handler.JwtAuthenticationEntryPoint;
|
||||
import cn.odboy.core.framework.permission.core.handler.TokenProvider;
|
||||
@@ -34,7 +34,7 @@ public class SpringSecurityConfig {
|
||||
private final JwtAuthenticationEntryPoint authenticationErrorHandler;
|
||||
private final JwtAccessDeniedHandler jwtAccessDeniedHandler;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final SystemUserOnlineDAO systemUserOnlineDAO;
|
||||
private final SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
|
||||
|
||||
@Bean
|
||||
public GrantedAuthorityDefaults grantedAuthorityDefaults() {
|
||||
@@ -112,6 +112,6 @@ public class SpringSecurityConfig {
|
||||
}
|
||||
|
||||
private TokenConfigurer securityConfigurerAdapter() {
|
||||
return new TokenConfigurer(tokenProvider, systemUserOnlineDAO);
|
||||
return new TokenConfigurer(tokenProvider, systemUserOnlineInfoDAO);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package cn.odboy.core.framework.permission.config;
|
||||
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineInfoDAO;
|
||||
import cn.odboy.core.framework.permission.core.handler.TokenFilter;
|
||||
import cn.odboy.core.framework.permission.core.handler.TokenProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -12,11 +12,11 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
||||
@RequiredArgsConstructor
|
||||
public class TokenConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
private final TokenProvider tokenProvider;
|
||||
private final SystemUserOnlineDAO systemUserOnlineDAO;
|
||||
private final SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) {
|
||||
TokenFilter customFilter = new TokenFilter(tokenProvider, systemUserOnlineDAO);
|
||||
TokenFilter customFilter = new TokenFilter(tokenProvider, systemUserOnlineInfoDAO);
|
||||
http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -3,7 +3,7 @@ package cn.odboy.core.framework.permission.core.handler;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.core.dal.model.system.SystemUserOnlineVo;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineInfoDAO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -20,14 +20,14 @@ import java.io.IOException;
|
||||
@Slf4j
|
||||
public class TokenFilter extends GenericFilterBean {
|
||||
private final TokenProvider tokenProvider;
|
||||
private final SystemUserOnlineDAO systemUserOnlineDAO;
|
||||
private final SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
|
||||
|
||||
/**
|
||||
* @param tokenProvider Token
|
||||
* @param systemUserOnlineDAO 用户在线
|
||||
* @param tokenProvider Token
|
||||
* @param systemUserOnlineInfoDAO 用户在线
|
||||
*/
|
||||
public TokenFilter(TokenProvider tokenProvider, SystemUserOnlineDAO systemUserOnlineDAO) {
|
||||
this.systemUserOnlineDAO = systemUserOnlineDAO;
|
||||
public TokenFilter(TokenProvider tokenProvider, SystemUserOnlineInfoDAO systemUserOnlineInfoDAO) {
|
||||
this.systemUserOnlineInfoDAO = systemUserOnlineInfoDAO;
|
||||
this.tokenProvider = tokenProvider;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TokenFilter extends GenericFilterBean {
|
||||
if (StrUtil.isNotBlank(token)) {
|
||||
// 获取用户Token的Key
|
||||
String loginKey = tokenProvider.loginKey(token);
|
||||
SystemUserOnlineVo userOnlineVo = systemUserOnlineDAO.queryUserOnlineModelByKey(loginKey);
|
||||
SystemUserOnlineVo userOnlineVo = systemUserOnlineInfoDAO.queryUserOnlineModelByKey(loginKey);
|
||||
// 判断用户在线信息是否为空
|
||||
if (userOnlineVo != null) {
|
||||
// Token 续期判断
|
||||
|
||||
+6
-6
@@ -3,7 +3,7 @@ package cn.odboy.core.framework.permission.core.handler;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemUserTb;
|
||||
import cn.odboy.core.dal.model.system.SystemRoleCodeVo;
|
||||
import cn.odboy.core.dal.model.system.SystemUserJwtVo;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserJwtDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserInfoDAO;
|
||||
import cn.odboy.core.service.system.SystemDataService;
|
||||
import cn.odboy.core.service.system.SystemRoleService;
|
||||
import cn.odboy.core.service.system.SystemUserService;
|
||||
@@ -22,25 +22,25 @@ public class UserDetailsHandler implements UserDetailsService {
|
||||
private final SystemRoleService systemRoleService;
|
||||
private final SystemUserService systemUserService;
|
||||
private final SystemDataService systemDataService;
|
||||
private final SystemUserJwtDAO systemUserJwtDAO;
|
||||
private final SystemUserInfoDAO systemUserInfoDAO;
|
||||
|
||||
@Override
|
||||
public SystemUserJwtVo loadUserByUsername(String username) {
|
||||
SystemUserJwtVo userJwtVo = systemUserJwtDAO.queryUserJwtModelByUsername(username);
|
||||
SystemUserJwtVo userJwtVo = systemUserInfoDAO.getUserLoginInfoByUserName(username);
|
||||
if (userJwtVo == null) {
|
||||
SystemUserTb user = systemUserService.queryUserByUsername(username);
|
||||
SystemUserTb user = systemUserService.getUserByUsername(username);
|
||||
if (user == null) {
|
||||
throw new BadRequestException("用户不存在");
|
||||
} else {
|
||||
if (!user.getEnabled()) {
|
||||
throw new BadRequestException("账号未激活!");
|
||||
throw new BadRequestException("账号未激活");
|
||||
}
|
||||
// 获取用户的权限
|
||||
List<SystemRoleCodeVo> authorities = systemRoleService.buildUserRolePermissions(user);
|
||||
// 初始化JwtUserDto
|
||||
userJwtVo = new SystemUserJwtVo(user, systemDataService.queryDeptIdListByArgs(user), authorities);
|
||||
// 添加缓存数据
|
||||
systemUserJwtDAO.saveUserJwtModelByUserName(username, userJwtVo);
|
||||
systemUserInfoDAO.saveUserLoginInfoByUserName(username, userJwtVo);
|
||||
}
|
||||
}
|
||||
return userJwtVo;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public class InitialActiveJobApplicationRunner implements ApplicationRunner {
|
||||
*/
|
||||
@Override
|
||||
public void run(ApplicationArguments applicationArguments) {
|
||||
List<SystemQuartzJobTb> quartzJobs = quartzJobMapper.queryActiveQuartzJobList();
|
||||
List<SystemQuartzJobTb> quartzJobs = quartzJobMapper.selectAllEnableQuartzJob();
|
||||
quartzJobs.forEach(quartzManage::addJob);
|
||||
log.info("Timing task injection complete");
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,6 +1,7 @@
|
||||
package cn.odboy.core.framework.templatefile;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.template.Template;
|
||||
import cn.hutool.extra.template.TemplateConfig;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
@@ -13,8 +14,9 @@ import cn.hutool.extra.template.TemplateUtil;
|
||||
* @date 2025-06-22
|
||||
*/
|
||||
public class CsResourceTemplateUtil {
|
||||
public static String render(String filename, Dict params) {
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
public static String render(String moduleName, String filename, Dict params) {
|
||||
String path = StrUtil.isBlank(moduleName) ? "template" : "template/" + moduleName;
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig(path, TemplateConfig.ResourceMode.CLASSPATH));
|
||||
Template template = engine.getTemplate(filename);
|
||||
return template.render(params);
|
||||
}
|
||||
|
||||
+56
-4
@@ -1,14 +1,28 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.core.constant.system.SystemDataScopeEnum;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDeptTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemUserTb;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据权限服务类
|
||||
* 数据权限 Service
|
||||
*
|
||||
* @author odboy
|
||||
*/
|
||||
public interface SystemDataService {
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemDataService {
|
||||
private final SystemRoleService systemRoleService;
|
||||
private final SystemDeptService systemDeptService;
|
||||
|
||||
/**
|
||||
* 获取数据权限
|
||||
@@ -16,5 +30,43 @@ public interface SystemDataService {
|
||||
* @param user /
|
||||
* @return /
|
||||
*/
|
||||
List<Long> queryDeptIdListByArgs(SystemUserTb user);
|
||||
public List<Long> queryDeptIdListByArgs(SystemUserTb user) {
|
||||
List<Long> deptIds = new ArrayList<>();
|
||||
// 查询用户角色
|
||||
List<SystemRoleTb> roleList = systemRoleService.queryRoleByUsersId(user.getId());
|
||||
// 获取对应的部门ID
|
||||
for (SystemRoleTb role : roleList) {
|
||||
SystemDataScopeEnum dataScopeEnum = SystemDataScopeEnum.find(role.getDataScope());
|
||||
switch (Objects.requireNonNull(dataScopeEnum)) {
|
||||
case THIS_LEVEL:
|
||||
deptIds.add(user.getDept().getId());
|
||||
break;
|
||||
case CUSTOMIZE:
|
||||
deptIds.addAll(queryCustomDataPermissionList(deptIds, role));
|
||||
break;
|
||||
default:
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
return deptIds.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义的数据权限
|
||||
*
|
||||
* @param deptIds 部门ID
|
||||
* @param role 角色
|
||||
* @return 数据权限ID
|
||||
*/
|
||||
private List<Long> queryCustomDataPermissionList(List<Long> deptIds, SystemRoleTb role) {
|
||||
List<SystemDeptTb> deptList = systemDeptService.queryDeptByRoleId(role.getId());
|
||||
for (SystemDeptTb dept : deptList) {
|
||||
deptIds.add(dept.getId());
|
||||
List<SystemDeptTb> deptChildren = systemDeptService.queryDeptByPid(dept.getId());
|
||||
if (CollUtil.isNotEmpty(deptChildren)) {
|
||||
deptIds.addAll(systemDeptService.queryChildDeptIdListByDeptIds(deptChildren));
|
||||
}
|
||||
}
|
||||
return deptIds;
|
||||
}
|
||||
}
|
||||
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.core.constant.system.SystemDataScopeEnum;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDeptTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemUserTb;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 数据权限服务实现
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemDataServiceImpl implements SystemDataService {
|
||||
private final SystemRoleService systemRoleService;
|
||||
private final SystemDeptService systemDeptService;
|
||||
|
||||
/**
|
||||
* 用户角色和用户部门改变时需清理缓存
|
||||
*
|
||||
* @param user /
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public List<Long> queryDeptIdListByArgs(SystemUserTb user) {
|
||||
Set<Long> deptIds = new HashSet<>();
|
||||
// 查询用户角色
|
||||
List<SystemRoleTb> roleList = systemRoleService.queryRoleListByUsersId(user.getId());
|
||||
// 获取对应的部门ID
|
||||
for (SystemRoleTb role : roleList) {
|
||||
SystemDataScopeEnum dataScopeEnum = SystemDataScopeEnum.find(role.getDataScope());
|
||||
switch (Objects.requireNonNull(dataScopeEnum)) {
|
||||
case THIS_LEVEL:
|
||||
deptIds.add(user.getDept().getId());
|
||||
break;
|
||||
case CUSTOMIZE:
|
||||
deptIds.addAll(queryCustomDataPermissionList(deptIds, role));
|
||||
break;
|
||||
default:
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(deptIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义的数据权限
|
||||
*
|
||||
* @param deptIds 部门ID
|
||||
* @param role 角色
|
||||
* @return 数据权限ID
|
||||
*/
|
||||
public Set<Long> queryCustomDataPermissionList(Set<Long> deptIds, SystemRoleTb role) {
|
||||
Set<SystemDeptTb> deptList = systemDeptService.queryDeptByRoleId(role.getId());
|
||||
for (SystemDeptTb dept : deptList) {
|
||||
deptIds.add(dept.getId());
|
||||
List<SystemDeptTb> deptChildren = systemDeptService.queryDeptListByPid(dept.getId());
|
||||
if (CollUtil.isNotEmpty(deptChildren)) {
|
||||
deptIds.addAll(systemDeptService.queryChildDeptIdListByDeptIds(deptChildren));
|
||||
}
|
||||
}
|
||||
return deptIds;
|
||||
}
|
||||
}
|
||||
+254
-37
@@ -1,47 +1,136 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.constant.system.SystemDataScopeEnum;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDeptTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemDeptArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemDeptArgs;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDeptMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.core.framework.permission.core.SecurityHelper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.ClassUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface SystemDeptService extends IService<SystemDeptTb> {
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor_ = @Lazy)
|
||||
public class SystemDeptService {
|
||||
private final SystemDeptMapper systemDeptMapper;
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
private final SystemRoleMapper systemRoleMapper;
|
||||
private final SystemDeptService systemDeptService;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void saveDept(CreateSystemDeptArgs resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDept(CreateSystemDeptArgs resources) {
|
||||
systemDeptMapper.insert(BeanUtil.copyProperties(resources, SystemDeptTb.class));
|
||||
systemDeptService.updateDeptSubCnt(resources.getPid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyDept(SystemDeptTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyDept(SystemDeptTb resources) {
|
||||
// 旧的部门
|
||||
Long oldPid = queryDeptById(resources.getId()).getPid();
|
||||
Long newPid = resources.getPid();
|
||||
if (resources.getPid() != null && resources.getId().equals(resources.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
SystemDeptTb dept = systemDeptMapper.selectById(resources.getId());
|
||||
resources.setId(dept.getId());
|
||||
systemDeptMapper.insertOrUpdate(resources);
|
||||
systemDeptService.updateDeptSubCnt(oldPid);
|
||||
systemDeptService.updateDeptSubCnt(newPid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param depts /
|
||||
* @param deptSet /
|
||||
*/
|
||||
void removeDeptByIds(Set<SystemDeptTb> depts);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeDeptByIds(Set<SystemDeptTb> deptSet) {
|
||||
for (SystemDeptTb dept : deptSet) {
|
||||
systemDeptMapper.deleteById(dept.getId());
|
||||
systemDeptService.updateDeptSubCnt(dept.getPid());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param depts 待导出的数据
|
||||
* @param deptList 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadDeptExcel(List<SystemDeptTb> depts, HttpServletResponse response) throws IOException;
|
||||
public void exportDeptExcel(List<SystemDeptTb> deptList, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemDeptTb dept : deptList) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("部门名称", dept.getName());
|
||||
map.put("部门状态", dept.getEnabled() ? "启用" : "停用");
|
||||
map.put("创建日期", dept.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新父节点中子节点数目
|
||||
*
|
||||
* @param deptId /
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDeptSubCnt(Long deptId) {
|
||||
if (deptId != null) {
|
||||
int count = systemDeptMapper.countDeptByPid(deptId);
|
||||
systemDeptMapper.updateDeptSubCountById(count, deptId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选出 list 中没有父部门(即 pid 不在其他部门 id 列表中的部门)的部门列表
|
||||
*/
|
||||
private List<SystemDeptTb> deduplication(List<SystemDeptTb> list) {
|
||||
List<SystemDeptTb> deptList = new ArrayList<>();
|
||||
// 使用 Set 存储所有部门的 id
|
||||
Set<Long> idSet = list.stream().map(SystemDeptTb::getId).collect(Collectors.toSet());
|
||||
// 遍历部门列表,筛选出没有父部门的部门
|
||||
for (SystemDeptTb dept : list) {
|
||||
if (!idSet.contains(dept.getPid())) {
|
||||
deptList.add(dept);
|
||||
}
|
||||
}
|
||||
return deptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
@@ -51,7 +140,40 @@ public interface SystemDeptService extends IService<SystemDeptTb> {
|
||||
* @return /
|
||||
* @throws Exception /
|
||||
*/
|
||||
List<SystemDeptTb> queryDeptList(QuerySystemDeptArgs criteria, Boolean isQuery) throws Exception;
|
||||
|
||||
public List<SystemDeptTb> queryAllDept(QuerySystemDeptArgs criteria, Boolean isQuery) throws Exception {
|
||||
String dataScopeType = SecurityHelper.getDataScopeType();
|
||||
if (isQuery) {
|
||||
if (dataScopeType.equals(SystemDataScopeEnum.ALL.getValue())) {
|
||||
criteria.setPidIsNull(true);
|
||||
}
|
||||
List<Field> fields = ClassUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
||||
List<String> fieldNames = new ArrayList<>() {{
|
||||
add("pidIsNull");
|
||||
add("enabled");
|
||||
}};
|
||||
for (Field field : fields) {
|
||||
// 设置对象的访问权限,保证对private的属性的访问
|
||||
field.setAccessible(true);
|
||||
Object val = field.get(criteria);
|
||||
if (fieldNames.contains(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(val)) {
|
||||
criteria.setPidIsNull(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 数据权限
|
||||
criteria.setIds(SecurityHelper.getCurrentUserDataScope());
|
||||
List<SystemDeptTb> list = systemDeptMapper.selectDeptByArgs(criteria);
|
||||
// 如果为空,就代表为自定义权限或者本级权限,就需要去重,不理解可以注释掉,看查询结果
|
||||
if (StringUtil.isBlank(dataScopeType)) {
|
||||
return deduplication(list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
@@ -59,7 +181,10 @@ public interface SystemDeptService extends IService<SystemDeptTb> {
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
SystemDeptTb queryDeptById(Long id);
|
||||
|
||||
public SystemDeptTb queryDeptById(Long id) {
|
||||
return systemDeptMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据PID查询
|
||||
@@ -67,7 +192,10 @@ public interface SystemDeptService extends IService<SystemDeptTb> {
|
||||
* @param pid /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemDeptTb> queryDeptListByPid(long pid);
|
||||
|
||||
public List<SystemDeptTb> queryDeptByPid(long pid) {
|
||||
return systemDeptMapper.selectDeptByPid(pid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询
|
||||
@@ -75,33 +203,29 @@ public interface SystemDeptService extends IService<SystemDeptTb> {
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
Set<SystemDeptTb> queryDeptByRoleId(Long id);
|
||||
|
||||
public List<SystemDeptTb> queryDeptByRoleId(Long id) {
|
||||
return systemDeptMapper.selectDeptByRoleId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门下所有关联的部门
|
||||
*
|
||||
* @param deptList /
|
||||
* @param depts /
|
||||
* @param deptTbList /
|
||||
* @param depts /
|
||||
* @return /
|
||||
*/
|
||||
Set<SystemDeptTb> queryRelationDeptSet(List<SystemDeptTb> deptList, Set<SystemDeptTb> depts);
|
||||
|
||||
/**
|
||||
* 根据ID获取同级与上级数据
|
||||
*
|
||||
* @param dept /
|
||||
* @param depts /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemDeptTb> querySuperiorDeptListByPid(SystemDeptTb dept, List<SystemDeptTb> depts);
|
||||
|
||||
/**
|
||||
* 构建树形数据
|
||||
*
|
||||
* @param depts /
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<Set<SystemDeptTb>> buildDeptTree(List<SystemDeptTb> depts);
|
||||
public Set<SystemDeptTb> queryRelationDeptSet(List<SystemDeptTb> deptTbList, Set<SystemDeptTb> depts) {
|
||||
for (SystemDeptTb dept : deptTbList) {
|
||||
depts.add(dept);
|
||||
List<SystemDeptTb> deptList = systemDeptMapper.selectDeptByPid(dept.getId());
|
||||
if (CollUtil.isNotEmpty(deptList)) {
|
||||
queryRelationDeptSet(deptList, depts);
|
||||
}
|
||||
}
|
||||
return depts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取
|
||||
@@ -109,19 +233,112 @@ public interface SystemDeptService extends IService<SystemDeptTb> {
|
||||
* @param deptList 、
|
||||
* @return 、
|
||||
*/
|
||||
List<Long> queryChildDeptIdListByDeptIds(List<SystemDeptTb> deptList);
|
||||
|
||||
public List<Long> queryChildDeptIdListByDeptIds(List<SystemDeptTb> deptList) {
|
||||
List<Long> list = new ArrayList<>();
|
||||
for (SystemDeptTb systemDeptTb : deptList) {
|
||||
if (systemDeptTb != null && systemDeptTb.getEnabled()) {
|
||||
List<SystemDeptTb> deptList1 = systemDeptMapper.selectDeptByPid(systemDeptTb.getId());
|
||||
if (CollUtil.isNotEmpty(deptList1)) {
|
||||
list.addAll(queryChildDeptIdListByDeptIds(deptList1));
|
||||
}
|
||||
list.add(systemDeptTb.getId());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取同级与上级数据
|
||||
*
|
||||
* @param dept /
|
||||
* @param deptList /
|
||||
* @return /
|
||||
*/
|
||||
|
||||
public List<SystemDeptTb> querySuperiorDeptListByPid(SystemDeptTb dept, List<SystemDeptTb> deptList) {
|
||||
if (dept.getPid() == null) {
|
||||
deptList.addAll(systemDeptMapper.selectDeptByPidIsNull());
|
||||
return deptList;
|
||||
}
|
||||
deptList.addAll(systemDeptMapper.selectDeptByPid(dept.getPid()));
|
||||
return querySuperiorDeptListByPid(queryDeptById(dept.getPid()), deptList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建树形数据
|
||||
*
|
||||
* @param deptList /
|
||||
* @return /
|
||||
*/
|
||||
|
||||
public CsResultVo<Set<SystemDeptTb>> buildDeptTree(List<SystemDeptTb> deptList) {
|
||||
Set<SystemDeptTb> trees = new LinkedHashSet<>();
|
||||
Set<SystemDeptTb> deptSet = new LinkedHashSet<>();
|
||||
List<String> deptNames = deptList.stream().map(SystemDeptTb::getName).collect(Collectors.toList());
|
||||
boolean isChild;
|
||||
for (SystemDeptTb dept : deptList) {
|
||||
isChild = false;
|
||||
if (dept.getPid() == null) {
|
||||
trees.add(dept);
|
||||
}
|
||||
for (SystemDeptTb it : deptList) {
|
||||
if (it.getPid() != null && dept.getId().equals(it.getPid())) {
|
||||
isChild = true;
|
||||
if (dept.getChildren() == null) {
|
||||
dept.setChildren(new ArrayList<>());
|
||||
}
|
||||
dept.getChildren().add(it);
|
||||
}
|
||||
}
|
||||
if (isChild) {
|
||||
deptSet.add(dept);
|
||||
} else if (dept.getPid() != null && !deptNames.contains(queryDeptById(dept.getPid()).getName())) {
|
||||
deptSet.add(dept);
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isEmpty(trees)) {
|
||||
trees = deptSet;
|
||||
}
|
||||
CsResultVo<Set<SystemDeptTb>> baseResult = new CsResultVo<>();
|
||||
baseResult.setContent(CollectionUtil.isEmpty(trees) ? deptSet : trees);
|
||||
baseResult.setTotalElements(deptSet.size());
|
||||
return baseResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否被角色或用户关联
|
||||
*
|
||||
* @param depts /
|
||||
* @param deptSet /
|
||||
*/
|
||||
void verifyBindRelationByIds(Set<SystemDeptTb> depts);
|
||||
|
||||
public void verifyBindRelationByIds(Set<SystemDeptTb> deptSet) {
|
||||
Set<Long> deptIds = deptSet.stream().map(SystemDeptTb::getId).collect(Collectors.toSet());
|
||||
if (systemUserMapper.countUserByDeptIds(deptIds) > 0) {
|
||||
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
|
||||
}
|
||||
if (systemRoleMapper.countRoleByDeptIds(deptIds) > 0) {
|
||||
throw new BadRequestException("所选部门存在角色关联,请解除后再试!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历所有部门和子部门
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
Set<SystemDeptTb> traverseDeptByIdWithPids(Set<Long> ids);
|
||||
|
||||
public Set<SystemDeptTb> traverseDeptByIdWithPids(Set<Long> ids) {
|
||||
Set<SystemDeptTb> depts = new HashSet<>();
|
||||
for (Long id : ids) {
|
||||
// 根部门
|
||||
depts.add(queryDeptById(id));
|
||||
// 子部门
|
||||
List<SystemDeptTb> deptList = queryDeptByPid(id);
|
||||
if (CollectionUtil.isNotEmpty(deptList)) {
|
||||
depts = queryRelationDeptSet(deptList, depts);
|
||||
}
|
||||
}
|
||||
return depts;
|
||||
}
|
||||
}
|
||||
|
||||
-257
@@ -1,257 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.constant.system.SystemDataScopeEnum;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDeptTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemDeptArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemDeptArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDeptMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.core.framework.permission.core.SecurityHelper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.ClassUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemDeptServiceImpl extends ServiceImpl<SystemDeptMapper, SystemDeptTb> implements SystemDeptService {
|
||||
private final SystemDeptMapper systemDeptMapper;
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
private final SystemRoleMapper systemRoleMapper;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDept(CreateSystemDeptArgs resources) {
|
||||
save(BeanUtil.copyProperties(resources, SystemDeptTb.class));
|
||||
// 清理缓存
|
||||
updateSubCnt(resources.getPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyDept(SystemDeptTb resources) {
|
||||
// 旧的部门
|
||||
Long oldPid = queryDeptById(resources.getId()).getPid();
|
||||
Long newPid = resources.getPid();
|
||||
if (resources.getPid() != null && resources.getId().equals(resources.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
SystemDeptTb dept = getById(resources.getId());
|
||||
resources.setId(dept.getId());
|
||||
saveOrUpdate(resources);
|
||||
// 更新父节点中子节点数目
|
||||
updateSubCnt(oldPid);
|
||||
updateSubCnt(newPid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeDeptByIds(Set<SystemDeptTb> deptSet) {
|
||||
for (SystemDeptTb dept : deptSet) {
|
||||
systemDeptMapper.deleteById(dept.getId());
|
||||
updateSubCnt(dept.getPid());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadDeptExcel(List<SystemDeptTb> deptList, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemDeptTb dept : deptList) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("部门名称", dept.getName());
|
||||
map.put("部门状态", dept.getEnabled() ? "启用" : "停用");
|
||||
map.put("创建日期", dept.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
|
||||
private void updateSubCnt(Long deptId) {
|
||||
if (deptId != null) {
|
||||
int count = systemDeptMapper.getDeptCountByPid(deptId);
|
||||
systemDeptMapper.updateSubCountById(count, deptId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选出 list 中没有父部门(即 pid 不在其他部门 id 列表中的部门)的部门列表
|
||||
*/
|
||||
private List<SystemDeptTb> deduplication(List<SystemDeptTb> list) {
|
||||
List<SystemDeptTb> deptList = new ArrayList<>();
|
||||
// 使用 Set 存储所有部门的 id
|
||||
Set<Long> idSet = list.stream().map(SystemDeptTb::getId).collect(Collectors.toSet());
|
||||
// 遍历部门列表,筛选出没有父部门的部门
|
||||
for (SystemDeptTb dept : list) {
|
||||
if (!idSet.contains(dept.getPid())) {
|
||||
deptList.add(dept);
|
||||
}
|
||||
}
|
||||
return deptList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemDeptTb> queryDeptList(QuerySystemDeptArgs criteria, Boolean isQuery) throws Exception {
|
||||
String dataScopeType = SecurityHelper.getDataScopeType();
|
||||
if (isQuery) {
|
||||
if (dataScopeType.equals(SystemDataScopeEnum.ALL.getValue())) {
|
||||
criteria.setPidIsNull(true);
|
||||
}
|
||||
List<Field> fields = ClassUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
||||
List<String> fieldNames = new ArrayList<>() {{
|
||||
add("pidIsNull");
|
||||
add("enabled");
|
||||
}};
|
||||
for (Field field : fields) {
|
||||
// 设置对象的访问权限,保证对private的属性的访问
|
||||
field.setAccessible(true);
|
||||
Object val = field.get(criteria);
|
||||
if (fieldNames.contains(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(val)) {
|
||||
criteria.setPidIsNull(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 数据权限
|
||||
criteria.setIds(SecurityHelper.getCurrentUserDataScope());
|
||||
List<SystemDeptTb> list = systemDeptMapper.queryDeptListByArgs(criteria);
|
||||
// 如果为空,就代表为自定义权限或者本级权限,就需要去重,不理解可以注释掉,看查询结果
|
||||
if (StringUtil.isBlank(dataScopeType)) {
|
||||
return deduplication(list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemDeptTb queryDeptById(Long id) {
|
||||
return systemDeptMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemDeptTb> queryDeptListByPid(long pid) {
|
||||
return systemDeptMapper.queryDeptListByPid(pid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SystemDeptTb> queryDeptByRoleId(Long id) {
|
||||
return systemDeptMapper.queryDeptSetByRoleId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SystemDeptTb> queryRelationDeptSet(List<SystemDeptTb> menuList, Set<SystemDeptTb> deptSet) {
|
||||
for (SystemDeptTb dept : menuList) {
|
||||
deptSet.add(dept);
|
||||
List<SystemDeptTb> deptList = systemDeptMapper.queryDeptListByPid(dept.getId());
|
||||
if (CollUtil.isNotEmpty(deptList)) {
|
||||
queryRelationDeptSet(deptList, deptSet);
|
||||
}
|
||||
}
|
||||
return deptSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> queryChildDeptIdListByDeptIds(List<SystemDeptTb> deptList) {
|
||||
List<Long> list = new ArrayList<>();
|
||||
for (SystemDeptTb systemDeptTb : deptList) {
|
||||
if (systemDeptTb != null && systemDeptTb.getEnabled()) {
|
||||
List<SystemDeptTb> deptList1 = systemDeptMapper.queryDeptListByPid(systemDeptTb.getId());
|
||||
if (CollUtil.isNotEmpty(deptList1)) {
|
||||
list.addAll(queryChildDeptIdListByDeptIds(deptList1));
|
||||
}
|
||||
list.add(systemDeptTb.getId());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemDeptTb> querySuperiorDeptListByPid(SystemDeptTb dept, List<SystemDeptTb> deptList) {
|
||||
if (dept.getPid() == null) {
|
||||
deptList.addAll(systemDeptMapper.queryDeptListByPidIsNull());
|
||||
return deptList;
|
||||
}
|
||||
deptList.addAll(systemDeptMapper.queryDeptListByPid(dept.getPid()));
|
||||
return querySuperiorDeptListByPid(queryDeptById(dept.getPid()), deptList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<Set<SystemDeptTb>> buildDeptTree(List<SystemDeptTb> deptList) {
|
||||
Set<SystemDeptTb> trees = new LinkedHashSet<>();
|
||||
Set<SystemDeptTb> deptSet = new LinkedHashSet<>();
|
||||
List<String> deptNames = deptList.stream().map(SystemDeptTb::getName).collect(Collectors.toList());
|
||||
boolean isChild;
|
||||
for (SystemDeptTb dept : deptList) {
|
||||
isChild = false;
|
||||
if (dept.getPid() == null) {
|
||||
trees.add(dept);
|
||||
}
|
||||
for (SystemDeptTb it : deptList) {
|
||||
if (it.getPid() != null && dept.getId().equals(it.getPid())) {
|
||||
isChild = true;
|
||||
if (dept.getChildren() == null) {
|
||||
dept.setChildren(new ArrayList<>());
|
||||
}
|
||||
dept.getChildren().add(it);
|
||||
}
|
||||
}
|
||||
if (isChild) {
|
||||
deptSet.add(dept);
|
||||
} else if (dept.getPid() != null && !deptNames.contains(queryDeptById(dept.getPid()).getName())) {
|
||||
deptSet.add(dept);
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isEmpty(trees)) {
|
||||
trees = deptSet;
|
||||
}
|
||||
CsResultVo<Set<SystemDeptTb>> baseResult = new CsResultVo<>();
|
||||
baseResult.setContent(CollectionUtil.isEmpty(trees) ? deptSet : trees);
|
||||
baseResult.setTotalElements(deptSet.size());
|
||||
return baseResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verifyBindRelationByIds(Set<SystemDeptTb> deptSet) {
|
||||
Set<Long> deptIds = deptSet.stream().map(SystemDeptTb::getId).collect(Collectors.toSet());
|
||||
if (systemUserMapper.getUserCountByDeptIds(deptIds) > 0) {
|
||||
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
|
||||
}
|
||||
if (systemRoleMapper.getRoleCountByDeptIds(deptIds) > 0) {
|
||||
throw new BadRequestException("所选部门存在角色关联,请解除后再试!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SystemDeptTb> traverseDeptByIdWithPids(Set<Long> ids) {
|
||||
Set<SystemDeptTb> depts = new HashSet<>();
|
||||
for (Long id : ids) {
|
||||
// 根部门
|
||||
depts.add(queryDeptById(id));
|
||||
// 子部门
|
||||
List<SystemDeptTb> deptList = queryDeptListByPid(id);
|
||||
if (CollectionUtil.isNotEmpty(deptList)) {
|
||||
depts = queryRelationDeptSet(deptList, depts);
|
||||
}
|
||||
}
|
||||
return depts;
|
||||
}
|
||||
}
|
||||
+39
-8
@@ -1,37 +1,60 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDictDetailTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemDictDetailArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemDictDetailArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDictDetailMapper;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface SystemDictDetailService extends IService<SystemDictDetailTb> {
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemDictDetailService {
|
||||
private final SystemDictDetailMapper systemDictDetailMapper;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void saveDictDetail(CreateSystemDictDetailArgs resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDictDetail(CreateSystemDictDetailArgs resources) {
|
||||
SystemDictDetailTb dictDetail = BeanUtil.copyProperties(resources, SystemDictDetailTb.class);
|
||||
dictDetail.setDictId(resources.getDict().getId());
|
||||
systemDictDetailMapper.insert(dictDetail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyDictDetailById(SystemDictDetailTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyDictDetailById(SystemDictDetailTb resources) {
|
||||
SystemDictDetailTb dictDetail = systemDictDetailMapper.selectById(resources.getId());
|
||||
resources.setId(dictDetail.getId());
|
||||
systemDictDetailMapper.insertOrUpdate(resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id /
|
||||
*/
|
||||
void removeDictDetailById(Long id);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeDictDetailById(Long id) {
|
||||
systemDictDetailMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
@@ -40,7 +63,10 @@ public interface SystemDictDetailService extends IService<SystemDictDetailTb> {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<List<SystemDictDetailTb>> queryDictDetailListByArgs(QuerySystemDictDetailArgs criteria, Page<Object> page);
|
||||
|
||||
public CsResultVo<List<SystemDictDetailTb>> queryDictDetailByArgs(QuerySystemDictDetailArgs criteria, Page<Object> page) {
|
||||
return CsPageUtil.toPage(systemDictDetailMapper.selectDictDetailByArgs(criteria, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典名称获取字典详情
|
||||
@@ -48,5 +74,10 @@ public interface SystemDictDetailService extends IService<SystemDictDetailTb> {
|
||||
* @param name 字典名称
|
||||
* @return /
|
||||
*/
|
||||
List<SystemDictDetailTb> queryDictDetailListByName(String name);
|
||||
|
||||
public List<SystemDictDetailTb> queryDictDetailByName(String name) {
|
||||
QuerySystemDictDetailArgs criteria = new QuerySystemDictDetailArgs();
|
||||
criteria.setDictName(name);
|
||||
return systemDictDetailMapper.selectDictDetailByArgs(criteria);
|
||||
}
|
||||
}
|
||||
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDictDetailTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemDictDetailArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemDictDetailArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDictDetailMapper;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemDictDetailServiceImpl extends ServiceImpl<SystemDictDetailMapper, SystemDictDetailTb> implements SystemDictDetailService {
|
||||
private final SystemDictDetailMapper systemDictDetailMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDictDetail(CreateSystemDictDetailArgs resources) {
|
||||
SystemDictDetailTb dictDetail = BeanUtil.copyProperties(resources, SystemDictDetailTb.class);
|
||||
dictDetail.setDictId(resources.getDict().getId());
|
||||
save(dictDetail);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyDictDetailById(SystemDictDetailTb resources) {
|
||||
SystemDictDetailTb dictDetail = getById(resources.getId());
|
||||
resources.setId(dictDetail.getId());
|
||||
// 更新数据
|
||||
saveOrUpdate(resources);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeDictDetailById(Long id) {
|
||||
removeById(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemDictDetailTb>> queryDictDetailListByArgs(QuerySystemDictDetailArgs criteria, Page<Object> page) {
|
||||
return PageUtil.toPage(systemDictDetailMapper.queryDictDetailListByArgs(criteria, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemDictDetailTb> queryDictDetailListByName(String name) {
|
||||
return systemDictDetailMapper.queryDictDetailListByDictName(name);
|
||||
}
|
||||
}
|
||||
+80
-11
@@ -1,48 +1,107 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDictDetailTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDictTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemDictArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemDictArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemDictDetailArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDictDetailMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDictMapper;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemDictService {
|
||||
private final SystemDictMapper systemDictMapper;
|
||||
private final SystemDictDetailMapper systemDictDetailMapper;
|
||||
|
||||
public interface SystemDictService extends IService<SystemDictTb> {
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void saveDict(CreateSystemDictArgs resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDict(CreateSystemDictArgs resources) {
|
||||
systemDictMapper.insert(BeanUtil.copyProperties(resources, SystemDictTb.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyDictById(SystemDictTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyDictById(SystemDictTb resources) {
|
||||
SystemDictTb dict = systemDictMapper.selectById(resources.getId());
|
||||
dict.setName(resources.getName());
|
||||
dict.setDescription(resources.getDescription());
|
||||
systemDictMapper.insertOrUpdate(dict);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void removeDictByIds(Set<Long> ids);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeDictByIds(Set<Long> ids) {
|
||||
// 删除字典
|
||||
systemDictMapper.deleteByIds(ids);
|
||||
// 删除字典详情
|
||||
systemDictDetailMapper.deleteDictDetailByDictIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param queryAll 待导出的数据
|
||||
* @param dicts 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadDictExcel(List<SystemDictTb> queryAll, HttpServletResponse response) throws IOException;
|
||||
|
||||
public void exportDictExcel(List<SystemDictTb> dicts, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemDictTb dict : dicts) {
|
||||
QuerySystemDictDetailArgs criteria = new QuerySystemDictDetailArgs();
|
||||
criteria.setDictName(dict.getName());
|
||||
List<SystemDictDetailTb> dictDetails = systemDictDetailMapper.selectDictDetailByArgs(criteria);
|
||||
if (CollectionUtil.isNotEmpty(dictDetails)) {
|
||||
for (SystemDictDetailTb dictDetail : dictDetails) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("字典名称", dict.getName());
|
||||
map.put("字典描述", dict.getDescription());
|
||||
map.put("字典标签", dictDetail.getLabel());
|
||||
map.put("字典值", dictDetail.getValue());
|
||||
map.put("创建日期", dictDetail.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
} else {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("字典名称", dict.getName());
|
||||
map.put("字典描述", dict.getDescription());
|
||||
map.put("字典标签", null);
|
||||
map.put("字典值", null);
|
||||
map.put("创建日期", dict.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
@@ -51,7 +110,10 @@ public interface SystemDictService extends IService<SystemDictTb> {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<List<SystemDictTb>> queryDictPage(QuerySystemDictArgs criteria, Page<SystemDictTb> page);
|
||||
|
||||
public CsResultVo<List<SystemDictTb>> queryDictByArgs(QuerySystemDictArgs criteria, Page<SystemDictTb> page) {
|
||||
return CsPageUtil.toPage(systemDictMapper.selectDictByArgs(criteria, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
@@ -59,5 +121,12 @@ public interface SystemDictService extends IService<SystemDictTb> {
|
||||
* @param criteria /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemDictTb> queryDictList(QuerySystemDictArgs criteria);
|
||||
|
||||
public List<SystemDictTb> queryDictByArgs(QuerySystemDictArgs criteria) {
|
||||
return systemDictMapper.selectDictByArgs(criteria);
|
||||
}
|
||||
|
||||
public SystemDictTb getById(int id) {
|
||||
return systemDictMapper.selectById(id);
|
||||
}
|
||||
}
|
||||
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDictDetailTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemDictTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemDictArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemDictArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDictDetailMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemDictMapper;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemDictServiceImpl extends ServiceImpl<SystemDictMapper, SystemDictTb> implements SystemDictService {
|
||||
private final SystemDictMapper systemDictMapper;
|
||||
private final SystemDictDetailMapper systemDictDetailMapper;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveDict(CreateSystemDictArgs resources) {
|
||||
save(BeanUtil.copyProperties(resources, SystemDictTb.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyDictById(SystemDictTb resources) {
|
||||
SystemDictTb dict = getById(resources.getId());
|
||||
dict.setName(resources.getName());
|
||||
dict.setDescription(resources.getDescription());
|
||||
saveOrUpdate(dict);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeDictByIds(Set<Long> ids) {
|
||||
// 删除字典
|
||||
systemDictMapper.deleteByIds(ids);
|
||||
// 删除字典详情
|
||||
systemDictDetailMapper.deleteDictDetailByDictIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadDictExcel(List<SystemDictTb> dicts, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemDictTb dict : dicts) {
|
||||
List<SystemDictDetailTb> dictDetails = systemDictDetailMapper.queryDictDetailListByDictName(dict.getName());
|
||||
if (CollectionUtil.isNotEmpty(dictDetails)) {
|
||||
for (SystemDictDetailTb dictDetail : dictDetails) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("字典名称", dict.getName());
|
||||
map.put("字典描述", dict.getDescription());
|
||||
map.put("字典标签", dictDetail.getLabel());
|
||||
map.put("字典值", dictDetail.getValue());
|
||||
map.put("创建日期", dictDetail.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
} else {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("字典名称", dict.getName());
|
||||
map.put("字典描述", dict.getDescription());
|
||||
map.put("字典标签", null);
|
||||
map.put("字典值", null);
|
||||
map.put("创建日期", dict.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemDictTb>> queryDictPage(QuerySystemDictArgs criteria, Page<SystemDictTb> page) {
|
||||
IPage<SystemDictTb> dicts = systemDictMapper.queryDictPageByArgs(criteria, page);
|
||||
return PageUtil.toPage(dicts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemDictTb> queryDictList(QuerySystemDictArgs criteria) {
|
||||
return systemDictMapper.queryDictPageByArgs(criteria, PageUtil.getCount(systemDictMapper)).getRecords();
|
||||
}
|
||||
}
|
||||
+118
-7
@@ -1,12 +1,35 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.extra.mail.Mail;
|
||||
import cn.hutool.extra.mail.MailAccount;
|
||||
import cn.odboy.core.constant.system.SystemCaptchaBizEnum;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemEmailConfigTb;
|
||||
import cn.odboy.core.dal.model.system.SendSystemEmailArgs;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.odboy.core.dal.mysql.system.SystemEmailConfigMapper;
|
||||
import cn.odboy.core.framework.templatefile.CsResourceTemplateUtil;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.redis.RedisHelper;
|
||||
import cn.odboy.util.DesEncryptUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public interface SystemEmailService extends IService<SystemEmailConfigTb> {
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemEmailService {
|
||||
private final SystemEmailConfigMapper systemEmailConfigMapper;
|
||||
private final RedisHelper redisHelper;
|
||||
@Value("${app.captcha.expireTime}")
|
||||
private Long captchaExpireTime;
|
||||
@Value("${spring.application.title}")
|
||||
private String applicationTitle;
|
||||
|
||||
/**
|
||||
* 更新邮件配置
|
||||
@@ -15,24 +38,112 @@ public interface SystemEmailService extends IService<SystemEmailConfigTb> {
|
||||
* @return /
|
||||
* @throws Exception /
|
||||
*/
|
||||
void modifyEmailConfigOnPassChange(SystemEmailConfigTb emailConfig) throws Exception;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyEmailConfig(SystemEmailConfigTb emailConfig) throws Exception {
|
||||
SystemEmailConfigTb systemEmailConfigTb = getLastEmailConfig();
|
||||
if (!emailConfig.getPassword().equals(systemEmailConfigTb.getPassword())) {
|
||||
// 对称加密
|
||||
systemEmailConfigTb.setPassword(DesEncryptUtil.desEncrypt(emailConfig.getPassword()));
|
||||
}
|
||||
systemEmailConfigTb.setId(1L);
|
||||
systemEmailConfigMapper.insertOrUpdate(systemEmailConfigTb);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param sendEmailRequest 邮件发送的内容
|
||||
*/
|
||||
void sendEmail(SendSystemEmailArgs sendEmailRequest);
|
||||
|
||||
|
||||
public void sendEmail(SendSystemEmailArgs sendEmailRequest) {
|
||||
SystemEmailConfigTb systemEmailConfigTb = getLastEmailConfig();
|
||||
if (systemEmailConfigTb.getId() == null) {
|
||||
throw new BadRequestException("请先配置,再操作");
|
||||
}
|
||||
// 封装
|
||||
MailAccount account = new MailAccount();
|
||||
// 设置用户
|
||||
String user = systemEmailConfigTb.getFromUser().split("@")[0];
|
||||
account.setUser(user);
|
||||
account.setHost(systemEmailConfigTb.getHost());
|
||||
account.setPort(Integer.parseInt(systemEmailConfigTb.getPort()));
|
||||
account.setAuth(true);
|
||||
try {
|
||||
// 对称解密
|
||||
account.setPass(DesEncryptUtil.desDecrypt(systemEmailConfigTb.getPassword()));
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
account.setFrom(systemEmailConfigTb.getUser() + "<" + systemEmailConfigTb.getFromUser() + ">");
|
||||
// ssl方式发送
|
||||
account.setSslEnable(true);
|
||||
// 使用STARTTLS安全连接
|
||||
account.setStarttlsEnable(true);
|
||||
// 解决jdk8之后默认禁用部分tls协议,导致邮件发送失败的问题
|
||||
account.setSslProtocols("TLSv1 TLSv1.1 TLSv1.2");
|
||||
String content = sendEmailRequest.getContent();
|
||||
// 发送
|
||||
try {
|
||||
int size = sendEmailRequest.getTos().size();
|
||||
Mail.create(account)
|
||||
.setTos(sendEmailRequest.getTos().toArray(new String[size]))
|
||||
.setTitle(sendEmailRequest.getSubject())
|
||||
.setContent(content)
|
||||
.setHtml(true)
|
||||
// 关闭session
|
||||
.setUseGlobalSession(false)
|
||||
.send();
|
||||
} catch (Exception e) {
|
||||
log.error("邮件发送失败", e);
|
||||
throw new BadRequestException("邮件发送失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验邮箱验证码
|
||||
*/
|
||||
void checkEmailCaptcha(SystemCaptchaBizEnum biEnum, String email, String code);
|
||||
|
||||
public void checkEmailCaptcha(SystemCaptchaBizEnum biEnum, String email, String code) {
|
||||
String redisKey = biEnum.getRedisKey() + email;
|
||||
String value = redisHelper.get(redisKey, String.class);
|
||||
if (value == null || !value.equals(code)) {
|
||||
throw new BadRequestException("无效验证码");
|
||||
} else {
|
||||
redisHelper.del(redisKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送给邮箱验证码
|
||||
*/
|
||||
void sendCaptcha(SystemCaptchaBizEnum biEnum, String email);
|
||||
|
||||
SystemEmailConfigTb getEmailConfig();
|
||||
public void sendCaptcha(SystemCaptchaBizEnum biEnum, String email) {
|
||||
if (biEnum == null) {
|
||||
throw new BadRequestException("biEnum必填");
|
||||
}
|
||||
String content;
|
||||
String redisKey = biEnum.getRedisKey() + email;
|
||||
String oldCode = redisHelper.get(redisKey, String.class);
|
||||
if (oldCode == null) {
|
||||
String code = RandomUtil.randomNumbers(6);
|
||||
// 存入缓存
|
||||
if (!redisHelper.set(redisKey, code, captchaExpireTime)) {
|
||||
throw new BadRequestException("服务异常,请联系网站负责人");
|
||||
}
|
||||
// 存在就再次发送原来的验证码
|
||||
content = CsResourceTemplateUtil.render("system", biEnum.getTemplateName(), Dict.create().set("code", code));
|
||||
} else {
|
||||
content = CsResourceTemplateUtil.render("system", biEnum.getTemplateName(), Dict.create().set("code", oldCode));
|
||||
}
|
||||
SendSystemEmailArgs sendEmailRequest = new SendSystemEmailArgs(Collections.singletonList(email), applicationTitle, content);
|
||||
sendEmail(sendEmailRequest);
|
||||
}
|
||||
|
||||
|
||||
public SystemEmailConfigTb getLastEmailConfig() {
|
||||
SystemEmailConfigTb systemEmailConfigTb = systemEmailConfigMapper.selectById(1L);
|
||||
return systemEmailConfigTb == null ? new SystemEmailConfigTb() : systemEmailConfigTb;
|
||||
}
|
||||
}
|
||||
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.extra.mail.Mail;
|
||||
import cn.hutool.extra.mail.MailAccount;
|
||||
import cn.odboy.core.constant.system.SystemCaptchaBizEnum;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemEmailConfigTb;
|
||||
import cn.odboy.core.dal.model.system.SendSystemEmailArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemEmailConfigMapper;
|
||||
import cn.odboy.core.framework.templatefile.CsResourceTemplateUtil;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.redis.RedisHelper;
|
||||
import cn.odboy.util.DesEncryptUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemEmailServiceImpl extends ServiceImpl<SystemEmailConfigMapper, SystemEmailConfigTb> implements SystemEmailService {
|
||||
private final RedisHelper redisHelper;
|
||||
@Value("${app.captcha.expireTime}")
|
||||
private Long captchaExpireTime;
|
||||
@Value("${spring.application.title}")
|
||||
private String applicationTitle;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyEmailConfigOnPassChange(SystemEmailConfigTb emailConfig) throws Exception {
|
||||
SystemEmailConfigTb systemEmailConfigTb = getEmailConfig();
|
||||
if (!emailConfig.getPassword().equals(systemEmailConfigTb.getPassword())) {
|
||||
// 对称加密
|
||||
systemEmailConfigTb.setPassword(DesEncryptUtil.desEncrypt(emailConfig.getPassword()));
|
||||
}
|
||||
systemEmailConfigTb.setId(1L);
|
||||
saveOrUpdate(systemEmailConfigTb);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendEmail(SendSystemEmailArgs sendEmailRequest) {
|
||||
SystemEmailConfigTb systemEmailConfigTb = getEmailConfig();
|
||||
if (systemEmailConfigTb.getId() == null) {
|
||||
throw new BadRequestException("请先配置,再操作");
|
||||
}
|
||||
// 封装
|
||||
MailAccount account = new MailAccount();
|
||||
// 设置用户
|
||||
String user = systemEmailConfigTb.getFromUser().split("@")[0];
|
||||
account.setUser(user);
|
||||
account.setHost(systemEmailConfigTb.getHost());
|
||||
account.setPort(Integer.parseInt(systemEmailConfigTb.getPort()));
|
||||
account.setAuth(true);
|
||||
try {
|
||||
// 对称解密
|
||||
account.setPass(DesEncryptUtil.desDecrypt(systemEmailConfigTb.getPassword()));
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
account.setFrom(systemEmailConfigTb.getUser() + "<" + systemEmailConfigTb.getFromUser() + ">");
|
||||
// ssl方式发送
|
||||
account.setSslEnable(true);
|
||||
// 使用STARTTLS安全连接
|
||||
account.setStarttlsEnable(true);
|
||||
// 解决jdk8之后默认禁用部分tls协议,导致邮件发送失败的问题
|
||||
account.setSslProtocols("TLSv1 TLSv1.1 TLSv1.2");
|
||||
String content = sendEmailRequest.getContent();
|
||||
// 发送
|
||||
try {
|
||||
int size = sendEmailRequest.getTos().size();
|
||||
Mail.create(account)
|
||||
.setTos(sendEmailRequest.getTos().toArray(new String[size]))
|
||||
.setTitle(sendEmailRequest.getSubject())
|
||||
.setContent(content)
|
||||
.setHtml(true)
|
||||
// 关闭session
|
||||
.setUseGlobalSession(false)
|
||||
.send();
|
||||
} catch (Exception e) {
|
||||
log.error("邮件发送失败", e);
|
||||
throw new BadRequestException("邮件发送失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkEmailCaptcha(SystemCaptchaBizEnum biEnum, String email, String code) {
|
||||
String redisKey = biEnum.getRedisKey() + email;
|
||||
String value = redisHelper.get(redisKey, String.class);
|
||||
if (value == null || !value.equals(code)) {
|
||||
throw new BadRequestException("无效验证码");
|
||||
} else {
|
||||
redisHelper.del(redisKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCaptcha(SystemCaptchaBizEnum biEnum, String email) {
|
||||
if (biEnum == null) {
|
||||
throw new BadRequestException("biEnum必填");
|
||||
}
|
||||
String content;
|
||||
String redisKey = biEnum.getRedisKey() + email;
|
||||
String oldCode = redisHelper.get(redisKey, String.class);
|
||||
if (oldCode == null) {
|
||||
String code = RandomUtil.randomNumbers(6);
|
||||
// 存入缓存
|
||||
if (!redisHelper.set(redisKey, code, captchaExpireTime)) {
|
||||
throw new BadRequestException("服务异常,请联系网站负责人");
|
||||
}
|
||||
// 存在就再次发送原来的验证码
|
||||
content = CsResourceTemplateUtil.render(biEnum.getTemplateName(), Dict.create().set("code", code));
|
||||
} else {
|
||||
content = CsResourceTemplateUtil.render(biEnum.getTemplateName(), Dict.create().set("code", oldCode));
|
||||
}
|
||||
SendSystemEmailArgs sendEmailRequest = new SendSystemEmailArgs(Collections.singletonList(email), applicationTitle, content);
|
||||
sendEmail(sendEmailRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemEmailConfigTb getEmailConfig() {
|
||||
SystemEmailConfigTb systemEmailConfigTb = getById(1L);
|
||||
return systemEmailConfigTb == null ? new SystemEmailConfigTb() : systemEmailConfigTb;
|
||||
}
|
||||
}
|
||||
+67
-20
@@ -1,57 +1,105 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemJobTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemJobArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemJobArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemJobMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemJobService {
|
||||
private final SystemJobMapper systemJobMapper;
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
|
||||
public interface SystemJobService extends IService<SystemJobTb> {
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void saveJob(CreateSystemJobArgs resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveJob(CreateSystemJobArgs resources) {
|
||||
SystemJobTb job = systemJobMapper.getJobByName(resources.getName());
|
||||
if (job != null) {
|
||||
throw new BadRequestException("职位名称已存在");
|
||||
}
|
||||
systemJobMapper.insert(BeanUtil.copyProperties(resources, SystemJobTb.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyJobById(SystemJobTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyJobById(SystemJobTb resources) {
|
||||
SystemJobTb job = systemJobMapper.selectById(resources.getId());
|
||||
SystemJobTb old = systemJobMapper.getJobByName(resources.getName());
|
||||
if (old != null && !old.getId().equals(resources.getId())) {
|
||||
throw new BadRequestException("职位名称已存在");
|
||||
}
|
||||
resources.setId(job.getId());
|
||||
systemJobMapper.insertOrUpdate(resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void removeJobByIds(Set<Long> ids);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeJobByIds(Set<Long> ids) {
|
||||
systemJobMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param jobs 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
* @throws IOException
|
||||
*/
|
||||
void downloadJobExcel(List<SystemJobTb> jobs, HttpServletResponse response) throws IOException;
|
||||
|
||||
public void exportJobExcel(List<SystemJobTb> jobs, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemJobTb job : jobs) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("岗位名称", job.getName());
|
||||
map.put("岗位状态", job.getEnabled() ? "启用" : "停用");
|
||||
map.put("创建日期", job.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
* @return
|
||||
*/
|
||||
CsResultVo<List<SystemJobTb>> queryJobPage(QuerySystemJobArgs criteria, Page<SystemJobTb> page);
|
||||
|
||||
|
||||
public CsResultVo<List<SystemJobTb>> queryJobByArgs(QuerySystemJobArgs criteria, Page<SystemJobTb> page) {
|
||||
return CsPageUtil.toPage(systemJobMapper.selectJobByArgs(criteria, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
@@ -59,21 +107,20 @@ public interface SystemJobService extends IService<SystemJobTb> {
|
||||
* @param criteria /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemJobTb> queryJobList(QuerySystemJobArgs criteria);
|
||||
|
||||
public List<SystemJobTb> queryJobByArgs(QuerySystemJobArgs criteria) {
|
||||
return systemJobMapper.selectJobByArgs(criteria, CsPageUtil.getCount(systemJobMapper)).getRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否被用户关联
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void verifyBindRelationByIds(Set<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
SystemJobTb queryJobById(Long id);
|
||||
public void verifyBindRelationByIds(Set<Long> ids) {
|
||||
if (systemUserMapper.countUserByJobIds(ids) > 0) {
|
||||
throw new BadRequestException("所选的岗位中存在用户关联,请解除关联再试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemJobTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemJobArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemJobArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemJobMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemJobServiceImpl extends ServiceImpl<SystemJobMapper, SystemJobTb> implements SystemJobService {
|
||||
private final SystemJobMapper systemJobMapper;
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveJob(CreateSystemJobArgs resources) {
|
||||
SystemJobTb job = systemJobMapper.getJobByName(resources.getName());
|
||||
if (job != null) {
|
||||
throw new BadRequestException("职位名称已存在");
|
||||
}
|
||||
save(BeanUtil.copyProperties(resources, SystemJobTb.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyJobById(SystemJobTb resources) {
|
||||
SystemJobTb job = getById(resources.getId());
|
||||
SystemJobTb old = systemJobMapper.getJobByName(resources.getName());
|
||||
if (old != null && !old.getId().equals(resources.getId())) {
|
||||
throw new BadRequestException("职位名称已存在");
|
||||
}
|
||||
resources.setId(job.getId());
|
||||
saveOrUpdate(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeJobByIds(Set<Long> ids) {
|
||||
removeBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadJobExcel(List<SystemJobTb> jobs, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemJobTb job : jobs) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("岗位名称", job.getName());
|
||||
map.put("岗位状态", job.getEnabled() ? "启用" : "停用");
|
||||
map.put("创建日期", job.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemJobTb>> queryJobPage(QuerySystemJobArgs criteria, Page<SystemJobTb> page) {
|
||||
return PageUtil.toPage(systemJobMapper.queryJobPageByArgs(criteria, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemJobTb> queryJobList(QuerySystemJobArgs criteria) {
|
||||
return systemJobMapper.queryJobPageByArgs(criteria, PageUtil.getCount(systemJobMapper)).getRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemJobTb queryJobById(Long id) {
|
||||
return systemJobMapper.selectById(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void verifyBindRelationByIds(Set<Long> ids) {
|
||||
if (systemUserMapper.getUserCountByJobIds(ids) > 0) {
|
||||
throw new BadRequestException("所选的岗位中存在用户关联,请解除关联再试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
+84
-10
@@ -1,40 +1,97 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemLocalStorageTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemLocalStorageArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemLocalStorageMapper;
|
||||
import cn.odboy.core.framework.properties.AppProperties;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface SystemLocalStorageService extends IService<SystemLocalStorageTb> {
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemLocalStorageService {
|
||||
private final SystemLocalStorageMapper systemLocalStorageMapper;
|
||||
private final AppProperties properties;
|
||||
|
||||
/**
|
||||
* 上传
|
||||
*
|
||||
* @param name 文件名称
|
||||
* @param file 文件
|
||||
* @param name 文件名称
|
||||
* @param multipartFile 文件
|
||||
* @return /
|
||||
*/
|
||||
SystemLocalStorageTb uploadFile(String name, MultipartFile file);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SystemLocalStorageTb uploadFile(String name, MultipartFile multipartFile) {
|
||||
long size = multipartFile.getSize();
|
||||
FileUtil.checkSize(properties.getFile().getFileMaxSize(), size);
|
||||
String suffix = FileUtil.getSuffix(multipartFile.getOriginalFilename());
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
File file = FileUtil.upload(multipartFile, properties.getFile().getPath() + type + File.separator);
|
||||
if (ObjectUtil.isNull(file)) {
|
||||
throw new BadRequestException("上传失败");
|
||||
}
|
||||
try {
|
||||
String formatSize = FileUtil.getSize(size);
|
||||
name = StringUtil.isBlank(name) ? FileUtil.getPrefix(multipartFile.getOriginalFilename()) : name;
|
||||
SystemLocalStorageTb localStorage = new SystemLocalStorageTb(
|
||||
file.getName(),
|
||||
name,
|
||||
suffix,
|
||||
file.getPath(),
|
||||
type,
|
||||
formatSize
|
||||
);
|
||||
systemLocalStorageMapper.insert(localStorage);
|
||||
return localStorage;
|
||||
} catch (Exception e) {
|
||||
FileUtil.del(file);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources 文件信息
|
||||
*/
|
||||
void modifyLocalStorageById(SystemLocalStorageTb resources);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyLocalStorageById(SystemLocalStorageTb resources) {
|
||||
SystemLocalStorageTb localStorage = systemLocalStorageMapper.selectById(resources.getId());
|
||||
localStorage.copy(resources);
|
||||
systemLocalStorageMapper.insertOrUpdate(localStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void removeFileByIds(Long[] ids);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeFileByIds(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
SystemLocalStorageTb storage = systemLocalStorageMapper.selectById(id);
|
||||
FileUtil.del(storage.getPath());
|
||||
systemLocalStorageMapper.deleteById(storage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
@@ -43,7 +100,20 @@ public interface SystemLocalStorageService extends IService<SystemLocalStorageTb
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadExcel(List<SystemLocalStorageTb> localStorages, HttpServletResponse response) throws IOException;
|
||||
public void exportLocalStorageExcel(List<SystemLocalStorageTb> localStorages, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemLocalStorageTb localStorage : localStorages) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("文件名", localStorage.getRealName());
|
||||
map.put("备注名", localStorage.getName());
|
||||
map.put("文件类型", localStorage.getType());
|
||||
map.put("文件大小", localStorage.getSize());
|
||||
map.put("创建者", localStorage.getCreateBy());
|
||||
map.put("创建日期", localStorage.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
@@ -52,7 +122,9 @@ public interface SystemLocalStorageService extends IService<SystemLocalStorageTb
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<List<SystemLocalStorageTb>> queryLocalStoragePage(QuerySystemLocalStorageArgs criteria, Page<SystemLocalStorageTb> page);
|
||||
public CsResultVo<List<SystemLocalStorageTb>> queryLocalStorage(QuerySystemLocalStorageArgs criteria, Page<SystemLocalStorageTb> page) {
|
||||
return CsPageUtil.toPage(systemLocalStorageMapper.selectLocalStorageByArgs(criteria, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
@@ -60,5 +132,7 @@ public interface SystemLocalStorageService extends IService<SystemLocalStorageTb
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<SystemLocalStorageTb> queryLocalStorageList(QuerySystemLocalStorageArgs criteria);
|
||||
public List<SystemLocalStorageTb> queryLocalStorage(QuerySystemLocalStorageArgs criteria) {
|
||||
return systemLocalStorageMapper.selectLocalStorageByArgs(criteria, CsPageUtil.getCount(systemLocalStorageMapper)).getRecords();
|
||||
}
|
||||
}
|
||||
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemLocalStorageTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemLocalStorageArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemLocalStorageMapper;
|
||||
import cn.odboy.core.framework.properties.AppProperties;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemLocalStorageServiceImpl extends ServiceImpl<SystemLocalStorageMapper, SystemLocalStorageTb> implements SystemLocalStorageService {
|
||||
private final SystemLocalStorageMapper systemLocalStorageMapper;
|
||||
private final AppProperties properties;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SystemLocalStorageTb uploadFile(String name, MultipartFile multipartFile) {
|
||||
long size = multipartFile.getSize();
|
||||
FileUtil.checkSize(properties.getFile().getFileMaxSize(), size);
|
||||
String suffix = FileUtil.getSuffix(multipartFile.getOriginalFilename());
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
File file = FileUtil.upload(multipartFile, properties.getFile().getPath() + type + File.separator);
|
||||
if (ObjectUtil.isNull(file)) {
|
||||
throw new BadRequestException("上传失败");
|
||||
}
|
||||
try {
|
||||
String formatSize = FileUtil.getSize(size);
|
||||
name = StringUtil.isBlank(name) ? FileUtil.getPrefix(multipartFile.getOriginalFilename()) : name;
|
||||
SystemLocalStorageTb localStorage = new SystemLocalStorageTb(
|
||||
file.getName(),
|
||||
name,
|
||||
suffix,
|
||||
file.getPath(),
|
||||
type,
|
||||
formatSize
|
||||
);
|
||||
save(localStorage);
|
||||
return localStorage;
|
||||
} catch (Exception e) {
|
||||
FileUtil.del(file);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyLocalStorageById(SystemLocalStorageTb resources) {
|
||||
SystemLocalStorageTb localStorage = getById(resources.getId());
|
||||
localStorage.copy(resources);
|
||||
saveOrUpdate(localStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeFileByIds(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
SystemLocalStorageTb storage = getById(id);
|
||||
FileUtil.del(storage.getPath());
|
||||
removeById(storage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadExcel(List<SystemLocalStorageTb> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemLocalStorageTb localStorage : queryAll) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("文件名", localStorage.getRealName());
|
||||
map.put("备注名", localStorage.getName());
|
||||
map.put("文件类型", localStorage.getType());
|
||||
map.put("文件大小", localStorage.getSize());
|
||||
map.put("创建者", localStorage.getCreateBy());
|
||||
map.put("创建日期", localStorage.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemLocalStorageTb>> queryLocalStoragePage(QuerySystemLocalStorageArgs criteria, Page<SystemLocalStorageTb> page) {
|
||||
return PageUtil.toPage(systemLocalStorageMapper.queryLocalStoragePageByArgs(criteria, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemLocalStorageTb> queryLocalStorageList(QuerySystemLocalStorageArgs criteria) {
|
||||
return systemLocalStorageMapper.queryLocalStoragePageByArgs(criteria, PageUtil.getCount(systemLocalStorageMapper)).getRecords();
|
||||
}
|
||||
}
|
||||
+301
-33
@@ -1,40 +1,146 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.odboy.core.constant.TransferProtocolConst;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemMenuTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemMenuArgs;
|
||||
import cn.odboy.core.dal.model.system.SystemMenuMetaVo;
|
||||
import cn.odboy.core.dal.model.system.SystemMenuVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.odboy.core.dal.mysql.system.SystemMenuMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMenuMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.ClassUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public interface SystemMenuService extends IService<SystemMenuTb> {
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor_ = @Lazy)
|
||||
public class SystemMenuService {
|
||||
private final SystemMenuMapper systemMenuMapper;
|
||||
private final SystemRoleMenuMapper systemRoleMenuMapper;
|
||||
private final SystemRoleService systemRoleService;
|
||||
private final SystemMenuService systemMenuService;
|
||||
|
||||
private static final String YES_STR = "是";
|
||||
private static final String NO_STR = "否";
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void saveMenu(SystemMenuTb resources);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveMenu(SystemMenuTb resources) {
|
||||
if (systemMenuMapper.getMenuByTitle(resources.getTitle()) != null) {
|
||||
throw new BadRequestException("菜单标题已存在");
|
||||
}
|
||||
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
||||
if (systemMenuMapper.getMenuByComponentName(resources.getComponentName()) != null) {
|
||||
throw new BadRequestException("菜单组件名称已存在");
|
||||
}
|
||||
}
|
||||
if (Long.valueOf(0L).equals(resources.getPid())) {
|
||||
resources.setPid(null);
|
||||
}
|
||||
if (resources.getIFrame()) {
|
||||
if (!(resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
systemMenuMapper.insert(resources);
|
||||
// 计算子节点数目
|
||||
resources.setSubCount(0);
|
||||
// 更新父节点菜单数目
|
||||
systemMenuService.updateMenuSubCnt(resources.getPid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyMenuById(SystemMenuTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyMenuById(SystemMenuTb resources) {
|
||||
if (resources.getId().equals(resources.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
SystemMenuTb menu = systemMenuMapper.selectById(resources.getId());
|
||||
if (resources.getIFrame()) {
|
||||
if (!(resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
SystemMenuTb menu1 = systemMenuMapper.getMenuByTitle(resources.getTitle());
|
||||
|
||||
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||
throw new BadRequestException("菜单标题已存在");
|
||||
}
|
||||
|
||||
if (resources.getPid().equals(0L)) {
|
||||
resources.setPid(null);
|
||||
}
|
||||
|
||||
// 记录的父节点ID
|
||||
Long oldPid = menu.getPid();
|
||||
Long newPid = resources.getPid();
|
||||
|
||||
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
||||
menu1 = systemMenuMapper.getMenuByComponentName(resources.getComponentName());
|
||||
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||
throw new BadRequestException("菜单组件名称已存在");
|
||||
}
|
||||
}
|
||||
menu.setTitle(resources.getTitle());
|
||||
menu.setComponent(resources.getComponent());
|
||||
menu.setPath(resources.getPath());
|
||||
menu.setIcon(resources.getIcon());
|
||||
menu.setIFrame(resources.getIFrame());
|
||||
menu.setPid(resources.getPid());
|
||||
menu.setMenuSort(resources.getMenuSort());
|
||||
menu.setCache(resources.getCache());
|
||||
menu.setHidden(resources.getHidden());
|
||||
menu.setComponentName(resources.getComponentName());
|
||||
menu.setPermission(resources.getPermission());
|
||||
menu.setType(resources.getType());
|
||||
// auto fill
|
||||
menu.setUpdateBy(null);
|
||||
menu.setUpdateTime(null);
|
||||
systemMenuMapper.insertOrUpdate(menu);
|
||||
// 计算父级菜单节点数目
|
||||
systemMenuService.updateMenuSubCnt(oldPid);
|
||||
systemMenuService.updateMenuSubCnt(newPid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param menuSet /
|
||||
*/
|
||||
void removeMenuByIds(Set<SystemMenuTb> menuSet);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeMenuByIds(Set<SystemMenuTb> menuSet) {
|
||||
for (SystemMenuTb menu : menuSet) {
|
||||
systemRoleMenuMapper.deleteRoleMenuByMenuId(menu.getId());
|
||||
systemMenuMapper.deleteById(menu.getId());
|
||||
systemMenuService.updateMenuSubCnt(menu.getPid());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
@@ -43,7 +149,30 @@ public interface SystemMenuService extends IService<SystemMenuTb> {
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadMenuExcel(List<SystemMenuTb> menus, HttpServletResponse response) throws IOException;
|
||||
|
||||
public void exportMenuExcel(List<SystemMenuTb> menus, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemMenuTb menu : menus) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("菜单标题", menu.getTitle());
|
||||
map.put("菜单类型", menu.getType() == null ? "目录" : menu.getType() == 1 ? "菜单" : "按钮");
|
||||
map.put("权限标识", menu.getPermission());
|
||||
map.put("外链菜单", menu.getIFrame() ? YES_STR : NO_STR);
|
||||
map.put("菜单可见", menu.getHidden() ? NO_STR : YES_STR);
|
||||
map.put("是否缓存", menu.getCache() ? YES_STR : NO_STR);
|
||||
map.put("创建日期", menu.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateMenuSubCnt(Long menuId) {
|
||||
if (menuId != null) {
|
||||
int count = systemMenuMapper.countMenuByPid(menuId);
|
||||
systemMenuMapper.updateMenuSubCntByMenuId(count, menuId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
@@ -53,7 +182,27 @@ public interface SystemMenuService extends IService<SystemMenuTb> {
|
||||
* @return /
|
||||
* @throws Exception /
|
||||
*/
|
||||
List<SystemMenuTb> queryMenuList(QuerySystemMenuArgs criteria, Boolean isQuery) throws Exception;
|
||||
|
||||
public List<SystemMenuTb> queryAllMenu(QuerySystemMenuArgs criteria, Boolean isQuery) throws Exception {
|
||||
if (Boolean.TRUE.equals(isQuery)) {
|
||||
criteria.setPidIsNull(true);
|
||||
List<Field> fields = ClassUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
||||
for (Field field : fields) {
|
||||
//设置对象的访问权限,保证对private的属性的访问
|
||||
field.setAccessible(true);
|
||||
Object val = field.get(criteria);
|
||||
if ("pidIsNull".equals(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
// 如果有查询条件,则不指定pidIsNull
|
||||
if (ObjectUtil.isNotNull(val)) {
|
||||
criteria.setPidIsNull(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return systemMenuMapper.selectMenuByArgs(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
@@ -61,7 +210,23 @@ public interface SystemMenuService extends IService<SystemMenuTb> {
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
SystemMenuTb queryMenuById(long id);
|
||||
|
||||
public SystemMenuTb getMenuById(long id) {
|
||||
return systemMenuMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前用户获取菜单
|
||||
*
|
||||
* @param currentUserId /
|
||||
* @return /
|
||||
*/
|
||||
|
||||
public List<SystemMenuTb> queryMenuListByUserId(Long currentUserId) {
|
||||
List<SystemRoleTb> roles = systemRoleService.queryRoleByUsersId(currentUserId);
|
||||
Set<Long> roleIds = roles.stream().map(SystemRoleTb::getId).collect(Collectors.toSet());
|
||||
return new ArrayList<>(systemMenuMapper.selectMenuByRoleIdsAndType(roleIds, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有子节点,包含自身ID
|
||||
@@ -70,23 +235,17 @@ public interface SystemMenuService extends IService<SystemMenuTb> {
|
||||
* @param menuSet /
|
||||
* @return /
|
||||
*/
|
||||
Set<SystemMenuTb> queryChildMenuSet(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet);
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
*
|
||||
* @param menus 原始数据
|
||||
* @return /
|
||||
*/
|
||||
List<SystemMenuTb> buildMenuTree(List<SystemMenuTb> menus);
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
*
|
||||
* @param menus /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemMenuVo> buildMenuVo(List<SystemMenuTb> menus);
|
||||
public Set<SystemMenuTb> queryChildMenu(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) {
|
||||
for (SystemMenuTb menu : menuList) {
|
||||
menuSet.add(menu);
|
||||
List<SystemMenuTb> menus = systemMenuMapper.selectMenuByPidOrderByMenuSort(menu.getId());
|
||||
if (CollUtil.isNotEmpty(menus)) {
|
||||
queryChildMenu(menus, menuSet);
|
||||
}
|
||||
}
|
||||
return menuSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 懒加载菜单数据
|
||||
@@ -94,22 +253,131 @@ public interface SystemMenuService extends IService<SystemMenuTb> {
|
||||
* @param pid /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemMenuTb> queryMenuListByPid(Long pid);
|
||||
|
||||
public List<SystemMenuTb> queryMenuByPid(Long pid) {
|
||||
List<SystemMenuTb> menus;
|
||||
if (pid != null && !pid.equals(0L)) {
|
||||
menus = systemMenuMapper.selectMenuByPidOrderByMenuSort(pid);
|
||||
} else {
|
||||
menus = systemMenuMapper.selectMenuByPidIsNullOrderByMenuSort();
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取同级与上级数据
|
||||
*
|
||||
* @param menu /
|
||||
* @param objects /
|
||||
* @param menu /
|
||||
* @param menus /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemMenuTb> querySuperiorMenuList(SystemMenuTb menu, List<SystemMenuTb> objects);
|
||||
|
||||
public List<SystemMenuTb> querySuperiorMenuList(SystemMenuTb menu, List<SystemMenuTb> menus) {
|
||||
if (menu.getPid() == null) {
|
||||
menus.addAll(systemMenuMapper.selectMenuByPidIsNullOrderByMenuSort());
|
||||
return menus;
|
||||
}
|
||||
menus.addAll(systemMenuMapper.selectMenuByPidOrderByMenuSort(menu.getPid()));
|
||||
return querySuperiorMenuList(getMenuById(menu.getPid()), menus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前用户获取菜单
|
||||
* 构建菜单树
|
||||
*
|
||||
* @param currentUserId /
|
||||
* @param menus 原始数据
|
||||
* @return /
|
||||
*/
|
||||
List<SystemMenuTb> queryMenuListByUserId(Long currentUserId);
|
||||
|
||||
public List<SystemMenuTb> buildMenuTree(List<SystemMenuTb> menus) {
|
||||
List<SystemMenuTb> trees = new ArrayList<>();
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (SystemMenuTb menu : menus) {
|
||||
if (menu.getPid() == null) {
|
||||
trees.add(menu);
|
||||
}
|
||||
for (SystemMenuTb it : menus) {
|
||||
if (menu.getId().equals(it.getPid())) {
|
||||
if (menu.getChildren() == null) {
|
||||
menu.setChildren(new ArrayList<>());
|
||||
}
|
||||
menu.getChildren().add(it);
|
||||
ids.add(it.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(trees)) {
|
||||
trees = menus.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
*
|
||||
* @param menus /
|
||||
* @return /
|
||||
*/
|
||||
|
||||
public List<SystemMenuVo> buildMenuVo(List<SystemMenuTb> menus) {
|
||||
List<SystemMenuVo> list = new LinkedList<>();
|
||||
menus.forEach(menu -> {
|
||||
if (menu != null) {
|
||||
List<SystemMenuTb> menuList = menu.getChildren();
|
||||
SystemMenuVo menuVo = new SystemMenuVo();
|
||||
menuVo.setName(ObjectUtil.isNotEmpty(menu.getComponentName()) ? menu.getComponentName() : menu.getTitle());
|
||||
// 一级目录需要加斜杠,不然会报警告
|
||||
menuVo.setPath(menu.getPid() == null ? "/" + menu.getPath() : menu.getPath());
|
||||
menuVo.setHidden(menu.getHidden());
|
||||
// 如果不是外链
|
||||
if (!menu.getIFrame()) {
|
||||
if (menu.getPid() == null) {
|
||||
menuVo.setComponent(StringUtil.isEmpty(menu.getComponent()) ? "Layout" : menu.getComponent());
|
||||
// 如果不是一级菜单,并且菜单类型为目录,则代表是多级菜单
|
||||
} else if (menu.getType() == 0) {
|
||||
menuVo.setComponent(StringUtil.isEmpty(menu.getComponent()) ? "ParentView" : menu.getComponent());
|
||||
} else if (StringUtil.isNoneBlank(menu.getComponent())) {
|
||||
menuVo.setComponent(menu.getComponent());
|
||||
}
|
||||
}
|
||||
menuVo.setMeta(new SystemMenuMetaVo(menu.getTitle(), menu.getIcon(), !menu.getCache()));
|
||||
if (CollectionUtil.isNotEmpty(menuList)) {
|
||||
menuVo.setAlwaysShow(true);
|
||||
menuVo.setRedirect("noredirect");
|
||||
menuVo.setChildren(buildMenuVo(menuList));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if (menu.getPid() == null) {
|
||||
SystemMenuVo menuVo1 = getMenuVo(menu, menuVo);
|
||||
menuVo.setName(null);
|
||||
menuVo.setMeta(null);
|
||||
menuVo.setComponent("Layout");
|
||||
List<SystemMenuVo> list1 = new ArrayList<>();
|
||||
list1.add(menuVo1);
|
||||
menuVo.setChildren(list1);
|
||||
}
|
||||
list.add(menuVo);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 MenuResponse
|
||||
*
|
||||
* @param menu /
|
||||
* @param menuVo /
|
||||
* @return /
|
||||
*/
|
||||
private SystemMenuVo getMenuVo(SystemMenuTb menu, SystemMenuVo menuVo) {
|
||||
SystemMenuVo menuVo1 = new SystemMenuVo();
|
||||
menuVo1.setMeta(menuVo.getMeta());
|
||||
// 非外链
|
||||
if (!menu.getIFrame()) {
|
||||
menuVo1.setPath("index");
|
||||
menuVo1.setName(menuVo.getName());
|
||||
menuVo1.setComponent(menuVo.getComponent());
|
||||
} else {
|
||||
menuVo1.setPath(menu.getPath());
|
||||
}
|
||||
return menuVo1;
|
||||
}
|
||||
}
|
||||
|
||||
-319
@@ -1,319 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.odboy.core.constant.TransferProtocolConst;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemMenuTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemMenuArgs;
|
||||
import cn.odboy.core.dal.model.system.SystemMenuMetaVo;
|
||||
import cn.odboy.core.dal.model.system.SystemMenuVo;
|
||||
import cn.odboy.core.dal.mysql.system.SystemMenuMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMenuMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.ClassUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemMenuTb> implements SystemMenuService {
|
||||
private final SystemMenuMapper systemMenuMapper;
|
||||
private final SystemRoleMenuMapper systemRoleMenuMapper;
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
private final SystemRoleService systemRoleService;
|
||||
|
||||
private static final String YES_STR = "是";
|
||||
private static final String NO_STR = "否";
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveMenu(SystemMenuTb resources) {
|
||||
if (systemMenuMapper.getMenuByTitle(resources.getTitle()) != null) {
|
||||
throw new BadRequestException("菜单标题已存在");
|
||||
}
|
||||
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
||||
if (systemMenuMapper.getMenuByComponentName(resources.getComponentName()) != null) {
|
||||
throw new BadRequestException("菜单组件名称已存在");
|
||||
}
|
||||
}
|
||||
if (Long.valueOf(0L).equals(resources.getPid())) {
|
||||
resources.setPid(null);
|
||||
}
|
||||
if (resources.getIFrame()) {
|
||||
if (!(resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
save(resources);
|
||||
// 计算子节点数目
|
||||
resources.setSubCount(0);
|
||||
// 更新父节点菜单数目
|
||||
updateSubCnt(resources.getPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyMenuById(SystemMenuTb resources) {
|
||||
if (resources.getId().equals(resources.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
SystemMenuTb menu = getById(resources.getId());
|
||||
if (resources.getIFrame()) {
|
||||
if (!(resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
SystemMenuTb menu1 = systemMenuMapper.getMenuByTitle(resources.getTitle());
|
||||
|
||||
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||
throw new BadRequestException("菜单标题已存在");
|
||||
}
|
||||
|
||||
if (resources.getPid().equals(0L)) {
|
||||
resources.setPid(null);
|
||||
}
|
||||
|
||||
// 记录的父节点ID
|
||||
Long oldPid = menu.getPid();
|
||||
Long newPid = resources.getPid();
|
||||
|
||||
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
||||
menu1 = systemMenuMapper.getMenuByComponentName(resources.getComponentName());
|
||||
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||
throw new BadRequestException("菜单组件名称已存在");
|
||||
}
|
||||
}
|
||||
menu.setTitle(resources.getTitle());
|
||||
menu.setComponent(resources.getComponent());
|
||||
menu.setPath(resources.getPath());
|
||||
menu.setIcon(resources.getIcon());
|
||||
menu.setIFrame(resources.getIFrame());
|
||||
menu.setPid(resources.getPid());
|
||||
menu.setMenuSort(resources.getMenuSort());
|
||||
menu.setCache(resources.getCache());
|
||||
menu.setHidden(resources.getHidden());
|
||||
menu.setComponentName(resources.getComponentName());
|
||||
menu.setPermission(resources.getPermission());
|
||||
menu.setType(resources.getType());
|
||||
// auto fill
|
||||
menu.setUpdateBy(null);
|
||||
menu.setUpdateTime(null);
|
||||
saveOrUpdate(menu);
|
||||
// 计算父级菜单节点数目
|
||||
updateSubCnt(oldPid);
|
||||
updateSubCnt(newPid);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeMenuByIds(Set<SystemMenuTb> menuSet) {
|
||||
for (SystemMenuTb menu : menuSet) {
|
||||
systemRoleMenuMapper.deleteByMenuId(menu.getId());
|
||||
systemMenuMapper.deleteById(menu.getId());
|
||||
updateSubCnt(menu.getPid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadMenuExcel(List<SystemMenuTb> menus, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemMenuTb menu : menus) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("菜单标题", menu.getTitle());
|
||||
map.put("菜单类型", menu.getType() == null ? "目录" : menu.getType() == 1 ? "菜单" : "按钮");
|
||||
map.put("权限标识", menu.getPermission());
|
||||
map.put("外链菜单", menu.getIFrame() ? YES_STR : NO_STR);
|
||||
map.put("菜单可见", menu.getHidden() ? NO_STR : YES_STR);
|
||||
map.put("是否缓存", menu.getCache() ? YES_STR : NO_STR);
|
||||
map.put("创建日期", menu.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
private void updateSubCnt(Long menuId) {
|
||||
if (menuId != null) {
|
||||
int count = systemMenuMapper.getMenuCountByPid(menuId);
|
||||
systemMenuMapper.updateSubCntByMenuId(count, menuId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemMenuTb> queryMenuList(QuerySystemMenuArgs criteria, Boolean isQuery) throws Exception {
|
||||
if (Boolean.TRUE.equals(isQuery)) {
|
||||
criteria.setPidIsNull(true);
|
||||
List<Field> fields = ClassUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
||||
for (Field field : fields) {
|
||||
//设置对象的访问权限,保证对private的属性的访问
|
||||
field.setAccessible(true);
|
||||
Object val = field.get(criteria);
|
||||
if ("pidIsNull".equals(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
// 如果有查询条件,则不指定pidIsNull
|
||||
if (ObjectUtil.isNotNull(val)) {
|
||||
criteria.setPidIsNull(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return systemMenuMapper.queryMenuListByArgs(criteria);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemMenuTb queryMenuById(long id) {
|
||||
return systemMenuMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户角色改变时需清理缓存
|
||||
*
|
||||
* @param currentUserId /
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public List<SystemMenuTb> queryMenuListByUserId(Long currentUserId) {
|
||||
List<SystemRoleTb> roles = systemRoleService.queryRoleListByUsersId(currentUserId);
|
||||
Set<Long> roleIds = roles.stream().map(SystemRoleTb::getId).collect(Collectors.toSet());
|
||||
return new ArrayList<>(systemMenuMapper.queryMenuSetByRoleIdsAndType(roleIds, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SystemMenuTb> queryChildMenuSet(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) {
|
||||
for (SystemMenuTb menu : menuList) {
|
||||
menuSet.add(menu);
|
||||
List<SystemMenuTb> menus = systemMenuMapper.queryMenuListByPidOrderByMenuSort(menu.getId());
|
||||
if (CollUtil.isNotEmpty(menus)) {
|
||||
queryChildMenuSet(menus, menuSet);
|
||||
}
|
||||
}
|
||||
return menuSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemMenuTb> queryMenuListByPid(Long pid) {
|
||||
List<SystemMenuTb> menus;
|
||||
if (pid != null && !pid.equals(0L)) {
|
||||
menus = systemMenuMapper.queryMenuListByPidOrderByMenuSort(pid);
|
||||
} else {
|
||||
menus = systemMenuMapper.queryMenuListByPidIsNullOrderByMenuSort();
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemMenuTb> querySuperiorMenuList(SystemMenuTb menu, List<SystemMenuTb> menus) {
|
||||
if (menu.getPid() == null) {
|
||||
menus.addAll(systemMenuMapper.queryMenuListByPidIsNullOrderByMenuSort());
|
||||
return menus;
|
||||
}
|
||||
menus.addAll(systemMenuMapper.queryMenuListByPidOrderByMenuSort(menu.getPid()));
|
||||
return querySuperiorMenuList(queryMenuById(menu.getPid()), menus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemMenuTb> buildMenuTree(List<SystemMenuTb> menus) {
|
||||
List<SystemMenuTb> trees = new ArrayList<>();
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (SystemMenuTb menu : menus) {
|
||||
if (menu.getPid() == null) {
|
||||
trees.add(menu);
|
||||
}
|
||||
for (SystemMenuTb it : menus) {
|
||||
if (menu.getId().equals(it.getPid())) {
|
||||
if (menu.getChildren() == null) {
|
||||
menu.setChildren(new ArrayList<>());
|
||||
}
|
||||
menu.getChildren().add(it);
|
||||
ids.add(it.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(trees)) {
|
||||
trees = menus.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemMenuVo> buildMenuVo(List<SystemMenuTb> menus) {
|
||||
List<SystemMenuVo> list = new LinkedList<>();
|
||||
menus.forEach(menu -> {
|
||||
if (menu != null) {
|
||||
List<SystemMenuTb> menuList = menu.getChildren();
|
||||
SystemMenuVo menuVo = new SystemMenuVo();
|
||||
menuVo.setName(ObjectUtil.isNotEmpty(menu.getComponentName()) ? menu.getComponentName() : menu.getTitle());
|
||||
// 一级目录需要加斜杠,不然会报警告
|
||||
menuVo.setPath(menu.getPid() == null ? "/" + menu.getPath() : menu.getPath());
|
||||
menuVo.setHidden(menu.getHidden());
|
||||
// 如果不是外链
|
||||
if (!menu.getIFrame()) {
|
||||
if (menu.getPid() == null) {
|
||||
menuVo.setComponent(StringUtil.isEmpty(menu.getComponent()) ? "Layout" : menu.getComponent());
|
||||
// 如果不是一级菜单,并且菜单类型为目录,则代表是多级菜单
|
||||
} else if (menu.getType() == 0) {
|
||||
menuVo.setComponent(StringUtil.isEmpty(menu.getComponent()) ? "ParentView" : menu.getComponent());
|
||||
} else if (StringUtil.isNoneBlank(menu.getComponent())) {
|
||||
menuVo.setComponent(menu.getComponent());
|
||||
}
|
||||
}
|
||||
menuVo.setMeta(new SystemMenuMetaVo(menu.getTitle(), menu.getIcon(), !menu.getCache()));
|
||||
if (CollectionUtil.isNotEmpty(menuList)) {
|
||||
menuVo.setAlwaysShow(true);
|
||||
menuVo.setRedirect("noredirect");
|
||||
menuVo.setChildren(buildMenuVo(menuList));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if (menu.getPid() == null) {
|
||||
SystemMenuVo menuVo1 = getMenuVo(menu, menuVo);
|
||||
menuVo.setName(null);
|
||||
menuVo.setMeta(null);
|
||||
menuVo.setComponent("Layout");
|
||||
List<SystemMenuVo> list1 = new ArrayList<>();
|
||||
list1.add(menuVo1);
|
||||
menuVo.setChildren(list1);
|
||||
}
|
||||
list.add(menuVo);
|
||||
}
|
||||
}
|
||||
);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 MenuResponse
|
||||
*
|
||||
* @param menu /
|
||||
* @param menuVo /
|
||||
* @return /
|
||||
*/
|
||||
private static SystemMenuVo getMenuVo(SystemMenuTb menu, SystemMenuVo menuVo) {
|
||||
SystemMenuVo menuVo1 = new SystemMenuVo();
|
||||
menuVo1.setMeta(menuVo.getMeta());
|
||||
// 非外链
|
||||
if (!menu.getIFrame()) {
|
||||
menuVo1.setPath("index");
|
||||
menuVo1.setName(menuVo.getName());
|
||||
menuVo1.setComponent(menuVo.getComponent());
|
||||
} else {
|
||||
menuVo1.setPath(menu.getPath());
|
||||
}
|
||||
return menuVo1;
|
||||
}
|
||||
}
|
||||
+177
-3
@@ -1,13 +1,187 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import java.util.Map;
|
||||
import cn.hutool.core.date.BetweenFormatter.Level;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.IpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.hardware.VirtualMemory;
|
||||
import oshi.software.os.FileSystem;
|
||||
import oshi.software.os.OSFileStore;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.FormatUtil;
|
||||
import oshi.util.Util;
|
||||
|
||||
public interface SystemMonitorService {
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SystemMonitorService {
|
||||
private final DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
/**
|
||||
* 查询服务器监控信息
|
||||
*
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> queryServerMonitorInfo();
|
||||
public Map<String, Object> queryServerMonitorInfo() {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>(8);
|
||||
try {
|
||||
SystemInfo si = new SystemInfo();
|
||||
OperatingSystem os = si.getOperatingSystem();
|
||||
HardwareAbstractionLayer hal = si.getHardware();
|
||||
// 系统信息
|
||||
resultMap.put("sys", getSystemInfo(os));
|
||||
// cpu 信息
|
||||
resultMap.put("cpu", getCpuInfo(hal.getProcessor()));
|
||||
// 内存信息
|
||||
resultMap.put("memory", getMemoryInfo(hal.getMemory()));
|
||||
// 交换区信息
|
||||
resultMap.put("swap", getSwapInfo(hal.getMemory()));
|
||||
// 磁盘
|
||||
resultMap.put("disk", getDiskInfo(os));
|
||||
resultMap.put("time", DateUtil.format(new Date(), "HH:mm:ss"));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取磁盘信息
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getDiskInfo(OperatingSystem os) {
|
||||
Map<String, Object> diskInfo = new LinkedHashMap<>();
|
||||
FileSystem fileSystem = os.getFileSystem();
|
||||
List<OSFileStore> fsArray = fileSystem.getFileStores();
|
||||
String osName = System.getProperty("os.name");
|
||||
long available = 0, total = 0;
|
||||
for (OSFileStore fs : fsArray) {
|
||||
// windows 需要将所有磁盘分区累加,linux 和 mac 直接累加会出现磁盘重复的问题,待修复
|
||||
if (osName.toLowerCase().startsWith(SystemConst.WIN)) {
|
||||
available += fs.getUsableSpace();
|
||||
total += fs.getTotalSpace();
|
||||
} else {
|
||||
available = fs.getUsableSpace();
|
||||
total = fs.getTotalSpace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
long used = total - available;
|
||||
diskInfo.put("total", total > 0 ? FileUtil.getSize(total) : "?");
|
||||
diskInfo.put("available", FileUtil.getSize(available));
|
||||
diskInfo.put("used", FileUtil.getSize(used));
|
||||
if (total != 0) {
|
||||
diskInfo.put("usageRate", df.format(used / (double) total * 100));
|
||||
} else {
|
||||
diskInfo.put("usageRate", 0);
|
||||
}
|
||||
return diskInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取交换区信息
|
||||
*
|
||||
* @param memory /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getSwapInfo(GlobalMemory memory) {
|
||||
Map<String, Object> swapInfo = new LinkedHashMap<>();
|
||||
VirtualMemory virtualMemory = memory.getVirtualMemory();
|
||||
long total = virtualMemory.getSwapTotal();
|
||||
long used = virtualMemory.getSwapUsed();
|
||||
swapInfo.put("total", FormatUtil.formatBytes(total));
|
||||
swapInfo.put("used", FormatUtil.formatBytes(used));
|
||||
swapInfo.put("available", FormatUtil.formatBytes(total - used));
|
||||
if (used == 0) {
|
||||
swapInfo.put("usageRate", 0);
|
||||
} else {
|
||||
swapInfo.put("usageRate", df.format(used / (double) total * 100));
|
||||
}
|
||||
return swapInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存信息
|
||||
*
|
||||
* @param memory /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getMemoryInfo(GlobalMemory memory) {
|
||||
Map<String, Object> memoryInfo = new LinkedHashMap<>();
|
||||
memoryInfo.put("total", FormatUtil.formatBytes(memory.getTotal()));
|
||||
memoryInfo.put("available", FormatUtil.formatBytes(memory.getAvailable()));
|
||||
memoryInfo.put("used", FormatUtil.formatBytes(memory.getTotal() - memory.getAvailable()));
|
||||
memoryInfo.put("usageRate", df.format((memory.getTotal() - memory.getAvailable()) / (double) memory.getTotal() * 100));
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Cpu相关信息
|
||||
*
|
||||
* @param processor /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getCpuInfo(CentralProcessor processor) {
|
||||
Map<String, Object> cpuInfo = new LinkedHashMap<>();
|
||||
cpuInfo.put("name", processor.getProcessorIdentifier().getName());
|
||||
cpuInfo.put("package", processor.getPhysicalPackageCount() + "个物理CPU");
|
||||
cpuInfo.put("core", processor.getPhysicalProcessorCount() + "个物理核心");
|
||||
cpuInfo.put("coreNumber", processor.getPhysicalProcessorCount());
|
||||
cpuInfo.put("logic", processor.getLogicalProcessorCount() + "个逻辑CPU");
|
||||
// CPU信息
|
||||
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||
// 默认等待300毫秒...
|
||||
long time = 300;
|
||||
Util.sleep(time);
|
||||
long[] ticks = processor.getSystemCpuLoadTicks();
|
||||
long minCpuLoadTick = 1000;
|
||||
while (Arrays.toString(prevTicks).equals(Arrays.toString(ticks)) && time < minCpuLoadTick) {
|
||||
time += 25;
|
||||
Util.sleep(25);
|
||||
ticks = processor.getSystemCpuLoadTicks();
|
||||
}
|
||||
long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
|
||||
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
|
||||
long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
|
||||
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
|
||||
long ioWait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
|
||||
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
|
||||
long softIrq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
|
||||
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
|
||||
long totalCpu = user + nice + sys + idle + ioWait + irq + softIrq + steal;
|
||||
cpuInfo.put("used", df.format(100d * user / totalCpu + 100d * sys / totalCpu));
|
||||
cpuInfo.put("idle", df.format(100d * idle / totalCpu));
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统相关信息,系统、运行天数、系统IP
|
||||
*
|
||||
* @param os /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getSystemInfo(OperatingSystem os) {
|
||||
Map<String, Object> systemInfo = new LinkedHashMap<>();
|
||||
// jvm 运行时间
|
||||
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||
Date date = new Date(time);
|
||||
// 计算项目运行时间
|
||||
String formatBetween = DateUtil.formatBetween(date, new Date(), Level.HOUR);
|
||||
// 系统信息
|
||||
systemInfo.put("os", os.toString());
|
||||
systemInfo.put("day", formatBetween);
|
||||
systemInfo.put("ip", IpUtil.getLocalIp());
|
||||
return systemInfo;
|
||||
}
|
||||
}
|
||||
|
||||
-183
@@ -1,183 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.date.BetweenFormatter.Level;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.IpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.hardware.VirtualMemory;
|
||||
import oshi.software.os.FileSystem;
|
||||
import oshi.software.os.OSFileStore;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.FormatUtil;
|
||||
import oshi.util.Util;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SystemMonitorServiceImpl implements SystemMonitorService {
|
||||
private final DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryServerMonitorInfo() {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>(8);
|
||||
try {
|
||||
SystemInfo si = new SystemInfo();
|
||||
OperatingSystem os = si.getOperatingSystem();
|
||||
HardwareAbstractionLayer hal = si.getHardware();
|
||||
// 系统信息
|
||||
resultMap.put("sys", getSystemInfo(os));
|
||||
// cpu 信息
|
||||
resultMap.put("cpu", getCpuInfo(hal.getProcessor()));
|
||||
// 内存信息
|
||||
resultMap.put("memory", getMemoryInfo(hal.getMemory()));
|
||||
// 交换区信息
|
||||
resultMap.put("swap", getSwapInfo(hal.getMemory()));
|
||||
// 磁盘
|
||||
resultMap.put("disk", getDiskInfo(os));
|
||||
resultMap.put("time", DateUtil.format(new Date(), "HH:mm:ss"));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取磁盘信息
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getDiskInfo(OperatingSystem os) {
|
||||
Map<String, Object> diskInfo = new LinkedHashMap<>();
|
||||
FileSystem fileSystem = os.getFileSystem();
|
||||
List<OSFileStore> fsArray = fileSystem.getFileStores();
|
||||
String osName = System.getProperty("os.name");
|
||||
long available = 0, total = 0;
|
||||
for (OSFileStore fs : fsArray) {
|
||||
// windows 需要将所有磁盘分区累加,linux 和 mac 直接累加会出现磁盘重复的问题,待修复
|
||||
if (osName.toLowerCase().startsWith(SystemConst.WIN)) {
|
||||
available += fs.getUsableSpace();
|
||||
total += fs.getTotalSpace();
|
||||
} else {
|
||||
available = fs.getUsableSpace();
|
||||
total = fs.getTotalSpace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
long used = total - available;
|
||||
diskInfo.put("total", total > 0 ? FileUtil.getSize(total) : "?");
|
||||
diskInfo.put("available", FileUtil.getSize(available));
|
||||
diskInfo.put("used", FileUtil.getSize(used));
|
||||
if (total != 0) {
|
||||
diskInfo.put("usageRate", df.format(used / (double) total * 100));
|
||||
} else {
|
||||
diskInfo.put("usageRate", 0);
|
||||
}
|
||||
return diskInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取交换区信息
|
||||
*
|
||||
* @param memory /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getSwapInfo(GlobalMemory memory) {
|
||||
Map<String, Object> swapInfo = new LinkedHashMap<>();
|
||||
VirtualMemory virtualMemory = memory.getVirtualMemory();
|
||||
long total = virtualMemory.getSwapTotal();
|
||||
long used = virtualMemory.getSwapUsed();
|
||||
swapInfo.put("total", FormatUtil.formatBytes(total));
|
||||
swapInfo.put("used", FormatUtil.formatBytes(used));
|
||||
swapInfo.put("available", FormatUtil.formatBytes(total - used));
|
||||
if (used == 0) {
|
||||
swapInfo.put("usageRate", 0);
|
||||
} else {
|
||||
swapInfo.put("usageRate", df.format(used / (double) total * 100));
|
||||
}
|
||||
return swapInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存信息
|
||||
*
|
||||
* @param memory /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getMemoryInfo(GlobalMemory memory) {
|
||||
Map<String, Object> memoryInfo = new LinkedHashMap<>();
|
||||
memoryInfo.put("total", FormatUtil.formatBytes(memory.getTotal()));
|
||||
memoryInfo.put("available", FormatUtil.formatBytes(memory.getAvailable()));
|
||||
memoryInfo.put("used", FormatUtil.formatBytes(memory.getTotal() - memory.getAvailable()));
|
||||
memoryInfo.put("usageRate", df.format((memory.getTotal() - memory.getAvailable()) / (double) memory.getTotal() * 100));
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Cpu相关信息
|
||||
*
|
||||
* @param processor /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getCpuInfo(CentralProcessor processor) {
|
||||
Map<String, Object> cpuInfo = new LinkedHashMap<>();
|
||||
cpuInfo.put("name", processor.getProcessorIdentifier().getName());
|
||||
cpuInfo.put("package", processor.getPhysicalPackageCount() + "个物理CPU");
|
||||
cpuInfo.put("core", processor.getPhysicalProcessorCount() + "个物理核心");
|
||||
cpuInfo.put("coreNumber", processor.getPhysicalProcessorCount());
|
||||
cpuInfo.put("logic", processor.getLogicalProcessorCount() + "个逻辑CPU");
|
||||
// CPU信息
|
||||
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||
// 默认等待300毫秒...
|
||||
long time = 300;
|
||||
Util.sleep(time);
|
||||
long[] ticks = processor.getSystemCpuLoadTicks();
|
||||
long minCpuLoadTick = 1000;
|
||||
while (Arrays.toString(prevTicks).equals(Arrays.toString(ticks)) && time < minCpuLoadTick) {
|
||||
time += 25;
|
||||
Util.sleep(25);
|
||||
ticks = processor.getSystemCpuLoadTicks();
|
||||
}
|
||||
long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
|
||||
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
|
||||
long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
|
||||
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
|
||||
long ioWait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
|
||||
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
|
||||
long softIrq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
|
||||
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
|
||||
long totalCpu = user + nice + sys + idle + ioWait + irq + softIrq + steal;
|
||||
cpuInfo.put("used", df.format(100d * user / totalCpu + 100d * sys / totalCpu));
|
||||
cpuInfo.put("idle", df.format(100d * idle / totalCpu));
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统相关信息,系统、运行天数、系统IP
|
||||
*
|
||||
* @param os /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String, Object> getSystemInfo(OperatingSystem os) {
|
||||
Map<String, Object> systemInfo = new LinkedHashMap<>();
|
||||
// jvm 运行时间
|
||||
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||
Date date = new Date(time);
|
||||
// 计算项目运行时间
|
||||
String formatBetween = DateUtil.formatBetween(date, new Date(), Level.HOUR);
|
||||
// 系统信息
|
||||
systemInfo.put("os", os.toString());
|
||||
systemInfo.put("day", formatBetween);
|
||||
systemInfo.put("ip", IpUtil.getLocalIp());
|
||||
return systemInfo;
|
||||
}
|
||||
}
|
||||
+30
-7
@@ -1,29 +1,52 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.odboy.core.constant.TransferProtocolConst;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQiniuConfigTb;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQiniuConfigMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
public interface SystemQiniuConfigService extends IService<SystemQiniuConfigTb> {
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemQiniuConfigService {
|
||||
private final SystemQiniuConfigMapper systemQiniuConfigMapper;
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param type 类型
|
||||
* @param qiniuConfig /
|
||||
*/
|
||||
void saveQiniuConfig(SystemQiniuConfigTb type);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveQiniuConfig(SystemQiniuConfigTb qiniuConfig) {
|
||||
qiniuConfig.setId(1L);
|
||||
if (!(qiniuConfig.getHost().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || qiniuConfig.getHost().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||
}
|
||||
systemQiniuConfigMapper.insertOrUpdate(qiniuConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param type 类型
|
||||
*/
|
||||
void modifyQiniuConfigType(String type);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyQiniuConfigType(String type) {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigMapper.selectById(1L);
|
||||
qiniuConfig.setType(type);
|
||||
systemQiniuConfigMapper.insertOrUpdate(qiniuConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询配置
|
||||
*
|
||||
* @return QiniuConfig
|
||||
* @return /
|
||||
*/
|
||||
SystemQiniuConfigTb queryQiniuConfig();
|
||||
public SystemQiniuConfigTb getLastQiniuConfig() {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigMapper.selectById(1L);
|
||||
return qiniuConfig == null ? new SystemQiniuConfigTb() : qiniuConfig;
|
||||
}
|
||||
}
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.odboy.core.constant.TransferProtocolConst;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQiniuConfigTb;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQiniuConfigMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemQiniuConfigServiceImpl extends ServiceImpl<SystemQiniuConfigMapper, SystemQiniuConfigTb> implements SystemQiniuConfigService {
|
||||
private final SystemQiniuConfigMapper systemQiniuConfigMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveQiniuConfig(SystemQiniuConfigTb qiniuConfig) {
|
||||
qiniuConfig.setId(1L);
|
||||
if (!(qiniuConfig.getHost().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || qiniuConfig.getHost().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||
}
|
||||
saveOrUpdate(qiniuConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyQiniuConfigType(String type) {
|
||||
SystemQiniuConfigTb qiniuConfig = getById(1L);
|
||||
qiniuConfig.setType(type);
|
||||
saveOrUpdate(qiniuConfig);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SystemQiniuConfigTb queryQiniuConfig() {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigMapper.selectById(1L);
|
||||
return qiniuConfig == null ? new SystemQiniuConfigTb() : qiniuConfig;
|
||||
}
|
||||
}
|
||||
+179
-16
@@ -1,25 +1,91 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQiniuConfigTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQiniuContentTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemQiniuArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQiniuContentMapper;
|
||||
import cn.odboy.core.util.QiniuUtil;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.util.Auth;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemQiniuContentService {
|
||||
private final SystemQiniuContentMapper systemQiniuContentMapper;
|
||||
private final SystemQiniuConfigService systemQiniuConfigService;
|
||||
@Value("${app.oss.qiniu.max-size}")
|
||||
private Long maxSize;
|
||||
|
||||
public interface SystemQiniuContentService extends IService<SystemQiniuContentTb> {
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @return QiniuContent
|
||||
*/
|
||||
SystemQiniuContentTb uploadFile(MultipartFile file);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SystemQiniuContentTb uploadFile(MultipartFile file) {
|
||||
FileUtil.checkSize(maxSize, file.getSize());
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.getLastQiniuConfig();
|
||||
if (qiniuConfig.getId() == null) {
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
// 构造一个带指定Zone对象的配置类
|
||||
Configuration cfg = new Configuration(QiniuUtil.getRegion(qiniuConfig.getZone()));
|
||||
UploadManager uploadManager = new UploadManager(cfg);
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
String upToken = auth.uploadToken(qiniuConfig.getBucket());
|
||||
try {
|
||||
String key = file.getOriginalFilename();
|
||||
if (systemQiniuContentMapper.getQiniuContentByName(key) != null) {
|
||||
key = QiniuUtil.getKey(key);
|
||||
}
|
||||
Response response = uploadManager.put(file.getBytes(), key, upToken);
|
||||
// 解析上传成功的结果
|
||||
DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class);
|
||||
String fileNameNoExt = FileUtil.getPrefix(putRet.key);
|
||||
SystemQiniuContentTb content = systemQiniuContentMapper.getQiniuContentByName(fileNameNoExt);
|
||||
if (content == null) {
|
||||
// 存入数据库
|
||||
SystemQiniuContentTb qiniuContent = new SystemQiniuContentTb();
|
||||
qiniuContent.setSuffix(FileUtil.getSuffix(putRet.key));
|
||||
qiniuContent.setBucket(qiniuConfig.getBucket());
|
||||
qiniuContent.setType(qiniuConfig.getType());
|
||||
qiniuContent.setKey(fileNameNoExt);
|
||||
qiniuContent.setUrl(qiniuConfig.getHost() + "/" + putRet.key);
|
||||
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(String.valueOf(file.getSize()))));
|
||||
systemQiniuContentMapper.insert(qiniuContent);
|
||||
}
|
||||
return content;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件预览链接
|
||||
@@ -27,19 +93,102 @@ public interface SystemQiniuContentService extends IService<SystemQiniuContentTb
|
||||
* @param content 文件信息
|
||||
* @return String
|
||||
*/
|
||||
String createFilePreviewUrl(SystemQiniuContentTb content);
|
||||
public String createFilePreviewUrl(SystemQiniuContentTb content) {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.getLastQiniuConfig();
|
||||
String finalUrl;
|
||||
String type = "公开";
|
||||
if (type.equals(content.getType())) {
|
||||
finalUrl = content.getUrl();
|
||||
} else {
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
// 1小时,可以自定义链接过期时间
|
||||
long expireInSeconds = 3600;
|
||||
finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
|
||||
}
|
||||
return finalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param id 文件id
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeFileById(Long id) {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.getLastQiniuConfig();
|
||||
SystemQiniuContentTb qiniuContent = systemQiniuContentMapper.selectById(id);
|
||||
if (qiniuContent == null) {
|
||||
throw new BadRequestException("文件不存在");
|
||||
}
|
||||
// 构造一个带指定Zone对象的配置类
|
||||
Configuration cfg = new Configuration(QiniuUtil.getRegion(qiniuConfig.getZone()));
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
try {
|
||||
bucketManager.delete(qiniuContent.getBucket(), qiniuContent.getKey() + "." + qiniuContent.getSuffix());
|
||||
} catch (QiniuException ex) {
|
||||
log.error("七牛云删除文件失败", ex);
|
||||
} finally {
|
||||
systemQiniuContentMapper.deleteById(qiniuContent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
*/
|
||||
void synchronize();
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void synchronize() {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.getLastQiniuConfig();
|
||||
if (qiniuConfig.getId() == null) {
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
//构造一个带指定Zone对象的配置类
|
||||
Configuration cfg = new Configuration(QiniuUtil.getRegion(qiniuConfig.getZone()));
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
//文件名前缀
|
||||
String prefix = "";
|
||||
//每次迭代的长度限制,最大1000,推荐值 1000
|
||||
int limit = 1000;
|
||||
//指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
|
||||
String delimiter = "";
|
||||
//列举空间文件列表
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(qiniuConfig.getBucket(), prefix, limit, delimiter);
|
||||
while (fileListIterator.hasNext()) {
|
||||
//处理获取的file list结果
|
||||
SystemQiniuContentTb qiniuContent;
|
||||
FileInfo[] items = fileListIterator.next();
|
||||
for (FileInfo item : items) {
|
||||
String filename = FileUtil.getPrefix(item.key);
|
||||
String suffix = FileUtil.getSuffix(item.key);
|
||||
if (systemQiniuContentMapper.getQiniuContentByName(filename) == null) {
|
||||
qiniuContent = new SystemQiniuContentTb();
|
||||
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(String.valueOf(item.fsize))));
|
||||
qiniuContent.setSuffix(suffix);
|
||||
qiniuContent.setKey(filename);
|
||||
qiniuContent.setType(qiniuConfig.getType());
|
||||
qiniuContent.setBucket(qiniuConfig.getBucket());
|
||||
qiniuContent.setUrl(qiniuConfig.getHost() + "/" + item.key);
|
||||
systemQiniuContentMapper.insert(qiniuContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param ids 文件ID数组
|
||||
*/
|
||||
void removeFileByIds(Long[] ids);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeFileByIds(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
SystemQiniuContentTb qiniuContent = systemQiniuContentMapper.selectById(id);
|
||||
if (qiniuContent != null) {
|
||||
removeFileById(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
@@ -48,14 +197,20 @@ public interface SystemQiniuContentService extends IService<SystemQiniuContentTb
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadExcel(List<SystemQiniuContentTb> queryAll, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param id 文件id
|
||||
*/
|
||||
void removeFileById(Long id);
|
||||
public void exportQiniuContentExcel(List<SystemQiniuContentTb> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemQiniuContentTb content : queryAll) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("文件名", content.getKey());
|
||||
map.put("文件类型", content.getSuffix());
|
||||
map.put("空间名称", content.getBucket());
|
||||
map.put("文件大小", content.getSize());
|
||||
map.put("空间类型", content.getType());
|
||||
map.put("创建日期", content.getUpdateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
@@ -64,7 +219,9 @@ public interface SystemQiniuContentService extends IService<SystemQiniuContentTb
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<List<SystemQiniuContentTb>> queryQiniuContentPage(QuerySystemQiniuArgs criteria, Page<SystemQiniuContentTb> page);
|
||||
public CsResultVo<List<SystemQiniuContentTb>> queryQiniuContentByArgs(QuerySystemQiniuArgs criteria, Page<SystemQiniuContentTb> page) {
|
||||
return CsPageUtil.toPage(systemQiniuContentMapper.selectQiniuContentByArgs(criteria, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
@@ -72,5 +229,11 @@ public interface SystemQiniuContentService extends IService<SystemQiniuContentTb
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<SystemQiniuContentTb> queryQiniuContentList(QuerySystemQiniuArgs criteria);
|
||||
public List<SystemQiniuContentTb> queryQiniuContentByArgs(QuerySystemQiniuArgs criteria) {
|
||||
return systemQiniuContentMapper.selectQiniuContentByArgs(criteria, CsPageUtil.getCount(systemQiniuContentMapper)).getRecords();
|
||||
}
|
||||
|
||||
public SystemQiniuContentTb getQiniuContentById(Long id) {
|
||||
return systemQiniuContentMapper.selectById(id);
|
||||
}
|
||||
}
|
||||
|
||||
-197
@@ -1,197 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQiniuConfigTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQiniuContentTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemQiniuArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQiniuContentMapper;
|
||||
import cn.odboy.core.util.QiniuUtil;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.util.Auth;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemQiniuContentServiceImpl extends ServiceImpl<SystemQiniuContentMapper, SystemQiniuContentTb> implements SystemQiniuContentService {
|
||||
private final SystemQiniuContentMapper systemQiniuContentMapper;
|
||||
private final SystemQiniuConfigService systemQiniuConfigService;
|
||||
@Value("${app.oss.qiniu.max-size}")
|
||||
private Long maxSize;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SystemQiniuContentTb uploadFile(MultipartFile file) {
|
||||
FileUtil.checkSize(maxSize, file.getSize());
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.queryQiniuConfig();
|
||||
if (qiniuConfig.getId() == null) {
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
// 构造一个带指定Zone对象的配置类
|
||||
Configuration cfg = new Configuration(QiniuUtil.getRegion(qiniuConfig.getZone()));
|
||||
UploadManager uploadManager = new UploadManager(cfg);
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
String upToken = auth.uploadToken(qiniuConfig.getBucket());
|
||||
try {
|
||||
String key = file.getOriginalFilename();
|
||||
if (systemQiniuContentMapper.getQiniuContentByName(key) != null) {
|
||||
key = QiniuUtil.getKey(key);
|
||||
}
|
||||
Response response = uploadManager.put(file.getBytes(), key, upToken);
|
||||
// 解析上传成功的结果
|
||||
DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class);
|
||||
String fileNameNoExt = FileUtil.getPrefix(putRet.key);
|
||||
SystemQiniuContentTb content = systemQiniuContentMapper.getQiniuContentByName(fileNameNoExt);
|
||||
if (content == null) {
|
||||
// 存入数据库
|
||||
SystemQiniuContentTb qiniuContent = new SystemQiniuContentTb();
|
||||
qiniuContent.setSuffix(FileUtil.getSuffix(putRet.key));
|
||||
qiniuContent.setBucket(qiniuConfig.getBucket());
|
||||
qiniuContent.setType(qiniuConfig.getType());
|
||||
qiniuContent.setKey(fileNameNoExt);
|
||||
qiniuContent.setUrl(qiniuConfig.getHost() + "/" + putRet.key);
|
||||
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(String.valueOf(file.getSize()))));
|
||||
save(qiniuContent);
|
||||
}
|
||||
return content;
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createFilePreviewUrl(SystemQiniuContentTb content) {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.queryQiniuConfig();
|
||||
String finalUrl;
|
||||
String type = "公开";
|
||||
if (type.equals(content.getType())) {
|
||||
finalUrl = content.getUrl();
|
||||
} else {
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
// 1小时,可以自定义链接过期时间
|
||||
long expireInSeconds = 3600;
|
||||
finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
|
||||
}
|
||||
return finalUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeFileById(Long id) {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.queryQiniuConfig();
|
||||
SystemQiniuContentTb qiniuContent = systemQiniuContentMapper.selectById(id);
|
||||
if (qiniuContent == null) {
|
||||
throw new BadRequestException("文件不存在");
|
||||
}
|
||||
// 构造一个带指定Zone对象的配置类
|
||||
Configuration cfg = new Configuration(QiniuUtil.getRegion(qiniuConfig.getZone()));
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
try {
|
||||
bucketManager.delete(qiniuContent.getBucket(), qiniuContent.getKey() + "." + qiniuContent.getSuffix());
|
||||
} catch (QiniuException ex) {
|
||||
log.error("七牛云删除文件失败", ex);
|
||||
} finally {
|
||||
removeById(qiniuContent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void synchronize() {
|
||||
SystemQiniuConfigTb qiniuConfig = systemQiniuConfigService.queryQiniuConfig();
|
||||
if (qiniuConfig.getId() == null) {
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
//构造一个带指定Zone对象的配置类
|
||||
Configuration cfg = new Configuration(QiniuUtil.getRegion(qiniuConfig.getZone()));
|
||||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
//文件名前缀
|
||||
String prefix = "";
|
||||
//每次迭代的长度限制,最大1000,推荐值 1000
|
||||
int limit = 1000;
|
||||
//指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
|
||||
String delimiter = "";
|
||||
//列举空间文件列表
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(qiniuConfig.getBucket(), prefix, limit, delimiter);
|
||||
while (fileListIterator.hasNext()) {
|
||||
//处理获取的file list结果
|
||||
SystemQiniuContentTb qiniuContent;
|
||||
FileInfo[] items = fileListIterator.next();
|
||||
for (FileInfo item : items) {
|
||||
String filename = FileUtil.getPrefix(item.key);
|
||||
String suffix = FileUtil.getSuffix(item.key);
|
||||
if (systemQiniuContentMapper.getQiniuContentByName(filename) == null) {
|
||||
qiniuContent = new SystemQiniuContentTb();
|
||||
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(String.valueOf(item.fsize))));
|
||||
qiniuContent.setSuffix(suffix);
|
||||
qiniuContent.setKey(filename);
|
||||
qiniuContent.setType(qiniuConfig.getType());
|
||||
qiniuContent.setBucket(qiniuConfig.getBucket());
|
||||
qiniuContent.setUrl(qiniuConfig.getHost() + "/" + item.key);
|
||||
save(qiniuContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeFileByIds(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
SystemQiniuContentTb qiniuContent = getById(id);
|
||||
if (qiniuContent != null) {
|
||||
removeFileById(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadExcel(List<SystemQiniuContentTb> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemQiniuContentTb content : queryAll) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("文件名", content.getKey());
|
||||
map.put("文件类型", content.getSuffix());
|
||||
map.put("空间名称", content.getBucket());
|
||||
map.put("文件大小", content.getSize());
|
||||
map.put("空间类型", content.getType());
|
||||
map.put("创建日期", content.getUpdateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemQiniuContentTb>> queryQiniuContentPage(QuerySystemQiniuArgs criteria, Page<SystemQiniuContentTb> page) {
|
||||
return PageUtil.toPage(systemQiniuContentMapper.queryQiniuContentPageByArgs(criteria, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemQiniuContentTb> queryQiniuContentList(QuerySystemQiniuArgs criteria) {
|
||||
return systemQiniuContentMapper.queryQiniuContentPageByArgs(criteria, PageUtil.getCount(systemQiniuContentMapper)).getRecords();
|
||||
}
|
||||
}
|
||||
+179
-35
@@ -1,63 +1,182 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQuartzJobTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQuartzLogTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemQuartzJobArgs;
|
||||
import cn.odboy.core.dal.model.system.UpdateSystemQuartzJobArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQuartzJobMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQuartzLogMapper;
|
||||
import cn.odboy.core.framework.quartz.core.QuartzManage;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.redis.RedisHelper;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.quartz.CronExpression;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemQuartzJobService {
|
||||
private final SystemQuartzJobMapper systemQuartzJobMapper;
|
||||
private final SystemQuartzLogMapper systemQuartzLogMapper;
|
||||
private final QuartzManage quartzManage;
|
||||
private final RedisHelper redisHelper;
|
||||
|
||||
public interface SystemQuartzJobService extends IService<SystemQuartzJobTb> {
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void createJob(SystemQuartzJobTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createJob(SystemQuartzJobTb resources) {
|
||||
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
||||
throw new BadRequestException("cron表达式格式错误");
|
||||
}
|
||||
systemQuartzJobMapper.insert(resources);
|
||||
quartzManage.addJob(resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改任务并重新调度
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyQuartzJobResumeCron(UpdateSystemQuartzJobArgs resources);
|
||||
|
||||
/**
|
||||
* 删除任务
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void removeJobByIds(Set<Long> ids);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyQuartzJobResumeCron(UpdateSystemQuartzJobArgs resources) {
|
||||
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
||||
throw new BadRequestException("cron表达式格式错误");
|
||||
}
|
||||
if (StringUtil.isNotBlank(resources.getSubTask())) {
|
||||
List<String> tasks = Arrays.asList(resources.getSubTask().split("[,,]"));
|
||||
if (tasks.contains(resources.getId().toString())) {
|
||||
throw new BadRequestException("子任务中不能添加当前任务ID");
|
||||
}
|
||||
}
|
||||
SystemQuartzJobTb quartzJob = BeanUtil.copyProperties(resources, SystemQuartzJobTb.class);
|
||||
systemQuartzJobMapper.insertOrUpdate(quartzJob);
|
||||
quartzManage.updateJobCron(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改定时任务状态
|
||||
*
|
||||
* @param quartzJob /
|
||||
*/
|
||||
void switchQuartzJobStatus(SystemQuartzJobTb quartzJob);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void switchQuartzJobStatus(SystemQuartzJobTb quartzJob) {
|
||||
// 置换暂停状态
|
||||
if (quartzJob.getIsPause()) {
|
||||
quartzManage.resumeJob(quartzJob);
|
||||
quartzJob.setIsPause(false);
|
||||
} else {
|
||||
quartzManage.pauseJob(quartzJob);
|
||||
quartzJob.setIsPause(true);
|
||||
}
|
||||
systemQuartzJobMapper.insertOrUpdate(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即执行定时任务
|
||||
*
|
||||
* @param quartzJob /
|
||||
*/
|
||||
void startQuartzJob(SystemQuartzJobTb quartzJob);
|
||||
|
||||
public void startQuartzJob(SystemQuartzJobTb quartzJob) {
|
||||
quartzManage.runJobNow(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeJobByIds(Set<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
SystemQuartzJobTb quartzJob = systemQuartzJobMapper.selectById(id);
|
||||
quartzManage.deleteJob(quartzJob);
|
||||
systemQuartzJobMapper.deleteById(quartzJob);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行子任务
|
||||
*
|
||||
* @param tasks /
|
||||
* @throws InterruptedException /
|
||||
*/
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void startSubQuartJob(String[] tasks) throws InterruptedException {
|
||||
for (String id : tasks) {
|
||||
if (StrUtil.isBlank(id)) {
|
||||
// 如果是手动清除子任务id,会出现id为空字符串的问题
|
||||
continue;
|
||||
}
|
||||
SystemQuartzJobTb quartzJob = systemQuartzJobMapper.selectById(Long.parseLong(id));
|
||||
if (quartzJob == null) {
|
||||
// 防止子任务不存在
|
||||
continue;
|
||||
}
|
||||
// 执行任务
|
||||
String uuid = IdUtil.simpleUUID();
|
||||
quartzJob.setUuid(uuid);
|
||||
// 执行任务
|
||||
startQuartzJob(quartzJob);
|
||||
// 获取执行状态,如果执行失败则停止后面的子任务执行
|
||||
Boolean result = redisHelper.get(uuid, Boolean.class);
|
||||
while (result == null) {
|
||||
// 休眠5秒,再次获取子任务执行情况
|
||||
Thread.sleep(5000);
|
||||
result = redisHelper.get(uuid, Boolean.class);
|
||||
}
|
||||
if (!result) {
|
||||
redisHelper.del(uuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出定时任务
|
||||
*
|
||||
* @param queryAll 待导出的数据
|
||||
* @param response /
|
||||
* @param quartzJobs 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadQuartzJobExcel(List<SystemQuartzJobTb> queryAll, HttpServletResponse response) throws IOException;
|
||||
|
||||
public void exportQuartzJobExcel(List<SystemQuartzJobTb> quartzJobs, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemQuartzJobTb quartzJob : quartzJobs) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("任务名称", quartzJob.getJobName());
|
||||
map.put("Bean名称", quartzJob.getBeanName());
|
||||
map.put("执行方法", quartzJob.getMethodName());
|
||||
map.put("参数", quartzJob.getParams());
|
||||
map.put("表达式", quartzJob.getCronExpression());
|
||||
map.put("状态", quartzJob.getIsPause() ? "暂停中" : "运行中");
|
||||
map.put("描述", quartzJob.getDescription());
|
||||
map.put("创建日期", quartzJob.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出定时任务日志
|
||||
@@ -66,15 +185,24 @@ public interface SystemQuartzJobService extends IService<SystemQuartzJobTb> {
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadQuartzLogExcel(List<SystemQuartzLogTb> queryAllLog, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 执行子任务
|
||||
*
|
||||
* @param tasks /
|
||||
* @throws InterruptedException /
|
||||
*/
|
||||
void startSubQuartJob(String[] tasks) throws InterruptedException;
|
||||
public void exportQuartzLogExcel(List<SystemQuartzLogTb> queryAllLog, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemQuartzLogTb quartzLog : queryAllLog) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("任务名称", quartzLog.getJobName());
|
||||
map.put("Bean名称", quartzLog.getBeanName());
|
||||
map.put("执行方法", quartzLog.getMethodName());
|
||||
map.put("参数", quartzLog.getParams());
|
||||
map.put("表达式", quartzLog.getCronExpression());
|
||||
map.put("异常详情", quartzLog.getExceptionDetail());
|
||||
map.put("耗时/毫秒", quartzLog.getTime());
|
||||
map.put("状态", quartzLog.getIsSuccess() ? "成功" : "失败");
|
||||
map.put("创建日期", quartzLog.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
@@ -83,15 +211,10 @@ public interface SystemQuartzJobService extends IService<SystemQuartzJobTb> {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<List<SystemQuartzJobTb>> queryQuartzJobPage(QuerySystemQuartzJobArgs criteria, Page<SystemQuartzJobTb> page);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<SystemQuartzJobTb> queryQuartzJobList(QuerySystemQuartzJobArgs criteria);
|
||||
public CsResultVo<List<SystemQuartzJobTb>> queryQuartzJobByArgs(QuerySystemQuartzJobArgs criteria, Page<SystemQuartzJobTb> page) {
|
||||
return CsPageUtil.toPage(systemQuartzJobMapper.selectQuartzJobByArgs(criteria, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询日志
|
||||
@@ -100,7 +223,10 @@ public interface SystemQuartzJobService extends IService<SystemQuartzJobTb> {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<List<SystemQuartzLogTb>> queryQuartzLogPage(QuerySystemQuartzJobArgs criteria, Page<SystemQuartzLogTb> page);
|
||||
|
||||
public CsResultVo<List<SystemQuartzLogTb>> queryQuartzLogByArgs(QuerySystemQuartzJobArgs criteria, Page<SystemQuartzLogTb> page) {
|
||||
return CsPageUtil.toPage(systemQuartzLogMapper.selectQuartzLogByArgs(criteria, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
@@ -108,5 +234,23 @@ public interface SystemQuartzJobService extends IService<SystemQuartzJobTb> {
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<SystemQuartzLogTb> queryQuartzLogList(QuerySystemQuartzJobArgs criteria);
|
||||
|
||||
public List<SystemQuartzJobTb> queryQuartzJobByArgs(QuerySystemQuartzJobArgs criteria) {
|
||||
return systemQuartzJobMapper.selectQuartzJobByArgs(criteria, CsPageUtil.getCount(systemQuartzJobMapper)).getRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
|
||||
public List<SystemQuartzLogTb> queryQuartzLogByArgs(QuerySystemQuartzJobArgs criteria) {
|
||||
return systemQuartzLogMapper.selectQuartzLogByArgs(criteria, CsPageUtil.getCount(systemQuartzLogMapper)).getRecords();
|
||||
}
|
||||
|
||||
public SystemQuartzJobTb getQuartzJobById(Long id) {
|
||||
return systemQuartzJobMapper.selectById(id);
|
||||
}
|
||||
}
|
||||
|
||||
-183
@@ -1,183 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQuartzJobTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemQuartzLogTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemQuartzJobArgs;
|
||||
import cn.odboy.core.dal.model.system.UpdateSystemQuartzJobArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQuartzJobMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemQuartzLogMapper;
|
||||
import cn.odboy.core.framework.quartz.core.QuartzManage;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.redis.RedisHelper;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.quartz.CronExpression;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Service(value = "quartzJobService")
|
||||
public class SystemQuartzJobServiceImpl extends ServiceImpl<SystemQuartzJobMapper, SystemQuartzJobTb> implements SystemQuartzJobService {
|
||||
private final SystemQuartzJobMapper systemQuartzJobMapper;
|
||||
private final SystemQuartzLogMapper systemQuartzLogMapper;
|
||||
private final QuartzManage quartzManage;
|
||||
private final RedisHelper redisHelper;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createJob(SystemQuartzJobTb resources) {
|
||||
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
||||
throw new BadRequestException("cron表达式格式错误");
|
||||
}
|
||||
save(resources);
|
||||
quartzManage.addJob(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyQuartzJobResumeCron(UpdateSystemQuartzJobArgs resources) {
|
||||
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
||||
throw new BadRequestException("cron表达式格式错误");
|
||||
}
|
||||
if (StringUtil.isNotBlank(resources.getSubTask())) {
|
||||
List<String> tasks = Arrays.asList(resources.getSubTask().split("[,,]"));
|
||||
if (tasks.contains(resources.getId().toString())) {
|
||||
throw new BadRequestException("子任务中不能添加当前任务ID");
|
||||
}
|
||||
}
|
||||
SystemQuartzJobTb quartzJob = BeanUtil.copyProperties(resources, SystemQuartzJobTb.class);
|
||||
saveOrUpdate(quartzJob);
|
||||
quartzManage.updateJobCron(quartzJob);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void switchQuartzJobStatus(SystemQuartzJobTb quartzJob) {
|
||||
// 置换暂停状态
|
||||
if (quartzJob.getIsPause()) {
|
||||
quartzManage.resumeJob(quartzJob);
|
||||
quartzJob.setIsPause(false);
|
||||
} else {
|
||||
quartzManage.pauseJob(quartzJob);
|
||||
quartzJob.setIsPause(true);
|
||||
}
|
||||
saveOrUpdate(quartzJob);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startQuartzJob(SystemQuartzJobTb quartzJob) {
|
||||
quartzManage.runJobNow(quartzJob);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeJobByIds(Set<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
SystemQuartzJobTb quartzJob = getById(id);
|
||||
quartzManage.deleteJob(quartzJob);
|
||||
removeById(quartzJob);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void startSubQuartJob(String[] tasks) throws InterruptedException {
|
||||
for (String id : tasks) {
|
||||
if (StrUtil.isBlank(id)) {
|
||||
// 如果是手动清除子任务id,会出现id为空字符串的问题
|
||||
continue;
|
||||
}
|
||||
SystemQuartzJobTb quartzJob = getById(Long.parseLong(id));
|
||||
if (quartzJob == null) {
|
||||
// 防止子任务不存在
|
||||
continue;
|
||||
}
|
||||
// 执行任务
|
||||
String uuid = IdUtil.simpleUUID();
|
||||
quartzJob.setUuid(uuid);
|
||||
// 执行任务
|
||||
startQuartzJob(quartzJob);
|
||||
// 获取执行状态,如果执行失败则停止后面的子任务执行
|
||||
Boolean result = redisHelper.get(uuid, Boolean.class);
|
||||
while (result == null) {
|
||||
// 休眠5秒,再次获取子任务执行情况
|
||||
Thread.sleep(5000);
|
||||
result = redisHelper.get(uuid, Boolean.class);
|
||||
}
|
||||
if (!result) {
|
||||
redisHelper.del(uuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadQuartzJobExcel(List<SystemQuartzJobTb> quartzJobs, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemQuartzJobTb quartzJob : quartzJobs) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("任务名称", quartzJob.getJobName());
|
||||
map.put("Bean名称", quartzJob.getBeanName());
|
||||
map.put("执行方法", quartzJob.getMethodName());
|
||||
map.put("参数", quartzJob.getParams());
|
||||
map.put("表达式", quartzJob.getCronExpression());
|
||||
map.put("状态", quartzJob.getIsPause() ? "暂停中" : "运行中");
|
||||
map.put("描述", quartzJob.getDescription());
|
||||
map.put("创建日期", quartzJob.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadQuartzLogExcel(List<SystemQuartzLogTb> queryAllLog, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemQuartzLogTb quartzLog : queryAllLog) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("任务名称", quartzLog.getJobName());
|
||||
map.put("Bean名称", quartzLog.getBeanName());
|
||||
map.put("执行方法", quartzLog.getMethodName());
|
||||
map.put("参数", quartzLog.getParams());
|
||||
map.put("表达式", quartzLog.getCronExpression());
|
||||
map.put("异常详情", quartzLog.getExceptionDetail());
|
||||
map.put("耗时/毫秒", quartzLog.getTime());
|
||||
map.put("状态", quartzLog.getIsSuccess() ? "成功" : "失败");
|
||||
map.put("创建日期", quartzLog.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemQuartzJobTb>> queryQuartzJobPage(QuerySystemQuartzJobArgs criteria, Page<SystemQuartzJobTb> page) {
|
||||
return PageUtil.toPage(systemQuartzJobMapper.queryQuartzJobPageByArgs(criteria, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemQuartzLogTb>> queryQuartzLogPage(QuerySystemQuartzJobArgs criteria, Page<SystemQuartzLogTb> page) {
|
||||
return PageUtil.toPage(systemQuartzLogMapper.queryQuartzLogPageByArgs(criteria, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemQuartzJobTb> queryQuartzJobList(QuerySystemQuartzJobArgs criteria) {
|
||||
return systemQuartzJobMapper.queryQuartzJobPageByArgs(criteria, PageUtil.getCount(systemQuartzJobMapper)).getRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemQuartzLogTb> queryQuartzLogList(QuerySystemQuartzJobArgs criteria) {
|
||||
return systemQuartzLogMapper.queryQuartzLogPageByArgs(criteria, PageUtil.getCount(systemQuartzLogMapper)).getRecords();
|
||||
}
|
||||
}
|
||||
+152
-37
@@ -1,92 +1,172 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemMenuTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemUserTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemRoleArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemRoleArgs;
|
||||
import cn.odboy.core.dal.model.system.SystemRoleCodeVo;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleDeptMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMenuMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public interface SystemRoleService extends IService<SystemRoleTb> {
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemRoleService {
|
||||
private final SystemRoleMapper systemRoleMapper;
|
||||
private final SystemRoleDeptMapper systemRoleDeptMapper;
|
||||
private final SystemRoleMenuMapper systemRoleMenuMapper;
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void saveRole(CreateSystemRoleArgs resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveRole(CreateSystemRoleArgs resources) {
|
||||
if (systemRoleMapper.getRoleByName(resources.getName()) != null) {
|
||||
throw new BadRequestException("角色名称已存在");
|
||||
}
|
||||
systemRoleMapper.insert(BeanUtil.copyProperties(resources, SystemRoleTb.class));
|
||||
// 判断是否有部门数据,若有,则需创建关联
|
||||
if (CollectionUtil.isNotEmpty(resources.getDepts())) {
|
||||
systemRoleDeptMapper.batchInsertRoleDept(resources.getDepts(), resources.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* 修改
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyRoleById(SystemRoleTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyRoleById(SystemRoleTb resources) {
|
||||
SystemRoleTb role = systemRoleMapper.selectById(resources.getId());
|
||||
SystemRoleTb role1 = systemRoleMapper.getRoleByName(resources.getName());
|
||||
if (role1 != null && !role1.getId().equals(role.getId())) {
|
||||
throw new BadRequestException("角色名称已存在");
|
||||
}
|
||||
role.setName(resources.getName());
|
||||
role.setDescription(resources.getDescription());
|
||||
role.setDataScope(resources.getDataScope());
|
||||
role.setDepts(resources.getDepts());
|
||||
role.setLevel(resources.getLevel());
|
||||
// 更新
|
||||
systemRoleMapper.insertOrUpdate(role);
|
||||
// 删除关联部门数据
|
||||
systemRoleDeptMapper.batchDeleteRoleDept(Collections.singleton(resources.getId()));
|
||||
// 判断是否有部门数据,若有,则需更新关联
|
||||
if (CollectionUtil.isNotEmpty(resources.getDepts())) {
|
||||
systemRoleDeptMapper.batchInsertRoleDept(resources.getDepts(), resources.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改绑定的菜单
|
||||
*
|
||||
* @param resources /
|
||||
* @param role /
|
||||
*/
|
||||
void modifyBindMenuById(SystemRoleTb resources);
|
||||
|
||||
public void modifyBindMenuById(SystemRoleTb role) {
|
||||
// 更新菜单
|
||||
systemRoleMenuMapper.deleteRoleMenuByRoleId(role.getId());
|
||||
// 判断是否为空
|
||||
if (CollUtil.isNotEmpty(role.getMenus())) {
|
||||
systemRoleMenuMapper.batchInsertRoleMenu(role.getMenus(), role.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void removeRoleByIds(Set<Long> ids);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeRoleByIds(Set<Long> ids) {
|
||||
systemRoleMapper.deleteByIds(ids);
|
||||
// 删除角色部门关联数据、角色菜单关联数据
|
||||
systemRoleDeptMapper.batchDeleteRoleDept(ids);
|
||||
systemRoleMenuMapper.batchDeleteRoleMenu(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param roles 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
* @throws IOException
|
||||
*/
|
||||
void downloadRoleExcel(List<SystemRoleTb> roles, HttpServletResponse response) throws IOException;
|
||||
|
||||
public void exportRoleExcel(List<SystemRoleTb> roles, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemRoleTb role : roles) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("角色名称", role.getName());
|
||||
map.put("角色级别", role.getLevel());
|
||||
map.put("描述", role.getDescription());
|
||||
map.put("创建日期", role.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
* 查询全部角色
|
||||
*
|
||||
* @return /
|
||||
* @return
|
||||
*/
|
||||
List<SystemRoleTb> queryRoleList();
|
||||
|
||||
public List<SystemRoleTb> queryAllRole() {
|
||||
return systemRoleMapper.selectAllRole();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
* 根据条件查询全部角色
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
* @return
|
||||
*/
|
||||
List<SystemRoleTb> queryRoleList(QuerySystemRoleArgs criteria);
|
||||
|
||||
public List<SystemRoleTb> queryRoleByArgs(QuerySystemRoleArgs criteria) {
|
||||
return systemRoleMapper.selectRoleByArgs(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* 待条件分页查询
|
||||
* 分页查询角色
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
* @return
|
||||
*/
|
||||
CsResultVo<List<SystemRoleTb>> queryRolePage(QuerySystemRoleArgs criteria, Page<Object> page);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
SystemRoleTb queryRoleById(long id);
|
||||
public CsResultVo<List<SystemRoleTb>> queryRoleByArgs(QuerySystemRoleArgs criteria, Page<Object> page) {
|
||||
criteria.setOffset(page.offset());
|
||||
List<SystemRoleTb> roles = systemRoleMapper.selectRoleByArgs(criteria);
|
||||
Long total = systemRoleMapper.countRoleByArgs(criteria);
|
||||
return CsPageUtil.toPage(roles, total);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -95,7 +175,10 @@ public interface SystemRoleService extends IService<SystemRoleTb> {
|
||||
* @param userId 用户ID
|
||||
* @return /
|
||||
*/
|
||||
List<SystemRoleTb> queryRoleListByUsersId(Long userId);
|
||||
|
||||
public List<SystemRoleTb> queryRoleByUsersId(Long userId) {
|
||||
return systemRoleMapper.selectRoleByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色查询角色级别
|
||||
@@ -103,7 +186,17 @@ public interface SystemRoleService extends IService<SystemRoleTb> {
|
||||
* @param roles /
|
||||
* @return /
|
||||
*/
|
||||
Integer queryDeptLevelByRoles(Set<SystemRoleTb> roles);
|
||||
|
||||
public Integer getDeptLevelByRoles(Set<SystemRoleTb> roles) {
|
||||
if (CollUtil.isEmpty(roles)) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
Set<SystemRoleTb> roleSet = new HashSet<>();
|
||||
for (SystemRoleTb role : roles) {
|
||||
roleSet.add(getRoleById(role.getId()));
|
||||
}
|
||||
return Collections.min(roleSet.stream().map(SystemRoleTb::getLevel).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限信息
|
||||
@@ -111,20 +204,42 @@ public interface SystemRoleService extends IService<SystemRoleTb> {
|
||||
* @param user 用户信息
|
||||
* @return 权限信息
|
||||
*/
|
||||
List<SystemRoleCodeVo> buildUserRolePermissions(SystemUserTb user);
|
||||
|
||||
public List<SystemRoleCodeVo> buildUserRolePermissions(SystemUserTb user) {
|
||||
Set<String> permissions = new HashSet<>();
|
||||
// 如果是管理员直接返回
|
||||
if (user.getIsAdmin()) {
|
||||
permissions.add("admin");
|
||||
return permissions.stream().map(SystemRoleCodeVo::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
List<SystemRoleTb> roles = systemRoleMapper.selectRoleByUserId(user.getId());
|
||||
permissions = roles.stream().flatMap(role -> role.getMenus().stream())
|
||||
.map(SystemMenuTb::getPermission)
|
||||
.filter(StringUtil::isNotBlank).collect(Collectors.toSet());
|
||||
return permissions.stream().map(SystemRoleCodeVo::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否被用户关联
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void verifyBindRelationByIds(Set<Long> ids);
|
||||
|
||||
public void verifyBindRelationByIds(Set<Long> ids) {
|
||||
if (systemUserMapper.countUserByRoleIds(ids) > 0) {
|
||||
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单Id查询
|
||||
* 根据ID查询
|
||||
*
|
||||
* @param menuId /
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
List<SystemRoleTb> queryRoleListByMenuId(Long menuId);
|
||||
public SystemRoleTb getRoleById(Long id) {
|
||||
return systemRoleMapper.selectById(id);
|
||||
}
|
||||
}
|
||||
|
||||
-178
@@ -1,178 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemMenuTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemUserTb;
|
||||
import cn.odboy.core.dal.model.system.CreateSystemRoleArgs;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemRoleArgs;
|
||||
import cn.odboy.core.dal.model.system.SystemRoleCodeVo;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleDeptMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemRoleMenuMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemRoleServiceImpl extends ServiceImpl<SystemRoleMapper, SystemRoleTb> implements SystemRoleService {
|
||||
private final SystemRoleMapper systemRoleMapper;
|
||||
private final SystemRoleDeptMapper systemRoleDeptMapper;
|
||||
private final SystemRoleMenuMapper systemRoleMenuMapper;
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveRole(CreateSystemRoleArgs resources) {
|
||||
if (systemRoleMapper.getRoleByName(resources.getName()) != null) {
|
||||
throw new BadRequestException("角色名称已存在");
|
||||
}
|
||||
save(BeanUtil.copyProperties(resources, SystemRoleTb.class));
|
||||
// 判断是否有部门数据,若有,则需创建关联
|
||||
if (CollectionUtil.isNotEmpty(resources.getDepts())) {
|
||||
systemRoleDeptMapper.insertBatchWithRoleId(resources.getDepts(), resources.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyRoleById(SystemRoleTb resources) {
|
||||
SystemRoleTb role = getById(resources.getId());
|
||||
SystemRoleTb role1 = systemRoleMapper.getRoleByName(resources.getName());
|
||||
if (role1 != null && !role1.getId().equals(role.getId())) {
|
||||
throw new BadRequestException("角色名称已存在");
|
||||
}
|
||||
role.setName(resources.getName());
|
||||
role.setDescription(resources.getDescription());
|
||||
role.setDataScope(resources.getDataScope());
|
||||
role.setDepts(resources.getDepts());
|
||||
role.setLevel(resources.getLevel());
|
||||
// 更新
|
||||
saveOrUpdate(role);
|
||||
// 删除关联部门数据
|
||||
systemRoleDeptMapper.deleteByRoleId(resources.getId());
|
||||
// 判断是否有部门数据,若有,则需更新关联
|
||||
if (CollectionUtil.isNotEmpty(resources.getDepts())) {
|
||||
systemRoleDeptMapper.insertBatchWithRoleId(resources.getDepts(), resources.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyBindMenuById(SystemRoleTb role) {
|
||||
List<SystemUserTb> users = systemUserMapper.queryUserListByRoleId(role.getId());
|
||||
// 更新菜单
|
||||
systemRoleMenuMapper.deleteByRoleId(role.getId());
|
||||
// 判断是否为空
|
||||
if (CollUtil.isNotEmpty(role.getMenus())) {
|
||||
systemRoleMenuMapper.insertBatchWithRoleId(role.getMenus(), role.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeRoleByIds(Set<Long> ids) {
|
||||
removeBatchByIds(ids);
|
||||
// 删除角色部门关联数据、角色菜单关联数据
|
||||
systemRoleDeptMapper.deleteByRoleIds(ids);
|
||||
systemRoleMenuMapper.deleteByRoleIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadRoleExcel(List<SystemRoleTb> roles, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemRoleTb role : roles) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("角色名称", role.getName());
|
||||
map.put("角色级别", role.getLevel());
|
||||
map.put("描述", role.getDescription());
|
||||
map.put("创建日期", role.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemRoleTb> queryRoleList() {
|
||||
return systemRoleMapper.queryRoleList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemRoleTb> queryRoleList(QuerySystemRoleArgs criteria) {
|
||||
return systemRoleMapper.queryRoleListByArgs(criteria);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemRoleTb>> queryRolePage(QuerySystemRoleArgs criteria, Page<Object> page) {
|
||||
criteria.setOffset(page.offset());
|
||||
List<SystemRoleTb> roles = systemRoleMapper.queryRoleListByArgs(criteria);
|
||||
Long total = systemRoleMapper.getRoleCountByArgs(criteria);
|
||||
return PageUtil.toPage(roles, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemRoleTb queryRoleById(long id) {
|
||||
return systemRoleMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemRoleTb> queryRoleListByUsersId(Long userId) {
|
||||
return systemRoleMapper.queryRoleListByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer queryDeptLevelByRoles(Set<SystemRoleTb> roles) {
|
||||
if (CollUtil.isEmpty(roles)) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
Set<SystemRoleTb> roleSet = new HashSet<>();
|
||||
for (SystemRoleTb role : roles) {
|
||||
roleSet.add(queryRoleById(role.getId()));
|
||||
}
|
||||
return Collections.min(roleSet.stream().map(SystemRoleTb::getLevel).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemRoleCodeVo> buildUserRolePermissions(SystemUserTb user) {
|
||||
Set<String> permissions = new HashSet<>();
|
||||
// 如果是管理员直接返回
|
||||
if (user.getIsAdmin()) {
|
||||
permissions.add("admin");
|
||||
return permissions.stream().map(SystemRoleCodeVo::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
List<SystemRoleTb> roles = systemRoleMapper.queryRoleListByUserId(user.getId());
|
||||
permissions = roles.stream().flatMap(role -> role.getMenus().stream())
|
||||
.map(SystemMenuTb::getPermission)
|
||||
.filter(StringUtil::isNotBlank).collect(Collectors.toSet());
|
||||
return permissions.stream().map(SystemRoleCodeVo::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verifyBindRelationByIds(Set<Long> ids) {
|
||||
if (systemUserMapper.getUserCountByRoleIds(ids) > 0) {
|
||||
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemRoleTb> queryRoleListByMenuId(Long menuId) {
|
||||
return systemRoleMapper.queryRoleListByMenuId(menuId);
|
||||
}
|
||||
}
|
||||
+254
-50
@@ -1,25 +1,70 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemJobTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemUserTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemUserArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserJobMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserRoleMapper;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserInfoDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineInfoDAO;
|
||||
import cn.odboy.core.framework.permission.core.SecurityHelper;
|
||||
import cn.odboy.core.framework.properties.AppProperties;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.CsPageUtil;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemUserService {
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
private final SystemUserJobMapper systemUserJobMapper;
|
||||
private final SystemUserRoleMapper systemUserRoleMapper;
|
||||
private final AppProperties properties;
|
||||
private final SystemUserInfoDAO systemUserInfoDAO;
|
||||
private final SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
|
||||
|
||||
public interface SystemUserService extends IService<SystemUserTb> {
|
||||
/**
|
||||
* 新增用户
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void saveUser(SystemUserTb resources);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveUser(SystemUserTb resources) {
|
||||
resources.setDeptId(resources.getDept().getId());
|
||||
if (systemUserMapper.getUserByUsername(resources.getUsername()) != null) {
|
||||
throw new BadRequestException("用户名已存在");
|
||||
}
|
||||
if (systemUserMapper.getUserByEmail(resources.getEmail()) != null) {
|
||||
throw new BadRequestException("邮箱已存在");
|
||||
}
|
||||
if (systemUserMapper.getUserByPhone(resources.getPhone()) != null) {
|
||||
throw new BadRequestException("手机号已存在");
|
||||
}
|
||||
systemUserMapper.insert(resources);
|
||||
// 保存用户岗位
|
||||
systemUserJobMapper.batchInsertUserJob(resources.getJobs(), resources.getId());
|
||||
// 保存用户角色
|
||||
systemUserRoleMapper.batchInsertUserRole(resources.getRoles(), resources.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑用户
|
||||
@@ -27,14 +72,86 @@ public interface SystemUserService extends IService<SystemUserTb> {
|
||||
* @param resources /
|
||||
* @throws Exception /
|
||||
*/
|
||||
void modifyUserById(SystemUserTb resources) throws Exception;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserById(SystemUserTb resources) {
|
||||
SystemUserTb user = systemUserMapper.selectById(resources.getId());
|
||||
SystemUserTb user1 = systemUserMapper.getUserByUsername(resources.getUsername());
|
||||
SystemUserTb user2 = systemUserMapper.getUserByEmail(resources.getEmail());
|
||||
SystemUserTb user3 = systemUserMapper.getUserByPhone(resources.getPhone());
|
||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||
throw new BadRequestException("用户名已存在");
|
||||
}
|
||||
if (user2 != null && !user.getId().equals(user2.getId())) {
|
||||
throw new BadRequestException("邮箱已存在");
|
||||
}
|
||||
if (user3 != null && !user.getId().equals(user3.getId())) {
|
||||
throw new BadRequestException("手机号已存在");
|
||||
}
|
||||
// 如果用户被禁用,则清除用户登录信息
|
||||
if (!resources.getEnabled()) {
|
||||
systemUserOnlineInfoDAO.kickOutByUsername(resources.getUsername());
|
||||
}
|
||||
user.setDeptId(resources.getDept().getId());
|
||||
user.setUsername(resources.getUsername());
|
||||
user.setEmail(resources.getEmail());
|
||||
user.setEnabled(resources.getEnabled());
|
||||
user.setRoles(resources.getRoles());
|
||||
user.setDept(resources.getDept());
|
||||
user.setJobs(resources.getJobs());
|
||||
user.setPhone(resources.getPhone());
|
||||
user.setNickName(resources.getNickName());
|
||||
user.setGender(resources.getGender());
|
||||
systemUserMapper.insertOrUpdate(user);
|
||||
// 清除用户登录缓存
|
||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(user.getUsername());
|
||||
// 更新用户岗位
|
||||
systemUserJobMapper.batchDeleteUserJob(Collections.singleton(resources.getId()));
|
||||
systemUserJobMapper.batchInsertUserJob(resources.getJobs(), resources.getId());
|
||||
// 更新用户角色
|
||||
systemUserRoleMapper.batchDeleteUserRole(Collections.singleton(resources.getId()));
|
||||
systemUserRoleMapper.batchInsertUserRole(resources.getRoles(), resources.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户自助修改资料
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserCenterInfoById(SystemUserTb resources) {
|
||||
SystemUserTb user = systemUserMapper.selectById(resources.getId());
|
||||
SystemUserTb user1 = systemUserMapper.getUserByPhone(resources.getPhone());
|
||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||
throw new BadRequestException("手机号已存在");
|
||||
}
|
||||
user.setNickName(resources.getNickName());
|
||||
user.setPhone(resources.getPhone());
|
||||
user.setGender(resources.getGender());
|
||||
systemUserMapper.insertOrUpdate(user);
|
||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(user.getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void removeUserByIds(Set<Long> ids);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeUserByIds(Set<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
// 清理缓存
|
||||
SystemUserTb user = systemUserMapper.selectById(id);
|
||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(user.getUsername());
|
||||
}
|
||||
systemUserMapper.deleteByIds(ids);
|
||||
// 删除用户岗位
|
||||
systemUserJobMapper.batchDeleteUserJob(ids);
|
||||
// 删除用户角色
|
||||
systemUserRoleMapper.batchDeleteUserRole(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
@@ -42,39 +159,12 @@ public interface SystemUserService extends IService<SystemUserTb> {
|
||||
* @param username 用户名
|
||||
* @param encryptPassword 密码
|
||||
*/
|
||||
void modifyUserPasswordByUsername(String username, String encryptPassword);
|
||||
|
||||
/**
|
||||
* 修改头像
|
||||
*
|
||||
* @param file 文件
|
||||
* @return /
|
||||
*/
|
||||
Map<String, String> modifyUserAvatar(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 修改邮箱
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param email 邮箱
|
||||
*/
|
||||
void modifyUserEmailByUsername(String username, String email);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param queryAll 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadUserExcel(List<SystemUserTb> queryAll, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 用户自助修改资料
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void modifyUserCenterInfoById(SystemUserTb resources);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserPasswordByUsername(String username, String encryptPassword) {
|
||||
systemUserMapper.updateUserPasswordByUsername(username, encryptPassword);
|
||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
@@ -82,24 +172,96 @@ public interface SystemUserService extends IService<SystemUserTb> {
|
||||
* @param ids 用户id
|
||||
* @param password 密码
|
||||
*/
|
||||
void resetUserPasswordByIds(Set<Long> ids, String password);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void resetUserPasswordByIds(Set<Long> ids, String password) {
|
||||
List<SystemUserTb> users = systemUserMapper.selectByIds(ids);
|
||||
// 清除缓存
|
||||
users.forEach(user -> {
|
||||
// 清除缓存
|
||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(user.getUsername());
|
||||
// 强制退出
|
||||
systemUserOnlineInfoDAO.kickOutByUsername(user.getUsername());
|
||||
});
|
||||
// 重置密码
|
||||
systemUserMapper.batchUpdatePassword(password, ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* 修改头像
|
||||
*
|
||||
* @param id ID
|
||||
* @param multipartFile 文件
|
||||
* @return /
|
||||
*/
|
||||
SystemUserTb queryUserById(long id);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, String> modifyUserAvatar(MultipartFile multipartFile) {
|
||||
SystemUserTb user = systemUserMapper.getUserByUsername(SecurityHelper.getCurrentUsername());
|
||||
String username = user.getUsername();
|
||||
if (StrUtil.isBlank(username)) {
|
||||
throw new BadRequestException("异常用户数据,请联系管理员处理");
|
||||
}
|
||||
// 文件大小验证
|
||||
FileUtil.checkSize(properties.getFile().getAvatarMaxSize(), multipartFile.getSize());
|
||||
// 验证文件上传的格式
|
||||
String image = "gif jpg png jpeg";
|
||||
String fileType = FileUtil.getSuffix(multipartFile.getOriginalFilename());
|
||||
if (fileType != null && !image.contains(fileType)) {
|
||||
throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式");
|
||||
}
|
||||
String oldPath = user.getAvatarPath();
|
||||
File file = FileUtil.upload(multipartFile, properties.getFile().getPath().getAvatar());
|
||||
user.setAvatarPath(Objects.requireNonNull(file).getPath());
|
||||
user.setAvatarName(file.getName());
|
||||
systemUserMapper.insertOrUpdate(user);
|
||||
if (StringUtil.isNotBlank(oldPath)) {
|
||||
FileUtil.del(oldPath);
|
||||
}
|
||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(username);
|
||||
return new HashMap<>(1) {{
|
||||
put("avatar", file.getName());
|
||||
}};
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询
|
||||
* 修改邮箱
|
||||
*
|
||||
* @param username /
|
||||
* @return /
|
||||
* @param username 用户名
|
||||
* @param email 邮箱
|
||||
*/
|
||||
SystemUserTb queryUserByUsername(String username);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserEmailByUsername(String username, String email) {
|
||||
systemUserMapper.updateUserEmailByUsername(username, email);
|
||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param users 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
|
||||
public void exportUserExcel(List<SystemUserTb> users, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemUserTb user : users) {
|
||||
List<String> roles = user.getRoles().stream().map(SystemRoleTb::getName).collect(Collectors.toList());
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", user.getUsername());
|
||||
map.put("角色", roles);
|
||||
map.put("部门", user.getDept().getName());
|
||||
map.put("岗位", user.getJobs().stream().map(SystemJobTb::getName).collect(Collectors.toList()));
|
||||
map.put("邮箱", user.getEmail());
|
||||
map.put("状态", user.getEnabled() ? "启用" : "禁用");
|
||||
map.put("手机号码", user.getPhone());
|
||||
map.put("修改密码的时间", user.getPwdResetTime());
|
||||
map.put("创建日期", user.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
@@ -108,7 +270,13 @@ public interface SystemUserService extends IService<SystemUserTb> {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
CsResultVo<List<SystemUserTb>> queryUserPage(QuerySystemUserArgs criteria, Page<Object> page);
|
||||
|
||||
public CsResultVo<List<SystemUserTb>> queryUserByArgs(QuerySystemUserArgs criteria, Page<Object> page) {
|
||||
criteria.setOffset(page.offset());
|
||||
List<SystemUserTb> users = systemUserMapper.selectUserByArgs(criteria, CsPageUtil.getCount(systemUserMapper)).getRecords();
|
||||
Long total = systemUserMapper.countUserByArgs(criteria);
|
||||
return CsPageUtil.toPage(users, total);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部不分页
|
||||
@@ -116,5 +284,41 @@ public interface SystemUserService extends IService<SystemUserTb> {
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<SystemUserTb> queryUserList(QuerySystemUserArgs criteria);
|
||||
|
||||
public List<SystemUserTb> queryUserByArgs(QuerySystemUserArgs criteria) {
|
||||
return systemUserMapper.selectUserByArgs(criteria, CsPageUtil.getCount(systemUserMapper)).getRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return /
|
||||
*/
|
||||
|
||||
public SystemUserTb getUserById(long id) {
|
||||
return systemUserMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询
|
||||
*
|
||||
* @param username /
|
||||
* @return /
|
||||
*/
|
||||
|
||||
public SystemUserTb getUserByUsername(String username) {
|
||||
return systemUserMapper.getUserByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页模糊查询
|
||||
*
|
||||
* @param wrapper
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
public IPage<SystemUserTb> queryUserByBlurry(LambdaQueryWrapper<SystemUserTb> wrapper, Page<SystemUserTb> page) {
|
||||
return systemUserMapper.selectPage(page, wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
-241
@@ -1,241 +0,0 @@
|
||||
package cn.odboy.core.service.system;
|
||||
|
||||
import cn.odboy.base.CsResultVo;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemJobTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemRoleTb;
|
||||
import cn.odboy.core.dal.dataobject.system.SystemUserTb;
|
||||
import cn.odboy.core.dal.model.system.QuerySystemUserArgs;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserJobMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserMapper;
|
||||
import cn.odboy.core.dal.mysql.system.SystemUserRoleMapper;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserJwtDAO;
|
||||
import cn.odboy.core.dal.redis.system.SystemUserOnlineDAO;
|
||||
import cn.odboy.core.framework.permission.core.SecurityHelper;
|
||||
import cn.odboy.core.framework.properties.AppProperties;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.util.FileUtil;
|
||||
import cn.odboy.util.PageUtil;
|
||||
import cn.odboy.util.StringUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUserTb> implements SystemUserService {
|
||||
private final SystemUserMapper systemUserMapper;
|
||||
private final SystemUserJobMapper systemUserJobMapper;
|
||||
private final SystemUserRoleMapper systemUserRoleMapper;
|
||||
private final AppProperties properties;
|
||||
private final SystemUserJwtDAO systemUserJwtDAO;
|
||||
private final SystemUserOnlineDAO systemUserOnlineDAO;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveUser(SystemUserTb resources) {
|
||||
resources.setDeptId(resources.getDept().getId());
|
||||
if (systemUserMapper.getUserByUsername(resources.getUsername()) != null) {
|
||||
throw new BadRequestException("用户名已存在");
|
||||
}
|
||||
if (systemUserMapper.getUserByEmail(resources.getEmail()) != null) {
|
||||
throw new BadRequestException("邮箱已存在");
|
||||
}
|
||||
if (systemUserMapper.getUserByPhone(resources.getPhone()) != null) {
|
||||
throw new BadRequestException("手机号已存在");
|
||||
}
|
||||
save(resources);
|
||||
// 保存用户岗位
|
||||
systemUserJobMapper.insertBatchWithUserId(resources.getJobs(), resources.getId());
|
||||
// 保存用户角色
|
||||
systemUserRoleMapper.insertBatchWithUserId(resources.getRoles(), resources.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserById(SystemUserTb resources) {
|
||||
SystemUserTb user = getById(resources.getId());
|
||||
SystemUserTb user1 = systemUserMapper.getUserByUsername(resources.getUsername());
|
||||
SystemUserTb user2 = systemUserMapper.getUserByEmail(resources.getEmail());
|
||||
SystemUserTb user3 = systemUserMapper.getUserByPhone(resources.getPhone());
|
||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||
throw new BadRequestException("用户名已存在");
|
||||
}
|
||||
if (user2 != null && !user.getId().equals(user2.getId())) {
|
||||
throw new BadRequestException("邮箱已存在");
|
||||
}
|
||||
if (user3 != null && !user.getId().equals(user3.getId())) {
|
||||
throw new BadRequestException("手机号已存在");
|
||||
}
|
||||
// 如果用户被禁用,则清除用户登录信息
|
||||
if (!resources.getEnabled()) {
|
||||
systemUserOnlineDAO.kickOutByUsername(resources.getUsername());
|
||||
}
|
||||
user.setDeptId(resources.getDept().getId());
|
||||
user.setUsername(resources.getUsername());
|
||||
user.setEmail(resources.getEmail());
|
||||
user.setEnabled(resources.getEnabled());
|
||||
user.setRoles(resources.getRoles());
|
||||
user.setDept(resources.getDept());
|
||||
user.setJobs(resources.getJobs());
|
||||
user.setPhone(resources.getPhone());
|
||||
user.setNickName(resources.getNickName());
|
||||
user.setGender(resources.getGender());
|
||||
saveOrUpdate(user);
|
||||
// 清除用户登录缓存
|
||||
flushLoginCacheInfo(user.getUsername());
|
||||
// 更新用户岗位
|
||||
systemUserJobMapper.deleteByUserId(resources.getId());
|
||||
systemUserJobMapper.insertBatchWithUserId(resources.getJobs(), resources.getId());
|
||||
// 更新用户角色
|
||||
systemUserRoleMapper.deleteByUserId(resources.getId());
|
||||
systemUserRoleMapper.insertBatchWithUserId(resources.getRoles(), resources.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserCenterInfoById(SystemUserTb resources) {
|
||||
SystemUserTb user = getById(resources.getId());
|
||||
SystemUserTb user1 = systemUserMapper.getUserByPhone(resources.getPhone());
|
||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||
throw new BadRequestException("手机号已存在");
|
||||
}
|
||||
user.setNickName(resources.getNickName());
|
||||
user.setPhone(resources.getPhone());
|
||||
user.setGender(resources.getGender());
|
||||
saveOrUpdate(user);
|
||||
flushLoginCacheInfo(user.getUsername());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeUserByIds(Set<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
// 清理缓存
|
||||
SystemUserTb user = getById(id);
|
||||
flushLoginCacheInfo(user.getUsername());
|
||||
}
|
||||
systemUserMapper.deleteByIds(ids);
|
||||
// 删除用户岗位
|
||||
systemUserJobMapper.deleteByUserIds(ids);
|
||||
// 删除用户角色
|
||||
systemUserRoleMapper.deleteByUserIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserPasswordByUsername(String username, String pass) {
|
||||
systemUserMapper.updatePasswordByUsername(username, pass, new Date());
|
||||
flushLoginCacheInfo(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void resetUserPasswordByIds(Set<Long> ids, String password) {
|
||||
List<SystemUserTb> users = systemUserMapper.selectByIds(ids);
|
||||
// 清除缓存
|
||||
users.forEach(user -> {
|
||||
// 清除缓存
|
||||
flushLoginCacheInfo(user.getUsername());
|
||||
// 强制退出
|
||||
systemUserOnlineDAO.kickOutByUsername(user.getUsername());
|
||||
});
|
||||
// 重置密码
|
||||
systemUserMapper.updatePasswordByUserIds(password, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, String> modifyUserAvatar(MultipartFile multipartFile) {
|
||||
// 文件大小验证
|
||||
FileUtil.checkSize(properties.getFile().getAvatarMaxSize(), multipartFile.getSize());
|
||||
// 验证文件上传的格式
|
||||
String image = "gif jpg png jpeg";
|
||||
String fileType = FileUtil.getSuffix(multipartFile.getOriginalFilename());
|
||||
if (fileType != null && !image.contains(fileType)) {
|
||||
throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式");
|
||||
}
|
||||
SystemUserTb user = systemUserMapper.getUserByUsername(SecurityHelper.getCurrentUsername());
|
||||
String oldPath = user.getAvatarPath();
|
||||
File file = FileUtil.upload(multipartFile, properties.getFile().getPath().getAvatar());
|
||||
user.setAvatarPath(Objects.requireNonNull(file).getPath());
|
||||
user.setAvatarName(file.getName());
|
||||
saveOrUpdate(user);
|
||||
if (StringUtil.isNotBlank(oldPath)) {
|
||||
FileUtil.del(oldPath);
|
||||
}
|
||||
@NotBlank String username = user.getUsername();
|
||||
flushLoginCacheInfo(username);
|
||||
return new HashMap<>(1) {{
|
||||
put("avatar", file.getName());
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifyUserEmailByUsername(String username, String email) {
|
||||
systemUserMapper.updateEmailByUsername(username, email);
|
||||
flushLoginCacheInfo(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadUserExcel(List<SystemUserTb> users, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SystemUserTb user : users) {
|
||||
List<String> roles = user.getRoles().stream().map(SystemRoleTb::getName).collect(Collectors.toList());
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", user.getUsername());
|
||||
map.put("角色", roles);
|
||||
map.put("部门", user.getDept().getName());
|
||||
map.put("岗位", user.getJobs().stream().map(SystemJobTb::getName).collect(Collectors.toList()));
|
||||
map.put("邮箱", user.getEmail());
|
||||
map.put("状态", user.getEnabled() ? "启用" : "禁用");
|
||||
map.put("手机号码", user.getPhone());
|
||||
map.put("修改密码的时间", user.getPwdResetTime());
|
||||
map.put("创建日期", user.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理 登陆时 用户缓存信息
|
||||
*
|
||||
* @param username /
|
||||
*/
|
||||
private void flushLoginCacheInfo(String username) {
|
||||
systemUserJwtDAO.cleanUserJwtModelCacheByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsResultVo<List<SystemUserTb>> queryUserPage(QuerySystemUserArgs criteria, Page<Object> page) {
|
||||
criteria.setOffset(page.offset());
|
||||
List<SystemUserTb> users = systemUserMapper.queryUserPageByArgs(criteria, PageUtil.getCount(systemUserMapper)).getRecords();
|
||||
Long total = systemUserMapper.getUserCountByArgs(criteria);
|
||||
return PageUtil.toPage(users, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemUserTb> queryUserList(QuerySystemUserArgs criteria) {
|
||||
return systemUserMapper.queryUserPageByArgs(criteria, PageUtil.getCount(systemUserMapper)).getRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemUserTb queryUserById(long id) {
|
||||
return systemUserMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemUserTb queryUserByUsername(String username) {
|
||||
return systemUserMapper.getUserByUsername(username);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
<select id="queryDeptListByArgs" resultMap="BaseResultMap">
|
||||
<select id="selectDeptByArgs" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
dept_id,
|
||||
`name`,
|
||||
@@ -52,7 +52,7 @@
|
||||
</where>
|
||||
ORDER BY dept_sort
|
||||
</select>
|
||||
<select id="queryDeptListByPid" resultMap="BaseResultMap">
|
||||
<select id="selectDeptByPid" resultMap="BaseResultMap">
|
||||
select dept_id,
|
||||
name,
|
||||
pid,
|
||||
@@ -66,12 +66,12 @@
|
||||
from system_dept
|
||||
where pid = #{pid}
|
||||
</select>
|
||||
<select id="getDeptCountByPid" resultType="java.lang.Integer">
|
||||
<select id="countDeptByPid" resultType="java.lang.Integer">
|
||||
select count(*)
|
||||
from system_dept
|
||||
where pid = #{pid}
|
||||
</select>
|
||||
<select id="queryDeptListByPidIsNull" resultMap="BaseResultMap">
|
||||
<select id="selectDeptByPidIsNull" resultMap="BaseResultMap">
|
||||
select dept_id,
|
||||
name,
|
||||
pid,
|
||||
@@ -85,7 +85,7 @@
|
||||
from system_dept
|
||||
where pid is null
|
||||
</select>
|
||||
<select id="queryDeptSetByRoleId" resultType="cn.odboy.core.dal.dataobject.system.SystemDeptTb">
|
||||
<select id="selectDeptByRoleId" resultType="cn.odboy.core.dal.dataobject.system.SystemDeptTb">
|
||||
SELECT d.dept_id AS id,
|
||||
d.NAME,
|
||||
d.pid,
|
||||
@@ -101,7 +101,7 @@
|
||||
WHERE d.dept_id = rd.dept_id
|
||||
AND rd.role_id = #{roleId}
|
||||
</select>
|
||||
<update id="updateSubCountById">
|
||||
<update id="updateDeptSubCountById">
|
||||
update system_dept
|
||||
set sub_count = #{count}
|
||||
where dept_id = #{id}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
from system_job
|
||||
where name = #{name}
|
||||
</select>
|
||||
<select id="queryJobPageByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemJobTb">
|
||||
<select id="selectJobByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemJobTb">
|
||||
select
|
||||
*
|
||||
from system_job
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.odboy.core.dal.mysql.system.SystemLocalStorageMapper">
|
||||
<select id="queryLocalStoragePageByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemLocalStorageTb">
|
||||
<select id="selectLocalStorageByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemLocalStorageTb">
|
||||
select
|
||||
*
|
||||
from system_local_storage
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
<select id="queryMenuListByArgs" resultMap="BaseResultMap">
|
||||
<select id="selectMenuByArgs" resultMap="BaseResultMap">
|
||||
select
|
||||
menu_id, title, name, menu_sort, component, path, type, permission, icon, cache, hidden, pid, sub_count,
|
||||
i_frame, create_by, update_by, create_time, update_time
|
||||
@@ -46,7 +46,7 @@
|
||||
</where>
|
||||
order by menu_sort
|
||||
</select>
|
||||
<select id="queryMenuSetByRoleIdsAndType" resultMap="BaseResultMap">
|
||||
<select id="selectMenuByRoleIdsAndType" resultMap="BaseResultMap">
|
||||
SELECT m.* FROM system_menu m, system_roles_menus r
|
||||
WHERE m.menu_id = r.menu_id AND r.role_id IN
|
||||
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
||||
@@ -55,7 +55,7 @@
|
||||
AND type != #{type}
|
||||
order by m.menu_sort
|
||||
</select>
|
||||
<select id="queryMenuListByPidIsNullOrderByMenuSort" resultMap="BaseResultMap">
|
||||
<select id="selectMenuByPidIsNullOrderByMenuSort" resultMap="BaseResultMap">
|
||||
SELECT menu_id,
|
||||
title,
|
||||
name,
|
||||
@@ -78,7 +78,7 @@
|
||||
where pid is null
|
||||
order by menu_sort
|
||||
</select>
|
||||
<select id="queryMenuListByPidOrderByMenuSort" resultMap="BaseResultMap">
|
||||
<select id="selectMenuByPidOrderByMenuSort" resultMap="BaseResultMap">
|
||||
SELECT menu_id,
|
||||
title,
|
||||
name,
|
||||
@@ -111,12 +111,12 @@
|
||||
FROM system_menu
|
||||
WHERE name = #{name}
|
||||
</select>
|
||||
<select id="getMenuCountByPid" resultType="java.lang.Integer">
|
||||
<select id="countMenuByPid" resultType="java.lang.Integer">
|
||||
SELECT count(*)
|
||||
FROM system_menu
|
||||
WHERE pid = #{pid}
|
||||
</select>
|
||||
<update id="updateSubCntByMenuId">
|
||||
<update id="updateMenuSubCntByMenuId">
|
||||
update system_menu
|
||||
set sub_count = #{count}
|
||||
where menu_id = #{menuId}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
WHERE name = #{name}
|
||||
</select>
|
||||
|
||||
<select id="queryQiniuContentPageByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemQiniuContentTb">
|
||||
<select id="selectQiniuContentByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemQiniuContentTb">
|
||||
SELECT
|
||||
*
|
||||
FROM system_qiniu_content
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.odboy.core.dal.mysql.system.SystemQuartzJobMapper">
|
||||
<select id="queryQuartzJobPageByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemQuartzJobTb">
|
||||
<select id="selectQuartzJobByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemQuartzJobTb">
|
||||
SELECT
|
||||
*
|
||||
FROM system_quartz_job
|
||||
@@ -15,7 +15,7 @@
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
<select id="queryActiveQuartzJobList" resultType="cn.odboy.core.dal.dataobject.system.SystemQuartzJobTb">
|
||||
<select id="selectAllEnableQuartzJob" resultType="cn.odboy.core.dal.dataobject.system.SystemQuartzJobTb">
|
||||
SELECT *
|
||||
FROM system_quartz_job
|
||||
WHERE is_pause = 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.odboy.core.dal.mysql.system.SystemQuartzLogMapper">
|
||||
<select id="queryQuartzLogPageByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemQuartzLogTb">
|
||||
<select id="selectQuartzLogByArgs" resultType="cn.odboy.core.dal.dataobject.system.SystemQuartzLogTb">
|
||||
SELECT
|
||||
*
|
||||
FROM system_quartz_log
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.odboy.core.dal.mysql.system.SystemRoleDeptMapper">
|
||||
<insert id="insertBatchWithRoleId">
|
||||
<insert id="batchInsertRoleDept">
|
||||
insert into system_roles_depts (role_id, dept_id)
|
||||
values
|
||||
<foreach collection="depts" item="item" open="(" separator="),(" close=")">
|
||||
@@ -9,13 +9,7 @@
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByRoleId">
|
||||
delete
|
||||
from system_roles_depts
|
||||
where role_id = #{roleId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByRoleIds">
|
||||
<delete id="batchDeleteRoleDept">
|
||||
delete from system_roles_depts
|
||||
where role_id in
|
||||
<foreach collection="roleIds" item="id" open="(" separator="," close=")">
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
<result column="dept_name" property="name"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="queryRoleList" resultType="cn.odboy.core.dal.dataobject.system.SystemRoleTb">
|
||||
<select id="selectAllRole" resultType="cn.odboy.core.dal.dataobject.system.SystemRoleTb">
|
||||
select role_id as id, name, level
|
||||
from system_role
|
||||
order by level
|
||||
</select>
|
||||
<select id="queryRoleListByArgs" resultMap="BaseResultMap">
|
||||
<select id="selectRoleByArgs" resultMap="BaseResultMap">
|
||||
select role.*,
|
||||
dept.dept_id as dept_id, dept.name as dept_name,
|
||||
menu.menu_id as menu_id, menu.title as menu_title, menu.permission as menu_permission
|
||||
@@ -58,7 +58,7 @@
|
||||
left join system_dept dept on dept.dept_id = srd.dept_id
|
||||
order by role.role_level
|
||||
</select>
|
||||
<select id="getRoleCountByArgs" resultType="java.lang.Long">
|
||||
<select id="countRoleByArgs" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from system_role role
|
||||
<where>
|
||||
@@ -100,7 +100,7 @@
|
||||
left join system_dept dept on dept.dept_id = srd.dept_id
|
||||
where role.role_id = #{roleId}
|
||||
</select>
|
||||
<select id="queryRoleListByUserId" resultMap="BaseResultMap">
|
||||
<select id="selectRoleByUserId" resultMap="BaseResultMap">
|
||||
SELECT role.role_id as role_role_id,
|
||||
role.name as role_name,
|
||||
role.data_scope as role_data_scope,
|
||||
@@ -124,7 +124,7 @@
|
||||
WHERE role.role_id = ur.role_id
|
||||
AND ur.user_id = #{userId}
|
||||
</select>
|
||||
<select id="getRoleCountByDeptIds" resultType="int">
|
||||
<select id="countRoleByDeptIds" resultType="int">
|
||||
select count(*)
|
||||
from system_role r, system_roles_depts d
|
||||
where r.role_id = d.role_id
|
||||
@@ -133,7 +133,7 @@
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="queryRoleListByMenuId" resultType="cn.odboy.core.dal.dataobject.system.SystemRoleTb">
|
||||
<select id="selectRoleByMenuId" resultType="cn.odboy.core.dal.dataobject.system.SystemRoleTb">
|
||||
SELECT role.role_id as id
|
||||
FROM system_role role,
|
||||
system_roles_menus rm
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.odboy.core.dal.mysql.system.SystemRoleMenuMapper">
|
||||
<insert id="insertBatchWithRoleId">
|
||||
<insert id="batchInsertRoleMenu">
|
||||
insert into system_roles_menus (role_id, menu_id)
|
||||
values
|
||||
<foreach collection="menus" item="item" open="(" separator="),(" close=")">
|
||||
#{roleId}, #{item.id}
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByRoleId">
|
||||
delete
|
||||
from system_roles_menus
|
||||
where role_id = #{roleId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByRoleIds">
|
||||
<delete id="batchDeleteRoleMenu">
|
||||
delete from system_roles_menus
|
||||
where role_id in
|
||||
<foreach collection="roleIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByMenuId">
|
||||
<delete id="deleteRoleMenuByRoleId">
|
||||
delete
|
||||
from system_roles_menus
|
||||
where role_id = #{roleId}
|
||||
</delete>
|
||||
<delete id="deleteRoleMenuByMenuId">
|
||||
delete
|
||||
from system_roles_menus
|
||||
where menu_id = #{menuId}
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.odboy.core.dal.mysql.system.SystemUserJobMapper">
|
||||
<insert id="insertBatchWithUserId">
|
||||
<insert id="batchInsertUserJob">
|
||||
insert into system_users_jobs (user_id, job_id)
|
||||
values
|
||||
<foreach collection="jobs" item="item" open="(" separator="),(" close=")">
|
||||
#{userId}, #{item.id}
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByUserId">
|
||||
delete
|
||||
from system_users_jobs
|
||||
where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByUserIds">
|
||||
<delete id="batchDeleteUserJob">
|
||||
delete from system_users_jobs
|
||||
where user_id in
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<result column="role_data_scope" property="dataScope"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="getUserCountByArgs" resultType="java.lang.Long">
|
||||
<select id="countUserByArgs" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from system_user u
|
||||
<where>
|
||||
@@ -62,7 +62,7 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="queryUserPageByArgs" resultMap="BaseResultMap">
|
||||
<select id="selectUserByArgs" resultMap="BaseResultMap">
|
||||
select u.*,
|
||||
j.id as job_id, j.name as job_name,
|
||||
r.role_id as role_id, r.name as role_name, r.level as role_level, r.data_scope as role_data_scope
|
||||
@@ -145,18 +145,18 @@
|
||||
from system_user
|
||||
where phone = #{phone}
|
||||
</select>
|
||||
<update id="updatePasswordByUsername">
|
||||
<update id="updateUserPasswordByUsername">
|
||||
update system_user
|
||||
set password = #{password},
|
||||
pwd_reset_time = #{lastPasswordResetTime}
|
||||
pwd_reset_time = NOW()
|
||||
where username = #{username}
|
||||
</update>
|
||||
<update id="updateEmailByUsername">
|
||||
<update id="updateUserEmailByUsername">
|
||||
update system_user
|
||||
set email = #{email}
|
||||
where username = #{username}
|
||||
</update>
|
||||
<select id="queryUserListByRoleId" resultType="cn.odboy.core.dal.dataobject.system.SystemUserTb">
|
||||
<select id="selectUserByRoleId" resultType="cn.odboy.core.dal.dataobject.system.SystemUserTb">
|
||||
SELECT u.user_id as id, u.username
|
||||
FROM system_user u,
|
||||
system_users_roles r
|
||||
@@ -164,7 +164,7 @@
|
||||
AND r.role_id = #{roleId}
|
||||
group by u.user_id
|
||||
</select>
|
||||
<select id="queryUserListByDeptId" resultType="cn.odboy.core.dal.dataobject.system.SystemUserTb">
|
||||
<select id="selectUserByDeptId" resultType="cn.odboy.core.dal.dataobject.system.SystemUserTb">
|
||||
SELECT u.*
|
||||
FROM system_user u,
|
||||
system_users_roles r,
|
||||
@@ -174,7 +174,7 @@
|
||||
AND d.dept_id = #{deptId}
|
||||
group by u.user_id
|
||||
</select>
|
||||
<select id="queryUserListByMenuId" resultType="cn.odboy.core.dal.dataobject.system.SystemUserTb">
|
||||
<select id="selectUserByMenuId" resultType="cn.odboy.core.dal.dataobject.system.SystemUserTb">
|
||||
SELECT u.user_id as id, u.username
|
||||
FROM system_user u,
|
||||
system_users_roles ur,
|
||||
@@ -184,28 +184,28 @@
|
||||
AND rm.menu_id = #{menuId}
|
||||
group by u.user_id
|
||||
</select>
|
||||
<select id="getUserCountByJobIds" resultType="int">
|
||||
<select id="countUserByJobIds" resultType="Long">
|
||||
SELECT count(*) FROM system_user u, system_users_jobs j
|
||||
WHERE u.user_id = j.user_id AND j.job_id IN
|
||||
<foreach collection="jobIds" item="jobId" open="(" separator="," close=")">
|
||||
#{jobId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getUserCountByDeptIds" resultType="int">
|
||||
<select id="countUserByDeptIds" resultType="Long">
|
||||
SELECT count(*) FROM system_user u
|
||||
WHERE u.dept_id IN
|
||||
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getUserCountByRoleIds" resultType="int">
|
||||
<select id="countUserByRoleIds" resultType="Long">
|
||||
SELECT count(*) FROM system_user u, system_users_roles r
|
||||
WHERE u.user_id = r.user_id AND r.role_id in
|
||||
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</select>
|
||||
<update id="updatePasswordByUserIds">
|
||||
<update id="batchUpdatePassword">
|
||||
update system_user set password = #{password}
|
||||
where user_id in
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.odboy.core.dal.mysql.system.SystemUserRoleMapper">
|
||||
<insert id="insertBatchWithUserId">
|
||||
<insert id="batchInsertUserRole">
|
||||
insert into system_users_roles (user_id, role_id)
|
||||
values
|
||||
<foreach collection="roles" item="item" open="(" separator="),(" close=")">
|
||||
@@ -9,13 +9,7 @@
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByUserId">
|
||||
delete
|
||||
from system_users_roles
|
||||
where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByUserIds">
|
||||
<delete id="batchDeleteUserRole">
|
||||
delete from system_users_roles
|
||||
where user_id in
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<style>
|
||||
@page {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="margin: 0px;
|
||||
padding: 0px;
|
||||
font: 100% SimSun, Microsoft YaHei, Times New Roman, Verdana, Arial, Helvetica, sans-serif;
|
||||
color: #000;">
|
||||
<div style="height: auto;
|
||||
width: 820px;
|
||||
min-width: 820px;
|
||||
margin: 0 auto;
|
||||
margin-top: 20px;
|
||||
border: 1px solid #eee;">
|
||||
<div style="padding: 10px;padding-bottom: 0px;">
|
||||
<p style="margin-bottom: 10px;padding-bottom: 0px;">尊敬的用户,您好:</p>
|
||||
<p style="text-indent: 2em; margin-bottom: 10px;">您正在申请邮箱验证,您的验证码为:</p>
|
||||
<p style="text-align: center;
|
||||
font-family: Times New Roman;
|
||||
font-size: 22px;
|
||||
color: #C60024;
|
||||
padding: 20px 0px;
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
background: #ebebeb;">${code}</p>
|
||||
<div class="foot-hr hr" style="margin: 0 auto;
|
||||
z-index: 111;
|
||||
width: 800px;
|
||||
margin-top: 30px;
|
||||
border-top: 1px solid #DA251D;">
|
||||
</div>
|
||||
<div style="text-align: center;
|
||||
font-size: 12px;
|
||||
padding: 20px 0px;
|
||||
font-family: Microsoft YaHei;">
|
||||
Copyright ©${.now?string("yyyy")} <a hover="color: #DA251D;" style="color: #999;"
|
||||
href="https://github.com/odboy-tianjun/cutejava" target="_blank">CuteJava</a>
|
||||
后台管理系统 All Rights Reserved.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,71 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<style>
|
||||
@page {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="margin: 0px;
|
||||
padding: 0px;
|
||||
font: 100% SimSun, Microsoft YaHei, Times New Roman, Verdana, Arial, Helvetica, sans-serif;
|
||||
color: #000;">
|
||||
<div style="height: auto;
|
||||
margin: 0 auto;
|
||||
margin-top: 20px;
|
||||
padding: 20px;
|
||||
border: 1px solid #eee;">
|
||||
<div>
|
||||
<p style="margin-bottom: 10px;">任务信息:</p>
|
||||
<table style="border-collapse: collapse;">
|
||||
<tr>
|
||||
<th style="padding: .65em;background: #666;border: 1px solid #777;color: #fff;">任务名称</th>
|
||||
<th style="padding: .65em;background: #666;border: 1px solid #777;color: #fff;">Bean名称</th>
|
||||
<th style="padding: .65em;background: #666;border: 1px solid #777;color: #fff;">执行方法</th>
|
||||
<th style="padding: .65em;background: #666;border: 1px solid #777;color: #fff;">参数内容</th>
|
||||
<th style="padding: .65em;background: #666;border: 1px solid #777;color: #fff;">Cron表达式</th>
|
||||
<th style="padding: .65em;background: #666;border: 1px solid #777;color: #fff;">描述内容</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: .65em;border: 1px solid#777;">${task.jobName}</td>
|
||||
<td style="padding: .65em;border: 1px solid#777;">${task.beanName}</td>
|
||||
<td style="padding: .65em;border: 1px solid#777;">${task.methodName}</td>
|
||||
<td style="padding: .65em;border: 1px solid#777;">${(task.params)!""}</td>
|
||||
<td style="padding: .65em;border: 1px solid#777;">${task.cronExpression}</td>
|
||||
<td style="padding: .65em;border: 1px solid#777;">${(task.description)!""}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<p style="margin-bottom: 10px;">异常信息:</p>
|
||||
<pre style="position: relative;
|
||||
padding: 15px;
|
||||
line-height: 20px;
|
||||
border-left: 5px solid #ddd;
|
||||
color: #333;
|
||||
font-family: Courier New, serif;
|
||||
font-size: 12px">
|
||||
${msg}
|
||||
</pre>
|
||||
</div>
|
||||
<div class="foot-hr hr" style="margin: 0 auto;
|
||||
z-index: 111;
|
||||
width: 800px;
|
||||
margin-top: 30px;
|
||||
border-top: 1px solid #DA251D;">
|
||||
</div>
|
||||
<div style="text-align: center;
|
||||
font-size: 12px;
|
||||
padding: 20px 0px;
|
||||
font-family: Microsoft YaHei;">
|
||||
Copyright ©${.now?string("yyyy")} <a hover="color: #DA251D;" style="color: #999;"
|
||||
href="https://github.com/odboy-tianjun/cutejava" target="_blank">CuteJava</a>
|
||||
后台管理系统 All Rights Reserved.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
<module>cutejava-starter</module>
|
||||
</modules>
|
||||
|
||||
<name>后台管理</name>
|
||||
<name>CuteJava后台管理</name>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Reference in New Issue
Block a user