更新控制器

This commit is contained in:
昕有灵犀
2018-07-03 17:15:07 +08:00
parent f33d085ade
commit e8725dd72e
34 changed files with 783 additions and 132 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,7 @@
.gradle
/build/
/logs/
/bin/
!gradle/wrapper/gradle-wrapper.jar
### STS ###

View File

@@ -1,3 +1,17 @@
/*
Navicat MySQL Data Transfer
Source Server : localhost3306
Source Server Version : 50550
Source Host : localhost:3306
Source Database : xyfs
Target Server Type : MYSQL
Target Server Version : 50550
File Encoding : 65001
Date: 2018-07-03 16:32:13
*/
SET FOREIGN_KEY_CHECKS=0;
@@ -7,31 +21,33 @@ SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `app`;
CREATE TABLE `app` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) DEFAULT NULL,
`code` varchar(30) DEFAULT NULL,
`key` varchar(50) DEFAULT NULL,
`available` char(1) DEFAULT 'y' COMMENT '是否可用',
`appkey` varchar(255) DEFAULT NULL,
`available` varchar(255) DEFAULT NULL,
`code` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of app
-- ----------------------------
INSERT INTO `app` VALUES ('1', 'xyTalk', 'xyTalk', null, null);
INSERT INTO `app` VALUES ('2', 'xyPortal', 'xyPortal', null, null);
INSERT INTO `app` VALUES ('1', 'password', '1', 'test1', 'test1');
INSERT INTO `app` VALUES ('2', 'password', '1', 'test2', 'test2');
INSERT INTO `app` VALUES ('3', 'password', '1', 'test3', 'test3');
INSERT INTO `app` VALUES ('4', 'password', '1', 'test4', 'test4');
-- ----------------------------
-- Table structure for `dailyreport`
-- ----------------------------
DROP TABLE IF EXISTS `dailyreport`;
CREATE TABLE `dailyreport` (
`id` int(11) NOT NULL DEFAULT '0',
`files` int(11) DEFAULT NULL,
`groups` int(11) DEFAULT NULL,
`spaces` int(11) DEFAULT NULL,
`curdate` varchar(30) DEFAULT NULL,
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`curdate` varchar(255) DEFAULT NULL,
`files` int(11) NOT NULL,
`groups` int(11) NOT NULL,
`spaces` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of dailyreport
@@ -42,31 +58,31 @@ CREATE TABLE `dailyreport` (
-- ----------------------------
DROP TABLE IF EXISTS `diskfile`;
CREATE TABLE `diskfile` (
`fileid` varchar(36) NOT NULL COMMENT '文件ID',
`appid` int(11) DEFAULT NULL COMMENT '所属app应用ID',
`formId` varchar(50) DEFAULT NULL COMMENT '用于集成第三方系统比如表单ID',
`filesource` varchar(10) DEFAULT NULL COMMENT '来源xyFS\\Seafile\\FastDFS\\MongoDB\\BFS\\PaxosStore\\aliOSS\\qiniu\\CFS',
`fileName` varchar(100) NOT NULL,
`fileSize` bigint(20) DEFAULT NULL,
`fileExt` varchar(20) DEFAULT NULL,
`fileUrl` varchar(100) DEFAULT NULL,
`fileFlag` char(1) DEFAULT NULL COMMENT '可用1已删除0',
`dfsGroupName` varchar(100) DEFAULT NULL,
`uploadDate` datetime DEFAULT NULL,
`uploadUser` varchar(50) DEFAULT NULL,
`expirationDate` datetime DEFAULT NULL,
`ispublic` char(1) DEFAULT NULL,
`groupId` varchar(50) DEFAULT NULL,
`groupName` varchar(100) DEFAULT NULL,
`downloadNum` int(11) DEFAULT '0',
`downloadPwd` varchar(64) DEFAULT NULL,
`extra1` varchar(100) DEFAULT NULL,
`extra2` varchar(100) DEFAULT NULL,
`extra3` varchar(100) DEFAULT NULL,
`extra4` varchar(100) DEFAULT NULL,
`extra5` varchar(100) DEFAULT NULL,
`fileid` varchar(255) NOT NULL,
`appid` int(11) NOT NULL,
`dfs_group_name` varchar(255) DEFAULT NULL,
`download_num` int(11) NOT NULL,
`download_pwd` varchar(255) DEFAULT NULL,
`expiration_date` datetime DEFAULT NULL,
`extra1` varchar(255) DEFAULT NULL,
`extra2` varchar(255) DEFAULT NULL,
`extra3` varchar(255) DEFAULT NULL,
`extra4` varchar(255) DEFAULT NULL,
`extra5` varchar(255) DEFAULT NULL,
`file_ext` varchar(255) DEFAULT NULL,
`file_flag` varchar(255) DEFAULT NULL,
`file_name` varchar(255) DEFAULT NULL,
`file_size` decimal(19,2) DEFAULT NULL,
`file_url` varchar(255) DEFAULT NULL,
`filesource` varchar(255) DEFAULT NULL,
`form_id` varchar(255) DEFAULT NULL,
`group_id` varchar(255) DEFAULT NULL,
`group_name` varchar(255) DEFAULT NULL,
`ispublic` varchar(255) DEFAULT NULL,
`upload_date` datetime DEFAULT NULL,
`upload_user` varchar(255) DEFAULT NULL,
PRIMARY KEY (`fileid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of diskfile
@@ -77,24 +93,24 @@ CREATE TABLE `diskfile` (
-- ----------------------------
DROP TABLE IF EXISTS `diskgroup`;
CREATE TABLE `diskgroup` (
`groupId` varchar(50) NOT NULL,
`groupName` varchar(50) DEFAULT NULL,
`fatherGroupId` varchar(50) DEFAULT NULL COMMENT '上级父亲组ID',
`groupCnName` varchar(100) DEFAULT NULL,
`groupFlag` char(1) DEFAULT NULL,
`groupCreator` varchar(50) DEFAULT NULL,
`groupType` varchar(10) DEFAULT NULL COMMENT '组类型MUC、文档库、图片、私有组',
`administrator` varchar(50) DEFAULT NULL,
`createDate` datetime DEFAULT NULL,
`maxNum` int(11) DEFAULT NULL,
`extra1` varchar(100) DEFAULT NULL,
`extra2` varchar(100) DEFAULT NULL,
`extra3` varchar(100) DEFAULT NULL,
`extra4` varchar(100) DEFAULT NULL,
`extra5` varchar(100) DEFAULT '',
`isPublic` char(255) DEFAULT 'y' COMMENT '是否是公开组',
PRIMARY KEY (`groupId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`group_id` varchar(50) NOT NULL,
`administrator` varchar(255) DEFAULT NULL,
`create_date` datetime DEFAULT NULL,
`extra1` varchar(255) DEFAULT NULL,
`extra2` varchar(255) DEFAULT NULL,
`extra3` varchar(255) DEFAULT NULL,
`extra4` varchar(255) DEFAULT NULL,
`extra5` varchar(255) DEFAULT NULL,
`father_group_id` varchar(255) DEFAULT NULL,
`group_cn_name` varchar(255) DEFAULT NULL,
`group_creator` varchar(255) DEFAULT NULL,
`group_flag` varchar(255) DEFAULT NULL,
`group_name` varchar(255) DEFAULT NULL,
`group_type` varchar(255) DEFAULT NULL,
`is_public` varchar(255) DEFAULT NULL,
`max_num` int(11) NOT NULL,
PRIMARY KEY (`group_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of diskgroup
@@ -105,62 +121,80 @@ CREATE TABLE `diskgroup` (
-- ----------------------------
DROP TABLE IF EXISTS `diskuser`;
CREATE TABLE `diskuser` (
`userName` varchar(50) NOT NULL,
`userCnName` varchar(50) DEFAULT NULL,
`userFlag` char(1) DEFAULT NULL COMMENT '可用1已删除0',
`password` varchar(64) DEFAULT NULL,
`appId` int(11) DEFAULT NULL COMMENT 'app应用ID',
`isAdmin` char(1) DEFAULT NULL COMMENT '是否超级管理员',
`phone` varchar(20) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`firstDate` datetime DEFAULT NULL,
`lastDate` datetime DEFAULT NULL,
`maxSpace` bigint(20) DEFAULT NULL,
`usedSpace` bigint(20) DEFAULT '0',
`extra1` varchar(100) DEFAULT NULL,
`extra2` varchar(100) DEFAULT NULL,
`extra3` varchar(100) DEFAULT NULL,
`extra4` varchar(100) DEFAULT NULL,
`extra5` varchar(100) DEFAULT NULL,
PRIMARY KEY (`userName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`user_name` varchar(255) NOT NULL,
`app_id` int(11) NOT NULL,
`email` varchar(255) DEFAULT NULL,
`extra1` varchar(255) DEFAULT NULL,
`extra2` varchar(255) DEFAULT NULL,
`extra3` varchar(255) DEFAULT NULL,
`extra4` varchar(255) DEFAULT NULL,
`extra5` varchar(255) DEFAULT NULL,
`first_date` datetime DEFAULT NULL,
`is_admin` varchar(255) DEFAULT NULL,
`last_date` datetime DEFAULT NULL,
`max_space` decimal(19,2) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
`used_space` decimal(19,2) DEFAULT NULL,
`user_cn_name` varchar(255) DEFAULT NULL,
`user_flag` varchar(255) DEFAULT NULL,
PRIMARY KEY (`user_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of diskuser
-- ----------------------------
INSERT INTO `diskuser` VALUES ('admin', '系统管理员', '1', 'admin', null, 'y', null, null, null, null, null, '0', null, null, null, null, null);
-- ----------------------------
-- Table structure for `groupuser`
-- ----------------------------
DROP TABLE IF EXISTS `groupuser`;
CREATE TABLE `groupuser` (
`groupId` varchar(50) DEFAULT NULL,
`userName` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` varchar(255) DEFAULT NULL,
`user_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of groupuser
-- ----------------------------
-- ----------------------------
-- Table structure for `hibernate_sequence`
-- ----------------------------
DROP TABLE IF EXISTS `hibernate_sequence`;
CREATE TABLE `hibernate_sequence` (
`next_val` bigint(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of hibernate_sequence
-- ----------------------------
INSERT INTO `hibernate_sequence` VALUES ('1');
INSERT INTO `hibernate_sequence` VALUES ('1');
INSERT INTO `hibernate_sequence` VALUES ('1');
INSERT INTO `hibernate_sequence` VALUES ('1');
INSERT INTO `hibernate_sequence` VALUES ('1');
-- ----------------------------
-- Table structure for `history`
-- ----------------------------
DROP TABLE IF EXISTS `history`;
CREATE TABLE `history` (
`id` int(11) NOT NULL,
`userName` varchar(50) NOT NULL,
`fileName` varchar(100) DEFAULT NULL,
`operation` varchar(50) NOT NULL,
`groupName` varchar(100) DEFAULT NULL,
`id` bigint(20) NOT NULL,
`extra1` varchar(255) DEFAULT NULL,
`extra2` varchar(255) DEFAULT NULL,
`extra3` varchar(255) DEFAULT NULL,
`extra4` varchar(255) DEFAULT NULL,
`extra5` varchar(255) DEFAULT NULL,
`file_name` varchar(255) DEFAULT NULL,
`group_name` varchar(255) DEFAULT NULL,
`operation` varchar(255) DEFAULT NULL,
`time` datetime DEFAULT NULL,
`extra1` varchar(100) DEFAULT NULL,
`extra2` varchar(100) DEFAULT NULL,
`extra3` varchar(100) DEFAULT NULL,
`extra4` varchar(100) DEFAULT NULL,
`extra5` varchar(100) DEFAULT NULL,
`user_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of history

View File

@@ -1,13 +1,9 @@
# xyFS私有OSS文件存储服务
#### 项目介绍
一站式企业私有文件服务。
一站式企业私有文件服务。针对软件开发时提供的文件存储系统,对文件上传、下载、分类、分组、审计、统计等操作进行业务剥离,支持企业内多项目提供统一的oss私有文件服务。
<br>
针对软件开发时提供的文件存储系统,对文件上传、下载、分类、分组、审计、统计等操作进行业务剥离,支持企业内多项目提供统一的oss私有文件服务
<br>
涵盖了保护企业隐私文件的私有存储,也可接入公有云存储方案。
<br>
开发初衷是应用于xyTalk企业IM即时通讯的离线文件存储、群文件、图片、短语音、短视频、企业文档库等应用。
涵盖了保护企业隐私文件的私有存储也可接入公有云存储方案。开发初衷是应用于xyTalk企业IM即时通讯的离线文件存储、群文件、图片、短语音、短视频、企业文档库等应用
<br>
xyTalk地址https://gitee.com/475660/xyTalk-pc
<br>
@@ -24,6 +20,10 @@ xyFS不仅仅是独立可用的文件系统还通过接口灵活集成以下
- 9.公有云存储:七牛云
- 10.公有云存储:腾讯文件云存储 CFS
#### 项目详细文档
http://xyfs.mydoc.io/
#### 软件组成
@@ -35,12 +35,15 @@ xyFS不仅仅是独立可用的文件系统还通过接口灵活集成以下
#### 采用技术
- 1.Spring Boot、MVC、JPA、Ehcache
- 2.HTML + Layer + Bootstrap
- 3.Tomcat
- 4.MySQL
- 5.Gradle
- 6.Nginx
- 1.Spring Boot、MVC、AOP
- 2.Dbcp2/Druid
- 3.JPA/Hibernate
- 4.Ehcache
- 5.HTML、Layer、Bootstrap
- 6.Tomcat
- 7.MySQL
- 8.Gradle
- 9.Nginx
#### 安装教程

1
bin/main/.gitignore vendored
View File

@@ -1 +1,2 @@
/xy/
/templates/

View File

@@ -1,6 +1,51 @@
server.port=8090
server.port=9091
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/boot
storage.location = uploadfiledir
# \u7b2c\u4e00\u6b21\u4f7f\u7528\u7684\u914d\u7f6e\uff1a\u81ea\u52a8\u521b\u5efa\u6570\u636e\u5e93\u8868\uff0c\u5982\u679c\u662f\u8fd0\u884cSQL\u811a\u672c\u5219\u65e0\u9700\u4f7f\u7528\u6b64\u914d\u7f6e #
# spring.jpa.hibernate.ddl-auto = create
# \u7b2c\u4e8c\u6b21\u5f00\u59cb\u4f7f\u7528\u7684\u914d\u7f6e\uff1a\u636e\u5e93\u8868\u4f1a\u6839\u636eEntity\u7684\u53d8\u52a8\u800c\u66f4\u65b0 #
spring.jpa.hibernate.ddl-auto = update
spring.datasource.url=jdbc:mysql://localhost:3306/xyfs
spring.datasource.username=root
spring.datasource.password=mysql
spring.datasource.password=mysql
# dbcp2\u8fde\u63a5\u6c60\u914d\u7f6e #
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
spring.datasource.dbcp2.max-wait-millis=10000
spring.datasource.dbcp2.min-idle=5
spring.datasource.dbcp2.initial-size=5
spring.datasource.dbcp2.validation-query=SELECT 1 FROM App
spring.datasource.dbcp2.connection-properties=characterEncoding=utf8
# druid\u8fde\u63a5\u6c60\u7684\u914d\u7f6e\u4fe1\u606f #
#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#spring.datasource.initialSize=5
#spring.datasource.minIdle=5
#spring.datasource.maxActive=20
#spring.datasource.maxWait=60000
#spring.datasource.timeBetweenEvictionRunsMillis=60000
#spring.datasource.minEvictableIdleTimeMillis=300000
#spring.datasource.validationQuery=SELECT 1 FROM App
#spring.datasource.testWhileIdle=true
#spring.datasource.testOnBorrow=false
#spring.datasource.testOnReturn=false
#spring.datasource.poolPreparedStatements=true
#spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
#spring.datasource.filters=stat,wall,log4j
# spring jackson \u65f6\u95f4\u914d\u7f6e #
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.joda-date-time-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
# multipart \u4e0a\u4f20\u914d\u7f6e #
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=1024MB
spring.servlet.multipart.max-request-size=1024MB
# oss \u65e5\u5fd7\u914d\u7f6e #
logging.config=classpath:logback.xml

38
bin/main/logback.xml Normal file
View File

@@ -0,0 +1,38 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %p (%file:%line\)- %m%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="syslog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>logs/xyfs.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/oss.%d.%i.log</fileNamePattern>
<!-- 每产生一个日志文件该日志文件的保存期限为31天 -->
<maxHistory>31</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d %p (%file:%line\)- %m%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
</appender>
<!-- 控制台输出日志级别 -->
<root level="info">
<appender-ref ref="STDOUT" />
</root>
<!-- 级别依次为【从高到低】FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
<logger name="xy.FileSystem" level="DEBUG">
<appender-ref ref="syslog" />
</logger>
<logger name="org.springframework.web" level="INFO">
<appender-ref ref="syslog" />
</logger>
<logger name="org.springframework.boot" level="INFO">
<appender-ref ref="syslog" />
</logger>
</configuration>

View File

@@ -32,6 +32,9 @@ dependencies {
compile("org.springframework.boot:spring-boot-devtools")
compile 'mysql:mysql-connector-java'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.4.0'
compile group: 'com.alibaba', name: 'druid', version: '1.1.10'
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile('com.jayway.jsonpath:json-path')

View File

@@ -0,0 +1,52 @@
package xy.FileSystem.Controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import xy.FileSystem.Entity.App;
import xy.FileSystem.Entity.AppRepository;
@Controller
@RequestMapping(path="/apps")
public class AppController {
@Autowired
private AppRepository appRepository;
@GetMapping(path="/add")
public @ResponseBody String addNewUser (@RequestParam String name
, @RequestParam String code, @RequestParam String appkey) {
add(name, code, appkey);
return "ok";
}
public void add(String name, String code, String appkey) {
App model = new App();
model.setName(name);
model.setAvailable("1");
model.setCode(code);
model.setAppkey(appkey);
appRepository.save(model);
}
@GetMapping(path="/findall")
public @ResponseBody Iterable<App> findall() {
return appRepository.findAll();
}
@GetMapping(path="/findbycode")
public @ResponseBody Iterable<App> getcode(@RequestParam String code) {
List<App> apps = appRepository.findbyCode(code);
return apps;
}
}

View File

@@ -0,0 +1,73 @@
package xy.FileSystem.Controller;
import java.io.IOException;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import xy.FileSystem.Exception.StorageFileNotFoundException;
import xy.FileSystem.Service.StorageService;
@Controller
public class FileUploadController {
private final StorageService storageService;
@Autowired
public FileUploadController(StorageService storageService) {
this.storageService = storageService;
}
@GetMapping("/")
public String listUploadedFiles(Model model) throws IOException {
model.addAttribute("files", storageService.loadAll().map(
path -> MvcUriComponentsBuilder.fromMethodName(FileUploadController.class,
"serveFile", path.getFileName().toString()).build().toString())
.collect(Collectors.toList()));
return "uploadForm";
}
@GetMapping("/files/{filename:.+}")
@ResponseBody
public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
Resource file = storageService.loadAsResource(filename);
return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"" + file.getFilename() + "\"").body(file);
}
@PostMapping("/")
public String handleFileUpload(@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
storageService.store(file);
redirectAttributes.addFlashAttribute("message",
"You successfully uploaded " + file.getOriginalFilename() + "!");
return "redirect:/";
}
@ExceptionHandler(StorageFileNotFoundException.class)
public ResponseEntity<?> handleStorageFileNotFound(StorageFileNotFoundException exc) {
return ResponseEntity.notFound().build();
}
}

View File

@@ -4,24 +4,31 @@ import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the app database table.
*
*/
@Entity
@Table(name="app")
@NamedQueries({
@NamedQuery(name="App.findAll", query="SELECT a FROM App a"),
@NamedQuery(name="App.findbyCode",query="SELECT a FROM App a WHERE a.code = :code")
})
public class App implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String appkey;
private String available;
private String code;
private String key;
private String name;
public App() {
@@ -35,6 +42,14 @@ public class App implements Serializable {
this.id = id;
}
public String getAppkey() {
return this.appkey;
}
public void setAppkey(String appkey) {
this.appkey = appkey;
}
public String getAvailable() {
return this.available;
}
@@ -51,14 +66,6 @@ public class App implements Serializable {
this.code = code;
}
public String getKey() {
return this.key;
}
public void setKey(String key) {
this.key = key;
}
public String getName() {
return this.name;
}

View File

@@ -0,0 +1,11 @@
package xy.FileSystem.Entity;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
public interface AppRepository extends CrudRepository<App, Integer> {
public List<App> findbyCode(String code);
}

View File

@@ -13,8 +13,8 @@ public class Dailyreport implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String curdate;
@@ -27,11 +27,11 @@ public class Dailyreport implements Serializable {
public Dailyreport() {
}
public int getId() {
public Long getId() {
return this.id;
}
public void setId(int id) {
public void setId(Long id) {
this.id = id;
}

View File

@@ -0,0 +1,7 @@
package xy.FileSystem.Entity;
import org.springframework.data.repository.CrudRepository;
public interface DailyreportRepository extends CrudRepository<Dailyreport, Long> {
}

View File

@@ -15,7 +15,7 @@ public class Diskfile implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
//@GeneratedValue(strategy=GenerationType.AUTO)
private String fileid;
private int appid;

View File

@@ -0,0 +1,7 @@
package xy.FileSystem.Entity;
import org.springframework.data.repository.CrudRepository;
public interface DiskfileRepository extends CrudRepository<Diskfile, String> {
}

View File

@@ -14,7 +14,7 @@ public class Diskgroup implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
//@GeneratedValue(strategy=GenerationType.AUTO)
private String groupId;
private String administrator;

View File

@@ -0,0 +1,7 @@
package xy.FileSystem.Entity;
import org.springframework.data.repository.CrudRepository;
public interface DiskgroupRepository extends CrudRepository<Diskgroup, String> {
}

View File

@@ -15,7 +15,7 @@ public class Diskuser implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
//@GeneratedValue(strategy=GenerationType.AUTO)
private String userName;
private int appId;

View File

@@ -0,0 +1,7 @@
package xy.FileSystem.Entity;
import org.springframework.data.repository.CrudRepository;
public interface DiskuserRepository extends CrudRepository<Diskuser, String> {
}

View File

@@ -11,7 +11,11 @@ import javax.persistence.*;
@Entity
public class Groupuser implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String groupId;
private String userName;
@@ -19,6 +23,14 @@ public class Groupuser implements Serializable {
public Groupuser() {
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getGroupId() {
return this.groupId;
}

View File

@@ -0,0 +1,7 @@
package xy.FileSystem.Entity;
import org.springframework.data.repository.CrudRepository;
public interface GroupuserRepository extends CrudRepository<Groupuser, Long> {
}

View File

@@ -14,8 +14,8 @@ public class History implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String fileName;
@@ -41,11 +41,11 @@ public class History implements Serializable {
public History() {
}
public int getId() {
public Long getId() {
return this.id;
}
public void setId(int id) {
public void setId(Long id) {
this.id = id;
}

View File

@@ -0,0 +1,7 @@
package xy.FileSystem.Entity;
import org.springframework.data.repository.CrudRepository;
public interface HistoryRepository extends CrudRepository<History, Long> {
}

View File

@@ -0,0 +1,12 @@
package xy.FileSystem.Exception;
public class StorageException extends RuntimeException {
public StorageException(String message) {
super(message);
}
public StorageException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,12 @@
package xy.FileSystem.Exception;
public class StorageFileNotFoundException extends StorageException {
public StorageFileNotFoundException(String message) {
super(message);
}
public StorageFileNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -1,12 +1,27 @@
package xy.FileSystem;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import xy.FileSystem.Propert.StorageProperties;
import xy.FileSystem.Service.StorageService;
@SpringBootApplication
@EnableConfigurationProperties(StorageProperties.class)
public class FileSystemApplication {
public static void main(String[] args) {
SpringApplication.run(FileSystemApplication.class, args);
}
@Bean
CommandLineRunner init(StorageService storageService) {
return (args) -> {
storageService.deleteAll();
storageService.init();
};
}
}

View File

@@ -0,0 +1,28 @@
package xy.FileSystem.Propert;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("storage")
public class StorageProperties {
private String location = "uploadfiles";
private String source = "xyfs";
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
}

View File

@@ -0,0 +1,12 @@
package xy.FileSystem.Service;
import org.springframework.stereotype.Service;
@Service
public class AppService {
public static AppService context;
}

View File

@@ -0,0 +1,5 @@
package xy.FileSystem.Service;
public class DailyreportService {
}

View File

@@ -0,0 +1,108 @@
package xy.FileSystem.Service;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import xy.FileSystem.Exception.StorageException;
import xy.FileSystem.Exception.StorageFileNotFoundException;
import xy.FileSystem.Propert.StorageProperties;
@Service
public class FileSystemStorageService implements StorageService {
private final Path rootLocation;
@Autowired
public FileSystemStorageService(StorageProperties properties) {
this.rootLocation = Paths.get(properties.getLocation());
}
@Override
public void store(MultipartFile file) {
String filename = StringUtils.cleanPath(file.getOriginalFilename());
try {
if (file.isEmpty()) {
throw new StorageException("Failed to store empty file " + filename);
}
if (filename.contains("..")) {
// This is a security check
throw new StorageException(
"Cannot store file with relative path outside current directory "
+ filename);
}
try (InputStream inputStream = file.getInputStream()) {
Files.copy(inputStream, this.rootLocation.resolve(filename),
StandardCopyOption.REPLACE_EXISTING);
}
}
catch (IOException e) {
throw new StorageException("Failed to store file " + filename, e);
}
}
@Override
public Stream<Path> loadAll() {
try {
return Files.walk(this.rootLocation, 1)
.filter(path -> !path.equals(this.rootLocation))
.map(this.rootLocation::relativize);
}
catch (IOException e) {
throw new StorageException("Failed to read stored files", e);
}
}
@Override
public Path load(String filename) {
return rootLocation.resolve(filename);
}
@Override
public Resource loadAsResource(String filename) {
try {
Path file = load(filename);
Resource resource = new UrlResource(file.toUri());
if (resource.exists() || resource.isReadable()) {
return resource;
}
else {
throw new StorageFileNotFoundException(
"Could not read file: " + filename);
}
}
catch (MalformedURLException e) {
throw new StorageFileNotFoundException("Could not read file: " + filename, e);
}
}
@Override
public void deleteAll() {
FileSystemUtils.deleteRecursively(rootLocation.toFile());
}
@Override
public void init() {
try {
Files.createDirectories(rootLocation);
}
catch (IOException e) {
throw new StorageException("Could not initialize storage", e);
}
}
}

View File

@@ -0,0 +1,23 @@
package xy.FileSystem.Service;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;
import java.nio.file.Path;
import java.util.stream.Stream;
public interface StorageService {
void init();
void store(MultipartFile file);
Stream<Path> loadAll();
Path load(String filename);
Resource loadAsResource(String filename);
void deleteAll();
}

View File

@@ -1,6 +1,55 @@
server.port=8090
# tomcat\u670d\u52a1\u7aef\u53e3 #
server.port=9091
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/boot
# \u5b58\u50a8\u6e90\uff0c\u7c7b\u578b\u6709\uff1axyfs\\Seafile\\FastDFS\\MongoDB\\BFS\\PaxosStore\\aliOSS\\qiniu\\CFS #
storage.source = xyfs
# \u5b58\u50a8\u7684\u76f8\u5bf9\u8def\u5f84\uff0c\u5982\u679c storage.source = xyfs \u9700\u8981\u914d\u7f6e #
storage.location = uploadfiledir
# \u7b2c\u4e00\u6b21\u4f7f\u7528\u7684\u914d\u7f6e\uff1a\u81ea\u52a8\u521b\u5efa\u6570\u636e\u5e93\u8868\uff0c\u5982\u679c\u662f\u8fd0\u884cSQL\u811a\u672c\u5219\u65e0\u9700\u4f7f\u7528\u6b64\u914d\u7f6e #
# spring.jpa.hibernate.ddl-auto = create
# \u7b2c\u4e8c\u6b21\u5f00\u59cb\u4f7f\u7528\u7684\u914d\u7f6e\uff1a\u636e\u5e93\u8868\u4f1a\u6839\u636eEntity\u7684\u53d8\u52a8\u800c\u66f4\u65b0 #
spring.jpa.hibernate.ddl-auto = update
spring.datasource.url=jdbc:mysql://localhost:3306/xyfs
spring.datasource.username=root
spring.datasource.password=mysql
spring.datasource.password=mysql
# dbcp2\u8fde\u63a5\u6c60\u914d\u7f6e #
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
spring.datasource.dbcp2.max-wait-millis=10000
spring.datasource.dbcp2.min-idle=5
spring.datasource.dbcp2.initial-size=5
spring.datasource.dbcp2.validation-query=SELECT 1 FROM App
spring.datasource.dbcp2.connection-properties=characterEncoding=utf8
# druid\u8fde\u63a5\u6c60\u7684\u914d\u7f6e\u4fe1\u606f #
#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#spring.datasource.initialSize=5
#spring.datasource.minIdle=5
#spring.datasource.maxActive=20
#spring.datasource.maxWait=60000
#spring.datasource.timeBetweenEvictionRunsMillis=60000
#spring.datasource.minEvictableIdleTimeMillis=300000
#spring.datasource.validationQuery=SELECT 1 FROM App
#spring.datasource.testWhileIdle=true
#spring.datasource.testOnBorrow=false
#spring.datasource.testOnReturn=false
#spring.datasource.poolPreparedStatements=true
#spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
#spring.datasource.filters=stat,wall,log4j
# spring jackson \u65f6\u95f4\u914d\u7f6e #
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.joda-date-time-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
# multipart \u4e0a\u4f20\u914d\u7f6e #
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=1024MB
spring.servlet.multipart.max-request-size=1024MB
# oss \u65e5\u5fd7\u914d\u7f6e #
logging.config=classpath:logback.xml

View File

@@ -0,0 +1,38 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %p (%file:%line\)- %m%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="syslog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>logs/xyfs.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/oss.%d.%i.log</fileNamePattern>
<!-- 每产生一个日志文件该日志文件的保存期限为31天 -->
<maxHistory>31</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d %p (%file:%line\)- %m%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
</appender>
<!-- 控制台输出日志级别 -->
<root level="info">
<appender-ref ref="STDOUT" />
</root>
<!-- 级别依次为【从高到低】FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
<logger name="xy.FileSystem" level="DEBUG">
<appender-ref ref="syslog" />
</logger>
<logger name="org.springframework.web" level="INFO">
<appender-ref ref="syslog" />
</logger>
<logger name="org.springframework.boot" level="INFO">
<appender-ref ref="syslog" />
</logger>
</configuration>

View File

@@ -0,0 +1,26 @@
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div th:if="${message}">
<h2 th:text="${message}"/>
</div>
<div>
<form method="POST" enctype="multipart/form-data" action="/">
<table>
<tr><td>File to upload:</td><td><input type="file" name="file" /></td></tr>
<tr><td></td><td><input type="submit" value="Upload" /></td></tr>
</table>
</form>
</div>
<div>
<ul>
<li th:each="file : ${files}">
<a th:href="${file}" th:text="${file}" />
</li>
</ul>
</div>
</body>
</html>