Browse Source

Merge remote-tracking branch 'origin/master' into master

zlisen 4 years ago
parent
commit
fbfdffc5e7

+ 36
- 27
src/main/java/com/shigongli/controller/TaPersonController.java View File

1
 package com.shigongli.controller;
1
 package com.shigongli.controller;
2
 
2
 
3
+import cn.binarywang.wx.miniapp.api.WxMaService;
4
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
6
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
-import com.shigongli.common.BaseController;
7
-import com.shigongli.common.JWTUtils;
8
-import com.shigongli.common.ResponseBean;
8
+import com.shigongli.common.*;
9
+import com.shigongli.service.ITaShopKeeperService;
10
+import com.shigongli.vo.AuthPhoneParams;
9
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiParam;
13
 import io.swagger.annotations.ApiParam;
14
+import me.chanjar.weixin.mp.api.WxMpService;
12
 import org.slf4j.Logger;
15
 import org.slf4j.Logger;
13
 import org.slf4j.LoggerFactory;
16
 import org.slf4j.LoggerFactory;
14
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
39
     @Autowired
42
     @Autowired
40
     public ITaPersonService iTaPersonService;
43
     public ITaPersonService iTaPersonService;
41
 
44
 
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
-//    }
45
+    @Autowired
46
+    private ITaShopKeeperService iTaShopKeeperService;
47
+
48
+    @Autowired
49
+    private WxUtils wxUtils;
50
+
51
+    @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "POST", response = ResponseBean.class)
52
+    @PostMapping("/ma/taPerson/phone")
53
+    public ResponseBean phone(@ApiParam("授权手机参数") @RequestBody AuthPhoneParams authPhoneParams,
54
+                              HttpServletRequest request) {
55
+        if (null == authPhoneParams) {
56
+            return ResponseBean.error("请设置授权手机号的参数", ResponseBean.ERROR_UNAVAILABLE);
57
+        }
58
+        TaPerson taPerson = getPerson(request);
59
+        if (null == taPerson) {
60
+            return ResponseBean.error("校验用户失败, 请退出重新进入", ResponseBean.ERROR_UNAVAILABLE);
61
+        }
62
+
63
+        WxMaService maService = wxUtils.getMaService();
64
+        WxMaPhoneNumberInfo phoneNoInfo = maService.getUserService().getPhoneNoInfo(authPhoneParams.getSessionKey(), authPhoneParams.getEncryptedData(), authPhoneParams.getIv());
65
+
66
+        String phone = phoneNoInfo.getPhoneNumber();
67
+        taPerson.setPhone(phone);
68
+        iTaPersonService.updateById(taPerson);
69
+
70
+        // 绑定店主
71
+        iTaShopKeeperService.bindPerson(taPerson);
72
+
73
+        return ResponseBean.success(taPerson);
74
+    }
66
 
75
 
67
 
76
 
