feat: 实现 EpicScriptService.switchVersion
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,11 +14,15 @@ import com.emotion.dto.response.ai.AiRuntimeTestResponse;
|
|||||||
import com.emotion.dto.response.EpicScriptInspirationResponse;
|
import com.emotion.dto.response.EpicScriptInspirationResponse;
|
||||||
import com.emotion.dto.response.EpicScriptResponse;
|
import com.emotion.dto.response.EpicScriptResponse;
|
||||||
import com.emotion.dto.response.InspirationSuggestionResponse;
|
import com.emotion.dto.response.InspirationSuggestionResponse;
|
||||||
|
import com.emotion.entity.Conversation;
|
||||||
import com.emotion.entity.EpicScript;
|
import com.emotion.entity.EpicScript;
|
||||||
|
import com.emotion.entity.Message;
|
||||||
import com.emotion.mapper.EpicScriptMapper;
|
import com.emotion.mapper.EpicScriptMapper;
|
||||||
import com.emotion.service.AiRuntimeService;
|
import com.emotion.service.AiRuntimeService;
|
||||||
|
import com.emotion.service.ConversationService;
|
||||||
import com.emotion.service.EpicScriptService;
|
import com.emotion.service.EpicScriptService;
|
||||||
import com.emotion.service.LifePathService;
|
import com.emotion.service.LifePathService;
|
||||||
|
import com.emotion.service.MessageService;
|
||||||
import com.emotion.service.ScriptContextService;
|
import com.emotion.service.ScriptContextService;
|
||||||
import com.emotion.service.TtsTaskService;
|
import com.emotion.service.TtsTaskService;
|
||||||
import com.emotion.util.UserContextHolder;
|
import com.emotion.util.UserContextHolder;
|
||||||
@@ -79,6 +83,12 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TtsTaskService ttsTaskService;
|
private TtsTaskService ttsTaskService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageService messageService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConversationService conversationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<EpicScriptResponse> getPageByCurrentUser(EpicScriptPageRequest request) {
|
public PageResult<EpicScriptResponse> getPageByCurrentUser(EpicScriptPageRequest request) {
|
||||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||||
@@ -675,6 +685,46 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
|
|||||||
return convertToResponse(script);
|
return convertToResponse(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
|
||||||
|
public EpicScriptResponse switchVersion(String scriptId, String messageId) {
|
||||||
|
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||||
|
EpicScript script = this.getById(scriptId);
|
||||||
|
if (script == null || !script.getUserId().equals(currentUserId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Message message = messageService.getById(messageId);
|
||||||
|
if (message == null || !"script".equals(message.getType())
|
||||||
|
|| !script.getConversationId().equals(message.getConversationId())) {
|
||||||
|
throw new IllegalStateException("消息不属于该剧本");
|
||||||
|
}
|
||||||
|
|
||||||
|
script.setCurrentVersionMessageId(messageId);
|
||||||
|
Map<String, Object> metadata = parseMetadata(message.getMetadata());
|
||||||
|
script.setTitle((String) metadata.getOrDefault("title", script.getTitle()));
|
||||||
|
script.setPlotIntro((String) metadata.getOrDefault("plotIntro", ""));
|
||||||
|
script.setPlotTurning((String) metadata.getOrDefault("plotTurning", ""));
|
||||||
|
script.setPlotClimax((String) metadata.getOrDefault("plotClimax", ""));
|
||||||
|
script.setPlotEnding((String) metadata.getOrDefault("plotEnding", ""));
|
||||||
|
|
||||||
|
Map<String, Object> plotJson = script.getPlotJson();
|
||||||
|
if (plotJson == null) {
|
||||||
|
plotJson = new java.util.HashMap<>();
|
||||||
|
}
|
||||||
|
plotJson.putAll(metadata);
|
||||||
|
script.setPlotJson(plotJson);
|
||||||
|
this.updateById(script);
|
||||||
|
|
||||||
|
Conversation conversation = conversationService.getById(script.getConversationId());
|
||||||
|
if (conversation != null) {
|
||||||
|
conversation.setCurrentMessageId(messageId);
|
||||||
|
conversationService.updateById(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertToResponse(script);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteScript(String id) {
|
public boolean deleteScript(String id) {
|
||||||
EpicScript script = this.getById(id);
|
EpicScript script = this.getById(id);
|
||||||
@@ -695,6 +745,20 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
|
|||||||
return this.removeById(id);
|
return this.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析消息元数据JSON
|
||||||
|
*/
|
||||||
|
private Map<String, Object> parseMetadata(String metadataJson) {
|
||||||
|
if (!StringUtils.hasText(metadataJson)) {
|
||||||
|
return new java.util.HashMap<>();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return com.alibaba.fastjson2.JSON.parseObject(metadataJson, Map.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new java.util.HashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换为响应对象
|
* 转换为响应对象
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user