ParkingLotExtendCache.java 2.44 KB
package com.zteits.park.cache;

import com.clouds.common.cache.base.AbstractCache;
import com.clouds.common.cache.base.HashCacheVO;
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.dto.park.dto.ParkingLotExtendDTO;
import com.zteits.park.domain.ParkingLotExtend;
import com.zteits.park.domain.ParkingLotExtendExample;
import com.zteits.park.mapper.ParkingLotExtendMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 停车场扩展信息缓存 <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 ParkingLotExtendCache extends AbstractCache<HashCacheVO>{
	@Autowired
	private ParkingLotExtendMapper parkingLotExtendMapper;
	
	@Override
	protected List<HashCacheVO> getData(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		ParkingLotExtendExample example = new ParkingLotExtendExample();
		example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		List<ParkingLotExtend> parkingLots = parkingLotExtendMapper.selectByExample(example );
		List<HashCacheVO> cacheVOs = Lists.newArrayList();
		
		for (ParkingLotExtend item : parkingLots) {
			ParkingLotExtendDTO parkingLotDTO = new ParkingLotExtendDTO();
			BeanUtils.copyProperties(item, parkingLotDTO);
			HashCacheVO vo = new HashCacheVO(item.getPlNo(), parkingLotDTO);
			cacheVOs.add(vo);
		}
		return cacheVOs;
	}

	@Override
	protected long getTotalSize() {
		ParkingLotExtendExample example = new ParkingLotExtendExample();
		example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		return parkingLotExtendMapper.countByExample(example );
	}

	@Override
	protected String getKey() {
		return RedisKeyEnum.PARK_PARKINGLOTEXTEND_PLNO_PARKLOTEXTEND.key();
	}

}