Commit 0ca26c69 authored by 赵啸非's avatar 赵啸非

添加离线 上线日志

parent 777344ec
......@@ -148,8 +148,6 @@
<profiles.redis.password>hotel@2020</profiles.redis.password>
<profiles.redis.database>6</profiles.redis.database>
<profiles.redis.database>6</profiles.redis.database>
<profiles.rabbitmq.host>172.15.28.115</profiles.rabbitmq.host>
<profiles.rabbitmq.port>5672</profiles.rabbitmq.port>
<profiles.rabbitmq.username>taxi_mq</profiles.rabbitmq.username>
......
......@@ -2,7 +2,7 @@ package com.mortals.xhx.busiz.req;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
......@@ -14,5 +14,10 @@ public class UploadDeviceReq extends DeviceReq {
private String action;
private List<String> deviceCodeList;
private String content;
}
package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.net.URLDecoder;
......@@ -990,7 +991,7 @@ public class DeviceApiController {
}
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
String domain = "http://10.12.185.213:11078";
UrlBuilder urlBuilder = UrlBuilder.ofHttp(domain).addPath("test");
......@@ -1025,6 +1026,18 @@ public class DeviceApiController {
System.out.println(decrypt);*/
//String content = EncryptUtil.myEnscrt("", 9, DES_STR, ENCRYPT_STR);
//System.out.println(content);
/* String decrypt = EncryptUtil.decrypt("W10=", ENCRYPT_STR);
System.out.println(decrypt);*/
System.out.println(new String(Base64.decode("W10=")));
}
......
package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
......@@ -25,6 +26,7 @@ import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -66,9 +68,9 @@ public class DeviceSendMsgController {
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, MESSAGETYPE_NOTIFY_REFRESH);
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode());
header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime());
header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime());
TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "W10=", header);
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(),JSON.toJSONString(queueMsg));
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), JSON.toJSONString(queueMsg));
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
deviceLogEntity.initAttrValue();
......@@ -82,13 +84,12 @@ public class DeviceSendMsgController {
deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue());
deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity,null);
deviceLogService.save(deviceLogEntity, null);
}
TimeUnit.SECONDS.sleep(1);
}
}
catch (InterruptedException e) {
log.error("异常",e);
} catch (InterruptedException e) {
log.error("异常", e);
}
};
Thread thread = new Thread(runnable);
......@@ -105,5 +106,66 @@ public class DeviceSendMsgController {
}
/**
* 下发消息
*
* @param req
* @return
*/
@PostMapping("downMsg")
@UnAuth
public String downMsg(@RequestBody UploadDeviceReq req) {
log.info("【设备通知数据】【请求体】--> " + JSONObject.toJSONString(req));
ApiResp<String> rsp = new ApiResp<>();
rsp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
try {
if (ObjectUtils.isEmpty(req.getDeviceCodeList())) {
DeviceQuery deviceQuery = new DeviceQuery();
deviceQuery.setDeviceCodeList(req.getDeviceCodeList());
//查询站点设备并通知每个设备
List<DeviceEntity> deviceList = deviceService.find(deviceQuery);
String content = "W10=";
if (ObjectUtils.isEmpty(req.getContent())) {
content = Base64.encode(req.getContent());
}
try {
for (DeviceEntity deviceEntity : deviceList) {
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, req.getAction());
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode());
header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime());
TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), content, header);
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), JSON.toJSONString(queueMsg));
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
deviceLogEntity.initAttrValue();
deviceLogEntity.setTraceID(IdUtil.fastSimpleUUID());
deviceLogEntity.setSiteId(deviceEntity.getSiteId());
deviceLogEntity.setDeviceId(deviceEntity.getId());
deviceLogEntity.setDeviceName(deviceEntity.getDeviceName());
deviceLogEntity.setDeviceCode(deviceEntity.getDeviceCode());
deviceLogEntity.setMessageHead(req.getAction());
deviceLogEntity.setContent(content);
deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue());
deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity, null);
}
} catch (Exception e) {
log.error("异常", e);
}
}
} catch (Exception e) {
log.error("接收数据失败", e);
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
}
log.debug("响应【设备通知刷新数据】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp);
}
}
......@@ -152,6 +152,8 @@ public class TestSendMsgController {
*/
}
......
......@@ -726,6 +726,44 @@ data|object|数据对象|-
```
### 接收第三方平台下发设备消息
**请求URL:** m/notify/downMsg
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:**
**请求参数:**
参数名称| 类型 |备注|必填|其它
:------|:--------|:--|:---|:---
deviceCodeList| Arrays |设备编码列表|是|-
action| String |设备下发消息行为,消息类型编号|是|-
content| String |下发消息内容|是|默认为[]数组内容
**请求样例:**
```
{}
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码|见附录码表
msg|String|消息|-
data|object|数据对象|-
**响应消息样例:**
```
```
### 接收第三方平台命令消息
**请求URL:** m/api/callback
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment