Explorar o código

:zap: 增加oss管理系统

smallchill %!s(int64=7) %!d(string=hai) anos
pai
achega
155e95184c

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 2
doc/sql/bladex-saber-mysql.sql


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 2
doc/sql/bladex-sword-mysql.sql


+ 10 - 0
pom.xml

@@ -80,6 +80,16 @@
             <artifactId>blade-starter-develop</artifactId>
             <version>${bladex.tool.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springblade</groupId>
+            <artifactId>blade-starter-minio</artifactId>
+            <version>${bladex.tool.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springblade</groupId>
+            <artifactId>blade-starter-qiniu</artifactId>
+            <version>${bladex.tool.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.springblade</groupId>
             <artifactId>blade-core-auto</artifactId>

+ 45 - 0
src/main/java/org/springblade/modules/resource/builder/MinioBuilder.java

@@ -0,0 +1,45 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.builder;
+
+import io.minio.MinioClient;
+import lombok.SneakyThrows;
+import org.springblade.core.minio.MinioTemplate;
+import org.springblade.core.minio.props.MinioProperties;
+import org.springblade.core.oss.OssTemplate;
+import org.springblade.core.oss.rule.OssRule;
+import org.springblade.modules.resource.entity.Oss;
+
+/**
+ * MinioBuilder
+ *
+ * @author Chill
+ */
+public class MinioBuilder {
+
+	@SneakyThrows
+	public static OssTemplate template(Oss oss, OssRule ossRule) {
+		MinioClient minioClient = new MinioClient(oss.getEndpoint(), oss.getAccessKey(), oss.getSecretKey());
+		MinioProperties minioProperties = new MinioProperties();
+		minioProperties.setEndpoint(oss.getEndpoint());
+		minioProperties.setAccessKey(oss.getAccessKey());
+		minioProperties.setSecretKey(oss.getSecretKey());
+		minioProperties.setBucketName(oss.getBucketName());
+		return new MinioTemplate(minioClient, ossRule, minioProperties);
+	}
+
+}

+ 118 - 0
src/main/java/org/springblade/modules/resource/builder/OssBuilder.java

@@ -0,0 +1,118 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.builder;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.springblade.core.cache.utils.CacheUtil;
+import org.springblade.core.oss.OssTemplate;
+import org.springblade.core.oss.rule.OssRule;
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.modules.resource.entity.Oss;
+import org.springblade.modules.resource.enums.OssEnum;
+import org.springblade.modules.resource.enums.OssStatusEnum;
+import org.springblade.modules.resource.mapper.OssMapper;
+import org.springblade.modules.resource.props.OssProperties;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
+
+/**
+ * Oss存储
+ *
+ * @author Chill
+ */
+public class OssBuilder {
+
+	public static final String OSS_CODE = "oss:code:";
+
+	private final OssProperties ossProperties;
+	private final OssMapper ossMapper;
+	private final OssRule ossRule;
+
+	public OssBuilder(OssProperties ossProperties, OssMapper ossMapper, OssRule ossRule) {
+		this.ossProperties = ossProperties;
+		this.ossMapper = ossMapper;
+		this.ossRule = ossRule;
+	}
+
+	/**
+	 * OssTemplate配置缓存池
+	 */
+	private Map<String, OssTemplate> templatePool = new ConcurrentHashMap<>();
+
+	/**
+	 * oss配置缓存池
+	 */
+	private Map<String, Oss> ossPool = new ConcurrentHashMap<>();
+
+	/**
+	 * 获取template
+	 *
+	 * @return OssTemplate
+	 */
+	public OssTemplate template() {
+		String tenantCode = SecureUtil.getTenantCode();
+		Oss oss = getOss(tenantCode);
+		Oss ossCached = ossPool.get(tenantCode);
+		OssTemplate template = templatePool.get(tenantCode);
+		// 若为空或者不一致,则重新加载
+		if (Func.hasEmpty(template, ossCached) || oss.getEndpoint().equals(ossCached.getEndpoint()) || !oss.getAccessKey().equals(ossCached.getAccessKey())) {
+			synchronized (OssBuilder.class) {
+				template = templatePool.get(tenantCode);
+				if (Func.hasEmpty(template, ossCached) || oss.getEndpoint().equals(ossCached.getEndpoint()) || !oss.getAccessKey().equals(ossCached.getAccessKey())) {
+					if (oss.getCategory() == OssEnum.MINIO.getCategory()) {
+						template = MinioBuilder.template(oss, ossRule);
+					} else if (oss.getCategory() == OssEnum.QINIU.getCategory()) {
+						template = QiniuBuilder.template(oss, ossRule);
+					}
+					templatePool.put(tenantCode, template);
+					ossPool.put(tenantCode, oss);
+				}
+			}
+		}
+		return template;
+	}
+
+	/**
+	 * 获取对象存储实体
+	 *
+	 * @param tenantCode 租户编号
+	 * @return Role
+	 */
+	public Oss getOss(String tenantCode) {
+		return CacheUtil.get(SYS_CACHE, OSS_CODE, tenantCode, () -> {
+			Oss o = ossMapper.selectOne(Wrappers.<Oss>query().lambda().eq(Oss::getStatus, OssStatusEnum.ENABLE.getNum()));
+			// 若为空则调用默认配置
+			if ((Func.isEmpty(o))) {
+				Oss defaultOss = new Oss();
+				defaultOss.setCategory(OssEnum.QINIU.getCategory());
+				defaultOss.setEndpoint(ossProperties.getEndpoint());
+				defaultOss.setBucketName(ossProperties.getBucketName());
+				defaultOss.setAccessKey(ossProperties.getAccessKey());
+				defaultOss.setSecretKey(ossProperties.getSecretKey());
+				return defaultOss;
+			} else {
+				return o;
+			}
+		});
+	}
+
+
+}

+ 52 - 0
src/main/java/org/springblade/modules/resource/builder/QiniuBuilder.java

@@ -0,0 +1,52 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.builder;
+
+import com.qiniu.common.Zone;
+import com.qiniu.storage.BucketManager;
+import com.qiniu.storage.Configuration;
+import com.qiniu.storage.UploadManager;
+import com.qiniu.util.Auth;
+import lombok.SneakyThrows;
+import org.springblade.core.oss.OssTemplate;
+import org.springblade.core.oss.rule.OssRule;
+import org.springblade.core.qiniu.QiniuTemplate;
+import org.springblade.core.qiniu.props.QiniuProperties;
+import org.springblade.modules.resource.entity.Oss;
+
+/**
+ * QiniuBuilder
+ *
+ * @author Chill
+ */
+public class QiniuBuilder {
+
+	@SneakyThrows
+	public static OssTemplate template(Oss oss, OssRule ossRule) {
+		Configuration cfg = new Configuration(Zone.zone0());
+		Auth auth = Auth.create(oss.getAccessKey(), oss.getSecretKey());
+		UploadManager uploadManager = new UploadManager(cfg);
+		BucketManager bucketManager = new BucketManager(auth, cfg);
+		QiniuProperties qiniuProperties = new QiniuProperties();
+		qiniuProperties.setEndpoint(oss.getEndpoint());
+		qiniuProperties.setAccessKey(oss.getAccessKey());
+		qiniuProperties.setSecretKey(oss.getSecretKey());
+		qiniuProperties.setBucketName(oss.getBucketName());
+		return new QiniuTemplate(auth, uploadManager, bucketManager, qiniuProperties, ossRule);
+	}
+
+}

+ 57 - 0
src/main/java/org/springblade/modules/resource/config/OssConfiguration.java

@@ -0,0 +1,57 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.config;
+
+import lombok.AllArgsConstructor;
+import org.springblade.core.minio.rule.BladeMinioRule;
+import org.springblade.core.oss.rule.OssRule;
+import org.springblade.modules.resource.builder.OssBuilder;
+import org.springblade.modules.resource.mapper.OssMapper;
+import org.springblade.modules.resource.props.OssProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Oss配置类
+ *
+ * @author Chill
+ */
+@Configuration
+@AllArgsConstructor
+@EnableConfigurationProperties(OssProperties.class)
+public class OssConfiguration {
+
+	private OssProperties ossProperties;
+
+	private OssMapper ossMapper;
+
+	@Bean
+	@ConditionalOnMissingBean(OssRule.class)
+	public OssRule ossRule() {
+		return new BladeMinioRule(true);
+	}
+
+	@Bean
+	@ConditionalOnBean(OssRule.class)
+	public OssBuilder ossBuilder(OssRule ossRule) {
+		return new OssBuilder(ossProperties, ossMapper, ossRule);
+	}
+
+}

+ 135 - 0
src/main/java/org/springblade/modules/resource/controller/OssController.java

@@ -0,0 +1,135 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.AllArgsConstructor;
+import org.springblade.core.boot.ctrl.BladeController;
+import org.springblade.core.cache.utils.CacheUtil;
+import org.springblade.core.launch.constant.AppConstant;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.modules.resource.builder.OssBuilder;
+import org.springblade.modules.resource.entity.Oss;
+import org.springblade.modules.resource.entity.OssVO;
+import org.springblade.modules.resource.service.IOssService;
+import org.springblade.modules.resource.wrapper.OssWrapper;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
+
+/**
+ * 控制器
+ *
+ * @author BladeX
+ * @since 2019-05-26
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/oss")
+@Api(value = "对象存储接口", tags = "接口")
+public class OssController extends BladeController {
+
+	private IOssService ossService;
+
+	/**
+	 * 详情
+	 */
+	@GetMapping("/detail")
+	@ApiOperation(value = "详情", notes = "传入oss", position = 1)
+	public R<OssVO> detail(Oss oss) {
+		Oss detail = ossService.getOne(Condition.getQueryWrapper(oss));
+		return R.data(OssWrapper.build().entityVO(detail));
+	}
+
+	/**
+	 * 分页
+	 */
+	@GetMapping("/list")
+	@ApiOperation(value = "分页", notes = "传入oss", position = 2)
+	public R<IPage<OssVO>> list(Oss oss, Query query) {
+		IPage<Oss> pages = ossService.page(Condition.getPage(query), Condition.getQueryWrapper(oss));
+		return R.data(OssWrapper.build().pageVO(pages));
+	}
+
+	/**
+	 * 自定义分页
+	 */
+	@GetMapping("/page")
+	@ApiOperation(value = "分页", notes = "传入oss", position = 3)
+	public R<IPage<OssVO>> page(OssVO oss, Query query) {
+		IPage<OssVO> pages = ossService.selectOssPage(Condition.getPage(query), oss);
+		return R.data(pages);
+	}
+
+	/**
+	 * 新增
+	 */
+	@PostMapping("/save")
+	@ApiOperation(value = "新增", notes = "传入oss", position = 4)
+	public R save(@Valid @RequestBody Oss oss) {
+		return R.status(ossService.save(oss));
+	}
+
+	/**
+	 * 修改
+	 */
+	@PostMapping("/update")
+	@ApiOperation(value = "修改", notes = "传入oss", position = 5)
+	public R update(@Valid @RequestBody Oss oss) {
+		return R.status(ossService.updateById(oss));
+	}
+
+	/**
+	 * 新增或修改
+	 */
+	@PostMapping("/submit")
+	@ApiOperation(value = "新增或修改", notes = "传入oss", position = 6)
+	public R submit(@Valid @RequestBody Oss oss) {
+		return R.status(ossService.saveOrUpdate(oss));
+	}
+
+
+	/**
+	 * 删除
+	 */
+	@PostMapping("/remove")
+	@ApiOperation(value = "逻辑删除", notes = "传入ids", position = 7)
+	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+		return R.status(ossService.deleteLogic(Func.toLongList(ids)));
+	}
+
+
+	/**
+	 * 启用
+	 */
+	@PostMapping("/enable")
+	@ApiOperation(value = "配置启用", notes = "传入id", position = 7)
+	public R enable(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
+		CacheUtil.evict(SYS_CACHE, OssBuilder.OSS_CODE, SecureUtil.getTenantCode());
+		return R.status(ossService.enable(id));
+	}
+
+}

+ 172 - 0
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java

@@ -0,0 +1,172 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.endpoint;
+
+import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+import org.springblade.core.launch.constant.AppConstant;
+import org.springblade.core.oss.model.OssFile;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.modules.resource.builder.OssBuilder;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 对象存储端点
+ *
+ * @author Chill
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/oss/endpoint")
+public class OssEndpoint {
+
+	private OssBuilder ossBuilder;
+
+	/**
+	 * 创建存储桶
+	 *
+	 * @param bucketName 存储桶名称
+	 * @return Bucket
+	 */
+	@SneakyThrows
+	@PostMapping("/make-bucket")
+	public R makeBucket(@RequestParam String bucketName) {
+		ossBuilder.template().makeBucket(bucketName);
+		return R.success("创建成功");
+	}
+
+	/**
+	 * 创建存储桶
+	 *
+	 * @param bucketName 存储桶名称
+	 * @return R
+	 */
+	@SneakyThrows
+	@PostMapping("/remove-bucket")
+	public R removeBucket(@RequestParam String bucketName) {
+		ossBuilder.template().removeBucket(bucketName);
+		return R.success("删除成功");
+	}
+
+	/**
+	 * 拷贝文件
+	 *
+	 * @param fileName       存储桶对象名称
+	 * @param destBucketName 目标存储桶名称
+	 * @param destFileName   目标存储桶对象名称
+	 * @return R
+	 */
+	@SneakyThrows
+	@PostMapping("/copy-file")
+	public R copyFile(@RequestParam String fileName, @RequestParam String destBucketName, String destFileName) {
+		ossBuilder.template().copyFile(fileName, destBucketName, destFileName);
+		return R.success("操作成功");
+	}
+
+	/**
+	 * 获取文件信息
+	 *
+	 * @param fileName 存储桶对象名称
+	 * @return InputStream
+	 */
+	@SneakyThrows
+	@GetMapping("/stat-file")
+	public R<OssFile> statFile(@RequestParam String fileName) {
+		return R.data(ossBuilder.template().statFile(fileName));
+	}
+
+	/**
+	 * 获取文件相对路径
+	 *
+	 * @param fileName 存储桶对象名称
+	 * @return String
+	 */
+	@SneakyThrows
+	@GetMapping("/file-path")
+	public R<String> filePath(@RequestParam String fileName) {
+		return R.data(ossBuilder.template().filePath(fileName));
+	}
+
+
+	/**
+	 * 获取文件外链
+	 *
+	 * @param fileName 存储桶对象名称
+	 * @return String
+	 */
+	@SneakyThrows
+	@GetMapping("/file-link")
+	public R<String> fileLink(@RequestParam String fileName) {
+		return R.data(ossBuilder.template().fileLink(fileName));
+	}
+
+	/**
+	 * 上传文件
+	 *
+	 * @param file 文件
+	 * @return ObjectStat
+	 */
+	@SneakyThrows
+	@PostMapping("/put-file")
+	public R<OssFile> putFile(@RequestParam MultipartFile file) {
+		ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
+		return R.data(ossBuilder.template().statFile(file.getOriginalFilename()));
+	}
+
+	/**
+	 * 上传文件
+	 *
+	 * @param fileName 存储桶对象名称
+	 * @param file     文件
+	 * @return ObjectStat
+	 */
+	@SneakyThrows
+	@PostMapping("/put-file-by-name")
+	public R<OssFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) {
+		ossBuilder.template().putFile(fileName, file.getInputStream());
+		return R.data(ossBuilder.template().statFile(fileName));
+	}
+
+	/**
+	 * 删除文件
+	 *
+	 * @param fileName 存储桶对象名称
+	 * @return R
+	 */
+	@SneakyThrows
+	@PostMapping("/remove-file")
+	public R removeFile(@RequestParam String fileName) {
+		ossBuilder.template().removeFile(fileName);
+		return R.success("操作成功");
+	}
+
+	/**
+	 * 批量删除文件
+	 *
+	 * @param fileNames 存储桶对象名称集合
+	 * @return R
+	 */
+	@SneakyThrows
+	@PostMapping("/remove-files")
+	public R removeFiles(@RequestParam String fileNames) {
+		ossBuilder.template().removeFiles(Func.toStrList(fileNames));
+		return R.success("操作成功");
+	}
+
+}

