浏览代码

同步预制点

lyq 1 月之前
父节点
当前提交
03c830b800

+ 5 - 2
monitor_ui/src/views/centerMonitor/camera/PolygonDrawer.vue

@@ -33,6 +33,7 @@
             <button @click="removeItem(item)" class="">
               <i class="fa fa-trash"></i> 删除
             </button>
+            {{ item.syncStatus == 1 ? "已同步" : "未同步" }}
           </div>
         </div>
       </div>
@@ -422,7 +423,8 @@ export default {
           lineColor: this.lineColor,
           fillColor: this.fillColor,
           lineWidth: this.lineWidth,
-          index: this.polygons.length == 0 ? 1 : this.polygons[this.polygons.length - 1].index + 1
+          index: this.polygons.length == 0 ? 1 : this.polygons[this.polygons.length - 1].index + 1,
+          syncStatus: 0
         })
 
         // 重置当前多边形
@@ -496,9 +498,10 @@ export default {
       }, 1000)
     },
     // 重绘所有多边形
-    redrawAllPolygons(data) {
+    redrawAllPolygons(data, status) {
       if (data) {
         this.polygons = JSON.parse(data).polygons
+        this.polygons.forEach(item => item.syncStatus = status)
       }
 
       const canvas = this.$refs.polygonCanvas

+ 11 - 2
monitor_ui/src/views/centerMonitor/camera/index.vue

@@ -2063,7 +2063,7 @@ export default {
         let param = {channelId: this.infoDraw.channelId, taskId: this.infoDraw.taskId, pointId: this.infoDraw.pointId, pointName: this.infoDraw.pointName, type: this.infoDraw.type}
         getRail(param).then(response => {
           if (response.data && response.data.jsonData) {
-            this.$refs.PolygonDrawer.redrawAllPolygons(response.data.jsonData)
+            this.$refs.PolygonDrawer.redrawAllPolygons(response.data.jsonData, response.data.syncStatus)
           } else {
             this.$refs.PolygonDrawer.clearCanvas()
           }
@@ -2071,7 +2071,16 @@ export default {
       }
     },
     raidoChange(val) {
-      if (this.$refs.PolygonDrawer.polygons.length != 0) {
+      if (this.infoDraw.channelId && this.infoDraw.taskId && this.infoDraw.pointId && this.infoDraw.pointName && this.infoDraw.type) {
+        let param = {channelId: this.infoDraw.channelId, taskId: this.infoDraw.taskId, pointId: this.infoDraw.pointId, pointName: this.infoDraw.pointName, type: this.infoDraw.type}
+        getRail(param).then(response => {
+          if (response.data && response.data.jsonData) {
+            this.$refs.PolygonDrawer.redrawAllPolygons(response.data.jsonData, response.data.syncStatus)
+          } else {
+            this.$refs.PolygonDrawer.clearCanvas()
+          }
+        })
+      } else {
         this.$refs.PolygonDrawer.polygons = []
         this.$refs.PolygonDrawer.redrawAllPolygons()
       }

+ 1 - 1
src/main/java/com/sooka/sponest/monitor/channelrail/controller/ChannelRailController.java

@@ -27,7 +27,7 @@ public class ChannelRailController extends BaseController {
 
     @PostMapping("/save")
     public AjaxResult save(@RequestBody ChannelRail channelRail) {
-        channelRailService.delete(channelRail.getChannelId(), channelRail.getTaskId(), channelRail.getPointId(), channelRail.getType());
+        channelRailService.delete(channelRail.getChannelId(), channelRail.getTaskId(), channelRail.getPointId());
         return channelRailService.save(channelRail) > 0 ? success() : error();
     }
 }

+ 2 - 0
src/main/java/com/sooka/sponest/monitor/channelrail/domain/ChannelRail.java

@@ -17,5 +17,7 @@ public class ChannelRail {
 
     private String jsonData;
 
+    private Integer syncStatus;
+
     private String info;
 }

+ 5 - 1
src/main/java/com/sooka/sponest/monitor/channelrail/mapper/ChannelRailMapper.java

@@ -4,6 +4,8 @@ import com.sooka.sponest.monitor.channelrail.domain.ChannelRail;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 /**
  * 摄像头Mapper接口
  *
@@ -15,8 +17,10 @@ public interface ChannelRailMapper {
 
     ChannelRail get(@Param("channelId") String channelId, @Param("taskId") Long taskId, @Param("pointId") Long pointId, @Param("type") String type);
 
+    List<ChannelRail> getList(@Param("channelId") String channelId, @Param("taskId") Long taskId);
+
     int save(ChannelRail channelRail);
 
-    int delete(@Param("channelId") String channelId, @Param("taskId") Long taskId, @Param("pointId") Long pointId, @Param("type") String type);
+    int delete(@Param("channelId") String channelId, @Param("taskId") Long taskId, @Param("pointId") Long pointId);
 }
 

+ 1 - 1
src/main/java/com/sooka/sponest/monitor/channelrail/service/IChannelRailService.java

@@ -14,7 +14,7 @@ public interface IChannelRailService {
 
     int save(ChannelRail channelRail);
 
-    int delete(String channelId, Long taskId, Long pointId, String type);
+    int delete(String channelId, Long taskId, Long pointId);
 }
 
 

+ 33 - 27
src/main/java/com/sooka/sponest/monitor/channelrail/service/impl/ChannelRailServiceImpl.java

@@ -34,50 +34,56 @@ public class ChannelRailServiceImpl implements IChannelRailService {
 
     @Override
     public int save(ChannelRail channelRail) {
+        int result = 0;
+        List<ChannelRail> rails = channelRailMapper.getList(channelRail.getChannelId(), channelRail.getTaskId());
+        rails.add(channelRail);
         try {
             JSONObject jsonObject = JSONObject.parseObject(channelRail.getInfo());
             List<JSONObject> channels = JSONObject.parseArray(jsonObject.getString("channelInfos"), JSONObject.class);
             channels = channels.stream().map(channel -> {
                 if (channel.getString("channelCode").equals(channelRail.getChannelId())) {
-                    List<JSONObject> channelPresetPointVOS = JSONObject.parseArray(channel.getString("channelPresetPointVOS"), JSONObject.class);
-                    channelPresetPointVOS = channelPresetPointVOS.stream().map(channelPresetPointVO -> {
-                        if (channelPresetPointVO.getLong("presetPointId").equals(channelRail.getPointId())) {
-                            List<Map<String, Object>> channelCutInfos = new ArrayList<>();
-                            List<JSONObject> polygons = JSONObject.parseArray(JSONObject.parseObject(channelRail.getJsonData()).getString("polygons"), JSONObject.class);
-                            polygons.forEach(item -> {
-                                Map<String, Object> map = new HashMap<>();
-                                map.put("taskId", jsonObject.getLong("id"));
-                                map.put("pointId", channelRail.getPointId());
-                                map.put("pointName", channelRail.getPointName());
-                                map.put("type", channelRail.getType());
-                                item.remove("lineColor");
-                                item.remove("fillColor");
-                                item.remove("lineWidth");
-                                map.put("areaPoints", item.toJSONString());
-                                map.put("channelCode", channel.getString("channelCode"));
-                                map.put("channelName", channel.getString("channelName"));
-                                channelCutInfos.add(map);
-                            });
-                            Collections.reverse(channelCutInfos);
-                            channelPresetPointVO.put("channelCutInfos", channelCutInfos);
-                        }
-                        return channelPresetPointVO;
-                    }).collect(Collectors.toList());
+                    List<JSONObject> channelPresetPointVOS = new ArrayList<>();
+                    for (ChannelRail rail : rails) {
+                        JSONObject channelPresetPointVO = new JSONObject();
+                        channelPresetPointVO.put("presetPointId", rail.getPointId());
+                        channelPresetPointVO.put("pointName", rail.getPointName());
+                        List<Map<String, Object>> channelCutInfos = new ArrayList<>();
+                        List<JSONObject> polygons = JSONObject.parseArray(JSONObject.parseObject(rail.getJsonData()).getString("polygons"), JSONObject.class);
+                        polygons.forEach(item -> {
+                            Map<String, Object> map = new HashMap<>();
+                            map.put("pointId", rail.getPointId());
+                            map.put("pointName", rail.getPointName());
+                            map.put("type", rail.getType());
+                            map.put("areaPoints", item.toJSONString());
+                            map.put("taskId", jsonObject.getLong("id"));
+                            map.put("channelCode", channel.getString("channelCode"));
+                            map.put("channelName", channel.getString("channelName"));
+                            channelCutInfos.add(map);
+                        });
+                        Collections.reverse(channelCutInfos);
+                        channelPresetPointVO.put("channelCutInfos", channelCutInfos);
+                        channelPresetPointVO.put("taskId", rail.getTaskId());
+                        channelPresetPointVO.put("channelCode", channel.getString("channelCode"));
+                        channelPresetPointVO.put("channelName", channel.getString("channelName"));
+                        channelPresetPointVO.put("pointType", 1);
+                        channelPresetPointVOS.add(channelPresetPointVO);
+                    }
                     channel.put("channelPresetPointVOS", channelPresetPointVOS);
                 }
                 return channel;
             }).collect(Collectors.toList());
             jsonObject.put("channelInfos", channels);
             System.out.println(JSON.toJSONString(jsonObject));
-            dahuaService.updateTask(jsonObject);
+            result = dahuaService.updateTask(jsonObject);
         } catch (Exception e) {
             e.printStackTrace();
         }
+        channelRail.setSyncStatus(result);
         return channelRailMapper.save(channelRail);
     }
 
     @Override
-    public int delete(String channelId, Long taskId, Long pointId, String type) {
-        return channelRailMapper.delete(channelId, taskId, pointId, type);
+    public int delete(String channelId, Long taskId, Long pointId) {
+        return channelRailMapper.delete(channelId, taskId, pointId);
     }
 }

+ 1 - 1
src/main/java/com/sooka/sponest/monitor/dahua/service/DahuaService.java

@@ -136,5 +136,5 @@ public interface DahuaService {
      */
     AjaxResult SitPosition(JSONObject json);
 
-    void updateTask(com.alibaba.fastjson.JSONObject jsonObject);
+    int updateTask(com.alibaba.fastjson.JSONObject jsonObject);
 }

+ 6 - 2
src/main/java/com/sooka/sponest/monitor/dahua/service/impl/DahuaServiceImpl.java

@@ -1070,17 +1070,21 @@ public class DahuaServiceImpl extends BaseService implements DahuaService {
     }
 
     @Override
-    public void updateTask(com.alibaba.fastjson.JSONObject jsonObject) {
+    public int updateTask(com.alibaba.fastjson.JSONObject jsonObject) {
         String prBody = "";
         try {
             IccHttpHttpRequest pr = new IccHttpHttpRequest(host + "/evo-apigw/evo-gmai/1.4.0/api/algorithmTask/update", Method.POST, JSON.toJSONString(jsonObject));
             pr.getHttpRequest().header("Authorization", "bearer " + getTokenByPassword());
             prBody = pr.execute();
-            AjaxResult.success("操作成功", JSON.parseObject(prBody));
+            if (JSON.parseObject(prBody).getBoolean("success")) {
+                return 1;
+            }
+            return 0;
         } catch (Exception ex) {
             log.error("操作失败", ex);
             AjaxResult.error("操作失败", JSON.parseObject(prBody));
         }
+        return 0;
     }
 
 

+ 9 - 2
src/main/resources/mapper/monitor/channelrail/ChannelRailMapper.xml

@@ -5,10 +5,15 @@
 <mapper namespace="com.sooka.sponest.monitor.channelrail.mapper.ChannelRailMapper">
 
     <select id="get" resultType="ChannelRail">
-        select channel_id channelId, task_id taskId, point_id pointId, type, json_data jsonData from centermonitor_t_channel_rail
+        select channel_id channelId, task_id taskId, point_id pointId, type, json_data jsonData, sync_status syncStatus from centermonitor_t_channel_rail
         where channel_id = #{channelId} and task_id = #{taskId} and point_id = #{pointId} and type = #{type}
     </select>
 
+    <select id="getList" resultType="ChannelRail">
+        select channel_id channelId, task_id taskId, point_id pointId, type, json_data jsonData from centermonitor_t_channel_rail
+        where channel_id = #{channelId} and task_id = #{taskId}
+    </select>
+
     <insert id="save" parameterType="ChannelRail">
         insert into centermonitor_t_channel_rail
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -17,6 +22,7 @@
             <if test="pointId != null">point_id,</if>
             <if test="type != null">type,</if>
             <if test="jsonData != null">json_data,</if>
+            <if test="syncStatus != null">sync_status,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="channelId != null">#{channelId},</if>
@@ -24,10 +30,11 @@
             <if test="pointId != null">#{pointId},</if>
             <if test="type != null">#{type},</if>
             <if test="jsonData != null">#{jsonData},</if>
+            <if test="syncStatus != null">#{syncStatus},</if>
         </trim>
     </insert>
 
     <delete id="delete">
-        delete from centermonitor_t_channel_rail where channel_id = #{channelId} and task_id = #{taskId} and point_id = #{pointId} and type = #{type}
+        delete from centermonitor_t_channel_rail where channel_id = #{channelId} and task_id = #{taskId} and point_id = #{pointId}
     </delete>
 </mapper>