From 97f5e6facacdfe8b2678dfc491edd00908432818 Mon Sep 17 00:00:00 2001 From: wu <wsjxh1023@163.com> Date: Fri, 17 May 2024 15:11:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9amb=E7=9A=84=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=9D=A1=E4=BB=B6;=20110=E7=9A=84=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E6=B7=BB=E5=8A=A0ai=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E4=B8=8D=E4=B8=BA=E7=A9=BA;=20=E6=96=B0=E5=A2=9E110=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E6=8E=A5=E5=8F=A35=E5=88=86=E9=92=9F=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yingji/quartz/AlarmQuartz.java | 38 ++++++++++ .../resources/mapper/yingji/AlarmMapper.xml | 69 +++++++++---------- .../service/impl/AccidentServiceImpl.java | 10 +-- 3 files changed, 77 insertions(+), 40 deletions(-) diff --git a/alarm/src/main/java/com/yingji/quartz/AlarmQuartz.java b/alarm/src/main/java/com/yingji/quartz/AlarmQuartz.java index 7ea393e..0ef0068 100644 --- a/alarm/src/main/java/com/yingji/quartz/AlarmQuartz.java +++ b/alarm/src/main/java/com/yingji/quartz/AlarmQuartz.java @@ -2,6 +2,8 @@ package com.yingji.quartz; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.json.JSONUtil; import com.yingji.entity.Alarm; import com.yingji.entity.dto.request.AlarmRequest; import com.yingji.service.AlarmService; @@ -16,7 +18,9 @@ import javax.annotation.Resource; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Random; /** @@ -46,6 +50,39 @@ public class AlarmQuartz { String token = alarmService.getToken(); // 查询所有id List<String> idList = findId(token); + // 根据id查询数据保存 + addList(idList, token); + } + + /** + * 110算法接口 + */ + @Async + @Scheduled(cron = "0 */5 * * * ? ") + public void emergencyAlgorithm() { + log.info("============110算法接口开始" + LocalDateTime.now() + "============="); + // 获取当前的时间 + LocalDateTime endTime = LocalDateTime.now(); + // 获取五分钟前时间 + LocalDateTime startTime = endTime.minusMinutes(5); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + String endTimeStr = endTime.format(formatter) + ":00"; + String startTimeStr = startTime.format(formatter) + ":00"; + Map<String, String> map = new HashMap<>(); + map.put("startTime", startTimeStr); + map.put("endTime", endTimeStr); + String body = JSONUtil.toJsonStr(map); + HttpRequest.post("http://localhost:9002/emergency_algorithm").body(body).execute().body(); + log.info("============110算法接口结束" + LocalDateTime.now() + "============="); + } + + /** + * 根据id查询数据保存 + * + * @param idList 数据id + * @param token token + */ + private void addList(List<String> idList, String token) { // 查询数据条件 AlarmRequest alarmRequest = new AlarmRequest(); alarmRequest.setType("getValue"); @@ -59,6 +96,7 @@ public class AlarmQuartz { try { for (String x : idList) { alarmRequest.setValue(x); + // 查询数据 Alarm alarm = alarmService.findDataList(alarmRequest, token); if (alarm != null) { alarm.setSourceId(x); diff --git a/page/src/main/resources/mapper/yingji/AlarmMapper.xml b/page/src/main/resources/mapper/yingji/AlarmMapper.xml index 7224616..8b29db9 100644 --- a/page/src/main/resources/mapper/yingji/AlarmMapper.xml +++ b/page/src/main/resources/mapper/yingji/AlarmMapper.xml @@ -7,41 +7,40 @@ <select id="page" resultType="com.yingji.entity.Alarm"> select * from alarm - <where> - <if test="req.startTime != null "> - emergency_event_time >= #{req.startTime} - </if> - <if test="req.endTime != null "> - and emergency_event_time <= #{req.endTime} - </if> - <if test="req.endTime != null "> - and emergency_event_time <= #{req.endTime} - </if> - <if test="req.emergencyEventDesc != null and req.emergencyEventDesc != ''"> - and emergency_event_desc like concat('%', #{req.emergencyEventDesc}, '%') - </if> - <if test="req.emergencyEventAddress != null and req.emergencyEventAddress != ''"> - and emergency_event_address like concat('%', #{req.emergencyEventAddress}, '%') - </if> - <if test="req.alarmPhoneNumber != null and req.alarmPhoneNumber != ''"> - and alarm_phone_number like concat('%', #{req.alarmPhoneNumber}, '%') - </if> - <if test="req.aiClass != null and req.aiClass != ''"> - and ai_class like concat('%', #{req.aiClass}, '%') - </if> - <if test="req.aiClass2 != null and req.aiClass2 != ''"> - and ai_class2 like concat('%', #{req.aiClass2}, '%') - </if> - <if test="req.aiLevel != null and req.aiLevel != ''"> - and ai_level like concat('%', #{req.aiLevel}, '%') - </if> - <if test="req.aiNumMin != null "> - and ai_num <= #{req.aiNumMin} - </if> - <if test="req.aiNumMax != null "> - and ai_num <= #{req.aiNumMax} - </if> - </where> + where ai_class is not null + <if test="req.startTime != null "> + and emergency_event_time >= #{req.startTime} + </if> + <if test="req.endTime != null "> + and emergency_event_time <= #{req.endTime} + </if> + <if test="req.endTime != null "> + and emergency_event_time <= #{req.endTime} + </if> + <if test="req.emergencyEventDesc != null and req.emergencyEventDesc != ''"> + and emergency_event_desc like concat('%', #{req.emergencyEventDesc}, '%') + </if> + <if test="req.emergencyEventAddress != null and req.emergencyEventAddress != ''"> + and emergency_event_address like concat('%', #{req.emergencyEventAddress}, '%') + </if> + <if test="req.alarmPhoneNumber != null and req.alarmPhoneNumber != ''"> + and alarm_phone_number like concat('%', #{req.alarmPhoneNumber}, '%') + </if> + <if test="req.aiClass != null and req.aiClass != ''"> + and ai_class like concat('%', #{req.aiClass}, '%') + </if> + <if test="req.aiClass2 != null and req.aiClass2 != ''"> + and ai_class2 like concat('%', #{req.aiClass2}, '%') + </if> + <if test="req.aiLevel != null and req.aiLevel != ''"> + and ai_level like concat('%', #{req.aiLevel}, '%') + </if> + <if test="req.aiNumMin != null "> + and ai_num <= #{req.aiNumMin} + </if> + <if test="req.aiNumMax != null "> + and ai_num <= #{req.aiNumMax} + </if> order by update_time desc </select> diff --git a/rescue/src/main/java/com/yingji/service/impl/AccidentServiceImpl.java b/rescue/src/main/java/com/yingji/service/impl/AccidentServiceImpl.java index 07c6b9e..13644d9 100644 --- a/rescue/src/main/java/com/yingji/service/impl/AccidentServiceImpl.java +++ b/rescue/src/main/java/com/yingji/service/impl/AccidentServiceImpl.java @@ -215,14 +215,14 @@ public class AccidentServiceImpl implements AccidentService { Task one = taskService.getOne(wrapper); if (BeanUtil.isEmpty(one)) { taskService.save(task); + Amb amb = taskInfo.getAmb(); + if (BeanUtil.isNotEmpty(amb)) { + amb.setTaskId(task.getTaskId()); + ambService.save(amb); + } } else { taskService.updateById(task); } - Amb amb = taskInfo.getAmb(); - if (BeanUtil.isNotEmpty(amb)) { - amb.setTaskId(task.getTaskId()); - ambService.save(amb); - } } } }