소스 검색

岗检小组成员批量添加/修改

csg6 10 달 전
부모
커밋
333faa85a8

+ 1 - 1
ruoyi-postcheck/src/main/java/com/ruoyi/postCheck/controller/PostTeamController.java

@@ -83,7 +83,6 @@ public class PostTeamController extends BaseController {
83 83
 
84 84
     /**
85 85
      * 导出岗检小组列表
86
-     */
87 86
     @ApiOperation("导出岗检小组列表")
88 87
     @PreAuthorize("@ss.hasPermi('postCheck:team:export')")
89 88
     @Log(title = "岗检小组", businessType = BusinessType.EXPORT)
@@ -93,6 +92,7 @@ public class PostTeamController extends BaseController {
93 92
         ExcelUtil<PostTeam> util = new ExcelUtil<PostTeam>(PostTeam.class);
94 93
         util.exportExcel(response, list, "岗检小组数据");
95 94
     }
95
+     */
96 96
 
97 97
     /**
98 98
      * 获取岗检小组详细信息

+ 18 - 18
ruoyi-postcheck/src/main/java/com/ruoyi/postCheck/controller/PostTeamUserController.java

@@ -54,16 +54,15 @@ public class PostTeamUserController extends BaseController {
54 54
 
55 55
     /**
56 56
      * 导出岗检小组关联成员列表
57
+     @ApiOperation("导出岗检小组关联成员列表")
58
+     @PreAuthorize("@ss.hasPermi('postCheck:teamUser:export')")
59
+     @Log(title = "岗检小组关联成员", businessType = BusinessType.EXPORT)
60
+     @PostMapping("/export") public void export(HttpServletResponse response, PostTeamUser postTeamUser) {
61
+     List<PostTeamUser> list = postTeamUserService.selectPostTeamUserList(postTeamUser);
62
+     ExcelUtil<PostTeamUser> util = new ExcelUtil<PostTeamUser>(PostTeamUser.class);
63
+     util.exportExcel(response, list, "岗检小组关联成员数据");
64
+     }
57 65
      */
58
-    @ApiOperation("导出岗检小组关联成员列表")
59
-    @PreAuthorize("@ss.hasPermi('postCheck:teamUser:export')")
60
-    @Log(title = "岗检小组关联成员", businessType = BusinessType.EXPORT)
61
-    @PostMapping("/export")
62
-    public void export(HttpServletResponse response, PostTeamUser postTeamUser) {
63
-        List<PostTeamUser> list = postTeamUserService.selectPostTeamUserList(postTeamUser);
64
-        ExcelUtil<PostTeamUser> util = new ExcelUtil<PostTeamUser>(PostTeamUser.class);
65
-        util.exportExcel(response, list, "岗检小组关联成员数据");
66
-    }
67 66
 
68 67
     /**
69 68
      * 获取岗检小组关联成员详细信息
@@ -90,20 +89,21 @@ public class PostTeamUserController extends BaseController {
90 89
     @PreAuthorize("@ss.hasPermi('postCheck:teamUser:add')")
91 90
     @Log(title = "岗检小组关联成员", businessType = BusinessType.INSERT)
92 91
     @PostMapping
93
-    public AjaxResult add(@RequestBody PostTeamUser postTeamUser) {
94
-        return toAjax(postTeamUserService.insertPostTeamUser(postTeamUser));
92
+    public AjaxResult add(@RequestBody List<PostTeamUser> postTeamUserList) {
93
+        return toAjax(postTeamUserService.insertPostTeamUser(postTeamUserList));
95 94
     }
96 95
 
97 96
     /**
97
+     * 前端使用使用添加新增,不使用修改,新增接口始终传全量数据
98 98
      * 修改岗检小组关联成员
99
+     *
100
+     @ApiOperation("修改岗检小组关联成员")
101
+     @PreAuthorize("@ss.hasPermi('postCheck:teamUser:edit')")
102
+     @Log(title = "岗检小组关联成员", businessType = BusinessType.UPDATE)
103
+     @PutMapping public AjaxResult edit(@RequestBody List<PostTeamUser> postTeamUserList) {
104
+     return toAjax(postTeamUserService.updatePostTeamUser(postTeamUserList));
105
+     }
99 106
      */
100
-    @ApiOperation("修改岗检小组关联成员")
101
-    @PreAuthorize("@ss.hasPermi('postCheck:teamUser:edit')")
102
-    @Log(title = "岗检小组关联成员", businessType = BusinessType.UPDATE)
103
-    @PutMapping
104
-    public AjaxResult edit(@RequestBody PostTeamUser postTeamUser) {
105
-        return toAjax(postTeamUserService.updatePostTeamUser(postTeamUser));
106
-    }
107 107
 
108 108
     /**
109 109
      * 删除岗检小组关联成员

+ 1 - 1
ruoyi-postcheck/src/main/java/com/ruoyi/postCheck/domain/PostTeamUser.java

@@ -40,7 +40,7 @@ public class PostTeamUser extends BaseEntity
40 40
     @ApiModelProperty("类型(1-组长;2-成员;)")
41 41
     @TableField(value = "type")
42 42
     @Excel(name = "类型", readConverterExp = "类型(1-组长;2-成员;)")
43
-    private Long type;
43
+    private Integer type;
44 44
 
45 45
     @ApiModelProperty("创建者用户ID")
46 46
     @TableField(value = "create_user_id")

+ 4 - 4
ruoyi-postcheck/src/main/java/com/ruoyi/postCheck/service/IPostTeamUserService.java

@@ -31,18 +31,18 @@ public interface IPostTeamUserService extends IService<PostTeamUser>
31 31
     /**
32 32
      * 新增岗检小组关联成员
33 33
      *
34
-     * @param postTeamUser 岗检小组关联成员
34
+     * @param postTeamUserList 岗检小组关联成员数组
35 35
      * @return 结果
36 36
      */
37
-    public int insertPostTeamUser(PostTeamUser postTeamUser);
37
+    public int insertPostTeamUser(List<PostTeamUser> postTeamUserList);
38 38
 
39 39
     /**
40 40
      * 修改岗检小组关联成员
41 41
      *
42
-     * @param postTeamUser 岗检小组关联成员
42
+     * @param postTeamUserList 岗检小组关联成员数组
43 43
      * @return 结果
44
+    public int updatePostTeamUser(List<PostTeamUser> postTeamUserList);
44 45
      */
45
-    public int updatePostTeamUser(PostTeamUser postTeamUser);
46 46
 
47 47
     /**
48 48
      * 批量删除岗检小组关联成员

+ 89 - 24
ruoyi-postcheck/src/main/java/com/ruoyi/postCheck/service/impl/PostTeamUserServiceImpl.java

@@ -1,8 +1,12 @@
1 1
 package com.ruoyi.postCheck.service.impl;
2 2
 
3 3
 import java.util.List;
4
+import java.util.stream.Collectors;
4 5
 
6
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
7
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
5 8
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
9
+import com.ruoyi.common.exception.base.BaseException;
6 10
 import com.ruoyi.common.utils.DateUtils;
7 11
 import org.springframework.beans.factory.annotation.Autowired;
8 12
 import org.springframework.stereotype.Service;
@@ -10,6 +14,7 @@ import com.ruoyi.postCheck.mapper.PostTeamUserMapper;
10 14
 import com.ruoyi.postCheck.domain.PostTeamUser;
11 15
 import com.ruoyi.postCheck.service.IPostTeamUserService;
12 16
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
17
+import org.springframework.util.CollectionUtils;
13 18
 
14 19
 /**
15 20
  * 岗检小组关联成员Service业务层处理
@@ -18,8 +23,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
18 23
  * @date 2023-12-19
19 24
  */
20 25
 @Service
21
-public class PostTeamUserServiceImpl extends ServiceImpl<PostTeamUserMapper, PostTeamUser> implements IPostTeamUserService
22
-{
26
+public class PostTeamUserServiceImpl extends ServiceImpl<PostTeamUserMapper, PostTeamUser> implements IPostTeamUserService {
23 27
     @Autowired
24 28
     private PostTeamUserMapper postTeamUserMapper;
25 29
 
@@ -30,8 +34,7 @@ public class PostTeamUserServiceImpl extends ServiceImpl<PostTeamUserMapper, Pos
30 34
      * @return 岗检小组关联成员
31 35
      */
32 36
     @Override
33
-    public PostTeamUser selectPostTeamUserById(Long id)
34
-    {
37
+    public PostTeamUser selectPostTeamUserById(Long id) {
35 38
         return postTeamUserMapper.selectPostTeamUserById(id);
36 39
     }
37 40
 
@@ -42,40 +45,104 @@ public class PostTeamUserServiceImpl extends ServiceImpl<PostTeamUserMapper, Pos
42 45
      * @return 岗检小组关联成员
43 46
      */
44 47
     @Override
45
-    public List<PostTeamUser> selectPostTeamUserList(PostTeamUser postTeamUser)
46
-    {
48
+    public List<PostTeamUser> selectPostTeamUserList(PostTeamUser postTeamUser) {
47 49
         return postTeamUserMapper.selectPostTeamUserList(postTeamUser);
48 50
     }
49 51
 
50 52
     /**
51 53
      * 新增岗检小组关联成员
52 54
      *
53
-     * @param postTeamUser 岗检小组关联成员
55
+     * @param postTeamUserList 岗检小组关联成员数组
54 56
      * @return 结果
55 57
      */
56 58
     @Override
57
-    public int insertPostTeamUser(PostTeamUser postTeamUser)
58
-    {
59
-        //TODO 自增主键修改为-MyBatis-Plus雪花算法(截取5位解决VUE精度丢失BUG)-系统登录日志
60
-        if (postTeamUser.getId() == null)
59
+    public int insertPostTeamUser(List<PostTeamUser> postTeamUserList) {
60
+        if (CollectionUtils.isEmpty(postTeamUserList)) {
61
+            return 0;
62
+        }
63
+
64
+        List<Long> postTeamIdList = postTeamUserList.stream().map(t -> t.getPostTeamId()).collect(Collectors.toList());
65
+        if (CollectionUtils.isEmpty(postTeamIdList)) {
66
+            throw new BaseException("postTeamId为空,请检查!");
67
+        }
68
+
69
+        //删除原来的用户
70
+        LambdaQueryWrapper<PostTeamUser> wrapper = new LambdaQueryWrapper<>();
71
+        wrapper.in(PostTeamUser::getPostTeamId, postTeamIdList);
72
+        postTeamUserMapper.delete(wrapper);
73
+
74
+        //新增用户
75
+        int count = 0;
76
+        int index = 0;
77
+        for (PostTeamUser postTeamUser : postTeamUserList) {
78
+            //类型(1-组长;2-成员;)
79
+            if (index++ == 0) {
80
+                postTeamUser.setType(1);
81
+            } else {
82
+                postTeamUser.setType(2);
83
+            }
84
+            Long postTeamId = postTeamUser.getPostTeamId();
85
+            if (postTeamId == null) {
86
+                throw new BaseException("postTeamId为空,请检查!");
87
+            }
88
+
89
+            //TODO 自增主键修改为-MyBatis-Plus雪花算法(截取5位解决VUE精度丢失BUG)-系统登录日志
90
+//        if (postTeamUser.getId() == null)
61 91
             postTeamUser.setId(Long.parseLong(IdWorker.getIdStr().substring(4)));
62
-        postTeamUser.setCreateDefault();
63
-        return postTeamUserMapper.insertPostTeamUser(postTeamUser);
92
+            postTeamUser.setCreateDefault();
93
+            count += postTeamUserMapper.insertPostTeamUser(postTeamUser);
94
+        }
95
+        return count;
64 96
     }
65 97
 
66 98
     /**
67 99
      * 修改岗检小组关联成员
68 100
      *
69
-     * @param postTeamUser 岗检小组关联成员
101
+     * @param postTeamUserList 岗检小组关联成员数组
70 102
      * @return 结果
71 103
      */
72
-    @Override
73
-    public int updatePostTeamUser(PostTeamUser postTeamUser)
74
-    {
75
-        postTeamUser.setUpdateDefault();
76
-        return postTeamUserMapper.updatePostTeamUser(postTeamUser);
77
-    }
104
+  /*  @Override
105
+    public int updatePostTeamUser(List<PostTeamUser> postTeamUserList) {
106
+        if (CollectionUtils.isEmpty(postTeamUserList)) {
107
+            return 0;
108
+        }
109
+
110
+        List<Long> postTeamIdList = postTeamUserList.stream().map(t -> t.getPostTeamId()).collect(Collectors.toList());
111
+        if (CollectionUtils.isEmpty(postTeamIdList)) {
112
+            throw new BaseException("postTeamId为空,请检查!");
113
+        }
114
+        //删除原来的用户
115
+        LambdaQueryWrapper<PostTeamUser> wrapper = new LambdaQueryWrapper<>();
116
+        wrapper.in(PostTeamUser::getPostTeamId, postTeamIdList);
117
+        postTeamUserMapper.delete(wrapper);
118
+
119
+        //新增用户
120
+        int count = 0;
121
+        int index = 0;
122
+        for (PostTeamUser postTeamUser : postTeamUserList) {
123
+            //类型(1-组长;2-成员;)
124
+            if (index++ == 0) {
125
+                postTeamUser.setType(1);
126
+            } else {
127
+                postTeamUser.setType(2);
128
+            }
78 129
 
130
+            Long postTeamId = postTeamUser.getPostTeamId();
131
+            if (postTeamId == null) {
132
+                throw new BaseException("postTeamId为空,请检查!");
133
+            }
134
+            //TODO 自增主键修改为-MyBatis-Plus雪花算法(截取5位解决VUE精度丢失BUG)-系统登录日志
135
+//        if (postTeamUser.getId() == null)
136
+            postTeamUser.setId(Long.parseLong(IdWorker.getIdStr().substring(4)));
137
+            postTeamUser.setCreateDefault();
138
+            count += postTeamUserMapper.insertPostTeamUser(postTeamUser);
139
+        }
140
+        return count;
141
+
142
+//        postTeamUser.setUpdateDefault();
143
+//        return postTeamUserMapper.updatePostTeamUser(postTeamUser);
144
+    }
145
+*/
79 146
     /**
80 147
      * 批量删除岗检小组关联成员
81 148
      *
@@ -83,8 +150,7 @@ public class PostTeamUserServiceImpl extends ServiceImpl<PostTeamUserMapper, Pos
83 150
      * @return 结果
84 151
      */
85 152
     @Override
86
-    public int deletePostTeamUserByIds(Long[] ids)
87
-    {
153
+    public int deletePostTeamUserByIds(Long[] ids) {
88 154
         return postTeamUserMapper.deletePostTeamUserByIds(ids);
89 155
     }
90 156
 
@@ -95,8 +161,7 @@ public class PostTeamUserServiceImpl extends ServiceImpl<PostTeamUserMapper, Pos
95 161
      * @return 结果
96 162
      */
97 163
     @Override
98
-    public int deletePostTeamUserById(Long id)
99
-    {
164
+    public int deletePostTeamUserById(Long id) {
100 165
         return postTeamUserMapper.deletePostTeamUserById(id);
101 166
     }
102 167
 }