|
@@ -86,7 +86,7 @@ public class DeviceImpl implements IDevice {
|
|
|
if(dataSync){
|
|
|
log.info("同步牧场端设备数据。");
|
|
|
//从数据库查询出牧场id
|
|
|
- String farmIp = "http://192.168.1.49:8091";
|
|
|
+ String farmIp = _getFarmIP(farmId);
|
|
|
String serviceUrl = farmIp + deviceAddService;
|
|
|
System.out.println("serviceUrl>>"+serviceUrl);
|
|
|
String data = textUtil.encode(JSON.toJSONString(outFarmDeviceEntity));
|
|
@@ -98,6 +98,11 @@ public class DeviceImpl implements IDevice {
|
|
|
return new Result(ResultCode.SUCCESS, outFarmDeviceEntity);
|
|
|
}
|
|
|
|
|
|
+ //获取牧场
|
|
|
+ private String _getFarmIP(Integer farmId){
|
|
|
+ return "http://192.168.1.49:8091";
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Method : editDevice
|
|
|
* @Description : 编辑设备
|
|
@@ -108,7 +113,7 @@ public class DeviceImpl implements IDevice {
|
|
|
* @Time : 22:03
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result editDevice(String deviceName, String deviceCode, String deviceType, String factory, String worker, String mainParams, Integer state, String record, Integer farmId, Integer id) {
|
|
|
+ public Result editDevice(String deviceName, String deviceCode, String deviceType, String factory, String worker, String mainParams, Integer state, String record, Integer farmId, Integer id) throws UnsupportedEncodingException {
|
|
|
|
|
|
Optional<FarmDeviceEntity> optional = deviceRepo.findById(id);
|
|
|
if (!optional.isPresent()) {
|
|
@@ -127,6 +132,20 @@ public class DeviceImpl implements IDevice {
|
|
|
deviceEntity.setState(state);
|
|
|
deviceEntity.setLastTime(new Timestamp(new Date().getTime()));
|
|
|
FarmDeviceEntity outFarmDeviceEntity = deviceRepo.saveAndFlush(deviceEntity);
|
|
|
+ log.info("数据中心添加设备信息>>"+outFarmDeviceEntity);
|
|
|
+ //同步牧场端设备数据
|
|
|
+ if(dataSync){
|
|
|
+ log.info("同步牧场端设备数据。");
|
|
|
+ //从数据库查询出牧场id
|
|
|
+ String farmIp = _getFarmIP(farmId);
|
|
|
+ String serviceUrl = farmIp + deviceEditService;
|
|
|
+ System.out.println("serviceUrl>>"+serviceUrl);
|
|
|
+ String data = textUtil.encode(JSON.toJSONString(outFarmDeviceEntity));
|
|
|
+ System.out.println("密文>>"+data);
|
|
|
+
|
|
|
+ //提交请求
|
|
|
+ httpTemplete.doPostSimple(serviceUrl,data);
|
|
|
+ }
|
|
|
return new Result(ResultCode.SUCCESS, outFarmDeviceEntity);
|
|
|
}
|
|
|
|
|
@@ -140,7 +159,49 @@ public class DeviceImpl implements IDevice {
|
|
|
* @Time : 22:02
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result removeDevice(String ids, Integer farmId) {
|
|
|
+ public Result removeDevice(Integer id, Integer farmId) throws UnsupportedEncodingException {
|
|
|
+// String[] idArray = ids.split(",");
|
|
|
+// List idList = new ArrayList<>();
|
|
|
+// for (int a = 0; a < idArray.length; a++) {
|
|
|
+// idList.add(Integer.parseInt(idArray[a]));
|
|
|
+// }
|
|
|
+// deviceRepo.deleteAllByIdInBatch(idList);
|
|
|
+ Optional<FarmDeviceEntity> optional = deviceRepo.findById(id);
|
|
|
+ if (!optional.isPresent()) {
|
|
|
+ String ERROR_INFO = "该记录已不存在.";
|
|
|
+ log.error(ERROR_INFO);
|
|
|
+ return new Result(10001, ERROR_INFO, false);
|
|
|
+ }
|
|
|
+ //
|
|
|
+ deviceRepo.deleteById(id);
|
|
|
+ //同步牧场端设备数据
|
|
|
+ if(dataSync){
|
|
|
+ log.info("同步牧场端设备数据。");
|
|
|
+ //从数据库查询出牧场id
|
|
|
+ String farmIp = _getFarmIP(farmId);
|
|
|
+ String serviceUrl = farmIp + deviceRemoveService;
|
|
|
+ System.out.println("serviceUrl>>"+serviceUrl);
|
|
|
+ String data = textUtil.encode(JSON.toJSONString(id));
|
|
|
+ System.out.println("密文>>"+data);
|
|
|
+
|
|
|
+ //提交请求
|
|
|
+ httpTemplete.doPostSimple(serviceUrl,data);
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : removeBatichDevice
|
|
|
+ * @Description :
|
|
|
+ * @Params : [ids, farmId]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/12/16
|
|
|
+ * @Time : 10:07
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result removeBatichDevice(String ids, Integer farmId) {
|
|
|
String[] idArray = ids.split(",");
|
|
|
List idList = new ArrayList<>();
|
|
|
for (int a = 0; a < idArray.length; a++) {
|