20
20
import com .alibaba .excel .read .builder .ExcelReaderBuilder ;
21
21
import com .baomidou .mybatisplus .core .conditions .query .QueryWrapper ;
22
22
import com .baomidou .mybatisplus .core .metadata .IPage ;
23
+ import com .baomidou .mybatisplus .core .toolkit .Wrappers ;
23
24
import com .github .xiaoymin .knife4j .annotations .ApiOperationSupport ;
24
25
import io .swagger .v3 .oas .annotations .Operation ;
25
26
import io .swagger .v3 .oas .annotations .Parameter ;
30
31
import jakarta .validation .Valid ;
31
32
import lombok .AllArgsConstructor ;
32
33
import lombok .SneakyThrows ;
34
+ import org .springblade .common .cache .CacheNames ;
33
35
import org .springblade .core .mp .support .Condition ;
34
36
import org .springblade .core .mp .support .Query ;
37
+ import org .springblade .core .redis .cache .BladeRedis ;
35
38
import org .springblade .core .secure .BladeUser ;
36
39
import org .springblade .core .secure .annotation .PreAuth ;
37
40
import org .springblade .core .secure .utils .SecureUtil ;
38
41
import org .springblade .core .tool .api .R ;
39
42
import org .springblade .core .tool .constant .BladeConstant ;
40
43
import org .springblade .core .tool .constant .RoleConstant ;
41
44
import org .springblade .core .tool .utils .Func ;
45
+ import org .springblade .core .tool .utils .StringUtil ;
42
46
import org .springblade .system .user .entity .User ;
43
47
import org .springblade .system .excel .UserExcel ;
44
48
import org .springblade .system .excel .UserImportListener ;
69
73
public class UserController {
70
74
71
75
private IUserService userService ;
76
+ private BladeRedis bladeRedis ;
72
77
73
78
/**
74
79
* 查询单条
@@ -85,7 +90,7 @@ public R<UserVO> detail(User user) {
85
90
/**
86
91
* 查询单条
87
92
*/
88
- @ ApiOperationSupport (order =2 )
93
+ @ ApiOperationSupport (order = 2 )
89
94
@ Operation (summary = "查看详情" , description = "传入id" )
90
95
@ GetMapping ("/info" )
91
96
public R <UserVO > info (BladeUser user ) {
@@ -212,7 +217,7 @@ public R<List<UserVO>> userList(User user) {
212
217
@ Operation (summary = "导入用户" , description = "传入excel" )
213
218
public R importUser (MultipartFile file , Integer isCovered ) {
214
219
String filename = file .getOriginalFilename ();
215
- if (StringUtils . isEmpty (filename )) {
220
+ if (StringUtil . isBlank (filename )) {
216
221
throw new RuntimeException ("请上传文件!" );
217
222
}
218
223
if ((!StringUtils .endsWithIgnoreCase (filename , ".xls" ) && !StringUtils .endsWithIgnoreCase (filename , ".xlsx" ))) {
@@ -240,14 +245,14 @@ public R importUser(MultipartFile file, Integer isCovered) {
240
245
@ PreAuth (RoleConstant .HAS_ROLE_ADMIN )
241
246
public void exportUser (@ Parameter (hidden = true ) @ RequestParam Map <String , Object > user , BladeUser bladeUser , HttpServletResponse response ) {
242
247
QueryWrapper <User > queryWrapper = Condition .getQueryWrapper (user , User .class );
243
- if (!SecureUtil .isAdministrator ()){
248
+ if (!SecureUtil .isAdministrator ()) {
244
249
queryWrapper .lambda ().eq (User ::getTenantId , bladeUser .getTenantId ());
245
250
}
246
251
queryWrapper .lambda ().eq (User ::getIsDeleted , BladeConstant .DB_NOT_DELETED );
247
252
List <UserExcel > list = userService .exportUser (queryWrapper );
248
253
response .setContentType ("application/vnd.ms-excel" );
249
254
response .setCharacterEncoding (StandardCharsets .UTF_8 .name ());
250
- String fileName = URLEncoder .encode ("用户数据导出" , StandardCharsets .UTF_8 . name () );
255
+ String fileName = URLEncoder .encode ("用户数据导出" , StandardCharsets .UTF_8 );
251
256
response .setHeader ("Content-disposition" , "attachment;filename=" + fileName + ".xlsx" );
252
257
EasyExcel .write (response .getOutputStream (), UserExcel .class ).sheet ("用户数据表" ).doWrite (list );
253
258
}
@@ -263,7 +268,7 @@ public void exportUser(HttpServletResponse response) {
263
268
List <UserExcel > list = new ArrayList <>();
264
269
response .setContentType ("application/vnd.ms-excel" );
265
270
response .setCharacterEncoding (StandardCharsets .UTF_8 .name ());
266
- String fileName = URLEncoder .encode ("用户数据模板" , StandardCharsets .UTF_8 . name () );
271
+ String fileName = URLEncoder .encode ("用户数据模板" , StandardCharsets .UTF_8 );
267
272
response .setHeader ("Content-disposition" , "attachment;filename=" + fileName + ".xlsx" );
268
273
EasyExcel .write (response .getOutputStream (), UserExcel .class ).sheet ("用户数据表" ).doWrite (list );
269
274
}
@@ -279,4 +284,20 @@ public R registerGuest(User user, Long oauthId) {
279
284
}
280
285
281
286
287
+ /**
288
+ * 用户解锁
289
+ */
290
+ @ PostMapping ("/unlock" )
291
+ @ ApiOperationSupport (order = 16 )
292
+ @ Operation (summary = "账号解锁" )
293
+ @ PreAuth (RoleConstant .HAS_ROLE_ADMIN )
294
+ public R unlock (String userIds ) {
295
+ if (StringUtil .isBlank (userIds )) {
296
+ return R .fail ("请至少选择一个用户" );
297
+ }
298
+ List <User > userList = userService .list (Wrappers .<User >lambdaQuery ().in (User ::getId , Func .toLongList (userIds )));
299
+ userList .forEach (user -> bladeRedis .del (CacheNames .tenantKey (user .getTenantId (), CacheNames .USER_FAIL_KEY , user .getAccount ())));
300
+ return R .success ("操作成功" );
301
+ }
302
+
282
303
}
0 commit comments