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 @@