From e5e514b522b773d7b0fdd75e8370a45e7b4b9836 Mon Sep 17 00:00:00 2001 From: xupei Date: Mon, 11 Nov 2024 17:31:55 +0800 Subject: [PATCH 01/12] =?UTF-8?q?ws=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/common/config/MyTaskScheduler.java | 4 +- .../com/ai/da/common/task/AccountTask.java | 10 +- .../com/ai/da/common/task/PaypalTask.java | 2 +- .../com/ai/da/common/task/StripeTask.java | 2 +- .../da/controller/ThirdPartyController.java | 10 +- .../com/ai/da/service/AccountService.java | 2 +- .../da/service/impl/AccountServiceImpl.java | 150 +++++++++--------- src/main/resources/application.properties | 4 +- 8 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 61e964ea..95c55e9a 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -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 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); diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index cfc65fd4..6950878d 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -19,21 +19,21 @@ public class AccountTask { /** * 每周日晚上刷新 年付用户、月付用户的积分 */ -// @Scheduled(cron = "59 59 23 ? * SUN") + @Scheduled(cron = "59 59 23 ? * SUN") // @Scheduled(cron = "59 59 23 * * ?") public void refreshCreditsMonthly() { log.info("每周日晚11:59:59刷新付费用户积分为 6000"); 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 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 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(); } diff --git a/src/main/java/com/ai/da/common/task/PaypalTask.java b/src/main/java/com/ai/da/common/task/PaypalTask.java index fa069971..865eaaa4 100644 --- a/src/main/java/com/ai/da/common/task/PaypalTask.java +++ b/src/main/java/com/ai/da/common/task/PaypalTask.java @@ -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 被执行......"); diff --git a/src/main/java/com/ai/da/common/task/StripeTask.java b/src/main/java/com/ai/da/common/task/StripeTask.java index d4a6fbaf..45d98997 100644 --- a/src/main/java/com/ai/da/common/task/StripeTask.java +++ b/src/main/java/com/ai/da/common/task/StripeTask.java @@ -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分钟以上仍未支付的订单 置为超时订单 diff --git a/src/main/java/com/ai/da/controller/ThirdPartyController.java b/src/main/java/com/ai/da/controller/ThirdPartyController.java index e077fa8c..b8d3ebbc 100644 --- a/src/main/java/com/ai/da/controller/ThirdPartyController.java +++ b/src/main/java/com/ai/da/controller/ThirdPartyController.java @@ -116,9 +116,9 @@ public class ThirdPartyController { return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request)); } - @CrossOrigin - @GetMapping("/auth/google_callback") - public Response googleCallback(@RequestParam("code") String code, HttpSession session) { - return Response.success(accountService.googleCallback(code, session)); - } +// @CrossOrigin +// @GetMapping("/auth/google_callback") +// public Response googleCallback(@RequestParam("code") String code, HttpSession session) { +// return Response.success(accountService.googleCallback(code, session)); +// } } diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index bd9c99b4..276c5645 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -183,7 +183,7 @@ public interface AccountService extends IService { void halfPricePromotion(); - String googleCallback(String code, HttpSession session); +// String googleCallback(String code, HttpSession session); List getPaidCustomerEmail(); } diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 2d826c03..787ec87d 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -1854,82 +1854,82 @@ public class AccountServiceImpl extends ServiceImpl 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 qw = new QueryWrapper<>(); -// qw.lambda().eq(AccountExtend::getAuth, googleUser.getId()); -// List accountExtends = accountExtendMapper.selectList(qw); -// Account existingUser = findUserByGoogleId(googleUser.getId()); - return "Login successful"; -// if (CollectionUtil.isNotEmpty(accountExtends)) { -// // 用户已存在,直接登录 -//// session.setAttribute("user", existingUser); -// return "Login successful"; -// } else { -// // 用户不存在,创建新用户(自动注册) -//// User newUser = googleAuthService.registerNewUser(googleUser); -//// 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://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 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); +// @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 qw = new QueryWrapper<>(); +//// qw.lambda().eq(AccountExtend::getAuth, googleUser.getId()); +//// List accountExtends = accountExtendMapper.selectList(qw); +//// Account existingUser = findUserByGoogleId(googleUser.getId()); +// return "Login successful"; +//// if (CollectionUtil.isNotEmpty(accountExtends)) { +//// // 用户已存在,直接登录 +////// session.setAttribute("user", existingUser); +//// return "Login successful"; +//// } else { +//// // 用户不存在,创建新用户(自动注册) +////// User newUser = googleAuthService.registerNewUser(googleUser); +////// session.setAttribute("user", newUser); +//// return "Registration and login successful"; +//// } +// } catch (Exception e) { +// return "Error processing Google login: " + e.getMessage(); +// } // } - -// 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); +// +// 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://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 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); +//// } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 974fee23..8550475d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ #spring.profiles.active=test #����application-prod�ļ�(��������) -#spring.profiles.active=prod +spring.profiles.active=prod #����application-dev�ļ�(��������) -spring.profiles.active=dev +#spring.profiles.active=dev From b70f909a32c848fa2bc38303de75b346ad6494c6 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 28 Nov 2024 17:14:11 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E4=BC=98=E5=8C=96-=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=B0=86Code-Create=E6=B3=A8=E5=86=8C=E7=9A=84=E6=96=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B7=BB=E5=8A=A0=E5=88=B0AiDA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/AccountServiceImpl.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 787ec87d..086a9df7 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -1392,7 +1392,7 @@ public class AccountServiceImpl extends ServiceImpl 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}") @@ -1404,7 +1404,8 @@ public class AccountServiceImpl extends ServiceImpl impl @Override @Transactional(rollbackFor = Exception.class) public void registerUserToVisitor(){ - ArrayList newUserEmails = new ArrayList<>(); + ArrayList> newUsersInfo = new ArrayList<>(); + ArrayList allEmail = new ArrayList<>(); long maxUserId = CommonConstant.MAXIMUM_USER_ID; try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(QUERY_MAXIMUM_USERID)) { @@ -1420,9 +1421,14 @@ public class AccountServiceImpl extends ServiceImpl 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 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"); @@ -1437,22 +1443,32 @@ public class AccountServiceImpl extends ServiceImpl impl // return null; } - if (!newUserEmails.isEmpty()){ + if (!newUsersInfo.isEmpty()){ // 查询这些邮箱在aida上是否有账号 QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.in("user_email", newUserEmails).select("user_email"); + queryWrapper.in("user_email", allEmail).select("user_email"); + // 重复的邮箱 List 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 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()); @@ -1463,7 +1479,7 @@ public class AccountServiceImpl extends ServiceImpl impl account.setSystemUser(0); baseMapper.insert(account); // 邮件通知用户 - SendEmailUtil.notificationForRegisterUser(email); + SendEmailUtil.notificationForRegisterUser(userInfo.get("email")); }); } // 记录当前最大的用户id From 2fab4721507411f931f8bc4f97792c9322bf2660 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 28 Nov 2024 17:21:58 +0800 Subject: [PATCH 03/12] to dev --- src/main/java/com/ai/da/common/task/AccountTask.java | 8 ++++---- src/main/java/com/ai/da/common/task/PaypalTask.java | 2 +- src/main/java/com/ai/da/common/task/StripeTask.java | 2 +- src/main/resources/application.properties | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index 6950878d..c73f8b7f 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -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 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 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(); } diff --git a/src/main/java/com/ai/da/common/task/PaypalTask.java b/src/main/java/com/ai/da/common/task/PaypalTask.java index 865eaaa4..fa069971 100644 --- a/src/main/java/com/ai/da/common/task/PaypalTask.java +++ b/src/main/java/com/ai/da/common/task/PaypalTask.java @@ -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 被执行......"); diff --git a/src/main/java/com/ai/da/common/task/StripeTask.java b/src/main/java/com/ai/da/common/task/StripeTask.java index 45d98997..d4a6fbaf 100644 --- a/src/main/java/com/ai/da/common/task/StripeTask.java +++ b/src/main/java/com/ai/da/common/task/StripeTask.java @@ -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分钟以上仍未支付的订单 置为超时订单 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8550475d..974fee23 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ #spring.profiles.active=test #����application-prod�ļ�(��������) -spring.profiles.active=prod +#spring.profiles.active=prod #����application-dev�ļ�(��������) -#spring.profiles.active=dev +spring.profiles.active=dev From 13397fa1f78e2c599f8b0210ac10c1ada126818a Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 28 Nov 2024 17:22:57 +0800 Subject: [PATCH 04/12] to dev --- src/main/java/com/ai/da/common/config/MyTaskScheduler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 95c55e9a..61e964ea 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -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 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); From ea4cd297230c37bde59de4f1cf441c258232f7c2 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 28 Nov 2024 17:26:53 +0800 Subject: [PATCH 05/12] to dev --- .../com/ai/da/controller/ThirdPartyController.java | 10 +++++----- src/main/java/com/ai/da/service/AccountService.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/ai/da/controller/ThirdPartyController.java b/src/main/java/com/ai/da/controller/ThirdPartyController.java index b8d3ebbc..e077fa8c 100644 --- a/src/main/java/com/ai/da/controller/ThirdPartyController.java +++ b/src/main/java/com/ai/da/controller/ThirdPartyController.java @@ -116,9 +116,9 @@ public class ThirdPartyController { return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request)); } -// @CrossOrigin -// @GetMapping("/auth/google_callback") -// public Response googleCallback(@RequestParam("code") String code, HttpSession session) { -// return Response.success(accountService.googleCallback(code, session)); -// } + @CrossOrigin + @GetMapping("/auth/google_callback") + public Response googleCallback(@RequestParam("code") String code, HttpSession session) { + return Response.success(accountService.googleCallback(code, session)); + } } diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index 276c5645..bd9c99b4 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -183,7 +183,7 @@ public interface AccountService extends IService { void halfPricePromotion(); -// String googleCallback(String code, HttpSession session); + String googleCallback(String code, HttpSession session); List getPaidCustomerEmail(); } From a237b4041d69e66ca491a0de98f171181a34f425 Mon Sep 17 00:00:00 2001 From: xupei Date: Fri, 29 Nov 2024 15:09:34 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E9=80=89=E6=8B=A9=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0high=20||=20fast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/GenerateServiceImpl.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 283879fa..b8725f5c 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -179,6 +179,11 @@ public class GenerateServiceImpl extends ServiceImpl i mode, category, generateThroughImageTextDTO.getGender()); jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue); } + if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){ + params.put("version","high"); + }else if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("fast")){ + params.put("version","fast"); + } Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, port, path); @@ -567,6 +572,21 @@ public class GenerateServiceImpl extends ServiceImpl i // 3、生成唯一id 使用uuid,由于uuid重复的几率很小,故取消对uuid重复性的校验 String uuid = UUID.randomUUID().toString(); + + // 模型迁移SD1.? -> flux,从而产生了不同模型的选择, + // high -> 生成图片质量高,但生成速度慢,每次生成只返回一张图片 + // fast -> 生成图片质量低,但生成速度快,每次生成返回四张图片 + if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){ + times = 1; + }else if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("fast")){ + times = 4; + } + + // 除了 Moodboard || Printboard->Pattern(可以区分三种风格) || Sketchboard(Generate Sketch)这三个地方需要区分high || fast之外,其他地方保持原样 + if (generateThroughImageTextDTO.getLevel1Type().equals("Printboard") && !generateThroughImageTextDTO.getLevel2Type().equals("Pattern")){ + generateThroughImageTextDTO.setVersion(null); + } + ArrayList taskIdList = new ArrayList<>(); for (int i = 1; i <= times; i++) { String temp = uuid; From b836e7fd67eda81c4a7b23d933c0dc41cbe52862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E4=BD=A9?= <1779019091@qq.com> Date: Sun, 1 Dec 2024 16:32:51 +0800 Subject: [PATCH 07/12] bugfix : fast || high --- .../java/com/ai/da/model/dto/GenerateToPythonDTO.java | 5 ++++- .../java/com/ai/da/service/impl/GenerateServiceImpl.java | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/model/dto/GenerateToPythonDTO.java b/src/main/java/com/ai/da/model/dto/GenerateToPythonDTO.java index 16fa7988..64c31bb7 100644 --- a/src/main/java/com/ai/da/model/dto/GenerateToPythonDTO.java +++ b/src/main/java/com/ai/da/model/dto/GenerateToPythonDTO.java @@ -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; } } diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index b8725f5c..fdfb94e9 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -150,6 +150,14 @@ public class GenerateServiceImpl extends ServiceImpl i String port = generateServicePort; String jsonString = ""; HashMap 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()) { From be1119be6fdb3ded57aea3098030809bcc0259aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E4=BD=A9?= <1779019091@qq.com> Date: Sun, 1 Dec 2024 16:51:38 +0800 Subject: [PATCH 08/12] bugfix : fast || high --- .../com/ai/da/service/impl/GenerateServiceImpl.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index fdfb94e9..9b72463d 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -179,19 +179,15 @@ public class GenerateServiceImpl extends ServiceImpl 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); } - if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){ - params.put("version","high"); - }else if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("fast")){ - params.put("version","fast"); - } + Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, port, path); From 8d6e3e9644c1844ee5fa6fcb176f55df170dd9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E4=BD=A9?= <1779019091@qq.com> Date: Sun, 1 Dec 2024 19:48:12 +0800 Subject: [PATCH 09/12] =?UTF-8?q?sketchboard-prompt=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 9b72463d..63c24bf6 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -334,7 +334,8 @@ public class GenerateServiceImpl extends ServiceImpl 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: } From b315ae5644bd390a41e06f7afd9d9a0dac816105 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Mon, 2 Dec 2024 12:02:19 +0800 Subject: [PATCH 10/12] TASK:toproductimage prompt; --- .../com/ai/da/common/utils/MinioUtil.java | 51 +++++ .../com/ai/da/common/utils/SendEmailUtil.java | 63 +++++- .../ai/da/controller/AccountController.java | 7 + .../controller/SavedCollectionController.java | 6 + .../com/ai/da/service/AccountService.java | 2 + .../ai/da/service/UserLikeGroupService.java | 2 + .../da/service/impl/AccountServiceImpl.java | 26 +++ .../impl/UserLikeGroupServiceImpl.java | 196 ++++++++++++++---- 8 files changed, 301 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/ai/da/common/utils/MinioUtil.java b/src/main/java/com/ai/da/common/utils/MinioUtil.java index bf5bea69..f8b86a51 100644 --- a/src/main/java/com/ai/da/common/utils/MinioUtil.java +++ b/src/main/java/com/ai/da/common/utils/MinioUtil.java @@ -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); // 获取路径的其余部分作为对象名称 + } } diff --git a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java index a89115f8..25e07339 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -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)); diff --git a/src/main/java/com/ai/da/controller/AccountController.java b/src/main/java/com/ai/da/controller/AccountController.java index c73fcdaa..ebf9b8a8 100644 --- a/src/main/java/com/ai/da/controller/AccountController.java +++ b/src/main/java/com/ai/da/controller/AccountController.java @@ -261,5 +261,12 @@ public class AccountController { return Response.success(true); } + @PostMapping("temporaryUpgrade") + @ApiOperation(value = "临时升级") + public Response temporaryUpgrade() { + accountService.temporaryUpgrade(); + return Response.success(true); + } + } diff --git a/src/main/java/com/ai/da/controller/SavedCollectionController.java b/src/main/java/com/ai/da/controller/SavedCollectionController.java index 29cbabac..1967b5c5 100644 --- a/src/main/java/com/ai/da/controller/SavedCollectionController.java +++ b/src/main/java/com/ai/da/controller/SavedCollectionController.java @@ -245,4 +245,10 @@ public class SavedCollectionController { public Response likeHistoryRelSketch() { return Response.success(userLikeGroupService.likeHistoryRelSketch()); } + + @ApiOperation(value = "download") + @PostMapping("/download") + public Response download() { + return Response.success(userLikeGroupService.download()); + } } diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index bd9c99b4..ab6320d0 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -186,4 +186,6 @@ public interface AccountService extends IService { String googleCallback(String code, HttpSession session); List getPaidCustomerEmail(); + + void temporaryUpgrade(); } diff --git a/src/main/java/com/ai/da/service/UserLikeGroupService.java b/src/main/java/com/ai/da/service/UserLikeGroupService.java index 71edbc50..918d29f5 100644 --- a/src/main/java/com/ai/da/service/UserLikeGroupService.java +++ b/src/main/java/com/ai/da/service/UserLikeGroupService.java @@ -62,4 +62,6 @@ public interface UserLikeGroupService extends IService { List getRelightResult(List taskIdList); String likeHistoryRelSketch(); + + String download(); } diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index c6e22d46..1a07fb08 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -1961,4 +1961,30 @@ public class AccountServiceImpl extends ServiceImpl impl // return userRepository.save(newUser); // } + @Override + public void temporaryUpgrade() { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().ne(Account::getSystemUser, 0); + queryWrapper.lambda().isNotNull(Account::getUserEmail); +// queryWrapper.lambda().eq(Account::getId, 6); + List 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 ++; + } + } + } diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 2c51cfa6..492d58d5 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -15,8 +15,10 @@ 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 +32,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; + /** * 服务实现类 * @@ -258,25 +261,47 @@ public class UserLikeGroupServiceImpl extends ServiceImpl designItemDetailQueryWrapper = new QueryWrapper<>(); + designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemId); + designItemDetailQueryWrapper.lambda().ne(DesignItemDetail::getType, "Body"); + List 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 +315,16 @@ public class UserLikeGroupServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); List userLikeGroups = userLikeGroupMapper.selectList(qw); - Map>>> result = new HashMap<>(); + List>> result = new ArrayList<>(); + for (UserLikeGroup userLikeGroup : userLikeGroups) { Long accountId = userLikeGroup.getAccountId(); Long collectionId = userLikeGroup.getCollectionId(); - QueryWrapper collectionElementQueryWrapper = new QueryWrapper<>(); - collectionElementQueryWrapper.lambda().eq(CollectionElement::getCollectionId, collectionId); - collectionElementQueryWrapper.lambda().eq(CollectionElement::getLevel1Type, "Sketchboard"); - List collectionElements = collectionElementMapper.selectList(collectionElementQueryWrapper); - List urlList = collectionElements.stream().map(CollectionElement::getUrl).collect(Collectors.toList()); + // 提前转换为Set以提高contains的效率 + List collectionElements = getCollectionElementsByCollectionId(collectionId); + Set urlSet = collectionElements.stream() + .map(CollectionElement::getUrl) + .collect(Collectors.toSet()); - QueryWrapper userLikeQueryWrapper = new QueryWrapper<>(); - userLikeQueryWrapper.lambda().eq(UserLike::getUserLikeGroupId, userLikeGroup.getId()); - List userLikes = userLikeMapper.selectList(userLikeQueryWrapper); - - List> list = new ArrayList<>(); + List userLikes = getUserLikesByGroupId(userLikeGroup.getId()); for (UserLike userLike : userLikes) { - QueryWrapper designItemDetailQueryWrapper = new QueryWrapper<>(); - designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, userLike.getDesignItemId()); - designItemDetailQueryWrapper.lambda().ne(DesignItemDetail::getType, "Body"); - List designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper); - Map sketch = new HashMap<>(); + List> userLikeSketchList = new ArrayList<>(); + List designItemDetails = getDesignItemDetails(userLike.getDesignItemId()); + for (DesignItemDetail designItemDetail : designItemDetails) { + Map 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>> 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 getCollectionElementsByCollectionId(Long collectionId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CollectionElement::getCollectionId, collectionId) + .eq(CollectionElement::getLevel1Type, "Sketchboard"); + return collectionElementMapper.selectList(qw); + } + + private List getUserLikesByGroupId(Long groupId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(UserLike::getUserLikeGroupId, groupId); + return userLikeMapper.selectList(qw); + } + + private List getDesignItemDetails(Long designItemId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(DesignItemDetail::getDesignItemId, designItemId) + .ne(DesignItemDetail::getType, "Body"); + return designItemDetailMapper.selectList(qw); + } + + private void saveResultAsPrettyJson(List>> result, String filePath) { + // 使用一个 Map 将结果存储为字符串键 + Map 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); } } From b4fe1ca1992e497a8d49f179e329a98f7288c724 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Mon, 2 Dec 2024 13:51:46 +0800 Subject: [PATCH 11/12] TASK:toproductimage prompt; --- .../com/ai/da/service/impl/UserLikeGroupServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 492d58d5..d712f4fd 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -289,11 +289,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl Date: Mon, 2 Dec 2024 14:34:10 +0800 Subject: [PATCH 12/12] =?UTF-8?q?high=20||=20fast=20=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/GenerateServiceImpl.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index b8725f5c..70f039c8 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -503,6 +503,13 @@ public class GenerateServiceImpl extends ServiceImpl 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())) { @@ -559,8 +566,14 @@ public class GenerateServiceImpl extends ServiceImpl 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、判断用户当前积分是否够本次生成消耗 @@ -572,16 +585,6 @@ public class GenerateServiceImpl extends ServiceImpl i // 3、生成唯一id 使用uuid,由于uuid重复的几率很小,故取消对uuid重复性的校验 String uuid = UUID.randomUUID().toString(); - - // 模型迁移SD1.? -> flux,从而产生了不同模型的选择, - // high -> 生成图片质量高,但生成速度慢,每次生成只返回一张图片 - // fast -> 生成图片质量低,但生成速度快,每次生成返回四张图片 - if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("high")){ - times = 1; - }else if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) && generateThroughImageTextDTO.getVersion().equals("fast")){ - times = 4; - } - // 除了 Moodboard || Printboard->Pattern(可以区分三种风格) || Sketchboard(Generate Sketch)这三个地方需要区分high || fast之外,其他地方保持原样 if (generateThroughImageTextDTO.getLevel1Type().equals("Printboard") && !generateThroughImageTextDTO.getLevel2Type().equals("Pattern")){ generateThroughImageTextDTO.setVersion(null);