From bb664df62f5a8af9a0a97b0630ecfce17faaa187 Mon Sep 17 00:00:00 2001 From: Odboy Date: Wed, 14 Jan 2026 23:15:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(quartz):=20=E9=87=8D=E6=9E=84=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=9B=B8=E5=85=B3=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=92=8C=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SystemDeptController.java | 2 +- .../controller/SystemDictController.java | 2 +- .../SystemDictDetailController.java | 11 - .../controller/SystemJobController.java | 2 +- .../SystemLocalStorageController.java | 2 +- .../controller/SystemMenuController.java | 2 +- .../controller/SystemOnlineController.java | 2 +- .../controller/SystemQuartzJobController.java | 13 +- .../controller/SystemRoleController.java | 2 +- .../controller/SystemUserController.java | 2 +- .../system/dal/dataobject/SystemDeptTb.java | 2 +- .../system/dal/dataobject/SystemJobTb.java | 2 +- .../dal/dataobject/SystemLocalStorageTb.java | 7 +- .../system/dal/dataobject/SystemMenuTb.java | 2 +- .../system/dal/dataobject/SystemRoleTb.java | 2 +- .../system/dal/dataobject/SystemUserTb.java | 4 +- .../model/request/SystemCreateRoleArgs.java | 2 +- .../model/request/SystemSendEmailArgs.java | 2 +- .../model/response/SystemSimpleUserVo.java | 2 +- .../dal/mysql/SystemQuartzJobMapper.java | 5 - .../system/dal/mysql/SystemRoleMapper.java | 3 + .../system/dal/mysql/SystemUserMapper.java | 4 + .../dal/mysql/SystemUserRoleMapper.java | 2 + .../dal/redis/SystemUserOnlineInfoDAO.java | 4 +- .../framework/quartz/ActiveJobRegister.java | 7 +- .../system/framework/quartz/QuartzManage.java | 36 ++-- .../system/service/SystemAuthService.java | 4 +- .../system/service/SystemCaptchaService.java | 7 +- .../system/service/SystemDataService.java | 9 +- .../system/service/SystemDeptService.java | 14 +- .../service/SystemDictDetailService.java | 12 +- .../system/service/SystemDictService.java | 2 +- .../system/service/SystemJobService.java | 34 ++-- .../service/SystemLocalStorageService.java | 34 +++- .../system/service/SystemMenuService.java | 12 +- .../system/service/SystemMonitorService.java | 10 +- .../service/SystemOperationLogService.java | 2 +- .../service/SystemOssStorageService.java | 2 +- .../service/SystemQuartzJobService.java | 84 ++++---- .../system/service/SystemRoleDeptService.java | 3 - .../system/service/SystemRoleService.java | 30 ++- .../system/service/SystemUserDeptService.java | 3 + .../system/service/SystemUserJobService.java | 16 +- .../system/service/SystemUserRoleService.java | 43 ++-- .../system/service/SystemUserService.java | 188 ++++++++++-------- .../impl/SystemMinioStorageServiceImpl.java | 2 +- .../src/main/resources/logback.xml | 78 ++++---- .../controller/SystemQuartzJobController.java | 11 +- .../dal/mysql/SystemQuartzJobMapper.java | 5 - .../framework/quartz/ActiveJobRegister.java | 7 +- .../system/framework/quartz/QuartzManage.java | 34 ++-- .../service/SystemLocalStorageService.java | 10 +- .../system/service/SystemMonitorService.java | 10 +- .../service/SystemOperationLogService.java | 2 +- .../service/SystemQuartzJobService.java | 78 ++++---- 55 files changed, 468 insertions(+), 404 deletions(-) diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDeptController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDeptController.java index 266ca03a..b6b009a0 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDeptController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDeptController.java @@ -26,9 +26,9 @@ import cn.odboy.system.service.SystemDeptService; import cn.odboy.util.KitPageUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictController.java index 1bd4485e..e3d3e9ae 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictController.java @@ -25,9 +25,9 @@ import cn.odboy.system.service.SystemDictService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictDetailController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictDetailController.java index 0b7cd08f..2434da94 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictDetailController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemDictDetailController.java @@ -26,17 +26,13 @@ import cn.odboy.system.service.SystemDictDetailService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import java.util.List; -import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -54,13 +50,6 @@ public class SystemDictDetailController { return ResponseEntity.ok(systemDictDetailService.searchDictDetail(pageArgs.getArgs(), page)); } - @ApiOperation("查询多个字典详情") - @GetMapping(value = "/getDictDetailMaps") - public ResponseEntity>> getDictDetailMaps(@RequestParam String dictName) { - Map> dictMap = systemDictDetailService.getDictDetailMap(dictName); - return ResponseEntity.ok(dictMap); - } - @OperationLog @ApiOperation("新增字典详情") @PostMapping(value = "/saveDictDetail") diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemJobController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemJobController.java index 2147717f..0ab929cf 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemJobController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemJobController.java @@ -25,8 +25,8 @@ import cn.odboy.system.service.SystemJobService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemLocalStorageController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemLocalStorageController.java index 938b7d18..a0a5246e 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemLocalStorageController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemLocalStorageController.java @@ -74,7 +74,7 @@ public class SystemLocalStorageController { @ApiOperation("上传图片") @PostMapping("/uploadPicture") public ResponseEntity uploadPicture(@RequestParam MultipartFile file) { - SystemLocalStorageTb localStorage = localStorageService.uploadPictureV1(file); + SystemLocalStorageTb localStorage = localStorageService.uploadPicture(file); return ResponseEntity.ok(localStorage); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java index dcbcae27..992eebd3 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java @@ -27,9 +27,9 @@ import cn.odboy.system.service.SystemMenuService; import cn.odboy.util.KitPageUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemOnlineController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemOnlineController.java index 5a0f5d91..2ccc1927 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemOnlineController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemOnlineController.java @@ -24,8 +24,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java index d366d25b..f0d4c69a 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java @@ -24,11 +24,12 @@ import cn.odboy.system.dal.model.request.SystemUpdateQuartzJobArgs; import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.framework.operalog.OperationLog; import cn.odboy.system.service.SystemQuartzJobService; +import cn.odboy.util.KitBeanUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -86,7 +87,7 @@ public class SystemQuartzJobController { @ApiOperation("新增定时任务") @PostMapping(value = "/createQuartzJob") @PreAuthorize("@el.check('quartzJob:add')") - public ResponseEntity createQuartzJob(@Validated @RequestBody SystemQuartzJobVo args) { + public ResponseEntity createQuartzJob(@Validated @RequestBody SystemQuartzJobTb args) { systemQuartzJobService.createJob(args); return ResponseEntity.ok(null); } @@ -106,7 +107,9 @@ public class SystemQuartzJobController { @PostMapping(value = "/switchQuartzJobStatus/{id}") @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity switchQuartzJobStatus(@PathVariable Long id) { - systemQuartzJobService.switchQuartzJobStatus(systemQuartzJobService.getQuartzJobById(id)); + SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); + systemQuartzJobService.switchQuartzJobStatus(quartzJobVo); return ResponseEntity.ok(null); } @@ -115,7 +118,9 @@ public class SystemQuartzJobController { @PostMapping(value = "/startQuartzJob/{id}") @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity startQuartzJob(@PathVariable Long id) { - systemQuartzJobService.startQuartzJob(systemQuartzJobService.getQuartzJobById(id)); + SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); + systemQuartzJobService.startQuartzJob(quartzJobVo); return ResponseEntity.ok(null); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemRoleController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemRoleController.java index 9fa710f3..d90d44e5 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemRoleController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemRoleController.java @@ -27,9 +27,9 @@ import cn.odboy.system.service.SystemRoleService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java index 2a7274f1..aa1358c9 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemUserController.java @@ -30,9 +30,9 @@ import cn.odboy.system.service.SystemUserService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.servlet.http.HttpServletResponse; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java index 4c454a28..7d79f580 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java @@ -20,9 +20,9 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; +import java.util.Objects; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.util.Objects; import lombok.Getter; import lombok.Setter; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemJobTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemJobTb.java index 0e9a12fb..53fa0274 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemJobTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemJobTb.java @@ -20,9 +20,9 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; +import java.util.Objects; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.util.Objects; import lombok.Getter; import lombok.Setter; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemLocalStorageTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemLocalStorageTb.java index 92c19c3b..cb3b2e7b 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemLocalStorageTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemLocalStorageTb.java @@ -16,7 +16,6 @@ package cn.odboy.system.dal.dataobject; import cn.odboy.base.KitBaseUserTimeTb; -import cn.odboy.util.KitBeanUtil; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -46,8 +45,4 @@ public class SystemLocalStorageTb extends KitBaseUserTimeTb { private String size; @ApiModelProperty(value = "日期分组") private String dateGroup; - - public void copy(SystemLocalStorageTb source) { - KitBeanUtil.copyToTarget(source, this); - } -} \ No newline at end of file +} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemMenuTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemMenuTb.java index a1b38205..0a9f3aa3 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemMenuTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemMenuTb.java @@ -21,8 +21,8 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; -import jakarta.validation.constraints.NotNull; import java.util.Objects; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemRoleTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemRoleTb.java index 54fc4884..8372251a 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemRoleTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemRoleTb.java @@ -23,9 +23,9 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; +import java.util.Objects; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.util.Objects; import lombok.Getter; import lombok.Setter; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemUserTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemUserTb.java index 01085ac8..31ea896b 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemUserTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemUserTb.java @@ -21,11 +21,11 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; +import java.util.Date; +import java.util.Objects; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.util.Date; -import java.util.Objects; import lombok.Getter; import lombok.Setter; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemCreateRoleArgs.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemCreateRoleArgs.java index c195955a..4a8f6496 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemCreateRoleArgs.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemCreateRoleArgs.java @@ -17,9 +17,9 @@ package cn.odboy.system.dal.model.request; import cn.odboy.base.KitObject; import cn.odboy.system.dal.dataobject.SystemDeptTb; +import java.util.Set; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.util.Set; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemSendEmailArgs.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemSendEmailArgs.java index ef1d03e2..3069250f 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemSendEmailArgs.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/request/SystemSendEmailArgs.java @@ -16,9 +16,9 @@ package cn.odboy.system.dal.model.request; import io.swagger.annotations.ApiModelProperty; +import java.util.List; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; -import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemSimpleUserVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemSimpleUserVo.java index 7585556c..fd60f0c1 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemSimpleUserVo.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemSimpleUserVo.java @@ -52,4 +52,4 @@ public class SystemSimpleUserVo extends KitObject { private Boolean enabled; @ApiModelProperty(value = "是否为admin账号", hidden = true) private Boolean isAdmin = false; -} +} \ No newline at end of file diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java index c420ffe1..333270ea 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java @@ -16,8 +16,6 @@ package cn.odboy.system.dal.mysql; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; -import cn.odboy.util.KitBeanUtil; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; @@ -29,7 +27,4 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface SystemQuartzJobMapper extends BaseMapper { - default SystemQuartzJobVo selectVoById(String id) { - return KitBeanUtil.copyToClass(selectById(id), SystemQuartzJobVo.class); - } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemRoleMapper.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemRoleMapper.java index c9bb0662..e4097313 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemRoleMapper.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemRoleMapper.java @@ -17,7 +17,9 @@ package cn.odboy.system.dal.mysql; import cn.odboy.system.dal.dataobject.SystemRoleTb; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import java.util.List; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 角色 Mapper @@ -27,4 +29,5 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface SystemRoleMapper extends BaseMapper { + List listRoleLevelByRoleIds(@Param("roleIds") List roleIds); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserMapper.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserMapper.java index 4bfdd651..bc91dbba 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserMapper.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserMapper.java @@ -18,8 +18,10 @@ package cn.odboy.system.dal.mysql; import cn.odboy.system.dal.dataobject.SystemUserTb; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import java.util.List; import java.util.Set; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 用户 Mapper @@ -49,4 +51,6 @@ public interface SystemUserMapper extends BaseMapper { wrapper.set(SystemUserTb::getPassword, password); update(null, wrapper); } + + List listUsernameByIds(@Param("userIds") Set userIds); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserRoleMapper.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserRoleMapper.java index cc6cf958..9ac6c281 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserRoleMapper.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemUserRoleMapper.java @@ -18,6 +18,7 @@ package cn.odboy.system.dal.mysql; import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemUserRoleTb; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import java.util.List; import java.util.Set; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -26,4 +27,5 @@ import org.apache.ibatis.annotations.Param; public interface SystemUserRoleMapper extends BaseMapper { Set listUserRoleByUserId(@Param("userId") Long userId); + List listUserRoleLevelByUserId(@Param("userId") Long userId); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserOnlineInfoDAO.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserOnlineInfoDAO.java index 17f6d339..4590eb5c 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserOnlineInfoDAO.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/redis/SystemUserOnlineInfoDAO.java @@ -15,14 +15,14 @@ import cn.odboy.util.KitIPUtil; import cn.odboy.util.KitPageUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.metadata.IPage; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java index 5ddc3b19..fb9997c9 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java @@ -15,8 +15,10 @@ */ package cn.odboy.system.framework.quartz; +import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.service.SystemQuartzJobService; +import cn.odboy.util.KitBeanUtil; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -40,8 +42,9 @@ public class ActiveJobRegister implements ApplicationRunner { */ @Override public void run(ApplicationArguments applicationArguments) { - List quartzJobs = systemQuartzJobService.listEnableQuartzJob(); - quartzJobs.forEach(quartzManage::addJob); + List quartzJobTbs = systemQuartzJobService.listEnableQuartzJob(); + List quartzJobVos = KitBeanUtil.copyToList(quartzJobTbs, SystemQuartzJobVo.class); + quartzJobVos.forEach(quartzManage::addJob); log.info("Timing task injection complete"); } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java index 3057ba88..2e0cc2aa 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java @@ -18,8 +18,9 @@ package cn.odboy.system.framework.quartz; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.model.response.SystemQuartzJobVo; -import jakarta.annotation.Resource; +import cn.odboy.util.KitBeanUtil; import java.util.Date; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.quartz.CronScheduleBuilder; import org.quartz.CronTrigger; @@ -45,12 +46,17 @@ public class QuartzManage { public void addJob(SystemQuartzJobVo quartzJob) { try { + String uuid = JOB_NAME + quartzJob.getId(); // 构建job信息 - JobDetail jobDetail = - JobBuilder.newJob(ExecutionJobBean.class).withIdentity(JOB_NAME + quartzJob.getId()).build(); + JobDetail jobDetail = JobBuilder.newJob(ExecutionJobBean.class) + .withIdentity(uuid) + .build(); // 通过触发器名和cron 表达式创建 Trigger - Trigger trigger = TriggerBuilder.newTrigger().withIdentity(JOB_NAME + quartzJob.getId()).startNow() - .withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression())).build(); + Trigger trigger = TriggerBuilder.newTrigger() + .withIdentity(uuid) + .startNow() + .withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression())) + .build(); trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJob); // 重置启动时间 ((CronTriggerImpl) trigger).setStartTime(new Date()); @@ -75,24 +81,25 @@ public class QuartzManage { * * @param quartzJob / */ - public void updateJobCron(SystemQuartzJobVo quartzJob) { + public void updateJobCron(SystemQuartzJobTb quartzJob) { try { - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobVo.class); + TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJobVo.getId()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 如果不存在则创建一个定时任务 if (trigger == null) { - addJob(quartzJob); + addJob(quartzJobVo); trigger = (CronTrigger) scheduler.getTrigger(triggerKey); } - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression()); + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJobVo.getCronExpression()); trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); // 重置启动时间 ((CronTriggerImpl) trigger).setStartTime(new Date()); - trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJob); + trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJobVo); scheduler.rescheduleJob(triggerKey, trigger); // 暂停任务 - if (quartzJob.getIsPause()) { - pauseJob(quartzJob); + if (quartzJobVo.getIsPause()) { + pauseJob(quartzJobVo); } } catch (Exception e) { log.error("更新定时任务失败", e); @@ -144,7 +151,8 @@ public class QuartzManage { */ public void runJobNow(SystemQuartzJobVo quartzJob) { try { - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); + String uuid = JOB_NAME + quartzJob.getId(); + TriggerKey triggerKey = TriggerKey.triggerKey(uuid); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 如果不存在则创建一个定时任务 if (trigger == null) { @@ -152,7 +160,7 @@ public class QuartzManage { } JobDataMap dataMap = new JobDataMap(); dataMap.put(SystemQuartzJobTb.JOB_KEY, quartzJob); - JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); + JobKey jobKey = JobKey.jobKey(uuid); scheduler.triggerJob(jobKey, dataMap); } catch (Exception e) { log.error("定时任务执行失败", e); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java index ce820994..cac9c36c 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java @@ -52,7 +52,7 @@ public class SystemAuthService { KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), loginArgs.getPassword()); // 校验验证码 systemCaptchaService.validate(loginArgs.getUuid(), loginArgs.getCode()); - // 获取用户信息 + // 查询用户信息 SystemUserJwtVo jwtUser = userDetailsService.loadUserByUsername(loginArgs.getUsername()); // 验证用户密码 if (!passwordEncoder.matches(password, jwtUser.getPassword())) { @@ -83,7 +83,7 @@ public class SystemAuthService { } /** - * 获取当前登录人信息 -> TestPassed + * 查询当前登录人信息 -> TestPassed */ public SystemUserJwtVo getCurrentUserInfo() { SystemUserJwtVo jwtUser = (SystemUserJwtVo) KitSecurityHelper.getCurrentUser(); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java index 308d5129..09a05676 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java @@ -26,10 +26,10 @@ public class SystemCaptchaService { private AppProperties properties; /** - * 获取登录验证码 -> TestPassed + * 查询登录验证码 -> TestPassed */ public SystemCaptchaVo getLoginCaptcha() { - // 获取运算的结果 + // 查询运算的结果 Captcha captcha = properties.getLogin().getCaptchaSetting().getCaptcha(); String uuid = SystemCacheKey.CAPTCHA_LOGIN + IdUtil.simpleUUID(); //当验证码类型为 arithmetic时且长度 >= 2 时, captcha.text()的结果有几率为浮点型 @@ -39,8 +39,7 @@ public class SystemCaptchaService { captchaValue = captchaValue.split("\\.")[0]; } // 保存 - redisHelper.set(uuid, captchaValue, properties.getLogin().getCaptchaSetting().getExpiration(), - TimeUnit.MINUTES); + redisHelper.set(uuid, captchaValue, properties.getLogin().getCaptchaSetting().getExpiration(), TimeUnit.MINUTES); // 验证码信息 SystemCaptchaVo captchaVo = new SystemCaptchaVo(); captchaVo.setUuid(uuid); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java index 17fd9f30..6a775d19 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java @@ -45,7 +45,7 @@ public class SystemDataService { private SystemRoleDeptService systemRoleDeptService; /** - * 获取数据权限 -> TestPassed + * 查询数据权限 -> TestPassed * * @param user / * @return / @@ -54,7 +54,7 @@ public class SystemDataService { List deptIds = new ArrayList<>(); // 查询用户角色 Set roleList = systemUserRoleService.listUserRoleByUserId(user.getId()); - // 获取对应的部门ID + // 查询对应的部门ID for (SystemRoleTb role : roleList) { SystemDataScopeEnum dataScopeEnum = SystemDataScopeEnum.find(role.getDataScope()); switch (Objects.requireNonNull(dataScopeEnum)) { @@ -75,7 +75,7 @@ public class SystemDataService { } /** - * 获取自定义的数据权限 -> TestPassed + * 查询自定义的数据权限 -> TestPassed * * @param deptIds 部门ID(外部数据) * @param roleId 角色ID @@ -83,8 +83,7 @@ public class SystemDataService { */ private List queryCustomDataPermissionByArgs(List deptIds, Long roleId) { Set deptList = systemRoleDeptService.listUserDeptByRoleId(roleId); - Map> deptPidMap = - systemDeptService.listPidNonNull().stream().collect(Collectors.groupingBy(SystemDeptTb::getPid)); + Map> deptPidMap = systemDeptService.listPidNonNull().stream().collect(Collectors.groupingBy(SystemDeptTb::getPid)); for (SystemDeptTb dept : deptList) { deptIds.add(dept.getId()); List deptChildren = deptPidMap.getOrDefault(dept.getId(), null); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java index f92bb582..0ff14e22 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java @@ -36,7 +36,6 @@ import cn.odboy.util.KitClassUtil; import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import jakarta.servlet.http.HttpServletResponse; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; @@ -48,6 +47,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -100,7 +100,7 @@ public class SystemDeptService { } /** - * 根据部门id获取部门信息 -> TestPassed + * 根据部门id查询部门信息 -> TestPassed * * @param id 部门id * @return / @@ -116,7 +116,7 @@ public class SystemDeptService { */ @Transactional(rollbackFor = Exception.class) public void deleteDeptByIds(Set ids) { - // 获取部门, 和其所有子部门 + // 查询部门, 和其所有子部门 Set depts = this.traverseDeptByIdWithPids(ids); // 验证是否被角色或用户关联 this.verifyBindRelationByIds(depts); @@ -229,7 +229,7 @@ public class SystemDeptService { } /** - * 获取部门下所有关联的部门 + * 查询部门下所有关联的部门 * * @param deptTbList / * @param depts / @@ -263,7 +263,7 @@ public class SystemDeptService { } /** - * 根据ID获取同级与上级数据 + * 根据ID查询同级与上级数据 * * @param dept / * @param deptList / @@ -388,7 +388,7 @@ public class SystemDeptService { } private List buildDeptSelectOptions(List depts) { - // 获取所有部门并按父子关系组织 + // 查询所有部门并按父子关系组织 Map deptMap = depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity())); List options = new ArrayList<>(); @@ -433,7 +433,7 @@ public class SystemDeptService { public List listDeptSelectProDataSource() { List depts = this.listEnabledDepts(); - // 获取所有部门并按父子关系组织 + // 查询所有部门并按父子关系组织 Map deptMap = depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity())); List options = new ArrayList<>(); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java index 863e9f45..031379a8 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java @@ -32,7 +32,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -117,7 +116,7 @@ public class SystemDictDetailService { } /** - * 根据字典名称获取字典详情 -> TestPassed + * 根据字典名称查询字典详情 -> TestPassed * * @param name 字典名称 * @return / @@ -140,13 +139,4 @@ public class SystemDictDetailService { } return detailVos; } - - public Map> getDictDetailMap(String dictName) { - String[] names = dictName.split("[,, ]"); - Map> dictMap = new HashMap<>(16); - for (String name : names) { - dictMap.put(name, this.listDictDetailByName(name)); - } - return dictMap; - } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java index a6b81a75..d2a9d6b7 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java @@ -29,10 +29,10 @@ import cn.odboy.util.KitPageUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java index 9187bdbf..79d283bd 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java @@ -29,10 +29,10 @@ import cn.odboy.util.KitPageUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -52,8 +52,7 @@ public class SystemJobService { */ @Transactional(rollbackFor = Exception.class) public void saveJob(SystemCreateJobArgs args) { - SystemJobTb job = this.getJobByName(args.getName()); - if (job != null) { + if (this.existJobWithName(args.getName())) { throw new BadRequestException("职位名称已存在"); } SystemJobTb systemJobTb = KitBeanUtil.copyToClass(args, SystemJobTb.class); @@ -68,8 +67,7 @@ public class SystemJobService { @Transactional(rollbackFor = Exception.class) public void updateJobById(SystemJobTb args) { SystemJobTb job = systemJobMapper.selectById(args.getId()); - SystemJobTb old = this.getJobByName(args.getName()); - if (old != null && !old.getId().equals(args.getId())) { + if (this.existJobWithNameNeSelf(args.getName(), job.getId())) { throw new BadRequestException("职位名称已存在"); } args.setId(job.getId()); @@ -121,13 +119,26 @@ public class SystemJobService { } } - public SystemJobTb getJobByName(String name) { + /** + * 根据岗位名称查询岗位是否存在 -> TestPassed + */ + private boolean existJobWithName(String name) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(SystemJobTb::getName, name); - return systemJobMapper.selectOne(wrapper); + return systemJobMapper.exists(wrapper); } - public void injectQueryParams(SystemQueryJobArgs args, LambdaQueryWrapper wrapper) { + /** + * 根据岗位名称和岗位id查询岗位是否存在 -> TestPassed + */ + private boolean existJobWithNameNeSelf(String name, Long currentJobId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemJobTb::getName, name); + wrapper.ne(SystemJobTb::getId, currentJobId); + return systemJobMapper.exists(wrapper); + } + + private void injectQueryParams(SystemQueryJobArgs args, LambdaQueryWrapper wrapper) { if (args != null) { wrapper.like(StrUtil.isNotBlank(args.getName()), SystemJobTb::getName, args.getName()); wrapper.eq(args.getEnabled() != null, SystemJobTb::getEnabled, args.getEnabled()); @@ -138,6 +149,9 @@ public class SystemJobService { wrapper.orderByDesc(SystemJobTb::getJobSort, SystemJobTb::getId); } + /** + * 导出岗位数据 -> TestPassed + */ public void exportJobXlsx(HttpServletResponse response, SystemQueryJobArgs args) { List systemJobTbs = this.queryJobByArgs(args); List rowVos = new ArrayList<>(); @@ -150,8 +164,4 @@ public class SystemJobService { } KitExcelExporter.exportSimple(response, "岗位数据", SystemJobExportRowVo.class, rowVos); } - - public List listByIds(Set jobIds) { - return systemJobMapper.selectByIds(jobIds); - } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java index 560ca012..14e0f978 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java @@ -22,7 +22,6 @@ import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; import cn.odboy.constant.FileTypeEnum; -import cn.odboy.framework.context.KitSpringBeanHolder; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.server.core.KitFileLocalUploadHelper; @@ -36,15 +35,18 @@ import cn.odboy.util.KitPageUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.util.Date; import java.util.List; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +@Slf4j @Service public class SystemLocalStorageService { @@ -54,6 +56,9 @@ public class SystemLocalStorageService { private KitFileLocalUploadHelper fileUploadPathHelper; @Autowired private AppProperties properties; + @Lazy + @Autowired + private SystemLocalStorageService localStorageService; /** * 上传 -> TestPassed @@ -75,8 +80,7 @@ public class SystemLocalStorageService { } try { String formatSize = KitFileUtil.getSize(size); - String prefixName = - StrUtil.isBlank(name) ? KitFileUtil.getPrefix(multipartFile.getOriginalFilename()) : name; + String prefixName = KitFileUtil.getPrefix(multipartFile.getOriginalFilename(), name); SystemLocalStorageTb localStorage = new SystemLocalStorageTb(); localStorage.setRealName(file.getName()); localStorage.setName(prefixName); @@ -88,6 +92,7 @@ public class SystemLocalStorageService { systemLocalStorageMapper.insert(localStorage); return localStorage; } catch (Exception e) { + log.error("上传文件失败", e); KitFileUtil.del(file); throw e; } @@ -100,9 +105,7 @@ public class SystemLocalStorageService { */ @Transactional(rollbackFor = Exception.class) public void updateLocalStorageById(SystemLocalStorageTb args) { - SystemLocalStorageTb localStorage = systemLocalStorageMapper.selectById(args.getId()); - localStorage.copy(args); - systemLocalStorageMapper.insertOrUpdate(localStorage); + systemLocalStorageMapper.updateById(args); } /** @@ -153,25 +156,34 @@ public class SystemLocalStorageService { wrapper.orderByDesc(SystemLocalStorageTb::getId); } + /** + * 查询文件上传记录 -> TestPassed + */ public List queryLocalStorageByArgs(SystemQueryStorageArgs args) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); this.injectQueryParams(args, wrapper); return systemLocalStorageMapper.selectList(wrapper); } - public SystemLocalStorageTb uploadPictureV1(MultipartFile file) { + /** + * 上传图片 -> TestPassed + */ + @Transactional(rollbackFor = Exception.class) + public SystemLocalStorageTb uploadPicture(MultipartFile file) { // 判断文件是否为图片 String suffix = KitFileUtil.getSuffix(file.getOriginalFilename()); if (!FileTypeEnum.IMAGE.getCode().equals(KitFileUtil.getFileType(suffix))) { throw new BadRequestException("只能上传图片"); } - return KitSpringBeanHolder.getBean(SystemLocalStorageService.class).uploadFile(null, file); + return localStorageService.uploadFile(null, file); } + /** + * 导出文件上传记录 -> TestPassed + */ public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) { List systemLocalStorageTbs = this.queryLocalStorageByArgs(args); - List rowVos = - KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class); + List rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class); KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos); } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java index 085e46c3..cf68f9e4 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java @@ -36,7 +36,6 @@ import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import jakarta.servlet.http.HttpServletResponse; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; @@ -46,6 +45,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -212,19 +212,19 @@ public class SystemMenuService { } /** - * 根据当前用户获取菜单 + * 根据当前用户查询菜单 * * @param currentUserId / * @return / */ public List listMenuByUserId(Long currentUserId) { - List roles = systemUserRoleService.queryRoleVoByUsersId(currentUserId); + List roles = systemUserRoleService.listRoleVoByUsersId(currentUserId); Set roleIds = roles.stream().map(SystemRoleVo::getId).collect(Collectors.toSet()); return new ArrayList<>(systemRoleMenuService.queryMenuByRoleIds(roleIds)); } /** - * 获取所有子节点, 包含自身ID + * 查询所有子节点, 包含自身ID * * @param menuList / * @param menuSet / @@ -261,7 +261,7 @@ public class SystemMenuService { } /** - * 根据ID获取同级与上级数据 + * 根据ID查询同级与上级数据 * * @param menu / * @param menus / @@ -355,7 +355,7 @@ public class SystemMenuService { } /** - * 获取 MenuResponse + * 查询 MenuResponse * * @param menu / * @param menuVo / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java index e506233d..ca998310 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java @@ -75,7 +75,7 @@ public class SystemMonitorService { } /** - * 获取磁盘信息 + * 查询磁盘信息 -> TestPassed * * @return / */ @@ -109,7 +109,7 @@ public class SystemMonitorService { } /** - * 获取交换区信息 + * 查询交换区信息 -> TestPassed * * @param memory / * @return / @@ -131,7 +131,7 @@ public class SystemMonitorService { } /** - * 获取内存信息 + * 查询内存信息 -> TestPassed * * @param memory / * @return / @@ -147,7 +147,7 @@ public class SystemMonitorService { } /** - * 获取Cpu相关信息 + * 查询Cpu相关信息 -> TestPassed * * @param processor / * @return / @@ -194,7 +194,7 @@ public class SystemMonitorService { } /** - * 获取系统相关信息,系统、运行天数、系统IP + * 查询系统相关信息,系统、运行天数、系统IP -> TestPassed * * @param os / * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java index 1742dbe1..3b3b7481 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java @@ -18,7 +18,7 @@ public class SystemOperationLogService { private SystemOperationLogMapper systemOperationLogMapper; /** - * 查询用户操作日志 + * 查询用户操作日志 -> TestPassed */ public IPage searchUserLog(KitPageArgs pageArgs) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOssStorageService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOssStorageService.java index 34696e7f..10e66194 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOssStorageService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOssStorageService.java @@ -21,8 +21,8 @@ import cn.odboy.system.dal.model.request.SystemQueryStorageArgs; import cn.odboy.system.dal.model.response.SystemOssStorageVo; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; -import jakarta.servlet.http.HttpServletResponse; import java.util.List; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.multipart.MultipartFile; /** diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java index 7a8c6a75..237ef652 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java @@ -34,15 +34,14 @@ import cn.odboy.system.dal.mysql.SystemQuartzLogMapper; import cn.odboy.system.framework.quartz.QuartzManage; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; -import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; +import jakarta.servlet.http.HttpServletResponse; import org.quartz.CronExpression; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -79,7 +78,7 @@ public class SystemQuartzJobService { * @param args / */ @Transactional(rollbackFor = Exception.class) - public void createJob(SystemQuartzJobVo args) { + public void createJob(SystemQuartzJobTb args) { if (args.getId() != null) { throw new BadRequestException("无效参数id"); } @@ -88,9 +87,9 @@ public class SystemQuartzJobService { if (!CronExpression.isValidExpression(args.getCronExpression())) { throw new BadRequestException("cron表达式格式错误"); } - SystemQuartzJobTb record = KitBeanUtil.copyToClass(args, SystemQuartzJobTb.class); - systemQuartzJobMapper.insert(record); - quartzManage.addJob(args); + systemQuartzJobMapper.insert(args); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(args, SystemQuartzJobVo.class); + quartzManage.addJob(quartzJobVo); } /** @@ -112,28 +111,27 @@ public class SystemQuartzJobService { } } SystemQuartzJobTb jobTb = KitBeanUtil.copyToClass(args, SystemQuartzJobTb.class); - systemQuartzJobMapper.insertOrUpdate(jobTb); - SystemQuartzJobVo jobVo = KitBeanUtil.copyToClass(args, SystemQuartzJobVo.class); - quartzManage.updateJobCron(jobVo); + systemQuartzJobMapper.updateById(jobTb); + quartzManage.updateJobCron(jobTb); } /** * 更改定时任务状态 * - * @param quartzJob / + * @param quartzJobVo / */ @Transactional(rollbackFor = Exception.class) - public void switchQuartzJobStatus(SystemQuartzJobVo quartzJob) { + public void switchQuartzJobStatus(SystemQuartzJobVo quartzJobVo) { // 置换暂停状态 - if (quartzJob.getIsPause()) { - quartzManage.resumeJob(quartzJob); - quartzJob.setIsPause(false); + if (quartzJobVo.getIsPause()) { + quartzManage.resumeJob(quartzJobVo); + quartzJobVo.setIsPause(false); } else { - quartzManage.pauseJob(quartzJob); - quartzJob.setIsPause(true); + quartzManage.pauseJob(quartzJobVo); + quartzJobVo.setIsPause(true); } - SystemQuartzJobTb quartzJobTb = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobTb.class); - systemQuartzJobMapper.insertOrUpdate(quartzJobTb); + SystemQuartzJobTb record = KitBeanUtil.copyToClass(quartzJobVo, SystemQuartzJobTb.class); + systemQuartzJobMapper.updateById(record); } /** @@ -172,20 +170,20 @@ public class SystemQuartzJobService { // 如果是手动清除子任务id, 会出现id为空字符串的问题 continue; } - SystemQuartzJobVo quartzJob = systemQuartzJobMapper.selectVoById(id); - if (quartzJob == null) { + SystemQuartzJobTb quartzJobTb = systemQuartzJobMapper.selectById(id); + if (quartzJobTb == null) { // 防止子任务不存在 continue; } + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); // 执行任务 String uuid = IdUtil.simpleUUID(); - quartzJob.setUuid(uuid); - // 执行任务 - startQuartzJob(quartzJob); - // 获取执行状态, 如果执行失败则停止后面的子任务执行 + quartzJobVo.setUuid(uuid); + startQuartzJob(quartzJobVo); + // 查询执行状态, 如果执行失败则停止后面的子任务执行 Boolean result = redisHelper.get(uuid, Boolean.class); while (result == null) { - // 休眠5秒, 再次获取子任务执行情况 + // 休眠5秒, 再次查询子任务执行情况 Thread.sleep(5000); result = redisHelper.get(uuid, Boolean.class); } @@ -203,25 +201,23 @@ public class SystemQuartzJobService { * @param page 分页参数 * @return / */ - public KitPageResult searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, - Page page) { + public KitPageResult searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, Page page) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); this.injectQuartzJobQueryParams(args, wrapper); return KitPageUtil.toPage(systemQuartzJobMapper.selectPage(page, wrapper)); } - private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, - LambdaQueryWrapper wrapper) { - KitValidUtil.notNull(args); - wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, args.getJobName()); - if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { - wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1)); + private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper wrapper) { + if (args != null) { + wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, args.getJobName()); + if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { + wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1)); + } } wrapper.orderByDesc(SystemQuartzJobTb::getId); } - private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, - LambdaQueryWrapper wrapper) { + private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper wrapper) { if (args != null) { wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzLogTb::getJobName, args.getJobName()); wrapper.eq(args.getIsSuccess() != null, SystemQuartzLogTb::getIsSuccess, args.getIsSuccess()); @@ -271,16 +267,15 @@ public class SystemQuartzJobService { return systemQuartzLogMapper.selectList(wrapper); } - public SystemQuartzJobVo getQuartzJobById(Long id) { - return KitBeanUtil.copyToClass(systemQuartzJobMapper.selectById(id), SystemQuartzJobVo.class); - } - - public List listEnableQuartzJob() { + public List listEnableQuartzJob() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(SystemQuartzJobTb::getIsPause, 0); - return KitBeanUtil.copyToList(systemQuartzJobMapper.selectList(wrapper), SystemQuartzJobVo.class); + return systemQuartzJobMapper.selectList(wrapper); } + /** + * 导出定时任务数据 -> TestPassed + */ public void exportQuartzJobXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzJobTbs = this.queryQuartzJobByArgs(args); List rowVos = new ArrayList<>(); @@ -299,6 +294,9 @@ public class SystemQuartzJobService { KitExcelExporter.exportSimple(response, "定时任务数据", SystemQuartzJobExportRowVo.class, rowVos); } + /** + * 导出定时任务日志数据 -> TestPassed + */ public void exportQuartzLogXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzLogTbs = this.queryQuartzLogByArgs(args); List rowVos = new ArrayList<>(); @@ -317,4 +315,8 @@ public class SystemQuartzJobService { } KitExcelExporter.exportSimple(response, "定时任务日志数据", SystemQuartzLogExportRowVo.class, rowVos); } + + public SystemQuartzJobTb getQuartzJobById(Long id) { + return systemQuartzJobMapper.selectById(id); + } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java index 172dbdb0..517f7c57 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java @@ -18,7 +18,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; import cn.odboy.system.dal.dataobject.SystemDeptTb; import cn.odboy.system.dal.dataobject.SystemRoleDeptTb; -import cn.odboy.system.dal.mysql.SystemDeptMapper; import cn.odboy.system.dal.mysql.SystemRoleDeptMapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import java.util.ArrayList; @@ -33,8 +32,6 @@ public class SystemRoleDeptService { @Autowired private SystemRoleDeptMapper systemRoleDeptMapper; - @Autowired - private SystemDeptMapper systemDeptMapper; @Transactional(rollbackFor = Exception.class) public void batchDeleteRoleDept(Set roleIds) { diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java index 71cb3033..2a0b88fe 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java @@ -36,13 +36,13 @@ import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -60,7 +60,7 @@ public class SystemRoleService { private SystemUserRoleService systemUserRoleService; /** - * 创建 + * 创建 -> TestPassed * * @param args / */ @@ -91,7 +91,7 @@ public class SystemRoleService { } /** - * 修改 + * 修改 -> TestPassed * * @param args / */ @@ -122,7 +122,7 @@ public class SystemRoleService { } /** - * 修改绑定的菜单 + * 修改绑定的菜单 -> TestPassed * * @param args / */ @@ -140,7 +140,7 @@ public class SystemRoleService { } /** - * 删除 + * 删除 -> TestPassed * * @param ids / */ @@ -161,7 +161,7 @@ public class SystemRoleService { } /** - * 查询全部角色 + * 查询全部角色 -> TestPassed */ public List listAllRole() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -170,7 +170,7 @@ public class SystemRoleService { } /** - * 根据条件查询全部角色 + * 根据条件查询全部角色 -> TestPassed * * @param args 条件 * @param rolePage 分页参数 @@ -197,7 +197,7 @@ public class SystemRoleService { } /** - * 分页查询角色 + * 分页查询角色 -> TestPassed * * @param args 条件 * @param page 分页条件 @@ -210,7 +210,7 @@ public class SystemRoleService { } /** - * 获取用户权限信息 + * 查询用户权限信息 -> TestPassed * * @param user 用户信息 * @return 权限信息 @@ -222,14 +222,14 @@ public class SystemRoleService { permissions.add("admin"); return permissions.stream().map(SystemRoleCodeVo::new).collect(Collectors.toList()); } - List roles = systemUserRoleService.queryRoleVoByUsersId(user.getId()); + List roles = systemUserRoleService.listRoleVoByUsersId(user.getId()); permissions = roles.stream().flatMap(role -> role.getMenus().stream()).map(SystemMenuVo::getPermission) .filter(StrUtil::isNotBlank).collect(Collectors.toSet()); return permissions.stream().map(SystemRoleCodeVo::new).collect(Collectors.toList()); } /** - * 验证是否被用户关联 + * 验证是否被用户关联 -> TestPassed * * @param ids / */ @@ -263,12 +263,12 @@ public class SystemRoleService { } /** - * 检查用户的角色级别 + * 检查用户的角色级别 -> TestPassed * * @return / */ private int checkRoleLevels(Integer level) { - List levels = systemUserRoleService.queryRoleVoByUsersId(KitSecurityHelper.getCurrentUserId()).stream() + List levels = systemUserRoleService.listRoleVoByUsersId(KitSecurityHelper.getCurrentUserId()).stream() .map(SystemRoleVo::getLevel).collect(Collectors.toList()); int min = Collections.min(levels); if (level != null) { @@ -292,8 +292,4 @@ public class SystemRoleService { } KitExcelExporter.exportSimple(response, "部门数据", SystemRoleExportRowVo.class, rowVos); } - - public List listByIds(Set roleIds) { - return systemRoleMapper.selectByIds(roleIds); - } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java index e051ae16..76580ef4 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java @@ -13,6 +13,9 @@ public class SystemUserDeptService { @Autowired private SystemUserMapper systemUserMapper; + /** + * 根据部门id统计用户数量 -> TestPassed + */ public long countUserByDeptIds(Set deptIds) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.in(SystemUserTb::getDeptId, deptIds); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java index ed5c0bab..b7966eef 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java @@ -33,6 +33,9 @@ public class SystemUserJobService { @Autowired private SystemUserJobMapper systemUserJobMapper; + /** + * 批量绑定用户岗位 -> TestPassed + */ @Transactional(rollbackFor = Exception.class) public void batchInsertUserJob(Set jobs, Long userId) { if (CollUtil.isNotEmpty(jobs)) { @@ -47,6 +50,9 @@ public class SystemUserJobService { } } + /** + * 批量解绑用户岗位 -> TestPassed + */ @Transactional(rollbackFor = Exception.class) public void batchDeleteUserJob(Set userIds) { if (CollUtil.isNotEmpty(userIds)) { @@ -57,9 +63,9 @@ public class SystemUserJobService { } /** - * 根据岗位ID统计用户数量 + * 根据岗位ID统计用户数量 -> TestPassed * - * @param jobIds 岗位ID集合 + * @param jobIds / * @return / */ public Long countUserByJobIds(Set jobIds) { @@ -71,6 +77,12 @@ public class SystemUserJobService { return systemUserJobMapper.selectCount(wrapper); } + /** + * 根据用户id列举岗位 -> TestPassed + * + * @param userId / + * @return / + */ public Set listUserJobByUserId(Long userId) { return systemUserJobMapper.listUserJobByUserId(userId); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java index 0e82aabe..d882fbea 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java @@ -50,6 +50,9 @@ public class SystemUserRoleService { @Autowired private SystemRoleDeptService systemRoleDeptService; + /** + * 批量绑定用户角色 -> TestPassed + */ @Transactional(rollbackFor = Exception.class) public void batchInsertUserRole(Set roles, Long userId) { if (CollUtil.isNotEmpty(roles)) { @@ -64,6 +67,9 @@ public class SystemUserRoleService { } } + /** + * 批量解绑用户角色 -> TestPassed + */ @Transactional(rollbackFor = Exception.class) public void batchDeleteUserRole(Set userIds) { if (CollUtil.isNotEmpty(userIds)) { @@ -94,18 +100,18 @@ public class SystemUserRoleService { } /** - * 根据用户ID查询 + * 根据用户ID查询 -> TestPassed * * @param userId 用户ID * @return / */ - public List queryRoleVoByUsersId(Long userId) { + public List listRoleVoByUsersId(Long userId) { Set roles = this.listUserRoleByUserId(userId); return roles.stream().map(this::convertToRoleVo).collect(Collectors.toList()); } /** - * 根据角色查询角色级别 + * 根据角色查询角色级别 -> TestPassed * * @param roles / * @return / @@ -115,16 +121,12 @@ public class SystemUserRoleService { // 最小权限 return Integer.MAX_VALUE; } - List roleIds = - roles.stream().map(SystemRoleTb::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList()); + List roleIds = roles.stream().map(SystemRoleTb::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList()); if (CollUtil.isEmpty(roleIds)) { // 最小权限 return Integer.MAX_VALUE; } - List roleLevels = systemRoleMapper.selectList( - new LambdaQueryWrapper().select(SystemRoleTb::getLevel).isNotNull(SystemRoleTb::getLevel) - .in(SystemRoleTb::getId, roleIds)).stream().map(SystemRoleTb::getLevel).distinct() - .collect(Collectors.toList()); + List roleLevels = systemRoleMapper.listRoleLevelByRoleIds(roleIds); if (CollUtil.isEmpty(roleLevels)) { // 最小权限 return Integer.MAX_VALUE; @@ -133,14 +135,13 @@ public class SystemUserRoleService { } /** - * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 + * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 -> TestPassed * * @param args / */ public void checkLevel(SystemUserVo args) { - Integer currentLevel = Collections.min( - this.queryRoleVoByUsersId(KitSecurityHelper.getCurrentUserId()).stream().map(SystemRoleVo::getLevel) - .collect(Collectors.toList())); + List roleLevels = systemUserRoleMapper.listUserRoleLevelByUserId(KitSecurityHelper.getCurrentUserId()); + Integer currentLevel = Collections.min(roleLevels); Integer optLevel = this.getDeptLevelByRoles(args.getRoles()); if (currentLevel > optLevel) { throw new BadRequestException("角色权限不足"); @@ -156,7 +157,23 @@ public class SystemUserRoleService { return systemUserRoleMapper.selectCount(wrapper); } + /** + * 根据用户id列举角色 -> TestPassed + * + * @param userId / + * @return / + */ public Set listUserRoleByUserId(Long userId) { return systemUserRoleMapper.listUserRoleByUserId(userId); } + + /** + * 根据用户id列举角色级别 -> TestPassed + * + * @param userId / + * @return / + */ + public List listUserRoleLevelByUserId(Long userId) { + return systemUserRoleMapper.listUserRoleLevelByUserId(userId); + } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java index 1fa9abfc..aa439fde 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java @@ -32,7 +32,6 @@ import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.model.export.SystemUserExportRowVo; import cn.odboy.system.dal.model.request.SystemQueryUserArgs; import cn.odboy.system.dal.model.request.SystemUpdateUserPasswordArgs; -import cn.odboy.system.dal.model.response.SystemRoleVo; import cn.odboy.system.dal.model.response.SystemUserVo; import cn.odboy.system.dal.mysql.SystemUserMapper; import cn.odboy.system.dal.redis.SystemUserInfoDAO; @@ -42,12 +41,10 @@ import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitRsaEncryptUtil; -import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -57,6 +54,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -91,7 +89,7 @@ public class SystemUserService { private PasswordEncoder passwordEncoder; /** - * 新增用户 + * 新增用户 -> TestPassed * * @param args / */ @@ -102,13 +100,13 @@ public class SystemUserService { // 默认密码 123456 record.setPassword(passwordEncoder.encode("123456")); record.setDeptId(args.getDept().getId()); - if (this.getUserByUsername(record.getUsername()) != null) { + if (this.existUserWithUsername(record.getUsername())) { throw new BadRequestException("用户名已存在"); } - if (this.getUserByEmail(record.getEmail()) != null) { + if (this.existUserWithEmail(record.getEmail())) { throw new BadRequestException("邮箱已存在"); } - if (this.getUserByPhone(record.getPhone()) != null) { + if (this.existUserWithPhone(record.getPhone())) { throw new BadRequestException("手机号已存在"); } // 保存用户 @@ -119,8 +117,29 @@ public class SystemUserService { systemUserRoleService.batchInsertUserRole(args.getRoles(), record.getId()); } + private boolean existUserWithPhone(String phone) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemUserTb::getPhone, phone); + wrapper.eq(SystemUserTb::getEnabled, 1); + return systemUserMapper.exists(wrapper); + } + + private boolean existUserWithEmail(String email) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemUserTb::getEmail, email); + wrapper.eq(SystemUserTb::getEnabled, 1); + return systemUserMapper.exists(wrapper); + } + + private boolean existUserWithUsername(String username) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemUserTb::getUsername, username); + wrapper.eq(SystemUserTb::getEnabled, 1); + return systemUserMapper.exists(wrapper); + } + /** - * 编辑用户 + * 编辑用户 -> TestPassed * * @param args / */ @@ -128,16 +147,13 @@ public class SystemUserService { public void updateUserById(SystemUserVo args) { systemUserRoleService.checkLevel(args); SystemUserTb user = systemUserMapper.selectById(args.getId()); - SystemUserTb user1 = this.getUserByUsername(args.getUsername()); - SystemUserTb user2 = this.getUserByEmail(args.getEmail()); - SystemUserTb user3 = this.getUserByPhone(args.getPhone()); - if (user1 != null && !user.getId().equals(user1.getId())) { + if (this.existUserWithUsernameNeSelf(args.getUsername(), user.getId())) { throw new BadRequestException("用户名已存在"); } - if (user2 != null && !user.getId().equals(user2.getId())) { + if (this.existUserWithEmailNeSelf(args.getEmail(), user.getId())) { throw new BadRequestException("邮箱已存在"); } - if (user3 != null && !user.getId().equals(user3.getId())) { + if (this.existUserWithPhoneNeSelf(args.getPhone(), user.getId())) { throw new BadRequestException("手机号已存在"); } // 如果用户被禁用, 则清除用户登录信息 @@ -162,8 +178,29 @@ public class SystemUserService { systemUserRoleService.batchInsertUserRole(args.getRoles(), args.getId()); } + private boolean existUserWithPhoneNeSelf(String phone, Long currentUserId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemUserTb::getPhone, phone); + wrapper.ne(SystemUserTb::getId, currentUserId); + return systemUserMapper.exists(wrapper); + } + + private boolean existUserWithEmailNeSelf(String email, Long currentUserId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemUserTb::getEmail, email); + wrapper.ne(SystemUserTb::getId, currentUserId); + return systemUserMapper.exists(wrapper); + } + + private boolean existUserWithUsernameNeSelf(String username, Long currentUserId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SystemUserTb::getUsername, username); + wrapper.ne(SystemUserTb::getId, currentUserId); + return systemUserMapper.exists(wrapper); + } + /** - * 用户自助修改资料 + * 用户自助修改资料 -> TestPassed * * @param args / */ @@ -173,19 +210,18 @@ public class SystemUserService { throw new BadRequestException("不能修改他人资料"); } SystemUserTb user = systemUserMapper.selectById(args.getId()); - SystemUserTb user1 = this.getUserByPhone(args.getPhone()); - if (user1 != null && !user.getId().equals(user1.getId())) { + if (this.existUserWithPhoneNeSelf(args.getPhone(), user.getId())) { throw new BadRequestException("手机号已存在"); } user.setNickName(args.getNickName()); user.setPhone(args.getPhone()); user.setGender(args.getGender()); - systemUserMapper.insertOrUpdate(user); + systemUserMapper.updateById(user); systemUserInfoDAO.deleteUserLoginInfoByUserName(user.getUsername()); } /** - * 删除用户 + * 删除用户 -> TestPassed * * @param ids / */ @@ -194,19 +230,15 @@ public class SystemUserService { Long currentUserId = KitSecurityHelper.getCurrentUserId(); // 校验权限 for (Long id : ids) { - Integer currentLevel = Collections.min( - systemUserRoleService.queryRoleVoByUsersId(currentUserId).stream().map(SystemRoleVo::getLevel) - .collect(Collectors.toList())); - Integer optLevel = Collections.min( - systemUserRoleService.queryRoleVoByUsersId(id).stream().map(SystemRoleVo::getLevel) - .collect(Collectors.toList())); + Integer currentLevel = Collections.min(systemUserRoleService.listUserRoleLevelByUserId(currentUserId)); + Integer optLevel = Collections.min(systemUserRoleService.listUserRoleLevelByUserId(id)); if (currentLevel > optLevel) { - throw new BadRequestException("角色权限不足, 不能删除:" + this.getUserById(id).getUsername()); + SystemUserTb systemUserTb = systemUserMapper.selectById(id); + throw new BadRequestException("角色权限不足, 不能删除:" + systemUserTb.getUsername()); } } // 清理缓存 - List usernameList = systemUserMapper.selectByIds(ids).stream().map(SystemUserTb::getUsername).distinct() - .collect(Collectors.toList()); + List usernameList = systemUserMapper.listUsernameByIds(ids); for (String username : usernameList) { systemUserInfoDAO.deleteUserLoginInfoByUserName(username); } @@ -219,7 +251,7 @@ public class SystemUserService { } /** - * 修改密码 + * 修改密码 -> TestPassed * * @param username 用户名 * @param args 参数 @@ -241,27 +273,27 @@ public class SystemUserService { } /** - * 重置密码 + * 重置密码 -> TestPassed * * @param ids 用户id */ @Transactional(rollbackFor = Exception.class) public void resetUserPasswordByIds(Set ids) { String defaultPwd = passwordEncoder.encode("123456"); - List users = systemUserMapper.selectByIds(ids); + List users = systemUserMapper.listUsernameByIds(ids); // 清除缓存 - for (SystemUserTb user : users) { + for (String username : users) { // 清除缓存 - systemUserInfoDAO.deleteUserLoginInfoByUserName(user.getUsername()); + systemUserInfoDAO.deleteUserLoginInfoByUserName(username); // 强制退出 - systemUserOnlineInfoDAO.kickOutByUsername(user.getUsername()); + systemUserOnlineInfoDAO.kickOutByUsername(username); } // 重置密码 systemUserMapper.updateUserPasswordByUserIds(defaultPwd, ids); } /** - * 修改头像 + * 修改头像 -> TestPassed * * @param multipartFile 文件 * @return / @@ -271,7 +303,7 @@ public class SystemUserService { SystemUserTb user = this.getUserByUsername(KitSecurityHelper.getCurrentUsername()); String username = user.getUsername(); if (StrUtil.isBlank(username)) { - throw new BadRequestException("异常用户数据, 请联系管理员处理"); + throw new BadRequestException("异常用户数据, 请联系管理员处理!"); } // 文件大小验证 KitFileUtil.checkSize(fileUploadPathHelper.getAvatarMaxSize(), multipartFile.getSize()); @@ -279,13 +311,13 @@ public class SystemUserService { String image = "gif jpg png jpeg"; String fileType = KitFileUtil.getSuffix(multipartFile.getOriginalFilename()); if (fileType != null && !image.contains(fileType)) { - throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式"); + throw new BadRequestException("文件格式错误, 仅支持 " + image + " 格式!"); } String oldPath = user.getAvatarPath(); File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath()); user.setAvatarPath(Objects.requireNonNull(file).getPath()); user.setAvatarName(file.getName()); - systemUserMapper.insertOrUpdate(user); + systemUserMapper.updateById(user); if (StrUtil.isNotBlank(oldPath)) { KitFileUtil.del(oldPath); } @@ -296,7 +328,7 @@ public class SystemUserService { } /** - * 修改邮箱 + * 修改邮箱 -> TestPassed * * @param username 用户名 * @param args 参数 @@ -304,8 +336,7 @@ public class SystemUserService { */ @Transactional(rollbackFor = Exception.class) public void updateUserEmailByUsername(String username, SystemUserTb args, String code) throws Exception { - String password = - KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getPassword()); + String password = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getPassword()); SystemUserTb user = this.getUserByUsername(username); if (!passwordEncoder.matches(password, user.getPassword())) { throw new BadRequestException("密码错误"); @@ -316,7 +347,7 @@ public class SystemUserService { } /** - * 查询全部 + * 查询全部 -> TestPassed * * @param args 条件 * @param page 分页参数 @@ -328,8 +359,7 @@ public class SystemUserService { IPage userPage = systemUserMapper.selectPage(page, wrapper); List users = userPage.getRecords(); // 转换为SystemUserVo并关联查询 - List userVos = - users.stream().map(m -> this.convertToUserVo(m, false)).collect(Collectors.toList()); + List userVos = users.stream().map(m -> this.convertToUserVo(m, false)).collect(Collectors.toList()); return KitPageUtil.toPage(userVos, userPage.getTotal()); } @@ -338,16 +368,6 @@ public class SystemUserService { return systemUserMapper.selectCount(wrapper); } - /** - * 根据ID查询 - * - * @param id ID - * @return / - */ - public SystemUserTb getUserById(long id) { - return systemUserMapper.selectById(id); - } - public List queryUserMetadataOptions(KitPageArgs pageArgs) { SystemQueryUserArgs args = pageArgs.getArgs(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -372,36 +392,37 @@ public class SystemUserService { } /** - * 构建用户查询条件 + * 构建用户查询条件 -> TestPassed * * @param args 查询条件 * @return / */ private LambdaQueryWrapper buildUserQueryWrapper(SystemQueryUserArgs args) { - KitValidUtil.notNull(args); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - if (args.getId() != null) { - wrapper.eq(SystemUserTb::getId, args.getId()); - } - if (args.getEnabled() != null) { - wrapper.eq(SystemUserTb::getEnabled, args.getEnabled()); - } - if (CollUtil.isNotEmpty(args.getDeptIds())) { - wrapper.in(SystemUserTb::getDeptId, args.getDeptIds()); - } - if (StrUtil.isNotBlank(args.getBlurry())) { - wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()).or() - .like(SystemUserTb::getNickName, args.getBlurry()).or().like(SystemUserTb::getEmail, args.getBlurry())); - } - if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { - wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1)); + if (args != null) { + if (args.getId() != null) { + wrapper.eq(SystemUserTb::getId, args.getId()); + } + if (args.getEnabled() != null) { + wrapper.eq(SystemUserTb::getEnabled, args.getEnabled()); + } + if (CollUtil.isNotEmpty(args.getDeptIds())) { + wrapper.in(SystemUserTb::getDeptId, args.getDeptIds()); + } + if (StrUtil.isNotBlank(args.getBlurry())) { + wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()).or() + .like(SystemUserTb::getNickName, args.getBlurry()).or().like(SystemUserTb::getEmail, args.getBlurry())); + } + if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { + wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1)); + } } wrapper.orderByDesc(SystemUserTb::getCreateTime); return wrapper; } /** - * 转换为SystemUserVo并关联查询部门、角色、岗位信息 + * 转换为SystemUserVo并关联查询部门、角色、岗位信息 -> TestPassed * * @param user 用户基本信息 * @param includePassword 是否包含用户密码 @@ -442,28 +463,16 @@ public class SystemUserService { return this.convertToUserVo(this.getUserByUsername(username), false); } - public SystemUserTb getUserByEmail(String email) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(SystemUserTb::getEmail, email); - wrapper.eq(SystemUserTb::getEnabled, 1); - return systemUserMapper.selectOne(wrapper); - } - - public SystemUserTb getUserByPhone(String phone) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(SystemUserTb::getPhone, phone); - wrapper.eq(SystemUserTb::getEnabled, 1); - return systemUserMapper.selectOne(wrapper); - } - + /** + * 聚合查询 -> TestPassed + */ public KitPageResult aggregationSearchUserByArgs(Page page, SystemQueryUserArgs args, String currentUsername) { if (!ObjectUtils.isEmpty(args.getDeptId())) { args.getDeptIds().add(args.getDeptId()); // 先查找是否存在子节点 List data = systemDeptService.listDeptByPid(args.getDeptId()); - Map> deptPidMap = - systemDeptService.listPidNonNull().stream().collect(Collectors.groupingBy(SystemDeptTb::getPid)); + Map> deptPidMap = systemDeptService.listPidNonNull().stream().collect(Collectors.groupingBy(SystemDeptTb::getPid)); // 然后把子节点的ID都加入到集合中 args.getDeptIds().addAll(systemDeptService.queryChildDeptIdByDeptIds(data, deptPidMap)); } @@ -484,6 +493,9 @@ public class SystemUserService { return KitPageUtil.emptyData(); } + /** + * 导出 -> TestPassed + */ public void exportUserXlsx(HttpServletResponse response, SystemQueryUserArgs args) { long totalCount = this.countUserByArgs(args); KitExcelExporter.exportByPage(response, "用户数据", SystemUserExportRowVo.class, totalCount, diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java index b34a1501..ce6373db 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java @@ -39,9 +39,9 @@ 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.impl.ServiceImpl; -import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.util.List; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/cutejava-springboot3/cutejava-starter/src/main/resources/logback.xml b/cutejava-springboot3/cutejava-starter/src/main/resources/logback.xml index 6e9cdd7a..51c5437f 100644 --- a/cutejava-springboot3/cutejava-starter/src/main/resources/logback.xml +++ b/cutejava-springboot3/cutejava-starter/src/main/resources/logback.xml @@ -1,44 +1,40 @@ - CuteJava - - - - - - - - - - - - - - - - - ${log.pattern} - ${log.charset} - - - - - ${log.home}/${log.name}.log - - ${log.home}/${log.name}.log.%d{yyyy-MM-dd}.%i.log - 90 - 100MB - - - ${log.pattern} - - - - - - - - - + CuteJava + + + + + + + + + + + + + + + ${log.pattern} + ${log.charset} + + + + ${log.home}/${log.name}.log + + ${log.home}/${log.name}.log.%d{yyyy-MM-dd}.%i.log + 90 + 100MB + + + ${log.pattern} + + + + + + + + \ No newline at end of file diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java index 3c513b29..56e305d8 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java @@ -24,6 +24,7 @@ import cn.odboy.system.dal.model.request.SystemUpdateQuartzJobArgs; import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.framework.operalog.OperationLog; import cn.odboy.system.service.SystemQuartzJobService; +import cn.odboy.util.KitBeanUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -86,7 +87,7 @@ public class SystemQuartzJobController { @ApiOperation("新增定时任务") @PostMapping(value = "/createQuartzJob") @PreAuthorize("@el.check('quartzJob:add')") - public ResponseEntity createQuartzJob(@Validated @RequestBody SystemQuartzJobVo args) { + public ResponseEntity createQuartzJob(@Validated @RequestBody SystemQuartzJobTb args) { systemQuartzJobService.createJob(args); return ResponseEntity.ok(null); } @@ -106,7 +107,9 @@ public class SystemQuartzJobController { @PostMapping(value = "/switchQuartzJobStatus/{id}") @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity switchQuartzJobStatus(@PathVariable Long id) { - systemQuartzJobService.switchQuartzJobStatus(systemQuartzJobService.getQuartzJobById(id)); + SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); + systemQuartzJobService.switchQuartzJobStatus(quartzJobVo); return ResponseEntity.ok(null); } @@ -115,7 +118,9 @@ public class SystemQuartzJobController { @PostMapping(value = "/startQuartzJob/{id}") @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity startQuartzJob(@PathVariable Long id) { - systemQuartzJobService.startQuartzJob(systemQuartzJobService.getQuartzJobById(id)); + SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); + systemQuartzJobService.startQuartzJob(quartzJobVo); return ResponseEntity.ok(null); } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java index 0b1cfb82..64c70147 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/mysql/SystemQuartzJobMapper.java @@ -16,8 +16,6 @@ package cn.odboy.system.dal.mysql; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; -import cn.odboy.util.KitBeanUtil; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; @@ -29,7 +27,4 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface SystemQuartzJobMapper extends BaseMapper { - default SystemQuartzJobVo selectVoById(String id) { - return KitBeanUtil.copyToClass(selectById(id), SystemQuartzJobVo.class); - } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java index 3f5427c0..d3d5999c 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java @@ -15,8 +15,10 @@ */ package cn.odboy.system.framework.quartz; +import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.service.SystemQuartzJobService; +import cn.odboy.util.KitBeanUtil; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -40,8 +42,9 @@ public class ActiveJobRegister implements ApplicationRunner { */ @Override public void run(ApplicationArguments applicationArguments) { - List quartzJobs = systemQuartzJobService.listEnableQuartzJob(); - quartzJobs.forEach(quartzManage::addJob); + List quartzJobTbs = systemQuartzJobService.listEnableQuartzJob(); + List quartzJobVos = KitBeanUtil.copyToList(quartzJobTbs, SystemQuartzJobVo.class); + quartzJobVos.forEach(quartzManage::addJob); log.info("Timing task injection complete"); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java index fa6d0006..21768809 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java @@ -18,6 +18,7 @@ package cn.odboy.system.framework.quartz; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.model.response.SystemQuartzJobVo; +import cn.odboy.util.KitBeanUtil; import java.util.Date; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -45,12 +46,17 @@ public class QuartzManage { public void addJob(SystemQuartzJobVo quartzJob) { try { + String uuid = JOB_NAME + quartzJob.getId(); // 构建job信息 - JobDetail jobDetail = - JobBuilder.newJob(ExecutionJobBean.class).withIdentity(JOB_NAME + quartzJob.getId()).build(); + JobDetail jobDetail = JobBuilder.newJob(ExecutionJobBean.class) + .withIdentity(uuid) + .build(); // 通过触发器名和cron 表达式创建 Trigger - Trigger trigger = TriggerBuilder.newTrigger().withIdentity(JOB_NAME + quartzJob.getId()).startNow() - .withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression())).build(); + Trigger trigger = TriggerBuilder.newTrigger() + .withIdentity(uuid) + .startNow() + .withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression())) + .build(); trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJob); // 重置启动时间 ((CronTriggerImpl) trigger).setStartTime(new Date()); @@ -75,24 +81,25 @@ public class QuartzManage { * * @param quartzJob / */ - public void updateJobCron(SystemQuartzJobVo quartzJob) { + public void updateJobCron(SystemQuartzJobTb quartzJob) { try { - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobVo.class); + TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJobVo.getId()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 如果不存在则创建一个定时任务 if (trigger == null) { - addJob(quartzJob); + addJob(quartzJobVo); trigger = (CronTrigger) scheduler.getTrigger(triggerKey); } - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression()); + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJobVo.getCronExpression()); trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); // 重置启动时间 ((CronTriggerImpl) trigger).setStartTime(new Date()); - trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJob); + trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJobVo); scheduler.rescheduleJob(triggerKey, trigger); // 暂停任务 - if (quartzJob.getIsPause()) { - pauseJob(quartzJob); + if (quartzJobVo.getIsPause()) { + pauseJob(quartzJobVo); } } catch (Exception e) { log.error("更新定时任务失败", e); @@ -144,7 +151,8 @@ public class QuartzManage { */ public void runJobNow(SystemQuartzJobVo quartzJob) { try { - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); + String uuid = JOB_NAME + quartzJob.getId(); + TriggerKey triggerKey = TriggerKey.triggerKey(uuid); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 如果不存在则创建一个定时任务 if (trigger == null) { @@ -152,7 +160,7 @@ public class QuartzManage { } JobDataMap dataMap = new JobDataMap(); dataMap.put(SystemQuartzJobTb.JOB_KEY, quartzJob); - JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); + JobKey jobKey = JobKey.jobKey(uuid); scheduler.triggerJob(jobKey, dataMap); } catch (Exception e) { log.error("定时任务执行失败", e); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java index 437bcc68..7cd58900 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java @@ -156,6 +156,9 @@ public class SystemLocalStorageService { wrapper.orderByDesc(SystemLocalStorageTb::getId); } + /** + * 查询文件上传记录 -> TestPassed + */ public List queryLocalStorageByArgs(SystemQueryStorageArgs args) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); this.injectQueryParams(args, wrapper); @@ -163,7 +166,7 @@ public class SystemLocalStorageService { } /** - * 上传图片 + * 上传图片 -> TestPassed */ @Transactional(rollbackFor = Exception.class) public SystemLocalStorageTb uploadPicture(MultipartFile file) { @@ -176,12 +179,11 @@ public class SystemLocalStorageService { } /** - * 导出文件上传记录 + * 导出文件上传记录 -> TestPassed */ public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) { List systemLocalStorageTbs = this.queryLocalStorageByArgs(args); - List rowVos = - KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class); + List rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class); KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java index f5bffc9e..6dc6dbb7 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java @@ -75,7 +75,7 @@ public class SystemMonitorService { } /** - * 查询磁盘信息 + * 查询磁盘信息 -> TestPassed * * @return / */ @@ -109,7 +109,7 @@ public class SystemMonitorService { } /** - * 查询交换区信息 + * 查询交换区信息 -> TestPassed * * @param memory / * @return / @@ -131,7 +131,7 @@ public class SystemMonitorService { } /** - * 查询内存信息 + * 查询内存信息 -> TestPassed * * @param memory / * @return / @@ -147,7 +147,7 @@ public class SystemMonitorService { } /** - * 查询Cpu相关信息 + * 查询Cpu相关信息 -> TestPassed * * @param processor / * @return / @@ -194,7 +194,7 @@ public class SystemMonitorService { } /** - * 查询系统相关信息,系统、运行天数、系统IP + * 查询系统相关信息,系统、运行天数、系统IP -> TestPassed * * @param os / * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java index 1742dbe1..3b3b7481 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java @@ -18,7 +18,7 @@ public class SystemOperationLogService { private SystemOperationLogMapper systemOperationLogMapper; /** - * 查询用户操作日志 + * 查询用户操作日志 -> TestPassed */ public IPage searchUserLog(KitPageArgs pageArgs) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java index 89b1cf6d..d71d2cef 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java @@ -34,7 +34,6 @@ import cn.odboy.system.dal.mysql.SystemQuartzLogMapper; import cn.odboy.system.framework.quartz.QuartzManage; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; -import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -79,7 +78,7 @@ public class SystemQuartzJobService { * @param args / */ @Transactional(rollbackFor = Exception.class) - public void createJob(SystemQuartzJobVo args) { + public void createJob(SystemQuartzJobTb args) { if (args.getId() != null) { throw new BadRequestException("无效参数id"); } @@ -88,9 +87,9 @@ public class SystemQuartzJobService { if (!CronExpression.isValidExpression(args.getCronExpression())) { throw new BadRequestException("cron表达式格式错误"); } - SystemQuartzJobTb record = KitBeanUtil.copyToClass(args, SystemQuartzJobTb.class); - systemQuartzJobMapper.insert(record); - quartzManage.addJob(args); + systemQuartzJobMapper.insert(args); + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(args, SystemQuartzJobVo.class); + quartzManage.addJob(quartzJobVo); } /** @@ -112,28 +111,27 @@ public class SystemQuartzJobService { } } SystemQuartzJobTb jobTb = KitBeanUtil.copyToClass(args, SystemQuartzJobTb.class); - systemQuartzJobMapper.insertOrUpdate(jobTb); - SystemQuartzJobVo jobVo = KitBeanUtil.copyToClass(args, SystemQuartzJobVo.class); - quartzManage.updateJobCron(jobVo); + systemQuartzJobMapper.updateById(jobTb); + quartzManage.updateJobCron(jobTb); } /** * 更改定时任务状态 * - * @param quartzJob / + * @param quartzJobVo / */ @Transactional(rollbackFor = Exception.class) - public void switchQuartzJobStatus(SystemQuartzJobVo quartzJob) { + public void switchQuartzJobStatus(SystemQuartzJobVo quartzJobVo) { // 置换暂停状态 - if (quartzJob.getIsPause()) { - quartzManage.resumeJob(quartzJob); - quartzJob.setIsPause(false); + if (quartzJobVo.getIsPause()) { + quartzManage.resumeJob(quartzJobVo); + quartzJobVo.setIsPause(false); } else { - quartzManage.pauseJob(quartzJob); - quartzJob.setIsPause(true); + quartzManage.pauseJob(quartzJobVo); + quartzJobVo.setIsPause(true); } - SystemQuartzJobTb quartzJobTb = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobTb.class); - systemQuartzJobMapper.insertOrUpdate(quartzJobTb); + SystemQuartzJobTb record = KitBeanUtil.copyToClass(quartzJobVo, SystemQuartzJobTb.class); + systemQuartzJobMapper.updateById(record); } /** @@ -172,16 +170,16 @@ public class SystemQuartzJobService { // 如果是手动清除子任务id, 会出现id为空字符串的问题 continue; } - SystemQuartzJobVo quartzJob = systemQuartzJobMapper.selectVoById(id); - if (quartzJob == null) { + SystemQuartzJobTb quartzJobTb = systemQuartzJobMapper.selectById(id); + if (quartzJobTb == null) { // 防止子任务不存在 continue; } + SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); // 执行任务 String uuid = IdUtil.simpleUUID(); - quartzJob.setUuid(uuid); - // 执行任务 - startQuartzJob(quartzJob); + quartzJobVo.setUuid(uuid); + startQuartzJob(quartzJobVo); // 查询执行状态, 如果执行失败则停止后面的子任务执行 Boolean result = redisHelper.get(uuid, Boolean.class); while (result == null) { @@ -203,25 +201,23 @@ public class SystemQuartzJobService { * @param page 分页参数 * @return / */ - public KitPageResult searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, - Page page) { + public KitPageResult searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, Page page) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); this.injectQuartzJobQueryParams(args, wrapper); return KitPageUtil.toPage(systemQuartzJobMapper.selectPage(page, wrapper)); } - private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, - LambdaQueryWrapper wrapper) { - KitValidUtil.notNull(args); - wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, args.getJobName()); - if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { - wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1)); + private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper wrapper) { + if (args != null) { + wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, args.getJobName()); + if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { + wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1)); + } } wrapper.orderByDesc(SystemQuartzJobTb::getId); } - private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, - LambdaQueryWrapper wrapper) { + private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper wrapper) { if (args != null) { wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzLogTb::getJobName, args.getJobName()); wrapper.eq(args.getIsSuccess() != null, SystemQuartzLogTb::getIsSuccess, args.getIsSuccess()); @@ -271,16 +267,15 @@ public class SystemQuartzJobService { return systemQuartzLogMapper.selectList(wrapper); } - public SystemQuartzJobVo getQuartzJobById(Long id) { - return KitBeanUtil.copyToClass(systemQuartzJobMapper.selectById(id), SystemQuartzJobVo.class); - } - - public List listEnableQuartzJob() { + public List listEnableQuartzJob() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(SystemQuartzJobTb::getIsPause, 0); - return KitBeanUtil.copyToList(systemQuartzJobMapper.selectList(wrapper), SystemQuartzJobVo.class); + return systemQuartzJobMapper.selectList(wrapper); } + /** + * 导出定时任务数据 -> TestPassed + */ public void exportQuartzJobXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzJobTbs = this.queryQuartzJobByArgs(args); List rowVos = new ArrayList<>(); @@ -299,6 +294,9 @@ public class SystemQuartzJobService { KitExcelExporter.exportSimple(response, "定时任务数据", SystemQuartzJobExportRowVo.class, rowVos); } + /** + * 导出定时任务日志数据 -> TestPassed + */ public void exportQuartzLogXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzLogTbs = this.queryQuartzLogByArgs(args); List rowVos = new ArrayList<>(); @@ -317,4 +315,8 @@ public class SystemQuartzJobService { } KitExcelExporter.exportSimple(response, "定时任务日志数据", SystemQuartzLogExportRowVo.class, rowVos); } + + public SystemQuartzJobTb getQuartzJobById(Long id) { + return systemQuartzJobMapper.selectById(id); + } }