From e521fe9f2852dd008f176e462bf8ad3e5267e68f Mon Sep 17 00:00:00 2001 From: nidapeng <jp@doumee.com> Date: 星期二, 23 四月 2024 10:57:08 +0800 Subject: [PATCH] 最新版本 --- server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java | 307 +++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 270 insertions(+), 37 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 285c101..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,15 +2,17 @@ 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.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; @@ -45,13 +47,80 @@ @Override // @Async public String syncHkDevices(AcsDeviceListRequest param){ - List<Device> deleteList = new ArrayList<>(); - List<Device> addList = new ArrayList<>(); - List<Device> editList = 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<>(); + Date date = new Date(); + //鏌ヨ鍏ㄩ儴闂ㄧ璁惧鏁版嵁 + List<Device> allList = deviceMapper.selectList(null); + List<DoorsInfoResponse> allDoors = getAllDoorList(); + List<AcsDeviceInfoResponse> allHkList = getAllDeViceList(); + /** + * 鑾峰彇澧炲垹鏀规暟鎹泦鍚� + */ + getDataChangeList(allList,allDoors,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; + } + } + @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(); List<AcsDeviceInfoResponse> allHkList = new ArrayList<>(); - Date date = new Date(); - //鏌ヨ鍏ㄩ儴闂ㄧ璁惧鏁版嵁 - List<Device> allList = deviceMapper.selectList(null); boolean hasNext = true; int curTotal = 0; int curPage = 1; @@ -76,39 +145,145 @@ } 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 allHkList; } - 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){ - for(AcsDeviceInfoResponse device : allHkList){ - Device model = getExistedDevice(device,allList); + public List<DoorsInfoResponse> getAllDoorList(){ + List<DoorsInfoResponse> allDoorList = new ArrayList<>(); + Date date = new Date(); + boolean hasNext = true; + int curTotal = 0; + int curPage = 1; + while (hasNext){ + //鍒嗛〉閬嶅巻寰幆鏌ヨ鎵�鏈夐棬绂佽澶囨暟鎹� + DoorsListRequest 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{ + allDoorList.addAll(r.getList()); + } + curPage++; + } + 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){ + //鑾峰彇娴峰悍鍏ㄩ儴闂ㄧ缁勬暟鎹� + for(DoorsInfoResponse device : hkDoorList){ + Device model = getExistedDoor(device,allList); if(model !=null){ //濡傛灉宸插瓨鍦紝鍒欐洿鏂版暟鎹� - model = initDataByHkData(model,device,date); + model = initDoorDataByHkData(model,device,date,allHkList); editList.add(model); }else{ //濡傛灉涓嶅瓨鍦紝鍒欐柊澧炴暟鎹� model = new Device(); - model = initDataByHkData(model,device,date); + model = initDoorDataByHkData(model,device,date,allHkList); + model.setIsEntrance(Constants.ZERO); + addList.add(model); + } + } + } + //鍒ゆ柇鑾峰彇鍒犻櫎鐨勯棬绂佽澶囷紝閫昏緫鍒犻櫎 + getDeleteDoorList(allList,hkDoorList,deleteList,date); + } + + private Device initDoorDataByHkData(Device model, DoorsInfoResponse door, Date date, List<AcsDeviceInfoResponse> allHkList) { + AcsDeviceInfoResponse device = getDeviceByDoorid(door.getParentIndexCode(),allHkList); + model.setIsdeleted(Constants.ZERO); + model.setIp(device.getIp()); + model.setHkDate(date); + 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)); + model.setChannelNo(door.getChannelNo()); + model.setChannelInfo(door.getName()); + model.setResourceType(device.getResourceType()); + model.setDevTypeCode(device.getDevTypeCode()); + model.setDevTypeDesc(device.getDevTypeDesc()); + model.setManufature(device.getManufacturer()); + model.setPort(device.getPort()); + model.setRemark(JSONObject.toJSONString(device)); + model.setDoorId(door.getIndexCode()); + model.setDoorName(door.getName()); + model.setRegionName(door.getRegionName()); + model.setRegionPathName(door.getRegionPathName()); + model.setDoorNo(door.getDoorNo()); + return model; + } + private AcsDeviceInfoResponse getDeviceByDoorid(String indexCode, List<AcsDeviceInfoResponse> allHkList ) { + if(allHkList!=null && allHkList.size()>0){ + for(AcsDeviceInfoResponse info : allHkList){ + if(StringUtils.equals(indexCode,info.getIndexCode())){ + return info; + } + } + } + + return new AcsDeviceInfoResponse(); + } + 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,hkDoorList); + editList.add(model); + }else{ + //濡傛灉涓嶅瓨鍦紝鍒欐柊澧炴暟鎹� + model = new Device(); + model = initDataByHkData(model,device,date,hkDoorList); addList.add(model); } } @@ -124,7 +299,7 @@ * @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); @@ -137,15 +312,50 @@ model.setManufature(device.getManufacturer()); model.setType(Constants.ZERO); // model.setNo(device.getDevSerialNum()); -// model.setChannelNo(device); + model.setChannelNo(getChannelNo(device.getIndexCode(),hkDoorList,model)); model.setResourceType(device.getResourceType()); model.setDevTypeCode(device.getDevTypeCode()); + model.setDevTypeDesc(device.getDevTypeDesc()); model.setManufature(device.getManufacturer()); model.setPort(device.getPort()); model.setRemark(JSONObject.toJSONString(device)); return model; } + private String getChannelNo(String indexCode, List<DoorsInfoResponse> hkDoorList,Device model ) { + String str = ""; + String names = ""; + 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 += ","; + names += ","; + } + str+=info.getChannelNo(); + names+=info.getName(); + } + } + } + model.setChannelNo(str); + model.setChannelInfo(names); + return str; + } + + private Device getExistedDoor(DoorsInfoResponse device, List<Device> allList) { + if(allList.size()>0){ + for(Device r : allList){ + if(StringUtils.equals(r.getDoorId(), device.getIndexCode())){ + //琛ㄧず鏈垹闄� + return r; + } + } + } + return null; + } private Device getExistedDevice(AcsDeviceInfoResponse device, List<Device> allList) { if(allList.size()>0){ for(Device r : allList){ @@ -169,7 +379,30 @@ } } } + private void getDeleteDoorList(List<Device> allList, List<DoorsInfoResponse> allHkList,List<Device> deleteList ,Date date) { + if(allList!=null && allList.size()>0){ + for(Device device : allList){ + if(isDeletedDoorDevice(device,allHkList)){ + device.setIsdeleted(Constants.ONE); + device.setEditDate(date); + deleteList.add(device); + } + } + } + } + private boolean isDeletedDoorDevice(Device device, List<DoorsInfoResponse> allHkList) { + if(allHkList.size()>0){ + for(DoorsInfoResponse r : allHkList){ + if(StringUtils.equals(device.getDoorId(), r.getIndexCode())){ + //琛ㄧず鏈垹闄� + return false; + } + } + } + return true; + + } private boolean isDeletedDevice(Device device, List<AcsDeviceInfoResponse> allHkList) { if(allHkList.size()>0){ for(AcsDeviceInfoResponse r : allHkList){ @@ -182,5 +415,5 @@ return true; } - + } -- Gitblit v1.9.3