| | |
| | | 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.config.DataSyncConfig; |
| | | 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.request.event.visit.EventVisitInfoRequest; |
| | | 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.DESUtil; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.ImageBase64Util; |
| | | import com.doumee.core.utils.*; |
| | | import com.doumee.core.wx.wxPlat.WxPlatNotice; |
| | | import com.doumee.dao.business.DeviceRoleMapper; |
| | | import com.doumee.dao.business.RetentionMapper; |
| | | import com.doumee.dao.business.VisitEventMapper; |
| | | import com.doumee.dao.business.join.VisitsJoinMapper; |
| | | import com.doumee.dao.business.model.DeviceRole; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Retention; |
| | | import com.doumee.dao.business.model.Visits; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 海康访客业务Service实现 |
| | |
| | | @Service |
| | | @Slf4j |
| | | public class HkSyncVisitServiceImpl extends HkSyncBaseServiceImpl { |
| | | |
| | | @Autowired |
| | | private DataSyncConfig dataSyncConfig; |
| | | @Autowired |
| | | private VisitsJoinMapper visitsMapper; |
| | | @Autowired |
| | | private VisitEventMapper visitEventMapper; |
| | | @Autowired |
| | | private RetentionMapper retentionMapper; |
| | | @Autowired |
| | |
| | | List<Visits> list = visitsMapper.selectJoinList(Visits.class,queryWrapper); |
| | | return list; |
| | | } |
| | | @Override |
| | | @Transactional |
| | | public void syncParkRecords(Date date){ |
| | | try { |
| | | if( Constants.formatIntegerNum(dataSyncConfig.getVisitorDataOrigin()) != DataSyncConfig.origin.hk){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,当前不支持海康数据同步操作~"); |
| | | } |
| | | AppointmentEventListRequest param = new AppointmentEventListRequest(); |
| | | //(全量同步) |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | //查询今天的 |
| | | Date start = Utils.Date.getStart(date); |
| | | Date end = new Date(); |
| | | if(DateUtil.daysBetweenDates(end,start) >1){ |
| | | end = Utils.Date.getEnd(date); |
| | | } |
| | | param.setEventTimeBegin(DateUtil.getISO8601Timestamp2( start)); |
| | | param.setEventTimeBegin(DateUtil.getISO8601Timestamp2( end)); |
| | | |
| | | List<VisitEvent> allHkList = new ArrayList<>(); |
| | | while (hasNext){ |
| | | //分页遍历循环查询所有门禁设备数据 |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<BaseListPageResponse<AppointmentEventInfoResponse>> response = HKService.appointmentEventQuery(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE) ){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | if(response.getData() == null || response.getData().getTotal() ==0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未同步到任何信息!"); |
| | | } |
| | | BaseListPageResponse<AppointmentEventInfoResponse> r = response.getData(); |
| | | curTotal += 100; |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | | } |
| | | if(r.getList() == null || r.getList().size()==0){ |
| | | hasNext =false; |
| | | }else{ |
| | | allHkList.addAll(getNewCarEventModelBYList(r.getList())); |
| | | } |
| | | curPage++; |
| | | } |
| | | if(allHkList .size() == 0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未同步到任何信息!"); |
| | | } |
| | | //清空原有当天的数据 |
| | | visitEventMapper.delete(new UpdateWrapper<VisitEvent>().lambda() |
| | | .ge(VisitEvent::getCreateDate,start) |
| | | .le(VisitEvent::getCreateDate,end)); |
| | | if(allHkList.size()>0){ |
| | | int sublistSize = 500; |
| | | |
| | | int startIndex = 0; |
| | | int endIndex = sublistSize; |
| | | |
| | | while (startIndex < allHkList.size()) { |
| | | if (endIndex > allHkList.size()) { |
| | | endIndex = allHkList.size(); |
| | | } |
| | | |
| | | List<VisitEvent> sublist = allHkList.subList(startIndex, endIndex); |
| | | if(sublist.size()>0){ |
| | | visitEventMapper.insertBatchSomeColumn(sublist);//插入新数据 |
| | | } |
| | | startIndex = endIndex; |
| | | endIndex += sublistSize; |
| | | } |
| | | } |
| | | |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | private List<VisitEvent> getNewCarEventModelBYList(List<AppointmentEventInfoResponse> list ) { |
| | | List<VisitEvent> newList = new ArrayList<>(); |
| | | if(list == null || list.size()==0){ |
| | | return newList; |
| | | } |
| | | for(AppointmentEventInfoResponse model :list){ |
| | | VisitEvent c = new VisitEvent(); |
| | | c.setHappenTime(model.getEventTime()); |
| | | c.setCreateDate(DateUtil.getISO8601DateByStr2(model.getEventTime())); |
| | | c.setPersonName(model.getVisitorName()); |
| | | c.setSex(Integer.parseInt(model.getVisitorSex())); |
| | | c.setCarNo(model.getCarNumber()); |
| | | c.setIdNo(model.getIdentityNum()); |
| | | c.setIdType(Integer.parseInt(model.getIdentityId())); |
| | | c.setPhone(model.getPhoneNum()); |
| | | c.setRemark(model.getCardNum()); |
| | | c.setPhotoUrl(model.getIdentityPhotoUri()); |
| | | c.setVisitorId(model.getVisitorId()); |
| | | c.setIsdeleted(Constants.ZERO); |
| | | c.setEventTypeName(model.getEventName()); |
| | | |
| | | newList.add(c); |
| | | } |
| | | return newList; |
| | | } |
| | | |
| | | } |