Browse Source

Default Changelist

zlisen 4 years ago
parent
commit
73b98f3879

+ 21
- 0
src/main/java/com/shigongli/common/BaseController.java View File

1
 package com.shigongli.common;
1
 package com.shigongli.common;
2
 
2
 
3
+import com.shigongli.entity.TaPerson;
4
+import com.shigongli.service.ITaPersonService;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+
7
+import javax.servlet.http.HttpServletRequest;
8
+import java.util.Map;
9
+
3
 public class BaseController {
10
 public class BaseController {
11
+    @Autowired
12
+    ITaPersonService iTaPersonService;
13
+
14
+    public TaPerson getPerson(HttpServletRequest request) {
15
+        String token = JWTUtils.getToken(request);
16
+        try {
17
+            Map<String, Object> params = JWTUtils.decode(token);
18
+            String personId = params.get("personId").toString();
19
+            return iTaPersonService.getById(personId);
20
+        } catch (Exception e) {
21
+            e.printStackTrace();
22
+            return null;
23
+        }
24
+    }
4
 }
25
 }

+ 1
- 1
src/main/java/com/shigongli/common/JWTUtils.java View File

54
             Claims claims = parse(token);
54
             Claims claims = parse(token);
55
             return encode(claims);
55
             return encode(claims);
56
         } catch (Exception e) {
56
         } catch (Exception e) {
57
-            log.error("解析 JWT Token 失败: {}", e.getMessage());
57
+//            log.error("解析 JWT Token 失败: {}", e.getMessage());
58
         }
58
         }
59
         return null;
59
         return null;
60
     }
60
     }

+ 1
- 1
src/main/java/com/shigongli/controller/LoginController.java View File

24
 //    @Autowired
24
 //    @Autowired
25
 //    ISysUserService iSysUserService;
25
 //    ISysUserService iSysUserService;
26
 
26
 
27
-    @PostMapping("/login")
27
+    @PostMapping("/mp/login")
28
     @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
28
     @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
29
     public ResponseBean login(@ApiParam("登录参数") @RequestBody LoginParam loginParam) throws Exception {
29
     public ResponseBean login(@ApiParam("登录参数") @RequestBody LoginParam loginParam) throws Exception {
30
 //        if (null == loginParam) {
30
 //        if (null == loginParam) {

+ 33
- 7
src/main/java/com/shigongli/controller/TaPersonController.java View File

4
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.shigongli.common.BaseController;
6
 import com.shigongli.common.BaseController;
7
+import com.shigongli.common.JWTUtils;
7
 import com.shigongli.common.ResponseBean;
8
 import com.shigongli.common.ResponseBean;
8
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.ApiOperation;
10
 import io.swagger.annotations.ApiOperation;
11
 import org.slf4j.Logger;
12
 import org.slf4j.Logger;
12
 import org.slf4j.LoggerFactory;
13
 import org.slf4j.LoggerFactory;
13
 import org.springframework.beans.factory.annotation.Autowired;
14
 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;
15
+import org.springframework.web.bind.annotation.*;
19
 import com.shigongli.service.ITaPersonService;
16
 import com.shigongli.service.ITaPersonService;
20
 import com.shigongli.entity.TaPerson;
17
 import com.shigongli.entity.TaPerson;
21
-import org.springframework.web.bind.annotation.RestController;
18
+
19
+import javax.servlet.http.HttpServletRequest;
20
+import java.util.HashMap;
21
+import java.util.Map;
22
 
22
 
23
 /**
23
 /**
24
  * <p>
24
  * <p>
39
     @Autowired
39
     @Autowired
40
     public ITaPersonService iTaPersonService;
40
     public ITaPersonService iTaPersonService;
41
 
41
 
42
+    @PostMapping("/ma/login")
43
+    public ResponseBean login(String code) {
44
+        // 用 code 去换 openid
45
+        String openid = "";
46
+
47
+        // 先查询人员是否存在
48
+        TaPerson taPerson = iTaPersonService.getByOpenId(openid);
49
+
50
+        // 如果人员不存在, 则新增
51
+        if (null == taPerson) {
52
+            taPerson = new TaPerson();
53
+            taPerson.setOpenid(openid);
54
+            iTaPersonService.save(taPerson);
55
+//            taPerson = iTaPersonService.getById(taPerson.getPersonId());
56
+        }
57
+
58
+        // 生成 token
59
+        Map<String, Object> claims = new HashMap<>();
60
+        claims.put("personId", taPerson.getPersonId());
61
+        String token = JWTUtils.encode(claims);
62
+        taPerson.setToken(token);
63
+
64
+        return ResponseBean.success(taPerson);
65
+    }
66
+
42
 
67
 
43
     /**
68
     /**
44
      * 分页查询列表
69
      * 分页查询列表
49
     @RequestMapping(value="/taPerson",method= RequestMethod.GET)
74
     @RequestMapping(value="/taPerson",method= RequestMethod.GET)
50
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
75
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
     public ResponseBean taPersonList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
76
     public ResponseBean taPersonList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
77
+                                     @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
78
+                                     HttpServletRequest request) throws Exception{
53
 
79
 
54
 		    IPage<TaPerson> pg = new Page<>(pageNum, pageSize);
80
 		    IPage<TaPerson> pg = new Page<>(pageNum, pageSize);
55
             QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();
81
             QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();

+ 5
- 2
src/main/java/com/shigongli/entity/TaPerson.java View File

2
 
2
 
3
 import com.baomidou.mybatisplus.annotation.IdType;
3
 import com.baomidou.mybatisplus.annotation.IdType;
4
 import java.time.LocalDateTime;
4
 import java.time.LocalDateTime;
5
+
6
+import com.baomidou.mybatisplus.annotation.TableField;
5
 import com.baomidou.mybatisplus.annotation.TableId;
7
 import com.baomidou.mybatisplus.annotation.TableId;
6
 import java.io.Serializable;
8
 import java.io.Serializable;
7
 import io.swagger.annotations.ApiModel;
9
 import io.swagger.annotations.ApiModel;
27
     private static final long serialVersionUID = 1L;
29
     private static final long serialVersionUID = 1L;
28
 
30
 
29
     @ApiModelProperty(value = "人员ID")
31
     @ApiModelProperty(value = "人员ID")
30
-    @TableId(value = "person_id", type = IdType.INPUT)
32
+    @TableId(value = "person_id", type = IdType.UUID)
31
     private String personId;
33
     private String personId;
32
 
34
 
33
     @ApiModelProperty(value = "手机")
35
     @ApiModelProperty(value = "手机")
51
     @ApiModelProperty(value = "创建时间")
53
     @ApiModelProperty(value = "创建时间")
52
     private LocalDateTime createDate;
54
     private LocalDateTime createDate;
53
 
55
 
54
-
56
+    @TableField(exist = false)
57
+    private String token;
55
 }
58
 }

+ 12
- 12
src/main/java/com/shigongli/interceptor/PermissionInterceptor.java View File

24
 
24
 
25
         // JWT
25
         // JWT
26
         String jws = JWTUtils.getToken(request);
26
         String jws = JWTUtils.getToken(request);
27
-        if (StringUtils.isEmpty(jws)) {
28
-            responseTokenError(response, "鉴权失败, 请先进行登录操作");
29
-            return false;
30
-        }
31
-
32
-        try {
33
-            JWTUtils.verify(jws);
34
-        } catch (Exception e) {
35
-            log.error("鉴权失败: {}", e.getMessage());
36
-            responseTokenError(response, "鉴权失败, 请重新登录");
37
-            return false;
38
-        }
27
+//        if (StringUtils.isEmpty(jws)) {
28
+//            responseTokenError(response, "鉴权失败, 请先进行登录操作");
29
+//            return false;
30
+//        }
31
+
32
+//        try {
33
+//            JWTUtils.verify(jws);
34
+//        } catch (Exception e) {
35
+//            log.error("鉴权失败: {}", e.getMessage());
36
+//            responseTokenError(response, "鉴权失败, 请重新登录");
37
+//            return false;
38
+//        }
39
 
39
 
40
         return true;
40
         return true;
41
     }
41
     }

+ 2
- 0
src/main/java/com/shigongli/mapper/TaPersonMapper.java View File

3
 import com.shigongli.entity.TaPerson;
3
 import com.shigongli.entity.TaPerson;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
6
 
7
 
7
 /**
8
 /**
8
  * <p>
9
  * <p>
15
 @Mapper
16
 @Mapper
16
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
17
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
17
 
18
 
19
+    TaPerson getByOpenId(@Param("openid") String openid);
18
 }
20
 }

+ 1
- 0
src/main/java/com/shigongli/service/ITaPersonService.java View File

13
  */
13
  */
14
 public interface ITaPersonService extends IService<TaPerson> {
14
 public interface ITaPersonService extends IService<TaPerson> {
15
 
15
 
16
+    TaPerson getByOpenId(String openid);
16
 }
17
 }

+ 8
- 0
src/main/java/com/shigongli/service/impl/TaPersonServiceImpl.java View File

4
 import com.shigongli.mapper.TaPersonMapper;
4
 import com.shigongli.mapper.TaPersonMapper;
5
 import com.shigongli.service.ITaPersonService;
5
 import com.shigongli.service.ITaPersonService;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.stereotype.Service;
8
 import org.springframework.stereotype.Service;
8
 
9
 
9
 /**
10
 /**
17
 @Service
18
 @Service
18
 public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
19
 public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
19
 
20
 
21
+    @Autowired
22
+    TaPersonMapper taPersonMapper;
23
+
24
+    @Override
25
+    public TaPerson getByOpenId(String openid) {
26
+        return taPersonMapper.getByOpenId(openid);
27
+    }
20
 }
28
 }

+ 3
- 0
src/main/resources/mapper/TaPersonMapper.xml View File

2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
 <mapper namespace="com.shigongli.mapper.TaPersonMapper">
3
 <mapper namespace="com.shigongli.mapper.TaPersonMapper">
4
 
4
 
5
+    <select id="getByOpenId" resultType="com.shigongli.entity.TaPerson">
6
+        select * from ta_person where openid = #{openid}
7
+    </select>
5
 </mapper>
8
 </mapper>