feat(grouping): 新增分组功能并优化 Markdown 文件操作
- 新增分组实体、控制器、服务和映射器 - 实现分组创建、获取、更新和删除接口 - 优化 Markdown 文件创建、获取和删除接口- 新增全局异常处理和日志记录 - 更新数据库表结构和字段类型 - 重构前端页面,支持分组和 Markdown 文件展示
This commit is contained in:
@@ -5,6 +5,8 @@ import com.test.bijihoudaun.common.exception.BaseException;
|
||||
import com.test.bijihoudaun.common.response.R;
|
||||
import com.test.bijihoudaun.common.response.ResultCode;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
@@ -20,6 +22,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
// 打印日志
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
/**
|
||||
* 处理业务异常
|
||||
@@ -34,6 +38,7 @@ public class GlobalExceptionHandler {
|
||||
*/
|
||||
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||
public R<String> handleFileSizeLimitExceeded() {
|
||||
log.error("文件大小超出限制");
|
||||
return R.fail("文件大小超过限制");
|
||||
}
|
||||
|
||||
@@ -46,6 +51,7 @@ public class GlobalExceptionHandler {
|
||||
.stream()
|
||||
.map(FieldError::getDefaultMessage)
|
||||
.collect(Collectors.toList());
|
||||
log.error("参数校验异常:{}", errors.get(0));
|
||||
return R.fail(ResultCode.VALIDATE_FAILED.getCode(), errors.get(0));
|
||||
}
|
||||
|
||||
@@ -58,6 +64,7 @@ public class GlobalExceptionHandler {
|
||||
.stream()
|
||||
.map(FieldError::getDefaultMessage)
|
||||
.collect(Collectors.toList());
|
||||
log.error("参数校验异常:{}", errors.get(0));
|
||||
return R.fail(ResultCode.VALIDATE_FAILED.getCode(), errors.get(0));
|
||||
}
|
||||
|
||||
@@ -66,6 +73,7 @@ public class GlobalExceptionHandler {
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public R<Void> handleException(Exception e) {
|
||||
return R.fail(ResultCode.FAILED.getCode(), "系统繁忙,请稍后再试");
|
||||
log.error("系统异常:{}", e.getMessage());
|
||||
return R.fail(ResultCode.FAILED.getCode(), "系统繁忙,请稍后再试:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,13 @@ public class Knife4jConfig {
|
||||
.pathsToMatch("/api/user/**")
|
||||
.build();
|
||||
}
|
||||
@Bean
|
||||
public GroupedOpenApi GroupingApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("分组接口")
|
||||
.pathsToMatch("/api/groupings/**")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedOrigins("http://localhost:5173") // 明确指定前端来源
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true) // 允许凭证
|
||||
.maxAge(3600); // 预检请求缓存时间
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,4 +23,4 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registry.addResourceHandler("/uploads/**")
|
||||
.addResourceLocations("file:uploads/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.test.bijihoudaun.controller;
|
||||
|
||||
import com.test.bijihoudaun.entity.Grouping;
|
||||
import com.test.bijihoudaun.service.GroupingService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "分组接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/groupings")
|
||||
public class GroupingController {
|
||||
|
||||
@Autowired
|
||||
private GroupingService groupingService;
|
||||
|
||||
@Operation(summary = "创建分组")
|
||||
@PostMapping
|
||||
public ResponseEntity<Grouping> createGrouping(@RequestBody Grouping grouping) {
|
||||
Grouping created = groupingService.createGrouping(grouping);
|
||||
return ResponseEntity.ok(created);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取全部分组")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Grouping>> getAllGroupings() {
|
||||
List<Grouping> groupings = groupingService.getAllGroupings();
|
||||
return ResponseEntity.ok(groupings);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新分组名称")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Grouping> updateGrouping(
|
||||
@PathVariable Long id,
|
||||
@RequestBody Grouping grouping) {
|
||||
grouping.setId(id);
|
||||
Grouping updated = groupingService.updateGrouping(grouping);
|
||||
return ResponseEntity.ok(updated);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除分组")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteGrouping(@PathVariable Long id) {
|
||||
groupingService.deleteGrouping(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -25,18 +25,16 @@ public class ImageController {
|
||||
|
||||
@Operation(summary = "上传图片")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id", required = true),
|
||||
@Parameter(name = "markdownId", description = "markdownid", required = true),
|
||||
@Parameter(name = "file", description = "图片文件", required = true)
|
||||
})
|
||||
@PostMapping
|
||||
public ResponseEntity<Image> uploadImage(
|
||||
@RequestParam Long userId,
|
||||
@RequestParam(required = false) Long markdownId,
|
||||
@RequestParam("file") MultipartFile file) {
|
||||
|
||||
try {
|
||||
Image image = imageService.uploadImage(userId, markdownId, file);
|
||||
Image image = imageService.uploadImage(markdownId, file);
|
||||
return ResponseEntity.ok(image);
|
||||
} catch (IOException e) {
|
||||
return ResponseEntity.status(500).build();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.test.bijihoudaun.controller;
|
||||
|
||||
import com.test.bijihoudaun.common.response.R;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.service.MarkdownFileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -9,6 +10,9 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "markdown接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/markdown")
|
||||
@@ -17,6 +21,13 @@ public class MarkdownController {
|
||||
@Autowired
|
||||
private MarkdownFileService markdownFileService;
|
||||
|
||||
@Operation(summary = "测试")
|
||||
@GetMapping("/test")
|
||||
public R<List<MarkdownFile>> test() {
|
||||
List<MarkdownFile> test = markdownFileService.test();
|
||||
return R.success(test);
|
||||
}
|
||||
|
||||
@Operation(summary = "预览markdown文件")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "文件ID", required = true)
|
||||
@@ -32,20 +43,20 @@ public class MarkdownController {
|
||||
|
||||
@Operation(summary = "创建markdown文件")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id",required = true),
|
||||
@Parameter(name = "groupingId", description = "分组id",required = true),
|
||||
@Parameter(name = "title", description = "标题",required = true),
|
||||
@Parameter(name = "fileName", description = "文件名",required = true),
|
||||
@Parameter(name = "content", description = "内容",required = true)
|
||||
})
|
||||
@PostMapping
|
||||
public ResponseEntity<MarkdownFile> createMarkdown(
|
||||
@RequestParam Long userId,
|
||||
@RequestParam Long groupingId,
|
||||
@RequestParam String title,
|
||||
@RequestParam String fileName,
|
||||
@RequestBody String content) {
|
||||
|
||||
MarkdownFile file = markdownFileService.createMarkdownFile(
|
||||
userId, title, fileName, content);
|
||||
groupingId, title, fileName, content);
|
||||
|
||||
return ResponseEntity.ok(file);
|
||||
}
|
||||
@@ -67,4 +78,28 @@ public class MarkdownController {
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有Markdown文件")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<MarkdownFile>> getAllMarkdownFiles() {
|
||||
// 固定用户ID=1,因为是个人笔记
|
||||
List<MarkdownFile> files = markdownFileService.getAllMarkdownFiles();
|
||||
return ResponseEntity.ok(files);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除Markdown文件")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteMarkdown(@PathVariable Long id) {
|
||||
if (markdownFileService.deleteMarkdownFile(id)) {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "根据分组ID获取Markdown文件")
|
||||
@GetMapping("/grouping/{groupingId}")
|
||||
public ResponseEntity<List<MarkdownFile>> getFilesByGroupingId(@PathVariable String groupingId) {
|
||||
List<MarkdownFile> files = markdownFileService.getFilesByGroupingId(groupingId);
|
||||
return ResponseEntity.ok(files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.test.bijihoudaun.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(name = "分组实体")
|
||||
@TableName("grouping")
|
||||
public class Grouping {
|
||||
@Schema(description = "分组id",implementation = Long.class)
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
@Schema(description = "分组名称",implementation = String.class)
|
||||
private String grouping;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(name = "图片实体")
|
||||
@@ -16,8 +16,6 @@ public class Image {
|
||||
@Schema(description = "图片id",implementation = Long.class)
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
@Schema(description = "外键,关联用户ID,标识图片所有者\n",implementation = Long.class )
|
||||
private Long userId;
|
||||
@Schema(description = " 外键,关联Markdown文件ID,标识图片所属文档",implementation = Long.class )
|
||||
private Long markdownId;
|
||||
|
||||
@@ -38,6 +36,6 @@ public class Image {
|
||||
@TableField("content_type")
|
||||
private String contentType;
|
||||
|
||||
@Schema(description = "图片上传时间",implementation = LocalDateTime.class )
|
||||
private LocalDateTime createdAt;
|
||||
@Schema(description = "图片上传时间",implementation = Date.class )
|
||||
private Date createdAt;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(name = "文本实体")
|
||||
@@ -16,7 +16,9 @@ public class MarkdownFile {
|
||||
@Schema(description = "文本id",implementation = Long.class)
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
@Schema(description = "用户id",implementation = Long.class)
|
||||
@Schema(description = "分组表id",implementation = Long.class)
|
||||
private Long groupingId;
|
||||
@Schema(description = "用户ID",implementation = Long.class)
|
||||
private Long userId;
|
||||
@Schema(description = "文本标题",implementation = String.class)
|
||||
private String title;
|
||||
@@ -27,8 +29,8 @@ public class MarkdownFile {
|
||||
|
||||
@Schema(description = "Markdown内容,存储实际文档内容",implementation = String.class)
|
||||
private String content;
|
||||
@Schema(description = "创建时间",implementation = LocalDateTime.class)
|
||||
private LocalDateTime createdAt;
|
||||
@Schema(description = "更新时间",implementation = LocalDateTime.class)
|
||||
private LocalDateTime updatedAt;
|
||||
@Schema(description = "创建时间",implementation = Date.class)
|
||||
private Date createdAt;
|
||||
@Schema(description = "更新时间",implementation = Date.class)
|
||||
private Date updatedAt;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(name = "用户实体")
|
||||
@@ -21,12 +21,12 @@ public class User {
|
||||
private String password;
|
||||
@Schema(description = "邮箱",implementation = String.class)
|
||||
private String email;
|
||||
@Schema(description = "用户创建时间",implementation = String.class)
|
||||
private LocalDateTime createdAt;
|
||||
@Schema(description = "用户更新时间",implementation = String.class)
|
||||
private LocalDateTime updatedAt;
|
||||
@Schema(description = "用户创建时间",implementation = Date.class)
|
||||
private Date createdAt;
|
||||
@Schema(description = "用户更新时间",implementation = Date.class)
|
||||
private Date updatedAt;
|
||||
@Schema(description = "用户token",implementation = String.class)
|
||||
private String token;
|
||||
@Schema(description = "用户token过期时间",implementation = String.class)
|
||||
private LocalDateTime tokenEnddata;
|
||||
@Schema(description = "用户token过期时间",implementation = Date.class)
|
||||
private Date tokenEnddata;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.test.bijihoudaun.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.test.bijihoudaun.entity.Grouping;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface GroupingMapper extends BaseMapper<Grouping> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.test.bijihoudaun.service;
|
||||
|
||||
import com.test.bijihoudaun.entity.Grouping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GroupingService {
|
||||
Grouping createGrouping(Grouping grouping);
|
||||
List<Grouping> getAllGroupings();
|
||||
Grouping updateGrouping(Grouping grouping);
|
||||
void deleteGrouping(Long id);
|
||||
}
|
||||
@@ -10,28 +10,20 @@ import java.util.List;
|
||||
public interface ImageService extends IService<Image> {
|
||||
/**
|
||||
* 上传图片
|
||||
* @param userId 用户ID
|
||||
* @param markdownId Markdown文件ID(可选)
|
||||
* @param file 图片文件
|
||||
* @return 上传的图片对象
|
||||
* @throws IOException 文件操作异常
|
||||
*/
|
||||
Image uploadImage(Long userId, Long markdownId, MultipartFile file) throws IOException;
|
||||
Image uploadImage(Long markdownId, MultipartFile file) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
* @param id 图片ID
|
||||
* @param userId 用户ID(用于权限验证)
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deleteImage(Long id, Long userId);
|
||||
boolean deleteImage(Long id);
|
||||
|
||||
/**
|
||||
* 获取用户的图片列表
|
||||
* @param userId 用户ID
|
||||
* @return 图片列表
|
||||
*/
|
||||
List<Image> getUserImages(Long userId);
|
||||
|
||||
/**
|
||||
* 获取Markdown文件关联的图片
|
||||
|
||||
@@ -8,13 +8,13 @@ import java.util.List;
|
||||
public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
/**
|
||||
* 创建Markdown文件
|
||||
* @param userId 用户ID
|
||||
* @param groupingId 分组ID
|
||||
* @param title 文件标题
|
||||
* @param fileName 文件名
|
||||
* @param content 文件内容
|
||||
* @return 创建的文件对象
|
||||
*/
|
||||
MarkdownFile createMarkdownFile(Long userId, String title, String fileName, String content);
|
||||
MarkdownFile createMarkdownFile(Long groupingId, String title, String fileName, String content);
|
||||
|
||||
/**
|
||||
* 更新Markdown内容
|
||||
@@ -31,10 +31,26 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
*/
|
||||
MarkdownFile getMarkdownById(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的所有Markdown文件
|
||||
* @param userId 用户ID
|
||||
* 根据分组ID获取Markdown文件
|
||||
* @param groupingId 分组ID
|
||||
* @return 文件列表
|
||||
*/
|
||||
List<MarkdownFile> getUserFiles(Long userId);
|
||||
List<MarkdownFile> getFilesByGroupingId(String groupingId);
|
||||
|
||||
/**
|
||||
* 删除Markdown文件
|
||||
* @param id 文件ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deleteMarkdownFile(Long id);
|
||||
|
||||
List<MarkdownFile> test();
|
||||
|
||||
/**
|
||||
* 获取所有Markdown文件
|
||||
* @return 文件列表
|
||||
*/
|
||||
List<MarkdownFile> getAllMarkdownFiles();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.test.bijihoudaun.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.entity.Grouping;
|
||||
import com.test.bijihoudaun.mapper.GroupingMapper;
|
||||
import com.test.bijihoudaun.service.GroupingService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class GroupingServiceImpl
|
||||
extends ServiceImpl<GroupingMapper, Grouping>
|
||||
implements GroupingService {
|
||||
|
||||
@Override
|
||||
public Grouping createGrouping(Grouping grouping) {
|
||||
this.save(grouping);
|
||||
return grouping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Grouping> getAllGroupings() {
|
||||
return this.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Grouping updateGrouping(Grouping grouping) {
|
||||
this.updateById(grouping);
|
||||
return grouping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGrouping(Long id) {
|
||||
this.removeById(id);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.entity.Image;
|
||||
import com.test.bijihoudaun.mapper.ImageMapper;
|
||||
import com.test.bijihoudaun.service.ImageService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -15,6 +16,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -25,9 +27,11 @@ public class ImageServiceImpl
|
||||
|
||||
@Value("${file.upload-dir}")
|
||||
private String uploadDir;
|
||||
@Resource
|
||||
private ImageMapper imageMapper;
|
||||
|
||||
@Override
|
||||
public Image uploadImage(Long userId, Long markdownId, MultipartFile file) throws IOException {
|
||||
public Image uploadImage(Long markdownId, MultipartFile file) throws IOException {
|
||||
// 创建上传目录
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
if (!Files.exists(uploadPath)) {
|
||||
@@ -45,30 +49,24 @@ public class ImageServiceImpl
|
||||
|
||||
// 创建图片实体
|
||||
Image image = new Image();
|
||||
image.setUserId(userId);
|
||||
image.setMarkdownId(markdownId);
|
||||
image.setOriginalName(originalFilename);
|
||||
image.setStoredName(storedName);
|
||||
image.setUrl("/uploads/" + storedName);
|
||||
image.setSize(file.getSize());
|
||||
image.setContentType(file.getContentType());
|
||||
image.setCreatedAt(LocalDateTime.now());
|
||||
image.setCreatedAt(new Date());
|
||||
|
||||
this.save(image);
|
||||
return image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteImage(Long id, Long userId) {
|
||||
QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id)
|
||||
.eq("user_id", userId);
|
||||
|
||||
Image image = this.getOne(queryWrapper);
|
||||
public boolean deleteImage(Long id) {
|
||||
Image image = imageMapper.selectById(id);
|
||||
if (image == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 删除文件系统中的图片
|
||||
Path filePath = Paths.get(uploadDir, image.getStoredName());
|
||||
@@ -82,14 +80,6 @@ public class ImageServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Image> getUserImages(Long userId) {
|
||||
QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId)
|
||||
.orderByDesc("created_at");
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Image> getMarkdownImages(Long markdownId) {
|
||||
QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
@@ -6,10 +6,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.mapper.MarkdownFileMapper;
|
||||
import com.test.bijihoudaun.service.MarkdownFileService;
|
||||
import com.test.bijihoudaun.util.SnowflakeIdGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -17,17 +20,23 @@ public class MarkdownFileServiceImpl
|
||||
extends ServiceImpl<MarkdownFileMapper, MarkdownFile>
|
||||
implements MarkdownFileService {
|
||||
|
||||
@Autowired
|
||||
MarkdownFileMapper markdownFileMapper;
|
||||
@Resource
|
||||
SnowflakeIdGenerator snowflakeIdGenerator;
|
||||
|
||||
@Override
|
||||
public MarkdownFile createMarkdownFile(Long userId, String title, String fileName, String content) {
|
||||
public MarkdownFile createMarkdownFile(Long groupingId, String title, String fileName, String content) {
|
||||
MarkdownFile file = new MarkdownFile();
|
||||
file.setUserId(userId);
|
||||
file.setId(snowflakeIdGenerator.nextId());
|
||||
file.setGroupingId(groupingId);
|
||||
file.setTitle(title);
|
||||
file.setFileName(fileName);
|
||||
file.setContent(content);
|
||||
file.setCreatedAt(LocalDateTime.now());
|
||||
file.setUpdatedAt(LocalDateTime.now());
|
||||
file.setCreatedAt(new Date());
|
||||
file.setUpdatedAt(new Date());
|
||||
|
||||
this.save(file);
|
||||
markdownFileMapper.insert(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -36,7 +45,7 @@ public class MarkdownFileServiceImpl
|
||||
MarkdownFile file = this.getById(id);
|
||||
if (file != null) {
|
||||
file.setContent(content);
|
||||
file.setUpdatedAt(LocalDateTime.now());
|
||||
file.setUpdatedAt(new Date());
|
||||
this.updateById(file);
|
||||
}
|
||||
return file;
|
||||
@@ -47,11 +56,28 @@ public class MarkdownFileServiceImpl
|
||||
return this.getById(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<MarkdownFile> getUserFiles(Long userId) {
|
||||
public List<MarkdownFile> getFilesByGroupingId(String groupingId) {
|
||||
QueryWrapper<MarkdownFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId)
|
||||
queryWrapper.eq("grouping_id", groupingId)
|
||||
.orderByDesc("updated_at");
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMarkdownFile(Long id) {
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkdownFile> test() {
|
||||
List<MarkdownFile> markdownFiles = markdownFileMapper.selectList(null);
|
||||
return markdownFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkdownFile> getAllMarkdownFiles() {
|
||||
return markdownFileMapper.selectList(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
@@ -36,7 +38,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
user.setUsername(username);
|
||||
user.setPassword(encrypt);
|
||||
user.setEmail(email);
|
||||
user.setCreatedAt(LocalDateTime.now());
|
||||
user.setCreatedAt(new Date());
|
||||
userMapper.insert(user);
|
||||
return user;
|
||||
}
|
||||
@@ -52,7 +54,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
}
|
||||
user.setToken(UuidV7.uuidNoHyphen());
|
||||
// 过期时间:当前时间+3天的时间
|
||||
user.setTokenEnddata(LocalDateTime.now().plusDays(3));
|
||||
// 修改时间计算方式
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 3); // 增加3天
|
||||
user.setTokenEnddata(calendar.getTime());
|
||||
userMapper.updateById(user);
|
||||
return user;
|
||||
}
|
||||
@@ -68,8 +73,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
queryWrapper.eq(User::getId, id)
|
||||
.eq(User::getToken, token);
|
||||
User user = getOne(queryWrapper);
|
||||
// 新增过期检查
|
||||
return user != null && LocalDateTime.now().isBefore(user.getTokenEnddata());
|
||||
|
||||
// 修改过期检查逻辑
|
||||
return user != null && new Date().before(user.getTokenEnddata());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: org.sqlite.JDBC
|
||||
url: jdbc:sqlite:C:\\it\\houtaigunli\\liu\\mydatabase.db
|
||||
url: jdbc:sqlite:C:\it\houtaigunli\biji\mydatabase.db
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
|
||||
Reference in New Issue
Block a user