+ 73 - 0
src/main/java/org/springblade/modules/resource/entity/Oss.java

@@ -0,0 +1,73 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.core.mp.base.BaseEntity;
+
+/**
+ * 实体类
+ *
+ * @author BladeX
+ * @since 2019-05-24
+ */
+@Data
+@TableName("blade_oss")
+@EqualsAndHashCode(callSuper = true)
+@ApiModel(value = "Oss对象", description = "Oss对象")
+public class Oss extends BaseEntity {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 所属分类
+	 */
+	@ApiModelProperty(value = "所属分类")
+	private Integer category;
+
+	/**
+	 * oss地址
+	 */
+	@ApiModelProperty(value = "资源地址")
+	private String endpoint;
+	/**
+	 * accessKey
+	 */
+	@ApiModelProperty(value = "accessKey")
+	private String accessKey;
+	/**
+	 * secretKey
+	 */
+	@ApiModelProperty(value = "secretKey")
+	private String secretKey;
+	/**
+	 * 空间名
+	 */
+	@ApiModelProperty(value = "空间名")
+	private String bucketName;
+	/**
+	 * 备注
+	 */
+	@ApiModelProperty(value = "备注")
+	private String remark;
+
+
+}

+ 23 - 0
src/main/java/org/springblade/modules/resource/entity/OssVO.java

