@@ -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 ;
}
}
}