Selaa lähdekoodia

相机截图开发

gao.qiang 1 kuukausi sitten
vanhempi
commit
eca7fd8c56

+ 9 - 0
business-service/src/main/java/com/ozs/service/entity/vo/Screenshot.java

@@ -0,0 +1,9 @@
+package com.ozs.service.entity.vo;
+
+import lombok.Data;
+
+@Data
+public class Screenshot {
+    private String code;
+    private String url;
+}

+ 4 - 0
business-service/src/main/java/com/ozs/service/service/impl/BaseCameraManagementServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.pagehelper.PageHelper;
 import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.exception.ServiceException;
 import com.ozs.common.exception.base.BaseException;
 import com.ozs.common.utils.AppendUtils;
@@ -61,6 +62,8 @@ public class BaseCameraManagementServiceImpl extends ServiceImpl<BaseCameraManag
     private CameraUpdateLogMapper cameraUpdateLogMapper;
     @Autowired
     private BaseRailwayManagementMapper baseRailwayManagementMapper;
+    @Autowired
+    private RedisCache redisCache;
 
     /**
      * 相机台账管理表导入
@@ -163,6 +166,7 @@ public class BaseCameraManagementServiceImpl extends ServiceImpl<BaseCameraManag
             }
         }
         if (failureNum > 0) {
+            redisCache.deleteObject("screenshot");
             failureMsg.insert(0, "很抱歉!需导入数据共有" + accountManageList.size() + "条。数据导入成功共 " + successNum + " 条。数据导入失败共 " + failureNum + " 条。错误如下:");
             throw new ServiceException(failureMsg.toString());
         } else {

+ 4 - 0
business-service/src/main/java/com/ozs/service/service/impl/BaseRailwayManagementServiceImpl.java

@@ -2,6 +2,7 @@ package com.ozs.service.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.exception.ServiceException;
 import com.ozs.common.utils.bean.BeanValidators;
 import com.ozs.service.entity.BaseRailwayManagement;
@@ -30,6 +31,8 @@ public class BaseRailwayManagementServiceImpl extends ServiceImpl<BaseRailwayMan
     BaseRailwayManagementMapper baseRailwayManagementMapper;
     @Autowired
     protected Validator validator;
+    @Autowired
+    private RedisCache redisCache;
 
     /**
      * 导出线路管理表信息
@@ -93,6 +96,7 @@ public class BaseRailwayManagementServiceImpl extends ServiceImpl<BaseRailwayMan
             failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
             throw new ServiceException(failureMsg.toString());
         } else {
+            redisCache.deleteObject("screenshot");
             successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条。");
         }
         return successMsg.toString();

+ 70 - 10
business-service/src/main/java/com/ozs/service/utils/CallbackUtil.java

@@ -1,18 +1,30 @@
 package com.ozs.service.utils;
 
 
-import com.ozs.service.service.CameraLogDetailService;
-import com.ozs.service.service.CameraUpdateLogService;
-import com.ozs.service.service.MqLogService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ozs.common.core.redis.RedisCache;
+import com.ozs.common.utils.AppendUtils;
+import com.ozs.common.utils.ImgUtil;
+import com.ozs.service.entity.BaseCameraManagement;
+import com.ozs.service.entity.BaseRailwayManagement;
+import com.ozs.service.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
 
 import javax.annotation.PostConstruct;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 相机工具
+ *
  * @author Administrator
  */
 
