张延森 3 gadus atpakaļ
vecāks
revīzija
1b275fa66f
19 mainītis faili ar 551 papildinājumiem un 27 dzēšanām
  1. 71
    1
      src/main/java/com/yunzhi/shigongli/common/StringUtils.java
  2. 12
    0
      src/main/java/com/yunzhi/shigongli/common/WxUtils.java
  3. 14
    9
      src/main/java/com/yunzhi/shigongli/controller/TaHotelWorkerController.java
  4. 8
    5
      src/main/java/com/yunzhi/shigongli/controller/TaShopController.java
  5. 7
    5
      src/main/java/com/yunzhi/shigongli/controller/TaShopPackageController.java
  6. 3
    3
      src/main/java/com/yunzhi/shigongli/controller/TaShopWorkerController.java
  7. 77
    1
      src/main/java/com/yunzhi/shigongli/controller/WxMaController.java
  8. 50
    0
      src/main/java/com/yunzhi/shigongli/entity/TaMiniappQrcode.java
  9. 0
    3
      src/main/java/com/yunzhi/shigongli/entity/TaPerson.java
  10. 52
    0
      src/main/java/com/yunzhi/shigongli/entity/TaPersonRole.java
  11. 18
    0
      src/main/java/com/yunzhi/shigongli/mapper/TaMiniappQrcodeMapper.java
  12. 23
    0
      src/main/java/com/yunzhi/shigongli/service/ITaMiniappQrcodeService.java
  13. 3
    0
      src/main/java/com/yunzhi/shigongli/service/ITaPersonService.java
  14. 2
    0
      src/main/java/com/yunzhi/shigongli/service/ITaShopService.java
  15. 124
    0
      src/main/java/com/yunzhi/shigongli/service/impl/TaMiniappQrcodeImpl.java
  16. 26
    0
      src/main/java/com/yunzhi/shigongli/service/impl/TaPersonServiceImpl.java
  17. 17
    0
      src/main/java/com/yunzhi/shigongli/service/impl/TaShopServiceImpl.java
  18. 39
    0
      src/main/java/com/yunzhi/shigongli/vo/QrCodeParamsVO.java
  19. 5
    0
      src/main/resources/mapper/TaMiniappQrcodeMapper.xml

+ 71
- 1
src/main/java/com/yunzhi/shigongli/common/StringUtils.java Parādīt failu

@@ -1,8 +1,9 @@
1 1
 package com.yunzhi.shigongli.common;
2 2
 
3 3
 import java.io.UnsupportedEncodingException;
4
+import java.net.URLDecoder;
4 5
 import java.net.URLEncoder;
5
-import java.util.Random;
6
+import java.util.*;
6 7
 import java.util.regex.Matcher;
7 8
 import java.util.regex.Pattern;
8 9
 
@@ -61,6 +62,17 @@ public class StringUtils {
61 62
         }
62 63
     }
63 64
 
65
+    public static String encodeURIComponent(String str) {
66
+        String result = urlEncode(str);
67
+
68
+        return result.replaceAll("\\+", "%20")
69
+                .replaceAll("\\%21", "!")
70
+                .replaceAll("\\%27", "'")
71
+                .replaceAll("\\%28", "(")
72
+                .replaceAll("\\%29", ")")
73
+                .replaceAll("\\%7E", "~");
74
+    }
75
+
64 76
     public static String humpToLine(String str) {
65 77
         if (null == str || "".equals(str)) return "";
66 78
 
@@ -117,4 +129,62 @@ public class StringUtils {
117 129
         prefix = prefix.substring(0, padLen);
118 130
         return prefix + src;
119 131
     }
132
+
133
+    /**
134
+     * 解析 QueryString
135
+     * @param queryStr
136
+     * @return
137
+     */
138
+    public static Map<String, String> parseQueryString(String queryStr) {
139
+        if (isEmpty(queryStr)) {
140
+            return null;
141
+        }
142
+        Map<String, String> result = new HashMap<String, String>();
143
+
144
+        String[] fields = queryStr.split("&");
145
+        for (String field : fields) {
146
+            String[] pairs = field.split("=");
147
+            if (2 != pairs.length) {
148
+                continue;
149
+            }
150
+
151
+            try {
152
+                String key = URLDecoder.decode(pairs[0].trim(), "UTF-8");
153
+                String val = URLDecoder.decode(pairs[1].trim(), "UTF-8");
154
+
155
+                result.put(key, val);
156
+            } catch (UnsupportedEncodingException e) {
157
+                e.printStackTrace();
158
+            }
159
+        }
160
+
161
+        return result;
162
+    }
163
+
164
+    /**
165
+     * Map 转 QueryString
166
+     * @param params
167
+     * @return
168
+     */
169
+    public static String buildQueryString(Map<String, Object> params) {
170
+        if (null == params) {
171
+            return null;
172
+        }
173
+
174
+        List<String> lst = new ArrayList<>();
175
+        for (Map.Entry<String, Object> entry : params.entrySet()) {
176
+            String key = StringUtils.urlEncode(entry.getKey());
177
+            Object o = entry.getValue();
178
+            if (null == o) {
179
+                continue;
180
+            }
181
+            String val = o.toString();
182
+            if (StringUtils.isEmpty(val)) {
183
+                continue;
184
+            }
185
+            String queryStr = key + "=" + StringUtils.urlEncode(val);
186
+            lst.add(queryStr);
187
+        }
188
+        return String.join("&", lst);
189
+    }
120 190
 }

