Merge branch 'dev/dev' into dev/dev_xp
# Conflicts: # src/main/java/com/ai/da/common/RabbitMQ/GenerateConsumer.java # src/main/java/com/ai/da/service/impl/AccountServiceImpl.java # src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java # src/main/resources/application-dev.properties # src/main/resources/messages_en.properties # src/main/resources/messages_zh.properties
This commit is contained in:
@@ -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==========");
|
||||
@@ -158,6 +160,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) {
|
||||
@@ -217,4 +267,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user