28
28
* @Date 2022/5/26 19:40:55
29
29
* @Wechat zhuoda1024
30
30
31
- * @Copyright <a href="https://1024lab.net">1024创新实验室</a>
31
+ * @Copyright <a href="https://1024lab.net">1024创新实验室</a>
32
32
*/
33
33
@ Service
34
34
public class DictService {
@@ -39,10 +39,6 @@ public class DictService {
39
39
private DictValueDao dictValueDao ;
40
40
@ Resource
41
41
private DictCacheService dictCacheService ;
42
- /**
43
- * CODE锁
44
- */
45
- private static final Interner <String > CODE_POOL = Interners .newWeakInterner ();
46
42
47
43
48
44
/**
@@ -51,15 +47,15 @@ public class DictService {
51
47
* @param keyAddForm
52
48
* @return
53
49
*/
54
- public ResponseDTO <String > keyAdd (DictKeyAddForm keyAddForm ) {
55
- synchronized (CODE_POOL .intern (keyAddForm .getKeyCode ())) {
56
- DictKeyEntity dictKeyEntity = dictKeyDao .selectByCode (keyAddForm .getKeyCode (), false );
57
- if (dictKeyEntity != null ) {
58
- return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
59
- }
60
- dictKeyEntity = SmartBeanUtil .copy (keyAddForm , DictKeyEntity .class );
61
- dictKeyDao .insert (dictKeyEntity );
50
+ public synchronized ResponseDTO <String > keyAdd (DictKeyAddForm keyAddForm ) {
51
+ DictKeyEntity dictKeyEntity = dictKeyDao .selectByCode (keyAddForm .getKeyCode (), false );
52
+ if (dictKeyEntity != null ) {
53
+ return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
62
54
}
55
+ dictKeyEntity = SmartBeanUtil .copy (keyAddForm , DictKeyEntity .class );
56
+ dictKeyDao .insert (dictKeyEntity );
57
+ //刷新缓存
58
+ dictCacheService .cacheRefresh ();
63
59
return ResponseDTO .ok ();
64
60
}
65
61
@@ -69,15 +65,15 @@ public ResponseDTO<String> keyAdd(DictKeyAddForm keyAddForm) {
69
65
* @param valueAddForm
70
66
* @return
71
67
*/
72
- public ResponseDTO <String > valueAdd (DictValueAddForm valueAddForm ) {
73
- synchronized (CODE_POOL .intern (valueAddForm .getValueCode ())) {
74
- DictValueEntity dictValueEntity = dictValueDao .selectByCode (valueAddForm .getValueCode (), false );
75
- if (dictValueEntity != null ) {
76
- return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
77
- }
78
- dictValueEntity = SmartBeanUtil .copy (valueAddForm , DictValueEntity .class );
79
- dictValueDao .insert (dictValueEntity );
68
+ public synchronized ResponseDTO <String > valueAdd (DictValueAddForm valueAddForm ) {
69
+ DictValueEntity dictValueEntity = dictValueDao .selectByCode (valueAddForm .getValueCode (), false );
70
+ if (dictValueEntity != null ) {
71
+ return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
80
72
}
73
+ dictValueEntity = SmartBeanUtil .copy (valueAddForm , DictValueEntity .class );
74
+ dictValueDao .insert (dictValueEntity );
75
+ //刷新缓存
76
+ dictCacheService .cacheRefresh ();
81
77
return ResponseDTO .ok ();
82
78
}
83
79
@@ -87,15 +83,15 @@ public ResponseDTO<String> valueAdd(DictValueAddForm valueAddForm) {
87
83
* @param keyUpdateForm
88
84
* @return
89
85
*/
90
- public ResponseDTO <String > keyEdit (DictKeyUpdateForm keyUpdateForm ) {
91
- synchronized (CODE_POOL .intern (keyUpdateForm .getKeyCode ())) {
92
- DictKeyEntity dictKeyEntity = dictKeyDao .selectByCode (keyUpdateForm .getKeyCode (), false );
93
- if (dictKeyEntity != null && !dictKeyEntity .getDictKeyId ().equals (keyUpdateForm .getDictKeyId ())) {
94
- return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
95
- }
96
- DictKeyEntity dictKeyUpdateEntity = SmartBeanUtil .copy (keyUpdateForm , DictKeyEntity .class );
97
- dictKeyDao .updateById (dictKeyUpdateEntity );
86
+ public synchronized ResponseDTO <String > keyEdit (DictKeyUpdateForm keyUpdateForm ) {
87
+ DictKeyEntity dictKeyEntity = dictKeyDao .selectByCode (keyUpdateForm .getKeyCode (), false );
88
+ if (dictKeyEntity != null && !dictKeyEntity .getDictKeyId ().equals (keyUpdateForm .getDictKeyId ())) {
89
+ return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
98
90
}
91
+ DictKeyEntity dictKeyUpdateEntity = SmartBeanUtil .copy (keyUpdateForm , DictKeyEntity .class );
92
+ dictKeyDao .updateById (dictKeyUpdateEntity );
93
+ //刷新缓存
94
+ dictCacheService .cacheRefresh ();
99
95
return ResponseDTO .ok ();
100
96
}
101
97
@@ -105,19 +101,19 @@ public ResponseDTO<String> keyEdit(DictKeyUpdateForm keyUpdateForm) {
105
101
* @param valueUpdateForm
106
102
* @return
107
103
*/
108
- public ResponseDTO <String > valueEdit (DictValueUpdateForm valueUpdateForm ) {
104
+ public synchronized ResponseDTO <String > valueEdit (DictValueUpdateForm valueUpdateForm ) {
109
105
DictKeyEntity dictKeyEntity = dictKeyDao .selectById (valueUpdateForm .getDictKeyId ());
110
106
if (dictKeyEntity == null || dictKeyEntity .getDeletedFlag ()) {
111
107
return ResponseDTO .userErrorParam ("key不能存在" );
112
108
}
113
- synchronized (CODE_POOL .intern (valueUpdateForm .getValueCode ())) {
114
- DictValueEntity dictValueEntity = dictValueDao .selectByCode (valueUpdateForm .getValueCode (), false );
115
- if (dictValueEntity != null && !dictValueEntity .getDictValueId ().equals (valueUpdateForm .getDictValueId ())) {
116
- return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
117
- }
118
- DictValueEntity dictValueUpdateEntity = SmartBeanUtil .copy (valueUpdateForm , DictValueEntity .class );
119
- dictValueDao .updateById (dictValueUpdateEntity );
109
+ DictValueEntity dictValueEntity = dictValueDao .selectByCode (valueUpdateForm .getValueCode (), false );
110
+ if (dictValueEntity != null && !dictValueEntity .getDictValueId ().equals (valueUpdateForm .getDictValueId ())) {
111
+ return ResponseDTO .error (UserErrorCode .ALREADY_EXIST );
120
112
}
113
+ DictValueEntity dictValueUpdateEntity = SmartBeanUtil .copy (valueUpdateForm , DictValueEntity .class );
114
+ dictValueDao .updateById (dictValueUpdateEntity );
115
+ //刷新缓存
116
+ dictCacheService .cacheRefresh ();
121
117
return ResponseDTO .ok ();
122
118
}
123
119
@@ -127,11 +123,13 @@ public ResponseDTO<String> valueEdit(DictValueUpdateForm valueUpdateForm) {
127
123
* @param keyIdList
128
124
* @return
129
125
*/
130
- public ResponseDTO <String > keyDelete (List <Long > keyIdList ) {
126
+ public synchronized ResponseDTO <String > keyDelete (List <Long > keyIdList ) {
131
127
if (CollectionUtils .isEmpty (keyIdList )) {
132
128
return ResponseDTO .ok ();
133
129
}
134
130
dictKeyDao .updateDeletedFlagByIdList (keyIdList , true );
131
+ //刷新缓存
132
+ dictCacheService .cacheRefresh ();
135
133
return ResponseDTO .ok ();
136
134
}
137
135
@@ -141,11 +139,13 @@ public ResponseDTO<String> keyDelete(List<Long> keyIdList) {
141
139
* @param valueIdList
142
140
* @return
143
141
*/
144
- public ResponseDTO <String > valueDelete (List <Long > valueIdList ) {
142
+ public synchronized ResponseDTO <String > valueDelete (List <Long > valueIdList ) {
145
143
if (CollectionUtils .isEmpty (valueIdList )) {
146
144
return ResponseDTO .ok ();
147
145
}
148
146
dictValueDao .updateDeletedFlagByIdList (valueIdList , true );
147
+ //刷新缓存
148
+ dictCacheService .cacheRefresh ();
149
149
return ResponseDTO .ok ();
150
150
}
151
151
0 commit comments