From d16520069e7a89b5ac0d13d0c8ba4e30af023279 Mon Sep 17 00:00:00 2001
From: nidapeng <jp@doumee.com>
Date: 星期四, 28 三月 2024 18:35:44 +0800
Subject: [PATCH] 整理

---
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java |   63 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java
index 911a5c5..0268516 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java
@@ -2,11 +2,14 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.haikang.model.HKConstants;
+import com.doumee.core.haikang.model.param.BaseListPageResponse;
 import com.doumee.core.haikang.model.param.BaseResponse;
 import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest;
+import com.doumee.core.haikang.model.param.request.AcsDeviceStatusListRequest;
 import com.doumee.core.haikang.model.param.request.DoorsListRequest;
 import com.doumee.core.haikang.model.param.request.ParkListRequest;
 import com.doumee.core.haikang.model.param.respose.*;
@@ -83,6 +86,37 @@
             Constants.DEALING_HK_SYNCDEVICE =false;
         }
     }
+    @Override
+//    @Async
+    public void getAscDeviceStatus(){
+        if(Constants.DEALING_HK_SYNCDEVICE_STATUS){
+            return;
+        }
+        Constants.DEALING_HK_SYNCDEVICE_STATUS =true;
+        try {
+            List<Device> editList = new ArrayList<>();
+            Date date = new Date();
+            //鏌ヨ鍏ㄩ儴闂ㄧ璁惧鏁版嵁
+            List<AscDeviceStatusInfoResponse> allHkList = getAllDeviceStatusList();
+
+            if(allHkList.size()>0){
+                //閫昏緫鍒犻櫎
+                for(AscDeviceStatusInfoResponse d : allHkList){
+                    deviceMapper.update(null,new UpdateWrapper<Device>().lambda()
+                            .set(Device::getOnline,d.getOnline())
+                            .set(Device::getIp,d.getIp())
+                            .set(Device::getPort,d.getPort())
+                            .set(Device::getManufature,d.getManufacturer())
+                            .set(Device::getEditDate,date)
+                            .eq(Device::getHkId,d.getIndexCode()));
+                }
+            }
+        }catch (Exception e){
+            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鍚屾璁惧鐘舵�佸け璐ワ紒");
+        }finally {
+            Constants.DEALING_HK_SYNCDEVICE_STATUS =false;
+        }
+    }
 
     private List<AcsDeviceInfoResponse> getAllDeViceList() {
         AcsDeviceListRequest param = new AcsDeviceListRequest();
@@ -143,6 +177,35 @@
         }
         return  allDoorList;
     }
+    public  List<AscDeviceStatusInfoResponse>  getAllDeviceStatusList(){
+        List<AscDeviceStatusInfoResponse> allDoorList = new ArrayList<>();
+        Date date = new Date();
+        boolean hasNext = true;
+        int curTotal = 0;
+        int curPage = 1;
+        while (hasNext){
+            //鍒嗛〉閬嶅巻寰幆鏌ヨ鎵�鏈夐棬绂佽澶囨暟鎹�
+            AcsDeviceStatusListRequest param = new AcsDeviceStatusListRequest();
+            param.setPageNo(curPage);
+            param.setPageSize(100);
+            BaseResponse<BaseListPageResponse<AscDeviceStatusInfoResponse>> response = HKService.acsDeviceStatus(param);
+            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
+                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝娴峰悍鍚屾鏁版嵁澶辫触~");
+            }
+            BaseListPageResponse r = response.getData();
+            curTotal += 100;
+            if(curTotal >= r.getTotal()){
+                hasNext = false;
+            }
+            if(r.getList() == null || r.getList().size()==0){
+                hasNext =false;
+            }else{
+                allDoorList.addAll(r.getList());
+            }
+            curPage++;
+        }
+        return  allDoorList;
+    }
 
     private void getDataChangeList(List<Device> allList, List<DoorsInfoResponse> hkDoorList , List<AcsDeviceInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) {
         if(hkDoorList!=null && hkDoorList.size()>0){

--
Gitblit v1.9.3