@@ -24,20 +36,68 @@ public class CallbackUtil {
     CameraLogDetailService cameraLogDetailService;
     @Autowired
     MqLogService mqLogService;
-    private static  CameraLogDetailService cameraLogDetail;
-    private static  MqLogService mqLog;
+    @Autowired
+    private RedisCache redisCache;
+    @Autowired
+    BaseCameraManagementService baseCameraManagementService;
+    @Autowired
+    BaseRailwayManagementService baseRailwayManagementService;
+    @Value("${base.imgUrl}")
+    private String imgUrl;
+    private static CameraLogDetailService cameraLogDetail;
+    private static MqLogService mqLog;
+    private static RedisCache redis;
+    private static BaseCameraManagementService baseCameraManagement;
+    private static BaseRailwayManagementService baseRailwayManagement;
+    public static String url;
+
+
+    public static String screenshot(String deviceSn, String stream, String imageUrl) {
+        String path = null;
+        Map<String, Object> screenshot = redis.getCacheMap("screenshot");
+        if (ObjectUtils.isEmpty(screenshot)) {
+            List<BaseCameraManagement> list = baseCameraManagement.list();
+            Map<String, String> map = new HashMap<>();
+            for (BaseCameraManagement came : list) {
+                BaseRailwayManagement baseRailwayManagementOne = baseRailwayManagement.getOne(new LambdaQueryWrapper<BaseRailwayManagement>()
+                        .eq(BaseRailwayManagement::getRailwayCode, came.getRailwayCode()));
+                map.put(came.getCameraCode(), "/" + baseRailwayManagementOne.getRailwayName() + "/" + AppendUtils.stringAppend(came.getInstallMile()) + "/");
+                if (came.equals(deviceSn)) {
+                    path = url + "/" + baseRailwayManagementOne.getRailwayName() + "/" + AppendUtils.stringAppend(came.getInstallMile()) + "/" + LocalDate.now().getYear() + "/" + LocalDate.now().getMonthValue() + "/" + LocalDate.now().getDayOfMonth() + "/" + LocalTime.now().getHour() + "/" + imageUrl;
+                }
+            }
+            redis.setCacheMap("screenshot", map);
+            return path;
+        } else {
+            for (Map.Entry<String, Object> entry : screenshot.entrySet()) {
+                String key = entry.getKey();
+                Object value = entry.getValue();
+                // 将Object转换为String
+                if (key.equals(deviceSn)) {
+                    String stringValue = value != null ? value.toString() : null;
+                    path = url + stringValue + LocalDate.now().getYear() + "/" + LocalDate.now().getMonthValue() + "/" + LocalDate.now().getDayOfMonth() + "/" + LocalTime.now().getHour() + "/" + imageUrl;
+                    return path;
+                }
+            }
+        }
+        return  null;
+    }
 
     @PostConstruct
     public void init() {
         cameraLogDetail = cameraLogDetailService;
-        mqLog=mqLogService;
+        mqLog = mqLogService;
+        redis = redisCache;
+        baseCameraManagement = baseCameraManagementService;
+        baseRailwayManagement = baseRailwayManagementService;
+        url = imgUrl;
     }
-    
-    public static void  callback(String deviceSn,Integer code,String remark){
-        CallbackUtil.cameraLogDetail.updateAccessories(deviceSn,code,remark);
+
+    public static void callback(String deviceSn, Integer code, String remark) {
+        CallbackUtil.cameraLogDetail.updateAccessories(deviceSn, code, remark);
     }
 
-    public static void  heart(String cameraCode){
+    public static void heart(String cameraCode) {
         CallbackUtil.mqLog.insetHeartLog(cameraCode);
     }
 }

+ 19 - 0
business-service/src/main/java/com/ozs/service/utils/PublishCallback.java

@@ -54,6 +54,8 @@ public class PublishCallback implements MqttCallback {
         String sign = null;
         String deviceSn = null;
         Integer code = null;
+        String stream=null;
+        String imageUrl=null;
         // subscribe后得到的消息会执行到这里面
         logger.info("接收消息主题 : {}", topic);
         logger.info("接收消息内容 : {}", new String(message.getPayload()));
@@ -73,6 +75,23 @@ public class PublishCallback implements MqttCallback {
                 logger.error(e.getMessage());
             }
         }
+        if ("screenshot".equals(topic)) {
+            try {
+                String s = new String(message.getPayload());
+                s = "[" + s + "]";
+                JSONArray jsonArray = JSONArray.parseArray(s);
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    JSONObject object = jsonArray.getJSONObject(i);
+                    deviceSn = (String) object.get("code");
+                    stream = (String) object.get("stream");
+                    imageUrl = (String) object.get("imageUrl");
+                }
+                String url = CallbackUtil.screenshot(deviceSn, stream, imageUrl);
+                PublishClient.screenshot(url, deviceSn);
+            } catch (Exception e) {
+                logger.error(e.getMessage());
+            }
+        }
         if ("update".equals(topic)) {
             try {
                 String s = new String(message.getPayload());

+ 28 - 0
business-service/src/main/java/com/ozs/service/utils/PublishClient.java

@@ -105,6 +105,34 @@ public class PublishClient {
         publish(getMqttTopic("heart_" + deviceSn), message);
     }
 
+
+    public static void screenshot(String url, String deviceSn) throws MqttException {
+        /**
+         * 发布客户端
+         */
+        Screenshot screenshot = new Screenshot();
+        screenshot.setCode(deviceSn);
+        screenshot.setUrl(url);
+        String s = JSON.toJSONString(screenshot);
+        MqttMessage message = new MqttMessage();
+        /**
+         * 保证消息能到达一次
+         */
+        message.setQos(1);
+        /**
+         * 消息保留
+         */
+//        server.message.setRetained(false);
+        /**
+         * 消息内容
+         */
+        message.setPayload(s.getBytes());
+        /**
+         * 发布
+         */
+        publish(getMqttTopic("screenshot_" + deviceSn), message);
+    }
+
     public static void main(String[] args) {
         JSONObject res = new JSONObject();
         res.put("Name", "ConfigRequest");

+ 3 - 0
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseCameraManagementController.java

@@ -285,6 +285,7 @@ public class BaseCameraManagementController extends BaseController {
             baseDeviceDynamicManagementService.remove(queryWrapper);
             baseCameraManagementService.removeById(accountManagementId);
         }
+        redisCache.deleteObject("screenshot");
         return AjaxResult.success();
     }
 
@@ -359,6 +360,7 @@ public class BaseCameraManagementController extends BaseController {
                 }
             }
             if (baseCameraManagementService.save(baseCameraManagement) && baseDeviceDynamicManagementService.save(baseDynamicManagement)) {
+                redisCache.deleteObject("screenshot");
                 return AjaxResult.success();
             } else {
                 return AjaxResult.error();
@@ -430,6 +432,7 @@ public class BaseCameraManagementController extends BaseController {
         LambdaUpdateWrapper<BaseCameraManagement> wrapper = new LambdaUpdateWrapper<>();
         wrapper.eq(BaseCameraManagement::getId, baseCameraManagement.getId());
         if (baseCameraManagementService.update(baseCameraManagement, wrapper) && baseDeviceDynamicManagementService.updateById(one)) {
+            redisCache.deleteObject("screenshot");
             return AjaxResult.success();
         }
         return AjaxResult.error();

+ 6 - 0
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseRailwayManagementController.java

@@ -9,6 +9,7 @@ import com.ozs.common.core.controller.BaseController;
 import com.ozs.common.core.domain.AjaxResult;
 import com.ozs.common.core.domain.entity.SysDept;
 import com.ozs.common.core.domain.entity.SysDictData;
+import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.enums.BusinessType;
 import com.ozs.common.utils.AppendUtils;
 import com.ozs.common.utils.ChineseToPingyin;
@@ -63,6 +64,8 @@ public class BaseRailwayManagementController extends BaseController {
     private BaseCameraManagementService baseCameraManagementService;
     @Autowired
     private IdempotenceUtils idempotenceUtils;
+    @Autowired
+    private RedisCache redisCache;
 
     /**
      * 线路管理表分页
@@ -118,6 +121,7 @@ public class BaseRailwayManagementController extends BaseController {
             }
         }
         if (baseRailwayManagementService.removeByIds(lineIds)) {
+            redisCache.deleteObject("screenshot");
             return AjaxResult.success();
         }
         return AjaxResult.error();
@@ -158,6 +162,7 @@ public class BaseRailwayManagementController extends BaseController {
             baseRailwayManagement.setCreateBy(getUserId());
             baseRailwayManagement.setUpdateBy(getUserId());
             if (baseRailwayManagementService.save(baseRailwayManagement)) {
+                redisCache.deleteObject("screenshot");
                 return AjaxResult.success();
             } else {
                 return AjaxResult.error();
@@ -209,6 +214,7 @@ public class BaseRailwayManagementController extends BaseController {
         baseRailwayManagement.setUpdateBy(getUserId());
         baseRailwayManagement.setUpdateTime(new Date());
         if (baseRailwayManagementService.updateById(baseRailwayManagement)) {
+            redisCache.deleteObject("screenshot");
             return AjaxResult.success();
         }
         return AjaxResult.error();

+ 0 - 2
hazard-sdk/src/main/java/com/ozs/controller/upload/UploadController.java

@@ -147,8 +147,6 @@ public class UploadController {
                 BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(wrapper);
                 String filename = cameraCode + "-" +
                         DateTime.now().toString("yyyyMMddHHmmss") + stream.getOriginalFilename().substring(stream.getOriginalFilename().lastIndexOf("."));
-                SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
-                String format1 = dateFormat1.format(new Date());
                 BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(new LambdaQueryWrapper<BaseRailwayManagement>()
                         .eq(BaseRailwayManagement::getRailwayCode, baseCameraManagement.getRailwayCode()));
                 String imgName = baseRailwayManagement.getRailwayName() + "/" + AppendUtils.stringAppend(baseCameraManagement.getInstallMile()) + "/" + LocalDate.now().getYear() + "/" + LocalDate.now().getMonthValue() + "/" + LocalDate.now().getDayOfMonth() + "/" + LocalTime.now().getHour() + "/" + filename;