1.修改各个工程端口
2.修改大屏接口
This commit is contained in:
parent
ec59d0ce95
commit
2ffb1df2f4
|
|
@ -13,24 +13,60 @@ public class CoordinateTransformUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Double lonAndLatConversion(String lonOrLatStr) {
|
||||
if(lonOrLatStr.contains("°") && lonOrLatStr.contains("′") && lonOrLatStr.contains("″")){
|
||||
String cleanStr = lonOrLatStr.replaceAll("[NSEW\\s]", "");
|
||||
String[] parts = cleanStr.split("[°′″:\\s]+");
|
||||
String deg = parts[0];
|
||||
String min = parts.length > 1 && !parts[1].isEmpty() ? parts[1] : "0";
|
||||
String sec = parts.length > 2 && !parts[2].isEmpty() ? parts[2] : "0";
|
||||
BigDecimal degBigDecimal = new BigDecimal(deg);
|
||||
BigDecimal minBigDecimal = new BigDecimal(min);
|
||||
BigDecimal secBigDecimal = new BigDecimal(sec);
|
||||
minBigDecimal = minBigDecimal.divide(new BigDecimal("60"), 6, RoundingMode.HALF_UP);
|
||||
secBigDecimal = secBigDecimal.divide(new BigDecimal("3600"), 6, RoundingMode.HALF_UP);
|
||||
return degBigDecimal.doubleValue() + minBigDecimal.doubleValue() + secBigDecimal.doubleValue();
|
||||
}else {
|
||||
if(lonOrLatStr.contains("°") && !lonOrLatStr.contains("′") && !lonOrLatStr.contains("″")){
|
||||
String cleanStr = lonOrLatStr.replaceAll("[NSEW°\\s]", "");
|
||||
return Double.parseDouble(cleanStr);
|
||||
}
|
||||
if (lonOrLatStr == null || lonOrLatStr.isEmpty()) {
|
||||
System.err.println("Warning: Input string is null or empty.");
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
lonOrLatStr = lonOrLatStr.trim();
|
||||
|
||||
try {
|
||||
double value = 0.0;
|
||||
if (lonOrLatStr.contains("°")) {
|
||||
// 1. 提取方向
|
||||
String originalStrForDirection = lonOrLatStr; // 保留原始用于查找方向
|
||||
char direction = ' ';
|
||||
String upperOriginalStr = originalStrForDirection.toUpperCase();
|
||||
for (int i = upperOriginalStr.length() - 1; i >= 0; i--) {
|
||||
char c = upperOriginalStr.charAt(i);
|
||||
if (c == 'N' || c == 'S' || c == 'E' || c == 'W') {
|
||||
direction = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 计算绝对值 (复用原始核心逻辑)
|
||||
String cleanStr = lonOrLatStr.replaceAll("[NSEW\\s]", "");
|
||||
String[] parts = cleanStr.split("[°'\"′″:\\s]+");
|
||||
String degStr = parts.length > 0 && !parts[0].isEmpty() ? parts[0] : "0";
|
||||
String minStr = parts.length > 1 && !parts[1].isEmpty() ? parts[1] : "0";
|
||||
String secStr = parts.length > 2 && !parts[2].isEmpty() ? parts[2] : "0";
|
||||
|
||||
BigDecimal deg = new BigDecimal(degStr);
|
||||
BigDecimal min = new BigDecimal(minStr);
|
||||
BigDecimal sec = new BigDecimal(secStr);
|
||||
|
||||
BigDecimal totalBD = deg
|
||||
.add(min.divide(BigDecimal.valueOf(60), 10, BigDecimal.ROUND_HALF_UP))
|
||||
.add(sec.divide(BigDecimal.valueOf(3600), 10, BigDecimal.ROUND_HALF_UP));
|
||||
value = totalBD.doubleValue();
|
||||
|
||||
// 3. 应用正负号
|
||||
if (direction == 'S' || direction == 'W') {
|
||||
value = -value;
|
||||
}
|
||||
|
||||
} else {
|
||||
value = Double.parseDouble(lonOrLatStr);
|
||||
}
|
||||
return value;
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Error parsing coordinate string: '" + lonOrLatStr + "'. Returning 0.0. Error: " + e.getMessage());
|
||||
return 0.0;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Unexpected error during conversion of: '" + lonOrLatStr + "'. Returning 0.0. Error: " + e.getMessage());
|
||||
return 0.0;
|
||||
}
|
||||
return 0D;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,6 @@ public class MapSituationDisplayController {
|
|||
private final HttpClientHostProperties hostProperties;
|
||||
private final MapSituationDisplayService mapSituationDisplayService;
|
||||
|
||||
@AutoLog(value = "查询全球站点信息")
|
||||
@GetMapping("getGlobalSiteInfo")
|
||||
public Result<?> getGlobalSiteInfo() {
|
||||
return Result.OK(mapSituationDisplayService.getGlobalSiteInfo());
|
||||
}
|
||||
|
||||
@AutoLog(value = "查询IMS台站数据有效率信息")
|
||||
@GetMapping("getDataProvisionEfficiency")
|
||||
public Result<?> getDataProvisionEfficiency() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.jeecg.gis.service;
|
||||
|
||||
import org.jeecg.gis.vo.DataProvisionEfficiencyVO;
|
||||
import org.jeecg.gis.vo.GlobalSiteInfoVO;
|
||||
import org.jeecg.modules.base.entity.configuration.*;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -10,11 +9,6 @@ import java.util.List;
|
|||
*/
|
||||
public interface MapSituationDisplayService {
|
||||
|
||||
/**
|
||||
* 获取全球站点信息包括:台站、核设施、反应堆、后处理厂、加速器核试验厂
|
||||
*/
|
||||
List<GlobalSiteInfoVO> getGlobalSiteInfo();
|
||||
|
||||
/**
|
||||
* 查询核设施站点信息
|
||||
* @return
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.jeecg.gis.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.text.StrSplitter;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
|
@ -11,15 +10,12 @@ import lombok.RequiredArgsConstructor;
|
|||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.gis.enums.GlobalSiteTypeEnum;
|
||||
import org.jeecg.gis.service.MapSituationDisplayService;
|
||||
import org.jeecg.gis.service.StationJsonData;
|
||||
import org.jeecg.gis.vo.DataProvisionEfficiencyVO;
|
||||
import org.jeecg.gis.vo.GlobalSiteInfoVO;
|
||||
import org.jeecg.modules.base.entity.configuration.*;
|
||||
import org.jeecg.modules.base.mapper.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -35,74 +31,96 @@ public class MapSituationDisplayServiceImpl implements MapSituationDisplayServic
|
|||
private final GardsNuclearTestingPlantMapper nuclearTestingPlantMapper;
|
||||
private final GardsAcceleratorMapper acceleratorMapper;
|
||||
|
||||
/**
|
||||
* 获取全球站点信息包括:台站、核设施、反应堆、后处理厂、加速器核试验厂
|
||||
*/
|
||||
@DS("ora")
|
||||
@Override
|
||||
public List<GlobalSiteInfoVO> getGlobalSiteInfo() {
|
||||
List<GlobalSiteInfoVO> list = new ArrayList<>();
|
||||
list.addAll(this.getIMSStations());
|
||||
list.addAll(this.getNuclearfacilitys());
|
||||
list.addAll(this.getNuclearReactors());
|
||||
list.addAll(this.getNuclearFuelFacilities());
|
||||
list.addAll(this.getNuclearTestPlant());
|
||||
list.addAll(this.getAccelerator());
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询核设施站点信息
|
||||
* @return
|
||||
*/
|
||||
@DS("ora")
|
||||
@Override
|
||||
public List<GardsNuclearReactors> getAllNuclearfacility() {
|
||||
return (List<GardsNuclearReactors>) redisUtil.get(CommonConstant.ALL_NUCLEARFACILITY);
|
||||
List<GardsNuclearReactors> nuclearReactors;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_NUCLEARFACILITY)){
|
||||
nuclearReactors = (List<GardsNuclearReactors>) redisUtil.get(CommonConstant.ALL_NUCLEARFACILITY);
|
||||
}else {
|
||||
nuclearReactors = nuclearReactorsMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_NUCLEARFACILITY, nuclearReactors);
|
||||
}
|
||||
return nuclearReactors;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询反应堆站点信息
|
||||
* @return
|
||||
*/
|
||||
@DS("ora")
|
||||
@Override
|
||||
public List<GardsResearchReactors> getAllResearchReactors() {
|
||||
return (List<GardsResearchReactors>) redisUtil.get(CommonConstant.ALL_RESEARCH_REACTORS);
|
||||
List<GardsResearchReactors> researchReactors;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_RESEARCH_REACTORS)){
|
||||
researchReactors = (List<GardsResearchReactors>)redisUtil.get(CommonConstant.ALL_RESEARCH_REACTORS);
|
||||
}else {
|
||||
researchReactors = researchReactorsMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_RESEARCH_REACTORS,researchReactors);
|
||||
}
|
||||
return researchReactors;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询后处理厂站点信息
|
||||
* @return
|
||||
*/
|
||||
@DS("ora")
|
||||
@Override
|
||||
public List<GardsNuclearFuelFacilities> getAllNuclearFuelFacilitiy() {
|
||||
return (List<GardsNuclearFuelFacilities>) redisUtil.get(CommonConstant.ALL_NUCLEAR_FUEL_FACILITIES);
|
||||
List<GardsNuclearFuelFacilities> nuclearFuelFacilities;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_NUCLEAR_FUEL_FACILITIES)){
|
||||
nuclearFuelFacilities = (List<GardsNuclearFuelFacilities>)redisUtil.get(CommonConstant.ALL_NUCLEAR_FUEL_FACILITIES);
|
||||
}else {
|
||||
nuclearFuelFacilities = nuclearFuelFacilitiesMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_NUCLEAR_FUEL_FACILITIES,nuclearFuelFacilities);
|
||||
}
|
||||
return nuclearFuelFacilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询核试验厂站点信息
|
||||
* @return
|
||||
*/
|
||||
@DS("ora")
|
||||
@Override
|
||||
public List<GardsNuclearTestingPlant> getAllNuclearTestPlant() {
|
||||
List<GardsNuclearTestingPlant> list = (List<GardsNuclearTestingPlant>) redisUtil.get(CommonConstant.ALL_NUCLEAR_TEST_PLANT);
|
||||
list.forEach(gardsNuclearTestingPlant -> {
|
||||
List<GardsNuclearTestingPlant> nuclearTestingPlants;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_NUCLEAR_TEST_PLANT)){
|
||||
nuclearTestingPlants = (List<GardsNuclearTestingPlant>)redisUtil.get(CommonConstant.ALL_NUCLEAR_TEST_PLANT);
|
||||
}else {
|
||||
nuclearTestingPlants = nuclearTestingPlantMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_NUCLEAR_TEST_PLANT,nuclearTestingPlants);
|
||||
}
|
||||
nuclearTestingPlants.forEach(gardsNuclearTestingPlant -> {
|
||||
gardsNuclearTestingPlant.setInfo(Strings.EMPTY);
|
||||
});
|
||||
return list;
|
||||
return nuclearTestingPlants;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询加速器站点信息
|
||||
* @return
|
||||
*/
|
||||
@DS("ora")
|
||||
@Override
|
||||
public List<GardsAccelerator> getAllAccelerator() {
|
||||
List<GardsAccelerator> list = (List<GardsAccelerator>) redisUtil.get(CommonConstant.ALL_ACCELERATOR);
|
||||
list.forEach(gardsAccelerator -> {
|
||||
List<GardsAccelerator> accelerators;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_ACCELERATOR)){
|
||||
accelerators = (List<GardsAccelerator>)redisUtil.get(CommonConstant.ALL_ACCELERATOR);
|
||||
}else {
|
||||
accelerators = acceleratorMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_ACCELERATOR,accelerators);
|
||||
}
|
||||
accelerators.forEach(gardsAccelerator -> {
|
||||
gardsAccelerator.setFacilityName(Strings.EMPTY);
|
||||
gardsAccelerator.setWebsite(Strings.EMPTY);
|
||||
});
|
||||
return list;
|
||||
return accelerators;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,9 +128,16 @@ public class MapSituationDisplayServiceImpl implements MapSituationDisplayServic
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
@DS("ora")
|
||||
@Override
|
||||
public List<DataProvisionEfficiencyVO> getDataProvisionEfficiency() {
|
||||
List<GardsStations> stations = (List<GardsStations>)redisUtil.get(CommonConstant.ALL_STATIONS);
|
||||
List<GardsStations> stations;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_STATIONS)){
|
||||
stations = (List<GardsStations>)redisUtil.get(CommonConstant.ALL_STATIONS);;
|
||||
}else {
|
||||
stations = stationsMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_STATIONS,stations);
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(StationJsonData.getJson());
|
||||
if (jsonObject.containsKey("result")) {
|
||||
Object obj = jsonObject.get("result");
|
||||
|
|
@ -132,172 +157,4 @@ public class MapSituationDisplayServiceImpl implements MapSituationDisplayServic
|
|||
}
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取台站
|
||||
* @return
|
||||
*/
|
||||
private List<GlobalSiteInfoVO> getIMSStations(){
|
||||
List<GardsStations> stations;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_STATIONS)){
|
||||
stations = (List<GardsStations>)redisUtil.get(CommonConstant.ALL_STATIONS);
|
||||
}else {
|
||||
stations = stationsMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_STATIONS,stations);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(stations)){
|
||||
List<GlobalSiteInfoVO> list = new ArrayList<>();
|
||||
for(GardsStations station:stations){
|
||||
GlobalSiteInfoVO globalSiteInfo = new GlobalSiteInfoVO();
|
||||
globalSiteInfo.setId(station.getStationId());
|
||||
globalSiteInfo.setName(station.getStationCode());
|
||||
globalSiteInfo.setLon(station.getLon());
|
||||
globalSiteInfo.setLat(station.getLat());
|
||||
globalSiteInfo.setSiteType(GlobalSiteTypeEnum.STATION.getValue());
|
||||
list.add(globalSiteInfo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取核设施
|
||||
* @return
|
||||
*/
|
||||
private List<GlobalSiteInfoVO> getNuclearfacilitys(){
|
||||
List<GardsNuclearReactors> nuclearReactors;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_NUCLEARFACILITY)){
|
||||
nuclearReactors = (List<GardsNuclearReactors>) redisUtil.get(CommonConstant.ALL_NUCLEARFACILITY);
|
||||
}else {
|
||||
nuclearReactors = nuclearReactorsMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_NUCLEARFACILITY, nuclearReactors);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(nuclearReactors)){
|
||||
List<GlobalSiteInfoVO> list = new ArrayList<>();
|
||||
for(GardsNuclearReactors nuclearReactor : nuclearReactors){
|
||||
GlobalSiteInfoVO globalSiteInfo = new GlobalSiteInfoVO();
|
||||
globalSiteInfo.setId(nuclearReactor.getId());
|
||||
globalSiteInfo.setName(nuclearReactor.getUnitName());
|
||||
globalSiteInfo.setLon(nuclearReactor.getLongitude());
|
||||
globalSiteInfo.setLat(nuclearReactor.getLatitude());
|
||||
globalSiteInfo.setSiteType(GlobalSiteTypeEnum.NUCLEAR_FACILITY.getValue());
|
||||
list.add(globalSiteInfo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取反应堆
|
||||
* @return
|
||||
*/
|
||||
private List<GlobalSiteInfoVO> getNuclearReactors(){
|
||||
List<GardsResearchReactors> researchReactors;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_RESEARCH_REACTORS)){
|
||||
researchReactors = (List<GardsResearchReactors>)redisUtil.get(CommonConstant.ALL_RESEARCH_REACTORS);
|
||||
}else {
|
||||
researchReactors = researchReactorsMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_RESEARCH_REACTORS,researchReactors);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(researchReactors)){
|
||||
List<GlobalSiteInfoVO> list = new ArrayList<>();
|
||||
for(GardsResearchReactors nuclearReactor:researchReactors){
|
||||
GlobalSiteInfoVO globalSiteInfo = new GlobalSiteInfoVO();
|
||||
globalSiteInfo.setId(nuclearReactor.getId());
|
||||
globalSiteInfo.setName(nuclearReactor.getFacilityName());
|
||||
globalSiteInfo.setLon(nuclearReactor.getLongitude());
|
||||
globalSiteInfo.setLat(nuclearReactor.getLatitude());
|
||||
globalSiteInfo.setSiteType(GlobalSiteTypeEnum.NUCLEAR_REACTOR.getValue());
|
||||
list.add(globalSiteInfo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后处理厂
|
||||
* @return
|
||||
*/
|
||||
private List<GlobalSiteInfoVO> getNuclearFuelFacilities(){
|
||||
List<GardsNuclearFuelFacilities> nuclearFuelFacilities;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_NUCLEAR_FUEL_FACILITIES)){
|
||||
nuclearFuelFacilities = (List<GardsNuclearFuelFacilities>)redisUtil.get(CommonConstant.ALL_NUCLEAR_FUEL_FACILITIES);
|
||||
}else {
|
||||
nuclearFuelFacilities = nuclearFuelFacilitiesMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_NUCLEAR_FUEL_FACILITIES,nuclearFuelFacilities);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(nuclearFuelFacilities)){
|
||||
List<GlobalSiteInfoVO> list = new ArrayList<>();
|
||||
for(GardsNuclearFuelFacilities nuclearFuelFacilitie:nuclearFuelFacilities){
|
||||
GlobalSiteInfoVO globalSiteInfo = new GlobalSiteInfoVO();
|
||||
globalSiteInfo.setId(nuclearFuelFacilitie.getId());
|
||||
globalSiteInfo.setName(nuclearFuelFacilitie.getFacilityName());
|
||||
globalSiteInfo.setLon(nuclearFuelFacilitie.getLongitude());
|
||||
globalSiteInfo.setLat(nuclearFuelFacilitie.getLatitude());
|
||||
globalSiteInfo.setSiteType(GlobalSiteTypeEnum.POST_PROCESSING_PLANT.getValue());
|
||||
list.add(globalSiteInfo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取核试验场
|
||||
* @return
|
||||
*/
|
||||
private List<GlobalSiteInfoVO> getNuclearTestPlant(){
|
||||
List<GardsNuclearTestingPlant> nuclearTestingPlants;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_NUCLEAR_TEST_PLANT)){
|
||||
nuclearTestingPlants = (List<GardsNuclearTestingPlant>)redisUtil.get(CommonConstant.ALL_NUCLEAR_TEST_PLANT);
|
||||
}else {
|
||||
nuclearTestingPlants = nuclearTestingPlantMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_NUCLEAR_TEST_PLANT,nuclearTestingPlants);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(nuclearTestingPlants)){
|
||||
List<GlobalSiteInfoVO> list = new ArrayList<>();
|
||||
for(GardsNuclearTestingPlant nuclearTestingPlant:nuclearTestingPlants){
|
||||
GlobalSiteInfoVO globalSiteInfo = new GlobalSiteInfoVO();
|
||||
globalSiteInfo.setId(nuclearTestingPlant.getId());
|
||||
globalSiteInfo.setName(nuclearTestingPlant.getName());
|
||||
globalSiteInfo.setLon(nuclearTestingPlant.getLongitude());
|
||||
globalSiteInfo.setLat(nuclearTestingPlant.getLatitude());
|
||||
globalSiteInfo.setSiteType(GlobalSiteTypeEnum.NUCLEAR_TESTING_PLANT.getValue());
|
||||
list.add(globalSiteInfo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加速器
|
||||
* @return
|
||||
*/
|
||||
private List<GlobalSiteInfoVO> getAccelerator(){
|
||||
List<GardsAccelerator> accelerators;
|
||||
if(redisUtil.hasKey(CommonConstant.ALL_ACCELERATOR)){
|
||||
accelerators = (List<GardsAccelerator>)redisUtil.get(CommonConstant.ALL_ACCELERATOR);
|
||||
}else {
|
||||
accelerators = acceleratorMapper.selectList(new LambdaQueryWrapper<>());
|
||||
redisUtil.set(CommonConstant.ALL_ACCELERATOR,accelerators);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(accelerators)){
|
||||
List<GlobalSiteInfoVO> list = new ArrayList<>();
|
||||
for(GardsAccelerator accelerator:accelerators){
|
||||
GlobalSiteInfoVO globalSiteInfo = new GlobalSiteInfoVO();
|
||||
globalSiteInfo.setId(accelerator.getId());
|
||||
globalSiteInfo.setName(accelerator.getFacilityName());
|
||||
globalSiteInfo.setLon(accelerator.getLongitude());
|
||||
globalSiteInfo.setLat(accelerator.getLatitude());
|
||||
globalSiteInfo.setSiteType(GlobalSiteTypeEnum.ACCELERATOR.getValue());
|
||||
list.add(globalSiteInfo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -490,8 +490,8 @@ public class HostMonitorServiceImpl implements HostMonitorService {
|
|||
throw new RuntimeException("此ip不在服务器列表中,请检查监控ip列表配置");
|
||||
}
|
||||
Integer port = serverProperties.getInstances().get(ip);
|
||||
return "192.168.186.143"+":"+port;
|
||||
//return ip+":"+port;
|
||||
//return "192.168.186.143"+":"+port;
|
||||
return ip+":"+port;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,300 +0,0 @@
|
|||
package org.jeecg.modules.quartz.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.ImportExcelUtil;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.config.security.utils.SecureUtil;
|
||||
import org.jeecg.modules.quartz.entity.QuartzJob;
|
||||
import org.jeecg.modules.quartz.service.IQuartzJobService;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version:V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/quartzJob")
|
||||
@Slf4j
|
||||
@Tag(name = "定时任务接口")
|
||||
public class QuartzJobController {
|
||||
@Autowired
|
||||
private IQuartzJobService quartzJobService;
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param quartzJob
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public Result<?> queryPageList(QuartzJob quartzJob, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
QueryWrapper<QuartzJob> queryWrapper = QueryGenerator.initQueryWrapper(quartzJob, req.getParameterMap());
|
||||
Page<QuartzJob> page = new Page<QuartzJob>(pageNo, pageSize);
|
||||
IPage<QuartzJob> pageList = quartzJobService.page(page, queryWrapper);
|
||||
return Result.ok(pageList);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加定时任务
|
||||
*
|
||||
* @param quartzJob
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PreAuthorize("@jps.requiresPermissions('system:quartzJob:add')")
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public Result<?> add(@RequestBody QuartzJob quartzJob) {
|
||||
quartzJobService.saveAndScheduleJob(quartzJob);
|
||||
return Result.ok("创建定时任务成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新定时任务
|
||||
*
|
||||
* @param quartzJob
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PreAuthorize("@jps.requiresPermissions('system:quartzJob:edit')")
|
||||
@RequestMapping(value = "/edit", method ={RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<?> eidt(@RequestBody QuartzJob quartzJob) {
|
||||
try {
|
||||
quartzJobService.editAndScheduleJob(quartzJob);
|
||||
} catch (SchedulerException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("更新定时任务失败!");
|
||||
}
|
||||
return Result.ok("更新定时任务成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PreAuthorize("@jps.requiresPermissions('system:quartzJob:delete')")
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
||||
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||
if (quartzJob == null) {
|
||||
return Result.error("未找到对应实体");
|
||||
}
|
||||
quartzJobService.deleteAndStopJob(quartzJob);
|
||||
return Result.ok("删除成功!");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PreAuthorize("@jps.requiresPermissions('system:quartzJob:deleteBatch')")
|
||||
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
|
||||
public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
return Result.error("参数不识别!");
|
||||
}
|
||||
for (String id : Arrays.asList(ids.split(SymbolConstant.COMMA))) {
|
||||
QuartzJob job = quartzJobService.getById(id);
|
||||
quartzJobService.deleteAndStopJob(job);
|
||||
}
|
||||
return Result.ok("删除定时任务成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停定时任务
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PreAuthorize("@jps.requiresPermissions('system:quartzJob:pause')")
|
||||
@GetMapping(value = "/pause")
|
||||
@Operation(summary = "停止定时任务")
|
||||
public Result<Object> pauseJob(@RequestParam(name = "id") String id) {
|
||||
QuartzJob job = quartzJobService.getById(id);
|
||||
if (job == null) {
|
||||
return Result.error("定时任务不存在!");
|
||||
}
|
||||
quartzJobService.pause(job);
|
||||
return Result.ok("停止定时任务成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动定时任务
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PreAuthorize("@jps.requiresPermissions('system:quartzJob:resume')")
|
||||
@GetMapping(value = "/resume")
|
||||
@Operation(summary = "启动定时任务")
|
||||
public Result<Object> resumeJob(@RequestParam(name = "id") String id) {
|
||||
QuartzJob job = quartzJobService.getById(id);
|
||||
if (job == null) {
|
||||
return Result.error("定时任务不存在!");
|
||||
}
|
||||
quartzJobService.resumeJob(job);
|
||||
//scheduler.resumeJob(JobKey.jobKey(job.getJobClassName().trim()));
|
||||
return Result.ok("启动定时任务成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryById", method = RequestMethod.GET)
|
||||
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||
return Result.ok(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param quartzJob
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, QuartzJob quartzJob) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<QuartzJob> queryWrapper = QueryGenerator.initQueryWrapper(quartzJob, request.getParameterMap());
|
||||
// 过滤选中数据
|
||||
String selections = request.getParameter("selections");
|
||||
if (oConvertUtils.isNotEmpty(selections)) {
|
||||
List<String> selectionList = Arrays.asList(selections.split(","));
|
||||
queryWrapper.in("id",selectionList);
|
||||
}
|
||||
// Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<QuartzJob> pageList = quartzJobService.list(queryWrapper);
|
||||
// 导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "定时任务列表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, QuartzJob.class);
|
||||
//获取当前登录用户
|
||||
//update-begin---author:wangshuai ---date:20211227 for:[JTC-116]导出人写死了------------
|
||||
LoginUser user = SecureUtil.currentUser();
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("定时任务列表数据", "导出人:"+user.getRealname(), "导出信息"));
|
||||
//update-end---author:wangshuai ---date:20211227 for:[JTC-116]导出人写死了------------
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
// 错误信息
|
||||
List<String> errorMessage = new ArrayList<>();
|
||||
int successLines = 0, errorLines = 0;
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue();
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<QuartzJob> listQuartzJobs = ExcelImportUtil.importExcel(file.getInputStream(), QuartzJob.class, params);
|
||||
//add-begin-author:taoyan date:20210909 for:导入定时任务,并不会被启动和调度,需要手动点击启动,才会加入调度任务中 #2986
|
||||
for(QuartzJob job: listQuartzJobs){
|
||||
job.setStatus(CommonConstant.STATUS_DISABLE);
|
||||
}
|
||||
List<String> list = ImportExcelUtil.importDateSave(listQuartzJobs, IQuartzJobService.class, errorMessage,CommonConstant.SQL_INDEX_UNIQ_JOB_CLASS_NAME);
|
||||
//add-end-author:taoyan date:20210909 for:导入定时任务,并不会被启动和调度,需要手动点击启动,才会加入调度任务中 #2986
|
||||
errorLines+=list.size();
|
||||
successLines+=(listQuartzJobs.size()-errorLines);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即执行
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@RequiresRoles("admin")
|
||||
@PreAuthorize("@jps.requiresPermissions('system:quartzJob:execute')")
|
||||
@GetMapping("/execute")
|
||||
public Result<?> execute(@RequestParam(name = "id", required = true) String id) {
|
||||
QuartzJob quartzJob = quartzJobService.getById(id);
|
||||
if (quartzJob == null) {
|
||||
return Result.error("未找到对应实体");
|
||||
}
|
||||
try {
|
||||
quartzJobService.execute(quartzJob);
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
log.info("定时任务 立即执行失败>>"+e.getMessage());
|
||||
return Result.error("执行失败!");
|
||||
}
|
||||
return Result.ok("执行成功!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
package org.jeecg.modules.quartz.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_quartz_job")
|
||||
public class QuartzJob implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**id*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private java.lang.String id;
|
||||
/**创建人*/
|
||||
private java.lang.String createBy;
|
||||
/**创建时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date createTime;
|
||||
/**删除状态*/
|
||||
private java.lang.Integer delFlag;
|
||||
/**修改人*/
|
||||
private java.lang.String updateBy;
|
||||
/**修改时间*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private java.util.Date updateTime;
|
||||
/**任务类名*/
|
||||
@Excel(name="任务类名",width=40)
|
||||
private java.lang.String jobClassName;
|
||||
/**cron表达式*/
|
||||
@Excel(name="cron表达式",width=30)
|
||||
private java.lang.String cronExpression;
|
||||
/**参数*/
|
||||
@Excel(name="参数",width=15)
|
||||
private java.lang.String parameter;
|
||||
/**描述*/
|
||||
@Excel(name="描述",width=40)
|
||||
private java.lang.String description;
|
||||
/**状态 0正常 -1停止*/
|
||||
@Excel(name="状态",width=15,dicCode="quartz_status")
|
||||
@Dict(dicCode = "quartz_status")
|
||||
private java.lang.Integer status;
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package org.jeecg.modules.quartz.job;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.quartz.*;
|
||||
|
||||
/**
|
||||
* @Description: 同步定时任务测试
|
||||
*
|
||||
* 此处的同步是指 当定时任务的执行时间大于任务的时间间隔时
|
||||
* 会等待第一个任务执行完成才会走第二个任务
|
||||
*
|
||||
*
|
||||
* @author: taoyan
|
||||
* @date: 2020年06月19日
|
||||
*/
|
||||
@PersistJobDataAfterExecution
|
||||
@DisallowConcurrentExecution
|
||||
@Slf4j
|
||||
public class AsyncJob implements Job {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info(" --- 同步任务调度开始 --- ");
|
||||
try {
|
||||
//此处模拟任务执行时间 5秒 任务表达式配置为每秒执行一次:0/1 * * * * ? *
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//测试发现 每5秒执行一次
|
||||
log.info(" --- 执行完毕,时间:"+DateUtils.now()+"---");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package org.jeecg.modules.quartz.job;
|
||||
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 示例不带参定时任务
|
||||
*
|
||||
* @Author Scott
|
||||
*/
|
||||
@Slf4j
|
||||
public class SampleJob implements Job {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info(" Job Execution key:"+jobExecutionContext.getJobDetail().getKey());
|
||||
log.info(String.format(" Jeecg-Boot 普通定时任务 SampleJob ! 时间:" + DateUtils.getTimestamp()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package org.jeecg.modules.quartz.job;
|
||||
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 示例带参定时任务
|
||||
*
|
||||
* @Author Scott
|
||||
*/
|
||||
@Slf4j
|
||||
public class SampleParamJob implements Job {
|
||||
|
||||
/**
|
||||
* 若参数变量名修改 QuartzJobController中也需对应修改
|
||||
*/
|
||||
private String parameter;
|
||||
|
||||
public void setParameter(String parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info(" Job Execution key:"+jobExecutionContext.getJobDetail().getKey());
|
||||
log.info( String.format("welcome %s! Jeecg-Boot 带参数定时任务 SampleParamJob ! 时间:" + DateUtils.now(), this.parameter));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package org.jeecg.modules.quartz.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.quartz.entity.QuartzJob;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2019-01-02
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface QuartzJobMapper extends BaseMapper<QuartzJob> {
|
||||
|
||||
/**
|
||||
* 根据jobClassName查询
|
||||
* @param jobClassName 任务类名
|
||||
* @return
|
||||
*/
|
||||
public List<QuartzJob> findByJobClassName(@Param("jobClassName") String jobClassName);
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.quartz.mapper.QuartzJobMapper">
|
||||
|
||||
<!-- 根据jobClassName查询 -->
|
||||
<select id="findByJobClassName" resultType="org.jeecg.modules.quartz.entity.QuartzJob">
|
||||
select * from sys_quartz_job where job_class_name = #{jobClassName}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
package org.jeecg.modules.quartz.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jeecg.modules.quartz.entity.QuartzJob;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2019-04-28
|
||||
* @Version: V1.1
|
||||
*/
|
||||
public interface IQuartzJobService extends IService<QuartzJob> {
|
||||
|
||||
/**
|
||||
* 通过类名寻找定时任务
|
||||
* @param jobClassName 类名
|
||||
* @return List<QuartzJob>
|
||||
*/
|
||||
List<QuartzJob> findByJobClassName(String jobClassName);
|
||||
|
||||
/**
|
||||
* 保存定时任务
|
||||
* @param quartzJob
|
||||
* @return boolean
|
||||
*/
|
||||
boolean saveAndScheduleJob(QuartzJob quartzJob);
|
||||
|
||||
/**
|
||||
* 编辑定时任务
|
||||
* @param quartzJob
|
||||
* @return boolean
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
boolean editAndScheduleJob(QuartzJob quartzJob) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
* @param quartzJob
|
||||
* @return boolean
|
||||
*/
|
||||
boolean deleteAndStopJob(QuartzJob quartzJob);
|
||||
|
||||
/**
|
||||
* 恢复定时任务
|
||||
* @param quartzJob
|
||||
* @return
|
||||
*/
|
||||
boolean resumeJob(QuartzJob quartzJob);
|
||||
|
||||
/**
|
||||
* 执行定时任务
|
||||
* @param quartzJob
|
||||
* @throws Exception
|
||||
*/
|
||||
void execute(QuartzJob quartzJob) throws Exception;
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
* @param quartzJob
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
void pause(QuartzJob quartzJob);
|
||||
}
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
package org.jeecg.modules.quartz.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.exception.JeecgBootException;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.modules.quartz.entity.QuartzJob;
|
||||
import org.jeecg.modules.quartz.mapper.QuartzJobMapper;
|
||||
import org.jeecg.modules.quartz.service.IQuartzJobService;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 定时任务在线管理
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2019-04-28
|
||||
* @Version: V1.1
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob> implements IQuartzJobService {
|
||||
@Autowired
|
||||
private QuartzJobMapper quartzJobMapper;
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* 立即执行的任务分组
|
||||
*/
|
||||
private static final String JOB_TEST_GROUP = "test_group";
|
||||
|
||||
@Override
|
||||
public List<QuartzJob> findByJobClassName(String jobClassName) {
|
||||
return quartzJobMapper.findByJobClassName(jobClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存&启动定时任务
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeecgBootException.class)
|
||||
public boolean saveAndScheduleJob(QuartzJob quartzJob) {
|
||||
// DB设置修改
|
||||
quartzJob.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||
boolean success = this.save(quartzJob);
|
||||
if (success) {
|
||||
if (CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
||||
// 定时器添加
|
||||
this.schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复定时任务
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeecgBootException.class)
|
||||
public boolean resumeJob(QuartzJob quartzJob) {
|
||||
schedulerDelete(quartzJob.getId());
|
||||
schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||
quartzJob.setStatus(CommonConstant.STATUS_NORMAL);
|
||||
return this.updateById(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑&启停定时任务
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeecgBootException.class)
|
||||
public boolean editAndScheduleJob(QuartzJob quartzJob) throws SchedulerException {
|
||||
if (CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
||||
schedulerDelete(quartzJob.getId());
|
||||
schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||
}else{
|
||||
scheduler.pauseJob(JobKey.jobKey(quartzJob.getId()));
|
||||
}
|
||||
return this.updateById(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除&停止删除定时任务
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeecgBootException.class)
|
||||
public boolean deleteAndStopJob(QuartzJob job) {
|
||||
schedulerDelete(job.getId());
|
||||
boolean ok = this.removeById(job.getId());
|
||||
return ok;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(QuartzJob quartzJob) throws Exception {
|
||||
String jobName = quartzJob.getJobClassName().trim();
|
||||
Date startDate = new Date();
|
||||
String ymd = DateUtils.date2Str(startDate,DateUtils.yyyymmddhhmmss.get());
|
||||
String identity = jobName + ymd;
|
||||
//3秒后执行 只执行一次
|
||||
// update-begin--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
||||
startDate.setTime(startDate.getTime() + 100L);
|
||||
// update-end--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
||||
// 定义一个Trigger
|
||||
SimpleTrigger trigger = (SimpleTrigger)TriggerBuilder.newTrigger()
|
||||
.withIdentity(identity, JOB_TEST_GROUP)
|
||||
.startAt(startDate)
|
||||
.build();
|
||||
// 构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(getClass(jobName).getClass()).withIdentity(identity).usingJobData("parameter", quartzJob.getParameter()).build();
|
||||
// 将trigger和 jobDetail 加入这个调度
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
// 启动scheduler
|
||||
scheduler.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = JeecgBootException.class)
|
||||
public void pause(QuartzJob quartzJob){
|
||||
schedulerDelete(quartzJob.getId());
|
||||
quartzJob.setStatus(CommonConstant.STATUS_DISABLE);
|
||||
this.updateById(quartzJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加定时任务
|
||||
*
|
||||
* @param jobClassName
|
||||
* @param cronExpression
|
||||
* @param parameter
|
||||
*/
|
||||
private void schedulerAdd(String id, String jobClassName, String cronExpression, String parameter) {
|
||||
try {
|
||||
// 启动调度器
|
||||
scheduler.start();
|
||||
|
||||
// 构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(getClass(jobClassName).getClass()).withIdentity(id).usingJobData("parameter", parameter).build();
|
||||
|
||||
// 表达式调度构建器(即任务执行的时间)
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
|
||||
|
||||
// 按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(id).withSchedule(scheduleBuilder).build();
|
||||
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
} catch (SchedulerException e) {
|
||||
throw new JeecgBootException("创建定时任务失败", e);
|
||||
} catch (RuntimeException e) {
|
||||
throw new JeecgBootException(e.getMessage(), e);
|
||||
}catch (Exception e) {
|
||||
throw new JeecgBootException("后台找不到该类名:" + jobClassName, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private void schedulerDelete(String id) {
|
||||
try {
|
||||
scheduler.pauseTrigger(TriggerKey.triggerKey(id));
|
||||
scheduler.unscheduleJob(TriggerKey.triggerKey(id));
|
||||
scheduler.deleteJob(JobKey.jobKey(id));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new JeecgBootException("删除定时任务失败");
|
||||
}
|
||||
}
|
||||
|
||||
private static Job getClass(String classname) throws Exception {
|
||||
Class<?> class1 = Class.forName(classname);
|
||||
return (Job) class1.newInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 9002
|
||||
port: 8006
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 8008
|
||||
port: 8009
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 8007
|
||||
port: 8008
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 8002
|
||||
port: 8004
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 8001
|
||||
port: 8000
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 8006
|
||||
port: 8001
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user