Browse Source

用户管理模块用户删除问题

ly 4 months ago
parent
commit
82bd6d9590

+ 7 - 5
src/main/java/com/liang/controller/SysUserInfoController.java

@@ -290,13 +290,15 @@ public class SysUserInfoController extends BaseController {
290 290
             logger.info("batchDelete -- idList:{}", userIdList);
291 291
         }
292 292
         int a = 0;
293
+        Map<Object,Object> map =new HashMap<>();
293 294
         // 批量判断 问题
294 295
         // 判断删除人员是否有部门信息
295
-        if (userIdList.size() > 1){
296
+        if (userIdList.size() > 0){
296 297
             for (int i =0 ; i<userIdList.size();i++){
297 298
                 // 查询当前人员岗位是非为空
298
-                List<String> postName = sysUserInfoService.getPostNameByUserId(userIdList.get(i));
299
-                if (postName.size() == 0){
299
+                map.put("id",userIdList.get(i));
300
+                List<SysUserInfo> sysUserInfos = sysUserInfoService.getSysUserInfoList(map);
301
+                if (sysUserInfos.size()==1 && sysUserInfos.get(0).getUserPostName() == null){
300 302
                     int num = sysUserInfoService.batchDelete(userIdList, getSysUserId());
301 303
                     if (num > 0) {
302 304
                         a++;
@@ -306,9 +308,9 @@ public class SysUserInfoController extends BaseController {
306 308
             }
307 309
         }
308 310
         if (a == 0){
309
-            return BaseResult.failure("批量删除失败! 该人员岗位信息不为空");
311
+            return BaseResult.failure(-1,"删除失败!请先删除当前人员岗位信息!");
310 312
         }
311
-        return BaseResult.success("批量删除成功");
313
+        return BaseResult.success("删除成功");
312 314
     }
313 315
 
314 316
     /**

+ 42 - 15
src/main/resources/mapper/SysUserInfoDao.xml

@@ -268,14 +268,30 @@
268 268
 
269 269
     <!--查询所有用户-->
270 270
     <select id="getSysUserInfoList" resultMap="SysUserInfoMap" parameterType="map">
271
-        select u.*, d.dept_name as deptName, p.post_name as userPostName
272
-        from sys_user_info u
273
-        left join sys_dept_info d on d.dept_id = u.dept_id
274
-        left join sys_user_post up on up.user_id = u.user_id
275
-        left join sys_post_info p on p.post_id = up.post_id
276
-        where u.del_flag = 0
271
+        WITH RankedData AS (
272
+        SELECT
273
+        u.user_id,
274
+        u.account,
275
+        u.create_time,
276
+        u.sex,
277
+        u.name,
278
+        u.phone,
279
+        u.status,
280
+        d.dept_name AS deptName,
281
+        p.post_name,
282
+        ROW_NUMBER() OVER (PARTITION BY u.user_id ORDER BY u.user_id) AS rn
283
+        FROM
284
+        sys_user_info u
285
+        LEFT JOIN
286
+        sys_dept_info d ON d.dept_id = u.dept_id
287
+        LEFT JOIN
288
+        sys_user_post up ON up.user_id = u.user_id
289
+        LEFT JOIN
290
+        sys_post_info p ON p.post_id = up.post_id
291
+        WHERE
292
+        u.del_flag = 0
277 293
         <if test="account != null and account != ''">
278
-            and u.account = #{account}
294
+            and u.account like '%'+#{account}+'%'
279 295
         </if>
280 296
         <if test="name != null and name != ''">
281 297
             and u.name like '%'+#{name}+'%'
@@ -295,14 +311,25 @@
295 311
         <if test="ssbm != null and ssbm != ''">
296 312
             and d.dept_id = #{ssbm}
297 313
         </if>
298
-        <choose>
299
-            <when test="sortName != null and sortName != '' and sortOrder != null and sortOrder != ''">
300
-                order by ${sortName} ${sortOrder}
301
-            </when>
302
-            <otherwise>
303
-                order by u.user_id asc
304
-            </otherwise>
305
-        </choose>
314
+        )
315
+        SELECT
316
+        user_id,
317
+        account,
318
+        status,
319
+        deptName,
320
+        phone,
321
+        create_time,
322
+        sex,
323
+        name,
324
+        STUFF((SELECT '、' + post_name
325
+        FROM RankedData sub
326
+        WHERE sub.user_id = main.user_id
327
+        AND sub.rn > 0
328
+        FOR XML PATH('')), 1, 1, '') AS userPostName
329
+        FROM
330
+        RankedData main
331
+        WHERE
332
+        rn = 1;
306 333
     </select>
307 334
 
308 335
     <!--查询用户-->

+ 28 - 14
src/main/resources/templates/userinfo/list.html

@@ -244,10 +244,10 @@
244 244
             defaultToolbar: ['filter', 'exports', 'print'],
245 245
             cols: [
246 246
                 [
247
-                    {type: "checkbox", fixed: 'left'},
248
-                    {type: 'numbers', fixed: 'left'},
247
+                    {type: "radio", fixed: 'left',title:'😊'},
248
+                    {type: 'numbers', fixed: 'left',title: '序号'},
249 249
                     {field: 'account', width: '8%', title: '账号', sort: true},
250
-                    {field: 'name', width: '8%', title: '名', sort: true},
250
+                    {field: 'name', width: '8%', title: '用户名', sort: true},
251 251
                     {field: 'sex', width: '5%', title: '性别', templet: '#sexTpl', align: 'center'},
252 252
                     // {
253 253
                     //     field: 'avatar', title: '头像', width: '6%', templet: function (d) {
@@ -305,7 +305,8 @@
305 305
                 "account": '',
306 306
                 "name": '',
307 307
                 'deptName': '',
308
-                'status': ''
308
+                'status': '',
309
+                'userPostName':''
309 310
             });
310 311
             // 执行搜索重载
311 312
             currTable.reload({
@@ -406,38 +407,51 @@
406 407
                     });
407 408
                 }
408 409
             } else if (obj.event === 'delete') {  // 监听删除操作
409
-                var checkStatus = table.checkStatus('currentTableId')
410
-                    , data = checkStatus.data;
411
-                if (data == null || data.length === 0) {
410
+                    var checkStatus = table.checkStatus('currentTableId')
411
+                        , data = checkStatus.data;
412
+                    if (data == null || data.length === 0) {
412 413
                     Message.warning("请选择要删除的用户!", 1000);
413 414
                     return;
414 415
                 }
415
-
416 416
                 var userIds = [];
417 417
                 for (var i = 0, len = data.length; i < len; i++) {
418 418
                     userIds.push(data[i].userId);
419 419
                 }
420
-                layer.confirm('确定批量删除用户吗?', function (index) {
421
-                    layer.close(index);
420
+                layer.confirm('确定要删除当前账号吗?', {
421
+                    title: '注意!',
422
+                    btn: ['确定', '取消']
423
+                }, function () {
424
+                    // 用户点击确定按钮后的回调函数
425
+                    console.log('执行退出账号操作');
422 426
                     AjaxUtil.post({
423 427
                         url: AjaxUtil.ctx + "userinfo/batchDelete",
424 428
                         contentType: "application/json",
425 429
                         data: JSON.stringify(userIds),
426 430
                         success: function (res) {
427
-                            if (res.code === 0) {
428
-                                Message.success(1500, res.message, function () {
431
+                            if (res.code == 0) {
432
+                                layer.msg(res.message,{icon:1},function () {
429 433
                                     // 重载表格
430 434
                                     currTable.reload();
431 435
                                 });
432
-                            } else {
433
-                                Message.error(res.message, 1000);
436
+                            } else if (res.code == -1){
437
+                                layer.msg(res.message, {icon:2});
438
+                                return;
434 439
                             }
435 440
                         },
436 441
                         error: function (error) {
437 442
                         }
438 443
                     });
444
+                    // 这里添加真实的退出账号逻辑,例如发送AJAX请求到服务器
445
+                }, function () {
446
+                    // 用户点击取消按钮后的回调函数
447
+                    console.log('已取消删除账号');
439 448
                 });
440 449
 
450
+              /*  layer.confirm('确定删除用户吗?', function (index) {
451
+                    layer.close(index);
452
+
453
+                });*/
454
+
441 455
                 // layer.alert(JSON.stringify(data));
442 456
             } else if (obj.event === 'downloadPdf') {
443 457
                 console.log("点击下载pdf");