refactor(ff-admin): 重构租户密钥相关功能
-移除 ApiAgentController 中的 info 方法 - 新增 generateTenantSn 方法到 ITenantSecretKeyService接口 - 实现 TenantSecretKeyServiceImpl 中的 generateTenantSn 方法 - 新增 NumberUtils 类中的 generateRandomCode 方法 - 更新 TenantSecretKeyMapper.xml 中的 SQL语句 - 调整 TenantSecretKey 类,移除不必要的字段main-p
parent
9ee0e34d16
commit
3c2b86e64f
|
@ -10,6 +10,7 @@ import com.ff.base.utils.bean.BeanUtils;
|
||||||
import com.ff.common.domain.TenantGameQuota;
|
import com.ff.common.domain.TenantGameQuota;
|
||||||
import com.ff.common.domain.TenantSecretKey;
|
import com.ff.common.domain.TenantSecretKey;
|
||||||
import com.ff.common.service.ITenantGameQuotaService;
|
import com.ff.common.service.ITenantGameQuotaService;
|
||||||
|
import com.ff.common.service.ITenantSecretKeyService;
|
||||||
import com.ff.config.KeyConfig;
|
import com.ff.config.KeyConfig;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
@ -32,22 +33,20 @@ public class ApiAgentController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ITenantGameQuotaService tenantGameQuotaService;
|
private ITenantSecretKeyService tenantSecretKeyService;
|
||||||
@Resource
|
@Resource
|
||||||
private KeyConfig keyConfig;
|
private KeyConfig keyConfig;
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 信息
|
// * 信息
|
||||||
*
|
// *
|
||||||
* @return {@link AjaxResult }
|
// * @return {@link AjaxResult }
|
||||||
*/
|
// */
|
||||||
@PostMapping("/create/tenant")
|
// @PostMapping("/create/tenant")
|
||||||
public AjaxResult info() {
|
// public AjaxResult info(TenantSecretKey tenantSecretKey) {
|
||||||
TenantSecretKey tenantSecretKey = keyConfig.get();
|
// tenantSecretKey.setAgentId(getUserId());
|
||||||
TenantGameQuota tenantGameQuota = tenantGameQuotaService.selectTenantGameQuotaByTenantKey(tenantSecretKey.getTenantKey(), QuotaType.BALANCE.getCode());
|
// tenantSecretKeyService.insertTenantSecretKey(tenantSecretKey);
|
||||||
TenantInfoResponse tenantInfoResponse= new TenantInfoResponse();
|
// return AjaxResult.success(tenantInfoResponse);
|
||||||
BeanUtils.copyProperties(tenantGameQuota,tenantInfoResponse);
|
// }
|
||||||
return AjaxResult.success(tenantInfoResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,7 @@ public class TenantSecretKey extends BaseEntity
|
||||||
/** 主键id */
|
/** 主键id */
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/** 账号 */
|
|
||||||
@Excel(name = "账号")
|
|
||||||
private String account;
|
|
||||||
|
|
||||||
/** 密码 */
|
|
||||||
@Excel(name = "密码")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/** 租户key */
|
/** 租户key */
|
||||||
@Excel(name = "租户key")
|
@Excel(name = "租户key")
|
||||||
|
|
|
@ -23,6 +23,8 @@ public interface ITenantGameQuotaService
|
||||||
*/
|
*/
|
||||||
TenantGameQuota selectTenantGameQuotaById(Long id);
|
TenantGameQuota selectTenantGameQuotaById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询租户游戏配额列表
|
* 查询租户游戏配额列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,6 +19,13 @@ public interface ITenantSecretKeyService
|
||||||
*/
|
*/
|
||||||
TenantSecretKey selectTenantSecretKeyById(Long id);
|
TenantSecretKey selectTenantSecretKeyById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成租户sn
|
||||||
|
*
|
||||||
|
* @return {@link String }
|
||||||
|
*/
|
||||||
|
String generateTenantSn();
|
||||||
/**
|
/**
|
||||||
* 按租户密钥选择租户密钥
|
* 按租户密钥选择租户密钥
|
||||||
*
|
*
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.ff.base.constant.Constants;
|
||||||
import com.ff.base.enums.*;
|
import com.ff.base.enums.*;
|
||||||
import com.ff.base.exception.base.ApiException;
|
import com.ff.base.exception.base.ApiException;
|
||||||
import com.ff.base.utils.DateUtils;
|
import com.ff.base.utils.DateUtils;
|
||||||
|
import com.ff.base.utils.NumberUtils;
|
||||||
import com.ff.base.utils.QuotaUtils;
|
import com.ff.base.utils.QuotaUtils;
|
||||||
import com.ff.base.utils.StringUtils;
|
import com.ff.base.utils.StringUtils;
|
||||||
import com.ff.common.domain.TenantGameQuotaFlow;
|
import com.ff.common.domain.TenantGameQuotaFlow;
|
||||||
|
@ -29,6 +30,7 @@ import com.ff.common.mapper.TenantGameQuotaMapper;
|
||||||
import com.ff.common.domain.TenantGameQuota;
|
import com.ff.common.domain.TenantGameQuota;
|
||||||
import com.ff.common.service.ITenantGameQuotaService;
|
import com.ff.common.service.ITenantGameQuotaService;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -74,6 +76,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
return tenantGameQuotaMapper.selectTenantGameQuotaById(id);
|
return tenantGameQuotaMapper.selectTenantGameQuotaById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询租户游戏配额列表
|
* 查询租户游戏配额列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,11 +2,13 @@ package com.ff.common.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.ff.base.utils.DateUtils;
|
import com.ff.base.utils.DateUtils;
|
||||||
|
import com.ff.base.utils.NumberUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ff.common.mapper.TenantSecretKeyMapper;
|
import com.ff.common.mapper.TenantSecretKeyMapper;
|
||||||
import com.ff.common.domain.TenantSecretKey;
|
import com.ff.common.domain.TenantSecretKey;
|
||||||
import com.ff.common.service.ITenantSecretKeyService;
|
import com.ff.common.service.ITenantSecretKeyService;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户租户密钥Service业务层处理
|
* 用户租户密钥Service业务层处理
|
||||||
|
@ -32,6 +34,23 @@ public class TenantSecretKeyServiceImpl implements ITenantSecretKeyService
|
||||||
return tenantSecretKeyMapper.selectTenantSecretKeyById(id);
|
return tenantSecretKeyMapper.selectTenantSecretKeyById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成租户sn
|
||||||
|
*
|
||||||
|
* @return {@link String }
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized String generateTenantSn() {
|
||||||
|
String sn = NumberUtils.generateRandomCode();
|
||||||
|
while (!CollectionUtils.isEmpty(tenantSecretKeyMapper.selectTenantSecretKeyList(TenantSecretKey.builder()
|
||||||
|
.tenantSn(sn)
|
||||||
|
.build()))) {
|
||||||
|
sn = NumberUtils.generateRandomCode();
|
||||||
|
}
|
||||||
|
return sn;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按租户密钥选择租户密钥
|
* 按租户密钥选择租户密钥
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,8 +6,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
|
||||||
<resultMap type="TenantSecretKey" id="TenantSecretKeyResult">
|
<resultMap type="TenantSecretKey" id="TenantSecretKeyResult">
|
||||||
<result property="id" column="id" />
|
<result property="id" column="id" />
|
||||||
<result property="account" column="account" />
|
|
||||||
<result property="password" column="password" />
|
|
||||||
<result property="tenantKey" column="tenant_key" />
|
<result property="tenantKey" column="tenant_key" />
|
||||||
<result property="agentId" column="agent_id" />
|
<result property="agentId" column="agent_id" />
|
||||||
<result property="tenantSn" column="tenant_sn" />
|
<result property="tenantSn" column="tenant_sn" />
|
||||||
|
@ -24,14 +22,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectTenantSecretKeyVo">
|
<sql id="selectTenantSecretKeyVo">
|
||||||
select id, account, password, tenant_key, agent_id, tenant_sn, tenant_secret, tenant_status, quota_type, score_ratio, tenant_type, deposit_ratio, create_by, create_time, update_by, update_time from ff_tenant_secret_key
|
select id, tenant_key, agent_id, tenant_sn, tenant_secret, tenant_status, quota_type, score_ratio, tenant_type, deposit_ratio, create_by, create_time, update_by, update_time from ff_tenant_secret_key
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectTenantSecretKeyList" parameterType="TenantSecretKey" resultMap="TenantSecretKeyResult">
|
<select id="selectTenantSecretKeyList" parameterType="TenantSecretKey" resultMap="TenantSecretKeyResult">
|
||||||
<include refid="selectTenantSecretKeyVo"/>
|
<include refid="selectTenantSecretKeyVo"/>
|
||||||
<where>
|
<where>
|
||||||
<if test="account != null and account != ''"> and account = #{account}</if>
|
|
||||||
<if test="password != null and password != ''"> and password = #{password}</if>
|
|
||||||
<if test="tenantKey != null and tenantKey != ''"> and tenant_key = #{tenantKey}</if>
|
<if test="tenantKey != null and tenantKey != ''"> and tenant_key = #{tenantKey}</if>
|
||||||
<if test="agentId != null "> and agent_id = #{agentId}</if>
|
<if test="agentId != null "> and agent_id = #{agentId}</if>
|
||||||
<if test="tenantSn != null and tenantSn != ''"> and tenant_sn = #{tenantSn}</if>
|
<if test="tenantSn != null and tenantSn != ''"> and tenant_sn = #{tenantSn}</if>
|
||||||
|
@ -57,8 +53,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<insert id="insertTenantSecretKey" parameterType="TenantSecretKey" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertTenantSecretKey" parameterType="TenantSecretKey" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into ff_tenant_secret_key
|
insert into ff_tenant_secret_key
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="account != null">account,</if>
|
|
||||||
<if test="password != null">password,</if>
|
|
||||||
<if test="tenantKey != null and tenantKey != ''">tenant_key,</if>
|
<if test="tenantKey != null and tenantKey != ''">tenant_key,</if>
|
||||||
<if test="agentId != null">agent_id,</if>
|
<if test="agentId != null">agent_id,</if>
|
||||||
<if test="tenantSn != null">tenant_sn,</if>
|
<if test="tenantSn != null">tenant_sn,</if>
|
||||||
|
@ -74,8 +68,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="updateTime != null">update_time,</if>
|
<if test="updateTime != null">update_time,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="account != null">#{account},</if>
|
|
||||||
<if test="password != null">#{password},</if>
|
|
||||||
<if test="tenantKey != null and tenantKey != ''">#{tenantKey},</if>
|
<if test="tenantKey != null and tenantKey != ''">#{tenantKey},</if>
|
||||||
<if test="agentId != null">#{agentId},</if>
|
<if test="agentId != null">#{agentId},</if>
|
||||||
<if test="tenantSn != null">#{tenantSn},</if>
|
<if test="tenantSn != null">#{tenantSn},</if>
|
||||||
|
@ -95,8 +87,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<update id="updateTenantSecretKey" parameterType="TenantSecretKey">
|
<update id="updateTenantSecretKey" parameterType="TenantSecretKey">
|
||||||
update ff_tenant_secret_key
|
update ff_tenant_secret_key
|
||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
<if test="account != null">account = #{account},</if>
|
|
||||||
<if test="password != null">password = #{password},</if>
|
|
||||||
<if test="tenantKey != null and tenantKey != ''">tenant_key = #{tenantKey},</if>
|
<if test="tenantKey != null and tenantKey != ''">tenant_key = #{tenantKey},</if>
|
||||||
<if test="agentId != null">agent_id = #{agentId},</if>
|
<if test="agentId != null">agent_id = #{agentId},</if>
|
||||||
<if test="tenantSn != null">tenant_sn = #{tenantSn},</if>
|
<if test="tenantSn != null">tenant_sn = #{tenantSn},</if>
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.ff.base.utils;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class NumberUtils {
|
public class NumberUtils {
|
||||||
|
@ -57,4 +58,34 @@ public class NumberUtils {
|
||||||
// 设置保留两位小数
|
// 设置保留两位小数
|
||||||
return randomValue.setScale(2, RoundingMode.HALF_UP);
|
return randomValue.setScale(2, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成随机码
|
||||||
|
*
|
||||||
|
* @return {@link String }
|
||||||
|
*/
|
||||||
|
public static String generateRandomCode() {
|
||||||
|
Random random = new Random();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
// 每位字符可以是字母(A-Z, a-z)或数字(0-9)
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
int choice = random.nextInt(3);
|
||||||
|
if (choice == 0) {
|
||||||
|
// 随机字母(大写或小写)
|
||||||
|
char letter = (char) ('A' + random.nextInt(26));
|
||||||
|
sb.append(letter);
|
||||||
|
} else if (choice == 1) {
|
||||||
|
// 随机小写字母
|
||||||
|
char letter = (char) ('a' + random.nextInt(26));
|
||||||
|
sb.append(letter);
|
||||||
|
} else {
|
||||||
|
// 随机数字
|
||||||
|
sb.append(random.nextInt(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue