diff --git a/src/main/java/com/ai/da/common/config/exception/BusinessException.java b/src/main/java/com/ai/da/common/config/exception/BusinessException.java index 8359b0f2..c2b2488a 100644 --- a/src/main/java/com/ai/da/common/config/exception/BusinessException.java +++ b/src/main/java/com/ai/da/common/config/exception/BusinessException.java @@ -1,8 +1,18 @@ 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.model.vo.AuthPrincipalVo; 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 * @description: 业务异常 @@ -15,14 +25,44 @@ public class BusinessException extends RuntimeException { private String msg; public BusinessException(ResultEnum resultEnum) { - super(resultEnum.getMsg()); this.code = resultEnum.getCode(); - this.msg = resultEnum.getMsg(); + this.msg = getMessageFromResource(resultEnum.getMsg(), getUserLocale()); } public BusinessException(String msg) { - super(msg); 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; // 如果找不到对应的资源文件,返回原始的消息 + } +} \ No newline at end of file diff --git a/src/main/java/com/ai/da/common/config/exception/ExceptionCatch.java b/src/main/java/com/ai/da/common/config/exception/ExceptionCatch.java index 2f3407e8..6ccb952a 100644 --- a/src/main/java/com/ai/da/common/config/exception/ExceptionCatch.java +++ b/src/main/java/com/ai/da/common/config/exception/ExceptionCatch.java @@ -64,7 +64,8 @@ public class ExceptionCatch { @ExceptionHandler(BindException.class) public Response bindExceptionHandler(BindException e) { 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 @ExceptionHandler(MethodArgumentNotValidException.class) - public Response methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) { + public Response handleValidationException(MethodArgumentNotValidException e) { 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()); } //初始化,不可预知异常自定义错误编码 diff --git a/src/main/java/com/ai/da/common/enums/OperationTypeEnum.java b/src/main/java/com/ai/da/common/enums/AuthenticationOperationTypeEnum.java similarity index 61% rename from src/main/java/com/ai/da/common/enums/OperationTypeEnum.java rename to src/main/java/com/ai/da/common/enums/AuthenticationOperationTypeEnum.java index 9278bd48..e8ea46d1 100644 --- a/src/main/java/com/ai/da/common/enums/OperationTypeEnum.java +++ b/src/main/java/com/ai/da/common/enums/AuthenticationOperationTypeEnum.java @@ -1,31 +1,31 @@ -package com.ai.da.common.enums; - -import java.util.stream.Stream; - -/** - * @author: yanglei - * @description: 操作类型 登入 忘记密码 - * @create: 2022-8-10 17:33 - **/ -public enum OperationTypeEnum { - /** - * 登入 - */ - LOGIN, - /** - * 异常ip - */ - EXCEPTION_IP, - /** - * 绑定邮箱 - */ - BIND_MAILBOX, - /** - * 忘记密码 - */ - FORGET_PWD; - - public static OperationTypeEnum of(String name) { - return Stream.of(OperationTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null); - } -} +package com.ai.da.common.enums; + +import java.util.stream.Stream; + +/** + * @author: yanglei + * @description: 操作类型 登入 忘记密码 + * @create: 2022-8-10 17:33 + **/ +public enum AuthenticationOperationTypeEnum { + /** + * 登入 + */ + LOGIN, + /** + * 异常ip + */ + EXCEPTION_IP, + /** + * 绑定邮箱 + */ + BIND_MAILBOX, + /** + * 忘记密码 + */ + FORGET_PWD; + + public static AuthenticationOperationTypeEnum of(String name) { + return Stream.of(AuthenticationOperationTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null); + } +} diff --git a/src/main/java/com/ai/da/common/enums/SwitchCategoryEnum.java b/src/main/java/com/ai/da/common/enums/SwitchCategoryEnum.java index 367592a2..25d67a56 100644 --- a/src/main/java/com/ai/da/common/enums/SwitchCategoryEnum.java +++ b/src/main/java/com/ai/da/common/enums/SwitchCategoryEnum.java @@ -28,6 +28,8 @@ public enum SwitchCategoryEnum { * 裤子 */ TROUSERS("Trousers"), + TOPS("Tops"), + BOTTOMS("Bottoms"), ; private String realName; diff --git a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java index 0b0077e2..f2f30238 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -11,6 +11,7 @@ import com.tencentcloudapi.ses.v20201002.models.SendEmailRequest; import com.tencentcloudapi.ses.v20201002.models.SendEmailResponse; import com.tencentcloudapi.ses.v20201002.models.Template; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.Assert; import java.util.Date; @@ -96,7 +97,7 @@ public class SendEmailUtil { return Boolean.TRUE; } catch (TencentCloudSDKException e) { log.info("邮件发送失败###{}", e.toString()); - throw new BusinessException(e.getMessage()); + throw new BusinessException("failed.to.send.mail"); } } diff --git a/src/main/java/com/ai/da/controller/DesignController.java b/src/main/java/com/ai/da/controller/DesignController.java index 993d50a8..38ee07ff 100644 --- a/src/main/java/com/ai/da/controller/DesignController.java +++ b/src/main/java/com/ai/da/controller/DesignController.java @@ -1,15 +1,16 @@ package com.ai.da.controller; +import com.ai.da.common.config.exception.BusinessException; import com.ai.da.common.response.Response; import com.ai.da.model.dto.*; import com.ai.da.model.vo.DesignCollectionVO; import com.ai.da.model.vo.DesignLikeVO; import com.ai.da.service.DesignService; -import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; diff --git a/src/main/java/com/ai/da/controller/LibraryController.java b/src/main/java/com/ai/da/controller/LibraryController.java index 5699811a..7c174c9a 100644 --- a/src/main/java/com/ai/da/controller/LibraryController.java +++ b/src/main/java/com/ai/da/controller/LibraryController.java @@ -176,7 +176,7 @@ public class LibraryController { private String calculateTempFileUrl(Long userId) { String rootPath = fileProperties.getSys().getPath(); 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) { diff --git a/src/main/java/com/ai/da/mapper/entity/Account.java b/src/main/java/com/ai/da/mapper/entity/Account.java index 49a6e5bc..a0388007 100644 --- a/src/main/java/com/ai/da/mapper/entity/Account.java +++ b/src/main/java/com/ai/da/mapper/entity/Account.java @@ -45,6 +45,16 @@ public class Account implements Serializable { */ private String userPassword; + /** + * 语言 + */ + private String language; + + /** + * 城市 + */ + private String country; + /** * 账户有效期开始时间 */ diff --git a/src/main/java/com/ai/da/model/dto/AccountBindEmailDTO.java b/src/main/java/com/ai/da/model/dto/AccountBindEmailDTO.java index b9cdce36..8671e051 100644 --- a/src/main/java/com/ai/da/model/dto/AccountBindEmailDTO.java +++ b/src/main/java/com/ai/da/model/dto/AccountBindEmailDTO.java @@ -11,15 +11,15 @@ import javax.validation.constraints.NotNull; @ApiModel("绑定邮箱") public class AccountBindEmailDTO { - @NotNull(message = "userId cannot be empty!") + @NotNull(message = "userId.cannot.be.empty") @ApiModelProperty("用户id") private Long userId; - @NotBlank(message = "Please input email!") + @NotBlank(message = "email.cannot.be.empty") @ApiModelProperty("邮箱") private String userEmail; - @NotBlank(message = "Please input the email verification code !") + @NotBlank(message = "emailVerifyCode.cannot.be.empty") @ApiModelProperty("邮箱验证码") private String emailVerifyCode; } diff --git a/src/main/java/com/ai/da/model/dto/AccountLoginDTO.java b/src/main/java/com/ai/da/model/dto/AccountLoginDTO.java index 8c8b1585..2c1483c9 100644 --- a/src/main/java/com/ai/da/model/dto/AccountLoginDTO.java +++ b/src/main/java/com/ai/da/model/dto/AccountLoginDTO.java @@ -11,11 +11,11 @@ import javax.validation.constraints.NotNull; @ApiModel("登入") public class AccountLoginDTO { - @NotNull(message = "userId cannot be empty !") + @NotNull(message = "userId.cannot.be.empty") @ApiModelProperty("userId") private Long userId; - @NotBlank(message = "Please input email !") + @NotBlank(message = "email.cannot.be.empty") @ApiModelProperty("邮箱") private String email; @@ -25,7 +25,7 @@ public class AccountLoginDTO { @ApiModelProperty("密码") private String password; - @NotBlank(message = "Please input loginType !") + @NotBlank(message = "loginType.cannot.be.empty") @ApiModelProperty("登入类型 EMAIL - >邮箱 , PASSWORD ->密码") private String loginType; diff --git a/src/main/java/com/ai/da/model/dto/AccountLogoutDTO.java b/src/main/java/com/ai/da/model/dto/AccountLogoutDTO.java index 56c4a5d5..08118849 100644 --- a/src/main/java/com/ai/da/model/dto/AccountLogoutDTO.java +++ b/src/main/java/com/ai/da/model/dto/AccountLogoutDTO.java @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull; @ApiModel("登出") public class AccountLogoutDTO { - @NotNull(message = "userId cannot be empty !") + @NotNull(message = "userId.cannot.be.empty") @ApiModelProperty("userId") private Long userId; diff --git a/src/main/java/com/ai/da/model/dto/AccountPreLoginDTO.java b/src/main/java/com/ai/da/model/dto/AccountPreLoginDTO.java index fd35fbbc..63cbec6e 100644 --- a/src/main/java/com/ai/da/model/dto/AccountPreLoginDTO.java +++ b/src/main/java/com/ai/da/model/dto/AccountPreLoginDTO.java @@ -10,20 +10,20 @@ import javax.validation.constraints.NotBlank; @ApiModel("预先登入") public class AccountPreLoginDTO { - @NotBlank(message = "userName cannot be empty!") + @NotBlank(message = "userName.cannot.be.empty") @ApiModelProperty("用户名") private String userName; /*新增字段*/ - @NotBlank(message = "Please input email !") + @NotBlank(message = "email.cannot.be.empty") @ApiModelProperty("邮箱") private String email; - @NotBlank(message = "password cannot be empty!") + @NotBlank(message = "password.cannot.be.empty") @ApiModelProperty("密码") private String password; - @NotBlank(message = "operationType cannot be empty") + @NotBlank(message = "operationType.cannot.be.empty") @ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱") private String operationType; diff --git a/src/main/java/com/ai/da/model/dto/AccountRegisterDTO.java b/src/main/java/com/ai/da/model/dto/AccountRegisterDTO.java index 7a8271b7..5d8c4065 100644 --- a/src/main/java/com/ai/da/model/dto/AccountRegisterDTO.java +++ b/src/main/java/com/ai/da/model/dto/AccountRegisterDTO.java @@ -10,15 +10,15 @@ import javax.validation.constraints.NotBlank; @ApiModel("账户") public class AccountRegisterDTO { - @NotBlank(message = "Please input email !") + @NotBlank(message = "email.cannot.be.empty") @ApiModelProperty("邮箱") private String email; - @NotBlank(message = "Please input password !") + @NotBlank(message = "password.cannot.be.empty") @ApiModelProperty("密码") private String password; - @NotBlank(message = "Please input the email verification code !") + @NotBlank(message = "emailVerifyCode.cannot.be.empty") @ApiModelProperty("邮箱验证码") private String emailVerifyCode; diff --git a/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java b/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java index 142c3490..a60796c5 100644 --- a/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java +++ b/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java @@ -20,41 +20,49 @@ public class DesignCollectionDTO { @ApiModelProperty("印花板图片 数组") private List printBoards; - @NotEmpty(message = "colorBoardRgbValues cannot be empty!") + @NotEmpty(message = "colorBoards.cannot.be.empty") @ApiModelProperty("颜色板RGB值 数组") private List colorBoards; @ApiModelProperty("手稿板图片id 数组") private List sketchBoards; - @ApiModelProperty("市场手稿板图片id 数组") - private List marketingSketchs; + // 2023.10版本去除该入参 +// @ApiModelProperty("市场手稿板图片id 数组") +// private List marketingSketchs; - @NotNull(message = "systemScale cannot be empty!") + @NotNull(message = "systemScale.cannot.be.empty") @ApiModelProperty("系统取图比列") private BigDecimal systemScale; + @NotBlank(message = "modelType.cannot.be.empty") + @ApiModelProperty("模特类型:System,Library") private String modelType; + @NotBlank(message = "modelSex.cannot.be.empty") + @ApiModelProperty("模特性别") private String modelSex; - @ApiModelProperty("templateId") + @NotNull(message = "templateId.cannot.be.empty") + @ApiModelProperty("模特ID") private Long templateId; @ApiModelProperty("mood版本id 没有传null") private String moodTemplateId; - @NotBlank(message = "singleOverall cannot be empty!") + @NotBlank(message = "singleOverall.cannot.be.empty") @ApiModelProperty("控制生成类型的参数,两个选项:outfit时候传 single , 另外一个传 overall") private String singleOverall; @ApiModelProperty("single模式下的类别选择参数 选项有outwear,dress,blouse,skirt,trousers") private String switchCategory; - @NotBlank(message = "timeZone cannot be empty!") + @NotBlank(message = "timeZone.cannot.be.empty") @ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取") private String timeZone; + @NotBlank(message = "processId.cannot.be.empty") + @ApiModelProperty("python端design进程ID") private String processId; } diff --git a/src/main/java/com/ai/da/model/dto/EmailSendDTO.java b/src/main/java/com/ai/da/model/dto/EmailSendDTO.java index 38ce0092..e79da073 100644 --- a/src/main/java/com/ai/da/model/dto/EmailSendDTO.java +++ b/src/main/java/com/ai/da/model/dto/EmailSendDTO.java @@ -10,11 +10,11 @@ import javax.validation.constraints.NotBlank; @ApiModel("邮箱发送") public class EmailSendDTO { - @NotBlank(message = "Please input email!") + @NotBlank(message = "email.cannot.be.empty") @ApiModelProperty("邮箱") private String email; - @NotBlank(message = "operationType cannot be empty") + @NotBlank(message = "operationType.cannot.be.empty") @ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱") private String operationType; diff --git a/src/main/java/com/ai/da/model/vo/AuthPrincipalVo.java b/src/main/java/com/ai/da/model/vo/AuthPrincipalVo.java index 0e2e87e0..825c607b 100644 --- a/src/main/java/com/ai/da/model/vo/AuthPrincipalVo.java +++ b/src/main/java/com/ai/da/model/vo/AuthPrincipalVo.java @@ -39,6 +39,16 @@ public class AuthPrincipalVo implements Serializable { */ private Integer status; + /** + * 语言 + */ + private String language; + + /** + * 城市 + */ + private String country; + /** * 角色 */ diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index e40f25ff..7ed2ebd3 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -16,6 +16,7 @@ import com.ai.da.service.PythonTAllInfoService; import com.ai.da.service.SysFileService; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import com.google.common.collect.Lists; @@ -1581,29 +1582,34 @@ public class PythonService { .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==") .addHeader("Content-Type", "application/json") .build(); - Response response = null; - String bodyStr = null; + Response response; + String bodyStr; try { log.info("generateAttributeRetrieval请求入参content###{}", JSON.toJSONString(content)); response = client.newCall(request).execute(); - bodyStr = response.body().string(); } catch (IOException ioException) { + AccessLimitUtils.validateOut("generateAttributeRetrieval"); log.error("generateAttributeRetrieval异常###{}", ExceptionUtil.getThrowableList(ioException)); + throw new BusinessException("attributeRetrieval.interface.exception"); } //去除限流 AccessLimitUtils.validateOut("generateAttributeRetrieval"); - if (Objects.isNull(response)) { - log.error("generateAttributeRetrieval异常###{}", "response or body is empty!"); - throw new BusinessException("system error!"); + if (response.isSuccessful()) { + try { + if (Objects.nonNull(response.body())) { + bodyStr = response.body().string(); + return resolveDesignAttributeRetrievalDTO(bodyStr); + } + //生成失败 + throw new BusinessException("attributeRetrieval.interface.exception"); + } catch (JSONException | IOException e) { + log.error("generateAttributeRetrieval异常###{}", e.getMessage()); + throw new BusinessException("attributeRetrieval.interface.exception"); + } } - JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response)); - Boolean result = jsonObject.getBoolean("successful"); - if (result) { - return resolveDesignAttributeRetrievalDTO(bodyStr); - } - log.info("attribute_retrieval失败###{}", bodyStr); + log.error("generateAttributeRetrieval异常###{}", response); //生成失败 - throw new BusinessException("system error!"); + throw new BusinessException("attributeRetrieval.interface.exception"); } private static DesignAttributeRetrievalDTO resolveDesignAttributeRetrievalDTO(String bodyStr) { @@ -1612,20 +1618,20 @@ public class PythonService { JSONObject data = jsonObject.getJSONObject("data"); if (data != null) { JSONObject jsonObjectSys = data.getJSONObject("sys_lib_dict"); - if (null == jsonObjectSys || jsonObjectSys.size() == 0) { + if (null == jsonObjectSys || jsonObjectSys.isEmpty()) { log.error("generateAttributeRetrieval异常###{}", "jsonObjectSys is empty!"); - throw new BusinessException("system error!"); + throw new BusinessException("attributeRetrieval.interface.exception"); } setUrls(jsonObjectSys, response.getSysFileUrlS()); JSONObject jsonObjectLibrary = data.getJSONObject("user_lib_dict"); - if (null == jsonObjectLibrary || jsonObjectLibrary.size() == 0) { + if (null == jsonObjectLibrary || jsonObjectLibrary.isEmpty()) { log.error("generateAttributeRetrieval异常###{}", "jsonObjectLibrary is empty!"); - throw new BusinessException("system error!"); + throw new BusinessException("attributeRetrieval.interface.exception"); } setUrls(jsonObjectLibrary, response.getLibraryUrls()); return response; } - throw new BusinessException("AttributeRetrieval response data is null"); + throw new BusinessException("attributeRetrieval.interface.exception"); } private static void setUrls(JSONObject jsonObjectSys, List urls) { @@ -1918,7 +1924,7 @@ public class PythonService { public JSONObject designNew(DesignPythonObjects designPythonObjects) { // todo 限流校验 -// AccessLimitUtils.validate("design",5); + AccessLimitUtils.validate("design",5); OkHttpClient client = new OkHttpClient().newBuilder() .connectTimeout(30, TimeUnit.SECONDS) .pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒) @@ -1937,39 +1943,34 @@ public class PythonService { .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==") .addHeader("Content-Type", "application/json") .build(); - Response response = null; + Response response; + String responseBody; try { 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) { + AccessLimitUtils.validateOut("design"); log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException)); + throw new BusinessException("design.interface.exception"); } //去除限流 -// 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"); + AccessLimitUtils.validateOut("design"); if (response.isSuccessful()) { try { - String responseBody = response.body().string(); - JSONObject responseObject = JSON.parseObject(responseBody); - return responseObject; - } catch (IOException e) { - throw new RuntimeException(e); + if (Objects.nonNull(response.body())) { + responseBody = response.body().string(); + JSONObject responseObject = JSON.parseObject(responseBody); + log.info("PythonService##responseObject###{}", responseObject); + return responseObject; + } + 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"); } diff --git a/src/main/java/com/ai/da/python/vo/DesignPythonItem.java b/src/main/java/com/ai/da/python/vo/DesignPythonItem.java index 02d37b7b..9b195247 100644 --- a/src/main/java/com/ai/da/python/vo/DesignPythonItem.java +++ b/src/main/java/com/ai/da/python/vo/DesignPythonItem.java @@ -74,9 +74,15 @@ public class DesignPythonItem { public static List OUTWEAR_DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.OUTWEAR.getRealName(), CollectionLevel2TypeEnum.DRESS.getRealName(), CollectionLevel2TypeEnum.BLOUSE.getRealName()); + public static List DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.DRESS.getRealName(), + CollectionLevel2TypeEnum.BLOUSE.getRealName()); + public static List SKIRT_TROUSERS = Arrays.asList( CollectionLevel2TypeEnum.SKIRT.getRealName(), CollectionLevel2TypeEnum.TROUSERS.getRealName()); + public static List OUTERWEAR = Arrays.asList( + "OuterWear"); + public static List TOPS = Arrays.asList( "Tops"); diff --git a/src/main/java/com/ai/da/service/impl/AccountLoginLogServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountLoginLogServiceImpl.java index 4671fba1..f7b80773 100644 --- a/src/main/java/com/ai/da/service/impl/AccountLoginLogServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountLoginLogServiceImpl.java @@ -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 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 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 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 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 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 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 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 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 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 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 queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_email", email); - return accountMapper.selectOne(queryWrapper); + queryWrapper.lambda().eq(Account::getUserEmail, email); + queryWrapper.lambda().last("limit 1"); + List 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 queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_name", userName); - return accountMapper.selectOne(queryWrapper); + queryWrapper.lambda().eq(Account::getUserName, userName); + queryWrapper.lambda().last("limit 1"); + List 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 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 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; } diff --git a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java index c04bc60d..9b8ae657 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java @@ -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 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 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 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 sketchBoardIds = designDTO.getSketchBoards().stream() @@ -408,7 +427,7 @@ public class CollectionElementServiceImpl extends ServiceImpl 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 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 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 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 queryWrapper = new QueryWrapper<>(); - queryWrapper.in("id", elementIds); + queryWrapper.lambda().in(CollectionElement::getId, elementIds); CollectionElement element = new CollectionElement(); element.setCollectionId(collectionId); //批量关联 diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index 6595af41..ef4610ce 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -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 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 impleme element.setHasPin((byte) 0); } element.setId(null); -// element.setType(DesignTypeEnum.LIBRARY.getRealName()); }); List saveElements = elementVO.getLibraryCollectionElements(); collectionElementService.saveBatch(saveElements); @@ -299,8 +298,6 @@ public class DesignServiceImpl extends ServiceImpl 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 impleme //生成library generateLibrary(elementVO, designDTO.getTimeZone()); //处理关联关系,修复element覆盖得情况 - List reLationelements = collectionElementService.getByOnlyCollectionId(collectionId); - List reLationelementIds = reLationelements.stream().map(CollectionElement::getId).collect(Collectors.toList()); - handleCollectionElementRelation(collectionId, (null == collectionIdParam) ? false : true, reLationelementIds); - //保存python返回信息 + List relationElements = collectionElementService.getByOnlyCollectionId(collectionId); + List 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 diff --git a/src/main/java/com/ai/da/service/impl/LibraryModelPointServiceImpl.java b/src/main/java/com/ai/da/service/impl/LibraryModelPointServiceImpl.java index bb249baf..2885e2cd 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryModelPointServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryModelPointServiceImpl.java @@ -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 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 libraryModelPoints = baseMapper.selectList(queryWrapper); + if (CollectionUtil.isNotEmpty(libraryModelPoints)) { + throw new BusinessException("modelPoint.not.find"); + } + return libraryModelPoints.get(0); } } diff --git a/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java b/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java index d0f6b5eb..f02f1070 100644 --- a/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java @@ -182,7 +182,7 @@ public class PanToneServiceImpl extends ServiceImpl impl private List coverPanToneToVoList(List panTones , Map indexToValue, Map valueToHsv, List hsvBatch) { - if (Objects.isNull(panTones)) { + if (CollectionUtil.isEmpty(panTones)) { throw new BusinessException("Pantone value does not exist !"); } List templateResposne = CopyUtil.copyList(panTones, PantoneVO.class, (o, d) -> { diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index ac8570bc..5d019e7b 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -2,9 +2,9 @@ server.port=5567 #datasource 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.username=root -spring.datasource.password=root +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=aida_con +spring.datasource.password=123456 #??? spring.datasource.hikari.minimum-idle=5 diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties new file mode 100644 index 00000000..ce833f2f --- /dev/null +++ b/src/main/resources/messages_en.properties @@ -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! \ No newline at end of file diff --git a/src/main/resources/messages_zh.properties b/src/main/resources/messages_zh.properties new file mode 100644 index 00000000..18da73c2 --- /dev/null +++ b/src/main/resources/messages_zh.properties @@ -0,0 +1 @@ +system.error=系统错误! \ No newline at end of file