|
@@ -1,20 +1,36 @@
|
|
|
package com.usky.http.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.nacos.common.utils.JacksonUtils;
|
|
|
+import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.ctg.ag.sdk.biz.AepDeviceCommandLwmProfileClient;
|
|
|
import com.ctg.ag.sdk.biz.aep_device_command_lwm_profile.CreateCommandLwm2mProfileRequest;
|
|
|
import com.ctg.ag.sdk.biz.aep_device_command_lwm_profile.CreateCommandLwm2mProfileResponse;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.common.core.util.JsonUtils;
|
|
|
+import com.usky.http.domain.DmpDevice;
|
|
|
import com.usky.http.domain.TcAepCommand;
|
|
|
import com.usky.http.mapper.TcAepCommandMapper;
|
|
|
+import com.usky.http.service.DmpDeviceService;
|
|
|
import com.usky.http.service.TcAepCommandService;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.http.service.config.mqtt.MqttOutConfig;
|
|
|
import com.usky.http.service.vo.TCAepDeviceCommendRequestVO;
|
|
|
+import com.usky.http.service.vo.TcAepJTPDeviceInfoAlarmRequestVO;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -27,6 +43,11 @@ import java.util.Map;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class TcAepCommandServiceImpl extends AbstractCrudService<TcAepCommandMapper, TcAepCommand> implements TcAepCommandService {
|
|
|
+ @Autowired
|
|
|
+ private DmpDeviceService dmpDeviceService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private MqttOutConfig.MqttGateway mqttGateway;
|
|
|
|
|
|
@Override
|
|
|
public void tcAepDeviceCommand(TCAepDeviceCommendRequestVO requestVO) throws Exception {
|
|
@@ -61,5 +82,60 @@ public class TcAepCommandServiceImpl extends AbstractCrudService<TcAepCommandMap
|
|
|
log.info(logInfo);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void tcAepJTYDeviceInfo(String requestBody){
|
|
|
+
|
|
|
+ Map map = JsonUtils.fromJson(requestBody,Map.class);
|
|
|
+ String deviceId = map.get("IMEI").toString();
|
|
|
+ LambdaQueryWrapper<DmpDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(DmpDevice::getDeviceId,deviceId);
|
|
|
+ DmpDevice one = dmpDeviceService.getOne(queryWrapper);
|
|
|
+ String companyCode = one.getCompanyCode();
|
|
|
+ String deviceName = one.getDeviceName();
|
|
|
+ String deviceType = one.getDeviceType().toString();
|
|
|
+ String infoTopic = String.format("/usky/ytDP0003/",companyCode,"/",deviceId,"/info");
|
|
|
+ String alarmTopic = String.format("/usky/ytDP0003/",companyCode,"/",deviceId,"/alarm");
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now();
|
|
|
+ String timestamp = String.valueOf(localDateTime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli());
|
|
|
+
|
|
|
+ String messageType = map.get("messageType").toString();
|
|
|
+
|
|
|
+ if(messageType.equals("dataReport")){
|
|
|
+ Map<String,Object> dataMap = JSONObject.parseObject(JSONObject.toJSONString(map.get("payload")));
|
|
|
+ if(Objects.nonNull(dataMap.get("smoke_state"))){ //alarm
|
|
|
+ String smokeState = dataMap.get("smoke_state").toString();
|
|
|
+ if(smokeState.equals("0")){
|
|
|
+ String deviceStatus = "0";
|
|
|
+ String battery = dataMap.get("battery_value").toString();
|
|
|
+ String signal = "";
|
|
|
+ String temperature = dataMap.get("").toString();
|
|
|
+ String smoke = dataMap.get("smoke_value").toString();
|
|
|
+ String deviceAlarmData = String.format("{\"devId\":\"",deviceId,"\",\"connType\":\"N\"",",\"deviceName\":\"",deviceName,"\",\"alarams\":[{\"dp\":[{\"property\":\"烟雾报警\",\"serial\":\"311\",\"value\":\"报警\",\"status\":\"0\" }],\"deviceName\":\"",
|
|
|
+ deviceName,"\",\"timeStamp\":\"",timestamp,"\",\"deviceModel\":\"\",\"deviceType\":\"",deviceType,"\",\"devId\":\"",deviceId,"\"}],\"type\":\"ALARM\",\"timeStamp\":\"",timestamp,"\"}");
|
|
|
+
|
|
|
+ mqttGateway.sendToMqtt(infoTopic,deviceAlarmData);
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{ //info
|
|
|
+ String deviceStatus = "0";
|
|
|
+ String battery = dataMap.get("battery_value").toString();
|
|
|
+ String signal = "";
|
|
|
+ String temperature = dataMap.get("").toString();
|
|
|
+ String smoke = "";
|
|
|
+ String deviceInfoData = String.format("{\"devId\":\"",deviceId,"\",\"connType\":\"N\"",",\"deviceName\":\"",deviceName,"\",\"devs\":[{\"dp\":[{\"property\":\"状态\",\"serial\":\"301\",\"value\":\""
|
|
|
+ ,deviceStatus,"\"},{\"property\":\"剩余电量\",\"serial\":\"302\",\"value\":\"",battery,"\"},{\"property\":\"无线信号\",\"serial\":\"303\",\"value\":\"",signal,
|
|
|
+ "\"},{\"property\":\"温度\",\"serial\":\"304\",\"value\":\"",temperature,"\"},{\"property\":\"浓度\",\"serial\":\"305\",\"value\":\"",smoke,"\"}],\"deviceName\":\"",deviceName,"\",\"timeStamp\":\"",timestamp,"\",\"deviceModel\":\"\",\"deviceType\":\"",deviceType,"\",\"devId\":\"",deviceId,"\"}],\"type\":\"INFO\",\"timeStamp\":\"",timestamp,"\"}");
|
|
|
+
|
|
|
+ mqttGateway.sendToMqtt(infoTopic,deviceInfoData);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }else if(messageType.equals("eventReport")){ //alarm
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|