Explorar o código

修复分页问题

wwh hai 1 mes
pai
achega
c9e323bff3

+ 24 - 0
baqing-admin/src/main/java/com/ruoyi/web/modules/diagnosis/controller/BizMedicalResourceController.java

@@ -86,6 +86,14 @@ public class BizMedicalResourceController extends BaseController
86
         return toAjax(bizMedicalResourceService.deleteBizMedicalResourceByIds(ids, getUsername()));
86
         return toAjax(bizMedicalResourceService.deleteBizMedicalResourceByIds(ids, getUsername()));
87
     }
87
     }
88
 
88
 
89
+    @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:publish')")
90
+    @Log(title = "畜牧医疗资源批量发布", businessType = BusinessType.UPDATE)
91
+    @PostMapping("/publish/batch")
92
+    public AjaxResult publishBatch(@RequestBody Long[] ids)
93
+    {
94
+        return toAjax(bizMedicalResourceService.publishByIds(ids));
95
+    }
96
+
89
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:publish')")
97
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:publish')")
90
     @Log(title = "畜牧医疗资源发布", businessType = BusinessType.UPDATE)
98
     @Log(title = "畜牧医疗资源发布", businessType = BusinessType.UPDATE)
91
     @PostMapping("/publish/{id}")
99
     @PostMapping("/publish/{id}")
@@ -94,6 +102,14 @@ public class BizMedicalResourceController extends BaseController
94
         return toAjax(bizMedicalResourceService.publish(id));
102
         return toAjax(bizMedicalResourceService.publish(id));
95
     }
103
     }
96
 
104
 
105
+    @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:offline')")
106
+    @Log(title = "畜牧医疗资源批量下架", businessType = BusinessType.UPDATE)
107
+    @PostMapping("/offline/batch")
108
+    public AjaxResult offlineBatch(@RequestBody Long[] ids)
109
+    {
110
+        return toAjax(bizMedicalResourceService.offlineByIds(ids));
111
+    }
112
+
97
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:offline')")
113
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:offline')")
98
     @Log(title = "畜牧医疗资源下架", businessType = BusinessType.UPDATE)
114
     @Log(title = "畜牧医疗资源下架", businessType = BusinessType.UPDATE)
99
     @PostMapping("/offline/{id}")
115
     @PostMapping("/offline/{id}")
@@ -102,6 +118,14 @@ public class BizMedicalResourceController extends BaseController
102
         return toAjax(bizMedicalResourceService.offline(id));
118
         return toAjax(bizMedicalResourceService.offline(id));
103
     }
119
     }
104
 
120
 
121
+    @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:assignAccount')")
122
+    @Log(title = "畜牧医疗资源批量分配账号", businessType = BusinessType.INSERT)
123
+    @PostMapping("/assignAccount/batch")
124
+    public AjaxResult assignAccountBatch(@RequestBody Long[] ids)
125
+    {
126
+        return toAjax(bizMedicalResourceService.assignAccountByIds(ids, getUsername()));
127
+    }
128
+
105
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:assignAccount')")
129
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:assignAccount')")
106
     @Log(title = "畜牧医疗资源分配账号", businessType = BusinessType.INSERT)
130
     @Log(title = "畜牧医疗资源分配账号", businessType = BusinessType.INSERT)
107
     @PostMapping("/assignAccount/{id}")
131
     @PostMapping("/assignAccount/{id}")

+ 9 - 0
baqing-admin/src/main/java/com/ruoyi/web/modules/diagnosis/service/IBizMedicalResourceService.java

@@ -22,5 +22,14 @@ public interface IBizMedicalResourceService
22
 
22
 
23
     int offline(Long id);
23
     int offline(Long id);
24
 
24
 
25
+    /** 批量发布;任一记录校验失败则整体回滚 */
26
+    int publishByIds(Long[] ids);
27
+
28
+    /** 批量下架;任一记录校验失败则整体回滚 */
29
+    int offlineByIds(Long[] ids);
30
+
25
     int assignAccount(Long id, String operator);
31
     int assignAccount(Long id, String operator);
32
+
33
+    /** 批量分配账号;已分配账号的记录跳过,其余按单条规则处理 */
34
+    int assignAccountByIds(Long[] ids, String operator);
26
 }
35
 }

