From dcd5a8f930b2a42589af9eba23b21f89e02987c7 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 16 Sep 2025 01:27:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(project):=20=E5=A2=9E=E5=8A=A0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A8=A1=E6=9D=BF=E5=85=B3=E8=81=94=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ProjectEntity 中添加 templateId 字段,用于绑定模板 - 在 ProjectReqQuery 和 ProjectRespVO 中添加 templateId 和 templateName 字段 - 修改 ProjectServiceImpl 中的查询方法,增加模板名称的查询和设置 - 更新 ProjectMapper.xml 中的 SQL语句,增加 template_id 相关操作 --- .../pc/project/entity/ProjectEntity.java | 5 ++ .../model/pc/project/req/ProjectReqQuery.java | 5 ++ .../model/pc/project/resp/ProjectRespVO.java | 10 +++ .../service/pc/impl/ProjectServiceImpl.java | 61 ++++++++++++++++++- src/main/resources/mapper/ProjectMapper.xml | 12 ++-- 5 files changed, 86 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ycwl/basic/model/pc/project/entity/ProjectEntity.java b/src/main/java/com/ycwl/basic/model/pc/project/entity/ProjectEntity.java index 9ec6f4fb..4ac8a84b 100644 --- a/src/main/java/com/ycwl/basic/model/pc/project/entity/ProjectEntity.java +++ b/src/main/java/com/ycwl/basic/model/pc/project/entity/ProjectEntity.java @@ -44,6 +44,11 @@ public class ProjectEntity { */ private Integer status; + /** + * 模板ID,用于绑定模板 + */ + private Long templateId; + private Date createAt; private Date updateAt; } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/model/pc/project/req/ProjectReqQuery.java b/src/main/java/com/ycwl/basic/model/pc/project/req/ProjectReqQuery.java index 19809799..7e50f316 100644 --- a/src/main/java/com/ycwl/basic/model/pc/project/req/ProjectReqQuery.java +++ b/src/main/java/com/ycwl/basic/model/pc/project/req/ProjectReqQuery.java @@ -28,4 +28,9 @@ public class ProjectReqQuery extends BaseQueryParameterReq { * 状态,0禁用,1启用 */ private Integer status; + + /** + * 模板ID + */ + private Long templateId; } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/model/pc/project/resp/ProjectRespVO.java b/src/main/java/com/ycwl/basic/model/pc/project/resp/ProjectRespVO.java index 37537938..0373cabb 100644 --- a/src/main/java/com/ycwl/basic/model/pc/project/resp/ProjectRespVO.java +++ b/src/main/java/com/ycwl/basic/model/pc/project/resp/ProjectRespVO.java @@ -45,6 +45,16 @@ public class ProjectRespVO { */ private Integer status; + /** + * 模板ID + */ + private Long templateId; + + /** + * 模板名称 + */ + private String templateName; + private Date createAt; private Date updateAt; } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/service/pc/impl/ProjectServiceImpl.java b/src/main/java/com/ycwl/basic/service/pc/impl/ProjectServiceImpl.java index 4b5998ce..2659a7f7 100644 --- a/src/main/java/com/ycwl/basic/service/pc/impl/ProjectServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/pc/impl/ProjectServiceImpl.java @@ -7,10 +7,13 @@ import com.ycwl.basic.model.pc.project.entity.ProjectEntity; import com.ycwl.basic.model.pc.project.req.ProjectReqQuery; import com.ycwl.basic.model.pc.project.resp.ProjectRespVO; import com.ycwl.basic.repository.ScenicRepository; +import com.ycwl.basic.repository.TemplateRepository; import com.ycwl.basic.service.pc.ProjectService; +import com.ycwl.basic.model.pc.template.resp.TemplateRespVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -30,6 +33,9 @@ public class ProjectServiceImpl implements ProjectService { @Autowired private ScenicRepository scenicRepository; + + @Autowired + private TemplateRepository templateRepository; @Override public PageInfo pageQuery(ProjectReqQuery projectReqQuery) { @@ -44,11 +50,28 @@ public class ProjectServiceImpl implements ProjectService { .collect(Collectors.toList()); Map scenicNames = scenicRepository.batchGetScenicNames(scenicIds); - // 设置景区名称 + // 批量获取模板名称 + List templateIds = list.stream() + .map(ProjectRespVO::getTemplateId) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + Map templateNames = new HashMap<>(); + for (Long templateId : templateIds) { + TemplateRespVO template = templateRepository.getTemplate(templateId); + if (template != null) { + templateNames.put(templateId, template.getName()); + } + } + + // 设置景区名称和模板名称 list.forEach(item -> { if (item.getScenicId() != null) { item.setScenicName(scenicNames.get(item.getScenicId())); } + if (item.getTemplateId() != null) { + item.setTemplateName(templateNames.get(item.getTemplateId())); + } }); PageInfo pageInfo = new PageInfo(list); @@ -67,11 +90,28 @@ public class ProjectServiceImpl implements ProjectService { .collect(Collectors.toList()); Map scenicNames = scenicRepository.batchGetScenicNames(scenicIds); - // 设置景区名称 + // 批量获取模板名称 + List templateIds = list.stream() + .map(ProjectRespVO::getTemplateId) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + Map templateNames = new HashMap<>(); + for (Long templateId : templateIds) { + TemplateRespVO template = templateRepository.getTemplate(templateId); + if (template != null) { + templateNames.put(templateId, template.getName()); + } + } + + // 设置景区名称和模板名称 list.forEach(item -> { if (item.getScenicId() != null) { item.setScenicName(scenicNames.get(item.getScenicId())); } + if (item.getTemplateId() != null) { + item.setTemplateName(templateNames.get(item.getTemplateId())); + } }); return list; @@ -79,7 +119,22 @@ public class ProjectServiceImpl implements ProjectService { @Override public ProjectRespVO getById(Long id) { - return projectMapper.getById(id); + ProjectRespVO project = projectMapper.getById(id); + if (project != null) { + // 设置景区名称 + if (project.getScenicId() != null) { + Map scenicNames = scenicRepository.batchGetScenicNames(List.of(project.getScenicId())); + project.setScenicName(scenicNames.get(project.getScenicId())); + } + // 设置模板名称 + if (project.getTemplateId() != null) { + TemplateRespVO template = templateRepository.getTemplate(project.getTemplateId()); + if (template != null) { + project.setTemplateName(template.getName()); + } + } + } + return project; } @Override diff --git a/src/main/resources/mapper/ProjectMapper.xml b/src/main/resources/mapper/ProjectMapper.xml index f94b6428..f3d981f0 100644 --- a/src/main/resources/mapper/ProjectMapper.xml +++ b/src/main/resources/mapper/ProjectMapper.xml @@ -2,8 +2,8 @@ - insert into project(scenic_id, `name`, min_play_time, max_play_time, status, create_at, update_at) - values (#{scenicId}, #{name}, #{minPlayTime}, #{maxPlayTime}, #{status}, now(), now()) + insert into project(scenic_id, `name`, min_play_time, max_play_time, status, template_id, create_at, update_at) + values (#{scenicId}, #{name}, #{minPlayTime}, #{maxPlayTime}, #{status}, #{templateId}, now(), now()) @@ -12,6 +12,7 @@ min_play_time = #{minPlayTime}, max_play_time = #{maxPlayTime}, status = #{status}, + template_id = #{templateId}, update_at = now() where id = #{id} @@ -35,7 +36,7 @@