This commit is contained in:
2025-09-02 20:09:37 +08:00
parent feca192f53
commit a59acb0903
21 changed files with 140 additions and 50 deletions

View File

@@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -159,7 +160,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<>();
@@ -193,7 +194,7 @@ public class MyTaskScheduler {
}
}
}
// @Scheduled(cron = "0 0 9 * * ?")
@Scheduled(cron = "0 0 9 * * ?")
public void sendTrialOrderExcelToManagements() {
// 获取前一天日期
LocalDate yesterday = LocalDate.now().minusDays(1);
@@ -1504,7 +1505,7 @@ public class MyTaskScheduler {
Workspace workspace = new Workspace();
workspace.setAgeGroup("Adult");
if (null != design.getTemplateId()) {
project.setProcess(DesignProcess.SERIES_DESIGN.getValue());
project.setProcess(DesignProcess.SERIES_DESIGN.name());
workspace.setPosition("Overall");
// workspace设置模特
if (design.getModelType().equals("System")) {
@@ -1531,7 +1532,7 @@ public class MyTaskScheduler {
}
}
}else {
project.setProcess(DesignProcess.SINGLE_DESIGN.getValue());
project.setProcess(DesignProcess.SINGLE_DESIGN.name());
workspace.setPosition(design.getSwitchCategory());
}
workspace.setSystemDesignerPercentage(design.getSystemScale().multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).intValueExact());
@@ -1661,6 +1662,11 @@ public class MyTaskScheduler {
project.setAccountId(userLikeGroup.getAccountId());
project.setName(userLikeGroup.getName());
project.setCreateTime(LocalDateTime.ofInstant(userLikeGroup.getCreateDate().toInstant(), ZoneId.systemDefault()));
if (Objects.isNull(userLikeGroup.getUpdateDate())){
project.setUpdateTime(LocalDateTime.ofInstant(userLikeGroup.getCreateDate().toInstant(), ZoneId.systemDefault()));
} else {
project.setUpdateTime(LocalDateTime.ofInstant(userLikeGroup.getUpdateDate().toInstant(), ZoneId.systemDefault()));
}
// project.setUpdateTime(LocalDateTime.ofInstant(userLikeGroup.getUpdateDate().toInstant(), ZoneId.systemDefault()));
project.setOriginal(userLikeGroup.getOriginal());
project.setOriginalAccountId(userLikeGroup.getOriginalAccountId());

View File

@@ -91,5 +91,6 @@ public class CommonConstant {
public static final String PARTIAL_DESIGN_PREVIEW_FILENAME = "Preview";
public static final String senderEmail = "info@aida.com.hk";
}

View File

@@ -22,16 +22,16 @@ public class AccountTask {
/**
* 每周日晚上刷新 年付用户、月付用户的积分
* 替换为
* 每个月月初只刷新年付用户的积分
* 每个月月初只刷新教育子账号的积分
*/
// @Scheduled(cron = "59 59 23 * * ?")
// @Scheduled(cron = "0 0 0 1 * ?")
@Scheduled(cron = "0 0 0 1 * ?")
public void refreshCreditsMonthly() {
log.info("每月1号0点 重置教育版子账号为默认积分");
accountService.refreshCreditsMonthly();
}
// @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();
@@ -51,7 +51,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);
@@ -74,7 +74,7 @@ public class AccountTask {
accountService.registerUserToVisitor();
}
// @Scheduled(cron = "0 0 0 1 * ?")
@Scheduled(cron = "0 0 0 1 * ?")
// 每月初刷新所有用户用户名剩余修改次数
public void resetUsernameModifyTimes(){
log.info("重置所有用户的用户名修改次数");

View File

@@ -96,6 +96,10 @@ public class GenerateTask {
apiGenerate.setUpdateTime(LocalDateTime.now());
apiGenerateService.updateById(apiGenerate);
}
// 将积分暂扣区的积分移除
if (toProductImageResult.getStatus().equals("Fail")){
creditsService.deleteCreditsDeduction(apiGenerate.getAccountId(), taskId);
}
}
}
}