+ 83 - 1
baqing-admin/src/main/java/com/ruoyi/web/modules/diagnosis/service/impl/BizMedicalResourceServiceImpl.java

@@ -183,11 +183,76 @@ public class BizMedicalResourceServiceImpl implements IBizMedicalResourceService
183
         return n;
183
         return n;
184
     }
184
     }
185
 
185
 
186
+    @Override
187
+    @Transactional(rollbackFor = Exception.class)
188
+    public int publishByIds(Long[] ids)
189
+    {
190
+        List<Long> cleaned = cleanIds(ids);
191
+        if (cleaned.isEmpty())
192
+        {
193
+            return 0;
194
+        }
195
+        int count = 0;
196
+        for (Long id : cleaned)
197
+        {
198
+            count += publish(id);
199
+        }
200
+        return count;
201
+    }
202
+
203
+    @Override
204
+    @Transactional(rollbackFor = Exception.class)
205
+    public int offlineByIds(Long[] ids)
206
+    {
207
+        List<Long> cleaned = cleanIds(ids);
208
+        if (cleaned.isEmpty())
209
+        {
210
+            return 0;
211
+        }
212
+        int count = 0;
213
+        for (Long id : cleaned)
214
+        {
215
+            count += offline(id);
216
+        }
217
+        return count;
218
+    }
219
+
186
     @Override
220
     @Override
187
     @Transactional(rollbackFor = Exception.class)
221
     @Transactional(rollbackFor = Exception.class)
188
     public int assignAccount(Long id, String operator)
222
     public int assignAccount(Long id, String operator)
189
     {
223
     {
190
-        BizMedicalResource row = requireRow(id);
224
+        return doAssignAccount(requireRow(id), operator);
225
+    }
226
+
227
+    @Override
228
+    @Transactional(rollbackFor = Exception.class)
229
+    public int assignAccountByIds(Long[] ids, String operator)
230
+    {
231
+        List<Long> cleaned = cleanIds(ids);
232
+        if (cleaned.isEmpty())
233
+        {
234
+            return 0;
235
+        }
236
+        int count = 0;
237
+        for (Long id : cleaned)
238
+        {
239
+            BizMedicalResource row = bizMedicalResourceMapper.selectBizMedicalResourceById(id);
240
+            if (row == null)
241
+            {
242
+                throw new ServiceException("记录不存在或已删除");
243
+            }
244
+            if (row.getAccountAssigned() != null
245
+                    && row.getAccountAssigned() == MedicalResourceRules.ACCOUNT_ASSIGNED_YES)
246
+            {
247
+                continue;
248
+            }
249
+            count += doAssignAccount(row, operator);
250
+        }
251
+        return count;
252
+    }
253
+
254
+    private int doAssignAccount(BizMedicalResource row, String operator)
255
+    {
191
         MedicalResourceValidation.validateForAssignAccount(row);
256
         MedicalResourceValidation.validateForAssignAccount(row);
192
         SysUser user = accountAssigner.createAccount(row, operator);
257
         SysUser user = accountAssigner.createAccount(row, operator);
193
         row.setAccountAssigned(MedicalResourceRules.ACCOUNT_ASSIGNED_YES);
258
         row.setAccountAssigned(MedicalResourceRules.ACCOUNT_ASSIGNED_YES);
@@ -207,6 +272,23 @@ public class BizMedicalResourceServiceImpl implements IBizMedicalResourceService
207
         return row;
272
         return row;
208
     }
273
     }
209
 
274
 
275
+    private static List<Long> cleanIds(Long[] ids)
276
+    {
277
+        List<Long> cleaned = new ArrayList<>();
278
+        if (ids == null)
279
+        {
280
+            return cleaned;
281
+        }
282
+        for (Long id : ids)
283
+        {
284
+            if (id != null)
285
+            {
286
+                cleaned.add(id);
287
+            }
288
+        }
289
+        return cleaned;
290
+    }
291
+
210
     private void enrichRow(BizMedicalResource row)
292
     private void enrichRow(BizMedicalResource row)
211
     {
293
     {
212
         if (row != null)
294
         if (row != null)

+ 36 - 0
baqing-admin/src/test/java/com/ruoyi/web/modules/diagnosis/controller/BizMedicalResourceControllerApiTest.java

@@ -159,6 +159,30 @@ class BizMedicalResourceControllerApiTest
159
                 .andExpect(jsonPath("$.code").value(200));
159
                 .andExpect(jsonPath("$.code").value(200));
160
     }
160
     }
