diff --git a/src/main/java/com/mzaxd/bps/config/FileConfig.java b/src/main/java/com/mzaxd/bps/config/FileConfig.java new file mode 100644 index 0000000..c669ecc --- /dev/null +++ b/src/main/java/com/mzaxd/bps/config/FileConfig.java @@ -0,0 +1,41 @@ +package com.mzaxd.bps.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * 文件上传配置 + * + * @author mzaxd + * @since 2024-04-06 + */ +@Configuration +@ConfigurationProperties(prefix = "file") +public class FileConfig { + + /** + * 上传路径 + */ + private String uploadPath; + + /** + * 访问路径 + */ + private String accessPath; + + public String getUploadPath() { + return uploadPath; + } + + public void setUploadPath(String uploadPath) { + this.uploadPath = uploadPath; + } + + public String getAccessPath() { + return accessPath; + } + + public void setAccessPath(String accessPath) { + this.accessPath = accessPath; + } +} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/bps/controller/FileController.java b/src/main/java/com/mzaxd/bps/controller/FileController.java new file mode 100644 index 0000000..127bad8 --- /dev/null +++ b/src/main/java/com/mzaxd/bps/controller/FileController.java @@ -0,0 +1,41 @@ +package com.mzaxd.bps.controller; + +import com.mzaxd.bps.config.FileConfig; +import com.mzaxd.bps.util.FileUtil; +import com.mzaxd.bps.util.Result; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.IOException; + +/** + * 文件上传Controller + * + * @author mzaxd + * @since 2024-04-06 + */ +@RestController +@RequestMapping("/file") +public class FileController { + + @Resource + private FileConfig fileConfig; + + /** + * 上传文件 + */ + @PostMapping("/upload") + public Result upload(@RequestParam("file") MultipartFile file) throws IOException { + String fileName = FileUtil.upload(file, fileConfig.getUploadPath()); + return Result.success(fileConfig.getAccessPath() + fileName); + } + + /** + * 删除文件 + */ + @DeleteMapping("/{fileName}") + public Result delete(@PathVariable String fileName) { + return Result.success(FileUtil.delete(fileConfig.getUploadPath() + fileName)); + } +} \ No newline at end of file diff --git a/src/main/java/com/mzaxd/bps/controller/SourceCategoryController.java b/src/main/java/com/mzaxd/bps/controller/SourceCategoryController.java index 7668bcd..4dcef90 100644 --- a/src/main/java/com/mzaxd/bps/controller/SourceCategoryController.java +++ b/src/main/java/com/mzaxd/bps/controller/SourceCategoryController.java @@ -1,50 +1,82 @@ package com.mzaxd.bps.controller; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzaxd.bps.domain.entity.SourceCategory; -import com.mzaxd.bps.domain.vo.SourceCategoryVo; import com.mzaxd.bps.service.SourceCategoryService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; +import com.mzaxd.bps.util.Result; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.util.List; /** - * 网盘分类表(SourceCategory)表控制层 + * 网盘分类Controller * * @author mzaxd - * @since 2024-04-06 10:00:00 + * @since 2024-04-06 */ @RestController -@RequestMapping("/api/source/category") -@Api(tags = "网盘分类管理") +@RequestMapping("/source/category") public class SourceCategoryController { - @Autowired + @Resource private SourceCategoryService sourceCategoryService; + /** + * 分页查询网盘分类 + */ + @GetMapping("/page") + public Result> page( + @RequestParam(defaultValue = "1") Integer pageNum, + @RequestParam(defaultValue = "10") Integer pageSize, + @RequestParam(required = false) String name) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.like(name != null, SourceCategory::getName, name) + .orderByAsc(SourceCategory::getSort); + return Result.success(sourceCategoryService.page(new Page<>(pageNum, pageSize), queryWrapper)); + } + + /** + * 获取所有网盘分类 + */ @GetMapping("/list") - @ApiOperation("获取分类列表") - public List getCategoryList() { - return sourceCategoryService.getCategoryList(); + public Result> list() { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SourceCategory::getStatus, 1) + .orderByAsc(SourceCategory::getSort); + return Result.success(sourceCategoryService.list(queryWrapper)); } + /** + * 获取网盘分类详情 + */ + @GetMapping("/{id}") + public Result getById(@PathVariable Long id) { + return Result.success(sourceCategoryService.getById(id)); + } + + /** + * 新增网盘分类 + */ @PostMapping - @ApiOperation("新增分类") - public boolean addCategory(@RequestBody SourceCategory category) { - return sourceCategoryService.addCategory(category); + public Result save(@RequestBody SourceCategory sourceCategory) { + return Result.success(sourceCategoryService.save(sourceCategory)); } + /** + * 修改网盘分类 + */ @PutMapping - @ApiOperation("更新分类") - public boolean updateCategory(@RequestBody SourceCategory category) { - return sourceCategoryService.updateCategory(category); + public Result updateById(@RequestBody SourceCategory sourceCategory) { + return Result.success(sourceCategoryService.updateById(sourceCategory)); } + /** + * 删除网盘分类 + */ @DeleteMapping("/{id}") - @ApiOperation("删除分类") - public boolean deleteCategory(@PathVariable Long id) { - return sourceCategoryService.deleteCategory(id); + public Result removeById(@PathVariable Long id) { + return Result.success(sourceCategoryService.removeById(id)); } } \ No newline at end of file diff --git a/src/main/java/com/mzaxd/bps/controller/SourceController.java b/src/main/java/com/mzaxd/bps/controller/SourceController.java index 5b2bc12..1eb74be 100644 --- a/src/main/java/com/mzaxd/bps/controller/SourceController.java +++ b/src/main/java/com/mzaxd/bps/controller/SourceController.java @@ -22,6 +22,18 @@ public class SourceController { @Resource private SourceService sourceService; + /** + * 搜索网盘资源 + */ + @GetMapping("/search") + public Result> search( + @RequestParam(defaultValue = "1") Integer pageNum, + @RequestParam(defaultValue = "10") Integer pageSize, + @RequestParam(required = false) String keyword, + @RequestParam(required = false) Long categoryId) { + return Result.success(sourceService.search(pageNum, pageSize, keyword, categoryId)); + } + /** * 分页查询网盘资源 */ diff --git a/src/main/java/com/mzaxd/bps/controller/SourceLogController.java b/src/main/java/com/mzaxd/bps/controller/SourceLogController.java index b312e15..c8627d5 100644 --- a/src/main/java/com/mzaxd/bps/controller/SourceLogController.java +++ b/src/main/java/com/mzaxd/bps/controller/SourceLogController.java @@ -1,42 +1,62 @@ package com.mzaxd.bps.controller; -import com.mzaxd.bps.domain.vo.PageVo; -import com.mzaxd.bps.domain.vo.SourceLogVo; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.mzaxd.bps.domain.entity.SourceLog; import com.mzaxd.bps.service.SourceLogService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; +import com.mzaxd.bps.util.Result; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; +import javax.annotation.Resource; /** - * 网盘日志表(SourceLog)表控制层 + * 网盘日志Controller * * @author mzaxd - * @since 2024-04-06 10:00:00 + * @since 2024-04-06 */ @RestController -@RequestMapping("/api/source/log") -@Api(tags = "网盘日志管理") +@RequestMapping("/source/log") public class SourceLogController { - @Autowired + @Resource private SourceLogService sourceLogService; - @GetMapping("/list") - @ApiOperation("获取日志列表") - public PageVo getLogList( + /** + * 分页查询网盘日志 + */ + @GetMapping("/page") + public Result> page( @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) Long sourceId) { - return sourceLogService.getLogList(pageNum, pageSize, sourceId); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(sourceId != null, SourceLog::getSourceId, sourceId) + .orderByDesc(SourceLog::getCreateTime); + return Result.success(sourceLogService.page(new Page<>(pageNum, pageSize), queryWrapper)); } - @PostMapping("/{sourceId}") - @ApiOperation("添加日志") - public boolean addLog(@PathVariable Long sourceId, HttpServletRequest request) { - String ip = request.getRemoteAddr(); - return sourceLogService.addLog(sourceId, ip); + /** + * 获取网盘日志详情 + */ + @GetMapping("/{id}") + public Result getById(@PathVariable Long id) { + return Result.success(sourceLogService.getById(id)); + } + + /** + * 新增网盘日志 + */ + @PostMapping + public Result save(@RequestBody SourceLog sourceLog) { + return Result.success(sourceLogService.save(sourceLog)); + } + + /** + * 删除网盘日志 + */ + @DeleteMapping("/{id}") + public Result removeById(@PathVariable Long id) { + return Result.success(sourceLogService.removeById(id)); } } \ No newline at end of file diff --git a/src/main/java/com/mzaxd/bps/service/SourceService.java b/src/main/java/com/mzaxd/bps/service/SourceService.java index 6d4759f..cb7504e 100644 --- a/src/main/java/com/mzaxd/bps/service/SourceService.java +++ b/src/main/java/com/mzaxd/bps/service/SourceService.java @@ -1,5 +1,6 @@ package com.mzaxd.bps.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.mzaxd.bps.domain.entity.Source; import com.mzaxd.bps.domain.vo.PageVo; @@ -56,4 +57,15 @@ public interface SourceService extends IService { * @return 是否成功 */ boolean deleteSource(Long id); + + /** + * 搜索网盘资源 + * + * @param pageNum 页码 + * @param pageSize 每页大小 + * @param keyword 关键词 + * @param categoryId 分类ID + * @return 分页结果 + */ + Page search(Integer pageNum, Integer pageSize, String keyword, Long categoryId); } \ No newline at end of file diff --git a/src/main/java/com/mzaxd/bps/service/impl/SourceServiceImpl.java b/src/main/java/com/mzaxd/bps/service/impl/SourceServiceImpl.java index 5782853..a41de84 100644 --- a/src/main/java/com/mzaxd/bps/service/impl/SourceServiceImpl.java +++ b/src/main/java/com/mzaxd/bps/service/impl/SourceServiceImpl.java @@ -116,4 +116,31 @@ public class SourceServiceImpl extends ServiceImpl impleme public boolean deleteSource(Long id) { return removeById(id); } + + @Override + public Page search(Integer pageNum, Integer pageSize, String keyword, Long categoryId) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + // 关键词搜索(标题、描述、代码) + if (StringUtils.hasText(keyword)) { + queryWrapper.and(wrapper -> wrapper + .like(Source::getTitle, keyword) + .or() + .like(Source::getDescription, keyword) + .or() + .like(Source::getCode, keyword)); + } + + // 分类筛选 + if (categoryId != null) { + queryWrapper.eq(Source::getSourceCategoryId, categoryId); + } + + // 只查询未删除的资源 + queryWrapper.eq(Source::getIsDelete, 0) + .eq(Source::getStatus, 1) + .orderByDesc(Source::getCreateTime); + + return page(new Page<>(pageNum, pageSize), queryWrapper); + } } \ No newline at end of file diff --git a/src/main/java/com/mzaxd/bps/util/FileUtil.java b/src/main/java/com/mzaxd/bps/util/FileUtil.java new file mode 100644 index 0000000..f857dff --- /dev/null +++ b/src/main/java/com/mzaxd/bps/util/FileUtil.java @@ -0,0 +1,55 @@ +package com.mzaxd.bps.util; + +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +/** + * 文件操作工具类 + * + * @author mzaxd + * @since 2024-04-06 + */ +public class FileUtil { + + /** + * 上传文件 + * + * @param file 文件 + * @param path 保存路径 + * @return 文件名 + */ + public static String upload(MultipartFile file, String path) throws IOException { + // 获取文件名 + String originalFilename = file.getOriginalFilename(); + // 获取文件后缀 + String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")); + // 生成新文件名 + String fileName = UUID.randomUUID().toString() + suffix; + // 创建文件对象 + File dest = new File(path + fileName); + // 判断路径是否存在,不存在则创建 + if (!dest.getParentFile().exists()) { + dest.getParentFile().mkdirs(); + } + // 保存文件 + file.transferTo(dest); + return fileName; + } + + /** + * 删除文件 + * + * @param path 文件路径 + * @return 是否成功 + */ + public static boolean delete(String path) { + File file = new File(path); + if (file.exists() && file.isFile()) { + return file.delete(); + } + return false; + } +} \ No newline at end of file