1.用能系统空调关机策略

2.终端模块对外接口
This commit is contained in:
2022-08-04 14:05:45 +08:00
parent 5c288be99b
commit 9a26722f14
16 changed files with 375 additions and 189 deletions

View File

@@ -210,4 +210,14 @@ public interface LineFeignClient {
@PostMapping("getDeviceList") @PostMapping("getDeviceList")
HttpResult<List<String>> getDeviceList(); HttpResult<List<String>> getDeviceList();
/**
* 获取当前状态在线的监测点数量
* @param lineIds 监测点集合
* @return 在线的监测点数量
* @author cdf
* @date 2022/8/1
*/
@PostMapping("getOnLineCount")
HttpResult<Integer> getOnLineCount(@RequestBody List<String> lineIds);
} }

View File

@@ -161,6 +161,12 @@ public class LineFeignClientFallbackFactory implements FallbackFactory<LineFeign
throw new BusinessException(finalExceptionEnum); throw new BusinessException(finalExceptionEnum);
} }
@Override
public HttpResult<Integer> getOnLineCount(List<String> lineIds) {
log.error("{}异常,降级处理,异常为:{}", "或取在线监测点数量异常: ", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
}; };
} }

View File

@@ -54,6 +54,7 @@ public class GeneralDeviceInfoController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true) @ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true)
}) })
@Deprecated
public HttpResult<List<GeneralDeviceDTO>> getPracticalRunDeviceInfoAsDept(@RequestBody @Validated DeviceInfoParam deviceInfoParam) { public HttpResult<List<GeneralDeviceDTO>> getPracticalRunDeviceInfoAsDept(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getPracticalRunDeviceInfoAsDept"); String methodDescribe = getMethodDescribe("getPracticalRunDeviceInfoAsDept");
List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfoAsDept(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList())); List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfoAsDept(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList()));
@@ -73,6 +74,7 @@ public class GeneralDeviceInfoController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true) @ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true)
}) })
@Deprecated
public HttpResult<List<GeneralDeviceDTO>> getOfflineRunDeviceInfoAsDept(@RequestBody @Validated DeviceInfoParam deviceInfoParam) { public HttpResult<List<GeneralDeviceDTO>> getOfflineRunDeviceInfoAsDept(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getOfflineRunDeviceInfoAsDept"); String methodDescribe = getMethodDescribe("getOfflineRunDeviceInfoAsDept");
List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfoAsDept(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(2).collect(Collectors.toList())); List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfoAsDept(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(2).collect(Collectors.toList()));
@@ -93,6 +95,7 @@ public class GeneralDeviceInfoController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true) @ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true)
}) })
@Deprecated
public HttpResult<List<GeneralDeviceDTO>> getPracticalAllDeviceInfoAsDept(@RequestBody @Validated DeviceInfoParam deviceInfoParam) { public HttpResult<List<GeneralDeviceDTO>> getPracticalAllDeviceInfoAsDept(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getPracticalAllDeviceInfoAsDept"); String methodDescribe = getMethodDescribe("getPracticalAllDeviceInfoAsDept");
List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfoAsDept(deviceInfoParam, null, Stream.of(1).collect(Collectors.toList())); List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfoAsDept(deviceInfoParam, null, Stream.of(1).collect(Collectors.toList()));
@@ -120,6 +123,7 @@ public class GeneralDeviceInfoController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true) @ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true)
}) })
@Deprecated
public HttpResult<List<GeneralDeviceDTO>> getPracticalRunDeviceInfoAsSubstation(@RequestBody @Validated DeviceInfoParam deviceInfoParam) { public HttpResult<List<GeneralDeviceDTO>> getPracticalRunDeviceInfoAsSubstation(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getPracticalRunDeviceInfoAsSubstation"); String methodDescribe = getMethodDescribe("getPracticalRunDeviceInfoAsSubstation");
List<GeneralDeviceDTO> substationDeviceInfos = generalDeviceService.getDeviceInfoAsSubstation(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList())); List<GeneralDeviceDTO> substationDeviceInfos = generalDeviceService.getDeviceInfoAsSubstation(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList()));
@@ -139,6 +143,7 @@ public class GeneralDeviceInfoController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true) @ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true)
}) })
@Deprecated
public HttpResult<List<GeneralDeviceDTO>> getPracticalRunDeviceInfo(@RequestBody @Validated DeviceInfoParam deviceInfoParam) { public HttpResult<List<GeneralDeviceDTO>> getPracticalRunDeviceInfo(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getPracticalRunDeviceInfo"); String methodDescribe = getMethodDescribe("getPracticalRunDeviceInfo");
List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfo(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList())); List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfo(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList()));
@@ -158,6 +163,7 @@ public class GeneralDeviceInfoController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true) @ApiImplicitParam(name = "deviceInfoParam", value = "查询终端条件", required = true)
}) })
@Deprecated
public HttpResult<List<GeneralDeviceDTO>> getOfflineRunDeviceInfo(@RequestBody @Validated DeviceInfoParam deviceInfoParam) { public HttpResult<List<GeneralDeviceDTO>> getOfflineRunDeviceInfo(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getOfflineRunDeviceInfo"); String methodDescribe = getMethodDescribe("getOfflineRunDeviceInfo");
List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfo(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(2).collect(Collectors.toList())); List<GeneralDeviceDTO> deptDeviceInfos = generalDeviceService.getDeviceInfo(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(2).collect(Collectors.toList()));

View File

@@ -288,4 +288,21 @@ public class LineController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineMapper.getDeviceList(), methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineMapper.getDeviceList(), methodDescribe);
} }
/**
* 获取当前状态在线的监测点数量
* @param lineIds 监测点集合
* @return 在线的监测点数量
* @author cdf
* @date 2022/8/1
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getOnLineCount")
@ApiOperation("获取当前状态在线的监测点数量")
@ApiImplicitParam(name = "lineIds", value = "监测点集合", required = true)
public HttpResult<Integer> getOnLineCount(@RequestBody List<String> lineIds) {
String methodDescribe = getMethodDescribe("getOnLineCount");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineMapper.getOnLineCount(lineIds), methodDescribe);
}
} }

View File

@@ -318,4 +318,10 @@ public interface LineMapper extends BaseMapper<Line> {
* @return 装置Id * @return 装置Id
*/ */
List<String> getDeviceList(); List<String> getDeviceList();
/**
* 获取当前状态在线的监测点数量
* @return 装置Id
*/
Integer getOnLineCount(@Param("lineIds")List<String> lineIds);
} }

