Procházet zdrojové kódy

Merge branch 'usky-zyj' of uskycloud/usky-modules into master

hanzhengyi před 1 týdnem
rodič
revize
ae778e1874

+ 21 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/VcDeviceController.java

@@ -5,10 +5,13 @@ import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.iot.domain.BaseGgpFacility;
 import com.usky.iot.domain.VcDevice;
+import com.usky.iot.domain.VcStream;
 import com.usky.iot.service.VcDeviceService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -56,6 +59,24 @@ public class VcDeviceController {
         return ApiResult.success(vcDeviceService.pageList(videoNumber, videoName, groupId, pageNum, pageSize));
     }
 
+    /**
+     * 实时拉取摄像头视频流
+     * @param deviceUuid
+     * @return
+     */
+    @GetMapping("getVcDeviceVideo")
+    public ApiResult<String> getVcDeviceVideo(@RequestParam(value = "deviceUuid") String deviceUuid) {
+        return ApiResult.success(vcDeviceService.getVcDeviceVideo(deviceUuid));
+    }
+
+    /**
+     * 停止拉取摄像头视频流
+     */
+    @GetMapping("stopDeviceVideo")
+    public void stopDeviceVideo(){
+        vcDeviceService.stopDeviceVideo();
+    }
+
     /**
      * 新增
      * @param vcDevice

+ 5 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/VcDeviceService.java

@@ -4,6 +4,7 @@ import com.usky.common.core.bean.CommonPage;
 import com.usky.iot.domain.BaseGgpFacility;
 import com.usky.iot.domain.VcDevice;
 import com.usky.common.mybatis.core.CrudService;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.util.List;
 
@@ -20,6 +21,10 @@ public interface VcDeviceService extends CrudService<VcDevice> {
 
     CommonPage<VcDevice> pageList(String videoNumber, String videoName, Integer groupId ,Integer pageNum, Integer pageSize);
 
+    String getVcDeviceVideo(String deviceUuid);
+
+    void stopDeviceVideo();
+
     boolean add(VcDevice vcDevice);
 
     void update(VcDevice vcDevice);

+ 62 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/DeviceOperate.java

@@ -0,0 +1,62 @@
+package com.usky.iot.service.config;
+
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.usky.common.core.bean.ApiResult;
+import com.usky.demo.RemoteTsdbProxyService;
+import com.usky.iot.domain.DmpDeviceStatus;
+import com.usky.iot.mapper.DmpDeviceStatusMapper;
+import com.usky.iot.service.DmpDeviceStatusService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Configuration
+public class DeviceOperate {
+    @Autowired
+    private RemoteTsdbProxyService remoteTsdbProxyService;
+
+    @Autowired
+    DmpDeviceStatusService dmpDeviceStatusService;
+
+    @Async
+    public void updateDeviceStatus(){
+        log.info("定时同步设备状态数据 start");
+        ApiResult<List<Map<String,Object>>> list = remoteTsdbProxyService.getAllDeviceRealTime();
+        List<Map<String,Object>> dataList = list.getData();
+        if(CollectionUtils.isNotEmpty(dataList)){
+            for(int i=0;i<dataList.size();i++){
+                String deviceuuid = dataList.get(i).get("deviceuuid").toString();
+                LocalDateTime lTime = Instant.ofEpochMilli(Long.valueOf(dataList.get(i).get("time").toString())).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
+                String date =  lTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+                String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+                LambdaUpdateWrapper<DmpDeviceStatus> updateWrapper = Wrappers.lambdaUpdate();
+                if(date.equals(currentDate)){
+                    updateWrapper.set(DmpDeviceStatus::getDeviceStatus,1)  //设备在线
+                            .set(DmpDeviceStatus::getLastOnlineTime,lTime)
+                            .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
+
+                }else{
+                    updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2)  //设备离线
+                            .set(DmpDeviceStatus::getLastOnlineTime,lTime)
+                            .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
+
+                }
+                dmpDeviceStatusService.update(updateWrapper);
+
+            }
+
+        }
+        log.info("定时同步设备状态数据 end");
+    }
+}

+ 0 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/BaseBuildServiceImpl.java

@@ -22,7 +22,6 @@ import com.usky.iot.service.vo.BuildFacilityStatusVO;
 import org.apache.tomcat.jni.Local;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import sun.security.util.Length;
 
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;

+ 12 - 4
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/BaseGgpFacilityServiceImpl.java

@@ -149,13 +149,11 @@ public class BaseGgpFacilityServiceImpl extends AbstractCrudService<BaseGgpFacil
         if (CollectionUtils.isNotEmpty(baseGgpFacilityList)) {
             for (int i = 0; i < baseGgpFacilityList.size(); i++) {
                 BaseGgpFacilityExportVo baseGgpFacilityExportVo = new BaseGgpFacilityExportVo();
-                baseGgpFacilityExportVo.setXh(i + 1);
-                baseGgpFacilityExportVo.setId(baseGgpFacilityList.get(i).getId());
                 baseGgpFacilityExportVo.setFacilityNum(baseGgpFacilityList.get(i).getFacilityNum());
                 baseGgpFacilityExportVo.setFacilityType("未知");
                 if (CollectionUtils.isNotEmpty(typeList)) {
                     for (int j = 0; j < typeList.size(); j++) {
-                        if (baseGgpFacilityList.get(i).getFacilityType().equals(typeList.get(j).getId())) {
+                        if (baseGgpFacilityList.get(i).getFacilityType().equals(typeList.get(j).getTypeCode())) {
                             baseGgpFacilityExportVo.setFacilityType(typeList.get(j).getTypeName());
                         }
                     }
@@ -166,7 +164,9 @@ public class BaseGgpFacilityServiceImpl extends AbstractCrudService<BaseGgpFacil
                 baseGgpFacilityExportVo.setImagesUrl(baseGgpFacilityList.get(i).getImagesUrl());
                 baseGgpFacilityExportVo.setContact(baseGgpFacilityList.get(i).getContact());
                 baseGgpFacilityExportVo.setContactPhone(baseGgpFacilityList.get(i).getContactPhone());
-                baseGgpFacilityExportVo.setStatus(baseGgpFacilityList.get(i).getFacilityStatus());
+                baseGgpFacilityExportVo.setFacilityStatus(baseGgpFacilityList.get(i).getFacilityStatus());
+                baseGgpFacilityExportVo.setLongitude(baseGgpFacilityList.get(i).getLongitude());
+                baseGgpFacilityExportVo.setLatitude(baseGgpFacilityList.get(i).getLatitude());
                 baseGgpFacilityExportVo.setCreateTime(baseGgpFacilityList.get(i).getCreateTime().format(df));
                 list.add(baseGgpFacilityExportVo);
             }
@@ -435,6 +435,14 @@ public class BaseGgpFacilityServiceImpl extends AbstractCrudService<BaseGgpFacil
                 int rot=3;
                 for (FacilityImportVo facilityImportVo:facilityImportVos) {
                     BaseGgpFacility baseGgpFacility = BeanMapperUtils.map(facilityImportVo, BaseGgpFacility.class);
+                    List<BaseGgpFacilityTypeNumVO> typeList = baseFacilityTypeMapper.typeNumList(SecurityUtils.getTenantId());
+                    if (CollectionUtils.isNotEmpty(typeList)) {
+                        for (int j = 0; j < typeList.size(); j++) {
+                            if (baseGgpFacility.getFacilityType().equals(typeList.get(j).getTypeName())) {
+                                baseGgpFacility.setFacilityType(typeList.get(j).getTypeCode());
+                            }
+                        }
+                    }
                     if (StringUtils.isBlank(baseGgpFacility.getFacilityType())||StringUtils.isBlank(baseGgpFacility.getFacilityName())||StringUtils.isBlank(baseGgpFacility.getAddress())||StringUtils.isBlank(baseGgpFacility.getLatitude())||StringUtils.isBlank(baseGgpFacility.getLongitude())){
 
                         String tmp = ",第"+rot+"行数据导入失败,必填字段不能为空";

+ 8 - 45
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceInfoServiceImpl.java

@@ -40,16 +40,17 @@ import com.usky.iot.service.BaseFacilityDeviceService;
 import com.usky.iot.service.DmpDeviceInfoService;
 import com.usky.iot.service.DmpDeviceStatusService;
 import com.usky.iot.service.DmpProductAttributeService;
+import com.usky.iot.service.config.DeviceOperate;
 import com.usky.iot.service.enums.TopicInfo;
 import com.usky.iot.service.vo.*;
 import com.usky.transfer.RemoteTransferService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.multipart.MultipartFile;
-import sun.net.dns.ResolverConfiguration;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
@@ -97,6 +98,9 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
 	@Autowired
     private DmpProductAttributeMapper dmpProductAttributeMapper;
 
+    @Autowired
+    private DeviceOperate deviceOperate;
+
     private static final String ALARM_HTTP_URL = "/service-alarm/baseAlarm/alarmInfo";
 
 
@@ -425,50 +429,9 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
 
     @Override
     public void deviceStatus(){
-        log.info("定时同步设备状态数据 start");
-        LastInnerQueryVO queryVO = new LastInnerQueryVO();
-        List<String> deviceuuidList = new ArrayList<>();
-        LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.select(DmpDeviceInfo::getDeviceUuid)
-                .eq(DmpDeviceInfo::getDeleteFlag,0)
-                .ne(DmpDeviceInfo::getServiceStatus,3)
-                .orderByDesc(DmpDeviceInfo::getId);
-        List<DmpDeviceInfo> devList = this.list(queryWrapper);
-        if(CollectionUtils.isNotEmpty(devList)){
-            int count = devList.size();
-            for (int i = 0; i < devList.size(); i++) {
-                deviceuuidList.add(devList.get(i).getDeviceUuid());
-            }
-        }
-        queryVO.setDeviceuuid(deviceuuidList);
-
-        List<LastInnerResultVO> list = remoteTsdbProxyService.last(queryVO);
-        if(CollectionUtils.isNotEmpty(list)){
-            for(int i=0;i<list.size();i++){
-                if(Objects.nonNull(list.get(i).getMetrics())){
-                    String deviceuuid = list.get(i).getDeviceuuid();
-                    LocalDateTime lTime = Instant.ofEpochMilli(Long.valueOf(list.get(i).getMetrics().get("time").toString())).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
-                    String date =  lTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-                    String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-                    LambdaUpdateWrapper<DmpDeviceStatus> updateWrapper = Wrappers.lambdaUpdate();
-                    if(date.equals(currentDate)){
-                        updateWrapper.set(DmpDeviceStatus::getDeviceStatus,1)  //设备在线
-                                .set(DmpDeviceStatus::getLastOnlineTime,lTime)
-                                .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
-
-                    }else{
-                        updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2)  //设备离线
-                                .set(DmpDeviceStatus::getLastOnlineTime,lTime)
-                                .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
-
-                    }
-                    dmpDeviceStatusService.update(updateWrapper);
-                }
-
-            }
-
-        }
-        log.info("定时同步设备状态数据 end");
+        log.info("设备状态 start");
+        deviceOperate.updateDeviceStatus();
+        log.info("设备状态 end");
     }
 
     @Override

+ 71 - 3
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/VcDeviceServiceImpl.java

@@ -6,16 +6,20 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.common.core.exception.BusinessException;
 import com.usky.common.security.utils.SecurityUtils;
-import com.usky.iot.domain.BaseFacilityDevice;
-import com.usky.iot.domain.BaseGgpFacility;
 import com.usky.iot.domain.VcDevice;
 import com.usky.iot.mapper.VcDeviceMapper;
 import com.usky.iot.service.VcDeviceService;
 import com.usky.common.mybatis.core.AbstractCrudService;
-import com.usky.iot.service.vo.BaseFacilityDeviceVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -27,8 +31,15 @@ import java.util.List;
  * @author han
  * @since 2024-10-22
  */
