Your Name 4 lat temu
rodzic
commit
1b68926c06
31 zmienionych plików z 549 dodań i 53 usunięć
  1. 64
    0
      src/main/java/com/yunzhi/demo/common/BaseController.java
  2. 4
    30
      src/main/java/com/yunzhi/demo/common/CurrentContext.java
  3. 60
    0
      src/main/java/com/yunzhi/demo/controller/MaIndexController.java
  4. 1
    2
      src/main/java/com/yunzhi/demo/controller/SysUserController.java
  5. 29
    7
      src/main/java/com/yunzhi/demo/controller/TaPersonController.java
  6. 69
    11
      src/main/java/com/yunzhi/demo/controller/TaPostController.java
  7. 128
    0
      src/main/java/com/yunzhi/demo/controller/WxMaController.java
  8. 4
    1
      src/main/java/com/yunzhi/demo/entity/TaPerson.java
  9. 4
    1
      src/main/java/com/yunzhi/demo/entity/TaPost.java
  10. 4
    1
      src/main/java/com/yunzhi/demo/interceptor/PermissionInterceptor.java
  11. 1
    0
      src/main/java/com/yunzhi/demo/mapper/TaPostDataMapper.java
  12. 1
    0
      src/main/java/com/yunzhi/demo/mapper/TaPostTestMapper.java
  13. 1
    0
      src/main/java/com/yunzhi/demo/mapper/TaReadLogMapper.java
  14. 3
    0
      src/main/java/com/yunzhi/demo/service/ISysBannerService.java
  15. 1
    0
      src/main/java/com/yunzhi/demo/service/ITaPersonService.java
  16. 2
    0
      src/main/java/com/yunzhi/demo/service/ITaPostDataService.java
  17. 1
    0
      src/main/java/com/yunzhi/demo/service/ITaPostSaveService.java
  18. 2
    0
      src/main/java/com/yunzhi/demo/service/ITaPostService.java
  19. 5
    0
      src/main/java/com/yunzhi/demo/service/ITaPostTestService.java
  20. 3
    0
      src/main/java/com/yunzhi/demo/service/ITaTopicService.java
  21. 11
    0
      src/main/java/com/yunzhi/demo/service/impl/SysBannerServiceImpl.java
  22. 9
    0
      src/main/java/com/yunzhi/demo/service/impl/TaPersonServiceImpl.java
  23. 31
    0
      src/main/java/com/yunzhi/demo/service/impl/TaPostDataServiceImpl.java
  24. 8
    0
      src/main/java/com/yunzhi/demo/service/impl/TaPostSaveServiceImpl.java
  25. 10
    0
      src/main/java/com/yunzhi/demo/service/impl/TaPostServiceImpl.java
  26. 21
    0
      src/main/java/com/yunzhi/demo/service/impl/TaPostTestServiceImpl.java
  27. 11
    0
      src/main/java/com/yunzhi/demo/service/impl/TaTopicServiceImpl.java
  28. 23
    0
      src/main/java/com/yunzhi/demo/vo/WxMaAuthParam.java
  29. 7
    0
      src/main/resources/mapper/TaPostDataMapper.xml
  30. 22
    0
      src/main/resources/mapper/TaPostTestMapper.xml
  31. 9
    0
      src/main/resources/mapper/TaReadLogMapper.xml

+ 64
- 0
src/main/java/com/yunzhi/demo/common/BaseController.java Wyświetl plik

@@ -1,4 +1,68 @@
1 1
 package com.yunzhi.demo.common;
2 2
 
3
+import com.yunzhi.demo.entity.SysUser;
4
+import com.yunzhi.demo.entity.TaPerson;
5
+import com.yunzhi.demo.service.ISysUserService;
6
+import com.yunzhi.demo.service.ITaPersonService;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.stereotype.Component;
9
+
10
+import java.util.Map;
11
+
12
+@Component
3 13
 public class BaseController {
14
+
15
+    @Autowired
16
+    ISysUserService iSysUserService;
17
+
18
+    @Autowired
19
+    ITaPersonService iTaPersonService;
20
+
21
+    /**
22
+     * 获取当前管理端人员
23
+     * @return
24
+     */
25
+    public SysUser getCurrentUser() {
26
+        Map<String, Object> tokenParam = CurrentContext.getTokenParam();
27
+        if (null == tokenParam) {
28
+            return null;
29
+        }
30
+
31
+        if (null != tokenParam.get("miniApp")) {
32
+            return null;
33
+        }
34
+
35
+        Object userId = tokenParam.get("userId");
36
+
37
+        SysUser sysUser = iSysUserService.getById((String) userId);
38
+        if (Constants.STATUS_DELETED.equals(sysUser.getStatus())) {
39
+            return null;
40
+        }
41
+
42
+        return sysUser;
43
+    }
44
+
45
+    /**
46
+     * 获取当前小程序端人员
47
+     * @return
48
+     */
49
+    public TaPerson getCurrentPerson() {
50
+        Map<String, Object> tokenParam = CurrentContext.getTokenParam();
51
+        if (null == tokenParam) {
52
+            return null;
53
+        }
54
+
55
+        if (null == tokenParam.get("miniApp")) {
56
+            return null;
57
+        }
58
+
59
+        Object personId = tokenParam.get("userId");
60
+
61
+        TaPerson taPerson = iTaPersonService.getById((String) personId);
62
+        if (Constants.STATUS_DELETED.equals(taPerson.getStatus())) {
63
+            return null;
64
+        }
65
+
66
+        return taPerson;
67
+    }
4 68
 }

