mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 22:48:03 +08:00
查看指定文章的引用网络
This commit is contained in:
parent
cfc4e74f36
commit
943e8ceb39
@ -1,5 +1,6 @@
|
||||
package com.blossom.backend.server.article.draft;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.net.URLEncodeUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@ -8,15 +9,20 @@ import com.blossom.backend.server.article.draft.pojo.*;
|
||||
import com.blossom.backend.server.article.open.ArticleOpenService;
|
||||
import com.blossom.backend.server.article.open.pojo.ArticleOpenEntity;
|
||||
import com.blossom.backend.server.doc.DocTypeEnum;
|
||||
import com.blossom.backend.server.folder.FolderService;
|
||||
import com.blossom.backend.server.folder.pojo.FolderEntity;
|
||||
import com.blossom.backend.server.utils.DocUtil;
|
||||
import com.blossom.common.base.enums.YesNo;
|
||||
import com.blossom.common.base.exception.XzException400;
|
||||
import com.blossom.common.base.exception.XzException404;
|
||||
import com.blossom.common.base.pojo.DelReq;
|
||||
import com.blossom.common.base.pojo.R;
|
||||
import com.blossom.common.base.util.DateUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
@ -29,6 +35,7 @@ import java.util.List;
|
||||
*
|
||||
* @author xzzz
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/article")
|
||||
@ -36,6 +43,7 @@ public class ArticleController {
|
||||
|
||||
private final ArticleService baseService;
|
||||
private final ArticleOpenService openService;
|
||||
private final FolderService folderService;
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
@ -178,4 +186,31 @@ public class ArticleController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章导入
|
||||
*
|
||||
* @param file 文件
|
||||
* @param pid 上级菜单
|
||||
*/
|
||||
@PostMapping("import")
|
||||
public R<?> upload(@RequestParam("file") MultipartFile file, @RequestParam(value = "pid") Long pid) {
|
||||
try {
|
||||
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
|
||||
if (!"txt".equals(suffix) && !"md".equals(suffix)) {
|
||||
throw new XzException404("不支持的文件类型: [" + suffix + "]");
|
||||
}
|
||||
FolderEntity folder = folderService.selectById(pid);
|
||||
XzException404.throwBy(ObjUtil.isNull(folder), "上级文件夹不存在");
|
||||
String content = new String(file.getBytes(), StandardCharsets.UTF_8);
|
||||
ArticleEntity article = new ArticleEntity();
|
||||
article.setMarkdown(content);
|
||||
article.setPid(pid);
|
||||
article.setName(FileUtil.getPrefix(file.getOriginalFilename()));
|
||||
baseService.insert(article);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,14 @@ public class ArticleReferenceController {
|
||||
* @param onlyInner 是否只查询内部文章之间的引用
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public R<Map<String, Object>> listAll(@RequestParam("onlyInner") Boolean onlyInner) {
|
||||
public R<Map<String, Object>> listAll(
|
||||
@RequestParam("onlyInner") Boolean onlyInner,
|
||||
@RequestParam(value = "articleId", required = false) Long articleId
|
||||
) {
|
||||
if (onlyInner == null) {
|
||||
onlyInner = true;
|
||||
}
|
||||
return R.ok(baseService.listAll(onlyInner, AuthContext.getUserId()));
|
||||
return R.ok(baseService.listAll(onlyInner, AuthContext.getUserId(), articleId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,4 +23,13 @@ public interface ArticleReferenceMapper extends BaseMapper<ArticleReferenceEntit
|
||||
* @param pictureUrls 图片列表
|
||||
*/
|
||||
void insertList(@Param("references") List<ArticleReferenceEntity> references);
|
||||
|
||||
/**
|
||||
* 查询引用关系
|
||||
*
|
||||
* @param inner 是否内部
|
||||
* @param userId 用户ID
|
||||
* @param articleId 文章ID
|
||||
*/
|
||||
List<ArticleReferenceEntity> listAll(@Param("inner") Boolean inner, @Param("userId") Long userId, @Param("articleId") Long articleId);
|
||||
}
|
@ -74,18 +74,25 @@ public class ArticleReferenceService extends ServiceImpl<ArticleReferenceMapper,
|
||||
*
|
||||
* @param onlyInner 是否只查询内部文章之间的引用
|
||||
* @param userId 用户ID
|
||||
* @param articleId 文章ID, 只查询和某个文章相关的引用
|
||||
*/
|
||||
public Map<String, Object> listAll(boolean onlyInner, Long userId) {
|
||||
public Map<String, Object> listAll(boolean onlyInner, Long userId, Long articleId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
LambdaQueryWrapper<ArticleReferenceEntity> where = new LambdaQueryWrapper<>();
|
||||
where.eq(ArticleReferenceEntity::getUserId, userId);
|
||||
if (onlyInner) {
|
||||
where.in(ArticleReferenceEntity::getType, 11);
|
||||
} else {
|
||||
where.in(ArticleReferenceEntity::getType, 11, 21);
|
||||
}
|
||||
// LambdaQueryWrapper<ArticleReferenceEntity> where = new LambdaQueryWrapper<>();
|
||||
// where.eq(ArticleReferenceEntity::getUserId, userId);
|
||||
// if (onlyInner) {
|
||||
// where.in(ArticleReferenceEntity::getType, 11);
|
||||
// } else {
|
||||
// where.in(ArticleReferenceEntity::getType, 11, 21);
|
||||
// }
|
||||
// if (articleId != null) {
|
||||
// LambdaQueryWrapper<ArticleReferenceEntity> articleIdOr = new LambdaQueryWrapper<>();
|
||||
// articleIdOr.eq(ArticleReferenceEntity::getSourceId, articleId);
|
||||
// articleIdOr.eq(ArticleReferenceEntity::getTargetId, articleId);
|
||||
// where.or(articleIdOr);
|
||||
// }
|
||||
|
||||
List<ArticleReferenceEntity> all = baseMapper.selectList(where);
|
||||
List<ArticleReferenceEntity> all = baseMapper.listAll(onlyInner, userId, articleId);
|
||||
if (CollUtil.isEmpty(all)) {
|
||||
return result;
|
||||
}
|
||||
|
@ -18,16 +18,38 @@ import java.io.Serializable;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ArticleReferenceEntity extends AbstractPOJO implements Serializable {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 文章ID
|
||||
*/
|
||||
private Long sourceId;
|
||||
/**
|
||||
* 文章名称
|
||||
*/
|
||||
private String sourceName;
|
||||
/**
|
||||
* 引用文章ID
|
||||
*/
|
||||
private Long targetId;
|
||||
/**
|
||||
* 引用名称
|
||||
*/
|
||||
private String targetName;
|
||||
/**
|
||||
* 引用链接
|
||||
*/
|
||||
private String targetUrl;
|
||||
/**
|
||||
* 引用类型: 10:图片; 11:文章; 21:外部文章
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,12 @@ public class PictureUtil {
|
||||
return defaultFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩图片
|
||||
*
|
||||
* @param path 图片路径
|
||||
* @param to 压缩后文件保存路径
|
||||
*/
|
||||
public static void compress(String path, String to) {
|
||||
File file = new File(path);
|
||||
File toFile = new File(to);
|
||||
|
@ -25,4 +25,26 @@
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="listAll" resultType="com.blossom.backend.server.article.reference.pojo.ArticleReferenceEntity">
|
||||
select id,
|
||||
source_id,
|
||||
source_name,
|
||||
target_Id,
|
||||
target_name,
|
||||
target_url,
|
||||
type,
|
||||
user_id
|
||||
from blossom_article_reference
|
||||
where user_id = #{userId}
|
||||
<if test="inner == true">
|
||||
and type = 11
|
||||
</if>
|
||||
<if test="inner == false">
|
||||
and type in (11,21)
|
||||
</if>
|
||||
<if test="articleId != null">
|
||||
and (source_id = #{articleId} or target_id = #{articleId})
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user