用能空调定时关机策略
This commit is contained in:
@@ -2,6 +2,7 @@ package com.njcn.energy.pojo.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.energy.pojo.api.fallback.EleAirStrategyFallbackFactory;
|
||||
import com.njcn.energy.pojo.api.fallback.EleOnlineRateFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -14,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
* @author cdf
|
||||
* @date 2022/4/22
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ENERGY,path = "/air",fallbackFactory = EleOnlineRateFallbackFactory.class)
|
||||
@FeignClient(value = ServerInfo.ENERGY,path = "/air",fallbackFactory = EleAirStrategyFallbackFactory.class)
|
||||
public interface EleAirStrategyFeignClient {
|
||||
|
||||
/**
|
||||
@@ -23,6 +24,6 @@ public interface EleAirStrategyFeignClient {
|
||||
* @date 2022/4/22
|
||||
*/
|
||||
@GetMapping("dealAirStrategyId")
|
||||
HttpResult<Boolean> dealAirStrategyId(@RequestParam("id") String id,@RequestParam("operation") String operation);
|
||||
HttpResult<Boolean> dealAirStrategyId(@RequestParam("operation") String operation);
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class EleAirStrategyFallbackFactory implements FallbackFactory<EleAirStra
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new EleAirStrategyFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Boolean> dealAirStrategyId(String id,String operation) {
|
||||
public HttpResult<Boolean> dealAirStrategyId(String operation) {
|
||||
log.error("{}异常,降级处理,异常为:{}","空调控制策略数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@@ -201,8 +201,8 @@ public class EleAirStrategyController extends BaseController {
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@GetMapping("/dealAirStrategyId")
|
||||
@ApiOperation("根据策略定时开启关闭空调")
|
||||
public void dealAirStrategyId(@RequestParam("id")String id,@RequestParam("operation")String operation) {
|
||||
eleAirStrategyService.dealAirStrategyId(id, operation);
|
||||
public void dealAirStrategyId(@RequestParam("operation")String operation) {
|
||||
eleAirStrategyService.dealAirStrategyId(operation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public interface EleAirStrategyService extends IService<AirStrategy> {
|
||||
* @author cdf
|
||||
* @date 2022/4/22
|
||||
*/
|
||||
void dealAirStrategyId(String id,String operation);
|
||||
void dealAirStrategyId(String operation);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,11 +32,11 @@ import com.njcn.energy.pojo.vo.AirStrategyVO;
|
||||
import com.njcn.energy.service.EleAirStrategyService;
|
||||
import com.njcn.energy.service.IEleSetService;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import com.njcn.job.api.JobFeignClient;
|
||||
import com.njcn.job.model.XxlJobInfo;
|
||||
//import com.njcn.job.api.JobFeignClient;
|
||||
//import com.njcn.job.model.XxlJobInfo;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
//import com.xxl.job.core.biz.model.ReturnT;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
@@ -66,7 +66,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
|
||||
private final IEleSetService iEleSetService;
|
||||
|
||||
private final JobFeignClient jobFeignClient;
|
||||
//private final JobFeignClient jobFeignClient;
|
||||
|
||||
private final LogicDeviceLineMapper logicDeviceLineMapper;
|
||||
|
||||
@@ -158,7 +158,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
String cronOn = "" + startTime.getSecond() + CharUtil.SPACE + startTime.getMinute() + CharUtil.SPACE + startTime.getHour() + CharUtil.SPACE + startTime.getDayOfMonth() + CharUtil.SPACE + startTime.getMonthValue() + CharUtil.SPACE + "?" + CharUtil.SPACE + startTime.getYear();
|
||||
String paramOn = "open" + StrUtil.C_COMMA + airStrategy.getId();
|
||||
|
||||
XxlJobInfo xxlJobInfo = assScheduling("测试定时开空调",cronOn,paramOn);
|
||||
/* XxlJobInfo xxlJobInfo = assScheduling("测试定时开空调",cronOn,paramOn);
|
||||
HttpResult<String> result = jobFeignClient.addJob(xxlJobInfo);
|
||||
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
|
||||
@@ -176,7 +176,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
}
|
||||
|
||||
String ids = result.getData() + StrUtil.COMMA + result2.getData();
|
||||
airStrategy.setXxlId(ids);
|
||||
airStrategy.setXxlId(ids);*/
|
||||
this.updateById(airStrategy);
|
||||
} else if(airStrategyParam.getType() == 1) {
|
||||
|
||||
@@ -194,7 +194,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
* 添加开机调度任务
|
||||
*/
|
||||
//时间表达式需要处理成 秒 分 时 日 月 ? 年,标志指定时间执行一次
|
||||
String startTime = airStrategyOnOff.getStartTime();
|
||||
/* String startTime = airStrategyOnOff.getStartTime();
|
||||
String[] temTime = startTime.split(":");
|
||||
String cron = "0" + CharUtil.SPACE + temTime[1] + CharUtil.SPACE + temTime[0] + CharUtil.SPACE + "* * ?";
|
||||
String param = "close" + StrUtil.C_COMMA + airStrategyOnOff.getId();
|
||||
@@ -203,7 +203,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
|
||||
}
|
||||
airStrategyOnOff.setXxlId(result.getData());
|
||||
airStrategyOnOff.setXxlId(result.getData());*/
|
||||
this.updateById(airStrategyOnOff);
|
||||
} else if(airStrategyParam.getType() == 2) {
|
||||
//开机策略
|
||||
@@ -217,7 +217,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
/*
|
||||
* 添加开机调度任务
|
||||
*/
|
||||
String startTime = airStrategyOnOff.getStartTime();
|
||||
/* String startTime = airStrategyOnOff.getStartTime();
|
||||
String[] temTime = startTime.split(":");
|
||||
String cron = "0" + CharUtil.SPACE + temTime[1] + CharUtil.SPACE + temTime[0] + CharUtil.SPACE + "* * ?";
|
||||
String param = "open" + StrUtil.C_COMMA + airStrategyOnOff.getId();
|
||||
@@ -226,7 +226,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
|
||||
}
|
||||
airStrategyOnOff.setXxlId(result.getData());
|
||||
airStrategyOnOff.setXxlId(result.getData());*/
|
||||
this.updateById(airStrategyOnOff);
|
||||
}
|
||||
|
||||
@@ -248,6 +248,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
}
|
||||
|
||||
/*组装调度任务*/
|
||||
/*
|
||||
private XxlJobInfo assScheduling(String desc,String confTime,String param){
|
||||
XxlJobInfo xxlJobInfo = new XxlJobInfo();
|
||||
//执行器ID,手动指定,此处设置为3,对应xxl_job_group中的executor--测试执行器
|
||||
@@ -268,6 +269,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
xxlJobInfo.setGlueRemark("GLUE代码初始化");
|
||||
return xxlJobInfo;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -293,7 +295,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
});
|
||||
iEleSetService.saveBatch(list);
|
||||
|
||||
|
||||
/*
|
||||
String[] jobIds = airStrategyRes.getXxlId().split(StrUtil.COMMA);
|
||||
if(updateParam.getType() == 0) {
|
||||
//时间表达式需要处理成 秒 分 时 日 月 ? 年,标志指定时间执行一次
|
||||
@@ -341,7 +343,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -366,14 +368,14 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
lambdaQueryWrapper.eq(AirSet::getId, id);
|
||||
iEleSetService.remove(lambdaQueryWrapper);
|
||||
|
||||
String[] arr = airStrategy.getXxlId().split(StrUtil.COMMA);
|
||||
/* String[] arr = airStrategy.getXxlId().split(StrUtil.COMMA);
|
||||
|
||||
for (String xxlId : arr) {
|
||||
HttpResult<String> result = jobFeignClient.removeJob(Integer.parseInt(xxlId));
|
||||
if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_DEL_ERROR);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -389,13 +391,13 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
if (airStrategy.getStatus() != 1) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_NO_RUN);
|
||||
}
|
||||
String[] arr = airStrategy.getXxlId().split(StrUtil.COMMA);
|
||||
/* String[] arr = airStrategy.getXxlId().split(StrUtil.COMMA);
|
||||
for (String xxlId : arr) {
|
||||
HttpResult<String> result = jobFeignClient.stopJob(Integer.parseInt(xxlId));
|
||||
if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_STOP_ERROR);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
this.lambdaUpdate()
|
||||
.set(AirStrategy::getStatus, 4)
|
||||
@@ -430,21 +432,21 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
String[] ids = airStrategy.getXxlId().split(StrUtil.COMMA);
|
||||
if (airStrategy.getStatus() == 0) {
|
||||
//可以启动
|
||||
for (String xxlId : ids) {
|
||||
/* for (String xxlId : ids) {
|
||||
HttpResult<String> result = jobFeignClient.startTask(Integer.parseInt(xxlId));
|
||||
if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_RUNING);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
this.lambdaUpdate().set(AirStrategy::getStatus, 1).eq(AirStrategy::getId, id).update();
|
||||
} else if (airStrategy.getStatus() == 1) {
|
||||
//已经执行中
|
||||
for (String xxlId : ids) {
|
||||
/* for (String xxlId : ids) {
|
||||
HttpResult<String> result = jobFeignClient.stopJob(Integer.parseInt(xxlId));
|
||||
if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) {
|
||||
throw new BusinessException(EnergyResponseEnum.TASK_DEL_ERROR);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
this.lambdaUpdate().set(AirStrategy::getStatus, 0).eq(AirStrategy::getId, id).update();
|
||||
} else {
|
||||
//已经完成
|
||||
@@ -455,16 +457,16 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
|
||||
|
||||
@Override
|
||||
public void dealAirStrategyId(String id, String operation) {
|
||||
public void dealAirStrategyId(String operation) {
|
||||
try {
|
||||
AirStrategy airStrategy = this.getById(id);
|
||||
AirStrategy airStrategy = this.list(new LambdaQueryWrapper<>()).get(0);
|
||||
if (Objects.isNull(airStrategy)) {
|
||||
throw new BusinessException(CommonResponseEnum.FAIL);
|
||||
}
|
||||
|
||||
|
||||
LambdaQueryWrapper<AirSet> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(AirSet::getId, id);
|
||||
lambdaQueryWrapper.eq(AirSet::getId, airStrategy.getId());
|
||||
List<AirSet> list = iEleSetService.list(lambdaQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
List<String> lineIds = list.stream().map(AirSet::getLineId).collect(Collectors.toList());
|
||||
@@ -528,8 +530,6 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
this.mqttSendCount = 0;
|
||||
this.mqttJsonMsg = json;
|
||||
this.mqttSendTopic = topic;
|
||||
flag = true;
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
}
|
||||
@@ -555,7 +555,6 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
this.mqttSendCount = 0;
|
||||
this.mqttJsonMsg = json;
|
||||
this.mqttSendTopic = topic;
|
||||
flag = true;
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
}
|
||||
@@ -578,7 +577,6 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
}
|
||||
|
||||
|
||||
private Boolean flag = false;
|
||||
private Integer mqttSendCount = 0;
|
||||
private String mqttJsonMsg;
|
||||
private String mqttSendTopic;
|
||||
@@ -590,20 +588,14 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
|
||||
String str = jsonObject.getStr("userId");
|
||||
|
||||
if (str.equals(clientId)) {
|
||||
|
||||
if (!jsonObject.getStr("code").equals("200")) {
|
||||
mqttSendCount++;
|
||||
if (mqttSendCount < 3) {
|
||||
System.out.println("进入错误重发++++++");
|
||||
System.out.println("错误重发详情" + mqttJsonMsg);
|
||||
publisher.send(mqttSendTopic, mqttJsonMsg, 1, false);
|
||||
} else {
|
||||
flag = false;
|
||||
}
|
||||
} else {
|
||||
flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.njcn.energy.pojo.vo.LoadStatisticVO;
|
||||
import com.njcn.energy.pojo.vo.LoadTendencyVO;
|
||||
import com.njcn.energy.service.HighAnalyticService;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import com.njcn.job.api.JobFeignClient;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.enums.SystemResponseEnum;
|
||||
@@ -59,7 +58,6 @@ public class HighAnalyticServiceImpl implements HighAnalyticService {
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final JobFeignClient jobFeignClient;
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.njcn.system.timer.tasks.energy;
|
||||
|
||||
|
||||
import com.njcn.energy.pojo.api.EleAirStrategyFeignClient;
|
||||
import com.njcn.system.timer.TimerTaskRunner;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AirControllerRunner implements TimerTaskRunner {
|
||||
|
||||
private final EleAirStrategyFeignClient eleAirStrategyFeignClient;
|
||||
|
||||
@Override
|
||||
public void action(String date) {
|
||||
eleAirStrategyFeignClient.dealAirStrategyId("close");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user