@@ -0,0 +1,23 @@
+package org.springblade.modules.resource.entity;
+
+import lombok.Data;
+
+/**
+ * OssVO
+ *
+ * @author Chill
+ */
+@Data
+public class OssVO extends Oss {
+
+	/**
+	 * 分类名
+	 */
+	private String categoryName;
+
+	/**
+	 * 是否启用
+	 */
+	private String statusName;
+
+}

+ 45 - 0
src/main/java/org/springblade/modules/resource/enums/OssEnum.java

@@ -0,0 +1,45 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * Oss枚举类
+ *
+ * @author Chill
+ */
+@Getter
+@AllArgsConstructor
+public enum OssEnum {
+
+	/**
+	 * minio
+	 */
+	MINIO("minio", 1),
+
+	/**
+	 * qiniu
+	 */
+	QINIU("qiniu", 2),
+	;
+
+	final String name;
+	final int category;
+
+}

+ 46 - 0
src/main/java/org/springblade/modules/resource/enums/OssStatusEnum.java

@@ -0,0 +1,46 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * Oss类型枚举
+ *
+ * @author Chill
+ */
+@Getter
+@AllArgsConstructor
+public enum OssStatusEnum {
+
+	/**
+	 * 关闭
+	 */
+	DISABLE(1),
+	/**
+	 * 启用
+	 */
+	ENABLE(2),
+	;
+
+	/**
+	 * 类型编号
+	 */
+	final int num;
+
+}

