Your Name 4 yıl önce
ebeveyn
işleme
07735364c6

+ 10
- 59
src/main/java/com/yunzhi/demo/controller/TaTopicController.java Dosyayı Görüntüle

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.demo.common.BaseController;
7 7
 import com.yunzhi.demo.common.ResponseBean;
8
+import com.yunzhi.demo.common.StringUtils;
8 9
 import com.yunzhi.demo.vo.SortParams;
9 10
 import io.swagger.annotations.Api;
10 11
 import io.swagger.annotations.ApiOperation;
@@ -80,22 +81,6 @@ public class TaTopicController extends BaseController {
80 81
         return ResponseBean.success(result);
81 82
     }
82 83
 
83
-    /**
84
-     * 保存对象
85
-     * @param taTopic 实体对象
86
-     * @return
87
-     */
88
-    @RequestMapping(value="/taTopic",method= RequestMethod.POST)
89
-    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
90
-    public ResponseBean taTopicAdd(@ApiParam("保存内容") @RequestBody TaTopic taTopic) throws Exception{
91
-
92
-        if (iTaTopicService.save(taTopic)){
93
-            return ResponseBean.success(taTopic);
94
-        }else {
95
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
96
-        }
97
-    }
98
-
99 84
     /**
100 85
      * 保存对象
101 86
      * @param taTopic 实体对象
@@ -105,6 +90,14 @@ public class TaTopicController extends BaseController {
105 90
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
106 91
     public ResponseBean topicAdd(@ApiParam("保存内容") @RequestBody TaTopic taTopic) throws Exception{
107 92
 
93
+        QueryWrapper<TaTopic> queryWrapper = new QueryWrapper<TaTopic>()
94
+                .orderByDesc("sort_no")
95
+                .last("limit 1");
96
+
97
+        TaTopic max = iTaTopicService.getOne(queryWrapper);
98
+        int sortNo = max == null ? 0 : max.getSortNo() + 1;
99
+        taTopic.setSortNo(sortNo);
100
+
108 101
         if (iTaTopicService.save(taTopic)){
109 102
             return ResponseBean.success(taTopic);
110 103
         }else {
@@ -112,20 +105,6 @@ public class TaTopicController extends BaseController {
112 105
         }
113 106
     }
114 107
 
115
-    /**
116
-     * 根据id删除对象
117
-     * @param id  实体ID
118
-     */
119
-    @RequestMapping(value="/taTopic/{id}", method= RequestMethod.DELETE)
120
-    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
121
-    public ResponseBean taTopicDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
122
-        if(iTaTopicService.removeById(id)){
123
-            return ResponseBean.success("success");
124
-        }else {
125
-            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
126
-        }
127
-    }
128
-
129 108
     /**
130 109
      * 根据id删除对象
131 110
      * @param id  实体ID
@@ -140,24 +119,6 @@ public class TaTopicController extends BaseController {
140 119
         }
141 120
     }
142 121
 
143
-    /**
144
-     * 修改对象
145
-     * @param id  实体ID
146
-     * @param taTopic 实体对象
147
-     * @return
148
-     */
149
-    @RequestMapping(value="/taTopic/{id}",method= RequestMethod.PUT)
150
-    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
151
-    public ResponseBean taTopicUpdate(@ApiParam("对象ID") @PathVariable Integer id,
152
-                                        @ApiParam("更新内容") @RequestBody TaTopic taTopic) throws Exception{
153
-
154
-        if (iTaTopicService.updateById(taTopic)){
155
-            return ResponseBean.success(iTaTopicService.getById(id));
156
-        }else {
157
-            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
158
-        }
159
-    }
160
-
161 122
     /**
162 123
      * 修改对象
163 124
      * @param id  实体ID
@@ -176,16 +137,6 @@ public class TaTopicController extends BaseController {
176 137
         }
177 138
     }
178 139
 
179
-    /**
180
-     * 根据id查询对象
181
-     * @param id  实体ID
182
-     */
183
-    @RequestMapping(value="/taTopic/{id}",method= RequestMethod.GET)
184
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
185
-    public ResponseBean taTopicGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
186
-        return ResponseBean.success(iTaTopicService.getById(id));
187
-    }
188
-
189 140
     /**
190 141
      * 根据id查询对象
191 142
      * @param id  实体ID
@@ -200,7 +151,7 @@ public class TaTopicController extends BaseController {
200 151
     @RequestMapping(value="/admin/sort/topic",method= RequestMethod.PUT)
201 152
     @ApiOperation(value="排序", notes = "排序", httpMethod = "PUT", response = ResponseBean.class)
202 153
     public ResponseBean topicSort(@ApiParam("排序") @RequestBody SortParams sortParams) throws Exception {
203
-        if (null == sortParams.getFrom() || null == sortParams.getTo()) {
154
+        if (StringUtils.isEmpty(sortParams.getFrom()) || StringUtils.isEmpty(sortParams.getTo())) {
204 155
             return ResponseBean.success("success");
205 156
         }
206 157
 

+ 11
- 5
src/main/java/com/yunzhi/demo/service/impl/TaTopicServiceImpl.java Dosyayı Görüntüle

@@ -40,15 +40,21 @@ public class TaTopicServiceImpl extends ServiceImpl<TaTopicMapper, TaTopic> impl
40 40
             return;
41 41
         }
42 42
 
43
-        if (sortParams.getFrom() > sortParams.getTo()) {
44
-            taTopicMapper.topicSortAdd(sortParams.getFrom(), sortParams.getTo());
43
+        TaTopic from = getById(sortParams.getFrom());
44
+        TaTopic to = getById(sortParams.getTo());
45
+
46
+        Integer source = from.getSortNo();
47
+        Integer target = to.getSortNo();
48
+
49
+        if (source > target) {
50
+            taTopicMapper.topicSortAdd(source, target);
45 51
         } else {
46
-            taTopicMapper.topicSortSub(sortParams.getFrom(), sortParams.getTo());
52
+            taTopicMapper.topicSortSub(source, target);
47 53
         }
48 54
 
49 55
         UpdateWrapper<TaTopic> updateWrapper = new UpdateWrapper<TaTopic>()
50
-                .set("sort_no", sortParams.getTo())
51
-                .eq("serial_no", sortParams.getId());
56
+                .set("sort_no", target)
57
+                .eq("serial_no", sortParams.getFrom());
52 58
         update(updateWrapper);
53 59
     }
54 60
 }

+ 2
- 5
src/main/java/com/yunzhi/demo/vo/SortParams.java Dosyayı Görüntüle

@@ -9,11 +9,8 @@ import lombok.Data;
9 9
 public class SortParams {
10 10
 
11 11
     @ApiModelProperty(value = "源排序")
12
-    private Integer from;
12
+    private String from;
13 13
 
14 14
     @ApiModelProperty(value = "目标排序")
15
-    private Integer to;
16
-
17
-    @ApiModelProperty(value = "数据ID")
18
-    private String id;
15
+    private String to;
19 16
 }