feat: 优化景区素材
This commit is contained in:
+26
-12
@@ -4,6 +4,7 @@ import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.model.TourismFile;
|
||||
import com.central.order.model.vo.TourismFileGroupVO;
|
||||
import com.central.order.service.ITourismFileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -18,10 +19,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tourism File information
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2025-2-19 17:51:47
|
||||
* 景区资源文件控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -37,25 +35,25 @@ public class TourismFileController {
|
||||
private FileCenterService fileCenterService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* 列表(原接口,保留)
|
||||
*/
|
||||
@Operation(summary = "查询列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
@Parameter(name = "page", description = "分页起始位置", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "limit", description = "分页结束位置", required = true, in = ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||
PageResult<TourismFile> pageResult = tourismFileService.findList(params);
|
||||
if (pageResult.getCount()>0){
|
||||
for (TourismFile tourismFile: pageResult.getData()){
|
||||
if (pageResult.getCount() > 0) {
|
||||
for (TourismFile tourismFile : pageResult.getData()) {
|
||||
tourismFile.setImageUrl(fileCenterService.getViewUrlByPath(tourismFile.getImageUrl()));
|
||||
}
|
||||
}
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
@PostMapping
|
||||
public Result saveOrUpdate(@RequestBody TourismFile tourismFile) {
|
||||
return tourismFileService.saveOrUpdateTourismFile(tourismFile);
|
||||
}
|
||||
@@ -67,12 +65,28 @@ public class TourismFileController {
|
||||
if (tourismFile == null) {
|
||||
return Result.failed("暂无数据");
|
||||
}
|
||||
return Result.succeed(tourismFile,"获取成功");
|
||||
return Result.succeed(tourismFile, "获取成功");
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
tourismFileService.removeById(id);
|
||||
return Result.succeed( "操作成功");
|
||||
return Result.succeed("操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新接口:按租户分组返回景区资源(以景区为组)
|
||||
* 逻辑:先根据租户获取其及子租户下的所有景区,再根据景区获取资源文件
|
||||
* 注意:保留原 /tourism/files 接口不变
|
||||
*/
|
||||
@Operation(summary = "按租户分组返回景区资源")
|
||||
@GetMapping("/grouped/by-tenant")
|
||||
public PageResult<TourismFileGroupVO> listGroupedByTenant(@RequestParam Map<String, Object> params) {
|
||||
try {
|
||||
return tourismFileService.findFilesGroupedByTenant(params);
|
||||
} catch (Exception e) {
|
||||
log.error("按租户分组查询景区资源失败", e);
|
||||
return PageResult.<TourismFileGroupVO>builder().data(java.util.Collections.emptyList()).resp_code(1).count(0L).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -10,23 +10,23 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tourism File information
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2025-2-17 17:52:54
|
||||
* 景区资源文件 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface TourismFileMapper extends SuperMapper<TourismFile> {
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
*
|
||||
* @param page
|
||||
* @param params
|
||||
* @return
|
||||
* 分页查询列表
|
||||
*/
|
||||
List<TourismFile> findList(Page<TourismFile> page, @Param("p") Map<String, Object> params);
|
||||
|
||||
// ID查询
|
||||
/** 按景区ID查询 */
|
||||
List<TourismFile> getByTourismId(@Param("tourismId") Long tourismId);
|
||||
|
||||
/**
|
||||
* 根据景区ID集合批量查询资源文件(可选过滤 type/status/description)
|
||||
*/
|
||||
List<TourismFile> findByTourismIds(@Param("tourismIds") List<Long> tourismIds,
|
||||
@Param("type") Integer type,
|
||||
@Param("status") Integer status,
|
||||
@Param("description") String description);
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.central.order.model.vo;
|
||||
|
||||
import com.central.order.model.TourismFile;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "景区资源")
|
||||
public class TourismFileGroupVO {
|
||||
|
||||
private Long tourismId;
|
||||
|
||||
private String tourismName;
|
||||
|
||||
private List<TourismFile> files;
|
||||
}
|
||||
+9
-23
@@ -4,37 +4,23 @@ import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.order.model.TourismFile;
|
||||
import com.central.order.model.vo.TourismFileGroupVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Firmware file information
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:52:54
|
||||
*/
|
||||
|
||||
public interface ITourismFileService extends ISuperService<TourismFile> {
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
|
||||
PageResult<TourismFile> findList(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param tourismFile
|
||||
* @return
|
||||
*/
|
||||
Result saveOrUpdateTourismFile(TourismFile tourismFile) ;
|
||||
|
||||
/**
|
||||
* id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Result saveOrUpdateTourismFile(TourismFile tourismFile);
|
||||
|
||||
|
||||
List<TourismFile> getByTourismId(Long id);
|
||||
|
||||
|
||||
PageResult<TourismFileGroupVO> findFilesGroupedByTenant(Map<String, Object> params);
|
||||
}
|
||||
|
||||
|
||||
+99
-14
@@ -4,42 +4,49 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.mapper.TourismFileMapper;
|
||||
import com.central.order.mapper.TourismMapper;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismFile;
|
||||
import com.central.order.model.vo.TourismFileGroupVO;
|
||||
import com.central.order.service.ITourismFileService;
|
||||
import com.central.order.service.ITourismService;
|
||||
import com.central.common.feign.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* Order information
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:52:54
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TourismFileServiceImpl extends SuperServiceImpl<TourismFileMapper, TourismFile> implements ITourismFileService {
|
||||
|
||||
@Autowired
|
||||
private TourismMapper tourismMapper;
|
||||
@Autowired
|
||||
private FileCenterService fileCenterService;
|
||||
@Autowired
|
||||
private UserService userCenterService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
* @return
|
||||
* 鍒嗛〉鍒楄〃
|
||||
*/
|
||||
@Override
|
||||
public PageResult<TourismFile> findList(Map<String, Object> params){
|
||||
public PageResult<TourismFile> findList(Map<String, Object> params) {
|
||||
Page<TourismFile> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
List<TourismFile> list = baseMapper.findList(page, params);
|
||||
List<TourismFile> list = baseMapper.findList(page, params);
|
||||
return PageResult.<TourismFile>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result saveOrUpdateTourismFile(TourismFile tourismFile) {
|
||||
boolean result = saveOrUpdate(tourismFile);
|
||||
return result ? Result.succeed(tourismFile, "操作成功") : Result.failed("操作失败");
|
||||
return result ? Result.succeed(tourismFile, "成功") : Result.failed("失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,4 +54,82 @@ public class TourismFileServiceImpl extends SuperServiceImpl<TourismFileMapper,
|
||||
return baseMapper.getByTourismId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<TourismFileGroupVO> findFilesGroupedByTenant(Map<String, Object> params) {
|
||||
List<TourismFileGroupVO> result = new ArrayList<>();
|
||||
if (params == null) params = new HashMap<>();
|
||||
String tenantId = MapUtils.getString(params, "tenantId");
|
||||
Boolean includeChildren = MapUtils.getBoolean(params, "includeChildren", true);
|
||||
Integer type = MapUtils.getInteger(params, "type", null);
|
||||
Integer status = MapUtils.getInteger(params, "status", null);
|
||||
String description = MapUtils.getString(params, "description", null);
|
||||
Long filterTourismId = null;
|
||||
try { filterTourismId = MapUtils.getLong(params, "tourismId", null); } catch (Exception ignored) {}
|
||||
Integer pageNo = MapUtils.getInteger(params, "page", 1);
|
||||
Integer pageSize = MapUtils.getInteger(params, "limit", 10);
|
||||
|
||||
// 兼容:未显式传入租户,尝试从上下文获取当前查询租户
|
||||
if (tenantId == null || tenantId.isEmpty()) {
|
||||
try {
|
||||
tenantId = com.central.common.context.TenantQueryOverrideContext.getTenantId();
|
||||
if (tenantId == null || tenantId.isEmpty()) {
|
||||
tenantId = com.central.common.context.LoginUserContextHolder.getCurrentTenantId();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取当前查询租户失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
if (tenantId == null || tenantId.isEmpty()) {
|
||||
return PageResult.<TourismFileGroupVO>builder().data(result).resp_code(0).count(0L).build();
|
||||
}
|
||||
|
||||
// 计算租户集合
|
||||
List<String> tenantIds;
|
||||
if (Boolean.FALSE.equals(includeChildren)) {
|
||||
tenantIds = Collections.singletonList(tenantId);
|
||||
} else {
|
||||
tenantIds = userCenterService.getSonTenantIds(tenantId);
|
||||
if (tenantIds == null || tenantIds.isEmpty()) {
|
||||
tenantIds = Collections.singletonList(tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
// 构建分页查询景区
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<Tourism> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNo, pageSize);
|
||||
Map<String, Object> p = new HashMap<>();
|
||||
p.put("tenantIds", tenantIds);
|
||||
if (filterTourismId != null && filterTourismId > 0) {
|
||||
p.put("tourismId", filterTourismId);
|
||||
}
|
||||
List<Tourism> tourisms = tourismMapper.findList(page, p);
|
||||
long total = page.getTotal();
|
||||
if (tourisms == null || tourisms.isEmpty()) {
|
||||
return PageResult.<TourismFileGroupVO>builder().data(result).resp_code(0).count(total).build();
|
||||
}
|
||||
|
||||
// 批量查询资源文件(只查本页景区)
|
||||
List<Long> pageTourismIds = tourisms.stream().map(Tourism::getId).collect(Collectors.toList());
|
||||
List<TourismFile> files = baseMapper.findByTourismIds(pageTourismIds, type, status, description);
|
||||
Map<Long, List<TourismFile>> grouped = files == null ? new HashMap<>() : files.stream().collect(Collectors.groupingBy(TourismFile::getTourismId));
|
||||
|
||||
for (Tourism t : tourisms) {
|
||||
TourismFileGroupVO vo = new TourismFileGroupVO();
|
||||
vo.setTourismId(t.getId());
|
||||
vo.setTourismName(t.getTourismName());
|
||||
List<TourismFile> list = grouped.getOrDefault(t.getId(), Collections.emptyList());
|
||||
// 转换 URL
|
||||
List<TourismFile> converted = new ArrayList<>(list.size());
|
||||
for (TourismFile f : list) {
|
||||
if (f != null && f.getImageUrl() != null) {
|
||||
try { f.setImageUrl(fileCenterService.getViewUrlByPath(f.getImageUrl())); } catch (Exception ignored) {}
|
||||
}
|
||||
converted.add(f);
|
||||
}
|
||||
vo.setFiles(converted);
|
||||
result.add(vo);
|
||||
}
|
||||
|
||||
return PageResult.<TourismFileGroupVO>builder().data(result).resp_code(0).count(total).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.central.order.mapper.TourismFileMapper">
|
||||
@@ -12,4 +12,30 @@
|
||||
<select id="getByTourismId" resultMap="TourismFileResultMap">
|
||||
SELECT * FROM tourisms_files WHERE tourism_id = #{tourismId}
|
||||
</select>
|
||||
|
||||
<select id="findByTourismIds" resultType="com.central.order.model.TourismFile">
|
||||
SELECT *
|
||||
FROM tourisms_files
|
||||
<where>
|
||||
<if test="tourismIds != null and tourismIds.size > 0">
|
||||
tourism_id IN
|
||||
<foreach collection="tourismIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="type != null">
|
||||
AND type = #{type}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="description != null and description != ''">
|
||||
AND description LIKE CONCAT('%', #{description}, '%')
|
||||
</if>
|
||||
<!-- 仅查询未删除数据 -->
|
||||
AND (is_del = 0 OR is_del IS NULL)
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user