| ÎļþÃû´Ó server/dmvisit_service/src/main/java/com/doumee/service/business/impl/HkSyncServiceImpl.java ÐÞ¸Ä |
| | |
| | | package com.doumee.service.business.impl; |
| | | package com.doumee.service.business.impl.hksync; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.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.service.HKService; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.DeviceMapper; |
| | | import com.doumee.dao.business.ParksMapper; |
| | | import com.doumee.dao.business.model.Device; |
| | | import com.doumee.service.business.DeviceService; |
| | | import com.doumee.service.business.HkSyncService; |
| | | 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; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | public class HkSyncServiceImpl implements HkSyncService { |
| | | public class HkSyncDeviceServiceImpl extends HkSyncBaseServiceImpl { |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @Autowired |
| | | private HKService hkService; |
| | | /** |
| | | * åæ¥æµ·åº·é¨ç¦è®¾å¤æ°æ® |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @Override |
| | | // @Async |
| | | public String syncHkDevices(AcsDeviceListRequest param){ |
| | |
| | | List<Device> allList = deviceMapper.selectList(null); |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | while (hasNext){ |
| | | //å页éåå¾ªç¯æ¥è¯¢ææé¨ç¦è®¾å¤æ°æ® |
| | | param = new AcsDeviceListRequest(); |
| | | param.setPageNo(1); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(10000); |
| | | BaseResponse<AcsDeviceListResponse> response = hkService.acsDeviceList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | | } |
| | | List<AcsDeviceInfoResponse> tlist = r.getList(); |
| | | if(r.getList() == null || r.getList().size()==0){ |
| | | hasNext =false; |
| | | }else{ |
| | | allHkList.addAll(r.getList()); |
| | | } |
| | | curPage++; |
| | | } |
| | | //夿è·åå é¤çé¨ç¦è®¾å¤ï¼é»è¾å é¤ |
| | | getAddAndEditList(allList,allHkList,addList,editList,date); |
| | | getDeleteList(allList,allHkList,deleteList,date); |
| | | /** |
| | | * è·åå¢å æ¹æ°æ®éå |
| | | */ |
| | | getDataChangeList(allList,allHkList,addList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //é»è¾å é¤ |
| | | for(Device d : deleteList){ |
| | |
| | | deviceMapper.updateById(d); |
| | | } |
| | | } |
| | | return "忥é¨ç¦æ°æ®ï¼æ°å¢ã"+addList.size()+"ãæ¡ï¼æ´æ°ã"+editList.size()+"ãæ¡ï¼å é¤ã"+deleteList.size()+"ãæ¡"; |
| | | return "åæ¥æ°æ®ï¼æ°å¢ã"+addList.size()+"ãæ¡ï¼æ´æ°ã"+editList.size()+"ãæ¡ï¼å é¤ã"+deleteList.size()+"ãæ¡"; |
| | | } |
| | | |
| | | private void getAddAndEditList(List<Device> allList, List<AcsDeviceInfoResponse> allHkList, List<Device> addList, List<Device> editList, Date date) { |
| | | 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); |
| | | if(model !=null){ |
| | | //妿已åå¨ï¼åæ´æ°æ°æ® |
| | | model = initDeviceByHkData(model,device,date); |
| | | model = initDataByHkData(model,device,date); |
| | | editList.add(model); |
| | | }else{ |
| | | //妿ä¸åå¨ï¼åæ°å¢æ°æ® |
| | | model = new Device(); |
| | | model = initDeviceByHkData(model,device,date); |
| | | model = initDataByHkData(model,device,date); |
| | | addList.add(model); |
| | | } |
| | | } |
| | | } |
| | | //夿è·åå é¤çé¨ç¦è®¾å¤ï¼é»è¾å é¤ |
| | | getDeleteList(allList,allHkList,deleteList,date); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param date |
| | | * @return |
| | | */ |
| | | private Device initDeviceByHkData(Device model, AcsDeviceInfoResponse device,Date date) { |
| | | private Device initDataByHkData(Device model, AcsDeviceInfoResponse device,Date date) { |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setIp(device.getIp()); |
| | | model.setHkDate(date); |