template sort

This commit is contained in:
2025-07-27 11:06:33 +08:00
parent 74a8953c8f
commit 4d2a962bc6
4 changed files with 44 additions and 2 deletions

View File

@@ -68,6 +68,12 @@ public class TemplateController {
return templateService.sortTemplate(request.getTemplateId(), request.getAfterTemplateId());
}
// 修改模板排序值
@PostMapping("/updateSort/{id}")
public ApiResponse<Boolean> updateSort(@PathVariable("id") Long id, @RequestParam Integer sort) {
return templateService.updateSort(id, sort);
}
@GetMapping("/config/{id}")
public ApiResponse<TemplateConfigEntity> getConfig(@PathVariable("id") Long id) {
return ApiResponse.success(templateService.getConfig(id));

View File

@@ -28,4 +28,6 @@ public interface TemplateService {
void saveConfig(Long configId, TemplateConfigEntity config);
ApiResponse<Boolean> sortTemplate(Long templateId, Long afterTemplateId);
ApiResponse<Boolean> updateSort(Long templateId, Integer sort);
}

View File

@@ -52,13 +52,28 @@ public class TemplateServiceImpl implements TemplateService {
@Override
public ApiResponse<Boolean> add(TemplateEntity template) {
template.setId(SnowFlakeUtil.getLongId());
// 如果sort为空,设置默认值
if (template.getSort() == null) {
// 获取当前景区下模板的最大sort值,然后+1
List<TemplateRespVO> existingTemplates = templateRepository.getAllTemplateListByScenicId(template.getScenicId());
int maxSort = existingTemplates.stream()
.mapToInt(t -> t.getSort() != null ? t.getSort() : 0)
.max()
.orElse(0);
template.setSort(maxSort + 1);
}
int i = templateMapper.add(template);
if (template.getChildren() != null) {
AtomicInteger childSort = new AtomicInteger(1);
template.getChildren().forEach(item -> {
item.setId(SnowFlakeUtil.getLongId());
item.setPid(template.getId());
item.setScenicId(template.getScenicId());
item.setStatus(1);
// 为子模板设置sort值
if (item.getSort() == null) {
item.setSort(childSort.getAndIncrement());
}
templateMapper.add(item);
});
}
@@ -87,11 +102,16 @@ public class TemplateServiceImpl implements TemplateService {
int i = templateMapper.update(template);
if (template.getChildren() != null) {
templateMapper.deleteByPid(template.getId());
AtomicInteger childSort = new AtomicInteger(1);
template.getChildren().forEach(item -> {
item.setId(SnowFlakeUtil.getLongId());
item.setPid(template.getId());
item.setScenicId(template.getScenicId());
item.setStatus(1);
// 为子模板设置sort值
if (item.getSort() == null) {
item.setSort(childSort.getAndIncrement());
}
templateMapper.add(item);
});
}
@@ -156,4 +176,15 @@ public class TemplateServiceImpl implements TemplateService {
});
return ApiResponse.success(true);
}
@Override
public ApiResponse<Boolean> updateSort(Long templateId, Integer sort) {
int i = templateMapper.updateSort(templateId, sort);
templateRepository.clearTemplateCache(templateId);
if (i > 0) {
return ApiResponse.success(true);
} else {
return ApiResponse.fail("更新模版排序失败");
}
}
}

View File

@@ -2,8 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ycwl.basic.mapper.TemplateMapper">
<insert id="add">
insert into template(id, scenic_id, `name`, pid, is_placeholder, source_url, effects, luts, overlays, audios, cover_url, frame_rate, speed, price, slash_price, crop_enable, only_if, resolution, create_time)
values (#{id}, #{scenicId}, #{name}, #{pid}, #{isPlaceholder}, #{sourceUrl}, #{effects}, #{luts}, #{overlays}, #{audios}, #{coverUrl}, #{frameRate}, #{speed}, #{price}, #{slashPrice}, #{cropEnable}, #{onlyIf}, #{resolution}, now())
insert into template(id, scenic_id, `name`, pid, is_placeholder, source_url, effects, luts, overlays, audios, cover_url, frame_rate, speed, price, slash_price, sort, crop_enable, only_if, resolution, create_time)
values (#{id}, #{scenicId}, #{name}, #{pid}, #{isPlaceholder}, #{sourceUrl}, #{effects}, #{luts}, #{overlays}, #{audios}, #{coverUrl}, #{frameRate}, #{speed}, #{price}, #{slashPrice}, #{sort}, #{cropEnable}, #{onlyIf}, #{resolution}, now())
</insert>
<insert id="addConfig">
insert into template_config(id, template_id, create_time)
@@ -101,6 +101,7 @@
select t.*, s.name as scenic_name
from template t left join scenic s on s.id = t.scenic_id
where pid = #{id}
order by sort
</select>
<select id="getConfig" resultType="com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity">
select * from template_config where template_id = #{templateId}
@@ -109,6 +110,7 @@
select *
from template
where scenic_id = #{scenicId} and pid = 0 and status = 1
order by sort
</select>
<select id="listFor" resultType="com.ycwl.basic.model.mobile.scenic.content.ContentPageVO">
select t.id templateId, t.scenic_id, s.name as scenic_name, t.`name`, pid, t.cover_url templateCoverUrl,
@@ -133,6 +135,7 @@
select *
from template
where status = 1 and pid = 0
order by sort
</select>
<select id="listAllTemplateIdByScenicId" resultType="java.lang.Long">
select t.id