From a05b419384e148fc950c77553816a2d05144f4ae Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 19 六月 2025 19:36:22 +0800
Subject: [PATCH] 修改生产环境配置

---
 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WarnServiceImpl.java |  304 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 298 insertions(+), 6 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 4bd54e6..cfded91 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
@@ -1,16 +1,36 @@
 package com.ruoyi.system.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+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;
 import com.ruoyi.system.api.model.Warn;
 import com.ruoyi.system.mapper.WarnMapper;
 import com.ruoyi.system.query.CarWarnListReq;
 import com.ruoyi.system.query.CarWarnListResp;
+import com.ruoyi.system.service.ICarService;
+import com.ruoyi.system.service.IDriverService;
+import com.ruoyi.system.service.IEnterpriseService;
 import com.ruoyi.system.service.IWarnService;
+import com.ruoyi.system.util.GDMapGeocodingUtil;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-import java.util.Map;
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 
 
 /**
@@ -19,6 +39,208 @@
  */
 @Service
 public class WarnServiceImpl extends ServiceImpl<WarnMapper, Warn> implements IWarnService {
+	
+	@Resource
+	private UPWarnMsgAdptInfoClient upWarnMsgAdptInfoClient;
+	
+	@Resource
+	private IEnterpriseService enterpriseService;
+	
+	@Resource
+	private IDriverService driverService;
+	
+	@Resource
+	private ICarService carService;
+	
+	@Resource
+	private UPWarnMsgOperationInfoClient upWarnMsgOperationInfoClient;
+	
+	
+	/**
+	 * 存储新的报警数据
+	 */
+	@Override
+	public void taskSaveNewWarn() {
+		Warn warn = this.getOne(new LambdaQueryWrapper<Warn>().orderByDesc(Warn::getCreateTime).last(" limit 1"));
+		Long createTime = -1L;
+		if (null != warn) {
+			createTime = warn.getCreateTime().toEpochSecond(ZoneOffset.ofHours(8));
+		}
+		List<UPWarnMsgAdptInfoVo> list = upWarnMsgAdptInfoClient.findByCreateTimeAfter(createTime).getData();
+		if (null == list || list.isEmpty()) {
+			return;
+		}
+		List<Enterprise> list1 = enterpriseService.list();
+		List<Driver> driverList = driverService.list(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1));
+		List<Car> carList = carService.list();
+		List<Warn> warns = new ArrayList<>();
+		for (UPWarnMsgAdptInfoVo vo : list) {
+			String warnTypeName = WarnType.getWarnTypeName(vo.getWarnType());
+			warn = new Warn();
+			Optional<Car> carOptional = carList.stream().filter(s -> s.getVehicleNumber().equals(vo.getVehicleNo())).findFirst();
+			if (carOptional.isPresent()) {
+				Car car = carOptional.get();
+				if(car.getOperateType().equals("出租车") && StringUtils.isNotEmpty(warnTypeName) && "疲劳驾驶报警".equals(warnTypeName)){
+					continue;
+				}
+				warn.setCarId(car.getId());
+			}
+			Optional<Driver> optional = driverList.stream().filter(s -> s.getVehicleNumber().equals(vo.getVehicleNo())).findFirst();
+			if (optional.isPresent()) {
+				warn.setDriverId(optional.get().getId());
+			}
+			Enterprise enterprise = list1.stream().filter(s -> s.getCode().equals(vo.getInferiorPlatformId().toString())).findFirst().get();
+			warn.setEnterpriseId(enterprise.getId());
+			warn.setStartTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(vo.getCreateTime() * 1000), ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+			warn.setEndTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(vo.getCreateTime() * 1000), ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+			warn.setWarnType(warnTypeName);
+			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());
+			}
+			if(null != vo.getLatitude() && 0 != vo.getLatitude()){
+				warn.setLatitude(new BigDecimal(vo.getLatitude()).divide(new BigDecimal(1000000)).toString());
+				Map<String, String> geocode = null;
+				try {
+					geocode = GDMapGeocodingUtil.geocode(warn.getLongitude(), warn.getLatitude());
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+				warn.setAddress(geocode.get("address"));
+			}
+			switch (vo.getResult()) {
+				case 0x00:
+					warn.setTreatmentState("处理中");
+					break;
+				case 0x01:
+					warn.setTreatmentState("已处理完毕");
+					break;
+				case 0x02:
+					warn.setTreatmentState("不作处理");
+					break;
+				case 0x03:
+					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());
+			warn.setPicUrl(vo.getPicUrl());
+			warns.add(warn);
+		}
+		if (warns.size() > 0) {
+			this.saveBatch(warns);
+		}
+	}
+	
+	
+	/**
+	 * 定时保存车辆id和司机id
+	 */
+	@Override
+	public void taskSaveCarIdAndDriverId() {
+		List<Warn> list = this.list(new LambdaQueryWrapper<Warn>().isNull(Warn::getCarId).or().isNull(Warn::getDriverId));
+		List<Car> carList = carService.list();
+		List<Driver> driverList = driverService.list(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1));
+		for (Warn warn : list) {
+			Optional<Driver> optional = driverList.stream().filter(s -> s.getVehicleNumber().equals(warn.getVehicleNumber())).findFirst();
+			if (optional.isPresent()) {
+				warn.setDriverId(optional.get().getId());
+				this.updateById(warn);
+			}
+			Optional<Car> optional1 = carList.stream().filter(s -> s.getVehicleNumber().equals(warn.getVehicleNumber())).findFirst();
+			if (optional1.isPresent()) {
+				Car car = optional1.get();
+				if(car.getOperateType().equals("出租车") && "疲劳驾驶报警".equals(warn.getWarnType())){
+					this.removeById(warn.getId());
+					continue;
+				}
+				warn.setCarId(optional1.get().getId());
+				this.updateById(warn);
+			}
+		}
+	}
+	
+	/**
+	 * 定时任务修改预警信息处理结果
+	 */
+	@Override
+	public void taskUpdateWarnStatus() {
+		List<Warn> warnList = this.list(new LambdaQueryWrapper<Warn>().eq(Warn::getTreatmentState, "处理中"));
+		for (Warn warn : warnList) {
+			UPWarnMsgAdptInfoVo vo = upWarnMsgAdptInfoClient.findByInfoId(warn.getObjectId()).getData();
+			if (null != vo && null != warn && vo.getResult() != 0x00) {
+				switch (vo.getResult()) {
+					case 0x00:
+						warn.setTreatmentState("处理中");
+						break;
+					case 0x01:
+						warn.setTreatmentState("已处理完毕");
+						break;
+					case 0x02:
+						warn.setTreatmentState("不作处理");
+						break;
+					case 0x03:
+						warn.setTreatmentState("将来处理");
+						break;
+				}
+			}
+			if(null == warn.getPicUrl()){
+				warn.setPicUrl(vo.getPicUrl());
+			}
+			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;
+					}
+				}
+			}
+			this.updateById(warn);
+		}
+		
+	}
 	
 	
 	/**
@@ -29,11 +251,38 @@
 	 */
 	@Override
 	public PageInfo<CarWarnListResp> getCarWarnList(CarWarnListReq carWarnListReq) {
-		PageInfo<CarWarnListResp> pageInfo = new PageInfo<>(carWarnListReq.getPageCurr(), carWarnListReq.getPageCurr());
+		PageInfo<CarWarnListResp> pageInfo = new PageInfo<>(carWarnListReq.getPageCurr(), carWarnListReq.getPageSize());
+		String warnType = carWarnListReq.getWarnType();
+		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);
 	}
