7
7
import org .hsweb .web .service .config .ConfigService ;
8
8
import org .hsweb .web .service .impl .AbstractServiceImpl ;
9
9
import org .hsweb .web .service .resource .ResourcesService ;
10
+ import org .springframework .cache .annotation .CacheEvict ;
11
+ import org .springframework .cache .annotation .CachePut ;
10
12
import org .springframework .cache .annotation .Cacheable ;
13
+ import org .springframework .cache .annotation .Caching ;
11
14
import org .springframework .stereotype .Service ;
12
15
import org .springframework .transaction .annotation .Transactional ;
13
16
14
17
import javax .annotation .Resource ;
18
+ import javax .naming .OperationNotSupportedException ;
15
19
16
20
/**
17
21
* 资源服务类
@@ -32,6 +36,7 @@ protected ResourcesMapper getMapper() {
32
36
return this .resourcesMapper ;
33
37
}
34
38
39
+
35
40
@ Override
36
41
@ Cacheable (value = CACHE_KEY , key = "'id.'+#id" )
37
42
@ Transactional (readOnly = true )
@@ -48,24 +53,28 @@ public Resources selectByPk(String id) {
48
53
*/
49
54
@ Cacheable (value = CACHE_KEY , key = "'md5.'+#md5" )
50
55
@ Transactional (readOnly = true )
51
- public Resources selectByMd5 (String md5 ) {
56
+ public Resources selectByMd5 (String md5 ) {
52
57
return this .selectSingle (new QueryParam ().where ("md5" , md5 ));
53
58
}
54
59
55
60
@ Override
56
61
@ Transactional (rollbackFor = Throwable .class )
62
+ @ Caching (evict = {
63
+ @ CacheEvict (value = CACHE_KEY , key = "'id.'+#data.id" ),
64
+ @ CacheEvict (value = CACHE_KEY , key = "'md5.'+#data.md5" )
65
+ })
57
66
public String insert (Resources data ) {
58
- data .setId (this .newid (6 ));//6位随机id
67
+ data .setId (this .newId (6 ));//6位随机id
59
68
return super .insert (data );
60
69
}
61
70
62
- public String newid (int len ) {
71
+ public String newId (int len ) {
63
72
String id = RandomUtil .randomChar (len );
64
73
for (int i = 0 ; i < 10 ; i ++) {
65
74
if (this .selectByPk (id ) == null ) {
66
75
return id ;
67
76
}
68
77
} //如果10次存在重复则位数+1
69
- return newid (len + 1 );
78
+ return newId (len + 1 );
70
79
}
71
80
}
0 commit comments