From 836986b24178f54d1d739b6f5cf729c6546412e0 Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Fri, 22 Mar 2024 21:23:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=AD=E9=9D=A2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BD=A6=E6=B5=81=E9=87=8F=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../statistics/cache/DailyTrafficStatisticsCache.java | 4 +++- .../statistics/cache/MonthlyTrafficStatisticsCache.java | 4 +++- .../statistics/cache/QuarterlyTrafficStatisticsCache.java | 4 +++- .../statistics/cache/YearlyTrafficStatisticsCache.java | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/statistics/cache/DailyTrafficStatisticsCache.java b/zc-business/src/main/java/com/zc/business/statistics/cache/DailyTrafficStatisticsCache.java index 043bbada..b3b600da 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/cache/DailyTrafficStatisticsCache.java +++ b/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); - // 将新数据添加到数据列表中 + // 移除旧数据 + instance.getData().remove(dcTrafficSectionData); + // 添加数据 instance.getData().add(dcTrafficSectionData); } diff --git a/zc-business/src/main/java/com/zc/business/statistics/cache/MonthlyTrafficStatisticsCache.java b/zc-business/src/main/java/com/zc/business/statistics/cache/MonthlyTrafficStatisticsCache.java index 0d3d5956..28c6f83a 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/cache/MonthlyTrafficStatisticsCache.java +++ b/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); - // 将新数据添加到数据列表中 + // 移除旧数据 + instance.getData().remove(dcTrafficSectionData); + // 添加数据 instance.getData().add(dcTrafficSectionData); } diff --git a/zc-business/src/main/java/com/zc/business/statistics/cache/QuarterlyTrafficStatisticsCache.java b/zc-business/src/main/java/com/zc/business/statistics/cache/QuarterlyTrafficStatisticsCache.java index 5b4d5ef0..ea3bc677 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/cache/QuarterlyTrafficStatisticsCache.java +++ b/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); - // 将新数据添加到数据列表中 + // 移除旧数据 + instance.getData().remove(dcTrafficSectionData); + // 添加数据 instance.getData().add(dcTrafficSectionData); } diff --git a/zc-business/src/main/java/com/zc/business/statistics/cache/YearlyTrafficStatisticsCache.java b/zc-business/src/main/java/com/zc/business/statistics/cache/YearlyTrafficStatisticsCache.java index 8b21f675..7b5147f4 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/cache/YearlyTrafficStatisticsCache.java +++ b/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); - // 将新数据添加到数据列表中 + // 移除旧数据 + instance.getData().remove(dcTrafficSectionData); + // 添加数据 instance.getData().add(dcTrafficSectionData); } From f99021d9f942882c194d46d7b1d3cf726e93423e Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Fri, 22 Mar 2024 21:36:56 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=A1=A9=E5=8F=B7=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcStakeMarkController.java | 7 ++ .../com/zc/business/domain/DcStakeMark.java | 2 + .../zc/business/mapper/DcStakeMarkMapper.java | 9 +- .../business/service/IDcStakeMarkService.java | 11 +++ .../service/impl/DcStakeMarkServiceImpl.java | 84 ++++++++++++++++++- .../mapper/business/DcStakeMarkMapper.xml | 41 +++++++++ 6 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 zc-business/src/main/resources/mapper/business/DcStakeMarkMapper.xml diff --git a/zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java b/zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java index 12b3a390..b926ae3f 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java +++ b/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.validation.Valid; +import java.io.IOException; import java.util.List; /** @@ -112,4 +113,10 @@ public class DcStakeMarkController extends BaseController { return toAjax(dcStakeMarkService.removeStakeMark(ids)); } + @ApiOperation("根据json文件路径导入桩号") + @PostMapping("importStakeMarkByJsonFilePath") + public AjaxResult importJsonStakeMark(String filePath) throws IOException { + return dcStakeMarkService.importJsonStakeMark(filePath); + } + } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java b/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java index 123c57cd..8370ee64 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcStakeMark.java @@ -29,5 +29,7 @@ public class DcStakeMark { private Date updateTime; @ApiModelProperty("所属辖区") private Long sectionId; + @ApiModelProperty("桩号里程") + private Long mileage; } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcStakeMarkMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcStakeMarkMapper.java index 448050c3..bc949499 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcStakeMarkMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcStakeMarkMapper.java @@ -1,14 +1,21 @@ package com.zc.business.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcStakeMark; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 桩号Mapper接口 * - * @author zhaoxianglong + * @author */ @Mapper public interface DcStakeMarkMapper extends BaseMapper { + + + boolean batchInsert(List dcStakeMarkList); + } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcStakeMarkService.java b/zc-business/src/main/java/com/zc/business/service/IDcStakeMarkService.java index 8390bd34..f508f7dc 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcStakeMarkService.java +++ b/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.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcStakeMark; +import java.io.IOException; import java.util.List; /** @@ -60,4 +62,13 @@ public interface IDcStakeMarkService extends IService { * @return 设备信息 */ DcStakeMark getStakeMark(String id); + + + /** + * 导入桩号 + * + * @param filePath json文件路径 + * @return + */ + AjaxResult importJsonStakeMark(String filePath) throws IOException; } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java index 3dacb227..7c8c3974 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java @@ -1,19 +1,24 @@ 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.extension.service.impl.ServiceImpl; import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.PageUtils; +import com.ruoyi.common.utils.StakeMarkUtils; import com.zc.business.domain.DcStakeMark; import com.zc.business.mapper.DcStakeMarkMapper; import com.zc.business.service.IDcStakeMarkService; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import javax.annotation.Resource; +import java.io.*; +import java.util.*; +import java.util.regex.Pattern; /** * 桩号Service业务层处理 @@ -23,6 +28,8 @@ import java.util.Objects; @Service public class DcStakeMarkServiceImpl extends ServiceImpl implements IDcStakeMarkService { + @Resource + private DcStakeMarkMapper dcStakeMarkMapper; public LambdaQueryWrapper stakeMarkQueryWrapper(DcStakeMark dcStakeMark) { @@ -125,5 +132,76 @@ public class DcStakeMarkServiceImpl extends ServiceImpl> map = JSON.parseObject(jsonStr, new TypeReference>>() {}); + List stakeMarkList = new ArrayList<>(); + + //桩号格式校验 + List errorKey = new ArrayList<>(); + map.keySet().forEach(key ->{ + if (!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(); + } + + /** + * @Description 桩号格式校验 + * + * 正确格式: K060+010 + * @author liuwenge + * @date 2024/3/22 20:05 + * @param stakeMark + * @return boolean + */ + private boolean checkStakeMark(String stakeMark){ + Pattern pattern = Pattern.compile("^K\\d{3}\\+\\d{3}$"); + return pattern.matcher(stakeMark).matches(); + } + } diff --git a/zc-business/src/main/resources/mapper/business/DcStakeMarkMapper.xml b/zc-business/src/main/resources/mapper/business/DcStakeMarkMapper.xml new file mode 100644 index 00000000..62cb4d6d --- /dev/null +++ b/zc-business/src/main/resources/mapper/business/DcStakeMarkMapper.xml @@ -0,0 +1,41 @@ + + + + + + + + insert into dc_stake_mark + + stake_mark, + longitude, + latitude, + direction, + section_id, + mileage, + create_time, + + + #{dcStakeMark.stakeMark}, + #{dcStakeMark.longitude}, + #{dcStakeMark.latitude}, + #{dcStakeMark.direction}, + #{dcStakeMark.sectionId}, + #{dcStakeMark.mileage}, + now(), + + ON DUPLICATE KEY UPDATE + + stake_mark = #{dcStakeMark.stakeMark}, + longitude = #{dcStakeMark.longitude}, + latitude = #{dcStakeMark.latitude}, + direction = #{dcStakeMark.direction}, + section_id = #{dcStakeMark.sectionId}, + mileage = #{dcStakeMark.mileage}, + update_time = now(), + + + + From f1013f64d5783c8090bb7c718f7b002a2d64a058 Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Sat, 23 Mar 2024 10:47:42 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=9B=91=E6=8E=A7=E6=91=84=E5=83=8F=E8=AE=BE=E5=A4=87?= =?UTF-8?q?ID=E6=93=8D=E4=BD=9C=E6=94=B9=E4=B8=BA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=89=A7=E8=A1=8C=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zc/business/controller/VideoController.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 427407cc..86d3a73f 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -22,6 +22,7 @@ import io.swagger.annotations.ApiParam; import okhttp3.Response; import org.springframework.scheduling.annotation.Scheduled; 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.RestController; @@ -71,17 +72,15 @@ public class VideoController extends BaseController { // 组织机构id private final static String CAM_DEPT_ID = "1301730"; - @PostConstruct - public void init() { - synchronizeIotIds(); - } /** * 同步物联网ID。 * 该方法用于查询未同步物联网ID的摄像头设备信息,并从外部API获取这些设备的详细信息,然后更新它们的物联网ID。 * 该过程主要涉及查询未初始化物联网ID的摄像头、构建设备IP与设备映射、从API获取设备详细信息以及批量更新设备的物联网ID。 */ - public void synchronizeIotIds() { + @ApiOperation("同步监控摄像设备ID") + @PatchMapping(value = "/sync/id") + public AjaxResult synchronizeIotIds() { // 查询未同步物联ID的摄像头设备信息 LambdaQueryWrapper query = new LambdaQueryWrapper<>(); query.eq(DcDevice::getDeviceType, DeviceTypeConstants.CAMERA) @@ -90,7 +89,7 @@ public class VideoController extends BaseController { List uninitializedCameras = iDcDeviceService.list(query); if (uninitializedCameras.isEmpty()) { - return; // 若无待同步设备,则直接返回 + return AjaxResult.success("没有需要同步的设备"); // 若无待同步设备,则直接返回 } // 将未初始化的摄像头列表转换为Map,以设备的桩号、方向和子类型拼接作为键,设备本身作为值 @@ -109,7 +108,7 @@ public class VideoController extends BaseController { JSONObject camApiResponse = getCamByDept(CAM_DEPT_ID); if (camApiResponse == null || !camApiResponse.containsKey("data")) { - return; // 如果获取信息失败或不含有效数据,直接返回 + return AjaxResult.error("根据组织机构获取摄像机信息失败"); // 如果获取信息失败或不含有效数据,直接返回 } JSONArray camDataArray = camApiResponse.getJSONArray("data"); @@ -138,9 +137,12 @@ public class VideoController extends BaseController { // 批量更新摄像头设备的物联ID iDcDeviceService.updateBatchById(devicesToUpdate); + return AjaxResult.success("同步物联ID成功", devicesToUpdate); } catch (Exception e) { logger.error("获取摄像头信息失败!", e); } + + return AjaxResult.error("同步物联ID失败"); } /** From 7107a0748f5f4475cd80084f5f748d6767a64838 Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Mon, 25 Mar 2024 09:11:04 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=A1=A9=E5=8F=B7=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/utils/StakeMarkUtils.java | 28 +++++++++++++++---- .../service/impl/DcStakeMarkServiceImpl.java | 16 +---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java index 6c61fa9a..686b4c29 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java +++ b/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.RoundingMode; +import java.util.regex.Pattern; /** - * @Description 桩号计算工具 + * @Description 桩号工具 * * @author liuwenge * @date 2024/1/17 14:43 */ 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 桩号转公里数 * @@ -20,7 +38,7 @@ public class StakeMarkUtils { * @return 公里数:123.123 */ public static String formatKilometre(String stakeMark){ - if (StringUtils.isEmpty(stakeMark)){ + if (!checkStakeMark(stakeMark)){ return ""; } return stakeMark.toLowerCase().replace("k","").replace("+","."); @@ -35,7 +53,7 @@ public class StakeMarkUtils { * @return 公里数:123123 */ public static String formatMetre(String stakeMark){ - if (StringUtils.isEmpty(stakeMark)){ + if (!checkStakeMark(stakeMark)){ return ""; } return stakeMark.toLowerCase().replace("k","").replace("+",""); @@ -51,7 +69,7 @@ public class StakeMarkUtils { * @return java.math.BigDecimal 距离 */ public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){ - if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ + if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){ return BigDecimal.ZERO; } String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); @@ -75,7 +93,7 @@ public class StakeMarkUtils { * @return java.math.BigDecimal 距离 */ public static BigDecimal getMetre(String startStakeMark, String endStakeMark){ - if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ + if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){ return BigDecimal.ZERO; } String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java index 7c8c3974..e2d3022b 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java @@ -162,7 +162,7 @@ public class DcStakeMarkServiceImpl extends ServiceImpl errorKey = new ArrayList<>(); map.keySet().forEach(key ->{ - if (!checkStakeMark(key)){ + if (!StakeMarkUtils.checkStakeMark(key)){ errorKey.add(key); } DcStakeMark dcStakeMark = new DcStakeMark(); @@ -189,19 +189,5 @@ public class DcStakeMarkServiceImpl extends ServiceImpl