Compare commits

...

2 Commits

Author SHA1 Message Date
d405d84dfe perf: 优化故事项查询性能并调整字段映射
All checks were successful
test/timeline-server/pipeline/head This commit looks good
删除 Service 层循环查询图片的逻辑,改为通过 SQL 关联或后续批量处理以减少数据库 IO 开销。同时在 Mapper 中完善字段选择,增加 id、type、status 等必要字段,并移除冗余的 update_time。
2026-02-11 17:09:45 +08:00
120d784345 feat: 完善故事条目功能并优化查询逻辑
1. 更新 StoryItem 实体类,新增 masterItemId、title、description、location 和 share_id 等字段。
2. 扩展 StoryItemVo,支持返回创建者姓名、更新者姓名、图片列表以及时间筛选参数。
3. 修改 StoryItemMapper,将查询结果类型从 StoryItem 变更为 StoryItemVo,并同步更新 SQL 映射。
4. 在 StoryItemServiceImpl 中增加时间过滤逻辑,并在分页查询时自动填充条目关联的图片信息。
2026-02-11 16:35:41 +08:00
5 changed files with 37 additions and 14 deletions

View File

@@ -24,7 +24,7 @@ public interface StoryItemMapper {
List<String> selectImagesByItemId(String itemId); List<String> selectImagesByItemId(String itemId);
List<StoryItem> selectStoryItemByStoryInstanceId(Map map); List<StoryItemVo> selectStoryItemByStoryInstanceId(Map map);
int countByStoryId(String storyInstanceId); int countByStoryId(String storyInstanceId);

View File

@@ -9,13 +9,17 @@ public class StoryItem {
private Long id; private Long id;
private String instanceId; private String instanceId;
private String storyInstanceId; private String storyInstanceId;
private String content; private String masterItemId;
private String title;
private String description;
private String location;
private LocalDateTime storyItemTime; private LocalDateTime storyItemTime;
private String type; private String type;
private String status; private String status;
private String cover; private String cover;
private String createId; private String createId;
private String updateId; private String updateId;
private String shareId;
private LocalDateTime createTime; private LocalDateTime createTime;
private LocalDateTime updateTime; private LocalDateTime updateTime;
private Integer isDelete; private Integer isDelete;

View File

@@ -35,9 +35,12 @@ public class StoryItemServiceImpl implements StoryItemService {
storyItemVo.getPageSize() != null ? storyItemVo.getPageSize() : 10); storyItemVo.getPageSize() != null ? storyItemVo.getPageSize() : 10);
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("storyInstanceId", storyItemVo.getStoryInstanceId()); params.put("storyInstanceId", storyItemVo.getStoryInstanceId());
if (storyItemVo.getAfterTime() != null) {
params.put("afterTime", storyItemVo.getAfterTime());
}
List<StoryItem> list = storyItemMapper.selectStoryItemByStoryInstanceId(params); List<StoryItemVo> list = storyItemMapper.selectStoryItemByStoryInstanceId(params);
PageInfo<StoryItem> pageInfo = new PageInfo<>(list); PageInfo<StoryItemVo> pageInfo = new PageInfo<>(list);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("list", pageInfo.getList()); result.put("list", pageInfo.getList());

View File

@@ -4,9 +4,18 @@ import com.timeline.story.entity.StoryItem;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.List;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class StoryItemVo extends StoryItem { public class StoryItemVo extends StoryItem {
private Integer current; private Integer current;
private Integer pageSize; private Integer pageSize;
private String createName;
private String updateName;
private List<String> images;
// 查询参数
private String afterTime;
private String beforeTime;
} }

View File

@@ -5,14 +5,16 @@
<mapper namespace="com.timeline.story.dao.StoryItemMapper"> <mapper namespace="com.timeline.story.dao.StoryItemMapper">
<insert id="insert"> <insert id="insert">
INSERT INTO story_item (instance_id, master_item_id, description, location, title, create_id, story_instance_id, is_delete, story_item_time, update_id) INSERT INTO story_item (instance_id, master_item_id, description, location, title, create_id, story_instance_id, is_delete, story_item_time, update_id, share_id, cover)
VALUES (#{instanceId}, #{masterItemId}, #{description}, #{location}, #{title},#{createId}, #{storyInstanceId}, #{isDelete}, #{storyItemTime}, #{updateId}) VALUES (#{instanceId}, #{masterItemId}, #{description}, #{location}, #{title},#{createId}, #{storyInstanceId}, #{isDelete}, #{storyItemTime}, #{updateId}, #{shareId}, #{cover})
</insert> </insert>
<update id="update"> <update id="update">
UPDATE story_item UPDATE story_item
SET description = #{description}, SET description = #{description},
location = #{location}, location = #{location},
title = #{title},
cover = #{cover},
create_id = #{createId}, create_id = #{createId},
update_time = NOW(), update_time = NOW(),
update_id = #{updateId}, update_id = #{updateId},
@@ -39,13 +41,19 @@
</select> </select>
<select id="selectStoryItemByStoryInstanceId" resultType="com.timeline.story.vo.StoryItemVo"> <select id="selectStoryItemByStoryInstanceId" resultType="com.timeline.story.vo.StoryItemVo">
SELECT SELECT
instance_id, si.id,
si.instance_id,
si.description, si.description,
si.location, si.location,
title, si.title,
story_instance_id, si.story_instance_id,
si.master_item_id,
si.share_id,
si.cover,
si.type,
si.status,
si.is_delete,
si.story_item_time as story_item_time, si.story_item_time as story_item_time,
si.update_time,
si.create_id AS create_id, si.create_id AS create_id,
si.create_time AS create_time, si.create_time AS create_time,
u1.username AS create_name, u1.username AS create_name,
@@ -92,15 +100,14 @@
si.id, si.id,
si.story_instance_id, si.story_instance_id,
si.title, si.title,
si.content, si.description,
si.story_item_time, si.story_item_time,
si.cover, si.cover
si.is_milestone
FROM FROM
story_item si story_item si
WHERE WHERE
si.is_delete = 0 si.is_delete = 0
AND (si.title LIKE CONCAT('%', #{keyword}, '%') OR si.content LIKE CONCAT('%', #{keyword}, '%')) AND (si.title LIKE CONCAT('%', #{keyword}, '%') OR si.description LIKE CONCAT('%', #{keyword}, '%'))
ORDER BY ORDER BY
si.story_item_time DESC si.story_item_time DESC
</select> </select>