Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions SpringBoot-Commons/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>SpringBootCodeBase</artifactId>
<groupId>com.fancv</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>SpringBoot-Commons</artifactId>

<name>SpringBoot-Commons</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- no more than 2.3.3-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
13 changes: 13 additions & 0 deletions SpringBoot-Commons/src/main/java/com/fancv/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fancv;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
51 changes: 51 additions & 0 deletions SpringBoot-Commons/src/main/java/com/ray/sdk/OssUtil/GetTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.ray.sdk.OssUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

public class GetTime {
/**
* 获取系统的当前时间
*
* @return String
*/
public static String PreTime() {
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日hh时mm分");//设置日期格式
String format = df.format(date);

return format;
}

/**
* 获取当天
*
* @return String
*/
public static String getToday() {
return new SimpleDateFormat("yyyyMMdd").format(new Date());
}

/**
* 获取当月
*
* @return String
*/
public static String getMonth() {
return new SimpleDateFormat("yyyy-MM").format(new Date());
}

/**
* 根据传入时间 获取当月
*
* @param time
* @return
*/
public static String getLastMonthFirstDate(Date time) {

return new SimpleDateFormat("yyyy-MM").format(time);

}


}
112 changes: 112 additions & 0 deletions SpringBoot-Commons/src/main/java/com/ray/sdk/OssUtil/RayOssUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.ray.sdk.OssUtil;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectResult;
import com.ray.sdk.config.ossConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

@Component
public class RayOssUtil {

@Autowired
OSS ossClient;

@Autowired
ossConfig ossConfig;

/**
* 上传文件
*
* @param name
* @param
* @return
* @throws FileNotFoundException
*/
public String putObject(String orgId, String name, InputStream inputStreame) throws IOException {
String key = new StringBuilder(orgId).append(GetTime.getToday()).append(name).toString();
PutObjectResult putObjectResult=ossClient.putObject(ossConfig.getBucketName(), key, inputStreame, getMetadata(inputStreame.available(), name));
return key;
}

/**
* 下载文件
*
* @param name
* @return
*/
public OSSObject getObject(String name) {
return ossClient.getObject(ossConfig.getBucketName(), name);
}

/***
* 删除文件
*/
public Boolean deleteObject(String key) throws IOException {
try {
ossClient.deleteObject(ossConfig.getBucketName(), key);
} catch (Exception e) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}


/**
* 要上传的文件类型
* ---->需要判断文件后缀名
*/
public ObjectMetadata getMetadata(Integer length, String fileName) throws IOException {
ObjectMetadata metadata = new ObjectMetadata();
//这里需要判断文件后缀名
metadata.setContentType(getContentType(fileName));
metadata.setContentLength(length.longValue());
metadata.setCacheControl("no-cache");
metadata.setHeader("Pragma", "no-cache");
metadata.setContentDisposition("inline;filename=" + fileName);
return metadata;
}

/**
* 判断要上传文件的后缀名
*/
public static String getContentType(String fileName) {
String filenameExtension = fileName.substring(fileName.lastIndexOf("."));
if (filenameExtension.equalsIgnoreCase(".bmp")) {
return "image/bmp";
}
if (filenameExtension.equalsIgnoreCase(".gif")) {
return "image/gif";
}
if (filenameExtension.equalsIgnoreCase(".jpeg") ||
filenameExtension.equalsIgnoreCase(".jpg") ||
filenameExtension.equalsIgnoreCase(".png")) {
return "image/jpeg";
}
if (filenameExtension.equalsIgnoreCase(".html")) {
return "text/html";
}
if (filenameExtension.equalsIgnoreCase(".txt")) {
return "text/plain";
}
if (filenameExtension.equalsIgnoreCase(".vsd")) {
return "application/vnd.visio";
}
if (filenameExtension.equalsIgnoreCase(".pptx") ||
filenameExtension.equalsIgnoreCase(".ppt")) {
return "application/vnd.ms-powerpoint";
}
if (filenameExtension.equalsIgnoreCase(".docx") ||
filenameExtension.equalsIgnoreCase(".doc")) {
return "application/msword";
}
return "image/jpeg";
}

}
47 changes: 47 additions & 0 deletions SpringBoot-Commons/src/main/java/com/ray/sdk/config/ossConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.ray.sdk.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
@Data
public class ossConfig {

@Value("${rayOssKey}")
private String rayOssKey;

@Value("${rayOssSecret}")
private String rayOssSecret;

@Value("${rayOssEndpoint}")
private String ossEndpoint;

@Value("${rayBucketName}")
private String bucketName;


@Bean
@Scope("prototype")
public OSS getOssObject(){
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
String endpoint = "https://oss-cn-zhangjiakou.aliyuncs.com";
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
String accessKeyId = "LTAI5tDT2HxdMRBVV8pE1MNv";
String accessKeySecret = "1whvEgrT0t7jo2vJxi0QgmJ0aWnzyH";
// 填写Bucket名称,例如examplebucket。
String bucketName = "fancv-sys";
// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。 按照orgId 年月日存储文件
String objectName = "exampledir3/1exampleobject.txt";

// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(ossEndpoint,rayOssKey,rayOssSecret);

return ossClient;

}
}
20 changes: 20 additions & 0 deletions SpringBoot-Commons/src/test/java/com/fancv/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.fancv;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions SpringBoot-Commons/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Created by Apache Maven 3.3.9
groupId=com.fancv
artifactId=SpringBoot-Commons
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
com\fancv\App.class
com\ray\sdk\config\ossConfig.class
com\ray\sdk\OssUtil\RayOssUtil.class
com\ray\sdk\OssUtil\GetTime.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\fancv\App.java
D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\ray\sdk\OssUtil\GetTime.java
D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\ray\sdk\config\ossConfig.java
D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\ray\sdk\OssUtil\RayOssUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com\fancv\AppTest.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\test\java\com\fancv\AppTest.java
Loading