+ 12
- 0
src/main/java/com/yunzhi/shigongli/common/WxUtils.java Parādīt failu

@@ -2,12 +2,14 @@ package com.yunzhi.shigongli.common;
2 2
 
3 3
 import cn.binarywang.wx.miniapp.api.WxMaService;
4 4
 import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
5
+import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
5 6
 import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
6 7
 import com.github.binarywang.wxpay.config.WxPayConfig;
7 8
 import com.github.binarywang.wxpay.constant.WxPayConstants;
8 9
 import com.github.binarywang.wxpay.service.WxPayService;
9 10
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
10 11
 import com.yunzhi.shigongli.config.WeixinConfig;
12
+import lombok.Data;
11 13
 import org.springframework.beans.factory.annotation.Autowired;
12 14
 import org.springframework.stereotype.Component;
13 15
 
@@ -57,4 +59,14 @@ public class WxUtils {
57 59
     public WxPayService getPayService() {
58 60
         return payService;
59 61
     }
62
+
63
+    @Data
64
+    public static class AQrCodeParam {
65
+        private String scene;
66
+        private String page;
67
+        private int width;
68
+        private boolean autoColor;
69
+        private WxMaCodeLineColor lineColor;
70
+        private boolean isHyaline;
71
+    }
60 72
 }

+ 14
- 9
src/main/java/com/yunzhi/shigongli/controller/TaHotelWorkerController.java Parādīt failu

@@ -4,7 +4,9 @@ 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.yunzhi.shigongli.common.BaseController;
7
+import com.yunzhi.shigongli.common.Constants;
7 8
 import com.yunzhi.shigongli.common.ResponseBean;
9
+import com.yunzhi.shigongli.common.StringUtils;
8 10
 import io.swagger.annotations.Api;
9 11
 import io.swagger.annotations.ApiOperation;
10 12
 import io.swagger.annotations.ApiParam;
@@ -49,14 +51,17 @@ public class TaHotelWorkerController extends BaseController {
49 51
     @RequestMapping(value="/admin/taHotelWorker",method= RequestMethod.GET)
50 52
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51 53
     public ResponseBean taHotelWorkerList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
54
+                                          @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
55
+                                          @ApiParam("民宿ID") @RequestParam(value ="hotelId", required = false) String hotelId) throws Exception{
53 56
 
54
-		    IPage<TaHotelWorker> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaHotelWorker> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
57
+        IPage<TaHotelWorker> pg = new Page<>(pageNum, pageSize);
58
+        QueryWrapper<TaHotelWorker> queryWrapper = new QueryWrapper<>();
59
+        queryWrapper.eq(!StringUtils.isEmpty(hotelId), "hotel_id", hotelId);
60
+        queryWrapper.gt("status", Constants.STATUS_DELETED);
61
+        queryWrapper.orderByDesc("create_date");
57 62
 
58
-            IPage<TaHotelWorker> result = iTaHotelWorkerService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
63
+        IPage<TaHotelWorker> result = iTaHotelWorkerService.page(pg, queryWrapper);
64
+        return ResponseBean.success(result);
60 65
     }
61 66
 
62 67
     /**
@@ -81,7 +86,7 @@ public class TaHotelWorkerController extends BaseController {
81 86
      */
82 87
     @RequestMapping(value="/admin/taHotelWorker/{id}", method= RequestMethod.DELETE)
