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/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/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失败"); } /** 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..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 @@ -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,62 @@ public class DcStakeMarkServiceImpl extends ServiceImpl> map = JSON.parseObject(jsonStr, new TypeReference>>() {}); + List stakeMarkList = new ArrayList<>(); + + //桩号格式校验 + List 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(); + } + } 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); } 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(), + + + +