xiangpei
2024-08-28 ddb3068a51a8af8aa9a8f8c2cb9b6e9228b0c8d9
同步国标设备、点播定时任务优化
4个文件已修改
2个文件已添加
1个文件已删除
580 ■■■■■ 已修改文件
ycl-pojo/src/main/java/com/ycl/platform/domain/entity/DeviceInfo.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/wvp/Device.java 463 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/task/DeviceChannelTask.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/task/DeviceSynTask.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/task/WorkOrderImgTask.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/resources/mapper/zgyw/WorkOrderMapper.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/entity/DeviceInfo.java
@@ -22,9 +22,9 @@
    /** 设备编号/国标码 */
    private String deviceId;
    @TableField("channel_id")
    /** 设备通道ID */
    private String channelId;
    @TableField("device_name")
    /** deviceName */
    private String deviceName;
}
ycl-pojo/src/main/java/com/ycl/platform/wvp/Device.java
New file
@@ -0,0 +1,463 @@
package com.ycl.platform.wvp;
import io.swagger.v3.oas.annotations.media.Schema;
/**
 * 国标设备/平台
 * @author lin
 */
@Schema(description = "国标设备/平台")
public class Device {
    /**
     * 设备国标编号
     */
    @Schema(description = "设备国标编号")
    private String deviceId;
    /**
     * 设备名
     */
    @Schema(description = "名称")
    private String name;
    /**
     * 生产厂商
     */
    @Schema(description = "生产厂商")
    private String manufacturer;
    /**
     * 型号
     */
    @Schema(description = "型号")
    private String model;
    /**
     * 固件版本
     */
    @Schema(description = "固件版本")
    private String firmware;
    /**
     * 传输协议
     * UDP/TCP
     */
    @Schema(description = "传输协议(UDP/TCP)")
    private String transport;
    /**
     * 数据流传输模式
     * UDP:udp传输
     * TCP-ACTIVE:tcp主动模式
     * TCP-PASSIVE:tcp被动模式
     */
    @Schema(description = "数据流传输模式")
    private String streamMode;
    /**
     * wan地址_ip
     */
    @Schema(description = "IP")
    private String  ip;
    /**
     * wan地址_port
     */
    @Schema(description = "端口")
    private int port;
    /**
     * wan地址
     */
    @Schema(description = "wan地址")
    private String  hostAddress;
    /**
     * 在线
     */
    @Schema(description = "是否在线,true为在线,false为离线")
    private boolean onLine;
    /**
     * 注册时间
     */
    @Schema(description = "注册时间")
    private String registerTime;
    /**
     * 心跳时间
     */
    @Schema(description = "心跳时间")
    private String keepaliveTime;
    /**
     * 心跳间隔
     */
    @Schema(description = "心跳间隔")
    private int keepaliveIntervalTime;
    /**
     * 通道个数
     */
    @Schema(description = "通道个数")
    private int channelCount;
    /**
     * 注册有效期
     */
    @Schema(description = "注册有效期")
    private int expires;
    /**
     * 创建时间
     */
    @Schema(description = "创建时间")
    private String createTime;
    /**
     * 更新时间
     */
    @Schema(description = "更新时间")
    private String updateTime;
    /**
     * 设备使用的媒体id, 默认为null
     */
    @Schema(description = "设备使用的媒体id, 默认为null")
    private String mediaServerId;
    /**
     * 字符集, 支持 UTF-8 与 GB2312
     */
    @Schema(description = "符集, 支持 UTF-8 与 GB2312")
    private String charset ;
    /**
     * 目录订阅周期,0为不订阅
     */
    @Schema(description = "目录订阅周期,o为不订阅")
    private int subscribeCycleForCatalog;
    /**
     * 移动设备位置订阅周期,0为不订阅
     */
    @Schema(description = "移动设备位置订阅周期,0为不订阅")
    private int subscribeCycleForMobilePosition;
    /**
     * 移动设备位置信息上报时间间隔,单位:秒,默认值5
     */
    @Schema(description = "移动设备位置信息上报时间间隔,单位:秒,默认值5")
    private int mobilePositionSubmissionInterval = 5;
    /**
     * 报警订阅周期,0为不订阅
     */
    @Schema(description = "报警心跳时间订阅周期,0为不订阅")
    private int subscribeCycleForAlarm;
    /**
     * 是否开启ssrc校验,默认关闭,开启可以防止串流
     */
    @Schema(description = "是否开启ssrc校验,默认关闭,开启可以防止串流")
    private boolean ssrcCheck = false;
    /**
     * 地理坐标系, 目前支持 WGS84,GCJ02
     */
    @Schema(description = "地理坐标系, 目前支持 WGS84,GCJ02")
    private String geoCoordSys;
    @Schema(description = "密码")
    private String password;
    @Schema(description = "收流IP")
    private String sdpIp;
    @Schema(description = "SIP交互IP(设备访问平台的IP)")
    private String localIp;
    @Schema(description = "是否作为消息通道")
    private boolean asMessageChannel;
    @Schema(description = "设备注册的事务信息")
    private Object sipTransactionInfo;
    @Schema(description = "控制语音对讲流程,释放收到ACK后发流")
    private boolean broadcastPushAfterAck;
    public String getDeviceId() {
        return deviceId;
    }
    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getManufacturer() {
        return manufacturer;
    }
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public String getFirmware() {
        return firmware;
    }
    public void setFirmware(String firmware) {
        this.firmware = firmware;
    }
    public String getTransport() {
        return transport;
    }
    public void setTransport(String transport) {
        this.transport = transport;
    }
    public String getStreamMode() {
        return streamMode;
    }
    public Integer getStreamModeForParam() {
        if (streamMode == null) {
            return 0;
        }
        if (streamMode.equalsIgnoreCase("UDP")) {
            return 0;
        }else if (streamMode.equalsIgnoreCase("TCP-PASSIVE")) {
            return 1;
        }else if (streamMode.equalsIgnoreCase("TCP-ACTIVE")) {
            return 2;
        }
        return 0;
    }
    public void setStreamMode(String streamMode) {
        this.streamMode = streamMode;
    }
    public String getIp() {
        return ip;
    }
    public void setIp(String ip) {
        this.ip = ip;
    }
    public int getPort() {
        return port;
    }
    public void setPort(int port) {
        this.port = port;
    }
    public String getHostAddress() {
        return hostAddress;
    }
    public void setHostAddress(String hostAddress) {
        this.hostAddress = hostAddress;
    }
    public boolean isOnLine() {
        return onLine;
    }
    public void setOnLine(boolean onLine) {
        this.onLine = onLine;
    }
    public int getChannelCount() {
        return channelCount;
    }
    public void setChannelCount(int channelCount) {
        this.channelCount = channelCount;
    }
    public String getRegisterTime() {
        return registerTime;
    }
    public void setRegisterTime(String registerTime) {
        this.registerTime = registerTime;
    }
    public String getKeepaliveTime() {
        return keepaliveTime;
    }
    public void setKeepaliveTime(String keepaliveTime) {
        this.keepaliveTime = keepaliveTime;
    }
    public int getExpires() {
        return expires;
    }
    public void setExpires(int expires) {
        this.expires = expires;
    }
    public String getCreateTime() {
        return createTime;
    }
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    public String getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
    public String getMediaServerId() {
        return mediaServerId;
    }
    public void setMediaServerId(String mediaServerId) {
        this.mediaServerId = mediaServerId;
    }
    public String getCharset() {
        return charset;
    }
    public void setCharset(String charset) {
        this.charset = charset;
    }
    public int getSubscribeCycleForCatalog() {
        return subscribeCycleForCatalog;
    }
    public void setSubscribeCycleForCatalog(int subscribeCycleForCatalog) {
        this.subscribeCycleForCatalog = subscribeCycleForCatalog;
    }
    public int getSubscribeCycleForMobilePosition() {
        return subscribeCycleForMobilePosition;
    }
    public void setSubscribeCycleForMobilePosition(int subscribeCycleForMobilePosition) {
        this.subscribeCycleForMobilePosition = subscribeCycleForMobilePosition;
    }
    public int getMobilePositionSubmissionInterval() {
        return mobilePositionSubmissionInterval;
    }
    public void setMobilePositionSubmissionInterval(int mobilePositionSubmissionInterval) {
        this.mobilePositionSubmissionInterval = mobilePositionSubmissionInterval;
    }
    public int getSubscribeCycleForAlarm() {
        return subscribeCycleForAlarm;
    }
    public void setSubscribeCycleForAlarm(int subscribeCycleForAlarm) {
        this.subscribeCycleForAlarm = subscribeCycleForAlarm;
    }
    public boolean isSsrcCheck() {
        return ssrcCheck;
    }
    public void setSsrcCheck(boolean ssrcCheck) {
        this.ssrcCheck = ssrcCheck;
    }
    public String getGeoCoordSys() {
        return geoCoordSys;
    }
    public void setGeoCoordSys(String geoCoordSys) {
        this.geoCoordSys = geoCoordSys;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getSdpIp() {
        return sdpIp;
    }
    public void setSdpIp(String sdpIp) {
        this.sdpIp = sdpIp;
    }
    public String getLocalIp() {
        return localIp;
    }
    public void setLocalIp(String localIp) {
        this.localIp = localIp;
    }
    public int getKeepaliveIntervalTime() {
        return keepaliveIntervalTime;
    }
    public void setKeepaliveIntervalTime(int keepaliveIntervalTime) {
        this.keepaliveIntervalTime = keepaliveIntervalTime;
    }
    public boolean isAsMessageChannel() {
        return asMessageChannel;
    }
    public void setAsMessageChannel(boolean asMessageChannel) {
        this.asMessageChannel = asMessageChannel;
    }
    public Object getSipTransactionInfo() {
        return sipTransactionInfo;
    }
    public void setSipTransactionInfo(Object sipTransactionInfo) {
        this.sipTransactionInfo = sipTransactionInfo;
    }
    public boolean isBroadcastPushAfterAck() {
        return broadcastPushAfterAck;
    }
    public void setBroadcastPushAfterAck(boolean broadcastPushAfterAck) {
        this.broadcastPushAfterAck = broadcastPushAfterAck;
    }
}
ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java
@@ -662,7 +662,7 @@
    @Override
    public String getFrameImgByDevice(String deviceId, String channelId) {
        String url = String.format(this.rtspServer + "/start/%s/%s", deviceId, channelId);
        String url = String.format(this.rtspServer + "/api/play/start/%s/%s", deviceId, channelId);
        String result = HttpUtils.sendGet(url);
        log.error("拿到取流响应结果:" + result);
        WVPResult wvpResult = JSON.parseObject(result, WVPResult.class);
ycl-server/src/main/java/com/ycl/task/DeviceChannelTask.java
File was deleted
ycl-server/src/main/java/com/ycl/task/DeviceSynTask.java
New file
@@ -0,0 +1,66 @@
package com.ycl.task;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.github.pagehelper.PageInfo;
import com.ycl.platform.domain.entity.DeviceInfo;
import com.ycl.platform.mapper.DeviceInfoMapper;
import com.ycl.platform.wvp.Device;
import com.ycl.platform.wvp.WVPResult;
import com.ycl.utils.http.HttpUtils;
import lombok.RequiredArgsConstructor;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * "国标设备"同步
 *
 * @author:xp
 * @date:2024/8/21 15:18
 */
@RequiredArgsConstructor
@Component("deviceSynTask")
public class DeviceSynTask {
    private final DeviceInfoMapper deviceInfoMapper;
    @Value("${rtsp.server:http://127.0.0.1:7788}")
    private String rtspServer;
    public void run() {
        String result = HttpUtils.sendGet(rtspServer + "/api/device/query/devices?page=1&count=15");
        WVPResult wvpResult = JSON.parseObject(result, WVPResult.class);
        if (0 == wvpResult.getCode()) {
            PageInfo<Device> page = (PageInfo) wvpResult.getData();
            List<Device> list = page.getList();
            if (! CollectionUtils.isEmpty(list)) {
                list.stream().forEach(item -> {
                    DeviceInfo device = new LambdaQueryChainWrapper<>(deviceInfoMapper)
                            .eq(DeviceInfo::getDeviceId, item.getDeviceId())
                            .one();
                    if (Objects.isNull(device)) {
                        DeviceInfo deviceInfo = new DeviceInfo();
                        deviceInfo.setDeviceId(item.getDeviceId());
                        deviceInfo.setDeviceName(item.getName());
                        Date now = new Date();
                        deviceInfo.setCreateTime(now);
                        deviceInfo.setUpdateTime(now);
                        deviceInfo.setDeleted(0);
                        deviceInfoMapper.insert(deviceInfo);
                    } else {
                        device.setDeviceName(item.getName());
                        deviceInfoMapper.updateById(device);
                    }
                });
            }
        }
    }
}
ycl-server/src/main/java/com/ycl/task/WorkOrderImgTask.java
@@ -1,10 +1,14 @@
package com.ycl.task;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.ycl.platform.domain.entity.DeviceInfo;
import com.ycl.platform.domain.vo.DeviceInfoVO;
import com.ycl.platform.mapper.DeviceInfoMapper;
import com.ycl.platform.service.WorkOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.List;
@@ -25,6 +29,7 @@
public class WorkOrderImgTask {
    private final WorkOrderService workOrderService;
    private final DeviceInfoMapper deviceInfoMapper;
    private static final ExecutorService executorService = new ThreadPoolExecutor(8,
            24,
@@ -37,9 +42,20 @@
    public void run() {
        // 查出故障的设备
        List<DeviceInfoVO> deviceList = workOrderService.hasErrorWorkOrderList();
        if (CollectionUtils.isEmpty(deviceList)) {
            return;
        }
        List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper)
                .orderByDesc(DeviceInfo::getUpdateTime)
                .last("limit 1")
                .list();
        if (CollectionUtils.isEmpty(gbDevices)) {
            return;
        }
        for (DeviceInfoVO deviceInfo : deviceList) {
            executorService.submit(() -> {
                String frameImg = workOrderService.getFrameImgByDevice(deviceInfo.getDeviceId(), deviceInfo.getChannelId());
                // 国标设备的编码就是取视频流的设备编码,国标设备就一个。国标设备的每一个通道代表一个摄像头,也就是设备id是取流的通道id
                String frameImg = workOrderService.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), deviceInfo.getDeviceId());
                if (StringUtils.hasText(frameImg)) {
                    workOrderService.updateImgById(deviceInfo.getWorkOrderId(), frameImg);
                }
ycl-server/src/main/resources/mapper/zgyw/WorkOrderMapper.xml
@@ -215,12 +215,11 @@
    <select id="hasErrorWorkOrderList" resultType="com.ycl.platform.domain.vo.DeviceInfoVO">
        SELECT
               wo.id as workOrderId,
               we.device_id,
               wec.channel_id
               wo.serial_number as deviceId
        FROM
             t_work_order wo
                 INNER JOIN wvp2.wvp_device we ON we.device_id = wo.serial_number
                 INNER JOIN wvp2.wvp_device_channel wec ON we.device_id = wec.device_id
        WHERE
            deleted = 0
    </select>
    <insert id="addMany">