数据补召优化
This commit is contained in:
@@ -5,8 +5,7 @@ import com.njcn.redis.utils.RedisUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -52,4 +51,22 @@ public class ChannelObjectUtil {
|
||||
public Object getDeviceMid(String nDid) {
|
||||
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, List<String>> objectToMap(Object obj) {
|
||||
// 创建并填充 Map
|
||||
Map<String, List<String>> resultMap = new HashMap<>();
|
||||
String json = obj.toString();
|
||||
// 移除首尾的 {}
|
||||
json = json.substring(1, json.length() - 1);
|
||||
// 找到键和值的分隔符位置
|
||||
int keyEndIndex = json.indexOf("=[");
|
||||
String key = json.substring(0, keyEndIndex);
|
||||
String valuesStr = json.substring(keyEndIndex + 2, json.length() - 1);
|
||||
// 将值字符串分割成列表
|
||||
String[] valuesArray = valuesStr.split(", ");
|
||||
List<String> valuesList = Arrays.asList(valuesArray);
|
||||
resultMap.put(key, valuesList);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.api.CsTopicFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FileCommonUtils {
|
||||
|
||||
@Resource
|
||||
private CsTopicFeignClient csTopicFeignClient;
|
||||
@Resource
|
||||
private MqttPublisher publisher;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 询问文件信息
|
||||
*/
|
||||
public void askFileInfo(String nDid, Integer mid, String fileName) {
|
||||
String version = csTopicFeignClient.find(nDid).getData();
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_8.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
String json = "{Name:\""+fileName+"\"}";
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
log.info("请求文件信息报文:" + new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空下载缓存
|
||||
*/
|
||||
public void cleanRedisData(String nDid, String fileName) {
|
||||
redisUtil.deleteKeysByString("downloadFilePath:"+ nDid);
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck" + nDid + fileName);
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_DOWN_TIME.concat(fileName));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user