TASK:code-create 注册用户添加为AiDA的游客
BUGFIX:0关注状态下获取动态
This commit is contained in:
@@ -1079,6 +1079,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
config.setJdbcUrl("jdbc:mysql://code-create.com.hk:3306/db1nfvsgmjp3b8");
|
||||
config.setUsername("uafqtz4gsvfrw");
|
||||
config.setPassword("aida123456.");
|
||||
// config.setJdbcUrl("jdbc:mysql://localhost:3306/code-create-local?serverTimezone=UTC");
|
||||
// config.setUsername("root");
|
||||
// config.setPassword("root");
|
||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
@@ -1235,6 +1238,86 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
return account;
|
||||
}
|
||||
|
||||
private static final String QUERY_MAXIMUM_USERID = "SELECT MAX(ID) AS max_id FROM pmr_users;";
|
||||
|
||||
private static final String QUERY_NEW_USER_EMAIL = "SELECT user_email FROM pmr_users " +
|
||||
"WHERE ID > ? ";
|
||||
|
||||
@Value("${redis.key.maximumUserId}")
|
||||
private String maximumUserIdKey;
|
||||
|
||||
/**
|
||||
* 将Code-Create上注册的用户添加为AiDA的游客
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void registerUserToVisitor(){
|
||||
ArrayList<String> newUserEmails = new ArrayList<>();
|
||||
long maxUserId = CommonConstant.MAXIMUM_USER_ID;
|
||||
try (Connection connection = dataSource.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(QUERY_MAXIMUM_USERID)) {
|
||||
try (ResultSet queryOrderResultSet = preparedStatement.executeQuery()) {
|
||||
while (queryOrderResultSet.next()) {
|
||||
// 获取最新的最大用户id
|
||||
maxUserId = queryOrderResultSet.getLong("max_id");
|
||||
// 获取历史最大用户id
|
||||
long maxUserIdHistory = StringUtil.isNullOrEmpty(redisUtil.getFromString(maximumUserIdKey)) ? CommonConstant.MAXIMUM_USER_ID : Long.parseLong(redisUtil.getFromString(maximumUserIdKey));
|
||||
if (maxUserId > maxUserIdHistory){
|
||||
// 查出新增用户的邮箱
|
||||
PreparedStatement newUserEmail = connection.prepareStatement(QUERY_NEW_USER_EMAIL);
|
||||
// 填充参数 - 历史最大用户ID
|
||||
newUserEmail.setLong(1, maxUserIdHistory);
|
||||
try (ResultSet queryEmailResultSet = newUserEmail.executeQuery()) {
|
||||
if (queryEmailResultSet.next()) {
|
||||
String email = queryEmailResultSet.getString("user_email");
|
||||
newUserEmails.add(email);
|
||||
} /*else {
|
||||
log.error("未知错误。code-create的用户表中没有付费用户的信息");
|
||||
throw new BusinessException("user info missing");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 记录异常并处理
|
||||
e.printStackTrace();
|
||||
// return null;
|
||||
}
|
||||
|
||||
if (!newUserEmails.isEmpty()){
|
||||
// 查询这些邮箱在aida上是否有账号
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("user_email", newUserEmails).select("user_email");
|
||||
|
||||
List<String> collect = baseMapper.selectList(queryWrapper).stream().map(Account::getUserEmail).collect(Collectors.toList());
|
||||
if (!collect.isEmpty()){
|
||||
// 移除Code-Create新增用户中在AiDA已有账号的邮箱
|
||||
newUserEmails.removeAll(collect);
|
||||
}
|
||||
// 将新增用户添加到AiDA,身份为游客
|
||||
if (!newUserEmails.isEmpty()){
|
||||
newUserEmails.forEach(email -> {
|
||||
Account account = new Account();
|
||||
account.setUserEmail(email);
|
||||
account.setUserName(email);
|
||||
account.setUserPassword("Third-000000");
|
||||
account.setLanguage(Language.ENGLISH.name());
|
||||
account.setCreateDate(new Date());
|
||||
account.setIsTrial(0);
|
||||
account.setIsBeginner(1);
|
||||
account.setCredits(new BigDecimal(0));
|
||||
account.setSystemUser(0);
|
||||
baseMapper.insert(account);
|
||||
// 邮件通知用户
|
||||
SendEmailUtil.notificationForRegisterUser(email);
|
||||
});
|
||||
}
|
||||
// 记录当前最大的用户id
|
||||
redisUtil.addToString(maximumUserIdKey, String.valueOf(maxUserId));
|
||||
}
|
||||
}
|
||||
|
||||
// 收集调查问卷的信息
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.mysql.cj.util.StringUtils;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
@@ -434,11 +435,20 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
|
||||
|
||||
|
||||
// 新增用户
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean addUser(AccountAddDTO accountAddDTO) {
|
||||
// 需要给的数据 用户邮箱、用户名、账号有效期截止时间、账号类型
|
||||
Account account = CopyUtil.copyObject(accountAddDTO, Account.class);
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_email", account.getUserEmail());
|
||||
|
||||
Account existsAccount = accountMapper.selectOne(queryWrapper);
|
||||
if (!Objects.isNull(existsAccount)){
|
||||
throw new BusinessException("The email address already exists. One email address can only register one AiDA account");
|
||||
}
|
||||
|
||||
// 添加正式用户
|
||||
assert accountAddDTO != null;
|
||||
if (Objects.isNull(accountAddDTO.getSystemUser())) {
|
||||
throw new BusinessException("you have to choose user type");
|
||||
} else {
|
||||
|
||||
@@ -401,6 +401,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
designPythonOutfitDetail.setUserId(userId);
|
||||
designPythonOutfitDetail.setOffset(String.valueOf(priorityOffset.get(Math.abs(Integer.parseInt(jsonObject.getString("priority"))))));
|
||||
designPythonOutfitDetail.setPriority((Integer) jsonObject.get("priority"));
|
||||
designPythonOutfitDetail.setCreateDate(LocalDateTime.now());
|
||||
list.add(designPythonOutfitDetail);
|
||||
}
|
||||
return list;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
@@ -81,6 +82,10 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
// 获取历史消息 可指定消息类型 分页查询
|
||||
@Override
|
||||
public PageBaseResponse<NotificationVO> getHistoryNotification(GetNotificationDTO getNotificationDTO) {
|
||||
log.info("获取历史消息:parameter => {}", getNotificationDTO);
|
||||
if (StringUtil.isNullOrEmpty(getNotificationDTO.getType())){
|
||||
throw new BusinessException("type cannot be empty");
|
||||
}
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
// 查动态
|
||||
if (!StringUtils.isNullOrEmpty(getNotificationDTO.getType()) && getNotificationDTO.getType().equals("newPosted")){
|
||||
@@ -291,7 +296,11 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
String lastViewTime = redisUtil.getFromString(lastViewNewPostedTimeKey + ":" + accountId);
|
||||
|
||||
QueryWrapper<Portfolio> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("account_id", followeeList);
|
||||
if (!followeeList.isEmpty()){
|
||||
queryWrapper.in("account_id", followeeList);
|
||||
}else {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
if (!StringUtil.isNullOrEmpty(lastViewTime)){
|
||||
queryWrapper.gt("create_date", lastViewTime);
|
||||
@@ -311,7 +320,12 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
List<Long> followeeList = portfolioService.getFolloweeList(accountId);
|
||||
// 1.2 分页查询我关注的用户发布的作品
|
||||
QueryWrapper<Portfolio> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("account_id", followeeList).orderByDesc("create_date");
|
||||
if (!followeeList.isEmpty()){
|
||||
queryWrapper.in("account_id", followeeList);
|
||||
}else {
|
||||
return new PageBaseResponse<>(new ArrayList<>(), page, size, 0, 0);
|
||||
}
|
||||
queryWrapper.orderByDesc("create_date");
|
||||
Page<Portfolio> portfolioPage = portfolioService.getBaseMapper().selectPage(new Page<>(page, size), queryWrapper);
|
||||
// 2、组装返回的数据
|
||||
|
||||
|
||||
Reference in New Issue
Block a user