+ 43 - 0
src/main/java/org/springblade/modules/resource/mapper/OssMapper.java

@@ -0,0 +1,43 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.modules.resource.entity.Oss;
+import org.springblade.modules.resource.entity.OssVO;
+
+import java.util.List;
+
+/**
+ *  Mapper 接口
+ *
+ * @author BladeX
+ * @since 2019-05-24
+ */
+public interface OssMapper extends BaseMapper<Oss> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param oss
+	 * @return
+	 */
+	List<OssVO> selectOssPage(IPage page, OssVO oss);
+
+}

+ 26 - 0
src/main/java/org/springblade/modules/resource/mapper/OssMapper.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.modules.resource.mapper.OssMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="ossResultMap" type="org.springblade.modules.resource.entity.Oss">
+        <result column="id" property="id"/>
+        <result column="create_user" property="createUser"/>
+        <result column="create_time" property="createTime"/>
+        <result column="update_user" property="updateUser"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="status" property="status"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="endpoint" property="endpoint"/>
+        <result column="access_key" property="accessKey"/>
+        <result column="secret_key" property="secretKey"/>
+        <result column="bucket_name" property="bucketName"/>
+        <result column="remark" property="remark"/>
+    </resultMap>
+
+
+    <select id="selectOssPage" resultMap="ossResultMap">
+        select * from blade_oss where is_deleted = 0
+    </select>
+
+</mapper>