View File

@@ -45,7 +45,7 @@ public class PaymentTask {
@Resource
private PayPalCheckoutService payPalCheckoutService;
// @Scheduled(cron = "0/30 * * * * ?")
@Scheduled(cron = "0/30 * * * * ?")
public void orderConfirmForPaypal() throws SerializeException {
// log.info("PayPal orderConfirm 被执行......");
@@ -120,7 +120,7 @@ public class PaymentTask {
}
}
// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
@Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
public void calcCouponsCommission(){
log.info("优惠券佣金计算定时器");
affiliateService.calcCouponsCommission();

View File

@@ -1,5 +1,6 @@
package com.ai.da.common.utils;
import com.ai.da.common.constant.CommonConstant;
import com.ai.da.model.dto.BasicEmailParamDTO;
import com.alibaba.fastjson.JSONObject;
import com.sun.mail.smtp.SMTPTransport;
@@ -132,7 +133,8 @@ public class MailUtil {
*/
public BasicEmailParamDTO setBasicEmailParams(List<String> mailTo, JSONObject jsonObject, String templatePath, String title) throws AddressException {
BasicEmailParamDTO basicEmailParamDTO = new BasicEmailParamDTO();
basicEmailParamDTO.setSenderUserMail("info@aida.com.hk");
// basicEmailParamDTO.setSenderUserMail("info@aida.com.hk");
basicEmailParamDTO.setSenderUserMail(CommonConstant.senderEmail);
basicEmailParamDTO.setMailTo(getInternetAddressList(mailTo));
basicEmailParamDTO.setSubject(title);
// todo 邮件模板不存在的报错与重试机制

View File

@@ -372,9 +372,11 @@ public class SendEmailUtil {
return jsonObject.toJSONString();
}
private final static Long UPGRADE_NOTIFICATION_ID = 118855L;
private final static Long UPGRADE_NOTIFICATION_ID = 146605L;
// private final static Long UPGRADE_NOTIFICATION_ID = 146551L;
private final static Long UPGRADE_SUCCESS_NOTIFICATION_ID = 118856L;
private final static Long UPGRADE_NOTIFICATION_ID_CHINESE = 122898L;
private final static Long UPGRADE_NOTIFICATION_ID_CHINESE = 146604L;
// private final static Long UPGRADE_NOTIFICATION_ID_CHINESE = 146552L;
private final static Long UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE = 122899L;
public static void sendUpgradeNotification(Account account, String senderAddress, Integer type) {
@@ -396,20 +398,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.0";
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID);
subject = "AiDA 3.1.0 System Maintenance Announcement";
template.setTemplateID(UPGRADE_NOTIFICATION_ID);
}else {
subject = "系统升级成功和AiDA 3.0新功能";
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE);
subject = "AiDA 3.1.0 系统维护公告";
template.setTemplateID(UPGRADE_NOTIFICATION_ID_CHINESE);
}
// if (type == 1) {
// subject = "Successful System Upgrade and New Features in AiDA 3.0";
// template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID);
// }else {
// subject = "系统升级成功和AiDA 3.0新功能";
// template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE);
// }
template.setTemplateData(buildAccountData(account));
req.setSubject(subject);
@@ -417,8 +419,8 @@ public class SendEmailUtil {
// 发送邮件
SendEmailResponse resp = client.SendEmail(req);
log.info(senderAddress);
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
// log.info(senderAddress);
// log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
log.info(senderAddress);
log.info("邮件发送失败###{}", e.toString());
@@ -764,7 +766,7 @@ public class SendEmailUtil {
try {
String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com";
String[] receiverEmail = {/*merchantEmail,*/ developer};
String[] receiverEmail = {merchantEmail, developer};
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
// 实例化一个http选项可选的没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
@@ -934,7 +936,7 @@ public class SendEmailUtil {
req.setFromEmailAddress(SEND_ADDRESS);
String merchantEmail = "kimwong@code-create.com.hk";
String developerEmail = "xupei@code-create.com.hk";
req.setDestination(new String[]{/*merchantEmail,*/ developerEmail});
req.setDestination(new String[]{merchantEmail, developerEmail});
Template template = new Template();
req.setSubject("New Credit Purchase Order");
template.setTemplateID(CREDITS_PURCHASE_MERCHANT);

View File

@@ -135,10 +135,10 @@ public class ProjectController {
}
/*@Resource
@Resource
private MyTaskScheduler myTaskScheduler;
@GetMapping("/dataMigration")
/*@GetMapping("/dataMigration")
public String dataMigration(){
myTaskScheduler.projectDataCreate();
return "success";

View File

@@ -18,7 +18,7 @@ public class ToProductImageDTO {
private BigDecimal imageStrengthMax;
private String modelName;
private String ageGroup;
// 使用子集中的元素作为父元素
// 使用子集中的元素作为父元素 用于重新排序
private Long userLikeSortId;
// 是否默认like生成的元素

View File

@@ -2964,7 +2964,7 @@ public class PythonService {
// 对印花类型为Generate的图片路径进行特殊处理
private void setUriToMinioPath(DesignSinglePrint print){
if (print.getDesignType().equals("Generate")){
if (!StringUtil.isNullOrEmpty(print.getDesignType()) && print.getDesignType().equals("Generate")){
if (!StringUtil.isNullOrEmpty(print.getPath())){
try {
URI uri = new URI(print.getPath());

View File

@@ -31,6 +31,8 @@ public interface CreditsService extends IService<CreditsDetail> {
void addRecordToCreditsDeduction(Long accountId, String taskId, CreditsEventsEnum creditsEventsEnum, Integer num);
void deleteCreditsDeduction(Long accountId, String taskId);
Boolean taskCreditsDeduction(Long accountId, String taskId);
CreditsDetail getByAccountIdAndChangeEvent(Long accountId, String changeEvent, String changedCredits);

View File

@@ -1266,12 +1266,12 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
static {
HikariConfig config = new HikariConfig();
// config.setJdbcUrl("jdbc:mysql://code-create.com.hk:3306/db1nfvsgmjp3b8");
// config.setUsername("uafqtz4gsvfrw");
// config.setPassword("aida123456.");
config.setJdbcUrl("jdbc:mysql://localhost:3306/code-create-local?serverTimezone=UTC");
config.setUsername("root");
config.setPassword("root");
config.setJdbcUrl("jdbc:mysql://code-create.com.hk:3306/db1nfvsgmjp3b8");
config.setUsername("uafqtz4gsvfrw");
config.setPassword("aida123456.");
// config.setJdbcUrl("jdbc:mysql://localhost:3306/code-create-local?serverTimezone=UTC");
// config.setUsername("root");
// config.setPassword("root");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

View File

@@ -82,7 +82,7 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
// 邮件通知审批者
String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com";
String[] receiverEmail = {/*merchantEmail, */developer};
String[] receiverEmail = {merchantEmail, developer};
SendEmailUtil.affiliateEmailReminder(receiverEmail, new AffiliateEmailParamsDTO(userHolder.getUsername(), promotionMethod), "new");
// emailService.affiliateEmailReminder(Arrays.asList(/*merchantEmail,*/ developer), new AffiliateEmailParamsDTO(userHolder.getUsername(), promotionMethod), "new");
}else {
@@ -387,7 +387,7 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com";
String[] receiverEmail = {/*merchantEmail,*/ developer};
String[] receiverEmail = {merchantEmail, developer};
// 邮件通知
SendEmailUtil.affiliateEmailReminder(receiverEmail, affiliateEmailParamsDTO, "summary");
// emailService.affiliateEmailReminder(Arrays.asList(/*merchantEmail,*/ developer), affiliateEmailParamsDTO, "summary");

View File

@@ -235,6 +235,12 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
redisUtil.addToString(creditsDeduction + ":" + accountId + ":" + taskId, String.valueOf(Long.parseLong(creditsEventsEnum.getValue()) * num), CommonConstant.CREDITS_EXPIRE_TIME);
}
@Override
public void deleteCreditsDeduction(Long accountId, String taskId) {
// 5、添加当前任务的预扣积分到redis 任务有效期一天,若待扣积分两天还没被移除,说明任务已经失败,待扣积分自动失效
redisUtil.removeFromString(creditsDeduction + ":" + accountId + ":" + taskId);
}
/**
* 执行扣除积分,更新数据库
*/

View File

@@ -958,7 +958,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
// 对印花类型为Generate的图片路径进行特殊处理
private void setUriToMinioPath(DesignSinglePrint print){
if (print.getDesignType().equals("Generate")){
if (!StringUtil.isNullOrEmpty(print.getDesignType()) && print.getDesignType().equals("Generate")){
if (!StringUtil.isNullOrEmpty(print.getPath())){
try {
URI uri = new URI(print.getPath());

View File

@@ -2,6 +2,7 @@ package com.ai.da.service.impl;
import com.ai.da.common.RabbitMQ.MQPublisher;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.constant.CommonConstant;
import com.ai.da.common.response.ResultEnum;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.MailUtil;
@@ -178,7 +179,8 @@ public class EmailServiceImpl implements EmailService {
EmailLog emailLog = new EmailLog();
emailLog.setTemplateId(emailTemplate.getId());
if (Objects.nonNull(jsonObject)) emailLog.setParameter(jsonObject.toString());
emailLog.setSender("info@aida.com.hk");
// emailLog.setSender("info@aida.com.hk");
emailLog.setSender(CommonConstant.senderEmail);
emailLog.setRecipients(mailTo.toString());
emailLog.setSubject(title);
emailLog.setCreateTime(LocalDateTime.now());
@@ -584,7 +586,7 @@ public class EmailServiceImpl implements EmailService {
try {
String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com";
List<String> merchantReceiver = Arrays.asList(/*merchantEmail, */developer);
List<String> merchantReceiver = Arrays.asList(merchantEmail, developer);
String merchantSubject = null;
String merchantTemplate = null;
@@ -704,7 +706,7 @@ public class EmailServiceImpl implements EmailService {
jsonObject.put("quantity", quantity);
jsonObject.put("totalFee", amount);
sendEmail(Arrays.asList(/*merchantEmail,*/developerEmail), jsonObject, CREDITS_PURCHASE_MERCHANT, "New Credit Purchase Order", null, null);
sendEmail(Arrays.asList(merchantEmail,developerEmail), jsonObject, CREDITS_PURCHASE_MERCHANT, "New Credit Purchase Order", null, null);
}
private final static String COMMON_EXCEPTION_REMINDER = "135279_common-exception-reminder.html";

View File

@@ -635,6 +635,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
* 处理wx模型生成
*/
private PrepareForGenerateVO handleWxModelGeneration(GenerateThroughImageTextDTO generateDTO) {
// 校验积分是否足够
validateCredits(CreditsEventsEnum.WX_TEXT2IMG);
// 创建生成任务
String taskId = createAsyncTask(generateDTO);
processCreditDeduction(generateDTO.getUserId(), taskId, CreditsEventsEnum.WX_TEXT2IMG);
return new PrepareForGenerateVO(Collections.singletonList(taskId), 200);
@@ -653,6 +656,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
* 处理flux pattern生成
*/
private PrepareForGenerateVO handleFluxPatternGeneration(GenerateThroughImageTextDTO generateDTO) {
// 校验积分是否足够
validateCredits(CreditsEventsEnum.FLUX_IMG2IMG);
// 获取图片路径
String imagePath = getImagePathForFlux(generateDTO);
@@ -2507,6 +2513,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
} else {
throw new BusinessException("unknown motion task");
}
Long accountId = poseTransformation.getAccountId();
PoseTransformationVO poseTransformationVO = new PoseTransformationVO();
WangXiangTaskStatusEnum statusEnum = WangXiangTaskStatusEnum.fromName(status);
switch (statusEnum) {
@@ -2528,7 +2535,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(poseTransformation.getFirstFrameUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
}
// 执行积分扣除
Long accountId = poseTransformation.getAccountId();
Boolean flag = creditsService.taskCreditsDeduction(accountId, taskId);
if (flag) creditsService.updateChangedCredits(String.valueOf(accountId), taskId);
@@ -2539,11 +2545,15 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
case FAILED:
AccessLimitUtils.validateOut("animation");
updatePoseTransferStatus(taskId, "Fail", poseTransformation);
// 将积分暂扣区的积分移除
creditsService.deleteCreditsDeduction(accountId, taskId);
throw new BusinessException(output.getStr("message"), ResultEnum.PROMPT.getCode());
case UNKNOWN_W:
AccessLimitUtils.validateOut("animation");
poseTransformationVO.setStatus("Fail");
updatePoseTransferStatus(taskId, "Fail", poseTransformation);
// 将积分暂扣区的积分移除
creditsService.deleteCreditsDeduction(accountId, taskId);
break;
case RUNNING:
case PENDING_W:
@@ -2555,6 +2565,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
log.info("未知状态: {}", status);
poseTransformationVO.setStatus("Fail");
updatePoseTransferStatus(taskId, "Fail", poseTransformation);
// 将积分暂扣区的积分移除
creditsService.deleteCreditsDeduction(accountId, taskId);
}
poseTransformationVO.setTaskId(taskId);
@@ -2968,9 +2980,14 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
String fluxResult = getFluxResult(taskId, objectName);
if (Objects.isNull(generateDetail)) {
if (StringUtil.isNullOrEmpty(fluxResult)) {
// 将积分暂扣区的积分移除
creditsService.deleteCreditsDeduction(accountId, taskId);
return new GenerateResultVO(taskId, "Fail");
} else if (fluxResult.equals("Fail") || fluxResult.equals("Pending")) {
String status = fluxResult.equals("Fail") ? "Fail" : "Executing";
if (status.equals("Fail")){
creditsService.deleteCreditsDeduction(accountId, taskId);
}
return new GenerateResultVO(taskId, status);
}
generateDetail = new GenerateDetail(generate.getId(), fluxResult,

View File

@@ -13,6 +13,7 @@ import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.mapper.primary.entity.Collection;
import com.ai.da.model.dto.*;
import com.ai.da.model.enums.DesignProcess;
import com.ai.da.model.enums.Position;
import com.ai.da.model.enums.Sex;
import com.ai.da.model.vo.*;
@@ -699,12 +700,15 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
if (workspace.getPosition().equals(Position.OVERALL.getValue())) {
design.setSingleOverall("overall");
design.setSwitchCategory("");
project.setProcess(DesignProcess.SERIES_DESIGN.name());
} else {
design.setSingleOverall("single");
design.setSwitchCategory(workspace.getPosition());
project.setProcess(DesignProcess.SINGLE_DESIGN.name());
}
design.setCreateDate(new Date());
designMapper.insert(design);
projectMapper.updateById(project);
for (CollectionElement element : collectionElementListOld) {
element.setCollectionId(collectionIdNew);

View File

@@ -771,6 +771,10 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
Boolean flag = creditsService.taskCreditsDeduction(project.getAccountId(), taskId);
if (flag) creditsService.updateChangedCredits(String.valueOf(project.getAccountId()), taskId);
}
// 将积分暂扣区的积分移除
if (toProductImageResult.getStatus().equals("Fail")){
creditsService.deleteCreditsDeduction(project.getAccountId(), taskId);
}
// 在这个stream中不再继续往后执行
return;
}
@@ -1287,6 +1291,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
Boolean flag = creditsService.taskCreditsDeduction(project.getAccountId(), taskId);
if (flag) creditsService.updateChangedCredits(String.valueOf(project.getAccountId()), taskId);
}
// 将积分暂扣区的积分移除
if (toProductImageResult.getStatus().equals("Fail")){
creditsService.deleteCreditsDeduction(project.getAccountId(), taskId);
}
return;
}