Explorar o código

修复分页问题

wwh hai 1 mes
pai
achega
4816fc97a9

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

@@ -18,7 +18,9 @@ import com.ruoyi.common.core.domain.AjaxResult;
18 18
 import com.ruoyi.common.core.page.TableDataInfo;
19 19
 import com.ruoyi.common.enums.BusinessType;
20 20
 import com.ruoyi.web.modules.diagnosis.domain.BizMedicalResource;
21
+import com.ruoyi.web.modules.diagnosis.domain.MedicalResourceBatchIdsBody;
21 22
 import com.ruoyi.web.modules.diagnosis.service.IBizMedicalResourceService;
23
+import com.ruoyi.web.modules.diagnosis.support.MedicalResourceBatchIds;
22 24
 import com.ruoyi.web.modules.diagnosis.support.MedicalResourceTypeValidator;
23 25
 import com.ruoyi.web.modules.diagnosis.support.MedicalResourceValidation;
24 26
 
@@ -89,9 +91,10 @@ public class BizMedicalResourceController extends BaseController
89 91
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:publish')")
90 92
     @Log(title = "畜牧医疗资源批量发布", businessType = BusinessType.UPDATE)
91 93
     @PostMapping("/publish/batch")
92
-    public AjaxResult publishBatch(@RequestBody Long[] ids)
94
+    public AjaxResult publishBatch(@RequestBody MedicalResourceBatchIdsBody body)
93 95
     {
94
-        return toAjax(bizMedicalResourceService.publishByIds(ids));
96
+        String ids = body != null ? body.getIds() : null;
97
+        return toAjax(bizMedicalResourceService.publishByIds(MedicalResourceBatchIds.parse(ids)));
95 98
     }
96 99
 
97 100
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:publish')")
@@ -105,9 +108,10 @@ public class BizMedicalResourceController extends BaseController
105 108
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:offline')")
106 109
     @Log(title = "畜牧医疗资源批量下架", businessType = BusinessType.UPDATE)
107 110
     @PostMapping("/offline/batch")
108
-    public AjaxResult offlineBatch(@RequestBody Long[] ids)
111
+    public AjaxResult offlineBatch(@RequestBody MedicalResourceBatchIdsBody body)
109 112
     {
110
-        return toAjax(bizMedicalResourceService.offlineByIds(ids));
113
+        String ids = body != null ? body.getIds() : null;
114
+        return toAjax(bizMedicalResourceService.offlineByIds(MedicalResourceBatchIds.parse(ids)));
111 115
     }
112 116
 
113 117
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:offline')")
@@ -121,9 +125,11 @@ public class BizMedicalResourceController extends BaseController
121 125
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:assignAccount')")
122 126
     @Log(title = "畜牧医疗资源批量分配账号", businessType = BusinessType.INSERT)
123 127
     @PostMapping("/assignAccount/batch")
124
-    public AjaxResult assignAccountBatch(@RequestBody Long[] ids)
128
+    public AjaxResult assignAccountBatch(@RequestBody MedicalResourceBatchIdsBody body)
125 129
     {
126
-        return toAjax(bizMedicalResourceService.assignAccountByIds(ids, getUsername()));
130
+        String ids = body != null ? body.getIds() : null;
131
+        return toAjax(bizMedicalResourceService.assignAccountByIds(
132
+                MedicalResourceBatchIds.parse(ids), getUsername()));
127 133
     }
128 134
 
129 135
     @PreAuthorize("@ss.hasPermi('diseaseTreatment:medicalResource:assignAccount')")

+ 19 - 0
baqing-admin/src/main/java/com/ruoyi/web/modules/diagnosis/domain/MedicalResourceBatchIdsBody.java

@@ -0,0 +1,19 @@
1
+package com.ruoyi.web.modules.diagnosis.domain;
2
+
3
+/**
4
+ * 畜牧医疗资源批量操作 ID 请求体(逗号分隔字符串)。
5
+ */
6
+public class MedicalResourceBatchIdsBody
7
+{
8
+    private String ids;
9
+
10
+    public String getIds()
11
+    {
12
+        return ids;
13
+    }
14
+
15
+    public void setIds(String ids)
16
+    {
17
+        this.ids = ids;
18
+    }
19
+}

+ 43 - 0
baqing-admin/src/main/java/com/ruoyi/web/modules/diagnosis/support/MedicalResourceBatchIds.java

