26 changed files with 1118 additions and 5 deletions
@ -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; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -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,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,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,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,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 { |
||||
|
|
||||
|
} |
Loading…
Reference in new issue