增加定时任务管理
This commit is contained in:
parent
621e7916dc
commit
03d09ca7d7
|
|
@ -1,17 +1,21 @@
|
|||
package com.mdd.admin.controller;
|
||||
|
||||
import com.mdd.admin.service.ICrontabService;
|
||||
import com.mdd.admin.validate.CrontabCreateValidate;
|
||||
import com.mdd.admin.validate.CrontabUpdateValidate;
|
||||
import com.mdd.admin.validate.commons.IdValidate;
|
||||
import com.mdd.admin.validate.commons.PageValidate;
|
||||
import com.mdd.admin.vo.CrontabDetailVo;
|
||||
import com.mdd.admin.vo.CrontabListedVo;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/crontab")
|
||||
public class CrontabController {
|
||||
|
||||
|
|
@ -23,31 +27,63 @@ public class CrontabController {
|
|||
*
|
||||
* @author fzr
|
||||
* @param pageValidate 分页参数
|
||||
* @return AjaxResult<Object>
|
||||
* @return AjaxResult< PageResult<CrontabListedVo>>
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public AjaxResult<Object> list(@Validated PageValidate pageValidate) {
|
||||
public AjaxResult< PageResult<CrontabListedVo>> list(@Validated PageValidate pageValidate) {
|
||||
PageResult<CrontabListedVo> list = iCrontabService.list(pageValidate);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划任务详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
public AjaxResult<Object> detail() {
|
||||
return AjaxResult.success();
|
||||
public AjaxResult<Object> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
CrontabDetailVo vo = iCrontabService.detail(id);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划任务新增
|
||||
*
|
||||
* @author fzr
|
||||
* @param createValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public AjaxResult<Object> add() {
|
||||
public AjaxResult<Object> add(@Validated @RequestBody CrontabCreateValidate createValidate) {
|
||||
iCrontabService.add(createValidate);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划任务编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param updateValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public AjaxResult<Object> edit() {
|
||||
public AjaxResult<Object> edit(@Validated @RequestBody CrontabUpdateValidate updateValidate) {
|
||||
iCrontabService.edit(updateValidate);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划任务删除
|
||||
*
|
||||
* @author fzr
|
||||
* @param idValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@PostMapping("/del")
|
||||
public AjaxResult<Object> del() {
|
||||
public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
|
||||
iCrontabService.del(idValidate.getId());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.mdd.admin.service;
|
||||
|
||||
import com.mdd.admin.validate.CrontabCreateValidate;
|
||||
import com.mdd.admin.validate.CrontabUpdateValidate;
|
||||
import com.mdd.admin.validate.commons.PageValidate;
|
||||
import com.mdd.admin.vo.CrontabDetailVo;
|
||||
import com.mdd.admin.vo.CrontabListedVo;
|
||||
|
|
@ -19,12 +21,37 @@ public interface ICrontabService {
|
|||
*/
|
||||
PageResult<CrontabListedVo> list(PageValidate pageValidate);
|
||||
|
||||
CrontabDetailVo detail();
|
||||
/**
|
||||
* 计划任务详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
* @return CrontabDetailVo
|
||||
*/
|
||||
CrontabDetailVo detail(Integer id);
|
||||
|
||||
void add();
|
||||
/**
|
||||
* 计划任务新增
|
||||
*
|
||||
* @author fzr
|
||||
* @param createValidate 参数
|
||||
*/
|
||||
void add(CrontabCreateValidate createValidate);
|
||||
|
||||
void edit();
|
||||
/**
|
||||
* 计划任务编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param updateValidate 参数
|
||||
*/
|
||||
void edit(CrontabUpdateValidate updateValidate);
|
||||
|
||||
void del();
|
||||
/**
|
||||
* 计划任务删除
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
*/
|
||||
void del(Integer id);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mdd.admin.service.ICrontabService;
|
||||
import com.mdd.admin.validate.CrontabCreateValidate;
|
||||
import com.mdd.admin.validate.CrontabUpdateValidate;
|
||||
import com.mdd.admin.validate.commons.PageValidate;
|
||||
import com.mdd.admin.vo.CrontabDetailVo;
|
||||
import com.mdd.admin.vo.CrontabListedVo;
|
||||
import com.mdd.admin.vo.article.ArticleListedVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.Crontab;
|
||||
import com.mdd.common.entity.server.Sys;
|
||||
import com.mdd.common.mapper.CrontabMapper;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
|
|
@ -48,29 +51,92 @@ public class CrontabServiceImpl implements ICrontabService {
|
|||
for (Crontab crontab : iPage.getRecords()) {
|
||||
CrontabListedVo vo = new CrontabListedVo();
|
||||
BeanUtils.copyProperties(crontab, vo);
|
||||
|
||||
list.add(vo);
|
||||
}
|
||||
|
||||
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划任务详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
* @return CrontabDetailVo
|
||||
*/
|
||||
@Override
|
||||
public CrontabDetailVo detail() {
|
||||
return null;
|
||||
public CrontabDetailVo detail(Integer id) {
|
||||
Crontab crontab = crontabMapper.selectOne(
|
||||
new QueryWrapper<Crontab>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(crontab, "数据不存在!");
|
||||
|
||||
CrontabDetailVo vo = new CrontabDetailVo();
|
||||
BeanUtils.copyProperties(crontab, vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划任务新增
|
||||
*
|
||||
* @author fzr
|
||||
* @param createValidate 参数
|
||||
*/
|
||||
@Override
|
||||
public void add(CrontabCreateValidate createValidate) {
|
||||
Crontab crontab = new Crontab();
|
||||
crontab.setName(createValidate.getName());
|
||||
crontab.setCommand(createValidate.getCommand());
|
||||
crontab.setRules(createValidate.getRules());
|
||||
crontab.setStatus(createValidate.getStatus());
|
||||
crontab.setRemark(createValidate.getRemark());
|
||||
crontab.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
crontab.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
crontabMapper.insert(crontab);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划任务编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param updateValidate 参数
|
||||
*/
|
||||
@Override
|
||||
public void edit(CrontabUpdateValidate updateValidate) {
|
||||
Crontab crontab = crontabMapper.selectOne(
|
||||
new QueryWrapper<Crontab>()
|
||||
.eq("id", updateValidate.getId())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(crontab, "数据不存在!");
|
||||
|
||||
crontab.setName(updateValidate.getName());
|
||||
crontab.setCommand(updateValidate.getCommand());
|
||||
crontab.setRules(updateValidate.getRules());
|
||||
crontab.setStatus(updateValidate.getStatus());
|
||||
crontab.setRemark(updateValidate.getRemark());
|
||||
crontab.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
crontabMapper.updateById(crontab);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add() {
|
||||
public void del(Integer id) {
|
||||
Crontab crontab = crontabMapper.selectOne(
|
||||
new QueryWrapper<Crontab>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void del() {
|
||||
Assert.notNull(crontab, "数据不存在!");
|
||||
|
||||
crontab.setIsDelete(1);
|
||||
crontab.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||
crontabMapper.updateById(crontab);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.mdd.admin.validate;
|
||||
|
||||
import com.mdd.common.validator.annotation.IntegerContains;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CrontabCreateValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "name参数缺失")
|
||||
private String name;
|
||||
|
||||
@NotNull(message = "command参数缺失")
|
||||
private String command;
|
||||
|
||||
@NotNull(message = "rules参数缺失")
|
||||
private String rules;
|
||||
|
||||
@IntegerContains(values = {1, 2, 3}, message = "status参数取值异常")
|
||||
private Integer status;
|
||||
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.mdd.admin.validate;
|
||||
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import com.mdd.common.validator.annotation.IntegerContains;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CrontabUpdateValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0")
|
||||
private Integer id;
|
||||
|
||||
@NotNull(message = "name参数缺失")
|
||||
private String name;
|
||||
|
||||
@NotNull(message = "command参数缺失")
|
||||
private String command;
|
||||
|
||||
@NotNull(message = "rules参数缺失")
|
||||
private String rules;
|
||||
|
||||
@IntegerContains(values = {1, 2, 3}, message = "status参数取值异常")
|
||||
private Integer status;
|
||||
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.mdd.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -12,6 +14,7 @@ public class Crontab implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id; // 主键
|
||||
private String name; // 任务名称
|
||||
private String command; // 任务命令
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.mdd.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -12,6 +14,7 @@ public class DecoratePage implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id;
|
||||
private Integer pageType;
|
||||
private String pageName;
|
||||
|
|
|
|||
Loading…
Reference in New Issue