feat:持久化监控项

This commit is contained in:
nieziyan 2023-08-22 16:52:26 +08:00
parent 72a8d901ea
commit 77bea6bda4
22 changed files with 272 additions and 135 deletions

View File

@ -30,4 +30,8 @@ public interface Prompt {
String PARAM_REQUIRED = "Param Is Required!"; String PARAM_REQUIRED = "Param Is Required!";
String PARAM_NOT_EMPTY = "Param Cat Not Be Empty!"; String PARAM_NOT_EMPTY = "Param Cat Not Be Empty!";
String EXEC_SUCC = "Task executed successfully!";
String EXEC_Faild = "Task executed Faild!";
} }

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.base.dto;
import lombok.Data; import lombok.Data;
import org.jeecg.modules.base.entity.monitor.Item; import org.jeecg.modules.base.entity.monitor.Item;
import org.jeecg.modules.base.entity.postgre.AlarmItem;
import java.io.Serializable; import java.io.Serializable;
@ -14,9 +15,9 @@ public class ItemDto implements Serializable{
private String units; private String units;
public ItemDto(Item item) { public ItemDto(AlarmItem alarmItem) {
this.itemId = item.getItemId(); this.itemId = alarmItem.getId();
this.name = item.getName(); this.name = alarmItem.getName();
this.units = item.getUnits(); this.units = alarmItem.getUnits();
} }
} }

View File

@ -20,8 +20,8 @@ public class AlarmAnalysisNuclideParamController extends JeecgController<AlarmAn
@GetMapping("refresh") @GetMapping("refresh")
@ApiOperation(value = "定时刷新核素计算参数信息",notes = "定时刷新核素计算参数信息") @ApiOperation(value = "定时刷新核素计算参数信息",notes = "定时刷新核素计算参数信息")
public void refreshParam(){ public boolean refreshParam(){
service.refresh(); return service.refresh();
} }
@GetMapping("findInfo") @GetMapping("findInfo")

View File

@ -1,20 +1,25 @@
package org.jeecg.modules.controller; package org.jeecg.modules.controller;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.base.entity.postgre.AlarmItem; import org.jeecg.modules.base.entity.postgre.AlarmItem;
import org.jeecg.modules.service.IAlarmItemService; import org.jeecg.modules.service.IAlarmItemService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@Api(value = "监控项管理",tags = "监控项管理") @Api(value = "监控项管理",tags = "监控项管理")
@RestController @RestController
@RequestMapping("/alarmitem") @RequestMapping("alarmItem")
public class AlarmItemController extends JeecgController<AlarmItem, IAlarmItemService> { public class AlarmItemController extends JeecgController<AlarmItem, IAlarmItemService> {
@Autowired @GetMapping("syncItem")
private IAlarmItemService alarmItemService; @ApiOperation(value = "同步监控项信息",notes = "同步监控项信息")
public boolean syncItem(@RequestParam String type,
@RequestParam String code){
return service.syncItem(type,code);
}
} }

View File

