张延森 3 years ago
parent
commit
c9e2a589d5

+ 46
- 29
src/main/java/com/njyunzhi/pet_identity/controller/TaApplicationController.java View File

@@ -8,6 +8,7 @@ import com.njyunzhi.pet_identity.common.Constants;
8 8
 import com.njyunzhi.pet_identity.common.ResponseBean;
9 9
 import com.njyunzhi.pet_identity.common.StringUtils;
10 10
 import com.njyunzhi.pet_identity.entity.*;
11
+import com.njyunzhi.pet_identity.service.ITaCardNoService;
11 12
 import com.njyunzhi.pet_identity.service.ITaOrderService;
12 13
 import com.njyunzhi.pet_identity.service.ITaPetIdentityService;
13 14
 import com.njyunzhi.pet_identity.vo.AuditParam;
@@ -54,6 +55,9 @@ public class TaApplicationController extends BaseController {
54 55
     @Autowired
55 56
     public ITaOrderService iTaOrderService;
56 57
 
58
+    @Autowired
59
+    public ITaCardNoService iTaCardNoService;
60
+
57 61
     /**
58 62
      * 分页查询列表
59 63
      * @param pageNum
@@ -74,9 +78,7 @@ public class TaApplicationController extends BaseController {
74 78
 
75 79
         if (Constants.WORKFLOW_PROCESS_AUDIT == process) {
76 80
             // 过滤待审批列表
77
-            // 必须是已交费的 或者 续期的
78 81
             queryWrapper.in("status", new Integer[] { Constants.WORKFLOW_STATUS_PROCESSING, Constants.WORKFLOW_STATUS_AUDIT });
79
-            queryWrapper.nested(q -> q.eq("pay_status", Constants.PAY_STATUS_PAID).or().eq("apply_type", Constants.APPLY_TYPE_RENEWAL));
80 82
         } else if (Constants.WORKFLOW_PROCESS_MADE == process) {
81 83
             // 过滤待制卡列表
82 84
             // 必须是审核通过的, 且是初次提审或者挂失补办的
@@ -161,6 +163,8 @@ public class TaApplicationController extends BaseController {
161 163
             if (null == taPetIdentity) {
162 164
                 return ResponseBean.error("未找到原始证件信息");
163 165
             }
166
+
167
+            // 续期不需要缴费, 直接状态位待审核
164 168
             taApplication.setStatus(Constants.WORKFLOW_STATUS_PROCESSING);
165 169
         } else if (Constants.APPLY_TYPE_REISSUE.equals(taApplication.getApplyType())) {
166 170
             // 如果是挂失补办
@@ -246,9 +250,31 @@ public class TaApplicationController extends BaseController {
246 250
             return ResponseBean.error("未找到数据");
247 251
         }
248 252
 
253
+        if (taApplication.getStatus() >= Constants.WORKFLOW_STATUS_AUDIT) {
254
+            return ResponseBean.error("当前记录已审批");
255
+        }
256
+
257
+        if (auditParam.getVerifyStatus() == Constants.AUDIT_STATUS_REJECT) {
258
+            if (StringUtils.isEmpty(auditParam.getRejectReason())) {
259
+                return ResponseBean.error("请填写驳回理由");
260
+            }
261
+
262
+            // 如果已经缴费, 则原路退回费用
263
+            if (Constants.PAY_STATUS_PAID == taApplication.getPayStatus()) {
264
+                iTaOrderService.refundByApplication(taApplication);
265
+            }
266
+        }
267
+
268
+        taApplication.setVerifyStatus(auditParam.getVerifyStatus());
269
+        taApplication.setRejectReason(auditParam.getRejectReason());
270
+        taApplication.setVerifyDate(LocalDateTime.now());
271
+        taApplication.setVerifyUser(sysUser.getUserId());
272
+        taApplication.setVerifyUserName(sysUser.getUserName());
273
+        taApplication.setStatus(Constants.WORKFLOW_STATUS_AUDIT);
274
+
249 275
         if (Constants.APPLY_TYPE_FIRST.equals(taApplication.getApplyType())) {
250 276
             // 办证申请
251
-            if (taApplication.getStatus() < Constants.WORKFLOW_STATUS_PROCESSING) {
277
+            if (taApplication.getPayStatus() != Constants.PAY_STATUS_PAID) {
252 278
                 return ResponseBean.error("用户未支付");
253 279
             }
254 280
         } else if (Constants.APPLY_TYPE_RENEWAL.equals(taApplication.getApplyType())) {
@@ -267,10 +293,14 @@ public class TaApplicationController extends BaseController {
267 293
                 if (!iTaPetIdentityService.extendDate(taPetIdentity)) {
268 294
                     return ResponseBean.error("续期证件失败, 请重试");
269 295
                 }
296
+
297
+                // 续期不需要制卡, 直接变为已制卡
298
+                taApplication.setStatus(Constants.WORKFLOW_STATUS_MADE);
299
+                taApplication.setMakeStatus(Constants.MAKE_STATUS_MADE);
270 300
             }
271 301
         } else if (Constants.APPLY_TYPE_REISSUE.equals(taApplication.getApplyType())) {
272 302
             // 补办
273
-            if (taApplication.getStatus() < Constants.WORKFLOW_STATUS_PROCESSING) {
303
+            if (taApplication.getPayStatus() != Constants.PAY_STATUS_PAID) {
274 304
                 return ResponseBean.error("用户未支付");
275 305
             }
276 306
 
@@ -286,28 +316,6 @@ public class TaApplicationController extends BaseController {
286 316
             return ResponseBean.error("申办业务类型不支持");
287 317
         }
288 318
 
289
-        if (taApplication.getStatus() >= Constants.WORKFLOW_STATUS_AUDIT) {
290
-            return ResponseBean.error("当前记录已审批");
291
-        }
292
-
293
-        if (auditParam.getVerifyStatus() == Constants.AUDIT_STATUS_REJECT) {
294
-            if (StringUtils.isEmpty(auditParam.getRejectReason())) {
295
-                return ResponseBean.error("请填写驳回理由");
296
-            }
297
-
298
-            // 如果已经缴费, 则原路退回费用
299
-            if (Constants.PAY_STATUS_PAID == taApplication.getPayStatus()) {
300
-                iTaOrderService.refundByApplication(taApplication);
301
-            }
302
-        }
303
-
304
-        taApplication.setVerifyStatus(auditParam.getVerifyStatus());
305
-        taApplication.setRejectReason(auditParam.getRejectReason());
306
-        taApplication.setVerifyDate(LocalDateTime.now());
307
-        taApplication.setVerifyUser(sysUser.getUserId());
308
-        taApplication.setVerifyUserName(sysUser.getUserName());
309
-        taApplication.setStatus(Constants.WORKFLOW_STATUS_AUDIT);
310
-
311 319
         if (iTaApplicationService.updateById(taApplication)){
312 320
             return ResponseBean.success(taApplication);
313 321
         }else {
@@ -360,11 +368,20 @@ public class TaApplicationController extends BaseController {
360 368
         }
361 369
 
362 370
         if (StringUtils.isEmpty(makeCardParam.getCardNo())) {
363
-            return ResponseBean.error("证件卡号不能为空");
371
+            return ResponseBean.error("卡号不能为空");
364 372
         } else {
373
+            TaCardNo taCardNo = iTaCardNoService.getUnuseCard(makeCardParam.getCardNo());
374
+            if (taCardNo != null) {
375
+                return ResponseBean.error("卡号无效或者已使用");
376
+            }
377
+
378
+            // 将卡号置为已使用
379
+            taCardNo.setStatus(Constants.STATUS_NORMAL);
380
+            iTaCardNoService.updateById(taCardNo);
381
+
365 382
             TaPetIdentity taPetIdentity = iTaPetIdentityService.getExistBy("card_no", makeCardParam.getCardNo(), false, true);
366
-            if (taPetIdentity != null) {
367
-                return ResponseBean.error("证件卡号已存在");
383
+            if (null != taPetIdentity) {
384
+                return ResponseBean.error("卡号已被占用");
368 385
             }
369 386
         }
370 387
 

+ 95
- 0
src/main/java/com/njyunzhi/pet_identity/controller/TaCardNoController.java View File

@@ -0,0 +1,95 @@
1
+package com.njyunzhi.pet_identity.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.njyunzhi.pet_identity.common.BaseController;
7
+import com.njyunzhi.pet_identity.common.ResponseBean;
8
+import com.njyunzhi.pet_identity.common.StringUtils;
9
+import com.njyunzhi.pet_identity.entity.TaSequence;
10
+import com.njyunzhi.pet_identity.service.ITaSequenceService;
11
+import com.njyunzhi.pet_identity.vo.BatchCardParams;
12
+import io.swagger.annotations.Api;
13
+import io.swagger.annotations.ApiOperation;
14
+import io.swagger.annotations.ApiParam;
15
+import org.slf4j.Logger;
16
+import org.slf4j.LoggerFactory;
17
+import org.springframework.beans.factory.annotation.Autowired;
18
+import org.springframework.web.bind.annotation.PathVariable;
19
+import org.springframework.web.bind.annotation.RequestBody;
20
+import org.springframework.web.bind.annotation.RequestMapping;
21
+import org.springframework.web.bind.annotation.RequestMethod;
22
+import org.springframework.web.bind.annotation.RequestParam;
23
+import com.njyunzhi.pet_identity.service.ITaCardNoService;
24
+import com.njyunzhi.pet_identity.entity.TaCardNo;
25
+import org.springframework.web.bind.annotation.RestController;
26
+
27
+/**
28
+ * <p>
29
+    * 卡号库 前端控制器
30
+    * </p>
31
+ *
32
+ * @author yansen
33
+ * @since 2022-05-28
34
+ */
35
+
36
+@Api(tags = "卡号库")
37
+@RestController
38
+@RequestMapping("/admin")
39
+public class TaCardNoController extends BaseController {
40
+
41
+    private final Logger logger = LoggerFactory.getLogger(TaCardNoController.class);
42
+
43
+    @Autowired
44
+    public ITaCardNoService iTaCardNoService;
45
+
46
+    @Autowired
47
+    public ITaSequenceService iTaSequenceService;
48
+
49
+    /**
50
+     * 分页查询列表
51
+     * @param pageNum
52
+     * @param pageSize
53
+     * @return
54
+     */
55
+    @RequestMapping(value="/cardNo",method= RequestMethod.GET)
56
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
57
+    public ResponseBean taCardNoList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
58
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
59
+
60
+        IPage<TaCardNo> pg = new Page<>(pageNum, pageSize);
61
+        QueryWrapper<TaCardNo> queryWrapper = new QueryWrapper<>();
62
+        queryWrapper.orderByDesc("create_date");
63
+
64
+        IPage<TaCardNo> result = iTaCardNoService.page(pg, queryWrapper);
65
+        return ResponseBean.success(result);
66
+    }
67
+
68
+    /**
69
+     * 保存对象
70
+     * @param batchCardParams 实体对象
71
+     * @return
72
+     */
73
+    @RequestMapping(value="/carNo/batch",method= RequestMethod.POST)
74
+    @ApiOperation(value="批量生成卡号", notes = "批量生成卡号", httpMethod = "POST", response = ResponseBean.class)
75
+    public ResponseBean taCardNoAdd(@ApiParam("保存内容") @RequestBody BatchCardParams batchCardParams) throws Exception{
76
+
77
+        if (StringUtils.isEmpty(batchCardParams.getPrefix())) {
78
+            return ResponseBean.error("请输入卡号前缀");
79
+        }
80
+        if (batchCardParams.getNum() == null || batchCardParams.getNum() < 1) {
81
+            return ResponseBean.error("请设置生成卡号数量");
82
+        }
83
+
84
+        Integer maxNum = 9999;
85
+        TaSequence taSequence = iTaSequenceService.getById("card-" + batchCardParams.getPrefix());
86
+        if (null != taSequence && taSequence.getValue() + batchCardParams.getNum() >= 9999) {
87
+            return ResponseBean.error(String.format("当前前缀合法卡号剩余 %d", maxNum - taSequence.getValue()));
88
+        }
89
+
90
+        iTaCardNoService.createBatchCardNo(batchCardParams);
91
+
92
+        return ResponseBean.success("ok");
93
+    }
94
+
95
+}