@@ -0,0 +1,43 @@
1
+package com.ruoyi.web.modules.diagnosis.support;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+import com.ruoyi.common.exception.ServiceException;
6
+import com.ruoyi.common.utils.StringUtils;
7
+
8
+/**
9
+ * 批量操作 ID 解析(逗号分隔字符串)。
10
+ */
11
+public final class MedicalResourceBatchIds
12
+{
13
+    private MedicalResourceBatchIds()
14
+    {
15
+    }
16
+
17
+    public static Long[] parse(String ids)
18
+    {
19
+        if (StringUtils.isEmpty(ids))
20
+        {
21
+            return new Long[0];
22
+        }
23
+        String[] parts = ids.split(",");
24
+        List<Long> cleaned = new ArrayList<>();
25
+        for (String part : parts)
26
+        {
27
+            String trimmed = part.trim();
28
+            if (StringUtils.isEmpty(trimmed))
29
+            {
30
+                continue;
31
+            }
32
+            try
33
+            {
34
+                cleaned.add(Long.valueOf(trimmed));
35
+            }
36
+            catch (NumberFormatException ex)
37
+            {
38
+                throw new ServiceException("ID 格式无效:" + trimmed);
39
+            }
40
+        }
41
+        return cleaned.toArray(new Long[0]);
42
+    }
43
+}

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

@@ -166,7 +166,7 @@ class BizMedicalResourceControllerApiTest
166 166
         when(bizMedicalResourceService.publishByIds(any())).thenReturn(2);
167 167
         mockMvc.perform(post("/diseaseTreatment/medicalResource/publish/batch")
168 168
                 .contentType(MediaType.APPLICATION_JSON)
169
-                .content("[1,2]"))
169
+                .content("{\"ids\":\"1,2\"}"))
170 170
                 .andExpect(status().isOk())
171 171
                 .andExpect(jsonPath("$.code").value(200));
172 172
     }
@@ -178,7 +178,7 @@ class BizMedicalResourceControllerApiTest
178 178
         when(bizMedicalResourceService.offlineByIds(any())).thenReturn(2);
179 179
         mockMvc.perform(post("/diseaseTreatment/medicalResource/offline/batch")
180 180
                 .contentType(MediaType.APPLICATION_JSON)
181
-                .content("[1,2]"))
181
+                .content("{\"ids\":\"1,2\"}"))
182 182
                 .andExpect(status().isOk())
183 183
                 .andExpect(jsonPath("$.code").value(200));
184 184
     }
@@ -210,7 +210,7 @@ class BizMedicalResourceControllerApiTest
210 210
         when(bizMedicalResourceService.assignAccountByIds(any(), eq("tester"))).thenReturn(1);
211 211
         mockMvc.perform(post("/diseaseTreatment/medicalResource/assignAccount/batch")
212 212
                 .contentType(MediaType.APPLICATION_JSON)
213
-                .content("[1,2]"))
213
+                .content("{\"ids\":\"1,2\"}"))
214 214
                 .andExpect(status().isOk())
215 215
                 .andExpect(jsonPath("$.code").value(200));
216 216
     }

+ 30 - 0
baqing-admin/src/test/java/com/ruoyi/web/modules/diagnosis/support/MedicalResourceBatchIdsTest.java

@@ -0,0 +1,30 @@
1
+package com.ruoyi.web.modules.diagnosis.support;
2
+
3
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4
+import static org.junit.jupiter.api.Assertions.assertEquals;
5
+import static org.junit.jupiter.api.Assertions.assertThrows;
6
+
7
+import com.ruoyi.common.exception.ServiceException;
8
+import org.junit.jupiter.api.DisplayName;
9
+import org.junit.jupiter.api.Test;
10
+
11
+@DisplayName("MedicalResourceBatchIds")
12
+class MedicalResourceBatchIdsTest
13
+{
14
+    @Test
15
+    @DisplayName("解析逗号分隔 ID")
16
+    void parse()
17
+    {
18
+        assertArrayEquals(new Long[] { 1L, 2L, 3L }, MedicalResourceBatchIds.parse("1,2,3"));
19
+        assertArrayEquals(new Long[] { 1L, 2L }, MedicalResourceBatchIds.parse(" 1 , 2 "));
20
+        assertEquals(0, MedicalResourceBatchIds.parse("").length);
21
+        assertEquals(0, MedicalResourceBatchIds.parse(null).length);
22
+    }
23
+
24
+    @Test
25
+    @DisplayName("非法 ID 抛错")
26
+    void parseInvalid()
27
+    {
28
+        assertThrows(ServiceException.class, () -> MedicalResourceBatchIds.parse("1,abc"));
29
+    }
30
+}