+ 4
- 30
src/main/java/com/yunzhi/demo/common/CurrentContext.java Wyświetl plik

@@ -1,46 +1,20 @@
1 1
 package com.yunzhi.demo.common;
2 2
 
3
-import com.yunzhi.demo.entity.SysUser;
4
-import com.yunzhi.demo.service.ISysUserService;
5
-import com.yunzhi.demo.vo.TokenParam;
3
+import java.util.Map;
6 4
 
7 5
 public class CurrentContext {
8 6
 
9 7
     /**
10 8
      * TokenParam 相关
11 9
      */
12
-    private static final ThreadLocal<TokenParam> tokenParamHolder = new ThreadLocal<>();
10
+    private static final ThreadLocal<Map<String, Object>> tokenParamHolder = new ThreadLocal<>();
13 11
 
14
-    public static void setTokenParam(TokenParam tokenParam) {
12
+    public static void setTokenParam(Map<String, Object> tokenParam) {
15 13
         tokenParamHolder.remove();
16 14
         tokenParamHolder.set(tokenParam);
17 15
     }
18 16
 
19
-    public static TokenParam getTokenParam() {
17
+    public static Map<String, Object> getTokenParam() {
20 18
         return tokenParamHolder.get();
21 19
     }
22
-
23
-    /**
24
-     * 获取当前请求用户
25
-     * @param iSysUserService
26
-     * @return
27
-     */
28
-    public static SysUser getCurrentUser(ISysUserService iSysUserService) {
29
-        try {
30
-            TokenParam tokenParam = getTokenParam();
31
-            if (null == tokenParam) {
32
-                return null;
33
-            }
34
-
35
-            SysUser sysUser = iSysUserService.getById(tokenParam.getUserId());
36
-            if (null == sysUser || Constants.STATUS_DELETED.equals(sysUser.getStatus())) {
37
-                return null;
38
-            }
39
-
40
-            return sysUser;
41
-        } catch (Exception e) {
42
-            e.printStackTrace();
43
-            return null;
44
-        }
45
-    }
46 20
 }

+ 60
- 0
src/main/java/com/yunzhi/demo/controller/MaIndexController.java Wyświetl plik

@@ -0,0 +1,60 @@
1
+package com.yunzhi.demo.controller;
2
+
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
+import com.yunzhi.demo.common.BaseController;
6
+import com.yunzhi.demo.common.ResponseBean;
7
+import com.yunzhi.demo.entity.SysBanner;
8
+import com.yunzhi.demo.entity.TaPost;
9
+import com.yunzhi.demo.entity.TaTopic;
10
+import com.yunzhi.demo.service.ISysBannerService;
11
+import com.yunzhi.demo.service.ITaPostService;
12
+import com.yunzhi.demo.service.ITaTopicService;
13
+import io.swagger.annotations.Api;
14
+import io.swagger.annotations.ApiOperation;
15
+import io.swagger.annotations.ApiParam;
16
+import org.springframework.beans.factory.annotation.Autowired;
17
+import org.springframework.web.bind.annotation.GetMapping;
18
+import org.springframework.web.bind.annotation.RequestMapping;
19
+import org.springframework.web.bind.annotation.RequestParam;
20
+import org.springframework.web.bind.annotation.RestController;
21
+
22
+import java.util.List;
23
+
24
+@Api(tags = "小程序首页")
25
+@RestController
26
+@RequestMapping("/ma/index")
27
+public class MaIndexController extends BaseController {
28
+
29
+    @Autowired
30
+    ISysBannerService iSysBannerService;
31
+
32
+    @Autowired
33
+    ITaTopicService iTaTopicService;
34
+
35
+    @Autowired
36
+    ITaPostService iTaPostService;
37
+
38
+    @GetMapping("/banner")
39
+    @ApiOperation(value="Banner列表", notes = "Banner列表", httpMethod = "GET", response = SysBanner.class)
40
+    public ResponseBean getBannerList() throws Exception {
41
+        List<SysBanner> bannerList = iSysBannerService.getIndexList();
42
+        return ResponseBean.success(bannerList);
43
+    }
44
+
45
+    @GetMapping("/topic")
46
+    @ApiOperation(value="热门列表", notes = "热门列表", httpMethod = "GET", response = TaTopic.class)
47
+    public ResponseBean getTopicList() throws Exception {
48
+        List<TaTopic> topicList = iTaTopicService.getIndexList();
49
+        return ResponseBean.success(topicList);
50
+    }
51
+
52
+    @GetMapping("/post")
53
+    @ApiOperation(value="最新文章", notes = "最新文章", httpMethod = "GET", response = TaPost.class)
54
+    public ResponseBean getPostList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
55
+                                    @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
56
+        IPage<TaPost> page = new Page<>(pageNum, pageSize);
57
+        IPage<TaPost> postList = iTaPostService.getIndexList(page);
58
+        return ResponseBean.success(postList);
59
+    }
60
+}

+ 1
- 2
src/main/java/com/yunzhi/demo/controller/SysUserController.java Wyświetl plik

@@ -135,12 +135,11 @@ public class SysUserController extends BaseController {
135 135
 
136 136
     /**
137 137
      * 当前用户
138
-     * @param id  实体ID
139 138
      */
140 139
     @RequestMapping(value="/admin/currentUser",method= RequestMethod.GET)
141 140
     @ApiOperation(value="当前用户", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
142 141
     public ResponseBean currentUser() throws Exception{
143
-        SysUser sysUser = CurrentContext.getCurrentUser(iSysUserService);
142
+        SysUser sysUser = getCurrentUser();
144 143
         List<SysMenu> sysMenuList = iSysMenuService.getListWithRoles();
145 144
         List<SysUserRole> sysUserRoleList = iSysUserRoleService.getListByUser(sysUser.getUserId());
146 145
 

+ 29
- 7
src/main/java/com/yunzhi/demo/controller/TaPersonController.java Wyświetl plik

@@ -5,20 +5,21 @@ 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.entity.TaPersonData;
9
+import com.yunzhi.demo.service.ITaPersonDataService;
10
+import com.yunzhi.demo.service.ITaPostDataService;
8 11
 import io.swagger.annotations.Api;
9 12
 import io.swagger.annotations.ApiOperation;
10 13
 import io.swagger.annotations.ApiParam;
11 14
 import org.slf4j.Logger;
12 15
 import org.slf4j.LoggerFactory;
13 16
 import org.springframework.beans.factory.annotation.Autowired;
14
-import org.springframework.web.bind.annotation.PathVariable;
15
-import org.springframework.web.bind.annotation.RequestBody;
16
-import org.springframework.web.bind.annotation.RequestMapping;
17
-import org.springframework.web.bind.annotation.RequestMethod;
18
-import org.springframework.web.bind.annotation.RequestParam;
17
+import org.springframework.web.bind.annotation.*;
19 18
 import com.yunzhi.demo.service.ITaPersonService;
20 19
 import com.yunzhi.demo.entity.TaPerson;
21
-import org.springframework.web.bind.annotation.RestController;
20
+
21
+import java.util.HashMap;
22
+import java.util.Map;
22 23
 
23 24
 /**
24 25
  * <p>
@@ -37,8 +38,10 @@ public class TaPersonController extends BaseController {
37 38
     private final Logger logger = LoggerFactory.getLogger(TaPersonController.class);
38 39
 
39 40
     @Autowired
40
-    public ITaPersonService iTaPersonService;
41
+    ITaPersonService iTaPersonService;
41 42
 
43
+    @Autowired
44
+    ITaPersonDataService iTaPersonDataService;
42 45
 
43 46
     /**
44 47
      * 分页查询列表
@@ -116,4 +119,23 @@ public class TaPersonController extends BaseController {
116 119
     public ResponseBean taPersonGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117 120
         return ResponseBean.success(iTaPersonService.getById(id));
118 121
     }
122
+
123
+    @GetMapping("/ma/currentPerson")
124
+    @ApiOperation(value="获取当前人员信息", notes = "获取当前人员信息", httpMethod = "GET", response = TaPerson.class)
125
+    public ResponseBean getCurrent() throws Exception {
126
+        Map<String, Object> result = new HashMap<>();
127
+
128
+        TaPerson taPerson = getCurrentPerson();
129
+        if (null == taPerson) {
130
+            throw new Exception("验证人员信息失败, 请退出重试");
131
+        }
132
+
133
+        // 获取统计数据
134
+        TaPersonData taPersonData = iTaPersonDataService.getById(taPerson.getPersonId());
135
+
136
+        result.put("person", taPerson);
137
+        result.put("personData", taPersonData);
138
+
139
+        return ResponseBean.success(taPersonData);
140
+    }
119 141
 }

+ 69
- 11
src/main/java/com/yunzhi/demo/controller/TaPostController.java Wyświetl plik

@@ -7,8 +7,8 @@ import com.yunzhi.demo.common.BaseController;
7 7
 import com.yunzhi.demo.common.Constants;
8 8
 import com.yunzhi.demo.common.ResponseBean;
9 9
 import com.yunzhi.demo.common.StringUtils;
10
-import com.yunzhi.demo.entity.TdPostType;
11
-import com.yunzhi.demo.service.ITdPostTypeService;
10
+import com.yunzhi.demo.entity.*;
11
+import com.yunzhi.demo.service.*;
12 12
 import io.swagger.annotations.Api;
13 13
 import io.swagger.annotations.ApiOperation;
14 14
 import io.swagger.annotations.ApiParam;
@@ -20,10 +20,13 @@ import org.springframework.web.bind.annotation.RequestBody;
20 20
 import org.springframework.web.bind.annotation.RequestMapping;
21 21
 import org.springframework.web.bind.annotation.RequestMethod;
22 22
 import org.springframework.web.bind.annotation.RequestParam;
23
-import com.yunzhi.demo.service.ITaPostService;
24
-import com.yunzhi.demo.entity.TaPost;
25 23
 import org.springframework.web.bind.annotation.RestController;
26 24
 
25
+import java.util.ArrayList;
26
+import java.util.HashMap;
27
+import java.util.List;
28
+import java.util.Map;
29
+
27 30
 /**
28 31
  * <p>
29 32
     * 文章表 前端控制器
@@ -46,6 +49,15 @@ public class TaPostController extends BaseController {
46 49
     @Autowired
47 50
     public ITdPostTypeService iTdPostTypeService;
48 51
 
52
+    @Autowired
53
+    public ITaPostDataService iTaPostDataService;
54
+
55
+    @Autowired
56
+    public ITaPostTestService iTaPostTestService;
57
+
58
+    @Autowired
59
+    public ITaPostSaveService iTaPostSaveService;
60
+
49 61
 
50 62
     /**
51 63
      * 分页查询列表
@@ -53,9 +65,10 @@ public class TaPostController extends BaseController {
53 65
      * @param pageSize
54 66
      * @return
55 67
      */
56
-    @RequestMapping(value="/admin/post",method= RequestMethod.GET)
68
+    @RequestMapping(value="/{client}/post",method= RequestMethod.GET)
57 69
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
58
-    public ResponseBean taPostList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
70
+    public ResponseBean taPostList(@ApiParam(value = "客户端", allowableValues = "admin,ma") @PathVariable String client,
71
+                                   @ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
59 72
                                    @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
60 73
                                    @ApiParam("名称") @RequestParam(value = "name", required = false) String name,
61 74
                                    @ApiParam("分类") @RequestParam(value = "typeId", required = false) String typeId,
@@ -89,6 +102,10 @@ public class TaPostController extends BaseController {
89 102
         }
90 103
 
91 104
         if (iTaPostService.save(taPost)){
105
+            TaPostData postData = new TaPostData();
106
+            postData.setPostId(taPost.getPostId());
107
+            iTaPostDataService.save(postData);
108
+
92 109
             return ResponseBean.success(iTaPostService.getById(taPost.getPostId()));
93 110
         }else {
94 111
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -133,12 +150,53 @@ public class TaPostController extends BaseController {
133 150
     }
134 151
 
135 152
     /**
136
-     * 根据id查询对象
153
+     * 根据id查询文章详情
137 154
      * @param id  实体ID
138 155
      */
139
-    @RequestMapping(value="/admin/post/{id}",method= RequestMethod.GET)
140
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
141
-    public ResponseBean taPostGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
142
-        return ResponseBean.success(iTaPostService.getById(id));
156
+    @RequestMapping(value="/{client}/post/{id}",method= RequestMethod.GET)
157
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = TaPost.class)
158
+    public ResponseBean taPostGet(@ApiParam(value = "客户端", allowableValues = "admin,ma") @PathVariable String client,
159
+                                  @ApiParam("文章ID") @PathVariable String id) throws Exception{
160
+
161
+        Map<String, Object> result = new HashMap<>();
162
+
163
+        // 获取文章信息
164
+        TaPost taPost = iTaPostService.getById(id);
165
+        if (null == taPost || Constants.STATUS_DELETED.equals(taPost.getStatus())) {
166
+            throw new Exception("文章内容不存在");
167
+        }
168
+
169
+        // 获取统计信息
170
+        TaPostData taPostData = iTaPostDataService.getById(id);
171
+
172
+
173
+        // 获取试题
174
+        List<TaPostTest> postTestList = new ArrayList<>();
175
+        if ("admin".equals(client)) {
176
+            postTestList = iTaPostTestService.getListByPostId(id);
177
+        } else {
178
+            // 当前人员是否收藏过
179
+            TaPerson taPerson = getCurrentPerson();
180
+            boolean saved = iTaPostSaveService.checkSaved(taPerson.getPersonId(), id);
181
+            result.put("saved", saved);
182
+
183
+            // 埋点数据
184
+            iTaPostDataService.recordBy(id, taPerson);
185
+
186
+            // 随机取题目
187
+            if (null != taPost.getAnswerNum() && taPost.getAnswerNum() > 0) {
188
+                for (int i = 0; i < taPost.getAnswerNum(); i++) {
189
+                    TaPostTest taPostTest = iTaPostTestService.getRandRowBy(id);
190
+                    taPostTest.setCorrectAnswers(null);
191
+                    postTestList.add(taPostTest);
192
+                }
193
+            }
194
+        }
195
+
196
+        result.put("post", taPost);
197
+        result.put("postData", taPostData);
198
+        result.put("postTest", postTestList);
199
+
200
+        return ResponseBean.success(result);
143 201
     }
144 202
 }

+ 128
- 0
src/main/java/com/yunzhi/demo/controller/WxMaController.java Wyświetl plik

@@ -0,0 +1,128 @@
1
+package com.yunzhi.demo.controller;
2
+
3
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
4
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
5
+import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
6
+import com.yunzhi.demo.common.*;
7
+import com.yunzhi.demo.entity.TaPerson;
8
+import com.yunzhi.demo.entity.TaPersonData;
9
+import com.yunzhi.demo.service.ITaPersonDataService;
10
+import com.yunzhi.demo.service.ITaPersonService;
11
+import com.yunzhi.demo.vo.WxMaAuthParam;
12
+import io.swagger.annotations.Api;
13
+import io.swagger.annotations.ApiOperation;
14
+import io.swagger.annotations.ApiParam;
15
+import org.springframework.beans.factory.annotation.Autowired;
16
+import org.springframework.web.bind.annotation.*;
17
+
18
+import java.util.HashMap;
19
+import java.util.Map;
20
+
21
+
22
+@Api(tags = "微信小程序")
23
+@RestController
24
+@RequestMapping("/ma")
25
+public class WxMaController extends BaseController {
26
+
27
+    @Autowired
28
+    WxUtils wxUtils;
29
+
30
+    @Autowired
31
+    ITaPersonService iTaPersonService;
32
+
33
+    @Autowired
34
+    ITaPersonDataService iTaPersonDataService;
35
+
36
+    @PostMapping("/login")
37
+    @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
38
+    public ResponseBean login(@ApiParam("登录参数") String code) throws Exception {
39
+        WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(code);
40
+
41
+        String openid = info.getOpenid();
42
+        TaPerson taPerson = iTaPersonService.getByOpenid(openid);
43
+        if (null == taPerson) {
44
+            taPerson = new TaPerson();
45
+            taPerson.setOpenid(openid);
46
+            iTaPersonService.save(taPerson);
47
+
48
+            TaPersonData taPersonData = new TaPersonData();
49
+            taPersonData.setPersonId(taPerson.getPersonId());
50
+            iTaPersonDataService.save(taPersonData);
51
+        }
52
+
53
+        Map<String, Object> tokenClaims = new HashMap<>();
54
+        tokenClaims.put("userId", taPerson.getPersonId());
55
+        tokenClaims.put("sessionKey", info.getSessionKey());
56
+        tokenClaims.put("miniApp", true);
57
+        String token = JWTUtils.encode(tokenClaims);
58
+
59
+        Map<String, Object> rtn = new HashMap<>();
60
+        rtn.put("person", taPerson);
61
+        rtn.put("token", token);
62
+
63
+        return ResponseBean.success(rtn);
64
+    }
65
+
66
+    @PutMapping("/auth-user")
67
+    @ApiOperation(value="授权头像", notes = "授权头像", httpMethod = "POST", response = TaPerson.class)
68
+    public ResponseBean updateUserInfo(@ApiParam("授权头像的参数") @RequestBody WxMaAuthParam params) throws Exception {
69
+        String sessionKey = (String) CurrentContext.getTokenParam().get("sessionKey");
70
+
71
+        checkAuthParams(params, sessionKey);
72
+
73
+        // 解密用户信息
74
+        WxMaUserInfo userInfo = wxUtils.getService().getUserService().getUserInfo(sessionKey, params.getEncryptedData(), params.getIv());
75
+
76
+        TaPerson taPerson = getCurrentPerson();
77
+        if (null == taPerson) {
78
+            throw new Exception("校验当前人员失败, 请重试");
79
+        }
80
+
81
+        taPerson.setAvatar(userInfo.getAvatarUrl());
82
+        taPerson.setNickName(userInfo.getNickName());
83
+        taPerson.setSex("1".equals(userInfo.getGender()) ? 1 : 2);
84
+
85
+        iTaPersonService.updateById(taPerson);
86
+
87
+        return ResponseBean.success(taPerson);
88
+    }
89
+
90
+    @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "POST", response = TaPerson.class)
91
+    @PutMapping("/auth-phone")
92
+    public ResponseBean updateUserPhone(@ApiParam("授权手机的参数") @RequestBody WxMaAuthParam params) throws Exception {
93
+        String sessionKey = (String) CurrentContext.getTokenParam().get("sessionKey");
94
+
95
+        checkAuthParams(params, sessionKey);
96
+
97
+        // 解密
98
+        WxMaPhoneNumberInfo phoneNoInfo = wxUtils.getService().getUserService().getPhoneNoInfo(sessionKey, params.getEncryptedData(), params.getIv());
99
+
100
+        TaPerson taPerson = getCurrentPerson();
101
+        if (null == taPerson) {
102
+            throw new Exception("校验当前人员失败, 请重试");
103
+        }
104
+
105
+        taPerson.setPhone(phoneNoInfo.getPhoneNumber());
106
+        iTaPersonService.updateById(taPerson);
107
+
108
+        return ResponseBean.success(taPerson);
109
+    }
110
+
111
+    private void checkAuthParams(WxMaAuthParam params, String sessionKey) throws Exception {
112
+        String signature = params.getSignature();
113
+        String rawData = params.getRawData();
114
+        String encryptedData = params.getEncryptedData();
115
+        String iv = params.getIv();
116
+
117
+        if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(rawData) || StringUtils.isEmpty(encryptedData) || StringUtils.isEmpty(iv)) {
118
+            throw new Exception("缺失授权参数");
119
+        }
120
+
121
+        boolean isValid = wxUtils.getService().getUserService().checkUserInfo(sessionKey, rawData, signature);
122
+        if (!isValid) {
123
+            throw new Exception("校验授权参数失败, 请重试");
124
+        }
125
+
126
+        return;
127
+    }
128
+}

+ 4
- 1
src/main/java/com/yunzhi/demo/entity/TaPerson.java Wyświetl plik

@@ -27,9 +27,12 @@ public class TaPerson implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "人员ID")
30
-    @TableId(value = "person_id", type = IdType.INPUT)
30
+    @TableId(value = "person_id", type = IdType.UUID)
31 31
     private String personId;
32 32
 
33
+    @ApiModelProperty(value = "openid")
34
+    private String openid;
35
+
33 36
     @ApiModelProperty(value = "姓名")
34 37
     private String name;
35 38
 

+ 4
- 1
src/main/java/com/yunzhi/demo/entity/TaPost.java Wyświetl plik

@@ -2,8 +2,12 @@ package com.yunzhi.demo.entity;
2 2
 
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import java.time.LocalDateTime;
5
+
6
+import com.baomidou.mybatisplus.annotation.TableField;
5 7
 import com.baomidou.mybatisplus.annotation.TableId;
6 8
 import java.io.Serializable;
9
+import java.util.List;
10
+
7 11
 import io.swagger.annotations.ApiModel;
8 12
 import io.swagger.annotations.ApiModelProperty;
9 13
 import lombok.Data;
@@ -84,5 +88,4 @@ public class TaPost implements Serializable {
84 88
     @ApiModelProperty(value = "更新时间")
85 89
     private LocalDateTime updateDate;
86 90
 
87
-
88 91
 }

+ 4
- 1
src/main/java/com/yunzhi/demo/interceptor/PermissionInterceptor.java Wyświetl plik

@@ -5,8 +5,11 @@ import com.yunzhi.demo.common.CurrentContext;
5 5
 import com.yunzhi.demo.common.JWTUtils;
6 6
 import com.yunzhi.demo.common.ResponseBean;
7 7
 import com.yunzhi.demo.common.StringUtils;
8
+import com.yunzhi.demo.service.ISysUserService;
9
+import com.yunzhi.demo.service.ITaPersonService;
8 10
 import com.yunzhi.demo.vo.TokenParam;
9 11
 import lombok.extern.slf4j.Slf4j;
12
+import org.springframework.beans.factory.annotation.Autowired;
10 13
 import org.springframework.stereotype.Component;
11 14
 import org.springframework.web.servlet.HandlerInterceptor;
12 15
 import org.springframework.web.servlet.ModelAndView;
@@ -34,7 +37,7 @@ public class PermissionInterceptor implements HandlerInterceptor {
34 37
 
35 38
         try {
36 39
             Map<String, Object> tokenMap = JWTUtils.decode(jws);
37
-            CurrentContext.setTokenParam(TokenParam.fromMap(tokenMap));
40
+            CurrentContext.setTokenParam(tokenMap);
38 41
         } catch (Exception e) {
39 42
             log.error("鉴权失败: {}", e.getMessage());
40 43
             responseTokenError(response, "鉴权失败, 请重新登录");

+ 1
- 0
src/main/java/com/yunzhi/demo/mapper/TaPostDataMapper.java Wyświetl plik

@@ -15,4 +15,5 @@ import org.apache.ibatis.annotations.Mapper;
15 15
 @Mapper
16 16
 public interface TaPostDataMapper extends BaseMapper<TaPostData> {
17 17
 
18
+    int updatePvUvBy(String postId, int addUv, int addPv);
18 19
 }

+ 1
- 0
src/main/java/com/yunzhi/demo/mapper/TaPostTestMapper.java Wyświetl plik

@@ -15,4 +15,5 @@ import org.apache.ibatis.annotations.Mapper;
15 15
 @Mapper
16 16
 public interface TaPostTestMapper extends BaseMapper<TaPostTest> {
17 17
 
18
+    TaPostTest getRandRowBy(String postId);
18 19
 }

+ 1
- 0
src/main/java/com/yunzhi/demo/mapper/TaReadLogMapper.java Wyświetl plik

@@ -15,4 +15,5 @@ import org.apache.ibatis.annotations.Mapper;
15 15
 @Mapper
16 16
 public interface TaReadLogMapper extends BaseMapper<TaReadLog> {
17 17
 
18
+    int countBy(String personId, String postId);
18 19
 }

+ 3
- 0
src/main/java/com/yunzhi/demo/service/ISysBannerService.java Wyświetl plik

@@ -3,6 +3,8 @@ package com.yunzhi.demo.service;
3 3
 import com.yunzhi.demo.entity.SysBanner;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * <p>
8 10
  * 广告栏 服务类
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 15
  */
14 16
 public interface ISysBannerService extends IService<SysBanner> {
15 17
 
18
+    List<SysBanner> getIndexList();
16 19
 }

+ 1
- 0
src/main/java/com/yunzhi/demo/service/ITaPersonService.java Wyświetl plik

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 13
  */
14 14
 public interface ITaPersonService extends IService<TaPerson> {
15 15
 
16
+    TaPerson getByOpenid(String openid);
16 17
 }

+ 2
- 0
src/main/java/com/yunzhi/demo/service/ITaPostDataService.java Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 package com.yunzhi.demo.service;
2 2
 
3
+import com.yunzhi.demo.entity.TaPerson;
3 4
 import com.yunzhi.demo.entity.TaPostData;
4 5
 import com.baomidou.mybatisplus.extension.service.IService;
5 6
 
@@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 14
  */
14 15
 public interface ITaPostDataService extends IService<TaPostData> {
15 16
 
17
+    void recordBy(String postId, TaPerson taPerson);
16 18
 }

+ 1
- 0
src/main/java/com/yunzhi/demo/service/ITaPostSaveService.java Wyświetl plik

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 13
  */
14 14
 public interface ITaPostSaveService extends IService<TaPostSave> {
15 15
 
16
+    boolean checkSaved(String personId, String postId);
16 17
 }

+ 2
- 0
src/main/java/com/yunzhi/demo/service/ITaPostService.java Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 package com.yunzhi.demo.service;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.yunzhi.demo.entity.TaPost;
4 5
 import com.baomidou.mybatisplus.extension.service.IService;
5 6
 
@@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 14
  */
14 15
 public interface ITaPostService extends IService<TaPost> {
15 16
 
17
+    IPage<TaPost> getIndexList(IPage<TaPost> page);
16 18
 }

+ 5
- 0
src/main/java/com/yunzhi/demo/service/ITaPostTestService.java Wyświetl plik

@@ -3,6 +3,8 @@ package com.yunzhi.demo.service;
3 3
 import com.yunzhi.demo.entity.TaPostTest;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * <p>
8 10
  * 题库 服务类
@@ -13,4 +15,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 15
  */
14 16
 public interface ITaPostTestService extends IService<TaPostTest> {
15 17
 
18
+    List<TaPostTest> getListByPostId(String postId);
19
+
20
+    TaPostTest getRandRowBy(String postId);
16 21
 }

+ 3
- 0
src/main/java/com/yunzhi/demo/service/ITaTopicService.java Wyświetl plik

@@ -3,6 +3,8 @@ package com.yunzhi.demo.service;
3 3
 import com.yunzhi.demo.entity.TaTopic;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * <p>
8 10
  * 热门 服务类
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 15
  */
14 16
 public interface ITaTopicService extends IService<TaTopic> {
15 17
 
18
+    List<TaTopic> getIndexList();
16 19
 }

+ 11
- 0
src/main/java/com/yunzhi/demo/service/impl/SysBannerServiceImpl.java Wyświetl plik

@@ -1,11 +1,15 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.demo.common.Constants;
3 5
 import com.yunzhi.demo.entity.SysBanner;
4 6
 import com.yunzhi.demo.mapper.SysBannerMapper;
5 7
 import com.yunzhi.demo.service.ISysBannerService;
6 8
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 9
 import org.springframework.stereotype.Service;
8 10
 
11
+import java.util.List;
12
+
9 13
 /**
10 14
  * <p>
11 15
  * 广告栏 服务实现类
@@ -17,4 +21,11 @@ import org.springframework.stereotype.Service;
17 21
 @Service
18 22
 public class SysBannerServiceImpl extends ServiceImpl<SysBannerMapper, SysBanner> implements ISysBannerService {
19 23
 
24
+    @Override
25
+    public List<SysBanner> getIndexList() {
26
+        QueryWrapper<SysBanner> queryWrapper = new QueryWrapper<SysBanner>()
27
+                .eq("status", Constants.STATUS_NORMAL)
28
+                .orderByAsc("sort_no");
29
+        return list(queryWrapper);
30
+    }
20 31
 }

+ 9
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPersonServiceImpl.java Wyświetl plik

@@ -1,5 +1,7 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.demo.common.Constants;
3 5
 import com.yunzhi.demo.entity.TaPerson;
4 6
 import com.yunzhi.demo.mapper.TaPersonMapper;
5 7
 import com.yunzhi.demo.service.ITaPersonService;
@@ -17,4 +19,11 @@ import org.springframework.stereotype.Service;
17 19
 @Service
18 20
 public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
19 21
 
22
+    @Override
23
+    public TaPerson getByOpenid(String openid) {
24
+        QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<TaPerson>()
25
+                .eq("openid", openid)
26
+                .gt("status", Constants.STATUS_DELETED);
27
+        return getOne(queryWrapper);
28
+    }
20 29
 }

+ 31
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostDataServiceImpl.java Wyświetl plik

@@ -1,9 +1,15 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.demo.entity.TaPerson;
3 5
 import com.yunzhi.demo.entity.TaPostData;
6
+import com.yunzhi.demo.entity.TaReadLog;
4 7
 import com.yunzhi.demo.mapper.TaPostDataMapper;
8
+import com.yunzhi.demo.mapper.TaReadLogMapper;
5 9
 import com.yunzhi.demo.service.ITaPostDataService;
6 10
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.scheduling.annotation.Async;
7 13
 import org.springframework.stereotype.Service;
8 14
 
9 15
 /**
@@ -17,4 +23,29 @@ import org.springframework.stereotype.Service;
17 23
 @Service
18 24
 public class TaPostDataServiceImpl extends ServiceImpl<TaPostDataMapper, TaPostData> implements ITaPostDataService {
19 25
 
26
+    @Autowired
27
+    TaPostDataMapper taPostDataMapper;
28
+
29
+    @Autowired
30
+    TaReadLogMapper taReadLogMapper;
31
+
32
+    @Async
33
+    @Override
34
+    public void recordBy(String postId, TaPerson taPerson) {
35
+        // 先查询当前人员以前有没有阅读过
36
+        int cnt = taReadLogMapper.countBy(taPerson.getPersonId(), postId);
37
+
38
+        int addPv = 1;
39
+        int addUv = cnt > 0 ? 0 : 1;
40
+
41
+        taPostDataMapper.updatePvUvBy(postId, addUv, addPv);
42
+
43
+        // 如果当前人员以前未读过
44
+        if (cnt == 0) {
45
+            TaReadLog taReadLog = new TaReadLog();
46
+            taReadLog.setPostId(postId);
47
+            taReadLog.setPersonId(taPerson.getPersonId());
48
+            taReadLogMapper.insert(taReadLog);
49
+        }
50
+    }
20 51
 }

+ 8
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostSaveServiceImpl.java Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.yunzhi.demo.entity.TaPostSave;
4 5
 import com.yunzhi.demo.mapper.TaPostSaveMapper;
5 6
 import com.yunzhi.demo.service.ITaPostSaveService;
@@ -17,4 +18,11 @@ import org.springframework.stereotype.Service;
17 18
 @Service
18 19
 public class TaPostSaveServiceImpl extends ServiceImpl<TaPostSaveMapper, TaPostSave> implements ITaPostSaveService {
19 20
 
21
+    @Override
22
+    public boolean checkSaved(String personId, String postId) {
23
+        QueryWrapper<TaPostSave> queryWrapper = new QueryWrapper<TaPostSave>()
24
+                .eq("person_id", personId)
25
+                .eq("post_id", postId);
26
+        return count(queryWrapper) > 0;
27
+    }
20 28
 }

+ 10
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostServiceImpl.java Wyświetl plik

@@ -1,5 +1,8 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.yunzhi.demo.common.Constants;
3 6
 import com.yunzhi.demo.entity.TaPost;
4 7
 import com.yunzhi.demo.mapper.TaPostMapper;
5 8
 import com.yunzhi.demo.service.ITaPostService;
@@ -17,4 +20,11 @@ import org.springframework.stereotype.Service;
17 20
 @Service
18 21
 public class TaPostServiceImpl extends ServiceImpl<TaPostMapper, TaPost> implements ITaPostService {
19 22
 
23
+    @Override
24
+    public IPage<TaPost> getIndexList(IPage<TaPost> page) {
25
+        QueryWrapper<TaPost> queryWrapper = new QueryWrapper<TaPost>()
26
+                .eq("status", Constants.STATUS_NORMAL)
27
+                .orderByDesc("create_date");
28
+        return page(page, queryWrapper);
29
+    }
20 30
 }

+ 21
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostTestServiceImpl.java Wyświetl plik

@@ -1,11 +1,16 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.demo.common.Constants;
3 5
 import com.yunzhi.demo.entity.TaPostTest;
4 6
 import com.yunzhi.demo.mapper.TaPostTestMapper;
5 7
 import com.yunzhi.demo.service.ITaPostTestService;
6 8
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
9
+import org.springframework.beans.factory.annotation.Autowired;
7 10
 import org.springframework.stereotype.Service;
8 11
 
12
+import java.util.List;
13
+
9 14
 /**
10 15
  * <p>
11 16
  * 题库 服务实现类
@@ -17,4 +22,20 @@ import org.springframework.stereotype.Service;
17 22
 @Service
18 23
 public class TaPostTestServiceImpl extends ServiceImpl<TaPostTestMapper, TaPostTest> implements ITaPostTestService {
19 24
 
25
+    @Autowired
26
+    TaPostTestMapper taPostTestMapper;
27
+
28
+    @Override
29
+    public List<TaPostTest> getListByPostId(String postId) {
30
+        QueryWrapper<TaPostTest> queryWrapper = new QueryWrapper<TaPostTest>()
31
+                .eq("post_id", postId)
32
+                .gt("status", Constants.STATUS_DELETED)
33
+                .orderByDesc("create_date");
34
+        return list(queryWrapper);
35
+    }
36
+
37
+    @Override
38
+    public TaPostTest getRandRowBy(String postId) {
39
+        return taPostTestMapper.getRandRowBy(postId);
40
+    }
20 41
 }

+ 11
- 0
src/main/java/com/yunzhi/demo/service/impl/TaTopicServiceImpl.java Wyświetl plik

@@ -1,11 +1,15 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.demo.common.Constants;
3 5
 import com.yunzhi.demo.entity.TaTopic;
4 6
 import com.yunzhi.demo.mapper.TaTopicMapper;
5 7
 import com.yunzhi.demo.service.ITaTopicService;
6 8
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 9
 import org.springframework.stereotype.Service;
8 10
 
11
+import java.util.List;
12
+
9 13
 /**
10 14
  * <p>
11 15
  * 热门 服务实现类
@@ -17,4 +21,11 @@ import org.springframework.stereotype.Service;
17 21
 @Service
18 22
 public class TaTopicServiceImpl extends ServiceImpl<TaTopicMapper, TaTopic> implements ITaTopicService {
19 23
 
24
+    @Override
25
+    public List<TaTopic> getIndexList() {
26
+        QueryWrapper<TaTopic> queryWrapper = new QueryWrapper<TaTopic>()
27
+                .eq("status", Constants.STATUS_NORMAL)
28
+                .orderByAsc("sort_no");
29
+        return list(queryWrapper);
30
+    }
20 31
 }

+ 23
- 0
src/main/java/com/yunzhi/demo/vo/WxMaAuthParam.java Wyświetl plik

@@ -0,0 +1,23 @@
1
+package com.yunzhi.demo.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(value = "微信小程序授权", description = "微信小程序授权参数")
9
+@Data
10
+public class WxMaAuthParam {
11
+
12
+    @ApiModelProperty("signature")
13
+    String signature;
14
+
15
+    @ApiModelProperty("rawData")
16
+    String rawData;
17
+
18
+    @ApiModelProperty("encryptedData")
19
+    String encryptedData;
20
+
21
+    @ApiModelProperty("iv")
22
+    String iv;
23
+}

+ 7
- 0
src/main/resources/mapper/TaPostDataMapper.xml Wyświetl plik

@@ -2,4 +2,11 @@
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.TaPostDataMapper">
4 4
 
5
+    <update id="updatePvUvBy">
6
+        UPDATE ta_post_data
7
+        SET p_v = p_v + #{addPv},
8
+            u_v = u_v + #{addUv}
9
+        WHERE
10
+            post_id = #{postId}
11
+    </update>
5 12
 </mapper>

+ 22
- 0
src/main/resources/mapper/TaPostTestMapper.xml Wyświetl plik

@@ -2,4 +2,26 @@
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.TaPostTestMapper">
4 4
 
5
+    <select id="getRandRowBy" resultType="com.yunzhi.demo.entity.TaPostTest">
6
+        SELECT
7
+            t1.*
8
+        FROM
9
+            ta_post_test AS t1
10
+                JOIN (
11
+                SELECT
12
+                    ROUND(
13
+                            RAND( ) * (
14
+                                ( SELECT MAX( serial_no ) FROM ta_post_test WHERE post_id = #{postId} AND `status` = 1 )
15
+                                    - ( SELECT MIN( serial_no ) FROM ta_post_test WHERE post_id = #{postId} AND `status` = 1 )
16
+                            ) + ( SELECT MIN( serial_no ) FROM ta_post_test WHERE post_id = #{postId} AND `status` = 1 )
17
+                        ) AS serial_no
18
+            ) AS t2
19
+        WHERE
20
+            t1.post_id = #{postId}
21
+          AND t1.`status` = 1
22
+          AND t1.serial_no >= t2.serial_no
23
+        ORDER BY
24
+            t1.serial_no
25
+            LIMIT 1
26
+    </select>
5 27
 </mapper>

+ 9
- 0
src/main/resources/mapper/TaReadLogMapper.xml Wyświetl plik

@@ -2,4 +2,13 @@
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.TaReadLogMapper">
4 4
 
5
+    <select id="countBy" resultType="java.lang.Integer">
6
+        SELECT
7
+            count( * )
8
+        FROM
9
+            ta_read_log t
10
+        WHERE
11
+            t.person_id = #{personId}
12
+          AND t.post_id = #{postId}
13
+    </select>
5 14
 </mapper>