Просмотр исходного кода

[电表][修复]:通信解析调整

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
a4fd26fff4
2 измененных файлов: 34 добавлений и 36 удалений
  1. +30
    -33
      mallinkCallback/src/main/java/com/iformall/controller/device/KwBoxV1Controller.java
  2. +4
    -3
      mallinkService/src/main/java/com/iformall/service/kw/impl/KwBoxServiceImpl.java

+ 30
- 33
mallinkCallback/src/main/java/com/iformall/controller/device/KwBoxV1Controller.java Просмотреть файл

@@ -36,7 +36,7 @@ public class KwBoxV1Controller extends BaseController {
private KwBoxCmdHistoryService kwBoxCmdHistoryService; private KwBoxCmdHistoryService kwBoxCmdHistoryService;




private void saveCmd(String tenantId, String cmd, String imei, String ccid, Date deviceTime, Map<String,String> paramMap)
private void saveCmd(String tenantId, String cmd, String imei, String ccid, Date deviceTime, Map<String,Object> paramMap)
{ {
KwBoxCmdHistory kwBoxCmdHistory = new KwBoxCmdHistory(); KwBoxCmdHistory kwBoxCmdHistory = new KwBoxCmdHistory();
kwBoxCmdHistory.setCmd(cmd); kwBoxCmdHistory.setCmd(cmd);
@@ -51,14 +51,14 @@ public class KwBoxV1Controller extends BaseController {


} }


private ResultData cmdRegist(String imei, String ccid, Date deviceTime, Map<String,String> paramMap)
private ResultData cmdRegist(String imei, String ccid, Date deviceTime, Map<String,Object> paramMap)
{ {


String fwv = paramMap.get("FWV");
String fwv = (String)paramMap.get("FWV");
if (StringUtil.isNullOrEmpty(fwv)) if (StringUtil.isNullOrEmpty(fwv))
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);


String hwv = paramMap.get("HWV");
String hwv = (String)paramMap.get("HWV");
if (StringUtil.isNullOrEmpty(hwv)) if (StringUtil.isNullOrEmpty(hwv))
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);


@@ -86,12 +86,13 @@ public class KwBoxV1Controller extends BaseController {
if (kwBox.getConfig() != null) if (kwBox.getConfig() != null)
data.put("config",kwBox.getConfig() ); data.put("config",kwBox.getConfig() );
List<String> meters = kwBoxService.findMeters(kwBox); List<String> meters = kwBoxService.findMeters(kwBox);
data.put("meters",meters);
if (!meters.isEmpty())
data.put("meters",meters);
return new ResultData(data); return new ResultData(data);


} }


private ResultData cmdLogin(String imei, String ccid, Date deviceTime, Map<String,String> paramMap)
private ResultData cmdLogin(String imei, String ccid, Date deviceTime, Map<String,Object> paramMap)
{ {
KwBox kwBox = kwBoxService.findByImei(imei); KwBox kwBox = kwBoxService.findByImei(imei);


@@ -110,13 +111,14 @@ public class KwBoxV1Controller extends BaseController {
record.setLastOnlineTime(new Date()); record.setLastOnlineTime(new Date());
kwBoxService.saveOrUpdate(record); kwBoxService.saveOrUpdate(record);
Map<String,Object> data = new HashMap<>(); Map<String,Object> data = new HashMap<>();
data.put("config",kwBox.getConfig());
if (kwBox.getConfig() != null)
data.put("config",kwBox.getConfig() );
return new ResultData(data); return new ResultData(data);
} }






private ResultData cmdHb(String imei, String ccid, Date deviceTime, Map<String,String> paramMap)
private ResultData cmdHb(String imei, String ccid, Date deviceTime, Map<String,Object> paramMap)
{ {
KwBox kwBox = kwBoxService.findByImei(imei); KwBox kwBox = kwBoxService.findByImei(imei);
if (kwBox == null) if (kwBox == null)
@@ -134,36 +136,31 @@ public class KwBoxV1Controller extends BaseController {
kwBoxService.saveOrUpdate(record); kwBoxService.saveOrUpdate(record);
Map<String,Object> resData = new HashMap<>(); Map<String,Object> resData = new HashMap<>();


List<Map<String,String>> metersData = (List<Map<String,String>>)paramMap.get("meters");


List<String> meters = kwBoxService.findMeters(kwBox);
String metersDataStr = paramMap.get("meters");
JSONArray ja = JSONObject.parseArray(metersDataStr);

boolean updateMeters = false;
boolean updateConfig = false;

if (ja.size() > 0) {
List<HashMap> metersData = ja.toJavaList(HashMap.class);
if (!metersData.isEmpty()) {
metersData.stream().forEach(m->{ metersData.stream().forEach(m->{
String addr = (String)m.get("addr");
String data = (String)m.get("data");
String addr = m.get("addr");
String data = m.get("data");
kwBoxService.saveMeterData(kwBox, deviceTime, addr, data); kwBoxService.saveMeterData(kwBox, deviceTime, addr, data);
}); });
}


if (metersData.size() != meters.size()) {
updateMeters = true;
} else {
if (!meters.containsAll(metersData.stream().map(m->m.get("addr")).collect(Collectors.toList())))
updateMeters = true;
}
List<String> meters = kwBoxService.findMeters(kwBox);


} else {
boolean updateMeters = false;
boolean updateConfig = false;

if (metersData.size() != meters.size())
{
updateMeters = true; updateMeters = true;
} else {
if (!meters.containsAll(metersData.stream().map(m->m.get("addr")).collect(Collectors.toList())))
updateMeters = true;
} }


if (updateMeters) { if (updateMeters) {
if (meters.size() > 0)
resData.put("meters", meters);
resData.put("meters", meters);
} }
if (updateConfig) { if (updateConfig) {
resData.put("config", kwBox.getConfig()); resData.put("config", kwBox.getConfig());
@@ -178,21 +175,21 @@ public class KwBoxV1Controller extends BaseController {


@ApiOperation("开物盒子V1") @ApiOperation("开物盒子V1")
@PostMapping("command") @PostMapping("command")
public Result command(@RequestBody Map<String,String> paramMap) {
public Result command(@RequestBody Map<String,Object> paramMap) {


String cmd = paramMap.get("CMD");
String cmd = (String)paramMap.get("CMD");
if (StringUtil.isNullOrEmpty(cmd)) if (StringUtil.isNullOrEmpty(cmd))
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);


String imei = paramMap.get("IMEI");
String imei = (String)paramMap.get("IMEI");
if (StringUtil.isNullOrEmpty(imei)) if (StringUtil.isNullOrEmpty(imei))
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);


String ccid = paramMap.get("CCID");
String ccid = (String)paramMap.get("CCID");
if (StringUtil.isNullOrEmpty(ccid)) if (StringUtil.isNullOrEmpty(ccid))
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);


String time = paramMap.get("TIME");
String time = (String)paramMap.get("TIME");
if (StringUtil.isNullOrEmpty(time)) if (StringUtil.isNullOrEmpty(time))
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);




+ 4
- 3
mallinkService/src/main/java/com/iformall/service/kw/impl/KwBoxServiceImpl.java Просмотреть файл

@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -119,20 +120,20 @@ public class KwBoxServiceImpl implements KwBoxService {


if (kwBoxMeters.isEmpty()) { if (kwBoxMeters.isEmpty()) {
logger.info("没找到盒子表关联项: boxId="+kwBoxMeter.getBoxId()); logger.info("没找到盒子表关联项: boxId="+kwBoxMeter.getBoxId());
return null;
return new ArrayList<>();
} }
KwMeter kwMeter = new KwMeter(); KwMeter kwMeter = new KwMeter();
kwMeter.setIds(kwBoxMeters.stream().map(KwBoxMeter::getMeterId).collect(Collectors.toList())); kwMeter.setIds(kwBoxMeters.stream().map(KwBoxMeter::getMeterId).collect(Collectors.toList()));


if (kwMeter.getIds().isEmpty()) { if (kwMeter.getIds().isEmpty()) {
logger.info("没找到盒子关联的表: boxId="+kwBoxMeter.getBoxId()); logger.info("没找到盒子关联的表: boxId="+kwBoxMeter.getBoxId());
return null;
return new ArrayList<>();
} }
List<KwMeter> kwMeters = kwMeterService.findList(kwMeter); List<KwMeter> kwMeters = kwMeterService.findList(kwMeter);


if (kwMeter.getIds().isEmpty()) { if (kwMeter.getIds().isEmpty()) {
logger.info("没找到盒子关联的表: ids=" + kwBoxMeter.getIds()); logger.info("没找到盒子关联的表: ids=" + kwBoxMeter.getIds());
return null;
return new ArrayList<>();
} }
return kwMeters.stream().map(KwMeter::getAddress).collect(Collectors.toList()); return kwMeters.stream().map(KwMeter::getAddress).collect(Collectors.toList());
} }


Загрузка…
Отмена
Сохранить