Your Name 3 年之前
父節點
當前提交
22958157f9

+ 69
- 69
src/main/java/com/njyunzhi/pet_identity/controller/TaMiniappQrcodeController.java 查看文件

@@ -39,80 +39,80 @@ public class TaMiniappQrcodeController extends BaseController {
39 39
     @Autowired
40 40
     public ITaMiniappQrcodeService iTaMiniappQrcodeService;
41 41
 
42
-
43
-    /**
44
-     * 分页查询列表
45
-     * @param pageNum
46
-     * @param pageSize
47
-     * @return
48
-     */
49
-    @RequestMapping(value="/taMiniappQrcode",method= RequestMethod.GET)
50
-    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
-    public ResponseBean taMiniappQrcodeList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
-
54
-		    IPage<TaMiniappQrcode> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaMiniappQrcode> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
57
-
58
-            IPage<TaMiniappQrcode> result = iTaMiniappQrcodeService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
60
-    }
61
-
62
-    /**
63
-     * 保存对象
64
-     * @param taMiniappQrcode 实体对象
65
-     * @return
66
-     */
67
-    @RequestMapping(value="/taMiniappQrcode",method= RequestMethod.POST)
68
-    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
-    public ResponseBean taMiniappQrcodeAdd(@ApiParam("保存内容") @RequestBody TaMiniappQrcode taMiniappQrcode) throws Exception{
70
-
71
-        if (iTaMiniappQrcodeService.save(taMiniappQrcode)){
72
-            return ResponseBean.success(taMiniappQrcode);
73
-        }else {
74
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
-        }
76
-    }
77
-
78
-    /**
79
-     * 根据id删除对象
80
-     * @param id  实体ID
81
-     */
82
-    @RequestMapping(value="/taMiniappQrcode/{id}", method= RequestMethod.DELETE)
83
-    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taMiniappQrcodeDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaMiniappQrcodeService.removeById(id)){
86
-            return ResponseBean.success("success");
87
-        }else {
88
-            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
-        }
90
-    }
91
-
92
-    /**
93
-     * 修改对象
94
-     * @param id  实体ID
95
-     * @param taMiniappQrcode 实体对象
96
-     * @return
97
-     */
98
-    @RequestMapping(value="/taMiniappQrcode/{id}",method= RequestMethod.PUT)
99
-    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taMiniappQrcodeUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
-                                        @ApiParam("更新内容") @RequestBody TaMiniappQrcode taMiniappQrcode) throws Exception{
102
-
103
-        if (iTaMiniappQrcodeService.updateById(taMiniappQrcode)){
104
-            return ResponseBean.success(iTaMiniappQrcodeService.getById(id));
105
-        }else {
106
-            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
-        }
108
-    }
42
+//
43
+//    /**
44
+//     * 分页查询列表
45
+//     * @param pageNum
46
+//     * @param pageSize
47
+//     * @return
48
+//     */
49
+//    @RequestMapping(value="/taMiniappQrcode",method= RequestMethod.GET)
50
+//    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+//    public ResponseBean taMiniappQrcodeList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+//									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+//
54
+//		    IPage<TaMiniappQrcode> pg = new Page<>(pageNum, pageSize);
55
+//            QueryWrapper<TaMiniappQrcode> queryWrapper = new QueryWrapper<>();
56
+//            queryWrapper.orderByDesc("create_date");
57
+//
58
+//            IPage<TaMiniappQrcode> result = iTaMiniappQrcodeService.page(pg, queryWrapper);
59
+//            return ResponseBean.success(result);
60
+//    }
61
+//
62
+//    /**
63
+//     * 保存对象
64
+//     * @param taMiniappQrcode 实体对象
65
+//     * @return
66
+//     */
67
+//    @RequestMapping(value="/taMiniappQrcode",method= RequestMethod.POST)
68
+//    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+//    public ResponseBean taMiniappQrcodeAdd(@ApiParam("保存内容") @RequestBody TaMiniappQrcode taMiniappQrcode) throws Exception{
70
+//
71
+//        if (iTaMiniappQrcodeService.save(taMiniappQrcode)){
72
+//            return ResponseBean.success(taMiniappQrcode);
73
+//        }else {
74
+//            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+//        }
76
+//    }
77
+//
78
+//    /**
79
+//     * 根据id删除对象
80
+//     * @param id  实体ID
81
+//     */
82
+//    @RequestMapping(value="/taMiniappQrcode/{id}", method= RequestMethod.DELETE)
83
+//    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+//    public ResponseBean taMiniappQrcodeDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+//        if(iTaMiniappQrcodeService.removeById(id)){
86
+//            return ResponseBean.success("success");
87
+//        }else {
88
+//            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+//        }
90
+//    }
91
+//
92
+//    /**
93
+//     * 修改对象
94
+//     * @param id  实体ID
95
+//     * @param taMiniappQrcode 实体对象
96
+//     * @return
97
+//     */
98
+//    @RequestMapping(value="/taMiniappQrcode/{id}",method= RequestMethod.PUT)
99
+//    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+//    public ResponseBean taMiniappQrcodeUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+//                                        @ApiParam("更新内容") @RequestBody TaMiniappQrcode taMiniappQrcode) throws Exception{
102
+//
103
+//        if (iTaMiniappQrcodeService.updateById(taMiniappQrcode)){
104
+//            return ResponseBean.success(iTaMiniappQrcodeService.getById(id));
105
+//        }else {
106
+//            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+//        }
108
+//    }
109 109
 
