| | |
| | | if (!ok) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), apiMsg(resp, "查询失败")); |
| | | } |
| | | if (ACTION_QUERY_DL == actionType && resp.getData() != null) { |
| | | try { |
| | | BigDecimal dl = new BigDecimal(String.valueOf(resp.getData())); |
| | | meter.setTotalDl(dl); |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | if (ACTION_QUERY_POWER == actionType && resp.getData() != null) { |
| | | try { |
| | | BigDecimal kw = new BigDecimal(String.valueOf(resp.getData())); |
| | | meter.setPowerKw(kw); |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | meter.setLastSyncDate(new Date()); |
| | | meterMapper.updateById(meter); |
| | | return "查询成功"; |
| | | String syncMsg = syncMeters(); |
| | | return "查询成功;" + syncMsg; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (StringUtils.isBlank(meter.getXyName())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "电表协议为空,请先同步电表"); |
| | | } |
| | | if (StringUtils.isBlank(meter.getDljMac())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "多联机MAC为空,请先同步电表"); |
| | | } |
| | | DevControlRequest req = new DevControlRequest(); |
| | | req.fillSessionDefaults(); |
| | | req.setWg_mac(meter.getWgMac()); |
| | |
| | | JSONObject setVal = new JSONObject(); |
| | | setVal.put("db_bb", meter.getDbBb() != null ? meter.getDbBb() : 1); |
| | | setVal.put("xy_name", meter.getXyName()); |
| | | setVal.put("dlj_mac", meter.getDljMac()); |
| | | setVal.put("btl", meter.getBtl() != null ? meter.getBtl() : 4); |
| | | setVal.put("jy", meter.getJy() != null ? meter.getJy() : 0); |
| | | req.setSet_val(setVal); |
| | | return req; |
| | | } |
| | |
| | | local.setWgId(item.getWg_id()); |
| | | local.setXyId(item.getXy_id()); |
| | | local.setXyName(item.getXy_name()); |
| | | local.setDljMac(item.getDlj_mac()); |
| | | local.setBtl(item.getBtl()); |
| | | local.setJy(item.getJy()); |
| | | local.setDbBb(item.getDb_bb()); |
| | | local.setOutdoorLoop(item.getDb_rhd()); |
| | | local.setDbUptime(item.getDb_uptime()); |
| | | if (item.getDb_data() != null) { |
| | | local.setDbData(JSON.toJSONString(item.getDb_data())); |
| | | BigDecimal energy = parseDbDataEnergy(item.getDb_data()); |
| | | if (energy != null) { |
| | | local.setTotalDl(energy); |
| | | } |
| | | } |
| | | local.setLastSyncDate(now); |
| | | local.setEditDate(now); |
| | | } |
| | | |
| | | private BigDecimal parseDbDataEnergy(Object dbData) { |
| | | if (dbData == null) { |
| | | return null; |
| | | } |
| | | if (dbData instanceof Number) { |
| | | return new BigDecimal(dbData.toString()); |
| | | } |
| | | if (dbData instanceof String) { |
| | | String text = ((String) dbData).trim(); |
| | | if (StringUtils.isBlank(text)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return new BigDecimal(text); |
| | | } catch (Exception ignored) { |
| | | try { |
| | | return parseDbDataEnergy(JSON.parse(text)); |
| | | } catch (Exception ignored2) { |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | if (dbData instanceof JSONObject) { |
| | | JSONObject obj = (JSONObject) dbData; |
| | | for (String key : Arrays.asList("dl", "dn", "total_dl", "totalDl", "db_data", "energy")) { |
| | | if (obj.containsKey(key) && obj.get(key) != null) { |
| | | return parseDbDataEnergy(obj.get(key)); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | if (dbData instanceof Map) { |
| | | return parseDbDataEnergy(new JSONObject((Map<String, Object>) dbData)); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private void fillConditionerFromStatus(YwConditioner local, DeviceStatusResponse item, |
| | | DeviceArchiveResponse archive, Date now) { |
| | | local.setPlatformDevId(item.getDev_id()); |