mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
add 增加 OSS 模块业务代码
This commit is contained in:
@ -0,0 +1,62 @@
|
||||
package com.ruoyi.system.bo;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* OSS云存储分页查询对象 sys_oss
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel("OSS云存储分页查询对象")
|
||||
public class SysOssQueryBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 分页大小
|
||||
*/
|
||||
@ApiModelProperty("分页大小")
|
||||
private Integer pageSize;
|
||||
/**
|
||||
* 当前页数
|
||||
*/
|
||||
@ApiModelProperty("当前页数")
|
||||
private Integer pageNum;
|
||||
/**
|
||||
* 排序列
|
||||
*/
|
||||
@ApiModelProperty("排序列")
|
||||
private String orderByColumn;
|
||||
/**
|
||||
* 排序的方向desc或者asc
|
||||
*/
|
||||
@ApiModelProperty(value = "排序的方向", example = "asc,desc")
|
||||
private String isAsc;
|
||||
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
@ApiModelProperty("文件名")
|
||||
private String fileName;
|
||||
/**
|
||||
* 文件后缀名
|
||||
*/
|
||||
@ApiModelProperty("文件后缀名")
|
||||
private String fileSuffix;
|
||||
/**
|
||||
* URL地址
|
||||
*/
|
||||
@ApiModelProperty("URL地址")
|
||||
private String url;
|
||||
/**
|
||||
* 服务商
|
||||
*/
|
||||
@ApiModelProperty("服务商")
|
||||
private String service;
|
||||
|
||||
}
|
@ -8,11 +8,18 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.system.bo.SysOssQueryBo;
|
||||
import com.ruoyi.system.domain.SysOss;
|
||||
import com.ruoyi.system.service.ISysOssService;
|
||||
import com.ruoyi.system.vo.SysOssVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -26,6 +33,8 @@ import java.util.Map;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Validated
|
||||
@Api(value = "OSS云存储控制器", tags = {"OSS云存储管理"})
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
@RestController
|
||||
@RequestMapping("/system/oss")
|
||||
@ -34,22 +43,27 @@ public class SysOssController extends BaseController {
|
||||
private final ISysOssService iSysOssService;
|
||||
|
||||
/**
|
||||
* 查询文件上传列表
|
||||
* 查询OSS云存储列表
|
||||
*/
|
||||
@ApiOperation("查询OSS云存储列表")
|
||||
@PreAuthorize("@ss.hasPermi('system:oss:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<SysOss> list(SysOss sysOss) {
|
||||
return iSysOssService.queryPageList(sysOss);
|
||||
public TableDataInfo<SysOssVo> list(@Validated SysOssQueryBo bo) {
|
||||
return iSysOssService.queryPageList(bo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* 上传OSS云存储
|
||||
*/
|
||||
@ApiOperation("上传OSS云存储")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "文件", dataType = "java.io.File", required = true),
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermi('system:oss:upload')")
|
||||
@Log(title = "OSS云存储", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit
|
||||
@PostMapping("/upload")
|
||||
public AjaxResult<Map<String, String>> upload(@RequestParam("file") MultipartFile file) {
|
||||
public AjaxResult<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
|
||||
if (file.isEmpty()) {
|
||||
throw new CustomException("上传文件不能为空");
|
||||
}
|
||||
@ -63,12 +77,13 @@ public class SysOssController extends BaseController {
|
||||
/**
|
||||
* 删除OSS云存储
|
||||
*/
|
||||
@ApiOperation("删除OSS云存储")
|
||||
@PreAuthorize("@ss.hasPermi('system:oss:remove')")
|
||||
@Log(title = "OSS云存储" , businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ossIds}")
|
||||
public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ossIds) {
|
||||
return toAjax(iSysOssService.deleteByIds(Arrays.asList(ossIds)) ? 1 : 0);
|
||||
return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true) ? 1 : 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
|
||||
import com.ruoyi.system.domain.SysOss;
|
||||
|
||||
/**
|
||||
@ -8,5 +8,5 @@ import com.ruoyi.system.domain.SysOss;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public interface SysOssMapper extends BaseMapper<SysOss> {
|
||||
public interface SysOssMapper extends BaseMapperPlus<SysOss> {
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.common.core.mybatisplus.core.IServicePlus;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.system.bo.SysOssQueryBo;
|
||||
import com.ruoyi.system.domain.SysOss;
|
||||
import com.ruoyi.system.vo.SysOssVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -12,11 +14,11 @@ import java.util.Collection;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public interface ISysOssService extends IService<SysOss> {
|
||||
public interface ISysOssService extends IServicePlus<SysOss> {
|
||||
|
||||
TableDataInfo<SysOss> queryPageList(SysOss sysOss);
|
||||
TableDataInfo<SysOssVo> queryPageList(SysOssQueryBo sysOss);
|
||||
|
||||
SysOss upload(MultipartFile file);
|
||||
|
||||
Boolean deleteByIds(Collection<Long> ids);
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
|
@ -3,40 +3,51 @@ package com.ruoyi.system.service.impl;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
||||
import com.ruoyi.common.core.page.PagePlus;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.common.utils.PageUtils;
|
||||
import com.ruoyi.oss.factory.OssFactory;
|
||||
import com.ruoyi.oss.service.ICloudStorageService;
|
||||
import com.ruoyi.system.bo.SysOssQueryBo;
|
||||
import com.ruoyi.system.domain.SysOss;
|
||||
import com.ruoyi.system.mapper.SysOssMapper;
|
||||
import com.ruoyi.system.service.ISysOssService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.system.vo.SysOssVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件上传 服务层实现
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysOssServiceImpl extends ServiceImpl<SysOssMapper, SysOss> implements ISysOssService {
|
||||
public class SysOssServiceImpl extends ServicePlusImpl<SysOssMapper, SysOss> implements ISysOssService {
|
||||
|
||||
@Override
|
||||
public TableDataInfo<SysOss> queryPageList(SysOss sysOss) {
|
||||
public TableDataInfo<SysOssVo> queryPageList(SysOssQueryBo bo) {
|
||||
PagePlus<SysOss, SysOssVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), SysOssVo.class);
|
||||
return PageUtils.buildDataInfo(result);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SysOss> buildQueryWrapper(SysOssQueryBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<SysOss> lqw = Wrappers.lambdaQuery();
|
||||
lqw.like(StrUtil.isNotBlank(sysOss.getFileName()), SysOss::getFileName, sysOss.getFileName());
|
||||
lqw.like(StrUtil.isNotBlank(sysOss.getFileSuffix()), SysOss::getFileSuffix, sysOss.getFileSuffix());
|
||||
lqw.like(StrUtil.isNotBlank(sysOss.getUrl()), SysOss::getUrl, sysOss.getUrl());
|
||||
lqw.like(StrUtil.isNotBlank(sysOss.getService()), SysOss::getService, sysOss.getService());
|
||||
return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw));
|
||||
lqw.like(StrUtil.isNotBlank(bo.getFileName()), SysOss::getFileName, bo.getFileName());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getFileSuffix()), SysOss::getFileSuffix, bo.getFileSuffix());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getUrl()), SysOss::getUrl, bo.getUrl());
|
||||
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
|
||||
SysOss::getCreateTime ,params.get("beginCreateTime"), params.get("endCreateTime"));
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getService()), SysOss::getService, bo.getService());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,7 +70,10 @@ public class SysOssServiceImpl extends ServiceImpl<SysOssMapper, SysOss> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteByIds(Collection<Long> ids) {
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
// 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
List<SysOss> list = listByIds(ids);
|
||||
for (SysOss sysOss : list) {
|
||||
ICloudStorageService storage = OssFactory.instance(sysOss.getService());
|
||||
|
63
ruoyi-oss/src/main/java/com/ruoyi/system/vo/SysOssVo.java
Normal file
63
ruoyi-oss/src/main/java/com/ruoyi/system/vo/SysOssVo.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.ruoyi.system.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* OSS云存储视图对象 sys_oss
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("OSS云存储视图对象")
|
||||
public class SysOssVo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 云存储主键
|
||||
*/
|
||||
@ApiModelProperty("云存储主键")
|
||||
private Long ossId;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
@ApiModelProperty("文件名")
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件后缀名
|
||||
*/
|
||||
@ApiModelProperty("文件后缀名")
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* URL地址
|
||||
*/
|
||||
@ApiModelProperty("URL地址")
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 上传人
|
||||
*/
|
||||
@ApiModelProperty("上传人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 服务商
|
||||
*/
|
||||
@ApiModelProperty("服务商")
|
||||
private String service;
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user