TASK:aida;

This commit is contained in:
shahaibo
2024-06-12 09:47:55 +08:00
parent b1b4b4147c
commit 3a29d25060
51 changed files with 1114 additions and 193 deletions

View File

@@ -44,6 +44,8 @@ public class GenerateConsumer {
@Value("${redis.key.generateResult}")
private String generateResultKey;
@Value("${redis.key.toProductImageResultKey}")
private String toProductImageResultKey;
public void generate(Message msg, Channel channel, String consumerName) {
log.info("============start listening==========");
@@ -154,6 +156,54 @@ public class GenerateConsumer {
}
public void processToProductImageResult(Message msg, Channel channel) {
log.info("============processToProductImageResult listening==========");
long start = System.currentTimeMillis();
Map<String, String> generateResult = JSONObject.parseObject(msg.getBody(), Map.class);
log.info("toProductImage response : {}", generateResult);
try {
log.info("tasks_id : {} start ", generateResult.get("tasks_id"));
if (generateResult.get("status").equals("SUCCESS")) {
String url = generateResult.get("image_url");
String taskId = generateResult.get("tasks_id");
String category = generateResult.get("category");
generateService.processToProductImageResult(taskId, url, category);
} else {
// 修改redis中的数据状态为exception
String key = toProductImageResultKey + ":" + generateResult.get("tasks_id");
redisUtil.addToString(key, new Gson().toJson(new GenerateResultVO(generateResult.get("tasks_id"), null, null, "Fail")), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
// 将异常信息存到exception中
HashMap<String, String> exceptionInfo = new HashMap<>();
exceptionInfo.put(generateResult.get("tasks_id"), generateResult.get("data"));
// 存redis
redisUtil.addToMap(exceptionMapKey, exceptionInfo);
}
} catch (Exception e) {
log.error(e.getMessage());
try {
channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
// 将消息从redis排队队列中删除,需保证被消费的消息存储到db之后再从redis删除
redisUtil.removeFromZSet(consumptionOrderKey, generateResult.get("tasks_id"));
} catch (IOException exception) {
log.error("手动确认,取消返回队列,不再重新消费");
}
// 将入参和错误信息存入数据库
String exceptionMessage = JSONObject.toJSONString(generateResult) +
" Exception message " + e.getMessage();
HashMap<String, String> exceptionInfo = new HashMap<>();
exceptionInfo.put(String.valueOf(generateResult.get("tasks_id")), exceptionMessage);
// 存redis
redisUtil.addToMap(exceptionMapKey, exceptionInfo);
}
long end = System.currentTimeMillis();
log.info("tasks_id : {}, end , message : {}, 执行时长: {} 毫秒", generateResult.get("tasks_id"), generateResult.get("message"), (end - start));
log.info("============ProcessGenerateResult End listening==========");
}
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer1(Message msg, Channel channel) {
@@ -213,4 +263,10 @@ public class GenerateConsumer {
// public void getGenerateResult(Message msg, Channel channel) {
// processGenerateResult(msg, channel);
// }
@RabbitListener(queues = MQConfig.TO_PRODUCT_IMAGE_RESULT_QUEUE)
@RabbitHandler
public void getToProductImageResult(Message msg, Channel channel) {
processToProductImageResult(msg, channel);
}
}

View File

@@ -23,6 +23,7 @@ public class MQConfig {
// public static final String GENERATE_RESULT_QUEUE = "GenerateImage-local";
public static final String GENERATE_RESULT_QUEUE = "GenerateImage-prod";
public static final String TO_PRODUCT_IMAGE_RESULT_QUEUE = "ToProductImage-local";
public MQConfig() {
}

View File

@@ -1,11 +1,11 @@
package com.ai.da.common.config;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.common.utils.SendEmailUtil;
import com.ai.da.mapper.primary.AccountMapper;
import com.ai.da.mapper.primary.TrialOrderMapper;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -22,10 +22,16 @@ import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class MyTaskScheduler {
@PostConstruct
public void test() {
// clearMinio();
}
@Resource
private AccountMapper accountMapper;
@@ -71,7 +77,7 @@ public class MyTaskScheduler {
// @Scheduled(cron = "0 0 8 * * ?")
public void sendTrialOrderExcelToManagements() {
// 获取前一天日期
LocalDate yesterday = LocalDate.now().minusDays(1);
LocalDate yesterday = LocalDate.now().minusDays(3);
// 查询前一天的试用订单
QueryWrapper<TrialOrder> qw = new QueryWrapper<>();
@@ -134,4 +140,69 @@ public class MyTaskScheduler {
SendEmailUtil.sendNoExcelEmail("kimwong@code-create.com.hk", null);
}
}
@Resource
private UserLikeGroupMapper userLikeGroupMapper;
@Resource
private UserLikeMapper userLikeMapper;
@Resource
private TDesignPythonOutfitMapper designPythonOutfitMapper;
@Resource
private TDesignPythonOutfitDetailMapper designPythonOutfitDetailMapper;
@Resource
private DesignItemMapper designItemMapper;
@Resource
private DesignItemDetailMapper designItemDetailMapper;
@Resource
private MinioUtil minioUtil;
public void clearMinio() {
// 获取当前所有history
QueryWrapper<UserLikeGroup> userLikeGroupQueryWrapper = new QueryWrapper<>();
List<UserLikeGroup> userLikeGroupList = userLikeGroupMapper.selectList(userLikeGroupQueryWrapper);
List<Long> userLikeGroupIdList = userLikeGroupList.stream().map(UserLikeGroup::getId).collect(Collectors.toList());
QueryWrapper<UserLike> userLikeQueryWrapper = new QueryWrapper<>();
userLikeQueryWrapper.lambda().in(UserLike::getUserLikeGroupId, userLikeGroupIdList);
// 所有喜欢的图片
List<UserLike> userLikes = userLikeMapper.selectList(userLikeQueryWrapper);
List<Long> designOutfitIdList = userLikes.stream().map(UserLike::getDesignOutfitId).collect(Collectors.toList());
QueryWrapper<TDesignPythonOutfit> designPythonOutfitQueryWrapper = new QueryWrapper<>();
designPythonOutfitQueryWrapper.lambda().notIn(TDesignPythonOutfit::getId, designOutfitIdList);
List<TDesignPythonOutfit> tDesignPythonOutfits = designPythonOutfitMapper.selectList(designPythonOutfitQueryWrapper);
// int i = 0;
// for (TDesignPythonOutfit tDesignPythonOutfit : tDesignPythonOutfits) {
// String designUrl = tDesignPythonOutfit.getDesignUrl();
// if (StringUtils.isNotBlank(designUrl)) {
// minioUtil.deleteObject(designUrl);
// i ++;
// }
// QueryWrapper<TDesignPythonOutfitDetail> designPythonOutfitDetailQueryWrapper = new QueryWrapper<>();
// designPythonOutfitDetailQueryWrapper.lambda().eq(TDesignPythonOutfitDetail::getDesignPythonOutfitId, tDesignPythonOutfit.getId());
// List<TDesignPythonOutfitDetail> tDesignPythonOutfitDetails = designPythonOutfitDetailMapper.selectList(designPythonOutfitDetailQueryWrapper);
// for (TDesignPythonOutfitDetail tDesignPythonOutfitDetail : tDesignPythonOutfitDetails) {
// if (!tDesignPythonOutfitDetail.getImageCategory().equals("body")) {
// if (StringUtils.isNotBlank(tDesignPythonOutfitDetail.getImageUrl())) {
// minioUtil.deleteObject(tDesignPythonOutfitDetail.getImageUrl());
// i ++;
// }
// if (StringUtils.isNotBlank(tDesignPythonOutfitDetail.getMaskUrl())) {
// minioUtil.deleteObject(tDesignPythonOutfitDetail.getMaskUrl());
// i ++;
// }
// }
// }
// }
System.out.println("i");
// List<Long> designItemIdList = userLikes.stream().map(UserLike::getDesignItemId).collect(Collectors.toList());
// QueryWrapper<DesignItem> designItemQueryWrapper = new QueryWrapper<>();
// designItemQueryWrapper.lambda().in(DesignItem::getId,designItemIdList);
// List<DesignItem> designItems = designItemMapper.selectList(designItemQueryWrapper);
// for (DesignItem designItem : designItems) {
// QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
// designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItem.getId());
// List<DesignItemDetail> designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
// for (DesignItemDetail designItemDetail : designItemDetails) {
//
// }
// }
}
}

View File

@@ -136,7 +136,7 @@ public class SendEmailUtil {
private final static Long TRIAL_ORDER_LIST_ID = 122273L;
private final static Long NO_TRIAL_ORDER_LIST_ID = 122591L;
public static void sendCustomEmail(String receiverAddress, String senderAddress, TrialOrder trialOrder, int emailType, String country) {
public static void sendCustomEmail(String receiverAddress, String senderAddress, TrialOrder trialOrder, int emailType, String country, boolean link) {
try {
// 实例化一个认证对象
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
@@ -173,7 +173,7 @@ public class SendEmailUtil {
}else {
template.setTemplateID(NOTIFICATION_TEMPLATE_ID);
}
template.setTemplateData(buildNotificationData(trialOrder));
template.setTemplateData(buildNotificationData(trialOrder, link));
break;
default:
break;
@@ -345,7 +345,7 @@ public class SendEmailUtil {
}
// 构建试用订单通过通知数据
private static String buildNotificationData(TrialOrder trialOrder) {
private static String buildNotificationData(TrialOrder trialOrder, boolean link) {
JSONObject jsonObject = new JSONObject();
// 设置试用订单通过通知相关数据
jsonObject.put("title", trialOrder.getTitle());
@@ -353,6 +353,11 @@ public class SendEmailUtil {
jsonObject.put("givenName", trialOrder.getGivenName());
jsonObject.put("userName", trialOrder.getUserName());
jsonObject.put("email", trialOrder.getEmail());
if (link) {
jsonObject.put("days", 14);
}else {
jsonObject.put("days", 5);
}
return jsonObject.toJSONString();
}