feat(account): 添加问题字段和调用ID关联功能
- 在AccountFrozen实体和DTO中添加question字段用于记录用户问题或需求 - 在AccountTransaction实体中添加callId字段用于关联冻结单调用 - 更新数据库映射文件中的查询和插入语句以支持新增字段 - 在账户冻结服务中实现question字段的赋值逻辑 - 在冻结单释放时将question和callId传递到交易记录中 - 添加数据库表结构变更SQL脚本为account_frozen表增加question字段 - 添加数据库表结构变更SQL脚本为account_transaction表增加call_id字段及索引 - 在用户注册流程中实现邀请奖励机制为被邀请用户赠送积分
This commit is contained in:
parent
e5433853ec
commit
0d934f7287
|
|
@ -0,0 +1,5 @@
|
||||||
|
-- 为 account_frozen 表添加 question 字段
|
||||||
|
-- 用于记录用户的问题或需求
|
||||||
|
|
||||||
|
ALTER TABLE `account_frozen`
|
||||||
|
ADD COLUMN `question` text DEFAULT NULL COMMENT '对应回答的问题或需求' AFTER `model_name`;
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
-- 为 account_transaction 表添加 call_id 字段
|
||||||
|
-- 用于关联冻结单释放时的调用ID
|
||||||
|
|
||||||
|
ALTER TABLE `account_transaction`
|
||||||
|
ADD COLUMN `call_id` varchar(100) DEFAULT NULL COMMENT '调用ID,关联冻结单' AFTER `business_type`;
|
||||||
|
|
||||||
|
-- 添加索引以提高查询性能
|
||||||
|
ALTER TABLE `account_transaction`
|
||||||
|
ADD INDEX `idx_call_id` (`call_id`);
|
||||||
|
|
@ -38,6 +38,9 @@ public class AccountFrozen extends BaseEntity implements Serializable {
|
||||||
@Schema(description ="模型名称")
|
@Schema(description ="模型名称")
|
||||||
private String modelName;
|
private String modelName;
|
||||||
|
|
||||||
|
@Schema(description ="对应回答的问题或需求")
|
||||||
|
private String question;
|
||||||
|
|
||||||
@Schema(description ="冻结金额/张数/次数/分钟")
|
@Schema(description ="冻结金额/张数/次数/分钟")
|
||||||
private BigDecimal frozenAmount;
|
private BigDecimal frozenAmount;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,9 @@ public class AccountTransaction extends BaseEntity implements Serializable {
|
||||||
@Schema(description ="业务类型")
|
@Schema(description ="业务类型")
|
||||||
private String businessType;
|
private String businessType;
|
||||||
|
|
||||||
|
@Schema(description ="调用ID,关联冻结单")
|
||||||
|
private String callId;
|
||||||
|
|
||||||
@Schema(description ="交易备注")
|
@Schema(description ="交易备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ public class AccountFrozenDto {
|
||||||
@Schema(description ="模型名称")
|
@Schema(description ="模型名称")
|
||||||
private String modelName;
|
private String modelName;
|
||||||
|
|
||||||
|
@Schema(description ="对应回答的问题或需求")
|
||||||
|
private String question;
|
||||||
|
|
||||||
@Schema(description ="冻结金额/张数/次数/分钟")
|
@Schema(description ="冻结金额/张数/次数/分钟")
|
||||||
private BigDecimal frozenAmount;
|
private BigDecimal frozenAmount;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 账户冻结单服务实现
|
* 账户冻结单服务实现
|
||||||
|
|
@ -135,6 +136,9 @@ public class AccountFrozenServiceImpl implements AccountFrozenService {
|
||||||
accountFrozen.setSessionId(accountFrozenDto.getSessionId());
|
accountFrozen.setSessionId(accountFrozenDto.getSessionId());
|
||||||
accountFrozen.setCallId(accountFrozenDto.getCallId());
|
accountFrozen.setCallId(accountFrozenDto.getCallId());
|
||||||
accountFrozen.setModelName(accountFrozenDto.getModelName());
|
accountFrozen.setModelName(accountFrozenDto.getModelName());
|
||||||
|
if(Objects.nonNull(accountFrozenDto.getQuestion())){
|
||||||
|
accountFrozen.setQuestion(accountFrozenDto.getQuestion());
|
||||||
|
}
|
||||||
accountFrozen.setFrozenAmount(finalFrozenAmount);
|
accountFrozen.setFrozenAmount(finalFrozenAmount);
|
||||||
accountFrozen.setFrozenType(accountFrozenDto.getFrozenType());
|
accountFrozen.setFrozenType(accountFrozenDto.getFrozenType());
|
||||||
accountFrozen.setStatus("RESERVED");
|
accountFrozen.setStatus("RESERVED");
|
||||||
|
|
@ -261,6 +265,13 @@ public class AccountFrozenServiceImpl implements AccountFrozenService {
|
||||||
transaction.setBusinessType("frozen_release"); // 冻结单释放
|
transaction.setBusinessType("frozen_release"); // 冻结单释放
|
||||||
transaction.setRemark("冻结单释放扣减: " + accountFrozen.getFrozenId());
|
transaction.setRemark("冻结单释放扣减: " + accountFrozen.getFrozenId());
|
||||||
transaction.setIsExpense(1); // 支出
|
transaction.setIsExpense(1); // 支出
|
||||||
|
transaction.setQuestion(accountFrozen.getQuestion());
|
||||||
|
if(Objects.nonNull(accountFrozen.getQuestion())){
|
||||||
|
transaction.setQuestion(accountFrozen.getQuestion());
|
||||||
|
}
|
||||||
|
if(Objects.nonNull(accountFrozen.getCallId())){
|
||||||
|
transaction.setCallId(accountFrozen.getCallId()); // 设置调用ID
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是token消费,记录token信息
|
// 如果是token消费,记录token信息
|
||||||
if (accountReleaseDto.getUsageInputTokens() != null && accountReleaseDto.getUsageOutputTokens() != null) {
|
if (accountReleaseDto.getUsageInputTokens() != null && accountReleaseDto.getUsageOutputTokens() != null) {
|
||||||
|
|
|
||||||
|
|
@ -1030,6 +1030,9 @@ public class SysUserServiceImpl implements SysUserService {
|
||||||
"invite",
|
"invite",
|
||||||
"邀请用户注册赠送"
|
"邀请用户注册赠送"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 给被邀请人(新用户)也赠送100积分作为邀请奖励
|
||||||
|
// 注意:这里先不执行,等账户创建后再执行
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置固定salt为666666
|
// 设置固定salt为666666
|
||||||
|
|
@ -1073,6 +1076,18 @@ public class SysUserServiceImpl implements SysUserService {
|
||||||
"注册赠送"
|
"注册赠送"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 如果有邀请码,额外赠送100积分作为邀请奖励
|
||||||
|
if (inviteCode != null && !inviteCode.isEmpty()) {
|
||||||
|
accountService.addGiftBalance(
|
||||||
|
sysUser.getUserId(),
|
||||||
|
BigDecimal.valueOf(100),
|
||||||
|
"gift_" + System.currentTimeMillis(),
|
||||||
|
null,
|
||||||
|
"invite_reward",
|
||||||
|
"通过邀请码注册赠送"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return sysUser;
|
return sysUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
<result column="call_id" property="callId" />
|
<result column="call_id" property="callId" />
|
||||||
<result column="session_id" property="sessionId" />
|
<result column="session_id" property="sessionId" />
|
||||||
<result column="model_name" property="modelName" />
|
<result column="model_name" property="modelName" />
|
||||||
|
<result column="question" property="question" />
|
||||||
<result column="frozen_amount" property="frozenAmount" />
|
<result column="frozen_amount" property="frozenAmount" />
|
||||||
<result column="frozen_type" property="frozenType" />
|
<result column="frozen_type" property="frozenType" />
|
||||||
<result column="final_amount" property="finalAmount" />
|
<result column="final_amount" property="finalAmount" />
|
||||||
|
|
@ -23,7 +24,7 @@
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
frozen_id, account_transaction_id, user_id, call_id, session_id, model_name, frozen_amount,
|
frozen_id, account_transaction_id, user_id, call_id, session_id, model_name, question, frozen_amount,
|
||||||
frozen_type, final_amount, usage_input_tokens, usage_output_tokens, usage_total_tokens,
|
frozen_type, final_amount, usage_input_tokens, usage_output_tokens, usage_total_tokens,
|
||||||
finalize_reason, status, expire_at, create_time, update_time
|
finalize_reason, status, expire_at, create_time, update_time
|
||||||
</sql>
|
</sql>
|
||||||
|
|
@ -37,11 +38,11 @@
|
||||||
|
|
||||||
<insert id="insert" parameterType="com.kexue.skills.entity.AccountFrozen">
|
<insert id="insert" parameterType="com.kexue.skills.entity.AccountFrozen">
|
||||||
insert into account_frozen
|
insert into account_frozen
|
||||||
(frozen_id, account_transaction_id, user_id, call_id, session_id, model_name, frozen_amount,
|
(frozen_id, account_transaction_id, user_id, call_id, session_id, model_name, question, frozen_amount,
|
||||||
frozen_type, final_amount, usage_input_tokens, usage_output_tokens, usage_total_tokens,
|
frozen_type, final_amount, usage_input_tokens, usage_output_tokens, usage_total_tokens,
|
||||||
finalize_reason, status, expire_at, create_time, update_time)
|
finalize_reason, status, expire_at, create_time, update_time)
|
||||||
values
|
values
|
||||||
(#{frozenId}, #{accountTransactionId}, #{userId}, #{callId}, #{sessionId}, #{modelName}, #{frozenAmount},
|
(#{frozenId}, #{accountTransactionId}, #{userId}, #{callId}, #{sessionId}, #{modelName}, #{question}, #{frozenAmount},
|
||||||
#{frozenType}, #{finalAmount}, #{usageInputTokens}, #{usageOutputTokens}, #{usageTotalTokens},
|
#{frozenType}, #{finalAmount}, #{usageInputTokens}, #{usageOutputTokens}, #{usageTotalTokens},
|
||||||
#{finalizeReason}, #{status}, #{expireAt}, #{createTime}, #{updateTime})
|
#{finalizeReason}, #{status}, #{expireAt}, #{createTime}, #{updateTime})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
@ -54,6 +55,7 @@
|
||||||
call_id = #{callId},
|
call_id = #{callId},
|
||||||
session_id = #{sessionId},
|
session_id = #{sessionId},
|
||||||
model_name = #{modelName},
|
model_name = #{modelName},
|
||||||
|
question = #{question},
|
||||||
frozen_amount = #{frozenAmount},
|
frozen_amount = #{frozenAmount},
|
||||||
frozen_type = #{frozenType},
|
frozen_type = #{frozenType},
|
||||||
final_amount = #{finalAmount},
|
final_amount = #{finalAmount},
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
<result property="payType" column="pay_type" jdbcType="INTEGER"/>
|
<result property="payType" column="pay_type" jdbcType="INTEGER"/>
|
||||||
<result property="businessId" column="business_id" jdbcType="BIGINT"/>
|
<result property="businessId" column="business_id" jdbcType="BIGINT"/>
|
||||||
<result property="businessType" column="business_type" jdbcType="VARCHAR"/>
|
<result property="businessType" column="business_type" jdbcType="VARCHAR"/>
|
||||||
|
<result property="callId" column="call_id" jdbcType="VARCHAR"/>
|
||||||
<result property="remark" column="remark" jdbcType="VARCHAR"/>
|
<result property="remark" column="remark" jdbcType="VARCHAR"/>
|
||||||
<result property="isExpense" column="is_expense" jdbcType="INTEGER"/>
|
<result property="isExpense" column="is_expense" jdbcType="INTEGER"/>
|
||||||
<result property="inputToken" column="input_token" jdbcType="INTEGER"/>
|
<result property="inputToken" column="input_token" jdbcType="INTEGER"/>
|
||||||
|
|
@ -34,7 +35,7 @@
|
||||||
<select id="queryById" resultMap="AccountTransactionMap">
|
<select id="queryById" resultMap="AccountTransactionMap">
|
||||||
select
|
select
|
||||||
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
||||||
transaction_no, pay_type, business_id, business_type, remark, is_expense, input_token, output_token,
|
transaction_no, pay_type, business_id, business_type, call_id, remark, is_expense, input_token, output_token,
|
||||||
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
||||||
from account_transaction
|
from account_transaction
|
||||||
where transaction_id = #{transactionId}
|
where transaction_id = #{transactionId}
|
||||||
|
|
@ -44,7 +45,7 @@
|
||||||
<select id="getPageList" resultMap="AccountTransactionMap">
|
<select id="getPageList" resultMap="AccountTransactionMap">
|
||||||
select
|
select
|
||||||
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
||||||
transaction_no, pay_type, business_id, business_type, remark, is_expense, input_token, output_token,
|
transaction_no, pay_type, business_id, business_type, call_id, remark, is_expense, input_token, output_token,
|
||||||
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
||||||
from account_transaction
|
from account_transaction
|
||||||
<where>
|
<where>
|
||||||
|
|
@ -82,7 +83,7 @@
|
||||||
<select id="getList" resultMap="AccountTransactionMap">
|
<select id="getList" resultMap="AccountTransactionMap">
|
||||||
select
|
select
|
||||||
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
||||||
transaction_no, pay_type, business_id, business_type, remark, is_expense, input_token, output_token,
|
transaction_no, pay_type, business_id, business_type, call_id, remark, is_expense, input_token, output_token,
|
||||||
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
||||||
from account_transaction
|
from account_transaction
|
||||||
<where>
|
<where>
|
||||||
|
|
@ -128,6 +129,7 @@
|
||||||
<if test="payType != null">pay_type,</if>
|
<if test="payType != null">pay_type,</if>
|
||||||
<if test="businessId != null">business_id,</if>
|
<if test="businessId != null">business_id,</if>
|
||||||
<if test="businessType != null">business_type,</if>
|
<if test="businessType != null">business_type,</if>
|
||||||
|
<if test="callId != null">call_id,</if>
|
||||||
<if test="remark != null">remark,</if>
|
<if test="remark != null">remark,</if>
|
||||||
<if test="isExpense != null">is_expense,</if>
|
<if test="isExpense != null">is_expense,</if>
|
||||||
<if test="inputToken != null">input_token,</if>
|
<if test="inputToken != null">input_token,</if>
|
||||||
|
|
@ -154,6 +156,7 @@
|
||||||
<if test="payType != null">#{payType},</if>
|
<if test="payType != null">#{payType},</if>
|
||||||
<if test="businessId != null">#{businessId},</if>
|
<if test="businessId != null">#{businessId},</if>
|
||||||
<if test="businessType != null">#{businessType},</if>
|
<if test="businessType != null">#{businessType},</if>
|
||||||
|
<if test="callId != null">#{callId},</if>
|
||||||
<if test="remark != null">#{remark},</if>
|
<if test="remark != null">#{remark},</if>
|
||||||
<if test="isExpense != null">#{isExpense},</if>
|
<if test="isExpense != null">#{isExpense},</if>
|
||||||
<if test="inputToken != null">#{inputToken},</if>
|
<if test="inputToken != null">#{inputToken},</if>
|
||||||
|
|
@ -185,6 +188,7 @@
|
||||||
<if test="payType != null">pay_type = #{payType},</if>
|
<if test="payType != null">pay_type = #{payType},</if>
|
||||||
<if test="businessId != null">business_id = #{businessId},</if>
|
<if test="businessId != null">business_id = #{businessId},</if>
|
||||||
<if test="businessType != null">business_type = #{businessType},</if>
|
<if test="businessType != null">business_type = #{businessType},</if>
|
||||||
|
<if test="callId != null">call_id = #{callId},</if>
|
||||||
<if test="remark != null">remark = #{remark},</if>
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
<if test="isExpense != null">is_expense = #{isExpense},</if>
|
<if test="isExpense != null">is_expense = #{isExpense},</if>
|
||||||
<if test="inputToken != null">input_token = #{inputToken},</if>
|
<if test="inputToken != null">input_token = #{inputToken},</if>
|
||||||
|
|
@ -219,7 +223,7 @@
|
||||||
<select id="queryByUserId" resultMap="AccountTransactionMap">
|
<select id="queryByUserId" resultMap="AccountTransactionMap">
|
||||||
select
|
select
|
||||||
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
transaction_id, user_id, user_name, transaction_type, amount, before_balance, after_balance, status,
|
||||||
transaction_no, pay_type, business_id, business_type, remark, is_expense, input_token, output_token,
|
transaction_no, pay_type, business_id, business_type, call_id, remark, is_expense, input_token, output_token,
|
||||||
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
total_tokens, model_name, question, income_type, create_time, update_time, create_by, update_by, delete_flag
|
||||||
from account_transaction
|
from account_transaction
|
||||||
where user_id = #{userId}
|
where user_id = #{userId}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue