Browse Source

对接畜牧监控

wwh 1 month ago
parent
commit
cbdbdac2ae

+ 1 - 1
baqing-admin/src/main/java/com/ruoyi/web/modules/video/controller/BizLivestockMonitorController.java

@@ -132,6 +132,6 @@ public class BizLivestockMonitorController extends BaseController
132
     @PostMapping("/sync")
132
     @PostMapping("/sync")
133
     public AjaxResult sync()
133
     public AjaxResult sync()
134
     {
134
     {
135
-        return success(bizLivestockMonitorService.syncFromThirdParty());
135
+        return success(bizLivestockMonitorService.syncFromThirdParty(getUsername()));
136
     }
136
     }
137
 }
137
 }

+ 2 - 1
baqing-admin/src/main/java/com/ruoyi/web/modules/video/service/IBizLivestockMonitorService.java

@@ -54,9 +54,10 @@ public interface IBizLivestockMonitorService
54
     /**
54
     /**
55
      * 从第三方生产管理系统同步监控点位。
55
      * 从第三方生产管理系统同步监控点位。
56
      *
56
      *
57
+     * @param operator 当前操作人(点击同步按钮的用户)
57
      * @return 新增/更新/失败条数、失败明细、同步完成时间
58
      * @return 新增/更新/失败条数、失败明细、同步完成时间
58
      */
59
      */
59
-    YakAssetSyncResultVo syncFromThirdParty();
60
+    YakAssetSyncResultVo syncFromThirdParty(String operator);
60
 
61
 
61
     /**
62
     /**
62
      * 按摄像头 ID 拉取实时播放地址(调用第三方 play-url 接口,不落库)。
63
      * 按摄像头 ID 拉取实时播放地址(调用第三方 play-url 接口,不落库)。

+ 4 - 2
baqing-admin/src/main/java/com/ruoyi/web/modules/video/service/LivestockMonitorSyncService.java

@@ -36,10 +36,12 @@ public class LivestockMonitorSyncService
36
     /**
36
     /**
37
      * 从第三方拉取监控列表并落库。
37
      * 从第三方拉取监控列表并落库。
38
      *
38
      *
39
+     * @param operator 当前操作人(点击同步的用户名)
39
      * @return 同步统计(新增/更新/失败条数、失败明细、同步时间)
40
      * @return 同步统计(新增/更新/失败条数、失败明细、同步时间)
40
      */
41
      */
41
-    public YakAssetSyncResultVo syncFromThirdParty()
42
+    public YakAssetSyncResultVo syncFromThirdParty(String operator)
42
     {
43
     {
44
+        String syncBy = StringUtils.isNotEmpty(operator) ? operator.trim() : "";
43
         if (!syncing.compareAndSet(false, true))
45
         if (!syncing.compareAndSet(false, true))
44
         {
46
         {
45
             throw new ServiceException(LivestockMonitorSyncRules.MSG_SYNC_IN_PROGRESS);
47
             throw new ServiceException(LivestockMonitorSyncRules.MSG_SYNC_IN_PROGRESS);
@@ -70,7 +72,7 @@ public class LivestockMonitorSyncService
70
             {
72
             {
71
                 try
73
                 try
72
                 {
74
                 {
73
-                    boolean inserted = livestockMonitorSyncTxService.persistCamera(dto, syncTime);
75
+                    boolean inserted = livestockMonitorSyncTxService.persistCamera(dto, syncTime, syncBy);
74
                     if (inserted)
76
                     if (inserted)
75
                     {
77
                     {
76
                         result.setInsertCount(result.getInsertCount() + 1);
78
                         result.setInsertCount(result.getInsertCount() + 1);

+ 5 - 3
baqing-admin/src/main/java/com/ruoyi/web/modules/video/service/LivestockMonitorSyncTxService.java

@@ -39,11 +39,13 @@ public class LivestockMonitorSyncTxService
39
      *
39
      *
40
      * @param dto      开放接口单条摄像头数据
40
      * @param dto      开放接口单条摄像头数据
41
      * @param syncTime 本次同步批次时间
41
      * @param syncTime 本次同步批次时间
42
+     * @param operator 当前操作人(写入 create_by / update_by)
42
      * @return true=新增,false=更新
43
      * @return true=新增,false=更新
43
      */
44
      */
44
     @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
45
     @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
45
-    public boolean persistCamera(OpenCameraDto dto, Date syncTime)
46
+    public boolean persistCamera(OpenCameraDto dto, Date syncTime, String operator)
46
     {
47
     {
48
+        String syncBy = StringUtils.isNotEmpty(operator) ? operator.trim() : "";
47
         if (dto == null || dto.getCameraId() == null)
49
         if (dto == null || dto.getCameraId() == null)
48
         {
50
         {
49
             throw new ServiceException(LivestockMonitorSyncRules.MSG_CAMERA_ID_REQUIRED);
51
             throw new ServiceException(LivestockMonitorSyncRules.MSG_CAMERA_ID_REQUIRED);
@@ -61,13 +63,13 @@ public class LivestockMonitorSyncTxService
61
         row.setVideoSource(videoSource);
63
         row.setVideoSource(videoSource);
62
         row.setOwnerName(trimToNull(dto.getFarmName(), 64));
64
         row.setOwnerName(trimToNull(dto.getFarmName(), 64));
63
         row.setDelFlag(LivestockMonitorRules.DEL_FLAG_NORMAL);
65
         row.setDelFlag(LivestockMonitorRules.DEL_FLAG_NORMAL);
64
-        row.setUpdateBy("sync");
66
+        row.setUpdateBy(syncBy);
65
 
67
 
66
         BizLivestockMonitor existing = bizLivestockMonitorMapper.selectBizLivestockMonitorByMonitorId(monitorId);
68
         BizLivestockMonitor existing = bizLivestockMonitorMapper.selectBizLivestockMonitorByMonitorId(monitorId);
67
         Date now = syncTime != null ? syncTime : new Date();
69
         Date now = syncTime != null ? syncTime : new Date();
68
         if (existing == null)
70
         if (existing == null)
69
         {
71
         {
70
-            row.setCreateBy("sync");
72
+            row.setCreateBy(syncBy);
71
             row.setCreateTime(now);
73
             row.setCreateTime(now);
72
             bizLivestockMonitorMapper.insertBizLivestockMonitor(row);
74
             bizLivestockMonitorMapper.insertBizLivestockMonitor(row);
73
             return true;
75
             return true;

+ 3 - 3
baqing-admin/src/main/java/com/ruoyi/web/modules/video/service/impl/BizLivestockMonitorServiceImpl.java

@@ -231,11 +231,11 @@ public class BizLivestockMonitorServiceImpl implements IBizLivestockMonitorServi
231
                 cleaned.toArray(new Long[0]), updateBy);
231
                 cleaned.toArray(new Long[0]), updateBy);
232
     }
232
     }
233
 
233
 
234
-    /** {@inheritDoc} 委托 {@link LivestockMonitorSyncService} */
234
+    /** {@inheritDoc} */
235
     @Override
235
     @Override
236
-    public YakAssetSyncResultVo syncFromThirdParty()
236
+    public YakAssetSyncResultVo syncFromThirdParty(String operator)
237
     {
237
     {
238
-        return livestockMonitorSyncService.syncFromThirdParty();
238
+        return livestockMonitorSyncService.syncFromThirdParty(operator);
239
     }
239
     }
240
 
240
 
241
     /** {@inheritDoc} */
241
     /** {@inheritDoc} */

+ 1 - 1
baqing-admin/src/test/java/com/ruoyi/web/modules/video/controller/BizLivestockMonitorControllerApiTest.java

@@ -190,7 +190,7 @@ class BizLivestockMonitorControllerApiTest
190
     {
190
     {
191
         YakAssetSyncResultVo vo = new YakAssetSyncResultVo();
191
         YakAssetSyncResultVo vo = new YakAssetSyncResultVo();
192
         vo.setInsertCount(2);
192
         vo.setInsertCount(2);
193
-        when(bizLivestockMonitorService.syncFromThirdParty()).thenReturn(vo);
193
+        when(bizLivestockMonitorService.syncFromThirdParty("tester")).thenReturn(vo);
194
         mockMvc.perform(post("/videoSurveillance/livestockMonitor/sync"))
194
         mockMvc.perform(post("/videoSurveillance/livestockMonitor/sync"))
195
                 .andExpect(status().isOk())
195
                 .andExpect(status().isOk())
196
                 .andExpect(jsonPath("$.code").value(200))
196
                 .andExpect(jsonPath("$.code").value(200))

+ 9 - 9
baqing-admin/src/test/java/com/ruoyi/web/modules/video/service/LivestockMonitorSyncServiceTest.java

@@ -38,7 +38,7 @@ class LivestockMonitorSyncServiceTest
38
     void syncDisabled()
38
     void syncDisabled()
39
     {
39
     {
40
         when(thirdPartyCameraClient.fetchAllCameras()).thenThrow(new ServiceException("第三方监控同步未启用"));
40
         when(thirdPartyCameraClient.fetchAllCameras()).thenThrow(new ServiceException("第三方监控同步未启用"));
41
-        assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty());
41
+        assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty("tester"));
42
     }
42
     }
43
 
43
 
44
     @Test
44
     @Test
@@ -46,7 +46,7 @@ class LivestockMonitorSyncServiceTest
46
     void syncEmpty()
46
     void syncEmpty()
47
     {
47
     {
48
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.emptyList());
48
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.emptyList());
49
-        YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty();
49
+        YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty("tester");
50
         assertNotNull(result.getSyncTime());
50
         assertNotNull(result.getSyncTime());
51
         assertEquals(0, result.getInsertCount());
51
         assertEquals(0, result.getInsertCount());
52
     }
52
     }
@@ -64,8 +64,8 @@ class LivestockMonitorSyncServiceTest
64
         camera2.setDeviceName("监控2");
64
         camera2.setDeviceName("监控2");
65
         camera2.setVideoSource("ys7");
65
         camera2.setVideoSource("ys7");
66
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Arrays.asList(camera1, camera2));
66
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Arrays.asList(camera1, camera2));
67
-        when(livestockMonitorSyncTxService.persistCamera(any(), any())).thenReturn(true, false);
68
-        YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty();
67
+        when(livestockMonitorSyncTxService.persistCamera(any(), any(), any())).thenReturn(true, false);
68
+        YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty("tester");
69
         assertEquals(1, result.getInsertCount());
69
         assertEquals(1, result.getInsertCount());
70
         assertEquals(1, result.getUpdateCount());
70
         assertEquals(1, result.getUpdateCount());
71
         assertEquals(0, result.getFailCount());
71
         assertEquals(0, result.getFailCount());
@@ -80,9 +80,9 @@ class LivestockMonitorSyncServiceTest
80
         camera.setDeviceName("监控1");
80
         camera.setDeviceName("监控1");
81
         camera.setVideoSource("wvp");
81
         camera.setVideoSource("wvp");
82
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.singletonList(camera));
82
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.singletonList(camera));
83
-        when(livestockMonitorSyncTxService.persistCamera(any(), any()))
83
+        when(livestockMonitorSyncTxService.persistCamera(any(), any(), any()))
84
                 .thenThrow(new ServiceException("视频来源不能为空"));
84
                 .thenThrow(new ServiceException("视频来源不能为空"));
85
-        YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty();
85
+        YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty("tester");
86
         assertEquals(1, result.getFailCount());
86
         assertEquals(1, result.getFailCount());
87
         assertEquals(1, result.getFailMessages().size());
87
         assertEquals(1, result.getFailMessages().size());
88
     }
88
     }
@@ -96,14 +96,14 @@ class LivestockMonitorSyncServiceTest
96
         camera.setDeviceName("监控1");
96
         camera.setDeviceName("监控1");
97
         camera.setVideoSource("wvp");
97
         camera.setVideoSource("wvp");
98
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.singletonList(camera));
98
         when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.singletonList(camera));
99
-        when(livestockMonitorSyncTxService.persistCamera(any(), any())).thenAnswer(invocation -> {
99
+        when(livestockMonitorSyncTxService.persistCamera(any(), any(), any())).thenAnswer(invocation -> {
100
             Thread.sleep(200);
100
             Thread.sleep(200);
101
             return true;
101
             return true;
102
         });
102
         });
103
-        Thread t1 = new Thread(() -> livestockMonitorSyncService.syncFromThirdParty());
103
+        Thread t1 = new Thread(() -> livestockMonitorSyncService.syncFromThirdParty("tester"));
104
         t1.start();
104
         t1.start();
105
         Thread.sleep(50);
105
         Thread.sleep(50);
106
-        ServiceException ex = assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty());
106
+        ServiceException ex = assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty("tester2"));
107
         assertEquals(LivestockMonitorSyncRules.MSG_SYNC_IN_PROGRESS, ex.getMessage());
107
         assertEquals(LivestockMonitorSyncRules.MSG_SYNC_IN_PROGRESS, ex.getMessage());
108
         t1.join();
108
         t1.join();
109
     }
109
     }