Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
zhaoxianglong 8 months ago
parent
commit
10aa6a6b5a
  1. 28
      ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java
  2. 7
      zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java
  3. 16
      zc-business/src/main/java/com/zc/business/controller/VideoController.java
  4. 2
      zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java
  5. 9
      zc-business/src/main/java/com/zc/business/mapper/DcStakeMarkMapper.java
  6. 11
      zc-business/src/main/java/com/zc/business/service/IDcStakeMarkService.java
  7. 70
      zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java
  8. 4
      zc-business/src/main/java/com/zc/business/statistics/cache/DailyTrafficStatisticsCache.java
  9. 4
      zc-business/src/main/java/com/zc/business/statistics/cache/MonthlyTrafficStatisticsCache.java
  10. 4
      zc-business/src/main/java/com/zc/business/statistics/cache/QuarterlyTrafficStatisticsCache.java
  11. 4
      zc-business/src/main/java/com/zc/business/statistics/cache/YearlyTrafficStatisticsCache.java
  12. 41
      zc-business/src/main/resources/mapper/business/DcStakeMarkMapper.xml

28
ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java

@ -2,15 +2,33 @@ package com.ruoyi.common.utils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.regex.Pattern;
/** /**
* @Description 桩号计算工具 * @Description 桩号工具
* *
* @author liuwenge * @author liuwenge
* @date 2024/1/17 14:43 * @date 2024/1/17 14:43
*/ */
public class StakeMarkUtils { public class StakeMarkUtils {
/**
* @Description 桩号格式校验
*
* 正确格式: K060+010
* @author liuwenge
* @date 2024/3/22 20:05
* @param stakeMark
* @return boolean
*/
public static boolean checkStakeMark(String stakeMark){
if (StringUtils.isEmpty(stakeMark)){
return false;
}
Pattern pattern = Pattern.compile("^K\\d{3}\\+\\d{3}$");
return pattern.matcher(stakeMark).matches();
}
/** /**
* @Description 桩号转公里数 * @Description 桩号转公里数
* *
@ -20,7 +38,7 @@ public class StakeMarkUtils {
* @return 公里数:123.123 * @return 公里数:123.123
*/ */
public static String formatKilometre(String stakeMark){ public static String formatKilometre(String stakeMark){
if (StringUtils.isEmpty(stakeMark)){ if (!checkStakeMark(stakeMark)){
return ""; return "";
} }
return stakeMark.toLowerCase().replace("k","").replace("+","."); return stakeMark.toLowerCase().replace("k","").replace("+",".");
@ -35,7 +53,7 @@ public class StakeMarkUtils {
* @return 公里数:123123 * @return 公里数:123123
*/ */
public static String formatMetre(String stakeMark){ public static String formatMetre(String stakeMark){
if (StringUtils.isEmpty(stakeMark)){ if (!checkStakeMark(stakeMark)){
return ""; return "";
} }
return stakeMark.toLowerCase().replace("k","").replace("+",""); return stakeMark.toLowerCase().replace("k","").replace("+","");
@ -51,7 +69,7 @@ public class StakeMarkUtils {
* @return java.math.BigDecimal 距离 * @return java.math.BigDecimal 距离
*/ */
public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){ public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){
if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); String start = startStakeMark.toLowerCase().replace("k","").replace("+",".");
@ -75,7 +93,7 @@ public class StakeMarkUtils {
* @return java.math.BigDecimal 距离 * @return java.math.BigDecimal 距离
*/ */
public static BigDecimal getMetre(String startStakeMark, String endStakeMark){ public static BigDecimal getMetre(String startStakeMark, String endStakeMark){
if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); String start = startStakeMark.toLowerCase().replace("k","").replace("+",".");

7
zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -112,4 +113,10 @@ public class DcStakeMarkController extends BaseController {
return toAjax(dcStakeMarkService.removeStakeMark(ids)); return toAjax(dcStakeMarkService.removeStakeMark(ids));
} }
@ApiOperation("根据json文件路径导入桩号")
@PostMapping("importStakeMarkByJsonFilePath")
public AjaxResult importJsonStakeMark(String filePath) throws IOException {
return dcStakeMarkService.importJsonStakeMark(filePath);
}
} }

16
zc-business/src/main/java/com/zc/business/controller/VideoController.java

@ -22,6 +22,7 @@ import io.swagger.annotations.ApiParam;
import okhttp3.Response; import okhttp3.Response;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -71,17 +72,15 @@ public class VideoController extends BaseController {
// 组织机构id // 组织机构id
private final static String CAM_DEPT_ID = "1301730"; private final static String CAM_DEPT_ID = "1301730";
@PostConstruct
public void init() {
synchronizeIotIds();
}
/** /**
* 同步物联网ID * 同步物联网ID
* 该方法用于查询未同步物联网ID的摄像头设备信息并从外部API获取这些设备的详细信息然后更新它们的物联网ID * 该方法用于查询未同步物联网ID的摄像头设备信息并从外部API获取这些设备的详细信息然后更新它们的物联网ID
* 该过程主要涉及查询未初始化物联网ID的摄像头构建设备IP与设备映射从API获取设备详细信息以及批量更新设备的物联网ID * 该过程主要涉及查询未初始化物联网ID的摄像头构建设备IP与设备映射从API获取设备详细信息以及批量更新设备的物联网ID
*/ */
public void synchronizeIotIds() { @ApiOperation("同步监控摄像设备ID")
@PatchMapping(value = "/sync/id")
public AjaxResult synchronizeIotIds() {
// 查询未同步物联ID的摄像头设备信息 // 查询未同步物联ID的摄像头设备信息
LambdaQueryWrapper<DcDevice> query = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DcDevice> query = new LambdaQueryWrapper<>();
query.eq(DcDevice::getDeviceType, DeviceTypeConstants.CAMERA) query.eq(DcDevice::getDeviceType, DeviceTypeConstants.CAMERA)
@ -90,7 +89,7 @@ public class VideoController extends BaseController {
List<DcDevice> uninitializedCameras = iDcDeviceService.list(query); List<DcDevice> uninitializedCameras = iDcDeviceService.list(query);
if (uninitializedCameras.isEmpty()) { if (uninitializedCameras.isEmpty()) {
return; // 若无待同步设备,则直接返回 return AjaxResult.success("没有需要同步的设备"); // 若无待同步设备,则直接返回
} }
// 将未初始化的摄像头列表转换为Map,以设备的桩号、方向和子类型拼接作为键,设备本身作为值 // 将未初始化的摄像头列表转换为Map,以设备的桩号、方向和子类型拼接作为键,设备本身作为值
@ -109,7 +108,7 @@ public class VideoController extends BaseController {
JSONObject camApiResponse = getCamByDept(CAM_DEPT_ID); JSONObject camApiResponse = getCamByDept(CAM_DEPT_ID);
if (camApiResponse == null || !camApiResponse.containsKey("data")) { if (camApiResponse == null || !camApiResponse.containsKey("data")) {
return; // 如果获取信息失败或不含有效数据,直接返回 return AjaxResult.error("根据组织机构获取摄像机信息失败"); // 如果获取信息失败或不含有效数据,直接返回
} }
JSONArray camDataArray = camApiResponse.getJSONArray("data"); JSONArray camDataArray = camApiResponse.getJSONArray("data");
@ -138,9 +137,12 @@ public class VideoController extends BaseController {
// 批量更新摄像头设备的物联ID // 批量更新摄像头设备的物联ID
iDcDeviceService.updateBatchById(devicesToUpdate); iDcDeviceService.updateBatchById(devicesToUpdate);
return AjaxResult.success("同步物联ID成功", devicesToUpdate);
} catch (Exception e) { } catch (Exception e) {
logger.error("获取摄像头信息失败!", e); logger.error("获取摄像头信息失败!", e);
} }
return AjaxResult.error("同步物联ID失败");
} }
/** /**

2
zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java

@ -29,5 +29,7 @@ public class DcStakeMark {
private Date updateTime; private Date updateTime;
@ApiModelProperty("所属辖区") @ApiModelProperty("所属辖区")
private Long sectionId; private Long sectionId;
@ApiModelProperty("桩号里程")
private Long mileage;
} }

9
zc-business/src/main/java/com/zc/business/mapper/DcStakeMarkMapper.java

@ -1,14 +1,21 @@
package com.zc.business.mapper; package com.zc.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcStakeMark; import com.zc.business.domain.DcStakeMark;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* 桩号Mapper接口 * 桩号Mapper接口
* *
* @author zhaoxianglong * @author
*/ */
@Mapper @Mapper
public interface DcStakeMarkMapper extends BaseMapper<DcStakeMark> { public interface DcStakeMarkMapper extends BaseMapper<DcStakeMark> {
boolean batchInsert(List<DcStakeMark> dcStakeMarkList);
} }

11
zc-business/src/main/java/com/zc/business/service/IDcStakeMarkService.java

@ -2,8 +2,10 @@ package com.zc.business.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcStakeMark; import com.zc.business.domain.DcStakeMark;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -60,4 +62,13 @@ public interface IDcStakeMarkService extends IService<DcStakeMark> {
* @return 设备信息 * @return 设备信息
*/ */
DcStakeMark getStakeMark(String id); DcStakeMark getStakeMark(String id);
/**
* 导入桩号
*
* @param filePath json文件路径
* @return
*/
AjaxResult importJsonStakeMark(String filePath) throws IOException;
} }

70
zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java

@ -1,19 +1,24 @@
package com.zc.business.service.impl; package com.zc.business.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.StakeMarkUtils;
import com.zc.business.domain.DcStakeMark; import com.zc.business.domain.DcStakeMark;
import com.zc.business.mapper.DcStakeMarkMapper; import com.zc.business.mapper.DcStakeMarkMapper;
import com.zc.business.service.IDcStakeMarkService; import com.zc.business.service.IDcStakeMarkService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.Date; import javax.annotation.Resource;
import java.util.List; import java.io.*;
import java.util.Objects; import java.util.*;
import java.util.regex.Pattern;
/** /**
* 桩号Service业务层处理 * 桩号Service业务层处理
@ -23,6 +28,8 @@ import java.util.Objects;
@Service @Service
public class DcStakeMarkServiceImpl extends ServiceImpl<DcStakeMarkMapper, DcStakeMark> implements IDcStakeMarkService { public class DcStakeMarkServiceImpl extends ServiceImpl<DcStakeMarkMapper, DcStakeMark> implements IDcStakeMarkService {
@Resource
private DcStakeMarkMapper dcStakeMarkMapper;
public LambdaQueryWrapper<DcStakeMark> stakeMarkQueryWrapper(DcStakeMark dcStakeMark) { public LambdaQueryWrapper<DcStakeMark> stakeMarkQueryWrapper(DcStakeMark dcStakeMark) {
@ -125,5 +132,62 @@ public class DcStakeMarkServiceImpl extends ServiceImpl<DcStakeMarkMapper, DcSta
return getById(id); return getById(id);
} }
/**
* @Description 导入桩号
*
* @author liuwenge
* @date 2024/3/22 11:16
* @param filePath json文件路径
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult importJsonStakeMark(String filePath) throws IOException {
Date methodStart = new Date();
File file = new File(filePath);
FileReader fileReader = new FileReader(file);
Reader reader = new InputStreamReader(new FileInputStream(file), "Utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
String jsonStr = sb.toString();
Map<String, Map<String,Object>> map = JSON.parseObject(jsonStr, new TypeReference<HashMap<String, Map<String,Object>>>() {});
List<DcStakeMark> stakeMarkList = new ArrayList<>();
//桩号格式校验
List<String> errorKey = new ArrayList<>();
map.keySet().forEach(key ->{
if (!StakeMarkUtils.checkStakeMark(key)){
errorKey.add(key);
}
DcStakeMark dcStakeMark = new DcStakeMark();
dcStakeMark.setStakeMark(key);
dcStakeMark.setLongitude(map.get(key).containsKey("lng") ? map.get(key).get("lng").toString() : "");
dcStakeMark.setLatitude(map.get(key).containsKey("lat") ? map.get(key).get("lat").toString() : "");
dcStakeMark.setDirection("1");
dcStakeMark.setSectionId(1L);
dcStakeMark.setMileage(Long.valueOf(StakeMarkUtils.formatMetre(key)));
stakeMarkList.add(dcStakeMark);
});
if (errorKey.size() > 0){
return AjaxResult.error("桩号格式错误",errorKey);
}
Date databaseStart = new Date();
Long time = databaseStart.getTime() - methodStart.getTime();
System.out.println("处理数据用时---------------------------------->" + time);
dcStakeMarkMapper.batchInsert(stakeMarkList);
Long endTime = new Date().getTime() - databaseStart.getTime();
System.out.println("导入数据库用时--------------------------------->" + endTime);
return AjaxResult.success();
}
} }

4
zc-business/src/main/java/com/zc/business/statistics/cache/DailyTrafficStatisticsCache.java

@ -70,7 +70,9 @@ public class DailyTrafficStatisticsCache extends AbstractTrafficStatisticsCache
// 更新统计日期 // 更新统计日期
dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.DAY); dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.DAY);
// 将新数据添加到数据列表中 // 移除旧数据
instance.getData().remove(dcTrafficSectionData);
// 添加数据
instance.getData().add(dcTrafficSectionData); instance.getData().add(dcTrafficSectionData);
} }

4
zc-business/src/main/java/com/zc/business/statistics/cache/MonthlyTrafficStatisticsCache.java

@ -70,7 +70,9 @@ public class MonthlyTrafficStatisticsCache extends AbstractTrafficStatisticsCach
// 更新统计日期 // 更新统计日期
dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.MONTH); dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.MONTH);
// 将新数据添加到数据列表中 // 移除旧数据
instance.getData().remove(dcTrafficSectionData);
// 添加数据
instance.getData().add(dcTrafficSectionData); instance.getData().add(dcTrafficSectionData);
} }

4
zc-business/src/main/java/com/zc/business/statistics/cache/QuarterlyTrafficStatisticsCache.java

@ -73,7 +73,9 @@ public class QuarterlyTrafficStatisticsCache extends AbstractTrafficStatisticsCa
// 更新统计日期 // 更新统计日期
dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.QUARTER); dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.QUARTER);
// 将新数据添加到数据列表中 // 移除旧数据
instance.getData().remove(dcTrafficSectionData);
// 添加数据
instance.getData().add(dcTrafficSectionData); instance.getData().add(dcTrafficSectionData);
} }

4
zc-business/src/main/java/com/zc/business/statistics/cache/YearlyTrafficStatisticsCache.java

@ -73,7 +73,9 @@ public class YearlyTrafficStatisticsCache extends AbstractTrafficStatisticsCache
// 更新统计日期 // 更新统计日期
dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.YEAR); dcTrafficSectionData.setStatisticalDate(dcTrafficSectionData.getStatisticalDate(), TrafficDataPeriodTypeEnum.YEAR);
// 将新数据添加到数据列表中 // 移除旧数据
instance.getData().remove(dcTrafficSectionData);
// 添加数据
instance.getData().add(dcTrafficSectionData); instance.getData().add(dcTrafficSectionData);
} }

41
zc-business/src/main/resources/mapper/business/DcStakeMarkMapper.xml

@ -0,0 +1,41 @@
<?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.zc.business.mapper.DcStakeMarkMapper">
<insert id="batchInsert" parameterType="List">
<foreach collection ="list" item="dcStakeMark" index= "index" separator =";">
insert into dc_stake_mark
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="dcStakeMark.stakeMark != null">stake_mark,</if>
<if test="dcStakeMark.longitude != null">longitude,</if>
<if test="dcStakeMark.latitude != null">latitude,</if>
<if test="dcStakeMark.direction != null">direction,</if>
<if test="dcStakeMark.sectionId != null">section_id,</if>
<if test="dcStakeMark.mileage != null">mileage,</if>
create_time,
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="dcStakeMark.stakeMark != null">#{dcStakeMark.stakeMark},</if>
<if test="dcStakeMark.longitude != null">#{dcStakeMark.longitude},</if>
<if test="dcStakeMark.latitude != null">#{dcStakeMark.latitude},</if>
<if test="dcStakeMark.direction != null">#{dcStakeMark.direction},</if>
<if test="dcStakeMark.sectionId != null">#{dcStakeMark.sectionId},</if>
<if test="dcStakeMark.mileage != null">#{dcStakeMark.mileage},</if>
now(),
</trim>
ON DUPLICATE KEY UPDATE
<trim suffixOverrides=",">
<if test="dcStakeMark.stakeMark != null">stake_mark = #{dcStakeMark.stakeMark},</if>
<if test="dcStakeMark.longitude != null">longitude = #{dcStakeMark.longitude},</if>
<if test="dcStakeMark.latitude != null">latitude = #{dcStakeMark.latitude},</if>
<if test="dcStakeMark.direction != null">direction = #{dcStakeMark.direction},</if>
<if test="dcStakeMark.sectionId != null">section_id = #{dcStakeMark.sectionId},</if>
<if test="dcStakeMark.mileage != null">mileage = #{dcStakeMark.mileage},</if>
update_time = now(),
</trim>
</foreach>
</insert>
</mapper>
Loading…
Cancel
Save