+ 53 - 0
src/main/java/org/springblade/modules/resource/props/OssProperties.java

@@ -0,0 +1,53 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.props;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Oss配置
+ *
+ * @author Chill
+ */
+@Data
+@ConfigurationProperties(prefix = "oss")
+public class OssProperties {
+	/**
+	 * 是否开启租户模式
+	 */
+	private Boolean tenantMode;
+	/**
+	 * 对象存储服务的URL
+	 */
+	private String endpoint;
+
+	/**
+	 * Access key就像用户ID,可以唯一标识你的账户
+	 */
+	private String accessKey;
+
+	/**
+	 * Secret key是你账户的密码
+	 */
+	private String secretKey;
+
+	/**
+	 * 默认的存储桶名称
+	 */
+	private String bucketName;
+}

+ 49 - 0
src/main/java/org/springblade/modules/resource/service/IOssService.java

@@ -0,0 +1,49 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.core.mp.base.BaseService;
+import org.springblade.modules.resource.entity.Oss;
+import org.springblade.modules.resource.entity.OssVO;
+
+/**
+ * 服务类
+ *
+ * @author BladeX
+ * @since 2019-05-24
+ */
+public interface IOssService extends BaseService<Oss> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param oss
+	 * @return
+	 */
+	IPage<OssVO> selectOssPage(IPage<OssVO> page, OssVO oss);
+
+	/**
+	 * 启动配置
+	 *
+	 * @param id
+	 * @return
+	 */
+	boolean enable(Long id);
+
+}

