-
Notifications
You must be signed in to change notification settings - Fork 2
/
UserAdvancedService.java
74 lines (66 loc) · 2.33 KB
/
UserAdvancedService.java
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
package com.dolplay.nutzcache.assets.service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.service.IdEntityService;
import com.dolplay.nutzcache.annotation.Cache;
import com.dolplay.nutzcache.annotation.CacheKeySuffix;
import com.dolplay.nutzcache.assets.CacheKeyPrefix;
import com.dolplay.nutzcache.assets.domain.User;
import com.dolplay.nutzcache.interceptor.InterceptorName;
import com.dolplay.nutzcache.type.CacheType;
@IocBean(args = { "refer:dao" })
public class UserAdvancedService extends IdEntityService<User> {
public UserAdvancedService(Dao dao) {
super(dao);
}
/**
* 根据指定性别查询用户id列表
* 缓存类型为有序集
* @param gender
* @return
*/
@Aop(InterceptorName.ADVANCEDCACHEINTERCEPTOR)
@Cache(cacheKeyPrefix = CacheKeyPrefix.TEST_CACHE_ALLUSERS_IDLIST, cacheType = CacheType.zset)
public List<Integer> listIdByGender(@CacheKeySuffix String gender) {
List<User> userList = query(Cnd.where("gender", "=", gender).desc("birthday"), null);
List<Integer> idList = new ArrayList<Integer>();
for (User u : userList) {
idList.add(u.getId().intValue());
}
return idList;
}
/**
* 根据指定性别查询用户列表
* 缓存类型为有序集
* @param gender
* @return
*/
@Aop(InterceptorName.ADVANCEDCACHEINTERCEPTOR)
@Cache(cacheKeyPrefix = CacheKeyPrefix.TEST_CACHE_ALLUSERS_LIST, cacheType = CacheType.zset)
public List<User> listByGender(@CacheKeySuffix String gender) {
List<User> userList = query(Cnd.where("gender", "=", gender).desc("birthday"), null);
return userList;
}
/**
* 查询08年以后出生的用户id列表
* @return
* @throws ParseException
*/
@Aop(InterceptorName.ADVANCEDCACHEINTERCEPTOR)
@Cache(cacheKeyPrefix = CacheKeyPrefix.TEST_CACHE_NEWUSERS_NAMELIST, cacheType = CacheType.zset, reverse = true)
public List<String> listNewUsers() throws ParseException {
List<User> userList = query(Cnd.where("birthday", ">", new SimpleDateFormat("yyyy-MM-dd").parse("2008-01-01"))
.desc("id"), null);
List<String> idList = new ArrayList<String>();
for (User u : userList) {
idList.add(String.valueOf(u.getName()));
}
return idList;
}
}