@@ -12,10 +12,7 @@ import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.ResultEnum ;
import com.ai.da.common.security.jwt.JWTTokenHelper ;
import com.ai.da.common.utils.* ;
import com.ai.da.mapper.primary.AccountExtendMapper ;
import com.ai.da.mapper.primary.AccountMapper ;
import com.ai.da.mapper.primary.QuestionnaireMapper ;
import com.ai.da.mapper.primary.TrialOrderMapper ;
import com.ai.da.mapper.primary.* ;
import com.ai.da.mapper.primary.entity.* ;
import com.ai.da.model.dto.* ;
import com.ai.da.model.enums.AutoApproved ;
@@ -97,12 +94,18 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Resource
private AccountLoginLogService accountLoginLogService ;
@Resource
private ConvenientInquiryService convenientInquiryService ;
@Resource
private LibraryService libraryService ;
@Resource
private OrderInfoService orderInfoService ;
@Resource
private OrganizationMapper organizationMapper ;
@Resource
private TrialOrderMapper trialOrderMapper ;
@@ -151,9 +154,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) & & ! StringUtil . isNullOrEmpty ( accountDTO . getPassword ( ) ) ) {
account . setUserPassword ( accountDTO . getPassword ( ) ) ;
accountMapper . updateById ( account ) ;
} else if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) ) {
} else if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) ) {
throw new BusinessException ( " password.cannot.be.empty " ) ;
} else {
} else {
if ( ! account . getUserPassword ( ) . equals ( accountDTO . getPassword ( ) ) ) {
throw new BusinessException ( " password.error " , ResultEnum . PROMPT . getCode ( ) ) ;
}
@@ -252,9 +255,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
response . setSystemUser ( account . getSystemUser ( ) ) ;
// 设置头像
String avatar ;
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
avatar = CommonConstant . DEFAULT_AVATAR ;
} else {
} else {
avatar = account . getAvatar ( ) ;
}
response . setAvatar ( minioUtil . getPreSignedUrl ( avatar , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
@@ -278,9 +281,12 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return accountList . get ( 0 ) ;
}
// 定义常量(临时)
private static final Integer SYSTEM_USER_TYPE_EDU_ADMIN = 7 ;
private void validateUserValidaExpire ( Account account ) {
Long currentTime = new Date ( ) . getTime ( ) ;
if ( account . getSystemUser ( ) . equals ( 0 ) ) {
if ( account . getSystemUser ( ) . equals ( 0 ) ) {
return ;
}
if ( Objects . nonNull ( account . getValidStartTime ( ) ) ) {
@@ -289,19 +295,26 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
}
if ( Objects . nonNull ( account . getValidEndTime ( ) ) ) {
if ( currentTime > account . getValidEndTime ( ) ) {
toVisitor ( account ) ;
return ;
// throw new BusinessException("user.expired");
boolean isExpired = currentTime > account . getValidEndTime ( ) ;
boolean isEduAdmin = SYSTEM_USER_TYPE_EDU_ADMIN . equals ( account . getSystemUser ( ) ) ;
if ( isExpired ) {
if ( isEduAdmin ) {
setEduAdminToExpire ( account ) ;
} else {
toVisitor ( account ) ;
return ;
// throw new BusinessException("user.expired");
}
}
}
}
// 判断当前用户应该从哪个入口登录
private void validateEduOrComLogin ( Account account ) {
private void validateEduOrComLogin ( Account account ) {
// 获取当前用户的身份,判断应该选择的登录入口
if ( Objects . nonNull ( account ) & & Objects . nonNull ( account . getSystemUser ( ) ) ) {
switch ( account . getSystemUser ( ) ) {
if ( Objects . nonNull ( account ) & & Objects . nonNull ( account . getSystemUser ( ) ) ) {
switch ( account . getSystemUser ( ) ) {
case 7 :
case 8 :
throw new BusinessException ( " school.account.login " , ResultEnum . PROMPT . getCode ( ) ) ;
@@ -533,7 +546,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( Objects . nonNull ( emailSendDTO . getUserId ( ) ) & &
( ! StringUtil . isNullOrEmpty ( emailSendDTO . getCountry ( ) ) | | ! StringUtil . isNullOrEmpty ( emailSendDTO . getOccupation ( ) )
| | StringUtils . isEmpty ( emailSendDTO . getSurname ( ) ) | | StringUtils . isNotEmpty ( emailSendDTO . getTitle ( ) ) ) ) {
| | StringUtils . isEmpty ( emailSendDTO . getSurname ( ) ) | | StringUtils . isNotEmpty ( emailSendDTO . getTitle ( ) ) ) ) {
Account account = baseMapper . selectById ( emailSendDTO . getUserId ( ) ) ;
account . setCountry ( emailSendDTO . getCountry ( ) ) ;
account . setOccupation ( emailSendDTO . getOccupation ( ) ) ;
@@ -549,9 +562,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
break ;
case UPDATE_USERINFO :
if ( ! StringUtil . isNullOrEmpty ( emailSendDTO . getCountry ( ) ) | | ! StringUtil . isNullOrEmpty ( emailSendDTO . getOccupation ( ) )
| | StringUtils . isEmpty ( emailSendDTO . getSurname ( ) ) | | StringUtils . isNotEmpty ( emailSendDTO . getTitle ( ) )
| | StringUtils . isNotEmpty ( emailSendDTO . getGivenName ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( emailSendDTO . getEmail ( ) ) ) {
| | StringUtils . isEmpty ( emailSendDTO . getSurname ( ) ) | | StringUtils . isNotEmpty ( emailSendDTO . getTitle ( ) )
| | StringUtils . isNotEmpty ( emailSendDTO . getGivenName ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( emailSendDTO . getEmail ( ) ) ) {
throw new BusinessException ( " email.cannot.be.empty " ) ;
}
// todo 如果之后允许存在相同的邮件,但是所属机构不同的情况,这里需要做修改
@@ -615,7 +628,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Boolean addUser ( AccountAddDTO accountAddDTO ) {
Account account ;
account = CopyUtil . copyObject ( accountAddDTO , Account . class ) ;
account = CopyUtil . copyObject ( accountAddDTO , Account . class ) ;
// account.setUserEmail(accountAddDTO.getUserEmail());
// account.setUserName(accountAddDTO.getUserName());
// account.setIsTrial(accountAddDTO.getIsTrial());
@@ -1079,8 +1092,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
int i = 0 ;
int size = accountList . size ( ) ;
for ( Account account : accountList ) {
i + + ;
if ( account ! = null & & ! StringUtil . isNullOrEmpty ( account . getUserEmail ( ) ) ) {
i + + ;
if ( account ! = null & & ! StringUtil . isNullOrEmpty ( account . getUserEmail ( ) ) ) {
try {
if ( account . getLanguage ( ) . equals ( Language . CHINESE_SIMPLIFIED . name ( ) ) ) {
log . info ( " 进度:{} / {} CN - {} " , i , size , account . getUserEmail ( ) ) ;
@@ -1090,11 +1103,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 英文
SendEmailUtil . sendUpgradeNotification ( account , null , 1 ) ;
}
} catch ( Exception e ) {
} catch ( Exception e ) {
log . error ( " 向 {} 发送邮件失败 " , account . getUserEmail ( ) ) ;
log . error ( e . getMessage ( ) ) ;
}
} else if ( account ! = null ) {
} else if ( account ! = null ) {
log . warn ( " 用户id 为 {},邮箱为空 " , account . getId ( ) ) ;
} else {
log . warn ( " 进度:{} / {} account 为空 " , i , size ) ;
@@ -1187,7 +1200,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// }
// }
// }
i + + ;
i + + ;
log . info ( " 十月优惠邮件成功发送第 " + i + " 条 " ) ;
}
}
@@ -1203,13 +1216,13 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
Account updateAcc = new Account ( ) ;
updateAcc . setId ( account . getId ( ) ) ;
updateAcc . setCredits ( new BigDecimal ( value ) ) ;
if ( Objects . nonNull ( endTime ) ) {
if ( Objects . nonNull ( endTime ) ) {
updateAcc . setValidEndTime ( toDayEnd ( endTime ) ) ;
}
if ( Objects . nonNull ( creditsUsage ) ) {
if ( Objects . nonNull ( creditsUsage ) ) {
// 机构的积分使用量不会超过上限
BigDecimal creditsUsageLimit = Objects . isNull ( account . getCreditsUsageLimit ( ) ) ? BigDecimal . ZERO : account . getCreditsUsageLimit ( ) ;
if ( creditsUsage . compareTo ( creditsUsageLimit ) > 0 ) {
if ( creditsUsage . compareTo ( creditsUsageLimit ) > 0 ) {
updateAcc . setCreditsUsage ( creditsUsageLimit ) ;
} else {
updateAcc . setCreditsUsage ( creditsUsage ) ;
@@ -1340,7 +1353,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
int orderId = queryOrderResultSet . getInt ( " order_id " ) ;
int customerId = queryOrderResultSet . getInt ( " customer_id " ) ;
double totalSales = queryOrderResultSet . getDouble ( " total_sales " ) ;
log . info ( " Code-Create 订单:{}, 顾客id:{}, 付款金额:{} " , orderId , customerId , totalSales ) ;
log . info ( " Code-Create 订单:{}, 顾客id:{}, 付款金额:{} " , orderId , customerId , totalSales ) ;
String email = " " ;
String userName = " " ;
// 为什么一般没有值
@@ -1382,15 +1395,15 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 不管是不是新用户 都要更新用户角色和积分
String credits = " 0 " ;
if ( totalSales = = 5000 . 0 ) {
if ( totalSales = = 5000 . 0 ) {
log . info ( " 年付用户, 初始积分50000 " ) ;
credits = CreditsEventsEnum . INIT_YEARLY . getValue ( ) ;
systemUserType = 1 ;
} else if ( totalSales = = 500 . 0 ) {
} else if ( totalSales = = 500 . 0 ) {
log . info ( " 月付用户, 初始积分3500 " ) ;
credits = CreditsEventsEnum . INIT_MONTHLY . getValue ( ) ;
systemUserType = 2 ;
} else if ( totalSales = = 0 . 0 ) {
} else if ( totalSales = = 0 . 0 ) {
log . info ( " 测试用户, 初始积分10 " ) ;
credits = " 10 " ;
systemUserType = 3 ;
@@ -1401,7 +1414,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
StringUtil . isNullOrEmpty ( userName ) ? email . substring ( 0 , email . indexOf ( " @ " ) ) : userName ,
country ,
account . getValidStartTime ( ) . toString ( ) ,
account . getValidEndTime ( ) . toString ( ) , 0 , new BigDecimal ( credits ) , systemUserType ) ) ;
account . getValidEndTime ( ) . toString ( ) , 0 , new BigDecimal ( credits ) , systemUserType ) ) ;
if ( b ) log . info ( " 付费新用户 {} 新增成功! " , email ) ;
} else {
userInfo . setValidEndTime ( toDayEnd ( account . getValidEndTime ( ) ) ) ;
@@ -1485,7 +1498,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public void registerUserToVisitor ( ) {
public void registerUserToVisitor ( ) {
ArrayList < Map < String , String > > newUsersInfo = new ArrayList < > ( ) ;
ArrayList < String > allEmail = new ArrayList < > ( ) ;
long maxUserId = CommonConstant . MAXIMUM_USER_ID ;
@@ -1499,7 +1512,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
long maxUserIdHistory = StringUtil . isNullOrEmpty ( redisUtil . getFromString ( maximumUserIdKey ) ) ? CommonConstant . MAXIMUM_USER_ID : Long . parseLong ( redisUtil . getFromString ( maximumUserIdKey ) ) ;
log . info ( " Code-Create Maximum User ID last time : {} " , maxUserIdHistory ) ;
log . info ( " Currently Code-Create Maximum User ID : {} " , maxUserIdHistory ) ;
if ( maxUserId > maxUserIdHistory ) {
if ( maxUserId > maxUserIdHistory ) {
// 查出新增用户的邮箱
PreparedStatement newUserEmail = connection . prepareStatement ( QUERY_NEW_USER_EMAIL ) ;
// 填充参数 - 历史最大用户ID
@@ -1527,18 +1540,18 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// return null;
}
if ( ! newUsersInfo . isEmpty ( ) ) {
if ( ! newUsersInfo . isEmpty ( ) ) {
// 查询这些邮箱在aida上是否有账号
QueryWrapper < Account > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . in ( " user_email " , allEmail ) . select ( " user_email " ) ;
// 重复的邮箱
List < String > duplicateEmails = baseMapper . selectList ( queryWrapper ) . stream ( ) . map ( Account : : getUserEmail ) . collect ( Collectors . toList ( ) ) ;
if ( ! duplicateEmails . isEmpty ( ) ) {
if ( ! duplicateEmails . isEmpty ( ) ) {
// 移除Code-Create新增用户中在AiDA已有账号的邮箱, allEmail中剩余邮箱均为新用户邮箱
allEmail . removeIf ( item - > duplicateEmails . stream ( )
. anyMatch ( removeItem - > removeItem . equalsIgnoreCase ( item ) ) ) ;
if ( ! allEmail . isEmpty ( ) ) {
if ( ! allEmail . isEmpty ( ) ) {
Iterator < Map < String , String > > iterator = newUsersInfo . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
Map < String , String > userInfo = iterator . next ( ) ;
@@ -1547,12 +1560,12 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
iterator . remove ( ) ; // 使用迭代器安全地移除元素
}
}
} else {
} else {
newUsersInfo . clear ( ) ;
}
}
// 将新增用户添加到AiDA, 身份为游客
if ( ! newUsersInfo . isEmpty ( ) ) {
if ( ! newUsersInfo . isEmpty ( ) ) {
newUsersInfo . forEach ( userInfo - > {
long epochMilli = Instant . now ( ) . toEpochMilli ( ) ;
Account account = new Account ( ) ;
@@ -1585,7 +1598,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
" and o.`status` != 'wc-failed' " +
" and c.email not in ('1779019091@qq.com', 'xupei3360@163.com', '1627315083@qq.com', 'gigiwu33@hotmail.com') " ;
public List < String > getPaidCustomerEmail ( ) {
public List < String > getPaidCustomerEmail ( ) {
List < String > paidCustomerEmail = new ArrayList < > ( ) ;
try ( Connection connection = dataSource . getConnection ( ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( QUERY_PAID_CUSTOMER_EMAIL ) ) {
@@ -1616,7 +1629,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
} catch ( BusinessException e ) {
log . info ( e . getMessage ( ) ) ;
log . warn ( " 当前用户 {} 在AiDA中没有账号 " , email ) ;
throw new BusinessException ( " user.has.no.account " , ResultEnum . PROMPT . getCode ( ) ) ;
throw new BusinessException ( " user.has.no.account " , ResultEnum . PROMPT . getCode ( ) ) ;
}
// 2、先判断当前用户是否已经填写过问卷
CreditsDetail record = creditsService . getByAccountIdAndChangeEvent ( account . getId ( ) , " Fill out the questionnaire " , " +100 " ) ;
@@ -1644,7 +1657,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
creditsService . save ( creditsDetail ) ;
// 3.3、更新 t_account 表
if ( account . getValidEndTime ( ) ! = null & & account . getValidEndTime ( ) < 1720972799000L ) {
if ( account . getValidEndTime ( ) ! = null & & account . getValidEndTime ( ) < 1720972799000L ) {
updateCreditsAndEndTime ( account , added . toString ( ) , 1720972799000L , null ) ;
}
}
@@ -1833,7 +1846,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
log . debug ( " 更新子账号 {} 积分: 旧值={}, 已使用={}, 新值={} " ,
subAcc . getId ( ) , oldCredits , creditsUsage , newCredits ) ;
subAcc . getId ( ) , oldCredits , creditsUsage , newCredits ) ;
}
/**
@@ -1863,7 +1876,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
@Override
public String getActivityBenefits ( ) {
public String getActivityBenefits ( ) {
Long id = UserContext . getUserHolder ( ) . getId ( ) ;
// 1、 判断用户的身份 正式用户 无福利
Account account = baseMapper . selectById ( id ) ;
@@ -1871,14 +1884,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
Instant now = Instant . now ( ) ;
ZoneId zoneId = ZoneId . of ( " Asia/Shanghai " ) ;
ZonedDateTime specifiedDateTime ;
if ( systemUser . equals ( 1 ) ) {
if ( systemUser . equals ( 1 ) ) {
long validEndTime = Objects . isNull ( account . getValidEndTime ( ) ) ? now . toEpochMilli ( ) : account . getValidEndTime ( ) ;
specifiedDateTime = ZonedDateTime . ofInstant ( Instant . ofEpochMilli ( validEndTime ) , zoneId ) ;
account . setValidEndTime ( toDayEnd ( specifiedDateTime . plusDays ( 30 ) . toInstant ( ) . toEpochMilli ( ) ) ) ;
} else if ( systemUser . equals ( 4 ) ) {
} else if ( systemUser . equals ( 4 ) ) {
throw new BusinessException ( " You have participated in the event " , 1 ) ;
} else if ( systemUser . equals ( 0 ) | | systemUser . equals ( 3 ) ) {
} else if ( systemUser . equals ( 0 ) | | systemUser . equals ( 3 ) ) {
// 2、赋予游客或试用用户 以正式用户的权限 即 积分置为6000, 有效期30天
// 将 Instant 转换为 ZonedDateTime, 使用指定时区
specifiedDateTime = ZonedDateTime . ofInstant ( now , zoneId ) ;
@@ -1895,8 +1908,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return " 参与成功 " ;
}
// 将指定unix时间置为当天的23: 59: 59
public long toDayEnd ( long unixTimestampMillis ) {
public long toDayEnd ( long unixTimestampMillis ) {
// 将UNIX时间戳转换为LocalDateTime对象
LocalDateTime dateTime = Instant . ofEpochMilli ( unixTimestampMillis )
. atZone ( ZoneId . systemDefault ( ) )
@@ -1912,10 +1926,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
/**
* 获取指定身份过期用户
*
* @param systemUserNum
* @return
*/
public List < Account > getExpiredUserBySystemUser ( Integer systemUserNum ) {
public List < Account > getExpiredUserBySystemUser ( Integer systemUserNum ) {
QueryWrapper < Account > queryWrapper = new QueryWrapper < > ( ) ;
long now = Instant . now ( ) . toEpochMilli ( ) ;
queryWrapper . eq ( " system_user " , systemUserNum )
@@ -1925,11 +1940,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return baseMapper . selectList ( queryWrapper ) ;
}
public void toVisitor ( Account account ) {
public void toVisitor ( Account account ) {
accountMapper . toVisitor ( account . getId ( ) ) ;
}
public List < Long > setUserValidToDayEnd ( ) {
public List < Long > setUserValidToDayEnd ( ) {
// 获取当前未过期的用户, 并将其有效期设置为过期当日的23: 59: 59
QueryWrapper < Account > queryWrapper = new QueryWrapper < > ( ) ;
long now = Instant . now ( ) . toEpochMilli ( ) ;
@@ -1937,7 +1952,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
List < Account > accounts = baseMapper . selectList ( queryWrapper ) ;
ArrayList < Long > ids = new ArrayList < > ( ) ;
for ( Account account : accounts ) {
for ( Account account : accounts ) {
account . setValidEndTime ( toDayEnd ( account . getValidEndTime ( ) ) ) ;
ids . add ( account . getId ( ) ) ;
updateById ( account ) ;
@@ -1946,19 +1961,19 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return ids ;
}
public IPage < Account > getPageByDateAndUserType ( String startTime , String endTime , Integer type , int pageNum , int size ) {
public IPage < Account > getPageByDateAndUserType ( String startTime , String endTime , Integer type , int pageNum , int size ) {
QueryWrapper < Account > queryWrapper = new QueryWrapper < > ( ) ;
setTimeAndSystemUser ( queryWrapper , startTime , endTime , type ) ;
setTimeAndSystemUser ( queryWrapper , startTime , endTime , type ) ;
Page < Account > accountPage = new Page < > ( pageNum , size ) ;
return baseMapper . selectPage ( accountPage , queryWrapper ) ;
}
private void setTimeAndSystemUser ( QueryWrapper < Account > queryWrapper , String startTime , String endTime , Integer type ) {
queryWrapper . gt ( " create_date " , startTime ) . lt ( " create_date " , endTime ) ;
private void setTimeAndSystemUser ( QueryWrapper < Account > queryWrapper , String startTime , String endTime , Integer type ) {
queryWrapper . gt ( " create_date " , startTime ) . lt ( " create_date " , endTime ) ;
if ( ! Objects . isNull ( type ) ) {
switch ( type ) {
if ( ! Objects . isNull ( type ) ) {
switch ( type ) {
case 0 :
// 游客
queryWrapper . eq ( " system_user " , 0 ) ;
@@ -1978,9 +1993,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
}
public Map < String , Long > getByDateAndUserType ( String startTime , String endTime , Integer type ) {
public Map < String , Long > getByDateAndUserType ( String startTime , String endTime , Integer type ) {
QueryWrapper < Account > queryWrapper = new QueryWrapper < > ( ) ;
setTimeAndSystemUser ( queryWrapper , startTime , endTime , type ) ;
setTimeAndSystemUser ( queryWrapper , startTime , endTime , type ) ;
queryWrapper . groupBy ( " system_user " ) ;
queryWrapper . select ( " system_user as type, count(id) as count " ) ;
@@ -1991,27 +2006,27 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
map - > Objects . isNull ( map . get ( " count " ) ) ? 0L : ( Long ) map . get ( " count " ) ) ) ;
}
public IPage < Account > getPageByIds ( List < Long > ids , int pageNum , int size ) {
public IPage < Account > getPageByIds ( List < Long > ids , int pageNum , int size ) {
QueryWrapper < Account > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . in ( " id " , ids ) ;
return baseMapper . selectPage ( new Page < > ( pageNum , size ) , queryWrapper ) ;
}
public List < Account > getByIds ( List < Long > ids ) {
public List < Account > getByIds ( List < Long > ids ) {
QueryWrapper < Account > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . in ( " id " , ids ) ;
return baseMapper . selectList ( queryWrapper ) ;
}
public String uploadAvatar ( MultipartFile file ) {
public String uploadAvatar ( MultipartFile file ) {
Long accountId = UserContext . getUserHolder ( ) . getId ( ) ;
// 1、上传图片到minio
String avatarPath = minioUtil . upload ( userBucket , accountId . toString ( ) + " /avatar " , file ) ;
// 2、查询该用户之前的头像
String avatar = baseMapper . selectById ( accountId ) . getAvatar ( ) ;
if ( ! StringUtil . isNullOrEmpty ( avatar ) & & ! avatar . equals ( CommonConstant . DEFAULT_AVATAR ) ) {
if ( ! StringUtil . isNullOrEmpty ( avatar ) & & ! avatar . equals ( CommonConstant . DEFAULT_AVATAR ) ) {
minioUtil . deleteObject ( avatar ) ;
}
@@ -2024,7 +2039,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return minioUtil . getPreSignedUrl ( avatarPath , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ;
}
public PersonalHomepageVO getPersonalHomepage ( Long accountId ) {
public PersonalHomepageVO getPersonalHomepage ( Long accountId ) {
// 需要返回 用户头像 用户名 作品总量 粉丝量 关注量 主页访问量 当前用户是否被查看者关注
Long currentUserId = UserContext . getUserHolder ( ) . getId ( ) ;
PersonalHomepageVO personalHomepageVO = new PersonalHomepageVO ( ) ;
@@ -2040,12 +2055,12 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
personalHomepageVO . setHomepageViewCount ( viewPersonalHomepageCount ( 0L ) ) ;
if ( accountId . equals ( currentUserId ) ) {
if ( accountId . equals ( currentUserId ) ) {
personalHomepageVO . setIsFollow ( 0 ) ;
Long viewCount = viewPersonalHomepageCount ( accountId ) ;
// 只有本人才能看到个人主页浏览量
personalHomepageVO . setHomepageViewCount ( viewCount = = null ? 0 : viewCount ) ;
} else {
personalHomepageVO . setHomepageViewCount ( viewCount = = null ? 0 : viewCount ) ;
} else {
personalHomepageVO . setIsFollow ( portfolioService . getIfFollowed ( accountId , currentUserId ) ) ;
// 非本人浏览主页时增加浏览量
viewsIncrease ( accountId ) ;
@@ -2064,7 +2079,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
// 获取当前用户本月内 剩余昵称修改次数
public Long getNicknameModifyTimes ( ) {
public Long getNicknameModifyTimes ( ) {
Long accountId = UserContext . getUserHolder ( ) . getId ( ) ;
String key = RedisUtil . NICKNAME_MODIFY_TIMES + accountId ;
Long times = redisUtil . getIncrementCount ( key ) ;
@@ -2076,15 +2091,15 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 修改用户名 允许用户当前月内修改5次
@Transactional ( rollbackFor = Exception . class )
public void editUserName ( String newUserName ) {
public void editUserName ( String newUserName ) {
Long accountId = UserContext . getUserHolder ( ) . getId ( ) ;
// 判断当前用户是否还有修改昵称的次数
// Map<String, Long> remainTimes = getNicknameModifyTimes();
Long remainingModifyTimes = getNicknameModifyTimes ( ) ;
if ( remainingModifyTimes > 0 ) {
if ( remainingModifyTimes > 0 ) {
Account account = baseMapper . selectById ( accountId ) ;
// 当新昵称与旧昵称不同时,修改
if ( ! account . getUserName ( ) . equals ( newUserName ) ) {
if ( ! account . getUserName ( ) . equals ( newUserName ) ) {
account . setUserName ( newUserName ) ;
account . setId ( accountId ) ;
baseMapper . updateById ( account ) ;
@@ -2093,7 +2108,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 增加修改次数
redisUtil . increaseCount ( key ) ;
}
} else {
} else {
throw new BusinessException ( " remaining.modifications " , 1 ) ;
}
}
@@ -2267,7 +2282,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
log . error ( " 邮件发送失败,用户邮箱:{},原因:{} " , account . getUserEmail ( ) , e . getMessage ( ) , e ) ;
}
}
i + + ;
i + + ;
}
}
@@ -2293,7 +2308,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) & & ! StringUtil . isNullOrEmpty ( accountDTO . getPassword ( ) ) ) {
account . setUserPassword ( accountDTO . getPassword ( ) ) ;
accountMapper . updateById ( account ) ;
} else if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) ) {
} else if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) ) {
throw new BusinessException ( " Password cannot be empty " ) ;
} else {
if ( ! account . getUserPassword ( ) . equals ( accountDTO . getPassword ( ) ) ) {
@@ -2361,7 +2376,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) & & ! StringUtil . isNullOrEmpty ( accountDTO . getPassword ( ) ) ) {
account . setUserPassword ( accountDTO . getPassword ( ) ) ;
accountMapper . updateById ( account ) ;
} else if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) ) {
} else if ( " Third-000000 " . equals ( account . getUserPassword ( ) ) ) {
throw new BusinessException ( " Password cannot be empty " ) ;
} else {
if ( ! account . getUserPassword ( ) . equals ( accountDTO . getPassword ( ) ) ) {
@@ -2439,18 +2454,18 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
List < Account > accounts = accountMapper . selectList ( qw ) ;
// 校验子账号总数是否达上限
if ( adminAcc . getSubAccountNum ( ) = = null | | adminAcc . getSubAccountNum ( ) < = 0 ) {
if ( adminAcc . getSubAccountNum ( ) = = null | | adminAcc . getSubAccountNum ( ) < = 0 ) {
throw new BusinessException ( " Error: Sub-account quota reached (Max: 0). Upgrade to create more. " ) ;
}
if ( accounts . size ( ) > = adminAcc . getSubAccountNum ( ) ) {
throw new BusinessException ( " Error: Sub-account quota reached (Max: " + adminAcc . getSubAccountNum ( ) + " ). Upgrade to create more. " ) ;
}
if ( StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserEmail ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserEmail ( ) ) ) {
throw new BusinessException ( " email.cannot.be.empty " ) ;
}
if ( StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserPassword ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserPassword ( ) ) ) {
throw new BusinessException ( " password.cannot.be.empty " ) ;
}
@@ -2474,11 +2489,12 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( Objects . nonNull ( subAccount ) & & personAccRole . contains ( subAccount . getSystemUser ( ) ) ) {
log . info ( " 将用户{} 加入组织{} " , addSubAccountDTO . getUserEmail ( ) , adminAcc . getOrganizationName ( ) ) ;
subAccount . setUserName ( addSubAccountDTO . getUserName ( ) ) ;
if ( ! StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserPassword ( ) ) ) subAccount . setUserPassword ( addSubAccountDTO . getUserPassword ( ) ) ;
if ( ! StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserPassword ( ) ) )
subAccount . setUserPassword ( addSubAccountDTO . getUserPassword ( ) ) ;
subAccount . setSystemUser ( subUserRole ) ;
subAccount . setOrganizationName ( adminAcc . getOrganizationName ( ) ) ;
subAccount . setParentId ( adminAcc . getId ( ) ) ;
if ( Objects . nonNull ( addSubAccountDTO . getCreditsUsageLimit ( ) ) ) {
if ( Objects . nonNull ( addSubAccountDTO . getCreditsUsageLimit ( ) ) ) {
if ( remainingCredits . compareTo ( addSubAccountDTO . getCreditsUsageLimit ( ) ) < 0 ) {
throw new BusinessException ( " Insufficient credits (Balance: " + remainingCredits + " ). " , ResultEnum . PROMPT . getCode ( ) ) ;
}
@@ -2486,14 +2502,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
subAccount . setCreditsUsage ( Objects . isNull ( addSubAccountDTO . getCreditsUsage ( ) ) ? BigDecimal . ZERO : addSubAccountDTO . getCreditsUsage ( ) ) ;
if ( Objects . nonNull ( subAccount . getCredits ( ) ) ) {
subAccount . setCredits ( subAccount . getCreditsUsageLimit ( ) . add ( subAccount . getCredits ( ) ) ) ;
} else {
} else {
subAccount . setCredits ( subAccount . getCreditsUsageLimit ( ) ) ;
}
adminAcc . setCreditsUsage ( adminAcc . getCreditsUsage ( ) . add ( subAccount . getCreditsUsageLimit ( ) ) ) ;
adminAcc . setCredits ( adminAcc . getCredits ( ) . subtract ( subAccount . getCreditsUsageLimit ( ) ) ) ;
adminAcc . setUpdateDate ( new Date ( ) ) ;
log . debug ( " 分配积分: remainingCredits={}, subAccId={}, setCredits={} " , remainingCredits , subAccount . getId ( ) , addSubAccountDTO . getCreditsUsageLimit ( ) ) ;
} else {
} else {
handleSubAccCredits ( subAccount , adminAcc ) ;
}
subAccount . setUpdateDate ( new Date ( ) ) ;
@@ -2512,7 +2528,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
subAccount . setUserPassword ( addSubAccountDTO . getUserPassword ( ) ) ;
// 指定积分上限
if ( Objects . nonNull ( addSubAccountDTO . getCreditsUsageLimit ( ) ) ) {
if ( Objects . nonNull ( addSubAccountDTO . getCreditsUsageLimit ( ) ) ) {
if ( remainingCredits . compareTo ( addSubAccountDTO . getCreditsUsageLimit ( ) ) < 0 ) {
throw new BusinessException ( " Insufficient credits (Balance: " + remainingCredits + " ). " , ResultEnum . PROMPT . getCode ( ) ) ;
}
@@ -2520,7 +2536,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
subAccount . setCreditsUsage ( Objects . isNull ( addSubAccountDTO . getCreditsUsage ( ) ) ? BigDecimal . ZERO : addSubAccountDTO . getCreditsUsage ( ) ) ;
if ( Objects . nonNull ( subAccount . getCredits ( ) ) ) {
subAccount . setCredits ( subAccount . getCreditsUsageLimit ( ) . add ( subAccount . getCredits ( ) ) ) ;
} else {
} else {
subAccount . setCredits ( subAccount . getCreditsUsageLimit ( ) ) ;
}
adminAcc . setCreditsUsage ( adminAcc . getCreditsUsage ( ) . add ( subAccount . getCreditsUsageLimit ( ) ) ) ;
@@ -2547,7 +2563,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
private Boolean updateSubAccount ( AddSubAccountDTO addSubAccountDTO , Account adminAcc , int subUserRole ) {
Account exAccountInfo = baseMapper . selectById ( addSubAccountDTO . getId ( ) ) ;
if ( ! exAccountInfo . getParentId ( ) . equals ( adminAcc . getId ( ) ) ) {
if ( ! exAccountInfo . getParentId ( ) . equals ( adminAcc . getId ( ) ) ) {
throw new BusinessException ( " Access denied. Insufficient permissions. " ) ;
}
@@ -2556,8 +2572,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
& & ! exAccountInfo . getUserName ( ) . equals ( addSubAccountDTO . getUserName ( ) )
& & isUsernameExists ( adminAcc . getOrganizationName ( ) , addSubAccountDTO . getUserName ( ) ) ) {
throw new BusinessException ( " This organization already has an account with the same username. " ) ;
} else if ( ! StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserName ( ) )
& & ! exAccountInfo . getUserName ( ) . equals ( addSubAccountDTO . getUserName ( ) ) ) {
} else if ( ! StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserName ( ) )
& & ! exAccountInfo . getUserName ( ) . equals ( addSubAccountDTO . getUserName ( ) ) ) {
exAccountInfo . setUserName ( addSubAccountDTO . getUserName ( ) ) ;
}
@@ -2597,7 +2613,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 校验密码是否变更
if ( ! StringUtil . isNullOrEmpty ( addSubAccountDTO . getUserPassword ( ) )
& & ! exAccountInfo . getUserPassword ( ) . equals ( addSubAccountDTO . getUserPassword ( ) ) ) {
& & ! exAccountInfo . getUserPassword ( ) . equals ( addSubAccountDTO . getUserPassword ( ) ) ) {
exAccountInfo . setUserPassword ( addSubAccountDTO . getUserPassword ( ) ) ;
}
@@ -2642,9 +2658,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
}
if ( Objects . nonNull ( adminAccount . getCreditsUsageLimit ( ) ) & & Objects . nonNull ( adminAccount . getCreditsUsage ( ) ) ) {
if ( Objects . nonNull ( adminAccount . getCreditsUsageLimit ( ) ) & & Objects . nonNull ( adminAccount . getCreditsUsage ( ) ) ) {
return adminAccount . getCreditsUsageLimit ( ) . subtract ( adminAccount . getCreditsUsage ( ) ) ;
} else if ( Objects . nonNull ( adminAccount . getCreditsUsageLimit ( ) ) ) {
} else if ( Objects . nonNull ( adminAccount . getCreditsUsageLimit ( ) ) ) {
return adminAccount . getCreditsUsageLimit ( ) ;
} else {
return BigDecimal . ZERO ;
@@ -2660,7 +2676,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( Objects . nonNull ( adminAcc . getCreditsUsageLimit ( ) ) & & ( Objects . isNull ( subAcc . getCreditsUsageLimit ( ) ) | | subAcc . getCreditsUsageLimit ( ) . compareTo ( BigDecimal . ZERO ) = = 0 ) ) {
// 默认使用平均积分
BigDecimal defaultCredits = adminAcc . getCreditsUsageLimit ( ) . divide ( new BigDecimal ( adminAcc . getSubAccountNum ( ) ) , RoundingMode . FLOOR ) ; ;
BigDecimal defaultCredits = adminAcc . getCreditsUsageLimit ( ) . divide ( new BigDecimal ( adminAcc . getSubAccountNum ( ) ) , RoundingMode . FLOOR ) ;
;
if ( remainingCredits . compareTo ( defaultCredits ) > = 0 ) {
subAcc . setCreditsUsageLimit ( defaultCredits ) ;
@@ -2677,7 +2694,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( Objects . nonNull ( subAcc . getCredits ( ) ) ) {
subAcc . setCredits ( subAcc . getCreditsUsageLimit ( ) . add ( subAcc . getCredits ( ) ) ) ;
} else {
} else {
subAcc . setCredits ( subAcc . getCreditsUsageLimit ( ) ) ;
}
}
@@ -2733,7 +2750,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
}
// 将积分回流
if ( unusedCreditsTotal . compareTo ( BigDecimal . ZERO ) ! = 0 ) {
if ( unusedCreditsTotal . compareTo ( BigDecimal . ZERO ) ! = 0 ) {
BigDecimal subtracted = adminAcc . getCreditsUsage ( ) . subtract ( unusedCreditsTotal ) ;
adminAcc . setCreditsUsage ( subtracted . compareTo ( BigDecimal . ZERO ) < 0 ? BigDecimal . ZERO : subtracted ) ;
// 管理员账号可以购买积分, 但是不会加入到可分配积分的池子里, 只需要加到credits
@@ -2773,14 +2790,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( StringUtils . isNotBlank ( subAccountPageDTO . getEndTime ( ) ) ) {
qw . lambda ( ) . le ( Account : : getCreateDate , subAccountPageDTO . getEndTime ( ) ) ;
}
if ( subAccountPageDTO . getEmail ( ) ! = null & & subAccountPageDTO . getEmail ( ) . size ( ) = = 1 ) {
if ( subAccountPageDTO . getEmail ( ) ! = null & & subAccountPageDTO . getEmail ( ) . size ( ) = = 1 ) {
qw . lambda ( ) . like ( Account : : getUserEmail , subAccountPageDTO . getEmail ( ) . get ( 0 ) ) ;
} else if ( subAccountPageDTO . getEmail ( ) ! = null & & subAccountPageDTO . getEmail ( ) . size ( ) > 1 ) {
} else if ( subAccountPageDTO . getEmail ( ) ! = null & & subAccountPageDTO . getEmail ( ) . size ( ) > 1 ) {
qw . lambda ( ) . in ( Account : : getUserEmail , subAccountPageDTO . getEmail ( ) ) ;
}
if ( subAccountPageDTO . getUserName ( ) ! = null & & subAccountPageDTO . getUserName ( ) . size ( ) = = 1 ) {
if ( subAccountPageDTO . getUserName ( ) ! = null & & subAccountPageDTO . getUserName ( ) . size ( ) = = 1 ) {
qw . lambda ( ) . like ( Account : : getUserName , subAccountPageDTO . getUserName ( ) . get ( 0 ) ) ;
} else if ( subAccountPageDTO . getUserName ( ) ! = null & & subAccountPageDTO . getUserName ( ) . size ( ) > 1 ) {
} else if ( subAccountPageDTO . getUserName ( ) ! = null & & subAccountPageDTO . getUserName ( ) . size ( ) > 1 ) {
qw . lambda ( ) . in ( Account : : getUserName , subAccountPageDTO . getUserName ( ) ) ;
}
@@ -2835,7 +2852,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
List < AccountExtend > accountExtends = accountExtendMapper . selectList ( accountExtendQW ) ;
if ( CollectionUtil . isNotEmpty ( accountExtends ) ) {
throw new BusinessException ( " This Google account has been registered for AiDA, please use Google Quick Login directly. " ) ;
} else {
} else {
QueryWrapper < Account > accountQueryWrapper = new QueryWrapper < > ( ) ;
accountQueryWrapper . lambda ( ) . eq ( Account : : getUserEmail , email ) ; // 根据邮箱查询用户
List < Account > accounts = accountMapper . selectList ( accountQueryWrapper ) ;
@@ -2848,7 +2865,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountExtendInsert . setName ( name ) ;
accountExtendInsert . setAccountId ( account . getId ( ) ) ;
accountExtendMapper . insert ( accountExtendInsert ) ;
} else {
} else {
Account newUser = new Account ( ) ;
newUser . setUserEmail ( email ) ;
newUser . setUserName ( name ) ;
@@ -2874,7 +2891,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountExtendMapper . insert ( accountExtendInsert ) ;
}
}
} else {
} else {
// 登录
QueryWrapper < AccountExtend > accountExtendQW = new QueryWrapper < > ( ) ;
accountExtendQW . lambda ( ) . eq ( AccountExtend : : getAuthType , " Google " ) ;
@@ -2883,7 +2900,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( CollectionUtil . isNotEmpty ( accountExtends ) ) {
AccountExtend accountExtend = accountExtends . get ( 0 ) ;
account = accountMapper . selectById ( accountExtend . getAccountId ( ) ) ;
} else {
} else {
throw new BusinessException ( " This Google account has not been bound to an AiDA account yet. Please register an AiDA account and bind it to a Google account, or bind the Google account to an existing AiDA account. " ) ;
}
}
@@ -2900,9 +2917,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
response . setSystemUser ( account . getSystemUser ( ) ) ;
// 设置头像
String avatar ;
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
avatar = CommonConstant . DEFAULT_AVATAR ;
} else {
} else {
avatar = account . getAvatar ( ) ;
}
response . setAvatar ( minioUtil . getPreSignedUrl ( avatar , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
@@ -2952,7 +2969,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
List < AccountExtend > accountExtends = accountExtendMapper . selectList ( queryWrapper ) ;
if ( CollectionUtil . isNotEmpty ( accountExtends ) ) {
throw new BusinessException ( " This Wechat account has been registered for AiDA, please use Wechat Quick Login directly. " ) ;
} else {
} else {
// 创建新用户(自动注册)
Account newUser = new Account ( ) ;
newUser . setUserName ( userName ) ;
@@ -2977,7 +2994,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account = newUser ;
}
} else {
} else {
// 登录
// 检查数据库中是否已有该unionid
QueryWrapper < AccountExtend > queryWrapper = new QueryWrapper < > ( ) ;
@@ -2987,7 +3004,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if ( CollectionUtil . isNotEmpty ( accountExtends ) ) {
AccountExtend accountExtend = accountExtends . get ( 0 ) ;
account = accountMapper . selectById ( accountExtend . getAccountId ( ) ) ;
} else {
} else {
throw new BusinessException ( " This WeChat account has not been bound to an AiDA account yet. Please register an AiDA account and bind it to the WeChat account, or bind the WeChat account to an existing AiDA account. " ) ;
}
}
@@ -3005,9 +3022,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
response . setSystemUser ( account . getSystemUser ( ) ) ;
// 设置头像
String avatar ;
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
avatar = CommonConstant . DEFAULT_AVATAR ;
} else {
} else {
avatar = account . getAvatar ( ) ;
}
response . setAvatar ( minioUtil . getPreSignedUrl ( avatar , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
@@ -3017,6 +3034,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
private static final String WECHAT_USER_INFO_URL = " https://api.weixin.qq.com/sns/userinfo " ;
private JSONObject getUserInfoFromWeChat ( String accessToken , String openId ) {
// 构造微信用户信息接口的 URL
String url = String . format (
@@ -3096,9 +3114,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
response . setSystemUser ( account . getSystemUser ( ) ) ;
// 设置头像
String avatar ;
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
if ( StringUtil . isNullOrEmpty ( account . getAvatar ( ) ) ) {
avatar = CommonConstant . DEFAULT_AVATAR ;
} else {
} else {
avatar = account . getAvatar ( ) ;
}
response . setAvatar ( minioUtil . getPreSignedUrl ( avatar , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
@@ -3299,13 +3317,13 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return result ;
}
public boolean updateAccountValidity ( Long accountId , Long currentPeriodEnd ) {
public boolean updateAccountValidity ( Long accountId , Long currentPeriodEnd ) {
// 不管当前用户的账号是否到期,都根据付款信息重置账号到期时间
Account account = accountMapper . selectById ( accountId ) ;
if ( ! Objects . isNull ( account . getValidEndTime ( ) )
& & account . getValidEndTime ( ) . equals ( currentPeriodEnd * 1000 ) ) {
& & account . getValidEndTime ( ) . equals ( currentPeriodEnd * 1000 ) ) {
return false ;
} else {
} else {
account . setValidEndTime ( currentPeriodEnd * 1000 ) ;
accountMapper . updateById ( account ) ;
}
@@ -3313,29 +3331,29 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
@Override
public void updateUserRoleAndCredits ( Long accountId , String orderNo ) {
public void updateUserRoleAndCredits ( Long accountId , String orderNo ) {
Account account = accountMapper . selectById ( accountId ) ;
OrderInfo orderInfo = orderInfoService . getOrderByOrderNo ( orderNo ) ;
if ( Objects . nonNull ( orderInfo ) & & ! StringUtil . isNullOrEmpty ( orderInfo . getTitle ( ) ) ) {
if ( Objects . nonNull ( orderInfo ) & & ! StringUtil . isNullOrEmpty ( orderInfo . getTitle ( ) ) ) {
String description = orderInfo . getTitle ( ) ;
Long productCredits ;
if ( description . equals ( ProductEnum . DailySubscription . getName ( ) ) ) {
if ( description . equals ( ProductEnum . DailySubscription . getName ( ) ) ) {
productCredits = ProductEnum . DailySubscription . getCredits ( ) ;
account . setSystemUser ( 3 ) ;
account . setCredits ( BigDecimal . valueOf ( Long . parseLong ( CreditsEventsEnum . INIT_WEEKLY . getValue ( ) ) ) ) ;
} else if ( description . equals ( ProductEnum . MonthlySubscription . getName ( ) ) ) {
} else if ( description . equals ( ProductEnum . MonthlySubscription . getName ( ) ) ) {
productCredits = ProductEnum . MonthlySubscription . getCredits ( ) ;
account . setSystemUser ( 2 ) ;
account . setCredits ( BigDecimal . valueOf ( Long . parseLong ( CreditsEventsEnum . INIT_MONTHLY . getValue ( ) ) ) ) ;
} else if ( description . equals ( ProductEnum . Eco_MonthlySubscription . getName ( ) ) ) {
} else if ( description . equals ( ProductEnum . Eco_MonthlySubscription . getName ( ) ) ) {
productCredits = ProductEnum . Eco_MonthlySubscription . getCredits ( ) ;
account . setSystemUser ( 2 ) ;
account . setCredits ( BigDecimal . valueOf ( Long . parseLong ( CreditsEventsEnum . INIT_MONTHLY_ECO . getValue ( ) ) ) ) ;
} else if ( description . equals ( ProductEnum . AnnualSubscription . getName ( ) ) ) {
} else if ( description . equals ( ProductEnum . AnnualSubscription . getName ( ) ) ) {
productCredits = ProductEnum . AnnualSubscription . getCredits ( ) ;
account . setSystemUser ( 1 ) ;
account . setCredits ( BigDecimal . valueOf ( Long . parseLong ( CreditsEventsEnum . INIT_YEARLY . getValue ( ) ) ) ) ;
} else {
} else {
log . error ( " 未知订阅类型: {} " , description ) ;
return ;
}
@@ -3343,7 +3361,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 先判断是否已添加添加积分变更记录
CreditsDetail creditsDetail = creditsService . queryDetailByTaskId ( orderNo ) ;
if ( Objects . isNull ( creditsDetail ) ) {
if ( Objects . isNull ( creditsDetail ) ) {
creditsService . insertToCreditsDetail ( accountId ,
description + " --Stripe " ,
String . valueOf ( productCredits ) ,
@@ -3369,7 +3387,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}*/
}
public Boolean updateUserInfo ( UpdateUserInfoDTO updateUserInfoDTO ) {
public Boolean updateUserInfo ( UpdateUserInfoDTO updateUserInfoDTO ) {
Long accountId = UserContext . getUserHolder ( ) . getId ( ) ;
Account account = accountMapper . selectById ( accountId ) ;
if ( StringUtils . isNotEmpty ( updateUserInfoDTO . getOccupation ( ) ) & & ! account . getOccupation ( ) . equals ( updateUserInfoDTO . getOccupation ( ) ) ) {
@@ -3500,11 +3518,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
qw . lambda ( ) . eq ( Account : : getSystemUser , 8 )
. eq ( Account : : getOrganizationName , parent . getOrganizationName ( ) ) ;
List < Account > accounts = accountMapper . selectList ( qw ) ;
if ( ! accounts . isEmpty ( ) ) {
if ( ! accounts . isEmpty ( ) ) {
throw new BusinessException ( " permit.bulk.creation " , ResultEnum . PROMPT . getCode ( ) ) ;
}
if ( importList . size ( ) > parent . getSubAccountNum ( ) - 1 ) {
throw new BusinessException ( " Action required: You cannot create [ " + importList . size ( ) + " ] sub-accounts (Current quota: [ " + ( parent . getSubAccountNum ( ) - 1 ) + " ]). " ) ;
if ( importList . size ( ) > parent . getSubAccountNum ( ) - 1 ) {
throw new BusinessException ( " Action required: You cannot create [ " + importList . size ( ) + " ] sub-accounts (Current quota: [ " + ( parent . getSubAccountNum ( ) - 1 ) + " ]). " ) ;
}
// 示例:打印或保存
for ( SubAccountImportDTO dto : importList ) {
@@ -3552,18 +3570,18 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Set < String > organizationNameSearch ( String type , String name ) {
QueryWrapper < Account > qw = new QueryWrapper < > ( ) ;
if ( ! StringUtil . isNullOrEmpty ( name ) ) {
if ( ! StringUtil . isNullOrEmpty ( name ) ) {
qw . lambda ( ) . like ( Account : : getOrganizationName , name ) ;
}
if ( type . equals ( " School " ) ) {
Set < Long > schoolList = new HashSet < > ( ) ;
Set < Long > schoolList = new HashSet < > ( ) ;
schoolList . add ( 7L ) ;
schoolList . add ( 8L ) ;
qw . lambda ( ) . in ( Account : : getSystemUser , schoolList ) ;
}
if ( type . equals ( " Enterprise " ) ) {
Set < Long > schoolList = new HashSet < > ( ) ;
Set < Long > schoolList = new HashSet < > ( ) ;
schoolList . add ( 5L ) ;
schoolList . add ( 6L ) ;
qw . lambda ( ) . in ( Account : : getSystemUser , schoolList ) ;
@@ -3603,23 +3621,49 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
}*/
@Transactional ( rollbackFor = Exception . class )
public void checkEduAdminExpireStatus ( ) {
@Override
public void checkEduAdminExpireStatus ( ) {
// 1、检查所有管理员账号到期状态
List < Account > expiredEduAdmin = getExpiredUserBySystemUser ( 7 ) ;
// 2、若有过期教育管理员, 则将该管理员下的所有子账号删除( 降为游客或者恢复其原本身份与积分)
if ( ! expiredEduAdmin . isEmpty ( ) ) {
for ( Account adminAccount : expiredEduAdmin ) {
List < Account > subAccountsByAdmin = getSubAccountsByAdmin ( adminAccount ) ;
if ( ! subAccountsByAdmin . isEmpty ( ) ) {
// 获取所有子账号的id,并删除
List < Long > subAccIdList = subAccountsByAdmin . stream ( ) . map ( Account : : getId ) . collect ( Collectors . toList ( ) ) ;
removeSubAccount ( new AddSubAccountDTO ( subAccIdList ) , adminAccount . getId ( ) ) ;
}
// 将教育管理员置为游客
toVisitor ( adminAccount ) ;
for ( Account adminAccount : expiredEduAdmin ) {
setEduAdminToExpire ( adminAccount ) ;
}
}
}
@Transactional ( rollbackFor = Exception . class )
@Override
public void setEduAdminToExpire ( Account adminAccount ) {
List < Account > subAccountsByAdmin = getSubAccountsByAdmin ( adminAccount ) ;
if ( ! subAccountsByAdmin . isEmpty ( ) ) {
// 获取所有子账号的id,并删除
List < Long > subAccIdList = subAccountsByAdmin . stream ( ) . map ( Account : : getId ) . collect ( Collectors . toList ( ) ) ;
removeSubAccount ( new AddSubAccountDTO ( subAccIdList ) , adminAccount . getId ( ) ) ;
}
setOrganizationStatus ( adminAccount , false ) ;
// 将教育管理员置为游客
toVisitor ( adminAccount ) ;
}
// todo 机构管理员再次订阅时,需要同步机构的激活状态
private void setOrganizationStatus ( Account adminAcc , boolean isActive ) {
Organization organization ;
if ( Objects . nonNull ( adminAcc . getOrganizationId ( ) ) ) {
organization = organizationMapper . selectById ( adminAcc . getOrganizationId ( ) ) ;
} else if ( ! StringUtil . isNullOrEmpty ( adminAcc . getOrganizationName ( ) ) ) {
organization = convenientInquiryService . checkOrganization ( adminAcc . getSystemUser ( ) , adminAcc . getOrganizationName ( ) ) ;
} else {
return ;
}
if ( isActive ) {
organization . setStatus ( 1 ) ;
} else {
organization . setStatus ( 0 ) ;
}
organization . setUpdateTime ( LocalDateTime . now ( ) ) ;
organizationMapper . updateById ( organization ) ;
}
}