View File

@@ -952,4 +952,23 @@ FROM
<select id="getDeviceList" resultType="string"> <select id="getDeviceList" resultType="string">
SELECT Id FROM pq_device WHERE Dev_Model = 1 AND Dev_Data_Type IN (1,2) AND Run_Flag = 0 SELECT Id FROM pq_device WHERE Dev_Model = 1 AND Dev_Data_Type IN (1,2) AND Run_Flag = 0
</select> </select>
<select id="getOnLineCount" resultType="int">
SELECT
count( f.Com_Flag )
FROM
pq_line a
INNER JOIN pq_line_detail b ON a.id = b.id
INNER JOIN pq_line c ON a.pid = c.id
INNER JOIN pq_line d ON c.pid = d.id
INNER JOIN pq_device f ON d.id = f.id
WHERE
a.state = 1
AND f.Com_Flag = 1
AND a.id in
<foreach collection="lineIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
</mapper> </mapper>

View File

@@ -67,7 +67,9 @@ public enum EnergyResponseEnum {
TASK_HAS_START("508","任务已经执行完毕"), TASK_HAS_START("508","任务已经执行完毕"),
TASK_DEL_ERROR("509","定时任务删除失败,请联系管理员"), TASK_DEL_ERROR("509","定时任务删除失败,请联系管理员"),
TASK_RUNING("510","任务正在执行无法操作,请先停止任务"), TASK_RUNING("510","任务正在执行无法操作,请先停止任务"),
TASK_TIME_ERROR("511","两条策略时间差应在5分钟以上") TASK_TIME_ERROR("511","两条策略时间差应在5分钟以上"),
TASK_NO_RUN("512","策略不在执行中"),
TASK_STOP_ERROR("513","策略停止失败,请联系管理员"),
; ;
private final String code; private final String code;

View File

@@ -31,14 +31,16 @@ public class AirStrategyParam{
@NotBlank(message = "名称不可为空") @NotBlank(message = "名称不可为空")
private String name; private String name;
@ApiModelProperty(name = "类型",required = true,value = "0.普通策略 1.关机策略 2.开机策略")
@NotNull(message = "策略类型不能为空")
private Integer type;
@ApiModelProperty(name = "开始时间",required = true) @ApiModelProperty(name = "开始时间",required = true)
@NotBlank(message = "开始时间不可为空") @NotBlank(message = "开始时间不可为空")
@DateTimeStrValid(format = "yyyy-MM-dd HH:mm:ss",message = "开始时间格式有误")
private String startTime; private String startTime;
@ApiModelProperty(name = "开始时间",required = true) @ApiModelProperty(name = "开始时间",required = true)
@NotBlank(message = "开始时间不可为空") @NotBlank(message = "开始时间不可为空")
@DateTimeStrValid(format = "yyyy-MM-dd HH:mm:ss",message = "结束时间格式有误")
private String endTime; private String endTime;
@ApiModelProperty(name = "空调模式",required = true) @ApiModelProperty(name = "空调模式",required = true)
@@ -83,6 +85,7 @@ public class AirStrategyParam{
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public static class AirStrategyQueryParam extends BaseParam { public static class AirStrategyQueryParam extends BaseParam {
private Integer type;
} }

View File

@@ -15,6 +15,7 @@ import lombok.Data;
public class AirStrategy extends BaseEntity { public class AirStrategy extends BaseEntity {
private String id; private String id;
private String name; private String name;
private Integer type;
private String startTime; private String startTime;
private String endTime; private String endTime;
private String mode; private String mode;

View File

@@ -30,6 +30,9 @@ public class AirStrategyVO {
@ApiModelProperty(name = "策略名称",required = true) @ApiModelProperty(name = "策略名称",required = true)
private String name; private String name;
@ApiModelProperty(name = "策略类型",required = true)
private Integer type;
@ApiModelProperty(name = "开始时间",required = true) @ApiModelProperty(name = "开始时间",required = true)
private String startTime; private String startTime;

View File

@@ -109,7 +109,7 @@ public class EleAirStrategyController extends BaseController {
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE) @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
@GetMapping("/delete") @GetMapping("/delete")
@ApiOperation("删除空调策略") @ApiOperation("删除空调策略")
@ApiImplicitParam(name = "id", value = "网关设备索引", required = true) @ApiImplicitParam(name = "id", value = "策略索引", required = true)
public HttpResult<Object> delete(@RequestParam("id") String id) { public HttpResult<Object> delete(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("delete"); String methodDescribe = getMethodDescribe("delete");
boolean result = eleAirStrategyService.deleteAirStrategy(id); boolean result = eleAirStrategyService.deleteAirStrategy(id);
@@ -121,6 +121,24 @@ public class EleAirStrategyController extends BaseController {
} }
/**
* 停止空调策略
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@GetMapping("/stop")
@ApiOperation("停止空调策略")
@ApiImplicitParam(name = "id", value = "策略索引", required = true)
public HttpResult<Object> stopAirStrategy(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("stopAirStrategy");
boolean result = eleAirStrategyService.stopAirStrategy(id);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
/** /**
* 查询空调策略详情 * 查询空调策略详情
* @author cdf * @author cdf

View File

@@ -12,7 +12,7 @@
</select> </select>
<select id="getEleLineList" resultType="EnergyDeviceTreeVO"> <select id="getEleLineList" resultType="EnergyDeviceTreeVO">
select id,pid,name,line_id,3 as level from ele_line select id,pid,name,line_id as lineId,3 as level from ele_line
where state = 1 where state = 1
order by ele_line.idx order by ele_line.idx
</select> </select>
@@ -178,7 +178,7 @@ WHERE
inner join ele_logic_dev b on a.pid = b.id inner join ele_logic_dev b on a.pid = b.id
inner join ele_net_dev c on b.pid = c.id inner join ele_net_dev c on b.pid = c.id
where a.state = 1 where a.state = 1
and a.id in and a.line_id in
<foreach collection="lineIds" item="item" open="(" close=")" separator=","> <foreach collection="lineIds" item="item" open="(" close=")" separator=",">
#{item} #{item}
</foreach> </foreach>

View File

@@ -45,6 +45,14 @@ public interface EleAirStrategyService extends IService<AirStrategy> {
*/ */
boolean deleteAirStrategy(String id); boolean deleteAirStrategy(String id);
/**
* 停止策略
* @param id id
* @return 操作结果
*/
boolean stopAirStrategy(String id);
/** /**
* 获取空调策略信息 * 获取空调策略信息
* @param id id * @param id id

View File

@@ -39,6 +39,9 @@ import com.njcn.energy.pojo.vo.AirStrategyVO;
import com.njcn.energy.pojo.vo.EnergyDeviceTreeVO; import com.njcn.energy.pojo.vo.EnergyDeviceTreeVO;
import com.njcn.energy.service.EleAirStrategyService; import com.njcn.energy.service.EleAirStrategyService;
import com.njcn.energy.service.IEleSetService; import com.njcn.energy.service.IEleSetService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDBCommUtils;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.job.api.JobFeignClient; import com.njcn.job.api.JobFeignClient;
import com.njcn.job.model.XxlJobInfo; import com.njcn.job.model.XxlJobInfo;
import com.njcn.web.factory.PageFactory; import com.njcn.web.factory.PageFactory;
@@ -48,10 +51,12 @@ import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@@ -75,17 +80,19 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
private final LogicDeviceLineMapper logicDeviceLineMapper; private final LogicDeviceLineMapper logicDeviceLineMapper;
private final MqttPublisher publisher; private final MqttPublisher publisher;
private final AirStrategyMapper airStrategyMapper; private final AirStrategyMapper airStrategyMapper;
private final MqttMessageHandler mqttMessageHandler; private final MqttMessageHandler mqttMessageHandler;
private final InfluxDbUtils influxDbUtils;
@Value("${mqtt.client-id}") @Value("${mqtt.client-id}")
private String clientId; private String clientId;
private Integer xxlGroup = 5; //徐扬执行器 5 陈道飞执行器6 3 18数据库测试执行器
private final Integer xxlGroup = 6;
@Override @Override
@@ -98,6 +105,11 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
queryWrapper queryWrapper
.and(param -> param.like("ele_air_strategy.name", queryParam.getSearchValue())); .and(param -> param.like("ele_air_strategy.name", queryParam.getSearchValue()));
} }
if (queryParam.getType() == 0) {
queryWrapper.eq("ele_air_strategy.type", queryParam.getType());
} else {
queryWrapper.ne("ele_air_strategy.type", 0);
}
//排序 //排序
if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) { if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) {
@@ -107,6 +119,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
queryWrapper.orderBy(true, true, "ele_air_strategy.sort"); queryWrapper.orderBy(true, true, "ele_air_strategy.sort");
} }
} }
queryWrapper.eq("ele_air_strategy.state", DataStateEnum.ENABLE.getCode()); queryWrapper.eq("ele_air_strategy.state", DataStateEnum.ENABLE.getCode());
return this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); return this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
@@ -115,10 +128,16 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean addAirStrategy(AirStrategyParam airStrategyParam) { public boolean addAirStrategy(AirStrategyParam airStrategyParam) {
checkDicTypeName(airStrategyParam, false); checkDicTypeName(airStrategyParam, false);
if (airStrategyParam.getType() == 0) {
//默认策略
//校验参数
LambdaQueryWrapper<AirStrategy> tem = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AirStrategy> tem = new LambdaQueryWrapper<>();
tem.eq(AirStrategy::getState, DataStateEnum.ENABLE.getCode()); tem.eq(AirStrategy::getState, DataStateEnum.ENABLE.getCode());
tem.eq(AirStrategy::getType,0);
List<AirStrategy> temList = this.list(tem); List<AirStrategy> temList = this.list(tem);
if (CollectionUtil.isNotEmpty(temList)) { if (CollectionUtil.isNotEmpty(temList)) {
for (AirStrategy airStrategy : temList) { for (AirStrategy airStrategy : temList) {
@@ -129,94 +148,136 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
LocalDateTime endParam = LocalDateTimeUtil.parse(airStrategyParam.getStartTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime endParam = LocalDateTimeUtil.parse(airStrategyParam.getStartTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
long rangeEnd = LocalDateTimeUtil.between(end, endParam).toMinutes(); long rangeEnd = LocalDateTimeUtil.between(end, endParam).toMinutes();
if(rangeStart<=5 ||rangeEnd<=5 ){ if (rangeStart <= 5 || rangeEnd <= 5) {
throw new BusinessException(EnergyResponseEnum.TASK_TIME_ERROR); throw new BusinessException(EnergyResponseEnum.TASK_TIME_ERROR);
} }
} }
} }
AirStrategy airStrategy = new AirStrategy(); AirStrategy airStrategy = assAirStrategy(airStrategyParam);
BeanUtils.copyProperties(airStrategyParam, airStrategy);
airStrategy.setState(DataStateEnum.ENABLE.getCode());
airStrategy.setStatus(0);
airStrategy.setCreateBy(RequestUtil.getUserIndex());
airStrategy.setCreateTime(LocalDateTime.now());
airStrategy.setUpdateTime(LocalDateTime.now());
this.save(airStrategy);
List<AirSet> list = new ArrayList<>(); List<AirSet> list = new ArrayList<>();
airStrategyParam.getLineIds().forEach((item)->{ airStrategyParam.getLineIds().forEach((item) -> {
AirSet airSet = new AirSet(airStrategy.getId(),item); AirSet airSet = new AirSet(airStrategy.getId(), item);
list.add(airSet); list.add(airSet);
}); });
iEleSetService.saveBatch(list); iEleSetService.saveBatch(list);
//时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次
LocalDateTime startTime = LocalDateTimeUtil.parse(airStrategy.getStartTime(), DatePattern.NORM_DATETIME_PATTERN);
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);
HttpResult<String> result = jobFeignClient.addJob(xxlJobInfo);
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
//时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次
LocalDateTime startTimeEnd = LocalDateTimeUtil.parse(airStrategy.getEndTime(), DatePattern.NORM_DATETIME_PATTERN);
String cronOff = "" + startTimeEnd.getSecond() + CharUtil.SPACE + startTimeEnd.getMinute() + CharUtil.SPACE + startTimeEnd.getHour() + CharUtil.SPACE + startTimeEnd.getDayOfMonth() + CharUtil.SPACE + startTimeEnd.getMonthValue() + CharUtil.SPACE + "?" + CharUtil.SPACE + startTimeEnd.getYear();
String paramOff = "close" + StrUtil.C_COMMA + airStrategy.getId();
XxlJobInfo airStrategyClose = assScheduling("测试定时关空调",cronOff,paramOff);
HttpResult<String> result2 = jobFeignClient.addJob(airStrategyClose);
if (result2.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
String ids = result.getData() + StrUtil.COMMA + result2.getData();
airStrategy.setXxlId(ids);
this.updateById(airStrategy);
} else if(airStrategyParam.getType() == 1) {
//开关机策略
AirStrategy airStrategyOnOff = assAirStrategy(airStrategyParam);
List<AirSet> list = new ArrayList<>();
airStrategyParam.getLineIds().forEach((item) -> {
AirSet airSet = new AirSet(airStrategyOnOff.getId(), item);
list.add(airSet);
});
iEleSetService.saveBatch(list);
/* /*
* 此处做示例,手动指定 * 添加开机调度任务
*/ */
//时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次
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();
XxlJobInfo xOn = assScheduling("每日定时关空调",cron,param);
HttpResult<String> result = jobFeignClient.addJob(xOn);
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
airStrategyOnOff.setXxlId(result.getData());
this.updateById(airStrategyOnOff);
} else if(airStrategyParam.getType() == 2) {
//开机策略
AirStrategy airStrategyOnOff = assAirStrategy(airStrategyParam);
List<AirSet> list = new ArrayList<>();
airStrategyParam.getLineIds().forEach((item) -> {
AirSet airSet = new AirSet(airStrategyOnOff.getId(), item);
list.add(airSet);
});
iEleSetService.saveBatch(list);
/*
* 添加开机调度任务
*/
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();
XxlJobInfo xOff = assScheduling("每日定时开空调",cron,param);
HttpResult<String> result = jobFeignClient.addJob(xOff);
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
airStrategyOnOff.setXxlId(result.getData());
this.updateById(airStrategyOnOff);
}
return true;
}
/*组装数据库数据*/
private AirStrategy assAirStrategy(AirStrategyParam airStrategyParam){
AirStrategy airStrategyOnOff = new AirStrategy();
BeanUtils.copyProperties(airStrategyParam, airStrategyOnOff);
airStrategyOnOff.setState(DataStateEnum.ENABLE.getCode());
airStrategyOnOff.setStatus(0);
airStrategyOnOff.setCreateBy(RequestUtil.getUserIndex());
airStrategyOnOff.setCreateTime(LocalDateTime.now());
airStrategyOnOff.setUpdateTime(LocalDateTime.now());
this.save(airStrategyOnOff);
return airStrategyOnOff;
}
/*组装调度任务*/
private XxlJobInfo assScheduling(String desc,String confTime,String param){
XxlJobInfo xxlJobInfo = new XxlJobInfo(); XxlJobInfo xxlJobInfo = new XxlJobInfo();
//执行器ID手动指定此处设置为3对应xxl_job_group中的executor--测试执行器 //执行器ID手动指定此处设置为3对应xxl_job_group中的executor--测试执行器
xxlJobInfo.setJobGroup(xxlGroup); xxlJobInfo.setJobGroup(xxlGroup);
//任务描述 //任务描述
xxlJobInfo.setJobDesc("开启空调"); xxlJobInfo.setJobDesc(desc);
xxlJobInfo.setAuthor("cdf"); xxlJobInfo.setAuthor("cdf");
xxlJobInfo.setScheduleType("CRON"); xxlJobInfo.setScheduleType("CRON");
//时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次 xxlJobInfo.setScheduleConf(confTime);
LocalDateTime startTime = LocalDateTimeUtil.parse(airStrategy.getStartTime(), DatePattern.NORM_DATETIME_PATTERN);
xxlJobInfo.setScheduleConf("" + startTime.getSecond() + CharUtil.SPACE + startTime.getMinute() + CharUtil.SPACE + startTime.getHour() + CharUtil.SPACE + startTime.getDayOfMonth() + CharUtil.SPACE + startTime.getMonthValue() + CharUtil.SPACE + "?" + CharUtil.SPACE + startTime.getYear());
xxlJobInfo.setMisfireStrategy("DO_NOTHING"); xxlJobInfo.setMisfireStrategy("DO_NOTHING");
xxlJobInfo.setExecutorRouteStrategy("FIRST"); xxlJobInfo.setExecutorRouteStrategy("FIRST");
xxlJobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION"); xxlJobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION");
//指定处理器 //指定处理器
xxlJobInfo.setExecutorHandler("airStrategyJob"); xxlJobInfo.setExecutorHandler("airStrategyJob");
//传递的参数 //传递的参数
xxlJobInfo.setExecutorParam("open" + StrUtil.C_COMMA + airStrategy.getId()); xxlJobInfo.setExecutorParam(param);
xxlJobInfo.setGlueType("BEAN"); xxlJobInfo.setGlueType("BEAN");
xxlJobInfo.setGlueRemark("GLUE代码初始化"); xxlJobInfo.setGlueRemark("GLUE代码初始化");
HttpResult result = jobFeignClient.addJob(xxlJobInfo); return xxlJobInfo;
if (result.getCode().equals(ReturnT.FAIL_CODE)) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
/*
* 此处做示例,手动指定
*/
XxlJobInfo xxlJobInfoEnd = new XxlJobInfo();
//执行器ID手动指定此处设置为3对应xxl_job_group中的executor--测试执行器
xxlJobInfoEnd.setJobGroup(xxlGroup);
//任务描述
xxlJobInfoEnd.setJobDesc("关闭空调");
xxlJobInfoEnd.setAuthor("cdf");
xxlJobInfoEnd.setScheduleType("CRON");
//时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次
LocalDateTime startTimeEnd = LocalDateTimeUtil.parse(airStrategy.getEndTime(), DatePattern.NORM_DATETIME_PATTERN);
xxlJobInfoEnd.setScheduleConf("" + startTimeEnd.getSecond() + CharUtil.SPACE + startTimeEnd.getMinute() + CharUtil.SPACE + startTimeEnd.getHour() + CharUtil.SPACE + startTimeEnd.getDayOfMonth() + CharUtil.SPACE + startTimeEnd.getMonthValue() + CharUtil.SPACE + "?" + CharUtil.SPACE + startTimeEnd.getYear());
xxlJobInfoEnd.setMisfireStrategy("DO_NOTHING");
xxlJobInfoEnd.setExecutorRouteStrategy("FIRST");
xxlJobInfoEnd.setExecutorBlockStrategy("SERIAL_EXECUTION");
//指定处理器
xxlJobInfoEnd.setExecutorHandler("airStrategyJob");
//传递的参数
xxlJobInfoEnd.setExecutorParam("close"+StrUtil.C_COMMA+airStrategy.getId());
xxlJobInfoEnd.setGlueType("BEAN");
xxlJobInfoEnd.setGlueRemark("GLUE代码初始化");
HttpResult result2 = jobFeignClient.addJob(xxlJobInfoEnd);
if (result2.getCode().equals(ReturnT.FAIL_CODE)) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
String ids = result.getData().toString() + StrUtil.COMMA + result2.getData().toString();
airStrategy.setXxlId(ids);
this.updateById(airStrategy);
return true;
} }
@Override @Override
@@ -227,6 +288,7 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
throw new BusinessException(CommonResponseEnum.FAIL); throw new BusinessException(CommonResponseEnum.FAIL);
} }
checkDicTypeName(updateParam, true); checkDicTypeName(updateParam, true);
AirStrategy airStrategy = new AirStrategy(); AirStrategy airStrategy = new AirStrategy();
BeanUtils.copyProperties(updateParam, airStrategy); BeanUtils.copyProperties(updateParam, airStrategy);
airStrategy.setUpdateBy(RequestUtil.getUserIndex()); airStrategy.setUpdateBy(RequestUtil.getUserIndex());
@@ -235,71 +297,62 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
iEleSetService.removeById(airStrategy.getId()); iEleSetService.removeById(airStrategy.getId());
List<AirSet> list = new ArrayList<>(); List<AirSet> list = new ArrayList<>();
updateParam.getLineIds().forEach((item) -> { updateParam.getLineIds().forEach((item) -> {
AirSet airSet = new AirSet(airStrategy.getId(), item); AirSet airSet = new AirSet(airStrategy.getId(), item);
list.add(airSet); list.add(airSet);
}); });
iEleSetService.saveBatch(list); iEleSetService.saveBatch(list);
/*
* 此处做示例,手动指定
*/
String[] jobIds = airStrategyRes.getXxlId().split(StrUtil.COMMA); String[] jobIds = airStrategyRes.getXxlId().split(StrUtil.COMMA);
XxlJobInfo xxlJobInfo = new XxlJobInfo(); if(updateParam.getType() == 0) {
//执行器ID手动指定此处设置为3对应xxl_job_group中的executor--测试执行器
xxlJobInfo.setId(Integer.parseInt(jobIds[0]));
xxlJobInfo.setJobGroup(xxlGroup);
//任务描述
xxlJobInfo.setJobDesc("开启空调");
xxlJobInfo.setAuthor("cdf");
xxlJobInfo.setScheduleType("CRON");
//时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次 //时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次
LocalDateTime startTime = LocalDateTimeUtil.parse(airStrategy.getStartTime(), DatePattern.NORM_DATETIME_PATTERN); LocalDateTime startTime = LocalDateTimeUtil.parse(airStrategy.getStartTime(), DatePattern.NORM_DATETIME_PATTERN);
xxlJobInfo.setScheduleConf("" + 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 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();
xxlJobInfo.setMisfireStrategy("DO_NOTHING"); String paramOn = "open" + StrUtil.C_COMMA + airStrategy.getId();
xxlJobInfo.setExecutorRouteStrategy("FIRST");
xxlJobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION"); XxlJobInfo xxlJobInfo = assScheduling("测试开空调",cronOn,paramOn);
//指定处理器 xxlJobInfo.setId(Integer.parseInt(jobIds[0]));
xxlJobInfo.setExecutorHandler("airStrategyJob"); HttpResult<String> result = jobFeignClient.updateJob(xxlJobInfo);
//传递的参数 if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
xxlJobInfo.setExecutorParam("open" + StrUtil.C_COMMA + airStrategy.getId());
xxlJobInfo.setGlueType("BEAN");
xxlJobInfo.setGlueRemark("GLUE代码初始化");
HttpResult result = jobFeignClient.updateJob(xxlJobInfo);
if (result.getCode().equals(ReturnT.FAIL_CODE)) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR); throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
} }
/*
* 此处做示例,手动指定
*/
XxlJobInfo xxlJobInfoEnd = new XxlJobInfo();
xxlJobInfoEnd.setId(Integer.parseInt(jobIds[1]));
//执行器ID手动指定此处设置为3对应xxl_job_group中的executor--测试执行器
xxlJobInfoEnd.setJobGroup(xxlGroup);
//任务描述
xxlJobInfoEnd.setJobDesc("关闭空调");
xxlJobInfoEnd.setAuthor("cdf");
xxlJobInfoEnd.setScheduleType("CRON");
//时间表达式需要处理成 秒 分 时 日 月 年,标志指定时间执行一次
LocalDateTime startTimeEnd = LocalDateTimeUtil.parse(airStrategy.getEndTime(), DatePattern.NORM_DATETIME_PATTERN); LocalDateTime startTimeEnd = LocalDateTimeUtil.parse(airStrategy.getEndTime(), DatePattern.NORM_DATETIME_PATTERN);
xxlJobInfoEnd.setScheduleConf("" + startTimeEnd.getSecond() + CharUtil.SPACE + startTimeEnd.getMinute() + CharUtil.SPACE + startTimeEnd.getHour() + CharUtil.SPACE + startTimeEnd.getDayOfMonth() + CharUtil.SPACE + startTimeEnd.getMonthValue() + CharUtil.SPACE + "?" + CharUtil.SPACE + startTimeEnd.getYear()); String cronOff = "" + startTimeEnd.getSecond() + CharUtil.SPACE + startTimeEnd.getMinute() + CharUtil.SPACE + startTimeEnd.getHour() + CharUtil.SPACE + startTimeEnd.getDayOfMonth() + CharUtil.SPACE + startTimeEnd.getMonthValue() + CharUtil.SPACE + "?" + CharUtil.SPACE + startTimeEnd.getYear();
xxlJobInfoEnd.setMisfireStrategy("DO_NOTHING"); String paramOff = "close" + StrUtil.C_COMMA + airStrategy.getId();
xxlJobInfoEnd.setExecutorRouteStrategy("FIRST");
xxlJobInfoEnd.setExecutorBlockStrategy("SERIAL_EXECUTION");
//指定处理器
xxlJobInfoEnd.setExecutorHandler("airStrategyJob");
//传递的参数
xxlJobInfoEnd.setExecutorParam("close" + StrUtil.C_COMMA + airStrategy.getId());
xxlJobInfoEnd.setGlueType("BEAN");
xxlJobInfoEnd.setGlueRemark("GLUE代码初始化");
HttpResult result2 = jobFeignClient.updateJob(xxlJobInfoEnd);
if (result2.getCode().equals(ReturnT.FAIL_CODE)) { XxlJobInfo xxlJobInfoOff = assScheduling("测试关空调",cronOff,paramOff);
xxlJobInfoOff.setId(Integer.parseInt(jobIds[1]));
HttpResult<String> result2 = jobFeignClient.updateJob(xxlJobInfoOff);
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR); throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
} }
if (result2.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
}else if(updateParam.getType() == 1){
String[] temTime = updateParam.getStartTime().split(":");
String cron = "0" + CharUtil.SPACE + temTime[1] + CharUtil.SPACE + temTime[0] + CharUtil.SPACE + "* * ?";
String param = "close" + StrUtil.C_COMMA + airStrategy.getId();
XxlJobInfo xOff = assScheduling("每日定时关空调",cron,param);
xOff.setId(Integer.parseInt(jobIds[0]));
HttpResult<String> result = jobFeignClient.updateJob(xOff);
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
}else if(updateParam.getType() == 2){
String[] temTime = updateParam.getStartTime().split(":");
String cron = "0" + CharUtil.SPACE + temTime[1] + CharUtil.SPACE + temTime[0] + CharUtil.SPACE + "* * ?";
String param = "open" + StrUtil.C_COMMA + airStrategy.getId();
XxlJobInfo xOff = assScheduling("每日定时开空调",cron,param);
xOff.setId(Integer.parseInt(jobIds[0]));
HttpResult<String> result = jobFeignClient.updateJob(xOff);
if (result.getCode().equals(String.valueOf(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_CREATE_ERROR);
}
}
return true; return true;
} }
@@ -337,6 +390,33 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
} }
@Override
@Transactional(rollbackFor = Exception.class)
public boolean stopAirStrategy(String id) {
AirStrategy airStrategy = this.getById(id);
if (Objects.isNull(airStrategy)) {
throw new BusinessException(CommonResponseEnum.FAIL);
}
if (airStrategy.getStatus() != 1) {
throw new BusinessException(EnergyResponseEnum.TASK_NO_RUN);
}
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)
.eq(AirStrategy::getId, id)
.update();
return true;
}
@Override @Override
public AirStrategyVO findById(String id) { public AirStrategyVO findById(String id) {
AirStrategy airStrategy = this.lambdaQuery().eq(AirStrategy::getId, id).one(); AirStrategy airStrategy = this.lambdaQuery().eq(AirStrategy::getId, id).one();
@@ -361,20 +441,15 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
String[] ids = airStrategy.getXxlId().split(StrUtil.COMMA); String[] ids = airStrategy.getXxlId().split(StrUtil.COMMA);
if (airStrategy.getStatus() == 0) { if (airStrategy.getStatus() == 0) {
//可以启动 //可以启动
for (String xxlId : ids) { for (String xxlId : ids) {
HttpResult<String> result = jobFeignClient.startTask(Integer.parseInt(xxlId)); HttpResult<String> result = jobFeignClient.startTask(Integer.parseInt(xxlId));
if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) { if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) {
throw new BusinessException(EnergyResponseEnum.TASK_RUNING); throw new BusinessException(EnergyResponseEnum.TASK_RUNING);
} }
} }
this.lambdaUpdate().set(AirStrategy::getStatus, 1).eq(AirStrategy::getId, id).update(); this.lambdaUpdate().set(AirStrategy::getStatus, 1).eq(AirStrategy::getId, id).update();
} else if (airStrategy.getStatus() == 1) { } else if (airStrategy.getStatus() == 1) {
//已经执行中 //已经执行中
for (String xxlId : ids) { for (String xxlId : ids) {
HttpResult<String> result = jobFeignClient.stopJob(Integer.parseInt(xxlId)); HttpResult<String> result = jobFeignClient.stopJob(Integer.parseInt(xxlId));
if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) { if (result.getCode().equals(StrUtil.toString(ReturnT.FAIL_CODE))) {
@@ -386,7 +461,6 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
//已经完成 //已经完成
throw new BusinessException(EnergyResponseEnum.TASK_HAS_START); throw new BusinessException(EnergyResponseEnum.TASK_HAS_START);
} }
return true; return true;
} }
@@ -398,14 +472,31 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
if (Objects.isNull(airStrategy)) { if (Objects.isNull(airStrategy)) {
throw new BusinessException(CommonResponseEnum.FAIL); throw new BusinessException(CommonResponseEnum.FAIL);
} }
LambdaQueryWrapper<AirSet> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AirSet> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(AirSet::getId, id); lambdaQueryWrapper.eq(AirSet::getId, id);
List<AirSet> list = iEleSetService.list(lambdaQueryWrapper); List<AirSet> list = iEleSetService.list(lambdaQueryWrapper);
if (CollectionUtil.isNotEmpty(list)) { if (CollectionUtil.isNotEmpty(list)) {
List<String> lineIds = list.stream().map(AirSet::getLineId).collect(Collectors.toList()); List<String> lineIds = list.stream().map(AirSet::getLineId).collect(Collectors.toList());
//如果是关闭操作
if ("close".equals(operation)) {
StringBuilder temSql = assToInfluxParam(lineIds);
String sql = "select LineId from air_data_Real where " + temSql + " and ACInStat = 'On'";
QueryResult result = influxDbUtils.query(sql);
List<QueryResult.Series> listSeries = result.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(listSeries)) {
System.out.println(listSeries);
List<String> lineIdTem = new ArrayList<>();
listSeries.get(0).getValues().forEach(item -> {
lineIdTem.add(item.get(1).toString());
});
lineIds = lineIdTem;
}
}
System.out.println(lineIds);
List<NetAndDevByLineDTO> netDevList = logicDeviceLineMapper.getNetAndDevByLineIds(lineIds); List<NetAndDevByLineDTO> netDevList = logicDeviceLineMapper.getNetAndDevByLineIds(lineIds);
if (CollectionUtil.isNotEmpty(netDevList)) { if (CollectionUtil.isNotEmpty(netDevList)) {
for (NetAndDevByLineDTO netAndDevByLineDTO : netDevList) { for (NetAndDevByLineDTO netAndDevByLineDTO : netDevList) {
@@ -419,11 +510,11 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
power = "On"; power = "On";
array = "ACInStat"; array = "ACInStat";
} else if (i == 1) { } else if (i == 1) {
power = airStrategy.getTemperature().toString();
array = "ACInSetTmp";
} else if (i == 2) {
power = airStrategy.getMode(); power = airStrategy.getMode();
array = "ACInMode"; array = "ACInMode";
} else if (i == 2) {
power = airStrategy.getTemperature().toString();
array = "ACInSetTmp";
} else { } else {
power = airStrategy.getWind(); power = airStrategy.getWind();
array = "ACInSpeed"; array = "ACInSpeed";
@@ -452,16 +543,10 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
this.mqttSendTopic = topic; this.mqttSendTopic = topic;
flag = true; flag = true;
while(flag){ while (flag) {
} }
/* try {
Thread.sleep(2000);
System.out.println("切换命令睡了1s");
} catch (InterruptedException e) {
e.printStackTrace();
}
*/
} }
} else { } else {
//关闭空调 //关闭空调
@@ -486,27 +571,13 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
this.mqttJsonMsg = json; this.mqttJsonMsg = json;
this.mqttSendTopic = topic; this.mqttSendTopic = topic;
flag = true; flag = true;
while(flag){ while (flag) {
} }
}
/*try {
Thread.sleep(2000);
System.out.println("切换监测点睡了1s");
} catch (InterruptedException e) {
e.printStackTrace();
}*/
} }
if ("close".equals(operation) && airStrategy.getType() == 0) {
}
System.out.println(operation);
if (operation.equals("close")) {
AirStrategy air = new AirStrategy(); AirStrategy air = new AirStrategy();
air.setId(airStrategy.getId()); air.setId(airStrategy.getId());
air.setStatus(2); air.setStatus(2);
@@ -514,8 +585,10 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
} }
} }
} }
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -526,24 +599,25 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
private Integer mqttSendCount = 0; private Integer mqttSendCount = 0;
private String mqttJsonMsg; private String mqttJsonMsg;
private String mqttSendTopic; private String mqttSendTopic;
@MqttSubscribe(value = "/platform/devack/#",qos = 1)
public void airOperation(String topic, MqttMessage message, @Payload String payload){ @MqttSubscribe(value = "/platform/devack/#", qos = 1)
public void airOperation(String topic, MqttMessage message, @Payload String payload) {
System.out.println(message.toString()); System.out.println(message.toString());
JSONObject jsonObject = new JSONObject(message.toString()); JSONObject jsonObject = new JSONObject(message.toString());
String str = jsonObject.getStr("userId"); String str = jsonObject.getStr("userId");
if(str.equals(clientId)){ if (str.equals(clientId)) {
if(!jsonObject.getStr("code").equals("200")){ if (!jsonObject.getStr("code").equals("200")) {
mqttSendCount++; mqttSendCount++;
if(mqttSendCount < 3){ if (mqttSendCount < 3) {
System.out.println("进入错误重发++++++"); System.out.println("进入错误重发++++++");
System.out.println("错误重发详情"+mqttJsonMsg); System.out.println("错误重发详情" + mqttJsonMsg);
publisher.send(mqttSendTopic, mqttJsonMsg, 1, false); publisher.send(mqttSendTopic, mqttJsonMsg, 1, false);
}else{ } else {
flag = false; flag = false;
} }
}else{ } else {
flag = false; flag = false;
} }
@@ -552,7 +626,6 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
} }
/** /**
* 校验参数,检查是否存在相同名称的空调策略 * 校验参数,检查是否存在相同名称的空调策略
*/ */
@@ -574,4 +647,16 @@ public class EleAirStrategyServiceImpl extends ServiceImpl<AirStrategyMapper, Ai
} }
} }
public static StringBuilder assToInfluxParam(List<String> lineIds) {
StringBuilder lineIdsStr = new StringBuilder("(");
for (int i = 0; i < lineIds.size(); i++) {
if (lineIds.size() - i != 1) {
lineIdsStr.append("LineId ='").append(lineIds.get(i)).append("' or ");
} else {
lineIdsStr.append("LineId ='").append(lineIds.get(i)).append("') ");
}
}
return lineIdsStr;
}
} }