83 88
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taHotelWorkerDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
89
+    public ResponseBean taHotelWorkerDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
85 90
         if(iTaHotelWorkerService.removeLogicById(id)){
86 91
             return ResponseBean.success("success");
87 92
         }else {
@@ -97,7 +102,7 @@ public class TaHotelWorkerController extends BaseController {
97 102
      */
98 103
     @RequestMapping(value="/admin/taHotelWorker/{id}",method= RequestMethod.PUT)
99 104
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taHotelWorkerUpdate(@ApiParam("对象ID") @PathVariable Integer id,
105
+    public ResponseBean taHotelWorkerUpdate(@ApiParam("对象ID") @PathVariable String id,
101 106
                                         @ApiParam("更新内容") @RequestBody TaHotelWorker taHotelWorker) throws Exception{
102 107
 
103 108
         if (iTaHotelWorkerService.updateById(taHotelWorker)){
@@ -113,7 +118,7 @@ public class TaHotelWorkerController extends BaseController {
113 118
      */
114 119
     @RequestMapping(value="/admin/taHotelWorker/{id}",method= RequestMethod.GET)
115 120
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taHotelWorkerGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
121
+    public ResponseBean taHotelWorkerGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
117 122
         return ResponseBean.success(iTaHotelWorkerService.getById(id));
118 123
     }
119 124
 }

+ 8
- 5
src/main/java/com/yunzhi/shigongli/controller/TaShopController.java Parādīt failu

@@ -66,13 +66,16 @@ public class TaShopController extends BaseController {
66 66
      */
67 67
     @RequestMapping(value="/admin/taShop",method= RequestMethod.POST)
68 68
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
-    public ResponseBean taShopAdd(@ApiParam("保存内容") @RequestBody TaShop taShop) throws Exception{
69
+    public ResponseBean taShopAdd(@ApiParam("保存内容") @RequestBody TaShop taShop) throws Exception {
70 70
 
71
-        if (iTaShopService.save(taShop)){
72
-            return ResponseBean.success(taShop);
73
-        }else {
74
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
71
+        try {
72
+            iTaShopService.createNew(taShop);
73
+        } catch (Exception e) {
74
+            e.printStackTrace();
75
+            return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
75 76
         }
77
+
78
+        return ResponseBean.success(taShop);
76 79
     }
77 80
 
78 81
     /**

+ 7
- 5
src/main/java/com/yunzhi/shigongli/controller/TaShopPackageController.java Parādīt failu

@@ -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.yunzhi.shigongli.common.BaseController;
7
+import com.yunzhi.shigongli.common.Constants;
7 8
 import com.yunzhi.shigongli.common.ResponseBean;
8 9
 import io.swagger.annotations.Api;
9 10
 import io.swagger.annotations.ApiOperation;
@@ -52,13 +53,14 @@ public class TaShopPackageController extends BaseController {
52 53
                                           @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
53 54
                                           @ApiParam("商铺") @RequestParam(value ="shopId") String shopId) throws Exception{
54 55
 
55
-		    IPage<TaShopPackage> pg = new Page<>(pageNum, pageSize);
56
-            QueryWrapper<TaShopPackage> queryWrapper = new QueryWrapper<>();
56
+        IPage<TaShopPackage> pg = new Page<>(pageNum, pageSize);
57
+        QueryWrapper<TaShopPackage> queryWrapper = new QueryWrapper<>();
57 58
         queryWrapper.eq("shop_id", shopId);
58
-            queryWrapper.orderByDesc("create_date");
59
+        queryWrapper.gt("status", Constants.STATUS_DELETED);
60
+        queryWrapper.orderByDesc("create_date");
59 61
 
60
-            IPage<TaShopPackage> result = iTaShopPackageService.page(pg, queryWrapper);
61
-            return ResponseBean.success(result);
62
+        IPage<TaShopPackage> result = iTaShopPackageService.page(pg, queryWrapper);
63
+        return ResponseBean.success(result);
62 64
     }
63 65
 
64 66
     /**

+ 3
- 3
src/main/java/com/yunzhi/shigongli/controller/TaShopWorkerController.java Parādīt failu

@@ -76,7 +76,7 @@ public class TaShopWorkerController extends BaseController {
76 76
      */
77 77
     @RequestMapping(value="/admin/taShopWorker/{id}", method= RequestMethod.DELETE)
78 78
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
79
-    public ResponseBean taShopWorkerDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
79
+    public ResponseBean taShopWorkerDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
80 80
         if(iTaShopWorkerService.removeLogicById(id)){
81 81
             return ResponseBean.success("success");
82 82
         }else {
@@ -92,7 +92,7 @@ public class TaShopWorkerController extends BaseController {
92 92
      */
93 93
     @RequestMapping(value="/admin/taShopWorker/{id}",method= RequestMethod.PUT)
94 94
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
95
-    public ResponseBean taShopWorkerUpdate(@ApiParam("对象ID") @PathVariable Integer id,
95
+    public ResponseBean taShopWorkerUpdate(@ApiParam("对象ID") @PathVariable String id,
96 96
                                         @ApiParam("更新内容") @RequestBody TaShopWorker taShopWorker) throws Exception{
97 97
 
98 98
         if (iTaShopWorkerService.updateById(taShopWorker)){
@@ -108,7 +108,7 @@ public class TaShopWorkerController extends BaseController {
108 108
      */
109 109
     @RequestMapping(value="/admin/taShopWorker/{id}",method= RequestMethod.GET)
110 110
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
111
-    public ResponseBean taShopWorkerGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
111
+    public ResponseBean taShopWorkerGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
112 112
         return ResponseBean.success(iTaShopWorkerService.getById(id));
113 113
     }
114 114
 }

+ 77
- 1
src/main/java/com/yunzhi/shigongli/controller/WxMaController.java Parādīt failu

@@ -1,15 +1,26 @@
1 1
 package com.yunzhi.shigongli.controller;
2 2
 
3
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
3 4
 import com.yunzhi.shigongli.common.*;
5
+import com.yunzhi.shigongli.entity.TaMiniappQrcode;
6
+import com.yunzhi.shigongli.entity.TaPerson;
7
+import com.yunzhi.shigongli.service.ITaMiniappQrcodeService;
4 8
 import com.yunzhi.shigongli.service.ITaPersonService;
5 9
 import io.swagger.annotations.Api;
10
+import io.swagger.annotations.ApiOperation;
11
+import me.chanjar.weixin.common.error.WxErrorException;
6 12
 import org.springframework.beans.factory.annotation.Autowired;
7 13
 import org.springframework.web.bind.annotation.*;
8 14
 
15
+import java.util.Arrays;
16
+import java.util.HashMap;
17
+import java.util.Map;
18
+import java.util.Optional;
19
+
9 20
 
10 21
 @Api(tags = "微信小程序")
11 22
 @RestController
12
-@RequestMapping("/ma")
23
+@RequestMapping("/wx")
13 24
 public class WxMaController extends BaseController {
14 25
 
15 26
     @Autowired
@@ -18,6 +29,71 @@ public class WxMaController extends BaseController {
18 29
     @Autowired
19 30
     ITaPersonService iTaPersonService;
20 31
 
32
+    @Autowired
33
+    ITaMiniappQrcodeService miniappQrcodeService;
34
+
35
+    @GetMapping("prefetch")
36
+    @ApiOperation(value="微信预拉取数据", notes = "微信预拉取数据", httpMethod = "GET", response = ResponseBean.class)
37
+    public ResponseBean perfetch(String appid,
38
+                                 String token,
39
+                                 String code,
40
+                                 Integer timestamp,
41
+                                 String path,
42
+                                 String query,
43
+                                 String scene) throws Exception {
44
+        WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(code);
45
+        String openid = info.getOpenid();
46
+
47
+        TaPerson taPerson = iTaPersonService.getByOpenid(openid);
48
+        if (null == taPerson) {
49
+            taPerson = new TaPerson();
50
+            taPerson.setOpenid(openid);
51
+            iTaPersonService.save(taPerson);
52
+            // 插入过程会有默认字段写入
53
+            taPerson = iTaPersonService.getById(taPerson.getPersonId());
54
+        }
55
+
56
+        Map<String, Object> result = new HashMap<>();
57
+        result.put("person", taPerson);
58
+
59
+        // 如果是通过扫码打开
60
+        if (!StringUtils.isEmpty(query)) {
61
+            Map<String, String> params = StringUtils.parseQueryString(query);
62
+
63
+            String fromType = params.get("fromType");
64
+            String recommender = params.get("recommender");
65
+            String qrCodeId = params.get("scene");
66
+
67
+            // 如果是扫码进入
68
+            if (!StringUtils.isEmpty(qrCodeId)) {
69
+                TaMiniappQrcode miniappQrcode = miniappQrcodeService.getById(Integer.valueOf(qrCodeId));
70
+                if (null != miniappQrcode) {
71
+                    String qrcodeParamStr = miniappQrcode.getScene();
72
+                    if (!StringUtils.isEmpty(qrcodeParamStr)) {
73
+                        // 把真正的参数返回
74
+                        result.put("qrcode", qrcodeParamStr);
75
+                        // 如果小程序码中有
76
+                        Map<String, String> qrcodeParams = StringUtils.parseQueryString(qrcodeParamStr);
77
+                        if (!StringUtils.isEmpty(qrcodeParams.get("id"))) {
78
+                            fromType = qrcodeParams.get("type");
79
+                            recommender = qrcodeParams.get("id");
80
+                        }
81
+                    }
82
+                }
83
+            }
84
+
85
+            // 如果有推广ID, 比如民宿或者商铺
86
+            if (StringUtils.isEmpty(taPerson.getRecommender()) && !StringUtils.isEmpty(recommender)) {
87
+                taPerson.setFromType(fromType);
88
+                taPerson.setRecommender(recommender);
89
+                iTaPersonService.setRecommender(taPerson);
90
+            }
91
+
92
+        }
93
+
94
+        return ResponseBean.success(result);
95
+    }
96
+
21 97
 //    @PostMapping("/login")
22 98
 //    @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
23 99
 //    public ResponseBean login(@ApiParam("登录参数") @RequestParam String code) throws Exception {

+ 50
- 0
src/main/java/com/yunzhi/shigongli/entity/TaMiniappQrcode.java Parādīt failu

@@ -0,0 +1,50 @@
1
+package com.yunzhi.shigongli.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import io.swagger.annotations.ApiModel;
6
+import io.swagger.annotations.ApiModelProperty;
7
+import lombok.Data;
8
+import lombok.EqualsAndHashCode;
9
+import lombok.experimental.Accessors;
10
+
11
+import java.io.Serializable;
12
+import java.time.LocalDateTime;
13
+
14
+/**
15
+ * <p>
16
+ * 访问人次
17
+ * </p>
18
+ *
19
+ * @author yansen
20
+ * @since 2021-08-17
21
+ */
22
+@Data
23
+@EqualsAndHashCode(callSuper = false)
24
+@Accessors(chain = true)
25
+@ApiModel(value="TaMiniappQrcode 对象", description="小程序码")
26
+public class TaMiniappQrcode implements Serializable {
27
+
28
+    private static final long serialVersionUID = 1L;
29
+
30
+    @ApiModelProperty(value = "qrID")
31
+    @TableId(value = "qr_id", type = IdType.AUTO)
32
+    private Integer qrId;
33
+
34
+    @ApiModelProperty(value = "小程序APPID")
35
+    private String miniappId;
36
+
37
+    @ApiModelProperty(value = "图片地址")
38
+    private String qrImage;
39
+
40
+    @ApiModelProperty(value = "页面地址")
41
+    private String page;
42
+
43
+    @ApiModelProperty(value = "页面参数")
44
+    private String scene;
45
+
46
+    @ApiModelProperty(value = "访问时间")
47
+    private LocalDateTime createDate;
48
+
49
+
50
+}

+ 0
- 3
src/main/java/com/yunzhi/shigongli/entity/TaPerson.java Parādīt failu

@@ -30,9 +30,6 @@ public class TaPerson implements Serializable {
30 30
     @TableId(value = "person_id", type = IdType.UUID)
31 31
     private String personId;
32 32
 
33
-    @ApiModelProperty(value = "类型")
34
-    private String personType;
35
-
36 33
     @ApiModelProperty(value = "openid")
37 34
     private String openid;
38 35
 

+ 52
- 0
src/main/java/com/yunzhi/shigongli/entity/TaPersonRole.java Parādīt failu

@@ -0,0 +1,52 @@
1
+package com.yunzhi.shigongli.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import io.swagger.annotations.ApiModel;
6
+import io.swagger.annotations.ApiModelProperty;
7
+import lombok.Data;
8
+import lombok.EqualsAndHashCode;
9
+import lombok.experimental.Accessors;
10
+
11
+import java.io.Serializable;
12
+import java.time.LocalDateTime;
13
+
14
+/**
15
+ * <p>
16
+ * 小程序人员表
17
+ * </p>
18
+ *
19
+ * @author yansen
20
+ * @since 2021-08-17
21
+ */
22
+@Data
23
+@EqualsAndHashCode(callSuper = false)
24
+@Accessors(chain = true)
25
+@ApiModel(value="TaPersonRole对象", description="小程序人员角色表")
26
+public class TaPersonRole implements Serializable {
27
+
28
+    private static final long serialVersionUID = 1L;
29
+
30
+    @ApiModelProperty(value = "角色序号")
31
+    @TableId(value = "role_no", type = IdType.AUTO)
32
+    private Integer roleNo;
33
+
34
+    @ApiModelProperty(value = "人员ID")
35
+    private String personId;
36
+
37
+    @ApiModelProperty(value = "用户ID")
38
+    private String userId;
39
+
40
+    @ApiModelProperty(value = "是否管理员")
41
+    private Integer isManager;
42
+
43
+    @ApiModelProperty(value = "映射类型")
44
+    private String targetType;
45
+
46
+    @ApiModelProperty(value = "类型对象ID")
47
+    private String targetId;
48
+
49
+    @ApiModelProperty(value = "创建时间")
50
+    private LocalDateTime createDate;
51
+
52
+}

+ 18
- 0
src/main/java/com/yunzhi/shigongli/mapper/TaMiniappQrcodeMapper.java Parādīt failu

@@ -0,0 +1,18 @@
1
+package com.yunzhi.shigongli.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.shigongli.entity.TaMiniappQrcode;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 访问人次 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2021-08-17
14
+ */
15
+@Mapper
16
+public interface TaMiniappQrcodeMapper extends BaseMapper<TaMiniappQrcode> {
17
+
18
+}

+ 23
- 0
src/main/java/com/yunzhi/shigongli/service/ITaMiniappQrcodeService.java Parādīt failu

@@ -0,0 +1,23 @@
1
+package com.yunzhi.shigongli.service;
2
+
3
+
4
+import com.yunzhi.shigongli.entity.TaMiniappQrcode;
5
+import com.yunzhi.shigongli.vo.QrCodeParamsVO;
6
+
7
+/**
8
+ * <p>
9
+ * 访问人次 服务类
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2021-08-17
14
+ */
15
+public interface ITaMiniappQrcodeService extends IBaseService<TaMiniappQrcode> {
16
+    /**
17
+     * 生成小程序码
18
+     * @param qrCodeParamsVO
19
+     * @return
20
+     * @throws Exception
21
+     */
22
+    String createQrCode(QrCodeParamsVO qrCodeParamsVO) throws Exception;
23
+}

+ 3
- 0
src/main/java/com/yunzhi/shigongli/service/ITaPersonService.java Parādīt failu

@@ -13,4 +13,7 @@ import com.yunzhi.shigongli.entity.TaPerson;
13 13
  */
14 14
 public interface ITaPersonService extends IBaseService<TaPerson> {
15 15
 
16
+    TaPerson getByOpenid(String openid);
17
+
18
+    void setRecommender(TaPerson taPerson) throws Exception;
16 19
 }

+ 2
- 0
src/main/java/com/yunzhi/shigongli/service/ITaShopService.java Parādīt failu

@@ -16,4 +16,6 @@ import com.yunzhi.shigongli.vo.ShopListVO;
16 16
 public interface ITaShopService extends IBaseService<TaShop> {
17 17
 
18 18
     IPage<ShopListVO> getPageListBy(IPage<ShopListVO> pg, String shopName, String phone);
19
+
20
+    void createNew(TaShop taShop) throws Exception;
19 21
 }

+ 124
- 0
src/main/java/com/yunzhi/shigongli/service/impl/TaMiniappQrcodeImpl.java Parādīt failu

@@ -0,0 +1,124 @@
1
+package com.yunzhi.shigongli.service.impl;
2
+
3
+import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
4
+import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
5
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
6
+import com.yunzhi.shigongli.common.OSSUtils;
7
+import com.yunzhi.shigongli.common.StringUtils;
8
+import com.yunzhi.shigongli.common.WxUtils;
9
+import com.yunzhi.shigongli.entity.TaMiniappQrcode;
10
+import com.yunzhi.shigongli.mapper.TaMiniappQrcodeMapper;
11
+import com.yunzhi.shigongli.service.ITaMiniappQrcodeService;
12
+import com.yunzhi.shigongli.vo.QrCodeParamsVO;
13
+import me.chanjar.weixin.common.error.WxErrorException;
14
+import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.stereotype.Service;
16
+import org.springframework.transaction.annotation.Transactional;
17
+import sun.security.krb5.internal.PAData;
18
+
19
+import java.io.File;
20
+import java.io.FileNotFoundException;
21
+import java.time.LocalDateTime;
22
+
23
+/**
24
+ * <p>
25
+ * 访问人次 服务实现类
26
+ * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2021-08-17
30
+ */
31
+@Service
32
+public class TaMiniappQrcodeImpl extends BaseServiceImpl<TaMiniappQrcodeMapper, TaMiniappQrcode> implements ITaMiniappQrcodeService {
33
+
34
+    @Autowired
35
+    WxUtils wxUtils;
36
+
37
+    @Autowired
38
+    OSSUtils ossUtils;
39
+
40
+    @Autowired
41
+    TaMiniappQrcodeMapper miniappQrcodeMapper;
42
+
43
+    @Transactional(rollbackFor = Exception.class)
44
+    @Override
45
+    public String createQrCode(QrCodeParamsVO qrCodeParamsVO) throws Exception {
46
+        if (null == qrCodeParamsVO || StringUtils.isEmpty(qrCodeParamsVO.getPage())) {
47
+            throw new Exception("小程序码生成参数为空");
48
+        }
49
+
50
+        if (StringUtils.isEmpty(qrCodeParamsVO.getType())) {
51
+            throw new Exception("小程序码页面参数非法");
52
+        }
53
+
54
+        // 页面地址, 不能以 / 开头
55
+        String page = qrCodeParamsVO.getPage();
56
+        if (page.startsWith("/")) {
57
+            page = page.substring(1);
58
+        }
59
+
60
+        // 页面参数
61
+        String secen = qrCodeParamsVO.getSceneQueryString();
62
+
63
+        // 小程序ID
64
+        String miniappId = wxUtils.getService().getWxMaConfig().getAppid();
65
+
66
+        // 先去查询数据库中是否已经存在相同参数的小程序码
67
+        LambdaQueryWrapper<TaMiniappQrcode> queryWrapper = new LambdaQueryWrapper<>();
68
+        queryWrapper.eq(TaMiniappQrcode::getMiniappId, miniappId)
69
+                .eq(TaMiniappQrcode::getPage, page)
70
+                .eq(!StringUtils.isEmpty(secen), TaMiniappQrcode::getScene, secen)
71
+                .orderByDesc(TaMiniappQrcode::getCreateDate)
72
+                .last("limit 1");
73
+
74
+        // 如果存在, 则直接返回
75
+        TaMiniappQrcode origin = getOne(queryWrapper);
76
+        if (null != origin) {
77
+            return origin.getQrImage();
78
+        }
79
+
80
+        // 否则, 则新生成一个
81
+        // 先入库
82
+        TaMiniappQrcode taMiniappQrcode = new TaMiniappQrcode();
83
+        taMiniappQrcode.setMiniappId(miniappId);
84
+        taMiniappQrcode.setPage(page);
85
+        taMiniappQrcode.setScene(secen);
86
+        taMiniappQrcode.setCreateDate(LocalDateTime.now());
87
+        save(taMiniappQrcode);
88
+
89
+        // 使用SDK生成
90
+        WxUtils.AQrCodeParam param = new WxUtils.AQrCodeParam();
91
+        param.setPage(page);
92
+        param.setScene(taMiniappQrcode.getQrId().toString()); // 使用 qrId 作为 scene
93
+        param.setWidth(860);
94
+        param.setAutoColor(false);
95
+        param.setLineColor(new WxMaCodeLineColor("0", "0", "0"));
96
+        param.setHyaline(true);
97
+
98
+        String qrImage = buildMAQrCode(param);
99
+
100
+        // 再反向更新库
101
+        taMiniappQrcode.setQrImage(qrImage);
102
+        updateById(taMiniappQrcode);
103
+
104
+        return qrImage;
105
+    }
106
+
107
+    /**
108
+     * 生成小程序码, 并上传阿里云
109
+     * @param param
110
+     * @return
111
+     * @throws WxErrorException
112
+     */
113
+    private String buildMAQrCode(WxUtils.AQrCodeParam param) throws WxErrorException, FileNotFoundException {
114
+        WxMaQrcodeService qrcodeService = wxUtils.getService().getQrcodeService();
115
+        File qrFile = qrcodeService.createWxaCodeUnlimit(param.getScene(),
116
+                param.getPage(),
117
+                param.getWidth(),
118
+                param.isAutoColor(),
119
+                param.getLineColor(),
120
+                param.isHyaline());
121
+
122
+        return ossUtils.putObject(qrFile);
123
+    }
124
+}

+ 26
- 0
src/main/java/com/yunzhi/shigongli/service/impl/TaPersonServiceImpl.java Parādīt failu

@@ -1,10 +1,14 @@
1 1
 package com.yunzhi.shigongli.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4
+import com.yunzhi.shigongli.common.Constants;
5
+import com.yunzhi.shigongli.common.StringUtils;
3 6
 import com.yunzhi.shigongli.entity.TaPerson;
4 7
 import com.yunzhi.shigongli.mapper.TaPersonMapper;
5 8
 import com.yunzhi.shigongli.service.ITaPersonService;
6 9
 
7 10
 import org.springframework.stereotype.Service;
11
+import org.springframework.transaction.annotation.Transactional;
8 12
 
9 13
 /**
10 14
  * <p>
@@ -17,4 +21,26 @@ import org.springframework.stereotype.Service;
17 21
 @Service
18 22
 public class TaPersonServiceImpl extends BaseServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
19 23
 
24
+    @Override
25
+    public TaPerson getByOpenid(String openid) {
26
+        if (StringUtils.isEmpty(openid)) {
27
+            return null;
28
+        }
29
+
30
+        LambdaQueryWrapper<TaPerson> queryWrapper = new LambdaQueryWrapper<>();
31
+        queryWrapper.eq(TaPerson::getOpenid, "openid");
32
+        queryWrapper.gt(TaPerson::getStatus, Constants.STATUS_DELETED);
33
+        queryWrapper.last("limit 1");
34
+
35
+        return getOne(queryWrapper);
36
+    }
37
+
38
+    @Transactional(rollbackFor = Exception.class)
39
+    @Override
40
+    public void setRecommender(TaPerson taPerson) throws Exception {
41
+        updateById(taPerson);
42
+
43
+        // 生成推广记录
44
+
45
+    }
20 46
 }

+ 17
- 0
src/main/java/com/yunzhi/shigongli/service/impl/TaShopServiceImpl.java Parādīt failu

@@ -2,12 +2,15 @@ package com.yunzhi.shigongli.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.shigongli.entity.TaShop;
5
+import com.yunzhi.shigongli.entity.TaShopAccount;
6
+import com.yunzhi.shigongli.mapper.TaShopAccountMapper;
5 7
 import com.yunzhi.shigongli.mapper.TaShopMapper;
6 8
 import com.yunzhi.shigongli.service.ITaShopService;
7 9
 
8 10
 import com.yunzhi.shigongli.vo.ShopListVO;
9 11
 import org.springframework.beans.factory.annotation.Autowired;
10 12
 import org.springframework.stereotype.Service;
13
+import org.springframework.transaction.annotation.Transactional;
11 14
 
12 15
 /**
13 16
  * <p>
@@ -23,8 +26,22 @@ public class TaShopServiceImpl extends BaseServiceImpl<TaShopMapper, TaShop> imp
23 26
     @Autowired
24 27
     TaShopMapper taShopMapper;
25 28
 
29
+    @Autowired
30
+    TaShopAccountMapper taShopAccountMapper;
31
+
26 32
     @Override
27 33
     public IPage<ShopListVO> getPageListBy(IPage<ShopListVO> pg, String shopName, String phone) {
28 34
         return taShopMapper.getPageListBy(pg, shopName, phone);
29 35
     }
36
+
37
+    @Transactional(rollbackFor = Exception.class)
38
+    @Override
39
+    public void createNew(TaShop taShop) throws Exception {
40
+        save(taShop);
41
+
42
+        TaShopAccount account = new TaShopAccount();
43
+        account.setShopId(taShop.getShopId());
44
+
45
+        taShopAccountMapper.insert(account);
46
+    }
30 47
 }

+ 39
- 0
src/main/java/com/yunzhi/shigongli/vo/QrCodeParamsVO.java Parādīt failu

@@ -0,0 +1,39 @@
1
+package com.yunzhi.shigongli.vo;
2
+
3
+import com.yunzhi.shigongli.common.StringUtils;
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+import java.util.Map;
9
+
10
+
11
+@ApiModel(description = "修改密码参数")
12
+@Data
13
+public class QrCodeParamsVO {
14
+
15
+    @ApiModelProperty("页面地址")
16
+    String page;
17
+
18
+    @ApiModelProperty("页面类型")
19
+    String type;
20
+
21
+    @ApiModelProperty("页面参数")
22
+    Map<String, Object> scene;
23
+
24
+    /**
25
+     * 获取 scene 字符串
26
+     * @return
27
+     */
28
+    public String getSceneQueryString() {
29
+        if (null == scene) {
30
+            return null;
31
+        }
32
+
33
+        if (!StringUtils.isEmpty(type)) {
34
+            scene.put("type", type);
35
+        }
36
+
37
+        return StringUtils.buildQueryString(scene);
38
+    }
39
+}

+ 5
- 0
src/main/resources/mapper/TaMiniappQrcodeMapper.xml Parādīt failu

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.shigongli.mapper.TaMiniappQrcodeMapper">
4
+
5
+</mapper>