|
|
@@ -1,8 +1,23 @@
|
|
|
package cn.qinys.platform.mobile.service.impl;
|
|
|
|
|
|
+import cn.qinys.platform.entity.wishing.ChatMessage;
|
|
|
+import cn.qinys.platform.entity.wishing.SpringAiChatMemory;
|
|
|
+import cn.qinys.platform.entity.wishing.UserWish;
|
|
|
import cn.qinys.platform.entity.wishing.WishingTreeExtension;
|
|
|
+import cn.qinys.platform.mobile.constants.MsgTypeEnum;
|
|
|
+import cn.qinys.platform.mobile.mapper.ChatMessageMapper;
|
|
|
+import cn.qinys.platform.mobile.mapper.SpringAiChatMemoryMapper;
|
|
|
+import cn.qinys.platform.mobile.mapper.UserWishMapper;
|
|
|
import cn.qinys.platform.mobile.mapper.WishingTreeExtensionMapper;
|
|
|
+import cn.qinys.platform.mobile.service.ImageService;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author lie tan
|
|
|
@@ -13,6 +28,15 @@ public abstract class AbstractUserWishService {
|
|
|
|
|
|
@Resource
|
|
|
WishingTreeExtensionMapper treeExtensionMapper;
|
|
|
+ @Resource
|
|
|
+ ImageService imageService;
|
|
|
+ @Resource
|
|
|
+ SpringAiChatMemoryMapper memoryMapper;
|
|
|
+ @Resource
|
|
|
+ UserWishMapper userWishMapper;
|
|
|
+ @Resource
|
|
|
+ ChatMessageMapper messageMapper;
|
|
|
+
|
|
|
|
|
|
public void treeWishesCounter(Integer treeId, Integer isPublic) {
|
|
|
WishingTreeExtension extension = treeExtensionMapper.selectByTreeId(treeId);
|
|
|
@@ -32,4 +56,39 @@ public abstract class AbstractUserWishService {
|
|
|
treeExtensionMapper.insertOrUpdate(extension);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void appendWishImage(UserWish wish) {
|
|
|
+ QueryWrapper<SpringAiChatMemory> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("conversation_id", wish.getUserId())
|
|
|
+ .orderByDesc("timestamp")
|
|
|
+ .last("limit 10");
|
|
|
+ List<SpringAiChatMemory> memoryList = memoryMapper.selectList(wrapper);
|
|
|
+ if (memoryList == null || memoryList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String sb = "请根据用户许下的愿望,以及最近几轮对话的内容,生成一张与许愿相关的图片。用户的愿望为" +
|
|
|
+ "content:" + wish.getContent() +
|
|
|
+ "tag:" + wish.getTags() +
|
|
|
+ "最近的聊天记录内容为:" + JSON.toJSONString(memoryList);
|
|
|
+
|
|
|
+ String imageUrl = imageService.getImageUrl(sb);
|
|
|
+
|
|
|
+ if (StringUtils.hasText(imageUrl)) {
|
|
|
+ wish.setImages(JSON.toJSONString(List.of(imageUrl)));
|
|
|
+ userWishMapper.updateById(wish);
|
|
|
+ ChatMessage chatMessage = new ChatMessage();
|
|
|
+ chatMessage.setUserId(wish.getUserId());
|
|
|
+ chatMessage.setTreeId(wish.getTreeId());
|
|
|
+ chatMessage.setType(MsgTypeEnum.TEXT.getValue());
|
|
|
+ chatMessage.setContent("小愿已为您的愿望生成了一张图片,您可以到许愿树下查看哦~~");
|
|
|
+ chatMessage.setRole("ai");
|
|
|
+ messageMapper.insert(chatMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|