소스 검색

BUG修复 获取站点实时信息多个水位一样时报错

qinguocai 1 년 전
부모
커밋
065484badf

+ 10 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BerthingServiceImpl.java

@@ -305,13 +305,18 @@ public class BerthingServiceImpl implements BerthingService {
         try {
             ArrayList<String> times = berthingTimeDTO.getTimes();
             if (berthingTime == null) {
-                //新增
                 berthingTime = new BerthingTimeConfig();
-                berthingTime.setTimeId(0L);
+                //先查询有无重复添加
+                berthingTime.setWlevel(berthingTimeDTO.getWlevel());
                 berthingTime.setSiteId(siteInfo.getSiteId());
+                long count = berthingTimeConfigMapper.count(berthingTime);
+                if (count > 0){
+                    throw new BaseException("起测水位已存在");
+                }
+                //新增
+                berthingTime.setTimeId(0L);
                 berthingTime.setPlanid(berthingTimeDTO.getPlanid());
                 berthingTime.setTimes(JSONUtil.toJsonStr(times));
-                berthingTime.setWlevel(berthingTimeDTO.getWlevel());
                 berthingTime.setCreateTime(new Date());
                 berthingTime.setIsDel(0);
                 berthingTime.setStatus(1);
@@ -337,6 +342,8 @@ public class BerthingServiceImpl implements BerthingService {
             String data = JSONUtil.toJsonStr(requestMap);
             log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
+        } catch (BaseException e){
+            throw new BaseException(e.getMessage());
         } catch (Exception e){
             log.error("新增或修改时间策略错误", e);
             throw new BaseException("新增或修改时间策略错误");

+ 3 - 1
ruoyi-system/src/main/resources/mapper/BerthingTimeConfigMapper.xml

@@ -24,6 +24,8 @@
         where time_id = #{timeId}
     </select>
 
+
+
     <!--查询单个-->
     <select id="queryByWlevel" resultMap="BerthingTimeConfigMap">
         select
@@ -32,7 +34,7 @@
         where #{wlevel} - wlevel = (
         SELECT MIN(#{wlevel} -t.wlevel)
         FROM berthing_time_config AS t
-        WHERE #{wlevel} > t.wlevel and site_id = #{siteId})
+        WHERE #{wlevel} > t.wlevel and t.site_id = #{siteId}) and site_id = #{siteId}
     </select>