110 110
     /**
111 111
      * 根据id查询对象
112 112
      * @param id  实体ID
113 113
      */
114
-    @RequestMapping(value="/taMiniappQrcode/{id}",method= RequestMethod.GET)
115
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
114
+    @RequestMapping(value="/wx/{clientId}/qrcode/{id}",method= RequestMethod.GET)
115
+    @ApiOperation(value="查询二维码详情", notes = "查询二维码详情", httpMethod = "GET", response = ResponseBean.class)
116 116
     public ResponseBean taMiniappQrcodeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117 117
         return ResponseBean.success(iTaMiniappQrcodeService.getById(id));
118 118
     }

+ 1
- 1
src/main/java/com/njyunzhi/pet_identity/entity/TaMiniappQrcode.java 查看文件

@@ -27,7 +27,7 @@ public class TaMiniappQrcode implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "小程序码ID")
30
-    @TableId(value = "qr_id", type = IdType.AUTO)
30
+    @TableId(value = "qr_id", type = IdType.INPUT)
31 31
     private Integer qrId;
32 32
 
33 33
     @ApiModelProperty(value = "小程序ID")

+ 2
- 1
src/main/java/com/njyunzhi/pet_identity/service/ITaMiniappQrcodeService.java 查看文件

@@ -2,6 +2,7 @@ package com.njyunzhi.pet_identity.service;
2 2
 
3 3
 import com.njyunzhi.pet_identity.entity.TaMiniappQrcode;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.njyunzhi.pet_identity.vo.MiniAppScene;
5 6
 
6 7
 /**
7 8
  * <p>
@@ -13,5 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 14
  */
14 15
 public interface ITaMiniappQrcodeService extends IService<TaMiniappQrcode> {
15 16
 
16
-    TaMiniappQrcode createQRCode(String page, String scene) throws Exception;
17
+    TaMiniappQrcode createQRCode(MiniAppScene scene) throws Exception;
17 18
 }

+ 5
- 5
src/main/java/com/njyunzhi/pet_identity/service/impl/TaCardNoServiceImpl.java 查看文件

@@ -11,6 +11,7 @@ import com.njyunzhi.pet_identity.service.ITaCardNoService;
11 11
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
12 12
 import com.njyunzhi.pet_identity.service.ITaMiniappQrcodeService;
13 13
 import com.njyunzhi.pet_identity.vo.BatchCardParams;
14
+import com.njyunzhi.pet_identity.vo.MiniAppScene;
14 15
 import org.springframework.beans.factory.annotation.Autowired;
15 16
 import org.springframework.beans.factory.annotation.Value;
16 17
 import org.springframework.scheduling.annotation.Async;
@@ -35,8 +36,8 @@ public class TaCardNoServiceImpl extends ServiceImpl<TaCardNoMapper, TaCardNo> i
35 36
     @Autowired
