apps创建唯一性调整
This commit is contained in:
1 parent
221b7c4f96
commit
410d777c0b
3 files changed
+23
-1
No files matched your search
@@ -15,6 +15,12 @@ import com.ruoyi.system.domain.AppsPlus;
|
||||
*/
|
||||
public interface AppsMapper extends BaseMapper<AppsPlus>
|
||||
{
|
||||
/** 锁定所属用户,串行化同一用户的应用创建。 */
|
||||
Long lockUserById(@Param("userId") Long userId);
|
||||
|
||||
/** 查询用户当前未删除的应用数量。 */
|
||||
int countActiveAppsByUserId(@Param("userId") Long userId);
|
||||
|
||||
int updatePublicKey(@Param("id") Long id, @Param("publicKey") String publicKey,
|
||||
@Param("updatedAt") java.util.Date updatedAt);
|
||||
|
||||
|
||||
@@ -286,15 +286,23 @@ public class AppsServiceImpl extends ServiceImpl<AppsMapper, AppsPlus> implement
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertApps(Apps apps, boolean isUser) {
|
||||
validateAppForCreate(apps, isUser);
|
||||
Long ownerUserId = isUser ? SecurityUtils.getUserId() : apps.getUserId();
|
||||
if (ownerUserId == null || appsMapper.lockUserById(ownerUserId) == null) {
|
||||
throw new CustomException("所属用户不存在");
|
||||
}
|
||||
if (appsMapper.countActiveAppsByUserId(ownerUserId) > 0) {
|
||||
throw new CustomException("该用户已经创建商户应用,每个用户只能创建一个应用");
|
||||
}
|
||||
apps.setUserId(ownerUserId);
|
||||
// 每个新应用统一使用全局配置主钱包地址,忽略请求中可能伪造的归集地址。
|
||||
apps.setDistTokenAddress(getGlobalAggregationAddress());
|
||||
apps.setCreatedAt(DateUtils.getNowDate());
|
||||
apps.setUpdatedAt(DateUtils.getNowDate());
|
||||
apps.setDeletedAt(null);
|
||||
if (isUser) {
|
||||
apps.setUserId(SecurityUtils.getUserId());
|
||||
apps.setTrxBalance(BigDecimal.ZERO);
|
||||
apps.setUsdtBalance(BigDecimal.ZERO);
|
||||
apps.setCreditLimit(BigDecimal.ZERO);
|
||||
|
||||
@@ -28,6 +28,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select id, user_id, name, description, status, created_at, updated_at, deleted_at, trx_balance, usdt_balance, public_key, credit_limit, google_sub, google_email, google_name, google_picture, dist_token_address from apps
|
||||
</sql>
|
||||
|
||||
<select id="lockUserById" resultType="Long">
|
||||
select user_id from sys_user where user_id = #{userId} for update
|
||||
</select>
|
||||
|
||||
<select id="countActiveAppsByUserId" resultType="int">
|
||||
select count(1) from apps where user_id = #{userId} and deleted_at is null
|
||||
</select>
|
||||
|
||||
<select id="selectAppsList" parameterType="Apps" resultMap="AppsResult">
|
||||
<include refid="selectAppsVo"/>
|
||||
<where>
|
||||
|
||||
Reference in new issue
Block a user