|
@@ -35,11 +35,8 @@ public class DeviceImpl implements IDevice {
|
|
|
|
|
|
@Override
|
|
|
public Result syncAddFarmDevice(String deviceData) throws UnsupportedEncodingException {
|
|
|
- deviceData = deviceData.replace("data=","");
|
|
|
- deviceData = textUtil.decode(deviceData.replace("%3D","="));
|
|
|
- JSONObject deviceDataJo = JSON.parseObject(deviceData);
|
|
|
-// String encodedText = deviceDataJo.getString("data");
|
|
|
-// System.out.println("encodedText>>"+encodedText);
|
|
|
+ //转义符号处理
|
|
|
+ JSONObject deviceDataJo = JSON.parseObject(_translateSymbol(deviceData));
|
|
|
FarmDeviceEntity deviceEntity = new FarmDeviceEntity();
|
|
|
deviceEntity.setDataId(deviceDataJo.getInteger("id"));
|
|
|
deviceEntity.setDeviceCode(deviceDataJo.getString("deviceCode"));
|
|
@@ -55,13 +52,19 @@ public class DeviceImpl implements IDevice {
|
|
|
deviceEntity.setState(deviceDataJo.getInteger("state"));
|
|
|
deviceEntity.setWorker(deviceDataJo.getString("worker"));
|
|
|
FarmDeviceEntity addEntity = deviceRepo.saveAndFlush(deviceEntity);
|
|
|
- log.info("同步牧场端设备数据>>"+addEntity);
|
|
|
+ log.info("同步添加牧场端设备数据>>"+addEntity);
|
|
|
return new Result(ResultCode.SUCCESS,addEntity);
|
|
|
}
|
|
|
|
|
|
+ //转义处理
|
|
|
+ public String _translateSymbol(String data) throws UnsupportedEncodingException {
|
|
|
+ return textUtil.decode(data.replace("data=","").replace("%3D","="));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public Result syncEditFarmDevice(String deviceData){
|
|
|
- JSONObject deviceDataJo = JSON.parseObject(deviceData);
|
|
|
+ public Result syncEditFarmDevice(String deviceData) throws UnsupportedEncodingException {
|
|
|
+ //转义符号处理
|
|
|
+ JSONObject deviceDataJo = JSON.parseObject(_translateSymbol(deviceData));
|
|
|
Integer dataId = deviceDataJo.getInteger("id");
|
|
|
//查询目标设备数据
|
|
|
List<Object[]> existList = deviceRepo.getDevice(dataId);
|
|
@@ -85,26 +88,30 @@ public class DeviceImpl implements IDevice {
|
|
|
deviceEntity.setState(deviceDataJo.getInteger("state"));
|
|
|
deviceEntity.setWorker(deviceDataJo.getString("worker"));
|
|
|
FarmDeviceEntity editEntity = deviceRepo.saveAndFlush(deviceEntity);
|
|
|
- log.info("编辑后的设备数据>>" + editEntity);
|
|
|
+ log.info("同步编辑牧场端设备数据>>" + editEntity);
|
|
|
return new Result(ResultCode.SUCCESS,editEntity);
|
|
|
}else{
|
|
|
+ log.info("错误:牧场端不存在data_id为"+dataId+"的记录。");
|
|
|
return new Result(ResultCode.SUCCESS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result syncRemoveFarmDevice(String deviceData){
|
|
|
- JSONObject deviceDataJo = JSON.parseObject(deviceData);
|
|
|
- Integer dataId = deviceDataJo.getInteger("dataId");
|
|
|
+ public Result syncRemoveFarmDevice(String deviceData) throws UnsupportedEncodingException {
|
|
|
+ //转义符号处理
|
|
|
+ Integer dataId = Integer.parseInt(_translateSymbol(deviceData));
|
|
|
//查询目标设备数据
|
|
|
List<Object[]> existList = deviceRepo.getDevice(dataId);
|
|
|
if(existList.size()>0) {
|
|
|
Object[] object = existList.get(0);
|
|
|
Integer id = (Integer) object[0];
|
|
|
deviceRepo.deleteById(id);
|
|
|
+ log.info("同步删除牧场端设备数据.");
|
|
|
return new Result(ResultCode.SUCCESS);
|
|
|
}else{
|
|
|
- return new Result(10001,"暂无删除设备数据.",false);
|
|
|
+ String ERR_INFO="暂无需要删除的设备数据.";
|
|
|
+ log.info(ERR_INFO);
|
|
|
+ return new Result(10001,ERR_INFO,false);
|
|
|
}
|
|
|
}
|
|
|
}
|