161
 
161
 
162
+    @Test
163
+    @DisplayName("POST /publish/batch")
164
+    void publishBatch() throws Exception
165
+    {
166
+        when(bizMedicalResourceService.publishByIds(any())).thenReturn(2);
167
+        mockMvc.perform(post("/diseaseTreatment/medicalResource/publish/batch")
168
+                .contentType(MediaType.APPLICATION_JSON)
169
+                .content("[1,2]"))
170
+                .andExpect(status().isOk())
171
+                .andExpect(jsonPath("$.code").value(200));
172
+    }
173
+
174
+    @Test
175
+    @DisplayName("POST /offline/batch")
176
+    void offlineBatch() throws Exception
177
+    {
178
+        when(bizMedicalResourceService.offlineByIds(any())).thenReturn(2);
179
+        mockMvc.perform(post("/diseaseTreatment/medicalResource/offline/batch")
180
+                .contentType(MediaType.APPLICATION_JSON)
181
+                .content("[1,2]"))
182
+                .andExpect(status().isOk())
183
+                .andExpect(jsonPath("$.code").value(200));
184
+    }
185
+
162
     @Test
186
     @Test
163
     @DisplayName("POST 发布")
187
     @DisplayName("POST 发布")
164
     void publish() throws Exception
188
     void publish() throws Exception
@@ -179,6 +203,18 @@ class BizMedicalResourceControllerApiTest
179
                 .andExpect(jsonPath("$.code").value(200));
203
                 .andExpect(jsonPath("$.code").value(200));
180
     }
204
     }
181
 
205
 
206
+    @Test
207
+    @DisplayName("POST /assignAccount/batch")
208
+    void assignAccountBatch() throws Exception
209
+    {
210
+        when(bizMedicalResourceService.assignAccountByIds(any(), eq("tester"))).thenReturn(1);
211
+        mockMvc.perform(post("/diseaseTreatment/medicalResource/assignAccount/batch")
212
+                .contentType(MediaType.APPLICATION_JSON)
213
+                .content("[1,2]"))
214
+                .andExpect(status().isOk())
215
+                .andExpect(jsonPath("$.code").value(200));
216
+    }
217
+
182
     @Test
218
     @Test
183
     @DisplayName("POST 分配账号")
219
     @DisplayName("POST 分配账号")
184
     void assignAccount() throws Exception
220
     void assignAccount() throws Exception

+ 70 - 0
baqing-admin/src/test/java/com/ruoyi/web/modules/diagnosis/service/impl/BizMedicalResourceServiceImplTest.java

@@ -7,6 +7,7 @@ import static org.mockito.ArgumentMatchers.argThat;
7
 import static org.mockito.ArgumentMatchers.eq;
7
 import static org.mockito.ArgumentMatchers.eq;
8
 import static org.mockito.Mockito.doNothing;
8
 import static org.mockito.Mockito.doNothing;
9
 import static org.mockito.Mockito.never;
9
 import static org.mockito.Mockito.never;
10
+import static org.mockito.Mockito.times;
10
 import static org.mockito.Mockito.verify;
11
 import static org.mockito.Mockito.verify;
11
 import static org.mockito.Mockito.when;
12
 import static org.mockito.Mockito.when;
12
 
13
 
@@ -132,6 +133,40 @@ class BizMedicalResourceServiceImplTest
132
         verify(mapper).logicDeleteBizMedicalResourceByIds(new Long[] { 6L }, "tester");
133
         verify(mapper).logicDeleteBizMedicalResourceByIds(new Long[] { 6L }, "tester");
133
     }
134
     }
134
 
135
 
