记得上下班打卡 | git大法好,push需谨慎

Commit 050d89b6 authored by anjiabin's avatar anjiabin

实现zxtnft购买功能

parent 1cecaaba
...@@ -26,6 +26,8 @@ public class GalaxyUserInfoBo implements Serializable,Cloneable{ ...@@ -26,6 +26,8 @@ public class GalaxyUserInfoBo implements Serializable,Cloneable{
private String userIdentification; private String userIdentification;
private String userPubKey; private String userPubKey;
private String userPriKey; private String userPriKey;
private String routerType;
private String blockChainAddress;
@Override @Override
public String toString(){ public String toString(){
......
...@@ -42,6 +42,6 @@ public class MathUtil { ...@@ -42,6 +42,6 @@ public class MathUtil {
log.info("redisConfig.defaultDb===",redisConfig.defaultDb); log.info("redisConfig.defaultDb===",redisConfig.defaultDb);
log.info("redisConfig.totalDbs===",redisConfig.totalDbs); log.info("redisConfig.totalDbs===",redisConfig.totalDbs);
// redisConfig.getRedisTemplateByDb(MathUtil.getIndex("1",redisConfig.defaultDb,redisConfig.totalDbs)); // redisConfig.getRedisTemplateByDb(MathUtil.getIndex("1",redisConfig.defaultDb,redisConfig.totalDbs));
System.out.println(""+MathUtil.getIndex("redis-test",1,16)); System.out.println(""+MathUtil.getIndex("galaxy:user:zxinchain:1222222",1,16));
} }
} }
...@@ -70,11 +70,11 @@ spring: ...@@ -70,11 +70,11 @@ spring:
profiles: profiles:
include: common-service #这里加载management相关公共配置 include: common-service #这里加载management相关公共配置
redis: redis:
database: ${liquidnet.redis.sweet.database} database: ${liquidnet.redis.galaxy.database}
dbs: ${liquidnet.redis.sweet.dbs} dbs: ${liquidnet.redis.galaxy.dbs}
port: ${liquidnet.redis.sweet.port} port: ${liquidnet.redis.galaxy.port}
host: ${liquidnet.redis.sweet.host} host: ${liquidnet.redis.galaxy.host}
password: ${liquidnet.redis.sweet.password} password: ${liquidnet.redis.galaxy.password}
lettuce: lettuce:
pool: pool:
max-active: 8 max-active: 8
......
...@@ -16,8 +16,10 @@ import com.liquidnet.commons.lang.util.BASE64Util; ...@@ -16,8 +16,10 @@ import com.liquidnet.commons.lang.util.BASE64Util;
import com.liquidnet.commons.lang.util.StringUtil; import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.constant.GalaxyConstant; import com.liquidnet.service.galaxy.constant.GalaxyConstant;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto; import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterRespDto; import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterRespDto;
import com.liquidnet.service.galaxy.utils.DataUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -49,30 +51,37 @@ public class ZxinUserBiz { ...@@ -49,30 +51,37 @@ public class ZxinUserBiz {
@Autowired @Autowired
private ZxlnftConfig zxlnftConfig; private ZxlnftConfig zxlnftConfig;
@Autowired
private DataUtils dataUtils;
public ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto) { public ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto) {
String userId = reqDto.getUserId(); String userId = reqDto.getUserId();
String userName = reqDto.getUserName(); String userName = reqDto.getUserName();
String mobile = reqDto.getMobile(); String mobile = reqDto.getMobile();
String idCardType = reqDto.getIdCardType(); String idCardType = reqDto.getIdCardType();
String idCard = reqDto.getIdCard(); String idCard = reqDto.getIdCard();
String mnemonic = null;
String mnemonic = "stuff name goat health siren dumb gorilla antique board tenant buffalo present"; //安家宾
// String mnemonic = "economy cost balance weapon flight also nut biology very sun slight about"; //周焕
Long index = 0L; Long index = 0L;
String userIdentification = null; String userIdentification = null;
String address = null; String address = null;
String userPubKey = null; String userPubKey = null;
String userPriKey = null; String userPriKey = null;
try{ GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouteType(),userId);
//生成助记词 if(userInfoBo!=null){
CreateMnemonicReq req = CreateMnemonicReq.getNew(); mnemonic = userInfoBo.getMnemonic();
CreateMnemonicResp createMnemonicResp = zxlWalletSdkUtil.createMnemonic(req); }else{
mnemonic = createMnemonicResp.getMnemonic(); try{
}catch(Exception e){ //生成助记词
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),"生成助记词失败!"); CreateMnemonicReq req = CreateMnemonicReq.getNew();
CreateMnemonicResp createMnemonicResp = zxlWalletSdkUtil.createMnemonic(req);
mnemonic = createMnemonicResp.getMnemonic();
}catch(Exception e){
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),"生成助记词失败!");
}
} }
/** /**
* todo 把助记词进行redis存储 key=userID mnemonic/index/userIdentification/address * todo 把助记词进行redis存储 key=userID mnemonic/index/userIdentification/address
*/ */
...@@ -150,6 +159,25 @@ public class ZxinUserBiz { ...@@ -150,6 +159,25 @@ public class ZxinUserBiz {
}else{ }else{
return ResponseDto.failure(nft016Resp.getMessage()); return ResponseDto.failure(nft016Resp.getMessage());
} }
//构造缓存数据
if(userInfoBo==null){
userInfoBo = GalaxyUserInfoBo.getNew();
userInfoBo.setUserId(userId);
userInfoBo.setUserName(userName);
userInfoBo.setMobile(mobile);
userInfoBo.setIdCardType(idCardType);
userInfoBo.setIdCard(idCard);
userInfoBo.setMnemonic(mnemonic);
userInfoBo.setIndex(index.toString());
userInfoBo.setUserIdentification(userIdentification);
userInfoBo.setUserPubKey(userPubKey);
userInfoBo.setUserPriKey(userPriKey);
userInfoBo.setRouterType(GalaxyConstant.RouterTypeEnum.ZXINCHAIN.getCode());
userInfoBo.setBlockChainAddress(address);
dataUtils.setGalaxyUserInfo(reqDto.getRouteType(),reqDto.getUserId(),userInfoBo);
}
} }
return ResponseDto.success(respDto); return ResponseDto.success(respDto);
} }
......
package com.liquidnet.service.galaxy.utils; package com.liquidnet.service.galaxy.utils;
import com.liquidnet.common.cache.redis.util.RedisGalaxyUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.galaxy.constant.GalaxyConstant; import com.liquidnet.service.galaxy.constant.GalaxyConstant;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesInfoBo; import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesInfoBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo; import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
...@@ -13,7 +13,7 @@ import org.springframework.stereotype.Component; ...@@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
@Component @Component
public class DataUtils { public class DataUtils {
@Autowired @Autowired
private RedisGalaxyUtil redisUtil; private RedisUtil redisUtil;
@Autowired @Autowired
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
...@@ -22,6 +22,7 @@ public class DataUtils { ...@@ -22,6 +22,7 @@ public class DataUtils {
public void setGalaxyUserInfo(String routeType,String userId, GalaxyUserInfoBo userInfoBo) { public void setGalaxyUserInfo(String routeType,String userId, GalaxyUserInfoBo userInfoBo) {
redisUtil.set(GalaxyConstant.REDIS_KET_GALAXY_USER.concat(routeType).concat(":") + userId,userInfoBo,keyExpireTime); redisUtil.set(GalaxyConstant.REDIS_KET_GALAXY_USER.concat(routeType).concat(":") + userId,userInfoBo,keyExpireTime);
mongoTemplate.save(userInfoBo,GalaxyUserInfoBo.class.getSimpleName());
} }
public GalaxyUserInfoBo getGalaxyUserInfo(String routeType,String userId) { public GalaxyUserInfoBo getGalaxyUserInfo(String routeType,String userId) {
......
package com.liquidnet.service.galaxy;
import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.service.galaxy.constant.GalaxyConstant;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: TestRedisUtil
* @Package com.liquidnet.service.galaxy
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/3/15 16:26
*/
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class TestRedisUtil {
@Autowired
private RedisDataSourceUtil redisUtil;
private long keyExpireTime = 3600*24*30;
@Test
public void testSet(){
String userId = "test123";
GalaxyUserInfoBo userInfoBo = GalaxyUserInfoBo.getNew();
userInfoBo.setUserId(userId);
String key = GalaxyConstant.REDIS_KET_GALAXY_USER.concat(GalaxyConstant.RouterTypeEnum.ZXINCHAIN.getCode()).concat(":") + userId;
redisUtil.getRedisGalaxyUtil().set(key,userInfoBo,keyExpireTime);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment