Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:系统定时任务持久化 #275

Closed

Conversation

Z-feiyao
Copy link
Contributor

@Z-feiyao Z-feiyao commented Nov 23, 2022

在提出此拉取请求时,我确认了以下几点(保存后请点击复选框):

  • 标题为fix、feat或doc开头
  • 我已检查没有与此请求重复的拉取请求。
  • 我已经考虑过,并确认这份呈件对其他人很有价值。
  • 我接受此提交可能不会被使用,并根据维护人员的意愿关闭拉取请求。

填写PR内容:
1、jobs 表添加 type 字段用于区分系统/非系统定时任务,需要对原来的非系统定时任务做下处理

  • ALTER TABLE jobs ADD type VARCHAR(20)
  • UPDATE jobs SET type = 'TEST_JOB' WHERE type is null

2、定时任务相关的接口根据 type 字段进行了过滤
3、系统定时任务保存到 jobs 表中,初始化系统定时任务时,从表中取 cron 表达式
4、如果表中没有系统定时任务,会初始化进去

@Z-feiyao Z-feiyao changed the title 系统定时任务持久化 fix:系统定时任务持久化 Nov 23, 2022
@prlabeler prlabeler bot added the fix label Nov 23, 2022
@@ -52,6 +55,7 @@ public class JobsServiceImpl extends SonicServiceImpl<JobsMapper, Jobs> implemen
@Transactional(rollbackFor = Exception.class)
public RespModel<String> saveJobs(Jobs jobs) throws SonicException {
jobs.setStatus(JobStatus.ENABLE);
jobs.setType("TEST_JOB");
save(jobs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个“TEST_JOB”可以提取为一个final string会更优雅,然后其他地方直接引用就行了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private List<String> typeList = Arrays.asList("cleanFile", "cleanResult", "sendDayReport", "sendWeekReport");

你这里全小写的,TEST_JOB也可以统一一下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为数据库有变更所以针对历史数据的处理,让用户自行处理,还是写个兼容的逻辑?

/**
* Mapper 接口
* @author JayWenStar
*/
@Mapper
public interface JobsMapper extends BaseMapper<Jobs> {

@Select("select * from jobs where type = #{type}")
Jobs findByType(@Param("type") String type);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们后面计划逐渐减少这种使用方法,建议可以直接在QuartzHandler.java 用lambdaquery直接eq type就可以了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我把 findByType 加到 JobsService 里面吧,然后用 lambdaquery 的写法

Copy link
Member

@ZhouYixun ZhouYixun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大体没什么问题,需要调整的点已经评论啦,可以继续优化一下哦

@Z-feiyao
Copy link
Contributor Author

已优化,我重新提交一个PR

@Z-feiyao Z-feiyao closed this Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants