|
|
@@ -1291,31 +1291,60 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
@Override
|
|
|
public synchronized void syncPicture() {
|
|
|
- while (true){
|
|
|
- //上传图片到cos
|
|
|
- List<MidjourneyUserConversation> imgConversations = conversationMapper.selectList(Wrappers.lambdaQuery(MidjourneyUserConversation.class)
|
|
|
- .eq(MidjourneyUserConversation::getStatus, "SUCCESS").notLike(MidjourneyUserConversation::getImageUrl, "cdn.mj.galaxydvd.com")
|
|
|
- .ge(MidjourneyUserConversation::getStartTime, DateUtil.offsetMinute(new Date(), -60 * 24 * 3).getTime())
|
|
|
- .eq(MidjourneyUserConversation::getImageInvalid,Boolean.FALSE).orderByAsc(MidjourneyUserConversation::getId).last(" limit 10"));
|
|
|
- if(imgConversations.size() == 0){
|
|
|
- break;
|
|
|
- }
|
|
|
- for (MidjourneyUserConversation conversation : imgConversations) {
|
|
|
- try {
|
|
|
- String imageUrl = conversation.getImageUrl();
|
|
|
- if (StringUtil.isNotBlank(imageUrl)) {
|
|
|
- conversation.setImageUrl(uploadPic(imageUrl, "conversation" + conversation.getId()));
|
|
|
- conversationMapper.updateById(conversation);
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("上传图片失败", e);
|
|
|
- conversation.setImageInvalid(Boolean.TRUE);
|
|
|
- conversationMapper.updateById(conversation);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ int batchSize = 10;
|
|
|
+ int maxRetries = 3;
|
|
|
+ while (true) {
|
|
|
+ // 查询需要上传的图片对话
|
|
|
+ List<MidjourneyUserConversation> imgConversations = conversationMapper.selectList(Wrappers.lambdaQuery(MidjourneyUserConversation.class)
|
|
|
+ .eq(MidjourneyUserConversation::getStatus, "SUCCESS")
|
|
|
+ .notLike(MidjourneyUserConversation::getImageUrl, ".mj.galaxydvd.com")
|
|
|
+ .ge(MidjourneyUserConversation::getStartTime, DateUtil.offsetMinute(new Date(), -60 * 24 * 3).getTime())
|
|
|
+ .eq(MidjourneyUserConversation::getImageInvalid, Boolean.FALSE)
|
|
|
+ .orderByAsc(MidjourneyUserConversation::getId)
|
|
|
+ .last(" limit " + batchSize));
|
|
|
+
|
|
|
+ // 如果没有数据,跳出循环
|
|
|
+ if (imgConversations.isEmpty()) {
|
|
|
+ log.info("所有图片已处理完毕,结束同步任务");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (MidjourneyUserConversation conversation : imgConversations) {
|
|
|
+ String imageUrl = conversation.getImageUrl();
|
|
|
+ if (StringUtil.isBlank(imageUrl)) {
|
|
|
+ log.warn("对话ID {} 的图片URL为空,跳过处理", conversation.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean uploadSuccess = false;
|
|
|
+ for (int i = 0; i < maxRetries; i++) {
|
|
|
+ try {
|
|
|
+ // 上传图片并更新URL
|
|
|
+ String newImageUrl = uploadPic(imageUrl, "conversation" + conversation.getId());
|
|
|
+ conversation.setImageUrl(newImageUrl);
|
|
|
+ uploadSuccess = true;
|
|
|
+ log.info("对话ID {} 图片上传成功,新的图片URL:{}", conversation.getId(), newImageUrl);
|
|
|
+ break;
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("对话ID {} 第 {} 次上传图片失败,原因:{}", conversation.getId(), i + 1, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conversation.setImageInvalid(!uploadSuccess);
|
|
|
+ conversationMapper.updateById(conversation);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 防止高频次查询,增加短暂的休眠时间
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("线程休眠被中断", e);
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Long checkUserLimit(MidjourneyUser user,Integer mode){
|
|
|
Long num = 0L;
|