Эх сурвалжийг харах

add 增加 OSS 模块业务代码

疯狂的狮子li 3 жил өмнө
parent
commit
00b9043915

+ 62 - 0
ruoyi-oss/src/main/java/com/ruoyi/system/bo/SysOssQueryBo.java

@@ -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;
+
+}

+ 21 - 6
ruoyi-oss/src/main/java/com/ruoyi/system/controller/SysOssController.java

@@ -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);
 	}
 
 }

+ 2 - 2
ruoyi-oss/src/main/java/com/ruoyi/system/mapper/SysOssMapper.java

@@ -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> {
 }

+ 6 - 4
ruoyi-oss/src/main/java/com/ruoyi/system/service/ISysOssService.java

@@ -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);
 }

+ 25 - 11
ruoyi-oss/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java

@@ -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 - 0
ruoyi-oss/src/main/java/com/ruoyi/system/vo/SysOssVo.java

@@ -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;
+
+
+}

+ 35 - 0
ruoyi-ui/src/api/system/oss.js

@@ -0,0 +1,35 @@
+import request from '@/utils/request'
+
+// 查询OSS云存储列表
+export function listOss(query) {
+  return request({
+    url: '/system/oss/list',
+    method: 'get',
+    params: query
+  })
+}
+
+// 上传OSS云存储
+export function addOss(data) {
+  return request({
+    url: '/system/oss/upload',
+    method: 'post',
+    data: data
+  })
+}
+
+// 下载OSS云存储
+export function downloadOss(ossId) {
+  return request({
+    url: '/system/oss/download/' + ossId,
+    method: 'get'
+  })
+}
+
+// 删除OSS云存储
+export function delOss(ossId) {
+  return request({
+    url: '/system/oss/' + ossId,
+    method: 'delete'
+  })
+}

+ 286 - 0
ruoyi-ui/src/views/system/oss/index.vue

