Compare commits
29 Commits
release/te
...
dev/dev_sh
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e28d579d1 | ||
|
|
1c96522447 | ||
| ea0332851d | |||
| a25a7dc023 | |||
|
|
b4fe1ca199 | ||
|
|
b315ae5644 | ||
|
|
8d6e3e9644 | ||
|
|
be1119be6f | ||
|
|
b836e7fd67 | ||
| a237b4041d | |||
| ea4cd29723 | |||
| 13397fa1f7 | |||
| 2fab472150 | |||
| 8c71b4845a | |||
| b70f909a32 | |||
|
|
9f064609e7 | ||
|
|
fd10d4dbc4 | ||
|
|
fadb5faf0d | ||
| e5e514b522 | |||
| 74e6d5a1da | |||
| 3cf0570912 | |||
|
|
8da51a0a82 | ||
|
|
37ff7fbb91 | ||
|
|
8c20b51e13 | ||
| 391a28d659 | |||
| 4535fb7dfb | |||
| 546d1b4c44 | |||
| 5fe605c130 | |||
| 4408c0ecc6 |
22
pom.xml
22
pom.xml
@@ -288,6 +288,28 @@
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.auth</groupId>
|
||||
<artifactId>google-auth-library-oauth2-http</artifactId>
|
||||
<version>1.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>1.32.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.oauth-client</groupId>
|
||||
<artifactId>google-oauth-client</artifactId>
|
||||
<version>1.32.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client-jackson2</artifactId>
|
||||
<version>1.41.5</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MyTaskScheduler {
|
||||
|
||||
// 定时任务,每十五天执行一次
|
||||
// @Scheduled(cron = "0 0 0 ? * MON")
|
||||
@Scheduled(cron = "0 0 0 */15 * ?")
|
||||
// @Scheduled(cron = "0 0 0 */15 * ?")
|
||||
public void checkExpiry() {
|
||||
// 检测正式用户是否快要过期
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
@@ -85,7 +85,7 @@ public class MyTaskScheduler {
|
||||
}
|
||||
}
|
||||
}
|
||||
@Scheduled(cron = "0 0 9 * * ?")
|
||||
// @Scheduled(cron = "0 0 9 * * ?")
|
||||
public void sendTrialOrderExcelToManagements() {
|
||||
// 获取前一天日期
|
||||
LocalDate yesterday = LocalDate.now().minusDays(1);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
|
||||
"/api/python/flush","/api/account/healthy","/api/ali-pay/trade/notify","/api/paypal/ipn/back","/api/alipay-hk/trade/notify",
|
||||
"/api/portfolio/page", "/api/portfolio/detail", "/api/portfolio/commentPage", "/api/portfolio/viewsIncrease",
|
||||
"/api/account/designWorksRegister","/api/account/questionnaire","/api/stripe/trade/notify",
|
||||
"/notification","/api/account/activateNewEmail"
|
||||
"/notification","/api/account/activateNewEmail","/api/third/party/auth/google_callback","/api/third/party/parseGoogleCredential","/api/third/party/receiveDesignResults","/api/third/party/parseWeChatCode"
|
||||
);
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,14 +26,14 @@ public class AccountTask {
|
||||
accountService.refreshCreditsWeekly();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
|
||||
// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
|
||||
public void getPaidUser() {
|
||||
// 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单
|
||||
accountService.extendValidityForCC();
|
||||
}
|
||||
|
||||
// 每天凌晨0点执行一次
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
// @Scheduled(cron = "0 0 0 * * ?")
|
||||
public void cancelActivityBenefits() {
|
||||
// 1、查询当前所有参与了活动且过期的用户
|
||||
List<Account> accountList = accountService.getExpiredUserBySystemUser(4);
|
||||
@@ -46,7 +46,7 @@ public class AccountTask {
|
||||
}
|
||||
|
||||
// 每天检测正式用户到期情况,每天凌晨0点执行
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
// @Scheduled(cron = "0 0 0 * * ?")
|
||||
public void paidUserToVisitor() {
|
||||
// 1、查询当前已过期正式用户或试用用户
|
||||
List<Account> accountList = accountService.getExpiredUserBySystemUser(1);
|
||||
@@ -63,7 +63,7 @@ public class AccountTask {
|
||||
/**
|
||||
* 将Code-Create上注册的用户添加为AiDA的游客
|
||||
*/
|
||||
@Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
|
||||
// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
|
||||
public void registerUserToVisitor() {
|
||||
accountService.registerUserToVisitor();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class PaypalTask {
|
||||
@Resource
|
||||
private PayPalCheckoutService payPalCheckoutService;
|
||||
|
||||
@Scheduled(cron = "0/30 * * * * ?")
|
||||
// @Scheduled(cron = "0/30 * * * * ?")
|
||||
public void orderConfirm() throws SerializeException {
|
||||
|
||||
// log.info("PayPal orderConfirm 被执行......");
|
||||
|
||||
@@ -22,7 +22,7 @@ public class StripeTask {
|
||||
@Resource
|
||||
private StripeService stripeService;
|
||||
|
||||
@Scheduled(cron = "0/30 * * * * ?")
|
||||
// @Scheduled(cron = "0/30 * * * * ?")
|
||||
public void orderConfirm() throws SerializeException {
|
||||
|
||||
// 查看超过30分钟以上仍未支付的订单 置为超时订单
|
||||
|
||||
@@ -484,6 +484,57 @@ public class MinioUtil {
|
||||
return null; // or throw an exception
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MinIO 下载对象到本地路径
|
||||
*
|
||||
* @param bucketName 存储桶名称
|
||||
* @param objectName MinIO 上对象的名称
|
||||
* @param localFilePath 本地文件路径
|
||||
*/
|
||||
public void downloadMinioObjectToLocal(String bucketName, String objectName, String localFilePath) {
|
||||
File localFile = new File(localFilePath);
|
||||
File parentDir = localFile.getParentFile();
|
||||
if (parentDir != null) {
|
||||
parentDir.mkdirs(); // 创建文件夹,确保路径结构与 MinIO 一致
|
||||
}
|
||||
|
||||
try (InputStream stream = minioClient.getObject(
|
||||
GetObjectArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
FileOutputStream out = new FileOutputStream(localFile)) {
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = stream.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
}
|
||||
log.info("Downloaded object {} to {}", objectName, localFilePath);
|
||||
} catch (Exception e) {
|
||||
log.error("Error while downloading object {}: {}", objectName, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从路径中提取存储桶名称
|
||||
*
|
||||
* @param path MinIO 路径
|
||||
* @return 存储桶名称
|
||||
*/
|
||||
public String getBucketNameFromPath(String path) {
|
||||
int index = path.indexOf("/");
|
||||
return path.substring(0, index); // 获取第一级路径作为 bucket 名称
|
||||
}
|
||||
|
||||
/**
|
||||
* 从路径中提取对象名称
|
||||
*
|
||||
* @param path MinIO 路径
|
||||
* @return 对象名称
|
||||
*/
|
||||
public String getObjectNameFromPath(String path) {
|
||||
int index = path.indexOf("/");
|
||||
return path.substring(index + 1); // 获取路径的其余部分作为对象名称
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -389,20 +389,20 @@ public class SendEmailUtil {
|
||||
// 根据邮件类型设置不同的主题和模板
|
||||
String subject = "";
|
||||
Template template = new Template();
|
||||
if (type == 1) {
|
||||
subject = "Upcoming System Upgrade for AiDA 3.0";
|
||||
template.setTemplateID(UPGRADE_NOTIFICATION_ID);
|
||||
}else {
|
||||
subject = "即将到来的AiDA 3.0系统升级";
|
||||
template.setTemplateID(UPGRADE_NOTIFICATION_ID_CHINESE);
|
||||
}
|
||||
// if (type == 1) {
|
||||
// subject = "Successful System Upgrade and New Features in AiDA 3.1";
|
||||
// template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID);
|
||||
// subject = "Upcoming System Upgrade for AiDA 3.0";
|
||||
// template.setTemplateID(UPGRADE_NOTIFICATION_ID);
|
||||
// }else {
|
||||
// subject = "系统升级成功和AiDA 3.1新功能";
|
||||
// template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE);
|
||||
// subject = "即将到来的AiDA 3.0系统升级";
|
||||
// template.setTemplateID(UPGRADE_NOTIFICATION_ID_CHINESE);
|
||||
// }
|
||||
if (type == 1) {
|
||||
subject = "Successful System Upgrade and New Features in AiDA 3.1";
|
||||
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID);
|
||||
}else {
|
||||
subject = "系统升级成功和AiDA 3.1新功能";
|
||||
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE);
|
||||
}
|
||||
template.setTemplateData(buildAccountData(account));
|
||||
|
||||
req.setSubject(subject);
|
||||
@@ -759,6 +759,47 @@ public class SendEmailUtil {
|
||||
req.setSubject(subject);
|
||||
req.setTemplate(template);
|
||||
|
||||
// 发送邮件
|
||||
SendEmailResponse resp = client.SendEmail(req);
|
||||
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
|
||||
} catch (TencentCloudSDKException e) {
|
||||
log.info("邮件发送失败###{}", e.toString());
|
||||
throw new BusinessException("failed.to.send.mail");
|
||||
}
|
||||
}
|
||||
private final static Long SYSTEM_UPGRADE_CN_ID = 131743L;
|
||||
private final static Long SYSTEM_UPGRADE_EN_ID = 131744L;
|
||||
public static void temporaryUpgrade(Account account, String senderAddress, int type) {
|
||||
try {
|
||||
// 实例化一个认证对象
|
||||
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("ses.tencentcloudapi.com");
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
SesClient client = new SesClient(cred, "ap-hongkong", clientProfile);
|
||||
SendEmailRequest req = new SendEmailRequest();
|
||||
if (StringUtils.isEmpty(senderAddress)) {
|
||||
senderAddress = CODE_CREATE_SEND_ADDRESS;
|
||||
}
|
||||
req.setFromEmailAddress(senderAddress);
|
||||
req.setDestination(new String[]{account.getUserEmail()});
|
||||
|
||||
// 根据邮件类型设置不同的主题和模板
|
||||
String subject = "";
|
||||
Template template = new Template();
|
||||
if (type == 1) {
|
||||
subject = "AiDA system upgrade completed";
|
||||
template.setTemplateID(SYSTEM_UPGRADE_EN_ID);
|
||||
}else {
|
||||
subject = "AiDA系统升级完成";
|
||||
template.setTemplateID(SYSTEM_UPGRADE_CN_ID);
|
||||
}
|
||||
template.setTemplateData(buildAccountData(account));
|
||||
|
||||
req.setSubject(subject);
|
||||
req.setTemplate(template);
|
||||
|
||||
// 发送邮件
|
||||
SendEmailResponse resp = client.SendEmail(req);
|
||||
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.ai.da.common.websocket;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.websocket.*;
|
||||
import javax.websocket.server.PathParam;
|
||||
@@ -16,54 +19,55 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@Slf4j
|
||||
public class NotificationConnection {
|
||||
|
||||
static Map<String,Session> sessionMap = new ConcurrentHashMap<>();
|
||||
//连接超时
|
||||
public static final long MAX_TIME_OUT = 3 * 60 * 1000;
|
||||
|
||||
private Session session;
|
||||
private Long userId;
|
||||
// 这里用ConcurrentHashMap 因为他是一个线程安全的Map
|
||||
private static ConcurrentHashMap<Long, NotificationConnection> websockets = new ConcurrentHashMap<>();
|
||||
//连接建立时执行的操作
|
||||
/*@OnOpen
|
||||
public void onOpen(Session session){
|
||||
sessionMap.put(session.getId(),session);
|
||||
log.info("websocket is open, sessionId: {}",session.getId());
|
||||
}*/
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("id") String id) { // 接收到前端传来的用户ID
|
||||
this.session = session;
|
||||
this.userId = Long.valueOf(id);
|
||||
this.session.setMaxIdleTimeout(MAX_TIME_OUT);
|
||||
websockets.put(Long.parseLong(id), this); //将ID作为key,当前的对象作为Value
|
||||
log.info("【建立连接】 用户为:{}", this.session);
|
||||
log.info("【建立连接】 用户Id为:{}", id);
|
||||
log.info("【建立连接】 总数为:{}", websockets.size());
|
||||
log.info("【当前连接总数】 为:{}", websockets.size());
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose() {
|
||||
websockets.remove(this); // 将当前的对象从集合中删除
|
||||
log.info("【连接断开】 用户为:{}", this.session);
|
||||
// log.info("【连接断开】 总数为:{}", websockets.size());
|
||||
public void onClose(CloseReason reason) {
|
||||
log.info("【连接断开】 用户为:{}, sessionId: {}, 原因为{}", this.userId, this.session.getId(), reason);
|
||||
log.info("【当前连接总数】 为:{}", websockets.size());
|
||||
websockets.remove(this.userId); // 将当前的对象从集合中删除
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误时调用
|
||||
* @param throwable 异常
|
||||
*/
|
||||
@OnError
|
||||
public void onError(Throwable throwable) {
|
||||
log.info("【连接异常】 用户为:{} , sessionId: {}", this.userId, this.session.getId(), throwable);
|
||||
websockets.remove(this.userId); // 将当前的对象从集合中删除
|
||||
log.info("【当前连接总数】 为:{}", websockets.size());
|
||||
}
|
||||
|
||||
//收到了客户端消息执行的操作
|
||||
@OnMessage
|
||||
public void onMessage(String text){
|
||||
log.info("收到了一条消息:"+text);
|
||||
public void onMessage(@RequestParam String text){
|
||||
Map<String, String> textMap = JSONObject.parseObject(text, Map.class);
|
||||
log.info("收到了一条来自 {} 的消息:{}, sessionId:{}", this.userId, textMap.get("text"), this.session.getId());
|
||||
// return "已收到你的消息";
|
||||
}
|
||||
/*//连接关闭的时候执行的操作
|
||||
@OnClose
|
||||
public void onClose(Session session){
|
||||
sessionMap.remove(session.getId());
|
||||
log.info("websocket is close, sessionId: {}",session.getId());
|
||||
}
|
||||
|
||||
public void sendMsg(String message) throws IOException {
|
||||
for(String key:sessionMap.keySet()){
|
||||
sessionMap.get(key).getBasicRemote().sendText(message);
|
||||
if (textMap.get("text").equals("PING")){
|
||||
sendMsg(JSON.toJSONString("PONG"), this.userId);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public void sendMsg(String message, Long userId) throws IOException {
|
||||
public void sendMsg(String message, Long userId) {
|
||||
if (userId == null) { // 如果等于null则证明是群发
|
||||
// 获取当前Map的一个迭代器,遍历Map的方式有很多种,看着来
|
||||
// 这个就是遍历这个集合的过程....
|
||||
@@ -73,7 +77,11 @@ public class NotificationConnection {
|
||||
NotificationConnection webSocket = entry.getValue();
|
||||
// 接下来就是遍历群发
|
||||
log.info("广播消息 【给用户】 :{}发送消息【{}】", webSocket, message);
|
||||
webSocket.session.getBasicRemote().sendText(message); // 发送!!!!!!!!!
|
||||
try {
|
||||
webSocket.session.getBasicRemote().sendText(message); // 发送!!!!!!!!!
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to send message to session {}: {}", webSocket.session.getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
} else { // 如果不是群发,则判断ID,其余步骤一致
|
||||
// 获取当前Map的一个迭代器,遍历Map的方式有很多种,看着来
|
||||
|
||||
@@ -6,8 +6,6 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
/**
|
||||
* Configuration of WebSocket
|
||||
*
|
||||
* @author db1995
|
||||
*/
|
||||
@Configuration
|
||||
public class WebSocketConfig {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ai.da.controller;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.Response;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
@@ -261,5 +262,52 @@ public class AccountController {
|
||||
return Response.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("temporaryUpgrade")
|
||||
@ApiOperation(value = "临时升级")
|
||||
public Response<Boolean> temporaryUpgrade() {
|
||||
accountService.temporaryUpgrade();
|
||||
return Response.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("enterpriseLogin")
|
||||
@ApiOperation(value = "企业登录")
|
||||
public Response<AccountLoginVO> enterpriseLogin(@Valid @RequestBody AccountLoginDTO accountDTO) {
|
||||
return Response.success(accountService.enterpriseLogin(accountDTO));
|
||||
}
|
||||
|
||||
@PostMapping("schoolLogin")
|
||||
@ApiOperation(value = "学校登录")
|
||||
public Response<AccountLoginVO> schoolLogin(@Valid @RequestBody AccountLoginDTO accountDTO) {
|
||||
return Response.success(accountService.schoolLogin(accountDTO));
|
||||
}
|
||||
|
||||
@PostMapping("addOrUpdateSubAccount")
|
||||
@ApiOperation(value = "子账号新增")
|
||||
public Response<Boolean> addSubAccount(@Valid @RequestBody AddSubAccountDTO addSubAccountDTO) {
|
||||
return Response.success(accountService.addSubAccount(addSubAccountDTO));
|
||||
}
|
||||
|
||||
@PostMapping("deleteSubAccount")
|
||||
@ApiOperation(value = "子账号删除")
|
||||
public Response<Boolean> deleteSubAccount(@Valid @RequestBody AddSubAccountDTO addSubAccountDTO) {
|
||||
return Response.success(accountService.deleteSubAccount(addSubAccountDTO));
|
||||
}
|
||||
|
||||
@PostMapping("subAccountList")
|
||||
@ApiOperation(value = "子账号查询")
|
||||
public Response<PageBaseResponse<Account>> subAccountList(@Valid @RequestBody SubAccountPageDTO subAccountPageDTO) {
|
||||
return Response.success(accountService.subAccountList(subAccountPageDTO));
|
||||
}
|
||||
|
||||
@GetMapping("accountDetail")
|
||||
@ApiOperation(value = "账号详情")
|
||||
public Response<Account> accountDetail(@RequestParam("id") Long id) {
|
||||
return Response.success(accountService.accountDetail(id));
|
||||
}
|
||||
|
||||
@PostMapping("getAccountDetail")
|
||||
@ApiOperation(value = "获取账户信息")
|
||||
public Response<AccountLoginVO> getAccountDetail() {
|
||||
return Response.success(accountService.getAccountDetail());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class DesignController {
|
||||
@ApiOperation(value = "设计 Conllection")
|
||||
@PostMapping("/designCollection")
|
||||
@CrossOrigin
|
||||
public Response<DesignCollectionVO> designCollection(@Valid @RequestBody DesignCollectionDTO designDTO) {
|
||||
public Response<String> designCollection(@Valid @RequestBody DesignCollectionDTO designDTO) {
|
||||
return Response.success(designService.designCollection(designDTO));
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class DesignController {
|
||||
|
||||
@ApiOperation(value = "重新设计 Collection")
|
||||
@PostMapping("/reDesignCollection")
|
||||
public Response<DesignCollectionVO> reDesignCollection(@Valid @RequestBody ReDesignCollectionDTO reDesignDTO) {
|
||||
public Response<String> reDesignCollection(@Valid @RequestBody ReDesignCollectionDTO reDesignDTO) {
|
||||
return Response.success(designService.reDesignCollection(reDesignDTO));
|
||||
}
|
||||
|
||||
@@ -83,4 +83,16 @@ public class DesignController {
|
||||
return Response.success(designService.getModel(designItemIdList));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取design结果")
|
||||
@GetMapping("/getDesignResult")
|
||||
public Response<DesignCollectionVO> getDesignResult(@RequestParam("requestId") String requestId, @RequestParam("objectSignList") List<String> objectSignList){
|
||||
return Response.success(designService.getDesignResult(requestId, objectSignList));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "云生成")
|
||||
@PostMapping("/designCloud")
|
||||
@CrossOrigin
|
||||
public Response<String> designCloud(@Valid @RequestBody DesignCollectionDTO designDTO) {
|
||||
return Response.success(designService.designCloud(designDTO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,4 +245,16 @@ public class SavedCollectionController {
|
||||
public Response<String> likeHistoryRelSketch() {
|
||||
return Response.success(userLikeGroupService.likeHistoryRelSketch());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "download")
|
||||
@PostMapping("/download")
|
||||
public Response<String> download() {
|
||||
return Response.success(userLikeGroupService.download());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "productImageInitialize")
|
||||
@PostMapping("/productImageInitialize")
|
||||
public Response<Boolean> productImageUpload(@Valid @RequestBody ProductImageInitializeDTO productImageInitializeDTO) {
|
||||
return Response.success(userLikeGroupService.productImageInitialize(productImageInitializeDTO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.ai.da.controller;
|
||||
|
||||
import com.ai.da.common.response.Response;
|
||||
import com.ai.da.mapper.primary.entity.GoogleUser;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
import com.ai.da.model.vo.DesignCollectionVO;
|
||||
import com.ai.da.service.AccountService;
|
||||
import com.ai.da.service.DesignService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -14,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.Valid;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
@@ -27,6 +32,9 @@ public class ThirdPartyController {
|
||||
@Resource
|
||||
private AccountService accountService;
|
||||
|
||||
@Resource
|
||||
private DesignService designService;
|
||||
|
||||
/*@ApiOperation(value = "Add user information")
|
||||
@PostMapping("/addUser")
|
||||
public Response<Boolean> addUser(@Valid @RequestBody AccountAddDTO accountAddDTO) {
|
||||
@@ -114,4 +122,28 @@ public class ThirdPartyController {
|
||||
public Response<String> updateNoLoginRequiredNew(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) {
|
||||
return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@GetMapping("/auth/google_callback")
|
||||
public Response<String> googleCallback(@RequestParam("code") String code, HttpSession session) {
|
||||
return Response.success(accountService.googleCallback(code, session));
|
||||
}
|
||||
@CrossOrigin
|
||||
@GetMapping("/parseGoogleCredential")
|
||||
public Response<AccountLoginVO> parseGoogleCredential(@RequestParam("credential") String credential) {
|
||||
return Response.success(accountService.parseGoogleCredential(credential));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@GetMapping("/parseWeChatCode")
|
||||
public Response<AccountLoginVO> parseWeChatCode(@RequestParam("code") String code) {
|
||||
return Response.success(accountService.parseWeChatCode(code));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "接收Design结果")
|
||||
@PostMapping("/receiveDesignResults")
|
||||
@CrossOrigin
|
||||
public Response<Boolean> receiveDesignResults(@Valid @RequestBody JSONObject responseObject) {
|
||||
return Response.success(designService.receiveDesignResults(responseObject));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.ai.da.mapper.primary;
|
||||
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.primary.entity.AccountExtend;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mapper 接口
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-06-13
|
||||
*/
|
||||
public interface AccountExtendMapper extends CommonMapper<AccountExtend> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.ai.da.mapper.primary;
|
||||
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.primary.entity.ProductImageAttribute;
|
||||
|
||||
public interface ProductImageAttributeMapper extends CommonMapper<ProductImageAttribute> {
|
||||
}
|
||||
@@ -97,6 +97,10 @@ public class Account implements Serializable {
|
||||
* 2 : 月付用户
|
||||
* 3 : 试用用户
|
||||
* 4 : 参加活动获取30天有效期和6000个积分的用户
|
||||
* 5 : 企业管理员账号
|
||||
* 6 : 企业子账号
|
||||
* 7 : 学校管理员
|
||||
* 8 : 学校子账号
|
||||
*/
|
||||
private Integer systemUser;
|
||||
|
||||
@@ -104,4 +108,16 @@ public class Account implements Serializable {
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
private String organizationName;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private Integer isAdmin;
|
||||
|
||||
private BigDecimal shareCredits;
|
||||
|
||||
private Integer subAccountNum;
|
||||
|
||||
private String invitationCode;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ai.da.mapper.primary.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("account_extend")
|
||||
public class AccountExtend implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Long accountId;
|
||||
|
||||
private String authType;
|
||||
|
||||
private String auth;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ai.da.mapper.primary.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GoogleUser {
|
||||
private String sub; // 用户唯一标识
|
||||
private String email;
|
||||
private String name;
|
||||
private String picture;
|
||||
private boolean emailVerified;
|
||||
private String givenName;
|
||||
private String familyName;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ai.da.mapper.primary.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("product_image_attribute")
|
||||
public class ProductImageAttribute implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String imgName;
|
||||
private String length;
|
||||
private String sleeveLength;
|
||||
private String sleeveShape;
|
||||
private String sleeveShoulder;
|
||||
private String neckline;
|
||||
private String collar;
|
||||
private String design;
|
||||
private String silhouette;
|
||||
private String type;
|
||||
private String openingType;
|
||||
private String subtype;
|
||||
|
||||
private String style;
|
||||
}
|
||||
@@ -19,6 +19,4 @@ public class AttributeRetrieval {
|
||||
private String subtype;
|
||||
|
||||
private String style;
|
||||
|
||||
private Integer deprecated;
|
||||
}
|
||||
|
||||
@@ -32,4 +32,6 @@ public class AccountLoginDTO {
|
||||
@ApiModelProperty("邮箱验证码")
|
||||
private String emailVerifyCode;
|
||||
|
||||
private String organizationName;
|
||||
|
||||
}
|
||||
|
||||
12
src/main/java/com/ai/da/model/dto/AddSubAccountDTO.java
Normal file
12
src/main/java/com/ai/da/model/dto/AddSubAccountDTO.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AddSubAccountDTO extends Account {
|
||||
|
||||
private List<Long> deleteIdList;
|
||||
}
|
||||
@@ -63,4 +63,8 @@ public class DesignCollectionDTO {
|
||||
|
||||
private String moodboardPostion;
|
||||
|
||||
private List<String> requestIdList;
|
||||
|
||||
private Integer designNum;
|
||||
|
||||
}
|
||||
|
||||
@@ -29,12 +29,15 @@ public class GenerateToPythonDTO {
|
||||
|
||||
private String svg;
|
||||
|
||||
public GenerateToPythonDTO(String tasks_id, String prompt, String image_url, String mode, String category, String gender) {
|
||||
private String version;
|
||||
|
||||
public GenerateToPythonDTO(String tasks_id, String prompt, String image_url, String mode, String category, String gender, String version) {
|
||||
this.image_url = image_url;
|
||||
this.category = category;
|
||||
this.prompt = prompt;
|
||||
this.mode = mode;
|
||||
this.tasks_id = tasks_id;
|
||||
this.gender = gender;
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ProductImageInitializeDTO {
|
||||
private List<Long> libraryIds;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class ReDesignCollectionDTO {
|
||||
@ApiModelProperty("市场手稿板图片id 数组")
|
||||
private List<DesignCollectionElementDTO> marketingSketchs;
|
||||
|
||||
@NotNull(message = "colorBoards.cannot.be.empty")
|
||||
@NotNull(message = "systemScale.cannot.be.empty")
|
||||
@ApiModelProperty("系统取图比列")
|
||||
private BigDecimal systemScale;
|
||||
|
||||
|
||||
9
src/main/java/com/ai/da/model/dto/SubAccountPageDTO.java
Normal file
9
src/main/java/com/ai/da/model/dto/SubAccountPageDTO.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import com.ai.da.model.vo.PageQueryBaseVo;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SubAccountPageDTO extends PageQueryBaseVo {
|
||||
private String userName;
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public class DesignCollectionItemVO {
|
||||
@ApiModelProperty("t_design_python_outfit id")
|
||||
private String designOutfitUrl;
|
||||
|
||||
private String objectSign;
|
||||
|
||||
public DesignCollectionItemVO() {
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public class DesignCollectionVO {
|
||||
|
||||
private String processId;
|
||||
|
||||
private List<String> UnfinishedList;
|
||||
|
||||
public DesignCollectionVO() {
|
||||
}
|
||||
}
|
||||
|
||||
13
src/main/java/com/ai/da/model/vo/GoogleTokenResponse.java
Normal file
13
src/main/java/com/ai/da/model/vo/GoogleTokenResponse.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GoogleTokenResponse {
|
||||
private String accessToken;
|
||||
private String idToken;
|
||||
private long expiresIn;
|
||||
private String tokenType;
|
||||
private String scope;
|
||||
|
||||
}
|
||||
@@ -47,4 +47,8 @@ public class ValidateElementVO {
|
||||
private String modelSex;
|
||||
|
||||
private String style;
|
||||
|
||||
private List<String> requestIdList;
|
||||
|
||||
private Integer designNum;
|
||||
}
|
||||
|
||||
@@ -230,13 +230,14 @@ public class PythonService {
|
||||
designPythonObjects.setProcess_id(processId);
|
||||
|
||||
long pinPrintNum = calculateDesignPinPrintNum(elementVO.getPrintBoardElements());
|
||||
long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements());
|
||||
long noPrintNum = 8 - pinPrintNum - noPinPrintNum;
|
||||
long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements(), elementVO.getDesignNum());
|
||||
long noPrintNum = elementVO.getDesignNum() - pinPrintNum - noPinPrintNum;
|
||||
elementVO.setNoPinPrintNum(noPinPrintNum);
|
||||
|
||||
int[] sketchNumbers = new int[3];
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int designNum = elementVO.getDesignNum();
|
||||
for (int i = 0; i < designNum; i++) {
|
||||
CurrentDesignPictureTypeEnum designPictureType = calculateCurrentDesignPictureTypeNew(elementVO, sketchNumbers, systemScale);
|
||||
if (designPictureType == null) break;
|
||||
|
||||
@@ -261,7 +262,7 @@ public class PythonService {
|
||||
elementVO.setDesignPythonItemPrint(designPythonItemPrint);
|
||||
elementVO.setDesignPrintPictureTypeLayoutList(calculateCurrentDesignPintPictureTypeLayout(elementVO.getModelSex()));
|
||||
|
||||
DesignPythonObject pythonObject = createDesignPythonObject(elementVO, designPictureType, systemScale, singleOverall, switchCategory);
|
||||
DesignPythonObject pythonObject = createDesignPythonObject(elementVO, designPictureType, systemScale, singleOverall, switchCategory, i);
|
||||
objects.add(pythonObject);
|
||||
redisUtil.addProcessId(processId, i + 1);
|
||||
}
|
||||
@@ -296,22 +297,24 @@ public class PythonService {
|
||||
}
|
||||
}
|
||||
|
||||
private DesignPythonObject createDesignPythonObject(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale, String singleOverall, String switchCategory) {
|
||||
private DesignPythonObject createDesignPythonObject(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale, String singleOverall, String switchCategory, int i) {
|
||||
DesignPythonObject pythonObject = new DesignPythonObject();
|
||||
pythonObject.setItems(coverToDesignPythonItemNew(elementVO, designPictureType, systemScale));
|
||||
pythonObject.setBasic(coverToBasic(pythonObject.getItems().get(0), singleOverall, switchCategory, elementVO.getDesignLibraryModelPoint()));
|
||||
pythonObject.setObjectSign(elementVO.getRequestIdList().get(i));
|
||||
return pythonObject;
|
||||
}
|
||||
|
||||
|
||||
private CurrentDesignPictureTypeEnum calculateCurrentDesignPictureTypeNew(ValidateElementVO elementVO, int[] sketchNumbers, BigDecimal systemScale) {
|
||||
List<CollectionElement> pinData = getPinData(elementVO);
|
||||
Integer designNum = elementVO.getDesignNum();
|
||||
if (CollectionUtil.isNotEmpty(pinData)) {
|
||||
return CurrentDesignPictureTypeEnum.PIN;
|
||||
} else {
|
||||
if (sketchNumbers[1] == 0 && sketchNumbers[2] == 0) {
|
||||
sketchNumbers[1] = systemScale.multiply(BigDecimal.valueOf(8 - sketchNumbers[0])).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
|
||||
sketchNumbers[2] = 8 - sketchNumbers[0] - sketchNumbers[1];
|
||||
sketchNumbers[1] = systemScale.multiply(BigDecimal.valueOf(designNum - sketchNumbers[0])).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
|
||||
sketchNumbers[2] = designNum - sketchNumbers[0] - sketchNumbers[1];
|
||||
}
|
||||
if (sketchNumbers[2] > 0 && sketchNumbers[1] > 0) {
|
||||
Long l = RandomsUtil.randomSysFile(0l, 2l);
|
||||
@@ -491,7 +494,7 @@ public class PythonService {
|
||||
}
|
||||
|
||||
//计算print 非Pin图片剩余张数
|
||||
private long calculateDesignNoPinPrintNum(List<CollectionElement> printBoardElements) {
|
||||
private long calculateDesignNoPinPrintNum(List<CollectionElement> printBoardElements, Integer designNum) {
|
||||
if (CollectionUtils.isEmpty(printBoardElements)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -500,10 +503,10 @@ public class PythonService {
|
||||
return 0;
|
||||
} else {
|
||||
long pinNum = printBoardElements.stream().filter(f -> f.getHasPin() == 1).count();
|
||||
if (8 - pinNum < 4) {
|
||||
return RandomsUtil.randomSysFile(0L, 8 - pinNum + 1);
|
||||
if (designNum - pinNum < designNum/2) {
|
||||
return RandomsUtil.randomSysFile(0L, designNum - pinNum + 1);
|
||||
} else {
|
||||
return RandomsUtil.randomSysFile(0L, 4L + 1);
|
||||
return RandomsUtil.randomSysFile(0L, (long) (designNum/2 + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -553,7 +556,7 @@ public class PythonService {
|
||||
if (elementVO.getSingleOverall().equals(SingleOverallEnum.OVERALL.getRealName())) {
|
||||
List<String> otherSketchCategoryList = getOtherSketchCategoryList(elementVO.getModelSex(), designPythonItem);
|
||||
if (!otherSketchCategoryList.isEmpty()) {
|
||||
JSONObject attributeRecognition = getAttributeRecognition(designPythonItem, designPythonItem.getType(), elementVO.getModelSex());
|
||||
JSONObject attributeRecognition = getAttributeRecognition(designPythonItem.getPath(), designPythonItem.getType(), elementVO.getModelSex());
|
||||
for (String styleCategory : otherSketchCategoryList) {
|
||||
DesignPythonItem otherSketch = processAttributeRecognition(attributeRecognition, elementVO, designPictureType, styleCategory, systemScale);
|
||||
itemList.add(otherSketch);
|
||||
@@ -790,7 +793,7 @@ public class PythonService {
|
||||
return attributeRetrieval;
|
||||
}
|
||||
|
||||
public JSONObject getAttributeRecognition(DesignPythonItem designPythonItem, String styleCategory, String modelSex) {
|
||||
public JSONObject getAttributeRecognition(String sketchImgUrl, String styleCategory, String modelSex) {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
@@ -801,7 +804,7 @@ public class PythonService {
|
||||
JSONObject paramJSONObject = new JSONObject();
|
||||
paramJSONObject.put("category", styleCategory);
|
||||
paramJSONObject.put("colony", modelSex);
|
||||
paramJSONObject.put("sketch_img_url", designPythonItem.getPath());
|
||||
paramJSONObject.put("sketch_img_url", sketchImgUrl);
|
||||
JSONArray paramArray = new JSONArray();
|
||||
paramArray.add(paramJSONObject);
|
||||
String param = JSON.toJSONString(paramArray, SerializerFeature.DisableCircularReferenceDetect);
|
||||
@@ -3003,6 +3006,58 @@ public class PythonService {
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
public JSONObject designStream(DesignPythonObjects designPythonObjects) {
|
||||
// todo 限流校验
|
||||
// AccessLimitUtils.validate("design",5);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||
String param = JSON.toJSONString(designPythonObjects, SerializerFeature.DisableCircularReferenceDetect);
|
||||
log.info("design请求python 参数:####{}", param);
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/design_v2")
|
||||
// .url(fastApiPythonAddress + "/api/design")
|
||||
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response;
|
||||
String responseBody;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
AccessLimitUtils.validateOut("design");
|
||||
log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
//去除限流
|
||||
// AccessLimitUtils.validateOut("design");
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
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.error("PythonService##design异常response###{}", response);
|
||||
//生成失败
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂时未用
|
||||
*/
|
||||
@@ -3566,4 +3621,54 @@ public class PythonService {
|
||||
//生成失败
|
||||
throw new BusinessException("bright.interface.exception");
|
||||
}
|
||||
|
||||
public JSONObject attributeRecognition(List<String> pictureUrls,List<String> ids, List<String> category) {
|
||||
//限流校验
|
||||
AccessLimitUtils.validate("attributeRecognition", 20);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(300, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(300, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
Map<String, List<String>> content = Maps.newHashMap();
|
||||
//识别图片路径数组
|
||||
content.put("upload_img_path", pictureUrls);
|
||||
//识别图片id数组
|
||||
content.put("upload_img_id", ids);
|
||||
content.put("upload_img_category", category);
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":9993/api/attribute")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
String bodyStr = null;
|
||||
try {
|
||||
log.info("识别python对应的属性标签值请求入参content###{}", JSON.toJSONString(content));
|
||||
response = client.newCall(request).execute();
|
||||
bodyStr = response.body().string();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService###attributeRecognition异常##{}", ExceptionUtil.getThrowableList(ioException));
|
||||
}
|
||||
log.info("识别python对应的属性标签值结果###{}",bodyStr.trim());
|
||||
//去除限流
|
||||
AccessLimitUtils.validateOut("attributeRecognition");
|
||||
if (Objects.isNull(response)) {
|
||||
log.error("PythonService##attributeRecognition异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("attribute recognition exception!");
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
||||
Boolean result = jsonObject.getBoolean("successful");
|
||||
if (result) {
|
||||
JSONObject attributeJSONObject = JSON.parseObject(bodyStr.trim());
|
||||
return attributeJSONObject;
|
||||
}
|
||||
log.info("识别python对应的属性标签值异常###{}", jsonObject);
|
||||
//生成失败
|
||||
throw new BusinessException("Atribute recognition exception!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,6 @@ public class DesignPythonObject {
|
||||
* basic 选项
|
||||
*/
|
||||
DesignPythonBasic basic;
|
||||
|
||||
private String objectSign;
|
||||
}
|
||||
|
||||
@@ -16,4 +16,6 @@ public class DesignPythonObjects {
|
||||
* design新增的library
|
||||
*/
|
||||
List<Library> addLibrary;
|
||||
|
||||
private String requestId;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.GoogleUser;
|
||||
import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
@@ -11,6 +13,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -182,5 +185,27 @@ public interface AccountService extends IService<Account> {
|
||||
|
||||
void halfPricePromotion();
|
||||
|
||||
String googleCallback(String code, HttpSession session);
|
||||
|
||||
List<String> getPaidCustomerEmail();
|
||||
|
||||
void temporaryUpgrade();
|
||||
|
||||
AccountLoginVO enterpriseLogin(AccountLoginDTO accountDTO);
|
||||
|
||||
AccountLoginVO schoolLogin(AccountLoginDTO accountDTO);
|
||||
|
||||
Boolean addSubAccount(AddSubAccountDTO addSubAccountDTO);
|
||||
|
||||
Boolean deleteSubAccount(AddSubAccountDTO addSubAccountDTO);
|
||||
|
||||
PageBaseResponse<Account> subAccountList(SubAccountPageDTO subAccountPageDTO);
|
||||
|
||||
Account accountDetail(Long id);
|
||||
|
||||
AccountLoginVO parseGoogleCredential(String credential);
|
||||
|
||||
AccountLoginVO parseWeChatCode(String code);
|
||||
|
||||
AccountLoginVO getAccountDetail();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.ai.da.model.vo.DesignCollectionVO;
|
||||
import com.ai.da.model.vo.DesignItemDetailVO;
|
||||
import com.ai.da.model.vo.DesignLikeVO;
|
||||
import com.ai.da.python.vo.DesignPythonObjects;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -25,7 +26,7 @@ public interface DesignService extends IService<Design> {
|
||||
* @param designDTO
|
||||
* @return
|
||||
*/
|
||||
DesignCollectionVO designCollection(DesignCollectionDTO designDTO);
|
||||
String designCollection(DesignCollectionDTO designDTO);
|
||||
|
||||
/**
|
||||
* redesign
|
||||
@@ -33,7 +34,7 @@ public interface DesignService extends IService<Design> {
|
||||
* @param reDesignDTO
|
||||
* @return
|
||||
*/
|
||||
DesignCollectionVO reDesignCollection(ReDesignCollectionDTO reDesignDTO);
|
||||
String reDesignCollection(ReDesignCollectionDTO reDesignDTO);
|
||||
|
||||
/**
|
||||
* redesign
|
||||
@@ -99,4 +100,10 @@ public interface DesignService extends IService<Design> {
|
||||
List<String> getModel(List<Long> designItemIdList);
|
||||
|
||||
Long getCountByUserAndTime(String startTime, String endTime, List<Long> accountIds);
|
||||
|
||||
Boolean receiveDesignResults(JSONObject responseObject);
|
||||
|
||||
DesignCollectionVO getDesignResult(String requestId, List<String> objectSignList);
|
||||
|
||||
String designCloud(DesignCollectionDTO designDTO);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ai.da.mapper.primary.entity.CanvasElementUpload;
|
||||
import com.ai.da.mapper.primary.entity.ToProductImageResult;
|
||||
import com.ai.da.mapper.primary.entity.UserLikeGroup;
|
||||
import com.ai.da.model.dto.ExportSaveDTO;
|
||||
import com.ai.da.model.dto.ProductImageInitializeDTO;
|
||||
import com.ai.da.model.dto.ProductImageLikeDTO;
|
||||
import com.ai.da.model.dto.ToProductImageDTO;
|
||||
import com.ai.da.model.vo.*;
|
||||
@@ -62,4 +63,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
||||
List<MagicToolResultVO> getRelightResult(List<String> taskIdList);
|
||||
|
||||
String likeHistoryRelSketch();
|
||||
|
||||
String download();
|
||||
|
||||
Boolean productImageInitialize(ProductImageInitializeDTO productImageInitializeDTO);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.AuthenticationOperationTypeEnum;
|
||||
import com.ai.da.common.enums.CreditsEventsEnum;
|
||||
import com.ai.da.common.enums.LoginTypeEnum;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.ResultEnum;
|
||||
import com.ai.da.common.security.jwt.JWTTokenHelper;
|
||||
import com.ai.da.common.utils.*;
|
||||
import com.ai.da.mapper.primary.AccountExtendMapper;
|
||||
import com.ai.da.mapper.primary.AccountMapper;
|
||||
import com.ai.da.mapper.primary.QuestionnaireMapper;
|
||||
import com.ai.da.mapper.primary.TrialOrderMapper;
|
||||
@@ -20,11 +22,16 @@ import com.ai.da.model.enums.Language;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
@@ -34,10 +41,12 @@ 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.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.sql.DataSource;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
@@ -62,6 +71,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
@Resource
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
@Resource
|
||||
private AccountExtendMapper accountExtendMapper;
|
||||
|
||||
@Resource
|
||||
private JWTTokenHelper jwtTokenHelper;
|
||||
|
||||
@@ -1387,7 +1399,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
|
||||
private static final String QUERY_MAXIMUM_USERID = "SELECT MAX(ID) AS max_id FROM pmr_users;";
|
||||
|
||||
private static final String QUERY_NEW_USER_EMAIL = "SELECT user_email FROM pmr_users " +
|
||||
private static final String QUERY_NEW_USER_EMAIL = "SELECT user_email, user_nicename FROM pmr_users " +
|
||||
"WHERE ID > ? ";
|
||||
|
||||
@Value("${redis.key.maximumUserId}")
|
||||
@@ -1399,7 +1411,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void registerUserToVisitor(){
|
||||
ArrayList<String> newUserEmails = new ArrayList<>();
|
||||
ArrayList<Map<String, String>> newUsersInfo = new ArrayList<>();
|
||||
ArrayList<String> allEmail = new ArrayList<>();
|
||||
long maxUserId = CommonConstant.MAXIMUM_USER_ID;
|
||||
try (Connection connection = dataSource.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(QUERY_MAXIMUM_USERID)) {
|
||||
@@ -1415,9 +1428,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
// 填充参数 - 历史最大用户ID
|
||||
newUserEmail.setLong(1, maxUserIdHistory);
|
||||
try (ResultSet queryEmailResultSet = newUserEmail.executeQuery()) {
|
||||
if (queryEmailResultSet.next()) {
|
||||
while (queryEmailResultSet.next()) {
|
||||
String email = queryEmailResultSet.getString("user_email");
|
||||
newUserEmails.add(email);
|
||||
String username = queryEmailResultSet.getString("user_nicename");
|
||||
HashMap<String, String> info = new HashMap<>();
|
||||
info.put("email", email);
|
||||
info.put("username", username);
|
||||
newUsersInfo.add(info);
|
||||
allEmail.add(email);
|
||||
} /*else {
|
||||
log.error("未知错误。code-create的用户表中没有付费用户的信息");
|
||||
throw new BusinessException("user info missing");
|
||||
@@ -1432,22 +1450,32 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
// return null;
|
||||
}
|
||||
|
||||
if (!newUserEmails.isEmpty()){
|
||||
if (!newUsersInfo.isEmpty()){
|
||||
// 查询这些邮箱在aida上是否有账号
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("user_email", newUserEmails).select("user_email");
|
||||
queryWrapper.in("user_email", allEmail).select("user_email");
|
||||
|
||||
// 重复的邮箱
|
||||
List<String> collect = baseMapper.selectList(queryWrapper).stream().map(Account::getUserEmail).collect(Collectors.toList());
|
||||
if (!collect.isEmpty()){
|
||||
// 移除Code-Create新增用户中在AiDA已有账号的邮箱
|
||||
newUserEmails.removeAll(collect);
|
||||
// 移除Code-Create新增用户中在AiDA已有账号的邮箱,allEmail中剩余邮箱均为新用户邮箱
|
||||
allEmail.removeAll(collect);
|
||||
if (!allEmail.isEmpty()){
|
||||
for (Map<String,String> userInfo : newUsersInfo){
|
||||
String email = userInfo.get("email");
|
||||
if (!allEmail.contains(email)) {
|
||||
newUsersInfo.remove(userInfo); // 移除不在 allEmail 中的用户
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 将新增用户添加到AiDA,身份为游客
|
||||
if (!newUserEmails.isEmpty()){
|
||||
newUserEmails.forEach(email -> {
|
||||
if (!newUsersInfo.isEmpty()){
|
||||
newUsersInfo.forEach(userInfo -> {
|
||||
Account account = new Account();
|
||||
account.setUserEmail(email);
|
||||
account.setUserName(email);
|
||||
account.setUserEmail(userInfo.get("email"));
|
||||
account.setUserName(userInfo.get("username"));
|
||||
account.setUserPassword("Third-000000");
|
||||
account.setLanguage(Language.ENGLISH.name());
|
||||
account.setValidStartTime(Instant.now().toEpochMilli());
|
||||
@@ -1458,7 +1486,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
account.setSystemUser(0);
|
||||
baseMapper.insert(account);
|
||||
// 邮件通知用户
|
||||
SendEmailUtil.notificationForRegisterUser(email);
|
||||
SendEmailUtil.notificationForRegisterUser(userInfo.get("email"));
|
||||
});
|
||||
}
|
||||
// 记录当前最大的用户id
|
||||
@@ -1849,4 +1877,522 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
log.info("邮箱绑定更改完成,用户id:{},新邮箱:{}", accountId, newMailbox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String googleCallback(String code, HttpSession session) {
|
||||
try {
|
||||
log.info("code: " + code);
|
||||
// 使用 code 获取 Google 用户信息
|
||||
GoogleUser googleUser = getGoogleUserFromCode(code);
|
||||
log.info("googleUser: " + JSON.toJSONString(googleUser));
|
||||
|
||||
// 检查数据库中是否已有该用户
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Account::getUserEmail, googleUser.getEmail()); // 根据邮箱查询用户
|
||||
List<Account> accounts = accountMapper.selectList(queryWrapper);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(accounts)) {
|
||||
// 用户已存在,直接登录
|
||||
session.setAttribute("user", accounts.get(0));
|
||||
return "Login successful";
|
||||
} else {
|
||||
// 用户不存在,创建新用户(自动注册)
|
||||
Account newUser = new Account();
|
||||
newUser.setUserEmail(googleUser.getEmail());
|
||||
newUser.setUserName(googleUser.getName());
|
||||
newUser.setUserPassword("Third-000000");
|
||||
newUser.setLanguage(Language.ENGLISH.name());
|
||||
newUser.setValidStartTime(System.currentTimeMillis());
|
||||
newUser.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
|
||||
newUser.setCreateDate(new Date());
|
||||
newUser.setIsTrial(1);
|
||||
newUser.setIsBeginner(1);
|
||||
newUser.setCredits(BigDecimal.valueOf(100));
|
||||
newUser.setSystemUser(3);
|
||||
accountMapper.insert(newUser);
|
||||
session.setAttribute("user", newUser);
|
||||
|
||||
return "Registration and login successful";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return "Error processing Google login: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TOKEN_URL = "https://oauth2.googleapis.com/token";
|
||||
private static final String USER_INFO_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
|
||||
private static final String CLIENT_ID = "194770296147-njd68pm7tnapgonkj2h48mhf63n15n3f.apps.googleusercontent.com";
|
||||
private static final String CLIENT_SECRET = "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";
|
||||
// private static final String REDIRECT_URI = "https://0551-117-143-125-51.ngrok-free.app/api/third/party/auth/google_callback";
|
||||
private static final String REDIRECT_URI = "https://develop.api.aida.com.hk/api/third/party/auth/google_callback";
|
||||
|
||||
public GoogleUser getGoogleUserFromCode(String code) {
|
||||
// Step 1: Exchange code for access_token
|
||||
String accessToken = getAccessToken(code);
|
||||
log.info("accessToken" + accessToken);
|
||||
|
||||
// Step 2: Use access_token to get Google User info
|
||||
return getGoogleUserInfo(accessToken);
|
||||
}
|
||||
|
||||
private String getAccessToken(String code) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("client_id", CLIENT_ID);
|
||||
params.put("client_secret", CLIENT_SECRET);
|
||||
params.put("redirect_uri", REDIRECT_URI);
|
||||
params.put("grant_type", "authorization_code");
|
||||
params.put("code", code);
|
||||
|
||||
// 使用 RestTemplate 发起请求以获取 access_token
|
||||
GoogleTokenResponse response = restTemplate.postForObject(TOKEN_URL, params, GoogleTokenResponse.class);
|
||||
return response.getAccessToken();
|
||||
}
|
||||
|
||||
private GoogleUser getGoogleUserInfo(String accessToken) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = USER_INFO_URL + "?access_token=" + accessToken;
|
||||
return restTemplate.getForObject(url, GoogleUser.class);
|
||||
}
|
||||
|
||||
// public User findUserByGoogleId(String googleId) {
|
||||
// // 从数据库中根据 Google ID 查找用户
|
||||
// return userRepository.findByGoogleId(googleId);
|
||||
// }
|
||||
|
||||
// public User registerNewUser(GoogleUser googleUser) {
|
||||
// // 创建并保存新用户
|
||||
// User newUser = new User();
|
||||
// newUser.setGoogleId(googleUser.getId());
|
||||
// newUser.setEmail(googleUser.getEmail());
|
||||
// newUser.setUsername(googleUser.getName());
|
||||
// return userRepository.save(newUser);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void temporaryUpgrade() {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().ne(Account::getSystemUser, 0);
|
||||
queryWrapper.lambda().isNotNull(Account::getUserEmail);
|
||||
// queryWrapper.lambda().eq(Account::getId, 6);
|
||||
List<Account> accountList = accountMapper.selectList(queryWrapper);
|
||||
int i = 0;
|
||||
for (Account account : accountList) {
|
||||
if (i >= 0) {
|
||||
try {
|
||||
// 判断用户语言,调用相应邮件发送方法
|
||||
if (Language.CHINESE_SIMPLIFIED.name().equals(account.getLanguage())) {
|
||||
// SendEmailUtil.temporaryUpgrade(account, null, 0);
|
||||
} else {
|
||||
// SendEmailUtil.temporaryUpgrade(account, null, 1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 捕获单个用户的发送失败异常,记录日志但不中断流程
|
||||
log.error("邮件发送失败,用户邮箱:{},原因:{}", account.getUserEmail(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AccountLoginVO enterpriseLogin(AccountLoginDTO accountDTO) {
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Account::getUserName, accountDTO.getUserName());
|
||||
qw.lambda().eq(Account::getOrganizationName, accountDTO.getOrganizationName());
|
||||
List<Account> accounts = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isEmpty(accounts)) {
|
||||
throw new BusinessException("Username or enterprise name incorrect.");
|
||||
}
|
||||
qw.lambda().eq(Account::getUserPassword, accountDTO.getPassword());
|
||||
accounts = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isEmpty(accounts)) {
|
||||
throw new BusinessException("Password error.");
|
||||
}
|
||||
Account account = accounts.get(0);
|
||||
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
|
||||
response.setEmail(account.getUserEmail());
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
} else {
|
||||
response.setToken(createAccountToken(account));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
response.setSystemUser(account.getSystemUser());
|
||||
// 设置头像
|
||||
String avatar;
|
||||
if (StringUtil.isNullOrEmpty(account.getAvatar())){
|
||||
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||
}else {
|
||||
avatar = account.getAvatar();
|
||||
}
|
||||
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
|
||||
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
|
||||
//判断是否常用ip 不是则发邮件提示
|
||||
// calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountLoginVO schoolLogin(AccountLoginDTO accountDTO) {
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Account::getUserName, accountDTO.getUserName());
|
||||
qw.lambda().eq(Account::getOrganizationName, accountDTO.getOrganizationName());
|
||||
List<Account> accounts = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isEmpty(accounts)) {
|
||||
throw new BusinessException("Username or school name incorrect.");
|
||||
}
|
||||
qw.lambda().eq(Account::getUserPassword, accountDTO.getPassword());
|
||||
accounts = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isEmpty(accounts)) {
|
||||
throw new BusinessException("Password error.");
|
||||
}
|
||||
Account account = accounts.get(0);
|
||||
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
|
||||
response.setEmail(account.getUserEmail());
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
} else {
|
||||
response.setToken(createAccountToken(account));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
response.setSystemUser(account.getSystemUser());
|
||||
// 设置头像
|
||||
String avatar;
|
||||
if (StringUtil.isNullOrEmpty(account.getAvatar())){
|
||||
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||
}else {
|
||||
avatar = account.getAvatar();
|
||||
}
|
||||
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
|
||||
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
|
||||
//判断是否常用ip 不是则发邮件提示
|
||||
// calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addSubAccount(AddSubAccountDTO addSubAccountDTO) {
|
||||
if (null == addSubAccountDTO.getId()) {
|
||||
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
||||
Account account = accountMapper.selectById(authPrincipalVo.getId());
|
||||
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Account::getOrganizationName, account.getOrganizationName());
|
||||
List<Account> accounts = accountMapper.selectList(qw);
|
||||
if (accounts.size() >= account.getSubAccountNum()) {
|
||||
throw new BusinessException("The maximum number of sub accounts that can be created has been reached.");
|
||||
}
|
||||
|
||||
qw.lambda().eq(Account::getUserName, addSubAccountDTO.getUserName());
|
||||
accounts = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isNotEmpty(accounts)) {
|
||||
throw new BusinessException("The enterprise already has an account with the same username.");
|
||||
}
|
||||
|
||||
Account subAccount = CopyUtil.copyObject(addSubAccountDTO, Account.class);
|
||||
subAccount.setSystemUser(6);
|
||||
subAccount.setValidStartTime(account.getValidStartTime());
|
||||
subAccount.setValidEndTime(account.getValidEndTime());
|
||||
subAccount.setLanguage(Language.ENGLISH.name());
|
||||
subAccount.setCreateDate(new Date());
|
||||
subAccount.setIsTrial(0);
|
||||
subAccount.setIsBeginner(1);
|
||||
subAccount.setParentId(account.getParentId());
|
||||
accountMapper.insert(subAccount);
|
||||
}else {
|
||||
Account subAccount = CopyUtil.copyObject(addSubAccountDTO, Account.class);
|
||||
accountMapper.updateById(subAccount);
|
||||
}
|
||||
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteSubAccount(AddSubAccountDTO addSubAccountDTO) {
|
||||
accountMapper.deleteBatchIds(addSubAccountDTO.getDeleteIdList());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBaseResponse<Account> subAccountList(SubAccountPageDTO subAccountPageDTO) {
|
||||
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
||||
Account account = accountMapper.selectById(authPrincipalVo);
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().ne(Account::getId, account.getId());
|
||||
qw.lambda().eq(Account::getOrganizationName, account.getOrganizationName());
|
||||
// 执行分页查询
|
||||
IPage<Account> page = accountMapper.selectPage(new Page<>(subAccountPageDTO.getPage(), subAccountPageDTO.getSize()), qw);
|
||||
|
||||
return PageBaseResponse.success(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account accountDetail(Long id) {
|
||||
return accountMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountLoginVO parseGoogleCredential(String credential) {
|
||||
try {
|
||||
// 配置 Google ID Token 验证器
|
||||
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(
|
||||
new NetHttpTransport(),
|
||||
JacksonFactory.getDefaultInstance())
|
||||
.setAudience(Collections.singletonList(CLIENT_ID))
|
||||
.build();
|
||||
|
||||
// 验证并解析 ID Token
|
||||
GoogleIdToken idToken = verifier.verify(credential);
|
||||
|
||||
|
||||
if (idToken != null) {
|
||||
GoogleIdToken.Payload payload = idToken.getPayload();
|
||||
|
||||
// 提取用户信息
|
||||
String userId = payload.getSubject();
|
||||
String email = payload.getEmail();
|
||||
String name = (String) payload.get("name");
|
||||
log.info(userId);
|
||||
log.info(email);
|
||||
log.info(name);
|
||||
|
||||
// 检查数据库中是否已有该用户
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Account::getUserEmail, email); // 根据邮箱查询用户
|
||||
List<Account> accounts = accountMapper.selectList(queryWrapper);
|
||||
Account account = new Account();
|
||||
if (CollectionUtil.isNotEmpty(accounts)) {
|
||||
account = accounts.get(0);
|
||||
} else {
|
||||
// 用户不存在,创建新用户(自动注册)
|
||||
Account newUser = new Account();
|
||||
newUser.setUserEmail(email);
|
||||
newUser.setUserName(name);
|
||||
newUser.setUserPassword("Third-000000");
|
||||
newUser.setLanguage(Language.ENGLISH.name());
|
||||
newUser.setValidStartTime(System.currentTimeMillis());
|
||||
newUser.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
|
||||
newUser.setCreateDate(new Date());
|
||||
newUser.setIsTrial(1);
|
||||
newUser.setIsBeginner(1);
|
||||
newUser.setCredits(BigDecimal.valueOf(100));
|
||||
newUser.setSystemUser(3);
|
||||
accountMapper.insert(newUser);
|
||||
|
||||
account = newUser;
|
||||
}
|
||||
|
||||
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
|
||||
response.setEmail(account.getUserEmail());
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
} else {
|
||||
response.setToken(createAccountToken(account));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
response.setSystemUser(account.getSystemUser());
|
||||
// 设置头像
|
||||
String avatar;
|
||||
if (StringUtil.isNullOrEmpty(account.getAvatar())){
|
||||
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||
}else {
|
||||
avatar = account.getAvatar();
|
||||
}
|
||||
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
|
||||
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
|
||||
return response;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid ID token.");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to verify ID token: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static final String WECHAT_ACCESS_TOKEN_URL =
|
||||
"https://api.weixin.qq.com/sns/oauth2/access_token";
|
||||
|
||||
private static final String APP_ID = "wxcfb92eb28d6385f5";
|
||||
private static final String APP_SECRET = "e5592c691756455b2d03ebfd21fc3131";
|
||||
|
||||
@Override
|
||||
public AccountLoginVO parseWeChatCode(String code) {
|
||||
// 1. 获取 access_token 和 openid
|
||||
JSONObject accessTokenResponse = getAccessTokenFromWeChat(code);
|
||||
String accessToken = accessTokenResponse.getString("access_token");
|
||||
String openId = accessTokenResponse.getString("openid");
|
||||
|
||||
if (StringUtils.isEmpty(accessToken) || StringUtils.isEmpty(openId)) {
|
||||
throw new RuntimeException("微信接口返回数据缺失: " + accessTokenResponse.toJSONString());
|
||||
}
|
||||
|
||||
// 2. 获取用户信息
|
||||
JSONObject userInfoResponse = getUserInfoFromWeChat(accessToken, openId);
|
||||
|
||||
// 提取 unionid 和 nickname
|
||||
String unionId = userInfoResponse.getString("unionid");
|
||||
String userName = userInfoResponse.getString("nickname");
|
||||
if (unionId == null) {
|
||||
throw new IllegalArgumentException("无法获取 unionid,请检查微信开发平台配置");
|
||||
}
|
||||
|
||||
// 检查数据库中是否已有该unionid
|
||||
QueryWrapper<AccountExtend> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(AccountExtend::getAuthType, "WeChat");
|
||||
queryWrapper.lambda().eq(AccountExtend::getAuth, unionId);
|
||||
List<AccountExtend> accountExtends = accountExtendMapper.selectList(queryWrapper);
|
||||
Account account = new Account();
|
||||
if (CollectionUtil.isEmpty(accountExtends)) {
|
||||
AccountExtend accountExtendInsert = new AccountExtend();
|
||||
accountExtendInsert.setAuth(unionId);
|
||||
accountExtendInsert.setAuthType("WeChat");
|
||||
|
||||
// 用户不存在,创建新用户(自动注册)
|
||||
Account newUser = new Account();
|
||||
// newUser.setUserEmail(email);
|
||||
newUser.setUserName(userName);
|
||||
newUser.setUserPassword("Third-000000");
|
||||
newUser.setLanguage(Language.ENGLISH.name());
|
||||
newUser.setValidStartTime(System.currentTimeMillis());
|
||||
newUser.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
|
||||
newUser.setCreateDate(new Date());
|
||||
newUser.setIsTrial(1);
|
||||
newUser.setIsBeginner(1);
|
||||
newUser.setCredits(BigDecimal.valueOf(100));
|
||||
newUser.setSystemUser(3);
|
||||
accountMapper.insert(newUser);
|
||||
|
||||
accountExtendInsert.setAccountId(newUser.getId());
|
||||
accountExtendMapper.insert(accountExtendInsert);
|
||||
|
||||
account = newUser;
|
||||
}else {
|
||||
AccountExtend accountExtend = accountExtends.get(0);
|
||||
account = accountMapper.selectById(accountExtend.getAccountId());
|
||||
}
|
||||
|
||||
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
|
||||
response.setEmail(account.getUserEmail());
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
} else {
|
||||
response.setToken(createAccountToken(account));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
response.setSystemUser(account.getSystemUser());
|
||||
// 设置头像
|
||||
String avatar;
|
||||
if (StringUtil.isNullOrEmpty(account.getAvatar())){
|
||||
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||
}else {
|
||||
avatar = account.getAvatar();
|
||||
}
|
||||
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
|
||||
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
|
||||
return response;
|
||||
|
||||
// // 2. 根据 unionid 检查用户是否存在
|
||||
// User user = userRepository.findByUnionid(unionid);
|
||||
// if (user == null) {
|
||||
// // 用户不存在,进行注册
|
||||
// user = new User();
|
||||
// user.setUnionid(unionid);
|
||||
// user.setOpenid(weChatResponse.getString("openid"));
|
||||
// user.setNickname(weChatResponse.getString("nickname"));
|
||||
// user.setAvatar(weChatResponse.getString("headimgurl"));
|
||||
// userRepository.save(user);
|
||||
// }
|
||||
//
|
||||
// // 3. 返回 unionid
|
||||
// return unionid;
|
||||
}
|
||||
|
||||
private static final String WECHAT_USER_INFO_URL = "https://api.weixin.qq.com/sns/userinfo";
|
||||
private JSONObject getUserInfoFromWeChat(String accessToken, String openId) {
|
||||
// 构造微信用户信息接口的 URL
|
||||
String url = String.format(
|
||||
"%s?access_token=%s&openid=%s&lang=zh_CN",
|
||||
WECHAT_USER_INFO_URL, accessToken, openId
|
||||
);
|
||||
|
||||
// 调用微信接口
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String response = restTemplate.getForObject(url, String.class);
|
||||
|
||||
// 转换为 JSON 对象
|
||||
JSONObject jsonResponse = JSONObject.parseObject(response);
|
||||
if (jsonResponse.containsKey("errcode")) {
|
||||
throw new RuntimeException("微信用户信息接口调用失败: " + jsonResponse.getString("errmsg"));
|
||||
}
|
||||
|
||||
return jsonResponse;
|
||||
}
|
||||
|
||||
private JSONObject getAccessTokenFromWeChat(String code) {
|
||||
// 构造微信接口请求 URL
|
||||
String url = String.format(
|
||||
"%s?appid=%s&secret=%s&code=%s&grant_type=authorization_code",
|
||||
WECHAT_ACCESS_TOKEN_URL, APP_ID, APP_SECRET, code
|
||||
);
|
||||
|
||||
// 调用微信接口
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String response = restTemplate.getForObject(url, String.class);
|
||||
|
||||
// 转换为 JSON 对象
|
||||
JSONObject jsonResponse = JSONObject.parseObject(response);
|
||||
if (jsonResponse.containsKey("errcode")) {
|
||||
throw new RuntimeException("微信接口调用失败: " + jsonResponse.getString("errmsg"));
|
||||
}
|
||||
|
||||
return jsonResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountLoginVO getAccountDetail() {
|
||||
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
||||
Long accountId = authPrincipalVo.getId();
|
||||
Account account = accountMapper.selectById(accountId);
|
||||
|
||||
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
|
||||
response.setEmail(account.getUserEmail());
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
} else {
|
||||
response.setToken(createAccountToken(account));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
response.setSystemUser(account.getSystemUser());
|
||||
// 设置头像
|
||||
String avatar;
|
||||
if (StringUtil.isNullOrEmpty(account.getAvatar())){
|
||||
avatar = CommonConstant.DEFAULT_AVATAR;
|
||||
}else {
|
||||
avatar = account.getAvatar();
|
||||
}
|
||||
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
|
||||
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
|
||||
//判断是否常用ip 不是则发邮件提示
|
||||
// calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,6 +607,12 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, 700, 320, byId.getUrl()));
|
||||
}
|
||||
elementVO.setModelSex(designDTO.getModelSex());
|
||||
elementVO.setRequestIdList(designDTO.getRequestIdList());
|
||||
if (null != designDTO.getDesignNum()) {
|
||||
elementVO.setDesignNum(designDTO.getDesignNum());
|
||||
}else {
|
||||
elementVO.setDesignNum(8);
|
||||
}
|
||||
return elementVO;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -109,8 +110,11 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
private final ConcurrentHashMap<String, Map<String, Object>> designContext = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||
public String designCollection(DesignCollectionDTO designDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
//校验collection element
|
||||
ValidateElementVO elementVO = collectionElementService.validateElement(designDTO);
|
||||
@@ -283,7 +287,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
// return saveDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone());
|
||||
// }
|
||||
|
||||
private DesignCollectionVO designOrRedesignOperateNew(DesignCollectionDTO designDTO, AuthPrincipalVo userInfo,
|
||||
private String designOrRedesignOperateNew(DesignCollectionDTO designDTO, AuthPrincipalVo userInfo,
|
||||
Long collectionIdParam, ValidateElementVO elementVO) {
|
||||
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
|
||||
//编辑sketchBoard
|
||||
@@ -336,7 +340,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
log.info("增加image_id关联运行时间:" + totalTimeInSeconds + " 秒");
|
||||
//design
|
||||
startTime = System.currentTimeMillis();
|
||||
JSONObject responseJSONObject = pythonService.designNew(pythonObjects);
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
pythonObjects.setRequestId(requestId);
|
||||
JSONObject responseJSONObject = pythonService.designStream(pythonObjects);
|
||||
endTime = System.currentTimeMillis();
|
||||
totalTimeInSeconds = (endTime - startTime) / 1000;
|
||||
log.info("design python端运行时间:" + totalTimeInSeconds + " 秒");
|
||||
@@ -350,10 +356,26 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
endTime = System.currentTimeMillis();
|
||||
totalTimeInSeconds = (endTime - startTime) / 1000;
|
||||
log.info("处理关联关系运行时间:" + totalTimeInSeconds + " 秒");
|
||||
|
||||
|
||||
Map<String, Object> context = new HashMap<>();
|
||||
context.put("pythonObjects", pythonObjects); // 转换后的 Python 请求参数
|
||||
context.put("designId", designId); // 设计 ID
|
||||
context.put("collectionId", collectionId); // 集合 ID
|
||||
context.put("userInfo", userInfo); // 用户信息
|
||||
context.put("timeZone", designDTO.getTimeZone()); // 时区
|
||||
context.put("singleOverall", designDTO.getSingleOverall()); // 其他设计参数
|
||||
context.put("requestIdList", elementVO.getRequestIdList());
|
||||
|
||||
// 将上下文存入全局设计上下文中
|
||||
designContext.put(requestId, context);
|
||||
|
||||
//保存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());
|
||||
return requestId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void relationImageId(DesignPythonObjects pythonObjects) {
|
||||
if (Objects.isNull(pythonObjects)) {
|
||||
@@ -601,6 +623,152 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
private DesignCollectionVO savePythonDesignItemAndDetailSingle(DesignPythonObjects pythonObjects, Long designId, Long collectionId, AuthPrincipalVo userInfo, String timeZone, JSONObject outfit, String singleOverall, Map<String, Object> context) {
|
||||
Object designCollectionVO = context.get("DesignCollectionVO");
|
||||
DesignCollectionVO response;
|
||||
List<DesignCollectionItemVO> designCollectionItems = Lists.newArrayList();
|
||||
if (null == designCollectionVO) {
|
||||
response = new DesignCollectionVO();
|
||||
response.setDesignId(designId);
|
||||
response.setCollectionId(collectionId);
|
||||
response.setProcessId(pythonObjects.getProcess_id());
|
||||
}else {
|
||||
response = (DesignCollectionVO) designCollectionVO;
|
||||
designCollectionItems = response.getDesignCollectionItems();
|
||||
}
|
||||
|
||||
response.setDesignCollectionItems(designCollectionItems);
|
||||
|
||||
|
||||
DesignPythonObject item = new DesignPythonObject();
|
||||
String objectSign = outfit.getString("objectSign");
|
||||
log.info(objectSign);
|
||||
for (DesignPythonObject object : pythonObjects.getObjects()) {
|
||||
if (object.getObjectSign().equals(objectSign)) {
|
||||
item = object;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DesignItem designItem = new DesignItem();
|
||||
designItem.setAccountId(userInfo.getId());
|
||||
designItem.setCollectionId(collectionId);
|
||||
designItem.setDesignId(designId);
|
||||
designItem.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
//生成的八张图片
|
||||
designItem.setDesignUrl(item.getBasic().getSave_name());
|
||||
designItem.setHasLike((byte) 0);
|
||||
//生成designItem
|
||||
Long designItemId = designItemService.saveOne(designItem);
|
||||
// python design返回入库及封装
|
||||
// JSONObject outfit = data.getJSONObject(i + "");
|
||||
// if (null == outfit) {
|
||||
// continue;
|
||||
// }
|
||||
TDesignPythonOutfit designPythonOutfit = new TDesignPythonOutfit();
|
||||
designPythonOutfit.setDesignItemId(designItemId);
|
||||
designPythonOutfit.setUserId(userInfo.getId());
|
||||
designPythonOutfit.setDesignId(designId);
|
||||
designPythonOutfit.setCollectionId(collectionId);
|
||||
String synthesisUrl = outfit.getString("synthesis_url");
|
||||
if (!StringUtils.isEmpty(synthesisUrl)) {
|
||||
designPythonOutfit.setDesignUrl(synthesisUrl);
|
||||
} else {
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
designPythonOutfitService.save(designPythonOutfit);
|
||||
|
||||
JSONArray layers = outfit.getJSONArray("layers");
|
||||
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
|
||||
DesignCollectionItemVO designCollectionItemVO = new DesignCollectionItemVO();
|
||||
designCollectionItemVO.setObjectSign(objectSign);
|
||||
for (int i1 = 0; i1 < layers.size(); i1++) {
|
||||
JSONObject jsonObject = layers.getJSONObject(i1);
|
||||
TDesignPythonOutfitDetail designPythonOutfitDetail = new TDesignPythonOutfitDetail();
|
||||
designPythonOutfitDetail.setDesignId(designId);
|
||||
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfit.getId());
|
||||
designPythonOutfitDetail.setPosition(jsonObject.getString("position"));
|
||||
designPythonOutfitDetail.setImageSize(jsonObject.getString("image_size"));
|
||||
designPythonOutfitDetail.setImageUrl(jsonObject.getString("image_url"));
|
||||
if (singleOverall.equals(SingleOverallEnum.SINGLE.getRealName())) {
|
||||
designCollectionItemVO.setDesignItemUrl(designItem.getDesignUrl());
|
||||
}
|
||||
designPythonOutfitDetail.setImageCategory(jsonObject.getString("image_category"));
|
||||
designPythonOutfitDetail.setMaskUrl(jsonObject.getString("mask_url"));
|
||||
designPythonOutfitDetail.setUserId(userInfo.getId());
|
||||
designPythonOutfitDetail.setPriority(Integer.parseInt(jsonObject.getString("priority")));
|
||||
designPythonOutfitDetail.setCreateDate(LocalDateTime.now());
|
||||
list.add(designPythonOutfitDetail);
|
||||
}
|
||||
designPythonOutfitDetailService.saveBatch(list);
|
||||
designCollectionItemVO.setDesignItemId(designItemId);
|
||||
designCollectionItemVO.setDesignItemUrl(designItem.getDesignUrl());
|
||||
designCollectionItemVO.setDesignOutfitId(designPythonOutfit.getId());
|
||||
String designUrl = designPythonOutfit.getDesignUrl();
|
||||
if (!StringUtils.isEmpty(designUrl) && designUrl.contains("/")) {
|
||||
int firstIndex = designUrl.indexOf("/");
|
||||
designCollectionItemVO.setDesignOutfitUrl(minioUtil.getPreSignedUrl(designUrl.substring(0, firstIndex) + "/" + designUrl.substring(firstIndex + 1), 24 * 60));
|
||||
}
|
||||
//response
|
||||
designCollectionItems.add(designCollectionItemVO);
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
Map<String, Integer> typePriority = list.stream().collect(Collectors.toMap(d -> d.getImageCategory().split("_")[0],
|
||||
d -> Math.abs(d.getPriority()),
|
||||
(existing, replacement) -> replacement));
|
||||
Map<String, String> typeAndUndividedLayer = designItemService.setTypeAndUndividedLayer(layers);
|
||||
for (DesignPythonItem detail : item.getItems()) {
|
||||
if (null == detail) {
|
||||
continue;
|
||||
}
|
||||
DesignItemDetail designItemDetail = CopyUtil.copyObject(detail, DesignItemDetail.class);
|
||||
designItemDetail.setAccountId(userInfo.getId());
|
||||
designItemDetail.setDesignId(designId);
|
||||
designItemDetail.setDesignItemId(designItemId);
|
||||
designItemDetail.setCollectionElementId(detail.getElementId());
|
||||
designItemDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
designItemDetail.setUndividedLayer(typeAndUndividedLayer.get(designItemDetail.getType().toLowerCase()));
|
||||
if (SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType())) {
|
||||
designItemDetail.setPath(detail.getBody_path());
|
||||
//BODY不关联businessId
|
||||
designItemDetail.setBusinessId(0L);
|
||||
}
|
||||
designItemDetail.setIconPath(detail.getIcon());
|
||||
designItemDetail.setPriority(typePriority.get(detail.getType().toLowerCase()));
|
||||
if (!detail.getType().equals("Body")){
|
||||
DesignPythonItemPrint printObject = detail.getPrint().getOverall();
|
||||
// designItemDetail.setPrintPath(Objects.isNull(printObject) ? "" : printObject.getPath());
|
||||
designItemDetail.setPrintPath(CollectionUtils.isEmpty(printObject.getPrint_path_list()) ? "" : printObject.getPrint_path_list().get(0));
|
||||
}
|
||||
designItemDetailService.save(designItemDetail);
|
||||
if (!SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType()) && !StringUtil.isNullOrEmpty(designItemDetail.getPrintPath())) {
|
||||
DesignItemDetailPrint print = new DesignItemDetailPrint();
|
||||
print.setDesignItemDetailId(designItemDetail.getId());
|
||||
print.setPrintType("print");
|
||||
print.setPath(designItemDetail.getPrintPath());
|
||||
print.setSingleOrOverall("overall");
|
||||
print.setPosition("[0.0,0.0]");
|
||||
// print.setScale(1d);
|
||||
// todo mark 将print默认scale置为0.3
|
||||
print.setScale(0.3d);
|
||||
print.setAngle(0.0);
|
||||
print.setPriority(1);
|
||||
QueryWrapper<CollectionElement> getPrintboardLevel2TypeQw = new QueryWrapper<>();
|
||||
getPrintboardLevel2TypeQw.lambda().eq(CollectionElement::getUrl, print.getPath());
|
||||
getPrintboardLevel2TypeQw.lambda().orderByDesc(CollectionElement::getCreateDate);
|
||||
getPrintboardLevel2TypeQw.last("limit 1");
|
||||
CollectionElement one = collectionElementService.getOne(getPrintboardLevel2TypeQw);
|
||||
print.setLevel2Type(one.getLevel2Type());
|
||||
print.setCreateDate(LocalDateTime.now());
|
||||
designItemDetailPrintService.save(print);
|
||||
}
|
||||
}
|
||||
synchronized (context) {
|
||||
context.put("DesignCollectionVO", response);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
private DesignCollectionVO savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
, Long designId, Long collectionId, AuthPrincipalVo userInfo, String timeZone, JSONObject responseJSONObject, String singleOverall) {
|
||||
DesignCollectionVO response = new DesignCollectionVO();
|
||||
@@ -612,6 +780,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
if (data == null) {
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
for (int i = 0; i < pythonObjects.getObjects().size(); i++) {
|
||||
DesignPythonObject item = pythonObjects.getObjects().get(i);
|
||||
DesignItem designItem = new DesignItem();
|
||||
@@ -641,6 +810,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
designPythonOutfitService.save(designPythonOutfit);
|
||||
|
||||
JSONArray layers = outfit.getJSONArray("layers");
|
||||
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
|
||||
DesignCollectionItemVO designCollectionItemVO = new DesignCollectionItemVO();
|
||||
@@ -750,7 +920,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
//生成designItem
|
||||
Long designItemId = designItemService.saveOne(designItem);
|
||||
//response
|
||||
designCollectionItems.add(new DesignCollectionItemVO(designItemId, designItem.getDesignUrl(), null, null));
|
||||
designCollectionItems.add(new DesignCollectionItemVO(designItemId, designItem.getDesignUrl(), null, null, null));
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
item.getItems().forEach(detail -> {
|
||||
@@ -797,7 +967,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public DesignCollectionVO reDesignCollection(ReDesignCollectionDTO reDesignDTO) {
|
||||
public String reDesignCollection(ReDesignCollectionDTO reDesignDTO) {
|
||||
//校验collection
|
||||
Collection collection = collectionService.getById(reDesignDTO.getCollectionId());
|
||||
if (Objects.isNull(collection)) {
|
||||
@@ -849,15 +1019,15 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
}
|
||||
List<DesignItem> designItems = designItemService.getByDesignId(designId);
|
||||
if (CollectionUtils.isEmpty(designItems)) {
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), null, null);
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), null, null, null);
|
||||
}
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), coverDesignItemToVO(designItems), null);
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), coverDesignItemToVO(designItems), null, null);
|
||||
}
|
||||
|
||||
private List<DesignCollectionItemVO> coverDesignItemToVO(List<DesignItem> designItems) {
|
||||
List<DesignCollectionItemVO> response = Lists.newArrayList();
|
||||
designItems.forEach(designItem -> {
|
||||
response.add(new DesignCollectionItemVO(designItem.getId(), designItem.getDesignUrl(), null, null));
|
||||
response.add(new DesignCollectionItemVO(designItem.getId(), designItem.getDesignUrl(), null, null, null));
|
||||
});
|
||||
return response;
|
||||
}
|
||||
@@ -1389,4 +1559,62 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean receiveDesignResults(JSONObject responseJSONObject) {
|
||||
String requestId = "UUID.randomUUID().toString()";
|
||||
// String requestId = responseJSONObject.getString("requestId");
|
||||
Map<String, Object> context;
|
||||
synchronized (designContext) {
|
||||
log.info(designContext.toString());
|
||||
context = designContext.get(requestId);
|
||||
if (context == null) {
|
||||
log.error("上下文数据缺失,无法完成操作");
|
||||
return false;
|
||||
}
|
||||
|
||||
DesignPythonObjects pythonObjects = (DesignPythonObjects) context.get("pythonObjects");
|
||||
Long designId = (Long) context.get("designId");
|
||||
Long collectionId = (Long) context.get("collectionId");
|
||||
AuthPrincipalVo userInfo = (AuthPrincipalVo) context.get("userInfo");
|
||||
String timeZone = (String) context.get("timeZone");
|
||||
String singleOverall = (String) context.get("singleOverall");
|
||||
|
||||
DesignCollectionVO designCollectionVO = savePythonDesignItemAndDetailSingle(pythonObjects, designId, collectionId, userInfo, timeZone, responseJSONObject, singleOverall, context);
|
||||
|
||||
log.info(designContext.toString());
|
||||
designContext.put(requestId, context);
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DesignCollectionVO getDesignResult(String requestId, List<String> objectSignList) {
|
||||
// Map<String, Object> stringObjectMap = designContext.get("UUID.randomUUID().toString()");
|
||||
Map<String, Object> stringObjectMap = designContext.get(requestId);
|
||||
log.info(stringObjectMap.toString());
|
||||
DesignCollectionVO result = (DesignCollectionVO) stringObjectMap.get("DesignCollectionVO");
|
||||
if (Objects.isNull(result)) {
|
||||
DesignCollectionVO noneResult = new DesignCollectionVO();
|
||||
noneResult.setUnfinishedList(objectSignList);
|
||||
return noneResult;
|
||||
}
|
||||
for (DesignCollectionItemVO designCollectionItem : result.getDesignCollectionItems()) {
|
||||
String objectSign = designCollectionItem.getObjectSign();
|
||||
objectSignList.remove(objectSign);
|
||||
}
|
||||
result.setUnfinishedList(objectSignList);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String designCloud(DesignCollectionDTO designDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
//校验collection element
|
||||
ValidateElementVO elementVO = collectionElementService.validateElement(designDTO);
|
||||
//design
|
||||
return designOrRedesignOperateNew(designDTO, userInfo, null, elementVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -150,6 +150,14 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
String port = generateServicePort;
|
||||
String jsonString = "";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
String version = null;
|
||||
if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){
|
||||
version = "high";
|
||||
params.put("version","high");
|
||||
}else if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("fast")){
|
||||
version = "fast";
|
||||
params.put("version","fast");
|
||||
}
|
||||
// 3.1 确定不同类型的印花分别调哪个接口
|
||||
if (generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName())) {
|
||||
switch (generateThroughImageTextDTO.getLevel2Type()) {
|
||||
@@ -171,15 +179,16 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
break;
|
||||
case "Pattern":
|
||||
GenerateToPythonDTO generateToPythonDTO = new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
|
||||
mode, category, generateThroughImageTextDTO.getGender());
|
||||
mode, category, generateThroughImageTextDTO.getGender(), version);
|
||||
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
||||
}
|
||||
} else {
|
||||
GenerateToPythonDTO generateToPythonDTO = new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
|
||||
mode, category, generateThroughImageTextDTO.getGender());
|
||||
mode, category, generateThroughImageTextDTO.getGender(), version);
|
||||
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
||||
}
|
||||
|
||||
|
||||
Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, port, path);
|
||||
|
||||
// 4、将请求信息落库,将本次generate的请求信息添加到t_generate表中
|
||||
@@ -325,7 +334,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
// generate.setText(text);
|
||||
break;
|
||||
case "Sketchboard":
|
||||
text = "clear lines, simple outlines monochrome white vector image of " + translated + ", no background, sketch flat, front view display, best quality, ultra-high resolution 8k";
|
||||
// text = "clear lines, simple outlines monochrome white vector image of " + translated + ", no background, sketch flat, front view display, best quality, ultra-high resolution 8k";
|
||||
text = "a single item of sketch of " + translated + ", 4k, white background";
|
||||
// generate.setText(text);
|
||||
default:
|
||||
}
|
||||
@@ -498,6 +508,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
// 校验后获取
|
||||
generateThroughImageTextDTO.setGenerateType(generate.getGenerateType());
|
||||
creditsEventsEnum = CreditsEventsEnum.PATTERN;
|
||||
|
||||
// 模型迁移SD1.? -> flux,从而产生了不同模型的选择,
|
||||
// high -> 生成图片质量高,但生成速度慢,每次生成只返回一张图片
|
||||
// fast -> 生成图片质量低,但生成速度快,每次生成返回四张图片
|
||||
if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){
|
||||
times = 1;
|
||||
}
|
||||
}
|
||||
// Slogan 参数校验
|
||||
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.SLOGAN.getRealName())) {
|
||||
@@ -554,8 +571,14 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
}
|
||||
} else if (generateThroughImageTextDTO.getLevel1Type().equals(MOOD_BOARD.getRealName())) {
|
||||
creditsEventsEnum = CreditsEventsEnum.MOOD_BOARD;
|
||||
if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){
|
||||
times = 1;
|
||||
}
|
||||
} else if (generateThroughImageTextDTO.getLevel1Type().equals(SKETCH_BOARD.getRealName())) {
|
||||
creditsEventsEnum = CreditsEventsEnum.SKETCH_BOARD;
|
||||
if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){
|
||||
times = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 2、判断用户当前积分是否够本次生成消耗
|
||||
@@ -567,6 +590,11 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
// 3、生成唯一id 使用uuid,由于uuid重复的几率很小,故取消对uuid重复性的校验
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
// 除了 Moodboard || Printboard->Pattern(可以区分三种风格) || Sketchboard(Generate Sketch)这三个地方需要区分high || fast之外,其他地方保持原样
|
||||
if (generateThroughImageTextDTO.getLevel1Type().equals("Printboard") && !generateThroughImageTextDTO.getLevel2Type().equals("Pattern")){
|
||||
generateThroughImageTextDTO.setVersion(null);
|
||||
}
|
||||
|
||||
ArrayList<String> taskIdList = new ArrayList<>();
|
||||
for (int i = 1; i <= times; i++) {
|
||||
String temp = uuid;
|
||||
|
||||
@@ -204,11 +204,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
String jsonString = JSON.toJSONString(resp);
|
||||
// log.info("消息推送 : {}", jsonString);
|
||||
|
||||
try {
|
||||
notificationConnection.sendMsg(jsonString, receiverId);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
notificationConnection.sendMsg(jsonString, receiverId);
|
||||
}
|
||||
|
||||
// 取消点赞、删除评论、取消关注
|
||||
|
||||
@@ -9,14 +9,18 @@ import com.ai.da.common.utils.*;
|
||||
import com.ai.da.mapper.primary.*;
|
||||
import com.ai.da.mapper.primary.entity.*;
|
||||
import com.ai.da.mapper.secondary.AttributeRetrievalMapper;
|
||||
import com.ai.da.mapper.secondary.entity.AttributeRecognitionJSON;
|
||||
import com.ai.da.model.dto.PortfolioDTO;
|
||||
import com.ai.da.model.dto.ProductImageInitializeDTO;
|
||||
import com.ai.da.model.dto.ProductImageLikeDTO;
|
||||
import com.ai.da.model.dto.ToProductImageDTO;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -30,13 +34,14 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.hutool.poi.excel.sax.AttributeName.s;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
@@ -79,6 +84,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
private CollectionElementMapper collectionElementMapper;
|
||||
@Resource
|
||||
private AttributeRetrievalMapper attributeRetrievalMapper;
|
||||
@Resource
|
||||
private ProductImageAttributeMapper productImageAttributeMapper;
|
||||
|
||||
@Override
|
||||
public void deleteUserGroup(Long userGroupId) {
|
||||
@@ -258,25 +265,47 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
int i = 0;
|
||||
// 翻译
|
||||
String prompt = toProductImageDTO.getPrompt();
|
||||
String s = "";
|
||||
StringBuilder sb = new StringBuilder("The best quality, masterpiece, real image.");
|
||||
if (!StringUtil.isNullOrEmpty(prompt)) {
|
||||
s = pythonService.promptTranslate(prompt);
|
||||
}else {
|
||||
s = "best quality, masterpiece. detailed, high-res, simple background, studio photography, extremely detailed, updo, detailed face, face, close-up, HDR, UHD, 8K realistic, Highly detailed, simple background, Studio lighting";
|
||||
prompt = pythonService.promptTranslate(prompt);
|
||||
}
|
||||
// else {
|
||||
// s = "best quality, masterpiece. detailed, high-res, simple background, studio photography, extremely detailed, updo, detailed face, face, close-up, HDR, UHD, 8K realistic, Highly detailed, simple background, Studio lighting";
|
||||
// }
|
||||
for (ToProductImageVO toProductImageVO : toProductImageDTO.getToProductImageVOList()) {
|
||||
String taskId;
|
||||
if (toProductImageVO.getElementType().equals("DesignOutfit")) {
|
||||
taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
|
||||
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageVO.getElementId());
|
||||
|
||||
Long designItemId = tDesignPythonOutfit.getDesignItemId();
|
||||
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
|
||||
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemId);
|
||||
designItemDetailQueryWrapper.lambda().ne(DesignItemDetail::getType, "Body");
|
||||
List<DesignItemDetail> designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
|
||||
String collect = designItemDetails.stream().map(DesignItemDetail::getType).collect(Collectors.joining(","));
|
||||
|
||||
Long designId = tDesignPythonOutfit.getDesignId();
|
||||
Design design = designMapper.selectById(designId);
|
||||
String productType = "overall";
|
||||
if (design.getSingleOverall().equals("single")) {
|
||||
productType = "single";
|
||||
sb.append(collect);
|
||||
}else {
|
||||
if (collect.contains("Tops")) {
|
||||
sb.append("a handsome man,");
|
||||
}else {
|
||||
sb.append("a beautiful women,");
|
||||
}
|
||||
sb.append("wearing ").append(collect);
|
||||
}
|
||||
if (StringUtils.isEmpty(prompt)) {
|
||||
sb.append(",8K realistic,HDR");
|
||||
}else {
|
||||
sb.append(",").append(prompt).append(",8K realistic,HDR");
|
||||
}
|
||||
// 走模型
|
||||
pythonService.toProductImage(tDesignPythonOutfit.getDesignUrl(), taskId, s, toProductImageDTO.getImageStrength(), productType);
|
||||
pythonService.toProductImage(tDesignPythonOutfit.getDesignUrl(), taskId, sb.toString(), toProductImageDTO.getImageStrength(), productType);
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
toProductImageResult.setElementId(tDesignPythonOutfit.getId());
|
||||
toProductImageResult.setElementType("DesignOutfit");
|
||||
@@ -290,10 +319,16 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
||||
result.add(toProductImageResult);
|
||||
}else {
|
||||
if (StringUtils.isEmpty(prompt)) {
|
||||
sb.append(",8K realistic,HDR");
|
||||
}else {
|
||||
sb.append(",").append(prompt).append(",8K realistic,HDR");
|
||||
}
|
||||
|
||||
taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
|
||||
// 走模型
|
||||
pythonService.toProductImage(toProductElement.getUrl(), taskId, s, toProductImageDTO.getImageStrength(), "overall");
|
||||
pythonService.toProductImage(toProductElement.getUrl(), taskId, sb.toString(), toProductImageDTO.getImageStrength(), "overall");
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
toProductImageResult.setElementId(toProductElement.getId());
|
||||
toProductImageResult.setElementType("ProductElement");
|
||||
@@ -611,67 +646,150 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
public String likeHistoryRelSketch() {
|
||||
QueryWrapper<UserLikeGroup> qw = new QueryWrapper<>();
|
||||
List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(qw);
|
||||
Map<Long, List<List<Map<String, Object>>>> result = new HashMap<>();
|
||||
List<List<Map<String, Object>>> result = new ArrayList<>();
|
||||
|
||||
for (UserLikeGroup userLikeGroup : userLikeGroups) {
|
||||
Long accountId = userLikeGroup.getAccountId();
|
||||
Long collectionId = userLikeGroup.getCollectionId();
|
||||
|
||||
QueryWrapper<CollectionElement> collectionElementQueryWrapper = new QueryWrapper<>();
|
||||
collectionElementQueryWrapper.lambda().eq(CollectionElement::getCollectionId, collectionId);
|
||||
collectionElementQueryWrapper.lambda().eq(CollectionElement::getLevel1Type, "Sketchboard");
|
||||
List<CollectionElement> collectionElements = collectionElementMapper.selectList(collectionElementQueryWrapper);
|
||||
List<String> urlList = collectionElements.stream().map(CollectionElement::getUrl).collect(Collectors.toList());
|
||||
// 提前转换为Set以提高contains的效率
|
||||
List<CollectionElement> collectionElements = getCollectionElementsByCollectionId(collectionId);
|
||||
Set<String> urlSet = collectionElements.stream()
|
||||
.map(CollectionElement::getUrl)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
QueryWrapper<UserLike> userLikeQueryWrapper = new QueryWrapper<>();
|
||||
userLikeQueryWrapper.lambda().eq(UserLike::getUserLikeGroupId, userLikeGroup.getId());
|
||||
List<UserLike> userLikes = userLikeMapper.selectList(userLikeQueryWrapper);
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
List<UserLike> userLikes = getUserLikesByGroupId(userLikeGroup.getId());
|
||||
|
||||
for (UserLike userLike : userLikes) {
|
||||
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
|
||||
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, userLike.getDesignItemId());
|
||||
designItemDetailQueryWrapper.lambda().ne(DesignItemDetail::getType, "Body");
|
||||
List<DesignItemDetail> designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
|
||||
Map<String, Object> sketch = new HashMap<>();
|
||||
List<Map<String, Object>> userLikeSketchList = new ArrayList<>();
|
||||
List<DesignItemDetail> designItemDetails = getDesignItemDetails(userLike.getDesignItemId());
|
||||
|
||||
for (DesignItemDetail designItemDetail : designItemDetails) {
|
||||
Map<String, Object> sketch = new HashMap<>();
|
||||
String path = designItemDetail.getPath();
|
||||
|
||||
// 下载路径到本地
|
||||
// if (!StringUtils.isEmpty(path)) {
|
||||
// String bucketName = minioUtil.getBucketNameFromPath(path);
|
||||
// String objectName = minioUtil.getObjectNameFromPath(path);
|
||||
// String localBasePath = "C:\\workspace\\fileData\\minio";
|
||||
// String localFilePath = Paths.get(localBasePath, path).toString();
|
||||
//
|
||||
// // 检查文件是否已经存在,避免重复下载
|
||||
// File localFile = new File(localFilePath);
|
||||
// if (!localFile.exists()) {
|
||||
// minioUtil.downloadMinioObjectToLocal(bucketName, objectName, localFilePath);
|
||||
// } else {
|
||||
// log.info("File already exists, skipping download: {}", localFilePath);
|
||||
// }
|
||||
// }
|
||||
|
||||
Long designId = designItemDetail.getDesignId();
|
||||
Design design = designMapper.selectById(designId);
|
||||
if (null == design) {
|
||||
continue;
|
||||
}
|
||||
if (design.getSingleOverall().equals("single")) {
|
||||
continue;
|
||||
}
|
||||
if (design.getModelType().equals("System")) {
|
||||
SysFile sysFile = sysFileMapper.selectById(design.getTemplateId());
|
||||
if (null == sysFile) {
|
||||
continue;
|
||||
}
|
||||
sketch.put("sex", sysFile.getLevel2Type().equals("Male") ? "Male" : "Female");
|
||||
} else {
|
||||
Library library = libraryMapper.selectById(design.getTemplateId());
|
||||
if (null == library) {
|
||||
continue;
|
||||
}
|
||||
sketch.put("sex", library.getLevel2Type().equals("Female") ? "Female" : "Male");
|
||||
}
|
||||
|
||||
sketch.put("type", designItemDetail.getType());
|
||||
sketch.put("path", path);
|
||||
if (urlList.contains(path)) {
|
||||
sketch.put("beSelected", true);
|
||||
}else {
|
||||
sketch.put("beSelected", false);
|
||||
}
|
||||
sketch.put("beSelected", urlSet.contains(path));
|
||||
sketch.put("accountId", accountId);
|
||||
|
||||
if (path.contains("aida-sys-image/images/")) {
|
||||
String searchPath = new String(path);
|
||||
String replace = searchPath.replace("aida-sys-image/images/", "");
|
||||
String replace = path.replace("aida-sys-image/images/", "");
|
||||
String style = getStyleByUrl(replace);
|
||||
if (!StringUtils.isEmpty(style)) {
|
||||
sketch.put("style", style);
|
||||
}
|
||||
}
|
||||
userLikeSketchList.add(sketch);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(userLikeSketchList)) {
|
||||
result.add(userLikeSketchList);
|
||||
}
|
||||
list.add(sketch);
|
||||
}
|
||||
if (result.containsKey(accountId)) {
|
||||
result.get(accountId).add(list);
|
||||
}else {
|
||||
List<List<Map<String, Object>>> lists = new ArrayList<>();
|
||||
lists.add(list);
|
||||
result.put(accountId, lists);
|
||||
}
|
||||
}
|
||||
System.out.println(JSONObject.toJSONString(result));
|
||||
|
||||
// 将结果以美观的JSON形式保存到文件中
|
||||
saveResultAsPrettyJson(result, "C:\\Users\\10233\\Desktop\\result.json");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String download() {
|
||||
// 下载 aida-collection-element bucket 下所有 Sketchboard 文件夹内容
|
||||
// String sketchboardLocalPath = "C:\\workspace\\fileData\\minio";
|
||||
// minioUtil.downloadSketchboardDirectories(sketchboardLocalPath);
|
||||
//
|
||||
// // 下载整个 aida-users bucket
|
||||
// String aidaUsersLocalPath = "C:\\workspace\\fileData\\minio";
|
||||
// minioUtil.downloadEntireBucket("aida-users", aidaUsersLocalPath);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 提取公共方法
|
||||
private List<CollectionElement> getCollectionElementsByCollectionId(Long collectionId) {
|
||||
QueryWrapper<CollectionElement> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(CollectionElement::getCollectionId, collectionId)
|
||||
.eq(CollectionElement::getLevel1Type, "Sketchboard");
|
||||
return collectionElementMapper.selectList(qw);
|
||||
}
|
||||
|
||||
private List<UserLike> getUserLikesByGroupId(Long groupId) {
|
||||
QueryWrapper<UserLike> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(UserLike::getUserLikeGroupId, groupId);
|
||||
return userLikeMapper.selectList(qw);
|
||||
}
|
||||
|
||||
private List<DesignItemDetail> getDesignItemDetails(Long designItemId) {
|
||||
QueryWrapper<DesignItemDetail> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(DesignItemDetail::getDesignItemId, designItemId)
|
||||
.ne(DesignItemDetail::getType, "Body");
|
||||
return designItemDetailMapper.selectList(qw);
|
||||
}
|
||||
|
||||
private void saveResultAsPrettyJson(List<List<Map<String, Object>>> result, String filePath) {
|
||||
// 使用一个 Map<String, Object> 将结果存储为字符串键
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("data", result);
|
||||
|
||||
try (FileWriter file = new FileWriter(filePath)) {
|
||||
// 使用 JSONObject 将转换后的 Map 转为 JSON
|
||||
JSONObject jsonObject = new JSONObject(resultMap);
|
||||
// 格式化输出为美观的 JSON
|
||||
file.write(JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private String getStyleByUrl(String replace) {
|
||||
String[] split = replace.split("/");
|
||||
String tableName = getTableName(split);
|
||||
if (StringUtils.isEmpty(tableName)) {
|
||||
return null;
|
||||
}else {
|
||||
replace = split[1] + "/" + split[2];
|
||||
return attributeRetrievalMapper.getStyleByUrl(replace, tableName);
|
||||
}
|
||||
}
|
||||
@@ -721,4 +839,53 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Boolean productImageInitialize(ProductImageInitializeDTO productImageInitializeDTO) {
|
||||
|
||||
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
||||
accountService.getById(authPrincipalVo.getId());
|
||||
|
||||
for (Long libraryId : productImageInitializeDTO.getLibraryIds()) {
|
||||
Library library = libraryMapper.selectById(libraryId);
|
||||
String url = library.getUrl();
|
||||
String gender = library.getLevel2Type();
|
||||
|
||||
String clothCategory = pythonService.getClothCategory(url, gender);
|
||||
JSONObject attributeRecognition = pythonService.getAttributeRecognition(url, clothCategory, gender);
|
||||
JSONObject data = attributeRecognition.getJSONObject("data");
|
||||
JSONObject attrDict = ((JSONObject) data.getJSONArray("list").get(0)).getJSONObject("attr_dict");
|
||||
AttributeRecognitionJSON attrDictJSON = attrDict.toJavaObject(AttributeRecognitionJSON.class);
|
||||
ProductImageAttribute productImageAttribute = toAttrDict(attrDictJSON);
|
||||
productImageAttributeMapper.insert(productImageAttribute);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ProductImageAttribute toAttrDict(AttributeRecognitionJSON attrDictJSON) {
|
||||
ProductImageAttribute attributeRetrieval = new ProductImageAttribute();
|
||||
// attributeRetrieval.setImgName(attrDictJSON.getImgName().get(0));
|
||||
// attributeRetrieval.setLength(attrDictJSON.getLength().get(0));
|
||||
// attributeRetrieval.setSleeveLength(attrDictJSON.getSleeveLength().get(0));
|
||||
// attributeRetrieval.setSleeveShape(attrDictJSON.getSleeveShape().get(0));
|
||||
// attributeRetrieval.setSleeveShoulder(attrDictJSON.getSleeveShoulder().get(0));
|
||||
// attributeRetrieval.setNeckline(attrDictJSON.getNeckline().get(0));
|
||||
// attributeRetrieval.setCollar(attrDictJSON.getCollar().get(0));
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getDesign()) && attrDictJSON.getDesign().get(0) != null) {
|
||||
attributeRetrieval.setDesign(attrDictJSON.getDesign().get(0));
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getSilhouette()) && attrDictJSON.getSilhouette().get(0) != null) {
|
||||
attributeRetrieval.setSilhouette(attrDictJSON.getSilhouette().get(0));
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getType()) && attrDictJSON.getType().get(0) != null) {
|
||||
attributeRetrieval.setType(attrDictJSON.getType().get(0));
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getSubtype()) && attrDictJSON.getSubtype().get(0) != null) {
|
||||
attributeRetrieval.setSubtype(attrDictJSON.getSubtype().get(0));
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getOpeningType()) && attrDictJSON.getOpeningType().get(0) != null) {
|
||||
attributeRetrieval.setOpeningType(attrDictJSON.getOpeningType().get(0));
|
||||
}
|
||||
return attributeRetrieval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#spring.profiles.active=test
|
||||
|
||||
#<23><><EFBFBD><EFBFBD>application-prod<6F>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
spring.profiles.active=prod
|
||||
#spring.profiles.active=prod
|
||||
|
||||
#<23><><EFBFBD><EFBFBD>application-dev<65>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
#spring.profiles.active=dev
|
||||
spring.profiles.active=dev
|
||||
|
||||
Reference in New Issue
Block a user