From af4b8add9d103889472a75973847871b7dcdf3c8 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期一, 08 九月 2025 14:23:36 +0800
Subject: [PATCH] 0908

---
 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WarnServiceImpl.java |  142 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 117 insertions(+), 25 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WarnServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WarnServiceImpl.java
index b2afff4..a26aa75 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WarnServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WarnServiceImpl.java
@@ -2,11 +2,14 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.core.utils.DateUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.web.page.PageInfo;
 import com.ruoyi.dataInterchange.api.feignClient.UPWarnMsgAdptInfoClient;
+import com.ruoyi.dataInterchange.api.feignClient.UPWarnMsgOperationInfoClient;
 import com.ruoyi.dataInterchange.api.model.enums.WarnType;
 import com.ruoyi.dataInterchange.api.vo.UPWarnMsgAdptInfoVo;
+import com.ruoyi.dataInterchange.api.vo.UPWarnMsgOperationInfoVo;
 import com.ruoyi.system.api.model.Car;
 import com.ruoyi.system.api.model.Driver;
 import com.ruoyi.system.api.model.Enterprise;
@@ -19,6 +22,7 @@
 import com.ruoyi.system.service.IEnterpriseService;
 import com.ruoyi.system.service.IWarnService;
 import com.ruoyi.system.util.GDMapGeocodingUtil;
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -50,6 +54,9 @@
 	@Resource
 	private ICarService carService;
 	
+	@Resource
+	private UPWarnMsgOperationInfoClient upWarnMsgOperationInfoClient;
+	
 	
 	/**
 	 * 存储新的报警数据
@@ -69,7 +76,12 @@
 		List<Driver> driverList = driverService.list(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1));
 		List<Car> carList = carService.list();
 		List<Warn> warns = new ArrayList<>();
+		List<Warn> updateWarns = new ArrayList<>();
 		for (UPWarnMsgAdptInfoVo vo : list) {
+			long count = this.count(new LambdaQueryWrapper<Warn>().eq(Warn::getObjectId, vo.getInfoId()));
+			if(0 != count){
+				continue;
+			}
 			String warnTypeName = WarnType.getWarnTypeName(vo.getWarnType());
 			warn = new Warn();
 			Optional<Car> carOptional = carList.stream().filter(s -> s.getVehicleNumber().equals(vo.getVehicleNo())).findFirst();
@@ -92,17 +104,21 @@
 			warn.setWarnNumber(1);
 			warn.setSpeed(null == vo.getSpeed() ? BigDecimal.ZERO : new BigDecimal(vo.getSpeed()));
 			if(null != vo.getLongitude() && 0 != vo.getLongitude()){
-				warn.setLongitude(new BigDecimal(vo.getLongitude()).divide(new BigDecimal(1000000)).toString());
+				String s = vo.getLongitude().toString();
+				warn.setLongitude(s.substring(0, 3) + "." + s.substring(3));
 			}
 			if(null != vo.getLatitude() && 0 != vo.getLatitude()){
-				warn.setLatitude(new BigDecimal(vo.getLatitude()).divide(new BigDecimal(1000000)).toString());
+				String s = vo.getLatitude().toString();
+				warn.setLatitude(s.substring(0, 2) + "." + s.substring(2));
 				Map<String, String> geocode = null;
 				try {
 					geocode = GDMapGeocodingUtil.geocode(warn.getLongitude(), warn.getLatitude());
 				} catch (Exception e) {
 					e.printStackTrace();
 				}
-				warn.setAddress(geocode.get("address"));
+				if(null != geocode){
+					warn.setAddress(geocode.get("address"));
+				}
 			}
 			switch (vo.getResult()) {
 				case 0x00:
@@ -118,17 +134,58 @@
 					warn.setTreatmentState("将来处理");
 					break;
 			}
+			if(0x00 != vo.getResult() && null == warn.getTreatmentTime()){
+				UPWarnMsgOperationInfoVo upWarnMsgOperationInfoVo = upWarnMsgOperationInfoClient.getUPWarnMsgOperationInfo(warn.getObjectId()).getData();
+				if(null != upWarnMsgOperationInfoVo){
+					warn.setTreatmentUser(upWarnMsgOperationInfoVo.getOperator());
+					warn.setTreatmentTime(LocalDateTime.ofEpochSecond(upWarnMsgOperationInfoVo.getCreateTime(), 0, ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+					switch (upWarnMsgOperationInfoVo.getMethod()) {
+						case 0x01:
+							warn.setTreatmentRemark("快速拍照");
+							break;
+						case 0x02:
+							warn.setTreatmentRemark("语音下发");
+							break;
+						case 0x03:
+							warn.setTreatmentRemark("不做处理");
+							break;
+						case 0x04:
+							warn.setTreatmentRemark("其他");
+							break;
+						default:
+							warn.setTreatmentRemark("其他");
+							break;
+					}
+				}
+			}
 			warn.setCreateTime(LocalDateTime.now());
 			warn.setObjectId(vo.getInfoId());
 			warn.setVehicleNumber(vo.getVehicleNo());
-			warns.add(warn);
-		}
-		if (warns.size() > 0) {
-			this.saveBatch(warns);
+			warn.setPicUrl(vo.getPicUrl());
+
+			List<Warn> list2 = this.list(new LambdaQueryWrapper<Warn>().eq(Warn::getObjectId, vo.getInfoId()));
+
+			if (!list2.isEmpty()) {
+				Warn warn1 = list2.get(0);
+				// 比较2个时间大小
+				String startTime = warn1.getStartTime();
+				String startTime1 = warn.getStartTime();
+                if (DateUtils.parseDate(startTime).getTime()>DateUtils.parseDate(startTime1).getTime()) {
+                    warn1.setStartTime(startTime1);
+					warn1.setEndTime(startTime);
+                }else {
+					warn1.setEndTime(startTime1);
+				}
+				this.updateById(warn1);
+			}else {
+				this.save(warn);
+			}
+
 		}
 	}
-	
-	
+
+
+
 	/**
 	 * 定时保存车辆id和司机id
 	 */
