人生轨迹功能模块补充
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.dto.request.EpicScriptCreateRequest;
|
||||
import com.emotion.dto.request.EpicScriptPageRequest;
|
||||
import com.emotion.dto.request.EpicScriptUpdateRequest;
|
||||
import com.emotion.dto.response.EpicScriptResponse;
|
||||
import com.emotion.service.EpicScriptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 爽文剧本控制器
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/epicScript")
|
||||
public class EpicScriptController {
|
||||
|
||||
@Autowired
|
||||
private EpicScriptService epicScriptService;
|
||||
|
||||
/**
|
||||
* 分页查询当前用户的爽文剧本
|
||||
*/
|
||||
@GetMapping(value = "/page")
|
||||
public Result<PageResult<EpicScriptResponse>> getPage(@Validated EpicScriptPageRequest request) {
|
||||
PageResult<EpicScriptResponse> pageResult = epicScriptService.getPageByCurrentUser(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的所有爽文剧本列表
|
||||
*/
|
||||
@GetMapping(value = "/listAll")
|
||||
public Result<List<EpicScriptResponse>> getList() {
|
||||
List<EpicScriptResponse> scripts = epicScriptService.getListByCurrentUser();
|
||||
return Result.success(scripts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取爽文剧本详情
|
||||
*/
|
||||
@GetMapping(value = "/detail")
|
||||
public Result<EpicScriptResponse> getById(@RequestParam String id) {
|
||||
EpicScriptResponse script = epicScriptService.getScriptById(id);
|
||||
if (script == null) {
|
||||
return Result.notFound("爽文剧本不存在");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建爽文剧本
|
||||
*/
|
||||
@PostMapping(value = "/create")
|
||||
public Result<EpicScriptResponse> create(@Valid @RequestBody EpicScriptCreateRequest request) {
|
||||
EpicScriptResponse script = epicScriptService.createScript(request);
|
||||
if (script == null) {
|
||||
return Result.error("创建失败");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新爽文剧本
|
||||
*/
|
||||
@PutMapping(value = "/update")
|
||||
public Result<EpicScriptResponse> update(@Valid @RequestBody EpicScriptUpdateRequest request) {
|
||||
EpicScriptResponse script = epicScriptService.updateScript(request);
|
||||
if (script == null) {
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中剧本(取消其他选中状态)
|
||||
*/
|
||||
@PutMapping(value = "/select")
|
||||
public Result<EpicScriptResponse> select(@RequestParam String id) {
|
||||
EpicScriptResponse script = epicScriptService.selectScript(id);
|
||||
if (script == null) {
|
||||
return Result.error("选中失败");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除爽文剧本
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<Void> delete(@RequestParam String id) {
|
||||
boolean deleted = epicScriptService.deleteScript(id);
|
||||
if (!deleted) {
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.dto.request.LifeEventCreateRequest;
|
||||
import com.emotion.dto.request.LifeEventPageRequest;
|
||||
import com.emotion.dto.request.LifeEventUpdateRequest;
|
||||
import com.emotion.dto.response.LifeEventResponse;
|
||||
import com.emotion.service.LifeEventService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生命事件控制器
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/lifeEvent")
|
||||
public class LifeEventController {
|
||||
|
||||
@Autowired
|
||||
private LifeEventService lifeEventService;
|
||||
|
||||
/**
|
||||
* 分页查询当前用户的生命事件
|
||||
*/
|
||||
@GetMapping(value = "/page")
|
||||
public Result<PageResult<LifeEventResponse>> getPage(@Validated LifeEventPageRequest request) {
|
||||
PageResult<LifeEventResponse> pageResult = lifeEventService.getPageByCurrentUser(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的所有生命事件列表
|
||||
*/
|
||||
@GetMapping(value = "/list")
|
||||
public Result<List<LifeEventResponse>> getList() {
|
||||
List<LifeEventResponse> events = lifeEventService.getListByCurrentUser();
|
||||
return Result.success(events);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取生命事件详情
|
||||
*/
|
||||
@GetMapping(value = "/detail")
|
||||
public Result<LifeEventResponse> getById(@RequestParam String id) {
|
||||
LifeEventResponse event = lifeEventService.getEventById(id);
|
||||
if (event == null) {
|
||||
return Result.notFound("生命事件不存在");
|
||||
}
|
||||
return Result.success(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建生命事件
|
||||
*/
|
||||
@PostMapping(value = "/create")
|
||||
public Result<LifeEventResponse> create(@Valid @RequestBody LifeEventCreateRequest request) {
|
||||
LifeEventResponse event = lifeEventService.createEvent(request);
|
||||
if (event == null) {
|
||||
return Result.error("创建失败");
|
||||
}
|
||||
return Result.success(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新生命事件
|
||||
*/
|
||||
@PutMapping(value = "/update")
|
||||
public Result<LifeEventResponse> update(@Valid @RequestBody LifeEventUpdateRequest request) {
|
||||
LifeEventResponse event = lifeEventService.updateEvent(request);
|
||||
if (event == null) {
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
return Result.success(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除生命事件
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<Void> delete(@RequestParam String id) {
|
||||
boolean deleted = lifeEventService.deleteEvent(id);
|
||||
if (!deleted) {
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.dto.request.LifePathCreateRequest;
|
||||
import com.emotion.dto.request.LifePathPageRequest;
|
||||
import com.emotion.dto.request.LifePathUpdateRequest;
|
||||
import com.emotion.dto.response.LifePathResponse;
|
||||
import com.emotion.service.LifePathService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 实现路径控制器
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/lifePath")
|
||||
public class LifePathController {
|
||||
|
||||
@Autowired
|
||||
private LifePathService lifePathService;
|
||||
|
||||
/**
|
||||
* 分页查询当前用户的实现路径
|
||||
*/
|
||||
@GetMapping(value = "/page")
|
||||
public Result<PageResult<LifePathResponse>> getPage(@Validated LifePathPageRequest request) {
|
||||
PageResult<LifePathResponse> pageResult = lifePathService.getPageByCurrentUser(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的所有实现路径列表
|
||||
*/
|
||||
@GetMapping(value = "/listAll")
|
||||
public Result<List<LifePathResponse>> getList() {
|
||||
List<LifePathResponse> paths = lifePathService.getListByCurrentUser();
|
||||
return Result.success(paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据剧本ID获取实现路径
|
||||
*/
|
||||
@GetMapping(value = "/byScript")
|
||||
public Result<LifePathResponse> getByScriptId(@RequestParam String scriptId) {
|
||||
LifePathResponse path = lifePathService.getByScriptId(scriptId);
|
||||
if (path == null) {
|
||||
return Result.notFound("实现路径不存在");
|
||||
}
|
||||
return Result.success(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取实现路径详情
|
||||
*/
|
||||
@GetMapping(value = "/detail")
|
||||
public Result<LifePathResponse> getById(@RequestParam String id) {
|
||||
LifePathResponse path = lifePathService.getPathById(id);
|
||||
if (path == null) {
|
||||
return Result.notFound("实现路径不存在");
|
||||
}
|
||||
return Result.success(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建实现路径
|
||||
*/
|
||||
@PostMapping(value = "/create")
|
||||
public Result<LifePathResponse> create(@Valid @RequestBody LifePathCreateRequest request) {
|
||||
LifePathResponse path = lifePathService.createPath(request);
|
||||
if (path == null) {
|
||||
return Result.error("创建失败");
|
||||
}
|
||||
return Result.success(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新实现路径
|
||||
*/
|
||||
@PutMapping(value = "/update")
|
||||
public Result<LifePathResponse> update(@Valid @RequestBody LifePathUpdateRequest request) {
|
||||
LifePathResponse path = lifePathService.updatePath(request);
|
||||
if (path == null) {
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
return Result.success(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除实现路径
|
||||
*/
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<Void> delete(@RequestParam String id) {
|
||||
boolean deleted = lifePathService.deletePath(id);
|
||||
if (!deleted) {
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 爽文剧本创建请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class EpicScriptCreateRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 剧本标题
|
||||
*/
|
||||
@NotBlank(message = "剧本标题不能为空")
|
||||
@Size(max = 200, message = "剧本标题长度不能超过200个字符")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 剧本主题/渴望
|
||||
*/
|
||||
private String theme;
|
||||
|
||||
/**
|
||||
* 剧本风格: career-职场逆袭, love-情感圆满, fantasy-玄幻觉醒
|
||||
*/
|
||||
private String style;
|
||||
|
||||
/**
|
||||
* 篇幅长度: medium-标准篇, long-长篇
|
||||
*/
|
||||
private String length;
|
||||
|
||||
/**
|
||||
* 序幕:低谷回响
|
||||
*/
|
||||
private String plotIntro;
|
||||
|
||||
/**
|
||||
* 转折:契机出现
|
||||
*/
|
||||
private String plotTurning;
|
||||
|
||||
/**
|
||||
* 高潮:命运抉择
|
||||
*/
|
||||
private String plotClimax;
|
||||
|
||||
/**
|
||||
* 结局:新的开始
|
||||
*/
|
||||
private String plotEnding;
|
||||
|
||||
/**
|
||||
* 完整剧情JSON结构
|
||||
*/
|
||||
private Map<String, Object> plotJson;
|
||||
|
||||
/**
|
||||
* 是否当前选中
|
||||
*/
|
||||
private Boolean isSelected;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import com.emotion.common.BasePageRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 爽文剧本分页查询请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class EpicScriptPageRequest extends BasePageRequest {
|
||||
|
||||
/**
|
||||
* 剧本风格筛选
|
||||
*/
|
||||
private String style;
|
||||
|
||||
/**
|
||||
* 篇幅长度筛选
|
||||
*/
|
||||
private String length;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 爽文剧本更新请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class EpicScriptUpdateRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 剧本ID
|
||||
*/
|
||||
@NotBlank(message = "剧本ID不能为空")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 剧本标题
|
||||
*/
|
||||
@Size(max = 200, message = "剧本标题长度不能超过200个字符")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 剧本主题/渴望
|
||||
*/
|
||||
private String theme;
|
||||
|
||||
/**
|
||||
* 剧本风格: career-职场逆袭, love-情感圆满, fantasy-玄幻觉醒
|
||||
*/
|
||||
private String style;
|
||||
|
||||
/**
|
||||
* 篇幅长度: medium-标准篇, long-长篇
|
||||
*/
|
||||
private String length;
|
||||
|
||||
/**
|
||||
* 序幕:低谷回响
|
||||
*/
|
||||
private String plotIntro;
|
||||
|
||||
/**
|
||||
* 转折:契机出现
|
||||
*/
|
||||
private String plotTurning;
|
||||
|
||||
/**
|
||||
* 高潮:命运抉择
|
||||
*/
|
||||
private String plotClimax;
|
||||
|
||||
/**
|
||||
* 结局:新的开始
|
||||
*/
|
||||
private String plotEnding;
|
||||
|
||||
/**
|
||||
* 完整剧情JSON结构
|
||||
*/
|
||||
private Map<String, Object> plotJson;
|
||||
|
||||
/**
|
||||
* 是否当前选中
|
||||
*/
|
||||
private Boolean isSelected;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生命事件创建请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifeEventCreateRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 事件类型: daily_log-日常记录, milestone-里程碑
|
||||
*/
|
||||
private String eventType;
|
||||
|
||||
/**
|
||||
* 事件日期 (ISO格式字符串)
|
||||
*/
|
||||
private String eventDate;
|
||||
|
||||
/**
|
||||
* 事件标题
|
||||
*/
|
||||
@NotBlank(message = "事件标题不能为空")
|
||||
@Size(max = 200, message = "事件标题长度不能超过200个字符")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 事件内容
|
||||
*/
|
||||
@NotBlank(message = "事件内容不能为空")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* AI疗愈回复
|
||||
*/
|
||||
private String aiReply;
|
||||
|
||||
/**
|
||||
* 情绪类型
|
||||
*/
|
||||
private String emotionType;
|
||||
|
||||
/**
|
||||
* 情绪评分
|
||||
*/
|
||||
private Double emotionScore;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tags;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import com.emotion.common.BasePageRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 生命事件分页查询请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifeEventPageRequest extends BasePageRequest {
|
||||
|
||||
/**
|
||||
* 事件类型筛选
|
||||
*/
|
||||
private String eventType;
|
||||
|
||||
/**
|
||||
* 开始日期
|
||||
*/
|
||||
private String startDate;
|
||||
|
||||
/**
|
||||
* 结束日期
|
||||
*/
|
||||
private String endDate;
|
||||
|
||||
/**
|
||||
* 情绪类型筛选
|
||||
*/
|
||||
private String emotionType;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生命事件更新请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifeEventUpdateRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 事件ID
|
||||
*/
|
||||
@NotBlank(message = "事件ID不能为空")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 事件类型: daily_log-日常记录, milestone-里程碑
|
||||
*/
|
||||
private String eventType;
|
||||
|
||||
/**
|
||||
* 事件日期 (ISO格式字符串)
|
||||
*/
|
||||
private String eventDate;
|
||||
|
||||
/**
|
||||
* 事件标题
|
||||
*/
|
||||
@Size(max = 200, message = "事件标题长度不能超过200个字符")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 事件内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* AI疗愈回复
|
||||
*/
|
||||
private String aiReply;
|
||||
|
||||
/**
|
||||
* 情绪类型
|
||||
*/
|
||||
private String emotionType;
|
||||
|
||||
/**
|
||||
* 情绪评分
|
||||
*/
|
||||
private Double emotionScore;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tags;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 实现路径创建请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifePathCreateRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 关联剧本ID
|
||||
*/
|
||||
@NotBlank(message = "关联剧本ID不能为空")
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 路径标题
|
||||
*/
|
||||
@Size(max = 200, message = "路径标题长度不能超过200个字符")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路径描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 路径步骤列表
|
||||
* 每个步骤包含: phase, time, content, action, resources, habit
|
||||
*/
|
||||
private List<Map<String, Object>> steps;
|
||||
|
||||
/**
|
||||
* 状态: active-进行中, completed-已完成, archived-已归档
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 完成进度百分比
|
||||
*/
|
||||
private Double progress;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import com.emotion.common.BasePageRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 实现路径分页查询请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifePathPageRequest extends BasePageRequest {
|
||||
|
||||
/**
|
||||
* 关联剧本ID筛选
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 状态筛选
|
||||
*/
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.emotion.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 实现路径更新请求
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifePathUpdateRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 路径ID
|
||||
*/
|
||||
@NotBlank(message = "路径ID不能为空")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 路径标题
|
||||
*/
|
||||
@Size(max = 200, message = "路径标题长度不能超过200个字符")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路径描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 路径步骤列表
|
||||
* 每个步骤包含: phase, time, content, action, resources, habit
|
||||
*/
|
||||
private List<Map<String, Object>> steps;
|
||||
|
||||
/**
|
||||
* 状态: active-进行中, completed-已完成, archived-已归档
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 完成进度百分比
|
||||
*/
|
||||
private Double progress;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.emotion.dto.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 爽文剧本响应
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class EpicScriptResponse extends BaseResponse {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 剧本标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 剧本主题/渴望
|
||||
*/
|
||||
private String theme;
|
||||
|
||||
/**
|
||||
* 剧本风格
|
||||
*/
|
||||
private String style;
|
||||
|
||||
/**
|
||||
* 篇幅长度
|
||||
*/
|
||||
private String length;
|
||||
|
||||
/**
|
||||
* 序幕:低谷回响
|
||||
*/
|
||||
private String plotIntro;
|
||||
|
||||
/**
|
||||
* 转折:契机出现
|
||||
*/
|
||||
private String plotTurning;
|
||||
|
||||
/**
|
||||
* 高潮:命运抉择
|
||||
*/
|
||||
private String plotClimax;
|
||||
|
||||
/**
|
||||
* 结局:新的开始
|
||||
*/
|
||||
private String plotEnding;
|
||||
|
||||
/**
|
||||
* 完整剧情JSON结构
|
||||
*/
|
||||
private Map<String, Object> plotJson;
|
||||
|
||||
/**
|
||||
* 是否当前选中
|
||||
*/
|
||||
private Boolean isSelected;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.emotion.dto.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生命事件响应
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifeEventResponse extends BaseResponse {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 事件类型
|
||||
*/
|
||||
private String eventType;
|
||||
|
||||
/**
|
||||
* 事件日期
|
||||
*/
|
||||
private String eventDate;
|
||||
|
||||
/**
|
||||
* 事件标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 事件内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* AI疗愈回复
|
||||
*/
|
||||
private String aiReply;
|
||||
|
||||
/**
|
||||
* 情绪类型
|
||||
*/
|
||||
private String emotionType;
|
||||
|
||||
/**
|
||||
* 情绪评分
|
||||
*/
|
||||
private Double emotionScore;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tags;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.emotion.dto.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 实现路径响应
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LifePathResponse extends BaseResponse {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 关联剧本ID
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 路径标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路径描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 路径步骤列表
|
||||
*/
|
||||
private List<Map<String, Object>> steps;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 完成进度百分比
|
||||
*/
|
||||
private Double progress;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.emotion.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.emotion.common.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 爽文剧本实体类
|
||||
* 存储用户生成的爽文剧本,包括主题、风格、剧情章节等
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName(value = "t_epic_script", autoResultMap = true)
|
||||
public class EpicScript extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID (关联t_user.id)
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 剧本标题
|
||||
*/
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 剧本主题/渴望
|
||||
*/
|
||||
@TableField("theme")
|
||||
private String theme;
|
||||
|
||||
/**
|
||||
* 剧本风格: career-职场逆袭, love-情感圆满, fantasy-玄幻觉醒
|
||||
*/
|
||||
@TableField("style")
|
||||
private String style;
|
||||
|
||||
/**
|
||||
* 篇幅长度: medium-标准篇, long-长篇
|
||||
*/
|
||||
@TableField("length")
|
||||
private String length;
|
||||
|
||||
/**
|
||||
* 序幕:低谷回响
|
||||
*/
|
||||
@TableField("plot_intro")
|
||||
private String plotIntro;
|
||||
|
||||
/**
|
||||
* 转折:契机出现
|
||||
*/
|
||||
@TableField("plot_turning")
|
||||
private String plotTurning;
|
||||
|
||||
/**
|
||||
* 高潮:命运抉择
|
||||
*/
|
||||
@TableField("plot_climax")
|
||||
private String plotClimax;
|
||||
|
||||
/**
|
||||
* 结局:新的开始
|
||||
*/
|
||||
@TableField("plot_ending")
|
||||
private String plotEnding;
|
||||
|
||||
/**
|
||||
* 完整剧情JSON结构
|
||||
*/
|
||||
@TableField(value = "plot_json", typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String, Object> plotJson;
|
||||
|
||||
/**
|
||||
* 是否当前选中: 0-否, 1-是
|
||||
*/
|
||||
@TableField("is_selected")
|
||||
private Integer isSelected;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.emotion.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.emotion.common.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生命事件实体类
|
||||
* 存储用户的人生轨迹事件,包括日期、标题、内容、AI回复等
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName(value = "t_life_event", autoResultMap = true)
|
||||
public class LifeEvent extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID (关联t_user.id)
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 事件类型: daily_log-日常记录, milestone-里程碑
|
||||
*/
|
||||
@TableField("event_type")
|
||||
private String eventType;
|
||||
|
||||
/**
|
||||
* 事件日期
|
||||
*/
|
||||
@TableField("event_date")
|
||||
private LocalDateTime eventDate;
|
||||
|
||||
/**
|
||||
* 事件标题
|
||||
*/
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 事件内容
|
||||
*/
|
||||
@TableField("content")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* AI疗愈回复
|
||||
*/
|
||||
@TableField("ai_reply")
|
||||
private String aiReply;
|
||||
|
||||
/**
|
||||
* 情绪类型
|
||||
*/
|
||||
@TableField("emotion_type")
|
||||
private String emotionType;
|
||||
|
||||
/**
|
||||
* 情绪评分
|
||||
*/
|
||||
@TableField("emotion_score")
|
||||
private BigDecimal emotionScore;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
@TableField(value = "tags", typeHandler = JacksonTypeHandler.class)
|
||||
private List<String> tags;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.emotion.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.emotion.common.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 实现路径实体类
|
||||
* 存储基于剧本生成的实现路径规划
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName(value = "t_life_path", autoResultMap = true)
|
||||
public class LifePath extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID (关联t_user.id)
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 关联剧本ID (关联t_epic_script.id)
|
||||
*/
|
||||
@TableField("script_id")
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 路径标题
|
||||
*/
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路径描述
|
||||
*/
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 路径步骤列表 (JSON数组)
|
||||
* 每个步骤包含: phase, time, content, action, resources, habit
|
||||
*/
|
||||
@TableField(value = "steps", typeHandler = JacksonTypeHandler.class)
|
||||
private List<Map<String, Object>> steps;
|
||||
|
||||
/**
|
||||
* 状态: active-进行中, completed-已完成, archived-已归档
|
||||
*/
|
||||
@TableField("status")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 完成进度百分比
|
||||
*/
|
||||
@TableField("progress")
|
||||
private BigDecimal progress;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.emotion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.emotion.entity.EpicScript;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 爽文剧本Mapper接口
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Mapper
|
||||
public interface EpicScriptMapper extends BaseMapper<EpicScript> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.emotion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.emotion.entity.LifeEvent;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 生命事件Mapper接口
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Mapper
|
||||
public interface LifeEventMapper extends BaseMapper<LifeEvent> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.emotion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.emotion.entity.LifePath;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 实现路径Mapper接口
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Mapper
|
||||
public interface LifePathMapper extends BaseMapper<LifePath> {
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.emotion.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.dto.request.EpicScriptCreateRequest;
|
||||
import com.emotion.dto.request.EpicScriptPageRequest;
|
||||
import com.emotion.dto.request.EpicScriptUpdateRequest;
|
||||
import com.emotion.dto.response.EpicScriptResponse;
|
||||
import com.emotion.entity.EpicScript;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 爽文剧本服务接口
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
public interface EpicScriptService extends IService<EpicScript> {
|
||||
|
||||
/**
|
||||
* 分页查询当前用户的剧本
|
||||
*
|
||||
* @param request 分页请求
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResult<EpicScriptResponse> getPageByCurrentUser(EpicScriptPageRequest request);
|
||||
|
||||
/**
|
||||
* 获取当前用户的所有剧本列表
|
||||
*
|
||||
* @return 剧本列表
|
||||
*/
|
||||
List<EpicScriptResponse> getListByCurrentUser();
|
||||
|
||||
/**
|
||||
* 根据ID获取剧本
|
||||
*
|
||||
* @param id 剧本ID
|
||||
* @return 剧本响应
|
||||
*/
|
||||
EpicScriptResponse getScriptById(String id);
|
||||
|
||||
/**
|
||||
* 创建剧本
|
||||
*
|
||||
* @param request 创建请求
|
||||
* @return 剧本响应
|
||||
*/
|
||||
EpicScriptResponse createScript(EpicScriptCreateRequest request);
|
||||
|
||||
/**
|
||||
* 更新剧本
|
||||
*
|
||||
* @param request 更新请求
|
||||
* @return 剧本响应
|
||||
*/
|
||||
EpicScriptResponse updateScript(EpicScriptUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 选中剧本
|
||||
*
|
||||
* @param id 剧本ID
|
||||
* @return 剧本响应
|
||||
*/
|
||||
EpicScriptResponse selectScript(String id);
|
||||
|
||||
/**
|
||||
* 删除剧本
|
||||
*
|
||||
* @param id 剧本ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteScript(String id);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.emotion.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.dto.request.LifeEventCreateRequest;
|
||||
import com.emotion.dto.request.LifeEventPageRequest;
|
||||
import com.emotion.dto.request.LifeEventUpdateRequest;
|
||||
import com.emotion.dto.response.LifeEventResponse;
|
||||
import com.emotion.entity.LifeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生命事件服务接口
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
public interface LifeEventService extends IService<LifeEvent> {
|
||||
|
||||
/**
|
||||
* 分页查询当前用户的生命事件
|
||||
*
|
||||
* @param request 分页请求
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResult<LifeEventResponse> getPageByCurrentUser(LifeEventPageRequest request);
|
||||
|
||||
/**
|
||||
* 获取当前用户的所有生命事件列表
|
||||
*
|
||||
* @return 事件列表
|
||||
*/
|
||||
List<LifeEventResponse> getListByCurrentUser();
|
||||
|
||||
/**
|
||||
* 根据ID获取生命事件
|
||||
*
|
||||
* @param id 事件ID
|
||||
* @return 事件响应
|
||||
*/
|
||||
LifeEventResponse getEventById(String id);
|
||||
|
||||
/**
|
||||
* 创建生命事件
|
||||
*
|
||||
* @param request 创建请求
|
||||
* @return 事件响应
|
||||
*/
|
||||
LifeEventResponse createEvent(LifeEventCreateRequest request);
|
||||
|
||||
/**
|
||||
* 更新生命事件
|
||||
*
|
||||
* @param request 更新请求
|
||||
* @return 事件响应
|
||||
*/
|
||||
LifeEventResponse updateEvent(LifeEventUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 删除生命事件
|
||||
*
|
||||
* @param id 事件ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteEvent(String id);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.emotion.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.dto.request.LifePathCreateRequest;
|
||||
import com.emotion.dto.request.LifePathPageRequest;
|
||||
import com.emotion.dto.request.LifePathUpdateRequest;
|
||||
import com.emotion.dto.response.LifePathResponse;
|
||||
import com.emotion.entity.LifePath;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 实现路径服务接口
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
public interface LifePathService extends IService<LifePath> {
|
||||
|
||||
/**
|
||||
* 分页查询当前用户的路径
|
||||
*
|
||||
* @param request 分页请求
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResult<LifePathResponse> getPageByCurrentUser(LifePathPageRequest request);
|
||||
|
||||
/**
|
||||
* 获取当前用户的所有路径列表
|
||||
*
|
||||
* @return 路径列表
|
||||
*/
|
||||
List<LifePathResponse> getListByCurrentUser();
|
||||
|
||||
/**
|
||||
* 根据剧本ID获取路径
|
||||
*
|
||||
* @param scriptId 剧本ID
|
||||
* @return 路径响应
|
||||
*/
|
||||
LifePathResponse getByScriptId(String scriptId);
|
||||
|
||||
/**
|
||||
* 根据ID获取路径
|
||||
*
|
||||
* @param id 路径ID
|
||||
* @return 路径响应
|
||||
*/
|
||||
LifePathResponse getPathById(String id);
|
||||
|
||||
/**
|
||||
* 创建路径
|
||||
*
|
||||
* @param request 创建请求
|
||||
* @return 路径响应
|
||||
*/
|
||||
LifePathResponse createPath(LifePathCreateRequest request);
|
||||
|
||||
/**
|
||||
* 更新路径
|
||||
*
|
||||
* @param request 更新请求
|
||||
* @return 路径响应
|
||||
*/
|
||||
LifePathResponse updatePath(LifePathUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 删除路径
|
||||
*
|
||||
* @param id 路径ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deletePath(String id);
|
||||
|
||||
/**
|
||||
* 根据剧本ID删除路径
|
||||
*
|
||||
* @param scriptId 剧本ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteByScriptId(String scriptId);
|
||||
}
|
||||
@@ -121,6 +121,14 @@ public class AiConfigServiceImpl extends ServiceImpl<AiConfigMapper, AiConfig> i
|
||||
BeanUtils.copyProperties(request, aiConfig);
|
||||
aiConfig.setId(String.valueOf(snowflakeIdGenerator.nextId()));
|
||||
|
||||
// 处理JSON字段,防止空字符串导致数据库报错
|
||||
if (!StringUtils.hasText(aiConfig.getCustomHeaders())) {
|
||||
aiConfig.setCustomHeaders("{}");
|
||||
}
|
||||
if (!StringUtils.hasText(aiConfig.getCustomParams())) {
|
||||
aiConfig.setCustomParams("{}");
|
||||
}
|
||||
|
||||
boolean saved = this.save(aiConfig);
|
||||
return saved ? convertToResponse(aiConfig) : null;
|
||||
}
|
||||
@@ -133,6 +141,15 @@ public class AiConfigServiceImpl extends ServiceImpl<AiConfigMapper, AiConfig> i
|
||||
}
|
||||
|
||||
BeanUtils.copyProperties(request, aiConfig);
|
||||
|
||||
// 处理JSON字段,防止空字符串导致数据库报错
|
||||
if (request.getCustomHeaders() != null && !StringUtils.hasText(request.getCustomHeaders())) {
|
||||
aiConfig.setCustomHeaders("{}");
|
||||
}
|
||||
if (request.getCustomParams() != null && !StringUtils.hasText(request.getCustomParams())) {
|
||||
aiConfig.setCustomParams("{}");
|
||||
}
|
||||
|
||||
boolean updated = this.updateById(aiConfig);
|
||||
return updated ? convertToResponse(aiConfig) : null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
package com.emotion.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.dto.request.EpicScriptCreateRequest;
|
||||
import com.emotion.dto.request.EpicScriptPageRequest;
|
||||
import com.emotion.dto.request.EpicScriptUpdateRequest;
|
||||
import com.emotion.dto.response.EpicScriptResponse;
|
||||
import com.emotion.entity.EpicScript;
|
||||
import com.emotion.mapper.EpicScriptMapper;
|
||||
import com.emotion.service.EpicScriptService;
|
||||
import com.emotion.service.LifePathService;
|
||||
import com.emotion.util.UserContextHolder;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 爽文剧本服务实现类
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Service
|
||||
public class EpicScriptServiceImpl extends ServiceImpl<EpicScriptMapper, EpicScript>
|
||||
implements EpicScriptService {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private LifePathService lifePathService;
|
||||
|
||||
@Override
|
||||
public PageResult<EpicScriptResponse> getPageByCurrentUser(EpicScriptPageRequest request) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return new PageResult<>();
|
||||
}
|
||||
|
||||
Page<EpicScript> page = new Page<>(request.getCurrent(), request.getSize());
|
||||
LambdaQueryWrapper<EpicScript> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EpicScript::getUserId, currentUserId)
|
||||
.eq(EpicScript::getIsDeleted, 0);
|
||||
|
||||
// 风格筛选
|
||||
if (StringUtils.hasText(request.getStyle())) {
|
||||
wrapper.eq(EpicScript::getStyle, request.getStyle());
|
||||
}
|
||||
|
||||
// 篇幅筛选
|
||||
if (StringUtils.hasText(request.getLength())) {
|
||||
wrapper.eq(EpicScript::getLength, request.getLength());
|
||||
}
|
||||
|
||||
// 关键词搜索
|
||||
if (StringUtils.hasText(request.getKeyword())) {
|
||||
wrapper.and(w -> w.like(EpicScript::getTitle, request.getKeyword())
|
||||
.or().like(EpicScript::getTheme, request.getKeyword()));
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
wrapper.orderByDesc(EpicScript::getCreateTime);
|
||||
|
||||
Page<EpicScript> resultPage = this.page(page, wrapper);
|
||||
List<EpicScriptResponse> responses = resultPage.getRecords().stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PageResult<EpicScriptResponse> pageResult = new PageResult<>();
|
||||
pageResult.setCurrent(resultPage.getCurrent());
|
||||
pageResult.setSize(resultPage.getSize());
|
||||
pageResult.setTotal(resultPage.getTotal());
|
||||
pageResult.setPages(resultPage.getPages());
|
||||
pageResult.setRecords(responses);
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EpicScriptResponse> getListByCurrentUser() {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<EpicScript> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EpicScript::getUserId, currentUserId)
|
||||
.eq(EpicScript::getIsDeleted, 0)
|
||||
.orderByDesc(EpicScript::getCreateTime);
|
||||
|
||||
return this.list(wrapper).stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EpicScriptResponse getScriptById(String id) {
|
||||
EpicScript script = this.getById(id);
|
||||
if (script == null || script.getIsDeleted() == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!script.getUserId().equals(currentUserId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return convertToResponse(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EpicScriptResponse createScript(EpicScriptCreateRequest request) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
EpicScript script = new EpicScript();
|
||||
script.setUserId(currentUserId);
|
||||
script.setTitle(request.getTitle());
|
||||
script.setTheme(request.getTheme());
|
||||
script.setStyle(StringUtils.hasText(request.getStyle()) ? request.getStyle() : "career");
|
||||
script.setLength(StringUtils.hasText(request.getLength()) ? request.getLength() : "medium");
|
||||
script.setPlotIntro(request.getPlotIntro());
|
||||
script.setPlotTurning(request.getPlotTurning());
|
||||
script.setPlotClimax(request.getPlotClimax());
|
||||
script.setPlotEnding(request.getPlotEnding());
|
||||
script.setPlotJson(request.getPlotJson());
|
||||
script.setIsSelected(request.getIsSelected() != null && request.getIsSelected() ? 1 : 0);
|
||||
|
||||
this.save(script);
|
||||
return convertToResponse(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EpicScriptResponse updateScript(EpicScriptUpdateRequest request) {
|
||||
EpicScript script = this.getById(request.getId());
|
||||
if (script == null || script.getIsDeleted() == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!script.getUserId().equals(currentUserId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 更新字段
|
||||
if (StringUtils.hasText(request.getTitle())) {
|
||||
script.setTitle(request.getTitle());
|
||||
}
|
||||
if (request.getTheme() != null) {
|
||||
script.setTheme(request.getTheme());
|
||||
}
|
||||
if (StringUtils.hasText(request.getStyle())) {
|
||||
script.setStyle(request.getStyle());
|
||||
}
|
||||
if (StringUtils.hasText(request.getLength())) {
|
||||
script.setLength(request.getLength());
|
||||
}
|
||||
if (request.getPlotIntro() != null) {
|
||||
script.setPlotIntro(request.getPlotIntro());
|
||||
}
|
||||
if (request.getPlotTurning() != null) {
|
||||
script.setPlotTurning(request.getPlotTurning());
|
||||
}
|
||||
if (request.getPlotClimax() != null) {
|
||||
script.setPlotClimax(request.getPlotClimax());
|
||||
}
|
||||
if (request.getPlotEnding() != null) {
|
||||
script.setPlotEnding(request.getPlotEnding());
|
||||
}
|
||||
if (request.getPlotJson() != null) {
|
||||
script.setPlotJson(request.getPlotJson());
|
||||
}
|
||||
if (request.getIsSelected() != null) {
|
||||
script.setIsSelected(request.getIsSelected() ? 1 : 0);
|
||||
}
|
||||
|
||||
this.updateById(script);
|
||||
return convertToResponse(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EpicScriptResponse selectScript(String id) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 先取消所有选中
|
||||
LambdaQueryWrapper<EpicScript> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EpicScript::getUserId, currentUserId)
|
||||
.eq(EpicScript::getIsSelected, 1)
|
||||
.eq(EpicScript::getIsDeleted, 0);
|
||||
List<EpicScript> selectedScripts = this.list(wrapper);
|
||||
for (EpicScript s : selectedScripts) {
|
||||
s.setIsSelected(0);
|
||||
this.updateById(s);
|
||||
}
|
||||
|
||||
// 选中指定剧本
|
||||
EpicScript script = this.getById(id);
|
||||
if (script == null || script.getIsDeleted() == 1) {
|
||||
return null;
|
||||
}
|
||||
if (!script.getUserId().equals(currentUserId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
script.setIsSelected(1);
|
||||
this.updateById(script);
|
||||
return convertToResponse(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteScript(String id) {
|
||||
EpicScript script = this.getById(id);
|
||||
if (script == null || script.getIsDeleted() == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!script.getUserId().equals(currentUserId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 删除关联的路径
|
||||
lifePathService.deleteByScriptId(id);
|
||||
|
||||
script.setIsDeleted(1);
|
||||
return this.updateById(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为响应对象
|
||||
*/
|
||||
private EpicScriptResponse convertToResponse(EpicScript script) {
|
||||
EpicScriptResponse response = new EpicScriptResponse();
|
||||
BeanUtils.copyProperties(script, response);
|
||||
response.setId(script.getId());
|
||||
response.setIsSelected(script.getIsSelected() != null && script.getIsSelected() == 1);
|
||||
if (script.getCreateTime() != null) {
|
||||
response.setCreateTime(script.getCreateTime().format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
if (script.getUpdateTime() != null) {
|
||||
response.setUpdateTime(script.getUpdateTime().format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package com.emotion.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.dto.request.LifeEventCreateRequest;
|
||||
import com.emotion.dto.request.LifeEventPageRequest;
|
||||
import com.emotion.dto.request.LifeEventUpdateRequest;
|
||||
import com.emotion.dto.response.LifeEventResponse;
|
||||
import com.emotion.entity.LifeEvent;
|
||||
import com.emotion.mapper.LifeEventMapper;
|
||||
import com.emotion.service.LifeEventService;
|
||||
import com.emotion.util.UserContextHolder;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 生命事件服务实现类
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Service
|
||||
public class LifeEventServiceImpl extends ServiceImpl<LifeEventMapper, LifeEvent>
|
||||
implements LifeEventService {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private static final DateTimeFormatter ISO_FORMATTER = DateTimeFormatter.ISO_DATE_TIME;
|
||||
|
||||
@Override
|
||||
public PageResult<LifeEventResponse> getPageByCurrentUser(LifeEventPageRequest request) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return new PageResult<>();
|
||||
}
|
||||
|
||||
Page<LifeEvent> page = new Page<>(request.getCurrent(), request.getSize());
|
||||
LambdaQueryWrapper<LifeEvent> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(LifeEvent::getUserId, currentUserId)
|
||||
.eq(LifeEvent::getIsDeleted, 0);
|
||||
|
||||
// 事件类型筛选
|
||||
if (StringUtils.hasText(request.getEventType())) {
|
||||
wrapper.eq(LifeEvent::getEventType, request.getEventType());
|
||||
}
|
||||
|
||||
// 情绪类型筛选
|
||||
if (StringUtils.hasText(request.getEmotionType())) {
|
||||
wrapper.eq(LifeEvent::getEmotionType, request.getEmotionType());
|
||||
}
|
||||
|
||||
// 关键词搜索
|
||||
if (StringUtils.hasText(request.getKeyword())) {
|
||||
wrapper.and(w -> w.like(LifeEvent::getTitle, request.getKeyword())
|
||||
.or().like(LifeEvent::getContent, request.getKeyword()));
|
||||
}
|
||||
|
||||
// 按事件日期倒序排列
|
||||
wrapper.orderByDesc(LifeEvent::getEventDate);
|
||||
|
||||
Page<LifeEvent> resultPage = this.page(page, wrapper);
|
||||
List<LifeEventResponse> responses = resultPage.getRecords().stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PageResult<LifeEventResponse> pageResult = new PageResult<>();
|
||||
pageResult.setCurrent(resultPage.getCurrent());
|
||||
pageResult.setSize(resultPage.getSize());
|
||||
pageResult.setTotal(resultPage.getTotal());
|
||||
pageResult.setPages(resultPage.getPages());
|
||||
pageResult.setRecords(responses);
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LifeEventResponse> getListByCurrentUser() {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<LifeEvent> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(LifeEvent::getUserId, currentUserId)
|
||||
.eq(LifeEvent::getIsDeleted, 0)
|
||||
.orderByDesc(LifeEvent::getEventDate);
|
||||
|
||||
return this.list(wrapper).stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifeEventResponse getEventById(String id) {
|
||||
LifeEvent event = this.getById(id);
|
||||
if (event == null || event.getIsDeleted() == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!event.getUserId().equals(currentUserId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return convertToResponse(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifeEventResponse createEvent(LifeEventCreateRequest request) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LifeEvent event = new LifeEvent();
|
||||
event.setUserId(currentUserId);
|
||||
event.setEventType(StringUtils.hasText(request.getEventType()) ? request.getEventType() : "daily_log");
|
||||
event.setTitle(request.getTitle());
|
||||
event.setContent(request.getContent());
|
||||
event.setAiReply(request.getAiReply());
|
||||
event.setEmotionType(request.getEmotionType());
|
||||
event.setTags(request.getTags());
|
||||
|
||||
// 解析事件日期
|
||||
if (StringUtils.hasText(request.getEventDate())) {
|
||||
try {
|
||||
event.setEventDate(LocalDateTime.parse(request.getEventDate(), ISO_FORMATTER));
|
||||
} catch (Exception e) {
|
||||
event.setEventDate(LocalDateTime.now());
|
||||
}
|
||||
} else {
|
||||
event.setEventDate(LocalDateTime.now());
|
||||
}
|
||||
|
||||
// 情绪评分
|
||||
if (request.getEmotionScore() != null) {
|
||||
event.setEmotionScore(BigDecimal.valueOf(request.getEmotionScore()));
|
||||
}
|
||||
|
||||
this.save(event);
|
||||
return convertToResponse(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifeEventResponse updateEvent(LifeEventUpdateRequest request) {
|
||||
LifeEvent event = this.getById(request.getId());
|
||||
if (event == null || event.getIsDeleted() == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!event.getUserId().equals(currentUserId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 更新字段
|
||||
if (StringUtils.hasText(request.getEventType())) {
|
||||
event.setEventType(request.getEventType());
|
||||
}
|
||||
if (StringUtils.hasText(request.getTitle())) {
|
||||
event.setTitle(request.getTitle());
|
||||
}
|
||||
if (StringUtils.hasText(request.getContent())) {
|
||||
event.setContent(request.getContent());
|
||||
}
|
||||
if (request.getAiReply() != null) {
|
||||
event.setAiReply(request.getAiReply());
|
||||
}
|
||||
if (request.getEmotionType() != null) {
|
||||
event.setEmotionType(request.getEmotionType());
|
||||
}
|
||||
if (request.getTags() != null) {
|
||||
event.setTags(request.getTags());
|
||||
}
|
||||
if (StringUtils.hasText(request.getEventDate())) {
|
||||
try {
|
||||
event.setEventDate(LocalDateTime.parse(request.getEventDate(), ISO_FORMATTER));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (request.getEmotionScore() != null) {
|
||||
event.setEmotionScore(BigDecimal.valueOf(request.getEmotionScore()));
|
||||
}
|
||||
|
||||
this.updateById(event);
|
||||
return convertToResponse(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteEvent(String id) {
|
||||
LifeEvent event = this.getById(id);
|
||||
if (event == null || event.getIsDeleted() == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!event.getUserId().equals(currentUserId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
event.setIsDeleted(1);
|
||||
return this.updateById(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为响应对象
|
||||
*/
|
||||
private LifeEventResponse convertToResponse(LifeEvent event) {
|
||||
LifeEventResponse response = new LifeEventResponse();
|
||||
BeanUtils.copyProperties(event, response);
|
||||
response.setId(event.getId());
|
||||
if (event.getEventDate() != null) {
|
||||
response.setEventDate(event.getEventDate().format(ISO_FORMATTER));
|
||||
}
|
||||
if (event.getEmotionScore() != null) {
|
||||
response.setEmotionScore(event.getEmotionScore().doubleValue());
|
||||
}
|
||||
if (event.getCreateTime() != null) {
|
||||
response.setCreateTime(event.getCreateTime().format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
if (event.getUpdateTime() != null) {
|
||||
response.setUpdateTime(event.getUpdateTime().format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package com.emotion.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.dto.request.LifePathCreateRequest;
|
||||
import com.emotion.dto.request.LifePathPageRequest;
|
||||
import com.emotion.dto.request.LifePathUpdateRequest;
|
||||
import com.emotion.dto.response.LifePathResponse;
|
||||
import com.emotion.entity.LifePath;
|
||||
import com.emotion.mapper.LifePathMapper;
|
||||
import com.emotion.service.LifePathService;
|
||||
import com.emotion.util.UserContextHolder;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 实现路径服务实现类
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Service
|
||||
public class LifePathServiceImpl extends ServiceImpl<LifePathMapper, LifePath>
|
||||
implements LifePathService {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public PageResult<LifePathResponse> getPageByCurrentUser(LifePathPageRequest request) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return new PageResult<>();
|
||||
}
|
||||
|
||||
Page<LifePath> page = new Page<>(request.getCurrent(), request.getSize());
|
||||
LambdaQueryWrapper<LifePath> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(LifePath::getUserId, currentUserId)
|
||||
.eq(LifePath::getIsDeleted, 0);
|
||||
|
||||
// 剧本ID筛选
|
||||
if (StringUtils.hasText(request.getScriptId())) {
|
||||
wrapper.eq(LifePath::getScriptId, request.getScriptId());
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
if (StringUtils.hasText(request.getStatus())) {
|
||||
wrapper.eq(LifePath::getStatus, request.getStatus());
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
wrapper.orderByDesc(LifePath::getCreateTime);
|
||||
|
||||
Page<LifePath> resultPage = this.page(page, wrapper);
|
||||
List<LifePathResponse> responses = resultPage.getRecords().stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PageResult<LifePathResponse> pageResult = new PageResult<>();
|
||||
pageResult.setCurrent(resultPage.getCurrent());
|
||||
pageResult.setSize(resultPage.getSize());
|
||||
pageResult.setTotal(resultPage.getTotal());
|
||||
pageResult.setPages(resultPage.getPages());
|
||||
pageResult.setRecords(responses);
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LifePathResponse> getListByCurrentUser() {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<LifePath> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(LifePath::getUserId, currentUserId)
|
||||
.eq(LifePath::getIsDeleted, 0)
|
||||
.orderByDesc(LifePath::getCreateTime);
|
||||
|
||||
return this.list(wrapper).stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifePathResponse getByScriptId(String scriptId) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<LifePath> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(LifePath::getUserId, currentUserId)
|
||||
.eq(LifePath::getScriptId, scriptId)
|
||||
.eq(LifePath::getIsDeleted, 0);
|
||||
|
||||
LifePath path = this.getOne(wrapper);
|
||||
return path != null ? convertToResponse(path) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifePathResponse getPathById(String id) {
|
||||
LifePath path = this.getById(id);
|
||||
if (path == null || path.getIsDeleted() == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!path.getUserId().equals(currentUserId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return convertToResponse(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifePathResponse createPath(LifePathCreateRequest request) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LifePath path = new LifePath();
|
||||
path.setUserId(currentUserId);
|
||||
path.setScriptId(request.getScriptId());
|
||||
path.setTitle(request.getTitle());
|
||||
path.setDescription(request.getDescription());
|
||||
path.setSteps(request.getSteps());
|
||||
path.setStatus(StringUtils.hasText(request.getStatus()) ? request.getStatus() : "active");
|
||||
path.setProgress(request.getProgress() != null ? BigDecimal.valueOf(request.getProgress()) : BigDecimal.ZERO);
|
||||
|
||||
this.save(path);
|
||||
return convertToResponse(path);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LifePathResponse updatePath(LifePathUpdateRequest request) {
|
||||
LifePath path = this.getById(request.getId());
|
||||
if (path == null || path.getIsDeleted() == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!path.getUserId().equals(currentUserId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 更新字段
|
||||
if (StringUtils.hasText(request.getTitle())) {
|
||||
path.setTitle(request.getTitle());
|
||||
}
|
||||
if (request.getDescription() != null) {
|
||||
path.setDescription(request.getDescription());
|
||||
}
|
||||
if (request.getSteps() != null) {
|
||||
path.setSteps(request.getSteps());
|
||||
}
|
||||
if (StringUtils.hasText(request.getStatus())) {
|
||||
path.setStatus(request.getStatus());
|
||||
}
|
||||
if (request.getProgress() != null) {
|
||||
path.setProgress(BigDecimal.valueOf(request.getProgress()));
|
||||
}
|
||||
|
||||
this.updateById(path);
|
||||
return convertToResponse(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePath(String id) {
|
||||
LifePath path = this.getById(id);
|
||||
if (path == null || path.getIsDeleted() == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (!path.getUserId().equals(currentUserId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
path.setIsDeleted(1);
|
||||
return this.updateById(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByScriptId(String scriptId) {
|
||||
String currentUserId = UserContextHolder.getCurrentUserId();
|
||||
if (currentUserId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<LifePath> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(LifePath::getUserId, currentUserId)
|
||||
.eq(LifePath::getScriptId, scriptId)
|
||||
.eq(LifePath::getIsDeleted, 0);
|
||||
|
||||
List<LifePath> paths = this.list(wrapper);
|
||||
for (LifePath path : paths) {
|
||||
path.setIsDeleted(1);
|
||||
this.updateById(path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为响应对象
|
||||
*/
|
||||
private LifePathResponse convertToResponse(LifePath path) {
|
||||
LifePathResponse response = new LifePathResponse();
|
||||
BeanUtils.copyProperties(path, response);
|
||||
response.setId(path.getId());
|
||||
if (path.getProgress() != null) {
|
||||
response.setProgress(path.getProgress().doubleValue());
|
||||
}
|
||||
if (path.getCreateTime() != null) {
|
||||
response.setCreateTime(path.getCreateTime().format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
if (path.getUpdateTime() != null) {
|
||||
response.setUpdateTime(path.getUpdateTime().format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user