feat: 完善故事条目功能并优化查询逻辑

1. 更新 StoryItem 实体类,新增 masterItemId、title、description、location 和 share_id 等字段。
2. 扩展 StoryItemVo,支持返回创建者姓名、更新者姓名、图片列表以及时间筛选参数。
3. 修改 StoryItemMapper,将查询结果类型从 StoryItem 变更为 StoryItemVo,并同步更新 SQL 映射。
4. 在 StoryItemServiceImpl 中增加时间过滤逻辑,并在分页查询时自动填充条目关联的图片信息。
This commit is contained in:
2026-02-11 16:35:41 +08:00
parent 073f5af70a
commit 120d784345
5 changed files with 39 additions and 10 deletions

View File

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

View File

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

View File

@@ -35,9 +35,21 @@ public class StoryItemServiceImpl implements StoryItemService {
storyItemVo.getPageSize() != null ? storyItemVo.getPageSize() : 10);
Map<String, Object> params = new HashMap<>();
params.put("storyInstanceId", storyItemVo.getStoryInstanceId());
if (storyItemVo.getAfterTime() != null) {
params.put("afterTime", storyItemVo.getAfterTime());
}
List<StoryItem> list = storyItemMapper.selectStoryItemByStoryInstanceId(params);
PageInfo<StoryItem> pageInfo = new PageInfo<>(list);
List<StoryItemVo> list = storyItemMapper.selectStoryItemByStoryInstanceId(params);
// 填充图片信息
if (list != null && !list.isEmpty()) {
for (StoryItemVo item : list) {
List<String> images = storyItemMapper.selectImagesByItemId(item.getInstanceId());
item.setImages(images);
}
}
PageInfo<StoryItemVo> pageInfo = new PageInfo<>(list);
Map<String, Object> result = new HashMap<>();
result.put("list", pageInfo.getList());

View File

@@ -4,9 +4,18 @@ import com.timeline.story.entity.StoryItem;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
public class StoryItemVo extends StoryItem {
private Integer current;
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">
<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)
VALUES (#{instanceId}, #{masterItemId}, #{description}, #{location}, #{title},#{createId}, #{storyInstanceId}, #{isDelete}, #{storyItemTime}, #{updateId})
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}, #{shareId}, #{cover})
</insert>
<update id="update">
UPDATE story_item
SET description = #{description},
location = #{location},
title = #{title},
cover = #{cover},
create_id = #{createId},
update_time = NOW(),
update_id = #{updateId},
@@ -44,6 +46,9 @@
si.location,
title,
story_instance_id,
si.master_item_id,
si.share_id,
si.cover,
si.story_item_time as story_item_time,
si.update_time,
si.create_id AS create_id,
@@ -92,15 +97,14 @@
si.id,
si.story_instance_id,
si.title,
si.content,
si.description,
si.story_item_time,
si.cover,
si.is_milestone
si.cover
FROM
story_item si
WHERE
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
si.story_item_time DESC
</select>