36 37
     ITaMiniappQrcodeService iTaMiniappQrcodeService;
37 38
 
38
-    @Value("${yz.miniapp.qrpath}")
39
-    String qrpath;
39
+    @Value("${yz.miniapp.cardpath}")
40
+    String cardpath;
40 41
 
41 42
     @Override
42 43
     public TaCardNo getUnuseCard(String cardNo) {
@@ -62,11 +63,10 @@ public class TaCardNoServiceImpl extends ServiceImpl<TaCardNoMapper, TaCardNo> i
62 63
         for (int i = 0; i < batchCardParams.getNum(); i += 1) {
63 64
             Integer nextVal = taSequenceMapper.getNextVal("card-" + batchCardParams.getPrefix());
64 65
             String cardNo = batchCardParams.getPrefix() + StringUtils.lpad(nextVal.toString(), "0", 4);
65
-            String scene = StringUtils.urlEncode(String.format("page=%s&cardno=%s", "cardinfo", cardNo));
66
+            MiniAppScene scene = new MiniAppScene().setPage(cardpath).setQueryStr("cardno=" + StringUtils.urlEncode(cardNo));
66 67
 
67 68
             // 生成小程序码
68
-            qrpath = StringUtils.trim(qrpath, "/"); // 去掉开头的 /
69
-            TaMiniappQrcode qrCode = iTaMiniappQrcodeService.createQRCode(qrpath, scene);
69
+            TaMiniappQrcode qrCode = iTaMiniappQrcodeService.createQRCode(scene);
70 70
             // 生成模板图片
71 71
             // TODO
72 72
 

+ 26
- 12
src/main/java/com/njyunzhi/pet_identity/service/impl/TaMiniappQrcodeServiceImpl.java 查看文件

@@ -2,14 +2,17 @@ package com.njyunzhi.pet_identity.service.impl;
2 2
 
3 3
 import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
4 4
 import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
5
+import com.alibaba.fastjson.JSON;
5 6
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
6 7
 import com.njyunzhi.pet_identity.common.OSSUtils;
7 8
 import com.njyunzhi.pet_identity.common.StringUtils;
8 9
 import com.njyunzhi.pet_identity.common.WxUtils;
9 10
 import com.njyunzhi.pet_identity.entity.TaMiniappQrcode;
10 11
 import com.njyunzhi.pet_identity.mapper.TaMiniappQrcodeMapper;
12
+import com.njyunzhi.pet_identity.mapper.TaSequenceMapper;
11 13
 import com.njyunzhi.pet_identity.service.ITaMiniappQrcodeService;
12 14
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
15
+import com.njyunzhi.pet_identity.vo.MiniAppScene;
13 16
 import me.chanjar.weixin.common.error.WxErrorException;
14 17
 import org.springframework.beans.factory.annotation.Autowired;
15 18
 import org.springframework.beans.factory.annotation.Value;
@@ -39,20 +42,32 @@ public class TaMiniappQrcodeServiceImpl extends ServiceImpl<TaMiniappQrcodeMappe
39 42
     @Value("${weixin.miniapp.appid}")
40 43
     String miniAppid;
41 44
 
45
+    @Value("${yz.miniapp.qrpath}")
46
+    String qrpath;
47
+
42 48
     @Value("${yz.miniapp.qrEnv}")
43 49
     String envVersion;
44 50
 
51
+    @Autowired
52
+    TaSequenceMapper taSequenceMapper;
53
+
45 54
     @Override
46
-    public TaMiniappQrcode createQRCode(String page, String scene) throws Exception {
47
-        TaMiniappQrcode taMiniappQrcode = getByPageAndScene(page, scene);
55
+    public TaMiniappQrcode createQRCode(MiniAppScene scene) throws Exception {
56
+        String sceneStr = JSON.toJSONString(scene);
57
+        TaMiniappQrcode taMiniappQrcode = getByScene(sceneStr);
48 58
         if (null != taMiniappQrcode) return taMiniappQrcode;
49 59
 
50
-        // 调用SDK
51
-        String qrImage = buildMAQrCode(page, scene);
60
+        // 从 nextval 是从 0 开始, qrcodeId 必须从 +1 开始
61
+        Integer qrCodeID = taSequenceMapper.getNextVal("qrcode") + 1;
62
+
63
+        // 调用SDK, 生成小程序码, 小程序码的 scene 实际上是 TaMiniappQrcode 的主键
64
+        String qrImage = buildMAQrCode(qrCodeID.toString());
65
+        //
52 66
         taMiniappQrcode = new TaMiniappQrcode();
67
+        taMiniappQrcode.setQrId(qrCodeID);
53 68
         taMiniappQrcode.setMiniappId(miniAppid);
54
-        taMiniappQrcode.setPage(page);
55
-        taMiniappQrcode.setScene(scene);
69
+        taMiniappQrcode.setPage(qrpath);
70
+        taMiniappQrcode.setScene(sceneStr);
56 71
         taMiniappQrcode.setQrImage(qrImage);
57 72
 
58 73
         if (!save(taMiniappQrcode)) {
@@ -62,11 +77,11 @@ public class TaMiniappQrcodeServiceImpl extends ServiceImpl<TaMiniappQrcodeMappe
62 77
         return taMiniappQrcode;
63 78
     }
64 79
 
65
-    public TaMiniappQrcode getByPageAndScene(String page, String scene) {
80
+    public TaMiniappQrcode getByScene(String sceneStr) {
66 81
         LambdaQueryWrapper<TaMiniappQrcode> queryWrapper = new LambdaQueryWrapper<>();
67 82
         queryWrapper.eq(TaMiniappQrcode::getMiniappId, miniAppid)
68
-                .eq(TaMiniappQrcode::getPage, page)
69
-                .eq(!StringUtils.isEmpty(scene), TaMiniappQrcode::getScene, scene)
83
+                .eq(TaMiniappQrcode::getPage, qrpath)
84
+                .eq(TaMiniappQrcode::getScene, sceneStr)
70 85
                 .orderByDesc(TaMiniappQrcode::getCreateDate)
71 86
                 .last("limit 1");
72 87
 
@@ -75,15 +90,14 @@ public class TaMiniappQrcodeServiceImpl extends ServiceImpl<TaMiniappQrcodeMappe
75 90
 
76 91
     /**
77 92
      * 生成小程序码, 并上传阿里云
78
-     * @param page
79 93
      * @param scene
80 94
      * @return
81 95
      * @throws WxErrorException
82 96
      */
83
-    private String buildMAQrCode(String page, String scene) throws WxErrorException, FileNotFoundException {
97
+    private String buildMAQrCode(String scene) throws WxErrorException, FileNotFoundException {
84 98
         WxMaQrcodeService qrcodeService = wxUtils.getMaService().getQrcodeService();
85 99
         File qrFile = qrcodeService.createWxaCodeUnlimit(scene,
86
-                page,
100
+                qrpath,
87 101
                 false, // checkPath
88 102
                 envVersion,
89 103
                 430, // width

+ 19
- 0
src/main/java/com/njyunzhi/pet_identity/vo/MiniAppScene.java 查看文件

@@ -0,0 +1,19 @@
1
+package com.njyunzhi.pet_identity.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+import lombok.experimental.Accessors;
8
+
9
+@ApiModel(description = "小程序二维码参数")
10
+@Data
11
+@Accessors(chain = true)
12
+public class MiniAppScene {
13
+
14
+    @ApiModelProperty(value = "页面地址",notes = "")
15
+    String page;
16
+
17
+    @ApiModelProperty(value = "页面参数",notes = "")
18
+    String queryStr;
19
+}

+ 2
- 0
src/main/resources/application.yml 查看文件

@@ -43,7 +43,9 @@ yz:
43 43
   default:
44 44
     servBase: https://pet-certificate-online.njyunzhi.com/api
45 45
   miniapp:
46
+    # 以下小程序页面地址, 不能以 / 开头
46 47
     qrpath: pages/qrcode/index
48
+    cardpath: pages/dogCardDetail/index
47 49
     qrEnv: develop
48 50
   sms:
49 51
     ## ??????