主键字段Long-->String

This commit is contained in:
ludj
2022-12-16 14:53:03 +08:00
parent 78cb2023a8
commit 74105971e1
51 changed files with 115 additions and 966 deletions

View File

@@ -19,7 +19,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
@@ -698,9 +697,9 @@ public class RedisUtils {
*/
public void delByKeys(String prefix, Set<Long> ids) {
Set<Object> keys = new HashSet<>();
for (Long id : ids) {
/* for (String id : ids) {
keys.addAll(redisTemplate.keys(new StringBuffer(prefix).append(id).toString()));
}
}*/
long count = redisTemplate.delete(keys);
// 此处提示可自行删除
log.debug("--------------------------------------------");

View File

@@ -31,7 +31,7 @@ import java.util.Date;
@NoArgsConstructor
public class Log implements Serializable {
private Long id;
private String id;
/** 操作用户 */
private String username;

View File

@@ -1,45 +0,0 @@
package org.nl.modules.quartz.config;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import netscape.javascript.JSObject;
import org.nl.modules.quartz.utils.QuartzManage;
import org.nl.modules.wql.core.bean.WQLObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.function.Consumer;
/**
* @author: lyd
* @description:
* @Date: 2022/12/5
*/
@Component
@RequiredArgsConstructor
@Order(100)
public class JobRunner implements ApplicationRunner {
private static final Logger log = LoggerFactory.getLogger(JobRunner.class);
// private final QuartzJobRepository quartzJobRepository;
private final QuartzManage quartzManage;
/**
* 项目启动时重新激活启用的定时任务
*
* @param applicationArguments /
*/
@Override
public void run(ApplicationArguments applicationArguments) {
log.info("--------------------注入定时任务---------------------");
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
JSONArray quartzJobs = jobTab.query("is_pause = '0'").getResultJSONArray(0);
quartzJobs.forEach( job -> quartzManage.addJob((JSONObject) job));
log.info("--------------------定时任务注入完成---------------------");
}
}

View File

@@ -1,57 +0,0 @@
package org.nl.modules.quartz.config;
import org.quartz.Scheduler;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
/**
* @author: lyd
* @description: 定时任务配置
* @Date: 2022/12/5
*/
@Configuration
public class QuartzConfig {
/**
* 解决Job中注入Spring Bean为null的问题
*/
@Component("quartzJobFactory")
public static class QuartzJobFactory extends AdaptableJobFactory {
private final AutowireCapableBeanFactory capableBeanFactory;
public QuartzJobFactory(AutowireCapableBeanFactory capableBeanFactory) {
this.capableBeanFactory = capableBeanFactory;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
}
/**
* 注入scheduler到spring
* @param quartzJobFactory /
* @return Scheduler
* @throws Exception /
*/
@Bean(name = "scheduler")
public Scheduler scheduler(QuartzJobFactory quartzJobFactory) throws Exception {
SchedulerFactoryBean factoryBean=new SchedulerFactoryBean();
factoryBean.setJobFactory(quartzJobFactory);
factoryBean.afterPropertiesSet();
Scheduler scheduler=factoryBean.getScheduler();
scheduler.start();
return scheduler;
}
}

View File

@@ -1,92 +0,0 @@
package org.nl.modules.quartz.rest;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.logging.annotation.Log;
import org.nl.modules.quartz.service.QuartzJobService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.Set;
/**
* @author: lyd
* @description:
* @Date: 2022/12/5
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/jobs")
@Api(tags = "系统:定时任务管理")
public class QuartzJobController {
private final QuartzJobService quartzJobService;
@GetMapping
@Log("查询点位")
@ApiOperation("查询点位")
//@SaCheckPermission("timing:list")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(quartzJobService.queryAll(whereJson, page), HttpStatus.OK);
}
@ApiOperation("查询任务执行日志")
@GetMapping(value = "/logs")
@SaCheckPermission("timing:list")
public ResponseEntity<Object> queryJobLog(@RequestParam Map criteria, Pageable pageable) {
return new ResponseEntity<>(quartzJobService.queryAllLog(criteria, pageable), HttpStatus.OK);
}
@Log("新增定时任务")
@ApiOperation("新增定时任务")
@PostMapping
// @SaCheckPermission("timing:add")
public ResponseEntity<Object> create(@RequestBody JSONObject resources) {
quartzJobService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改定时任务")
@ApiOperation("修改定时任务")
@PutMapping
// @SaCheckPermission("timing:edit")
public ResponseEntity<Object> update(@RequestBody JSONObject resources) {
quartzJobService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("更改定时任务状态")
@ApiOperation("更改定时任务状态")
@PutMapping(value = "/{id}")
// @SaCheckPermission("timing:edit")
public ResponseEntity<Object> update(@PathVariable Long id) {
quartzJobService.updateIsPause(quartzJobService.findById(id));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("执行定时任务")
@ApiOperation("执行定时任务")
@PutMapping(value = "/exec/{id}")
// @SaCheckPermission("timing:edit")
public ResponseEntity<Object> execution(@PathVariable Long id) {
quartzJobService.execution(quartzJobService.findById(id));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除定时任务")
@ApiOperation("删除定时任务")
@DeleteMapping
// @SaCheckPermission("timing:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
quartzJobService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@@ -1,79 +0,0 @@
package org.nl.modules.quartz.service;
import com.alibaba.fastjson.JSONObject;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.Set;
/**
* @author: lyd
* @description:
* @Date: 2022/12/5
*/
public interface QuartzJobService {
/**
* 分页查询
* @param whereJson
* @param page
* @return
*/
Object queryAll(Map whereJson, Pageable page);
/**
* 添加
* @param resources
*/
void create(JSONObject resources);
/**
* 日志查询
* @param criteria
* @param pageable
* @return
*/
Object queryAllLog(Map criteria, Pageable pageable);
/**
* 修改任务
* @param resources
*/
void update(JSONObject resources);
/**
* 根据ID查询
*
* @param id ID
* @return /
*/
JSONObject findById(Long id);
/**
* 立即执行定时任务
*
* @param quartzJob /
*/
void execution(JSONObject quartzJob);
/**
* 更改定时任务状态
*
* @param job /
*/
void updateIsPause(JSONObject job);
/**
* 执行子任务
*
* @param tasks /
* @throws InterruptedException /
*/
void executionSubJob(String[] tasks) throws InterruptedException;
/**
* 批量删除
* @param ids
*/
void delete(Set<Long> ids);
}

View File

@@ -1,221 +0,0 @@
package org.nl.modules.quartz.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.quartz.service.QuartzJobService;
import org.nl.modules.quartz.utils.QuartzManage;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.quartz.CronExpression;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author: lyd
* @description:
* @Date: 2022/12/5
*/
@RequiredArgsConstructor
@Service(value = "quartzJobService")
public class QuartzJobServiceImpl implements QuartzJobService {
private final RedisUtils redisUtils;
private final QuartzManage quartzManage;
@Override
public Object queryAll(Map whereJson, Pageable page) {
WQLObject quartzTab = WQLObject.getWQLObject("sys_quartz_job");
String param = "1 = 1";
if (ObjectUtil.isNotEmpty(whereJson.get("job_name"))) {
String job_name = whereJson.get("job_name").toString();
param = param + " AND job_name like '%" + job_name + "%'";
}
ResultBean rb = quartzTab.pagequery(WqlUtil.getHttpContext(page), param, "update_time desc");
final JSONObject json = rb.pageResult();
return json;
}
/**
* 添加
*
* @param resources
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void create(JSONObject resources) {
if (!CronExpression.isValidExpression(resources.getString("cron_expression"))) {
throw new BadRequestException("cron表达式格式错误");
}
WQLObject quartzTab = WQLObject.getWQLObject("sys_quartz_job");
String userId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
resources.put("job_id", IdUtil.getSnowflake(1,1).nextId());
resources.put("create_id", userId);
resources.put("create_name", nickName);
resources.put("create_time", now);
resources.put("update_id", userId);
resources.put("update_optname", nickName);
resources.put("update_time", now);
quartzTab.insert(resources);
// 添加任务
quartzManage.addJob(resources);
}
/**
* 日志查询
*
* @param criteria
* @param pageable
* @return
*/
@Override
public Object queryAllLog(Map criteria, Pageable pageable) {
WQLObject logTab = WQLObject.getWQLObject("sys_quartz_log");
String param = "1=1";
if (ObjectUtil.isNotEmpty(criteria.get("job_name"))) {
param = param + " AND job_name = '" + criteria.get("job_name").toString() + "'";
}
if (ObjectUtil.isNotEmpty(criteria.get("is_success"))) {
param = param + " AND is_success = '" + criteria.get("is_success").toString() + "'";
}
if (ObjectUtil.isNotEmpty(criteria.get("createTime"))) {
param = param + " AND create_time >= " + criteria.get("begin_time") + " AND" +
" create_time <= " + criteria.get("end_time");
}
ResultBean rb = logTab.pagequery(WqlUtil.getHttpContext(pageable), param, "create_time desc");
final JSONObject json = rb.pageResult();
return json;
}
/**
* 修改任务
*
* @param resources
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void update(JSONObject resources) {
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
JSONObject entity = this.findById(resources.getLong("job_id"));
if (entity == null) {
throw new BadRequestException("被删除或无权限,操作失败!");
}
if (!CronExpression.isValidExpression(resources.getString("cron_expression"))) {
throw new BadRequestException("cron表达式格式错误");
}
if (StrUtil.isNotEmpty(resources.getString("sub_task"))) {
List<String> tasks = Arrays.asList(resources.getString("sub_task").split("[,]"));
if (tasks.contains(resources.getString("job_id"))) {
throw new BadRequestException("子任务中不能添加当前任务ID");
}
}
resources.put("update_id", SecurityUtils.getCurrentUserId());
resources.put("update_optname", SecurityUtils.getCurrentNickName());
resources.put("update_time", DateUtil.now());
jobTab.update(resources);
quartzManage.updateJobCron(resources);
}
/**
* 根据ID查询
*
* @param id ID
* @return /
*/
@Override
public JSONObject findById(Long id) {
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
JSONObject entity = jobTab.query("job_id = '" + id + "'").uniqueResult(0);
return entity;
}
/**
* 立即执行定时任务
*
* @param quartzJob /
*/
@Override
public void execution(JSONObject quartzJob) {
quartzManage.runJobNow(quartzJob);
}
/**
* 更改定时任务状态
*
* @param quartzJob /
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateIsPause(JSONObject quartzJob) {
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
if (quartzJob.getString("is_pause").equals("1")) {
quartzManage.resumeJob(quartzJob);
quartzJob.put("is_pause", "0");
} else {
quartzManage.pauseJob(quartzJob);
quartzJob.put("is_pause", "1");
}
jobTab.update(quartzJob);
}
/**
* 执行子任务
*
* @param tasks /
* @throws InterruptedException /
*/
@Override
public void executionSubJob(String[] tasks) throws InterruptedException {
for (String id : tasks) {
JSONObject quartzJob = findById(Long.parseLong(id));
// 执行任务
String uuid = IdUtil.simpleUUID();
quartzJob.put("job_id", uuid);
// 执行任务
execution(quartzJob);
// 获取执行状态,如果执行失败则停止后面的子任务执行
Boolean result = (Boolean) redisUtils.get(uuid);
while (result == null) {
// 休眠5秒再次获取子任务执行情况
Thread.sleep(5000);
result = (Boolean) redisUtils.get(uuid);
}
if (!result) {
redisUtils.del(uuid);
break;
}
}
}
/**
* 批量删除
*
* @param ids
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> ids) {
WQLObject jobTab = WQLObject.getWQLObject("sys_quartz_job");
WQLObject logTab = WQLObject.getWQLObject("sys_quartz_log");
for (Long id : ids) {
JSONObject quartzJob = findById(id);
quartzManage.deleteJob(quartzJob);
jobTab.delete(quartzJob);
}
}
}

View File

@@ -1,26 +0,0 @@
package org.nl.modules.quartz.task;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author: lyd
* @description: 测试任务
* @Date: 2022/12/5
*/
@Slf4j
@Component
public class TestTask {
public void run(){
log.info("run 执行成功");
}
public void run1(String str){
log.info("run1 执行成功,参数为: {}" + str);
}
public void run2(){
log.info("run2 执行成功");
}
}

View File

@@ -1,102 +0,0 @@
package org.nl.modules.quartz.utils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.config.thread.ThreadPoolExecutorUtil;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.ThrowableUtil;
import org.nl.modules.quartz.service.QuartzJobService;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.SpringContextHolder;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author: lyd
* @description:
* @Date: 2022/12/5
*/
@Async
@SuppressWarnings({"unchecked", "all"})
@Slf4j
public class ExecutionJob extends QuartzJobBean {
/**
* 该处仅供参考
*/
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
@Override
public void executeInternal(JobExecutionContext context) {
JSONObject quartzJob = (JSONObject) context.getMergedJobDataMap().get(QuartzManage.JOB_KEY);
// 获取spring bean
QuartzJobService quartzJobService = SpringContextHolder.getBean(QuartzJobService.class);
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
WQLObject logTab = WQLObject.getWQLObject("sys_quartz_log");
String uuid = quartzJob.getString("job_id");
JSONObject logDto = new JSONObject();
logDto.put("log_id", IdUtil.getSnowflake(1,1).nextId());
logDto.put("create_time", DateUtil.now()); // ????
logDto.put("job_name", quartzJob.getString("job_name"));
logDto.put("bean_name", quartzJob.getString("bean_name"));
logDto.put("method_name", quartzJob.getString("method_name"));
logDto.put("params", quartzJob.getString("params"));
long startTime = System.currentTimeMillis();
logDto.put("cron_expression", quartzJob.getString("cron_expression"));
try {
// 执行任务
System.out.println("--------------------------------------------------------------");
System.out.println("任务开始执行,任务名称:" + quartzJob.getString("bean_name"));
QuartzRunnable task = new QuartzRunnable(quartzJob.getString("bean_name"), quartzJob.getString("method_name"),
quartzJob.getString("params"));
Future<?> future = EXECUTOR.submit(task);
future.get();
long times = System.currentTimeMillis() - startTime;
logDto.put("time", times);
if (StrUtil.isNotEmpty(uuid)) {
redisUtils.set(uuid, true);
}
// 任务状态
logDto.put("is_success", "1");
System.out.println("任务执行完毕,任务名称:" + quartzJob.getString("job_name") + ", 执行时间:" + times + "毫秒");
System.out.println("--------------------------------------------------------------");
// 判断是否存在子任务
if (StrUtil.isNotEmpty(quartzJob.getString("sub_task"))) {
String[] tasks = quartzJob.getString("sub_task").split("[,]");
// 执行子任务
quartzJobService.executionSubJob(tasks);
}
} catch (Exception e) {
if (StrUtil.isNotEmpty(uuid)) {
redisUtils.set(uuid, false);
}
System.out.println("任务执行失败,任务名称:" + quartzJob.getString("job_name"));
System.out.println("--------------------------------------------------------------");
long times = System.currentTimeMillis() - startTime;
logDto.put("time", times);
// 任务状态 0成功 1失败
logDto.put("is_success", "0");
logDto.put("exception_detail", ThrowableUtil.getStackTrace(e));
// 任务如果失败了则暂停
if (quartzJob.getString("pause_after_failure") != null && quartzJob.getString("pause_after_failure").equals("1")) {
quartzJob.put("is_pause", "0");
//更新状态
quartzJobService.updateIsPause(quartzJob);
}
//异常时候打印日志
log.info(logDto.toString());
logTab.insert(logDto);
} finally {
}
}
}

View File

@@ -1,156 +0,0 @@
package org.nl.modules.quartz.utils;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException;
import org.quartz.*;
import org.quartz.impl.triggers.CronTriggerImpl;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import static org.quartz.TriggerBuilder.newTrigger;
/**
* @author: lyd
* @description: 任务管理
* @Date: 2022/12/5
*/
@Slf4j
@Component
public class QuartzManage {
private static final String JOB_NAME = "TASK_";
public static final String JOB_KEY = "JOB_KEY";
@Resource(name = "scheduler")
private Scheduler scheduler;
public void addJob(JSONObject quartzJob){
try {
// 构建job信息
JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class).
withIdentity(JOB_NAME + quartzJob.getString("job_id")).build();
//通过触发器名和cron 表达式创建 Trigger
Trigger cronTrigger = newTrigger()
.withIdentity(JOB_NAME + quartzJob.getString("job_id"))
.startNow()
.withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getString("cron_expression")))
.build();
cronTrigger.getJobDataMap().put(QuartzManage.JOB_KEY, quartzJob);
//重置启动时间
((CronTriggerImpl)cronTrigger).setStartTime(new Date());
//执行定时任务
scheduler.scheduleJob(jobDetail,cronTrigger);
// 暂停任务
if (quartzJob.getString("is_pause").equals("1")) {
pauseJob(quartzJob);
}
} catch (Exception e){
log.error("创建定时任务失败", e);
throw new BadRequestException("创建定时任务失败");
}
}
/**
* 执行任务
* @param quartzJob
*/
public void runJobNow(JSONObject quartzJob) {
try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getString("job_id"));
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if(trigger == null) {
addJob(quartzJob);
}
JobDataMap dataMap = new JobDataMap();
dataMap.put(QuartzManage.JOB_KEY, quartzJob);
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
scheduler.triggerJob(jobKey,dataMap);
} catch (Exception e){
log.error("定时任务执行失败", e);
throw new BadRequestException("定时任务执行失败");
}
}
/**
* 暂停一个job
* @param quartzJob /
*/
public void pauseJob(JSONObject quartzJob){
try {
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
scheduler.pauseJob(jobKey);
} catch (Exception e){
log.error("定时任务暂停失败", e);
throw new BadRequestException("定时任务暂停失败");
}
}
/**
* 更新job cron表达式
* @param quartzJob /
*/
public void updateJobCron(JSONObject quartzJob) {
try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getString("job_id"));
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if(trigger == null){
addJob(quartzJob);
trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
}
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getString("cron_expression"));
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
//重置启动时间
((CronTriggerImpl)trigger).setStartTime(new Date());
trigger.getJobDataMap().put(QuartzManage.JOB_KEY, quartzJob);
scheduler.rescheduleJob(triggerKey, trigger);
// 暂停任务
if (quartzJob.getString("is_pause").equals("1")) {
pauseJob(quartzJob);
}
} catch (Exception e){
log.error("更新定时任务失败", e);
throw new BadRequestException("更新定时任务失败");
}
}
/**
* 恢复一个job
* @param quartzJob /
*/
public void resumeJob(JSONObject quartzJob) {
try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getString("job_id"));
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if(trigger == null) {
addJob(quartzJob);
}
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
scheduler.resumeJob(jobKey);
} catch (Exception e){
log.error("恢复定时任务失败", e);
throw new BadRequestException("恢复定时任务失败");
}
}
public void deleteJob(JSONObject quartzJob) {
try {
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getString("job_id"));
scheduler.pauseJob(jobKey);
scheduler.deleteJob(jobKey);
} catch (Exception e){
log.error("删除定时任务失败", e);
throw new BadRequestException("删除定时任务失败");
}
}
}