@@ -163,8 +220,14 @@
 	public void taskUpdateWarnStatus() {
 		List<Warn> warnList = this.list(new LambdaQueryWrapper<Warn>().eq(Warn::getTreatmentState, "处理中"));
 		for (Warn warn : warnList) {
+			if(null == warn.getObjectId()){
+				continue;
+			}
 			UPWarnMsgAdptInfoVo vo = upWarnMsgAdptInfoClient.findByInfoId(warn.getObjectId()).getData();
-			if (null != vo && null != warn && vo.getResult() != 0x00) {
+			if(null == vo){
+				continue;
+			}
+			if (null != warn && vo.getResult() != 0x00) {
 				switch (vo.getResult()) {
 					case 0x00:
 						warn.setTreatmentState("处理中");
@@ -179,8 +242,35 @@
 						warn.setTreatmentState("将来处理");
 						break;
 				}
-				this.updateById(warn);
 			}
+			if(null == warn.getPicUrl()){
+				warn.setPicUrl(vo.getPicUrl());
+			}
+			if(0x00 != vo.getResult()){
+				UPWarnMsgOperationInfoVo upWarnMsgOperationInfoVo = upWarnMsgOperationInfoClient.getUPWarnMsgOperationInfo(warn.getObjectId()).getData();
+				if(null != upWarnMsgOperationInfoVo){
+					warn.setTreatmentUser(upWarnMsgOperationInfoVo.getOperator());
+					warn.setTreatmentTime(LocalDateTime.ofEpochSecond(upWarnMsgOperationInfoVo.getCreateTime(), 0, ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+					switch (upWarnMsgOperationInfoVo.getMethod()) {
+						case 0x01:
+							warn.setTreatmentRemark("快速拍照");
+							break;
+						case 0x02:
+							warn.setTreatmentRemark("语音下发");
+							break;
+						case 0x03:
+							warn.setTreatmentRemark("不做处理");
+							break;
+						case 0x04:
+							warn.setTreatmentRemark("其他");
+							break;
+						default:
+							warn.setTreatmentRemark("其他");
+							break;
+					}
+				}
+			}
+			this.updateById(warn);
 		}
 		
 	}
@@ -196,19 +286,21 @@
 	public PageInfo<CarWarnListResp> getCarWarnList(CarWarnListReq carWarnListReq) {
 		PageInfo<CarWarnListResp> pageInfo = new PageInfo<>(carWarnListReq.getPageCurr(), carWarnListReq.getPageSize());
 		String warnType = carWarnListReq.getWarnType();
-		switch (warnType) {
-			case "前向碰撞报警":
-				carWarnListReq.setWarnTypes(Arrays.asList("前向碰撞报警", "碰撞预警"));
-				break;
-			case "车道偏离报警":
-				carWarnListReq.setWarnTypes(Arrays.asList("车道偏离报警", "偏离路线报警", "车道偏离报警"));
-				break;
-			case "疲劳驾驶报警":
-				carWarnListReq.setWarnTypes(Arrays.asList("疲劳驾驶报警", "疲劳驾驶报警(生理疲劳)"));
-				break;
-			default:
-				carWarnListReq.setWarnTypes(Arrays.asList(warnType));
-				break;
+		if(StringUtils.isNotEmpty(warnType)){
+			switch (warnType) {
+				case "前向碰撞报警":
+					carWarnListReq.setWarnTypes(Arrays.asList("前向碰撞报警", "碰撞预警"));
+					break;
+				case "车道偏离报警":
+					carWarnListReq.setWarnTypes(Arrays.asList("车道偏离报警", "偏离路线报警", "车道偏离报警"));
+					break;
+				case "疲劳驾驶报警":
+					carWarnListReq.setWarnTypes(Arrays.asList("疲劳驾驶报警", "疲劳驾驶报警(生理疲劳)"));
+					break;
+				default:
+					carWarnListReq.setWarnTypes(Arrays.asList(warnType));
+					break;
+			}
 		}
 		return this.baseMapper.getCarWarnList(pageInfo, carWarnListReq);
 	}
@@ -271,7 +363,7 @@
 			if(total == 0){
 				map.put("rate", BigDecimal.ZERO);
 			}else{
-				map.put("rate", BigDecimal.valueOf(processed / total * 100).setScale(2, RoundingMode.HALF_EVEN));
+				map.put("rate", new BigDecimal(processed).divide(new BigDecimal(total), 4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN));
 			}
 		}
 		return allWarnGroupVehicleType;

--
Gitblit v1.7.1