feat(user): 新增用户注册后默认分配5个人设
This commit is contained in:
@@ -36,8 +36,6 @@ public class CharacterController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private KeyboardCharacterService characterService;
|
private KeyboardCharacterService characterService;
|
||||||
@Autowired
|
|
||||||
private ChatModel chatModel;
|
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "人设列表", description = "人设列表接口按 rank 排名")
|
@Operation(summary = "人设列表", description = "人设列表接口按 rank 排名")
|
||||||
@@ -75,7 +73,8 @@ public class CharacterController {
|
|||||||
@PostMapping("/addUserCharacter")
|
@PostMapping("/addUserCharacter")
|
||||||
@Operation(summary = "添加用户人设", description = "添加用户人设接口")
|
@Operation(summary = "添加用户人设", description = "添加用户人设接口")
|
||||||
public BaseResponse<Boolean> addUserCharacter(@RequestBody KeyboardUserCharacterAddDTO addDTO) {
|
public BaseResponse<Boolean> addUserCharacter(@RequestBody KeyboardUserCharacterAddDTO addDTO) {
|
||||||
characterService.addUserCharacter(addDTO);
|
long loginIdAsLong = StpUtil.getLoginIdAsLong();
|
||||||
|
characterService.addUserCharacter(addDTO,loginIdAsLong);
|
||||||
return ResultUtils.success(true);
|
return ResultUtils.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ public interface KeyboardCharacterService extends IService<KeyboardCharacter>{
|
|||||||
|
|
||||||
void updateSort(KeyboardUserCharacterSortUpdateDTO sortUpdateDTO);
|
void updateSort(KeyboardUserCharacterSortUpdateDTO sortUpdateDTO);
|
||||||
|
|
||||||
void addUserCharacter(KeyboardUserCharacterAddDTO addDTO);
|
void addUserCharacter(KeyboardUserCharacterAddDTO addDTO, Long userId);
|
||||||
|
|
||||||
void removeUserCharacter(Long id);
|
void removeUserCharacter(Long id);
|
||||||
|
|
||||||
List<KeyboardCharacterRespVO> selectListWithNotLoginRank();
|
List<KeyboardCharacterRespVO> selectListWithNotLoginRank();
|
||||||
|
|
||||||
List<KeyboardCharacterRespVO> selectListByTagWithNotLogin(Long tagId);
|
List<KeyboardCharacterRespVO> selectListByTagWithNotLogin(Long tagId);
|
||||||
|
|
||||||
|
void addDefaultUserCharacter(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,5 @@ public interface UserService extends IService<KeyboardUser> {
|
|||||||
Boolean verifyMailCode(VerifyCodeDTO verifyCodeDTO);
|
Boolean verifyMailCode(VerifyCodeDTO verifyCodeDTO);
|
||||||
|
|
||||||
Boolean resetPassWord(ResetPassWordDTO resetPassWordDTO);
|
Boolean resetPassWord(ResetPassWordDTO resetPassWordDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.yolo.keyborad.exception.BusinessException;
|
|||||||
import com.yolo.keyborad.model.entity.KeyboardUser;
|
import com.yolo.keyborad.model.entity.KeyboardUser;
|
||||||
import com.yolo.keyborad.model.vo.user.KeyboardUserRespVO;
|
import com.yolo.keyborad.model.vo.user.KeyboardUserRespVO;
|
||||||
import com.yolo.keyborad.service.IAppleService;
|
import com.yolo.keyborad.service.IAppleService;
|
||||||
|
import com.yolo.keyborad.service.KeyboardCharacterService;
|
||||||
import com.yolo.keyborad.service.UserService;
|
import com.yolo.keyborad.service.UserService;
|
||||||
import io.jsonwebtoken.*;
|
import io.jsonwebtoken.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@@ -39,6 +40,8 @@ public class AppleServiceImpl implements IAppleService {
|
|||||||
@Resource
|
@Resource
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyboardCharacterService keyboardCharacterService;
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
/*
|
/*
|
||||||
* @author: ziin
|
* @author: ziin
|
||||||
* @date: 2025/12/3 14:18
|
* @date: 2025/12/3 14:18
|
||||||
@@ -101,10 +102,9 @@ public class KeyboardCharacterServiceImpl extends ServiceImpl<KeyboardCharacterM
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addUserCharacter(KeyboardUserCharacterAddDTO addDTO) {
|
public void addUserCharacter(KeyboardUserCharacterAddDTO addDTO, Long userId) {
|
||||||
// 1. 插入用户人设
|
// 1. 插入用户人设
|
||||||
KeyboardUserCharacter keyboardUserCharacter = BeanUtil.copyProperties(addDTO, KeyboardUserCharacter.class);
|
KeyboardUserCharacter keyboardUserCharacter = BeanUtil.copyProperties(addDTO, KeyboardUserCharacter.class);
|
||||||
long userId = StpUtil.getLoginIdAsLong();
|
|
||||||
keyboardUserCharacter.setUserId(userId);
|
keyboardUserCharacter.setUserId(userId);
|
||||||
KeyboardUserCharacter alreadyExistsCharacter = keyboardUserCharacterMapper.selectOne(
|
KeyboardUserCharacter alreadyExistsCharacter = keyboardUserCharacterMapper.selectOne(
|
||||||
new LambdaQueryWrapper<KeyboardUserCharacter>()
|
new LambdaQueryWrapper<KeyboardUserCharacter>()
|
||||||
@@ -166,4 +166,15 @@ public class KeyboardCharacterServiceImpl extends ServiceImpl<KeyboardCharacterM
|
|||||||
.orderByDesc(KeyboardCharacter::getRank));
|
.orderByDesc(KeyboardCharacter::getRank));
|
||||||
return BeanUtil.copyToList(keyboardCharacters, KeyboardCharacterRespVO.class);
|
return BeanUtil.copyToList(keyboardCharacters, KeyboardCharacterRespVO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDefaultUserCharacter(Long userId) {
|
||||||
|
KeyboardUserCharacterAddDTO keyboardUserCharacterAddDTO = new KeyboardUserCharacterAddDTO();
|
||||||
|
Stream<KeyboardCharacterRespVO> limit = selectListWithNotLoginRank().stream().limit(5);
|
||||||
|
limit.forEach(character -> {
|
||||||
|
keyboardUserCharacterAddDTO.setCharacterId(character.getId());
|
||||||
|
keyboardUserCharacterAddDTO.setEmoji(character.getEmoji());
|
||||||
|
this.addUserCharacter(keyboardUserCharacterAddDTO,userId);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ import com.yolo.keyborad.mapper.KeyboardUserMapper;
|
|||||||
import com.yolo.keyborad.model.dto.user.*;
|
import com.yolo.keyborad.model.dto.user.*;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardUser;
|
import com.yolo.keyborad.model.entity.KeyboardUser;
|
||||||
import com.yolo.keyborad.model.vo.user.KeyboardUserRespVO;
|
import com.yolo.keyborad.model.vo.user.KeyboardUserRespVO;
|
||||||
|
import com.yolo.keyborad.service.KeyboardCharacterService;
|
||||||
import com.yolo.keyborad.service.UserService;
|
import com.yolo.keyborad.service.UserService;
|
||||||
import com.yolo.keyborad.utils.RedisUtil;
|
import com.yolo.keyborad.utils.RedisUtil;
|
||||||
import com.yolo.keyborad.utils.SendMailUtils;
|
import com.yolo.keyborad.utils.SendMailUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.checkerframework.checker.units.qual.K;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
@@ -46,6 +48,8 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyboardCharacterService keyboardCharacterService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeyboardUser selectUserWithSubjectId(String sub) {
|
public KeyboardUser selectUserWithSubjectId(String sub) {
|
||||||
@@ -62,6 +66,7 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
|||||||
keyboardUser.setUid(IdUtil.getSnowflake().nextId());
|
keyboardUser.setUid(IdUtil.getSnowflake().nextId());
|
||||||
keyboardUser.setNickName("User_" + RandomUtil.randomString(6));
|
keyboardUser.setNickName("User_" + RandomUtil.randomString(6));
|
||||||
keyboardUserMapper.insert(keyboardUser);
|
keyboardUserMapper.insert(keyboardUser);
|
||||||
|
keyboardCharacterService.addDefaultUserCharacter(keyboardUser.getId());
|
||||||
return keyboardUser;
|
return keyboardUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,12 +132,16 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
|||||||
keyboardUser.setGender(userRegisterDTO.getGender());
|
keyboardUser.setGender(userRegisterDTO.getGender());
|
||||||
log.info(keyboardUser.toString());
|
log.info(keyboardUser.toString());
|
||||||
String s = redisUtil.get("user:" + userRegisterDTO.getMailAddress());
|
String s = redisUtil.get("user:" + userRegisterDTO.getMailAddress());
|
||||||
if (!s.equals(userRegisterDTO.getVerifyCode())) {
|
if (!userRegisterDTO.getVerifyCode().equals(s)) {
|
||||||
throw new BusinessException(ErrorCode.VERIFY_CODE_ERROR);
|
throw new BusinessException(ErrorCode.VERIFY_CODE_ERROR);
|
||||||
}
|
}
|
||||||
keyboardUser.setEmailVerified(true);
|
keyboardUser.setEmailVerified(true);
|
||||||
redisUtil.delete("user:" + userRegisterDTO.getMailAddress());
|
redisUtil.delete("user:" + userRegisterDTO.getMailAddress());
|
||||||
return keyboardUserMapper.insert(keyboardUser) > 0;
|
int insertCount = keyboardUserMapper.insert(keyboardUser);
|
||||||
|
if (insertCount > 0) {
|
||||||
|
keyboardCharacterService.addDefaultUserCharacter(keyboardUser.getId());
|
||||||
|
}
|
||||||
|
return insertCount > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -190,4 +199,5 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
|||||||
return keyboardUserMapper.updateById(keyboardUser) > 0;
|
return keyboardUserMapper.updateById(keyboardUser) > 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user