+ 53 - 0
src/main/java/org/springblade/modules/resource/service/impl/OssServiceImpl.java

@@ -0,0 +1,53 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.modules.resource.entity.Oss;
+import org.springblade.modules.resource.entity.OssVO;
+import org.springblade.modules.resource.mapper.OssMapper;
+import org.springblade.modules.resource.service.IOssService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * 服务实现类
+ *
+ * @author BladeX
+ * @since 2019-05-24
+ */
+@Service
+public class OssServiceImpl extends BaseServiceImpl<OssMapper, Oss> implements IOssService {
+
+	@Override
+	public IPage<OssVO> selectOssPage(IPage<OssVO> page, OssVO oss) {
+		return page.setRecords(baseMapper.selectOssPage(page, oss));
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public boolean enable(Long id) {
+		// 先禁用
+		boolean temp1 = this.update(Wrappers.<Oss>update().lambda().set(Oss::getStatus, 1));
+		// 在启用
+		boolean temp2 = this.update(Wrappers.<Oss>update().lambda().set(Oss::getStatus, 2).eq(Oss::getId, id));
+		return temp1 && temp2;
+	}
+
+}

+ 48 - 0
src/main/java/org/springblade/modules/resource/wrapper/OssWrapper.java

@@ -0,0 +1,48 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.resource.wrapper;
+
+import org.springblade.common.cache.DictCache;
+import org.springblade.core.mp.support.BaseEntityWrapper;
+import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.modules.resource.entity.Oss;
+import org.springblade.modules.resource.entity.OssVO;
+
+/**
+ * 包装类,返回视图层所需的字段
+ *
+ * @author BladeX
+ * @since 2019-05-26
+ */
+public class OssWrapper extends BaseEntityWrapper<Oss, OssVO> {
+
+	public static OssWrapper build() {
+		return new OssWrapper();
+	}
+
+	@Override
+	public OssVO entityVO(Oss oss) {
+		OssVO ossVO = BeanUtil.copy(oss, OssVO.class);
+		assert ossVO != null;
+		String categoryName = DictCache.getValue("oss", oss.getCategory());
+		String statusName = DictCache.getValue("yes_no", oss.getStatus());
+		ossVO.setCategoryName(categoryName);
+		ossVO.setStatusName(statusName);
+		return ossVO;
+	}
+
+}

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio