From 86a3327f45cae29e314c150a3bcd7637378fa227 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 21 十二月 2023 09:23:52 +0800
Subject: [PATCH] 海康接口对接开发
---
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java | 146 +++++++++++++++++++++++++++++++++++-------------
1 files changed, 106 insertions(+), 40 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 1c99ba1..6e24bd8 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
@@ -1,14 +1,15 @@
package com.doumee.service.business.impl.hksync;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
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.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.request.ParkListRequest;
-import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse;
-import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse;
-import com.doumee.core.haikang.model.param.respose.ParkListResponse;
+import com.doumee.core.haikang.model.param.respose.*;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
@@ -43,70 +44,113 @@
@Override
// @Async
public String syncHkDevices(AcsDeviceListRequest param){
- List<Device> deleteList = new ArrayList<>();
- List<Device> addList = new ArrayList<>();
- List<Device> editList = new ArrayList<>();
- List<AcsDeviceInfoResponse> allHkList = new ArrayList<>();
+ if(Constants.DEALING_HK_SYNCDEVICE){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鍚屾浠诲姟姝e湪鎵ц鍝︼紝璇风◢鍚庢煡鐪嬬粨鏋滐紒") ;
+ }
+ Constants.DEALING_HK_SYNCDEVICE =true;
+ try {
+ List<Device> deleteList = new ArrayList<>();
+ List<Device> addList = new ArrayList<>();
+ List<Device> editList = new ArrayList<>();
+ List<AcsDeviceInfoResponse> 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 AcsDeviceListRequest();
+ param.setPageNo(curPage);
+ param.setPageSize(100);
+ BaseResponse<AcsDeviceListResponse> response = HKService.acsDeviceList(param);
+ if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
+ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝娴峰悍鍚屾鏁版嵁澶辫触~");
+ }
+ AcsDeviceListResponse 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++;
+ }
+ /**
+ * 鑾峰彇澧炲垹鏀规暟鎹泦鍚�
+ */
+ 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;
+ }
+ }
+
+ public List<DoorsInfoResponse> getAllDoorList(){
+ List<DoorsInfoResponse> allDoorList = 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 AcsDeviceListRequest();
+ DoorsListRequest param = new DoorsListRequest();
param.setPageNo(curPage);
- param.setPageSize(10000);
- BaseResponse<AcsDeviceListResponse> response = hkService.acsDeviceList(param);
+ 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(), "瀵逛笉璧凤紝娴峰悍鍚屾鏁版嵁澶辫触~");
}
- AcsDeviceListResponse r = response.getData();
- curTotal += 10000;
+ 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());
+ allDoorList.addAll(r.getList());
}
curPage++;
}
- /**
- * 鑾峰彇澧炲垹鏀规暟鎹泦鍚�
- */
- 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()+"銆戞潯";
+ return allDoorList;
}
private void getDataChangeList(List<Device> allList, List<AcsDeviceInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) {
if(allHkList!=null && allHkList.size()>0){
+ //鑾峰彇娴峰悍鍏ㄩ儴闂ㄧ缁勬暟鎹�
+ List<DoorsInfoResponse> hkDoorList = getAllDoorList();
for(AcsDeviceInfoResponse device : allHkList){
Device model = getExistedDevice(device,allList);
if(model !=null){
//濡傛灉宸插瓨鍦紝鍒欐洿鏂版暟鎹�
- model = initDataByHkData(model,device,date);
+ model = initDataByHkData(model,device,date,hkDoorList);
editList.add(model);
}else{
//濡傛灉涓嶅瓨鍦紝鍒欐柊澧炴暟鎹�
model = new Device();
- model = initDataByHkData(model,device,date);
+ model = initDataByHkData(model,device,date,hkDoorList);
addList.add(model);
}
}
@@ -122,24 +166,46 @@
* @param date
* @return
*/
- private Device initDataByHkData(Device model, AcsDeviceInfoResponse device,Date date) {
+ private Device initDataByHkData(Device model, AcsDeviceInfoResponse device,Date date, List<DoorsInfoResponse> hkDoorList) {
model.setIsdeleted(Constants.ZERO);
model.setIp(device.getIp());
model.setHkDate(date);
- model.setCreateDate(DateUtil.StringToDate2(device.getCreateTime()));
- model.setEditDate(DateUtil.StringToDate2(device.getUpdateTime()));
- model.setNo(device.getDeviceCode());
+ model.setCreateDate(DateUtil.getISO8601DateByStr(device.getCreateTime()));
+ model.setEditDate(DateUtil.getISO8601DateByStr(device.getUpdateTime()));
+ model.setNo(device.getDevSerialNum());
model.setHkId(device.getIndexCode());
model.setName(device.getName());
model.setHkStatus(Constants.ONE);
+ model.setManufature(device.getManufacturer());
model.setType(Constants.ZERO);
+// model.setNo(device.getDevSerialNum());
+ model.setChannelNo(getChannelNo(device.getIndexCode(),hkDoorList));
model.setResourceType(device.getResourceType());
model.setDevTypeCode(device.getDevTypeCode());
model.setManufature(device.getManufacturer());
model.setPort(device.getPort());
+ model.setRemark(JSONObject.toJSONString(device));
return model;
}
+ private String getChannelNo(String indexCode, List<DoorsInfoResponse> hkDoorList) {
+ String str = "";
+ if(hkDoorList!=null && hkDoorList.size()>0){
+ for(DoorsInfoResponse info : hkDoorList){
+ if(StringUtils.equals(indexCode,info.getParentIndexCode())){
+ if(StringUtils.isBlank(info.getChannelNo())){
+ continue;
+ }
+ if(StringUtils.isNotBlank(str)){
+ str += ",";
+ }
+ str+=info.getChannelNo();
+ }
+ }
+ }
+ return str;
+ }
+
private Device getExistedDevice(AcsDeviceInfoResponse device, List<Device> allList) {
if(allList.size()>0){
for(Device r : allList){
--
Gitblit v1.9.3