136
+    @Test
137
+    @DisplayName("批量发布")
138
+    void publishByIds()
139
+    {
140
+        BizMedicalResource db1 = MedicalResourceTestSamples.sampleVetDraft();
141
+        db1.setId(1L);
142
+        db1.setConsultModes("1,2");
143
+        db1.setServiceWeekdays("1,2,3,4,5");
144
+        BizMedicalResource db2 = MedicalResourceTestSamples.sampleVetDraft();
145
+        db2.setId(2L);
146
+        db2.setConsultModes("1,2");
147
+        db2.setServiceWeekdays("1,2,3,4,5");
148
+        when(mapper.selectBizMedicalResourceById(1L)).thenReturn(db1);
149
+        when(mapper.selectBizMedicalResourceById(2L)).thenReturn(db2);
150
+        when(mapper.updateBizMedicalResource(any())).thenReturn(1);
151
+        assertEquals(2, service.publishByIds(new Long[] { 1L, 2L }));
152
+        verify(mapper, times(2)).updateBizMedicalResource(any());
153
+    }
154
+
155
+    @Test
156
+    @DisplayName("批量下架")
157
+    void offlineByIds()
158
+    {
159
+        BizMedicalResource db1 = MedicalResourceTestSamples.samplePublishedVet();
160
+        db1.setId(1L);
161
+        BizMedicalResource db2 = MedicalResourceTestSamples.samplePublishedVet();
162
+        db2.setId(2L);
163
+        when(mapper.selectBizMedicalResourceById(1L)).thenReturn(db1);
164
+        when(mapper.selectBizMedicalResourceById(2L)).thenReturn(db2);
165
+        when(mapper.updateBizMedicalResource(any())).thenReturn(1);
166
+        assertEquals(2, service.offlineByIds(new Long[] { 1L, 2L }));
167
+        verify(mapper, times(2)).updateBizMedicalResource(any());
168
+    }
169
+
135
     @Test
170
     @Test
136
     @DisplayName("分配账号")
171
     @DisplayName("分配账号")
137
     void assignAccount()
172
     void assignAccount()
@@ -149,4 +184,39 @@ class BizMedicalResourceServiceImplTest
149
                 MedicalResourceRules.ACCOUNT_ASSIGNED_YES == r.getAccountAssigned()
184
                 MedicalResourceRules.ACCOUNT_ASSIGNED_YES == r.getAccountAssigned()
150
                         && Long.valueOf(100L).equals(r.getSysUserId())));
185
                         && Long.valueOf(100L).equals(r.getSysUserId())));
151
     }
186
     }
187
+
188
+    @Test
189
+    @DisplayName("批量分配账号跳过已分配")
190
+    void assignAccountByIdsSkipsAssigned()
191
+    {
192
+        BizMedicalResource assigned = MedicalResourceTestSamples.sampleVetDraft();
193
+        assigned.setId(1L);
194
+        assigned.setAccountAssigned(MedicalResourceRules.ACCOUNT_ASSIGNED_YES);
195
+        assigned.setSysUserId(99L);
196
+        BizMedicalResource unassigned = MedicalResourceTestSamples.sampleVetDraft();
197
+        unassigned.setId(2L);
198
+        when(mapper.selectBizMedicalResourceById(1L)).thenReturn(assigned);
199
+        when(mapper.selectBizMedicalResourceById(2L)).thenReturn(unassigned);
200
+        SysUser user = new SysUser();
201
+        user.setUserId(100L);
202
+        user.setUserName("zhangshouyi2");
203
+        when(accountAssigner.createAccount(any(), any())).thenReturn(user);
204
+        when(mapper.updateBizMedicalResource(any())).thenReturn(1);
205
+        assertEquals(1, service.assignAccountByIds(new Long[] { 1L, 2L }, "admin"));
206
+        verify(accountAssigner, times(1)).createAccount(any(), any());
207
+        verify(mapper, times(1)).updateBizMedicalResource(any());
208
+    }
209
+
210
+    @Test
211
+    @DisplayName("批量分配账号全部已分配返回0")
212
+    void assignAccountByIdsAllSkipped()
213
+    {
214
+        BizMedicalResource assigned = MedicalResourceTestSamples.sampleVetDraft();
215
+        assigned.setId(1L);
216
+        assigned.setAccountAssigned(MedicalResourceRules.ACCOUNT_ASSIGNED_YES);
217
+        when(mapper.selectBizMedicalResourceById(1L)).thenReturn(assigned);
218
+        assertEquals(0, service.assignAccountByIds(new Long[] { 1L }, "admin"));
219
+        verify(accountAssigner, never()).createAccount(any(), any());
220
+        verify(mapper, never()).updateBizMedicalResource(any());
221
+    }
152
 }
222
 }