TASK:模块化;

This commit is contained in:
shahaibo
2025-04-11 10:10:38 +08:00
parent cf9b621159
commit 1ee612674e
6 changed files with 232 additions and 49 deletions

View File

@@ -12,6 +12,8 @@ import com.ai.da.model.vo.AccountPreLoginVO;
import com.ai.da.model.vo.BindEmailVO;
import com.ai.da.model.vo.PersonalHomepageVO;
import com.ai.da.service.AccountService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.minio.errors.MinioException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@@ -22,10 +24,13 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Api(tags = "Account模块")
@@ -273,16 +278,22 @@ public class AccountController {
@PostMapping("enterpriseLogin")
@ApiOperation(value = "企业登录")
public Response<AccountLoginVO> enterpriseLogin(@Valid @RequestBody AccountLoginDTO accountDTO) {
public Response<AccountPreLoginVO> enterpriseLogin(@Valid @RequestBody AccountLoginDTO accountDTO) {
return Response.success(accountService.enterpriseLogin(accountDTO));
}
@PostMapping("schoolLogin")
@ApiOperation(value = "学校登录")
public Response<AccountLoginVO> schoolLogin(@Valid @RequestBody AccountLoginDTO accountDTO) {
public Response<AccountPreLoginVO> schoolLogin(@Valid @RequestBody AccountLoginDTO accountDTO) {
return Response.success(accountService.schoolLogin(accountDTO));
}
@PostMapping("organizationNameSearch")
@ApiOperation(value = "组织名模糊查询")
public Response<Set<String>> organizationNameSearch(@RequestParam("type") String type, @RequestParam("name") String name) {
return Response.success(accountService.organizationNameSearch(type, name));
}
@PostMapping("addOrUpdateSubAccount")
@ApiOperation(value = "子账号新增")
public Response<Boolean> addSubAccount(@Valid @RequestBody AddSubAccountDTO addSubAccountDTO) {
@@ -348,4 +359,16 @@ public class AccountController {
public Response<Boolean> updateUserInfo(@Valid @RequestBody UpdateUserInfoDTO updateUserInfoDTO) {
return Response.success(accountService.updateUserInfo(updateUserInfoDTO));
}
@GetMapping("/subAccountImportExcelDownload")
@ApiOperation(value = "模板下载")
public void subAccountImportExcelDownload(HttpServletResponse response) {
accountService.subAccountImportExcelDownload(response);
}
@PostMapping("/subAccountImport")
@ApiOperation(value = "模板导入")
public Response<Boolean> subAccountImport(@RequestParam("file") MultipartFile file) {
return Response.success(accountService.subAccountImport(file));
}
}

View File

@@ -5,5 +5,11 @@ import lombok.Data;
@Data
public class SubAccountPageDTO extends PageQueryBaseVo {
private String startTime;
private String endTime;
private String email;
private String userName;
}

View File

@@ -0,0 +1,13 @@
package com.ai.da.model.dto;
import com.ai.da.model.vo.PageQueryBaseVo;
public class SubAccountPageQuery extends PageQueryBaseVo {
private String startTime;
private String endTime;
private String email;
private String userName;
}

View File

@@ -14,9 +14,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 服务类
@@ -194,9 +196,9 @@ public interface AccountService extends IService<Account> {
void temporaryUpgrade();
AccountLoginVO enterpriseLogin(AccountLoginDTO accountDTO);
AccountPreLoginVO enterpriseLogin(AccountLoginDTO accountDTO);
AccountLoginVO schoolLogin(AccountLoginDTO accountDTO);
AccountPreLoginVO schoolLogin(AccountLoginDTO accountDTO);
Boolean addSubAccount(AddSubAccountDTO addSubAccountDTO);
@@ -225,4 +227,10 @@ public interface AccountService extends IService<Account> {
void updateUserRoleAndCredits(Long accountId, String type);
Boolean updateUserInfo(UpdateUserInfoDTO updateUserInfoDTO);
void subAccountImportExcelDownload(HttpServletResponse response);
Boolean subAccountImport(MultipartFile file);
Set<String> organizationNameSearch(String type, String name);
}

View File

@@ -38,6 +38,7 @@ import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
@@ -46,10 +47,14 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.sql.Connection;
@@ -176,7 +181,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getEmail()), "Please input a email !");
// Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getEmailVerifyCode()), "Please input the email verification code !");
log.info("aida确认登入###accountLoginDTO###{}", JSON.toJSONString(accountLoginDTO));
Account accountExist = getOneByEmail(accountLoginDTO.getEmail().trim());
Account accountExist = getOneByEmailAndOrganizationName(accountLoginDTO.getEmail().trim(), accountLoginDTO.getOrganizationName());
LoginTypeEnum accountType = LoginTypeEnum.of(accountLoginDTO.getLoginType());
if (Objects.isNull(accountType)) {
throw new BusinessException("unknown.login.type");
@@ -237,6 +242,19 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return response;
}
private Account getOneByEmailAndOrganizationName(String email, String organizationName) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("BINARY user_email", email);
if (StringUtils.isNotBlank(organizationName)) {
queryWrapper.eq("organizationName", organizationName);
}
List<Account> accountList = accountMapper.selectList(queryWrapper);
if (CollectionUtil.isEmpty(accountList)) {
throw new BusinessException("email.does.not.exist", ResultEnum.PROMPT.getCode());
}
return accountList.get(0);
}
private void validateUserValidaExpire(Account account) {
Long currentTime = new Date().getTime();
if (account.getSystemUser().equals(0)){
@@ -2143,7 +2161,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public AccountLoginVO enterpriseLogin(AccountLoginDTO accountDTO) {
public AccountPreLoginVO enterpriseLogin(AccountLoginDTO accountDTO) {
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.lambda().eq(Account::getUserEmail, accountDTO.getEmail());
qw.lambda().eq(Account::getOrganizationName, accountDTO.getOrganizationName());
@@ -2157,34 +2175,58 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
throw new BusinessException("Password error.");
}
Account account = accounts.get(0);
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
response.setEmail(account.getUserEmail());
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
if (StringUtils.isNotBlank(token)) {
//用户已登入
response.setToken(token);
validateUserValidaExpire(account);
if ("Third-000000".equals(account.getUserPassword())) {
account.setUserPassword(accountDTO.getPassword());
accountMapper.updateById(account);
} else {
response.setToken(createAccountToken(account));
if (!account.getUserPassword().equals(accountDTO.getPassword())) {
throw new BusinessException("password.error", ResultEnum.PROMPT.getCode());
}
}
response.setUserId(account.getId());
response.setSystemUser(account.getSystemUser());
// 设置头像
String avatar;
if (StringUtil.isNullOrEmpty(account.getAvatar())){
avatar = CommonConstant.DEFAULT_AVATAR;
}else {
avatar = account.getAvatar();
/*发送邮件*/
AuthenticationOperationTypeEnum authenticationOperationTypeEnum = AuthenticationOperationTypeEnum.of("LOGIN");
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
LocalCacheUtils.setVerifyCodeCache(
"LOGIN_" + accountDTO.getEmail(), randomVerifyCode);
Boolean result = Boolean.FALSE;
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
if (!result) {
throw new BusinessException("failed.to.send.mail");
}
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
//判断是否常用ip 不是则发邮件提示
// calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
return response;
return new AccountPreLoginVO(account.getId());
// AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
// response.setEmail(account.getUserEmail());
// String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
// if (StringUtils.isNotBlank(token)) {
// //用户已登入
// response.setToken(token);
// } else {
// response.setToken(createAccountToken(account));
// }
// response.setUserId(account.getId());
// response.setSystemUser(account.getSystemUser());
// // 设置头像
// String avatar;
// if (StringUtil.isNullOrEmpty(account.getAvatar())){
// avatar = CommonConstant.DEFAULT_AVATAR;
// }else {
// avatar = account.getAvatar();
// }
// response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
// response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
// response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
// //判断是否常用ip 不是则发邮件提示
//// calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
// return response;
}
@Override
public AccountLoginVO schoolLogin(AccountLoginDTO accountDTO) {
public AccountPreLoginVO schoolLogin(AccountLoginDTO accountDTO) {
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.lambda().eq(Account::getUserEmail, accountDTO.getEmail());
qw.lambda().eq(Account::getOrganizationName, accountDTO.getOrganizationName());
@@ -2198,30 +2240,53 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
throw new BusinessException("Password error.");
}
Account account = accounts.get(0);
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
response.setEmail(account.getUserEmail());
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
if (StringUtils.isNotBlank(token)) {
//用户已登入
response.setToken(token);
validateUserValidaExpire(account);
if ("Third-000000".equals(account.getUserPassword())) {
account.setUserPassword(accountDTO.getPassword());
accountMapper.updateById(account);
} else {
response.setToken(createAccountToken(account));
if (!account.getUserPassword().equals(accountDTO.getPassword())) {
throw new BusinessException("password.error", ResultEnum.PROMPT.getCode());
}
}
response.setUserId(account.getId());
response.setSystemUser(account.getSystemUser());
// 设置头像
String avatar;
if (StringUtil.isNullOrEmpty(account.getAvatar())){
avatar = CommonConstant.DEFAULT_AVATAR;
}else {
avatar = account.getAvatar();
/*发送邮件*/
AuthenticationOperationTypeEnum authenticationOperationTypeEnum = AuthenticationOperationTypeEnum.of("LOGIN");
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
LocalCacheUtils.setVerifyCodeCache(
"LOGIN_" + accountDTO.getEmail(), randomVerifyCode);
Boolean result = Boolean.FALSE;
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
if (!result) {
throw new BusinessException("failed.to.send.mail");
}
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
//判断是否常用ip 不是则发邮件提示
// calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
return response;
return new AccountPreLoginVO(account.getId());
// AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
// response.setEmail(account.getUserEmail());
// String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
// if (StringUtils.isNotBlank(token)) {
// //用户已登入
// response.setToken(token);
// } else {
// response.setToken(createAccountToken(account));
// }
// response.setUserId(account.getId());
// response.setSystemUser(account.getSystemUser());
// // 设置头像
// String avatar;
// if (StringUtil.isNullOrEmpty(account.getAvatar())){
// avatar = CommonConstant.DEFAULT_AVATAR;
// }else {
// avatar = account.getAvatar();
// }
// response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
// response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
// response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
// //判断是否常用ip 不是则发邮件提示
//// calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
// return response;
}
@Override
@@ -2275,6 +2340,18 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.lambda().ne(Account::getId, account.getId());
qw.lambda().eq(Account::getOrganizationName, account.getOrganizationName());
if (StringUtils.isNotBlank(subAccountPageDTO.getStartTime())) {
qw.lambda().ge(Account::getCreateDate, subAccountPageDTO.getStartTime());
}
if (StringUtils.isNotBlank(subAccountPageDTO.getEndTime())) {
qw.lambda().le(Account::getCreateDate, subAccountPageDTO.getEndTime());
}
if (StringUtils.isNotBlank(subAccountPageDTO.getEmail())) {
qw.lambda().like(Account::getUserEmail, subAccountPageDTO.getEmail());
}
if (StringUtils.isNotBlank(subAccountPageDTO.getUserName())) {
qw.lambda().like(Account::getUserName, subAccountPageDTO.getUserName());
}
// 执行分页查询
IPage<Account> page = accountMapper.selectPage(new Page<>(subAccountPageDTO.getPage(), subAccountPageDTO.getSize()), qw);
@@ -2837,4 +2914,60 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountMapper.updateById(account);
return Boolean.TRUE;
}
@Override
public void subAccountImportExcelDownload(HttpServletResponse response) {
// 文件名
String fileName = "sub_account_import_template.xlsx";
// 获取文件输入流
try (InputStream inputStream = new ClassPathResource("files/" + fileName).getInputStream();
OutputStream outputStream = response.getOutputStream()) {
// 设置响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
// 写出数据
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
outputStream.flush();
} catch (IOException e) {
throw new RuntimeException("下载模板文件失败", e);
}
}
@Override
public Boolean subAccountImport(MultipartFile file) {
return null;
}
@Override
public Set<String> organizationNameSearch(String type, String name) {
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.lambda().like(Account::getOrganizationName, name);
if (type.equals("School")) {
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<>();
schoolList.add(5L);
schoolList.add(6L);
qw.lambda().in(Account::getSystemUser, schoolList);
}
List<Account> accountList = accountMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(accountList)) {
return accountList.stream().map(Account::getOrganizationName).collect(Collectors.toSet());
}
return new HashSet<>();
}
}