feat: 迁移2
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<String> upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||||
|
String fileName = FileUtil.upload(file, fileConfig.getUploadPath());
|
||||||
|
return Result.success(fileConfig.getAccessPath() + fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{fileName}")
|
||||||
|
public Result<Boolean> delete(@PathVariable String fileName) {
|
||||||
|
return Result.success(FileUtil.delete(fileConfig.getUploadPath() + fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,50 +1,82 @@
|
|||||||
package com.mzaxd.bps.controller;
|
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.entity.SourceCategory;
|
||||||
import com.mzaxd.bps.domain.vo.SourceCategoryVo;
|
|
||||||
import com.mzaxd.bps.service.SourceCategoryService;
|
import com.mzaxd.bps.service.SourceCategoryService;
|
||||||
import io.swagger.annotations.Api;
|
import com.mzaxd.bps.util.Result;
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网盘分类表(SourceCategory)表控制层
|
* 网盘分类Controller
|
||||||
*
|
*
|
||||||
* @author mzaxd
|
* @author mzaxd
|
||||||
* @since 2024-04-06 10:00:00
|
* @since 2024-04-06
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/source/category")
|
@RequestMapping("/source/category")
|
||||||
@Api(tags = "网盘分类管理")
|
|
||||||
public class SourceCategoryController {
|
public class SourceCategoryController {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private SourceCategoryService sourceCategoryService;
|
private SourceCategoryService sourceCategoryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询网盘分类
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
public Result<Page<SourceCategory>> page(
|
||||||
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||||
|
@RequestParam(required = false) String name) {
|
||||||
|
LambdaQueryWrapper<SourceCategory> 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")
|
@GetMapping("/list")
|
||||||
@ApiOperation("获取分类列表")
|
public Result<List<SourceCategory>> list() {
|
||||||
public List<SourceCategoryVo> getCategoryList() {
|
LambdaQueryWrapper<SourceCategory> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
return sourceCategoryService.getCategoryList();
|
queryWrapper.eq(SourceCategory::getStatus, 1)
|
||||||
|
.orderByAsc(SourceCategory::getSort);
|
||||||
|
return Result.success(sourceCategoryService.list(queryWrapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取网盘分类详情
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Result<SourceCategory> getById(@PathVariable Long id) {
|
||||||
|
return Result.success(sourceCategoryService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增网盘分类
|
||||||
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("新增分类")
|
public Result<Boolean> save(@RequestBody SourceCategory sourceCategory) {
|
||||||
public boolean addCategory(@RequestBody SourceCategory category) {
|
return Result.success(sourceCategoryService.save(sourceCategory));
|
||||||
return sourceCategoryService.addCategory(category);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改网盘分类
|
||||||
|
*/
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ApiOperation("更新分类")
|
public Result<Boolean> updateById(@RequestBody SourceCategory sourceCategory) {
|
||||||
public boolean updateCategory(@RequestBody SourceCategory category) {
|
return Result.success(sourceCategoryService.updateById(sourceCategory));
|
||||||
return sourceCategoryService.updateCategory(category);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除网盘分类
|
||||||
|
*/
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@ApiOperation("删除分类")
|
public Result<Boolean> removeById(@PathVariable Long id) {
|
||||||
public boolean deleteCategory(@PathVariable Long id) {
|
return Result.success(sourceCategoryService.removeById(id));
|
||||||
return sourceCategoryService.deleteCategory(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,18 @@ public class SourceController {
|
|||||||
@Resource
|
@Resource
|
||||||
private SourceService sourceService;
|
private SourceService sourceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索网盘资源
|
||||||
|
*/
|
||||||
|
@GetMapping("/search")
|
||||||
|
public Result<Page<Source>> 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));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询网盘资源
|
* 分页查询网盘资源
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,42 +1,62 @@
|
|||||||
package com.mzaxd.bps.controller;
|
package com.mzaxd.bps.controller;
|
||||||
|
|
||||||
import com.mzaxd.bps.domain.vo.PageVo;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.mzaxd.bps.domain.vo.SourceLogVo;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.mzaxd.bps.domain.entity.SourceLog;
|
||||||
import com.mzaxd.bps.service.SourceLogService;
|
import com.mzaxd.bps.service.SourceLogService;
|
||||||
import io.swagger.annotations.Api;
|
import com.mzaxd.bps.util.Result;
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网盘日志表(SourceLog)表控制层
|
* 网盘日志Controller
|
||||||
*
|
*
|
||||||
* @author mzaxd
|
* @author mzaxd
|
||||||
* @since 2024-04-06 10:00:00
|
* @since 2024-04-06
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/source/log")
|
@RequestMapping("/source/log")
|
||||||
@Api(tags = "网盘日志管理")
|
|
||||||
public class SourceLogController {
|
public class SourceLogController {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private SourceLogService sourceLogService;
|
private SourceLogService sourceLogService;
|
||||||
|
|
||||||
@GetMapping("/list")
|
/**
|
||||||
@ApiOperation("获取日志列表")
|
* 分页查询网盘日志
|
||||||
public PageVo<SourceLogVo> getLogList(
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
public Result<Page<SourceLog>> page(
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||||
@RequestParam(required = false) Long sourceId) {
|
@RequestParam(required = false) Long sourceId) {
|
||||||
return sourceLogService.getLogList(pageNum, pageSize, sourceId);
|
LambdaQueryWrapper<SourceLog> 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();
|
@GetMapping("/{id}")
|
||||||
return sourceLogService.addLog(sourceId, ip);
|
public Result<SourceLog> getById(@PathVariable Long id) {
|
||||||
|
return Result.success(sourceLogService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增网盘日志
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public Result<Boolean> save(@RequestBody SourceLog sourceLog) {
|
||||||
|
return Result.success(sourceLogService.save(sourceLog));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除网盘日志
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Result<Boolean> removeById(@PathVariable Long id) {
|
||||||
|
return Result.success(sourceLogService.removeById(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.mzaxd.bps.service;
|
package com.mzaxd.bps.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.mzaxd.bps.domain.entity.Source;
|
import com.mzaxd.bps.domain.entity.Source;
|
||||||
import com.mzaxd.bps.domain.vo.PageVo;
|
import com.mzaxd.bps.domain.vo.PageVo;
|
||||||
@@ -56,4 +57,15 @@ public interface SourceService extends IService<Source> {
|
|||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
boolean deleteSource(Long id);
|
boolean deleteSource(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索网盘资源
|
||||||
|
*
|
||||||
|
* @param pageNum 页码
|
||||||
|
* @param pageSize 每页大小
|
||||||
|
* @param keyword 关键词
|
||||||
|
* @param categoryId 分类ID
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
Page<Source> search(Integer pageNum, Integer pageSize, String keyword, Long categoryId);
|
||||||
}
|
}
|
||||||
@@ -116,4 +116,31 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
|||||||
public boolean deleteSource(Long id) {
|
public boolean deleteSource(Long id) {
|
||||||
return removeById(id);
|
return removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<Source> search(Integer pageNum, Integer pageSize, String keyword, Long categoryId) {
|
||||||
|
LambdaQueryWrapper<Source> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user