TASK:模块化;
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user