Commit 5104cef7 by jscat

nyx app 产品-功能

1. 调整qrcode生成流程
before: java app无需管理qrcode,qrcode生成放在weapp前端
after: java app生成qrcode, 上传阿里云oss, 生成qrcode_url
原因: weapp没有很完善的qrcode生成机制
parent 92028e8a
USE rockwell_key; USE rockwell_key;
...@@ -11,6 +11,7 @@ USE rockwell_key; ...@@ -11,6 +11,7 @@ USE rockwell_key;
- 积分使用状态match_status(可用|不可用): 01|00 - 积分使用状态match_status(可用|不可用): 01|00
- 积分值match_point: 4.5 - 积分值match_point: 4.5
- 答题结果match_result: 9/10 - 答题结果match_result: 9/10
- 二维码url qrcode_url: https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png
- 答题时间create_datetime: 2020/07/30 12:00:00 - 答题时间create_datetime: 2020/07/30 12:00:00
- 更新时间update_datetime: 2020/07/30 12:00:00 - 更新时间update_datetime: 2020/07/30 12:00:00
...@@ -24,6 +25,7 @@ CREATE TABLE tbl_match ( ...@@ -24,6 +25,7 @@ CREATE TABLE tbl_match (
`match_status` VARCHAR(2) COMMENT '(可用|不可用): 01|00; 为什么00,因为所有RequestParam参数的defaultValue都设为0值, 会被认为是空或者null', `match_status` VARCHAR(2) COMMENT '(可用|不可用): 01|00; 为什么00,因为所有RequestParam参数的defaultValue都设为0值, 会被认为是空或者null',
`match_point` double(10,2) COMMENT '得分: 4.5 or 5.0', `match_point` double(10,2) COMMENT '得分: 4.5 or 5.0',
`match_result` VARCHAR(20) COMMENT '结果: 9/10', `match_result` VARCHAR(20) COMMENT '结果: 9/10',
`qrcode_url` VARCHAR(200) COMMENT 'qrcode的二维码url',
`create_datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', `create_datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`update_datetime` DATETIME DEFAULT NULL, `update_datetime` DATETIME DEFAULT NULL,
PRIMARY KEY(`match_id`), PRIMARY KEY(`match_id`),
...@@ -32,6 +34,6 @@ CREATE TABLE tbl_match ( ...@@ -32,6 +34,6 @@ CREATE TABLE tbl_match (
INSERT INTO `tbl_match`(`match_id`, `member_id`, `user_id`, `match_status`, `match_point`,`match_result`, `create_datetime`,`update_datetime`) INSERT INTO `tbl_match`(`match_id`, `member_id`, `user_id`, `match_status`, `match_point`,`match_result`, `create_datetime`,`update_datetime`)
VALUES VALUES
('mid_001', 'mid_123', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '00', 4.5, '9/10', '2019-11-20 11:24:45', '2019-11-20 11:24:45'), ('mid_001', 'mid_123', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '00', 4.5, '9/10', 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('mid_002', 'mid_123', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '01', 4.5, '9/10', '2019-11-20 11:24:45', '2019-11-20 11:24:45'), ('mid_002', 'mid_123', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '01', 4.5, '9/10', 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('mid_003', 'mid_123', 'uid_088a957b-78e9-49cd-980b-ce8bc47b4e11', '01', 4.0, '8/10', '2019-11-20 11:24:45', '2019-11-20 11:24:45'); ('mid_003', 'mid_123', 'uid_088a957b-78e9-49cd-980b-ce8bc47b4e11', '01', 4.0, '8/10', 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png', '2019-11-20 11:24:45', '2019-11-20 11:24:45');
\ No newline at end of file \ No newline at end of file
USE rockwell_key; USE rockwell_key;
...@@ -15,7 +15,7 @@ DROP VIEW IF EXISTS view_match_point; ...@@ -15,7 +15,7 @@ DROP VIEW IF EXISTS view_match_point;
CREATE VIEW view_match_point CREATE VIEW view_match_point
AS AS
SELECT aa.match_id, aa.match_status, aa.member_id, bb.member_name, cc.nickName AS nick_name, aa.match_point, dd.bonus_count, dd.bonus_point, aa.match_point+dd.bonus_point AS total_point, aa.user_id SELECT aa.match_id, aa.match_status, aa.member_id, bb.member_name, cc.nickName AS nick_name, aa.match_point, dd.bonus_count, dd.bonus_point, aa.match_point+dd.bonus_point AS total_point, aa.user_id, aa.qrcode_url
FROM tbl_match aa FROM tbl_match aa
LEFT JOIN tbl_member bb ON aa.member_id=bb.id LEFT JOIN tbl_member bb ON aa.member_id=bb.id
LEFT JOIN rockwell_user.tbl_userinfo cc ON aa.user_id=cc.userid LEFT JOIN rockwell_user.tbl_userinfo cc ON aa.user_id=cc.userid
......
package cn.com.fun.nyxkey.api.domain; package cn.com.fun.nyxkey.api.domain;
...@@ -18,9 +18,10 @@ public class Rockwell_keyT_match{ ...@@ -18,9 +18,10 @@ public class Rockwell_keyT_match{
private String matchId; // 竞答的id uuid format private String matchId; // 竞答的id uuid format
private String memberId; // 商家的id uuid format private String memberId; // 商家的id uuid format
private String userId; // 用户的id uuid format private String userId; // 用户的id uuid format
private String matchStatus; // (可用|不可用): 1| private String matchStatus; // (可用|不可用): 01|00
private Double matchPoint; // 得分: 4.5 or 5.0 private Double matchPoint; // 得分: 4.5 or 5.0
private String matchResult; // 结果: 9/10 private String matchResult; // 结果: 9/10
private String qrcodeUrl; // qrcode的二维码url
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date createDatetime; // 创建时间 private Date createDatetime; // 创建时间
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
......
package cn.com.fun.nyxkey.api.domain; package cn.com.fun.nyxkey.api.domain;
...@@ -16,7 +16,8 @@ import java.util.Date; ...@@ -16,7 +16,8 @@ import java.util.Date;
public class Rockwell_keyV_match_point{ public class Rockwell_keyV_match_point{
private String matchId; // 竞答的id uuid format private String matchId; // 竞答的id uuid format
private String matchStatus; // (可用|不可用): 1| private String matchStatus; // (可用|不可用): 01|00
private String qrcodeUrl; // qrcode的二维码url
private String memberId; // 商家的id uuid format private String memberId; // 商家的id uuid format
private String memberName; // 商家的名称 private String memberName; // 商家的名称
......
package cn.com.fun.nyxkey.api.service; package cn.com.fun.nyxkey.api.service;
...@@ -29,7 +29,8 @@ public interface Rockwell_keyService { ...@@ -29,7 +29,8 @@ public interface Rockwell_keyService {
JSONResult Rockwell_keyServiceGetT_match_by_matchid(String matchId); JSONResult Rockwell_keyServiceGetT_match_by_matchid(String matchId);
JSONResult Rockwell_keyServiceGetT_match_by_page(String memberId, String userId, String matchStatus); JSONResult Rockwell_keyServiceGetT_match_by_page(String memberId, String userId, String matchStatus);
void Rockwell_keyServiceAddT_matchList(List<Rockwell_keyT_match> listRockwell_keyT_match); void Rockwell_keyServiceAddT_matchList(List<Rockwell_keyT_match> listRockwell_keyT_match);
void Rockwell_keyServiceAddT_matchItem(String memberId, String userId, Double matchPoint, String matchResult); void Rockwell_keyServiceAddT_matchItem(String matchId, String memberId, String userId,
Double matchPoint, String matchResult, String qrcodeUrl);
void Rockwell_keyServiceUpdateT_match_status(String matchId); void Rockwell_keyServiceUpdateT_match_status(String matchId);
void Rockwell_keyServiceAddT_match_bonusItem(String matchId, String userId, String userName, Double bonusPoint); void Rockwell_keyServiceAddT_match_bonusItem(String matchId, String userId, String userName, Double bonusPoint);
JSONResult Rockwell_keyServiceGetV_match_point_by_page(String memberId, String userId, String matchStatus); JSONResult Rockwell_keyServiceGetV_match_point_by_page(String memberId, String userId, String matchStatus);
......
package cn.com.fun.nyxkey.api.service; package cn.com.fun.nyxkey.api.service;
...@@ -15,6 +15,7 @@ import java.util.List; ...@@ -15,6 +15,7 @@ import java.util.List;
public interface Rockwell_ossService { public interface Rockwell_ossService {
JSONResult Rockwell_ossServiceGetToken(String userName, String tokenName); JSONResult Rockwell_ossServiceGetToken(String userName, String tokenName);
String Rockwell_ossServiceGetQrcodeUrl(String matchId);
void testQrcode(); void testQrcode();
} }
package cn.com.fun.nyxkey.api.service.impl; package cn.com.fun.nyxkey.api.service.impl;
...@@ -177,16 +177,18 @@ public class Rockwell_keyServiceImpl implements Rockwell_keyService { ...@@ -177,16 +177,18 @@ public class Rockwell_keyServiceImpl implements Rockwell_keyService {
rockwell_keyMapper.addT_matchList(rockwell_keyT_matchQuery); rockwell_keyMapper.addT_matchList(rockwell_keyT_matchQuery);
} }
public void Rockwell_keyServiceAddT_matchItem(String memberId, String userId, Double matchPoint, String matchResult) public void Rockwell_keyServiceAddT_matchItem(String matchId, String memberId, String userId,
Double matchPoint, String matchResult, String qrcodeUrl)
{ {
LOGGER.debug("find Rockwell_keyServiceAddT_matchItem"); LOGGER.debug("find Rockwell_keyServiceAddT_matchItem");
Rockwell_keyT_match rockwell_keyT_match = new Rockwell_keyT_match(); Rockwell_keyT_match rockwell_keyT_match = new Rockwell_keyT_match();
rockwell_keyT_match.setMatchId("mid_"+UUID.randomUUID().toString()); rockwell_keyT_match.setMatchId(matchId);
rockwell_keyT_match.setMatchStatus("1"); rockwell_keyT_match.setMatchStatus("01");
rockwell_keyT_match.setMemberId(memberId); rockwell_keyT_match.setMemberId(memberId);
rockwell_keyT_match.setUserId(userId); rockwell_keyT_match.setUserId(userId);
rockwell_keyT_match.setMatchPoint(matchPoint); rockwell_keyT_match.setMatchPoint(matchPoint);
rockwell_keyT_match.setMatchResult(matchResult); rockwell_keyT_match.setMatchResult(matchResult);
rockwell_keyT_match.setQrcodeUrl(qrcodeUrl);
rockwell_keyT_match.setCreateDatetime(new Date()); rockwell_keyT_match.setCreateDatetime(new Date());
rockwell_keyT_match.setUpdateDatetime(new Date()); rockwell_keyT_match.setUpdateDatetime(new Date());
rockwell_keyMapper.addT_matchItem(rockwell_keyT_match); rockwell_keyMapper.addT_matchItem(rockwell_keyT_match);
......
package cn.com.fun.nyxkey.api.service.impl; package cn.com.fun.nyxkey.api.service.impl;
...@@ -99,6 +99,9 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService { ...@@ -99,6 +99,9 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
@Value("${aliyun.oss.dir}") @Value("${aliyun.oss.dir}")
private String aliyunOssDir; private String aliyunOssDir;
@Value("${aliyun.oss.dirQrcode}")
private String aliyunOssDirQrcode;
/* /*
总体流程 总体流程
1. 获取角色的授权accessid, getToken() 1. 获取角色的授权accessid, getToken()
...@@ -315,7 +318,7 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService { ...@@ -315,7 +318,7 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
PutObjectResult res = ossClient.putObject(putObjectRequest); PutObjectResult res = ossClient.putObject(putObjectRequest);
ossClient.shutdown(); ossClient.shutdown();
if (res != null) { if (res != null) {
return fileKey; return getBucketUrl()+ "/" + fileKey;
} }
return null; return null;
} }
...@@ -353,6 +356,9 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService { ...@@ -353,6 +356,9 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
return respMap; return respMap;
} }
/*
返回bucketUrl
*/
public String getBucketUrl() { public String getBucketUrl() {
String endpoint = aliyunOssEndpoint; // 请填写您的 endpoint。 String endpoint = aliyunOssEndpoint; // 请填写您的 endpoint。
String bucket = aliyunOssBucket; // 请填写您的 bucketname 。 String bucket = aliyunOssBucket; // 请填写您的 bucketname 。
...@@ -360,8 +366,13 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService { ...@@ -360,8 +366,13 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
return host; return host;
} }
/*
public String getQrcode(String text, int width, int height, String filekey) { 输入
param1: 券码 text String text = "mid_123";
param2: dir 和 文件名 String filename = "user_dir/mid_123.png";
输出: url
*/
public String getQrcode(String text, String filename, int width, int height) {
try { try {
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
...@@ -369,7 +380,7 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService { ...@@ -369,7 +380,7 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
MatrixToImageWriter.writeToStream(bitMatrix, "png", os); MatrixToImageWriter.writeToStream(bitMatrix, "png", os);
byte[] bytes = os.toByteArray(); byte[] bytes = os.toByteArray();
String url = ossUploadByteStream(filekey, bytes); String url = ossUploadByteStream(filename, bytes);
if (url == null) { if (url == null) {
return null; return null;
...@@ -381,11 +392,26 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService { ...@@ -381,11 +392,26 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
} }
} }
public void testQrcode(){ /*
String filekey = aliyunOssDir + "this_is_ohlkw.png"; 通过matchId, 生成qrcode, 上传阿里云oss, 获取qrcode_url
String text = "this_is_ohlkw"; */
getQrcode(text, 200, 200, filekey); public String Rockwell_ossServiceGetQrcodeUrl(String matchId)
{
String filename = aliyunOssDirQrcode + matchId + ".png";
String text = matchId;
String url = getQrcode(text, filename, 200, 200);
System.out.println("====qrcode_url: "+url);
return url;
}
/*
Test code; in JUnit Test
*/
public void testQrcode(){
String filename = aliyunOssDirQrcode + "mid_11235813.png";
String text = "mid_11235813";
String url = getQrcode(text, filename, 200, 200);
System.out.println("qrcode_url: "+url);
} }
......
package cn.com.fun.nyxkey.api.web.controller; package cn.com.fun.nyxkey.api.web.controller;
...@@ -37,6 +37,9 @@ public class NyxApiController { ...@@ -37,6 +37,9 @@ public class NyxApiController {
@Autowired @Autowired
private Rockwell_keyService keyService; private Rockwell_keyService keyService;
@Autowired
private Rockwell_ossService ossService;
// 1.1 获取最近10条quiz // 1.1 获取最近10条quiz
// http://localhost:8084/api/financing/hotsearch/report?pageNum=1&pageCount=5 // http://localhost:8084/api/financing/hotsearch/report?pageNum=1&pageCount=5
@ApiOperation(value="顺序获取quiz", notes="获取quiz") @ApiOperation(value="顺序获取quiz", notes="获取quiz")
...@@ -99,6 +102,7 @@ public class NyxApiController { ...@@ -99,6 +102,7 @@ public class NyxApiController {
// APi2 t_match接口 // APi2 t_match接口
// 2.1 为t_match添加match,对应tbl_match // 2.1 为t_match添加match,对应tbl_match
// 输入为list
@ApiOperation(value="为t_match添加match,对应tbl_match", notes="为t_match添加match,对应tbl_match") @ApiOperation(value="为t_match添加match,对应tbl_match", notes="为t_match添加match,对应tbl_match")
@ApiImplicitParams({ @ApiImplicitParams({
}) })
...@@ -113,13 +117,14 @@ public class NyxApiController { ...@@ -113,13 +117,14 @@ public class NyxApiController {
// APi2 t_match接口 jscat 20200731 // APi2 t_match接口 jscat 20200731
// 2.2 为t_match添加match,对应tbl_match // 2.2 为t_match添加match,对应tbl_match
/* 积分生成流程: /* 积分生成流程 v2 (因为小程序端没有特别稳定的qrcode生成library):
1) user_id 参与 member_id 竞答 1) user_id 参与 member_id 竞答
2) 得到 match_point, match_result, 默认 match_status 为1 2) 得到 match_point, match_result, 默认 match_status 为1
3) 生成 match_id 3) 生成 match_id
4)存储到数据库 4) (新增)生成qrcode并上传 得到qrcode_url
5)存储到数据库
积分使用流程: 积分使用流程:
5)小程序前端基于 match_id 生成 qrcode (pros: 1.不需要存储到oss; 2.小程序前端直接生成) 5)(删除)小程序前端基于 match_id 生成 qrcode (pros: 1.不需要存储到oss; 2.小程序前端直接生成)
6)扫一扫识别 qrcode 拿到 match_id 然后后台调用 updateT_match_status() 6)扫一扫识别 qrcode 拿到 match_id 然后后台调用 updateT_match_status()
7) 完成 7) 完成
*/ */
...@@ -138,8 +143,11 @@ public class NyxApiController { ...@@ -138,8 +143,11 @@ public class NyxApiController {
@RequestParam(value = "matchPoint", required = false, defaultValue = "0.0") Double matchPoint, @RequestParam(value = "matchPoint", required = false, defaultValue = "0.0") Double matchPoint,
@RequestParam(value = "matchResult", required = false, defaultValue = "0") String matchResult @RequestParam(value = "matchResult", required = false, defaultValue = "0") String matchResult
) { ) {
//生成matchId
keyService.Rockwell_keyServiceAddT_matchItem(memberId, userId, matchPoint, matchResult); String matchId = "mid_"+UUID.randomUUID().toString();
//生成qrcode, 上传oss,得到qrcode_url
String qrcodeUrl = ossService.Rockwell_ossServiceGetQrcodeUrl(matchId);
keyService.Rockwell_keyServiceAddT_matchItem(matchId, memberId, userId, matchPoint, matchResult, qrcodeUrl);
} }
// APi2 t_match接口 jscat 20200731 // APi2 t_match接口 jscat 20200731
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
...@@ -119,7 +119,7 @@ limitations under the License. ...@@ -119,7 +119,7 @@ limitations under the License.
<!-- match api1-2 新增一条 tbl_match 记录 update jscat 20200731 --> <!-- match api1-2 新增一条 tbl_match 记录 update jscat 20200731 -->
<insert id="addT_matchItem" parameterType="cn.com.fun.nyxkey.api.domain.Rockwell_keyT_match"> <insert id="addT_matchItem" parameterType="cn.com.fun.nyxkey.api.domain.Rockwell_keyT_match">
insert into tbl_match(match_id, member_id, user_id, match_status, match_point, match_result, create_datetime,update_datetime) insert into tbl_match(match_id, member_id, user_id, match_status, match_point, match_result, qrcode_url, create_datetime,update_datetime)
values values
( (
#{matchId}, #{matchId},
...@@ -128,6 +128,7 @@ limitations under the License. ...@@ -128,6 +128,7 @@ limitations under the License.
#{matchStatus}, #{matchStatus},
#{matchPoint}, #{matchPoint},
#{matchResult}, #{matchResult},
#{qrcodeUrl},
#{createDatetime}, #{createDatetime},
#{updateDatetime} #{updateDatetime}
) )
......
server: server:
...@@ -82,3 +82,4 @@ aliyun: ...@@ -82,3 +82,4 @@ aliyun:
bucket: 930-test-sh bucket: 930-test-sh
callbackUrl: http://88.88.88.88:8888 callbackUrl: http://88.88.88.88:8888
dir: user-dir/ dir: user-dir/
dirQrcode: qrcode-dir/
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论