|
@@ -127,8 +127,29 @@ public class FarmDeviceImpl implements IFarmDevice {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result removeDevice(String deviceData){
|
|
|
-
|
|
|
+ public Result removeDevice(String deviceData) throws UnsupportedEncodingException {
|
|
|
+ JSONObject deviceDataJo = JSON.parseObject(deviceData);
|
|
|
+ Integer id = deviceDataJo.getInteger("id");
|
|
|
+ //查询记录是否存在
|
|
|
+ Optional<FarmDeviceEntity> optional = deviceRepo.findById(id);
|
|
|
+ if(!optional.isPresent()){
|
|
|
+ String ERR_INFO_NOEXIST = "该记录不存在.";
|
|
|
+ log.error(ERR_INFO_NOEXIST);
|
|
|
+ return new Result(10001,ERR_INFO_NOEXIST,false);
|
|
|
+ }
|
|
|
+ Long dataId = optional.get().getDataId();
|
|
|
+ //
|
|
|
+ deviceRepo.deleteById(id);
|
|
|
+ //同步牧场端设备数据
|
|
|
+ if(dataSync){
|
|
|
+ log.info("同步数据中心端设备数据。");
|
|
|
+ String serviceUrl = DATA_CENTER_IP_ADDR + PORT + deviceRemoveService;
|
|
|
+ log.info("serviceUrl>>"+serviceUrl);
|
|
|
+ String data = textUtil.encode(JSON.toJSONString(dataId));
|
|
|
+ log.info("base64密文>>"+data);
|
|
|
+ //提交请求
|
|
|
+ httpTemplete.doPostSimple(serviceUrl,data);
|
|
|
+ }
|
|
|
return new Result(ResultCode.SUCCESS);
|
|
|
}
|
|
|
|