ParkFreeBerthsCache.java
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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<HashCacheVO>{
@Autowired
private ParkFreeBerthMapper parkFreeBerthMapper;
@Override
public List<HashCacheVO> getData(int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
ParkFreeBerthExample record = new ParkFreeBerthExample();
record.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
List<ParkFreeBerth> parkFreeBerthList=parkFreeBerthMapper.selectByExample(record);
if(CollectionUtils.isEmpty(parkFreeBerthList)){
return Lists.newArrayList();
}
List<HashCacheVO> 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();
}
}