Your Name 4 年前
父节点
当前提交
07735364c6

+ 10
- 59
src/main/java/com/yunzhi/demo/controller/TaTopicController.java 查看文件

5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.yunzhi.demo.common.BaseController;
6
 import com.yunzhi.demo.common.BaseController;
7
 import com.yunzhi.demo.common.ResponseBean;
7
 import com.yunzhi.demo.common.ResponseBean;
8
+import com.yunzhi.demo.common.StringUtils;
8
 import com.yunzhi.demo.vo.SortParams;
9
 import com.yunzhi.demo.vo.SortParams;
9
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
80
         return ResponseBean.success(result);
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
      * @param taTopic 实体对象
86
      * @param taTopic 实体对象
105
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
90
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
106
     public ResponseBean topicAdd(@ApiParam("保存内容") @RequestBody TaTopic taTopic) throws Exception{
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
         if (iTaTopicService.save(taTopic)){
101
         if (iTaTopicService.save(taTopic)){
109
             return ResponseBean.success(taTopic);
102
             return ResponseBean.success(taTopic);
110
         }else {
103
         }else {
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
      * 根据id删除对象
109
      * 根据id删除对象
131
      * @param id  实体ID
110
      * @param id  实体ID
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
      * @param id  实体ID
124
      * @param id  实体ID
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
      * 根据id查询对象
141
      * 根据id查询对象
191
      * @param id  实体ID
142
      * @param id  实体ID
200
     @RequestMapping(value="/admin/sort/topic",method= RequestMethod.PUT)
151
     @RequestMapping(value="/admin/sort/topic",method= RequestMethod.PUT)
201
     @ApiOperation(value="排序", notes = "排序", httpMethod = "PUT", response = ResponseBean.class)
152
     @ApiOperation(value="排序", notes = "排序", httpMethod = "PUT", response = ResponseBean.class)
202
     public ResponseBean topicSort(@ApiParam("排序") @RequestBody SortParams sortParams) throws Exception {
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
             return ResponseBean.success("success");
155
             return ResponseBean.success("success");
205
         }
156
         }
206
 
157
 

+ 11
- 5
src/main/java/com/yunzhi/demo/service/impl/TaTopicServiceImpl.java 查看文件

40
             return;
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
         } else {
51
         } else {
46
-            taTopicMapper.topicSortSub(sortParams.getFrom(), sortParams.getTo());
52
+            taTopicMapper.topicSortSub(source, target);
47
         }
53
         }
48
 
54
 
49
         UpdateWrapper<TaTopic> updateWrapper = new UpdateWrapper<TaTopic>()
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
         update(updateWrapper);
58
         update(updateWrapper);
53
     }
59
     }
54
 }
60
 }

+ 2
- 5
src/main/java/com/yunzhi/demo/vo/SortParams.java 查看文件

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