张延森 4 anos atrás
pai
commit
ce8caec220

+ 2
- 2
src/main/java/com/yunzhi/demo/common/JWTUtils.java Ver arquivo

@@ -23,8 +23,8 @@ import java.util.Map;
23 23
 @Slf4j
24 24
 public class JWTUtils {
25 25
 
26
-    // 过期时间 10 分钟
27
-    public static final long EXPIRE_TIME = 10 * 60;
26
+    // 过期时间 30 分钟
27
+    public static final long EXPIRE_TIME = 30 * 60;
28 28
 
29 29
     // 私钥
30 30
     static final SecretKey SECRET_KEY = Keys.hmacShaKeyFor(Base64.getEncoder().encode("Yansen is so handsome. He is a good man. Everyone like him !!!".getBytes()));

+ 14
- 0
src/main/java/com/yunzhi/demo/controller/TaTopicController.java Ver arquivo

@@ -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.vo.SortParams;
8 9
 import io.swagger.annotations.Api;
9 10
 import io.swagger.annotations.ApiOperation;
10 11
 import io.swagger.annotations.ApiParam;
@@ -72,6 +73,7 @@ public class TaTopicController extends BaseController {
72 73
 
73 74
         IPage<TaTopic> pg = new Page<>(pageNum, pageSize);
74 75
         QueryWrapper<TaTopic> queryWrapper = new QueryWrapper<>();
76
+        queryWrapper.orderByAsc("sort_no");
75 77
         queryWrapper.orderByDesc("create_date");
76 78
 
77 79
         IPage<TaTopic> result = iTaTopicService.page(pg, queryWrapper);
@@ -193,4 +195,16 @@ public class TaTopicController extends BaseController {
193 195
     public ResponseBean topicGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
194 196
         return ResponseBean.success(iTaTopicService.getById(id));
195 197
     }
198
+
199
+
200
+    @RequestMapping(value="/admin/sort/topic",method= RequestMethod.PUT)
201
+    @ApiOperation(value="排序", notes = "排序", httpMethod = "PUT", response = ResponseBean.class)
202
+    public ResponseBean topicSort(@ApiParam("排序") @RequestBody SortParams sortParams) throws Exception {
203
+        if (null == sortParams.getFrom() || null == sortParams.getTo()) {
204
+            return ResponseBean.success("success");
205
+        }
206
+
207
+        iTaTopicService.reSort(sortParams);
208
+        return ResponseBean.success("success");
209
+    }
196 210
 }

+ 3
- 0
src/main/java/com/yunzhi/demo/mapper/TaTopicMapper.java Ver arquivo

@@ -15,4 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
15 15
 @Mapper
16 16
 public interface TaTopicMapper extends BaseMapper<TaTopic> {
17 17
 
18
+    int topicSortAdd(Integer max, Integer min);
19
+
20
+    int topicSortSub(Integer min, Integer max);
18 21
 }

+ 3
- 0
src/main/java/com/yunzhi/demo/service/ITaTopicService.java Ver arquivo

@@ -2,6 +2,7 @@ package com.yunzhi.demo.service;
2 2
 
3 3
 import com.yunzhi.demo.entity.TaTopic;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.yunzhi.demo.vo.SortParams;
5 6
 
6 7
 import java.util.List;
7 8
 
@@ -16,4 +17,6 @@ import java.util.List;
16 17
 public interface ITaTopicService extends IService<TaTopic> {
17 18
 
18 19
     List<TaTopic> getIndexList();
20
+
21
+    void reSort(SortParams sortParams);
19 22
 }

+ 23
- 0
src/main/java/com/yunzhi/demo/service/impl/TaTopicServiceImpl.java Ver arquivo

@@ -1,11 +1,14 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
4 5
 import com.yunzhi.demo.common.Constants;
5 6
 import com.yunzhi.demo.entity.TaTopic;
6 7
 import com.yunzhi.demo.mapper.TaTopicMapper;
7 8
 import com.yunzhi.demo.service.ITaTopicService;
8 9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
10
+import com.yunzhi.demo.vo.SortParams;
11
+import org.springframework.beans.factory.annotation.Autowired;
9 12
 import org.springframework.stereotype.Service;
10 13
 
11 14
 import java.util.List;
@@ -20,6 +23,8 @@ import java.util.List;
20 23
  */
21 24
 @Service
22 25
 public class TaTopicServiceImpl extends ServiceImpl<TaTopicMapper, TaTopic> implements ITaTopicService {
26
+    @Autowired
27
+    TaTopicMapper taTopicMapper;
23 28
 
24 29
     @Override
25 30
     public List<TaTopic> getIndexList() {
@@ -28,4 +33,22 @@ public class TaTopicServiceImpl extends ServiceImpl<TaTopicMapper, TaTopic> impl
28 33
                 .orderByAsc("sort_no");
29 34
         return list(queryWrapper);
30 35
     }
36
+
37
+    @Override
38
+    public void reSort(SortParams sortParams) {
39
+        if (sortParams.getFrom().equals(sortParams.getTo())) {
40
+            return;
41
+        }
42
+
43
+        if (sortParams.getFrom() > sortParams.getTo()) {
44
+            taTopicMapper.topicSortAdd(sortParams.getFrom(), sortParams.getTo());
45
+        } else {
46
+            taTopicMapper.topicSortSub(sortParams.getFrom(), sortParams.getTo());
47
+        }
48
+
49
+        UpdateWrapper<TaTopic> updateWrapper = new UpdateWrapper<TaTopic>()
50
+                .set("sort_no", sortParams.getTo())
51
+                .eq("serial_no", sortParams.getId());
52
+        update(updateWrapper);
53
+    }
31 54
 }

+ 19
- 0
src/main/java/com/yunzhi/demo/vo/SortParams.java Ver arquivo

@@ -0,0 +1,19 @@
1
+package com.yunzhi.demo.vo;
2
+
3
+import io.swagger.annotations.ApiModel;
4
+import io.swagger.annotations.ApiModelProperty;
5
+import lombok.Data;
6
+
7
+@ApiModel(description = "排序参数")
8
+@Data
9
+public class SortParams {
10
+
11
+    @ApiModelProperty(value = "源排序")
12
+    private Integer from;
13
+
14
+    @ApiModelProperty(value = "目标排序")
15
+    private Integer to;
16
+
17
+    @ApiModelProperty(value = "数据ID")
18
+    private String id;
19
+}

+ 16
- 0
src/main/resources/mapper/TaTopicMapper.xml Ver arquivo

@@ -2,4 +2,20 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.yunzhi.demo.mapper.TaTopicMapper">
4 4
 
5
+    <update id="topicSortAdd">
6
+        UPDATE ta_topic
7
+            SET sort_no = sort_no + 1
8
+        WHERE
9
+            `status` > - 1
10
+            AND sort_no &gt;= #{min}
11
+            AND sort_no &lt; #{max}
12
+    </update>
13
+    <update id="topicSortSub">
14
+        UPDATE ta_topic
15
+        SET sort_no = sort_no - 1
16
+        WHERE
17
+            `status` > - 1
18
+          AND sort_no &gt; #{min}
19
+          AND sort_no &lt;= #{max}
20
+    </update>
5 21
 </mapper>