+ 119
- 0
src/main/java/com/njyunzhi/pet_identity/controller/TaMiniappQrcodeController.java View File

@@ -0,0 +1,119 @@
1
+package com.njyunzhi.pet_identity.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.njyunzhi.pet_identity.common.BaseController;
7
+import com.njyunzhi.pet_identity.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+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;
19
+import com.njyunzhi.pet_identity.service.ITaMiniappQrcodeService;
20
+import com.njyunzhi.pet_identity.entity.TaMiniappQrcode;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 小程序码 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-05-28
30
+ */
31
+
32
+@Api(tags = "小程序码")
33
+@RestController
34
+@RequestMapping("/")
35
+public class TaMiniappQrcodeController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(TaMiniappQrcodeController.class);
38
+
39
+    @Autowired
40
+    public ITaMiniappQrcodeService iTaMiniappQrcodeService;
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
+    }
109
+
110
+    /**
111
+     * 根据id查询对象
112
+     * @param id  实体ID
113
+     */
114
+    @RequestMapping(value="/taMiniappQrcode/{id}",method= RequestMethod.GET)
115
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+    public ResponseBean taMiniappQrcodeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+        return ResponseBean.success(iTaMiniappQrcodeService.getById(id));
118
+    }
119
+}

+ 49
- 0
src/main/java/com/njyunzhi/pet_identity/entity/TaCardNo.java View File

@@ -0,0 +1,49 @@
1
+package com.njyunzhi.pet_identity.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import java.time.LocalDateTime;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import java.io.Serializable;
7
+import io.swagger.annotations.ApiModel;
8
+import io.swagger.annotations.ApiModelProperty;
9
+import lombok.Data;
10
+import lombok.EqualsAndHashCode;
11
+import lombok.experimental.Accessors;
12
+
13
+/**
14
+ * <p>
15
+ * 卡号库
16
+ * </p>
17
+ *
18
+ * @author yansen
19
+ * @since 2022-05-28
20
+ */
21
+@Data
22
+@EqualsAndHashCode(callSuper = false)
23
+@Accessors(chain = true)
24
+@ApiModel(value="TaCardNo对象", description="卡号库")
25
+public class TaCardNo implements Serializable {
26
+
27
+    private static final long serialVersionUID = 1L;
28
+
29
+    @ApiModelProperty(value = "卡号")
30
+    @TableId(value = "card_no", type = IdType.INPUT)
31
+    private String cardNo;
32
+
33
+    @ApiModelProperty(value = "关联小程序码")
34
+    private String qrId;
35
+
36
+    @ApiModelProperty(value = "小程序码图片地址")
37
+    private String qrImage;
38
+
39
+    @ApiModelProperty(value = "卡模板图片")
40
+    private String tplImage;
41
+
42
+    @ApiModelProperty(value = "状态;0未使用,1已使用")
43
+    private Integer status;
44
+
45
+    @ApiModelProperty(value = "生成日期")
46
+    private LocalDateTime createDate;
47
+
48
+
49
+}

+ 52
- 0
src/main/java/com/njyunzhi/pet_identity/entity/TaMiniappQrcode.java View File

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

+ 18
- 0
src/main/java/com/njyunzhi/pet_identity/mapper/TaCardNoMapper.java View File

@@ -0,0 +1,18 @@
1
+package com.njyunzhi.pet_identity.mapper;
2
+
3
+import com.njyunzhi.pet_identity.entity.TaCardNo;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 卡号库 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-05-28
14
+ */
15
+@Mapper
16
+public interface TaCardNoMapper extends BaseMapper<TaCardNo> {
17
+
18
+}

+ 18
- 0
src/main/java/com/njyunzhi/pet_identity/mapper/TaMiniappQrcodeMapper.java View File

@@ -0,0 +1,18 @@
1
+package com.njyunzhi.pet_identity.mapper;
2
+
3
+import com.njyunzhi.pet_identity.entity.TaMiniappQrcode;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 小程序码 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-05-28
14
+ */
15
+@Mapper
16
+public interface TaMiniappQrcodeMapper extends BaseMapper<TaMiniappQrcode> {
17
+
18
+}

+ 20
- 0
src/main/java/com/njyunzhi/pet_identity/service/ITaCardNoService.java View File

@@ -0,0 +1,20 @@
1
+package com.njyunzhi.pet_identity.service;
2
+
3
+import com.njyunzhi.pet_identity.entity.TaCardNo;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.njyunzhi.pet_identity.vo.BatchCardParams;
6
+
7
+/**
8
+ * <p>
9
+ * 卡号库 服务类
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-05-28
14
+ */
15
+public interface ITaCardNoService extends IService<TaCardNo> {
16
+
17
+    TaCardNo getUnuseCard(String cardNo);
18
+
19
+    void createBatchCardNo(BatchCardParams batchCardParams) throws Exception;
20
+}

+ 17
- 0
src/main/java/com/njyunzhi/pet_identity/service/ITaMiniappQrcodeService.java View File

@@ -0,0 +1,17 @@
1
+package com.njyunzhi.pet_identity.service;
2
+
3
+import com.njyunzhi.pet_identity.entity.TaMiniappQrcode;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 小程序码 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-05-28
13
+ */
14
+public interface ITaMiniappQrcodeService extends IService<TaMiniappQrcode> {
15
+
16
+    TaMiniappQrcode createQRCode(String page, String scene) throws Exception;
17
+}

+ 83
- 0
src/main/java/com/njyunzhi/pet_identity/service/impl/TaCardNoServiceImpl.java View File

@@ -0,0 +1,83 @@
1
+package com.njyunzhi.pet_identity.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.njyunzhi.pet_identity.common.Constants;
5
+import com.njyunzhi.pet_identity.common.StringUtils;
6
+import com.njyunzhi.pet_identity.entity.TaCardNo;
7
+import com.njyunzhi.pet_identity.entity.TaMiniappQrcode;
8
+import com.njyunzhi.pet_identity.mapper.TaCardNoMapper;
9
+import com.njyunzhi.pet_identity.mapper.TaSequenceMapper;
10
+import com.njyunzhi.pet_identity.service.ITaCardNoService;
11
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
12
+import com.njyunzhi.pet_identity.service.ITaMiniappQrcodeService;
13
+import com.njyunzhi.pet_identity.vo.BatchCardParams;
14
+import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.beans.factory.annotation.Value;
16
+import org.springframework.scheduling.annotation.Async;
17
+import org.springframework.stereotype.Service;
18
+
19
+import java.time.LocalDateTime;
20
+
21
+/**
22
+ * <p>
23
+ * 卡号库 服务实现类
24
+ * </p>
25
+ *
26
+ * @author yansen
27
+ * @since 2022-05-28
28
+ */
29
+@Service
30
+public class TaCardNoServiceImpl extends ServiceImpl<TaCardNoMapper, TaCardNo> implements ITaCardNoService {
31
+
32
+    @Autowired
33
+    TaSequenceMapper taSequenceMapper;
34
+
35
+    @Autowired
36
+    ITaMiniappQrcodeService iTaMiniappQrcodeService;
37
+
38
+    @Value("${yz.miniapp.qrpath}")
39
+    String qrpath;
40
+
41
+    @Override
42
+    public TaCardNo getUnuseCard(String cardNo) {
43
+        if (StringUtils.isEmpty(cardNo)) return null;
44
+
45
+        TaCardNo taCardNo = getById(cardNo);
46
+
47
+        // 已经关联的无效
48
+        if (Constants.STATUS_READY != taCardNo.getStatus()) return null;
49
+
50
+        // 没有小程序码的无效
51
+        if (StringUtils.isEmpty(taCardNo.getQrId())) return null;
52
+
53
+        return taCardNo;
54
+    }
55
+
56
+    @Async
57
+    @Override
58
+    public void createBatchCardNo(BatchCardParams batchCardParams) throws Exception {
59
+        LocalDateTime now = LocalDateTime.now();
60
+
61
+        for (int i = 0; i < batchCardParams.getNum(); i += 1) {
62
+            Integer nextVal = taSequenceMapper.getNextVal("card-" + batchCardParams.getPrefix());
63
+            String cardNo = batchCardParams.getPrefix() + StringUtils.lpad(nextVal.toString(), "0", 4);
64
+            String scene = "page=carddetail&cardno=" + cardNo;
65
+
66
+            // 生成小程序码
67
+            TaMiniappQrcode qrCode = iTaMiniappQrcodeService.createQRCode(qrpath, scene);
68
+            // 生成模板图片
69
+            // TODO
70
+
71
+            TaCardNo taCardNo = new TaCardNo();
72
+            taCardNo.setCardNo(cardNo);
73
+            taCardNo.setQrId(qrCode.getQrId().toString());
74
+            taCardNo.setQrImage(qrCode.getQrImage());
75
+            taCardNo.setStatus(Constants.STATUS_READY);
76
+            taCardNo.setCreateDate(now);
77
+
78
+            if (!save(taCardNo)) {
79
+                throw new Exception("生成卡号失败");
80
+            }
81
+        }
82
+    }
83
+}

+ 86
- 0
src/main/java/com/njyunzhi/pet_identity/service/impl/TaMiniappQrcodeServiceImpl.java View File