68
     /**
77
     /**

+ 15
- 0
src/main/java/com/shigongli/controller/TaShopKeeperController.java View File

6
 import com.shigongli.common.BaseController;
6
 import com.shigongli.common.BaseController;
7
 import com.shigongli.common.ResponseBean;
7
 import com.shigongli.common.ResponseBean;
8
 import com.shigongli.constants.StatusConstant;
8
 import com.shigongli.constants.StatusConstant;
9
+import com.shigongli.entity.TaPerson;
10
+import com.shigongli.service.ITaPersonService;
9
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiParam;
13
 import io.swagger.annotations.ApiParam;
40
     @Autowired
42
     @Autowired
41
     public ITaShopKeeperService iTaShopKeeperService;
43
     public ITaShopKeeperService iTaShopKeeperService;
42
 
44
 
45
+    @Autowired
46
+    public ITaPersonService iTaPersonService;
47
+
43
 
48
 
44
     /**
49
     /**
45
      * 分页查询列表
50
      * 分页查询列表
72
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
77
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
73
     public ResponseBean taShopKeeperAdd(@ApiParam("保存内容") @RequestBody TaShopKeeper taShopKeeper) throws Exception{
78
     public ResponseBean taShopKeeperAdd(@ApiParam("保存内容") @RequestBody TaShopKeeper taShopKeeper) throws Exception{
74
 
79
 
80
+        TaPerson taPerson = iTaPersonService.getByPhone(taShopKeeper.getPhone());
81
+        if (null != taPerson) {
82
+            taShopKeeper.setPersonId(taPerson.getPersonId());
83
+        }
84
+
75
         if (iTaShopKeeperService.save(taShopKeeper)){
85
         if (iTaShopKeeperService.save(taShopKeeper)){
76
             return ResponseBean.success(taShopKeeper);
86
             return ResponseBean.success(taShopKeeper);
77
         }else {
87
         }else {
106
     public ResponseBean taShopKeeperUpdate(@ApiParam("对象ID") @PathVariable String id,
116
     public ResponseBean taShopKeeperUpdate(@ApiParam("对象ID") @PathVariable String id,
107
                                         @ApiParam("更新内容") @RequestBody TaShopKeeper taShopKeeper) throws Exception{
117
                                         @ApiParam("更新内容") @RequestBody TaShopKeeper taShopKeeper) throws Exception{
108
 
118
 
119
+        TaPerson taPerson = iTaPersonService.getByPhone(taShopKeeper.getPhone());
120
+        if (null != taPerson) {
121
+            taShopKeeper.setPersonId(taPerson.getPersonId());
122
+        }
123
+
109
         if (iTaShopKeeperService.updateById(taShopKeeper)){
124
         if (iTaShopKeeperService.updateById(taShopKeeper)){
110
             return ResponseBean.success(iTaShopKeeperService.getById(id));
125
             return ResponseBean.success(iTaShopKeeperService.getById(id));
111
         }else {
126
         }else {

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

2
 
2
 
3
 import com.shigongli.entity.TaPerson;
3
 import com.shigongli.entity.TaPerson;
4
 import com.baomidou.mybatisplus.extension.service.IService;
4
 import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.shigongli.entity.TaShopKeeper;
5
 
6
 
6
 /**
7
 /**
7
  * <p>
8
  * <p>
14
 public interface ITaPersonService extends IService<TaPerson> {
15
 public interface ITaPersonService extends IService<TaPerson> {
15
 
16
 
16
     TaPerson getByOpenId(String openid);
17
     TaPerson getByOpenId(String openid);
18
+
19
+    TaPerson getByPhone(String phone);
17
 }
20
 }

+ 6
- 0
src/main/java/com/shigongli/service/ITaShopKeeperService.java View File

1
 package com.shigongli.service;
1
 package com.shigongli.service;
2
 
2
 
3
+import com.shigongli.entity.TaPerson;
3
 import com.shigongli.entity.TaShopKeeper;
4
 import com.shigongli.entity.TaShopKeeper;
4
 import com.baomidou.mybatisplus.extension.service.IService;
5
 import com.baomidou.mybatisplus.extension.service.IService;
5
 
6
 
7
+import java.util.List;
8
+
6
 /**
9
 /**
7
  * <p>
10
  * <p>
8
  * 店主 服务类
11
  * 店主 服务类
13
  */
16
  */
14
 public interface ITaShopKeeperService extends IService<TaShopKeeper> {
17
 public interface ITaShopKeeperService extends IService<TaShopKeeper> {
15
 
18
 
19
+    void bindPerson(TaPerson taPerson);
20
+
21
+    List<TaShopKeeper> getByPhone(String phone);
16
 }
22
 }

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

1
 package com.shigongli.service.impl;
1
 package com.shigongli.service.impl;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.shigongli.common.StringUtils;
5
+import com.shigongli.constants.StatusConstant;
3
 import com.shigongli.entity.TaPerson;
6
 import com.shigongli.entity.TaPerson;
7
+import com.shigongli.entity.TaShopKeeper;
4
 import com.shigongli.mapper.TaPersonMapper;
