第一次提交
This commit is contained in:
@ -0,0 +1,82 @@
|
||||
package com.fastbee.jsonPak;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.annotation.SysProtocol;
|
||||
import com.fastbee.common.constant.FastBeeConstant;
|
||||
import com.fastbee.common.core.mq.DeviceReport;
|
||||
import com.fastbee.common.core.mq.MQSendMessageBo;
|
||||
import com.fastbee.common.core.mq.message.DeviceData;
|
||||
import com.fastbee.common.core.mq.message.FunctionCallBackBo;
|
||||
import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
|
||||
import com.fastbee.common.core.thingsModel.ThingsModelValuesInput;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.protocol.base.protocol.IProtocol;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author gsb
|
||||
* @date 2022/10/10 16:55
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@SysProtocol(name = "JSONObject解析协议",protocolCode = FastBeeConstant.PROTOCOL.JsonObject,description = "系统内置JSONObject解析协议")
|
||||
public class JsonPakProtocolService implements IProtocol {
|
||||
|
||||
/**
|
||||
* 上报数据格式 <p>
|
||||
* {
|
||||
* "params": {
|
||||
* "DI" : 0,
|
||||
* "DO" : 1
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
@Override
|
||||
public DeviceReport decode(DeviceData deviceData, String clientId) {
|
||||
try {
|
||||
DeviceReport reportMessage = new DeviceReport();
|
||||
// bytep[] 转String
|
||||
String data = new String(deviceData.getData(),StandardCharsets.UTF_8);
|
||||
JSONObject params = JSONObject.parseObject(data);
|
||||
List<ThingsModelSimpleItem> result = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
ThingsModelSimpleItem item = new ThingsModelSimpleItem();
|
||||
item.setTs(DateUtils.getNowDate());
|
||||
item.setValue(entry.getValue()+"");
|
||||
item.setId(entry.getKey());
|
||||
result.add(item);
|
||||
}
|
||||
reportMessage.setThingsModelSimpleItem(result);
|
||||
reportMessage.setIsPackage(true);
|
||||
reportMessage.setMessageId("0");
|
||||
reportMessage.setClientId(clientId);
|
||||
reportMessage.setSerialNumber(clientId);
|
||||
return reportMessage;
|
||||
}catch (Exception e){
|
||||
throw new ServiceException("数据解析异常"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionCallBackBo encode(MQSendMessageBo message) {
|
||||
try {
|
||||
FunctionCallBackBo callBack = new FunctionCallBackBo();
|
||||
String msg = message.getParams().toString();
|
||||
callBack.setMessage(msg.getBytes());
|
||||
callBack.setSources(msg);
|
||||
return callBack;
|
||||
}catch (Exception e){
|
||||
log.error("=>指令编码异常,device={},data={}",message.getSerialNumber(),
|
||||
message.getParams());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.fastbee.jsonPak.pak;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.fastbee.base.core.annotation.Node;
|
||||
import com.fastbee.base.core.annotation.PakMapping;
|
||||
import com.fastbee.base.session.Session;
|
||||
import com.fastbee.common.core.mq.DeviceReport;
|
||||
import com.fastbee.common.core.protocol.Message;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author gsb
|
||||
* @date 2023/5/4 15:09
|
||||
*/
|
||||
@Node
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JsonEndPoint {
|
||||
|
||||
|
||||
@PakMapping(types = 0)
|
||||
public void register(DeviceReport message, Session session){
|
||||
// 注册设备
|
||||
session.register(message);
|
||||
//String callback = "{\"pak_ty\":\"set_inf\",\"cj_s\":null,\"up_s\":3600,\"xt_s\":3600,\"x_yz\":500,\"y_yz\":500,\"z_yz\":500,\"nian\":2022,\"yue\":3,\"ri\":25,\"shi\":12,\"fen\":23,\"miao\":33}";
|
||||
//message.setBody(callback);
|
||||
//return message;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user