mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update运营商VIP
This commit is contained in:
@@ -4,8 +4,6 @@ import com.google.common.collect.Sets;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.RandomUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -14,129 +12,124 @@ import java.util.Set;
|
||||
* @author jsowell
|
||||
*/
|
||||
public class IdUtils {
|
||||
/**
|
||||
* 获取随机UUID
|
||||
*
|
||||
* @return 随机UUID
|
||||
*/
|
||||
public static String randomUUID() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
/**
|
||||
* 获取随机UUID
|
||||
*
|
||||
* @return 随机UUID
|
||||
*/
|
||||
public static String randomUUID() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 简化的UUID,去掉了横线
|
||||
*
|
||||
* @return 简化的UUID,去掉了横线
|
||||
*/
|
||||
public static String simpleUUID() {
|
||||
return UUID.randomUUID().toString(true);
|
||||
}
|
||||
/**
|
||||
* 简化的UUID,去掉了横线
|
||||
*
|
||||
* @return 简化的UUID,去掉了横线
|
||||
*/
|
||||
public static String simpleUUID() {
|
||||
return UUID.randomUUID().toString(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取随机UUID,使用性能更好的ThreadLocalRandom生成UUID
|
||||
*
|
||||
* @return 随机UUID
|
||||
*/
|
||||
public static String fastUUID() {
|
||||
return UUID.fastUUID().toString();
|
||||
}
|
||||
/**
|
||||
* 获取随机UUID,使用性能更好的ThreadLocalRandom生成UUID
|
||||
*
|
||||
* @return 随机UUID
|
||||
*/
|
||||
public static String fastUUID() {
|
||||
return UUID.fastUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 简化的UUID,去掉了横线,使用性能更好的ThreadLocalRandom生成UUID
|
||||
*
|
||||
* @return 简化的UUID,去掉了横线
|
||||
*/
|
||||
public static String fastSimpleUUID() {
|
||||
return UUID.fastUUID().toString(true);
|
||||
}
|
||||
/**
|
||||
* 简化的UUID,去掉了横线,使用性能更好的ThreadLocalRandom生成UUID
|
||||
*
|
||||
* @return 简化的UUID,去掉了横线
|
||||
*/
|
||||
public static String fastSimpleUUID() {
|
||||
return UUID.fastUUID().toString(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过UUID生成16位唯一订单号
|
||||
*/
|
||||
public static String get16UUID(){
|
||||
// 1.开头两位,标识业务代码或机器代码(可变参数)
|
||||
String machineId = "89";
|
||||
// 2.中间四位整数,标识日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
|
||||
String dayTime = sdf.format(new Date());
|
||||
/**
|
||||
* 通过UUID生成16位唯一订单号
|
||||
*/
|
||||
public static String get16UUID(String prefix) {
|
||||
// 2.生成四位随机整数
|
||||
int valueOf = (int) ((Math.random() * 9 + 1) * 1000);
|
||||
|
||||
// 2.生成四位随机整数
|
||||
int valueOf = (int)((Math.random()*9+1)*1000);
|
||||
|
||||
// 3.生成uuid的hashCode值
|
||||
int hashCode = UUID.randomUUID().toString().hashCode();
|
||||
// 4.可能为负数
|
||||
if(hashCode < 0){
|
||||
hashCode = -hashCode;
|
||||
}
|
||||
// 5.算法处理: 0-代表前面补充0; 10-代表长度为10; d-代表参数为正数型
|
||||
String value = machineId + valueOf + String.format("%010d", hashCode);
|
||||
// System.out.println(value);
|
||||
return value;
|
||||
}
|
||||
// 3.生成uuid的hashCode值
|
||||
int hashCode = UUID.randomUUID().toString().hashCode();
|
||||
// 4.可能为负数
|
||||
if (hashCode < 0) {
|
||||
hashCode = -hashCode;
|
||||
}
|
||||
// 5.算法处理: 开头两位,标识业务代码或机器代码(可变参数) 0-代表前面补充0; 10-代表长度为10; d-代表参数为正数型
|
||||
String value = prefix + valueOf + String.format("%010d", hashCode);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成交易流水号
|
||||
* @param pileSn 桩编号 例如:32010600019236
|
||||
* @param connectorCode 枪口号 例如:01
|
||||
*/
|
||||
public static String generateTransactionCode(String pileSn, String connectorCode) {
|
||||
return generateTransactionCode(pileSn + connectorCode);
|
||||
}
|
||||
/**
|
||||
* 生成交易流水号
|
||||
*
|
||||
* @param pileSn 桩编号 例如:32010600019236
|
||||
* @param connectorCode 枪口号 例如:01
|
||||
*/
|
||||
public static String generateTransactionCode(String pileSn, String connectorCode) {
|
||||
return generateTransactionCode(pileSn + connectorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成交易流水号
|
||||
* 生成规则为 格式桩号(7bytes) +枪号(1byte) +年月日时分秒(6bytes) +自 增序号(2bytes);
|
||||
* @param pileConnectorCode 为已经拼好的充电桩枪口号 例如:3201060001923601
|
||||
* @return 交易流水号 例如:32010600019236012001061803423060 88000000000001012211301501294274
|
||||
*/
|
||||
public static String generateTransactionCode(String pileConnectorCode) {
|
||||
String timeNow = DateUtils.dateTimeNow(DateUtils.YYMMDDHHMMSS);
|
||||
//随机生成一个四位整数
|
||||
String randomNumber = RandomUtil.getRandomNumber(4);
|
||||
return pileConnectorCode + timeNow + randomNumber;
|
||||
}
|
||||
/**
|
||||
* 生成交易流水号
|
||||
* 生成规则为 格式桩号(7bytes) +枪号(1byte) +年月日时分秒(6bytes) +自 增序号(2bytes);
|
||||
*
|
||||
* @param pileConnectorCode 为已经拼好的充电桩枪口号 例如:3201060001923601
|
||||
* @return 交易流水号 例如:32010600019236012001061803423060 88000000000001012211301501294274
|
||||
*/
|
||||
public static String generateTransactionCode(String pileConnectorCode) {
|
||||
String timeNow = DateUtils.dateTimeNow(DateUtils.YYMMDDHHMMSS);
|
||||
// 随机生成一个四位整数
|
||||
String randomNumber = RandomUtil.getRandomNumber(4);
|
||||
return pileConnectorCode + timeNow + randomNumber;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Set<String> set = Sets.newHashSet();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
String id = getOrderCode();
|
||||
set.add(id);
|
||||
System.out.println(id);
|
||||
}
|
||||
System.out.println("set size = " + set.size());
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
Set<String> set = Sets.newHashSet();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
String id = getOrderCode();
|
||||
set.add(id);
|
||||
System.out.println(id);
|
||||
}
|
||||
System.out.println("set size = " + set.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成12位orderCode
|
||||
*/
|
||||
public static String getOrderCode() {
|
||||
long id = Long.parseLong(SnowflakeIdWorker.getSnowflakeId());
|
||||
StringBuilder sb = new StringBuilder(id + "");
|
||||
StringBuilder reverse = sb.reverse();//将id翻转:我们发现id很长,且高位很长部分是一样的数
|
||||
id = new Long(reverse.toString()) / 1000;//切去部分长度
|
||||
while (id > 100000000000L) {
|
||||
id /= 10;
|
||||
}
|
||||
// Integer num = Integer.parseInt(id + "");
|
||||
return String.valueOf(id);
|
||||
}
|
||||
/**
|
||||
* 生成12位orderCode
|
||||
*/
|
||||
public static String getOrderCode() {
|
||||
long id = Long.parseLong(SnowflakeIdWorker.getSnowflakeId());
|
||||
StringBuilder sb = new StringBuilder(id + "");
|
||||
StringBuilder reverse = sb.reverse();// 将id翻转:我们发现id很长,且高位很长部分是一样的数
|
||||
id = new Long(reverse.toString()) / 1000;// 切去部分长度
|
||||
while (id > 100000000000L) {
|
||||
id /= 10;
|
||||
}
|
||||
// Integer num = Integer.parseInt(id + "");
|
||||
return String.valueOf(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成八位会员id
|
||||
*/
|
||||
public static String getMemberId() {
|
||||
long id = Long.parseLong(SnowflakeIdWorker.getSnowflakeId());
|
||||
StringBuilder sb = new StringBuilder(id + "");
|
||||
StringBuilder reverse = sb.reverse();//将id翻转:我们发现id很长,且高位很长部分是一样的数
|
||||
id = new Long(reverse.toString()) / 1000;//切去部分长度
|
||||
while (id > 100000000) {
|
||||
id /= 10;
|
||||
}
|
||||
Integer num = Integer.parseInt(id + "");
|
||||
return String.valueOf(num);
|
||||
}
|
||||
/**
|
||||
* 生成八位会员id
|
||||
*/
|
||||
public static String getMemberId() {
|
||||
long id = Long.parseLong(SnowflakeIdWorker.getSnowflakeId());
|
||||
StringBuilder sb = new StringBuilder(id + "");
|
||||
StringBuilder reverse = sb.reverse();// 将id翻转:我们发现id很长,且高位很长部分是一样的数
|
||||
id = new Long(reverse.toString()) / 1000;// 切去部分长度
|
||||
while (id > 100000000) {
|
||||
id /= 10;
|
||||
}
|
||||
Integer num = Integer.parseInt(id + "");
|
||||
return String.valueOf(num);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -175,6 +175,21 @@ public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService {
|
||||
return memberBasicInfoMapper.selectInfoByMemberId(memberId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成钱包卡号WalletCode
|
||||
* @return
|
||||
*/
|
||||
private String generateWalletCode() {
|
||||
while (true) {
|
||||
String walletCode = IdUtils.get16UUID("89");
|
||||
// 通过walletCode查询是否已经存在
|
||||
MemberWalletInfo memberWalletInfo = memberWalletInfoService.selectByWalletCode(walletCode);
|
||||
if (memberWalletInfo == null) {
|
||||
return walletCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户余额 唯一方法
|
||||
* 接收的金额都是正数,通过操作类型判断 充值还是扣减
|
||||
@@ -201,7 +216,7 @@ public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService {
|
||||
log.warn("根据会员id:{}, 目标运营商id:{}, 查询会员信息为空, 新建会员钱包", memberId, targetMerchantId);
|
||||
// 如果查询到钱包为空,就新建一个该运营商的钱包
|
||||
walletInfo = MemberWalletInfo.builder()
|
||||
.walletCode(IdUtils.get16UUID())
|
||||
.walletCode(generateWalletCode())
|
||||
.memberId(memberId)
|
||||
.merchantId(targetMerchantId)
|
||||
.giftBalance(BigDecimal.ZERO)
|
||||
@@ -299,8 +314,8 @@ public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Set<String> set = Sets.newHashSet();
|
||||
for (int i = 0; i < 10000000; i++) {
|
||||
String s = IdUtils.get16UUID();
|
||||
for (int i = 0; i < 85; i++) {
|
||||
String s = IdUtils.get16UUID("89");
|
||||
System.out.println(s);
|
||||
set.add(s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user