|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
4
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.shigongli.common.BaseController;
|
|
7
|
+import com.shigongli.common.JWTUtils;
|
7
|
8
|
import com.shigongli.common.ResponseBean;
|
8
|
9
|
import io.swagger.annotations.Api;
|
9
|
10
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -11,14 +12,13 @@ import io.swagger.annotations.ApiParam;
|
11
|
12
|
import org.slf4j.Logger;
|
12
|
13
|
import org.slf4j.LoggerFactory;
|
13
|
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
|
16
|
import com.shigongli.service.ITaPersonService;
|
20
|
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
|
24
|
* <p>
|
|
@@ -39,6 +39,31 @@ public class TaPersonController extends BaseController {
|
39
|
39
|
@Autowired
|
40
|
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,7 +74,8 @@ public class TaPersonController extends BaseController {
|
49
|
74
|
@RequestMapping(value="/taPerson",method= RequestMethod.GET)
|
50
|
75
|
@ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
|
51
|
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
|
80
|
IPage<TaPerson> pg = new Page<>(pageNum, pageSize);
|
55
|
81
|
QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();
|