View File

@@ -20,6 +20,7 @@ spring:
cloud: cloud:
nacos: nacos:
discovery: discovery:
ip: @service.server.url@
server-addr: @nacos.url@ server-addr: @nacos.url@
namespace: @nacos.namespace@ namespace: @nacos.namespace@
config: config:

View File

@@ -16,6 +16,7 @@ spring:
cloud: cloud:
nacos: nacos:
discovery: discovery:
ip: @service.server.url@
server-addr: @nacos.url@ server-addr: @nacos.url@
namespace: @nacos.namespace@ namespace: @nacos.namespace@
config: config:
@@ -41,12 +42,12 @@ logging:
xxl: xxl:
job: job:
admin: admin:
addresses: http://192.168.1.13:10217/job-admin addresses: http://192.168.1.102:10217/job-admin
#执行器通讯TOKEN [选填]:非空时启用; #执行器通讯TOKEN [选填]:非空时启用;
accessToken: accessToken:
executor: executor:
#执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册 #执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
appname: executor appname: executorCdf
#执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。 #执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
address: address:
#执行器IP [选填]默认为空表示自动获取IP多网卡时可手动设置指定IP该IP不会绑定Host仅作为通讯实用地址信息用于 "执行器注册" 和 "调度中心请求并触发任务" #执行器IP [选填]默认为空表示自动获取IP多网卡时可手动设置指定IP该IP不会绑定Host仅作为通讯实用地址信息用于 "执行器注册" 和 "调度中心请求并触发任务"