增加修改和删除功能

This commit is contained in:
2025-12-24 15:20:58 +08:00
parent 1aa39e11b4
commit 31cc78038b
26 changed files with 707 additions and 492 deletions
@@ -118,9 +118,8 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
return false;
}
// 逻辑删除
comment.setIsDeleted(1);
return this.updateById(comment);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -140,9 +140,8 @@ public class CommunityPostServiceImpl extends ServiceImpl<CommunityPostMapper, C
return false;
}
// 逻辑删除
post.setIsDeleted(1);
return this.updateById(post);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -271,9 +271,8 @@ public class CozeApiCallServiceImpl extends ServiceImpl<CozeApiCallMapper, CozeA
return false;
}
// 逻辑删除
apiCall.setIsDeleted(1);
return this.updateById(apiCall);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
@Override
@@ -339,10 +339,127 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
script.setIsSelected(request.getIsSelected() ? 1 : 0);
}
// 如果需要重新生成AI内容
if (Boolean.TRUE.equals(request.getRegenerateContent())) {
String aiGeneratedContent = regenerateScriptByAi(request, script, currentUserId);
if (aiGeneratedContent != null) {
Map<String, Object> plotJson = script.getPlotJson();
if (plotJson == null) {
plotJson = new java.util.HashMap<>();
}
plotJson.put("fullContent", aiGeneratedContent);
script.setPlotJson(plotJson);
log.info("AI重新生成剧本内容成功,用户ID: {}, 剧本ID: {}", currentUserId, script.getId());
}
}
this.updateById(script);
return convertToResponse(script);
}
/**
* 调用Coze AI重新生成爽文剧本内容
*
* @param request 剧本更新请求
* @param script 原剧本实体
* @param userId 用户ID
* @return AI生成的剧本内容,失败时返回null
*/
private String regenerateScriptByAi(EpicScriptUpdateRequest request, EpicScript script, String userId) {
try {
// 组装AI输入
String input = assembleUpdateScriptInput(request, script);
log.info("开始调用AI重新生成剧本,用户ID: {}, 剧本ID: {}", userId, script.getId());
// 调用Coze工作流
String result = aiChatService.callWorkflowByConfigKey(COZE_EPIC_SCRIPT_CONFIG_KEY, input, userId);
log.info("AI重新生成剧本完成,用户ID: {}, 结果长度: {}", userId, result != null ? result.length() : 0);
return result;
} catch (Exception e) {
log.error("AI重新生成剧本失败,用户ID: {}, 剧本ID: {}, 错误: {}", userId, script.getId(), e.getMessage(), e);
return null;
}
}
/**
* 组装更新时的AI输入内容
*
* @param request 更新请求
* @param script 原剧本实体
* @return 格式化的输入字符串
*/
private String assembleUpdateScriptInput(EpicScriptUpdateRequest request, EpicScript script) {
StringBuilder sb = new StringBuilder();
// 角色信息(优先使用请求中的,否则使用原有的)
String characterInfo = StringUtils.hasText(request.getCharacterInfo())
? request.getCharacterInfo() : null;
if (characterInfo != null) {
sb.append("【角色信息】").append(characterInfo).append("\n");
}
// 过往经历
String lifeEventsSummary = StringUtils.hasText(request.getLifeEventsSummary())
? request.getLifeEventsSummary() : null;
if (lifeEventsSummary != null) {
sb.append("【过往经历】").append(lifeEventsSummary).append("\n");
}
// 标题
String title = StringUtils.hasText(request.getTitle()) ? request.getTitle() : script.getTitle();
if (StringUtils.hasText(title)) {
sb.append("【剧本标题】").append(title).append("\n");
}
// 主题/渴望
String theme = request.getTheme() != null ? request.getTheme() : script.getTheme();
if (StringUtils.hasText(theme)) {
sb.append("【主题渴望】").append(theme).append("\n");
}
// 风格
String style = StringUtils.hasText(request.getStyle()) ? request.getStyle() : script.getStyle();
if (StringUtils.hasText(style)) {
String styleDesc = getStyleDescription(style);
sb.append("【剧本风格】").append(styleDesc).append("\n");
}
// 篇幅
String length = StringUtils.hasText(request.getLength()) ? request.getLength() : script.getLength();
if (StringUtils.hasText(length)) {
String lengthDesc = getLengthDescription(length);
sb.append("【篇幅长度】").append(lengthDesc).append("\n");
}
// 序幕
String plotIntro = request.getPlotIntro() != null ? request.getPlotIntro() : script.getPlotIntro();
if (StringUtils.hasText(plotIntro)) {
sb.append("【序幕-低谷回响】").append(plotIntro).append("\n");
}
// 转折
String plotTurning = request.getPlotTurning() != null ? request.getPlotTurning() : script.getPlotTurning();
if (StringUtils.hasText(plotTurning)) {
sb.append("【转折-契机出现】").append(plotTurning).append("\n");
}
// 高潮
String plotClimax = request.getPlotClimax() != null ? request.getPlotClimax() : script.getPlotClimax();
if (StringUtils.hasText(plotClimax)) {
sb.append("【高潮-命运抉择】").append(plotClimax).append("\n");
}
// 结局
String plotEnding = request.getPlotEnding() != null ? request.getPlotEnding() : script.getPlotEnding();
if (StringUtils.hasText(plotEnding)) {
sb.append("【结局-新的开始】").append(plotEnding).append("\n");
}
return sb.toString().trim();
}
@Override
public EpicScriptResponse selectScript(String id) {
String currentUserId = UserContextHolder.getCurrentUserId();
@@ -378,7 +495,7 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
@Override
public boolean deleteScript(String id) {
EpicScript script = this.getById(id);
if (script == null || script.getIsDeleted() == 1) {
if (script == null) {
return false;
}
@@ -391,8 +508,8 @@ public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScr
// 删除关联的路径
lifePathService.deleteByScriptId(id);
script.setIsDeleted(1);
return this.updateById(script);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -147,13 +147,12 @@ public class GrowthTopicServiceImpl extends ServiceImpl<GrowthTopicMapper, Growt
@Override
public boolean deleteGrowthTopic(String id) {
GrowthTopic topic = this.getById(id);
if (topic == null || topic.getIsDeleted() == 1) {
if (topic == null) {
return false;
}
// 逻辑删除
topic.setIsDeleted(1);
return this.updateById(topic);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -223,13 +223,10 @@ public class GuestUserServiceImpl extends ServiceImpl<GuestUserMapper, GuestUser
LocalDateTime expireTime = LocalDateTime.now().minusDays(days);
LambdaQueryWrapper<GuestUser> wrapper = new LambdaQueryWrapper<>();
wrapper.lt(GuestUser::getLastActiveTime, expireTime)
.eq(GuestUser::getIsDeleted, 0);
wrapper.lt(GuestUser::getLastActiveTime, expireTime);
GuestUser updateUser = new GuestUser();
updateUser.setIsDeleted(1);
return this.update(updateUser, wrapper);
// 使用 MyBatis-Plus 的 remove 方法,自动处理逻辑删除
return this.remove(wrapper);
}
@Override
@@ -285,13 +282,12 @@ public class GuestUserServiceImpl extends ServiceImpl<GuestUserMapper, GuestUser
@Override
public boolean deleteGuestUser(String id) {
GuestUser guestUser = this.getById(id);
if (guestUser == null || guestUser.getIsDeleted() == 1) {
if (guestUser == null) {
return false;
}
// 逻辑删除
guestUser.setIsDeleted(1);
return this.updateById(guestUser);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -271,7 +271,7 @@ public class LifeEventServiceImpl extends ServiceImpl<LifeEventMapper, LifeEvent
@Override
public boolean deleteEvent(String id) {
LifeEvent event = this.getById(id);
if (event == null || event.getIsDeleted() == 1) {
if (event == null) {
return false;
}
@@ -281,8 +281,8 @@ public class LifeEventServiceImpl extends ServiceImpl<LifeEventMapper, LifeEvent
return false;
}
event.setIsDeleted(1);
return this.updateById(event);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -180,7 +180,7 @@ public class LifePathServiceImpl extends ServiceImpl<LifePathMapper, LifePath>
@Override
public boolean deletePath(String id) {
LifePath path = this.getById(id);
if (path == null || path.getIsDeleted() == 1) {
if (path == null) {
return false;
}
@@ -190,8 +190,8 @@ public class LifePathServiceImpl extends ServiceImpl<LifePathMapper, LifePath>
return false;
}
path.setIsDeleted(1);
return this.updateById(path);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
@Override
@@ -203,15 +203,10 @@ public class LifePathServiceImpl extends ServiceImpl<LifePathMapper, LifePath>
LambdaQueryWrapper<LifePath> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(LifePath::getUserId, currentUserId)
.eq(LifePath::getScriptId, scriptId)
.eq(LifePath::getIsDeleted, 0);
.eq(LifePath::getScriptId, scriptId);
List<LifePath> paths = this.list(wrapper);
for (LifePath path : paths) {
path.setIsDeleted(1);
this.updateById(path);
}
return true;
// 使用 MyBatis-Plus 的 remove 方法,自动处理逻辑删除
return this.remove(wrapper);
}
/**
@@ -430,13 +430,12 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
@Override
public boolean deleteMessage(String id) {
Message message = this.getById(id);
if (message == null || message.getIsDeleted() == 1) {
if (message == null) {
return false;
}
// 逻辑删除
message.setIsDeleted(1);
return this.updateById(message);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -326,13 +326,12 @@ public class RewardServiceImpl extends ServiceImpl<RewardMapper, Reward> impleme
@Override
public boolean deleteReward(String id) {
Reward reward = this.getById(id);
if (reward == null || reward.getIsDeleted() == 1) {
if (reward == null) {
return false;
}
// 逻辑删除
reward.setIsDeleted(1);
return this.updateById(reward);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -127,11 +127,11 @@ public class TopicInteractionServiceImpl extends ServiceImpl<TopicInteractionMap
@Override
public boolean deleteTopicInteraction(String id) {
TopicInteraction topicInteraction = this.getById(id);
if (topicInteraction == null || topicInteraction.getIsDeleted() == 1) {
if (topicInteraction == null) {
return false;
}
topicInteraction.setIsDeleted(1);
return this.updateById(topicInteraction);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
/**
@@ -238,11 +238,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override
public boolean deleteUser(String id) {
User user = this.getById(id);
if (user == null || user.getIsDeleted() == 1) {
if (user == null) {
return false;
}
user.setIsDeleted(1);
return this.updateById(user);
// 使用 MyBatis-Plus 的 removeById 方法,自动处理逻辑删除
return this.removeById(id);
}
@Override