@@ -0,0 +1,286 @@
+<template>
+  <div class="app-container">
+    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
+      <el-form-item label="文件名" prop="fileName">
+        <el-input
+          v-model="queryParams.fileName"
+          placeholder="请输入文件名"
+          clearable
+          size="small"
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
+      <el-form-item label="文件后缀" prop="fileSuffix">
+        <el-input
+          v-model="queryParams.fileSuffix"
+          placeholder="请输入文件后缀"
+          clearable
+          size="small"
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
+      <el-form-item label="创建时间">
+        <el-date-picker
+          v-model="daterangeCreateTime"
+          size="small"
+          style="width: 240px"
+          value-format="yyyy-MM-dd"
+          type="daterange"
+          range-separator="-"
+          start-placeholder="开始日期"
+          end-placeholder="结束日期"
+        ></el-date-picker>
+      </el-form-item>
+      <el-form-item label="上传人" prop="createBy">
+        <el-input
+          v-model="queryParams.createBy"
+          placeholder="请输入上传人"
+          clearable
+          size="small"
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
+      <el-form-item label="服务商" prop="service">
+        <el-input
+          v-model="queryParams.service"
+          placeholder="请输入服务商"
+          clearable
+          size="small"
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
+      <el-form-item>
+        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
+        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
+      </el-form-item>
+    </el-form>
+
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          plain
+          icon="el-icon-plus"
+          size="mini"
+          @click="handleAdd"
+          v-hasPermi="['system:oss:upload']"
+        >上传</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="danger"
+          plain
+          icon="el-icon-delete"
+          size="mini"
+          :disabled="multiple"
+          @click="handleDelete"
+          v-hasPermi="['system:oss:remove']"
+        >删除</el-button>
+      </el-col>
+      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
+    </el-row>
+
+    <el-table v-loading="loading" :data="ossList" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" align="center" />
+      <el-table-column label="云存储主键" align="center" prop="ossId" v-if="false"/>
+      <el-table-column label="文件名" align="center" prop="fileName" />
+      <el-table-column label="文件后缀名" align="center" prop="fileSuffix" />
+      <el-table-column label="URL地址" align="center" prop="url" />
+      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
+        <template slot-scope="scope">
+          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column label="上传人" align="center" prop="createBy" />
+      <el-table-column label="服务商" align="center" prop="service" />
+      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+        <template slot-scope="scope">
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-edit"
+            @click="handleDownload(scope.row)"
+            v-hasPermi="['system:oss:download']"
+          >下载</el-button>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-delete"
+            @click="handleDelete(scope.row)"
+            v-hasPermi="['system:oss:remove']"
+          >删除</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <pagination
+      v-show="total>0"
+      :total="total"
+      :page.sync="queryParams.pageNum"
+      :limit.sync="queryParams.pageSize"
+      @pagination="getList"
+    />
+
+    <!-- 添加或修改OSS云存储对话框 -->
+    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
+      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
+        <el-form-item label="文件名">
+          <imageUpload v-model="form.file"/>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
+        <el-button @click="cancel">取 消</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import { listOss, delOss, addOss, downloadOss } from "@/api/system/oss";
+
+export default {
+  name: "Oss",
+  data() {
+    return {
+      // 按钮loading
+      buttonLoading: false,
+      // 遮罩层
+      loading: true,
+      // 导出遮罩层
+      exportLoading: false,
+      // 选中数组
+      ids: [],
+      // 非单个禁用
+      single: true,
+      // 非多个禁用
+      multiple: true,
+      // 显示搜索条件
+      showSearch: true,
+      // 总条数
+      total: 0,
+      // OSS云存储表格数据
+      ossList: [],
+      // 弹出层标题
+      title: "",
+      // 是否显示弹出层
+      open: false,
+      // 创建时间时间范围
+      daterangeCreateTime: [],
+      // 查询参数
+      queryParams: {
+        pageNum: 1,
+        pageSize: 10,
+        fileName: undefined,
+        fileSuffix: undefined,
+        url: undefined,
+        createTime: undefined,
+        createBy: undefined,
+        service: undefined
+      },
+      // 表单参数
+      form: {},
+      // 表单校验
+      rules: {
+        file: [
+          { required: true, message: "文件不能为空", trigger: "blur" }
+        ]
+      }
+    };
+  },
+  created() {
+    this.getList();
+  },
+  methods: {
+    /** 查询OSS云存储列表 */
+    getList() {
+      this.loading = true;
+      this.queryParams.params = {};
+      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
+        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
+        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
+      }
+      listOss(this.queryParams).then(response => {
+        this.ossList = response.rows;
+        this.total = response.total;
+        this.loading = false;
+      });
+    },
+    // 取消按钮
+    cancel() {
+      this.open = false;
+      this.reset();
+    },
+    // 表单重置
+    reset() {
+      this.form = {
+        ossId: undefined,
+        file: undefined,
+        fileName: undefined,
+        fileSuffix: undefined,
+        url: undefined,
+        createTime: undefined,
+        createBy: undefined,
+        updateTime: undefined,
+        updateBy: undefined,
+        service: undefined
+      };
+      this.resetForm("form");
+    },
+    /** 搜索按钮操作 */
+    handleQuery() {
+      this.queryParams.pageNum = 1;
+      this.getList();
+    },
+    /** 重置按钮操作 */
+    resetQuery() {
+      this.daterangeCreateTime = [];
+      this.resetForm("queryForm");
+      this.handleQuery();
+    },
+    // 多选框选中数据
+    handleSelectionChange(selection) {
+      this.ids = selection.map(item => item.ossId)
+      this.single = selection.length!==1
+      this.multiple = !selection.length
+    },
+    /** 新增按钮操作 */
+    handleAdd() {
+      this.reset();
+      this.open = true;
+      this.title = "上传OSS云存储";
+    },
+    /** 提交按钮 */
+    submitForm() {
+      this.$refs["form"].validate(valid => {
+        if (valid) {
+          this.buttonLoading = true;
+          addOss(this.form).then(response => {
+            this.msgSuccess("上传成功");
+            this.open = false;
+            this.getList();
+          }).finally(() => {
+            this.buttonLoading = false;
+          });
+        }
+      });
+    },
+    /** 删除按钮操作 */
+    handleDelete(row) {
+      const ossIds = row.ossId || this.ids;
+      this.$confirm('是否确认删除OSS云存储编号为"' + ossIds + '"的数据项?', "警告", {
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning"
+        }).then(() => {
+          this.loading = true;
+          return delOss(ossIds);
+        }).then(() => {
+          this.loading = false;
+          this.getList();
+          this.msgSuccess("删除成功");
+        }).catch(() => {});
+    }
+  }
+};
+</script>

+ 1 - 1
sql/oss.sql

@@ -17,7 +17,7 @@ create table sys_oss (
 
 insert into sys_config values(10, 'OSS云存储服务商',       'sys.oss.cloudStorageService',      'minio',          'Y', 'admin', sysdate(), '', null, 'OSS云存储服务商(qiniu:七牛云, aliyun:阿里云, qcloud:腾讯云, minio: Minio)');
 
-insert into sys_menu values('118',  '文件管理', '1',   '10', 'oss',     'system/oss/index',      1, 0, 'C', '0', '0', 'system:oss:list',      'oss',       'admin', sysdate(), '', null, '文件管理菜单');
+insert into sys_menu values('118',  '文件管理', '1',   '10', 'oss',     'system/oss/index',      1, 0, 'C', '0', '0', 'system:oss:list',      'upload',       'admin', sysdate(), '', null, '文件管理菜单');
 
 insert into sys_menu values('1600', '文件查询', '118', '1', '#', '', 1, 0, 'F', '0', '0', 'system:oss:query',        '#', 'admin', sysdate(), '', null, '');
 insert into sys_menu values('1601', '文件上传', '118', '2', '#', '', 1, 0, 'F', '0', '0', 'system:oss:upload',       '#', 'admin', sysdate(), '', null, '');