8
 import com.shigongli.mapper.TaPersonMapper;
5
 import com.shigongli.service.ITaPersonService;
9
 import com.shigongli.service.ITaPersonService;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
10
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
25
     public TaPerson getByOpenId(String openid) {
29
     public TaPerson getByOpenId(String openid) {
26
         return taPersonMapper.getByOpenId(openid);
30
         return taPersonMapper.getByOpenId(openid);
27
     }
31
     }
32
+
33
+    @Override
34
+    public TaPerson getByPhone(String phone) {
35
+        if (StringUtils.isEmpty(phone)) {
36
+            return null;
37
+        }
38
+
39
+        QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<TaPerson>()
40
+                .eq("phone", phone)
41
+                .eq("status", StatusConstant.NORMAL);
42
+
43
+        return getOne(queryWrapper);
44
+    }
28
 }
45
 }

+ 27
- 0
src/main/java/com/shigongli/service/impl/TaShopKeeperServiceImpl.java View File

1
 package com.shigongli.service.impl;
1
 package com.shigongli.service.impl;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.shigongli.constants.StatusConstant;
5
+import com.shigongli.entity.TaPerson;
3
 import com.shigongli.entity.TaShopKeeper;
6
 import com.shigongli.entity.TaShopKeeper;
4
 import com.shigongli.mapper.TaShopKeeperMapper;
7
 import com.shigongli.mapper.TaShopKeeperMapper;
5
 import com.shigongli.service.ITaShopKeeperService;
8
 import com.shigongli.service.ITaShopKeeperService;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
 import org.springframework.stereotype.Service;
10
 import org.springframework.stereotype.Service;
8
 
11
 
12
+import java.util.List;
13
+
9
 /**
14
 /**
10
  * <p>
15
  * <p>
11
  * 店主 服务实现类
16
  * 店主 服务实现类
17
 @Service
22
 @Service
18
 public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaShopKeeper> implements ITaShopKeeperService {
23
 public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaShopKeeper> implements ITaShopKeeperService {
19
 
24
 
25
+    @Override
26
+    public void bindPerson(TaPerson taPerson) {
27
+        List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
28
+
29
+        if (null == shopKeeperList) {
30
+            return ;
31
+        }
32
+
33
+        for (TaShopKeeper shopKeeper: shopKeeperList) {
34
+            shopKeeper.setPersonId(taPerson.getPersonId());
35
+            updateById(shopKeeper);
36
+        }
37
+    }
38
+
39
+    @Override
40
+    public List<TaShopKeeper> getByPhone(String phone) {
41
+        QueryWrapper<TaShopKeeper> queryWrapper = new QueryWrapper<TaShopKeeper>()
42
+                .eq("phone", phone)
43
+                .eq("status", StatusConstant.NORMAL);
44
+
45
+        return list(queryWrapper);
46
+    }
20
 }
47
 }

+ 20
- 0
src/main/java/com/shigongli/vo/AuthPhoneParams.java View File

1
+package com.shigongli.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(description = "授权手机参数")
9
+@Data
10
+public class AuthPhoneParams {
11
+
12
+    @ApiModelProperty("sessionKey")
13
+    String sessionKey;
14
+
15
+    @ApiModelProperty("encryptedData")
16
+    String encryptedData;
17
+
18
+    @ApiModelProperty("iv")
19
+    String iv;
20
+}

+ 1
- 1
src/main/java/com/shigongli/vo/ImageTagUpdateParams.java View File

5
 import io.swagger.annotations.ApiModelProperty;
5
 import io.swagger.annotations.ApiModelProperty;
6
 import lombok.Data;
6
 import lombok.Data;
7
 
7
 
8
-@ApiModel(description = "登录参数")
8
+@ApiModel(description = "修改标签图片参数")
9
 @Data
9
 @Data
10
 public class ImageTagUpdateParams {
10
 public class ImageTagUpdateParams {
11
 
11