@@ -0,0 +1,86 @@
1
+package com.njyunzhi.pet_identity.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.njyunzhi.pet_identity.common.OSSUtils;
7
+import com.njyunzhi.pet_identity.common.StringUtils;
8
+import com.njyunzhi.pet_identity.common.WxUtils;
9
+import com.njyunzhi.pet_identity.entity.TaMiniappQrcode;
10
+import com.njyunzhi.pet_identity.mapper.TaMiniappQrcodeMapper;
11
+import com.njyunzhi.pet_identity.service.ITaMiniappQrcodeService;
12
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13
+import me.chanjar.weixin.common.error.WxErrorException;
14
+import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.beans.factory.annotation.Value;
16
+import org.springframework.stereotype.Service;
17
+
18
+import java.io.File;
19
+import java.io.FileNotFoundException;
20
+import java.time.LocalDateTime;
21
+
22
+/**
23
+ * <p>
24
+ * 小程序码 服务实现类
25
+ * </p>
26
+ *
27
+ * @author yansen
28
+ * @since 2022-05-28
29
+ */
30
+@Service
31
+public class TaMiniappQrcodeServiceImpl extends ServiceImpl<TaMiniappQrcodeMapper, TaMiniappQrcode> implements ITaMiniappQrcodeService {
32
+
33
+    @Autowired
34
+    WxUtils wxUtils;
35
+    
36
+    @Autowired
37
+    OSSUtils ossUtils;
38
+
39
+    @Value("${weixin.miniapp.appid}")
40
+    String miniAppid;
41
+
42
+    @Override
43
+    public TaMiniappQrcode createQRCode(String page, String scene) throws Exception {
44
+        TaMiniappQrcode taMiniappQrcode = getByPageAndScene(page, scene);
45
+        if (null != taMiniappQrcode) return taMiniappQrcode;
46
+
47
+        // 调用SDK
48
+        String qrImage = buildMAQrCode(page, scene);
49
+        taMiniappQrcode = new TaMiniappQrcode();
50
+        taMiniappQrcode.setMiniappId(miniAppid);
51
+        taMiniappQrcode.setPage(page);
52
+        taMiniappQrcode.setScene(scene);
53
+        taMiniappQrcode.setQrImage(qrImage);
54
+
55
+        if (!save(taMiniappQrcode)) {
56
+            throw new Exception("生成小程序码失败, 请重试");
57
+        }
58
+
59
+        return taMiniappQrcode;
60
+    }
61
+
62
+    public TaMiniappQrcode getByPageAndScene(String page, String scene) {
63
+        LambdaQueryWrapper<TaMiniappQrcode> queryWrapper = new LambdaQueryWrapper<>();
64
+        queryWrapper.eq(TaMiniappQrcode::getMiniappId, miniAppid)
65
+                .eq(TaMiniappQrcode::getPage, page)
66
+                .eq(!StringUtils.isEmpty(scene), TaMiniappQrcode::getScene, scene)
67
+                .orderByDesc(TaMiniappQrcode::getCreateDate)
68
+                .last("limit 1");
69
+
70
+        return getOne(queryWrapper);
71
+    }
72
+
73
+    /**
74
+     * 生成小程序码, 并上传阿里云
75
+     * @param page
76
+     * @param scene
77
+     * @return
78
+     * @throws WxErrorException
79
+     */
80
+    private String buildMAQrCode(String page, String scene) throws WxErrorException, FileNotFoundException {
81
+        WxMaQrcodeService qrcodeService = wxUtils.getMaService().getQrcodeService();
82
+        File qrFile = qrcodeService.createWxaCodeUnlimit(scene, page);
83
+
84
+        return ossUtils.putObject(qrFile);
85
+    }
86
+}

+ 17
- 0
src/main/java/com/njyunzhi/pet_identity/vo/BatchCardParams.java View File

@@ -0,0 +1,17 @@
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
+
8
+@ApiModel(description = "批量生成卡号参数")
9
+@Data
10
+public class BatchCardParams {
11
+
12
+    @ApiModelProperty("卡号前缀")
13
+    String prefix;
14
+
15
+    @ApiModelProperty("生成数量")
16
+    Integer num;
17
+}

+ 2
- 0
src/main/resources/application.yml View File

@@ -42,6 +42,8 @@ sms:
42 42
 yz:
43 43
   default:
44 44
     servBase: https://pet-certificate-online.njyunzhi.com/api
45
+  miniapp:
46
+    qrpath: pages/qrcode/index
45 47
   sms:
46 48
     ## ??????
47 49
     appid: ubpa

+ 5
- 0
src/main/resources/mapper/TaCardNoMapper.xml View File

@@ -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.njyunzhi.pet_identity.mapper.TaCardNoMapper">
4
+
5
+</mapper>

+ 5
- 0
src/main/resources/mapper/TaMiniappQrcodeMapper.xml View File

@@ -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.njyunzhi.pet_identity.mapper.TaMiniappQrcodeMapper">
4
+
5
+</mapper>