
16 changed files with 326 additions and 22 deletions
@ -0,0 +1,68 @@ |
|||
package com.yxt.supervise.monitor.api.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.yxt.common.core.domain.EntityWithId; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@ApiModel(value = "有ID的实体", description = "有ID的实体") |
|||
@TableName("y_task") |
|||
public class YTask extends EntityWithId { |
|||
// `id`使用继承的
|
|||
|
|||
@ApiModelProperty("记录创建时间") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
private Date createTime = new Date(); // 记录创建时间
|
|||
|
|||
@ApiModelProperty("备注说明") |
|||
private String remarks; // 备注说明
|
|||
|
|||
@ApiModelProperty("状态") |
|||
private String status; |
|||
|
|||
@ApiModelProperty("信息状态") |
|||
private String state; |
|||
|
|||
@ApiModelProperty("是否删除") |
|||
private String isDelete; |
|||
|
|||
@ApiModelProperty("修改时间") |
|||
private String modifyTime; |
|||
|
|||
@ApiModelProperty("是否可用") |
|||
private String isEnable; |
|||
|
|||
@ApiModelProperty("创建人") |
|||
private String createBySid; |
|||
|
|||
@ApiModelProperty("更新人") |
|||
private String updateBySid; |
|||
|
|||
@ApiModelProperty("秒") |
|||
private String second; |
|||
|
|||
@ApiModelProperty("分") |
|||
private String divide; |
|||
|
|||
@ApiModelProperty("时") |
|||
private String hour; |
|||
|
|||
@ApiModelProperty("天") |
|||
private String day; |
|||
|
|||
@ApiModelProperty("月") |
|||
private String month; |
|||
|
|||
@ApiModelProperty("年") |
|||
private String year; |
|||
|
|||
@TableField(exist = false) |
|||
@ApiModelProperty("多少秒") |
|||
private String seconds; |
|||
} |
@ -1,22 +1,90 @@ |
|||
package com.yxt.supervise.monitor.biz.scheduled; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.yxt.common.core.result.ResultBean; |
|||
import com.yxt.supervise.monitor.api.entity.YTask; |
|||
import com.yxt.supervise.monitor.biz.task.YTaskService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.util.List; |
|||
|
|||
|
|||
@Slf4j |
|||
@RestController |
|||
@RequiredArgsConstructor |
|||
public class SyncUpdater { |
|||
|
|||
@Autowired |
|||
YTaskService yTaskService; |
|||
|
|||
private final SyncDetection scheduleTask; |
|||
|
|||
@GetMapping("/updateCron") |
|||
public void updateCron(String cron) { |
|||
public ResultBean updateCron(YTask yTask) { |
|||
// 0/30 * * * * ?
|
|||
String cron = parseCronStr(yTask); |
|||
log.info("new cron :{}", cron); |
|||
scheduleTask.setCron(cron); |
|||
|
|||
ResultBean rb = ResultBean.fireSuccess(); |
|||
rb.setData(yTaskService.refreshTask(yTask)); |
|||
return rb; |
|||
} |
|||
|
|||
@PostConstruct |
|||
public void initTask() { |
|||
QueryWrapper<YTask> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq("status", "1"); |
|||
List<YTask> list = yTaskService.list(wrapper); |
|||
if (list.size() > 0) { |
|||
String cron = parseCronStr(list.get(0)); |
|||
scheduleTask.setCron(cron); |
|||
} |
|||
} |
|||
|
|||
private String parseCronStr(YTask yTask) { |
|||
String cron = ""; |
|||
if (yTask.getSecond() != null) { |
|||
cron += yTask.getSecond() + " "; |
|||
} else { |
|||
cron += "* "; |
|||
} |
|||
|
|||
if (yTask.getDivide() != null) { |
|||
cron += yTask.getDivide() + " "; |
|||
} else { |
|||
cron += "* "; |
|||
} |
|||
|
|||
if (yTask.getHour() != null) { |
|||
cron += yTask.getHour() + " "; |
|||
} else { |
|||
cron += "* "; |
|||
} |
|||
|
|||
if (yTask.getDay() != null) { |
|||
cron += yTask.getDay() + " "; |
|||
} else { |
|||
cron += "* "; |
|||
} |
|||
|
|||
if (yTask.getMonth() != null) { |
|||
cron += yTask.getMonth() + " "; |
|||
} else { |
|||
cron += "* "; |
|||
} |
|||
|
|||
if (yTask.getYear() != null) { |
|||
cron += yTask.getYear(); |
|||
} else { |
|||
cron += "?"; |
|||
} |
|||
return cron; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,11 @@ |
|||
package com.yxt.supervise.monitor.biz.task; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.yxt.supervise.monitor.api.entity.DeviceLog; |
|||
import com.yxt.supervise.monitor.api.entity.YTask; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
@Mapper |
|||
public interface YTaskMapper extends BaseMapper<YTask> { |
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.yxt.supervise.monitor.biz.task; |
|||
|
|||
import com.yxt.common.core.result.ResultBean; |
|||
import com.yxt.supervise.monitor.api.entity.YTask; |
|||
import com.yxt.supervise.monitor.api.vo.PageVo; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.Map; |
|||
|
|||
@Api(tags = "定时修改控制器") |
|||
@RestController("com.yxt.supervise.monitor.biz.task.YTaskRest") |
|||
@RequestMapping("/yTask") |
|||
public class YTaskRest { |
|||
|
|||
@Autowired |
|||
YTaskService yTaskService; |
|||
|
|||
@ApiOperation("手动修改定时") |
|||
@GetMapping("/refreshTask") |
|||
public ResultBean refreshTask(YTask yTask) { |
|||
ResultBean rb = ResultBean.fireSuccess(); |
|||
rb.setData(yTaskService.refreshTask(yTask)); |
|||
return rb; |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.yxt.supervise.monitor.biz.task; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.yxt.supervise.monitor.api.entity.DeviceLog; |
|||
import com.yxt.supervise.monitor.api.entity.YTask; |
|||
import com.yxt.supervise.monitor.api.vo.PageVo; |
|||
import com.yxt.supervise.monitor.biz.scheduled.SyncDetection; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class YTaskService extends ServiceImpl<YTaskMapper, YTask> { |
|||
|
|||
public boolean refreshTask(YTask yTask) { |
|||
UpdateWrapper<YTask> wrapper = new UpdateWrapper<>(); |
|||
wrapper.set("status", "0"); |
|||
this.update(wrapper); |
|||
|
|||
yTask.setStatus("1"); |
|||
return this.save(yTask); |
|||
} |
|||
|
|||
} |
@ -1,3 +1,3 @@ |
|||
scheduleTime.cron=0/30 * * * * ? |
|||
scheduleTime.cron=0/59 0/2 * * * ? |
|||
|
|||
scheduleTime.timer=15000 |
|||
image.folder=D:\\resources\\download\\ |
Loading…
Reference in new issue