TASK: 全局异常处理,代码优化,测试数据库连接信息变更;
This commit is contained in:
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
@@ -28,6 +29,7 @@ public class AccountLoginLogServiceImpl extends ServiceImpl<AccountLoginLogMappe
|
||||
AccountLoginLogMapper accountLoginLogMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean saveLoginLog(String ip, Long accountId) {
|
||||
AccountLoginLog accountLoginLog = new AccountLoginLog();
|
||||
accountLoginLog.setAccountId(accountId);
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.ai.da.service.impl;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.enums.LoginTypeEnum;
|
||||
import com.ai.da.common.enums.OperationTypeEnum;
|
||||
import com.ai.da.common.enums.AuthenticationOperationTypeEnum;
|
||||
import com.ai.da.common.security.jwt.JWTTokenHelper;
|
||||
import com.ai.da.common.utils.*;
|
||||
import com.ai.da.mapper.AccountMapper;
|
||||
@@ -51,41 +51,44 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
||||
log.info("aida预先登入accountDTO###{}", JSON.toJSONString(accountDTO));
|
||||
Account account = getOneByUserName(accountDTO.getUserName());
|
||||
Assert.isTrue(Objects.nonNull(account), "User does not exist!");
|
||||
//用户有效期校验
|
||||
validateUserValidaExpire(account);
|
||||
if ("Third-000000".equals(account.getUserPassword())) {
|
||||
account.setUserPassword(accountDTO.getPassword());
|
||||
accountMapper.updateById(account);
|
||||
} else {
|
||||
Assert.isTrue(account.getUserPassword().equals(accountDTO.getPassword()), "Password error !");
|
||||
if (!account.getUserPassword().equals(accountDTO.getPassword())) {
|
||||
throw new BusinessException("password.error");
|
||||
}
|
||||
}
|
||||
/*发送邮件*/
|
||||
OperationTypeEnum operationTypeEnum = OperationTypeEnum.of(accountDTO.getOperationType());
|
||||
AuthenticationOperationTypeEnum authenticationOperationTypeEnum = AuthenticationOperationTypeEnum.of(accountDTO.getOperationType());
|
||||
log.info(account.getUserEmail());
|
||||
log.info(accountDTO.getEmail());
|
||||
Assert.isTrue(account.getUserEmail().equals(accountDTO.getEmail()), "Email error !");
|
||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
||||
if (!account.getUserEmail().equals(accountDTO.getEmail())) {
|
||||
throw new BusinessException("email.error");
|
||||
}
|
||||
if (Objects.isNull(authenticationOperationTypeEnum)) {
|
||||
throw new BusinessException("unknown.authentication.operation.type");
|
||||
}
|
||||
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
|
||||
LocalCacheUtils.setVerifyCodeCache(
|
||||
accountDTO.getOperationType() + "_" + accountDTO.getEmail(), randomVerifyCode);
|
||||
Boolean result = Boolean.FALSE;
|
||||
switch (operationTypeEnum) {
|
||||
switch (authenticationOperationTypeEnum) {
|
||||
case LOGIN:
|
||||
Assert.notNull(accountDTO, "Email not registered!");
|
||||
result = SendEmailUtil.send(accountDTO.getEmail(), null,
|
||||
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
case FORGET_PWD:
|
||||
Assert.notNull(accountDTO, "Email not registered!");
|
||||
result = SendEmailUtil.send(accountDTO.getEmail(), null,
|
||||
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
case EXCEPTION_IP:
|
||||
Assert.notNull(accountDTO, "Email not registered!");
|
||||
result = SendEmailUtil.send(accountDTO.getEmail(), accountDTO.getIp(),
|
||||
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
@@ -94,22 +97,26 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
default:
|
||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
||||
}
|
||||
Assert.isTrue(result, "Failed to send mail");
|
||||
if (!result) {
|
||||
throw new BusinessException("failed.to.send.mail");
|
||||
}
|
||||
return new AccountPreLoginVO(account.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request) {
|
||||
// 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());
|
||||
Assert.notNull(accountExist, "User does not exist!");
|
||||
|
||||
LoginTypeEnum accountType = LoginTypeEnum.of(accountLoginDTO.getLoginType());
|
||||
if (Objects.isNull(accountType) || accountType.equals(LoginTypeEnum.PASSWORD)) {
|
||||
throw new BusinessException("Unknown login type!");
|
||||
if (Objects.isNull(accountType)) {
|
||||
throw new BusinessException("unknown.login.type");
|
||||
}
|
||||
if (!accountType.equals(LoginTypeEnum.EMAIL)) {
|
||||
throw new BusinessException("error.login.type");
|
||||
}
|
||||
//用户有效期校验
|
||||
validateUserValidaExpire(accountExist);
|
||||
@@ -117,25 +124,23 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
Account account = null;
|
||||
switch (accountType) {
|
||||
case PASSWORD:
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getPassword()), "Please input a password !");
|
||||
account = getOneByUserName(accountLoginDTO.getUserName());
|
||||
Assert.isTrue(Objects.nonNull(account), "User does not exist!");
|
||||
Assert.isTrue(account.getUserPassword().equals(accountLoginDTO.getPassword()), "Password error !");
|
||||
// Assert.isTrue(StringUtils.isBlank(
|
||||
// LocalCacheUtils.getTokenCache(String.valueOf(account.getId()))),"该用户已登入");
|
||||
// Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getPassword()), "Please input a password !");
|
||||
// account = getOneByUserName(accountLoginDTO.getUserName());
|
||||
// Assert.isTrue(Objects.nonNull(account), "User does not exist!");
|
||||
// Assert.isTrue(account.getUserPassword().equals(accountLoginDTO.getPassword()), "Password error !");
|
||||
// 走不到这边
|
||||
break;
|
||||
case EMAIL:
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getEmail()), "Please input a email !");
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getEmailVerifyCode()), "Please input the email verification code !");
|
||||
account = getOneByEmail(accountLoginDTO.getEmail().trim());
|
||||
if (Objects.isNull(account)) {
|
||||
throw new BusinessException("Email not registered!");
|
||||
}
|
||||
//校验邮箱验证码
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.LOGIN.name() + "_" + accountLoginDTO.getEmail());
|
||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired!");
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(AuthenticationOperationTypeEnum.LOGIN.name() + "_" + accountLoginDTO.getEmail());
|
||||
if (StringUtils.isBlank(verifyCode)) {
|
||||
throw new BusinessException("the.verification.code.has.expired");
|
||||
}
|
||||
if (!"921314".equals(accountLoginDTO.getEmailVerifyCode())) {
|
||||
Assert.isTrue(verifyCode.equals(accountLoginDTO.getEmailVerifyCode()), "Verification code error!");
|
||||
if (!verifyCode.equals(accountLoginDTO.getEmailVerifyCode())) {
|
||||
throw new BusinessException("verification.code.error");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -147,7 +152,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
} else {
|
||||
response.setToken(createAccountToken(account.getId(), account.getUserName()));
|
||||
response.setToken(createAccountToken(account));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
//判断是否常用ip 不是则发邮件提示
|
||||
@@ -158,10 +163,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
private void validateUserValidaExpire(Account account) {
|
||||
Long currentTime = new Date().getTime();
|
||||
if (Objects.nonNull(account.getValidStartTime())) {
|
||||
Assert.isTrue(currentTime >= account.getValidStartTime(), "User expired !");
|
||||
if (currentTime < account.getValidStartTime()) {
|
||||
throw new BusinessException("user.expired");
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(account.getValidEndTime())) {
|
||||
Assert.isTrue(currentTime <= account.getValidEndTime(), "User expired !");
|
||||
if (currentTime > account.getValidEndTime()) {
|
||||
throw new BusinessException("user.expired");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +184,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
//非常用ip,没有出现过
|
||||
EmailSendDTO emailSendDTO = new EmailSendDTO();
|
||||
emailSendDTO.setEmail(account.getUserEmail());
|
||||
emailSendDTO.setOperationType(OperationTypeEnum.EXCEPTION_IP.name());
|
||||
emailSendDTO.setOperationType(AuthenticationOperationTypeEnum.EXCEPTION_IP.name());
|
||||
emailSendDTO.setIp(ip);
|
||||
sendEmail(emailSendDTO);
|
||||
}
|
||||
@@ -185,28 +194,34 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
accountLoginLogService.saveLoginLog(ip, account.getId());
|
||||
}
|
||||
|
||||
private String createAccountToken(Long userId, String userName) {
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(userId));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
return token;
|
||||
}
|
||||
private String createAccountToken(Account account) {
|
||||
AuthPrincipalVo principal = new AuthPrincipalVo();
|
||||
principal.setId(userId);
|
||||
principal.setUsername(userName);
|
||||
principal.setId(account.getId());
|
||||
principal.setUsername(account.getUserName());
|
||||
principal.setLanguage(account.getLanguage());
|
||||
principal.setCountry(account.getCountry());
|
||||
String token2 = jwtTokenHelper.createToken(principal);
|
||||
LocalCacheUtils.setTokenCache(String.valueOf(userId), token2);
|
||||
LocalCacheUtils.setTokenCache(String.valueOf(account.getId()), token2);
|
||||
return token2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO) {
|
||||
Account account = getOneByUserId(accountBindEmailDTO.getUserId());
|
||||
Assert.notNull(account, "User does not exist !");
|
||||
Assert.isTrue(StringUtils.isBlank(account.getUserEmail()), "User has bound mailbox !");
|
||||
Account account = baseMapper.selectById(accountBindEmailDTO.getUserId());
|
||||
if (Objects.isNull(account)) {
|
||||
throw new BusinessException("userName.does.not.exist");
|
||||
}
|
||||
if (StringUtils.isNotBlank(account.getUserEmail())) {
|
||||
throw new BusinessException("user.has.bound.mailbox");
|
||||
}
|
||||
//校验邮箱验证码
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.BIND_MAILBOX.name() + "_" + accountBindEmailDTO.getUserEmail());
|
||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired !");
|
||||
Assert.isTrue(verifyCode.equals(accountBindEmailDTO.getEmailVerifyCode()), "Verification code error !");
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(AuthenticationOperationTypeEnum.BIND_MAILBOX.name() + "_" + accountBindEmailDTO.getUserEmail());
|
||||
if (StringUtils.isBlank(verifyCode)) {
|
||||
throw new BusinessException("the.verification.code.has.expired");
|
||||
}
|
||||
if (!verifyCode.equals(accountBindEmailDTO.getEmailVerifyCode())) {
|
||||
throw new BusinessException("verification.code.error");
|
||||
}
|
||||
//绑定
|
||||
updatePwdByUserId(accountBindEmailDTO.getUserEmail(), accountBindEmailDTO.getUserId());
|
||||
return Boolean.TRUE;
|
||||
@@ -216,44 +231,54 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
@Override
|
||||
public Boolean forgetPwd(AccountRegisterDTO accountDTO) {
|
||||
Account emailAccount = getOneByEmail(accountDTO.getEmail());
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
//校验邮箱验证码
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.FORGET_PWD.name() + "_" + accountDTO.getEmail());
|
||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired!");
|
||||
Assert.isTrue(verifyCode.equals(accountDTO.getEmailVerifyCode()), "Verification code error!");
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(AuthenticationOperationTypeEnum.FORGET_PWD.name() + "_" + accountDTO.getEmail());
|
||||
if (StringUtils.isBlank(verifyCode)) {
|
||||
throw new BusinessException("the.verification.code.has.expired");
|
||||
}
|
||||
if (!verifyCode.equals(accountDTO.getEmailVerifyCode())) {
|
||||
throw new BusinessException("verification.code.error");
|
||||
}
|
||||
updatePwdByEmail(accountDTO.getPassword(), accountDTO.getEmail());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private void updatePwdByEmail(String pwd, String email) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_email", email);
|
||||
|
||||
queryWrapper.lambda().eq(Account::getUserEmail, email);
|
||||
Account accountNew = new Account();
|
||||
accountNew.setUserPassword(pwd);
|
||||
accountMapper.update(accountNew, queryWrapper);
|
||||
}
|
||||
|
||||
private void updatePwdByUserId(String email, Long userId) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", userId);
|
||||
|
||||
Account accountNew = new Account();
|
||||
accountNew.setUserEmail(email);
|
||||
accountMapper.update(accountNew, queryWrapper);
|
||||
accountNew.setId(userId);
|
||||
accountMapper.updateById(accountNew);
|
||||
}
|
||||
|
||||
|
||||
private Account getOneByEmail(String email) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_email", email);
|
||||
return accountMapper.selectOne(queryWrapper);
|
||||
queryWrapper.lambda().eq(Account::getUserEmail, email);
|
||||
queryWrapper.lambda().last("limit 1");
|
||||
List<Account> accountList = accountMapper.selectList(queryWrapper);
|
||||
if (CollectionUtil.isEmpty(accountList)) {
|
||||
throw new BusinessException("email.does.not.exist");
|
||||
}
|
||||
return accountList.get(0);
|
||||
}
|
||||
|
||||
private Account getOneByUserName(String userName) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_name", userName);
|
||||
return accountMapper.selectOne(queryWrapper);
|
||||
queryWrapper.lambda().eq(Account::getUserName, userName);
|
||||
queryWrapper.lambda().last("limit 1");
|
||||
List<Account> accountList = accountMapper.selectList(queryWrapper);
|
||||
if (CollectionUtil.isEmpty(accountList)) {
|
||||
throw new BusinessException("userName.does.not.exist");
|
||||
}
|
||||
return accountList.get(0);
|
||||
}
|
||||
|
||||
private Account getOneByUserId(Long userId) {
|
||||
@@ -265,27 +290,25 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
|
||||
@Override
|
||||
public Boolean sendEmail(EmailSendDTO emailSendDTO) {
|
||||
OperationTypeEnum operationTypeEnum = OperationTypeEnum.of(emailSendDTO.getOperationType());
|
||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
||||
|
||||
AuthenticationOperationTypeEnum authenticationOperationTypeEnum = AuthenticationOperationTypeEnum.of(emailSendDTO.getOperationType());
|
||||
if (Objects.isNull(authenticationOperationTypeEnum)) {
|
||||
throw new BusinessException("unknown.authentication.operation.type");
|
||||
}
|
||||
Account emailAccount = getOneByEmail(emailSendDTO.getEmail());
|
||||
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
|
||||
LocalCacheUtils.setVerifyCodeCache(
|
||||
emailSendDTO.getOperationType() + "_" + emailSendDTO.getEmail(), randomVerifyCode);
|
||||
Boolean result = Boolean.FALSE;
|
||||
switch (operationTypeEnum) {
|
||||
switch (authenticationOperationTypeEnum) {
|
||||
case LOGIN:
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
case FORGET_PWD:
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
case EXCEPTION_IP:
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), emailSendDTO.getIp(),
|
||||
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
@@ -294,9 +317,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
default:
|
||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
||||
}
|
||||
Assert.isTrue(result, "Failed to send mail");
|
||||
if (!result) {
|
||||
throw new BusinessException("failed.to.send.mail");
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ import com.ai.da.mapper.CollectionElementMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.enums.MalePosition;
|
||||
import com.ai.da.model.enums.ModelType;
|
||||
import com.ai.da.model.enums.Sex;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.python.vo.DesignPythonItem;
|
||||
@@ -308,8 +310,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
.collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(moodBoardIds)) {
|
||||
List<CollectionElement> MoodBoardElements = collectionElementMapper.selectBatchIds(moodBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(MoodBoardElements)
|
||||
&& MoodBoardElements.size() == moodBoardIds.size(), "get moodboard data is mismatch");
|
||||
if (CollectionUtil.isEmpty(MoodBoardElements) || MoodBoardElements.size() != moodBoardIds.size()) {
|
||||
throw new BusinessException("get.moodBoards.data.is.mismatch");
|
||||
}
|
||||
elementVO.setMoodBoardElements(MoodBoardElements);
|
||||
usedElementIds.addAll(moodBoardIds);
|
||||
}
|
||||
@@ -348,7 +351,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
//校验printboard
|
||||
List<CollectionElement> printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(printBoardElements)
|
||||
&& printBoardElements.size() == printBoardIds.size(), "get printboard data is mismatch");
|
||||
&& printBoardElements.size() == printBoardIds.size(), "get.printBoards.data.is.mismatch");
|
||||
elementVO.setPrintBoardElements(printBoardElements);
|
||||
usedElementIds.addAll(printBoardIds);
|
||||
}
|
||||
@@ -384,20 +387,36 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
|
||||
//校验PIN是否满足 上衣或者下衣必须不超过8
|
||||
long topNum = designDTO.getSketchBoards().stream()
|
||||
long topNum = 0;
|
||||
long bottomNum = 0;
|
||||
long outerwearNum = 0;
|
||||
if (designDTO.getModelSex().equals(Sex.FEMALE.getValue())) {
|
||||
topNum= designDTO.getSketchBoards().stream()
|
||||
.filter(skecth -> skecth.getIsPin() == 1
|
||||
&& DesignPythonItem.DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
|
||||
bottomNum = designDTO.getSketchBoards().stream()
|
||||
.filter(skecth -> skecth.getIsPin() == 1
|
||||
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
|
||||
}else if (designDTO.getModelSex().equals(Sex.MALE.getValue())) {
|
||||
topNum= designDTO.getSketchBoards().stream()
|
||||
.filter(skecth -> skecth.getIsPin() == 1
|
||||
&& DesignPythonItem.TOPS.contains(skecth.getLevel2Type())).count();
|
||||
bottomNum = designDTO.getSketchBoards().stream()
|
||||
.filter(skecth -> skecth.getIsPin() == 1
|
||||
&& DesignPythonItem.BOTTOMS.contains(skecth.getLevel2Type())).count();
|
||||
}
|
||||
outerwearNum = designDTO.getSketchBoards().stream()
|
||||
.filter(skecth -> skecth.getIsPin() == 1
|
||||
&& DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
|
||||
Assert.isTrue(topNum <= 8, "The number of PIN sketch cannot be greater than 8!");
|
||||
long bottomNum = designDTO.getSketchBoards().stream()
|
||||
.filter(skecth -> skecth.getIsPin() == 1
|
||||
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
|
||||
Assert.isTrue(bottomNum <= 8, "The number of PIN sketch cannot be greater than 8!");
|
||||
&& DesignPythonItem.OUTERWEAR.contains(skecth.getLevel2Type())).count();
|
||||
if (topNum > 8 || bottomNum > 8 || outerwearNum > 8) {
|
||||
throw new BusinessException("the.number.of.PIN.top.or.bottom.or.outerwear.sketchBoard.cannot.be.more.than.8");
|
||||
}
|
||||
//校验designType
|
||||
Boolean result = designDTO.getSketchBoards().stream()
|
||||
.filter(mood -> StringUtils.isEmpty(mood.getDesignType()))
|
||||
.findFirst().isPresent();
|
||||
if (result) {
|
||||
throw new BusinessException("sketchBoards designType cannot be empty!");
|
||||
throw new BusinessException("sketchBoards.designType.cannot.be.empty");
|
||||
}
|
||||
|
||||
List<Long> sketchBoardIds = designDTO.getSketchBoards().stream()
|
||||
@@ -408,7 +427,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
//校验sketchBoard
|
||||
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(sketchBoardElements)
|
||||
&& sketchBoardElements.size() == sketchBoardIds.size(), "get sketchboard data is mismatch");
|
||||
&& sketchBoardElements.size() == sketchBoardIds.size(), "get.sketchBoards.data.is.mismatch");
|
||||
elementVO.setSketchBoardElements(sketchBoardElements);
|
||||
usedElementIds.addAll(sketchBoardIds);
|
||||
}
|
||||
@@ -473,43 +492,24 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
// }
|
||||
//校验控制生成类型
|
||||
SingleOverallEnum singleOverall = SingleOverallEnum.of(designDTO.getSingleOverall());
|
||||
Assert.notNull(singleOverall, "unknown parameter singleOverall!");
|
||||
if (Objects.isNull(singleOverall)) {
|
||||
throw new BusinessException("unknown.parameter.singleOverall");
|
||||
}
|
||||
if (SingleOverallEnum.SINGLE.equals(singleOverall)) {
|
||||
SwitchCategoryEnum switchCategory = SwitchCategoryEnum.of(designDTO.getSwitchCategory());
|
||||
Assert.notNull(switchCategory, "unknown parameter switchCategory!");
|
||||
}
|
||||
//校验template
|
||||
if (Objects.nonNull(designDTO.getTemplateId())) {
|
||||
// LibraryModelPoint modelPoint = libraryModelPointService.getById(designDTO.getTemplateId());
|
||||
// Assert.notNull(modelPoint, "template cannot by empty!");
|
||||
// Library library = libraryService.getById(modelPoint.getLibraryId());
|
||||
// Assert.notNull(library, "template library cannot by empty!");
|
||||
if (designDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
|
||||
Library byId = libraryService.getById(designDTO.getTemplateId());
|
||||
QueryWrapper<LibraryModelPoint> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(LibraryModelPoint::getModelType, ModelType.LIBRARY.getValue());
|
||||
qw.lambda().eq(LibraryModelPoint::getRelationId, byId.getId());
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getOne(qw);
|
||||
if (Objects.isNull(modelPoint)) {
|
||||
throw new BusinessException("error modelPoint get");
|
||||
}
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, byId.getHigh(), byId.getWidth(), byId.getUrl()));
|
||||
} else if (designDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
|
||||
SysFileVO byId = sysFileService.getById(designDTO.getTemplateId());
|
||||
QueryWrapper<LibraryModelPoint> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(LibraryModelPoint::getModelType, ModelType.SYSTEM.getValue());
|
||||
qw.lambda().eq(LibraryModelPoint::getRelationId, byId.getId());
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getOne(qw);
|
||||
if (Objects.isNull(modelPoint)) {
|
||||
throw new BusinessException("error modelPoint get");
|
||||
}
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, 1050, 500, byId.getUrl()));
|
||||
if (Objects.isNull(switchCategory)) {
|
||||
throw new BusinessException("unknown.parameter.switchCategory");
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException("templateId or modelType can't be null");
|
||||
}
|
||||
if (StringUtils.isEmpty(designDTO.getModelSex())) {
|
||||
throw new BusinessException("modelSex can't be null");
|
||||
// 校验模特
|
||||
if (designDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
|
||||
Library byId = libraryService.getById(designDTO.getTemplateId());
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), designDTO.getModelType());
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, byId.getHigh(), byId.getWidth(), byId.getUrl()));
|
||||
} else if (designDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
|
||||
SysFileVO byId = sysFileService.getById(designDTO.getTemplateId());
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), designDTO.getModelType());
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, 680, 200, byId.getUrl()));
|
||||
}
|
||||
elementVO.setModelSex(designDTO.getModelSex());
|
||||
return elementVO;
|
||||
@@ -597,7 +597,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
private void validateDesignType(List<DesignCollectionElementDTO> collectionElements, String msg) {
|
||||
Boolean result = collectionElements.stream().filter(mood -> StringUtils.isEmpty(mood.getDesignType())).findFirst().isPresent();
|
||||
if (result) {
|
||||
throw new BusinessException(msg + " designType cannot be empty!");
|
||||
throw new BusinessException(msg + ".designType.cannot.be.empty");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,7 +638,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
return;
|
||||
}
|
||||
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", elementIds);
|
||||
queryWrapper.lambda().in(CollectionElement::getId, elementIds);
|
||||
CollectionElement element = new CollectionElement();
|
||||
element.setCollectionId(collectionId);
|
||||
//批量关联
|
||||
|
||||
@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -97,7 +98,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
@Value("${minio.bucketName.results}")
|
||||
private String bucketName;
|
||||
|
||||
// @Transactional
|
||||
@Override
|
||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
@@ -156,7 +156,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
element.setHasPin((byte) 0);
|
||||
}
|
||||
element.setId(null);
|
||||
// element.setType(DesignTypeEnum.LIBRARY.getRealName());
|
||||
});
|
||||
List<CollectionElement> saveElements = elementVO.getLibraryCollectionElements();
|
||||
collectionElementService.saveBatch(saveElements);
|
||||
@@ -299,8 +298,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
//组装design入参
|
||||
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
|
||||
designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId());
|
||||
//缓存保存的文件 方便后面处理进度问题 采用新的进度条获取方式 根据processId获取
|
||||
// setDesignProcess(userInfo.getId(), pythonObjects);
|
||||
// pythonObjects增加image_id关联
|
||||
relationImageId(pythonObjects);
|
||||
//design
|
||||
@@ -308,13 +305,11 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
//生成library
|
||||
generateLibrary(elementVO, designDTO.getTimeZone());
|
||||
//处理关联关系,修复element覆盖得情况
|
||||
List<CollectionElement> reLationelements = collectionElementService.getByOnlyCollectionId(collectionId);
|
||||
List<Long> reLationelementIds = reLationelements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||
handleCollectionElementRelation(collectionId, (null == collectionIdParam) ? false : true, reLationelementIds);
|
||||
//保存python返回信息
|
||||
List<CollectionElement> relationElements = collectionElementService.getByOnlyCollectionId(collectionId);
|
||||
List<Long> relationElementIds = relationElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||
handleCollectionElementRelation(collectionId, null != collectionIdParam, relationElementIds);
|
||||
//保存python返回信息;保存designItem和detail
|
||||
return savePythonDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone(), responseJSONObject, designDTO.getSingleOverall());
|
||||
//保存designItem 和detail
|
||||
// return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
@@ -137,10 +138,14 @@ public class LibraryModelPointServiceImpl extends ServiceImpl<LibraryModelPointM
|
||||
@Override
|
||||
public LibraryModelPoint getByRelationId(Long relationId, String modelType) {
|
||||
QueryWrapper<LibraryModelPoint> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("relation_id", relationId)
|
||||
.eq("model_type", modelType);
|
||||
|
||||
return baseMapper.selectOne(queryWrapper);
|
||||
queryWrapper.lambda().eq(LibraryModelPoint::getRelationId, relationId);
|
||||
queryWrapper.lambda().eq(LibraryModelPoint::getModelType, modelType);
|
||||
queryWrapper.lambda().last("limit 1");
|
||||
List<LibraryModelPoint> libraryModelPoints = baseMapper.selectList(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(libraryModelPoints)) {
|
||||
throw new BusinessException("modelPoint.not.find");
|
||||
}
|
||||
return libraryModelPoints.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
|
||||
private List<PantoneVO> coverPanToneToVoList(List<PanTone> panTones
|
||||
, Map<Integer, Integer> indexToValue, Map<Integer, GetRgbByHsvBatchDTO> valueToHsv,
|
||||
List<GetRgbByHsvBatchDTO> hsvBatch) {
|
||||
if (Objects.isNull(panTones)) {
|
||||
if (CollectionUtil.isEmpty(panTones)) {
|
||||
throw new BusinessException("Pantone value does not exist !");
|
||||
}
|
||||
List<PantoneVO> templateResposne = CopyUtil.copyList(panTones, PantoneVO.class, (o, d) -> {
|
||||
|
||||
Reference in New Issue
Block a user