@ -6,9 +6,11 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.dto.ItemDto; import org.jeecg.modules.base.dto.ItemDto;
import org.jeecg.modules.base.entity.monitor.Host; import org.jeecg.modules.base.entity.monitor.Host;
import org.jeecg.modules.base.entity.monitor.Servers; import org.jeecg.modules.base.entity.monitor.Servers;
import org.jeecg.modules.base.entity.postgre.AlarmItem;
import org.jeecg.modules.base.entity.postgre.AlarmRule; import org.jeecg.modules.base.entity.postgre.AlarmRule;
import org.jeecg.modules.base.vo.AlarmRuleVo; import org.jeecg.modules.base.vo.AlarmRuleVo;
import org.jeecg.modules.feignclient.MonitorAlarm; import org.jeecg.modules.feignclient.MonitorAlarm;
import org.jeecg.modules.service.IAlarmItemService;
import org.jeecg.modules.service.IAlarmRuleService; import org.jeecg.modules.service.IAlarmRuleService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -28,6 +30,9 @@ public class AlarmRuleController {
@Autowired @Autowired
private IAlarmRuleService alarmRuleService; private IAlarmRuleService alarmRuleService;
@Autowired
private IAlarmItemService alarmItemService;
@GetMapping("findPage") @GetMapping("findPage")
@ApiOperation(value = "分页查询报警规则", notes = "分页查询报警规则") @ApiOperation(value = "分页查询报警规则", notes = "分页查询报警规则")
public Result findPage(AlarmRuleVo alarmRuleVo){ public Result findPage(AlarmRuleVo alarmRuleVo){
@ -66,17 +71,9 @@ public class AlarmRuleController {
@GetMapping("getItems") @GetMapping("getItems")
@ApiOperation(value = "根据资源名称获取监控项",notes = "根据资源名称获取监控项") @ApiOperation(value = "根据资源名称获取监控项",notes = "根据资源名称获取监控项")
public Result getItems(@RequestParam String sourceName){ public Result getItems(@RequestParam String sourceId){
Result<Servers> result = monitorAlarm.listBack(sourceName); List<AlarmItem> alarmItems = alarmItemService.alarmItems(sourceId);
List<Host> hosts = result.getResult().getRecords(); List<ItemDto> itemDtos = alarmItems.stream().map(ItemDto::new).collect(Collectors.toList());
List<ItemDto> itemDtos = new ArrayList<>();
for (Host host : hosts) {
boolean equals = host.getCode().equals(sourceName);
if(!equals)continue;
itemDtos = host.getItems().values().stream()
.map(ItemDto::new)
.collect(Collectors.toList());
}
return Result.OK(itemDtos); return Result.OK(itemDtos);
} }

View File

@ -19,8 +19,8 @@ public class CalculateConcController {
@GetMapping("caclAndSave") @GetMapping("caclAndSave")
@ApiOperation(value = "计算并保存核素浓度",notes = "计算并保存核素浓度") @ApiOperation(value = "计算并保存核素浓度",notes = "计算并保存核素浓度")
public void caclAndSave(){ public boolean caclAndSave(){
calculateConcService.calcAndSave(); return calculateConcService.calcAndSave();
} }
} }

View File

@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@Component @Component
@FeignClient(name = "monitorAlarm",url = "http://218.249.158.97:7008/mobile/monitor") @FeignClient(name = "monitorAlarm",url = "http://123.124.245.134:7008/mobile/monitor")
public interface MonitorAlarm { public interface MonitorAlarm {
// --------------------后端专用------------------- // --------------------后端专用-------------------

View File

@ -38,10 +38,10 @@
AND source_id = #{sourceId} AND source_id = #{sourceId}
</if> </if>
</where> </where>
ORDER BY enabled DESC, create_time DESC
<if test="pageFlag == null"> <if test="pageFlag == null">
LIMIT #{pageSize} OFFSET #{pageStart} LIMIT #{pageSize} OFFSET #{pageStart}
</if> </if>
ORDER BY enabled DESC, create_time DESC
</select> </select>
<select id="findInfo" parameterType="String" resultType="org.jeecg.modules.base.dto.AlarmRuleInfo"> <select id="findInfo" parameterType="String" resultType="org.jeecg.modules.base.dto.AlarmRuleInfo">

View File

@ -8,7 +8,7 @@ import java.util.Map;
public interface CalculateConcService { public interface CalculateConcService {
void calcAndSave(); boolean calcAndSave();
Map<String,String> calculate(List<ConcDto> concDtos, BigDecimal index); Map<String,String> calculate(List<ConcDto> concDtos, BigDecimal index);
} }

View File

@ -4,6 +4,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.entity.postgre.AlarmItem; import org.jeecg.modules.base.entity.postgre.AlarmItem;
import java.util.List;
public interface IAlarmItemService extends IService<AlarmItem> { public interface IAlarmItemService extends IService<AlarmItem> {
Result syncItem(String sourceType,String code); boolean syncItem(String sourceType,String code);
List<AlarmItem> alarmItems(String sourceId);
} }

View File

@ -10,6 +10,9 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.time.LocalDate;
import java.time.ZoneId;
@Service @Service
public class AlarmAnalysisNuclideParamServiceImpl extends ServiceImpl<AlarmAnalysisNuclideParamMapper, AlarmAnalysisNuclideParam> implements IAlarmAnalysisNuclideParamService { public class AlarmAnalysisNuclideParamServiceImpl extends ServiceImpl<AlarmAnalysisNuclideParamMapper, AlarmAnalysisNuclideParam> implements IAlarmAnalysisNuclideParamService {
@ -22,11 +25,22 @@ public class AlarmAnalysisNuclideParamServiceImpl extends ServiceImpl<AlarmAnaly
@Override @Override
public boolean refresh() { public boolean refresh() {
try {
AlarmAnalysisNuclideParam nuclideParam = new AlarmAnalysisNuclideParam(); AlarmAnalysisNuclideParam nuclideParam = new AlarmAnalysisNuclideParam();
AlarmAnalysisNuclideParam latest = getLatest();
LocalDate localDate = latest.getCreateTime().toInstant()
.atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate today = LocalDate.now();
boolean isToday = today.equals(localDate);
if (isToday) return true;
CopyOptions options = CopyOptions.create() CopyOptions options = CopyOptions.create()
.setIgnoreProperties("id","createTime"); .setIgnoreProperties("id","createTime");
BeanUtil.copyProperties(getLatest(),nuclideParam,options); BeanUtil.copyProperties(latest,nuclideParam,options);
return save(nuclideParam); return save(nuclideParam);
}catch (Throwable e){
e.printStackTrace();
return false;
}
} }
@Override @Override

View File

@ -1,8 +1,10 @@
package org.jeecg.modules.service.impl; package org.jeecg.modules.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.Prompt; import org.jeecg.common.constant.Prompt;
@ -17,6 +19,7 @@ import org.jeecg.modules.service.ISysDatabaseService;
import org.jeecg.modules.service.ISysServerService; import org.jeecg.modules.service.ISysServerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -38,17 +41,18 @@ public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem
private ISysDatabaseService databaseService; private ISysDatabaseService databaseService;
@Override @Override
public Result syncItem(String type,String code) { public boolean syncItem(String type,String code) {
try {
String sourceId = null; String sourceId = null;
if (SERVER.getType().equals(type)){ if (SERVER.getType().equals(type)){
sourceId = serverService.getByName(code); sourceId = serverService.getByName(code);
} else if (DATABASE.getType().equals(type)) { } else if (DATABASE.getType().equals(type)) {
}else { }else {
return Result.error("Soucrce Type Not Extis!"); return false;
} }
if (StrUtil.isBlank(sourceId)) if (StrUtil.isBlank(sourceId))
return Result.error(Prompt.DATA_NOT_EXITS); return false;
Result<Servers> result = monitorAlarm.listBack(code); Result<Servers> result = monitorAlarm.listBack(code);
List<Host> hosts = result.getResult().getRecords(); List<Host> hosts = result.getResult().getRecords();
@ -59,20 +63,28 @@ public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem
items = ListUtil.toList(host.getItems().values()); items = ListUtil.toList(host.getItems().values());
} }
if (CollUtil.isEmpty(items)) if (CollUtil.isEmpty(items))
return Result.error(Prompt.DATA_IS_EMPTY); return false;
List<AlarmItem> alarmItems = new ArrayList<>(); List<AlarmItem> alarmItems = new ArrayList<>();
for (Item item : items) { for (Item item : items) {
AlarmItem alarmItem = new AlarmItem(); AlarmItem alarmItem = BeanUtil.copyProperties(item, AlarmItem.class);
alarmItem.setId(item.getItemId()); alarmItem.setId(item.getItemId());
alarmItem.setName(item.getName());
alarmItem.setUnits(item.getUnits());
alarmItem.setSourceId(sourceId); alarmItem.setSourceId(sourceId);
alarmItem.setDescription(item.getDescription());
alarmItems.add(alarmItem); alarmItems.add(alarmItem);
} }
if(saveOrUpdateBatch(alarmItems)) return saveOrUpdateBatch(alarmItems);
return Result.OK(Prompt.UPDATE_SUCC); }catch (Exception e){
return Result.error(Prompt.UPDATE_ERR); e.printStackTrace();
return false;
}
}
@Override
public List<AlarmItem> alarmItems(String sourceId) {
if (StrUtil.isBlank(sourceId))
return ListUtil.empty();
LambdaQueryWrapper<AlarmItem> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AlarmItem::getSourceId,sourceId);
return list(wrapper);
} }
} }

View File

@ -46,7 +46,8 @@ public class CalculateConcServiceImpl implements CalculateConcService {
private IAlarmAnalysisNuclideParamService nuclideParamService; private IAlarmAnalysisNuclideParamService nuclideParamService;
@Override @Override
public void calcAndSave() { public boolean calcAndSave() {
try {
String comma = SymbolConstant.COMMA; String comma = SymbolConstant.COMMA;
List<AlarmAnalysisRule> analysisRules = analysisRuleService.allAnalysisRule(); List<AlarmAnalysisRule> analysisRules = analysisRuleService.allAnalysisRule();
Set<String> nuclideNames = analysisRules.stream() Set<String> nuclideNames = analysisRules.stream()
@ -93,7 +94,11 @@ public class CalculateConcServiceImpl implements CalculateConcService {
manAvgs.addAll(autoAvgs); manAvgs.addAll(autoAvgs);
String cycle = startDate + SymbolConstant.WELL_NUMBER + endDate; String cycle = startDate + SymbolConstant.WELL_NUMBER + endDate;
manAvgs.forEach(item -> item.setCycle(cycle).setCaclDate(dayAgo)); manAvgs.forEach(item -> item.setCycle(cycle).setCaclDate(dayAgo));
nuclideAvgService.saveBatch(manAvgs); return nuclideAvgService.saveBatch(manAvgs);
}catch (Throwable e){
e.printStackTrace();
return false;
}
} }
@Override @Override

View File

@ -31,9 +31,14 @@ public interface AbnormalAlarmClient {
/* CalculateConcController下相关接口 */ /* CalculateConcController下相关接口 */
@GetMapping("/calculateConc/caclAndSave") @GetMapping("/calculateConc/caclAndSave")
void calculateConc(); boolean calculateConc();
/* AlarmAnalysisNuclideParamController下相关接口 */ /* AlarmAnalysisNuclideParamController下相关接口 */
@GetMapping("/nuclideParam/refresh") @GetMapping("/nuclideParam/refresh")
void refreshParam(); boolean refreshParam();
/* AlarmItemController下相关接口 */
@GetMapping("/alarmItem/syncItem")
boolean syncItem(@RequestParam String type,
@RequestParam String code);
} }

View File

@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.system.vo.LoginUser;
@ -272,19 +273,17 @@ public class QuartzJobController {
//@RequiresRoles("admin") //@RequiresRoles("admin")
//@RequiresPermissions("system:quartzJob:execute") //@RequiresPermissions("system:quartzJob:execute")
@GetMapping("/execute") @GetMapping("/execute")
public Result<?> execute(@RequestParam(name = "id", required = true) String id) { public Result<?> execute(@RequestParam("id") String id) {
QuartzJob quartzJob = quartzJobService.getById(id); QuartzJob quartzJob = quartzJobService.getById(id);
if (quartzJob == null) { if (quartzJob == null) {
return Result.error("未找到对应实体"); return Result.error("The specified task entity class was not found");
} }
try { try {
quartzJobService.execute(quartzJob); return quartzJobService.execute(quartzJob);
} catch (Exception e) { } catch (Exception e) {
//e.printStackTrace(); e.printStackTrace();
log.info("定时任务 立即执行失败>>"+e.getMessage()); return Result.error(Prompt.EXEC_Faild);
return Result.error("执行失败!");
} }
return Result.ok("执行成功!");
} }
} }

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.quartz.job; package org.jeecg.modules.quartz.job;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.util.SpringContextUtils; import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.feignclient.AbnormalAlarmClient; import org.jeecg.modules.feignclient.AbnormalAlarmClient;
@ -15,17 +16,27 @@ import static org.jeecg.common.util.TokenUtils.getTempToken;
/** /**
* 定时更新核素浓度计算参数 * 定时更新核素浓度计算参数
*/ */
@Slf4j
@DisallowConcurrentExecution @DisallowConcurrentExecution
@PersistJobDataAfterExecution @PersistJobDataAfterExecution
public class NuclideParamJob implements Job { public class NuclideParamJob implements Job {
private AbnormalAlarmClient alarmClient; private AbnormalAlarmClient alarmClient;
private boolean success = true;
@Override @Override
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init(); init();
alarmClient.refreshParam(); success = alarmClient.refreshParam();
}catch (Exception e){
e.printStackTrace();
success = false;
}finally {
destroy(); destroy();
context.getJobDetail().getJobDataMap().put("success",success);
}
} }
private void init(){ private void init(){

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.quartz.job; package org.jeecg.modules.quartz.job;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.util.SpringContextUtils; import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.feignclient.AbnormalAlarmClient; import org.jeecg.modules.feignclient.AbnormalAlarmClient;
@ -15,23 +16,34 @@ import static org.jeecg.common.util.TokenUtils.getTempToken;
/** /**
* 定时计算核素浓度均值 * 定时计算核素浓度均值
*/ */
@Slf4j
@DisallowConcurrentExecution @DisallowConcurrentExecution
@PersistJobDataAfterExecution @PersistJobDataAfterExecution
public class NucliedAvgJob implements Job { public class NucliedAvgJob implements Job {
private AbnormalAlarmClient alarmClient; private AbnormalAlarmClient alarmClient;
private boolean success = true;
@Override @Override
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init(); init();
alarmClient.calculateConc(); success = alarmClient.calculateConc();
}catch (Exception e){
e.printStackTrace();
success = false;
}finally {
destroy(); destroy();
context.getJobDetail().getJobDataMap().put("success",success);
}
} }
private void init(){ private void init(){
// start:生成临时Token到线程中 // start:生成临时Token到线程中
UserTokenContext.setToken(getTempToken()); UserTokenContext.setToken(getTempToken());
alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
throw new RuntimeException("test");
} }
private void destroy(){ private void destroy(){

View File

@ -0,0 +1,53 @@
package org.jeecg.modules.quartz.job;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.base.enums.SourceType;
import org.jeecg.modules.feignclient.AbnormalAlarmClient;
import org.quartz.*;
import static org.jeecg.common.util.TokenUtils.getTempToken;
/**
* 此处的同步是指:当定时任务的执行时间大于任务的时间
* 间隔时会等待第一个任务执行完成才会走第二个任务
*/
/**
* 监控项信息更新保存
*/
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class SyncItemJob implements Job {
private AbnormalAlarmClient alarmClient;
private boolean success = true;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
init();
success = alarmClient.syncItem(SourceType.SERVER.getType(), "172.21.60.231");
}catch (Exception e){
e.printStackTrace();
success = false;
}finally {
destroy();
context.getJobDetail().getJobDataMap().put("success",success);
}
}
private void init(){
// start:生成临时Token到线程中
UserTokenContext.setToken(getTempToken());
alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class);
}
private void destroy(){
// end:删除临时Token
UserTokenContext.remove();
}
}

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.quartz.service; package org.jeecg.modules.quartz.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.quartz.entity.QuartzJob; import org.jeecg.modules.quartz.entity.QuartzJob;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;
@ -55,7 +56,7 @@ public interface IQuartzJobService extends IService<QuartzJob> {
* @param quartzJob * @param quartzJob
* @throws Exception * @throws Exception
*/ */
void execute(QuartzJob quartzJob) throws Exception; Result<?> execute(QuartzJob quartzJob) throws Exception;
/** /**
* 暂停任务 * 暂停任务

View File

@ -1,8 +1,12 @@
package org.jeecg.modules.quartz.service.impl; package org.jeecg.modules.quartz.service.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.quartz.entity.QuartzJob; import org.jeecg.modules.quartz.entity.QuartzJob;
@ -102,7 +106,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
} }
@Override @Override
public void execute(QuartzJob quartzJob) throws Exception { public Result<?> execute(QuartzJob quartzJob) throws Exception {
String jobName = quartzJob.getJobClassName().trim(); String jobName = quartzJob.getJobClassName().trim();
Date startDate = new Date(); Date startDate = new Date();
String ymd = DateUtils.date2Str(startDate,DateUtils.yyyymmddhhmmss.get()); String ymd = DateUtils.date2Str(startDate,DateUtils.yyyymmddhhmmss.get());
@ -117,11 +121,21 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
.startAt(startDate) .startAt(startDate)
.build(); .build();
// 构建job信息 // 构建job信息
JobDetail jobDetail = JobBuilder.newJob(getClass(jobName).getClass()).withIdentity(identity).usingJobData("parameter", quartzJob.getParameter()).build(); JobDetail jobDetail = JobBuilder.newJob(getClass(jobName).getClass())
.withIdentity(identity)
.storeDurably()
.usingJobData("parameter", quartzJob.getParameter())
.build();
// 将trigger和 jobDetail 加入这个调度 // 将trigger和 jobDetail 加入这个调度
scheduler.scheduleJob(jobDetail, trigger); scheduler.scheduleJob(jobDetail, trigger);
// 启动scheduler // 启动scheduler
scheduler.start(); scheduler.start();
// 获取 JobDetail 对象
JobDetail detail = scheduler.getJobDetail(new JobKey(identity));
if (ObjectUtil.isNull(detail))
return Result.OK(Prompt.EXEC_SUCC);
boolean success = detail.getJobDataMap().getBoolean("success");
return success ? Result.OK(Prompt.EXEC_SUCC) : Result.error(Prompt.EXEC_Faild);
} }
@Override @Override

View File

@ -71,7 +71,7 @@ public class GardsSohDataServiceImpl extends ServiceImpl<GardsSohDataMapper, Gar
item.setDetectorName(detectorName); item.setDetectorName(detectorName);
} }
if (Objects.nonNull(item.getStartTime())) { if (Objects.nonNull(item.getStartTime())) {
long endSecond = (item.getStartTime().getTime() / 1000) + Long.valueOf(item.getTime()); long endSecond = (item.getStartTime().getTime() / 1000) + Math.round(item.getTime());
Date endDateTime = new Date(); Date endDateTime = new Date();
endDateTime.setTime(endSecond*1000); endDateTime.setTime(endSecond*1000);
item.setEndTime(endDateTime); item.setEndTime(endDateTime);
@ -162,7 +162,7 @@ public class GardsSohDataServiceImpl extends ServiceImpl<GardsSohDataMapper, Gar
Date startT = sohDatum.getStartTime(); Date startT = sohDatum.getStartTime();
if (ObjectUtil.isNotNull(startT)) { if (ObjectUtil.isNotNull(startT)) {
long stratSecod = startT.getTime() / 1000; long stratSecod = startT.getTime() / 1000;
long endSecond = stratSecod + Long.valueOf(sohDatum.getTime()); long endSecond = stratSecod + Math.round(sohDatum.getTime());
Date endDateTime = new Date(endSecond * 1000); Date endDateTime = new Date(endSecond * 1000);
sohDatum.setEndTime(endDateTime); sohDatum.setEndTime(endDateTime);
} }

View File

@ -20,4 +20,4 @@ spring:
monitor: monitor:
username: wmhr username: wmhr
password: Wmhr.123 password: Wmhr.123
url: http://218.249.158.97:7008/mobile/monitor url: http://123.124.245.134:7008/mobile/monitor