+@Slf4j
 @Service
 public class VcDeviceServiceImpl extends AbstractCrudService<VcDeviceMapper, VcDevice> implements VcDeviceService {
+
+    @Value("${vc.rtmp-ip}")
+    private String rtmpIp;
+
+    Process process = null;
+
     @Override
     public List<VcDevice> VcDeviceList(Integer groupId){
         LambdaQueryWrapper<VcDevice> queryWrapper = Wrappers.lambdaQuery();
@@ -51,6 +62,63 @@ public class VcDeviceServiceImpl extends AbstractCrudService<VcDeviceMapper, VcD
         return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
     }
 
+    @Override
+    public String getVcDeviceVideo(String deviceUuid){
+        LambdaQueryWrapper<VcDevice> lambdaQuery = Wrappers.lambdaQuery();
+        lambdaQuery.like(StringUtils.isNotBlank(deviceUuid),VcDevice::getVideoNumber,deviceUuid)
+                .eq(VcDevice::getDelFlag,0);
+        VcDevice one = this.getOne(lambdaQuery);
+        if(one==null){
+            throw new BusinessException("未查询到设备信息");
+        }
+        String accountNumber = one.getAccountNumber();
+        String videoPassword = one.getVideoPassword();
+        String videoIp = one.getVideoIp();
+        String videoPort = one.getVideoPort().toString();
+        String command = "ffmpeg -i rtsp://"+accountNumber+":"+videoPassword+"@"+videoIp+":"+videoPort+" -vcodec copy -acodec aac -ar 44100 -c:v libx264 -preset ultrafast -tune zerolatency -strict -2 -ac 1 -r 30 -s 1280x720 -q 10 -f flv -hls_time 1 -hls_list_size 3 -hls_flags delete_segments rtmp://"+rtmpIp+":1935/hls/"+deviceUuid;
+        System.out.println(command);
+
+        try {
+            log.info("【begin】实时拉取摄像头数据流 "+command);
+            // 创建 ProcessBuilder 实例
+            ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
+            // 启动进程
+            process = processBuilder.start();
+
+            new Thread(() -> {
+                try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
+                    String line;
+                    while ((line = reader.readLine()) != null) {
+                        System.out.println(line);
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }).start();
+
+            String repDeviceVideo = rtmpIp+":80/hls/"+deviceUuid+".m3u8";
+            return repDeviceVideo;
+
+
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+
+    @Override
+    public void stopDeviceVideo() {
+        if (process != null && process.isAlive()) {
+            process.destroy();
+            try {
+                process.waitFor();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
     @Override
     public boolean add(VcDevice vcDevice){
         vcDevice.setCreateBy(SecurityUtils.getUsername());

+ 17 - 17
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/BaseGgpFacilityExportVo.java

@@ -24,18 +24,6 @@ public class BaseGgpFacilityExportVo implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    /**
-     * 主键ID
-     */
-    @TableId(value = "id", type = IdType.AUTO)
-    private Integer id;
-
-    /**
-     * 序号
-     */
-    @Excel(name = "序号")
-    private Integer xh;
-
     /**
      * 设施编号
      */
@@ -61,7 +49,7 @@ public class BaseGgpFacilityExportVo implements Serializable {
     private String address;
 
     /**
-     * 图片地址URL
+     * 设施图片
      */
     @Excel(name = "设施图片")
     private String imagesUrl;
@@ -73,19 +61,31 @@ public class BaseGgpFacilityExportVo implements Serializable {
     private String contact;
 
     /**
-     * 联系方式
+     * 联系电话
      */
-    @Excel(name = "联系方式")
+    @Excel(name = "联系电话")
     private String contactPhone;
 
     /**
      * 设施状态
      */
     @Excel(name = "设施状态", readConverterExp = "0=正常,1=维修,2=关闭")
-    private Integer status;
+    private Integer facilityStatus;
+
+    /**
+     * 经度
+     */
+    @Excel(name = "经度")
+    private String longitude;
+
+    /**
+     * 维度
+     */
+    @Excel(name = "维度")
+    private String latitude;
 
     /**
-     * 开始时间
+     * 创建时间
      */
     @Excel(name = "创建时间")
     private String createTime;

+ 34 - 9
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/FacilityImportVo.java

@@ -1,8 +1,12 @@
 package com.usky.iot.service.vo;
 
-import cn.afterturn.easypoi.excel.annotation.Excel;
 
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.time.LocalDateTime;
 
 /**
  * <p>
@@ -13,24 +17,38 @@ import lombok.Data;
  * @since 2023-07-27
  */
 @Data
+@EqualsAndHashCode(callSuper = false)
 public class FacilityImportVo{
+    /**
+     * 设施编号
+     */
+    @Excel(name = "设施编号")
+    private String facilityNum;
+
     /**
      * 设施类型(必填)
      */
-    @Excel(name = "设施类型(必填)")
+    @Excel(name = "设施类型")
     private String facilityType;
 
     /**
      * 设施名称(必填)
      */
-    @Excel(name = "设施名称(必填)")
+    @Excel(name = "设施名称")
     private String facilityName;
 
     /**
      * 设施地址(必填)
      */
-    @Excel(name = "设施地址(必填)")
+    @Excel(name = "设施地址")
     private String address;
+
+    /**
+     * 设施图片
+     */
+    @Excel(name = "设施图片")
+    private String imagesUrl;
+
     /**
      * 联系人
      */
@@ -44,21 +62,28 @@ public class FacilityImportVo{
     private String contactPhone;
 
     /**
-     * 备注
+     * 设施状态
      */
-    @Excel(name = "备注")
-    private String facilityDesc;
+    @Excel(name = "设施状态",replace = {"正常_0", "维修_1", "关闭_2"})
+    private Integer facilityStatus;
 
     /**
      * 经度(必填)
      */
-    @Excel(name = "经度(必填)")
+    @Excel(name = "经度")
     private String longitude;
 
     /**
      * 维度(必填)
      */
-    @Excel(name = "维度(必填)")
+    @Excel(name = "维度")
     private String latitude;
 
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间")
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime createTime;
+
 }