Commit 25c1b88a authored by wujiang's avatar wujiang

修改生成指数问题

parent 779ac0bc
......@@ -24,11 +24,13 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler;
import java.net.InetAddress;
......@@ -52,7 +54,8 @@ import java.net.InetAddress;
"com.yeejoin.amos.boot.module.**.api.mapper", "com.yeejoin.amos.boot.biz.common.dao.mapper",
"com.yeejoin.amos.boot.module.common.biz.*", "com.yeejoin.amos.boot.module.jxiop.api.mapper",
"com.yeejoin.amos.boot.module.jxiop.biz.tdmapper", "com.yeejoin.amos.boot.module.jxiop.biz.mapper5" })
@ComponentScan(basePackages = { "org.typroject", "com.yeejoin.amos" })
@ComponentScan(basePackages = { "org.typroject", "com.yeejoin.amos" },excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
GlobalExceptionHandler.class }))
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class })
//@SpringBootApplication
public class AmosJxiopAnalyseApplication {
......@@ -86,8 +89,8 @@ public class AmosJxiopAnalyseApplication {
return;
}
// 订阅固化周期性数据成功的消息
emqKeeper.subscript("sync_esdata_to_tdengine_notice", 1, syncESDataToTdengineMqttListener);
emqKeeper.subscript("sync_esdata_to_tdengine_notice1", 1, syncESDataToTdengineMqttListener);
// 订阅业务固化同步数据成功消息
emqKeeper.subscript("sync_iotdata_to_tdengine_notice", 1, syncDasSuccessMqttListener);
//emqKeeper.subscript("sync_iotdata_to_tdengine_notice", 1, syncDasSuccessMqttListener);
}
}
......@@ -1863,13 +1863,13 @@ public class TDBigScreenAnalyseController extends BaseController implements Appl
@Override
public void run(ApplicationArguments args) throws Exception {
initStationFirstSelect();
//initStationFirstSelect();
}
/**
* 初始化场站第一个选中
*/
@Scheduled(cron = "0 */3 * * * ?")
@Scheduled(cron = "0 */10 * * * ?")
public void initStationFirstSelect() {
List<StationBasicDto> stationBasicDtos = stationBasicMapper.getStationBasicList();
if(CollectionUtil.isNotEmpty(stationBasicDtos)){
......
......@@ -9,6 +9,9 @@ import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.TdengineTimeServiceIm
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;
......@@ -27,6 +30,7 @@ import java.util.concurrent.TimeUnit;
*/
@Component
@Slf4j
@EnableScheduling
public class SyncESDataToTdengineMqttListener extends EmqxListener {
@Autowired
......@@ -43,10 +47,70 @@ public class SyncESDataToTdengineMqttListener extends EmqxListener {
@PostConstruct
public void test() {
// 每次启动清空redis
//redisUtils.set(JXIOP_ANALYSE_TIME, "2024-07-30 13:40:00");
// redisUtils.set(JXIOP_ANALYSE_TIME, "2024-07-30 13:40:00");
redisUtils.del(JXIOP_ANALYSE_TIME);
}
// @Async("async")
@Scheduled(cron = "0 */10 * * * ?")
public void run() throws ParseException {
Date time = new Date();
time = DateUtil.offsetMinute(time, -DateUtil.minute(time) % 10);
String format = DateUtil.format(time, "yyyy-MM-dd HH:mm:00");
time = DateUtil.parse(format, "yyyy-MM-dd HH:mm:00");
if (redisUtils.get(JXIOP_ANALYSE_TIME) != null) {
// 如果相差20分钟 按10分钟处理 可能装备发消息晚了
String lastformat = String.valueOf(redisUtils.get(JXIOP_ANALYSE_TIME));
Date oldTime = DateUtil.parse(lastformat, "yyyy-MM-dd HH:mm:00");
long diffInMillies = Math.abs(time.getTime() - oldTime.getTime());
long diffInMinutes = TimeUnit.MINUTES.convert(diffInMillies, TimeUnit.MILLISECONDS);
if (diffInMinutes == 20) {
time = DateUtil.offsetMinute(time, -10);
format = DateUtil.format(time, "yyyy-MM-dd HH:mm:00");
}
}
redisUtils.set(JXIOP_ANALYSE_TIME, format);
System.out.println(format);
final Date timeF = time;
CompletableFuture<String> fan = CompletableFuture.supplyAsync(() -> {
try {
commonServiceImpl.healthWarningMinuteByFan(timeF);
} catch (Exception e) {
e.printStackTrace();
}
String fanResult = "风电任务完成..";
System.out.println(fanResult);
return fanResult;
});
CompletableFuture<String> pv = CompletableFuture.supplyAsync(() -> {
try {
commonServiceImpl.healthWarningMinuteByPv(timeF);
} catch (Exception e) {
e.printStackTrace();
}
String pvResult = "光伏任务完成..";
System.out.println(pvResult);
return pvResult;
});
try {
String fanResult = fan.get();
String pvResult = pv.get();
// 区域 全域最后统一生成
tdengineTimeService.insertMomentDataAll(format);
if (isWholeHour(format)) {
tdengineTimeService.insertHourData();
}
if (isWholeDay(format)) {
tdengineTimeService.insertDayData();
}
} catch (InterruptedException | ExecutionException e) {
System.out.println("任务执行异常");
e.printStackTrace();
}
}
@Override
public void processMessage(String topic, MqttMessage mqttMessage) throws ParseException {
log.info(topic + "收到数据同步成功,开始计算健康指数!");
......@@ -56,54 +120,7 @@ public class SyncESDataToTdengineMqttListener extends EmqxListener {
JSONObject jsonObject = JSONObject.parseObject(msg);
String flag = jsonObject.get("sync_flag").toString();
if ("success".equals(flag)) {
Date time = new Date();
time = DateUtil.offsetMinute(time, -DateUtil.minute(time) % 10);
String format = DateUtil.format(time, "yyyy-MM-dd HH:mm:00");
time = DateUtil.parse(format, "yyyy-MM-dd HH:mm:00");
if (redisUtils.get(JXIOP_ANALYSE_TIME) != null) {
// 如果相差20分钟 按10分钟处理 可能装备发消息晚了
String lastformat = String.valueOf(redisUtils.get(JXIOP_ANALYSE_TIME));
Date oldTime = DateUtil.parse(lastformat, "yyyy-MM-dd HH:mm:00");
long diffInMillies = Math.abs(time.getTime() - oldTime.getTime());
long diffInMinutes = TimeUnit.MINUTES.convert(diffInMillies, TimeUnit.MILLISECONDS);
if (diffInMinutes == 20) {
time = DateUtil.offsetMinute(time, -10);
format = DateUtil.format(time, "yyyy-MM-dd HH:mm:00");
}
}
redisUtils.set(JXIOP_ANALYSE_TIME, format);
System.out.println(format);
final Date timeF = time;
CompletableFuture<String> fan=CompletableFuture.supplyAsync(()->{
commonServiceImpl.healthWarningMinuteByFan(timeF);
String fanResult = "风电任务完成..";
System.out.println(fanResult);
return fanResult;
});
CompletableFuture<String> pv=CompletableFuture.supplyAsync(()->{
commonServiceImpl.healthWarningMinuteByPv(timeF);
String pvResult = "光伏任务完成..";
System.out.println(pvResult);
return pvResult;
});
try {
String fanResult = fan.get();
String pvResult = pv.get();
// 区域 全域最后统一生成
tdengineTimeService.insertMomentDataAll(format);
if (isWholeHour(format)){
tdengineTimeService.insertHourData();
}
if (isWholeDay(format)){
tdengineTimeService.insertDayData();
}
} catch (InterruptedException | ExecutionException e) {
System.out.println("任务执行异常");
e.printStackTrace();
}
run();
//
// ExecutorService excutorService = Executors.newFixedThreadPool(10);
// int taskCount = 2;
......@@ -159,7 +176,8 @@ public class SyncESDataToTdengineMqttListener extends EmqxListener {
// }).start();
// }
}
private boolean isWholeHour(String dateTimeStr) {
private boolean isWholeHour(String dateTimeStr) {
try {
DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, FORMATTER);
......@@ -169,7 +187,7 @@ public class SyncESDataToTdengineMqttListener extends EmqxListener {
}
}
private boolean isWholeDay(String dateTimeStr) {
private boolean isWholeDay(String dateTimeStr) {
try {
DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, FORMATTER);
......
......@@ -34,7 +34,7 @@ spring.redis.host=10.20.1.210
spring.redis.port=6379
spring.redis.password=yeejoin@2020
openHealth=false
openHealth=true
spring.cache.type=GENERIC
j2cache.open-spring-cache=true
j2cache.cache-clean-mode=passive
......
......@@ -173,6 +173,8 @@
<if test="dto.analysisType!= null and dto.analysisType!= ''">and analysis_type = #{dto.analysisType}</if>
<if test="dto.endDateTs!= null and dto.endDateTs!= '' "> and ts &lt;= #{dto.endDateTs} </if>
<if test="dto.startDateTs!= null and dto.startDateTs!= ''"> and ts &gt;= #{dto.startDateTs} </if>
<!--<if test="dto.endDate!= null and dto.endDate!= ''"> and ts &lt;= #{dto.endDate} </if>
<if test="dto.startDate!= null and dto.startDate!= ''"> and ts &gt;= #{dto.startDate} </if>-->
<if test="dto.area!= null and dto.area!= ''"> AND area = #{dto.area} </if>
<if test="dto.number!= null and dto.number!= ''"> AND `number` = #{dto.number} </if>
<if test="dto.pointName!= null and dto.pointName!= ''">AND point_name = #{dto.pointName} </if>
......
......@@ -205,6 +205,8 @@
<if test="dto.analysisType!= null and dto.analysisType!= ''">and analysis_type = #{dto.analysisType}</if>
<if test="dto.endDateTs!= null and dto.endDateTs!= ''"> and ts &lt;= #{dto.endDateTs} </if>
<if test="dto.startDateTs!= null and dto.startDateTs!= ''"> and ts &gt;= #{dto.startDateTs} </if>
<!--<if test="dto.endDate!= null and dto.endDate!= ''"> and ts &lt;= #{dto.endDate} </if>
<if test="dto.startDate!= null and dto.startDate!= ''"> and ts &gt;= #{dto.startDate} </if>-->
<if test="dto.area!= null and dto.area!= ''"> AND area = #{dto.area} </if>
<if test="dto.subarray!= null and dto.subarray!= ''"> AND subarray = #{dto.subarray} </if>
<if test="dto.pointName!= null and dto.pointName!= ''">AND point_name = #{dto.pointName} </if>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment