TASK: 全局异常处理,代码优化,测试数据库连接信息变更;
This commit is contained in:
@@ -1,8 +1,18 @@
|
|||||||
package com.ai.da.common.config.exception;
|
package com.ai.da.common.config.exception;
|
||||||
|
|
||||||
|
import com.ai.da.common.context.UserContext;
|
||||||
import com.ai.da.common.response.ResultEnum;
|
import com.ai.da.common.response.ResultEnum;
|
||||||
|
import com.ai.da.model.vo.AuthPrincipalVo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.PropertyResourceBundle;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: dangweijian
|
* @author: dangweijian
|
||||||
* @description: 业务异常
|
* @description: 业务异常
|
||||||
@@ -15,14 +25,44 @@ public class BusinessException extends RuntimeException {
|
|||||||
private String msg;
|
private String msg;
|
||||||
|
|
||||||
public BusinessException(ResultEnum resultEnum) {
|
public BusinessException(ResultEnum resultEnum) {
|
||||||
super(resultEnum.getMsg());
|
|
||||||
this.code = resultEnum.getCode();
|
this.code = resultEnum.getCode();
|
||||||
this.msg = resultEnum.getMsg();
|
this.msg = getMessageFromResource(resultEnum.getMsg(), getUserLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BusinessException(String msg) {
|
public BusinessException(String msg) {
|
||||||
super(msg);
|
|
||||||
this.code = ResultEnum.FAIL.getCode();
|
this.code = ResultEnum.FAIL.getCode();
|
||||||
this.msg = msg;
|
this.msg = getMessageFromResource(msg, getUserLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(String msg, Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = getMessageFromResource(msg, getUserLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(Throwable cause) {
|
||||||
|
this.code = ResultEnum.FAIL.getCode();
|
||||||
|
this.msg = getMessageFromResource(cause.getMessage(), getUserLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Locale getUserLocale() {
|
||||||
|
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||||
|
if (Objects.isNull(userInfo)) {
|
||||||
|
return new Locale("en");
|
||||||
|
}
|
||||||
|
return new Locale(userInfo.getLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getMessageFromResource(String msg, Locale userLocale) {
|
||||||
|
try (InputStream inputStream = BusinessException.class.getClassLoader().getResourceAsStream("messages_" + userLocale.getLanguage() + ".properties")) {
|
||||||
|
if (inputStream != null) {
|
||||||
|
ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||||
|
if (bundle.containsKey(msg)) {
|
||||||
|
return bundle.getString(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return msg; // 如果找不到对应的资源文件,返回原始的消息
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,8 @@ public class ExceptionCatch {
|
|||||||
@ExceptionHandler(BindException.class)
|
@ExceptionHandler(BindException.class)
|
||||||
public Response<String> bindExceptionHandler(BindException e) {
|
public Response<String> bindExceptionHandler(BindException e) {
|
||||||
log.error("参数错误bind:{}", e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
log.error("参数错误bind:{}", e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
||||||
return Response.fail(ResultEnum.FAIL.getCode(), e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
BusinessException businessException = new BusinessException(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
||||||
|
return Response.error(businessException.getCode(), businessException.getMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,9 +76,10 @@ public class ExceptionCatch {
|
|||||||
*/
|
*/
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
public Response<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
|
public Response<String> handleValidationException(MethodArgumentNotValidException e) {
|
||||||
log.error("参数错误bind:{}", e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
log.error("参数错误bind:{}", e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
||||||
return Response.fail(ResultEnum.FAIL.getCode(), e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
BusinessException businessException = new BusinessException(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
||||||
|
return Response.error(businessException.getCode(), businessException.getMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化,不可预知异常自定义错误编码
|
//初始化,不可预知异常自定义错误编码
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.stream.Stream;
|
|||||||
* @description: 操作类型 登入 忘记密码
|
* @description: 操作类型 登入 忘记密码
|
||||||
* @create: 2022-8-10 17:33
|
* @create: 2022-8-10 17:33
|
||||||
**/
|
**/
|
||||||
public enum OperationTypeEnum {
|
public enum AuthenticationOperationTypeEnum {
|
||||||
/**
|
/**
|
||||||
* 登入
|
* 登入
|
||||||
*/
|
*/
|
||||||
@@ -25,7 +25,7 @@ public enum OperationTypeEnum {
|
|||||||
*/
|
*/
|
||||||
FORGET_PWD;
|
FORGET_PWD;
|
||||||
|
|
||||||
public static OperationTypeEnum of(String name) {
|
public static AuthenticationOperationTypeEnum of(String name) {
|
||||||
return Stream.of(OperationTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null);
|
return Stream.of(AuthenticationOperationTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,8 @@ public enum SwitchCategoryEnum {
|
|||||||
* 裤子
|
* 裤子
|
||||||
*/
|
*/
|
||||||
TROUSERS("Trousers"),
|
TROUSERS("Trousers"),
|
||||||
|
TOPS("Tops"),
|
||||||
|
BOTTOMS("Bottoms"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private String realName;
|
private String realName;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.tencentcloudapi.ses.v20201002.models.SendEmailRequest;
|
|||||||
import com.tencentcloudapi.ses.v20201002.models.SendEmailResponse;
|
import com.tencentcloudapi.ses.v20201002.models.SendEmailResponse;
|
||||||
import com.tencentcloudapi.ses.v20201002.models.Template;
|
import com.tencentcloudapi.ses.v20201002.models.Template;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@ public class SendEmailUtil {
|
|||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
} catch (TencentCloudSDKException e) {
|
} catch (TencentCloudSDKException e) {
|
||||||
log.info("邮件发送失败###{}", e.toString());
|
log.info("邮件发送失败###{}", e.toString());
|
||||||
throw new BusinessException(e.getMessage());
|
throw new BusinessException("failed.to.send.mail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package com.ai.da.controller;
|
package com.ai.da.controller;
|
||||||
|
|
||||||
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
import com.ai.da.common.response.Response;
|
import com.ai.da.common.response.Response;
|
||||||
import com.ai.da.model.dto.*;
|
import com.ai.da.model.dto.*;
|
||||||
import com.ai.da.model.vo.DesignCollectionVO;
|
import com.ai.da.model.vo.DesignCollectionVO;
|
||||||
import com.ai.da.model.vo.DesignLikeVO;
|
import com.ai.da.model.vo.DesignLikeVO;
|
||||||
import com.ai.da.service.DesignService;
|
import com.ai.da.service.DesignService;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ public class LibraryController {
|
|||||||
private String calculateTempFileUrl(Long userId) {
|
private String calculateTempFileUrl(Long userId) {
|
||||||
String rootPath = fileProperties.getSys().getPath();
|
String rootPath = fileProperties.getSys().getPath();
|
||||||
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||||
return rootPath + day + File.separator + "tmp" + File.separator + userId + File.separator + UUID.randomUUID().toString();
|
return rootPath + day + File.separator + "tmp" + File.separator + userId + File.separator + UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String calculateTempFileUrlNew(Long userId) {
|
private String calculateTempFileUrlNew(Long userId) {
|
||||||
|
|||||||
@@ -45,6 +45,16 @@ public class Account implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String userPassword;
|
private String userPassword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语言
|
||||||
|
*/
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 城市
|
||||||
|
*/
|
||||||
|
private String country;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 账户有效期开始时间
|
* 账户有效期开始时间
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ import javax.validation.constraints.NotNull;
|
|||||||
@ApiModel("绑定邮箱")
|
@ApiModel("绑定邮箱")
|
||||||
public class AccountBindEmailDTO {
|
public class AccountBindEmailDTO {
|
||||||
|
|
||||||
@NotNull(message = "userId cannot be empty!")
|
@NotNull(message = "userId.cannot.be.empty")
|
||||||
@ApiModelProperty("用户id")
|
@ApiModelProperty("用户id")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@NotBlank(message = "Please input email!")
|
@NotBlank(message = "email.cannot.be.empty")
|
||||||
@ApiModelProperty("邮箱")
|
@ApiModelProperty("邮箱")
|
||||||
private String userEmail;
|
private String userEmail;
|
||||||
|
|
||||||
@NotBlank(message = "Please input the email verification code !")
|
@NotBlank(message = "emailVerifyCode.cannot.be.empty")
|
||||||
@ApiModelProperty("邮箱验证码")
|
@ApiModelProperty("邮箱验证码")
|
||||||
private String emailVerifyCode;
|
private String emailVerifyCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ import javax.validation.constraints.NotNull;
|
|||||||
@ApiModel("登入")
|
@ApiModel("登入")
|
||||||
public class AccountLoginDTO {
|
public class AccountLoginDTO {
|
||||||
|
|
||||||
@NotNull(message = "userId cannot be empty !")
|
@NotNull(message = "userId.cannot.be.empty")
|
||||||
@ApiModelProperty("userId")
|
@ApiModelProperty("userId")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@NotBlank(message = "Please input email !")
|
@NotBlank(message = "email.cannot.be.empty")
|
||||||
@ApiModelProperty("邮箱")
|
@ApiModelProperty("邮箱")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ public class AccountLoginDTO {
|
|||||||
@ApiModelProperty("密码")
|
@ApiModelProperty("密码")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank(message = "Please input loginType !")
|
@NotBlank(message = "loginType.cannot.be.empty")
|
||||||
@ApiModelProperty("登入类型 EMAIL - >邮箱 , PASSWORD ->密码")
|
@ApiModelProperty("登入类型 EMAIL - >邮箱 , PASSWORD ->密码")
|
||||||
private String loginType;
|
private String loginType;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull;
|
|||||||
@ApiModel("登出")
|
@ApiModel("登出")
|
||||||
public class AccountLogoutDTO {
|
public class AccountLogoutDTO {
|
||||||
|
|
||||||
@NotNull(message = "userId cannot be empty !")
|
@NotNull(message = "userId.cannot.be.empty")
|
||||||
@ApiModelProperty("userId")
|
@ApiModelProperty("userId")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
|
|||||||
@@ -10,20 +10,20 @@ import javax.validation.constraints.NotBlank;
|
|||||||
@ApiModel("预先登入")
|
@ApiModel("预先登入")
|
||||||
public class AccountPreLoginDTO {
|
public class AccountPreLoginDTO {
|
||||||
|
|
||||||
@NotBlank(message = "userName cannot be empty!")
|
@NotBlank(message = "userName.cannot.be.empty")
|
||||||
@ApiModelProperty("用户名")
|
@ApiModelProperty("用户名")
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
/*新增字段*/
|
/*新增字段*/
|
||||||
@NotBlank(message = "Please input email !")
|
@NotBlank(message = "email.cannot.be.empty")
|
||||||
@ApiModelProperty("邮箱")
|
@ApiModelProperty("邮箱")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank(message = "password cannot be empty!")
|
@NotBlank(message = "password.cannot.be.empty")
|
||||||
@ApiModelProperty("密码")
|
@ApiModelProperty("密码")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank(message = "operationType cannot be empty")
|
@NotBlank(message = "operationType.cannot.be.empty")
|
||||||
@ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱")
|
@ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱")
|
||||||
private String operationType;
|
private String operationType;
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ import javax.validation.constraints.NotBlank;
|
|||||||
@ApiModel("账户")
|
@ApiModel("账户")
|
||||||
public class AccountRegisterDTO {
|
public class AccountRegisterDTO {
|
||||||
|
|
||||||
@NotBlank(message = "Please input email !")
|
@NotBlank(message = "email.cannot.be.empty")
|
||||||
@ApiModelProperty("邮箱")
|
@ApiModelProperty("邮箱")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank(message = "Please input password !")
|
@NotBlank(message = "password.cannot.be.empty")
|
||||||
@ApiModelProperty("密码")
|
@ApiModelProperty("密码")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank(message = "Please input the email verification code !")
|
@NotBlank(message = "emailVerifyCode.cannot.be.empty")
|
||||||
@ApiModelProperty("邮箱验证码")
|
@ApiModelProperty("邮箱验证码")
|
||||||
private String emailVerifyCode;
|
private String emailVerifyCode;
|
||||||
|
|
||||||
|
|||||||
@@ -20,41 +20,49 @@ public class DesignCollectionDTO {
|
|||||||
@ApiModelProperty("印花板图片 数组")
|
@ApiModelProperty("印花板图片 数组")
|
||||||
private List<DesignCollectionPrintElementDTO> printBoards;
|
private List<DesignCollectionPrintElementDTO> printBoards;
|
||||||
|
|
||||||
@NotEmpty(message = "colorBoardRgbValues cannot be empty!")
|
@NotEmpty(message = "colorBoards.cannot.be.empty")
|
||||||
@ApiModelProperty("颜色板RGB值 数组")
|
@ApiModelProperty("颜色板RGB值 数组")
|
||||||
private List<CollectionColorDTO> colorBoards;
|
private List<CollectionColorDTO> colorBoards;
|
||||||
|
|
||||||
@ApiModelProperty("手稿板图片id 数组")
|
@ApiModelProperty("手稿板图片id 数组")
|
||||||
private List<CollectionSketchDTO> sketchBoards;
|
private List<CollectionSketchDTO> sketchBoards;
|
||||||
|
|
||||||
@ApiModelProperty("市场手稿板图片id 数组")
|
// 2023.10版本去除该入参
|
||||||
private List<DesignCollectionElementDTO> marketingSketchs;
|
// @ApiModelProperty("市场手稿板图片id 数组")
|
||||||
|
// private List<DesignCollectionElementDTO> marketingSketchs;
|
||||||
|
|
||||||
@NotNull(message = "systemScale cannot be empty!")
|
@NotNull(message = "systemScale.cannot.be.empty")
|
||||||
@ApiModelProperty("系统取图比列")
|
@ApiModelProperty("系统取图比列")
|
||||||
private BigDecimal systemScale;
|
private BigDecimal systemScale;
|
||||||
|
|
||||||
|
@NotBlank(message = "modelType.cannot.be.empty")
|
||||||
|
@ApiModelProperty("模特类型:System,Library")
|
||||||
private String modelType;
|
private String modelType;
|
||||||
|
|
||||||
|
@NotBlank(message = "modelSex.cannot.be.empty")
|
||||||
|
@ApiModelProperty("模特性别")
|
||||||
private String modelSex;
|
private String modelSex;
|
||||||
|
|
||||||
@ApiModelProperty("templateId")
|
@NotNull(message = "templateId.cannot.be.empty")
|
||||||
|
@ApiModelProperty("模特ID")
|
||||||
private Long templateId;
|
private Long templateId;
|
||||||
|
|
||||||
@ApiModelProperty("mood版本id 没有传null")
|
@ApiModelProperty("mood版本id 没有传null")
|
||||||
private String moodTemplateId;
|
private String moodTemplateId;
|
||||||
|
|
||||||
@NotBlank(message = "singleOverall cannot be empty!")
|
@NotBlank(message = "singleOverall.cannot.be.empty")
|
||||||
@ApiModelProperty("控制生成类型的参数,两个选项:outfit时候传 single , 另外一个传 overall")
|
@ApiModelProperty("控制生成类型的参数,两个选项:outfit时候传 single , 另外一个传 overall")
|
||||||
private String singleOverall;
|
private String singleOverall;
|
||||||
|
|
||||||
@ApiModelProperty("single模式下的类别选择参数 选项有outwear,dress,blouse,skirt,trousers")
|
@ApiModelProperty("single模式下的类别选择参数 选项有outwear,dress,blouse,skirt,trousers")
|
||||||
private String switchCategory;
|
private String switchCategory;
|
||||||
|
|
||||||
@NotBlank(message = "timeZone cannot be empty!")
|
@NotBlank(message = "timeZone.cannot.be.empty")
|
||||||
@ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
|
@ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
|
||||||
private String timeZone;
|
private String timeZone;
|
||||||
|
|
||||||
|
@NotBlank(message = "processId.cannot.be.empty")
|
||||||
|
@ApiModelProperty("python端design进程ID")
|
||||||
private String processId;
|
private String processId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import javax.validation.constraints.NotBlank;
|
|||||||
@ApiModel("邮箱发送")
|
@ApiModel("邮箱发送")
|
||||||
public class EmailSendDTO {
|
public class EmailSendDTO {
|
||||||
|
|
||||||
@NotBlank(message = "Please input email!")
|
@NotBlank(message = "email.cannot.be.empty")
|
||||||
@ApiModelProperty("邮箱")
|
@ApiModelProperty("邮箱")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank(message = "operationType cannot be empty")
|
@NotBlank(message = "operationType.cannot.be.empty")
|
||||||
@ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱")
|
@ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱")
|
||||||
private String operationType;
|
private String operationType;
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,16 @@ public class AuthPrincipalVo implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语言
|
||||||
|
*/
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 城市
|
||||||
|
*/
|
||||||
|
private String country;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色
|
* 角色
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.ai.da.service.PythonTAllInfoService;
|
|||||||
import com.ai.da.service.SysFileService;
|
import com.ai.da.service.SysFileService;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONException;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -1581,29 +1582,34 @@ public class PythonService {
|
|||||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.build();
|
.build();
|
||||||
Response response = null;
|
Response response;
|
||||||
String bodyStr = null;
|
String bodyStr;
|
||||||
try {
|
try {
|
||||||
log.info("generateAttributeRetrieval请求入参content###{}", JSON.toJSONString(content));
|
log.info("generateAttributeRetrieval请求入参content###{}", JSON.toJSONString(content));
|
||||||
response = client.newCall(request).execute();
|
response = client.newCall(request).execute();
|
||||||
bodyStr = response.body().string();
|
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
|
AccessLimitUtils.validateOut("generateAttributeRetrieval");
|
||||||
log.error("generateAttributeRetrieval异常###{}", ExceptionUtil.getThrowableList(ioException));
|
log.error("generateAttributeRetrieval异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||||
|
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||||
}
|
}
|
||||||
//去除限流
|
//去除限流
|
||||||
AccessLimitUtils.validateOut("generateAttributeRetrieval");
|
AccessLimitUtils.validateOut("generateAttributeRetrieval");
|
||||||
if (Objects.isNull(response)) {
|
if (response.isSuccessful()) {
|
||||||
log.error("generateAttributeRetrieval异常###{}", "response or body is empty!");
|
try {
|
||||||
throw new BusinessException("system error!");
|
if (Objects.nonNull(response.body())) {
|
||||||
}
|
bodyStr = response.body().string();
|
||||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
|
||||||
Boolean result = jsonObject.getBoolean("successful");
|
|
||||||
if (result) {
|
|
||||||
return resolveDesignAttributeRetrievalDTO(bodyStr);
|
return resolveDesignAttributeRetrievalDTO(bodyStr);
|
||||||
}
|
}
|
||||||
log.info("attribute_retrieval失败###{}", bodyStr);
|
|
||||||
//生成失败
|
//生成失败
|
||||||
throw new BusinessException("system error!");
|
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||||
|
} catch (JSONException | IOException e) {
|
||||||
|
log.error("generateAttributeRetrieval异常###{}", e.getMessage());
|
||||||
|
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.error("generateAttributeRetrieval异常###{}", response);
|
||||||
|
//生成失败
|
||||||
|
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DesignAttributeRetrievalDTO resolveDesignAttributeRetrievalDTO(String bodyStr) {
|
private static DesignAttributeRetrievalDTO resolveDesignAttributeRetrievalDTO(String bodyStr) {
|
||||||
@@ -1612,20 +1618,20 @@ public class PythonService {
|
|||||||
JSONObject data = jsonObject.getJSONObject("data");
|
JSONObject data = jsonObject.getJSONObject("data");
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
JSONObject jsonObjectSys = data.getJSONObject("sys_lib_dict");
|
JSONObject jsonObjectSys = data.getJSONObject("sys_lib_dict");
|
||||||
if (null == jsonObjectSys || jsonObjectSys.size() == 0) {
|
if (null == jsonObjectSys || jsonObjectSys.isEmpty()) {
|
||||||
log.error("generateAttributeRetrieval异常###{}", "jsonObjectSys is empty!");
|
log.error("generateAttributeRetrieval异常###{}", "jsonObjectSys is empty!");
|
||||||
throw new BusinessException("system error!");
|
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||||
}
|
}
|
||||||
setUrls(jsonObjectSys, response.getSysFileUrlS());
|
setUrls(jsonObjectSys, response.getSysFileUrlS());
|
||||||
JSONObject jsonObjectLibrary = data.getJSONObject("user_lib_dict");
|
JSONObject jsonObjectLibrary = data.getJSONObject("user_lib_dict");
|
||||||
if (null == jsonObjectLibrary || jsonObjectLibrary.size() == 0) {
|
if (null == jsonObjectLibrary || jsonObjectLibrary.isEmpty()) {
|
||||||
log.error("generateAttributeRetrieval异常###{}", "jsonObjectLibrary is empty!");
|
log.error("generateAttributeRetrieval异常###{}", "jsonObjectLibrary is empty!");
|
||||||
throw new BusinessException("system error!");
|
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||||
}
|
}
|
||||||
setUrls(jsonObjectLibrary, response.getLibraryUrls());
|
setUrls(jsonObjectLibrary, response.getLibraryUrls());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
throw new BusinessException("AttributeRetrieval response data is null");
|
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setUrls(JSONObject jsonObjectSys, List<String> urls) {
|
private static void setUrls(JSONObject jsonObjectSys, List<String> urls) {
|
||||||
@@ -1918,7 +1924,7 @@ public class PythonService {
|
|||||||
|
|
||||||
public JSONObject designNew(DesignPythonObjects designPythonObjects) {
|
public JSONObject designNew(DesignPythonObjects designPythonObjects) {
|
||||||
// todo 限流校验
|
// todo 限流校验
|
||||||
// AccessLimitUtils.validate("design",5);
|
AccessLimitUtils.validate("design",5);
|
||||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||||
.connectTimeout(30, TimeUnit.SECONDS)
|
.connectTimeout(30, TimeUnit.SECONDS)
|
||||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||||
@@ -1937,39 +1943,34 @@ public class PythonService {
|
|||||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.build();
|
.build();
|
||||||
Response response = null;
|
Response response;
|
||||||
|
String responseBody;
|
||||||
try {
|
try {
|
||||||
response = client.newCall(request).execute();
|
response = client.newCall(request).execute();
|
||||||
// log.info("PythonService##response###{}", response);
|
|
||||||
// log.info("PythonService##responseBodyStr###{}", response.body().string());
|
|
||||||
// log.info("PythonService##responseBodyJson###{}", JSON.toJSONString(response.body()));
|
|
||||||
String responseBody = response.body().string();
|
|
||||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
|
||||||
return responseObject;
|
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
|
AccessLimitUtils.validateOut("design");
|
||||||
log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException));
|
log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||||
|
throw new BusinessException("design.interface.exception");
|
||||||
}
|
}
|
||||||
//去除限流
|
//去除限流
|
||||||
// AccessLimitUtils.validateOut("design");
|
AccessLimitUtils.validateOut("design");
|
||||||
if (Objects.isNull(response)) {
|
|
||||||
log.error("PythonService##design异常###{}", "response or body is empty!");
|
|
||||||
throw new BusinessException("system error!");
|
|
||||||
}
|
|
||||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
|
||||||
log.info("PythonService##jsonObject###{}", jsonObject);
|
|
||||||
Boolean result = jsonObject.getBoolean("successful");
|
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
try {
|
try {
|
||||||
String responseBody = response.body().string();
|
if (Objects.nonNull(response.body())) {
|
||||||
|
responseBody = response.body().string();
|
||||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||||
|
log.info("PythonService##responseObject###{}", responseObject);
|
||||||
return responseObject;
|
return responseObject;
|
||||||
} catch (IOException e) {
|
}
|
||||||
throw new RuntimeException(e);
|
throw new BusinessException("design.interface.exception");
|
||||||
|
} catch (IOException | JSONException e) {
|
||||||
|
log.error("PythonService##design异常###{}", e.getMessage());
|
||||||
|
throw new BusinessException("design.interface.exception");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("PythonService##design异常jsonObject###{}", jsonObject);
|
log.error("PythonService##design异常response###{}", response);
|
||||||
//生成失败
|
//生成失败
|
||||||
throw new BusinessException("generate design exception!");
|
throw new BusinessException("design.interface.exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -74,9 +74,15 @@ public class DesignPythonItem {
|
|||||||
public static List<String> OUTWEAR_DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.OUTWEAR.getRealName(),
|
public static List<String> OUTWEAR_DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.OUTWEAR.getRealName(),
|
||||||
CollectionLevel2TypeEnum.DRESS.getRealName(), CollectionLevel2TypeEnum.BLOUSE.getRealName());
|
CollectionLevel2TypeEnum.DRESS.getRealName(), CollectionLevel2TypeEnum.BLOUSE.getRealName());
|
||||||
|
|
||||||
|
public static List<String> DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.DRESS.getRealName(),
|
||||||
|
CollectionLevel2TypeEnum.BLOUSE.getRealName());
|
||||||
|
|
||||||
public static List<String> SKIRT_TROUSERS = Arrays.asList(
|
public static List<String> SKIRT_TROUSERS = Arrays.asList(
|
||||||
CollectionLevel2TypeEnum.SKIRT.getRealName(), CollectionLevel2TypeEnum.TROUSERS.getRealName());
|
CollectionLevel2TypeEnum.SKIRT.getRealName(), CollectionLevel2TypeEnum.TROUSERS.getRealName());
|
||||||
|
|
||||||
|
public static List<String> OUTERWEAR = Arrays.asList(
|
||||||
|
"OuterWear");
|
||||||
|
|
||||||
public static List<String> TOPS = Arrays.asList(
|
public static List<String> TOPS = Arrays.asList(
|
||||||
"Tops");
|
"Tops");
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -28,6 +29,7 @@ public class AccountLoginLogServiceImpl extends ServiceImpl<AccountLoginLogMappe
|
|||||||
AccountLoginLogMapper accountLoginLogMapper;
|
AccountLoginLogMapper accountLoginLogMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Boolean saveLoginLog(String ip, Long accountId) {
|
public Boolean saveLoginLog(String ip, Long accountId) {
|
||||||
AccountLoginLog accountLoginLog = new AccountLoginLog();
|
AccountLoginLog accountLoginLog = new AccountLoginLog();
|
||||||
accountLoginLog.setAccountId(accountId);
|
accountLoginLog.setAccountId(accountId);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.ai.da.service.impl;
|
|||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.ai.da.common.config.exception.BusinessException;
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
import com.ai.da.common.enums.LoginTypeEnum;
|
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.security.jwt.JWTTokenHelper;
|
||||||
import com.ai.da.common.utils.*;
|
import com.ai.da.common.utils.*;
|
||||||
import com.ai.da.mapper.AccountMapper;
|
import com.ai.da.mapper.AccountMapper;
|
||||||
@@ -51,41 +51,44 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
||||||
log.info("aida预先登入accountDTO###{}", JSON.toJSONString(accountDTO));
|
log.info("aida预先登入accountDTO###{}", JSON.toJSONString(accountDTO));
|
||||||
Account account = getOneByUserName(accountDTO.getUserName());
|
Account account = getOneByUserName(accountDTO.getUserName());
|
||||||
Assert.isTrue(Objects.nonNull(account), "User does not exist!");
|
|
||||||
//用户有效期校验
|
//用户有效期校验
|
||||||
validateUserValidaExpire(account);
|
validateUserValidaExpire(account);
|
||||||
if ("Third-000000".equals(account.getUserPassword())) {
|
if ("Third-000000".equals(account.getUserPassword())) {
|
||||||
account.setUserPassword(accountDTO.getPassword());
|
account.setUserPassword(accountDTO.getPassword());
|
||||||
accountMapper.updateById(account);
|
accountMapper.updateById(account);
|
||||||
} else {
|
} 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(account.getUserEmail());
|
||||||
log.info(accountDTO.getEmail());
|
log.info(accountDTO.getEmail());
|
||||||
Assert.isTrue(account.getUserEmail().equals(accountDTO.getEmail()), "Email error !");
|
if (!account.getUserEmail().equals(accountDTO.getEmail())) {
|
||||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
throw new BusinessException("email.error");
|
||||||
|
}
|
||||||
|
if (Objects.isNull(authenticationOperationTypeEnum)) {
|
||||||
|
throw new BusinessException("unknown.authentication.operation.type");
|
||||||
|
}
|
||||||
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
|
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
|
||||||
LocalCacheUtils.setVerifyCodeCache(
|
LocalCacheUtils.setVerifyCodeCache(
|
||||||
accountDTO.getOperationType() + "_" + accountDTO.getEmail(), randomVerifyCode);
|
accountDTO.getOperationType() + "_" + accountDTO.getEmail(), randomVerifyCode);
|
||||||
Boolean result = Boolean.FALSE;
|
Boolean result = Boolean.FALSE;
|
||||||
switch (operationTypeEnum) {
|
switch (authenticationOperationTypeEnum) {
|
||||||
case LOGIN:
|
case LOGIN:
|
||||||
Assert.notNull(accountDTO, "Email not registered!");
|
|
||||||
result = SendEmailUtil.send(accountDTO.getEmail(), null,
|
result = SendEmailUtil.send(accountDTO.getEmail(), null,
|
||||||
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
case FORGET_PWD:
|
case FORGET_PWD:
|
||||||
Assert.notNull(accountDTO, "Email not registered!");
|
|
||||||
result = SendEmailUtil.send(accountDTO.getEmail(), null,
|
result = SendEmailUtil.send(accountDTO.getEmail(), null,
|
||||||
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
case EXCEPTION_IP:
|
case EXCEPTION_IP:
|
||||||
Assert.notNull(accountDTO, "Email not registered!");
|
|
||||||
result = SendEmailUtil.send(accountDTO.getEmail(), accountDTO.getIp(),
|
result = SendEmailUtil.send(accountDTO.getEmail(), accountDTO.getIp(),
|
||||||
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
@@ -94,22 +97,26 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
default:
|
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());
|
return new AccountPreLoginVO(account.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request) {
|
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));
|
log.info("aida确认登入###accountLoginDTO###{}", JSON.toJSONString(accountLoginDTO));
|
||||||
Account accountExist = getOneByEmail(accountLoginDTO.getEmail().trim());
|
Account accountExist = getOneByEmail(accountLoginDTO.getEmail().trim());
|
||||||
Assert.notNull(accountExist, "User does not exist!");
|
|
||||||
|
|
||||||
LoginTypeEnum accountType = LoginTypeEnum.of(accountLoginDTO.getLoginType());
|
LoginTypeEnum accountType = LoginTypeEnum.of(accountLoginDTO.getLoginType());
|
||||||
if (Objects.isNull(accountType) || accountType.equals(LoginTypeEnum.PASSWORD)) {
|
if (Objects.isNull(accountType)) {
|
||||||
throw new BusinessException("Unknown login type!");
|
throw new BusinessException("unknown.login.type");
|
||||||
|
}
|
||||||
|
if (!accountType.equals(LoginTypeEnum.EMAIL)) {
|
||||||
|
throw new BusinessException("error.login.type");
|
||||||
}
|
}
|
||||||
//用户有效期校验
|
//用户有效期校验
|
||||||
validateUserValidaExpire(accountExist);
|
validateUserValidaExpire(accountExist);
|
||||||
@@ -117,25 +124,23 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
Account account = null;
|
Account account = null;
|
||||||
switch (accountType) {
|
switch (accountType) {
|
||||||
case PASSWORD:
|
case PASSWORD:
|
||||||
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getPassword()), "Please input a password !");
|
// Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getPassword()), "Please input a password !");
|
||||||
account = getOneByUserName(accountLoginDTO.getUserName());
|
// account = getOneByUserName(accountLoginDTO.getUserName());
|
||||||
Assert.isTrue(Objects.nonNull(account), "User does not exist!");
|
// Assert.isTrue(Objects.nonNull(account), "User does not exist!");
|
||||||
Assert.isTrue(account.getUserPassword().equals(accountLoginDTO.getPassword()), "Password error !");
|
// Assert.isTrue(account.getUserPassword().equals(accountLoginDTO.getPassword()), "Password error !");
|
||||||
// Assert.isTrue(StringUtils.isBlank(
|
// 走不到这边
|
||||||
// LocalCacheUtils.getTokenCache(String.valueOf(account.getId()))),"该用户已登入");
|
|
||||||
break;
|
break;
|
||||||
case EMAIL:
|
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());
|
account = getOneByEmail(accountLoginDTO.getEmail().trim());
|
||||||
if (Objects.isNull(account)) {
|
|
||||||
throw new BusinessException("Email not registered!");
|
|
||||||
}
|
|
||||||
//校验邮箱验证码
|
//校验邮箱验证码
|
||||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.LOGIN.name() + "_" + accountLoginDTO.getEmail());
|
String verifyCode = LocalCacheUtils.getVerifyCodeCache(AuthenticationOperationTypeEnum.LOGIN.name() + "_" + accountLoginDTO.getEmail());
|
||||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired!");
|
if (StringUtils.isBlank(verifyCode)) {
|
||||||
|
throw new BusinessException("the.verification.code.has.expired");
|
||||||
|
}
|
||||||
if (!"921314".equals(accountLoginDTO.getEmailVerifyCode())) {
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -147,7 +152,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
//用户已登入
|
//用户已登入
|
||||||
response.setToken(token);
|
response.setToken(token);
|
||||||
} else {
|
} else {
|
||||||
response.setToken(createAccountToken(account.getId(), account.getUserName()));
|
response.setToken(createAccountToken(account));
|
||||||
}
|
}
|
||||||
response.setUserId(account.getId());
|
response.setUserId(account.getId());
|
||||||
//判断是否常用ip 不是则发邮件提示
|
//判断是否常用ip 不是则发邮件提示
|
||||||
@@ -158,10 +163,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
private void validateUserValidaExpire(Account account) {
|
private void validateUserValidaExpire(Account account) {
|
||||||
Long currentTime = new Date().getTime();
|
Long currentTime = new Date().getTime();
|
||||||
if (Objects.nonNull(account.getValidStartTime())) {
|
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())) {
|
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,没有出现过
|
//非常用ip,没有出现过
|
||||||
EmailSendDTO emailSendDTO = new EmailSendDTO();
|
EmailSendDTO emailSendDTO = new EmailSendDTO();
|
||||||
emailSendDTO.setEmail(account.getUserEmail());
|
emailSendDTO.setEmail(account.getUserEmail());
|
||||||
emailSendDTO.setOperationType(OperationTypeEnum.EXCEPTION_IP.name());
|
emailSendDTO.setOperationType(AuthenticationOperationTypeEnum.EXCEPTION_IP.name());
|
||||||
emailSendDTO.setIp(ip);
|
emailSendDTO.setIp(ip);
|
||||||
sendEmail(emailSendDTO);
|
sendEmail(emailSendDTO);
|
||||||
}
|
}
|
||||||
@@ -185,28 +194,34 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
accountLoginLogService.saveLoginLog(ip, account.getId());
|
accountLoginLogService.saveLoginLog(ip, account.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createAccountToken(Long userId, String userName) {
|
private String createAccountToken(Account account) {
|
||||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(userId));
|
|
||||||
if (StringUtils.isNotBlank(token)) {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
AuthPrincipalVo principal = new AuthPrincipalVo();
|
AuthPrincipalVo principal = new AuthPrincipalVo();
|
||||||
principal.setId(userId);
|
principal.setId(account.getId());
|
||||||
principal.setUsername(userName);
|
principal.setUsername(account.getUserName());
|
||||||
|
principal.setLanguage(account.getLanguage());
|
||||||
|
principal.setCountry(account.getCountry());
|
||||||
String token2 = jwtTokenHelper.createToken(principal);
|
String token2 = jwtTokenHelper.createToken(principal);
|
||||||
LocalCacheUtils.setTokenCache(String.valueOf(userId), token2);
|
LocalCacheUtils.setTokenCache(String.valueOf(account.getId()), token2);
|
||||||
return token2;
|
return token2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO) {
|
public Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO) {
|
||||||
Account account = getOneByUserId(accountBindEmailDTO.getUserId());
|
Account account = baseMapper.selectById(accountBindEmailDTO.getUserId());
|
||||||
Assert.notNull(account, "User does not exist !");
|
if (Objects.isNull(account)) {
|
||||||
Assert.isTrue(StringUtils.isBlank(account.getUserEmail()), "User has bound mailbox !");
|
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());
|
String verifyCode = LocalCacheUtils.getVerifyCodeCache(AuthenticationOperationTypeEnum.BIND_MAILBOX.name() + "_" + accountBindEmailDTO.getUserEmail());
|
||||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired !");
|
if (StringUtils.isBlank(verifyCode)) {
|
||||||
Assert.isTrue(verifyCode.equals(accountBindEmailDTO.getEmailVerifyCode()), "Verification code error !");
|
throw new BusinessException("the.verification.code.has.expired");
|
||||||
|
}
|
||||||
|
if (!verifyCode.equals(accountBindEmailDTO.getEmailVerifyCode())) {
|
||||||
|
throw new BusinessException("verification.code.error");
|
||||||
|
}
|
||||||
//绑定
|
//绑定
|
||||||
updatePwdByUserId(accountBindEmailDTO.getUserEmail(), accountBindEmailDTO.getUserId());
|
updatePwdByUserId(accountBindEmailDTO.getUserEmail(), accountBindEmailDTO.getUserId());
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
@@ -216,44 +231,54 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
@Override
|
@Override
|
||||||
public Boolean forgetPwd(AccountRegisterDTO accountDTO) {
|
public Boolean forgetPwd(AccountRegisterDTO accountDTO) {
|
||||||
Account emailAccount = getOneByEmail(accountDTO.getEmail());
|
Account emailAccount = getOneByEmail(accountDTO.getEmail());
|
||||||
Assert.notNull(emailAccount, "Email not registered!");
|
|
||||||
//校验邮箱验证码
|
//校验邮箱验证码
|
||||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.FORGET_PWD.name() + "_" + accountDTO.getEmail());
|
String verifyCode = LocalCacheUtils.getVerifyCodeCache(AuthenticationOperationTypeEnum.FORGET_PWD.name() + "_" + accountDTO.getEmail());
|
||||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired!");
|
if (StringUtils.isBlank(verifyCode)) {
|
||||||
Assert.isTrue(verifyCode.equals(accountDTO.getEmailVerifyCode()), "Verification code error!");
|
throw new BusinessException("the.verification.code.has.expired");
|
||||||
|
}
|
||||||
|
if (!verifyCode.equals(accountDTO.getEmailVerifyCode())) {
|
||||||
|
throw new BusinessException("verification.code.error");
|
||||||
|
}
|
||||||
updatePwdByEmail(accountDTO.getPassword(), accountDTO.getEmail());
|
updatePwdByEmail(accountDTO.getPassword(), accountDTO.getEmail());
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePwdByEmail(String pwd, String email) {
|
private void updatePwdByEmail(String pwd, String email) {
|
||||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("user_email", email);
|
queryWrapper.lambda().eq(Account::getUserEmail, email);
|
||||||
|
|
||||||
Account accountNew = new Account();
|
Account accountNew = new Account();
|
||||||
accountNew.setUserPassword(pwd);
|
accountNew.setUserPassword(pwd);
|
||||||
accountMapper.update(accountNew, queryWrapper);
|
accountMapper.update(accountNew, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePwdByUserId(String email, Long userId) {
|
private void updatePwdByUserId(String email, Long userId) {
|
||||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("id", userId);
|
|
||||||
|
|
||||||
Account accountNew = new Account();
|
Account accountNew = new Account();
|
||||||
accountNew.setUserEmail(email);
|
accountNew.setUserEmail(email);
|
||||||
accountMapper.update(accountNew, queryWrapper);
|
accountNew.setId(userId);
|
||||||
|
accountMapper.updateById(accountNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Account getOneByEmail(String email) {
|
private Account getOneByEmail(String email) {
|
||||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("user_email", email);
|
queryWrapper.lambda().eq(Account::getUserEmail, email);
|
||||||
return accountMapper.selectOne(queryWrapper);
|
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) {
|
private Account getOneByUserName(String userName) {
|
||||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("user_name", userName);
|
queryWrapper.lambda().eq(Account::getUserName, userName);
|
||||||
return accountMapper.selectOne(queryWrapper);
|
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) {
|
private Account getOneByUserId(Long userId) {
|
||||||
@@ -265,27 +290,25 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean sendEmail(EmailSendDTO emailSendDTO) {
|
public Boolean sendEmail(EmailSendDTO emailSendDTO) {
|
||||||
OperationTypeEnum operationTypeEnum = OperationTypeEnum.of(emailSendDTO.getOperationType());
|
AuthenticationOperationTypeEnum authenticationOperationTypeEnum = AuthenticationOperationTypeEnum.of(emailSendDTO.getOperationType());
|
||||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
if (Objects.isNull(authenticationOperationTypeEnum)) {
|
||||||
|
throw new BusinessException("unknown.authentication.operation.type");
|
||||||
|
}
|
||||||
Account emailAccount = getOneByEmail(emailSendDTO.getEmail());
|
Account emailAccount = getOneByEmail(emailSendDTO.getEmail());
|
||||||
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
|
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
|
||||||
LocalCacheUtils.setVerifyCodeCache(
|
LocalCacheUtils.setVerifyCodeCache(
|
||||||
emailSendDTO.getOperationType() + "_" + emailSendDTO.getEmail(), randomVerifyCode);
|
emailSendDTO.getOperationType() + "_" + emailSendDTO.getEmail(), randomVerifyCode);
|
||||||
Boolean result = Boolean.FALSE;
|
Boolean result = Boolean.FALSE;
|
||||||
switch (operationTypeEnum) {
|
switch (authenticationOperationTypeEnum) {
|
||||||
case LOGIN:
|
case LOGIN:
|
||||||
Assert.notNull(emailAccount, "Email not registered!");
|
|
||||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||||
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
case FORGET_PWD:
|
case FORGET_PWD:
|
||||||
Assert.notNull(emailAccount, "Email not registered!");
|
|
||||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||||
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
case EXCEPTION_IP:
|
case EXCEPTION_IP:
|
||||||
Assert.notNull(emailAccount, "Email not registered!");
|
|
||||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), emailSendDTO.getIp(),
|
result = SendEmailUtil.send(emailSendDTO.getEmail(), emailSendDTO.getIp(),
|
||||||
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
@@ -294,9 +317,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
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.*;
|
||||||
import com.ai.da.mapper.entity.Collection;
|
import com.ai.da.mapper.entity.Collection;
|
||||||
import com.ai.da.model.dto.*;
|
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.ModelType;
|
||||||
|
import com.ai.da.model.enums.Sex;
|
||||||
import com.ai.da.model.vo.*;
|
import com.ai.da.model.vo.*;
|
||||||
import com.ai.da.python.PythonService;
|
import com.ai.da.python.PythonService;
|
||||||
import com.ai.da.python.vo.DesignPythonItem;
|
import com.ai.da.python.vo.DesignPythonItem;
|
||||||
@@ -308,8 +310,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (!CollectionUtils.isEmpty(moodBoardIds)) {
|
if (!CollectionUtils.isEmpty(moodBoardIds)) {
|
||||||
List<CollectionElement> MoodBoardElements = collectionElementMapper.selectBatchIds(moodBoardIds);
|
List<CollectionElement> MoodBoardElements = collectionElementMapper.selectBatchIds(moodBoardIds);
|
||||||
Assert.isTrue(CollectionUtil.isNotEmpty(MoodBoardElements)
|
if (CollectionUtil.isEmpty(MoodBoardElements) || MoodBoardElements.size() != moodBoardIds.size()) {
|
||||||
&& MoodBoardElements.size() == moodBoardIds.size(), "get moodboard data is mismatch");
|
throw new BusinessException("get.moodBoards.data.is.mismatch");
|
||||||
|
}
|
||||||
elementVO.setMoodBoardElements(MoodBoardElements);
|
elementVO.setMoodBoardElements(MoodBoardElements);
|
||||||
usedElementIds.addAll(moodBoardIds);
|
usedElementIds.addAll(moodBoardIds);
|
||||||
}
|
}
|
||||||
@@ -348,7 +351,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
//校验printboard
|
//校验printboard
|
||||||
List<CollectionElement> printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
List<CollectionElement> printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
||||||
Assert.isTrue(CollectionUtil.isNotEmpty(printBoardElements)
|
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);
|
elementVO.setPrintBoardElements(printBoardElements);
|
||||||
usedElementIds.addAll(printBoardIds);
|
usedElementIds.addAll(printBoardIds);
|
||||||
}
|
}
|
||||||
@@ -384,20 +387,36 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
}
|
}
|
||||||
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
|
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
|
||||||
//校验PIN是否满足 上衣或者下衣必须不超过8
|
//校验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
|
.filter(skecth -> skecth.getIsPin() == 1
|
||||||
&& DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
|
&& DesignPythonItem.DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
|
||||||
Assert.isTrue(topNum <= 8, "The number of PIN sketch cannot be greater than 8!");
|
bottomNum = designDTO.getSketchBoards().stream()
|
||||||
long bottomNum = designDTO.getSketchBoards().stream()
|
|
||||||
.filter(skecth -> skecth.getIsPin() == 1
|
.filter(skecth -> skecth.getIsPin() == 1
|
||||||
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
|
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
|
||||||
Assert.isTrue(bottomNum <= 8, "The number of PIN sketch cannot be greater than 8!");
|
}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.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
|
//校验designType
|
||||||
Boolean result = designDTO.getSketchBoards().stream()
|
Boolean result = designDTO.getSketchBoards().stream()
|
||||||
.filter(mood -> StringUtils.isEmpty(mood.getDesignType()))
|
.filter(mood -> StringUtils.isEmpty(mood.getDesignType()))
|
||||||
.findFirst().isPresent();
|
.findFirst().isPresent();
|
||||||
if (result) {
|
if (result) {
|
||||||
throw new BusinessException("sketchBoards designType cannot be empty!");
|
throw new BusinessException("sketchBoards.designType.cannot.be.empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Long> sketchBoardIds = designDTO.getSketchBoards().stream()
|
List<Long> sketchBoardIds = designDTO.getSketchBoards().stream()
|
||||||
@@ -408,7 +427,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
//校验sketchBoard
|
//校验sketchBoard
|
||||||
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
|
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
|
||||||
Assert.isTrue(CollectionUtil.isNotEmpty(sketchBoardElements)
|
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);
|
elementVO.setSketchBoardElements(sketchBoardElements);
|
||||||
usedElementIds.addAll(sketchBoardIds);
|
usedElementIds.addAll(sketchBoardIds);
|
||||||
}
|
}
|
||||||
@@ -473,43 +492,24 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
// }
|
// }
|
||||||
//校验控制生成类型
|
//校验控制生成类型
|
||||||
SingleOverallEnum singleOverall = SingleOverallEnum.of(designDTO.getSingleOverall());
|
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)) {
|
if (SingleOverallEnum.SINGLE.equals(singleOverall)) {
|
||||||
SwitchCategoryEnum switchCategory = SwitchCategoryEnum.of(designDTO.getSwitchCategory());
|
SwitchCategoryEnum switchCategory = SwitchCategoryEnum.of(designDTO.getSwitchCategory());
|
||||||
Assert.notNull(switchCategory, "unknown parameter switchCategory!");
|
if (Objects.isNull(switchCategory)) {
|
||||||
|
throw new BusinessException("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())) {
|
if (designDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
|
||||||
Library byId = libraryService.getById(designDTO.getTemplateId());
|
Library byId = libraryService.getById(designDTO.getTemplateId());
|
||||||
QueryWrapper<LibraryModelPoint> qw = new QueryWrapper<>();
|
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), designDTO.getModelType());
|
||||||
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()));
|
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, byId.getHigh(), byId.getWidth(), byId.getUrl()));
|
||||||
} else if (designDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
|
} else if (designDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
|
||||||
SysFileVO byId = sysFileService.getById(designDTO.getTemplateId());
|
SysFileVO byId = sysFileService.getById(designDTO.getTemplateId());
|
||||||
QueryWrapper<LibraryModelPoint> qw = new QueryWrapper<>();
|
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), designDTO.getModelType());
|
||||||
qw.lambda().eq(LibraryModelPoint::getModelType, ModelType.SYSTEM.getValue());
|
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, 680, 200, byId.getUrl()));
|
||||||
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()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new BusinessException("templateId or modelType can't be null");
|
|
||||||
}
|
|
||||||
if (StringUtils.isEmpty(designDTO.getModelSex())) {
|
|
||||||
throw new BusinessException("modelSex can't be null");
|
|
||||||
}
|
}
|
||||||
elementVO.setModelSex(designDTO.getModelSex());
|
elementVO.setModelSex(designDTO.getModelSex());
|
||||||
return elementVO;
|
return elementVO;
|
||||||
@@ -597,7 +597,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
private void validateDesignType(List<DesignCollectionElementDTO> collectionElements, String msg) {
|
private void validateDesignType(List<DesignCollectionElementDTO> collectionElements, String msg) {
|
||||||
Boolean result = collectionElements.stream().filter(mood -> StringUtils.isEmpty(mood.getDesignType())).findFirst().isPresent();
|
Boolean result = collectionElements.stream().filter(mood -> StringUtils.isEmpty(mood.getDesignType())).findFirst().isPresent();
|
||||||
if (result) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.in("id", elementIds);
|
queryWrapper.lambda().in(CollectionElement::getId, elementIds);
|
||||||
CollectionElement element = new CollectionElement();
|
CollectionElement element = new CollectionElement();
|
||||||
element.setCollectionId(collectionId);
|
element.setCollectionId(collectionId);
|
||||||
//批量关联
|
//批量关联
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@@ -97,7 +98,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
@Value("${minio.bucketName.results}")
|
@Value("${minio.bucketName.results}")
|
||||||
private String bucketName;
|
private String bucketName;
|
||||||
|
|
||||||
// @Transactional
|
|
||||||
@Override
|
@Override
|
||||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||||
@@ -156,7 +156,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
element.setHasPin((byte) 0);
|
element.setHasPin((byte) 0);
|
||||||
}
|
}
|
||||||
element.setId(null);
|
element.setId(null);
|
||||||
// element.setType(DesignTypeEnum.LIBRARY.getRealName());
|
|
||||||
});
|
});
|
||||||
List<CollectionElement> saveElements = elementVO.getLibraryCollectionElements();
|
List<CollectionElement> saveElements = elementVO.getLibraryCollectionElements();
|
||||||
collectionElementService.saveBatch(saveElements);
|
collectionElementService.saveBatch(saveElements);
|
||||||
@@ -299,8 +298,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
//组装design入参
|
//组装design入参
|
||||||
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
|
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
|
||||||
designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId());
|
designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId());
|
||||||
//缓存保存的文件 方便后面处理进度问题 采用新的进度条获取方式 根据processId获取
|
|
||||||
// setDesignProcess(userInfo.getId(), pythonObjects);
|
|
||||||
// pythonObjects增加image_id关联
|
// pythonObjects增加image_id关联
|
||||||
relationImageId(pythonObjects);
|
relationImageId(pythonObjects);
|
||||||
//design
|
//design
|
||||||
@@ -308,13 +305,11 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
//生成library
|
//生成library
|
||||||
generateLibrary(elementVO, designDTO.getTimeZone());
|
generateLibrary(elementVO, designDTO.getTimeZone());
|
||||||
//处理关联关系,修复element覆盖得情况
|
//处理关联关系,修复element覆盖得情况
|
||||||
List<CollectionElement> reLationelements = collectionElementService.getByOnlyCollectionId(collectionId);
|
List<CollectionElement> relationElements = collectionElementService.getByOnlyCollectionId(collectionId);
|
||||||
List<Long> reLationelementIds = reLationelements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
List<Long> relationElementIds = relationElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||||
handleCollectionElementRelation(collectionId, (null == collectionIdParam) ? false : true, reLationelementIds);
|
handleCollectionElementRelation(collectionId, null != collectionIdParam, relationElementIds);
|
||||||
//保存python返回信息
|
//保存python返回信息;保存designItem和detail
|
||||||
return savePythonDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone(), responseJSONObject, designDTO.getSingleOverall());
|
return savePythonDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone(), responseJSONObject, designDTO.getSingleOverall());
|
||||||
//保存designItem 和detail
|
|
||||||
// return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ai.da.service.impl;
|
package com.ai.da.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.ai.da.common.config.exception.BusinessException;
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
@@ -137,10 +138,14 @@ public class LibraryModelPointServiceImpl extends ServiceImpl<LibraryModelPointM
|
|||||||
@Override
|
@Override
|
||||||
public LibraryModelPoint getByRelationId(Long relationId, String modelType) {
|
public LibraryModelPoint getByRelationId(Long relationId, String modelType) {
|
||||||
QueryWrapper<LibraryModelPoint> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<LibraryModelPoint> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("relation_id", relationId)
|
queryWrapper.lambda().eq(LibraryModelPoint::getRelationId, relationId);
|
||||||
.eq("model_type", modelType);
|
queryWrapper.lambda().eq(LibraryModelPoint::getModelType, modelType);
|
||||||
|
queryWrapper.lambda().last("limit 1");
|
||||||
return baseMapper.selectOne(queryWrapper);
|
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
|
private List<PantoneVO> coverPanToneToVoList(List<PanTone> panTones
|
||||||
, Map<Integer, Integer> indexToValue, Map<Integer, GetRgbByHsvBatchDTO> valueToHsv,
|
, Map<Integer, Integer> indexToValue, Map<Integer, GetRgbByHsvBatchDTO> valueToHsv,
|
||||||
List<GetRgbByHsvBatchDTO> hsvBatch) {
|
List<GetRgbByHsvBatchDTO> hsvBatch) {
|
||||||
if (Objects.isNull(panTones)) {
|
if (CollectionUtil.isEmpty(panTones)) {
|
||||||
throw new BusinessException("Pantone value does not exist !");
|
throw new BusinessException("Pantone value does not exist !");
|
||||||
}
|
}
|
||||||
List<PantoneVO> templateResposne = CopyUtil.copyList(panTones, PantoneVO.class, (o, d) -> {
|
List<PantoneVO> templateResposne = CopyUtil.copyList(panTones, PantoneVO.class, (o, d) -> {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ server.port=5567
|
|||||||
|
|
||||||
#datasource
|
#datasource
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.datasource.url=jdbc:mysql://18.167.251.121:33006/aida?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
spring.datasource.url=jdbc:mysql://18.167.251.121:33008/aida?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||||
spring.datasource.username=root
|
spring.datasource.username=aida_con
|
||||||
spring.datasource.password=root
|
spring.datasource.password=123456
|
||||||
|
|
||||||
#???
|
#???
|
||||||
spring.datasource.hikari.minimum-idle=5
|
spring.datasource.hikari.minimum-idle=5
|
||||||
|
|||||||
27
src/main/resources/messages_en.properties
Normal file
27
src/main/resources/messages_en.properties
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# 业务逻辑
|
||||||
|
system.error=System error!
|
||||||
|
userName.does.not.exist=UserName does not exist!
|
||||||
|
user.expired=User expired!
|
||||||
|
password.error=Password error!
|
||||||
|
email.error=Email error!
|
||||||
|
unknown.authentication.operation.type=Unknown authentication operation type!
|
||||||
|
failed.to.send.mail=Failed to send mail!
|
||||||
|
email.does.not.exist=Email does not exist!
|
||||||
|
unknown.login.type=Unknown login type!
|
||||||
|
error.login.type=Error login type!
|
||||||
|
the.verification.code.has.expired=The verification code has expired!
|
||||||
|
verification.code.error=Verification code error!
|
||||||
|
user.has.bound.mailbox=User has bound mailbox!
|
||||||
|
|
||||||
|
# 前端传参校验
|
||||||
|
singleOverall.cannot.be.empty=SingleOverall cannot be empty!
|
||||||
|
colorBoards.cannot.be.empty=ColorBoards cannot be empty!
|
||||||
|
systemScale.cannot.be.empty=SystemScale cannot be empty!
|
||||||
|
modelType.cannot.be.empty=ModelType cannot be empty!
|
||||||
|
modelSex.cannot.be.empty=ModelSex cannot be empty!
|
||||||
|
templateId.cannot.be.empty=TemplateId cannot be empty!
|
||||||
|
processId.cannot.be.empty=ProcessId cannot be empty!
|
||||||
|
timeZone.cannot.be.empty=TimeZone cannot be empty!
|
||||||
|
userId.cannot.be.empty=UserId cannot be empty!
|
||||||
|
email.cannot.be.empty=Email cannot be empty!
|
||||||
|
operationType.cannot.be.empty=OperationType cannot be empty!
|
||||||
1
src/main/resources/messages_zh.properties
Normal file
1
src/main/resources/messages_zh.properties
Normal file
@@ -0,0 +1 @@
|
|||||||
|
system.error=系统错误!
|
||||||
Reference in New Issue
Block a user