Jelajahi Sumber

远程修改服务器ip和端

fllmoyu 5 tahun lalu
induk
melakukan
de37a7fccb

+ 9 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java

@@ -184,5 +184,14 @@ public interface ILapiService {
      */
     DataServersDTO getDeviceDateServer(String deviceNo) throws Exception;
 
+    /**
+     * 修改设备的服务器ip端口
+     * @param deviceNoList 设备序列号集合
+     * @param newAddress   新ip
+     * @param newPort 新端口
+     * @throws Exception
+     */
+    void updateDeviceData(List<String> deviceNoList,String newAddress,String newPort) throws Exception;
+
 
 }

+ 49 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java

@@ -14,6 +14,7 @@ import com.jpsoft.smart.modules.common.utils.LApiUtil;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
 import com.jpsoft.smart.modules.constant.LApiConstant;
 import com.jpsoft.smart.modules.lapi.dto.DataServersDTO;
+import com.jpsoft.smart.modules.lapi.dto.ServerAddrDTO;
 import com.jpsoft.smart.modules.lapi.request.LapiRequest;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
 import com.jpsoft.smart.modules.lapi.vo.*;
@@ -996,5 +997,53 @@ public class LapiServiceImpl implements ILapiService {
         return null;
     }
 
+    @Override
+    public void updateDeviceData(List<String> deviceNoList, String newAddress, String newPort) throws Exception {
+
+
+        if (deviceNoList.size() <= 0) {
+            throw new Exception("设备为空");
+        }
+        for (String deviceNo : deviceNoList) {
+            try {
+                DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(deviceNo);
+                DataServersDTO dataServersDTO = getDeviceDateServer(deviceNo);
+
+                if (dataServersDTO != null) {
+                    ServerAddrDTO serverAddrDTO = dataServersDTO.getServerAddr();
+                    /*if (StringUtils.isNotBlank(newDeviceNo)) {
+                        dataServersDTO.setTollgateID(newDeviceNo);
+                    }*/
+                    if (StringUtils.isNotBlank(newAddress)) {
+                        serverAddrDTO.setAddress(newAddress);
+                    }
+                    if (StringUtils.isNotBlank(newPort)) {
+                        serverAddrDTO.setPort(Integer.valueOf(newPort));
+                    }
+                    dataServersDTO.setServerAddr(serverAddrDTO);
+
+                    List<DataServersDTO> dataServersDTOList = new ArrayList<>();
+                    dataServersDTOList.add(dataServersDTO);
+                    HashMap<String, Object> map = new HashMap<>();
+                    map.put("Num", 1);
+                    map.put("DataServerList", dataServersDTOList);
+                    JSONObject jsonObject = lapiRequest.send(deviceNo, LApiConstant.DATASERVERS, HttpMethod.PUT, map);
+                    JSONObject dataJson = jsonObject.getJSONObject("Response");
+                    JSONObject response = LApiUtil.getResponse(dataJson);
+
+                    if (dataJson.getString("ResponseString").equals("Succeed") && dataJson.getString("StatusString").equals("Succeed")) {
+                        //  deviceInfo.setDeviceNo(newDeviceNo);
+                        deviceInfo.setUpdateTime(new Date());
+                        deviceInfoService.update(deviceInfo);
+                    }
+                }
+
+
+            } catch (Exception ex) {
+                log.error(ex.getMessage(), ex);
+            }
+        }
+    }
+
 
 }