This commit is contained in:
huangzj
2023-09-04 15:26:30 +08:00
parent 338735b132
commit 04f16ee8ee
13 changed files with 201 additions and 22 deletions

View File

@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -75,6 +76,10 @@ public class MqttMessageHandler {
public void responseTopoData(String topic, @NamedValue("devId") String devId, MqttMessage message, @Payload String payload) {
List<ThdDataVO> result = new ArrayList<>();
List<ThdDataVO> tempList = new ArrayList<>();
ExecutorService executorService = new ThreadPoolExecutor(40, 400,
1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(100, true),
Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
List<Future<List<ThdDataVO>>> resultList = new ArrayList< Future<List<ThdDataVO>>>();
//1.查询拓扑图配置的指标:拓扑图扑图配置7677f94c749dedaff30f911949cbd724
List<EleEpdPqd> data = csStatisticalSetFeignClient.queryStatisticalSelect("7677f94c749dedaff30f911949cbd724").getData();
@@ -86,21 +91,32 @@ public class MqttMessageHandler {
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
commonStatisticalQueryParam.setFrequency(i+"");
List<ThdDataVO> thdDataVOS = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
tempList.addAll(thdDataVOS);
Future<List<ThdDataVO>> listFuture= executorService.submit(new TaskWithResult(commonStatisticalQueryParam));
resultList.add(listFuture);
}
}else {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
List<ThdDataVO> thdDataVOS = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
tempList.addAll(thdDataVOS);
}
}else {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
Future<List<ThdDataVO>> listFuture= executorService.submit(new TaskWithResult(commonStatisticalQueryParam));
resultList.add(listFuture);
}
});
executorService.shutdown();
resultList.forEach(temp->{
try {
tempList.addAll(temp.get());
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
});
//过滤M相
List<ThdDataVO> m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList());
m.stream().forEach(temp->{
@@ -198,4 +214,26 @@ public class MqttMessageHandler {
}
return "";
}
class TaskWithResult implements Callable<List<ThdDataVO>> {
private CommonStatisticalQueryParam commonStatisticalQueryParam;
public TaskWithResult(CommonStatisticalQueryParam commonStatisticalQueryParam) {
this.commonStatisticalQueryParam = commonStatisticalQueryParam;
}
/**
* 任务的具体过程一旦任务传给ExecutorService的submit方法则该方法自动在一个线程上执行。
*
* @return
* @throws Exception
*/
@Override
public List<ThdDataVO> call() throws Exception {
List<ThdDataVO> thdDataVOList = new ArrayList<>();
thdDataVOList = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
return thdDataVOList;
}
}
}

View File

@@ -0,0 +1,15 @@
package com.njcn.csharmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csharmonic.pojo.po.CsEventPO;
/**
*
* Description:
* Date: 2023/9/4 15:15【需求编号】
*
* @author clam
* @version V1.0.0
*/
public interface CsEventPOMapper extends BaseMapper<CsEventPO> {
}

View File

@@ -0,0 +1,15 @@
package com.njcn.csharmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
/**
*
* Description:
* Date: 2023/9/4 15:15【需求编号】
*
* @author clam
* @version V1.0.0
*/
public interface CsEventUserPOMapper extends BaseMapper<CsEventUserPO> {
}

View File

@@ -0,0 +1,18 @@
<?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="com.njcn.csharmonic.mapper.CsEventPOMapper">
<resultMap id="BaseResultMap" type="com.njcn.csharmonic.pojo.po.CsEventPO">
<!--@mbg.generated-->
<!--@Table cs_event-->
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="line_id" jdbcType="VARCHAR" property="lineId" />
<result column="device_id" jdbcType="VARCHAR" property="deviceId" />
<result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
<result column="tag" jdbcType="VARCHAR" property="tag" />
<result column="wave_id" jdbcType="VARCHAR" property="waveId" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, line_id, device_id, start_time, tag, wave_id
</sql>
</mapper>

View File

@@ -0,0 +1,16 @@
<?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="com.njcn.csharmonic.mapper.CsEventUserPOMapper">
<resultMap id="BaseResultMap" type="com.njcn.csharmonic.pojo.po.CsEventUserPO">
<!--@mbg.generated-->
<!--@Table cs_event_user-->
<result column="device_id" jdbcType="VARCHAR" property="deviceId" />
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="event_id" jdbcType="VARCHAR" property="eventId" />
<result column="status" jdbcType="INTEGER" property="status" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
device_id, user_id, event_id, `status`
</sql>
</mapper>

View File

@@ -21,6 +21,7 @@ import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.pojo.po.EleEpdPqd;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;