Merge branch 'main' of https://git.jsspisoft.com/ry-das
This commit is contained in:
commit
a142567520
@ -5,6 +5,7 @@ import com.das.common.result.R;
|
||||
import com.das.modules.calc.domain.vo.CalcModuleVo;
|
||||
import com.das.modules.calc.service.CalcService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -54,6 +55,57 @@ public class CalcController {
|
||||
log.error("注册计算模块失败", ex);
|
||||
return R.fail(String.format("计算模块注册失败, %s",ex.getMessage()));
|
||||
}
|
||||
return R.success();
|
||||
return R.success("注册成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除计算模块
|
||||
* @param moduleName 计算模块名称
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/module/remove")
|
||||
public R<?> removeCalcModule(String moduleName) throws IOException {
|
||||
try {
|
||||
calcService.removeCalcModule(moduleName);
|
||||
}
|
||||
catch (Exception ex){
|
||||
log.error("删除计算模块失败", ex);
|
||||
return R.fail(String.format("删除计算模块失败, %s",ex.getMessage()));
|
||||
}
|
||||
return R.success("删除成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 激活计算模块
|
||||
* @param moduleName
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/module/active")
|
||||
public R<?> activeCalcModule(String moduleName){
|
||||
try {
|
||||
calcService.activeCalcModule(moduleName);
|
||||
} catch (Exception e) {
|
||||
log.error("激活计算模块失败", e);
|
||||
return R.fail(String.format("激活计算模块失败, %s",e.getMessage()));
|
||||
}
|
||||
return R.success("激活成功");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/module/deactive")
|
||||
public R<?> deActiveCalcModule(String moduleName){
|
||||
try {
|
||||
calcService.deActiveCalcModule(moduleName);
|
||||
} catch (Exception e) {
|
||||
log.error("禁用计算模块失败", e);
|
||||
return R.fail(String.format("禁用计算模块失败, %s",e.getMessage()));
|
||||
}
|
||||
return R.success("禁用成功");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@ -66,6 +67,9 @@ public class CalcService {
|
||||
dataMap.put("aviator", aviator);
|
||||
dataMap.put("cache", cacheService);
|
||||
JobKey jobKey = JobKey.jobKey(scriptModule.getName(), "CalcEngine");
|
||||
if (sh.checkExists(jobKey)){
|
||||
throw new SchedulerException("计算模块已启动,请先停止该模块");
|
||||
}
|
||||
JobDetail jobDetail = JobBuilder
|
||||
.newJob(CalcJob.class)
|
||||
.setJobData(dataMap)
|
||||
@ -80,15 +84,20 @@ public class CalcService {
|
||||
|
||||
/**
|
||||
* 停止计算任务
|
||||
* @param scriptModule
|
||||
* @param name
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
public void stopCalcJob(CalcModule scriptModule) throws SchedulerException {
|
||||
public void stopCalcJob(String name) throws SchedulerException {
|
||||
Scheduler sh = quartzScheduler.getScheduler();
|
||||
JobKey jobKey = JobKey.jobKey(scriptModule.getName(), "CalcEngine");
|
||||
sh.deleteJob(jobKey);
|
||||
JobKey jobKey = JobKey.jobKey(name, "CalcEngine");
|
||||
if (sh.checkExists(jobKey)){
|
||||
sh.deleteJob(jobKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为计算引擎新增扩展函数
|
||||
*/
|
||||
public void addExtendFunctions(){
|
||||
//获取设备实时数据 - rt( code, attrs )
|
||||
FunctionRealData rt = new FunctionRealData( dataService, cacheService);
|
||||
@ -132,19 +141,76 @@ public class CalcService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询计算模块列表
|
||||
* @return
|
||||
*/
|
||||
public List<CalcModuleVo> queryCalcModules() {
|
||||
List<CalcModule> scriptModules = calcModuleMapper.selectList(null);
|
||||
|
||||
return scriptModules.stream().map(CalcModuleVo::of).toList();
|
||||
}
|
||||
|
||||
public void registerCalcModule(String content) {
|
||||
/**
|
||||
* 注册或者更新计算模块
|
||||
* @param content 计算模块脚本文件内容
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
public void registerCalcModule(String content) throws SchedulerException {
|
||||
CalcModule module = CalcModule.of(content);
|
||||
CalcModule scriptModules = calcModuleMapper.selectById(module.getName());
|
||||
if (scriptModules == null){
|
||||
calcModuleMapper.insert(module);
|
||||
} else {
|
||||
calcModuleMapper.updateById(module);
|
||||
scriptModules.setScript(module.getScript());
|
||||
scriptModules.setCron(module.getCron());
|
||||
scriptModules.setLocalName(module.getLocalName());
|
||||
scriptModules.setDescription(module.getDescription());
|
||||
calcModuleMapper.updateById(scriptModules);
|
||||
//重新启动任务
|
||||
stopCalcJob(scriptModules.getName());
|
||||
startCalcJob(scriptModules);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除并停止正在运行的计算模块
|
||||
* @param moduleName 计算模块名称
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeCalcModule(String moduleName) throws SchedulerException {
|
||||
calcModuleMapper.deleteById(moduleName);
|
||||
stopCalcJob(moduleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活计算模块
|
||||
* @param moduleName 计算模块名称
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void activeCalcModule(String moduleName) throws SchedulerException {
|
||||
CalcModule calcModule = calcModuleMapper.selectById(moduleName);
|
||||
if (calcModule != null) {
|
||||
calcModule.setDisabled(0);
|
||||
calcModuleMapper.updateById(calcModule);
|
||||
startCalcJob(calcModule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用计算模块
|
||||
* @param moduleName 计算模块名称
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deActiveCalcModule(String moduleName) throws SchedulerException {
|
||||
CalcModule calcModule = calcModuleMapper.selectById(moduleName);
|
||||
if (calcModule != null) {
|
||||
calcModule.setDisabled(1);
|
||||
calcModuleMapper.updateById(calcModule);
|
||||
stopCalcJob(moduleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ const initpowerChart = () => {
|
||||
const option = {
|
||||
grid: {
|
||||
top: 50,
|
||||
right: 23,
|
||||
right: 25,
|
||||
bottom: 10,
|
||||
left: 25,
|
||||
containLabel: true,
|
||||
@ -604,6 +604,7 @@ const initpowerChart = () => {
|
||||
name: '风速m/s',
|
||||
nameTextStyle: {
|
||||
color: '#4E5969',
|
||||
padding: [0, 50, 0, 0],
|
||||
},
|
||||
axisLine: {
|
||||
show: false,
|
||||
|
Loading…
Reference in New Issue
Block a user