树列表
This commit is contained in:
@ -3,6 +3,7 @@ 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 com.yj.earth.dto.source.AddModelSourceDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -22,4 +23,6 @@ public interface SourceService extends IService<Source> {
|
||||
List<Source> getSourceListByUserId(String userId);
|
||||
|
||||
String checkIsPass(String parentId, String sourceName);
|
||||
|
||||
Source addModelSource(AddModelSourceDto addModelSourceDto);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -15,6 +16,9 @@ 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 com.yj.earth.common.util.JsonUtil;
|
||||
import com.yj.earth.common.util.MapUtil;
|
||||
import com.yj.earth.dto.source.AddModelSourceDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -24,6 +28,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.yj.earth.common.constant.GlobalConstant.SHOW;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -76,15 +82,41 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
return "父级不存在";
|
||||
}
|
||||
}
|
||||
// // 验证该目录下是否已经存在此资源名一样的
|
||||
// LambdaQueryWrapper<Source> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.eq(Source::getSourceName, sourceName);
|
||||
// if (sourceService.count(queryWrapper) > 0) {
|
||||
// return "此目录下已存在此资源";
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source addModelSource(AddModelSourceDto addModelSourceDto) {
|
||||
// 获取资源绝对路径
|
||||
String sourcePath = addModelSourceDto.getSourcePath();
|
||||
// 获取资源名称
|
||||
String sourceName = FileUtil.mainName(sourcePath);
|
||||
// 校验是否通过
|
||||
String message = sourceService.checkIsPass(addModelSourceDto.getParentId(), sourceName);
|
||||
if (message != null) {
|
||||
return null;
|
||||
}
|
||||
// 调用SDK加载资源
|
||||
String sourceId = sourceService.addAndGetSourceId(sourcePath);
|
||||
// 获取文件路径并处理详情
|
||||
String detail = sourceService.getDetail(sourcePath, sourceId);
|
||||
// 构建并保存资源对象
|
||||
Source source = new Source();
|
||||
source.setId(addModelSourceDto.getId());
|
||||
source.setSourcePath(sourcePath);
|
||||
source.setSourceName(sourceName);
|
||||
source.setParentId(addModelSourceDto.getParentId());
|
||||
source.setTreeIndex(addModelSourceDto.getTreeIndex());
|
||||
source.setParams(JsonUtil.mapToJson(addModelSourceDto.getParams()));
|
||||
source.setDetail(detail);
|
||||
source.setSourceType(MapUtil.getString(MapUtil.jsonToMap(detail), "fileType"));
|
||||
source.setIsShow(SHOW);
|
||||
sourceService.save(source);
|
||||
// 添加资源到该用户的角色下
|
||||
roleSourceService.addRoleSource(userService.getById(StpUtil.getLoginIdAsString()).getRoleId(), source.getId());
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件后缀获取详情信息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user