| | |
| | | package com.doumee.service.business.impl.hksync; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.aliyun.tea.TeaException; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.dao.business.DeviceMapper; |
| | | import com.doumee.dao.business.ParksMapper; |
| | | import com.doumee.dao.business.model.Device; |
| | | import com.doumee.dao.business.model.Parks; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | */ |
| | | @Service |
| | | public class HkSyncDeviceServiceImpl extends HkSyncBaseServiceImpl { |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | /** |
| | | * 同步海康门禁设备数据 |
| | | * @param param |
| | |
| | | Constants.DEALING_HK_SYNCDEVICE =false; |
| | | } |
| | | } |
| | | @Override |
| | | // @Async |
| | | public String syncHkBroadcastDevice(Device param){ |
| | | if(Constants.DEALING_HK_SYNCDEVICE){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "同步任务正在执行哦,请稍后查看结果!") ; |
| | | } |
| | | 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(new QueryWrapper<Device>().lambda() |
| | | .eq(Device::getType,Constants.FOUR)); |
| | | List<FetchAudioDeviceInfoResponse> allHkList = getAllBroadcastDeviceList(); |
| | | /** |
| | | * 获取增删改数据集合 |
| | | */ |
| | | getBroadcastDeviceDataChangeList(allList,allHkList,addList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //逻辑删除 |
| | | for(Device d : deleteList){ |
| | | deviceMapper.updateById(d); |
| | | } |
| | | } |
| | | if(addList.size()>0){ |
| | | deviceMapper.insert(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; |
| | | } |
| | | } |
| | | |
| | | private void getBroadcastDataChangeList(List<Device> allList, List<FetchAudioChannelInfoResponse> allHkList, List<Device> addList, List<Device> editList, List<Device> deleteList, Date date) { |
| | | if(allHkList!=null && allHkList.size()>0){ |
| | |
| | | } |
| | | //判断获取删除的门禁设备,逻辑删除 |
| | | getDeleteBroadcastList(allList,allHkList,deleteList,date); |
| | | } |
| | | private void getBroadcastDeviceDataChangeList(List<Device> allList, List<FetchAudioDeviceInfoResponse> allHkList, List<Device> addList, List<Device> editList, List<Device> deleteList, Date date) { |
| | | if(allHkList!=null && allHkList.size()>0){ |
| | | //获取海康全部门禁组数据 |
| | | for(FetchAudioDeviceInfoResponse device : allHkList){ |
| | | Device model = getExistedBroadcastDevice(device,allList); |
| | | if(model !=null){ |
| | | //如果已存在,则更新数据 |
| | | model = initBroadcastDeviceDataByHkData(model,device,date); |
| | | editList.add(model); |
| | | }else{ |
| | | //如果不存在,则新增数据 |
| | | model = new Device(); |
| | | model = initBroadcastDeviceDataByHkData(model,device,date); |
| | | model.setIsEntrance(Constants.ZERO); |
| | | addList.add(model); |
| | | } |
| | | } |
| | | } |
| | | //判断获取删除的门禁设备,逻辑删除 |
| | | getDeleteBroadcastDeviceList(allList,allHkList,deleteList,date); |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | BaseListPageResponse<FetchAudioChannelInfoResponse> 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; |
| | | } |
| | | /** |
| | | * 获取全部广播点数据 |
| | | * @return |
| | | */ |
| | | public List<FetchAudioDeviceInfoResponse> getAllBroadcastDeviceList(){ |
| | | List<FetchAudioDeviceInfoResponse> allDoorList = new ArrayList<>(); |
| | | Date date = new Date(); |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | while (hasNext){ |
| | | //分页遍历循环查询所有门禁设备数据 |
| | | FetchAudioDeviceRequest param = new FetchAudioDeviceRequest(); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<BaseListPageResponse<FetchAudioDeviceInfoResponse>> response = HKService.fetchAudioDevice(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | BaseListPageResponse<FetchAudioDeviceInfoResponse> r = response.getData(); |
| | | curTotal += 100; |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | |
| | | model.setResourceType(device.getAudioChannelType()); |
| | | model.setStatus(device.getState()); |
| | | model.setRegionName(device.getRegionName()); |
| | | return model; |
| | | } |
| | | private Device initBroadcastDeviceDataByHkData(Device model, FetchAudioDeviceInfoResponse device, Date date) { |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setHkDate(date); |
| | | model.setHkId(device.getDeviceIndexCode()); |
| | | model.setName(device.getDeviceName()); |
| | | model.setHkStatus(Constants.ONE); |
| | | model.setType(Constants.THREE); |
| | | model.setChannelNo(device.getDeviceCode()); |
| | | model.setChannelInfo(device.getDeviceType()); |
| | | model.setResourceType(device.getDeviceType()); |
| | | model.setStatus(Constants.ZERO); |
| | | model.setRemark(device.getDesc()); |
| | | model.setRegionName(device.getRegionIndexCode()); |
| | | return model; |
| | | } |
| | | private Device initDoorDataByHkData(Device model, DoorsInfoResponse door, Date date, List<AcsDeviceInfoResponse> allHkList) { |
| | |
| | | } |
| | | return null; |
| | | } |
| | | private Device getExistedBroadcastDevice(FetchAudioDeviceInfoResponse device, List<Device> allList) { |
| | | if(allList.size()>0){ |
| | | for(Device r : allList){ |
| | | if(StringUtils.equals(r.getHkId(), device.getDeviceIndexCode())){ |
| | | //表示未删除 |
| | | return r; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | private Device getExistedDevice(AcsDeviceInfoResponse device, List<Device> allList) { |
| | | if(allList.size()>0){ |
| | | for(Device r : allList){ |
| | |
| | | private void getDeleteBroadcastList(List<Device> allList, List<FetchAudioChannelInfoResponse> allHkList,List<Device> deleteList ,Date date) { |
| | | if(allList!=null && allList.size()>0){ |
| | | for(Device device : allList){ |
| | | if(isDeletedBroadcast(device,allHkList)){ |
| | | device.setIsdeleted(Constants.ONE); |
| | | device.setEditDate(date); |
| | | deleteList.add(device); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | private void getDeleteBroadcastDeviceList(List<Device> allList, List<FetchAudioDeviceInfoResponse> allHkList,List<Device> deleteList ,Date date) { |
| | | if(allList!=null && allList.size()>0){ |
| | | for(Device device : allList){ |
| | | if(isDeletedBroadcastDevice(device,allHkList)){ |
| | | device.setIsdeleted(Constants.ONE); |
| | | device.setEditDate(date); |
| | |
| | | return true; |
| | | |
| | | } |
| | | private boolean isDeletedBroadcastDevice(Device device, List<FetchAudioChannelInfoResponse> allHkList) { |
| | | private boolean isDeletedBroadcast(Device device, List<FetchAudioChannelInfoResponse> allHkList) { |
| | | if(allHkList.size()>0){ |
| | | for(FetchAudioChannelInfoResponse r : allHkList){ |
| | | if(StringUtils.equals(device.getHkId(), r.getAudioChannelIndexCode())){ |
| | |
| | | return true; |
| | | |
| | | } |
| | | private boolean isDeletedBroadcastDevice(Device device, List<FetchAudioDeviceInfoResponse> allHkList) { |
| | | if(allHkList.size()>0){ |
| | | for(FetchAudioDeviceInfoResponse r : allHkList){ |
| | | if(StringUtils.equals(device.getHkId(), r.getDeviceIndexCode())){ |
| | | //表示未删除 |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | |
| | | } |
| | | private boolean isDeletedDevice(Device device, List<AcsDeviceInfoResponse> allHkList) { |
| | | if(allHkList.size()>0){ |
| | | for(AcsDeviceInfoResponse r : allHkList){ |