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.ParkingLotDTO; import com.zteits.clouds.api.dto.park.dto.ParkingLotDoorDTO; import com.zteits.park.domain.ParkingLot; import com.zteits.park.domain.ParkingLotDoor; import com.zteits.park.domain.ParkingLotDoorExample; import com.zteits.park.domain.ParkingLotExample; import com.zteits.park.mapper.ParkingLotDoorMapper; import com.zteits.park.mapper.ParkingLotMapper; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; /** * 停车场信息缓存
* 是要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 ParkingLotDoorCache extends AbstractCache{ @Autowired private ParkingLotDoorMapper parkingLotDoorMapper; @Override protected List getData(int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); ParkingLotDoorExample example = new ParkingLotDoorExample(); example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List parkingLotDoors = parkingLotDoorMapper.selectByExample(example ); List cacheVOs = Lists.newArrayList(); for (ParkingLotDoor parkingLotDoor : parkingLotDoors) { ParkingLotDoorDTO parkingLotDoorDTO = new ParkingLotDoorDTO(); BeanUtils.copyProperties(parkingLotDoor,parkingLotDoorDTO); HashCacheVO vo = new HashCacheVO(parkingLotDoor.getPlDoorId(), parkingLotDoorDTO); cacheVOs.add(vo); } return cacheVOs; } @Override protected long getTotalSize() { ParkingLotDoorExample example = new ParkingLotDoorExample(); example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); return parkingLotDoorMapper.countByExample(example ); } @Override protected String getKey() { return RedisKeyEnum.PARK_PARKINGLOTDOOR_PLDOORID_PARKLODOORTINFO.key(); } }