-	
-	
+
+
+	/**
+	 * 获取所有报警数据
+	 * @param carWarnListReq
+	 * @return
+	 */
+	@Override
+	public List<Warn> getAllCarWarnList(CarWarnListReq carWarnListReq) {
+		return this.baseMapper.getAllCarWarnList(carWarnListReq);
+	}
+
 	/**
 	 * 获取预警汇总统计最高的10类报警数据
 	 *
@@ -41,6 +290,49 @@
 	 */
 	@Override
 	public List<Map<String, Object>> getWarnGroupCount() {
-		return this.baseMapper.getWarnGroupCount();
+		List<Map<String, Object>> list = this.baseMapper.getWarnGroup10Count();
+		List<String> collect = new ArrayList<>();
+		for (Map<String, Object> map : list) {
+			collect.add(map.get("warnType").toString());
+		}
+		if (!collect.isEmpty()) {
+			List<Map<String, Object>> warnGroupCount = this.baseMapper.getWarnGroupCount(collect);
+			Integer num = Integer.valueOf(warnGroupCount.get(0).get("num").toString());
+			if(num > 0){
+				list.addAll(warnGroupCount);
+			}
+		}
+		return list;
+	}
+	
+	
+	/**
+	 * 获取预警汇总前10排行榜
+	 *
+	 * @return
+	 */
+	@Override
+	public List<Map<String, Object>> getWarnGroupCountTop10() {
+		return this.baseMapper.getWarnGroupCountTop10();
+	}
+
+
+	/**
+	 * 获取根据车辆类型的报警汇总数据
+	 * @return
+	 */
+	@Override
+	public List<Map<String, Object>> getAllWarnGroupVehicleType() {
+		List<Map<String, Object>> allWarnGroupVehicleType = this.baseMapper.getAllWarnGroupVehicleType();
+		for (Map<String, Object> map : allWarnGroupVehicleType) {
+			Integer total = Integer.valueOf(map.get("total").toString());
+			Integer processed = Integer.valueOf(map.get("processed").toString());
+			if(total == 0){
+				map.put("rate", BigDecimal.ZERO);
+			}else{
+				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