refactor(ff-admin): 重构租户密钥相关功能

-移除 ApiAgentController 中的 info 方法
- 新增 generateTenantSn 方法到 ITenantSecretKeyService接口
- 实现 TenantSecretKeyServiceImpl 中的 generateTenantSn 方法
- 新增 NumberUtils 类中的 generateRandomCode 方法
- 更新 TenantSecretKeyMapper.xml 中的 SQL语句
- 调整 TenantSecretKey 类,移除不必要的字段
main-p
shi 2025-02-21 16:12:11 +08:00
parent 9ee0e34d16
commit 3c2b86e64f
8 changed files with 78 additions and 32 deletions

View File

@ -10,6 +10,7 @@ import com.ff.base.utils.bean.BeanUtils;
import com.ff.common.domain.TenantGameQuota;
import com.ff.common.domain.TenantSecretKey;
import com.ff.common.service.ITenantGameQuotaService;
import com.ff.common.service.ITenantSecretKeyService;
import com.ff.config.KeyConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
@ -32,22 +33,20 @@ public class ApiAgentController extends BaseController {
@Resource
private ITenantGameQuotaService tenantGameQuotaService;
private ITenantSecretKeyService tenantSecretKeyService;
@Resource
private KeyConfig keyConfig;
/**
*
*
* @return {@link AjaxResult }
*/
@PostMapping("/create/tenant")
public AjaxResult info() {
TenantSecretKey tenantSecretKey = keyConfig.get();
TenantGameQuota tenantGameQuota = tenantGameQuotaService.selectTenantGameQuotaByTenantKey(tenantSecretKey.getTenantKey(), QuotaType.BALANCE.getCode());
TenantInfoResponse tenantInfoResponse= new TenantInfoResponse();
BeanUtils.copyProperties(tenantGameQuota,tenantInfoResponse);
return AjaxResult.success(tenantInfoResponse);
}
// /**
// * 信息
// *
// * @return {@link AjaxResult }
// */
// @PostMapping("/create/tenant")
// public AjaxResult info(TenantSecretKey tenantSecretKey) {
// tenantSecretKey.setAgentId(getUserId());
// tenantSecretKeyService.insertTenantSecretKey(tenantSecretKey);
// return AjaxResult.success(tenantInfoResponse);
// }
}

View File

@ -25,13 +25,7 @@ public class TenantSecretKey extends BaseEntity
/** 主键id */
private Long id;
/** 账号 */
@Excel(name = "账号")
private String account;
/** 密码 */
@Excel(name = "密码")
private String password;
/** 租户key */
@Excel(name = "租户key")

View File

@ -23,6 +23,8 @@ public interface ITenantGameQuotaService
*/
TenantGameQuota selectTenantGameQuotaById(Long id);
/**
*
*

View File

@ -19,6 +19,13 @@ public interface ITenantSecretKeyService
*/
TenantSecretKey selectTenantSecretKeyById(Long id);
/**
* sn
*
* @return {@link String }
*/
String generateTenantSn();
/**
*
*

View File

@ -9,6 +9,7 @@ import com.ff.base.constant.Constants;
import com.ff.base.enums.*;
import com.ff.base.exception.base.ApiException;
import com.ff.base.utils.DateUtils;
import com.ff.base.utils.NumberUtils;
import com.ff.base.utils.QuotaUtils;
import com.ff.base.utils.StringUtils;
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.service.ITenantGameQuotaService;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
@ -74,6 +76,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
return tenantGameQuotaMapper.selectTenantGameQuotaById(id);
}
/**
*
*

View File

@ -2,11 +2,13 @@ package com.ff.common.service.impl;
import java.util.List;
import com.ff.base.utils.DateUtils;
import com.ff.base.utils.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ff.common.mapper.TenantSecretKeyMapper;
import com.ff.common.domain.TenantSecretKey;
import com.ff.common.service.ITenantSecretKeyService;
import org.springframework.util.CollectionUtils;
/**
* Service
@ -32,6 +34,23 @@ public class TenantSecretKeyServiceImpl implements ITenantSecretKeyService
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;
}
/**
*
*

View File

@ -6,8 +6,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="TenantSecretKey" id="TenantSecretKeyResult">
<result property="id" column="id" />
<result property="account" column="account" />
<result property="password" column="password" />
<result property="tenantKey" column="tenant_key" />
<result property="agentId" column="agent_id" />
<result property="tenantSn" column="tenant_sn" />
@ -24,14 +22,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<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>
<select id="selectTenantSecretKeyList" parameterType="TenantSecretKey" resultMap="TenantSecretKeyResult">
<include refid="selectTenantSecretKeyVo"/>
<where>
<if test="account != null and account != ''"> and account = #{account}</if>
<if test="password != null and password != ''"> and password = #{password}</if>
<where>
<if test="tenantKey != null and tenantKey != ''"> and tenant_key = #{tenantKey}</if>
<if test="agentId != null "> and agent_id = #{agentId}</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 into ff_tenant_secret_key
<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="agentId != null">agent_id,</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>
</trim>
<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="agentId != null">#{agentId},</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 ff_tenant_secret_key
<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="agentId != null">agent_id = #{agentId},</if>
<if test="tenantSn != null">tenant_sn = #{tenantSn},</if>

View File

@ -3,6 +3,7 @@ package com.ff.base.utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class NumberUtils {
@ -57,4 +58,34 @@ public class NumberUtils {
// 设置保留两位小数
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();
}
}