| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.service.business.impl.hksync; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | 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.*; |
| | | 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; |
| | | import com.doumee.dao.business.PlatformDeviceMapper; |
| | | import com.doumee.dao.business.PlatformJobMapper; |
| | | import com.doumee.dao.business.PlatformMapper; |
| | | import com.doumee.dao.business.model.Device; |
| | | import com.doumee.dao.business.model.Platform; |
| | | import com.doumee.dao.business.model.PlatformDevice; |
| | | import com.doumee.dao.business.model.PlatformJob; |
| | | import com.github.xiaoymin.knife4j.core.util.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 设å¤ä¿¡æ¯è¡¨Serviceå®ç° |
| | | * @author æ±è¹è¹ |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | public class HkSyncPlatformsServiceImpl extends HkSyncBaseServiceImpl { |
| | | @Autowired |
| | | private PlatformMapper platformMapper; |
| | | @Autowired |
| | | private PlatformJobMapper platformJobMapper; |
| | | @Autowired |
| | | private PlatformDeviceMapper platformDeviceMapper; |
| | | @Autowired |
| | | @Lazy |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | |
| | | /** |
| | | * åæ¥æµ·åº·æå°æ°æ® |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public String syncPlatforms(PlatformsListRequest param){ |
| | | if(Constants.DEALING_HK_SYNCPLATFORM){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "忥任塿£å¨æ§è¡å¦ï¼è¯·ç¨åæ¥çç»æï¼") ; |
| | | } |
| | | Constants.DEALING_HK_SYNCPLATFORM =true; |
| | | try { |
| | | List<Platform> deleteList = new ArrayList<>(); |
| | | List<Platform> addList = new ArrayList<>(); |
| | | List<Platform> editList = new ArrayList<>(); |
| | | List<PlatformDevice> deviceList = new ArrayList<>(); |
| | | Date date = new Date(); |
| | | //æ¥è¯¢å
¨é¨é¨ç¦è®¾å¤æ°æ® |
| | | List<Platform> allList = platformMapper.selectList(new QueryWrapper<Platform>().lambda().eq(Platform::getIsdeleted,Constants.ZERO)); |
| | | List<PlatformListInfoResponse> allHkList = getAllHkList(param); |
| | | /** |
| | | * è·åå¢å æ¹æ°æ®éå |
| | | */ |
| | | getDataChangeList(allList,allHkList,addList,deviceList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //é»è¾å é¤ |
| | | List<Integer> platIds = new ArrayList<>(); |
| | | for(Platform d : deleteList){ |
| | | platformMapper.updateById(d); |
| | | platIds.add(d.getId()); |
| | | } |
| | | //æ´æ°å é¤çæå°ä¿¡æ¯å æ£å¨æ§è¡çä½ä¸ç¶æä¸ºãå¾
ç¾å°ãç¶æ |
| | | platformJobMapper.update(null, new UpdateWrapper<PlatformJob>().lambda() |
| | | .eq(PlatformJob::getIsdeleted,Constants.ZERO) |
| | | .notIn(PlatformJob::getStatus,Constants.PlatformJobStatus.WART_SIGN_IN.getKey() |
| | | ,Constants.PlatformJobStatus.WAIT_CONFIRM.getKey() |
| | | ,Constants.PlatformJobStatus.DONE.getKey() |
| | | ,Constants.PlatformJobStatus.LEAVED.getKey() |
| | | ,Constants.PlatformJobStatus.CANCEL.getKey() ) |
| | | .in(PlatformJob::getPlatformId,platIds) |
| | | .set(PlatformJob::getPlatformId,null) |
| | | .set(PlatformJob::getPlatforms,null) |
| | | .set(PlatformJob::getStatus,Constants.PlatformJobStatus.WART_SIGN_IN.getKey()) |
| | | ); |
| | | } |
| | | if(deviceList.size()>0){ |
| | | platformDeviceMapper.insert(deviceList); |
| | | } |
| | | if(editList.size()>0){ |
| | | for(Platform d : editList){ |
| | | platformMapper.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_SYNCPLATFORM =false; |
| | | } |
| | | } |
| | | @Override |
| | | // @Async |
| | | public String getPlatformStatus(PlatformStatusRequest param){ |
| | | if(Constants.DEALING_HK_SYNCPLATFORM_STATUS){ |
| | | return null; |
| | | } |
| | | Constants.DEALING_HK_SYNCPLATFORM_STATUS =true; |
| | | try { |
| | | List<Device> editList = new ArrayList<>(); |
| | | Date date = new Date(); |
| | | //æ¥è¯¢å
¨é¨é¨ç¦è®¾å¤æ°æ® |
| | | List<PlatformStatusInfoResponse> allHkList = getAllHKStatusList(param); |
| | | |
| | | if(allHkList.size()>0){ |
| | | //æ´æ°ç¶æ (æå°ç¶æ 0-æ 车 1-æè½¦ 2-è¶
æ¶åé 3-é误åé ) |
| | | for(PlatformStatusInfoResponse d : allHkList){ |
| | | platformMapper.update(null,new UpdateWrapper<Platform>().lambda() |
| | | .set(Platform::getPlatformStatus,d.getStatus()) |
| | | .set(Platform::getEditDate,date) |
| | | .eq(Platform::getHkId,d.getPlatformId())); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "åæ¥è®¾å¤ç¶æå¤±è´¥ï¼"); |
| | | }finally { |
| | | Constants.DEALING_HK_SYNCPLATFORM_STATUS =false; |
| | | } |
| | | return "忥æå"; |
| | | } |
| | | |
| | | private List<PlatformListInfoResponse> getAllHkList(PlatformsListRequest param) { |
| | | BaseResponse<BaseListPageResponse<PlatformListInfoResponse>> response = HKService.platformsList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE) || response.getData() ==null){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æµ·åº·åæ¥æ°æ®å¤±è´¥~"); |
| | | } |
| | | |
| | | return response.getData().getList(); |
| | | } |
| | | |
| | | public List<PlatformStatusInfoResponse> getAllHKStatusList(PlatformStatusRequest param){ |
| | | //å页éåå¾ªç¯æ¥è¯¢ææé¨ç¦è®¾å¤æ°æ® |
| | | BaseResponse<BaseListPageResponse<PlatformStatusInfoResponse>> response = HKService.platformStatus(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE) || response.getData() ==null){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æµ·åº·åæ¥æ°æ®å¤±è´¥~"); |
| | | } |
| | | return response.getData().getList(); |
| | | |
| | | } |
| | | |
| | | |
| | | 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<Platform> allList, |
| | | List<PlatformListInfoResponse> allHkList, |
| | | List<Platform> addList , |
| | | List<PlatformDevice> deviceList, |
| | | List<Platform> editList, |
| | | List<Platform> deleteList, Date date) { |
| | | if(allHkList!=null && allHkList.size()>0){ |
| | | //è·å海康å
¨é¨é¨ç¦ç»æ°æ® |
| | | for(PlatformListInfoResponse device : allHkList){ |
| | | Platform model = getExistedDevice(device,allList); |
| | | if(model !=null){ |
| | | //妿已åå¨ï¼åæ´æ°æ°æ® |
| | | model = initDataByHkData(model,device,date); |
| | | editList.add(model); |
| | | //æ¸
ç©ºçæ§ç¹æ°æ® |
| | | platformDeviceMapper.delete(new UpdateWrapper<PlatformDevice>().lambda() |
| | | .eq(PlatformDevice::getPlatformId,model.getId()) |
| | | .eq(PlatformDevice::getType,Constants.ONE) |
| | | ); |
| | | deviceList.addAll(getCameraList(device.getCameras(),model)); |
| | | }else{ |
| | | //妿ä¸åå¨ï¼åæ°å¢æ°æ® |
| | | model = new Platform(); |
| | | model = initDataByHkData(model,device,date); |
| | | platformMapper.insert(model); |
| | | addList.add(model); |
| | | deviceList.addAll(getCameraList(device.getCameras(),model)); |
| | | } |
| | | } |
| | | } |
| | | //夿è·åå é¤çé¨ç¦è®¾å¤ï¼é»è¾å é¤ |
| | | getDeleteList(allList,allHkList,deleteList,date); |
| | | } |
| | | |
| | | private List<PlatformDevice> getCameraList(List<PlatformCameraInfoResponse> cameras, Platform model) { |
| | | List<PlatformDevice> list = new ArrayList<>(); |
| | | if(cameras!=null && cameras.size()>0){ |
| | | for(PlatformCameraInfoResponse param :cameras){ |
| | | PlatformDevice d = new PlatformDevice(); |
| | | d.setCreateDate(model.getCreateDate()); |
| | | d.setPlatformId(model.getId()); |
| | | d.setIsdeleted(Constants.ZERO); |
| | | d.setDeviceId(param.getCameraId()); |
| | | d.setName(param.getCameraName()); |
| | | d.setType(Constants.ONE); |
| | | list.add(d); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * åå§å海康å
¥åºæ°æ® |
| | | * @param model |
| | | * @param device |
| | | * @param date |
| | | * @return |
| | | */ |
| | | private Platform initDataByHkData(Platform model, PlatformListInfoResponse device,Date date ) { |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setCreateDate(date); |
| | | model.setHkDate(date); |
| | | model.setHkId(device.getPlatformId()); |
| | | model.setCreateDate(DateUtil.getISO8601DateByStr(device.getCreateTime())); |
| | | model.setName(device.getPlatformName()); |
| | | model.setCompanys(device.getCompanyNames()); |
| | | model.setAngle(device.getAngle()); |
| | | model.setXpos(device.getX()); |
| | | model.setYpos(device.getY()); |
| | | model.setWidth(device.getWidth()); |
| | | model.setHeight(device.getHeight()); |
| | | model.setRemark(JSONObject.toJSONString(device)); |
| | | return model; |
| | | } |
| | | |
| | | private Platform getExistedDevice(PlatformListInfoResponse device, List<Platform> allList) { |
| | | if(allList.size()>0){ |
| | | for(Platform r : allList){ |
| | | if(StringUtils.equals(r.getHkId(), device.getPlatformId())){ |
| | | //表示æªå é¤ |
| | | return r; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private void getDeleteList(List<Platform> allList, List<PlatformListInfoResponse> allHkList,List<Platform> deleteList ,Date date) { |
| | | if(allList!=null && allList.size()>0){ |
| | | for(Platform device : allList){ |
| | | if(isDeletedData(device,allHkList)){ |
| | | device.setIsdeleted(Constants.ONE); |
| | | device.setEditDate(date); |
| | | deleteList.add(device); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | private boolean isDeletedData(Platform device, List<PlatformListInfoResponse> allHkList) { |
| | | if(allHkList.size()>0){ |
| | | for(PlatformListInfoResponse r : allHkList){ |
| | | if(StringUtils.equals(device.getHkId(), r.getPlatformId())){ |
| | | //表示æªå é¤ |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | public List<Integer> getMenuConfig(String userId){ |
| | | try { |
| | | List<Integer> resultList= new ArrayList<>(); |
| | | Map<String,String> param = new HashMap<>(); |
| | | param.put("userId",userId); |
| | | BaseResponse<MenuDataResponse> result = HKService.getMenuConfig(param); |
| | | if(result !=null){ |
| | | if(!StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),result.getMsg()); |
| | | } |
| | | MenuDataResponse menuDataResponse = result.getData(); |
| | | List<String> list = menuDataResponse.getList(); |
| | | if(CollectionUtils.isNotEmpty(list)){ |
| | | //åå«å¤æ4个èå |
| | | if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.afzx)).collect(Collectors.toList()).size()>Constants.ZERO){ |
| | | resultList.add(0); |
| | | } |
| | | if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.xkzx)).collect(Collectors.toList()).size()>Constants.ZERO){ |
| | | resultList.add(1); |
| | | } |
| | | if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.ngzx)).collect(Collectors.toList()).size()>Constants.ZERO){ |
| | | resultList.add(2); |
| | | } |
| | | if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.jsc)).collect(Collectors.toList()).size()>Constants.ZERO){ |
| | | resultList.add(3); |
| | | } |
| | | if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.kqgzt)).collect(Collectors.toList()).size()>Constants.ZERO){ |
| | | resultList.add(4); |
| | | } |
| | | } |
| | | return resultList; |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对ä¸èµ·ï¼è·åèå失败ï¼"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对ä¸èµ·ï¼è·åèå失败ï¼è¯·ç¨åéè¯ï¼"); |
| | | } |
| | | |
| | | } |