diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/config/JobRunner.java b/nladmin-system/src/main/java/org/nl/modules/quartz/config/JobRunner.java index 8eb12ebd9..85f1b8b74 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/config/JobRunner.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/config/JobRunner.java @@ -16,20 +16,25 @@ package org.nl.modules.quartz.config; import lombok.RequiredArgsConstructor; +import org.nl.modules.quartz.domain.QuartzJob; import org.nl.modules.quartz.repository.QuartzJobRepository; import org.nl.modules.quartz.utils.QuartzManage; 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; + /** * @author Zheng Jie * @date 2019-01-07 */ @Component @RequiredArgsConstructor +@Order(100) public class JobRunner implements ApplicationRunner { private static final Logger log = LoggerFactory.getLogger(JobRunner.class); private final QuartzJobRepository quartzJobRepository; @@ -42,9 +47,9 @@ public class JobRunner implements ApplicationRunner { */ @Override public void run(ApplicationArguments applicationArguments) { - /* log.info("--------------------注入定时任务---------------------"); + log.info("--------------------注入定时任务---------------------"); List quartzJobs = quartzJobRepository.findByIsPauseIsFalse(); quartzJobs.forEach(quartzManage::addJob); - log.info("--------------------定时任务注入完成---------------------");*/ + log.info("--------------------定时任务注入完成---------------------"); } } diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/rest/QuartzJobController.java b/nladmin-system/src/main/java/org/nl/modules/quartz/rest/QuartzJobController.java index 0d4246b50..f84511bab 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/rest/QuartzJobController.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/rest/QuartzJobController.java @@ -31,8 +31,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.Set; /** @@ -52,38 +50,24 @@ public class QuartzJobController { @ApiOperation("查询定时任务") @GetMapping @SaCheckPermission("timing:list") - public ResponseEntity query(JobQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(quartzJobService.queryAll(criteria,pageable), HttpStatus.OK); - } - - @ApiOperation("导出任务数据") - @GetMapping(value = "/download") - @SaCheckPermission("timing:list") - public void download(HttpServletResponse response, JobQueryCriteria criteria) throws IOException { - quartzJobService.download(quartzJobService.queryAll(criteria), response); - } - - @ApiOperation("导出日志数据") - @GetMapping(value = "/logs/download") - @SaCheckPermission("timing:list") - public void downloadLog(HttpServletResponse response, JobQueryCriteria criteria) throws IOException { - quartzJobService.downloadLog(quartzJobService.queryAllLog(criteria), response); + public ResponseEntity query(JobQueryCriteria criteria, Pageable pageable) { + return new ResponseEntity<>(quartzJobService.queryAll(criteria, pageable), HttpStatus.OK); } @ApiOperation("查询任务执行日志") @GetMapping(value = "/logs") @SaCheckPermission("timing:list") - public ResponseEntity queryJobLog(JobQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(quartzJobService.queryAllLog(criteria,pageable), HttpStatus.OK); + public ResponseEntity queryJobLog(JobQueryCriteria criteria, Pageable pageable) { + return new ResponseEntity<>(quartzJobService.queryAllLog(criteria, pageable), HttpStatus.OK); } @Log("新增定时任务") @ApiOperation("新增定时任务") @PostMapping @SaCheckPermission("timing:add") - public ResponseEntity create(@Validated @RequestBody QuartzJob resources){ + public ResponseEntity create(@Validated @RequestBody QuartzJob resources) { if (resources.getId() != null) { - throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID"); + throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID"); } quartzJobService.create(resources); return new ResponseEntity<>(HttpStatus.CREATED); @@ -93,7 +77,7 @@ public class QuartzJobController { @ApiOperation("修改定时任务") @PutMapping @SaCheckPermission("timing:edit") - public ResponseEntity update(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources){ + public ResponseEntity update(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources) { quartzJobService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -102,7 +86,7 @@ public class QuartzJobController { @ApiOperation("更改定时任务状态") @PutMapping(value = "/{id}") @SaCheckPermission("timing:edit") - public ResponseEntity update(@PathVariable Long id){ + public ResponseEntity update(@PathVariable Long id) { quartzJobService.updateIsPause(quartzJobService.findById(id)); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -111,7 +95,7 @@ public class QuartzJobController { @ApiOperation("执行定时任务") @PutMapping(value = "/exec/{id}") @SaCheckPermission("timing:edit") - public ResponseEntity execution(@PathVariable Long id){ + public ResponseEntity execution(@PathVariable Long id) { quartzJobService.execution(quartzJobService.findById(id)); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -120,7 +104,7 @@ public class QuartzJobController { @ApiOperation("删除定时任务") @DeleteMapping @SaCheckPermission("timing:del") - public ResponseEntity delete(@RequestBody Set ids){ + public ResponseEntity delete(@RequestBody Set ids) { quartzJobService.delete(ids); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/service/QuartzJobService.java b/nladmin-system/src/main/java/org/nl/modules/quartz/service/QuartzJobService.java index 0f6658226..74ec177f6 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/service/QuartzJobService.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/service/QuartzJobService.java @@ -20,8 +20,6 @@ import org.nl.modules.quartz.domain.QuartzLog; import org.nl.modules.quartz.service.dto.JobQueryCriteria; import org.springframework.data.domain.Pageable; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.List; import java.util.Set; @@ -33,6 +31,7 @@ public interface QuartzJobService { /** * 分页查询 + * * @param criteria 条件 * @param pageable 分页参数 * @return / @@ -41,6 +40,7 @@ public interface QuartzJobService { /** * 查询全部 + * * @param criteria 条件 * @return / */ @@ -48,6 +48,7 @@ public interface QuartzJobService { /** * 分页查询日志 + * * @param criteria 条件 * @param pageable 分页参数 * @return / @@ -56,6 +57,7 @@ public interface QuartzJobService { /** * 查询全部 + * * @param criteria 条件 * @return / */ @@ -63,24 +65,28 @@ public interface QuartzJobService { /** * 创建 + * * @param resources / */ void create(QuartzJob resources); /** * 编辑 + * * @param resources / */ void update(QuartzJob resources); /** * 删除任务 + * * @param ids / */ void delete(Set ids); /** * 根据ID查询 + * * @param id ID * @return / */ @@ -88,34 +94,22 @@ public interface QuartzJobService { /** * 更改定时任务状态 + * * @param quartzJob / */ void updateIsPause(QuartzJob quartzJob); /** * 立即执行定时任务 + * * @param quartzJob / */ void execution(QuartzJob quartzJob); - /** - * 导出定时任务 - * @param queryAll 待导出的数据 - * @param response / - * @throws IOException / - */ - void download(List queryAll, HttpServletResponse response) throws IOException; - - /** - * 导出定时任务日志 - * @param queryAllLog 待导出的数据 - * @param response / - * @throws IOException / - */ - void downloadLog(List queryAllLog, HttpServletResponse response) throws IOException; /** * 执行子任务 + * * @param tasks / * @throws InterruptedException / */ diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/service/impl/QuartzJobServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/quartz/service/impl/QuartzJobServiceImpl.java index baebaecc9..edc15b6b6 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/service/impl/QuartzJobServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/service/impl/QuartzJobServiceImpl.java @@ -19,7 +19,10 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.*; +import org.nl.modules.common.utils.PageUtil; +import org.nl.modules.common.utils.QueryHelp; +import org.nl.modules.common.utils.RedisUtils; +import org.nl.modules.common.utils.ValidationUtil; import org.nl.modules.quartz.domain.QuartzJob; import org.nl.modules.quartz.domain.QuartzLog; import org.nl.modules.quartz.repository.QuartzJobRepository; @@ -33,9 +36,9 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.List; +import java.util.Set; /** * @author Zheng Jie @@ -51,36 +54,36 @@ public class QuartzJobServiceImpl implements QuartzJobService { private final RedisUtils redisUtils; @Override - public Object queryAll(JobQueryCriteria criteria, Pageable pageable){ - return PageUtil.toPage(quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable)); + public Object queryAll(JobQueryCriteria criteria, Pageable pageable) { + return PageUtil.toPage(quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable)); } @Override - public Object queryAllLog(JobQueryCriteria criteria, Pageable pageable){ - return PageUtil.toPage(quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable)); + public Object queryAllLog(JobQueryCriteria criteria, Pageable pageable) { + return PageUtil.toPage(quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable)); } @Override public List queryAll(JobQueryCriteria criteria) { - return quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); + return quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); } @Override public List queryAllLog(JobQueryCriteria criteria) { - return quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); + return quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); } @Override public QuartzJob findById(Long id) { QuartzJob quartzJob = quartzJobRepository.findById(id).orElseGet(QuartzJob::new); - ValidationUtil.isNull(quartzJob.getId(),"QuartzJob","id",id); + ValidationUtil.isNull(quartzJob.getId(), "QuartzJob", "id", id); return quartzJob; } @Override @Transactional(rollbackFor = Exception.class) public void create(QuartzJob resources) { - if (!CronExpression.isValidExpression(resources.getCronExpression())){ + if (!CronExpression.isValidExpression(resources.getCronExpression())) { throw new BadRequestException("cron表达式格式错误"); } resources = quartzJobRepository.save(resources); @@ -90,10 +93,10 @@ public class QuartzJobServiceImpl implements QuartzJobService { @Override @Transactional(rollbackFor = Exception.class) public void update(QuartzJob resources) { - if (!CronExpression.isValidExpression(resources.getCronExpression())){ + if (!CronExpression.isValidExpression(resources.getCronExpression())) { throw new BadRequestException("cron表达式格式错误"); } - if(StrUtil.isNotEmpty(resources.getSubTask())){ + if (StrUtil.isNotEmpty(resources.getSubTask())) { List tasks = Arrays.asList(resources.getSubTask().split("[,,]")); if (tasks.contains(resources.getId().toString())) { throw new BadRequestException("子任务中不能添加当前任务ID"); @@ -148,47 +151,11 @@ public class QuartzJobServiceImpl implements QuartzJobService { Thread.sleep(5000); result = (Boolean) redisUtils.get(uuid); } - if(!result){ + if (!result) { redisUtils.del(uuid); break; } } } - @Override - public void download(List quartzJobs, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (QuartzJob quartzJob : quartzJobs) { - Map map = new LinkedHashMap<>(); - map.put("任务名称", quartzJob.getJobName()); - map.put("Bean名称", quartzJob.getBeanName()); - map.put("执行方法", quartzJob.getMethodName()); - map.put("参数", quartzJob.getParams()); - map.put("表达式", quartzJob.getCronExpression()); - map.put("状态", quartzJob.getIsPause() ? "暂停中" : "运行中"); - map.put("描述", quartzJob.getDescription()); - map.put("创建日期", quartzJob.getCreateTime()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - @Override - public void downloadLog(List queryAllLog, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (QuartzLog quartzLog : queryAllLog) { - Map map = new LinkedHashMap<>(); - map.put("任务名称", quartzLog.getJobName()); - map.put("Bean名称", quartzLog.getBeanName()); - map.put("执行方法", quartzLog.getMethodName()); - map.put("参数", quartzLog.getParams()); - map.put("表达式", quartzLog.getCronExpression()); - map.put("异常详情", quartzLog.getExceptionDetail()); - map.put("耗时/毫秒", quartzLog.getTime()); - map.put("状态", quartzLog.getIsSuccess() ? "成功" : "失败"); - map.put("创建日期", quartzLog.getCreateTime()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } } diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestSch.java b/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestSch.java deleted file mode 100644 index 588faca15..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestSch.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.nl.modules.quartz.task; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -@Slf4j -@Component -public class TestSch { - public void run() { - log.info("run 执行成功1"); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java b/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java index 0d67ce09e..6a0b518c9 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java @@ -16,6 +16,7 @@ package org.nl.modules.quartz.task; import lombok.extern.slf4j.Slf4j; +import org.nl.modules.wql.core.bean.WQLObject; import org.springframework.stereotype.Component; /** @@ -28,6 +29,7 @@ import org.springframework.stereotype.Component; public class TestTask { public void run(){ + log.info("run 执行成功"); } @@ -36,6 +38,7 @@ public class TestTask { } public void run2(){ + WQLObject.getWQLObject("sys_param"); log.info("run2 执行成功"); } } diff --git a/nladmin-system/src/main/java/org/nl/modules/security/rest/test.java b/nladmin-system/src/main/java/org/nl/modules/security/rest/test.java deleted file mode 100644 index 78d45c4ce..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/security/rest/test.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.nl.modules.security.rest; - -import cn.dev33.satoken.secure.SaSecureUtil; - -/** - * @author lyd - * @description 密码加密测试 - */ -public class test { - public static void main(String[] args) { - String salt = SaSecureUtil.md5BySalt("123456", "salt"); - System.out.println(salt); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/system/service/impl/ParamServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/system/service/impl/ParamServiceImpl.java index 1ebae3afb..78ec333bb 100644 --- a/nladmin-system/src/main/java/org/nl/modules/system/service/impl/ParamServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/modules/system/service/impl/ParamServiceImpl.java @@ -98,12 +98,11 @@ public class ParamServiceImpl implements ParamService { ParamDto entity = this.findById(dto.getId()); if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); - CurrentUser currentUsername = SecurityUtils.getCurrentUser(); String now = DateUtil.now(); dto.setUpdate_optid(StpUtil.getLoginIdAsLong()); dto.setUpdate_time(now); - dto.setUpdate_optname(currentUsername.getNickName()); + dto.setUpdate_optname(SecurityUtils.getCurrentNickName()); WQLObject wo = WQLObject.getWQLObject("sys_param"); JSONObject json = JSONObject.parseObject( JSONObject.toJSONString(dto)); diff --git a/nladmin-system/src/main/java/org/nl/start/Init.java b/nladmin-system/src/main/java/org/nl/start/Init.java index 10b6f11c8..e7ea3c749 100644 --- a/nladmin-system/src/main/java/org/nl/start/Init.java +++ b/nladmin-system/src/main/java/org/nl/start/Init.java @@ -2,43 +2,27 @@ package org.nl.start; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.nl.modules.quartz.domain.QuartzJob; -import org.nl.modules.quartz.repository.QuartzJobRepository; -import org.nl.modules.quartz.utils.QuartzManage; import org.nl.modules.wql.WQLCore; 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; - /** * 随项目启动模块 */ @Slf4j @Component @RequiredArgsConstructor +@Order(0) public class Init implements ApplicationRunner { - private final QuartzJobRepository quartzJobRepository; - private final QuartzManage quartzManage; - private void init() throws Exception { //初始化WQL initWql(); - //初始化任务调度 - initQuartz(); System.out.println("项目启动成功!"); } - private void initQuartz() { - log.info("--------------------注入定时任务---------------------"); - List quartzJobs = quartzJobRepository.findByIsPauseIsFalse(); - quartzJobs.forEach(quartzManage::addJob); - log.info("--------------------定时任务注入完成---------------------"); - - } - private void initWql() throws Exception { WQLCore.ROOT = "org.nl"; WQLCore.init(); diff --git a/nladmin-ui/src/views/system/param/index.vue b/nladmin-ui/src/views/system/param/index.vue index dfc8963c2..cb5090f5b 100644 --- a/nladmin-ui/src/views/system/param/index.vue +++ b/nladmin-ui/src/views/system/param/index.vue @@ -22,12 +22,6 @@ - - - - - - @@ -49,16 +43,10 @@ - - + + - - - - +