| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.utils.RedisUtil; |
| | | import com.ruoyi.device.constant.DCResistanceMqttConstants; |
| | | import com.ruoyi.device.dto.DeviceCollectionDto; |
| | |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log; |
| | | |
| | | public class DataAcquisition { |
| | | |
| | |
| | | List<Object> list = new ArrayList<>(); |
| | | for (int config = 0; config < v.size(); config++) { |
| | | String refery = getRefer(v.get(config).getRefery()); |
| | | // 从 Redis 中获取值 |
| | | Object value = RedisUtil.get(refery); |
| | | if (ObjectUtils.isNotEmpty(value)) { |
| | | if (value instanceof String && ((String) value).startsWith("[") && ((String) value).endsWith("]")) { |
| | | try { |
| | | // 解析 JSON 数组字符串为 List<BigDecimal> |
| | | List<BigDecimal> values = JSONArray.parseArray((String) value, BigDecimal.class); |
| | | list.addAll(values); |
| | | numberOfDataEntries.addAndGet(values.size()); |
| | | } catch (Exception e) { |
| | | // 解析失败,记录错误日志,使用原字符串值 |
| | | System.err.println("解析 Redis 返回的 JSON 数组失败: " + value); |
| | | list.add(value); |
| | | if (refery.equals(DCResistanceMqttConstants.NSDQCS_DQCS_DZZ)){ |
| | | // 从 Redis 中获取一个数据 |
| | | Object value = RedisUtil.get(refery); |
| | | list.add(value); |
| | | numberOfDataEntries.addAndGet(1); |
| | | }else { |
| | | // 从 Redis 中获取列表数据 |
| | | List<Object> objectList = RedisUtil.lGet(refery, 0, -1); |
| | | for (Object item : objectList) { |
| | | // System.out.println(item); |
| | | String[] split = item.toString().replace("[","").replace("]","").split(","); |
| | | for (Object a : |
| | | split) { |
| | | list.add(a); |
| | | numberOfDataEntries.addAndGet(1); |
| | | } |
| | | } else { |
| | | numberOfDataEntries.addAndGet(1); |
| | | list.add(value); |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | if (listResult.size() >= 1) { |
| | | hashMap.put("result", listResult); |
| | | } else { |
| | | hashMap.put("result", listResult.get(0).toString()); |
| | | hashMap.put("result", listResult); |
| | | } |
| | | hashMap.put("equipName", device.getDeviceName()); |
| | | hashMap.put("equipValue", device.getManagementNumber()); |