From e59a768f56efb64bf2fad412f62eca2a836b652f Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期四, 28 十二月 2023 14:13:00 +0800 Subject: [PATCH] 海康接口对接开发 --- server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDoorsServiceImpl.java | 108 +++++++++++++++++++++++++++++------------------------ 1 files changed, 59 insertions(+), 49 deletions(-) diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDoorsServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDoorsServiceImpl.java index 5ff883d..cd1be6c 100644 --- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDoorsServiceImpl.java +++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDoorsServiceImpl.java @@ -7,10 +7,8 @@ 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.DoorsListRequest; +import com.doumee.core.haikang.model.param.respose.*; import com.doumee.core.haikang.model.param.respose.DoorsInfoResponse; -import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse; -import com.doumee.core.haikang.model.param.respose.DoorsInfoResponse; -import com.doumee.core.haikang.model.param.respose.DoorsListResponse; import com.doumee.core.haikang.service.HKService; import com.doumee.core.utils.Constants; import com.doumee.core.utils.DateUtil; @@ -43,56 +41,68 @@ @Override // @Async public String syncDoors(DoorsListRequest param){ - List<Device> deleteList = new ArrayList<>(); - List<Device> addList = new ArrayList<>(); - List<Device> editList = new ArrayList<>(); - List<DoorsInfoResponse> allHkList = new ArrayList<>(); - Date date = new Date(); - //鏌ヨ鍏ㄩ儴闂ㄧ璁惧鏁版嵁 - List<Device> allList = deviceMapper.selectList(null); - boolean hasNext = true; - int curTotal = 0; - int curPage = 1; - while (hasNext){ - //鍒嗛〉閬嶅巻寰幆鏌ヨ鎵�鏈夐棬绂佽澶囨暟鎹� - param = new DoorsListRequest(); - param.setPageNo(curPage); - param.setPageSize(100); - BaseResponse<DoorsListResponse> response = HKService.doorSearch(param); - if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ - throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝娴峰悍鍚屾鏁版嵁澶辫触~"); - } - DoorsListResponse r = response.getData(); - curTotal += 100; - if(curTotal >= r.getTotal()){ - hasNext = false; - } - if(r.getList() == null || r.getList().size()==0){ - hasNext =false; - }else{ - allHkList.addAll(r.getList()); - } - curPage++; + if(Constants.DEALING_HK_SYNCDEVICE){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鍚屾浠诲姟姝e湪鎵ц鍝︼紝璇风◢鍚庢煡鐪嬬粨鏋滐紒") ; } - /** - * 鑾峰彇澧炲垹鏀规暟鎹泦鍚� - */ - getDataChangeList(allList,allHkList,addList,editList,deleteList,date); - if(deleteList.size()>0){ - //閫昏緫鍒犻櫎 - for(Device d : deleteList){ - deviceMapper.updateById(d); + Constants.DEALING_HK_SYNCDEVICE =true; + try { + List<Device> deleteList = new ArrayList<>(); + List<Device> addList = new ArrayList<>(); + List<Device> editList = new ArrayList<>(); + List<DoorsInfoResponse> allHkList = new ArrayList<>(); + Date date = new Date(); + //鏌ヨ鍏ㄩ儴闂ㄧ璁惧鏁版嵁 + List<Device> allList = deviceMapper.selectList(null); + boolean hasNext = true; + int curTotal = 0; + int curPage = 1; + while (hasNext){ + //鍒嗛〉閬嶅巻寰幆鏌ヨ鎵�鏈夐棬绂佽澶囨暟鎹� + param = new DoorsListRequest(); + param.setPageNo(curPage); + param.setPageSize(100); + BaseResponse<DoorsListResponse> response = HKService.doorSearch(param); + if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ + throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝娴峰悍鍚屾鏁版嵁澶辫触~"); + } + DoorsListResponse r = response.getData(); + curTotal += 100; + if(curTotal >= r.getTotal()){ + hasNext = false; + } + if(r.getList() == null || r.getList().size()==0){ + hasNext =false; + }else{ + allHkList.addAll(r.getList()); + } + curPage++; } - } - if(addList.size()>0){ - deviceMapper.insertBatchSomeColumn(addList); - } - if(editList.size()>0){ - for(Device d : editList){ - deviceMapper.updateById(d); + /** + * 鑾峰彇澧炲垹鏀规暟鎹泦鍚� + */ + getDataChangeList(allList,allHkList,addList,editList,deleteList,date); + if(deleteList.size()>0){ + //閫昏緫鍒犻櫎 + for(Device d : deleteList){ + deviceMapper.updateById(d); + } } + if(addList.size()>0){ + deviceMapper.insertBatchSomeColumn(addList); + } + if(editList.size()>0){ + for(Device d : editList){ + deviceMapper.updateById(d); + } + } + return "鍚屾鏁版嵁锛氭柊澧炪��"+addList.size()+"銆戞潯锛屾洿鏂般��"+editList.size()+"銆戞潯锛屽垹闄ゃ��"+deleteList.size()+"銆戞潯"; + }catch (Exception e){ + e.printStackTrace(); + throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鍚屾澶辫触锛�"); + }finally { + Constants.DEALING_HK_SYNCDEVICE =false; } - return "鍚屾鏁版嵁锛氭柊澧炪��"+addList.size()+"銆戞潯锛屾洿鏂般��"+editList.size()+"銆戞潯锛屽垹闄ゃ��"+deleteList.size()+"銆戞潯"; + } private void getDataChangeList(List<Device> allList, List<DoorsInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) { -- Gitblit v1.9.3