第一次提交

This commit is contained in:
wyw
2024-08-08 00:31:26 +08:00
commit c202e2b63d
1819 changed files with 221890 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package com.fastbee.sgz;
import cn.hutool.json.JSONObject;
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.thingsModel.ThingsModelSimpleItem;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author gsb
* @date 2024/3/29 16:06
*/
@Node
@Component
public class SgzEndPoint {
@PakMapping(types = 150)
public DeviceReport heart(DeviceReport report, Session session){
JSONObject params = new JSONObject();
params.putIfAbsent("device",report.getClientId());
List<ThingsModelSimpleItem> items = report.getThingsModelSimpleItem();
for (ThingsModelSimpleItem item : items) {
if (item.getId().equals("dtype")){
params.putIfAbsent("dtype",item.getValue());
}
}
params.putIfAbsent("fuc",SgzMessageType.LINKING.type);
params.putIfAbsent("sdata",SgzMessageType.LINKING.type);
report.setBody(params);
return report;
}
@PakMapping(types = 154)
public DeviceReport dataCallBack(DeviceReport report){
JSONObject params = new JSONObject();
params.putIfAbsent("device",report.getClientId());
List<ThingsModelSimpleItem> items = report.getThingsModelSimpleItem();
for (ThingsModelSimpleItem item : items) {
if (item.getId().equals("dtype")){
params.putIfAbsent("dtype",item.getValue());
}
}
params.putIfAbsent("fuc",SgzMessageType.CZROK.type);
params.putIfAbsent("sdata",SgzMessageType.CZROK.type);
report.setBody(params);
return report;
}
}

View File

@ -0,0 +1,34 @@
package com.fastbee.sgz;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author gsb
* @date 2024/3/29 11:31
*/
@Getter
@AllArgsConstructor
public enum SgzMessageType {
HEART(150,"heart","心跳"),
LINKING(151," LINKING"," LINKING已连接"),
CZOK(152," CZOK","开始充装"),
UNLOCK(153,"UNLOCK","已解锁"),
CZSTOP(154,"CZSTOP","数据上报"),
CZROK(155,"CZROK","充装结束回复设备");
int messageId;
String type;
String desc;
public static SgzMessageType convert(String type){
for (SgzMessageType value : SgzMessageType.values()) {
if (value.type.equals(type)){
return value;
}
}
return HEART;
}
}

View File

@ -0,0 +1,116 @@
package com.fastbee.sgz;
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.DeviceDownMessage;
import com.fastbee.common.core.mq.message.FunctionCallBackBo;
import com.fastbee.common.core.redis.RedisCache;
import com.fastbee.common.core.redis.RedisKeyBuilder;
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.iot.model.ThingsModels.ValueItem;
import com.fastbee.protocol.base.protocol.IProtocol;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @author gsb
* @date 2024/3/29 11:27
*/
@Slf4j
@Component
@SysProtocol(name = "数码灌装解析协议", protocolCode = FastBeeConstant.PROTOCOL.SGZ, description = "数码灌装解析协议")
public class SgzProtocolService implements IProtocol {
@Resource
private RedisCache redisCache;
/**
* 上报数据格式 <p>
* {
* "params": {
* "DI" : 0,
* "DO" : 1
* }
* }
*/
@Override
public DeviceReport decode(DeviceData deviceData, String clientId) {
SgzMessageType dtype = SgzMessageType.HEART;
DeviceReport reportMessage = new DeviceReport();
String data = new String(deviceData.getData(), StandardCharsets.UTF_8);
JSONObject params = (JSONObject) JSON.parse(data);
List<ThingsModelSimpleItem> result = new ArrayList<>();
for (Map.Entry<String, Object> entry : params.entrySet()) {
ThingsModelSimpleItem item = new ThingsModelSimpleItem();
String val = entry.getValue() + "";
item.setTs(DateUtils.getNowDate());
item.setValue(val);
item.setId(entry.getKey());
result.add(item);
if (entry.getKey().equals("fuc")) {
dtype = SgzMessageType.convert(val);
}
if (dtype.equals(SgzMessageType.CZSTOP)) {
String[] strings = {"stime", "sno", "scode", "smiao", "sjz", "spz", "etime", "stotal"};
String[] split = val.split(",");
for (int i = 0; i < split.length; i++) {
ThingsModelSimpleItem simpleItem = new ThingsModelSimpleItem();
simpleItem.setTs(DateUtils.getNowDate());
simpleItem.setValue(split[i]);
simpleItem.setId(strings[i]);
result.add(simpleItem);
}
}
}
reportMessage.setThingsModelSimpleItem(result);
reportMessage.setIsPackage(true);
reportMessage.setMessageId(dtype.messageId + "");
reportMessage.setClientId(clientId);
reportMessage.setSerialNumber(clientId);
return reportMessage;
}
@Override
public FunctionCallBackBo encode(MQSendMessageBo message) {
try {
FunctionCallBackBo callBack = new FunctionCallBackBo();
String cacheKey = RedisKeyBuilder.buildTSLVCacheKey(message.getDp().getProductId(), message.getSerialNumber());
String data = redisCache.getCacheMapValue(cacheKey, "dtype");
ValueItem valueItem = JSON.parseObject(data, ValueItem.class);
JSONObject params = message.getParams();
Object scode = params.get("scode");
params.put("device", message.getSerialNumber());
params.put("fuc", SgzMessageType.CZOK);
params.put("dtype", valueItem.getValue());
params.put("sdata", scode);
String out = JSON.toJSONString(params);
callBack.setMessage(out.getBytes());
callBack.setSources(out);
return callBack;
// }
} catch (Exception e) {
throw new ServiceException("指令编号异常" + e.getMessage());
}
}
@Override
public byte[] encodeCallBack(Object message) {
return new byte[0];
}
}