View File

@@ -1,45 +0,0 @@
package org.nl.modules.quartz.utils;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.wql.util.SpringContextHolder;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;
/**
* @author: lyd
* @description: 执行定时任务
* @Date: 2022/12/5
*/
@Slf4j
public class QuartzRunnable implements Callable {
private final Object target;
private final Method method;
private final String params;
QuartzRunnable(String beanName, String methodName, String params)
throws NoSuchMethodException, SecurityException {
this.target = SpringContextHolder.getBean(beanName);
this.params = params;
if (StrUtil.isNotEmpty(params)) {
this.method = target.getClass().getDeclaredMethod(methodName, String.class);
} else {
this.method = target.getClass().getDeclaredMethod(methodName);
}
}
@Override
public Object call() throws Exception {
ReflectionUtils.makeAccessible(method);
if (StrUtil.isNotEmpty(params)) {
method.invoke(target, params);
} else {
method.invoke(target);
}
return null;
}
}

View File

@@ -7,7 +7,7 @@
@Data
public class CurrentUser implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private String id;
private String username;
@@ -22,7 +22,7 @@ public class CurrentUser implements Serializable {
@Setter
public class UserDto extends BaseDTO implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private String id;
private Set<RoleSmallDto> roles;

View File

@@ -15,18 +15,13 @@
*/
package org.nl.modules.system.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.nl.modules.common.base.BaseDTO;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;
/**
* @author Zheng Jie
@@ -36,7 +31,7 @@ import java.util.Set;
public class Dept extends BaseDTO implements Serializable {
private Long dept_id;
private String dept_id;
private String code;
@@ -57,7 +52,7 @@ public class Dept extends BaseDTO implements Serializable {
private String is_used;
@ApiModelProperty(value = "上级部门")
private Long pid;
private String pid;
@ApiModelProperty(value = "子节点数目", hidden = true)
private Integer sub_count = 0;

View File

@@ -30,7 +30,7 @@ import java.io.Serializable;
public class Dict implements Serializable {
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
private String id;
// 字典标识
@JsonSerialize(using= ToStringSerializer.class)
private Long dict_id;

View File

@@ -31,7 +31,7 @@ public class DictDetail implements Serializable {
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
private String id;
private Dict dict;

View File

@@ -34,7 +34,7 @@ public class Menu implements Serializable {
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
private String id;
@JsonIgnore
@ApiModelProperty(value = "菜单角色")

View File

@@ -36,7 +36,7 @@ public class Role implements Serializable {
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
private String id;
private Set<SysUser> users;

View File

@@ -87,7 +87,7 @@ public class DictController2 {
@ApiOperation("删除字典")
@DeleteMapping
// @SaCheckPermission("dict:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
public ResponseEntity<Object> delete(@RequestBody Set<String> ids){
dictService2.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@@ -84,7 +84,7 @@ public class DictDetailController {
@ApiOperation("删除字典详情")
@DeleteMapping(value = "/{id}")
// @SaCheckPermission("dict:del")
public ResponseEntity<Object> delete(@PathVariable Long id){
public ResponseEntity<Object> delete(@PathVariable String id){
dictDetailService.delete(id);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@@ -3,23 +3,17 @@ package org.nl.modules.system.rest;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.nl.modules.logging.annotation.Log;
import org.nl.modules.system.domain.vo.RoleVo;
import org.nl.modules.system.service.RoleService;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.system.service.role.ISysRoleService;
import org.nl.system.service.role.dao.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -86,7 +80,7 @@ public class RoleController {
@ApiOperation("删除角色")
@DeleteMapping
@SaCheckPermission("roles:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
roleService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@@ -15,9 +15,7 @@
*/
package org.nl.modules.system.service;
import org.apache.poi.ss.formula.functions.T;
import org.nl.modules.system.domain.Dept;
import org.nl.modules.system.service.dto.DeptDto;
import org.nl.modules.system.service.dto.DeptQueryCriteria;
import org.nl.modules.system.service.dto.DeptTree;
@@ -46,7 +44,7 @@ public interface DeptService {
* @param deptList
* @return
*/
List<Long> getDeptChildren(List<Dept> deptList);
List<String> getDeptChildren(List<Dept> deptList);
/**
* 根据ID查询
@@ -54,9 +52,9 @@ public interface DeptService {
* @param id /
* @return /
*/
Dept findById(Long id);
Dept findById(String id);
List<Dept> findByPid(Long pid);
List<Dept> findByPid(String pid);
/**
* 创建
@@ -76,21 +74,21 @@ public interface DeptService {
* 查询pid所有子集
*
*/
Set<Long> findPidChild(Long pid);
Set<String> findPidChild(String pid);
/**
* 删除
*
* @param deptDtos /
*/
void delete(Set<Long> deptDtos);
void delete(Set<String> deptDtos);
/**
* 根据PID查询
*
* @return /
*/
<T> T findById(Long id, Class<T> tagert);
<T> T findById(String id, Class<T> tagert);
@@ -125,7 +123,7 @@ public interface DeptService {
*
* @param deptDtos /
*/
void verification(Set<Long> deptDtos);
void verification(Set<String> deptDtos);
/**
* 获取当前节点的所有子类节点集合数据
@@ -133,7 +131,7 @@ public interface DeptService {
* @param dept_id
* @return
*/
Set<Long> getChildIdSet(Long dept_id);
Set<String> getChildIdSet(String dept_id);
/**
* 获取查询条件的所有子节点集合
@@ -141,7 +139,7 @@ public interface DeptService {
* @param dept_idStr
* @return
*/
Set<Long> getAllChildIdSet(String dept_idStr);
Set<String> getAllChildIdSet(String dept_idStr);
/**
* 获取当前节点的所有子类节点集合串,用于拼接SQLin
@@ -149,7 +147,7 @@ public interface DeptService {
* @param dept_id
* @return
*/
String getChildIdStr(Long dept_id);
String getChildIdStr(String dept_id);
/**
* 获取所有节点的子节点的ID串

View File

@@ -44,7 +44,7 @@ public interface DictDetailService {
* 删除
* @param id /
*/
void delete(Long id);
void delete(String id);
/**
* 分页查询
@@ -66,6 +66,6 @@ public interface DictDetailService {
* @param dict_id ID
* @return Point
*/
DictDto findById(Long dict_id);
DictDto findById(String dict_id);
}

View File

@@ -51,7 +51,7 @@ public interface DictService2 {
* @param dict_id ID
* @return Point
*/
DictDto findById(Long dict_id);
DictDto findById(String dict_id);
/**
@@ -71,7 +71,7 @@ public interface DictService2 {
* 删除
* @param ids /
*/
void delete(Set<Long> ids);
void delete(Set<String> ids);
/**
* 导出数据

View File

@@ -16,16 +16,8 @@
package org.nl.modules.system.service;
import com.alibaba.fastjson.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.nl.modules.system.domain.Role;
import org.nl.modules.system.service.dto.RoleDto;
import org.nl.modules.system.service.dto.RoleQueryCriteria;
import org.nl.modules.system.service.dto.RoleSmallDto;
import org.nl.modules.system.service.dto.UserDto;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -60,7 +52,7 @@ public interface RoleService {
* 删除
* @param ids /
*/
void delete(Set<Long> ids);
void delete(Set<String> ids);
/**

View File

@@ -32,7 +32,7 @@ import java.util.Objects;
@Setter
public class DeptDto extends BaseDTO implements Serializable {
private Long id;
private String id;
private String name;

View File

@@ -26,7 +26,7 @@ import java.io.Serializable;
@Data
public class DeptSmallDto implements Serializable {
private Long id;
private String id;
private String code;

View File

@@ -18,11 +18,9 @@ package org.nl.modules.system.service.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;
import org.nl.modules.common.base.BaseDTO;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
/**
* @author Zheng Jie
@@ -32,9 +30,9 @@ import java.util.Objects;
@Setter
public class DeptTree implements Serializable {
private Long deptId;
private String deptId;
private Long pid;
private String pid;
private String name;
@JsonInclude(JsonInclude.Include.NON_EMPTY)

View File

@@ -29,7 +29,7 @@ import java.io.Serializable;
@Setter
public class DictDetailDto extends BaseDTO implements Serializable {
private Long id;
private String id;
private DictSmallDto dict;

View File

@@ -1,10 +1,11 @@
package org.nl.modules.system.service.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.io.Serializable;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @description /
@@ -17,7 +18,7 @@ public class DictDto implements Serializable {
/** 字典标识 */
/** 防止精度丢失 */
@JsonSerialize(using= ToStringSerializer.class)
private Long dict_id;
private String dict_id;
private String dictCode; // 区分使用

View File

@@ -28,5 +28,5 @@ import java.io.Serializable;
@Setter
public class DictSmallDto implements Serializable {
private Long id;
private String id;
}

View File

@@ -31,7 +31,7 @@ import java.util.Objects;
@Setter
public class MenuDto extends BaseDTO implements Serializable {
private Long menuId;
private String menuId;
private List<MenuDto> children;
@@ -48,7 +48,7 @@ public class MenuDto extends BaseDTO implements Serializable {
private String component;
private Long pid;
private String pid;
private Integer subCount;

View File

@@ -31,7 +31,7 @@ import java.util.Set;
@Setter
public class RoleDto extends BaseDTO implements Serializable {
private Long id;
private String id;
private Set<MenuDto> menus;

View File

@@ -26,7 +26,7 @@ import java.io.Serializable;
@Data
public class RoleSmallDto implements Serializable {
private Long id;
private String id;
private String name;

View File

@@ -34,7 +34,7 @@ import java.util.Set;
@Setter
public class UserDto extends BaseDTO implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private String id;
// private Set<RoleSmallDto> roles;

View File

@@ -23,7 +23,6 @@ import cn.hutool.db.Entity;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.nl.modules.common.exception.BadRequestException;
@@ -41,7 +40,6 @@ import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.SpringContextHolder;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -78,7 +76,7 @@ public class DeptServiceImpl implements DeptService {
}
@Override
public <T> T findById(Long id,Class<T> tagert) {
public <T> T findById(String id,Class<T> tagert) {
if (id==null){
return null;
}
@@ -87,19 +85,19 @@ public class DeptServiceImpl implements DeptService {
}
@Override
public Dept findById(Long id) {
public Dept findById(String id) {
JSONObject result = WQLObject.getWQLObject("sys_dept").query("dept_id ='" + id + "'").uniqueResult(0);
return result.toJavaObject(Dept.class);
}
@Override
public List<Dept> findByPid(Long pid) {
public List<Dept> findByPid(String pid) {
JSONArray result = WQLObject.getWQLObject("sys_dept").query("pid ='" + pid + "'").getResultJSONArray(0);
return result.toJavaList(Dept.class);
}
@Override
@SneakyThrows
public Set<Long> findPidChild(Long pid) {
public Set<String> findPidChild(String pid) {
if (pid!=null) {
String sql = "SELECT\n" +
" max(t3.childId) as deptIds \n" +
@@ -117,7 +115,7 @@ public class DeptServiceImpl implements DeptService {
Object deptIds = list.get(0).get("deptIds");
if (deptIds != null && (deptIds instanceof String)) {
String[] split = ((String) deptIds).split(",");
return Arrays.stream(split).map(a -> Long.valueOf(a)).collect(Collectors.toSet());
return Arrays.stream(split).map(a -> String.valueOf(a)).collect(Collectors.toSet());
}
}
return new HashSet();
@@ -144,8 +142,8 @@ public class DeptServiceImpl implements DeptService {
@Transactional(rollbackFor = Exception.class)
public void update(Dept resources) {
// 旧的部门
Long oldPid = findById(resources.getDept_id()).getPid();
Long newPid = resources.getPid();
String oldPid = findById(resources.getDept_id()).getPid();
String newPid = resources.getPid();
if (resources.getPid() != null && resources.getDept_id().equals(resources.getPid())) {
throw new BadRequestException("上级不能为自己");
}
@@ -163,10 +161,10 @@ public class DeptServiceImpl implements DeptService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> deptDtos) {
public void delete(Set<String> deptDtos) {
if (!CollectionUtils.isEmpty(deptDtos)){
Set<Long> depts = new HashSet<>();
for (Long id : deptDtos) {
Set<String> depts = new HashSet<>();
for (String id : deptDtos) {
depts.addAll(this.findPidChild(id));
}
// 验证是否被角色或用户关联
@@ -174,10 +172,10 @@ public class DeptServiceImpl implements DeptService {
String collectSql = deptDtos.stream().map(a -> String.valueOf(a)).collect(Collectors.joining("','"));
WQLObject.getWQLObject("sys_dept").delete("dept_id in ('" + collectSql + "')");
for (Long deptDto : deptDtos) {
for (String deptDto : deptDtos) {
// 清理缓存
delCaches(deptDto);
updateSubCnt(deptDto);
// delCaches(deptDto);
// updateSubCnt(deptDto);
}
}
}
@@ -237,7 +235,7 @@ public class DeptServiceImpl implements DeptService {
}
@Override
public void verification(Set<Long> deptDtos) {
public void verification(Set<String> deptDtos) {
if (!CollectionUtils.isEmpty(deptDtos)){
String collectSql = deptDtos.stream().map(a -> String.valueOf(a)).collect(Collectors.joining("','"));
ResultBean result = WQLObject.getWQLObject("sys_user_dept").query("dept_id in ('" + collectSql + "')");
@@ -248,7 +246,7 @@ public class DeptServiceImpl implements DeptService {
}
private void updateSubCnt(Long deptId) {
private void updateSubCnt(String deptId) {
if (deptId != null) {
List<Dept> byPid = findByPid(deptId);
WQLObject.getWQLObject("sys_dept").update(MapOf.of("sub_count",byPid.size()),"dept_id = '"+deptId+"'");
@@ -277,7 +275,7 @@ public class DeptServiceImpl implements DeptService {
*
* @param id /
*/
public void delCaches(Long id) {
public void delCaches(String id) {
JSONArray array = WQLObject.getWQLObject("sys_user_dept").query("dept_id ='" + id + "'").getResultJSONArray(0);
Set<Long> users = array.stream().map(a -> ((JSONObject) a).getLong("user_id")).collect(Collectors.toSet());
// 删除数据权限
@@ -286,8 +284,8 @@ public class DeptServiceImpl implements DeptService {
}
@Override
public List<Long> getDeptChildren(List<Dept> deptList) {
List<Long> list = new ArrayList<>();
public List<String> getDeptChildren(List<Dept> deptList) {
List<String> list = new ArrayList<>();
deptList.forEach(dept -> {
if (dept != null && "1".equals(dept.getIs_used())) {
List<Dept> depts = findByPid(dept.getDept_id());
@@ -302,7 +300,7 @@ public class DeptServiceImpl implements DeptService {
}
@Override
public Set<Long> getChildIdSet(Long pid) {
public Set<String> getChildIdSet(String pid) {
String sql = "select dept_id from (\n" +
" select t1.dept_id,\n" +
" if(find_in_set(pid, @pids) > 0, @pids := concat(@pids, ',', dept_id), 0) as ischild\n" +
@@ -311,14 +309,14 @@ public class DeptServiceImpl implements DeptService {
" ) t1,\n" +
" (select @pids :=" + pid + ") t2\n" +
" ) t3 where ischild != 0";
Set<Long> set = new HashSet<>();
Set<String> set = new HashSet<>();
//添加本级
set.add(pid);
//添加子节点
try {
List<Entity> list = Db.use((DataSource) SpringContextHolder.getBean("dataSource")).query(sql);
list.forEach(item -> {
set.add(item.getLong("dept_id"));
set.add(item.getStr("dept_id"));
});
} catch (SQLException e) {
e.printStackTrace();
@@ -327,18 +325,18 @@ public class DeptServiceImpl implements DeptService {
}
@Override
public Set<Long> getAllChildIdSet(String dept_idStr) {
public Set<String> getAllChildIdSet(String dept_idStr) {
JSONArray arr = WQLObject.getWQLObject("sys_dept").query("dept_id IN " + dept_idStr).getResultJSONArray(0);
Set<Long> set = new HashSet<>();
Set<String> set = new HashSet<>();
for (int i = 0; i < arr.size(); i++) {
set.addAll(this.getChildIdSet(arr.getJSONObject(i).getLong("dept_id")));
set.addAll(this.getChildIdSet(arr.getJSONObject(i).getString("dept_id")));
}
return set;
}
@Override
public String getChildIdStr(Long dept_id) {
Set<Long> set = this.getChildIdSet(dept_id);
public String getChildIdStr(String dept_id) {
Set<String> set = this.getChildIdSet(dept_id);
StringBuilder sb = new StringBuilder();
set.forEach(item -> {
sb.append(",'" + item + "'");
@@ -352,7 +350,7 @@ public class DeptServiceImpl implements DeptService {
@Override
public String getAllChildIdStr(String dept_idStr) {
Set<Long> set = this.getAllChildIdSet(dept_idStr);
Set<String> set = this.getAllChildIdSet(dept_idStr);
StringBuilder sb = new StringBuilder();
set.forEach(item -> {
sb.append(",'" + item + "'");

View File

@@ -16,7 +16,6 @@
package org.nl.modules.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@@ -28,6 +27,7 @@ import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.system.service.DictDetailService;
import org.nl.modules.system.service.dto.DictDetailQueryCriteria;
import org.nl.modules.system.service.dto.DictDto;
import org.nl.modules.tools.IdUtil;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
@@ -83,7 +83,7 @@ public class DictDetailServiceImpl implements DictDetailService {
return;
}
// 插入新的数据
resources.setDict_id(IdUtil.getSnowflake(1, 1).nextId());
resources.setDict_id(IdUtil.getStringId());
resources.setCode(dictObj.getString("code"));
resources.setName(dictObj.getString("name"));
resources.setCreate_id(Long.valueOf(SecurityUtils.getCurrentUserId()));
@@ -128,7 +128,7 @@ public class DictDetailServiceImpl implements DictDetailService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
public void delete(String id) {
DictDto dictDto = this.findById(id);
if (dictDto == null) {
throw new BadRequestException("被删除或无权限,操作失败!");
@@ -145,7 +145,7 @@ public class DictDetailServiceImpl implements DictDetailService {
}
@Override
public DictDto findById(Long dict_id) {
public DictDto findById(String dict_id) {
WQLObject wo = WQLObject.getWQLObject("sys_dict");
JSONObject json = wo.query("dict_id =" + dict_id + "").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {

View File

@@ -16,7 +16,6 @@
package org.nl.modules.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@@ -29,6 +28,7 @@ import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.system.service.DictService2;
import org.nl.modules.system.service.dto.DictDto;
import org.nl.modules.system.service.dto.DictQueryCriteria;
import org.nl.modules.tools.IdUtil;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
@@ -78,7 +78,7 @@ public class DictService2Impl implements DictService2 {
String currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String date = DateUtil.now();
dto.setDict_id(IdUtil.getSnowflake(1, 1).nextId());
dto.setDict_id(IdUtil.getStringId());
dto.setCreate_id(Long.valueOf(currentUserId));
dto.setCreate_name(nickName);
dto.setUpdate_id(Long.valueOf(currentUserId));
@@ -110,9 +110,9 @@ public class DictService2Impl implements DictService2 {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> ids) {
public void delete(Set<String> ids) {
WQLObject wo = WQLObject.getWQLObject("sys_dict");
for (Long id : ids) {
for (String id : ids) {
JSONObject object = wo.query("dict_id = '" + id + "'").uniqueResult(0);
// 删除数据
wo.delete("code = '" + object.getString("code") + "'");
@@ -149,7 +149,7 @@ public class DictService2Impl implements DictService2 {
}
@Override
public DictDto findById(Long dict_id) {
public DictDto findById(String dict_id) {
WQLObject wo = WQLObject.getWQLObject("sys_dict");
JSONObject json = wo.query("dict_id =" + dict_id + "").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {

View File

@@ -68,14 +68,14 @@ public class MenuServiceImpl implements MenuService {
@Override
public MenuDto menuJsonToMenuDto(JSONObject json) {
MenuDto menuDto = new MenuDto();
menuDto.setMenuId(json.getLong("menu_id"));
menuDto.setMenuId(json.getString("menu_id"));
menuDto.setType(json.getInteger("type"));
menuDto.setPermission(json.getString("permission"));
menuDto.setTitle(json.getString("title"));
menuDto.setMenuSort(json.getInteger("menu_sort"));
menuDto.setPath(json.getString("path"));
menuDto.setComponent(json.getString("component"));
menuDto.setPid(json.getLong("pid"));
menuDto.setPid(json.getString("pid"));
menuDto.setIcon(json.getString("icon"));
menuDto.setSubCount(json.getInteger("sub_count"));

View File

@@ -106,10 +106,10 @@ public class RoleServiceImpl implements RoleService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> ids) {
public void delete(Set<String> ids) {
WQLObject wo = WQLObject.getWQLObject("sys_role");
WQLObject rmTab = WQLObject.getWQLObject("sys_roles_menus");
for (Long id : ids) {
for (String id : ids) {
wo.delete("role_id =" + id);
rmTab.delete("role_id =" + id);
}

View File

@@ -2,7 +2,6 @@ package org.nl.modules.tools.rest;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -70,7 +69,7 @@ public class LocalStorageController {
@Log("删除文件")
@DeleteMapping
@ApiOperation("多选删除")
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
public ResponseEntity<Object> delete(@RequestBody String[] ids) {
localStorageService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@@ -24,7 +24,6 @@ public interface LocalStorageService {
/**
* 上传
* @param name 文件名称
* @param file 文件
* @return
*/
JSONObject create(String name, MultipartFile multipartFile);
@@ -46,6 +45,6 @@ public interface LocalStorageService {
* 多选删除
* @param ids /
*/
void deleteAll(Long[] ids);
void deleteAll(String[] ids);
}

View File

@@ -11,7 +11,6 @@ import org.nl.modules.common.config.FileProperties;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.common.utils.ValidationUtil;
import org.nl.modules.tools.domain.LocalStorage;
import org.nl.modules.tools.service.LocalStorageService;
import org.nl.modules.wql.core.bean.ResultBean;
@@ -142,9 +141,9 @@ public class LocalStorageServiceImpl implements LocalStorageService {
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
public void deleteAll(String[] ids) {
WQLObject toolTab = WQLObject.getWQLObject("tool_local_storage");
for (Long id : ids) {
for (String id : ids) {
JSONObject storage = this.findById(id.toString());
if (ObjectUtil.isEmpty(storage)) continue;
FileUtil.del(storage.getString("path"));

View File

@@ -110,7 +110,7 @@ public class SysDictController {
@ApiOperation("删除字典详情")
@DeleteMapping(value = "/dictDetail/{id}")
// @SaCheckPermission("dict:del")
public ResponseEntity<Object> deleteDetail(@PathVariable Long id){
public ResponseEntity<Object> deleteDetail(@PathVariable String id){
dictService.deleteDetail(id);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@@ -47,17 +47,17 @@ public class SysMenuController {
@ApiOperation("返回全部的菜单")
@GetMapping(value = "/lazy")//新增时候点击
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
public ResponseEntity<Object> query(@RequestParam Long pid) {
public ResponseEntity<Object> query(@RequestParam String pid) {
return new ResponseEntity<>(baseService.getMenus(pid), HttpStatus.OK);
}
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
@PostMapping("/superior")
@SaCheckPermission("menu:list")
public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
public ResponseEntity<Object> getSuperior(@RequestBody List<String> ids) {
Set<MenuDto> menuDtos = new LinkedHashSet<>();
if (CollectionUtil.isNotEmpty(ids)) {
for (Long id : ids) {
for (String id : ids) {
MenuDto menuDto = baseService.doToDto(baseService.findById(id));
menuDtos.addAll(baseService.getSuperior(menuDto, new ArrayList<>()));
}
@@ -77,12 +77,12 @@ public class SysMenuController {
@ApiOperation("根据菜单ID返回所有子节点ID包含自身ID")
@GetMapping(value = "/child")
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
public ResponseEntity<Object> child(@RequestParam Long id) {
public ResponseEntity<Object> child(@RequestParam String id) {
Set<SysMenu> menuSet = new HashSet<>();
List<SysMenu> menuList = baseService.getMenus(id);
menuSet.add(baseService.findById(id));
menuSet = baseService.getChildMenus(menuList, menuSet);
Set<Long> ids = menuSet.stream().map(SysMenu::getMenuId).collect(Collectors.toSet());
Set<String> ids = menuSet.stream().map(SysMenu::getMenuId).collect(Collectors.toSet());
return new ResponseEntity<>(ids, HttpStatus.OK);
}
@@ -108,9 +108,9 @@ public class SysMenuController {
@ApiOperation("删除菜单")
@DeleteMapping
@SaCheckPermission("menu:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
Set<SysMenu> menuSet = new HashSet<>();
for (Long id : ids) {
for (String id : ids) {
//获取所有子节点
List<SysMenu> menuList = baseService.getMenus(id);
menuSet.add(baseService.findById(id));

View File

@@ -104,8 +104,8 @@ public class UserController {
@ApiOperation("删除用户")
@DeleteMapping
// @SaCheckPermission("user:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
for (Long id : ids) {
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
for (String id : ids) {
/* Integer currentLevel = Collections.min(roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList()));
Integer optLevel = Collections.min(roleService.findByUsersId(id).stream().map(Role::getLevel).collect(Collectors.toList()));
if (currentLevel > optLevel) {

View File

@@ -78,5 +78,5 @@ public interface ISysDictService extends IService<Dict> {
* 删除字典
* @param id
*/
void deleteDetail(Long id);
void deleteDetail(String id);
}

View File

@@ -162,7 +162,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDetail(Long id) {
public void deleteDetail(String id) {
sysDictMapper.deleteById(id);
}

View File

@@ -41,8 +41,8 @@ public interface ISysMenuService extends IService<SysMenu> {
* @param id /
* @return /
*/
SysMenu findById(long id);
List<SysMenu> findByPid(long pid);
SysMenu findById(String id);
List<SysMenu> findByPid(String pid);
List<SysMenu> findByPidIsNull();
/**
@@ -97,7 +97,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* @param pid /
* @return /
*/
List<SysMenu> getMenus(Long pid);
List<SysMenu> getMenus(String pid);
/**
* @param sysMenu

View File

@@ -27,12 +27,12 @@ public class SysMenu implements Serializable {
* 菜单标识
*/
@TableId(value = "menu_id", type = IdType.AUTO)
private Long menuId;
private String menuId;
/**
* 上级菜单ID
*/
private Long pid;
private String pid;
/**
* 子菜单数目

View File

@@ -20,7 +20,7 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
List<SysMenu> findByPidIsNull();
@Select("select * from sys_menu where pid = #{pid}")
List<SysMenu> findByPid(@Param("pid") Long pid);
List<SysMenu> findByPid(@Param("pid") String pid);
/**
* 根据用户获取菜单

View File

@@ -34,7 +34,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override
public List<MenuDto> queryAll(Map<String, Object> param) throws Exception {
Long pid = MapUtil.getLong(param, "pid");
String pid = MapUtil.getStr(param, "pid");
/*List<SysMenu> sysMenus = baseMapper.selectList(null);
List<MenuDto> menus = sysMenus.stream().map(menu -> doToDto(menu)).collect(Collectors.toList());*/
return getMenus(pid).stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
@@ -52,12 +52,12 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
}
@Override
public SysMenu findById(long id) {
public SysMenu findById(String id) {
return baseMapper.selectById(id);
}
@Override
public List<SysMenu> findByPid(long pid) {
public List<SysMenu> findByPid(String pid) {
return baseMapper.findByPid(pid);
}
@@ -127,8 +127,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
}
// 记录的父节点ID
Long oldPid = menu.getPid();
Long newPid = resources.getPid();
String oldPid = menu.getPid();
String newPid = resources.getPid();
menu.setTitle(resources.getTitle());
menu.setComponent(resources.getComponent());
menu.setPath(resources.getPath());
@@ -152,7 +152,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
*
* @param menuId
*/
private void updateSubCnt(Long menuId) {
private void updateSubCnt(String menuId) {
if (menuId != null) {
int count = baseMapper.findByPid(menuId).size();
SysMenu sysMenu = baseMapper.selectById(menuId);
@@ -223,7 +223,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override
public List<MenuDto> buildTree(List<MenuDto> menuDtos) {
List<MenuDto> trees = new ArrayList<>();
Set<Long> ids = new HashSet<>();
Set<String> ids = new HashSet<>();
for (MenuDto menuDTO : menuDtos) {
if (menuDTO.getPid() == null) {
trees.add(menuDTO);
@@ -245,7 +245,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
}
@Override
public List<SysMenu> getMenus(Long pid) {
public List<SysMenu> getMenus(String pid) {
QueryWrapper<SysMenu> queryWrapper;
if (pid != null && !pid.equals(0L)) {
queryWrapper = new QueryWrapper<SysMenu>().eq("pid", pid);