Merge branch 'refs/heads/xmgl'

This commit is contained in:
2025-09-16 15:03:33 +08:00
5 changed files with 86 additions and 7 deletions

View File

@@ -44,6 +44,11 @@ public class ProjectEntity {
*/ */
private Integer status; private Integer status;
/**
* 模板ID,用于绑定模板
*/
private Long templateId;
private Date createAt; private Date createAt;
private Date updateAt; private Date updateAt;
} }

View File

@@ -28,4 +28,9 @@ public class ProjectReqQuery extends BaseQueryParameterReq {
* 状态,0禁用,1启用 * 状态,0禁用,1启用
*/ */
private Integer status; private Integer status;
/**
* 模板ID
*/
private Long templateId;
} }

View File

@@ -45,6 +45,16 @@ public class ProjectRespVO {
*/ */
private Integer status; private Integer status;
/**
* 模板ID
*/
private Long templateId;
/**
* 模板名称
*/
private String templateName;
private Date createAt; private Date createAt;
private Date updateAt; private Date updateAt;
} }

View File

@@ -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.req.ProjectReqQuery;
import com.ycwl.basic.model.pc.project.resp.ProjectRespVO; import com.ycwl.basic.model.pc.project.resp.ProjectRespVO;
import com.ycwl.basic.repository.ScenicRepository; import com.ycwl.basic.repository.ScenicRepository;
import com.ycwl.basic.repository.TemplateRepository;
import com.ycwl.basic.service.pc.ProjectService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -31,6 +34,9 @@ public class ProjectServiceImpl implements ProjectService {
@Autowired @Autowired
private ScenicRepository scenicRepository; private ScenicRepository scenicRepository;
@Autowired
private TemplateRepository templateRepository;
@Override @Override
public PageInfo<ProjectRespVO> pageQuery(ProjectReqQuery projectReqQuery) { public PageInfo<ProjectRespVO> pageQuery(ProjectReqQuery projectReqQuery) {
PageHelper.startPage(projectReqQuery.getPageNum(), projectReqQuery.getPageSize()); PageHelper.startPage(projectReqQuery.getPageNum(), projectReqQuery.getPageSize());
@@ -44,11 +50,28 @@ public class ProjectServiceImpl implements ProjectService {
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds); Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
// 设置景区名称 // 批量获取模板名称
List<Long> templateIds = list.stream()
.map(ProjectRespVO::getTemplateId)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
Map<Long, String> templateNames = new HashMap<>();
for (Long templateId : templateIds) {
TemplateRespVO template = templateRepository.getTemplate(templateId);
if (template != null) {
templateNames.put(templateId, template.getName());
}
}
// 设置景区名称和模板名称
list.forEach(item -> { list.forEach(item -> {
if (item.getScenicId() != null) { if (item.getScenicId() != null) {
item.setScenicName(scenicNames.get(item.getScenicId())); item.setScenicName(scenicNames.get(item.getScenicId()));
} }
if (item.getTemplateId() != null) {
item.setTemplateName(templateNames.get(item.getTemplateId()));
}
}); });
PageInfo<ProjectRespVO> pageInfo = new PageInfo(list); PageInfo<ProjectRespVO> pageInfo = new PageInfo(list);
@@ -67,11 +90,28 @@ public class ProjectServiceImpl implements ProjectService {
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds); Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
// 设置景区名称 // 批量获取模板名称
List<Long> templateIds = list.stream()
.map(ProjectRespVO::getTemplateId)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
Map<Long, String> templateNames = new HashMap<>();
for (Long templateId : templateIds) {
TemplateRespVO template = templateRepository.getTemplate(templateId);
if (template != null) {
templateNames.put(templateId, template.getName());
}
}
// 设置景区名称和模板名称
list.forEach(item -> { list.forEach(item -> {
if (item.getScenicId() != null) { if (item.getScenicId() != null) {
item.setScenicName(scenicNames.get(item.getScenicId())); item.setScenicName(scenicNames.get(item.getScenicId()));
} }
if (item.getTemplateId() != null) {
item.setTemplateName(templateNames.get(item.getTemplateId()));
}
}); });
return list; return list;
@@ -79,7 +119,22 @@ public class ProjectServiceImpl implements ProjectService {
@Override @Override
public ProjectRespVO getById(Long id) { public ProjectRespVO getById(Long id) {
return projectMapper.getById(id); ProjectRespVO project = projectMapper.getById(id);
if (project != null) {
// 设置景区名称
if (project.getScenicId() != null) {
Map<Long, String> 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 @Override

View File

@@ -2,8 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ycwl.basic.mapper.ProjectMapper"> <mapper namespace="com.ycwl.basic.mapper.ProjectMapper">
<insert id="add"> <insert id="add">
insert into project(scenic_id, `name`, min_play_time, max_play_time, status, create_at, update_at) 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}, now(), now()) values (#{scenicId}, #{name}, #{minPlayTime}, #{maxPlayTime}, #{status}, #{templateId}, now(), now())
</insert> </insert>
<update id="update"> <update id="update">
@@ -12,6 +12,7 @@
min_play_time = #{minPlayTime}, min_play_time = #{minPlayTime},
max_play_time = #{maxPlayTime}, max_play_time = #{maxPlayTime},
status = #{status}, status = #{status},
template_id = #{templateId},
update_at = now() update_at = now()
where id = #{id} where id = #{id}
</update> </update>
@@ -35,7 +36,7 @@
</delete> </delete>
<select id="list" resultType="com.ycwl.basic.model.pc.project.resp.ProjectRespVO"> <select id="list" resultType="com.ycwl.basic.model.pc.project.resp.ProjectRespVO">
select p.id, p.scenic_id, p.`name`, p.min_play_time, p.max_play_time, p.status, p.create_at, p.update_at select p.id, p.scenic_id, p.`name`, p.min_play_time, p.max_play_time, p.status, p.template_id, p.create_at, p.update_at
from project p from project p
<where> <where>
<if test="scenicId != null"> <if test="scenicId != null">
@@ -47,12 +48,15 @@
<if test="status != null"> <if test="status != null">
and p.`status` = #{status} and p.`status` = #{status}
</if> </if>
<if test="templateId != null">
and p.template_id = #{templateId}
</if>
</where> </where>
order by p.create_at desc order by p.create_at desc
</select> </select>
<select id="getById" resultType="com.ycwl.basic.model.pc.project.resp.ProjectRespVO"> <select id="getById" resultType="com.ycwl.basic.model.pc.project.resp.ProjectRespVO">
select p.id, p.scenic_id, p.`name`, p.min_play_time, p.max_play_time, p.status, p.create_at, p.update_at select p.id, p.scenic_id, p.`name`, p.min_play_time, p.max_play_time, p.status, p.template_id, p.create_at, p.update_at
from project p from project p
where p.id = #{id} where p.id = #{id}
</select> </select>