ParkingLotGeoForMarsCache.java 3.2 KB
package com.zteits.park.cache;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.clouds.common.cache.base.AbstractCache;
import com.clouds.common.cache.base.CacheType;
import com.clouds.common.cache.base.GeoCacheVO;
import com.clouds.common.constants.RedisKeyEnum;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.LonLatTypeEnum;
import com.zteits.clouds.api.dto.park.dto.ParkingLotGeoDTO;
import com.zteits.park.constant.ParkConstant;
import com.zteits.park.domain.ParkingLotGeo;
import com.zteits.park.domain.ParkingLotGeoExample;
import com.zteits.park.mapper.ParkingLotGeoMapper;
/**
 * 停车场经纬度信息缓存  火星经纬度<br>
 * 是要hash类型,hkey为停车场编号,value为经纬度信息
 * 
 * Copyright: Copyright (c) 2017  zteits
 * 
 * @ClassName: ParkingLotAndGeoInfoCache.java
 * @Description: 
 * @version: v1.0.0
 * @author: zhaowg
 * @date: 2017年6月6日   上午9:58:38 
 * Modification History: 
 * Date             Author          Version            Description
 *---------------------------------------------------------*
 * 2017年6月6日      zhaowg              v1.0.0               创建
 */
@Component
public class ParkingLotGeoForMarsCache extends AbstractCache<GeoCacheVO>{
	@Autowired
	private ParkingLotGeoMapper parkingLotGeoMapper;
	
	@Override
	protected List<GeoCacheVO> getData(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		ParkingLotGeoExample example = new ParkingLotGeoExample();
		example.createCriteria()
			.andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
			//只查询停车场坐标
			.andGeoTypeEqualTo(ParkConstant.ParkingLotGeo.GeoType.TYPE_PARKINGLOT)
			//只查询高德坐标
			.andLonLatTypeEqualTo(LonLatTypeEnum.LON_LAT_TYPE_3.value());
		List<ParkingLotGeo> parkingLotGeos = parkingLotGeoMapper.selectByExample(example );
		
		List<GeoCacheVO> cacheVOs = Lists.newArrayList();
		for (ParkingLotGeo tabParkinglot : parkingLotGeos) {
			ParkingLotGeoDTO parkingLotDTO = new ParkingLotGeoDTO();
			if(tabParkinglot.getLonId()==null || tabParkinglot.getLatId()==null){
				continue;
			}
			BeanUtils.copyProperties(tabParkinglot, parkingLotDTO);
			GeoCacheVO vo = new GeoCacheVO(tabParkinglot.getPlNo(), parkingLotDTO.getLonId().doubleValue(),parkingLotDTO.getLatId().doubleValue());;
			cacheVOs.add(vo);
		}
		return cacheVOs;
	}

	@Override
	protected long getTotalSize() {
		ParkingLotGeoExample example = new ParkingLotGeoExample();
		example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
		//只查询停车场坐标   
		.andGeoTypeEqualTo(ParkConstant.ParkingLotGeo.GeoType.TYPE_PARKINGLOT)
		//只查询高德坐标
		.andLonLatTypeEqualTo(LonLatTypeEnum.LON_LAT_TYPE_3.value());
		return parkingLotGeoMapper.countByExample(example);
	}

	@Override
	protected String getKey() {
		return RedisKeyEnum.PARK_PARKINGLOTGEO_PLNO_PARKLOTGEO_MARS.key();
	}
	
	@Override
	protected CacheType getCacheType() {
		return CacheType.GEO;
	}

}