Merge remote-tracking branch 'origin/dev/3.1_release_merge' into dev/3.1_release_merge

This commit is contained in:
litianxiang
2025-10-07 14:02:08 +08:00
10 changed files with 335 additions and 185 deletions

View File

@@ -220,9 +220,9 @@ public class ConvenientInquiryController {
} }
@ApiOperation("查询所有企业或教育机构") @ApiOperation("查询所有企业或教育机构")
@GetMapping("/queryOrganization") @PostMapping("/queryOrganization")
public Response<List<Organization>> queryOrganization(@ApiParam(value = "Enterprise || Education") @RequestParam String type){ public Response<IPage<Organization>> queryOrganization(@RequestBody QueryOrganizationPageDTO queryOrganizationPageDTO){
return Response.success(convenientInquiryService.queryOrganization(type)); return Response.success(convenientInquiryService.queryOrganization(queryOrganizationPageDTO));
} }
} }

View File

@@ -18,6 +18,6 @@ public class Organization extends BaseEntity{
private String level; private String level;
// 父分类ID自引用 // 父分类ID自引用
private Long parentId; private Long parentId;
// 状态 // 状态 0 inactive || 1 active
private Integer status; private Integer status;
} }

View File

@@ -0,0 +1,23 @@
package com.ai.da.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel
@NoArgsConstructor
public class QueryOrganizationPageDTO extends QueryPageByTimeDTO{
@ApiModelProperty("组织类型 Enterprise || Education")
private String type;
@ApiModelProperty("组织名字")
private String name;
public QueryOrganizationPageDTO(String type, String name) {
this.type = type;
this.name = name;
}
}

View File

@@ -1,6 +1,7 @@
package com.ai.da.model.enums; package com.ai.da.model.enums;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
import io.netty.util.internal.StringUtil;
public enum PrintboardLevel2TypeEnum implements IEnumDisplay { public enum PrintboardLevel2TypeEnum implements IEnumDisplay {
PATTERN("图案", "Pattern"), PATTERN("图案", "Pattern"),
@@ -41,6 +42,9 @@ public enum PrintboardLevel2TypeEnum implements IEnumDisplay {
// 根据名称获取枚举值 // 根据名称获取枚举值
public static PrintboardLevel2TypeEnum fromName(String name) { public static PrintboardLevel2TypeEnum fromName(String name) {
if (StringUtil.isNullOrEmpty(name)){
return PrintboardLevel2TypeEnum.PATTERN;
}
for (PrintboardLevel2TypeEnum designElement : PrintboardLevel2TypeEnum.values()) { for (PrintboardLevel2TypeEnum designElement : PrintboardLevel2TypeEnum.values()) {
if (designElement.english.equals(name)) { if (designElement.english.equals(name)) {
return designElement; return designElement;

View File

@@ -242,4 +242,6 @@ public interface AccountService extends IService<Account> {
/*void send618PromotionEmailTemp();*/ /*void send618PromotionEmailTemp();*/
void checkEduAdminExpireStatus(); void checkEduAdminExpireStatus();
void setEduAdminToExpire(Account adminAccount);
} }

View File

@@ -44,6 +44,8 @@ public interface ConvenientInquiryService extends IService<Questionnaire> {
Boolean addUser(AccountAddDTO accountAddDTO); Boolean addUser(AccountAddDTO accountAddDTO);
Organization checkOrganization(Integer systemUser, String organizationName);
Boolean modifyUser(Long accountId, Long validEndTime, Integer systemUser, Long credits); Boolean modifyUser(Long accountId, Long validEndTime, Integer systemUser, Long credits);
IPage<Account> getUserInfo(QueryUserConditionsVO queryUserConditionsVO); IPage<Account> getUserInfo(QueryUserConditionsVO queryUserConditionsVO);
@@ -60,7 +62,7 @@ public interface ConvenientInquiryService extends IService<Questionnaire> {
List<String> getAllGenerateFuncName(); List<String> getAllGenerateFuncName();
void addOrganization(String name, String type); Organization addOrganization(String name, String type);
List<Organization> queryOrganization(String type); IPage<Organization> queryOrganization(QueryOrganizationPageDTO queryOrganizationPageDTOe);
} }

View File

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

View File

@@ -330,6 +330,18 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
} }
String name = DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD); String name = DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD);
List<Library> libraryList = CopyUtil.copyList(elements, Library.class, (o, d) -> { List<Library> libraryList = CopyUtil.copyList(elements, Library.class, (o, d) -> {
if (StringUtil.isNullOrEmpty(o.getLevel2Type())){
switch(d.getLevel1Type()){
case "Sketchboard":
d.setLevel2Type("Outwear");
break;
case "Printboard":
d.setLevel2Type("Pattern");
break;
}
} else {
d.setLevel2Type(o.getLevel2Type());
}
d.setCreateDate(DateUtil.getByTimeZone(timeZone)); d.setCreateDate(DateUtil.getByTimeZone(timeZone));
d.setName(name); d.setName(name);
d.setId(null); d.setId(null);
@@ -369,6 +381,18 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
// // TODO:暂不处理 // // TODO:暂不处理
// } // }
} }
if (StringUtil.isNullOrEmpty(o.getLevel2Type())){
switch(d.getLevel1Type()){
case "Sketchboard":
d.setLevel2Type("Outwear");
break;
case "Printboard":
d.setLevel2Type("Pattern");
break;
}
} else {
d.setLevel2Type(o.getLevel2Type());
}
d.setCreateDate(DateUtil.getByTimeZone(timeZone)); d.setCreateDate(DateUtil.getByTimeZone(timeZone));
d.setName(name); d.setName(name);
d.setId(null); d.setId(null);

View File

@@ -153,11 +153,11 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
// yyyy-MM-dd HH:mm:ss "HH"表示24小时制 "hh"表示12小时制 // yyyy-MM-dd HH:mm:ss "HH"表示24小时制 "hh"表示12小时制
endTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); endTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} }
if (!StringUtil.isNullOrEmpty(email)){ if (!StringUtil.isNullOrEmpty(email)) {
email = email.trim(); email = email.trim();
} }
String role; String role;
switch (account.getSystemUser()){ switch (account.getSystemUser()) {
case 5: case 5:
role = "corp"; role = "corp";
break; break;
@@ -423,7 +423,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode()); throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
} }
if ((ids == null || ids.isEmpty()) && (account.getSystemUser() == 5 || account.getSystemUser() == 7)){ if ((ids == null || ids.isEmpty()) && (account.getSystemUser() == 5 || account.getSystemUser() == 7)) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>(); QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Account::getParentId, accountId).eq(Account::getOrganizationName, account.getOrganizationName()); queryWrapper.lambda().eq(Account::getParentId, accountId).eq(Account::getOrganizationName, account.getOrganizationName());
List<Account> accounts = accountMapper.selectList(queryWrapper); List<Account> accounts = accountMapper.selectList(queryWrapper);
@@ -497,10 +497,10 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode()); throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
} }
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>(); QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
if (!StringUtils.isNullOrEmpty(startTime)){ if (!StringUtils.isNullOrEmpty(startTime)) {
queryWrapper.gt("create_time", startTime); queryWrapper.gt("create_time", startTime);
} }
if (!StringUtils.isNullOrEmpty(endTime)){ if (!StringUtils.isNullOrEmpty(endTime)) {
queryWrapper.lt("create_time", endTime); queryWrapper.lt("create_time", endTime);
} }
// 获取试用用户总数 // 获取试用用户总数
@@ -512,10 +512,10 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
// 获取从试用用户转为正式用户的用户数量 // 获取从试用用户转为正式用户的用户数量
List<String> paidCustomerEmail = accountService.getPaidCustomerEmail(); List<String> paidCustomerEmail = accountService.getPaidCustomerEmail();
QueryWrapper<TrialOrder> qw = new QueryWrapper<>(); QueryWrapper<TrialOrder> qw = new QueryWrapper<>();
if (!StringUtils.isNullOrEmpty(startTime)){ if (!StringUtils.isNullOrEmpty(startTime)) {
qw.gt("create_time", startTime); qw.gt("create_time", startTime);
} }
if (!StringUtils.isNullOrEmpty(endTime)){ if (!StringUtils.isNullOrEmpty(endTime)) {
qw.lt("create_time", endTime); qw.lt("create_time", endTime);
} }
qw.in("email", paidCustomerEmail); qw.in("email", paidCustomerEmail);
@@ -545,10 +545,10 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode()); throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
} }
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>(); QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
if (!StringUtils.isNullOrEmpty(startTime)){ if (!StringUtils.isNullOrEmpty(startTime)) {
queryWrapper.gt("create_time", startTime); queryWrapper.gt("create_time", startTime);
} }
if (!StringUtils.isNullOrEmpty(endTime)){ if (!StringUtils.isNullOrEmpty(endTime)) {
queryWrapper.lt("create_time", endTime); queryWrapper.lt("create_time", endTime);
} }
@@ -570,12 +570,12 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
// 新增用户 // 新增用户
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean addUser(AccountAddDTO accountAddDTO) { public Boolean addUser(AccountAddDTO accountAddDTO) {
if (Objects.isNull(accountAddDTO.getSystemUser())){ if (Objects.isNull(accountAddDTO.getSystemUser())) {
throw new BusinessException("Please choose an user type."); throw new BusinessException("Please choose an user type.");
} }
// 如果是学校或者企业身份,组织名不能为空 // 如果是学校或者企业身份,组织名不能为空
if (Arrays.asList(5,6,7,8).contains(accountAddDTO.getSystemUser()) if (Arrays.asList(5, 6, 7, 8).contains(accountAddDTO.getSystemUser())
&& StringUtil.isNullOrEmpty(accountAddDTO.getOrganizationName())){ && StringUtil.isNullOrEmpty(accountAddDTO.getOrganizationName())) {
throw new BusinessException("The organization name cannot be empty."); throw new BusinessException("The organization name cannot be empty.");
} }
@@ -585,7 +585,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
queryWrapper.eq("user_email", account.getUserEmail()); queryWrapper.eq("user_email", account.getUserEmail());
Account existsAccount = accountMapper.selectOne(queryWrapper); Account existsAccount = accountMapper.selectOne(queryWrapper);
if (!Objects.isNull(existsAccount)){ if (!Objects.isNull(existsAccount)) {
throw new BusinessException("The email address already exists. One email address can only register one AiDA account"); throw new BusinessException("The email address already exists. One email address can only register one AiDA account");
} }
@@ -627,16 +627,16 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
} }
} }
if (Objects.nonNull(accountAddDTO.getCredits())){ if (Objects.nonNull(accountAddDTO.getCredits())) {
account.setCredits(accountAddDTO.getCredits()); account.setCredits(accountAddDTO.getCredits());
account.setCreditsUsage(BigDecimal.ZERO); account.setCreditsUsage(BigDecimal.ZERO);
account.setCreditsUsageLimit(accountAddDTO.getCredits()); account.setCreditsUsageLimit(accountAddDTO.getCredits());
} }
if (Objects.nonNull(accountAddDTO.getSubAccountNum())){ if (Objects.nonNull(accountAddDTO.getSubAccountNum())) {
account.setSubAccountNum(accountAddDTO.getSubAccountNum()); account.setSubAccountNum(accountAddDTO.getSubAccountNum());
} }
if (!StringUtil.isNullOrEmpty(accountAddDTO.getOrganizationName())){ if (!StringUtil.isNullOrEmpty(accountAddDTO.getOrganizationName())) {
account.setOrganizationName(accountAddDTO.getOrganizationName()); checkAndSetOrganization(accountAddDTO, account);
} }
account.setValidStartTime(Long.parseLong(accountAddDTO.getValidStartTime())); account.setValidStartTime(Long.parseLong(accountAddDTO.getValidStartTime()));
account.setValidEndTime(Long.parseLong(accountAddDTO.getValidEndTime())); account.setValidEndTime(Long.parseLong(accountAddDTO.getValidEndTime()));
@@ -649,6 +649,36 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
return accountService.save(account); return accountService.save(account);
} }
private void checkAndSetOrganization(AccountAddDTO accountAddDTO, Account account){
Organization organization = checkOrganization(accountAddDTO.getSystemUser(), accountAddDTO.getOrganizationName());
if (Objects.nonNull(organization)){
account.setOrganizationId(organization.getId());
} else {
organization = addOrganization(accountAddDTO.getOrganizationName(), organization.getType());
account.setOrganizationName(accountAddDTO.getOrganizationName());
account.setOrganizationId(organization.getId());
}
}
public Organization checkOrganization(Integer systemUser, String organizationName){
String type ;
switch (systemUser){
case 5:
type = "Enterprise";
break;
case 7:
type = "Education";
break;
default:
return null;
}
QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Organization::getType, type).eq(Organization::getName, organizationName);
return organizationMapper.selectOne(queryWrapper);
}
// 修改用户信息 // 修改用户信息
public Boolean modifyUser(Long accountId, Long validEndTime, Integer systemUser, Long credits) { public Boolean modifyUser(Long accountId, Long validEndTime, Integer systemUser, Long credits) {
log.info("modifyUser ==> accountId:{}, validEndTime:{}, systemUser:{}, systemUser:{}", accountId, validEndTime, systemUser, credits); log.info("modifyUser ==> accountId:{}, validEndTime:{}, systemUser:{}, systemUser:{}", accountId, validEndTime, systemUser, credits);
@@ -772,7 +802,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
|| account.getSystemUser().equals(7) || account.getSystemUser().equals(7)
|| ADMIN_IDS.contains(account.getId()) || ADMIN_IDS.contains(account.getId())
|| ADMIN_IDS_READ_ONLY.contains(account.getId()) || ADMIN_IDS_READ_ONLY.contains(account.getId())
)){ )) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>(); QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.select("id as value, user_name as label"); queryWrapper.select("id as value, user_name as label");
if ((account.getSystemUser().equals(7) || account.getSystemUser().equals(5)) if ((account.getSystemUser().equals(7) || account.getSystemUser().equals(5))
@@ -780,7 +810,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
queryWrapper.lambda().eq(Account::getOrganizationName, account.getOrganizationName()); queryWrapper.lambda().eq(Account::getOrganizationName, account.getOrganizationName());
} }
return accountMapper.selectMaps(queryWrapper); return accountMapper.selectMaps(queryWrapper);
} else { } else {
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode()); throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
} }
// return maps.stream().map(map -> (Long)map.get("id")).collect(Collectors.toList()); // return maps.stream().map(map -> (Long)map.get("id")).collect(Collectors.toList());
@@ -833,7 +863,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
return response; return response;
} }
public Map<String, List<String>> getCities(){ public Map<String, List<String>> getCities() {
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(accountId); Account account = accountService.getById(accountId);
// 允许查看数据的用户id // 允许查看数据的用户id
@@ -857,7 +887,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
}}; }};
} }
public String exportTransactionRecords(QueryPaymentInfoDTO queryPaymentInfoDTO, HttpServletResponse response){ public String exportTransactionRecords(QueryPaymentInfoDTO queryPaymentInfoDTO, HttpServletResponse response) {
// QueryPaymentInfoDTO queryPaymentInfoDTO = JSONObject.parseObject(params, QueryPaymentInfoDTO.class); // QueryPaymentInfoDTO queryPaymentInfoDTO = JSONObject.parseObject(params, QueryPaymentInfoDTO.class);
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
@@ -888,7 +918,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
@Resource @Resource
private MinioClient minioClient; private MinioClient minioClient;
public String excelExport(List<PaymentInfoVO> paymentInfoVOS, HttpServletResponse response) throws IOException { public String excelExport(List<PaymentInfoVO> paymentInfoVOS, HttpServletResponse response) throws IOException {
if (paymentInfoVOS == null || paymentInfoVOS.isEmpty()) { if (paymentInfoVOS == null || paymentInfoVOS.isEmpty()) {
log.info("无数据,直接返回,不生成空文件"); log.info("无数据,直接返回,不生成空文件");
return null; return null;
@@ -1030,10 +1060,11 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
/** /**
* 查询generate使用频次 * 查询generate使用频次
*
* @param queryDTO * @param queryDTO
* @return * @return
*/ */
public PageBaseResponse<AccountCreditsUsageDTO> getGenerateFrequency(AccountCreditsUsageQueryDTO queryDTO){ public PageBaseResponse<AccountCreditsUsageDTO> getGenerateFrequency(AccountCreditsUsageQueryDTO queryDTO) {
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(accountId); Account account = accountService.getById(accountId);
// 允许查看数据的用户id // 允许查看数据的用户id
@@ -1045,7 +1076,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
)) { )) {
boolean groupByEvent = !StringUtil.isNullOrEmpty(queryDTO.getChangeEvent()); boolean groupByEvent = !StringUtil.isNullOrEmpty(queryDTO.getChangeEvent());
String role; String role;
switch (account.getSystemUser()){ switch (account.getSystemUser()) {
case 5: case 5:
role = "corp"; role = "corp";
break; break;
@@ -1063,7 +1094,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
List<AccountCreditsUsageDTO> creditsUsageDTOS = accountMapper.selectCreditUsage( List<AccountCreditsUsageDTO> creditsUsageDTOS = accountMapper.selectCreditUsage(
groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(), groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(),
queryDTO.getStartTime(), queryDTO.getEndTime(), size, offset, account.getOrganizationName()); queryDTO.getStartTime(), queryDTO.getEndTime(), size, offset, account.getOrganizationName());
if (!creditsUsageDTOS.isEmpty()){ if (!creditsUsageDTOS.isEmpty()) {
int total = accountMapper.countCreditUsage( int total = accountMapper.countCreditUsage(
groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(), groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(),
queryDTO.getStartTime(), queryDTO.getEndTime(), account.getOrganizationName()); queryDTO.getStartTime(), queryDTO.getEndTime(), account.getOrganizationName());
@@ -1077,21 +1108,22 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
response.setTotal(total); response.setTotal(total);
response.setPages((long) totalPage); response.setPages((long) totalPage);
return response; return response;
}else { } else {
return new PageBaseResponse<>(); return new PageBaseResponse<>();
} }
}else { } else {
throw new BusinessException("have.no.permission"); throw new BusinessException("have.no.permission");
} }
} }
public List<String> getAllGenerateFuncName(){ public List<String> getAllGenerateFuncName() {
return CreditsEventsEnum.generateFunctionNames(); return CreditsEventsEnum.generateFunctionNames();
} }
@Resource @Resource
private OrganizationMapper organizationMapper; private OrganizationMapper organizationMapper;
public void addOrganization(String name, String type){
public Organization addOrganization(String name, String type) {
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(accountId); Account account = accountService.getById(accountId);
// 允许查看数据的用户id // 允许查看数据的用户id
@@ -1102,19 +1134,37 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
organization.setName(name); organization.setName(name);
organization.setType(type); organization.setType(type);
organization.setCategoryType("root"); organization.setCategoryType("root");
organization.setStatus(1);
organization.setCreateTime(LocalDateTime.now()); organization.setCreateTime(LocalDateTime.now());
organizationMapper.insert(organization); organizationMapper.insert(organization);
return organization;
} }
public List<Organization> queryOrganization(String type){ public IPage<Organization> queryOrganization(QueryOrganizationPageDTO queryDTO) {
// 查询所有的组织名及id QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
switch (type){ // 按时间区间查
case "Enterprise": if (!StringUtils.isNullOrEmpty(queryDTO.getStartTime())) {
case "Education": queryWrapper.lambda().gt(Organization::getCreateTime, queryDTO.getStartTime());
return organizationMapper.selectList(new QueryWrapper<Organization>().eq("type", type).eq("category_type", "root"));
default:
throw new BusinessException("Unknown type");
} }
if (!StringUtils.isNullOrEmpty(queryDTO.getEndTime())) {
queryWrapper.lambda().lt(Organization::getCreateTime, queryDTO.getEndTime());
}
if (Objects.nonNull(queryDTO.getId())){
queryWrapper.lambda().eq(Organization::getId, queryDTO.getId());
}
// 按类型查
if (!StringUtil.isNullOrEmpty(queryDTO.getType())){
if (!queryDTO.getType().equals("Enterprise") && !queryDTO.getType().equals("Education")) {
throw new BusinessException("Unknown type");
}
queryWrapper.lambda().eq(Organization::getType, queryDTO.getType());
}
// 按机构名查
if (!StringUtil.isNullOrEmpty(queryDTO.getName())){
queryWrapper.lambda().like(Organization::getName, queryDTO.getName());
}
return organizationMapper.selectPage(new Page<>(queryDTO.getPage(), queryDTO.getSize()), queryWrapper);
} }
} }

View File

@@ -1052,6 +1052,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
Library library = new Library(); Library library = new Library();
library.setAccountId(UserContext.getUserHolder().getId()); library.setAccountId(UserContext.getUserHolder().getId());
library.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName()); library.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
library.setLevel2Type(print.getLevel2Type());
library.setUrl(print.getMinIOPath()); library.setUrl(print.getMinIOPath());
library.setName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))); library.setName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
library.setMd5(md5); library.setMd5(md5);