refactor(quartz): 重构定时任务相关服务和控制器
This commit is contained in:
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
-11
@@ -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<Map<String, List<SystemDictDetailVo>>> getDictDetailMaps(@RequestParam String dictName) {
|
||||
Map<String, List<SystemDictDetailVo>> dictMap = systemDictDetailService.getDictDetailMap(dictName);
|
||||
return ResponseEntity.ok(dictMap);
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("新增字典详情")
|
||||
@PostMapping(value = "/saveDictDetail")
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class SystemLocalStorageController {
|
||||
@ApiOperation("上传图片")
|
||||
@PostMapping("/uploadPicture")
|
||||
public ResponseEntity<SystemLocalStorageTb> uploadPicture(@RequestParam MultipartFile file) {
|
||||
SystemLocalStorageTb localStorage = localStorageService.uploadPictureV1(file);
|
||||
SystemLocalStorageTb localStorage = localStorageService.uploadPicture(file);
|
||||
return ResponseEntity.ok(localStorage);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+9
-4
@@ -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<Void> createQuartzJob(@Validated @RequestBody SystemQuartzJobVo args) {
|
||||
public ResponseEntity<Void> 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<Void> 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<Void> 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);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+1
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -52,4 +52,4 @@ public class SystemSimpleUserVo extends KitObject {
|
||||
private Boolean enabled;
|
||||
@ApiModelProperty(value = "是否为admin账号", hidden = true)
|
||||
private Boolean isAdmin = false;
|
||||
}
|
||||
}
|
||||
-5
@@ -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<SystemQuartzJobTb> {
|
||||
|
||||
default SystemQuartzJobVo selectVoById(String id) {
|
||||
return KitBeanUtil.copyToClass(selectById(id), SystemQuartzJobVo.class);
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -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<SystemRoleTb> {
|
||||
|
||||
List<Integer> listRoleLevelByRoleIds(@Param("roleIds") List<Long> roleIds);
|
||||
}
|
||||
|
||||
+4
@@ -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<SystemUserTb> {
|
||||
wrapper.set(SystemUserTb::getPassword, password);
|
||||
update(null, wrapper);
|
||||
}
|
||||
|
||||
List<String> listUsernameByIds(@Param("userIds") Set<Long> userIds);
|
||||
}
|
||||
|
||||
+2
@@ -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<SystemUserRoleTb> {
|
||||
|
||||
Set<SystemRoleTb> listUserRoleByUserId(@Param("userId") Long userId);
|
||||
List<Integer> listUserRoleLevelByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+5
-2
@@ -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<SystemQuartzJobVo> quartzJobs = systemQuartzJobService.listEnableQuartzJob();
|
||||
quartzJobs.forEach(quartzManage::addJob);
|
||||
List<SystemQuartzJobTb> quartzJobTbs = systemQuartzJobService.listEnableQuartzJob();
|
||||
List<SystemQuartzJobVo> quartzJobVos = KitBeanUtil.copyToList(quartzJobTbs, SystemQuartzJobVo.class);
|
||||
quartzJobVos.forEach(quartzManage::addJob);
|
||||
log.info("Timing task injection complete");
|
||||
}
|
||||
}
|
||||
|
||||
+22
-14
@@ -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);
|
||||
|
||||
+2
-2
@@ -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();
|
||||
|
||||
+3
-4
@@ -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);
|
||||
|
||||
+4
-5
@@ -45,7 +45,7 @@ public class SystemDataService {
|
||||
private SystemRoleDeptService systemRoleDeptService;
|
||||
|
||||
/**
|
||||
* 获取数据权限 -> TestPassed
|
||||
* 查询数据权限 -> TestPassed
|
||||
*
|
||||
* @param user /
|
||||
* @return /
|
||||
@@ -54,7 +54,7 @@ public class SystemDataService {
|
||||
List<Long> deptIds = new ArrayList<>();
|
||||
// 查询用户角色
|
||||
Set<SystemRoleTb> 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<Long> queryCustomDataPermissionByArgs(List<Long> deptIds, Long roleId) {
|
||||
Set<SystemDeptTb> deptList = systemRoleDeptService.listUserDeptByRoleId(roleId);
|
||||
Map<Long, List<SystemDeptTb>> deptPidMap =
|
||||
systemDeptService.listPidNonNull().stream().collect(Collectors.groupingBy(SystemDeptTb::getPid));
|
||||
Map<Long, List<SystemDeptTb>> deptPidMap = systemDeptService.listPidNonNull().stream().collect(Collectors.groupingBy(SystemDeptTb::getPid));
|
||||
for (SystemDeptTb dept : deptList) {
|
||||
deptIds.add(dept.getId());
|
||||
List<SystemDeptTb> deptChildren = deptPidMap.getOrDefault(dept.getId(), null);
|
||||
|
||||
+7
-7
@@ -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<Long> ids) {
|
||||
// 获取部门, 和其所有子部门
|
||||
// 查询部门, 和其所有子部门
|
||||
Set<SystemDeptVo> 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<SystemProductLineVo> buildDeptSelectOptions(List<SystemDeptTb> depts) {
|
||||
// 获取所有部门并按父子关系组织
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<SystemProductLineVo> options = new ArrayList<>();
|
||||
@@ -433,7 +433,7 @@ public class SystemDeptService {
|
||||
|
||||
public List<SystemProductLineTreeVo> listDeptSelectProDataSource() {
|
||||
List<SystemDeptTb> depts = this.listEnabledDepts();
|
||||
// 获取所有部门并按父子关系组织
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<SystemProductLineTreeVo> options = new ArrayList<>();
|
||||
|
||||
+1
-11
@@ -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<String, List<SystemDictDetailVo>> getDictDetailMap(String dictName) {
|
||||
String[] names = dictName.split("[,, ]");
|
||||
Map<String, List<SystemDictDetailVo>> dictMap = new HashMap<>(16);
|
||||
for (String name : names) {
|
||||
dictMap.put(name, this.listDictDetailByName(name));
|
||||
}
|
||||
return dictMap;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+22
-12
@@ -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<SystemJobTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemJobTb::getName, name);
|
||||
return systemJobMapper.selectOne(wrapper);
|
||||
return systemJobMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
public void injectQueryParams(SystemQueryJobArgs args, LambdaQueryWrapper<SystemJobTb> wrapper) {
|
||||
/**
|
||||
* 根据岗位名称和岗位id查询岗位是否存在 -> TestPassed
|
||||
*/
|
||||
private boolean existJobWithNameNeSelf(String name, Long currentJobId) {
|
||||
LambdaQueryWrapper<SystemJobTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemJobTb::getName, name);
|
||||
wrapper.ne(SystemJobTb::getId, currentJobId);
|
||||
return systemJobMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private void injectQueryParams(SystemQueryJobArgs args, LambdaQueryWrapper<SystemJobTb> 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<SystemJobTb> systemJobTbs = this.queryJobByArgs(args);
|
||||
List<SystemJobExportRowVo> rowVos = new ArrayList<>();
|
||||
@@ -150,8 +164,4 @@ public class SystemJobService {
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "岗位数据", SystemJobExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
public List<SystemJobTb> listByIds(Set<Long> jobIds) {
|
||||
return systemJobMapper.selectByIds(jobIds);
|
||||
}
|
||||
}
|
||||
|
||||
+23
-11
@@ -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<SystemLocalStorageTb> queryLocalStorageByArgs(SystemQueryStorageArgs args) {
|
||||
LambdaQueryWrapper<SystemLocalStorageTb> 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<SystemLocalStorageTb> systemLocalStorageTbs = this.queryLocalStorageByArgs(args);
|
||||
List<SystemLocalStorageExportRowVo> rowVos =
|
||||
KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
|
||||
List<SystemLocalStorageExportRowVo> rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
|
||||
KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -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<SystemMenuVo> listMenuByUserId(Long currentUserId) {
|
||||
List<SystemRoleVo> roles = systemUserRoleService.queryRoleVoByUsersId(currentUserId);
|
||||
List<SystemRoleVo> roles = systemUserRoleService.listRoleVoByUsersId(currentUserId);
|
||||
Set<Long> 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 /
|
||||
|
||||
+5
-5
@@ -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 /
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class SystemOperationLogService {
|
||||
private SystemOperationLogMapper systemOperationLogMapper;
|
||||
|
||||
/**
|
||||
* 查询用户操作日志
|
||||
* 查询用户操作日志 -> TestPassed
|
||||
*/
|
||||
public IPage<SystemOperationLogTb> searchUserLog(KitPageArgs<SystemQueryOperationLogArgs> pageArgs) {
|
||||
LambdaQueryWrapper<SystemOperationLogTb> wrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
+43
-41
@@ -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<SystemQuartzJobTb> searchQuartzJobByArgs(SystemQueryQuartzJobArgs args,
|
||||
Page<SystemQuartzJobTb> page) {
|
||||
public KitPageResult<SystemQuartzJobTb> searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, Page<SystemQuartzJobTb> page) {
|
||||
LambdaQueryWrapper<SystemQuartzJobTb> wrapper = new LambdaQueryWrapper<>();
|
||||
this.injectQuartzJobQueryParams(args, wrapper);
|
||||
return KitPageUtil.toPage(systemQuartzJobMapper.selectPage(page, wrapper));
|
||||
}
|
||||
|
||||
private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args,
|
||||
LambdaQueryWrapper<SystemQuartzJobTb> 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<SystemQuartzJobTb> 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<SystemQuartzLogTb> wrapper) {
|
||||
private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzLogTb> 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<SystemQuartzJobVo> listEnableQuartzJob() {
|
||||
public List<SystemQuartzJobTb> listEnableQuartzJob() {
|
||||
LambdaQueryWrapper<SystemQuartzJobTb> 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<SystemQuartzJobTb> systemQuartzJobTbs = this.queryQuartzJobByArgs(args);
|
||||
List<SystemQuartzJobExportRowVo> 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<SystemQuartzLogTb> systemQuartzLogTbs = this.queryQuartzLogByArgs(args);
|
||||
List<SystemQuartzLogExportRowVo> 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);
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -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<Long> roleIds) {
|
||||
|
||||
+13
-17
@@ -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<SystemRoleTb> listAllRole() {
|
||||
LambdaQueryWrapper<SystemRoleTb> 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<SystemRoleVo> roles = systemUserRoleService.queryRoleVoByUsersId(user.getId());
|
||||
List<SystemRoleVo> 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<Integer> levels = systemUserRoleService.queryRoleVoByUsersId(KitSecurityHelper.getCurrentUserId()).stream()
|
||||
List<Integer> 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<SystemRoleTb> listByIds(Set<Long> roleIds) {
|
||||
return systemRoleMapper.selectByIds(roleIds);
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -13,6 +13,9 @@ public class SystemUserDeptService {
|
||||
@Autowired
|
||||
private SystemUserMapper systemUserMapper;
|
||||
|
||||
/**
|
||||
* 根据部门id统计用户数量 -> TestPassed
|
||||
*/
|
||||
public long countUserByDeptIds(Set<Long> deptIds) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(SystemUserTb::getDeptId, deptIds);
|
||||
|
||||
+14
-2
@@ -33,6 +33,9 @@ public class SystemUserJobService {
|
||||
@Autowired
|
||||
private SystemUserJobMapper systemUserJobMapper;
|
||||
|
||||
/**
|
||||
* 批量绑定用户岗位 -> TestPassed
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchInsertUserJob(Set<SystemJobTb> jobs, Long userId) {
|
||||
if (CollUtil.isNotEmpty(jobs)) {
|
||||
@@ -47,6 +50,9 @@ public class SystemUserJobService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量解绑用户岗位 -> TestPassed
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchDeleteUserJob(Set<Long> 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<Long> jobIds) {
|
||||
@@ -71,6 +77,12 @@ public class SystemUserJobService {
|
||||
return systemUserJobMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id列举岗位 -> TestPassed
|
||||
*
|
||||
* @param userId /
|
||||
* @return /
|
||||
*/
|
||||
public Set<SystemJobTb> listUserJobByUserId(Long userId) {
|
||||
return systemUserJobMapper.listUserJobByUserId(userId);
|
||||
}
|
||||
|
||||
+30
-13
@@ -50,6 +50,9 @@ public class SystemUserRoleService {
|
||||
@Autowired
|
||||
private SystemRoleDeptService systemRoleDeptService;
|
||||
|
||||
/**
|
||||
* 批量绑定用户角色 -> TestPassed
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchInsertUserRole(Set<SystemRoleTb> roles, Long userId) {
|
||||
if (CollUtil.isNotEmpty(roles)) {
|
||||
@@ -64,6 +67,9 @@ public class SystemUserRoleService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量解绑用户角色 -> TestPassed
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchDeleteUserRole(Set<Long> userIds) {
|
||||
if (CollUtil.isNotEmpty(userIds)) {
|
||||
@@ -94,18 +100,18 @@ public class SystemUserRoleService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询
|
||||
* 根据用户ID查询 -> TestPassed
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemRoleVo> queryRoleVoByUsersId(Long userId) {
|
||||
public List<SystemRoleVo> listRoleVoByUsersId(Long userId) {
|
||||
Set<SystemRoleTb> 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<Long> roleIds =
|
||||
roles.stream().map(SystemRoleTb::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
List<Long> roleIds = roles.stream().map(SystemRoleTb::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(roleIds)) {
|
||||
// 最小权限
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
List<Integer> roleLevels = systemRoleMapper.selectList(
|
||||
new LambdaQueryWrapper<SystemRoleTb>().select(SystemRoleTb::getLevel).isNotNull(SystemRoleTb::getLevel)
|
||||
.in(SystemRoleTb::getId, roleIds)).stream().map(SystemRoleTb::getLevel).distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<Integer> 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<Integer> 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<SystemRoleTb> listUserRoleByUserId(Long userId) {
|
||||
return systemUserRoleMapper.listUserRoleByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id列举角色级别 -> TestPassed
|
||||
*
|
||||
* @param userId /
|
||||
* @return /
|
||||
*/
|
||||
public List<Integer> listUserRoleLevelByUserId(Long userId) {
|
||||
return systemUserRoleMapper.listUserRoleLevelByUserId(userId);
|
||||
}
|
||||
}
|
||||
|
||||
+100
-88
@@ -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<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getPhone, phone);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private boolean existUserWithEmail(String email) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getEmail, email);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private boolean existUserWithUsername(String username) {
|
||||
LambdaQueryWrapper<SystemUserTb> 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<SystemUserTb> 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<SystemUserTb> 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<SystemUserTb> 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<String> usernameList = systemUserMapper.selectByIds(ids).stream().map(SystemUserTb::getUsername).distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<String> 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<Long> ids) {
|
||||
String defaultPwd = passwordEncoder.encode("123456");
|
||||
List<SystemUserTb> users = systemUserMapper.selectByIds(ids);
|
||||
List<String> 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<SystemUserTb> userPage = systemUserMapper.selectPage(page, wrapper);
|
||||
List<SystemUserTb> users = userPage.getRecords();
|
||||
// 转换为SystemUserVo并关联查询
|
||||
List<SystemUserVo> userVos =
|
||||
users.stream().map(m -> this.convertToUserVo(m, false)).collect(Collectors.toList());
|
||||
List<SystemUserVo> 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<KitSelectOptionVo> queryUserMetadataOptions(KitPageArgs<SystemQueryUserArgs> pageArgs) {
|
||||
SystemQueryUserArgs args = pageArgs.getArgs();
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
@@ -372,36 +392,37 @@ public class SystemUserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建用户查询条件
|
||||
* 构建用户查询条件 -> TestPassed
|
||||
*
|
||||
* @param args 查询条件
|
||||
* @return /
|
||||
*/
|
||||
private LambdaQueryWrapper<SystemUserTb> buildUserQueryWrapper(SystemQueryUserArgs args) {
|
||||
KitValidUtil.notNull(args);
|
||||
LambdaQueryWrapper<SystemUserTb> 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<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getEmail, email);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
public SystemUserTb getUserByPhone(String phone) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getPhone, phone);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合查询 -> TestPassed
|
||||
*/
|
||||
public KitPageResult<SystemUserVo> aggregationSearchUserByArgs(Page<SystemUserTb> page, SystemQueryUserArgs args,
|
||||
String currentUsername) {
|
||||
if (!ObjectUtils.isEmpty(args.getDeptId())) {
|
||||
args.getDeptIds().add(args.getDeptId());
|
||||
// 先查找是否存在子节点
|
||||
List<SystemDeptTb> data = systemDeptService.listDeptByPid(args.getDeptId());
|
||||
Map<Long, List<SystemDeptTb>> deptPidMap =
|
||||
systemDeptService.listPidNonNull().stream().collect(Collectors.groupingBy(SystemDeptTb::getPid));
|
||||
Map<Long, List<SystemDeptTb>> 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,
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -1,44 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="30 seconds" debug="false">
|
||||
<contextName>CuteJava</contextName>
|
||||
<property name="log.name" value="cutejava"/>
|
||||
<property name="log.home" value="/var/logs"/>
|
||||
<property name="log.charset" value="utf-8"/>
|
||||
<property name="log.pattern"
|
||||
value="%red(%contextName) - %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) - %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %msg%n"/>
|
||||
|
||||
<!-- Spring 日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
<!-- DnsServerAddressStreamProviders调整为ERROR -->
|
||||
<logger name="io.netty.resolver.dns.DnsServerAddressStreamProviders" level="ERROR"/>
|
||||
<!-- 设置其他类的日志级别为 ERROR -->
|
||||
<logger name="org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]" level="ERROR"/>
|
||||
<logger name="org.springframework.web.servlet.DispatcherServlet" level="ERROR"/>
|
||||
|
||||
<!--输出到控制台-->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${log.pattern}</pattern>
|
||||
<charset>${log.charset}</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${log.home}/${log.name}.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.home}/${log.name}.log.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxHistory>90</maxHistory>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<!--普通日志输出到控制台-->
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<!--普通日志输出到文件-->
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
<contextName>CuteJava</contextName>
|
||||
<property name="log.name" value="cutejava"/>
|
||||
<property name="log.home" value="/Users/tianjun/Downloads/logs"/>
|
||||
<property name="log.charset" value="utf-8"/>
|
||||
<property name="log.pattern"
|
||||
value="%red(%contextName) - %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) - %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %msg%n"/>
|
||||
<!-- Spring 日志级别控制 -->
|
||||
<logger name="org.springframework" level="WARN"/>
|
||||
<!-- DnsServerAddressStreamProviders调整为ERROR -->
|
||||
<logger name="io.netty.resolver.dns.DnsServerAddressStreamProviders" level="ERROR"/>
|
||||
<!-- 设置其他类的日志级别为 ERROR -->
|
||||
<logger name="org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]" level="ERROR"/>
|
||||
<logger name="org.springframework.web.servlet.DispatcherServlet" level="ERROR"/>
|
||||
<!--输出到控制台-->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${log.pattern}</pattern>
|
||||
<charset>${log.charset}</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${log.home}/${log.name}.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.home}/${log.name}.log.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxHistory>90</maxHistory>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<!--普通日志输出到控制台-->
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<!--普通日志输出到文件-->
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
</configuration>
|
||||
+8
-3
@@ -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<Void> createQuartzJob(@Validated @RequestBody SystemQuartzJobVo args) {
|
||||
public ResponseEntity<Void> 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<Void> 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<Void> 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);
|
||||
}
|
||||
|
||||
|
||||
-5
@@ -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<SystemQuartzJobTb> {
|
||||
|
||||
default SystemQuartzJobVo selectVoById(String id) {
|
||||
return KitBeanUtil.copyToClass(selectById(id), SystemQuartzJobVo.class);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -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<SystemQuartzJobVo> quartzJobs = systemQuartzJobService.listEnableQuartzJob();
|
||||
quartzJobs.forEach(quartzManage::addJob);
|
||||
List<SystemQuartzJobTb> quartzJobTbs = systemQuartzJobService.listEnableQuartzJob();
|
||||
List<SystemQuartzJobVo> quartzJobVos = KitBeanUtil.copyToList(quartzJobTbs, SystemQuartzJobVo.class);
|
||||
quartzJobVos.forEach(quartzManage::addJob);
|
||||
log.info("Timing task injection complete");
|
||||
}
|
||||
}
|
||||
|
||||
+21
-13
@@ -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);
|
||||
|
||||
+6
-4
@@ -156,6 +156,9 @@ public class SystemLocalStorageService {
|
||||
wrapper.orderByDesc(SystemLocalStorageTb::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件上传记录 -> TestPassed
|
||||
*/
|
||||
public List<SystemLocalStorageTb> queryLocalStorageByArgs(SystemQueryStorageArgs args) {
|
||||
LambdaQueryWrapper<SystemLocalStorageTb> 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<SystemLocalStorageTb> systemLocalStorageTbs = this.queryLocalStorageByArgs(args);
|
||||
List<SystemLocalStorageExportRowVo> rowVos =
|
||||
KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
|
||||
List<SystemLocalStorageExportRowVo> rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
|
||||
KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -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 /
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class SystemOperationLogService {
|
||||
private SystemOperationLogMapper systemOperationLogMapper;
|
||||
|
||||
/**
|
||||
* 查询用户操作日志
|
||||
* 查询用户操作日志 -> TestPassed
|
||||
*/
|
||||
public IPage<SystemOperationLogTb> searchUserLog(KitPageArgs<SystemQueryOperationLogArgs> pageArgs) {
|
||||
LambdaQueryWrapper<SystemOperationLogTb> wrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
+40
-38
@@ -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<SystemQuartzJobTb> searchQuartzJobByArgs(SystemQueryQuartzJobArgs args,
|
||||
Page<SystemQuartzJobTb> page) {
|
||||
public KitPageResult<SystemQuartzJobTb> searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, Page<SystemQuartzJobTb> page) {
|
||||
LambdaQueryWrapper<SystemQuartzJobTb> wrapper = new LambdaQueryWrapper<>();
|
||||
this.injectQuartzJobQueryParams(args, wrapper);
|
||||
return KitPageUtil.toPage(systemQuartzJobMapper.selectPage(page, wrapper));
|
||||
}
|
||||
|
||||
private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args,
|
||||
LambdaQueryWrapper<SystemQuartzJobTb> 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<SystemQuartzJobTb> 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<SystemQuartzLogTb> wrapper) {
|
||||
private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzLogTb> 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<SystemQuartzJobVo> listEnableQuartzJob() {
|
||||
public List<SystemQuartzJobTb> listEnableQuartzJob() {
|
||||
LambdaQueryWrapper<SystemQuartzJobTb> 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<SystemQuartzJobTb> systemQuartzJobTbs = this.queryQuartzJobByArgs(args);
|
||||
List<SystemQuartzJobExportRowVo> 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<SystemQuartzLogTb> systemQuartzLogTbs = this.queryQuartzLogByArgs(args);
|
||||
List<SystemQuartzLogExportRowVo> 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user