package com.zteits.park.cache; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.apache.commons.lang3.StringUtils; import com.alibaba.fastjson.JSONObject; 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.park.domain.ParkFreeBerth; import com.zteits.park.domain.ParkFreeBerthExample; import com.zteits.park.mapper.ParkFreeBerthMapper; /** * 停车场空闲车位缓存 * * Copyright: Copyright (c) 2017 zteits * * @ClassName: ParkLotIdleBerths.java * @Description: * @version: v1.0.0 * @author: zhaowg * @date: 2017年5月24日 下午2:28:40 * Modification History: * Date Author Version Description *---------------------------------------------------------* * 2017年5月24日 zhaowg v1.0.0 创建 */ @Component public class ParkFreeBerthsCache extends AbstractCache{ @Autowired private ParkFreeBerthMapper parkFreeBerthMapper; @Override public List getData(int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); ParkFreeBerthExample record = new ParkFreeBerthExample(); record.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List parkFreeBerthList=parkFreeBerthMapper.selectByExample(record); if(CollectionUtils.isEmpty(parkFreeBerthList)){ return Lists.newArrayList(); } List result = Lists.newArrayList(); for (ParkFreeBerth parkFreeBerth : parkFreeBerthList) { //存放值 String hkey = parkFreeBerth.getPlNo(); if(StringUtils.isBlank(hkey)){ continue; } JSONObject json = new JSONObject(); json.put("plNo", hkey); json.put("freeBerths", parkFreeBerth.getFreeBerth()); json.put("realFreeBerths",parkFreeBerth.getRealFreeBerth()); HashCacheVO cacheVO = new HashCacheVO(hkey, json); result.add(cacheVO); } return result; } @Override public long getTotalSize() { ParkFreeBerthExample record = new ParkFreeBerthExample(); record.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); return parkFreeBerthMapper.countByExample(record); } @Override public String getKey() { return RedisKeyEnum.PARK_FREEBERTH_PLNO_FREEBERTH_MAP.key(); } }