213 changed files with 9990 additions and 300 deletions
@ -0,0 +1,10 @@ |
|||
package org.dromara.system.api; |
|||
|
|||
import org.dromara.system.api.domain.bo.RemoteNoticeBo; |
|||
import org.dromara.system.api.domain.vo.RemotePostVo; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface RemoteNoticeService { |
|||
int saveNotice(RemoteNoticeBo bo); |
|||
} |
@ -0,0 +1,20 @@ |
|||
package org.dromara.system.api; |
|||
|
|||
import org.dromara.common.core.domain.R; |
|||
import org.dromara.system.api.domain.vo.RemoteClientVo; |
|||
|
|||
/** |
|||
* 客户端服务 |
|||
* |
|||
* @author Michelle.Chung |
|||
*/ |
|||
public interface RemoteSubmailConfigService { |
|||
|
|||
/** |
|||
* 根据客户端id获取客户端详情 |
|||
* |
|||
* @return 客户端对象 |
|||
*/ |
|||
R<String> remoteCmdSend(String code, String multiParam ); |
|||
|
|||
} |
@ -0,0 +1,8 @@ |
|||
package org.dromara.system.api; |
|||
|
|||
import org.dromara.system.api.domain.vo.RemoteSubscribeApiVo; |
|||
|
|||
public interface RemoteSubscribeService { |
|||
RemoteSubscribeApiVo getPrivateKey(String subscribeApiCode); |
|||
|
|||
} |
@ -0,0 +1,74 @@ |
|||
package org.dromara.system.api.domain.bo; |
|||
|
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serial; |
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 操作日志记录表 oper_log |
|||
* |
|||
* @author Lion Li |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
public class RemoteNoticeBo implements Serializable { |
|||
|
|||
@Serial |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
private Long noticeId; |
|||
|
|||
|
|||
/** |
|||
* 公告标题 |
|||
*/ |
|||
private String noticeTitle; |
|||
|
|||
/** |
|||
* 公告类型(1通知 2公告) |
|||
*/ |
|||
private String noticeType; |
|||
|
|||
/** |
|||
* 公告内容 |
|||
*/ |
|||
private String noticeContent; |
|||
|
|||
/** |
|||
* 公告状态(0正常 1关闭) |
|||
*/ |
|||
private String status; |
|||
|
|||
/** |
|||
* 备注 |
|||
*/ |
|||
private String remark; |
|||
|
|||
private Integer isRead; |
|||
/** |
|||
* 创建部门 |
|||
*/ |
|||
|
|||
private Long createDept; |
|||
|
|||
/** |
|||
* 创建者 |
|||
*/ |
|||
|
|||
private Long createBy; |
|||
private String deviceSn; |
|||
|
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
private Date createTime; |
|||
|
|||
private String param; |
|||
|
|||
|
|||
} |
@ -0,0 +1,49 @@ |
|||
package org.dromara.system.api.domain.vo; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serial; |
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class RemoteSubscribeApiVo implements Serializable { |
|||
|
|||
@Serial |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
|
|||
private Long id; |
|||
|
|||
/** |
|||
* 订阅名称 |
|||
*/ |
|||
private String subscribeName; |
|||
|
|||
/** |
|||
* 订阅编码 |
|||
*/ |
|||
private String subscribeCode; |
|||
|
|||
/** |
|||
* 订阅人 |
|||
*/ |
|||
private List<String> subscribeUser; |
|||
|
|||
/** |
|||
* 公钥 |
|||
*/ |
|||
private String publicKey; |
|||
|
|||
/** |
|||
*私钥 |
|||
*/ |
|||
private String privateKey; |
|||
|
|||
/** |
|||
*是否开启 |
|||
*/ |
|||
private Boolean isEnable; |
|||
|
|||
|
|||
} |
@ -0,0 +1,22 @@ |
|||
package org.dromara.auth.form; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.dromara.common.core.domain.model.LoginBody; |
|||
|
|||
/** |
|||
* 免密登录对象 |
|||
* |
|||
* @author Lion Li |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class CasLoginBody extends LoginBody { |
|||
|
|||
/** |
|||
* 用户名 |
|||
*/ |
|||
private String username; |
|||
|
|||
|
|||
} |
@ -0,0 +1,56 @@ |
|||
package org.dromara.auth.service.impl; |
|||
|
|||
|
|||
import cn.dev33.satoken.stp.SaLoginModel; |
|||
import cn.dev33.satoken.stp.StpUtil; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.dubbo.config.annotation.DubboReference; |
|||
import org.dromara.auth.domain.vo.LoginVo; |
|||
import org.dromara.auth.form.CasLoginBody; |
|||
import org.dromara.auth.service.IAuthStrategy; |
|||
import org.dromara.common.json.utils.JsonUtils; |
|||
import org.dromara.common.satoken.utils.LoginHelper; |
|||
import org.dromara.common.tenant.helper.TenantHelper; |
|||
import org.dromara.system.api.RemoteUserService; |
|||
import org.dromara.system.api.domain.vo.RemoteClientVo; |
|||
import org.dromara.system.api.model.LoginUser; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Slf4j |
|||
@Service("cas" + IAuthStrategy.BASE_NAME) |
|||
@RequiredArgsConstructor |
|||
public class CasAuthStrategy implements IAuthStrategy{ |
|||
|
|||
@DubboReference |
|||
private RemoteUserService remoteUserService; |
|||
|
|||
@Override |
|||
public LoginVo login(String body, RemoteClientVo client) { |
|||
CasLoginBody loginBody = JsonUtils.parseObject(body, CasLoginBody.class); |
|||
String tenantId = loginBody.getTenantId(); |
|||
String username = loginBody.getUsername(); |
|||
|
|||
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> { |
|||
return remoteUserService.getUserInfo(username, tenantId); |
|||
}); |
|||
|
|||
loginUser.setClientKey(client.getClientKey()); |
|||
loginUser.setDeviceType(client.getDeviceType()); |
|||
SaLoginModel model = new SaLoginModel(); |
|||
model.setDevice(client.getDeviceType()); |
|||
// 例如: 后台用户30分钟过期 app用户1天过期
|
|||
model.setTimeout(client.getTimeout()); |
|||
model.setActiveTimeout(client.getActiveTimeout()); |
|||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId()); |
|||
|
|||
// 生成token
|
|||
LoginHelper.login(loginUser, model); |
|||
|
|||
LoginVo loginVo = new LoginVo(); |
|||
loginVo.setAccessToken(StpUtil.getTokenValue()); |
|||
loginVo.setExpireIn(StpUtil.getTokenTimeout()); |
|||
loginVo.setClientId(client.getClientId()); |
|||
return loginVo; |
|||
} |
|||
} |
@ -0,0 +1,108 @@ |
|||
package org.dromara.auth.util; |
|||
|
|||
import org.apache.http.HttpEntity; |
|||
import org.apache.http.HttpResponse; |
|||
import org.apache.http.client.ClientProtocolException; |
|||
import org.apache.http.client.config.RequestConfig; |
|||
import org.apache.http.client.methods.*; |
|||
import org.apache.http.entity.ContentType; |
|||
import org.apache.http.entity.StringEntity; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.util.EntityUtils; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.Map; |
|||
|
|||
public class HttpClientUtil { |
|||
|
|||
// 默认超时时间
|
|||
private static final int TIMEOUT = 5000; |
|||
|
|||
// 创建默认的 HttpClient
|
|||
private static CloseableHttpClient createHttpClient() { |
|||
RequestConfig config = RequestConfig.custom() |
|||
.setConnectTimeout(TIMEOUT) |
|||
.setConnectionRequestTimeout(TIMEOUT) |
|||
.setSocketTimeout(TIMEOUT) |
|||
.build(); |
|||
return HttpClients.custom() |
|||
.setDefaultRequestConfig(config) |
|||
.build(); |
|||
} |
|||
|
|||
// 发送 GET 请求
|
|||
public static String sendGet(String url, Map<String, String> headers) throws IOException { |
|||
HttpGet httpGet = new HttpGet(url); |
|||
if (headers != null) { |
|||
headers.forEach(httpGet::addHeader); |
|||
} |
|||
|
|||
try (CloseableHttpClient httpClient = createHttpClient(); |
|||
CloseableHttpResponse response = httpClient.execute(httpGet)) { |
|||
|
|||
return handleResponse(response); |
|||
} |
|||
} |
|||
|
|||
// 发送 POST 请求
|
|||
public static String sendPost(String url, String body, Map<String, String> headers) throws IOException { |
|||
HttpPost httpPost = new HttpPost(url); |
|||
if (headers != null) { |
|||
headers.forEach(httpPost::addHeader); |
|||
} |
|||
if (body != null) { |
|||
HttpEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON); |
|||
httpPost.setEntity(entity); |
|||
} |
|||
|
|||
try (CloseableHttpClient httpClient = createHttpClient(); |
|||
CloseableHttpResponse response = httpClient.execute(httpPost)) { |
|||
|
|||
return handleResponse(response); |
|||
} |
|||
} |
|||
|
|||
// 发送 PUT 请求
|
|||
public static String sendPut(String url, String body, Map<String, String> headers) throws IOException { |
|||
HttpPut httpPut = new HttpPut(url); |
|||
if (headers != null) { |
|||
headers.forEach(httpPut::addHeader); |
|||
} |
|||
if (body != null) { |
|||
HttpEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON); |
|||
httpPut.setEntity(entity); |
|||
} |
|||
|
|||
try (CloseableHttpClient httpClient = createHttpClient(); |
|||
CloseableHttpResponse response = httpClient.execute(httpPut)) { |
|||
|
|||
return handleResponse(response); |
|||
} |
|||
} |
|||
|
|||
// 发送 DELETE 请求
|
|||
public static String sendDelete(String url, Map<String, String> headers) throws IOException { |
|||
HttpDelete httpDelete = new HttpDelete(url); |
|||
if (headers != null) { |
|||
headers.forEach(httpDelete::addHeader); |
|||
} |
|||
|
|||
try (CloseableHttpClient httpClient = createHttpClient(); |
|||
CloseableHttpResponse response = httpClient.execute(httpDelete)) { |
|||
|
|||
return handleResponse(response); |
|||
} |
|||
} |
|||
|
|||
// 处理响应
|
|||
private static String handleResponse(HttpResponse response) throws IOException { |
|||
int statusCode = response.getStatusLine().getStatusCode(); |
|||
if (statusCode >= 200 && statusCode < 300) { |
|||
HttpEntity entity = response.getEntity(); |
|||
return entity != null ? EntityUtils.toString(entity) : null; |
|||
} else { |
|||
throw new ClientProtocolException("Unexpected response status: " + statusCode); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
package org.dromara.common.sdk.cloudapi.device; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonValue; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import org.dromara.common.sdk.exception.CloudSDKException; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* @author sean |
|||
* @version 1.7 |
|||
* @date 2023/5/26 |
|||
*/ |
|||
@Schema(description = "DeviceTypeVideoEnum", enumAsRef = true) |
|||
public enum DeviceTypeVideoEnum { |
|||
|
|||
ZERO(0), |
|||
SEVEN(7); |
|||
|
|||
; |
|||
|
|||
private final int videoType; |
|||
|
|||
DeviceTypeVideoEnum(int videoType) { |
|||
this.videoType = videoType; |
|||
} |
|||
|
|||
@JsonValue |
|||
public int getVideoType() { |
|||
return videoType; |
|||
} |
|||
|
|||
@JsonCreator |
|||
public static DeviceTypeVideoEnum find(int videoType) { |
|||
return Arrays.stream(values()).filter(typeEnum -> typeEnum.videoType == videoType).findAny() |
|||
.orElseThrow(() -> new CloudSDKException(DeviceTypeVideoEnum.class, videoType)); |
|||
} |
|||
} |
@ -0,0 +1,80 @@ |
|||
package org.dromara.common.sdk.cloudapi.device; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonValue; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import org.dromara.common.core.utils.StringUtils; |
|||
import org.dromara.common.sdk.exception.CloudSDKException; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* @author sean |
|||
* @version 1.7 |
|||
* @date 2023/5/19 |
|||
*/ |
|||
@Schema(description = "device model key.", format = "domain-type-subType", enumAsRef = true, example = "0-89-0") |
|||
public enum DeviceVideoEnum { |
|||
|
|||
|
|||
DOCK(DeviceTypeEnum.DOCK_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.SEVEN), |
|||
|
|||
DJIDock2(DeviceTypeEnum.DOCK_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.SEVEN), |
|||
|
|||
DOCK3(DeviceTypeEnum.DOCK_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.SEVEN), |
|||
Matrice30(DeviceTypeEnum.M30_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.ZERO), |
|||
|
|||
Matrice30T(DeviceTypeEnum.M30T_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.ZERO), |
|||
M3D(DeviceTypeEnum.M3D_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.ZERO), |
|||
|
|||
M3TD(DeviceTypeEnum.M3TD_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.ZERO), |
|||
|
|||
M4D(DeviceTypeEnum.M4D_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.ZERO), |
|||
|
|||
M4TD(DeviceTypeEnum.M4TD_CAMERA, DeviceSubTypeEnum.ZERO, DeviceTypeVideoEnum.ZERO), |
|||
|
|||
; |
|||
|
|||
|
|||
@Schema(enumAsRef = true) |
|||
private final DeviceTypeEnum type; |
|||
|
|||
@Schema(enumAsRef = true) |
|||
private final DeviceSubTypeEnum subType; |
|||
|
|||
@Schema(enumAsRef = true) |
|||
private final DeviceTypeVideoEnum videoType; |
|||
|
|||
DeviceVideoEnum(DeviceTypeEnum type, DeviceSubTypeEnum subType, DeviceTypeVideoEnum videoType) { |
|||
this.type = type; |
|||
this.subType = subType; |
|||
this.videoType = videoType; |
|||
} |
|||
|
|||
public DeviceTypeEnum getType() { |
|||
return type; |
|||
} |
|||
|
|||
public DeviceSubTypeEnum getSubType() { |
|||
return subType; |
|||
} |
|||
|
|||
public DeviceTypeVideoEnum getVideoType() { |
|||
return videoType; |
|||
} |
|||
|
|||
@JsonValue |
|||
public String getDevice() { |
|||
return String.format("%s-%s-%s", type.getType(), subType.getSubType(),videoType.getVideoType()); |
|||
} |
|||
|
|||
|
|||
@JsonCreator |
|||
public static DeviceVideoEnum find(String key) { |
|||
String finalKey = key.replaceAll(" ",""); |
|||
return Arrays.stream(values()).filter(device -> device.toString().equals(finalKey)) |
|||
.findAny().orElseThrow(() -> new CloudSDKException(DeviceEnum.class, finalKey)); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,45 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<parent> |
|||
<groupId>org.dromara</groupId> |
|||
<artifactId>dk-common</artifactId> |
|||
<version>${revision}</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>common-rocketmq</artifactId> |
|||
|
|||
<description> |
|||
common-rocketmq 配置中心 |
|||
</description> |
|||
|
|||
<dependencies> |
|||
<!--rocketmq消息队列--> |
|||
<dependency> |
|||
<groupId>org.apache.rocketmq</groupId> |
|||
<artifactId>rocketmq-client</artifactId> |
|||
<version> 4.9.0</version> |
|||
</dependency> |
|||
|
|||
<!--RocketMQ--> |
|||
<dependency> |
|||
<groupId>org.apache.rocketmq</groupId> |
|||
<artifactId>rocketmq-spring-boot-starter</artifactId> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.dromara</groupId> |
|||
<artifactId>common-core</artifactId> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.dromara</groupId> |
|||
<artifactId>common-nacos</artifactId> |
|||
</dependency> |
|||
|
|||
</dependencies> |
|||
|
|||
|
|||
</project> |
@ -0,0 +1,58 @@ |
|||
package org.dromara.common.rocketmq.config; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.rocketmq.client.exception.MQClientException; |
|||
import org.apache.rocketmq.client.producer.DefaultMQProducer; |
|||
import org.dromara.common.rocketmq.model.ProducerMode; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.autoconfigure.AutoConfiguration; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
|
|||
|
|||
/** |
|||
* mq搭建地址连接 |
|||
* 生产者初者连接信息 具体看nacos配置 |
|||
*/ |
|||
@AutoConfiguration |
|||
@Slf4j |
|||
@EnableConfigurationProperties(ProducerMode.class) |
|||
public class ProducerConfig { |
|||
|
|||
/** |
|||
* 远程调用连接信息 |
|||
*/ |
|||
public static DefaultMQProducer producer; |
|||
|
|||
/** |
|||
* 连接客户端信息配置 具体看nacos配置 |
|||
*/ |
|||
@Autowired |
|||
private ProducerMode producerMode; |
|||
|
|||
@Bean |
|||
public DefaultMQProducer getRocketMQProducer() { |
|||
producer = new DefaultMQProducer(producerMode.getGroupName()); |
|||
producer.setNamesrvAddr(producerMode.getNameServer()); |
|||
//如果需要同一个jvm中不同的producer往不同的mq集群发送消息,需要设置不同的instanceName
|
|||
if(producerMode.getMaxMessageSize()!=null){ |
|||
producer.setMaxMessageSize(producerMode.getMaxMessageSize()); |
|||
} |
|||
if(producerMode.getSendMsgTimeout()!=null){ |
|||
producer.setSendMsgTimeout(producerMode.getSendMsgTimeout()); |
|||
} |
|||
//如果发送消息失败,设置重试次数,默认为2次
|
|||
if(producerMode.getRetryTimesWhenSendFailed()!=null){ |
|||
producer.setRetryTimesWhenSendFailed(producerMode.getRetryTimesWhenSendFailed()); |
|||
} |
|||
producer.setVipChannelEnabled(false); |
|||
try { |
|||
producer.start(); |
|||
log.info("生产者初始化成功:{}",producer.toString()); |
|||
} catch (MQClientException e) { |
|||
log.error("生产者初始化失败:{}",e.getMessage()); |
|||
} |
|||
return producer; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
package org.dromara.common.rocketmq.model; |
|||
|
|||
import lombok.Data; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* 生产者初始化 |
|||
*/ |
|||
@Data |
|||
@ConfigurationProperties(prefix = "rocketmq.producer") |
|||
public class ProducerMode { |
|||
|
|||
private String groupName; |
|||
|
|||
private String nameServer; |
|||
|
|||
private Integer maxMessageSize; |
|||
|
|||
private Integer sendMsgTimeout; |
|||
|
|||
private Integer retryTimesWhenSendFailed; |
|||
} |
@ -0,0 +1,189 @@ |
|||
package org.dromara.common.rocketmq.producer; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.rocketmq.client.exception.MQBrokerException; |
|||
import org.apache.rocketmq.client.exception.MQClientException; |
|||
import org.apache.rocketmq.client.producer.SendCallback; |
|||
import org.apache.rocketmq.client.producer.SendResult; |
|||
import org.apache.rocketmq.common.message.Message; |
|||
import org.apache.rocketmq.remoting.common.RemotingHelper; |
|||
import org.apache.rocketmq.remoting.exception.RemotingException; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.UnsupportedEncodingException; |
|||
import java.text.DateFormat; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
import static org.dromara.common.rocketmq.config.ProducerConfig.producer; |
|||
|
|||
|
|||
/** |
|||
* 消息发送 |
|||
*/ |
|||
@Slf4j |
|||
public class MessageProducerUtil { |
|||
|
|||
/** |
|||
* 同步发送消息 |
|||
* @param topic 主题 |
|||
* @param tag 标签 |
|||
* @param key 自定义的key,根据业务来定 |
|||
* @param value 消息的内容 |
|||
* 通过调用 send() 方法发送消息,阻塞等待服务器响应。 |
|||
*/ |
|||
public static SendResult sendSynchronizeMessage(String topic, String tag, String key, String value){ |
|||
String body = "topic:【"+topic+"】, tag:【"+tag+"】, key:【"+key+"】, value:【"+value+"】"; |
|||
try { |
|||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET)); |
|||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value)); |
|||
SendResult result = producer.send(msg); |
|||
return result; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
log.error("消息初始化失败!body:{}",body); |
|||
|
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 单向发送消息 |
|||
* @param topic 主题 |
|||
* @param tag 标签 |
|||
* @param key 自定义的key,根据业务来定 |
|||
* @param value 消息的内容 |
|||
* 单向发送:通过调用 sendOneway() 方法发送消息,不关心发送结果,适用于对可靠性要求不高的场景。 |
|||
*/ |
|||
public static void sendOnewayMessage(String topic, String tag, String key, String value){ |
|||
String body = "topic:【"+topic+"】, tag:【"+tag+"】, key:【"+key+"】, value:【"+value+"】"; |
|||
try { |
|||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET)); |
|||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value)); |
|||
producer.sendOneway(msg); |
|||
} catch (UnsupportedEncodingException e) { |
|||
log.error("消息初始化失败!body:{}",body); |
|||
|
|||
} catch (MQClientException | InterruptedException | RemotingException e) { |
|||
log.error("消息发送失败! body:{}",body); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 批量发送消息 |
|||
* @param messages 消息列表 |
|||
* 批量发送:通过调用 send() 方法并传入多条消息,实现批量发送消息。 |
|||
*/ |
|||
// public static SendResult sendBatchMessage(List<Message> messages){
|
|||
// String body = messages.toString();
|
|||
// try {
|
|||
// System.out.println("生产者发送消息:"+ messages);
|
|||
// // 发送批量消息
|
|||
// SendResult sendResult = producer.send(messages);
|
|||
// return sendResult;
|
|||
// } catch (MQClientException | InterruptedException | RemotingException e) {
|
|||
// log.error("消息发送失败! body:{}",body);
|
|||
// } catch (MQBrokerException e) {
|
|||
// throw new RuntimeException(e);
|
|||
// }
|
|||
// return null;
|
|||
// }
|
|||
|
|||
|
|||
/** |
|||
* 发送有序的消息 |
|||
* @param messagesList Message集合 |
|||
* @param messageQueueNumber 消息队列数量,根据实际情况设定 |
|||
* 顺序发送: messageQueueNumber 表示消息的业务标识,可以根据具体需求进行设置来保证消息按顺序发送。 |
|||
*/ |
|||
// public static SendResult sendOrderlyMessage(List<Message> messagesList, Integer messageQueueNumber) {
|
|||
// SendResult result = null;
|
|||
// for (Message message : messagesList) {
|
|||
// try {
|
|||
// result = producer.send(message, (list, msg, arg) -> {
|
|||
// Integer queueNumber = (Integer) arg;
|
|||
// //int queueIndex = queueNumber % list.size();
|
|||
// return list.get(queueNumber);
|
|||
// }, messageQueueNumber);//根据编号取模,选择消息队列
|
|||
// } catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
|
|||
// log.error("发送有序消息失败");
|
|||
// return result;
|
|||
// }
|
|||
// }
|
|||
// return result;
|
|||
// }
|
|||
|
|||
/** |
|||
* 发送延迟消息 |
|||
* @param topic 主题 |
|||
* @param tag 标签 |
|||
* @param key 自定义的key,根据业务来定 |
|||
* @param value 消息的内容 |
|||
* 延迟发送:通过设置延迟级别来实现延迟发送消息。 |
|||
*/ |
|||
public static SendResult sendDelayMessage(String topic, String tag, String key, String value) |
|||
{ |
|||
SendResult result = null; |
|||
try |
|||
{ |
|||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET)); |
|||
//设置消息延迟级别,我这里设置5,对应就是延时一分钟
|
|||
// "1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h"
|
|||
msg.setDelayTimeLevel(4); |
|||
// 发送消息到一个Broker
|
|||
result = producer.send(msg); |
|||
// 通过sendResult返回消息是否成功送达
|
|||
log.info("发送延迟消息结果:======sendResult:{}", result); |
|||
DateFormat format =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
log.info("发送时间:{}", format.format(new Date())); |
|||
return result; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
e.printStackTrace(); |
|||
log.error("延迟消息队列推送消息异常:{},推送内容:{}", e.getMessage(), result); |
|||
} |
|||
return result; |
|||
} |
|||
/** |
|||
* 发送异步的消息 |
|||
* @param topic 主题 |
|||
* @param tag 标签 |
|||
* @param key 自定义的key,根据业务来定 |
|||
* @param value 消息的内容 |
|||
* 通过调用 send() 方法,并传入一个 SendCallback 对象,在发送消息的同时可以继续处理其他逻辑,消息发送结果通过回调函数通知。 |
|||
*/ |
|||
public static SendResult sendAsyncProducerMessage(String topic, String tag, String key, String value){ |
|||
|
|||
try { |
|||
//创建一个消息实例,指定主题、标签和消息体。
|
|||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET)); |
|||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value)); |
|||
producer.send(msg,new SendCallback() { |
|||
// 异步回调的处理
|
|||
@Override |
|||
public void onSuccess(SendResult sendResult) { |
|||
System.out.printf("%-10d 异步发送消息成功 %s %n", msg, sendResult.getMsgId()); |
|||
} |
|||
@Override |
|||
public void onException(Throwable e) { |
|||
System.out.printf("%-10d 异步发送消息失败 %s %n", msg, e); |
|||
e.printStackTrace(); |
|||
} |
|||
}); |
|||
} catch (MQClientException e) { |
|||
e.printStackTrace(); |
|||
} catch (RemotingException e) { |
|||
e.printStackTrace(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} catch (UnsupportedEncodingException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1 @@ |
|||
org.dromara.common.rocketmq.config.ProducerConfig |
@ -0,0 +1,34 @@ |
|||
package org.dromara.business.domain; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.dromara.common.mybatis.core.domain.BaseEntity; |
|||
|
|||
import java.io.Serial; |
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* @auther yq |
|||
* @data 2025/2/26 |
|||
*/ |
|||
@Data |
|||
@TableName("business_task_label") |
|||
public class BusinessTaskLabel implements Serializable { |
|||
@Serial |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
private Long taskId; |
|||
|
|||
private String labelCn; |
|||
private String labelEn; |
|||
|
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package org.dromara.business.domain.vo; |
|||
|
|||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import io.github.linpeilie.annotations.AutoMapper; |
|||
import lombok.Data; |
|||
import org.dromara.business.domain.BusinessTask; |
|||
import org.dromara.business.domain.BusinessTaskLabel; |
|||
|
|||
import java.io.Serial; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @auther yq |
|||
* @data 2025/2/26 |
|||
*/ |
|||
@Data |
|||
@ExcelIgnoreUnannotated |
|||
@AutoMapper(target = BusinessTaskLabel.class) |
|||
public class BusinessTaskLabelVo implements Serializable { |
|||
@Serial |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
|
|||
private Long id; |
|||
|
|||
private Long taskId; |
|||
|
|||
private String labelCn; |
|||
private String labelEn; |
|||
|
|||
|
|||
} |
@ -0,0 +1,27 @@ |
|||
package org.dromara.business.mapper; |
|||
|
|||
|
|||
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.dromara.business.domain.BusinessTask; |
|||
import org.dromara.business.domain.BusinessTaskLabel; |
|||
import org.dromara.business.domain.bo.BusinessTaskBo; |
|||
import org.dromara.business.domain.vo.BusinessTaskLabelVo; |
|||
import org.dromara.business.domain.vo.BusinessTaskVo; |
|||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; |
|||
|
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* 工单预约Mapper接口 |
|||
* |
|||
* @author LionLi |
|||
* @date 2025-02-26 |
|||
*/ |
|||
public interface BusinessTaskLabelMapper extends BaseMapperPlus<BusinessTaskLabel, BusinessTaskLabelVo> { |
|||
List<BusinessTaskLabelVo> selectTaskLabelList(@Param("taskId") Long taskId); |
|||
|
|||
|
|||
} |
@ -0,0 +1,11 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="org.dromara.business.mapper.BusinessTaskLabelMapper"> |
|||
|
|||
|
|||
<select id="selectTaskLabelList" resultType="org.dromara.business.domain.vo.BusinessTaskLabelVo"> |
|||
select * from business_task_label where task_id=#{taskId} |
|||
</select> |
|||
</mapper> |
@ -0,0 +1,68 @@ |
|||
package org.dromara.sample.common.util; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
import java.nio.charset.StandardCharsets; |
|||
import java.security.MessageDigest; |
|||
|
|||
/** |
|||
* Md5加密方法 |
|||
* |
|||
* @author ruoyi |
|||
*/ |
|||
public class Md5Utils |
|||
{ |
|||
private static final Logger log = LoggerFactory.getLogger(Md5Utils.class); |
|||
|
|||
private static byte[] md5(String s) |
|||
{ |
|||
MessageDigest algorithm; |
|||
try |
|||
{ |
|||
algorithm = MessageDigest.getInstance("MD5"); |
|||
algorithm.reset(); |
|||
algorithm.update(s.getBytes("UTF-8")); |
|||
byte[] messageDigest = algorithm.digest(); |
|||
return messageDigest; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
log.error("MD5 Error...", e); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private static final String toHex(byte hash[]) |
|||
{ |
|||
if (hash == null) |
|||
{ |
|||
return null; |
|||
} |
|||
StringBuffer buf = new StringBuffer(hash.length * 2); |
|||
int i; |
|||
|
|||
for (i = 0; i < hash.length; i++) |
|||
{ |
|||
if ((hash[i] & 0xff) < 0x10) |
|||
{ |
|||
buf.append("0"); |
|||
} |
|||
buf.append(Long.toString(hash[i] & 0xff, 16)); |
|||
} |
|||
return buf.toString(); |
|||
} |
|||
|
|||
public static String hash(String s) |
|||
{ |
|||
try |
|||
{ |
|||
return new String(toHex(md5(s)).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
log.error("not supported charset...{}", e); |
|||
return s; |
|||
} |
|||
} |
|||
} |
@ -1,15 +0,0 @@ |
|||
package org.dromara.sample.feign; |
|||
|
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
|
|||
@FeignClient(name = "gateway",path = "business") |
|||
public interface BusinessTaskFeign { |
|||
|
|||
@PostMapping("/update/status") |
|||
void updateTaskStatus(@RequestParam String waylineId, |
|||
@RequestParam String status, |
|||
@RequestParam(required = false) String jobId, |
|||
@RequestParam(required = false) String jobName); |
|||
} |
@ -1,4 +1,4 @@ |
|||
package org.dromara.sample.fegin; |
|||
package org.dromara.sample.feign; |
|||
|
|||
import org.dromara.common.core.domain.R; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
@ -0,0 +1,16 @@ |
|||
package org.dromara.sample.feign; |
|||
|
|||
import org.dromara.common.core.domain.R; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
|
|||
import java.util.List; |
|||
|
|||
@FeignClient(name = "gateway",path = "system") |
|||
public interface RemoteSystemFeign { |
|||
|
|||
@GetMapping("/config/selectStreamType") |
|||
public List<String> selectStreamType(@RequestParam String deviceSn); |
|||
} |
@ -0,0 +1,87 @@ |
|||
package org.dromara.sample.manage.controller; |
|||
|
|||
import com.alibaba.nacos.common.utils.CollectionUtils; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.dromara.common.satoken.utils.LoginHelper; |
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.common.sdk.common.PaginationData; |
|||
import org.dromara.common.sdk.exception.CloudSDKErrorEnum; |
|||
import org.dromara.common.sdk.mqtt.property.PropertySetReplyResultEnum; |
|||
import org.dromara.sample.manage.model.dto.CallBackDTO; |
|||
import org.dromara.sample.manage.model.dto.DeviceDTO; |
|||
import org.dromara.sample.manage.model.dto.DeviceFirmwareUpgradeDTO; |
|||
import org.dromara.sample.manage.model.dto.EventsDTO; |
|||
import org.dromara.sample.manage.model.entity.WarningRecordEntity; |
|||
import org.dromara.sample.manage.service.IDeviceService; |
|||
import org.dromara.sample.manage.service.IEngineRecordService; |
|||
import org.dromara.sample.manage.service.IWarningRecordService; |
|||
import org.dromara.system.api.model.LoginUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Optional; |
|||
|
|||
/** |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/15 |
|||
*/ |
|||
@RestController |
|||
@Slf4j |
|||
@RequestMapping("${url.manage.prefix}${url.manage.version}/engineRecord") |
|||
@Tag(name = "无人机设备模块") |
|||
public class EngineRecordController { |
|||
|
|||
@Autowired |
|||
private IEngineRecordService engineRecordService; |
|||
@Autowired |
|||
private IWarningRecordService warningRecordService; |
|||
|
|||
/** |
|||
* 启动星罗引擎。 |
|||
* Get the topology list of all online devices in one workspace. |
|||
* @return |
|||
*/ |
|||
@PostMapping("/startEngine") |
|||
@Operation(summary = "启动星罗引擎。", description = "启动星罗引擎") |
|||
public HttpResultResponse<Map<String,Object>> startEngine(@RequestBody Map<String,Object> objectMap) { |
|||
return HttpResultResponse.success(engineRecordService.startEngine(objectMap)); |
|||
} |
|||
|
|||
@PostMapping("/closeEngine") |
|||
@Operation(summary = "关闭星罗引擎。", description = "关闭星罗引擎") |
|||
public HttpResultResponse closeEngine(@RequestBody Map<String,Object> objectMap) { |
|||
engineRecordService.closeEngine(objectMap); |
|||
return HttpResultResponse.success(); |
|||
} |
|||
|
|||
@PostMapping("/some") |
|||
@Operation(summary = "存储推流的预警(对外接口)。", description = "存储推流的预警(对外接口)。") |
|||
public void some(@RequestBody CallBackDTO callBackVo){ |
|||
WarningRecordEntity warningRecord = new WarningRecordEntity(); |
|||
List<WarningRecordEntity> list = new ArrayList<>(); |
|||
if (CollectionUtils.isNotEmpty(callBackVo.getEvents())){ |
|||
for (EventsDTO eventsVo :callBackVo.getEvents()){ |
|||
warningRecord.setTaskId(callBackVo.getTaskId()); |
|||
warningRecord.setAlgoId(eventsVo.getAlgoId()); |
|||
warningRecord.setEventId(eventsVo.getEventId()); |
|||
warningRecord.setExtraType(eventsVo.getExtraType()); |
|||
warningRecord.setPicUrl(eventsVo.getPicUrl()); |
|||
warningRecord.setTimestamp(eventsVo.getTimestamp()); |
|||
list.add(warningRecord); |
|||
} |
|||
warningRecordService.saveBatch(list); |
|||
System.out.println(callBackVo); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package org.dromara.sample.manage.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.dromara.sample.manage.model.entity.DeviceStreamEntity; |
|||
import org.dromara.sample.manage.model.entity.PlayTextEntity; |
|||
|
|||
/** |
|||
* |
|||
* @author sean.zhou |
|||
* @date 2021/11/10 |
|||
* @version 0.1 |
|||
*/ |
|||
public interface IDeviceStreamMapper extends BaseMapper<DeviceStreamEntity> { |
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
package org.dromara.sample.manage.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.dromara.sample.manage.model.entity.DeviceEntity; |
|||
import org.dromara.sample.manage.model.entity.EngineRecordEntity; |
|||
|
|||
/** |
|||
* |
|||
* @author sean.zhou |
|||
* @date 2021/11/10 |
|||
* @version 0.1 |
|||
*/ |
|||
public interface IEngineRecordMapper extends BaseMapper<EngineRecordEntity> { |
|||
|
|||
} |
@ -0,0 +1,18 @@ |
|||
package org.dromara.sample.manage.mapper; |
|||
|
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.dromara.sample.manage.model.entity.WarningRecordEntity; |
|||
|
|||
/** |
|||
* 设备对象-》用于存储设备Mapper接口 |
|||
* |
|||
* @author wuyuan |
|||
* @date 2022-10-25 |
|||
*/ |
|||
@Mapper |
|||
public interface WarningRecordMapper extends BaseMapper<WarningRecordEntity> { |
|||
|
|||
} |
|||
|
@ -0,0 +1,30 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 设备对象-》用于存储设备对象 iot_device |
|||
* |
|||
* @author wuyuan |
|||
* @date 2022-10-25 |
|||
*/ |
|||
@TableName("iot_device") |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Accessors(chain = true) |
|||
public class CallBackDTO implements Serializable { |
|||
//任务 id
|
|||
private String taskId; |
|||
|
|||
//检测事件列表
|
|||
private List<EventsDTO> events; |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* The entity class of the device |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class Engine implements Serializable { |
|||
|
|||
|
|||
|
|||
private String task_id; |
|||
|
|||
private String mission_batch; |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* The entity class of the device |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class EngineResponse implements Serializable { |
|||
|
|||
private Long code; |
|||
|
|||
private String message; |
|||
|
|||
private Engine data; |
|||
|
|||
|
|||
} |
@ -0,0 +1,45 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 设备对象-》用于存储设备对象 iot_device |
|||
* |
|||
* @author wuyuan |
|||
* @date 2022-10-25 |
|||
*/ |
|||
@TableName("iot_device") |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Accessors(chain = true) |
|||
public class EventsDTO implements Serializable { |
|||
//算法 id")
|
|||
private Integer algoId; |
|||
|
|||
//算法类型字符串")
|
|||
private String extraType; |
|||
|
|||
|
|||
//分配的事件 id")
|
|||
private String eventId; |
|||
|
|||
|
|||
//保存后图片的 url")
|
|||
private String picUrl; |
|||
|
|||
|
|||
//事件时间戳,单位:毫秒")
|
|||
private Integer timestamp; |
|||
|
|||
//检测事件列表")
|
|||
private List<ObjectsDTO> objects; |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* The entity class of the device |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class ExtraType implements Serializable { |
|||
|
|||
private Long id; |
|||
|
|||
private String sence; |
|||
|
|||
private String type; |
|||
|
|||
private String extra_type; |
|||
|
|||
private String model; |
|||
|
|||
private String user; |
|||
|
|||
private int difficult; |
|||
|
|||
private int if_open; |
|||
|
|||
private int sence_id; |
|||
|
|||
private Double conf; |
|||
|
|||
private int aiConfig; |
|||
|
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* The entity class of the device |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class ExtraTypeResponse implements Serializable { |
|||
|
|||
private Long code; |
|||
|
|||
private String message; |
|||
|
|||
private List<ExtraType> data; |
|||
|
|||
|
|||
} |
@ -0,0 +1,49 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 设备对象-》用于存储设备对象 iot_device |
|||
* |
|||
* @author wuyuan |
|||
* @date 2022-10-25 |
|||
*/ |
|||
@TableName("iot_device") |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Accessors(chain = true) |
|||
public class ObjectsDTO implements Serializable { |
|||
//画面运动方向角度,-180度 到 180度")
|
|||
private String anglePx; |
|||
|
|||
//属性截图,base64编码")
|
|||
private String attrImage; |
|||
|
|||
//属性名称,车牌,人脸,或其他")
|
|||
private String attrName; |
|||
|
|||
//属性文字")
|
|||
private String attrText; |
|||
|
|||
//类别唯一ID")
|
|||
private String classId; |
|||
|
|||
//画面像素速度,单位(像素/秒)")
|
|||
private Integer speedPx; |
|||
|
|||
//追踪ID")
|
|||
private String trackId; |
|||
|
|||
//目标中心X")
|
|||
private Integer x; |
|||
|
|||
//目标中心Y")
|
|||
private Integer y; |
|||
|
|||
|
|||
} |
@ -0,0 +1,37 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/23 |
|||
*/ |
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
public class StreamTypeDTO { |
|||
private String jobId; |
|||
|
|||
private String jobName; |
|||
|
|||
private String labelCn; |
|||
|
|||
|
|||
private String labelEn; |
|||
|
|||
private Long deptId; |
|||
|
|||
private String deptName; |
|||
|
|||
private String deviceSn; |
|||
|
|||
private String lat; |
|||
|
|||
private String lng; |
|||
|
|||
private String images; |
|||
|
|||
} |
@ -0,0 +1,43 @@ |
|||
package org.dromara.sample.manage.model.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* The entity class of the device |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@TableName(value = "manage_device_stream") |
|||
public class DeviceStreamEntity implements Serializable { |
|||
|
|||
@TableId(type = IdType.AUTO) |
|||
private Integer id; |
|||
|
|||
@TableField(value = "rtmp_url") |
|||
private String rtmpUrl; |
|||
|
|||
@TableField(value = "stream_type") |
|||
private String streamType; |
|||
|
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Date createTime; |
|||
|
|||
@TableField(fill = FieldFill.INSERT_UPDATE) |
|||
private Date updateTime; |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,48 @@ |
|||
package org.dromara.sample.manage.model.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
import java.time.LocalDateTime; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* The entity class of the EngineRecord |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@TableName(value = "engine_record") |
|||
public class EngineRecordEntity implements Serializable { |
|||
|
|||
@TableId(type = IdType.AUTO) |
|||
private Integer id; |
|||
|
|||
@TableField(value = "device_sn") |
|||
private String deviceSn; |
|||
|
|||
@TableField(value = "extra_type") |
|||
private String extraType; |
|||
|
|||
@TableField(value = "task_id") |
|||
private String taskId; |
|||
|
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Date createTime; |
|||
|
|||
@TableField(fill = FieldFill.INSERT_UPDATE) |
|||
private Date updateTime; |
|||
|
|||
@TableField(value = "push_url") |
|||
private String pushUrl; |
|||
|
|||
} |
@ -0,0 +1,55 @@ |
|||
package org.dromara.sample.manage.model.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 设备对象-》用于存储设备对象 iot_device |
|||
* |
|||
* @author wuyuan |
|||
* @date 2022-10-25 |
|||
*/ |
|||
@TableName("warning_record") |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Accessors(chain = true) |
|||
public class WarningRecordEntity implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@TableId(type = IdType.AUTO) |
|||
private String id; |
|||
|
|||
@TableField(value = "task_id") |
|||
private String taskId; |
|||
|
|||
@TableField(value = "algo_id") |
|||
//算法 id")
|
|||
private Integer algoId; |
|||
|
|||
@TableField(value = "extra_type") |
|||
//算法类型字符串")
|
|||
private String extraType; |
|||
|
|||
@TableField(value = "event_id") |
|||
//分配的事件 id")
|
|||
private String eventId; |
|||
|
|||
@TableField(value = "pic_url") |
|||
//保存后图片的 url")
|
|||
private String picUrl; |
|||
|
|||
@TableField(value = "timestamp") |
|||
//事件时间戳,单位:毫秒")
|
|||
private Integer timestamp; |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package org.dromara.sample.manage.service; |
|||
|
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.common.sdk.common.PaginationData; |
|||
import org.dromara.sample.manage.model.entity.PlayTextEntity; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author sean.zhou |
|||
* @date 2021/11/10 |
|||
* @version 0.1 |
|||
*/ |
|||
public interface IDeviceStreamService { |
|||
|
|||
|
|||
} |
@ -0,0 +1,32 @@ |
|||
package org.dromara.sample.manage.service; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import org.dromara.common.sdk.cloudapi.device.ControlSourceEnum; |
|||
import org.dromara.common.sdk.cloudapi.device.DeviceOsdHost; |
|||
import org.dromara.common.sdk.cloudapi.device.DockModeCodeEnum; |
|||
import org.dromara.common.sdk.cloudapi.device.DroneModeCodeEnum; |
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.common.sdk.common.PaginationData; |
|||
import org.dromara.common.sdk.config.version.GatewayManager; |
|||
import org.dromara.common.websocket.dto.BizCodeEnum; |
|||
import org.dromara.sample.manage.model.dto.DeviceDTO; |
|||
import org.dromara.sample.manage.model.dto.DeviceFirmwareUpgradeDTO; |
|||
import org.dromara.sample.manage.model.dto.TopologyDeviceDTO; |
|||
import org.dromara.sample.manage.model.param.DeviceQueryParam; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Optional; |
|||
|
|||
/** |
|||
* @author sean.zhou |
|||
* @date 2021/11/10 |
|||
* @version 0.1 |
|||
*/ |
|||
public interface IEngineRecordService { |
|||
|
|||
Map<String,Object> startEngine(Map<String,Object> objectMap); |
|||
|
|||
void closeEngine(Map<String,Object> objectMap); |
|||
} |
@ -0,0 +1,15 @@ |
|||
package org.dromara.sample.manage.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import org.dromara.sample.manage.model.entity.WarningRecordEntity; |
|||
|
|||
/** |
|||
* 设备对象-》用于存储设备Service接口 |
|||
* |
|||
* @author wuyuan |
|||
* @date 2022-10-25 |
|||
*/ |
|||
public interface IWarningRecordService extends IService<WarningRecordEntity>{ |
|||
|
|||
|
|||
} |
@ -0,0 +1,44 @@ |
|||
package org.dromara.sample.manage.service.impl; |
|||
|
|||
import cn.hutool.core.convert.Convert; |
|||
import cn.hutool.crypto.SecureUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import jakarta.annotation.Resource; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.collections.CollectionUtils; |
|||
import org.apache.dubbo.config.annotation.DubboReference; |
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.common.sdk.common.Pagination; |
|||
import org.dromara.common.sdk.common.PaginationData; |
|||
import org.dromara.common.sdk.mqtt.CommonTopicRequest; |
|||
import org.dromara.common.sdk.mqtt.MqttGatewayPublish; |
|||
import org.dromara.sample.feign.RemoteSystemFeign; |
|||
import org.dromara.sample.manage.mapper.IPlayTextMapper; |
|||
import org.dromara.sample.manage.model.dto.StreamTypeDTO; |
|||
import org.dromara.sample.manage.model.entity.PlayTextEntity; |
|||
import org.dromara.sample.manage.service.IDeviceStreamService; |
|||
import org.dromara.sample.manage.service.IPlayTextService; |
|||
import org.dromara.system.api.RemoteConfigService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Objects; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Service |
|||
@Slf4j |
|||
@Transactional |
|||
public class DeviceStreamServiceImpl implements IDeviceStreamService { |
|||
|
|||
} |
@ -0,0 +1,246 @@ |
|||
package org.dromara.sample.manage.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.JsonMappingException; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import io.seata.common.util.StringUtils; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.http.client.methods.CloseableHttpResponse; |
|||
import org.apache.http.client.methods.HttpGet; |
|||
import org.apache.http.client.methods.HttpPost; |
|||
import org.apache.http.client.utils.URIBuilder; |
|||
import org.apache.http.entity.StringEntity; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.util.EntityUtils; |
|||
import org.dromara.common.sdk.cloudapi.device.*; |
|||
import org.dromara.common.sdk.cloudapi.firmware.*; |
|||
import org.dromara.common.sdk.cloudapi.firmware.api.AbstractFirmwareService; |
|||
import org.dromara.common.sdk.cloudapi.property.api.AbstractPropertyService; |
|||
import org.dromara.common.sdk.cloudapi.tsa.DeviceIconUrl; |
|||
import org.dromara.common.sdk.cloudapi.tsa.TopologyDeviceModel; |
|||
import org.dromara.common.sdk.common.*; |
|||
import org.dromara.common.sdk.config.version.GatewayManager; |
|||
import org.dromara.common.sdk.exception.CloudSDKException; |
|||
import org.dromara.common.sdk.mqtt.IMqttTopicService; |
|||
import org.dromara.common.sdk.mqtt.MqttGatewayPublish; |
|||
import org.dromara.common.sdk.mqtt.events.EventsSubscribe; |
|||
import org.dromara.common.sdk.mqtt.osd.OsdSubscribe; |
|||
import org.dromara.common.sdk.mqtt.property.PropertySetReplyResultEnum; |
|||
import org.dromara.common.sdk.mqtt.property.PropertySetSubscribe; |
|||
import org.dromara.common.sdk.mqtt.requests.RequestsSubscribe; |
|||
import org.dromara.common.sdk.mqtt.services.ServicesReplyData; |
|||
import org.dromara.common.sdk.mqtt.services.ServicesSubscribe; |
|||
import org.dromara.common.sdk.mqtt.services.TopicServicesResponse; |
|||
import org.dromara.common.sdk.mqtt.state.StateSubscribe; |
|||
import org.dromara.common.sdk.mqtt.status.StatusSubscribe; |
|||
import org.dromara.common.websocket.dto.BizCodeEnum; |
|||
import org.dromara.sample.common.error.CommonErrorEnum; |
|||
import org.dromara.sample.common.util.Md5Utils; |
|||
import org.dromara.sample.component.mqtt.model.EventsReceiver; |
|||
import org.dromara.sample.control.model.enums.DroneAuthorityEnum; |
|||
import org.dromara.sample.manage.mapper.IDeviceMapper; |
|||
import org.dromara.sample.manage.mapper.IDeviceProMapper; |
|||
import org.dromara.sample.manage.mapper.IEngineRecordMapper; |
|||
import org.dromara.sample.manage.model.dto.*; |
|||
import org.dromara.sample.manage.model.entity.DeviceEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceProEntity; |
|||
import org.dromara.sample.manage.model.entity.EngineRecordEntity; |
|||
import org.dromara.sample.manage.model.enums.DeviceFirmwareStatusEnum; |
|||
import org.dromara.sample.manage.model.enums.PropertySetFieldEnum; |
|||
import org.dromara.sample.manage.model.enums.UserTypeEnum; |
|||
import org.dromara.sample.manage.model.param.DeviceQueryParam; |
|||
import org.dromara.sample.manage.model.receiver.BasicDeviceProperty; |
|||
import org.dromara.sample.manage.service.*; |
|||
import org.dromara.sample.websocket.service.IWebSocketMessageService; |
|||
import org.json.JSONObject; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.net.URI; |
|||
import java.net.URISyntaxException; |
|||
import java.time.LocalDateTime; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import static org.apache.commons.compress.utils.ArchiveUtils.sanitize; |
|||
|
|||
/** |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Service |
|||
@Slf4j |
|||
@Transactional |
|||
public class EngineRecordServiceImpl implements IEngineRecordService { |
|||
@Resource |
|||
IEngineRecordMapper mapper; |
|||
|
|||
|
|||
@Override |
|||
public Map<String, Object> startEngine(Map<String, Object> objectMap){ |
|||
EngineRecordEntity record = new EngineRecordEntity(); |
|||
//获取token
|
|||
//设置请求Header和Body(如JSON)
|
|||
String md5 = Md5Utils.hash("xuzhou_ai"); |
|||
JSONObject jsonObj = new JSONObject(); |
|||
jsonObj.put("username", sanitize("xuzhou_ai")); // sanitize函数见下文
|
|||
jsonObj.put("password", sanitize(md5)); |
|||
String responseBody = PostRequest(jsonObj, "http://60.204.247.65:8100/Third/Login"); |
|||
JSONObject jsonObject = new JSONObject(responseBody); |
|||
// 逐层获取 data -> token
|
|||
JSONObject data = jsonObject.getJSONObject("data"); |
|||
String token = data.getString("token"); |
|||
String sceneResponseBody = null; |
|||
String algorithmResponseBody = null; |
|||
//查询用户开通的场景
|
|||
if (StringUtils.isNotEmpty(token)){ |
|||
try { |
|||
URI uri = new URIBuilder("http://60.204.247.65:8100/V2/AI/WX/User/Scene") |
|||
.build(); |
|||
sceneResponseBody = GetRequest(uri, token); |
|||
} catch (URISyntaxException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
JSONObject jsonObject1 = new JSONObject(sceneResponseBody); |
|||
// 逐层获取 data -> token
|
|||
JSONObject data1 = jsonObject.getJSONObject("data"); |
|||
String scene = data1.getString("scene"); |
|||
|
|||
//查询场景算法
|
|||
List<String> extra_type_list = new ArrayList<>(); |
|||
try { |
|||
URI uri = new URIBuilder("http://60.204.247.65:8100/V2/AI/WX/User/ExtraType/Get") |
|||
.addParameter("scene",scene) |
|||
.addParameter("if_open","1") |
|||
.build(); |
|||
algorithmResponseBody = GetRequest(uri, token); |
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
ExtraTypeResponse response = mapper.readValue(algorithmResponseBody,ExtraTypeResponse.class); |
|||
List<ExtraType> list = response.getData(); |
|||
for (ExtraType extraType : list) { |
|||
extra_type_list.add(extraType.getExtra_type()); |
|||
break; |
|||
} |
|||
} catch (URISyntaxException | JsonProcessingException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
|
|||
JSONObject jsonObj2 = new JSONObject(); |
|||
jsonObj2.put("scene", scene); // sanitize函数见下文
|
|||
jsonObj2.put("callback_url", objectMap.get("callback_url")); |
|||
jsonObj2.put("input_url", objectMap.get("input_url")); |
|||
jsonObj2.put("push_url", objectMap.get("push_url")); |
|||
jsonObj2.put("play_url", objectMap.get("play_url")); |
|||
String responseBody2 = PostRequest(jsonObj2, "http://60.204.247.65:8100/Third/Engine/Start"); |
|||
ObjectMapper mapper1 = new ObjectMapper(); |
|||
EngineResponse response = null; |
|||
try { |
|||
response = mapper1.readValue(responseBody2, EngineResponse.class); |
|||
} catch (JsonProcessingException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
objectMap.put("task_id",response.getData().getTask_id()); |
|||
record.setPushUrl(objectMap.get("push_url").toString()); |
|||
record.setDeviceSn(objectMap.get("device_sn").toString()); |
|||
record.setTaskId(response.getData().getTask_id()); |
|||
record.setExtraType(String.join(",", extra_type_list)); |
|||
} |
|||
Map<String, Object> map = new HashMap(); |
|||
map.put("callback_url", objectMap.get("callback_url")); |
|||
map.put("input_url", objectMap.get("input_url")); |
|||
map.put("push_url", objectMap.get("push_url")); |
|||
map.put("play_url", objectMap.get("play_url")); |
|||
map.put("task_id", objectMap.get("task_id")); |
|||
//添加启动引擎记录
|
|||
mapper.insert(record); |
|||
return map; |
|||
} |
|||
|
|||
@Override |
|||
public void closeEngine(Map<String, Object> objectMap) { |
|||
JSONObject jsonObj2 = new JSONObject(); |
|||
EngineRecordEntity record = mapper.selectOne(new LambdaQueryWrapper<EngineRecordEntity>().eq(EngineRecordEntity::getDeviceSn, objectMap.get("device_sn"))); |
|||
if (record == null){ |
|||
throw new RuntimeException("关闭引擎失败!"); |
|||
} |
|||
jsonObj2.put("task_id", record.getTaskId()); // sanitize函数见下文
|
|||
String responseBody2 = PostRequest(jsonObj2, "http://60.204.247.65:8100/Third/Engine/Stop"); |
|||
JSONObject json = new JSONObject(responseBody2); |
|||
// 方式2:安全获取(先判空再转换)
|
|||
Object dataObj = json.get("data"); |
|||
if(dataObj != null && dataObj instanceof Integer) { |
|||
int data = (Integer) dataObj; |
|||
if (data ==1){ |
|||
mapper.delete(new LambdaQueryWrapper<EngineRecordEntity>().eq(EngineRecordEntity::getDeviceSn, objectMap.get("device_sn"))); |
|||
}else { |
|||
throw new RuntimeException("关闭引擎失败!"); |
|||
} |
|||
} else { |
|||
throw new RuntimeException("关闭引擎失败!"); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
public String PostRequest( JSONObject jsonObj, String url |
|||
) { |
|||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|||
// 1. 创建POST请求对象
|
|||
HttpPost post = new HttpPost(url); |
|||
StringEntity requestEntity = new StringEntity(jsonObj.toString(), "UTF-8"); |
|||
requestEntity.setContentType("application/json"); |
|||
post.setEntity(requestEntity); |
|||
post.setHeader("Accept", "application/json"); |
|||
// 3. 执行请求并获取响应
|
|||
try (CloseableHttpResponse response = httpClient.execute(post)) { |
|||
String responseBody = EntityUtils.toString(response.getEntity()); |
|||
if (response.getStatusLine().getStatusCode() == 200) { |
|||
return responseBody; |
|||
} else { |
|||
throw new RuntimeException("第三方接口调用失败!"); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
|
|||
} |
|||
|
|||
public String GetRequest(URI uri, String token |
|||
) { |
|||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|||
// URI uri = new URIBuilder("https://api.example.com/data")
|
|||
// .addParameter("param1", "value1")
|
|||
// .addParameter("param2", "value2")
|
|||
// .build();
|
|||
HttpGet httpGet = new HttpGet(uri); |
|||
httpGet.setHeader("token",token); |
|||
try (CloseableHttpResponse response = httpClient.execute(httpGet)) { |
|||
// 处理响应
|
|||
String responseBody = EntityUtils.toString(response.getEntity()); |
|||
if (response.getStatusLine().getStatusCode() == 200){ |
|||
return responseBody; |
|||
}else { |
|||
throw new RuntimeException("第三方接口调用失败!"); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,20 @@ |
|||
package org.dromara.sample.manage.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.dromara.sample.manage.mapper.WarningRecordMapper; |
|||
import org.dromara.sample.manage.model.entity.WarningRecordEntity; |
|||
import org.dromara.sample.manage.service.IWarningRecordService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* 设备对象-》用于存储设备Service业务层处理 |
|||
* |
|||
* @author wuyuan |
|||
* @date 2022-10-25 |
|||
*/ |
|||
@Service |
|||
@Slf4j |
|||
public class WarningRecordServiceImpl extends ServiceImpl<WarningRecordMapper, WarningRecordEntity> implements IWarningRecordService { |
|||
|
|||
} |
@ -0,0 +1,79 @@ |
|||
package org.dromara.sample.rocketmq; |
|||
|
|||
import org.apache.rocketmq.common.message.MessageExt; |
|||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
|||
import org.apache.rocketmq.spring.core.RocketMQListener; |
|||
import org.dromara.common.sdk.cloudapi.device.VideoId; |
|||
import org.dromara.common.sdk.cloudapi.livestream.LensChangeVideoTypeEnum; |
|||
import org.dromara.common.sdk.cloudapi.livestream.UrlTypeEnum; |
|||
import org.dromara.common.sdk.cloudapi.livestream.VideoQualityEnum; |
|||
import org.dromara.common.sdk.cloudapi.wayline.FlighttaskProgress; |
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.sample.component.mqtt.model.EventsReceiver; |
|||
import org.dromara.sample.manage.model.dto.DeviceDTO; |
|||
import org.dromara.sample.manage.model.dto.LiveDTO; |
|||
import org.dromara.sample.manage.model.dto.LiveTypeDTO; |
|||
import org.dromara.sample.manage.model.entity.DeviceEntity; |
|||
import org.dromara.sample.manage.service.IDeviceRedisService; |
|||
import org.dromara.sample.manage.service.IDeviceService; |
|||
import org.dromara.sample.manage.service.ILiveStreamService; |
|||
import org.dromara.sample.manage.service.IPlayTextService; |
|||
import org.dromara.sample.wayline.model.dto.WaylineJobDTO; |
|||
import org.dromara.sample.wayline.service.IWaylineJobService; |
|||
import org.dromara.sample.wayline.service.IWaylineRedisService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.util.ObjectUtils; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import java.util.Optional; |
|||
|
|||
/** |
|||
* @auther wuyuan |
|||
* @data 2025/5/12 |
|||
*/ |
|||
@RocketMQMessageListener(consumerGroup = "videoStart",topic = "videoStartConsum") |
|||
@Component |
|||
public class RocketMqConsum implements RocketMQListener<MessageExt> { |
|||
|
|||
@Autowired |
|||
private ILiveStreamService liveStreamService; |
|||
|
|||
@Autowired |
|||
private IPlayTextService playTextService; |
|||
|
|||
@Autowired |
|||
private IWaylineRedisService waylineRedisService; |
|||
|
|||
@Autowired |
|||
private IDeviceService deviceService; |
|||
|
|||
@Autowired |
|||
private IWaylineJobService waylineJobService; |
|||
|
|||
@Autowired |
|||
private IDeviceRedisService deviceRedisService; |
|||
|
|||
@Override |
|||
public void onMessage(MessageExt message) { |
|||
String videoIds = new String(message.getBody()); |
|||
VideoId videoId = new VideoId(videoIds); |
|||
LiveTypeDTO liveTypeDTO = new LiveTypeDTO(); |
|||
liveTypeDTO.setUrlType(UrlTypeEnum.WHIP); |
|||
liveTypeDTO.setVideoType(LensChangeVideoTypeEnum.WIDE); |
|||
liveTypeDTO.setVideoQuality(VideoQualityEnum.ULTRA_HD); |
|||
liveTypeDTO.setVideoId(videoId); |
|||
DeviceEntity deviceBySn = deviceService.getDeviceByChildSn(videoId.getDroneSn()); |
|||
Optional<EventsReceiver<FlighttaskProgress>> runningWaylineJob = waylineRedisService.getRunningWaylineJob(deviceBySn.getDeviceSn()); |
|||
Map<String,Object> reqMap = new HashMap<>(); |
|||
if(runningWaylineJob.isPresent()) { |
|||
String jobId = runningWaylineJob.get().getOutput().getExt().getFlightId(); |
|||
Optional<WaylineJobDTO> waylineJobDTO = waylineJobService.getJobByJobInternalId(jobId); |
|||
reqMap.put("jobId",waylineJobDTO.get().getJobId()); |
|||
reqMap.put("jobName",waylineJobDTO.get().getJobName()); |
|||
reqMap.put("deviceSn",videoId.getDroneSn()); |
|||
playTextService.streamType(reqMap); |
|||
} |
|||
} |
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue