最新产品
This commit is contained in:
@ -0,0 +1,9 @@
|
||||
package com.yj.earth.business.service;
|
||||
|
||||
import com.yj.earth.business.domain.FileInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
public interface FileInfoService extends IService<FileInfo> {
|
||||
// 根据文件ID获取文件绝对路径
|
||||
String getFileAbsolutePath(String id);
|
||||
}
|
||||
16
src/main/java/com/yj/earth/business/service/RoleService.java
Normal file
16
src/main/java/com/yj/earth/business/service/RoleService.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.yj.earth.business.service;
|
||||
|
||||
import com.yj.earth.business.domain.Role;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
public interface RoleService extends IService<Role> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.yj.earth.business.service;
|
||||
|
||||
import com.yj.earth.business.domain.RoleSource;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
|
||||
public interface RoleSourceService extends IService<RoleSource> {
|
||||
void addRoleSource(String roleId, String sourceId);
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.yj.earth.business.service;
|
||||
|
||||
import com.yj.earth.business.domain.Source;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yj.earth.common.util.ApiResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SourceService extends IService<Source> {
|
||||
String addAndGetSourceId(String sourcePath);
|
||||
|
||||
String getDetail(String sourcePath, String sourceId);
|
||||
|
||||
String buildSdkUrl(String path);
|
||||
|
||||
String fetchCltDetail(String sourceId);
|
||||
|
||||
String fetchMbtilesDetail(String sourceId);
|
||||
|
||||
String fetchPakDetail(String sourceId);
|
||||
|
||||
List<Source> getSourceListByUserId(String userId);
|
||||
|
||||
String checkIsPass(String parentId, String sourceName);
|
||||
}
|
||||
16
src/main/java/com/yj/earth/business/service/UserService.java
Normal file
16
src/main/java/com/yj/earth/business/service/UserService.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.yj.earth.business.service;
|
||||
|
||||
import com.yj.earth.business.domain.User;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
public interface UserService extends IService<User> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import com.yj.earth.business.domain.FileInfo;
|
||||
import com.yj.earth.business.mapper.FileInfoMapper;
|
||||
import com.yj.earth.business.service.FileInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Service
|
||||
public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> implements FileInfoService {
|
||||
|
||||
@Value("${file.upload.path}")
|
||||
private String uploadPath;
|
||||
|
||||
public String getFileAbsolutePath(String id) {
|
||||
|
||||
// 根据ID查询文件信息
|
||||
FileInfo fileInfo = this.getById(id);
|
||||
if (fileInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 构建完整文件路径
|
||||
String fullPath = uploadPath + File.separator + fileInfo.getFilePath();
|
||||
File file = new File(fullPath);
|
||||
|
||||
// 校验文件是否存在
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取并返回绝对路径
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import com.yj.earth.business.domain.Role;
|
||||
import com.yj.earth.business.mapper.RoleMapper;
|
||||
import com.yj.earth.business.service.RoleService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
@Service
|
||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import com.yj.earth.business.domain.RoleSource;
|
||||
import com.yj.earth.business.mapper.RoleSourceMapper;
|
||||
import com.yj.earth.business.service.RoleSourceService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
public class RoleSourceServiceImpl extends ServiceImpl<RoleSourceMapper, RoleSource> implements RoleSourceService {
|
||||
|
||||
@Override
|
||||
public void addRoleSource(String roleId, String sourceId) {
|
||||
RoleSource roleSource = new RoleSource();
|
||||
roleSource.setRoleId(roleId);
|
||||
roleSource.setSourceId(sourceId);
|
||||
save(roleSource);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,166 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yj.earth.business.domain.Role;
|
||||
import com.yj.earth.business.domain.RoleSource;
|
||||
import com.yj.earth.business.domain.Source;
|
||||
import com.yj.earth.business.domain.User;
|
||||
import com.yj.earth.business.mapper.SourceMapper;
|
||||
import com.yj.earth.business.service.RoleService;
|
||||
import com.yj.earth.business.service.RoleSourceService;
|
||||
import com.yj.earth.business.service.SourceService;
|
||||
import com.yj.earth.business.service.UserService;
|
||||
import com.yj.earth.common.config.ServerConfig;
|
||||
import com.yj.earth.common.util.ApiResponse;
|
||||
import com.yj.earth.common.util.HttpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> implements SourceService {
|
||||
|
||||
@Resource
|
||||
private ServerConfig serverConfig;
|
||||
@Resource
|
||||
private RoleSourceService roleSourceService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private SourceService sourceService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
// 存储文件后缀与对应处理函数的映射关系
|
||||
public final Map<String, Function<String, String>> detailFetchers;
|
||||
|
||||
// 初始化映射关系
|
||||
public SourceServiceImpl() {
|
||||
detailFetchers = new HashMap<>();
|
||||
detailFetchers.put("clt", this::fetchCltDetail);
|
||||
detailFetchers.put("mbtiles", this::fetchMbtilesDetail);
|
||||
detailFetchers.put("pak", this::fetchPakDetail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用SDK获取资源ID
|
||||
*/
|
||||
@Override
|
||||
public String addAndGetSourceId(String sourcePath) {
|
||||
Map<String, Object> addParams = new HashMap<>();
|
||||
addParams.put("filePath", sourcePath);
|
||||
String url = buildSdkUrl("/sourceMap/add");
|
||||
return HttpUtil.doPostForm(url, addParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测资源是否通过审核
|
||||
*/
|
||||
@Override
|
||||
public String checkIsPass(String parentId, String sourceName) {
|
||||
// 先查询父节点是否存在
|
||||
if (parentId != null) {
|
||||
LambdaQueryWrapper<Source> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Source::getId, parentId);
|
||||
List<Source> list = sourceService.list(queryWrapper);
|
||||
if (sourceService.count(queryWrapper) == 0) {
|
||||
return "父级不存在";
|
||||
}
|
||||
}
|
||||
// // 验证该目录下是否已经存在此资源名一样的
|
||||
// LambdaQueryWrapper<Source> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.eq(Source::getSourceName, sourceName);
|
||||
// if (sourceService.count(queryWrapper) > 0) {
|
||||
// return "此目录下已存在此资源";
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件后缀获取详情信息
|
||||
*/
|
||||
@Override
|
||||
public String getDetail(String sourcePath, String sourceId) {
|
||||
String ext = FileUtil.extName(sourcePath);
|
||||
// 通过映射关系获取并执行对应的处理函数
|
||||
Function<String, String> fetcher = detailFetchers.get(ext);
|
||||
if (fetcher != null) {
|
||||
String detailResult = fetcher.apply(sourceId);
|
||||
return detailResult;
|
||||
} else {
|
||||
log.info("未找到{}类型的处理方式", ext);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建SDK请求URL
|
||||
*/
|
||||
@Override
|
||||
public String buildSdkUrl(String path) {
|
||||
return "http://" + serverConfig.getHost() + ":" + serverConfig.getSdkPort() + path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 CLT 类型资源详情
|
||||
*/
|
||||
@Override
|
||||
public String fetchCltDetail(String sourceId) {
|
||||
String url = buildSdkUrl("/data/clt/detail/" + sourceId);
|
||||
return HttpUtil.doGet(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 MBTiles 类型资源详情
|
||||
*/
|
||||
@Override
|
||||
public String fetchMbtilesDetail(String sourceId) {
|
||||
String url = buildSdkUrl("/data/mbtiles/detail/" + sourceId);
|
||||
return HttpUtil.doGet(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 PAK 类型资源详情
|
||||
*/
|
||||
@Override
|
||||
public String fetchPakDetail(String sourceId) {
|
||||
String url = buildSdkUrl("/data/pak/detail/" + sourceId);
|
||||
return HttpUtil.doGet(url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户资源列表
|
||||
*/
|
||||
@Override
|
||||
public List<Source> getSourceListByUserId(String userId) {
|
||||
// 查询该用户信息
|
||||
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(User::getId, userId);
|
||||
User user = userService.getOne(queryWrapper);
|
||||
// 查询角色信息
|
||||
String roleId = user.getRoleId();
|
||||
LambdaQueryWrapper<Role> roleQueryWrapper = new LambdaQueryWrapper<>();
|
||||
roleQueryWrapper.eq(Role::getId, roleId);
|
||||
// 如果这个角色是管理员则直接返回所有资源
|
||||
if (roleService.getOne(roleQueryWrapper).getIsSuper() == 1) {
|
||||
return sourceService.list();
|
||||
}
|
||||
// 查询属于该角色的资源列表
|
||||
LambdaQueryWrapper<RoleSource> roleSourceQueryWrapper = new LambdaQueryWrapper<>();
|
||||
roleSourceQueryWrapper.eq(RoleSource::getRoleId, roleId);
|
||||
List<RoleSource> roleSourceList = roleSourceService.list(roleSourceQueryWrapper);
|
||||
// 从结果提取出资源ID列表
|
||||
List<String> sourceIdList = roleSourceList.stream().map(RoleSource::getSourceId).toList();
|
||||
return sourceService.listByIds(sourceIdList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import com.yj.earth.business.domain.User;
|
||||
import com.yj.earth.business.mapper.UserMapper;
|
||||
import com.yj.earth.business.service.UserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user