├── .gitee ├── ISSUE_TEMPLATE.zh-CN.md └── PULL_REQUEST_TEMPLATE.zh-CN.md ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── LICENSE ├── META-INF └── MANIFEST.MF ├── README.md ├── efo.iml ├── mvnw ├── mvnw.cmd ├── mysql ├── efo.mwb ├── efo.mwb.bak └── efo.sql ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── zhazhapan │ │ └── efo │ │ ├── EfoApplication.java │ │ ├── annotation │ │ └── AuthInterceptor.java │ │ ├── config │ │ ├── SettingConfig.java │ │ ├── TokenConfig.java │ │ └── WebMvcConfig.java │ │ ├── dao │ │ ├── AuthDAO.java │ │ ├── CategoryDAO.java │ │ ├── DownloadedDAO.java │ │ ├── FileDAO.java │ │ ├── UploadedDAO.java │ │ ├── UserDAO.java │ │ └── sqlprovider │ │ │ ├── AuthSqlProvider.java │ │ │ ├── CommonSqlProvider.java │ │ │ ├── DownloadedSqlProvider.java │ │ │ ├── FileSqlProvider.java │ │ │ ├── UploadedSqlProvider.java │ │ │ └── UserSqlProvider.java │ │ ├── entity │ │ ├── Auth.java │ │ ├── Category.java │ │ ├── Download.java │ │ ├── File.java │ │ └── User.java │ │ ├── enums │ │ └── InterceptorLevel.java │ │ ├── exception │ │ └── GlobalExceptionHandler.java │ │ ├── interceptor │ │ └── WebInterceptor.java │ │ ├── model │ │ ├── AuthRecord.java │ │ ├── BaseAuthRecord.java │ │ ├── DownloadRecord.java │ │ ├── FileBasicRecord.java │ │ ├── FileRecord.java │ │ └── UploadedRecord.java │ │ ├── modules │ │ └── constant │ │ │ ├── ConfigConsts.java │ │ │ └── DefaultValues.java │ │ ├── service │ │ ├── IAuthService.java │ │ ├── ICategoryService.java │ │ ├── ICommonService.java │ │ ├── IConfigService.java │ │ ├── IDownloadedService.java │ │ ├── IFileManagerService.java │ │ ├── IFileService.java │ │ ├── IUploadedService.java │ │ ├── IUserService.java │ │ └── impl │ │ │ ├── AuthServiceImpl.java │ │ │ ├── CategoryServiceImpl.java │ │ │ ├── CommonServiceImpl.java │ │ │ ├── ConfigServiceImpl.java │ │ │ ├── DownloadedServiceImpl.java │ │ │ ├── FileManagerServiceImpl.java │ │ │ ├── FileServiceImpl.java │ │ │ ├── UploadedServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ ├── util │ │ ├── BeanUtils.java │ │ ├── CommonUtils.java │ │ ├── ControllerUtils.java │ │ └── ServiceUtils.java │ │ └── web │ │ └── controller │ │ ├── AuthController.java │ │ ├── CategoryController.java │ │ ├── CommonController.java │ │ ├── ConfigController.java │ │ ├── CustomErrorController.java │ │ ├── DownloadedController.java │ │ ├── FileController.java │ │ ├── FileMangerController.java │ │ ├── UploadedController.java │ │ ├── UserController.java │ │ └── ViewController.java └── resources │ ├── application-prod.properties │ ├── application.properties │ ├── assets │ ├── css │ │ ├── angular-filemanager.min.css │ │ ├── bootstrap.min.css │ │ ├── fileinput.min.css │ │ ├── fontawesome-all.css │ │ ├── glyphicons.css │ │ ├── nav.css │ │ ├── old │ │ │ └── bootstrap.min.css │ │ ├── pretty-checkbox.min.css │ │ └── style.css │ ├── fonts │ │ ├── fa-brands-400.eot │ │ ├── fa-brands-400.svg │ │ ├── fa-brands-400.ttf │ │ ├── fa-brands-400.woff │ │ ├── fa-brands-400.woff2 │ │ ├── fa-regular-400.eot │ │ ├── fa-regular-400.svg │ │ ├── fa-regular-400.ttf │ │ ├── fa-regular-400.woff │ │ ├── fa-regular-400.woff2 │ │ ├── fa-solid-900.eot │ │ ├── fa-solid-900.svg │ │ ├── fa-solid-900.ttf │ │ ├── fa-solid-900.woff │ │ ├── fa-solid-900.woff2 │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ ├── glyphicons-halflings-regular.woff2 │ │ ├── glyphicons-regular.eot │ │ ├── glyphicons-regular.svg │ │ ├── glyphicons-regular.ttf │ │ ├── glyphicons-regular.woff │ │ ├── iconfont.css │ │ ├── iconfont.eot │ │ ├── iconfont.js │ │ ├── iconfont.svg │ │ ├── iconfont.ttf │ │ └── iconfont.woff │ ├── img │ │ ├── default-user.jpg │ │ ├── efo-favicon.png │ │ ├── loading-sm.gif │ │ ├── loading.gif │ │ └── mini.png │ └── js │ │ ├── admin.js │ │ ├── angular-filemanager.min.js │ │ ├── angular-translate.min.js │ │ ├── angular.min.js │ │ ├── bootstrap.min.js │ │ ├── default.js │ │ ├── fileinput.min.js │ │ ├── index.js │ │ ├── jquery-3.3.1.js │ │ ├── layer.js │ │ ├── mobile │ │ ├── layer.js │ │ └── need │ │ │ └── layer.css │ │ ├── nav.js │ │ ├── ng-file-upload.min.js │ │ ├── old │ │ ├── bootstrap.min.js │ │ └── jquery.min.js │ │ ├── particles.js │ │ ├── particles.json │ │ ├── piexif.min.js │ │ ├── popper.min.js │ │ ├── purify.min.js │ │ ├── signin.js │ │ ├── sortable.min.js │ │ ├── theme.js │ │ ├── theme │ │ └── default │ │ │ ├── icon-ext.png │ │ │ ├── icon.png │ │ │ ├── layer.css │ │ │ ├── loading-0.gif │ │ │ ├── loading-1.gif │ │ │ └── loading-2.gif │ │ ├── upload.js │ │ ├── utils.js │ │ └── vue.js │ ├── config.json │ ├── log4j.properties │ └── static │ ├── 404.html │ ├── admin.html │ ├── error.html │ ├── filemanager.html │ ├── index.html │ ├── signin.html │ └── upload.html └── test └── java └── com └── zhazhapan └── efo ├── EfoApplicationTest.java ├── common └── CommonTest.java ├── config └── SettingConfigTest.java ├── dao ├── AuthDAOTest.java ├── CategoryDAOTest.java ├── DownloadedDAOTest.java ├── FileDAOTest.java ├── UserDAOTest.java └── sqlprovider │ └── FileSqlProviderTest.java └── service └── CategoryServiceTest.java /.gitee/ISSUE_TEMPLATE.zh-CN.md: -------------------------------------------------------------------------------- 1 | ### 该问题是怎么引起的? 2 | 3 | 4 | 5 | ### 重现步骤 6 | 7 | 8 | 9 | ### 报错信息 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md: -------------------------------------------------------------------------------- 1 | ### 该Pull Request关联的Issue 2 | 3 | 4 | ### 修改描述 5 | 6 | 7 | 8 | ### 测试用例 9 | 10 | 11 | 12 | ### 修复效果的截屏 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | target/ 25 | pom.xml.tag 26 | pom.xml.releaseBackup 27 | pom.xml.versionsBackup 28 | pom.xml.next 29 | release.properties 30 | dependency-reduced-pom.xml 31 | buildNumber.properties 32 | .mvn/timing.properties 33 | 34 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 35 | !/.mvn/wrapper/maven-wrapper.jar 36 | 37 | ### IntelliJ IDEA ### 38 | .idea 39 | *.iws 40 | *.ipr 41 | 42 | .DS_Store 43 | !.mvn/wrapper/maven-wrapper.jar 44 | 45 | ### STS ### 46 | .apt_generated 47 | .classpath 48 | .factorypath 49 | .project 50 | .settings 51 | .springBeans 52 | 53 | ### NetBeans ### 54 | nbproject/private/ 55 | build/ 56 | nbbuild/ 57 | dist/ 58 | nbdist/ 59 | .nb-gradle/ 60 | /META-INF/ 61 | src/main/resources/templates/ 62 | /out/ 63 | /bin/ 64 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 zhazhapan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: com.zhazhapan.efo.EfoApplication 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 欢迎体验我们全新的桌面端效率工具 2 | 3 | **欢迎体验我们全新的桌面端效率工具[RunFlow](https://myrest.top/myflow)。** 4 | 5 | > [https://myrest.top/myflow](https://myrest.top/myflow) 6 | 7 | ### 关于项目 8 | 9 | - 项目名称 `efo` 是 `Easy File Online` 的缩写,字面意思就是让您轻松实现线上文件管理 10 | 11 | - 本系统具有文件分享的功能,权限控制和自定义配置都很强大(可能还不完善) 12 | 13 | - 系统后端框架有Spring Boot,Spring, SpringMVC,MyBatis; 前段框架有Bootstrap,Jquery, Layer, Vue。项目完全纯注解,零XML配置。 14 | 15 | > 第一次运行系统,请先运行 [SQL代码](/mysql/efo.sql) , 并登陆系统修改用户 `system` (默认密码 `123456`)的密码 16 | 17 | ### 环境要求 18 | 19 | - MySQL 5.7+ 20 | 21 | - JDK 1.8+ 22 | 23 | ### 系统部分截图(背景图片可通过配置设置) 24 | 25 | - 登录页面(包含登录、注册、密码重置),路径 `/signin` 26 | 27 | ![登录页面](http://towerpan.qiniu.segocat.com/git/efo/signin.png) 28 | 29 | - 资源首页,路径 `/index` 30 | 31 | ![登录页面](http://towerpan.qiniu.segocat.com/git/efo/index.png) 32 | 33 | - 上传页面,路径 `/upload` 34 | 35 | ![登录页面](http://towerpan.qiniu.segocat.com/git/efo/upload.png) 36 | 37 | - 管理员管理页面,路径 `/admin` 38 | 39 | ![登录页面](http://towerpan.qiniu.segocat.com/git/efo/admin.png) 40 | 41 | - 远程文件管理(管理服务器端所有文件,只有系统用户才能进入此页面),路径 `/filemanager` 42 | 43 | ![登录页面](http://towerpan.qiniu.segocat.com/git/efo/filemanager.png) 44 | 45 | > 此功能基于 [angular-filamanager](https://github.com/joni2back/angular-filemanager) 实现 46 | 47 | **项目有不足的地方欢迎提出来哦,大家一起交流学习,觉得不错的话,Star来一个呗** 48 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /mysql/efo.mwb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/mysql/efo.mwb -------------------------------------------------------------------------------- /mysql/efo.mwb.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/mysql/efo.mwb.bak -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/EfoApplication.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo; 2 | 3 | import com.spring4all.swagger.EnableSwagger2Doc; 4 | import com.zhazhapan.config.JsonParser; 5 | import com.zhazhapan.efo.config.TokenConfig; 6 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 7 | import com.zhazhapan.efo.modules.constant.DefaultValues; 8 | import com.zhazhapan.util.FileExecutor; 9 | import com.zhazhapan.util.MailSender; 10 | import com.zhazhapan.util.ReflectUtils; 11 | import org.mybatis.spring.annotation.MapperScan; 12 | import org.springframework.boot.SpringApplication; 13 | import org.springframework.boot.autoconfigure.SpringBootApplication; 14 | import org.springframework.transaction.annotation.EnableTransactionManagement; 15 | 16 | import java.io.IOException; 17 | import java.util.Hashtable; 18 | import java.util.List; 19 | 20 | /** 21 | * @author pantao 22 | */ 23 | @SpringBootApplication 24 | @EnableSwagger2Doc 25 | @MapperScan("com.zhazhapan.efo.dao") 26 | @EnableTransactionManagement 27 | public class EfoApplication { 28 | 29 | public static JsonParser settings = new JsonParser(); 30 | 31 | public static List> controllers; 32 | 33 | public static Hashtable tokens; 34 | 35 | public static void main(String[] args) throws IOException, ClassNotFoundException { 36 | settings.setJsonObject(FileExecutor.read(EfoApplication.class.getResourceAsStream(DefaultValues.SETTING_PATH))); 37 | MailSender.config(settings.getObjectUseEval(ConfigConsts.EMAIL_CONFIG_OF_SETTINGS)); 38 | controllers = ReflectUtils.getClasses(DefaultValues.CONTROLLER_PACKAGE); 39 | tokens = TokenConfig.loadToken(); 40 | SpringApplication.run(EfoApplication.class, args); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/annotation/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.annotation; 2 | 3 | import com.zhazhapan.efo.enums.InterceptorLevel; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * @author pantao 9 | * @since 2018/1/25 10 | */ 11 | @Documented 12 | @Target({ElementType.TYPE, ElementType.METHOD}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface AuthInterceptor { 15 | 16 | /** 17 | * 定义拦截级别,默认为用户级别拦截 18 | * 19 | * @return {@link InterceptorLevel} 20 | */ 21 | InterceptorLevel value() default InterceptorLevel.USER; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/config/SettingConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.config; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 5 | import com.zhazhapan.efo.util.CommonUtils; 6 | import com.zhazhapan.modules.constant.ValueConsts; 7 | import com.zhazhapan.util.Checker; 8 | import com.zhazhapan.util.FileExecutor; 9 | import com.zhazhapan.util.Formatter; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import java.util.Date; 14 | 15 | import static com.zhazhapan.efo.EfoApplication.settings; 16 | 17 | /** 18 | * @author pantao 19 | * @since 2018/1/26 20 | */ 21 | public class SettingConfig { 22 | 23 | private static final String WINDOWS = "windows"; 24 | 25 | private static final String MAC = "mac"; 26 | 27 | private static final String LINUX = "linux"; 28 | 29 | private static Logger logger = LoggerFactory.getLogger(SettingConfig.class); 30 | 31 | private static OsName currentOS; 32 | 33 | static { 34 | if (Checker.isWindows()) { 35 | currentOS = OsName.WINDOWS; 36 | } else if (Checker.isMacOS()) { 37 | currentOS = OsName.MAC; 38 | } else { 39 | currentOS = OsName.LINUX; 40 | } 41 | } 42 | 43 | public static int[] getAuth(String jsonPath) { 44 | int[] auth = new int[5]; 45 | for (int i = 0; i < ConfigConsts.AUTH_OF_SETTINGS.length; i++) { 46 | String key = jsonPath + ValueConsts.DOT_SIGN + ConfigConsts.AUTH_OF_SETTINGS[i]; 47 | auth[i] = settings.getBooleanUseEval(key) ? 1 : 0; 48 | } 49 | return auth; 50 | } 51 | 52 | public static String getUploadStoragePath() { 53 | String parent = getStoragePath(ConfigConsts.UPLOAD_PATH_OF_SETTING); 54 | String formatWay = EfoApplication.settings.getStringUseEval(ConfigConsts.UPLOAD_FORM_OF_SETTING); 55 | String childPath = ValueConsts.SEPARATOR + Formatter.datetimeToCustomString(new Date(), formatWay); 56 | String path = parent + childPath; 57 | if (!FileExecutor.createFolder(path)) { 58 | path = ConfigConsts.DEFAULT_UPLOAD_PATH + childPath; 59 | FileExecutor.createFolder(path); 60 | } 61 | logger.info("upload path: " + path); 62 | return path; 63 | } 64 | 65 | public static String getAvatarStoragePath() { 66 | String path = getStoragePath(ConfigConsts.UPLOAD_PATH_OF_SETTING) + ValueConsts.SEPARATOR + "avatar"; 67 | FileExecutor.createFolder(path); 68 | return path; 69 | } 70 | 71 | public static String getStoragePath(String path) { 72 | path += ValueConsts.DOT_SIGN; 73 | if (currentOS == OsName.WINDOWS) { 74 | path += WINDOWS; 75 | } else if (currentOS == OsName.MAC) { 76 | path += MAC; 77 | } else { 78 | path += LINUX; 79 | } 80 | return CommonUtils.checkPath(EfoApplication.settings.getStringUseEval(path)); 81 | } 82 | 83 | /** 84 | * 当前系统名称 85 | */ 86 | public enum OsName { 87 | /** 88 | * windows系统 89 | */ 90 | WINDOWS, 91 | 92 | /** 93 | * MacOS系统 94 | */ 95 | MAC, 96 | 97 | /** 98 | * Linux系统 99 | */ 100 | LINUX 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/config/TokenConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.config; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.zhazhapan.efo.EfoApplication; 7 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 8 | import com.zhazhapan.modules.constant.ValueConsts; 9 | import com.zhazhapan.util.Checker; 10 | import com.zhazhapan.util.FileExecutor; 11 | import com.zhazhapan.util.Formatter; 12 | import com.zhazhapan.util.RandomUtils; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import java.util.Hashtable; 17 | 18 | /** 19 | * @author pantao 20 | * @since 2018/1/26 21 | */ 22 | public class TokenConfig { 23 | 24 | private static Logger logger = LoggerFactory.getLogger(TokenConfig.class); 25 | 26 | public static String generateToken(String token, int userId) { 27 | if (Checker.isNotEmpty(token)) { 28 | EfoApplication.tokens.remove(token); 29 | } 30 | return generateToken(userId); 31 | } 32 | 33 | public static String generateToken(int userId) { 34 | String token = RandomUtils.getRandomStringOnlyLetter(ValueConsts.THIRTY_TWO_INT); 35 | EfoApplication.tokens.put(token, userId); 36 | saveToken(); 37 | return token; 38 | } 39 | 40 | public static void saveToken() { 41 | String tokens = Formatter.mapToJson(EfoApplication.tokens); 42 | try { 43 | FileExecutor.saveFile(SettingConfig.getStoragePath(ConfigConsts.TOKEN_OF_SETTINGS), tokens); 44 | } catch (Exception e) { 45 | logger.error("save token error: " + e.getMessage()); 46 | } 47 | } 48 | 49 | public static Hashtable loadToken() { 50 | Hashtable tokens = new Hashtable<>(ValueConsts.SIXTEEN_INT); 51 | try { 52 | String token = FileExecutor.readFile(SettingConfig.getStoragePath(ConfigConsts.TOKEN_OF_SETTINGS)); 53 | JSONArray array = JSON.parseArray(token); 54 | array.forEach(object -> { 55 | JSONObject jsonObject = (JSONObject) object; 56 | tokens.put(jsonObject.getString(ValueConsts.KEY_STRING), jsonObject.getInteger(ValueConsts 57 | .VALUE_STRING)); 58 | }); 59 | } catch (Exception e) { 60 | logger.error("load token error: " + e.getMessage()); 61 | } 62 | return tokens; 63 | } 64 | 65 | public static void removeTokenByValue(int userId) { 66 | if (userId > 0) { 67 | String removeKey = ""; 68 | for (String key : EfoApplication.tokens.keySet()) { 69 | if (EfoApplication.tokens.get(key) == userId) { 70 | removeKey = key; 71 | break; 72 | } 73 | } 74 | if (Checker.isNotEmpty(removeKey)) { 75 | EfoApplication.tokens.remove(removeKey); 76 | TokenConfig.saveToken(); 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.config; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.zhazhapan.efo.exception.GlobalExceptionHandler; 5 | import com.zhazhapan.efo.interceptor.WebInterceptor; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.web.servlet.HandlerExceptionResolver; 9 | import org.springframework.web.servlet.config.annotation.*; 10 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author pantao 16 | * @since 2018/1/22 17 | */ 18 | @Configuration 19 | public class WebMvcConfig implements WebMvcConfigurer { 20 | 21 | @Override 22 | public void configureViewResolvers(ViewResolverRegistry registry) { 23 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 24 | viewResolver.setPrefix("/"); 25 | viewResolver.setSuffix(".html"); 26 | registry.viewResolver(viewResolver); 27 | } 28 | 29 | @Override 30 | public void configureHandlerExceptionResolvers(List resolvers) { 31 | resolvers.add(globalExceptionHandler()); 32 | } 33 | 34 | @Override 35 | public void configurePathMatch(PathMatchConfigurer configurer) { 36 | configurer.setUseSuffixPatternMatch(false); 37 | } 38 | 39 | @Override 40 | public void addInterceptors(InterceptorRegistry registry) { 41 | registry.addInterceptor(webInterceptor()); 42 | } 43 | 44 | @Override 45 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 46 | registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets/"); 47 | } 48 | 49 | @Bean 50 | public WebInterceptor webInterceptor() { 51 | return new WebInterceptor(); 52 | } 53 | 54 | @Bean 55 | public GlobalExceptionHandler globalExceptionHandler() { 56 | return new GlobalExceptionHandler(); 57 | } 58 | 59 | @Bean 60 | public JSONObject jsonObject() { 61 | return new JSONObject(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/AuthDAO.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.dao.sqlprovider.AuthSqlProvider; 4 | import com.zhazhapan.efo.entity.Auth; 5 | import com.zhazhapan.efo.model.AuthRecord; 6 | import org.apache.ibatis.annotations.*; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author pantao 13 | * @since 2018/1/19 14 | */ 15 | @Repository 16 | public interface AuthDAO { 17 | 18 | /** 19 | * 检测某个权限是否存在 20 | * 21 | * @param userId 用户编号 22 | * @param fileId 文件编号 23 | * 24 | * @return {@link Auth} 25 | */ 26 | @Select("select * from auth where user_id=#{userId} and file_id=#{fileId}") 27 | Auth exists(@Param("userId") int userId, @Param("fileId") long fileId); 28 | 29 | /** 30 | * 批量删除权限记录 31 | * 32 | * @param ids 权限编号集 33 | * 34 | * @return 是否删除成功 35 | */ 36 | @DeleteProvider(type = AuthSqlProvider.class, method = "batchDelete") 37 | boolean batchDelete(@Param("ids") String ids); 38 | 39 | /** 40 | * 添加一条权限记录 41 | * 42 | * @param auth {@link Auth} 43 | * 44 | * @return 是否添加成功 45 | */ 46 | @Insert("insert into auth(user_id,file_id,is_downloadable,is_uploadable,is_deletable,is_updatable,is_visible) " + 47 | "values(#{userId},#{fileId},#{isDownloadable},#{isUploadable},#{isDeletable},#{isUpdatable},#{isVisible})") 48 | boolean insertAuth(Auth auth); 49 | 50 | /** 51 | * 删除一条权限记录 52 | * 53 | * @param id 编号 54 | */ 55 | @Delete("delete from auth where id=#{id}") 56 | void removeAuthById(int id); 57 | 58 | /** 59 | * 删除一条权限记录 60 | * 61 | * @param userId 编号 62 | */ 63 | @Delete("delete from auth where user_id=#{userId}") 64 | void removeAuthByUserId(int userId); 65 | 66 | /** 67 | * 删除一条权限记录 68 | * 69 | * @param fileId 编号 70 | * 71 | * @return 是否删除成功 72 | */ 73 | @Delete("delete from auth where file_id=#{fileId}") 74 | boolean removeAuthByFileId(long fileId); 75 | 76 | /** 77 | * 更新权限记录 78 | * 79 | * @param id 编号 80 | * @param isDownloadable 下载权限 81 | * @param isUploadable 上传权限 82 | * @param isVisible 可查权限 83 | * @param isDeletable 删除权限 84 | * @param isUpdatable 更新权限 85 | * 86 | * @return 是否更新成功 87 | */ 88 | @UpdateProvider(type = AuthSqlProvider.class, method = "updateAuthById") 89 | boolean updateAuthById(@Param("id") long id, @Param("isDownloadable") int isDownloadable, @Param("isUploadable") 90 | int isUploadable, @Param("isDeletable") int isDeletable, @Param("isUpdatable") int isUpdatable, @Param 91 | ("isVisible") int isVisible); 92 | 93 | /** 94 | * 获取权限记录 95 | * 96 | * @param id 编号,值小于等于0时不作为条件 97 | * @param userId 用户编号,值小于等于0时不作为条件 98 | * @param fileId 文件编号,值小于等于0时不作为条件 99 | * @param fileName 模糊搜索文件名(当参数不为空时) 100 | * @param offset 偏移 101 | * 102 | * @return {@link List} 103 | */ 104 | @SelectProvider(type = AuthSqlProvider.class, method = "getAuthBy") 105 | List listAuthBy(@Param("id") long id, @Param("userId") int userId, @Param("fileId") long fileId, 106 | @Param("fileName") String fileName, @Param("offset") int offset); 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/CategoryDAO.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.entity.Category; 4 | import org.apache.ibatis.annotations.*; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author pantao 11 | * @since 2018/1/18 12 | */ 13 | @Repository 14 | public interface CategoryDAO { 15 | 16 | /** 17 | * 通过分类名获取ID 18 | * 19 | * @param name 分类名 20 | * 21 | * @return {@link Integer} 22 | */ 23 | @Select("select id from category where name=#{name}") 24 | int getIdByName(String name); 25 | 26 | /** 27 | * 添加一个分类 28 | * 29 | * @param name 分类名 30 | * 31 | * @return 是否添加成功 32 | */ 33 | @Insert("insert into category(name) values(#{name})") 34 | boolean insertCategory(String name); 35 | 36 | /** 37 | * 通过编号删除一个分类 38 | * 39 | * @param id 编号 40 | * 41 | * @return 是否删除成功 42 | */ 43 | @Delete("delete from category where id=#{id}") 44 | boolean removeCategoryById(int id); 45 | 46 | /** 47 | * 通过名称删除一个分类 48 | * 49 | * @param name 分类名称 50 | * 51 | * @return 是否删除成功 52 | */ 53 | @Delete("delete from category where name=#{name}") 54 | boolean removeCategoryByName(String name); 55 | 56 | /** 57 | * 更新一个分类名 58 | * 59 | * @param name 分类名 60 | * @param id 分类ID 61 | * 62 | * @return 是否更新成功 63 | */ 64 | @Update("update category set name=#{name} where id=#{id}") 65 | boolean updateNameById(@Param("id") int id, @Param("name") String name); 66 | 67 | /** 68 | * 通过分类名更新分类名 69 | * 70 | * @param newName 新的分类名 71 | * @param oldName 旧的分类名 72 | */ 73 | @Update("update category set name=#{newName} where name=#{oldName}") 74 | void updateNameByName(String newName, String oldName); 75 | 76 | /** 77 | * 获取所有分类 78 | * 79 | * @return {@link List} 80 | */ 81 | @Select("select * from category") 82 | List listCategory(); 83 | 84 | /** 85 | * 通过编号获取一个分类 86 | * 87 | * @param id 编号 88 | * 89 | * @return {@link Category} 90 | */ 91 | @Select("select * from category where id=#{id}") 92 | Category getCategoryById(int id); 93 | 94 | /** 95 | * 通过名称获取一个分类 96 | * 97 | * @param name 名称 98 | * 99 | * @return {@link Category} 100 | */ 101 | @Select("select * from category where name=#{name}") 102 | Category getCategoryByName(String name); 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/DownloadedDAO.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.dao.sqlprovider.DownloadedSqlProvider; 4 | import com.zhazhapan.efo.model.DownloadRecord; 5 | import org.apache.ibatis.annotations.Delete; 6 | import org.apache.ibatis.annotations.Insert; 7 | import org.apache.ibatis.annotations.Param; 8 | import org.apache.ibatis.annotations.SelectProvider; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author pantao 15 | * @since 2018/1/18 16 | */ 17 | @Repository 18 | public interface DownloadedDAO { 19 | 20 | /** 21 | * 新增一条下载记录 22 | * 23 | * @param userId 用户编号 24 | * @param fileId 文件编号 25 | */ 26 | @Insert("insert into download(user_id,file_id) values(#{userId},#{fileId})") 27 | void insertDownload(@Param("userId") int userId, @Param("fileId") long fileId); 28 | 29 | /** 30 | * 查询下载记录 31 | * 32 | * @param userId 用户编号,不使用用户编号作为条件时设置值小于等于0即可 33 | * @param fileId 文件编号,不使用文件编号作为条件时设置值小于等于0即可 34 | * @param categoryId 分类编号,不用分类编号作为条件时设置值小于等于0即可 35 | * @param fileName 文件名,不使用文件名作为条件时设置值为空即可 36 | * @param offset 偏移 37 | * 38 | * @return 下载记录 39 | */ 40 | @SelectProvider(type = DownloadedSqlProvider.class, method = "getDownloadBy") 41 | List listDownloadedBy(@Param("userId") int userId, @Param("fileId") long fileId, @Param 42 | ("fileName") String fileName, @Param("categoryId") int categoryId, @Param("offset") int offset); 43 | 44 | /** 45 | * 删除文件 46 | * 47 | * @param fileId 文件编号 48 | * 49 | * @return 是否删除成功 50 | */ 51 | @Delete("delete from download where file_id=#{fileId}") 52 | boolean removeByFileId(long fileId); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/UploadedDAO.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.dao.sqlprovider.UploadedSqlProvider; 4 | import com.zhazhapan.efo.model.UploadedRecord; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.SelectProvider; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author pantao 13 | * @since 2018/2/28 14 | */ 15 | @Repository 16 | public interface UploadedDAO { 17 | 18 | /** 19 | * 查询上传记录 20 | * 21 | * @param userId 用户编号,不使用用户编号作为条件时设置值小于等于0即可 22 | * @param fileId 文件编号,不使用文件编号作为条件时设置值小于等于0即可 23 | * @param categoryId 分类编号,不用分类编号作为条件时设置值小于等于0即可 24 | * @param fileName 文件名,不使用文件名作为条件时设置值为空即可 25 | * @param offset 偏移 26 | * 27 | * @return 上传记录 28 | */ 29 | @SelectProvider(type = UploadedSqlProvider.class, method = "getDownloadBy") 30 | List listUploadedBy(@Param("userId") int userId, @Param("fileId") long fileId, @Param("fileName") 31 | String fileName, @Param("categoryId") int categoryId, @Param("offset") int offset); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/UserDAO.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.dao.sqlprovider.UserSqlProvider; 4 | import com.zhazhapan.efo.entity.User; 5 | import org.apache.ibatis.annotations.*; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author pantao 12 | * @since 2018/1/12 13 | */ 14 | @Repository 15 | public interface UserDAO { 16 | 17 | /** 18 | * 更新用户权限 19 | * 20 | * @param id 用户编号 21 | * @param permission 权限 22 | * 23 | * @return 是否更新成功 24 | */ 25 | @Update("update user set permission=#{permission} where id=#{id}") 26 | boolean updatePermission(@Param("id") int id, @Param("permission") int permission); 27 | 28 | /** 29 | * 用过用户名获取用户Id 30 | * 31 | * @param usernameOrEmail 用户名或邮箱 32 | * 33 | * @return 用户编号 34 | */ 35 | @Select("select id from user where username=#{usernameOrEmail} or email=#{usernameOrEmail}") 36 | int getUserId(String usernameOrEmail); 37 | 38 | /** 39 | * 通过ID更新用户基本信息 40 | * 41 | * @param id 编号 42 | * @param avatar 头像 43 | * @param realName 真实姓名 44 | * @param email 邮箱 45 | * 46 | * @return 是否更新成功 47 | */ 48 | @Update("update user set avatar=#{avatar},real_name=#{realName},email=#{email} where id=#{id}") 49 | boolean updateBasicInfo(@Param("id") int id, @Param("avatar") String avatar, @Param("realName") String realName, 50 | @Param("email") String email); 51 | 52 | /** 53 | * 通过id获取一个用户 54 | * 55 | * @param id 编号 56 | * 57 | * @return {@link User} 58 | */ 59 | @Select("select * from user where id=#{id}") 60 | User getUserById(int id); 61 | 62 | /** 63 | * 通过权限获取用户 64 | * 65 | * @param permission 权限 66 | * @param condition 条件 67 | * @param offset 偏移 68 | * 69 | * @return {@link List} 70 | */ 71 | @SelectProvider(type = UserSqlProvider.class, method = "getUserBy") 72 | List listUserBy(@Param("permission") int permission, @Param("condition") String condition, 73 | @Param("offset") int offset); 74 | 75 | /** 76 | * 用户登录 77 | * 78 | * @param usernameOrEmail 用户名 79 | * @param password 密码 80 | * 81 | * @return {@link User} 82 | */ 83 | @Select("select * from user where (username=#{usernameOrEmail} or email=#{usernameOrEmail}) and password=sha2" + 84 | "(#{password},256)") 85 | User login(@Param("usernameOrEmail") String usernameOrEmail, @Param("password") String password); 86 | 87 | /** 88 | * 添加一个用户 89 | * 90 | * @param user {@link User} 91 | * 92 | * @return 是否插入成功 93 | */ 94 | @Insert("insert into user(username,real_name,email,password,is_downloadable,is_uploadable,is_deletable," + 95 | "is_updatable,is_visible) values(#{username},#{realName},#{email},sha2(#{password},256)," + 96 | "#{isDownloadable},#{isUploadable},#{isDeletable},#{isUpdatable},#{isVisible})") 97 | boolean insertUser(User user); 98 | 99 | /** 100 | * 通过id更新用户登录时间 101 | * 102 | * @param id 编号 103 | * 104 | * @return {@link Boolean} 105 | */ 106 | @Update("update user set last_login_time=current_timestamp where id=#{id}") 107 | boolean updateUserLoginTime(int id); 108 | 109 | /** 110 | * 更新操作用户权限 111 | * 112 | * @param id 用户编号 113 | * @param isDownloadable 下载权限 114 | * @param isUploadable 上传权限 115 | * @param isVisible 可查权限 116 | * @param isDeletable 删除权限 117 | * @param isUpdatable 更新权限 118 | * 119 | * @return {@link Boolean} 120 | */ 121 | @UpdateProvider(type = UserSqlProvider.class, method = "updateAuthById") 122 | boolean updateAuthById(@Param("id") int id, @Param("isDownloadable") int isDownloadable, 123 | @Param("isUploadable") int isUploadable, @Param("isDeletable") int isDeletable, @Param( 124 | "isUpdatable") int isUpdatable, @Param("isVisible") int isVisible); 125 | 126 | /** 127 | * 通过编号哦更新密码 128 | * 129 | * @param id 编号 130 | * @param password 密码 131 | * 132 | * @return {@link Boolean} 133 | */ 134 | @Update("update user set password=sha2(#{password},256) where id=#{id}") 135 | boolean updatePasswordById(@Param("id") int id, @Param("password") String password); 136 | 137 | /** 138 | * 通过邮箱更新密码 139 | * 140 | * @param password 密码 141 | * @param email 邮箱 142 | * 143 | * @return {@link Boolean} 144 | */ 145 | @Update("update user set password=sha2(#{password},256) where email=#{email}") 146 | boolean updatePasswordByEmail(@Param("password") String password, @Param("email") String email); 147 | 148 | /** 149 | * 检查用户名 150 | * 151 | * @param username 用户名 152 | * 153 | * @return {@link Integer} 154 | */ 155 | @Select("select count(*) from user where username=#{username}") 156 | int checkUsername(String username); 157 | 158 | /** 159 | * 检查邮箱 160 | * 161 | * @param email 邮箱 162 | * 163 | * @return {@link Integer} 164 | */ 165 | @Select("select count(*) from user where email=#{email}") 166 | int checkEmail(String email); 167 | } 168 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/sqlprovider/AuthSqlProvider.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao.sqlprovider; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 5 | import com.zhazhapan.util.Checker; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.jdbc.SQL; 8 | 9 | /** 10 | * @author pantao 11 | * @since 2018/1/19 12 | */ 13 | public class AuthSqlProvider { 14 | 15 | public String updateAuthById() { 16 | return CommonSqlProvider.updateAuthById("auth"); 17 | } 18 | 19 | public String batchDelete(@Param("ids") String ids) { 20 | return "delete from auth where id in " + (ids.startsWith("(") ? "" : "(") + ids + (ids.endsWith(")") ? "" : 21 | ")"); 22 | } 23 | 24 | public String getAuthBy(@Param("id") long id, @Param("userId") int userId, @Param("fileId") long fileId, @Param 25 | ("fileName") String fileName, @Param("offset") int offset) { 26 | String sql = new SQL() {{ 27 | SELECT("a.id,a.user_id,a.file_id,u.username,f.name file_name,f.local_url,a.is_downloadable,a" + "" + "" + 28 | ".is_uploadable,a.is_deletable,a.is_updatable,a.is_visible,a.create_time"); 29 | FROM("auth a"); 30 | JOIN("user u on u.id=a.user_id"); 31 | JOIN("file f on f.id=a.file_id"); 32 | if (id > 0) { 33 | WHERE("a.id=#{id}"); 34 | } 35 | if (userId > 0) { 36 | WHERE("u.id=#{userId}"); 37 | } 38 | if (fileId > 0) { 39 | WHERE("f.id=#{fileId}"); 40 | } else if (Checker.isNotEmpty(fileName)) { 41 | WHERE("f.local_url like '%" + fileName + "%'"); 42 | } 43 | ORDER_BY("a." + EfoApplication.settings.getStringUseEval(ConfigConsts.AUTH_ORDER_BY_OF_SETTINGS)); 44 | }}.toString(); 45 | int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.AUTH_PAGE_SIZE_OF_SETTINGS); 46 | return sql + " limit " + (offset * size) + "," + size; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/sqlprovider/CommonSqlProvider.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao.sqlprovider; 2 | 3 | import org.apache.ibatis.jdbc.SQL; 4 | 5 | /** 6 | * @author pantao 7 | * @since 2018/1/19 8 | */ 9 | public class CommonSqlProvider { 10 | 11 | private CommonSqlProvider() {} 12 | 13 | public static String updateAuthById(String table) { 14 | return new SQL() {{ 15 | UPDATE(table); 16 | SET("is_downloadable=#{isDownloadable}"); 17 | SET("is_uploadable=#{isUploadable}"); 18 | SET("is_deletable=#{isDeletable}"); 19 | SET("is_updatable=#{isUpdatable}"); 20 | SET("is_visible=#{isVisible}"); 21 | WHERE("id=#{id}"); 22 | }}.toString(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/sqlprovider/DownloadedSqlProvider.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao.sqlprovider; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 5 | import com.zhazhapan.util.Checker; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.jdbc.SQL; 8 | 9 | /** 10 | * @author pantao 11 | * @since 2018/1/19 12 | */ 13 | public class DownloadedSqlProvider { 14 | 15 | /** 16 | * 生成一条下载记录表的查询语句 17 | * 18 | * @param userId 用户编号 19 | * @param fileId 文件编号 20 | * 21 | * @return SQL语句 22 | */ 23 | public String getDownloadBy(@Param("userId") int userId, @Param("fileId") long fileId, @Param("fileName") String 24 | fileName, @Param("categoryId") int categoryId, @Param("offset") int offset) { 25 | String sql = new SQL() {{ 26 | SELECT("d.id,d.user_id,d.file_id,u.username,u.email,f.name file_name,c.name category_name,f.visit_url,d" 27 | + ".create_time"); 28 | FROM("download d"); 29 | JOIN("user u on d.user_id=u.id"); 30 | JOIN("file f on d.file_id=f.id"); 31 | JOIN("category c on f.category_id=c.id"); 32 | if (userId > 0) { 33 | WHERE("d.user_id=#{userId}"); 34 | } 35 | if (fileId > 0) { 36 | WHERE("d.file_id=#{fileId}"); 37 | } else if (Checker.isNotEmpty(fileName)) { 38 | WHERE("f.local_url like '%" + fileName + "%'"); 39 | } 40 | if (categoryId > 0) { 41 | WHERE("c.id=#{categoryId}"); 42 | } 43 | ORDER_BY("d." + EfoApplication.settings.getStringUseEval(ConfigConsts.DOWNLOAD_ORDER_BY_OF_SETTINGS)); 44 | }}.toString(); 45 | int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.DOWNLOAD_PAGE_SIZE_OF_SETTINGS); 46 | return sql + " limit " + (offset * size) + "," + size; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/sqlprovider/FileSqlProvider.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao.sqlprovider; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 5 | import com.zhazhapan.modules.constant.ValueConsts; 6 | import com.zhazhapan.util.Checker; 7 | import org.apache.ibatis.annotations.Param; 8 | import org.apache.ibatis.jdbc.SQL; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * @author pantao 13 | * @since 2018/1/19 14 | */ 15 | @Component 16 | public class FileSqlProvider { 17 | 18 | public String updateAuthById() { 19 | return CommonSqlProvider.updateAuthById("file"); 20 | } 21 | 22 | /** 23 | * 生成一条文件基本信息的查询语句 24 | * 25 | * @param userId 用户编号 26 | * @param fileId 文件编号 27 | * 28 | * @return SQL语句 29 | */ 30 | public String getBasicBy(@Param("userId") int userId, @Param("fileId") long fileId, @Param("fileName") String 31 | fileName, @Param("categoryId") int categoryId, @Param("offset") int offset) { 32 | String sql = new SQL() {{ 33 | SELECT("f.id,u.username,f.local_url,c.name category_name,f.visit_url,f.download_times," + "f" + "" + "" + 34 | ".create_time"); 35 | FROM("file f"); 36 | JOIN("user u on f.user_id=u.id"); 37 | JOIN("category c on f.category_id=c.id"); 38 | if (userId > 0) { 39 | WHERE("f.user_id=#{userId}"); 40 | } 41 | if (fileId > 0) { 42 | WHERE("f.id=#{fileId}"); 43 | } else if (Checker.isNotEmpty(fileName)) { 44 | WHERE("f.local_url like '%" + fileName + "%'"); 45 | } 46 | if (categoryId > 0) { 47 | WHERE("c.id=#{categoryId}"); 48 | } 49 | ORDER_BY("f." + EfoApplication.settings.getStringUseEval(ConfigConsts.FILE_ORDER_BY_OF_SETTING)); 50 | }}.toString(); 51 | int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.FILE_PAGE_SIZE_OF_SETTING); 52 | return sql + " limit " + (offset * size) + "," + size; 53 | } 54 | 55 | private String getSqlEnds(int offset, String orderBy, String search) { 56 | int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.FILE_PAGE_SIZE_OF_SETTING); 57 | return getSearch(search) + " order by " + (Checker.isEmpty(orderBy) ? EfoApplication.settings 58 | .getStringUseEval(ConfigConsts.FILE_ORDER_BY_OF_SETTING) : orderBy) + " limit " + offset * size 59 | + "," + size; 60 | } 61 | 62 | public String getAll(@Param("offset") int offset, @Param("categoryId") int categoryId, @Param("orderBy") String 63 | orderBy, @Param("search") String search) { 64 | return getBaseSql(ValueConsts.FALSE) + " where f.is_visible=1" + (categoryId < 1 ? "" : " and " + 65 | "category_id=#{categoryId}") + " and ((select a.is_visible from auth a where a.file_id=f.id and a" + 66 | ".user_id=#{userId}) is null or (a.user_id=#{userId} and a.is_visible=1))" + getSqlEnds(offset, 67 | orderBy, search); 68 | } 69 | 70 | public String getUserUploaded(@Param("offset") int offset, @Param("search") String search) { 71 | return getBaseSql(ValueConsts.FALSE) + " where f.is_visible=1 and (f.user_id=#{userId} or a.is_updatable=1 or" + 72 | " a.is_deletable=1)" + getSqlEnds(offset, 73 | ValueConsts.EMPTY_STRING, search); 74 | } 75 | 76 | public String getUserDownloaded(@Param("offset") int offset, @Param("search") String search) { 77 | return getBaseSql(ValueConsts.TRUE) + " where d.user_id=#{userId}" + getSqlEnds(offset, ValueConsts 78 | .EMPTY_STRING, search); 79 | } 80 | 81 | private String getSearch(String search) { 82 | if (Checker.isEmpty(search)) { 83 | return ValueConsts.EMPTY_STRING; 84 | } else { 85 | search = "'%" + search + "%'"; 86 | return " and (f.name like " + search + " or f.visit_url like " + search + " or f.description like " + 87 | search + " or f.tag like " + search + ")"; 88 | } 89 | } 90 | 91 | private String getBaseSql(boolean isDownloaded) { 92 | return new SQL() {{ 93 | SELECT("distinct f.id,f.user_id,u.username,u.avatar,f.name file_name,f.size,f.create_time,c.name " + 94 | "category_name,f" 95 | + ".description,f.tag,f.check_times,f.download_times,f.visit_url,f.is_uploadable,f.is_deletable," 96 | + "f.is_updatable,f.is_downloadable,f.is_visible"); 97 | if (isDownloaded) { 98 | SELECT("d.create_time download_time"); 99 | } 100 | FROM("file f"); 101 | JOIN("user u on u.id=f.user_id"); 102 | JOIN("category c on c.id=f.category_id"); 103 | if (isDownloaded) { 104 | JOIN("download d on d.file_id=f.id"); 105 | } else { 106 | JOIN("auth a on a.file_id=f.id"); 107 | } 108 | }}.toString(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/sqlprovider/UploadedSqlProvider.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao.sqlprovider; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 5 | import com.zhazhapan.util.Checker; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.jdbc.SQL; 8 | 9 | /** 10 | * @author pantao 11 | * @since 2018/2/28 12 | */ 13 | public class UploadedSqlProvider { 14 | 15 | /** 16 | * 生成一条上传记录表的查询语句 17 | * 18 | * @param userId 用户编号 19 | * @param fileId 文件编号 20 | * 21 | * @return SQL语句 22 | */ 23 | public String getDownloadBy(@Param("userId") int userId, @Param("fileId") long fileId, @Param("fileName") String 24 | fileName, @Param("categoryId") int categoryId, @Param("offset") int offset) { 25 | String sql = new SQL() {{ 26 | SELECT("f.id,f.user_id,u.username,u.email,f.name file_name,c.name category_name,f.local_url,f.visit_url," 27 | + "" + "" + "" + "f" + ".create_time"); 28 | FROM("file f"); 29 | JOIN("user u on f.user_id=u.id"); 30 | JOIN("category c on f.category_id=c.id"); 31 | if (userId > 0) { 32 | WHERE("f.user_id=#{userId}"); 33 | } 34 | if (fileId > 0) { 35 | WHERE("f.id=#{fileId}"); 36 | } else if (Checker.isNotEmpty(fileName)) { 37 | WHERE("f.local_url like '%" + fileName + "%'"); 38 | } 39 | if (categoryId > 0) { 40 | WHERE("c.id=#{categoryId}"); 41 | } 42 | ORDER_BY("f." + EfoApplication.settings.getStringUseEval(ConfigConsts.FILE_ORDER_BY_OF_SETTING)); 43 | }}.toString(); 44 | int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.FILE_PAGE_SIZE_OF_SETTING); 45 | return sql + " limit " + (offset * size) + "," + size; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/dao/sqlprovider/UserSqlProvider.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao.sqlprovider; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 5 | import com.zhazhapan.efo.modules.constant.DefaultValues; 6 | import com.zhazhapan.util.Checker; 7 | import org.apache.ibatis.annotations.Param; 8 | import org.apache.ibatis.jdbc.SQL; 9 | 10 | /** 11 | * @author pantao 12 | * @since 2018/1/19 13 | */ 14 | public class UserSqlProvider { 15 | 16 | public String updateAuthById() { 17 | return CommonSqlProvider.updateAuthById("user"); 18 | } 19 | 20 | public String getUserBy(@Param("permission") int permission, @Param("condition") String condition, @Param 21 | ("offset") int offset) { 22 | String sql = new SQL() {{ 23 | SELECT("*"); 24 | FROM("user"); 25 | if (permission == DefaultValues.THREE_INT) { 26 | WHERE("permission<3"); 27 | } else if (permission == DefaultValues.TWO_INT) { 28 | WHERE("permission<2"); 29 | } else { 30 | WHERE("permission<0"); 31 | } 32 | if (Checker.isNotEmpty(condition)) { 33 | WHERE("username like '%" + condition + "%' or email like '%" + condition + "%' or real_name like '" + 34 | condition + "'"); 35 | } 36 | ORDER_BY(EfoApplication.settings.getStringUseEval(ConfigConsts.USER_ORDER_BY_OF_SETTINGS)); 37 | }}.toString(); 38 | int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.USER_PAGE_SIZE_OF_SETTINGS); 39 | return sql + " limit " + (offset * size) + "," + size; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/entity/Auth.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.entity; 2 | 3 | import com.zhazhapan.efo.util.BeanUtils; 4 | 5 | import java.sql.Timestamp; 6 | 7 | /** 8 | * @author pantao 9 | * @since 2018/1/18 10 | */ 11 | public class Auth { 12 | 13 | private long id; 14 | 15 | private int isUploadable; 16 | 17 | private int isDeletable; 18 | 19 | private int isUpdatable; 20 | 21 | private int isDownloadable; 22 | 23 | private int isVisible; 24 | 25 | private int userId; 26 | 27 | private long fileId; 28 | 29 | private Timestamp createTime; 30 | 31 | public Auth(int userId, long fileId) { 32 | this.userId = userId; 33 | this.fileId = fileId; 34 | } 35 | 36 | public Auth(long id, int isUploadable, int isDeletable, int isUpdatable, int userId, long fileId, int isVisible, 37 | int isDownloadable, Timestamp createTime) { 38 | this.id = id; 39 | this.isUploadable = isUploadable; 40 | this.isDeletable = isDeletable; 41 | this.isUpdatable = isUpdatable; 42 | this.isDownloadable = isDownloadable; 43 | this.isVisible = isVisible; 44 | this.userId = userId; 45 | this.fileId = fileId; 46 | this.createTime = createTime; 47 | } 48 | 49 | public void setAuth(int isDownloadable, int isUploadable, int isDeletable, int isUpdatable, int isVisible) { 50 | this.isUploadable = isUploadable; 51 | this.isDeletable = isDeletable; 52 | this.isUpdatable = isUpdatable; 53 | this.isDownloadable = isDownloadable; 54 | this.isVisible = isVisible; 55 | } 56 | 57 | public void setAuth(int[] auth) { 58 | setAuth(auth[0], auth[1], auth[2], auth[3], auth[4]); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return BeanUtils.toPrettyJson(this); 64 | } 65 | 66 | public long getId() { 67 | return id; 68 | } 69 | 70 | public void setId(long id) { 71 | this.id = id; 72 | } 73 | 74 | public int getIsUploadable() { 75 | return isUploadable; 76 | } 77 | 78 | public void setIsUploadable(int isUploadable) { 79 | this.isUploadable = isUploadable; 80 | } 81 | 82 | public int getIsDeletable() { 83 | return isDeletable; 84 | } 85 | 86 | public void setIsDeletable(int isDeletable) { 87 | this.isDeletable = isDeletable; 88 | } 89 | 90 | public int getIsUpdatable() { 91 | return isUpdatable; 92 | } 93 | 94 | public void setIsUpdatable(int isUpdatable) { 95 | this.isUpdatable = isUpdatable; 96 | } 97 | 98 | public int getIsDownloadable() { 99 | return isDownloadable; 100 | } 101 | 102 | public void setIsDownloadable(int isDownloadable) { 103 | this.isDownloadable = isDownloadable; 104 | } 105 | 106 | public int getIsVisible() { 107 | return isVisible; 108 | } 109 | 110 | public void setIsVisible(int isVisible) { 111 | this.isVisible = isVisible; 112 | } 113 | 114 | public int getUserId() { 115 | return userId; 116 | } 117 | 118 | public void setUserId(int userId) { 119 | this.userId = userId; 120 | } 121 | 122 | public long getFileId() { 123 | return fileId; 124 | } 125 | 126 | public void setFileId(long fileId) { 127 | this.fileId = fileId; 128 | } 129 | 130 | public Timestamp getCreateTime() { 131 | return createTime; 132 | } 133 | 134 | public void setCreateTime(Timestamp createTime) { 135 | this.createTime = createTime; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/entity/Category.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.entity; 2 | 3 | import com.zhazhapan.efo.util.BeanUtils; 4 | 5 | import java.sql.Timestamp; 6 | 7 | /** 8 | * 分类表 9 | * 10 | * @author pantao 11 | * @since 2018/1/11 12 | */ 13 | public class Category { 14 | 15 | private int id; 16 | 17 | /** 18 | * 分类名称 19 | */ 20 | private String name; 21 | 22 | private Timestamp createTime; 23 | 24 | public Category(String name) { 25 | this.name = name; 26 | } 27 | 28 | public Category(int id, String name, Timestamp createTime) { 29 | this.id = id; 30 | this.name = name; 31 | this.createTime = createTime; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return BeanUtils.toPrettyJson(this); 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public Timestamp getCreateTime() { 48 | return createTime; 49 | } 50 | 51 | public void setCreateTime(Timestamp createTime) { 52 | this.createTime = createTime; 53 | } 54 | 55 | public int getId() { 56 | 57 | return id; 58 | } 59 | 60 | public void setId(int id) { 61 | this.id = id; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/entity/Download.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.entity; 2 | 3 | import com.zhazhapan.efo.util.BeanUtils; 4 | 5 | import java.sql.Timestamp; 6 | 7 | /** 8 | * 下载记录表 9 | * 10 | * @author pantao 11 | * @since 2018/1/11 12 | */ 13 | public class Download { 14 | 15 | private long id; 16 | 17 | private Timestamp createTime; 18 | 19 | private int userId; 20 | 21 | private int fileId; 22 | 23 | public Download(int userId, int fileId) { 24 | this.userId = userId; 25 | this.fileId = fileId; 26 | } 27 | 28 | public Download(int id, Timestamp createTime, int userId, int fileId) { 29 | this.id = id; 30 | this.createTime = createTime; 31 | this.userId = userId; 32 | this.fileId = fileId; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return BeanUtils.toPrettyJson(this); 38 | } 39 | 40 | public long getId() { 41 | return id; 42 | } 43 | 44 | public void setId(int id) { 45 | this.id = id; 46 | } 47 | 48 | public Timestamp getCreateTime() { 49 | return createTime; 50 | } 51 | 52 | public void setCreateTime(Timestamp createTime) { 53 | this.createTime = createTime; 54 | } 55 | 56 | public int getUserId() { 57 | return userId; 58 | } 59 | 60 | public void setUserId(int userId) { 61 | this.userId = userId; 62 | } 63 | 64 | public int getFileId() { 65 | return fileId; 66 | } 67 | 68 | public void setFileId(int fileId) { 69 | this.fileId = fileId; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.entity; 2 | 3 | import com.zhazhapan.efo.util.BeanUtils; 4 | 5 | import java.sql.Timestamp; 6 | 7 | /** 8 | * 用户表 9 | * 10 | * @author pantao 11 | * @since 2018/1/11 12 | */ 13 | public class User { 14 | 15 | private int id; 16 | 17 | private String username; 18 | 19 | private String realName; 20 | 21 | private String email; 22 | 23 | private String password; 24 | 25 | private int isUploadable; 26 | 27 | private int isDeletable; 28 | 29 | private int isUpdatable; 30 | 31 | private int isDownloadable; 32 | 33 | private int isVisible; 34 | 35 | /** 36 | * 权限级别:0(禁止登录),1(正常,普通用户),2(正常,管理员),3(正常,超级管理员) 37 | */ 38 | private int permission; 39 | 40 | private Timestamp createTime; 41 | 42 | private Timestamp lastLoginTime; 43 | 44 | private String avatar; 45 | 46 | public User(String username, String realName, String email, String password) { 47 | this.username = username; 48 | this.realName = realName; 49 | this.email = email; 50 | this.password = password; 51 | } 52 | 53 | public User(int id, String username, String realName, String email, String password, int permission, Timestamp 54 | createTime, Timestamp lastLoginTime, int isDownloadable, int isUploadable, int isVisible, int 55 | isDeletable, int isUpdatable, String avatar) { 56 | this.id = id; 57 | this.username = username; 58 | this.realName = realName; 59 | this.email = email; 60 | this.password = password; 61 | this.isUploadable = isUploadable; 62 | this.isDeletable = isDeletable; 63 | this.isUpdatable = isUpdatable; 64 | this.isDownloadable = isDownloadable; 65 | this.isVisible = isVisible; 66 | this.permission = permission; 67 | this.createTime = createTime; 68 | this.lastLoginTime = lastLoginTime; 69 | this.avatar = avatar; 70 | } 71 | 72 | public void setAuth(int isDownloadable, int isUploadable, int isDeletable, int isUpdatable, int isVisible) { 73 | this.isUploadable = isUploadable; 74 | this.isDeletable = isDeletable; 75 | this.isUpdatable = isUpdatable; 76 | this.isDownloadable = isDownloadable; 77 | this.isVisible = isVisible; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return BeanUtils.toPrettyJson(this); 83 | } 84 | 85 | public int getIsUploadable() { 86 | return isUploadable; 87 | } 88 | 89 | public void setIsUploadable(int isUploadable) { 90 | this.isUploadable = isUploadable; 91 | } 92 | 93 | public int getIsDeletable() { 94 | return isDeletable; 95 | } 96 | 97 | public void setIsDeletable(int isDeletable) { 98 | this.isDeletable = isDeletable; 99 | } 100 | 101 | public int getIsUpdatable() { 102 | return isUpdatable; 103 | } 104 | 105 | public void setIsUpdatable(int isUpdatable) { 106 | this.isUpdatable = isUpdatable; 107 | } 108 | 109 | public int getIsDownloadable() { 110 | return isDownloadable; 111 | } 112 | 113 | public void setIsDownloadable(int isDownloadable) { 114 | this.isDownloadable = isDownloadable; 115 | } 116 | 117 | public int getIsVisible() { 118 | return isVisible; 119 | } 120 | 121 | public void setIsVisible(int isVisible) { 122 | this.isVisible = isVisible; 123 | } 124 | 125 | public int getId() { 126 | return id; 127 | } 128 | 129 | public void setId(int id) { 130 | this.id = id; 131 | } 132 | 133 | public String getUsername() { 134 | return username; 135 | } 136 | 137 | public void setUsername(String username) { 138 | this.username = username; 139 | } 140 | 141 | public String getRealName() { 142 | return realName; 143 | } 144 | 145 | public void setRealName(String realName) { 146 | this.realName = realName; 147 | } 148 | 149 | public String getEmail() { 150 | return email; 151 | } 152 | 153 | public void setEmail(String email) { 154 | this.email = email; 155 | } 156 | 157 | public String getPassword() { 158 | return password; 159 | } 160 | 161 | public void setPassword(String password) { 162 | this.password = password; 163 | } 164 | 165 | public int getPermission() { 166 | return permission; 167 | } 168 | 169 | public void setPermission(int permission) { 170 | this.permission = permission; 171 | } 172 | 173 | public Timestamp getCreateTime() { 174 | return createTime; 175 | } 176 | 177 | public void setCreateTime(Timestamp createTime) { 178 | this.createTime = createTime; 179 | } 180 | 181 | public Timestamp getLastLoginTime() { 182 | return lastLoginTime; 183 | } 184 | 185 | public void setLastLoginTime(Timestamp lastLoginTime) { 186 | this.lastLoginTime = lastLoginTime; 187 | } 188 | 189 | public String getAvatar() { 190 | return avatar; 191 | } 192 | 193 | public void setAvatar(String avatar) { 194 | this.avatar = avatar; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/enums/InterceptorLevel.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.enums; 2 | 3 | /** 4 | * 拦截级别 5 | * 6 | * @author pantao 7 | * @since 2018/1/25 8 | */ 9 | public enum InterceptorLevel { 10 | /** 11 | * 不拦截 12 | */ 13 | NONE, 14 | 15 | /** 16 | * 用户级别拦截 17 | */ 18 | USER, 19 | 20 | /** 21 | * 管理员级别拦截 22 | */ 23 | ADMIN, 24 | 25 | /** 26 | * 系统用户 27 | */ 28 | SYSTEM 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.exception; 2 | 3 | import com.alibaba.fastjson.support.spring.FastJsonJsonView; 4 | import com.zhazhapan.modules.constant.ValueConsts; 5 | import com.zhazhapan.util.Checker; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.web.servlet.HandlerExceptionResolver; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | * @author pantao 17 | * @since 2018/2/5 18 | */ 19 | public class GlobalExceptionHandler implements HandlerExceptionResolver { 20 | 21 | @Override 22 | public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, 23 | Exception ex) { 24 | ModelAndView mv = new ModelAndView(); 25 | FastJsonJsonView view = new FastJsonJsonView(); 26 | Map attributes = new HashMap<>(ValueConsts.TWO_INT); 27 | attributes.put("code", "502"); 28 | attributes.put("message", ex.getMessage()); 29 | String queryString = request.getQueryString(); 30 | attributes.put("url", request.getRequestURI() + (Checker.isEmpty(queryString) ? "" : "?" + queryString)); 31 | view.setAttributesMap(attributes); 32 | mv.setView(view); 33 | mv.setStatus(HttpStatus.INTERNAL_SERVER_ERROR); 34 | return mv; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/interceptor/WebInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.interceptor; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.annotation.AuthInterceptor; 5 | import com.zhazhapan.efo.entity.User; 6 | import com.zhazhapan.efo.enums.InterceptorLevel; 7 | import com.zhazhapan.efo.modules.constant.DefaultValues; 8 | import com.zhazhapan.efo.service.impl.UserServiceImpl; 9 | import com.zhazhapan.modules.constant.ValueConsts; 10 | import com.zhazhapan.util.Checker; 11 | import com.zhazhapan.util.HttpUtils; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.method.HandlerMethod; 15 | import org.springframework.web.servlet.HandlerInterceptor; 16 | 17 | import javax.servlet.http.Cookie; 18 | import javax.servlet.http.HttpServletRequest; 19 | import javax.servlet.http.HttpServletResponse; 20 | 21 | /** 22 | * @author pantao 23 | * @since 2018/1/25 24 | */ 25 | public class WebInterceptor implements HandlerInterceptor { 26 | 27 | @Autowired 28 | UserServiceImpl userService; 29 | 30 | @Override 31 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws 32 | Exception { 33 | String url = request.getServletPath(); 34 | InterceptorLevel level = InterceptorLevel.NONE; 35 | if (handler instanceof HandlerMethod) { 36 | AuthInterceptor interceptor = ((HandlerMethod) handler).getMethodAnnotation(AuthInterceptor.class); 37 | //注解到类上面的注解,无法直接获取,只能通过扫描 38 | if (Checker.isNull(interceptor)) { 39 | for (Class type : EfoApplication.controllers) { 40 | RequestMapping mapping = type.getAnnotation(RequestMapping.class); 41 | if (Checker.isNotNull(mapping)) { 42 | for (String path : mapping.value()) { 43 | if (url.startsWith(path)) { 44 | interceptor = type.getAnnotation(AuthInterceptor.class); 45 | break; 46 | } 47 | } 48 | break; 49 | } 50 | } 51 | } 52 | if (Checker.isNotNull(interceptor)) { 53 | level = interceptor.value(); 54 | } 55 | } 56 | User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING); 57 | if (Checker.isNull(user)) { 58 | //读取token,自动登录 59 | Cookie cookie = HttpUtils.getCookie(ValueConsts.TOKEN_STRING, request.getCookies()); 60 | if (Checker.isNotNull(cookie)) { 61 | user = userService.login(ValueConsts.EMPTY_STRING, ValueConsts.EMPTY_STRING, cookie.getValue(), 62 | response); 63 | if (Checker.isNotNull(user)) { 64 | request.getSession().setAttribute(ValueConsts.USER_STRING, user); 65 | } 66 | } 67 | } 68 | if (level != InterceptorLevel.NONE) { 69 | boolean isRedirect = Checker.isNull(user) || (level == InterceptorLevel.ADMIN && user.getPermission() < 70 | 2) || (level == InterceptorLevel.SYSTEM && user.getPermission() < 3); 71 | if (isRedirect) { 72 | response.sendRedirect(DefaultValues.SIGNIN_PAGE); 73 | return false; 74 | } 75 | } 76 | return true; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/model/AuthRecord.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.model; 2 | 3 | import com.zhazhapan.efo.util.BeanUtils; 4 | 5 | import java.sql.Timestamp; 6 | 7 | /** 8 | * @author pantao 9 | * @since 2018/1/19 10 | */ 11 | public class AuthRecord { 12 | 13 | private long id; 14 | 15 | private int userId; 16 | 17 | private long fileId; 18 | 19 | private String username; 20 | 21 | private String fileName; 22 | 23 | private String localUrl; 24 | 25 | private int isDownloadable; 26 | 27 | private int isUploadable; 28 | 29 | private int isDeletable; 30 | 31 | private int isUpdatable; 32 | 33 | private int isVisible; 34 | 35 | private Timestamp createTime; 36 | 37 | public AuthRecord(long id, int userId, long fileId, String username, String fileName, String localUrl, int 38 | isDownloadable, int isUploadable, int isDeletable, int isUpdatable, int isVisible, Timestamp createTime) { 39 | this.id = id; 40 | this.userId = userId; 41 | this.fileId = fileId; 42 | this.username = username; 43 | this.fileName = fileName; 44 | this.localUrl = localUrl; 45 | this.isDownloadable = isDownloadable; 46 | this.isUploadable = isUploadable; 47 | this.isDeletable = isDeletable; 48 | this.isUpdatable = isUpdatable; 49 | this.isVisible = isVisible; 50 | this.createTime = createTime; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return BeanUtils.toPrettyJson(this); 56 | } 57 | 58 | public long getId() { 59 | return id; 60 | } 61 | 62 | public void setId(long id) { 63 | this.id = id; 64 | } 65 | 66 | public int getUserId() { 67 | return userId; 68 | } 69 | 70 | public void setUserId(int userId) { 71 | this.userId = userId; 72 | } 73 | 74 | public long getFileId() { 75 | return fileId; 76 | } 77 | 78 | public void setFileId(long fileId) { 79 | this.fileId = fileId; 80 | } 81 | 82 | public String getUsername() { 83 | return username; 84 | } 85 | 86 | public void setUsername(String username) { 87 | this.username = username; 88 | } 89 | 90 | public String getFileName() { 91 | return fileName; 92 | } 93 | 94 | public void setFileName(String fileName) { 95 | this.fileName = fileName; 96 | } 97 | 98 | public String getLocalUrl() { 99 | return localUrl; 100 | } 101 | 102 | public void setLocalUrl(String localUrl) { 103 | this.localUrl = localUrl; 104 | } 105 | 106 | public int getIsDownloadable() { 107 | return isDownloadable; 108 | } 109 | 110 | public void setIsDownloadable(int isDownloadable) { 111 | this.isDownloadable = isDownloadable; 112 | } 113 | 114 | public int getIsUploadable() { 115 | return isUploadable; 116 | } 117 | 118 | public void setIsUploadable(int isUploadable) { 119 | this.isUploadable = isUploadable; 120 | } 121 | 122 | public int getIsDeletable() { 123 | return isDeletable; 124 | } 125 | 126 | public void setIsDeletable(int isDeletable) { 127 | this.isDeletable = isDeletable; 128 | } 129 | 130 | public int getIsUpdatable() { 131 | return isUpdatable; 132 | } 133 | 134 | public void setIsUpdatable(int isUpdatable) { 135 | this.isUpdatable = isUpdatable; 136 | } 137 | 138 | public int getIsVisible() { 139 | return isVisible; 140 | } 141 | 142 | public void setIsVisible(int isVisible) { 143 | this.isVisible = isVisible; 144 | } 145 | 146 | public Timestamp getCreateTime() { 147 | return createTime; 148 | } 149 | 150 | public void setCreateTime(Timestamp createTime) { 151 | this.createTime = createTime; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/model/BaseAuthRecord.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.model; 2 | 3 | /** 4 | * @author pantao 5 | * @since 2018/3/6 6 | */ 7 | public class BaseAuthRecord { 8 | 9 | private int isDownloadable; 10 | 11 | private int isUploadable; 12 | 13 | private int isDeletable; 14 | 15 | private int isUpdatable; 16 | 17 | private int isVisible; 18 | 19 | public BaseAuthRecord(int isDownloadable, int isUploadable, int isDeletable, int isUpdatable, int isVisible) { 20 | this.isDownloadable = isDownloadable; 21 | this.isUploadable = isUploadable; 22 | this.isDeletable = isDeletable; 23 | this.isUpdatable = isUpdatable; 24 | this.isVisible = isVisible; 25 | } 26 | 27 | public int getIsDownloadable() { 28 | return isDownloadable; 29 | } 30 | 31 | public void setIsDownloadable(int isDownloadable) { 32 | this.isDownloadable = isDownloadable; 33 | } 34 | 35 | public int getIsUploadable() { 36 | return isUploadable; 37 | } 38 | 39 | public void setIsUploadable(int isUploadable) { 40 | this.isUploadable = isUploadable; 41 | } 42 | 43 | public int getIsDeletable() { 44 | return isDeletable; 45 | } 46 | 47 | public void setIsDeletable(int isDeletable) { 48 | this.isDeletable = isDeletable; 49 | } 50 | 51 | public int getIsUpdatable() { 52 | return isUpdatable; 53 | } 54 | 55 | public void setIsUpdatable(int isUpdatable) { 56 | this.isUpdatable = isUpdatable; 57 | } 58 | 59 | public int getIsVisible() { 60 | return isVisible; 61 | } 62 | 63 | public void setIsVisible(int isVisible) { 64 | this.isVisible = isVisible; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/model/DownloadRecord.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.model; 2 | 3 | import com.zhazhapan.efo.util.BeanUtils; 4 | 5 | import java.sql.Timestamp; 6 | 7 | /** 8 | * @author pantao 9 | * @since 2018/1/19 10 | */ 11 | public class DownloadRecord { 12 | 13 | private long id; 14 | 15 | private int userId; 16 | 17 | private long fileId; 18 | 19 | private String username; 20 | 21 | private String email; 22 | 23 | private String fileName; 24 | 25 | private String categoryName; 26 | 27 | private String visitUrl; 28 | 29 | private Timestamp createTime; 30 | 31 | public DownloadRecord(long id, int userId, long fileId, String username, String email, String fileName, String 32 | categoryName, String visitUrl, Timestamp createTime) { 33 | this.id = id; 34 | this.userId = userId; 35 | this.fileId = fileId; 36 | this.username = username; 37 | this.email = email; 38 | this.fileName = fileName; 39 | this.categoryName = categoryName; 40 | this.visitUrl = visitUrl; 41 | this.createTime = createTime; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return BeanUtils.toPrettyJson(this); 47 | } 48 | 49 | public long getId() { 50 | return id; 51 | } 52 | 53 | public void setId(long id) { 54 | this.id = id; 55 | } 56 | 57 | public int getUserId() { 58 | return userId; 59 | } 60 | 61 | public void setUserId(int userId) { 62 | this.userId = userId; 63 | } 64 | 65 | public long getFileId() { 66 | return fileId; 67 | } 68 | 69 | public void setFileId(long fileId) { 70 | this.fileId = fileId; 71 | } 72 | 73 | public String getUsername() { 74 | return username; 75 | } 76 | 77 | public void setUsername(String username) { 78 | this.username = username; 79 | } 80 | 81 | public String getEmail() { 82 | return email; 83 | } 84 | 85 | public void setEmail(String email) { 86 | this.email = email; 87 | } 88 | 89 | public String getFileName() { 90 | return fileName; 91 | } 92 | 93 | public void setFileName(String fileName) { 94 | this.fileName = fileName; 95 | } 96 | 97 | public String getCategoryName() { 98 | return categoryName; 99 | } 100 | 101 | public void setCategoryName(String categoryName) { 102 | this.categoryName = categoryName; 103 | } 104 | 105 | public String getVisitUrl() { 106 | return visitUrl; 107 | } 108 | 109 | public void setVisitUrl(String visitUrl) { 110 | this.visitUrl = visitUrl; 111 | } 112 | 113 | public Timestamp getCreateTime() { 114 | return createTime; 115 | } 116 | 117 | public void setCreateTime(Timestamp createTime) { 118 | this.createTime = createTime; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/model/FileBasicRecord.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.model; 2 | 3 | import java.sql.Timestamp; 4 | 5 | /** 6 | * @author pantao 7 | * @since 2018/3/1 8 | */ 9 | public class FileBasicRecord { 10 | 11 | private long id; 12 | 13 | private String username; 14 | 15 | private String localUrl; 16 | 17 | private String categoryName; 18 | 19 | private String visitUrl; 20 | 21 | private int downloadTimes; 22 | 23 | private Timestamp createTime; 24 | 25 | public FileBasicRecord(long id, String username, String localUrl, String categoryName, String visitUrl, int 26 | downloadTimes, Timestamp createTime) { 27 | this.id = id; 28 | this.username = username; 29 | this.localUrl = localUrl; 30 | this.categoryName = categoryName; 31 | this.visitUrl = visitUrl; 32 | this.downloadTimes = downloadTimes; 33 | this.createTime = createTime; 34 | } 35 | 36 | public long getId() { 37 | return id; 38 | } 39 | 40 | public void setId(long id) { 41 | this.id = id; 42 | } 43 | 44 | public String getUsername() { 45 | return username; 46 | } 47 | 48 | public void setUsername(String username) { 49 | this.username = username; 50 | } 51 | 52 | public String getLocalUrl() { 53 | return localUrl; 54 | } 55 | 56 | public void setLocalUrl(String localUrl) { 57 | this.localUrl = localUrl; 58 | } 59 | 60 | public String getCategoryName() { 61 | return categoryName; 62 | } 63 | 64 | public void setCategoryName(String categoryName) { 65 | this.categoryName = categoryName; 66 | } 67 | 68 | public String getVisitUrl() { 69 | return visitUrl; 70 | } 71 | 72 | public void setVisitUrl(String visitUrl) { 73 | this.visitUrl = visitUrl; 74 | } 75 | 76 | public int getDownloadTimes() { 77 | return downloadTimes; 78 | } 79 | 80 | public void setDownloadTimes(int downloadTimes) { 81 | this.downloadTimes = downloadTimes; 82 | } 83 | 84 | public Timestamp getCreateTime() { 85 | return createTime; 86 | } 87 | 88 | public void setCreateTime(Timestamp createTime) { 89 | this.createTime = createTime; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/model/UploadedRecord.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.model; 2 | 3 | import java.sql.Timestamp; 4 | 5 | /** 6 | * @author pantao 7 | * @since 2018/2/28 8 | */ 9 | public class UploadedRecord { 10 | 11 | private long id; 12 | 13 | private int userId; 14 | 15 | private String username; 16 | 17 | private String email; 18 | 19 | private String fileName; 20 | 21 | private String categoryName; 22 | 23 | private String localUrl; 24 | 25 | private String visitUrl; 26 | 27 | private Timestamp createTime; 28 | 29 | public UploadedRecord(long id, int userId, String username, String email, String fileName, String categoryName, 30 | String localUrl, String visitUrl, Timestamp createTime) { 31 | this.id = id; 32 | this.userId = userId; 33 | this.username = username; 34 | this.email = email; 35 | this.fileName = fileName; 36 | this.categoryName = categoryName; 37 | this.localUrl = localUrl; 38 | this.visitUrl = visitUrl; 39 | this.createTime = createTime; 40 | } 41 | 42 | public long getId() { 43 | return id; 44 | } 45 | 46 | public void setId(long id) { 47 | this.id = id; 48 | } 49 | 50 | public int getUserId() { 51 | return userId; 52 | } 53 | 54 | public void setUserId(int userId) { 55 | this.userId = userId; 56 | } 57 | 58 | public String getUsername() { 59 | return username; 60 | } 61 | 62 | public void setUsername(String username) { 63 | this.username = username; 64 | } 65 | 66 | public String getEmail() { 67 | return email; 68 | } 69 | 70 | public void setEmail(String email) { 71 | this.email = email; 72 | } 73 | 74 | public String getFileName() { 75 | return fileName; 76 | } 77 | 78 | public void setFileName(String fileName) { 79 | this.fileName = fileName; 80 | } 81 | 82 | public String getCategoryName() { 83 | return categoryName; 84 | } 85 | 86 | public void setCategoryName(String categoryName) { 87 | this.categoryName = categoryName; 88 | } 89 | 90 | public String getLocalUrl() { 91 | return localUrl; 92 | } 93 | 94 | public void setLocalUrl(String localUrl) { 95 | this.localUrl = localUrl; 96 | } 97 | 98 | public String getVisitUrl() { 99 | return visitUrl; 100 | } 101 | 102 | public void setVisitUrl(String visitUrl) { 103 | this.visitUrl = visitUrl; 104 | } 105 | 106 | public Timestamp getCreateTime() { 107 | return createTime; 108 | } 109 | 110 | public void setCreateTime(Timestamp createTime) { 111 | this.createTime = createTime; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/modules/constant/ConfigConsts.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.modules.constant; 2 | 3 | /** 4 | * @author pantao 5 | * @since 2018/1/12 6 | */ 7 | public class ConfigConsts { 8 | 9 | /** 10 | * 认证方式 11 | */ 12 | public static final String AUTHENTICATION_OF_SETTING = "system.authentication"; 13 | 14 | /** 15 | * 最大标签长度 16 | */ 17 | public static final String TAG_SIZE_OF_SETTING = "file.tag.maxSize"; 18 | 19 | /** 20 | * 每个标签最大长度 21 | */ 22 | public static final String TAG_LENGTH_OF_SETTING = "file.tag.maxLength"; 23 | 24 | /** 25 | * 文件标签 26 | */ 27 | public static final String TAG_REQUIRE_OF_SETTING = "file.tag.require"; 28 | 29 | /** 30 | * 文件默认排序方式 31 | */ 32 | public static final String FILE_ORDER_BY_OF_SETTING = "file.orderBy"; 33 | 34 | /** 35 | * 文件分页大小 36 | */ 37 | public static final String FILE_PAGE_SIZE_OF_SETTING = "file.pageSize"; 38 | 39 | /** 40 | * 匿名用户下载权限 41 | */ 42 | public static final String ANONYMOUS_DOWNLOADABLE_OF_SETTING = "global.anonymousUser.downloadable"; 43 | 44 | /** 45 | * 匿名用户访问权限 46 | */ 47 | public static final String ANONYMOUS_VISIBLE_OF_SETTING = "global.anonymousUser.visible"; 48 | 49 | /** 50 | * 文件后缀匹配 51 | */ 52 | public static final String FILE_SUFFIX_MATCH_OF_SETTING = "file.suffixMatch.pattern"; 53 | 54 | /** 55 | * 是否覆盖文件 56 | */ 57 | public static final String FILE_COVER_OF_SETTING = "file.coverIfExists"; 58 | 59 | /** 60 | * 自定义文件上传链接 61 | */ 62 | public static final String CUSTOM_LINK_RULE_OF_SETTING = "file.linkRule.custom"; 63 | 64 | /** 65 | * 最大上传大小路径 66 | */ 67 | public static final String FILE_MAX_SIZE_OF_SETTING = "file.maxSize"; 68 | 69 | /** 70 | * 上传路径在全局中的路径 71 | */ 72 | public static final String UPLOAD_PATH_OF_SETTING = "global.uploadPath"; 73 | 74 | /** 75 | * 上传形式路径 76 | */ 77 | public static final String UPLOAD_FORM_OF_SETTING = "global.uploadForm"; 78 | 79 | /** 80 | * token的路径 81 | */ 82 | public static final String TOKEN_OF_SETTINGS = "global.tokenPath"; 83 | 84 | /** 85 | * 是否验证邮箱的路径 86 | */ 87 | public static final String EMAIL_VERIFY_OF_SETTINGS = "user.emailVerify"; 88 | 89 | /** 90 | * 用户默认权限 91 | */ 92 | public static final String FILE_DEFAULT_AUTH_OF_SETTING = "file.defaultAuth"; 93 | 94 | /** 95 | * 默认权限 96 | */ 97 | public static final String AUTH_DEFAULT_OF_SETTING = "auth.default"; 98 | 99 | /** 100 | * 用户默认权限 101 | */ 102 | public static final String USER_DEFAULT_AUTH_OF_SETTING = "user.defaultAuth"; 103 | 104 | /** 105 | * 默认权限路径 106 | */ 107 | public static final String[] AUTH_OF_SETTINGS = {"isDownloadable", "isUploadable", "isDeletable", "isUpdatable", 108 | "isVisible"}; 109 | 110 | /** 111 | * 密码最短长度的路径 112 | */ 113 | public static final String PASSWORD_MIN_LENGTH_OF_SETTINGS = "user.password.minLength"; 114 | 115 | /** 116 | * 密码最长长度的路径 117 | */ 118 | public static final String PASSWORD_MAX_LENGTH_OF_SETTINGS = "user.password.maxLength"; 119 | 120 | /** 121 | * 用户名匹配模式的路径 122 | */ 123 | public static final String USERNAME_PATTERN_OF_SETTINGS = "user.usernameMatch.pattern"; 124 | 125 | /** 126 | * 邮件配置的路径 127 | */ 128 | public static final String EMAIL_CONFIG_OF_SETTINGS = "user.emailConfig"; 129 | 130 | /** 131 | * 邮件配置在用户配置中的路径 132 | */ 133 | public static final String EMAIL_CONFIG_OF_USER = "emailConfig"; 134 | 135 | /** 136 | * 配置文件中用户配置的路径 137 | */ 138 | public static final String USER_OF_SETTINGS = "user"; 139 | 140 | /** 141 | * 是否允许用户注册的路径 142 | */ 143 | public static final String ALLOW_REGISTER_OF_SETTINGS = "global.allowRegister"; 144 | 145 | /** 146 | * 配置文件中登录的路径 147 | */ 148 | public static final String ALLOW_LOGIN_OF_SETTINGS = "global.allowLogin"; 149 | 150 | /** 151 | * token在全局中的路径 152 | */ 153 | public static final String TOKEN_PATH_OF_GLOBAL = "tokenPath"; 154 | 155 | /** 156 | * 上传路径在全局配置中的路径 157 | */ 158 | public static final String UPLOAD_PATH_OF_GLOBAL = "uploadPath"; 159 | 160 | /** 161 | * 配置文件中全局配置的路径 162 | */ 163 | public static final String GLOBAL_OF_SETTINGS = "global"; 164 | 165 | /** 166 | * 配置文件中用户表的order by路径 167 | */ 168 | public static final String USER_ORDER_BY_OF_SETTINGS = "user.orderBy"; 169 | 170 | /** 171 | * 配置文件中用户表的page size路径 172 | */ 173 | public static final String USER_PAGE_SIZE_OF_SETTINGS = "user.pageSize"; 174 | 175 | /** 176 | * 配置文件中下载记录表的order by路径 177 | */ 178 | public static final String DOWNLOAD_ORDER_BY_OF_SETTINGS = "download.orderBy"; 179 | 180 | /** 181 | * 配置文件中下载表的page size路径 182 | */ 183 | public static final String DOWNLOAD_PAGE_SIZE_OF_SETTINGS = "download.pageSize"; 184 | 185 | /** 186 | * 配置文件中权限记录表的order by路径 187 | */ 188 | public static final String AUTH_ORDER_BY_OF_SETTINGS = "auth.orderBy"; 189 | 190 | /** 191 | * 配置文件中权限表的page size路径 192 | */ 193 | public static final String AUTH_PAGE_SIZE_OF_SETTINGS = "auth.pageSize"; 194 | 195 | /** 196 | * 默认上传路径,如果配置文件中的上传路径无法创建,将使用默认的上传路径 197 | */ 198 | public static final String DEFAULT_UPLOAD_PATH = DefaultValues.STORAGE_PATH + "upload"; 199 | 200 | private ConfigConsts() {} 201 | } 202 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/modules/constant/DefaultValues.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.modules.constant; 2 | 3 | import com.zhazhapan.modules.constant.ValueConsts; 4 | 5 | /** 6 | * @author pantao 7 | * @since 2018/1/19 8 | */ 9 | public class DefaultValues { 10 | 11 | /** 12 | * 未分类 13 | */ 14 | public static final String UNCATEGORIZED = "未分类"; 15 | 16 | /** 17 | * 404页面路径 18 | */ 19 | public static final String NOT_FOUND_PAGE = "/404.html"; 20 | 21 | /** 22 | * Controller包路径 23 | */ 24 | public static final String CONTROLLER_PACKAGE = "com.zhazhapan.efo.web.controller"; 25 | 26 | /** 27 | * 配置文件路径 28 | */ 29 | public static final String SETTING_PATH = "/config.json"; 30 | 31 | /** 32 | * 冒号 33 | */ 34 | public static final String COLON = ":"; 35 | 36 | /** 37 | * 默认存储路径 38 | */ 39 | public static final String STORAGE_PATH = ValueConsts.USER_HOME + ValueConsts.SEPARATOR + "Desktop" + ValueConsts 40 | .SEPARATOR; 41 | 42 | /** 43 | * 首页映射路径 44 | */ 45 | public static final String INDEX_PAGE = "/index"; 46 | 47 | /** 48 | * 配置映射的路径 49 | */ 50 | public static final String CONFIG_PAGE = "/config"; 51 | 52 | /** 53 | * 资源映射的路径 54 | */ 55 | public static final String ASSETS_PAGE = "/assets"; 56 | 57 | /** 58 | * 登陆注册页面映射路径 59 | */ 60 | public static final String SIGNIN_PAGE = "/signin"; 61 | 62 | /** 63 | * 管理员页面映射路径 64 | */ 65 | public static final String ADMIN_PAGE = "/admin"; 66 | 67 | /** 68 | * int型数值3 69 | */ 70 | public static final int THREE_INT = 3; 71 | /** 72 | * int型数值2 73 | */ 74 | public static final int TWO_INT = 2; 75 | 76 | /** 77 | * code字符 78 | */ 79 | public static final String CODE_STRING = "code"; 80 | 81 | private DefaultValues() {} 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/IAuthService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import com.zhazhapan.efo.entity.Auth; 4 | import com.zhazhapan.efo.model.AuthRecord; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author pantao 10 | * @since 2018/2/1 11 | */ 12 | public interface IAuthService { 13 | 14 | /** 15 | * 添加权限集 16 | * 17 | * @param files 文件 18 | * @param users 用户 19 | * @param auths 权限集 20 | * 21 | * @return 是否添加成功 22 | */ 23 | boolean addAuth(String files, String users, String auths); 24 | 25 | /** 26 | * 批量删除权限记录 27 | * 28 | * @param ids 权限编号集 29 | * 30 | * @return 是否删除成功 31 | */ 32 | boolean batchDelete(String ids); 33 | 34 | /** 35 | * 更新权限 36 | * 37 | * @param id 权限编号 38 | * @param auths 权限 39 | * 40 | * @return 是否更新成功 41 | */ 42 | boolean updateAuth(long id, String auths); 43 | 44 | /** 45 | * 获取权限表数据 46 | * 47 | * @param usernameOrEmail 用户名或邮箱 48 | * @param fileName 文件名 49 | * @param offset 偏移 50 | * 51 | * @return {@link List} 52 | */ 53 | List listAuth(String usernameOrEmail, String fileName, int offset); 54 | 55 | /** 56 | * 获取一个权限 57 | * 58 | * @param fileId 文件编号 59 | * @param userId 用户编号 60 | * 61 | * @return {@link AuthRecord} 62 | */ 63 | AuthRecord getByFileIdAndUserId(long fileId, int userId); 64 | 65 | /** 66 | * 添加一个默认权限 67 | * 68 | * @param userId 用户编号 69 | * @param fileId 文件编号 70 | * 71 | * @return 是否添加成功 72 | */ 73 | boolean insertDefaultAuth(int userId, long fileId); 74 | 75 | /** 76 | * 添加一个权限 77 | * 78 | * @param auth {@link Auth} 79 | * 80 | * @return 是否添加成功 81 | */ 82 | boolean insertAuth(Auth auth); 83 | 84 | /** 85 | * 通过文件编号删除权限 86 | * 87 | * @param fileId 文件编号 88 | * 89 | * @return 是否删除成功 90 | */ 91 | boolean removeByFileId(long fileId); 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/ICategoryService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import com.zhazhapan.efo.entity.Category; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author pantao 9 | * @since 2018/1/30 10 | */ 11 | public interface ICategoryService { 12 | 13 | /** 14 | * 添加一个分类 15 | * 16 | * @param name 分类名称 17 | * 18 | * @return 是否添加成功 19 | */ 20 | boolean insert(String name); 21 | 22 | /** 23 | * 删除一个分类 24 | * 25 | * @param id 分类编号 26 | * 27 | * @return 是否删除成功 28 | */ 29 | boolean remove(int id); 30 | 31 | /** 32 | * 更新分类 33 | * 34 | * @param id 分类编号 35 | * @param name 分类名称 36 | * 37 | * @return 是否更新成功 38 | */ 39 | boolean update(int id, String name); 40 | 41 | /** 42 | * 获取一个分类 43 | * 44 | * @param id 分类编号 45 | * 46 | * @return {@link Category} 47 | */ 48 | Category getById(int id); 49 | 50 | /** 51 | * 获取所有的分类 52 | * 53 | * @return {@link List} 54 | */ 55 | List list(); 56 | 57 | /** 58 | * 通过分类名获取ID 59 | * 60 | * @param name 分类名 61 | * 62 | * @return {@link Integer} 63 | */ 64 | int getIdByName(String name); 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/ICommonService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | /** 6 | * @author pantao 7 | * @since 2018/1/23 8 | */ 9 | public interface ICommonService { 10 | 11 | /** 12 | * 发送验证码 13 | * 14 | * @param email 邮箱 15 | * 16 | * @return 验证码 17 | */ 18 | int sendVerifyCode(String email); 19 | 20 | /** 21 | * 上传头像 22 | * 23 | * @param multipartFile 头像文件 24 | * 25 | * @return 头像文件名 26 | */ 27 | String uploadAvatar(MultipartFile multipartFile); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/IConfigService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | /** 4 | * @author pantao 5 | * @since 2018/1/22 6 | */ 7 | public interface IConfigService { 8 | 9 | /** 10 | * 获取全局配置 11 | * 12 | * @return {@link String} 13 | */ 14 | String getGlobalConfig(); 15 | 16 | /** 17 | * 获取用户配置 18 | * 19 | * @return {@link String} 20 | */ 21 | String getUserConfig(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/IDownloadedService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import com.zhazhapan.efo.model.DownloadRecord; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author pantao 9 | * @since 2018/2/1 10 | */ 11 | public interface IDownloadedService { 12 | 13 | /** 14 | * 添加下载记录 15 | * 16 | * @param userId 用户编号 17 | * @param fileId 文件编号 18 | */ 19 | void insertDownload(int userId, long fileId); 20 | 21 | /** 22 | * 通过文件编号删除下载记录 23 | * 24 | * @param fileId 文件编号 25 | */ 26 | void removeByFileId(long fileId); 27 | 28 | /** 29 | * 获取所有下载记录 30 | * 31 | * @param user 用户名或邮箱 32 | * @param category 分类名称 33 | * @param file 文件名 34 | * @param offset 偏移 35 | * 36 | * @return {@link DownloadRecord} 37 | */ 38 | List list(String user, String file, String category, int offset); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/IFileManagerService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author pantao 12 | * @since 2018/1/29 13 | */ 14 | public interface IFileManagerService { 15 | 16 | 17 | /** 18 | * 下载多个文件 19 | * 20 | * @param response {@link HttpServletResponse} 21 | * @param items 文件集 22 | * @param destFile 目标文件名 23 | * 24 | * @throws IOException 异常 25 | */ 26 | void multiDownload(HttpServletResponse response, String[] items, String destFile) throws IOException; 27 | 28 | /** 29 | * 上传文件(暂时还没有实现) 30 | * 31 | * @param destination 目标文件 32 | * @param files {@link MultipartFile} 33 | * 34 | * @return {@link JSONObject} 35 | */ 36 | JSONObject upload(String destination, MultipartFile... files); 37 | 38 | /** 39 | * 解压文件 40 | * 41 | * @param object {@link JSONObject} 42 | * 43 | * @return {@link JSONObject} 44 | */ 45 | JSONObject extract(JSONObject object); 46 | 47 | /** 48 | * 压缩文件 49 | * 50 | * @param object {@link JSONObject} 51 | * 52 | * @return {@link JSONObject} 53 | */ 54 | JSONObject compress(JSONObject object); 55 | 56 | /** 57 | * 设置文件权限 58 | * 59 | * @param object {@link JSONObject} 60 | * 61 | * @return {@link JSONObject} 62 | */ 63 | JSONObject setPermission(JSONObject object); 64 | 65 | /** 66 | * 创建文件夹 67 | * 68 | * @param object {@link JSONObject} 69 | * 70 | * @return {@link JSONObject} 71 | */ 72 | JSONObject createFolder(JSONObject object); 73 | 74 | /** 75 | * 获取文件内容 76 | * 77 | * @param object {@link JSONObject} 78 | * 79 | * @return 文件内容 80 | */ 81 | String getContent(JSONObject object); 82 | 83 | /** 84 | * 编辑文件 85 | * 86 | * @param object {@link JSONObject} 87 | * 88 | * @return {@link JSONObject} 89 | */ 90 | JSONObject edit(JSONObject object); 91 | 92 | /** 93 | * 移除文件 94 | * 95 | * @param object {@link JSONObject} 96 | * 97 | * @return {@link JSONObject} 98 | */ 99 | JSONObject remove(JSONObject object); 100 | 101 | /** 102 | * 复制文件 103 | * 104 | * @param object {@link JSONObject} 105 | * 106 | * @return {@link JSONObject} 107 | */ 108 | JSONObject copy(JSONObject object); 109 | 110 | /** 111 | * 移动文件 112 | * 113 | * @param object {@link JSONObject} 114 | * 115 | * @return {@link JSONObject} 116 | */ 117 | JSONObject move(JSONObject object); 118 | 119 | /** 120 | * 重命名 121 | * 122 | * @param object {@link JSONObject} 123 | * 124 | * @return {@link JSONObject} 125 | */ 126 | JSONObject rename(JSONObject object); 127 | 128 | /** 129 | * 列出文件 130 | * 131 | * @param object {@link JSONObject} 132 | * 133 | * @return {@link JSONObject} 134 | */ 135 | JSONArray list(JSONObject object); 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/IFileService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import com.zhazhapan.efo.entity.User; 4 | import com.zhazhapan.efo.model.BaseAuthRecord; 5 | import com.zhazhapan.efo.model.FileBasicRecord; 6 | import com.zhazhapan.efo.model.FileRecord; 7 | import org.springframework.web.multipart.MultipartFile; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import java.io.File; 11 | import java.util.List; 12 | 13 | /** 14 | * @author pantao 15 | * @since 2018/1/29 16 | */ 17 | public interface IFileService { 18 | 19 | /** 20 | * 更新文件权限 21 | * 22 | * @param id 文件编号 23 | * @param auth 权限集 24 | * 25 | * @return 是否更新成功 26 | */ 27 | boolean updateAuth(long id, String auth); 28 | 29 | /** 30 | * 获取文件权限 31 | * 32 | * @param id 文件编号 33 | * 34 | * @return {@link BaseAuthRecord} 35 | */ 36 | BaseAuthRecord getAuth(long id); 37 | 38 | /** 39 | * 批量删除文件 40 | * 41 | * @param ids 所有文件编号 42 | * 43 | * @return 是否删除成功 44 | */ 45 | boolean deleteFiles(String ids); 46 | 47 | /** 48 | * 更新文件路径 49 | * 50 | * @param id 文件编号 51 | * @param oldLocalUrl 原本地路径 52 | * @param localUrl 本地路径 53 | * @param visitUrl 访问路径 54 | * 55 | * @return 是否更新成功 56 | */ 57 | boolean[] updateUrl(int id, String oldLocalUrl, String localUrl, String visitUrl); 58 | 59 | /** 60 | * 更新文件信息 61 | * 62 | * @param id 文件编号 63 | * @param user 用户对象 64 | * @param name 文件名 65 | * @param category 文件分类 66 | * @param tag 标签 67 | * @param description 文件描述 68 | * 69 | * @return 是否更新成功 70 | */ 71 | boolean updateFileInfo(long id, User user, String name, String category, String tag, String description); 72 | 73 | /** 74 | * 删除文件,验证权限 75 | * 76 | * @param user 用户对象 77 | * @param fileId 文件编号 78 | * 79 | * @return {@link Boolean} 80 | */ 81 | boolean removeFile(User user, long fileId); 82 | 83 | /** 84 | * 获取用户的下载资源 85 | * 86 | * @param userId 用户编号 87 | * @param offset 偏移 88 | * @param search 搜索 89 | * 90 | * @return {@link List} 91 | */ 92 | List listUserDownloaded(int userId, int offset, String search); 93 | 94 | /** 95 | * 获取用户的上传资源 96 | * 97 | * @param userId 用户编号 98 | * @param offset 偏移 99 | * @param search 搜索 100 | * 101 | * @return {@link List} 102 | */ 103 | List listUserUploaded(int userId, int offset, String search); 104 | 105 | /** 106 | * 通过编号删除,不验证权限 107 | * 108 | * @param id 编号 109 | * 110 | * @return 是否删除成功 111 | */ 112 | boolean removeById(long id); 113 | 114 | /** 115 | * 通过访问路径删除 116 | * 117 | * @param visitUrl 访问路径 118 | * 119 | * @return 是否删除成功 120 | */ 121 | boolean removeByVisitUrl(String visitUrl); 122 | 123 | /** 124 | * 通过本地路径删除 125 | * 126 | * @param localUrl 访问路径 127 | * 128 | * @return 是否删除成功 129 | */ 130 | boolean removeByLocalUrl(String localUrl); 131 | 132 | /** 133 | * 获取资源 134 | * 135 | * @param visitUrl 访问路径 136 | * @param request {@link HttpServletRequest} 137 | * 138 | * @return {@link File} 139 | */ 140 | String getResource(String visitUrl, HttpServletRequest request); 141 | 142 | /** 143 | * 通过访问路径获取本地文件路径 144 | * 145 | * @param visitUrl 访问路径 146 | * 147 | * @return {@link String} 148 | */ 149 | String getLocalUrlByVisitUrl(String visitUrl); 150 | 151 | /** 152 | * 获取所有文件 153 | * 154 | * @param userId 用户编号 155 | * @param offset 偏移 156 | * @param categoryId 分类编号 157 | * @param orderBy 排序方式 158 | * @param search 搜索 159 | * 160 | * @return {@link List} 161 | */ 162 | List listAll(int userId, int offset, int categoryId, String orderBy, String search); 163 | 164 | /** 165 | * 上传文件 166 | * 167 | * @param categoryId 分类ID 168 | * @param tag 标签 169 | * @param description 描述 170 | * @param prefix 自定义前缀 171 | * @param multipartFile 文件 172 | * @param user {@link User} 173 | * 174 | * @return 是否上传成功 175 | */ 176 | boolean upload(int categoryId, String tag, String description, String prefix, MultipartFile multipartFile, User 177 | user); 178 | 179 | /** 180 | * 分享服务器本地文件 181 | * 182 | * @param prefix 链接前缀 183 | * @param files 文件 184 | * @param user 用户对象 185 | * 186 | * @return 是否添加成功 187 | */ 188 | boolean shareFiles(String prefix, String files, User user); 189 | 190 | /** 191 | * 本地路径是否存在 192 | * 193 | * @param localUrl 本地路径 194 | * 195 | * @return {@link Boolean} 196 | */ 197 | boolean localUrlExists(String localUrl); 198 | 199 | /** 200 | * 访问路径是否存在 201 | * 202 | * @param visitUrl 访问路径 203 | * 204 | * @return {@link Boolean} 205 | */ 206 | boolean visitUrlExists(String visitUrl); 207 | 208 | /** 209 | * 通过本地路径获取文件编号 210 | * 211 | * @param localUrl 本地路径 212 | * 213 | * @return 文件编号 214 | */ 215 | long getFileId(String localUrl); 216 | 217 | /** 218 | * 获取所有文件基本信息 219 | * 220 | * @param user 用户名或邮箱 221 | * @param category 分类名称 222 | * @param file 文件名 223 | * @param offset 偏移 224 | * 225 | * @return {@link List} 226 | */ 227 | List listBasicAll(String user, String file, String category, int offset); 228 | } 229 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/IUploadedService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import com.zhazhapan.efo.model.UploadedRecord; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author pantao 9 | * @since 2018/2/28 10 | */ 11 | public interface IUploadedService { 12 | 13 | /** 14 | * 获取所有上传记录 15 | * 16 | * @param user 用户名或邮箱 17 | * @param category 分类名称 18 | * @param file 文件名 19 | * @param offset 偏移 20 | * 21 | * @return {@link List} 22 | */ 23 | List list(String user, String file, String category, int offset); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import com.zhazhapan.efo.entity.User; 4 | 5 | import javax.servlet.http.HttpServletResponse; 6 | import java.util.List; 7 | 8 | /** 9 | * @author pantao 10 | * @since 2018/1/22 11 | */ 12 | public interface IUserService { 13 | 14 | /** 15 | * 更新用户权限 16 | * 17 | * @param id 用户编号 18 | * @param permission 权限 19 | * 20 | * @return 是否更新成功 21 | */ 22 | boolean updatePermission(int id, int permission); 23 | 24 | /** 25 | * 重置用户密码 26 | * 27 | * @param id 用户编号 28 | * @param password 密码 29 | * 30 | * @return 是否重置成功 31 | */ 32 | boolean resetPassword(int id, String password); 33 | 34 | /** 35 | * 更新用户权限 36 | * 37 | * @param id 编号 38 | * @param auths 操作文件的权限集 39 | * 40 | * @return 是否更新成功 41 | */ 42 | boolean updateFileAuth(int id, String auths); 43 | 44 | /** 45 | * 获取用户 46 | * 47 | * @param permission 当前用户权限 48 | * @param condition 筛选条件 49 | * @param offset 偏移 50 | * 51 | * @return {@link List} 52 | */ 53 | List listUser(int permission, String condition, int offset); 54 | 55 | /** 56 | * 登录 57 | * 58 | * @param loginName 登录名 59 | * @param password 密码 60 | * @param token 自动登录 61 | * @param response 响应 62 | * 63 | * @return {@link User} 64 | */ 65 | User login(String loginName, String password, String token, HttpServletResponse response); 66 | 67 | /** 68 | * 注册 69 | * 70 | * @param username 用户名 71 | * @param email 邮箱 72 | * @param password 密码 73 | * 74 | * @return 是否插入成功 75 | */ 76 | boolean register(String username, String email, String password); 77 | 78 | /** 79 | * 重置密码 80 | * 81 | * @param email 邮箱 82 | * @param password 密码 83 | * 84 | * @return {@link Boolean} 85 | */ 86 | boolean resetPasswordByEmail(String email, String password); 87 | 88 | /** 89 | * 检查用户名是否存在 90 | * 91 | * @param username 用户名 92 | * 93 | * @return {@link Boolean} 94 | */ 95 | boolean usernameExists(String username); 96 | 97 | /** 98 | * 通过编号获取用户 99 | * 100 | * @param id 编号 101 | * 102 | * @return {@link User} 103 | */ 104 | User getUserById(int id); 105 | 106 | /** 107 | * 更新用户登录时间 108 | * 109 | * @param user {@link User} 110 | */ 111 | void updateUserLoginTime(User user); 112 | 113 | /** 114 | * 更新密码 115 | * 116 | * @param password 密码 117 | * @param id 用户编号 118 | * 119 | * @return 是否更新成功 120 | */ 121 | boolean updatePasswordById(String password, int id); 122 | 123 | /** 124 | * 检查密码是否合法 125 | * 126 | * @param password 密码 127 | * 128 | * @return {@link Boolean} 129 | */ 130 | boolean checkPassword(String password); 131 | 132 | /** 133 | * 检查邮箱是否存在 134 | * 135 | * @param email 邮箱 136 | * 137 | * @return {@link Boolean} 138 | */ 139 | boolean emailExists(String email); 140 | 141 | /** 142 | * 更新用户基本信息 143 | * 144 | * @param id 编号 145 | * @param avatar 头像 146 | * @param realName 真实姓名 147 | * @param email 邮箱 148 | * 149 | * @return 是否更新成功 150 | */ 151 | boolean updateBasicInfoById(int id, String avatar, String realName, String email); 152 | 153 | /** 154 | * 用过用户名获取用户Id 155 | * 156 | * @param usernameOrEmail 用户名或邮箱 157 | * 158 | * @return 用户编号 159 | */ 160 | int getUserId(String usernameOrEmail); 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/impl/AuthServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service.impl; 2 | 3 | import com.zhazhapan.efo.config.SettingConfig; 4 | import com.zhazhapan.efo.dao.AuthDAO; 5 | import com.zhazhapan.efo.entity.Auth; 6 | import com.zhazhapan.efo.model.AuthRecord; 7 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 8 | import com.zhazhapan.efo.service.IAuthService; 9 | import com.zhazhapan.efo.util.BeanUtils; 10 | import com.zhazhapan.efo.util.ServiceUtils; 11 | import com.zhazhapan.modules.constant.ValueConsts; 12 | import com.zhazhapan.util.Checker; 13 | import com.zhazhapan.util.Formatter; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | 17 | import java.util.List; 18 | 19 | /** 20 | * @author pantao 21 | * @since 2018/2/1 22 | */ 23 | @Service 24 | public class AuthServiceImpl implements IAuthService { 25 | 26 | private final AuthDAO authDAO; 27 | 28 | @Autowired 29 | public AuthServiceImpl(AuthDAO authDAO) {this.authDAO = authDAO;} 30 | 31 | @Override 32 | public boolean addAuth(String files, String users, String auths) { 33 | if (Checker.isNotEmpty(files) && Checker.isNotEmpty(users) && Checker.isNotEmpty(auths)) { 34 | String[] file = files.split(ValueConsts.COMMA_SIGN); 35 | String[] user = users.split(ValueConsts.COMMA_SIGN); 36 | for (String f : file) { 37 | long fileId = Formatter.stringToLong(f); 38 | for (String u : user) { 39 | int userId = Formatter.stringToInt(u); 40 | if (Checker.isNull(authDAO.exists(userId, fileId))) { 41 | Auth auth = new Auth(userId, fileId); 42 | auth.setAuth(BeanUtils.getAuth(auths)); 43 | authDAO.insertAuth(auth); 44 | } 45 | } 46 | } 47 | } 48 | return true; 49 | } 50 | 51 | @Override 52 | public boolean batchDelete(String ids) { 53 | return Checker.isNotEmpty(ids) && authDAO.batchDelete(ids); 54 | } 55 | 56 | @Override 57 | public boolean updateAuth(long id, String auths) { 58 | int[] auth = BeanUtils.getAuth(auths); 59 | return authDAO.updateAuthById(id, auth[0], auth[1], auth[2], auth[3], auth[4]); 60 | } 61 | 62 | @Override 63 | public List listAuth(String usernameOrEmail, String fileName, int offset) { 64 | long fileId = ServiceUtils.getFileId(fileName); 65 | int userId = ServiceUtils.getUserId(usernameOrEmail); 66 | return authDAO.listAuthBy(ValueConsts.ZERO_INT, userId, fileId, fileName, offset); 67 | } 68 | 69 | @Override 70 | public AuthRecord getByFileIdAndUserId(long fileId, int userId) { 71 | List authRecords = authDAO.listAuthBy(ValueConsts.ZERO_INT, userId, fileId, ValueConsts 72 | .EMPTY_STRING, ValueConsts.ZERO_INT); 73 | if (Checker.isNotEmpty(authRecords)) { 74 | return authRecords.get(0); 75 | } 76 | return null; 77 | } 78 | 79 | @Override 80 | public boolean insertDefaultAuth(int userId, long fileId) { 81 | int[] defaultAuth = SettingConfig.getAuth(ConfigConsts.AUTH_DEFAULT_OF_SETTING); 82 | Auth auth = new Auth(userId, fileId); 83 | auth.setAuth(defaultAuth[0], defaultAuth[1], defaultAuth[2], defaultAuth[3], defaultAuth[4]); 84 | return insertAuth(auth); 85 | } 86 | 87 | @Override 88 | public boolean insertAuth(Auth auth) { 89 | return authDAO.insertAuth(auth); 90 | } 91 | 92 | @Override 93 | public boolean removeByFileId(long fileId) { 94 | return authDAO.removeAuthByFileId(fileId); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/impl/CategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service.impl; 2 | 3 | import com.zhazhapan.efo.dao.CategoryDAO; 4 | import com.zhazhapan.efo.entity.Category; 5 | import com.zhazhapan.efo.modules.constant.DefaultValues; 6 | import com.zhazhapan.efo.service.ICategoryService; 7 | import com.zhazhapan.util.Checker; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author pantao 15 | * @since 2018/1/30 16 | */ 17 | @Service 18 | public class CategoryServiceImpl implements ICategoryService { 19 | 20 | private final CategoryDAO categoryDAO; 21 | 22 | @Autowired 23 | public CategoryServiceImpl(CategoryDAO categoryDAO) {this.categoryDAO = categoryDAO;} 24 | 25 | @Override 26 | public boolean insert(String name) { 27 | return Checker.isNotNull(name) && categoryDAO.insertCategory(name); 28 | } 29 | 30 | @Override 31 | public boolean remove(int id) { 32 | return isCategorized(id) && categoryDAO.removeCategoryById(id); 33 | } 34 | 35 | @Override 36 | public boolean update(int id, String name) { 37 | return Checker.isNotEmpty(name) && isCategorized(id) && categoryDAO.updateNameById(id, name); 38 | } 39 | 40 | private boolean isCategorized(int id) { 41 | return !DefaultValues.UNCATEGORIZED.equals(getById(id).getName()); 42 | } 43 | 44 | @Override 45 | public Category getById(int id) { 46 | return categoryDAO.getCategoryById(id); 47 | } 48 | 49 | @Override 50 | public List list() { 51 | return categoryDAO.listCategory(); 52 | } 53 | 54 | @Override 55 | public int getIdByName(String name) { 56 | try { 57 | return categoryDAO.getIdByName(name); 58 | } catch (Exception e) { 59 | return Integer.MAX_VALUE; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/impl/CommonServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service.impl; 2 | 3 | import com.zhazhapan.efo.config.SettingConfig; 4 | import com.zhazhapan.efo.modules.constant.DefaultValues; 5 | import com.zhazhapan.efo.service.ICommonService; 6 | import com.zhazhapan.modules.constant.ValueConsts; 7 | import com.zhazhapan.util.Checker; 8 | import com.zhazhapan.util.FileExecutor; 9 | import com.zhazhapan.util.MailSender; 10 | import com.zhazhapan.util.RandomUtils; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.web.multipart.MultipartFile; 15 | 16 | import java.io.File; 17 | import java.io.IOException; 18 | 19 | /** 20 | * @author pantao 21 | * @since 2018/1/23 22 | */ 23 | @Service 24 | public class CommonServiceImpl implements ICommonService { 25 | 26 | private static final String EMAIL_TITLE = "请查收您的验证码"; 27 | private static Logger logger = LoggerFactory.getLogger(CommonServiceImpl.class); 28 | 29 | @Override 30 | public int sendVerifyCode(String email) { 31 | int code = RandomUtils.getRandomInteger(ValueConsts.VERIFY_CODE_FLOOR, ValueConsts.VERIFY_CODE_CEIL); 32 | String content = "

您的验证码:" + code + "



如非本人操作,请忽略本条消息。

"; 33 | try { 34 | MailSender.sendMail(email, EMAIL_TITLE, content); 35 | return code; 36 | } catch (Exception e) { 37 | logger.error(e.getMessage()); 38 | return 0; 39 | } 40 | } 41 | 42 | @Override 43 | public String uploadAvatar(MultipartFile multipartFile) { 44 | if (!multipartFile.isEmpty()) { 45 | String name = RandomUtils.getRandomStringOnlyLowerCase(ValueConsts.SIXTEEN_INT) + ValueConsts.DOT_SIGN + 46 | FileExecutor.getFileSuffix(multipartFile.getOriginalFilename()); 47 | if (Checker.isImage(name) && multipartFile.getSize() < ValueConsts.MB * DefaultValues.TWO_INT) { 48 | String path = SettingConfig.getAvatarStoragePath() + ValueConsts.SEPARATOR + name; 49 | try { 50 | FileExecutor.writeByteArrayToFile(new File(path), multipartFile.getBytes()); 51 | return name; 52 | } catch (IOException e) { 53 | logger.error("upload avatar error: " + e.getMessage()); 54 | } 55 | } 56 | } 57 | return ""; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/impl/ConfigServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service.impl; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.zhazhapan.efo.EfoApplication; 5 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 6 | import com.zhazhapan.efo.service.IConfigService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @author pantao 11 | * @since 2018/1/22 12 | */ 13 | @Service 14 | public class ConfigServiceImpl implements IConfigService { 15 | 16 | @Override 17 | public String getGlobalConfig() { 18 | JSONObject jsonObject = (JSONObject) EfoApplication.settings.getObjectUseEval(ConfigConsts 19 | .GLOBAL_OF_SETTINGS).clone(); 20 | jsonObject.remove(ConfigConsts.UPLOAD_PATH_OF_GLOBAL); 21 | jsonObject.remove(ConfigConsts.TOKEN_PATH_OF_GLOBAL); 22 | jsonObject.remove(ConfigConsts.UPLOAD_FORM_OF_SETTING); 23 | return jsonObject.toString(); 24 | } 25 | 26 | @Override 27 | public String getUserConfig() { 28 | JSONObject jsonObject = (JSONObject) EfoApplication.settings.getObjectUseEval(ConfigConsts.USER_OF_SETTINGS) 29 | .clone(); 30 | jsonObject.remove(ConfigConsts.EMAIL_CONFIG_OF_USER); 31 | return jsonObject.toString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/impl/DownloadedServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service.impl; 2 | 3 | import com.zhazhapan.efo.dao.DownloadedDAO; 4 | import com.zhazhapan.efo.model.DownloadRecord; 5 | import com.zhazhapan.efo.service.IDownloadedService; 6 | import com.zhazhapan.efo.util.ServiceUtils; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author pantao 14 | * @since 2018/2/1 15 | */ 16 | @Service 17 | public class DownloadedServiceImpl implements IDownloadedService { 18 | 19 | private final DownloadedDAO downloadDAO; 20 | 21 | @Autowired 22 | public DownloadedServiceImpl(DownloadedDAO downloadDAO) { 23 | this.downloadDAO = downloadDAO; 24 | } 25 | 26 | @Override 27 | public void insertDownload(int userId, long fileId) { 28 | downloadDAO.insertDownload(userId, fileId); 29 | } 30 | 31 | @Override 32 | public void removeByFileId(long fileId) { 33 | downloadDAO.removeByFileId(fileId); 34 | } 35 | 36 | @SuppressWarnings("unchecked") 37 | @Override 38 | public List list(String user, String file, String category, int offset) { 39 | return (List) ServiceUtils.invokeFileFilter(downloadDAO, "listDownloadedBy", user, file, 40 | category, offset); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/service/impl/UploadedServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service.impl; 2 | 3 | import com.zhazhapan.efo.dao.UploadedDAO; 4 | import com.zhazhapan.efo.model.UploadedRecord; 5 | import com.zhazhapan.efo.service.IUploadedService; 6 | import com.zhazhapan.efo.util.ServiceUtils; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author pantao 14 | * @since 2018/2/28 15 | */ 16 | @Service 17 | public class UploadedServiceImpl implements IUploadedService { 18 | 19 | private final UploadedDAO uploadedDAO; 20 | 21 | @Autowired 22 | public UploadedServiceImpl(UploadedDAO uploadedDAO) {this.uploadedDAO = uploadedDAO;} 23 | 24 | @SuppressWarnings("unchecked") 25 | @Override 26 | public List list(String user, String file, String category, int offset) { 27 | return (List) ServiceUtils.invokeFileFilter(uploadedDAO, "listUploadedBy", user, file, 28 | category, offset); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/util/BeanUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.util; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.zhazhapan.modules.constant.ValueConsts; 5 | import com.zhazhapan.util.Checker; 6 | import com.zhazhapan.util.Formatter; 7 | import com.zhazhapan.util.enums.FieldModifier; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.lang.reflect.InvocationTargetException; 12 | 13 | /** 14 | * @author pantao 15 | * @since 2018/1/18 16 | */ 17 | public class BeanUtils { 18 | 19 | private static final String ERROR_JSON = "{\"error\":\"internal error, please try again later\"}"; 20 | 21 | private static Logger logger = LoggerFactory.getLogger(BeanUtils.class); 22 | 23 | private BeanUtils() {} 24 | 25 | /** 26 | * 将权限字符串装换成权限数组 27 | * 28 | * @param auth 权限字符串 29 | * 30 | * @return 权限数组 31 | */ 32 | public static int[] getAuth(String auth) { 33 | int[] a = new int[5]; 34 | if (Checker.isNotEmpty(auth)) { 35 | String[] u = auth.split(ValueConsts.COMMA_SIGN); 36 | int len = Math.min(a.length, u.length); 37 | for (int i = 0; i < len; i++) { 38 | a[i] = Formatter.stringToInt(u[i]); 39 | } 40 | } 41 | return a; 42 | } 43 | 44 | /** 45 | * 将Bean转换成JSON 46 | * 47 | * @param object Bean对象 48 | * 49 | * @return {@link String} 50 | */ 51 | public static String toPrettyJson(Object object) { 52 | String result; 53 | try { 54 | result = com.zhazhapan.util.BeanUtils.toPrettyJson(object, FieldModifier.PRIVATE); 55 | } catch (IllegalAccessException e) { 56 | result = Formatter.formatJson(ERROR_JSON); 57 | logger.error(e.getMessage()); 58 | } 59 | return result; 60 | } 61 | 62 | /** 63 | * 将类属性装换成JSON(只能转换有get方法的) 64 | * 65 | * @param object 转换的对象 66 | * 67 | * @return {@link JSONObject} 68 | */ 69 | public static JSONObject beanToJson(Object object) { 70 | try { 71 | return com.zhazhapan.util.BeanUtils.beanToJson(object); 72 | } catch (IllegalAccessException | InvocationTargetException e) { 73 | logger.error(e.getMessage()); 74 | return null; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/util/CommonUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.util; 2 | 3 | import com.zhazhapan.efo.modules.constant.DefaultValues; 4 | import com.zhazhapan.modules.constant.ValueConsts; 5 | 6 | /** 7 | * @author pantao 8 | * @since 2018/1/29 9 | */ 10 | public class CommonUtils { 11 | 12 | private CommonUtils() {} 13 | 14 | /** 15 | * 将相对路径转换成绝对路径 16 | * 17 | * @param path 文件路径 18 | * 19 | * @return {@link String} 20 | */ 21 | public static String checkPath(String path) { 22 | String prefix = DefaultValues.COLON + ValueConsts.SEPARATOR; 23 | return path.startsWith(ValueConsts.SEPARATOR) || path.startsWith(prefix, ValueConsts.ONE_INT) ? path : 24 | DefaultValues.STORAGE_PATH + path; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/util/ControllerUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.util; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.zhazhapan.efo.modules.constant.DefaultValues; 5 | import com.zhazhapan.util.Checker; 6 | 7 | import javax.servlet.ServletOutputStream; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.File; 10 | import java.io.FileInputStream; 11 | import java.io.IOException; 12 | import java.io.UnsupportedEncodingException; 13 | 14 | /** 15 | * @author pantao 16 | * @since 2018/1/30 17 | */ 18 | public class ControllerUtils { 19 | 20 | private ControllerUtils() {} 21 | 22 | /** 23 | * 获取一个简单的响应状态 24 | * 25 | * @param isSuccess 是否操作成功 26 | * 27 | * @return 响应JSON字符串 28 | */ 29 | public static String getResponse(boolean isSuccess) { 30 | JSONObject jsonObject = new JSONObject(); 31 | if (isSuccess) { 32 | jsonObject.put("status", "success"); 33 | } else { 34 | jsonObject.put("status", "error"); 35 | } 36 | return jsonObject.toString(); 37 | } 38 | 39 | /** 40 | * 加载本地资源 41 | * 42 | * @param response 返回的Response 43 | * @param path 资源路径 44 | * @param download 直接下载 45 | */ 46 | public static void loadResource(HttpServletResponse response, String path, boolean download) throws IOException { 47 | if (Checker.isNotEmpty(path)) { 48 | File file = new File(path); 49 | if (download) { 50 | setResponseFileName(response, file.getName()); 51 | } 52 | FileInputStream in = new FileInputStream(file); 53 | ServletOutputStream os = response.getOutputStream(); 54 | byte[] b; 55 | while (in.available() > 0) { 56 | b = in.available() > 1024 ? new byte[1024] : new byte[in.available()]; 57 | in.read(b, 0, b.length); 58 | os.write(b, 0, b.length); 59 | } 60 | in.close(); 61 | os.flush(); 62 | os.close(); 63 | } else { 64 | response.sendRedirect(DefaultValues.NOT_FOUND_PAGE); 65 | } 66 | } 67 | 68 | /** 69 | * 设置响应头的文件名 70 | * 71 | * @param response {@link HttpServletResponse} 72 | * @param fileName 文件名 73 | */ 74 | public static void setResponseFileName(HttpServletResponse response, String fileName) throws 75 | UnsupportedEncodingException { 76 | response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("UTF-8"), 77 | "ISO-8859-1")); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/util/ServiceUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.util; 2 | 3 | import com.zhazhapan.efo.service.ICategoryService; 4 | import com.zhazhapan.efo.service.IFileService; 5 | import com.zhazhapan.efo.service.IUserService; 6 | import com.zhazhapan.modules.constant.ValueConsts; 7 | import com.zhazhapan.util.Checker; 8 | import com.zhazhapan.util.ReflectUtils; 9 | import org.apache.log4j.Logger; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.lang.reflect.InvocationTargetException; 14 | 15 | /** 16 | * @author pantao 17 | * @since 2018/2/28 18 | */ 19 | @Component 20 | public class ServiceUtils { 21 | 22 | private static IUserService userService; 23 | 24 | private static IFileService fileService; 25 | 26 | private static ICategoryService categoryService; 27 | 28 | private static Logger logger = Logger.getLogger(ServiceUtils.class); 29 | 30 | @Autowired 31 | public ServiceUtils(IUserService userService, IFileService fileService, ICategoryService categoryService) { 32 | ServiceUtils.userService = userService; 33 | ServiceUtils.fileService = fileService; 34 | ServiceUtils.categoryService = categoryService; 35 | } 36 | 37 | public static int getUserId(String usernameOrEmail) { 38 | return Checker.isEmpty(usernameOrEmail) ? ValueConsts.ZERO_INT : userService.getUserId(usernameOrEmail); 39 | } 40 | 41 | public static long getFileId(String fileName) { 42 | return Checker.isEmpty(fileName) ? ValueConsts.ZERO_INT : fileService.getFileId(fileName); 43 | } 44 | 45 | public static int getCategoryId(String categoryName) { 46 | return Checker.isEmpty(categoryName) ? ValueConsts.ZERO_INT : categoryService.getIdByName(categoryName); 47 | } 48 | 49 | public static Object invokeFileFilter(Object object, String methodName, String user, String file, String 50 | category, int offset) { 51 | try { 52 | return ReflectUtils.invokeMethodUseBasicType(object, methodName, new Object[]{getUserId(user), getFileId 53 | (file), file, getCategoryId(category), offset}); 54 | } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { 55 | logger.error(e.getMessage()); 56 | return null; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.zhazhapan.efo.annotation.AuthInterceptor; 4 | import com.zhazhapan.efo.enums.InterceptorLevel; 5 | import com.zhazhapan.efo.service.IAuthService; 6 | import com.zhazhapan.efo.util.ControllerUtils; 7 | import com.zhazhapan.util.Formatter; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiImplicitParam; 10 | import io.swagger.annotations.ApiImplicitParams; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.PathVariable; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestMethod; 16 | import org.springframework.web.bind.annotation.RestController; 17 | 18 | /** 19 | * @author pantao 20 | * @since 2018/3/8 21 | */ 22 | @RestController 23 | @RequestMapping("/auth") 24 | @Api(value = "/auth", description = "权限表相关操作") 25 | public class AuthController { 26 | 27 | private final IAuthService authService; 28 | 29 | @Autowired 30 | public AuthController(IAuthService authService) {this.authService = authService;} 31 | 32 | @ApiOperation(value = "添加权限记录", notes = "设置指定用户对指定文件的权限") 33 | @ApiImplicitParams({@ApiImplicitParam(name = "files", value = "文件", example = "file1,file2,file3", required = true), 34 | @ApiImplicitParam(name = "users", value = "用户", example = "user1,user2,user3", required = true), 35 | @ApiImplicitParam(name = "auths", value = "权限", example = "1,1,1,1", required = true)}) 36 | @AuthInterceptor(InterceptorLevel.ADMIN) 37 | @RequestMapping(value = "", method = RequestMethod.POST) 38 | public String add(String files, String users, String auths) { 39 | System.out.println("files: " + files + " users: " + users + " auths: " + auths); 40 | return ControllerUtils.getResponse(authService.addAuth(files, users, auths)); 41 | } 42 | 43 | @ApiOperation(value = "获取权限记录") 44 | @ApiImplicitParams({@ApiImplicitParam(name = "user", value = "用户", required = true), @ApiImplicitParam(name = 45 | "file", value = "文件", required = true), @ApiImplicitParam(name = "offset", value = "偏移量", required = true)}) 46 | @AuthInterceptor(InterceptorLevel.ADMIN) 47 | @RequestMapping(value = "/all", method = RequestMethod.GET) 48 | public String getAuth(String user, String file, int offset) { 49 | return Formatter.listToJson(authService.listAuth(user, file, offset)); 50 | } 51 | 52 | @ApiOperation(value = "更新权限记录") 53 | @ApiImplicitParams({@ApiImplicitParam(name = "auth", value = "权限值", required = true)}) 54 | @AuthInterceptor(InterceptorLevel.ADMIN) 55 | @RequestMapping(value = "/{id}", method = RequestMethod.PUT) 56 | public String updateAuth(@PathVariable("id") long id, String auth) { 57 | return ControllerUtils.getResponse(authService.updateAuth(id, auth)); 58 | } 59 | 60 | @ApiOperation(value = "批量删除权限记录") 61 | @AuthInterceptor(InterceptorLevel.ADMIN) 62 | @RequestMapping(value = "/batch/{ids}", method = RequestMethod.DELETE) 63 | public String batchDelete(@PathVariable("ids") String ids) { 64 | return ControllerUtils.getResponse(authService.batchDelete(ids)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/CategoryController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.zhazhapan.efo.annotation.AuthInterceptor; 4 | import com.zhazhapan.efo.entity.Category; 5 | import com.zhazhapan.efo.enums.InterceptorLevel; 6 | import com.zhazhapan.efo.service.ICategoryService; 7 | import com.zhazhapan.efo.util.ControllerUtils; 8 | import com.zhazhapan.modules.constant.ValueConsts; 9 | import com.zhazhapan.util.Checker; 10 | import com.zhazhapan.util.Formatter; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiImplicitParam; 13 | import io.swagger.annotations.ApiOperation; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RequestMethod; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | /** 21 | * @author pantao 22 | * @since 2018/1/30 23 | */ 24 | @RestController 25 | @RequestMapping("/category") 26 | @Api(value = "/category", description = "文件分类相关操作") 27 | public class CategoryController { 28 | 29 | private final ICategoryService categoryService; 30 | 31 | @Autowired 32 | public CategoryController(ICategoryService categoryService) {this.categoryService = categoryService;} 33 | 34 | @ApiOperation(value = "新增一个分类") 35 | @AuthInterceptor(InterceptorLevel.ADMIN) 36 | @RequestMapping(value = "/{name}", method = RequestMethod.POST) 37 | public String add(@PathVariable("name") String name) { 38 | return ControllerUtils.getResponse(categoryService.insert(name)); 39 | } 40 | 41 | @ApiOperation(value = "更新分类名称") 42 | @ApiImplicitParam(name = "name", value = "新的名称", required = true) 43 | @AuthInterceptor(InterceptorLevel.ADMIN) 44 | @RequestMapping(value = "/{id}", method = RequestMethod.PUT) 45 | public String update(@PathVariable("id") int id, String name) { 46 | boolean isSuccess = Checker.isNotEmpty(name) && categoryService.update(id, name); 47 | return ControllerUtils.getResponse(isSuccess); 48 | } 49 | 50 | @ApiOperation(value = "删除一个分类") 51 | @AuthInterceptor(InterceptorLevel.ADMIN) 52 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 53 | public String remove(@PathVariable("id") int id) { 54 | return ControllerUtils.getResponse(categoryService.remove(id)); 55 | } 56 | 57 | @ApiOperation(value = "获取一个分类") 58 | @AuthInterceptor(InterceptorLevel.NONE) 59 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 60 | public String getById(@PathVariable("id") int id) { 61 | Category category = categoryService.getById(id); 62 | if (Checker.isNull(category)) { 63 | return ControllerUtils.getResponse(ValueConsts.FALSE); 64 | } else { 65 | return category.toString(); 66 | } 67 | } 68 | 69 | @ApiOperation(value = "获取所有分类") 70 | @AuthInterceptor(InterceptorLevel.NONE) 71 | @RequestMapping(value = "/all", method = RequestMethod.GET) 72 | public String getAll() { 73 | return Formatter.listToJson(categoryService.list()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/CommonController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.zhazhapan.efo.annotation.AuthInterceptor; 5 | import com.zhazhapan.efo.config.SettingConfig; 6 | import com.zhazhapan.efo.enums.InterceptorLevel; 7 | import com.zhazhapan.efo.modules.constant.DefaultValues; 8 | import com.zhazhapan.efo.service.ICommonService; 9 | import com.zhazhapan.efo.util.ControllerUtils; 10 | import com.zhazhapan.modules.constant.ValueConsts; 11 | import com.zhazhapan.util.Checker; 12 | import io.swagger.annotations.Api; 13 | import io.swagger.annotations.ApiImplicitParam; 14 | import io.swagger.annotations.ApiOperation; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.web.bind.annotation.*; 19 | import org.springframework.web.multipart.MultipartFile; 20 | 21 | import javax.servlet.http.HttpServletRequest; 22 | import javax.servlet.http.HttpServletResponse; 23 | import java.io.IOException; 24 | 25 | /** 26 | * @author pantao 27 | * @since 2018/1/23 28 | */ 29 | @RestController 30 | @RequestMapping("/common") 31 | @Api(value = "/common", description = "公共接口") 32 | public class CommonController { 33 | 34 | private static Logger logger = LoggerFactory.getLogger(ConfigController.class); 35 | 36 | private final ICommonService commonService; 37 | 38 | private final HttpServletRequest request; 39 | 40 | private final JSONObject jsonObject; 41 | 42 | @Autowired 43 | public CommonController(ICommonService commonService, HttpServletRequest request, JSONObject jsonObject) { 44 | this.commonService = commonService; 45 | this.request = request; 46 | this.jsonObject = jsonObject; 47 | } 48 | 49 | @ApiOperation(value = "获取头像资源") 50 | @AuthInterceptor(InterceptorLevel.NONE) 51 | @RequestMapping(value = "/avatar/{name}", method = RequestMethod.GET) 52 | public void getAvatar(HttpServletResponse response, @PathVariable("name") String name) throws IOException { 53 | String path = SettingConfig.getAvatarStoragePath() + ValueConsts.SEPARATOR + name; 54 | ControllerUtils.loadResource(response, path, ValueConsts.FALSE); 55 | } 56 | 57 | @ApiOperation(value = "上传头像") 58 | @ApiImplicitParam(name = "multipartFile", value = "头像", required = true) 59 | @AuthInterceptor(InterceptorLevel.USER) 60 | @RequestMapping(value = "/avatar", method = RequestMethod.POST) 61 | public String avatarUpload(@RequestParam("file") MultipartFile multipartFile) { 62 | String name = commonService.uploadAvatar(multipartFile); 63 | if (Checker.isEmpty(name)) { 64 | jsonObject.put("error", "文件格式不合法"); 65 | } else { 66 | jsonObject.put("success", "/common/avatar/" + name); 67 | } 68 | return jsonObject.toString(); 69 | } 70 | 71 | @ApiOperation(value = "发送验证码") 72 | @AuthInterceptor(InterceptorLevel.NONE) 73 | @RequestMapping(value = "/{email}/code", method = RequestMethod.POST) 74 | public String sendVerifyCode(@PathVariable("email") String email) { 75 | int code = commonService.sendVerifyCode(email); 76 | if (code > 0) { 77 | request.getSession().setAttribute(DefaultValues.CODE_STRING, code); 78 | logger.info("verify code: " + code); 79 | jsonObject.put("status", "success"); 80 | } else { 81 | jsonObject.put("status", "error"); 82 | } 83 | return jsonObject.toString(); 84 | } 85 | 86 | @ApiOperation(value = "验证验证码是否正确") 87 | @AuthInterceptor(InterceptorLevel.NONE) 88 | @RequestMapping(value = "/{code}/verification", method = RequestMethod.PUT) 89 | public String verifyCode(@PathVariable("code") String code) { 90 | boolean isSuccess = Checker.checkNull(code).equals(String.valueOf(request.getSession().getAttribute 91 | (DefaultValues.CODE_STRING))); 92 | return ControllerUtils.getResponse(isSuccess); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/ConfigController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.annotation.AuthInterceptor; 5 | import com.zhazhapan.efo.entity.User; 6 | import com.zhazhapan.efo.enums.InterceptorLevel; 7 | import com.zhazhapan.efo.modules.constant.DefaultValues; 8 | import com.zhazhapan.efo.service.IConfigService; 9 | import com.zhazhapan.modules.constant.ValueConsts; 10 | import com.zhazhapan.util.FileExecutor; 11 | import com.zhazhapan.util.NetUtils; 12 | import io.swagger.annotations.Api; 13 | import io.swagger.annotations.ApiImplicitParam; 14 | import io.swagger.annotations.ApiOperation; 15 | import org.apache.log4j.Logger; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestMethod; 19 | import org.springframework.web.bind.annotation.RestController; 20 | 21 | import javax.servlet.http.HttpServletRequest; 22 | import java.io.IOException; 23 | 24 | /** 25 | * @author pantao 26 | * @since 2018/1/22 27 | */ 28 | @RestController 29 | @RequestMapping("/config") 30 | @Api(value = "/config", description = "配置文件的相关操作") 31 | public class ConfigController { 32 | 33 | private static Logger logger = Logger.getLogger(ConfigController.class); 34 | 35 | private final IConfigService configService; 36 | 37 | private final HttpServletRequest request; 38 | 39 | @Autowired 40 | public ConfigController(IConfigService configService, HttpServletRequest request) { 41 | this.configService = configService; 42 | this.request = request; 43 | } 44 | 45 | @ApiOperation(value = "更新配置文件") 46 | @ApiImplicitParam(name = "config", value = "配置文件内容", required = true) 47 | @AuthInterceptor(InterceptorLevel.ADMIN) 48 | @RequestMapping(value = "", method = RequestMethod.PUT) 49 | public String updateConfig(String config) { 50 | User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING); 51 | if (user.getPermission() > ValueConsts.TWO_INT) { 52 | EfoApplication.settings.setJsonObject(config); 53 | //打包成jar之后无法修改config.json文件 54 | try { 55 | FileExecutor.saveFile(NetUtils.urlToString(EfoApplication.class.getResource(DefaultValues 56 | .SETTING_PATH)), EfoApplication.settings.toString()); 57 | } catch (IOException e) { 58 | logger.error(e.getMessage()); 59 | return "{\"message\":\"internal error, cannot save\"}"; 60 | } 61 | return "{\"message\":\"saved successfully\"}"; 62 | } else { 63 | return "{\"message\":\"permission denied\"}"; 64 | } 65 | } 66 | 67 | @ApiOperation(value = "获取配置文件内容") 68 | @AuthInterceptor(InterceptorLevel.ADMIN) 69 | @RequestMapping(value = "/all", method = RequestMethod.GET) 70 | public String getAll() { 71 | User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING); 72 | if (user.getPermission() > ValueConsts.TWO_INT) { 73 | return EfoApplication.settings.toString(); 74 | } else { 75 | return "{\"message\":\"permission denied\"}"; 76 | } 77 | } 78 | 79 | @ApiOperation(value = "获取配置文件中的全局相关配置内容") 80 | @AuthInterceptor(InterceptorLevel.NONE) 81 | @RequestMapping(value = "/global", method = RequestMethod.GET) 82 | public String getGlobalConfig() { 83 | return configService.getGlobalConfig(); 84 | } 85 | 86 | @ApiOperation(value = "获取配置文件中的用户相关配置内容") 87 | @AuthInterceptor(InterceptorLevel.NONE) 88 | @RequestMapping(value = "/user", method = RequestMethod.GET) 89 | public String getUserConfig() { 90 | return configService.getUserConfig(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/CustomErrorController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.zhazhapan.efo.annotation.AuthInterceptor; 4 | import com.zhazhapan.efo.enums.InterceptorLevel; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.boot.web.servlet.error.ErrorController; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.ResponseStatus; 12 | import springfox.documentation.annotations.ApiIgnore; 13 | 14 | /** 15 | * @author pantao 16 | * @since 2018/1/22 17 | */ 18 | @Controller 19 | @Api(description = "错误页面映射") 20 | public class CustomErrorController implements ErrorController { 21 | 22 | @ApiOperation(value = "异常页面") 23 | @AuthInterceptor(InterceptorLevel.NONE) 24 | @RequestMapping("/exception") 25 | public String handleError() { 26 | return "error"; 27 | } 28 | 29 | @ApiOperation(value = "404、错误页面") 30 | @AuthInterceptor(InterceptorLevel.NONE) 31 | @RequestMapping("/error") 32 | @ResponseStatus(HttpStatus.NOT_FOUND) 33 | public String handleNotFound() { 34 | return "/404"; 35 | } 36 | 37 | @ApiIgnore 38 | @Override 39 | public String getErrorPath() { 40 | return "/error"; 41 | } 42 | } -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/DownloadedController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.zhazhapan.efo.annotation.AuthInterceptor; 4 | import com.zhazhapan.efo.enums.InterceptorLevel; 5 | import com.zhazhapan.efo.service.IDownloadedService; 6 | import com.zhazhapan.util.Formatter; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiImplicitParam; 9 | import io.swagger.annotations.ApiImplicitParams; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | /** 17 | * @author pantao 18 | * @since 2018/2/9 19 | */ 20 | @RestController 21 | @RequestMapping(value = "/downloaded") 22 | @Api(value = "/downloaded", description = "下载记录相关操作") 23 | public class DownloadedController { 24 | 25 | private final IDownloadedService downloadService; 26 | 27 | @Autowired 28 | public DownloadedController(IDownloadedService downloadService) { 29 | this.downloadService = downloadService; 30 | } 31 | 32 | @ApiOperation(value = "获取文件下载记录") 33 | @ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name = 34 | "指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam(name = 35 | "offset", value = "偏移量", required = true)}) 36 | @AuthInterceptor(InterceptorLevel.ADMIN) 37 | @RequestMapping(value = "all", method = RequestMethod.GET) 38 | public String getAll(String user, String file, String category, int offset) { 39 | return Formatter.listToJson(downloadService.list(user, file, category, offset)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/FileMangerController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.zhazhapan.efo.annotation.AuthInterceptor; 5 | import com.zhazhapan.efo.enums.InterceptorLevel; 6 | import com.zhazhapan.efo.service.IFileManagerService; 7 | import com.zhazhapan.efo.util.ControllerUtils; 8 | import com.zhazhapan.modules.constant.ValueConsts; 9 | import com.zhazhapan.util.ArrayUtils; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RestController; 15 | import org.springframework.web.multipart.MultipartFile; 16 | import org.springframework.web.multipart.MultipartHttpServletRequest; 17 | import springfox.documentation.annotations.ApiIgnore; 18 | 19 | import javax.servlet.http.HttpServletResponse; 20 | import java.io.IOException; 21 | import java.util.Map; 22 | 23 | /** 24 | * see api doc 25 | * 26 | * @author pantao 27 | * @since 2018/1/29 28 | */ 29 | @ApiIgnore 30 | @RestController 31 | @RequestMapping("/filemanager") 32 | @AuthInterceptor(InterceptorLevel.SYSTEM) 33 | public class FileMangerController { 34 | 35 | private final IFileManagerService fileManagerService; 36 | 37 | private final JSONObject jsonObject; 38 | 39 | @Autowired 40 | public FileMangerController(IFileManagerService fileManagerService, JSONObject jsonObject) { 41 | this.fileManagerService = fileManagerService; 42 | this.jsonObject = jsonObject; 43 | } 44 | 45 | @AuthInterceptor(InterceptorLevel.SYSTEM) 46 | @RequestMapping(value = "/multidownload", method = RequestMethod.GET) 47 | public void multiDownload(HttpServletResponse response, String[] items, String toFilename) throws IOException { 48 | ControllerUtils.setResponseFileName(response, toFilename); 49 | fileManagerService.multiDownload(response, items, toFilename); 50 | } 51 | 52 | @AuthInterceptor(InterceptorLevel.SYSTEM) 53 | @RequestMapping(value = "/download", method = RequestMethod.GET) 54 | public void download(HttpServletResponse response, String path) throws IOException { 55 | ControllerUtils.loadResource(response, path, ValueConsts.TRUE); 56 | } 57 | 58 | /** 59 | * 暂时没有找到更好的解决方案 60 | * 61 | * @param destination 目的 62 | * 63 | * @return 响应结果 64 | */ 65 | @AuthInterceptor(InterceptorLevel.SYSTEM) 66 | @RequestMapping(value = "/upload", method = RequestMethod.POST) 67 | public String upload(String destination, MultipartHttpServletRequest request) { 68 | Map fileMap = request.getFileMap(); 69 | MultipartFile[] files = ArrayUtils.mapToArray(fileMap, MultipartFile.class); 70 | jsonObject.put("result", fileManagerService.upload(destination, files)); 71 | return jsonObject.toJSONString(); 72 | } 73 | 74 | @AuthInterceptor(InterceptorLevel.SYSTEM) 75 | @RequestMapping(value = "/extract", method = RequestMethod.POST) 76 | public String extract(@RequestBody JSONObject json) { 77 | jsonObject.put("result", fileManagerService.extract(json)); 78 | return jsonObject.toJSONString(); 79 | } 80 | 81 | @AuthInterceptor(InterceptorLevel.SYSTEM) 82 | @RequestMapping(value = "/compress", method = RequestMethod.POST) 83 | public String compress(@RequestBody JSONObject json) { 84 | jsonObject.put("result", fileManagerService.compress(json)); 85 | return jsonObject.toJSONString(); 86 | } 87 | 88 | @AuthInterceptor(InterceptorLevel.SYSTEM) 89 | @RequestMapping(value = "/permission", method = RequestMethod.POST) 90 | public String setPermission(@RequestBody JSONObject json) { 91 | jsonObject.put("result", fileManagerService.setPermission(json)); 92 | return jsonObject.toJSONString(); 93 | } 94 | 95 | @AuthInterceptor(InterceptorLevel.SYSTEM) 96 | @RequestMapping(value = "/folder", method = RequestMethod.POST) 97 | public String createFolder(@RequestBody JSONObject json) { 98 | jsonObject.put("result", fileManagerService.createFolder(json)); 99 | return jsonObject.toJSONString(); 100 | } 101 | 102 | @AuthInterceptor(InterceptorLevel.SYSTEM) 103 | @RequestMapping(value = "/content", method = RequestMethod.POST) 104 | public String getContent(@RequestBody JSONObject json) { 105 | jsonObject.put("result", fileManagerService.getContent(json)); 106 | return jsonObject.toJSONString(); 107 | } 108 | 109 | @AuthInterceptor(InterceptorLevel.SYSTEM) 110 | @RequestMapping(value = "/edit", method = RequestMethod.POST) 111 | public String edit(@RequestBody JSONObject json) { 112 | jsonObject.put("result", fileManagerService.edit(json)); 113 | return jsonObject.toJSONString(); 114 | } 115 | 116 | @AuthInterceptor(InterceptorLevel.SYSTEM) 117 | @RequestMapping(value = "/remove", method = RequestMethod.POST) 118 | public String remove(@RequestBody JSONObject json) { 119 | jsonObject.put("result", fileManagerService.remove(json)); 120 | return jsonObject.toJSONString(); 121 | } 122 | 123 | @AuthInterceptor(InterceptorLevel.SYSTEM) 124 | @RequestMapping(value = "/copy", method = RequestMethod.POST) 125 | public String copy(@RequestBody JSONObject json) { 126 | jsonObject.put("result", fileManagerService.copy(json)); 127 | return jsonObject.toJSONString(); 128 | } 129 | 130 | @AuthInterceptor(InterceptorLevel.SYSTEM) 131 | @RequestMapping(value = "/move", method = RequestMethod.POST) 132 | public String move(@RequestBody JSONObject json) { 133 | jsonObject.put("result", fileManagerService.move(json)); 134 | return jsonObject.toJSONString(); 135 | } 136 | 137 | @AuthInterceptor(InterceptorLevel.SYSTEM) 138 | @RequestMapping(value = "/rename", method = RequestMethod.POST) 139 | public String rename(@RequestBody JSONObject json) { 140 | jsonObject.put("result", fileManagerService.rename(json)); 141 | return jsonObject.toJSONString(); 142 | } 143 | 144 | @AuthInterceptor(InterceptorLevel.SYSTEM) 145 | @RequestMapping(value = "/list", method = RequestMethod.POST) 146 | public String list(@RequestBody JSONObject json) { 147 | jsonObject.put("result", fileManagerService.list(json)); 148 | return jsonObject.toJSONString(); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/UploadedController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.zhazhapan.efo.annotation.AuthInterceptor; 4 | import com.zhazhapan.efo.enums.InterceptorLevel; 5 | import com.zhazhapan.efo.service.IUploadedService; 6 | import com.zhazhapan.util.Formatter; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiImplicitParam; 9 | import io.swagger.annotations.ApiImplicitParams; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | /** 17 | * @author pantao 18 | * @since 2018/2/28 19 | */ 20 | @RestController 21 | @RequestMapping(value = "/uploaded") 22 | @Api(value = "/uploaded", description = "上传记录相关操作") 23 | public class UploadedController { 24 | 25 | private final IUploadedService uploadedService; 26 | 27 | @Autowired 28 | public UploadedController(IUploadedService uploadedService) {this.uploadedService = uploadedService;} 29 | 30 | @ApiOperation(value = "获取文件上传记录") 31 | @ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name = 32 | "指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam(name = 33 | "offset", value = "偏移量", required = true)}) 34 | @AuthInterceptor(InterceptorLevel.ADMIN) 35 | @RequestMapping(value = "all", method = RequestMethod.GET) 36 | public String getAll(String user, String file, String category, int offset) { 37 | return Formatter.listToJson(uploadedService.list(user, file, category, offset)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/zhazhapan/efo/web/controller/ViewController.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.web.controller; 2 | 3 | import com.zhazhapan.efo.annotation.AuthInterceptor; 4 | import com.zhazhapan.efo.enums.InterceptorLevel; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | import springfox.documentation.annotations.ApiIgnore; 12 | 13 | /** 14 | * @author pantao 15 | * @since 2018/1/25 16 | */ 17 | @Controller 18 | @Api(description = "视图页面映射") 19 | public class ViewController { 20 | 21 | @ApiOperation(value = "远程文件管理页面") 22 | @AuthInterceptor(InterceptorLevel.SYSTEM) 23 | @RequestMapping(value = "/filemanager", method = RequestMethod.GET) 24 | public String fileManager() { 25 | return "/filemanager"; 26 | } 27 | 28 | @ApiOperation(value = "上传页面") 29 | @AuthInterceptor 30 | @RequestMapping(value = "/upload", method = RequestMethod.GET) 31 | public String upload() { 32 | return "/upload"; 33 | } 34 | 35 | @ApiOperation(value = "首页") 36 | @AuthInterceptor(InterceptorLevel.NONE) 37 | @RequestMapping(value = "/index", method = RequestMethod.GET) 38 | public String index() { 39 | return "/index"; 40 | } 41 | 42 | @ApiOperation(value = "登录、注册、忘记密码页面") 43 | @AuthInterceptor(InterceptorLevel.NONE) 44 | @RequestMapping(value = "/signin", method = RequestMethod.GET) 45 | public String signin() { 46 | return "/signin"; 47 | } 48 | 49 | @ApiOperation(value = "管理员页面") 50 | @AuthInterceptor(InterceptorLevel.ADMIN) 51 | @RequestMapping(value = "/admin", method = RequestMethod.GET) 52 | public String admin() { 53 | return "/admin"; 54 | } 55 | 56 | @ApiIgnore 57 | @AuthInterceptor(InterceptorLevel.NONE) 58 | @RequestMapping(value = "/test", method = RequestMethod.GET) 59 | @ResponseBody 60 | public String test() { 61 | return "test"; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | mybatis.type-aliases-package=com.zhazhapan.efo.entity 3 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 4 | spring.datasource.url=jdbc:mysql://localhost:3306/efo?useUnicode=true&characterEncoding=utf-8&useSSL=true 5 | spring.datasource.username=zhazhapan 6 | spring.datasource.password=zhazhapan 7 | spring.jpa.show-sql=true 8 | spring.servlet.multipart.max-file-size=1099511627776 9 | spring.servlet.multipart.max-request-size=1099511627776 10 | spring.devtools.restart.enabled=false 11 | spring.devtools.restart.additional-paths=src/main 12 | #spring.mvc.favicon.enabled=false -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | mybatis.type-aliases-package=com.zhazhapan.efo.entity 3 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 4 | spring.datasource.url=jdbc:mysql://localhost:3306/efo?useUnicode=true&characterEncoding=utf-8&useSSL=true 5 | spring.datasource.username=zhazhapan 6 | spring.datasource.password=zhazhapan 7 | spring.jpa.show-sql=true 8 | spring.servlet.multipart.max-file-size=1099511627776 9 | spring.servlet.multipart.max-request-size=1099511627776 10 | spring.devtools.restart.enabled=false 11 | spring.devtools.restart.additional-paths=src/main 12 | #spring.profiles.active=prod 13 | #spring.mvc.favicon.enabled=false 14 | swagger.enabled=true 15 | 16 | swagger.title=线上文件管理系统 17 | swagger.description=上传、下载、分享、远程文件管理 18 | swagger.version=1.2 19 | swagger.license=MIT 20 | swagger.licenseUrl=https://opensource.org/licenses/MIT 21 | swagger.termsOfServiceUrl=https://github.com/code4everything/efo 22 | swagger.contact.name=zhazhapan 23 | swagger.contact.url=https://github.zhazhapan.com 24 | swagger.contact.email=zhazhapan.com 25 | swagger.base-package=com.zhazhapan.efo 26 | swagger.base-path=/** 27 | swagger.exclude-path=/error, /ops/** 28 | 29 | swagger.apply-default-response-messages=false 30 | swagger.global-response-message.get[0].code=401 31 | swagger.global-response-message.get[0].message=401get 32 | swagger.global-response-message.get[1].code=500 33 | swagger.global-response-message.get[1].message=500get 34 | swagger.global-response-message.get[1].modelRef=ERROR 35 | swagger.global-response-message.post[0].code=500 36 | swagger.global-response-message.post[0].message=500post 37 | swagger.global-response-message.post[0].modelRef=ERROR -------------------------------------------------------------------------------- /src/main/resources/assets/css/nav.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | /* 以下实际使用若已初始化可删除 .jq-nav height父级需逐级设置为100%*/ 3 | 4 | body, ul { 5 | margin: 0; 6 | padding: 0 7 | } 8 | 9 | body { 10 | -webkit-text-size-adjust: 100%; 11 | } 12 | 13 | li { 14 | list-style: none 15 | } 16 | 17 | a { 18 | text-decoration: none; 19 | } 20 | 21 | /* 以上实际使用若已初始化可删除 */ 22 | 23 | /* nav */ 24 | .jq-nav { 25 | width: 220px; 26 | height: 100%; 27 | background: #263238; 28 | transition: all .3s; 29 | } 30 | 31 | .jq-nav a { 32 | display: block; 33 | overflow: hidden; 34 | padding-left: 20px; 35 | line-height: 46px; 36 | max-height: 46px; 37 | color: #ABB1B7; 38 | transition: all .3s; 39 | } 40 | 41 | .jq-nav a span { 42 | margin-left: 30px; 43 | } 44 | 45 | .jq-nav-item { 46 | position: relative; 47 | } 48 | 49 | .jq-nav-item.jq-nav-show { 50 | border-bottom: none; 51 | } 52 | 53 | .jq-nav-item ul { 54 | display: none; 55 | background: rgba(0, 0, 0, .1); 56 | } 57 | 58 | .jq-nav-item.jq-nav-show ul { 59 | display: block; 60 | } 61 | 62 | .jq-nav-item > a:before { 63 | content: ""; 64 | position: absolute; 65 | left: 0; 66 | width: 2px; 67 | height: 46px; 68 | background: #34A0CE; 69 | opacity: 0; 70 | transition: all .3s; 71 | } 72 | 73 | .jq-nav .jq-nav-icon { 74 | font-size: 20px; 75 | position: absolute; 76 | margin-left: -1px; 77 | } 78 | 79 | /* 此处修改导航图标 可自定义iconfont 替换*/ 80 | .icon_1::after { 81 | content: "\e62b"; 82 | } 83 | 84 | .icon_2::after { 85 | content: "\e669"; 86 | } 87 | 88 | .icon_3::after { 89 | content: "\e61d"; 90 | } 91 | 92 | /*---------------------*/ 93 | .jq-nav-more { 94 | float: right; 95 | margin-right: 20px; 96 | font-size: 12px; 97 | transition: transform .3s; 98 | } 99 | 100 | /* 此处为导航右侧箭头 如果自定义iconfont 也需要替换*/ 101 | .jq-nav-more::after { 102 | content: "\e621"; 103 | } 104 | 105 | /*---------------------*/ 106 | .jq-nav-show .jq-nav-more { 107 | transform: rotate(90deg); 108 | } 109 | 110 | .jq-nav-show, .jq-nav-item > a:hover { 111 | color: #FFF; 112 | background: rgba(0, 0, 0, .1); 113 | } 114 | 115 | .jq-nav-show > a:before, .jq-nav-item > a:hover:before { 116 | opacity: 1; 117 | } 118 | 119 | .jq-nav-item li:hover a { 120 | color: #FFF; 121 | background: rgba(0, 0, 0, .1); 122 | } 123 | 124 | /* nav-mini */ 125 | .jq-nav-mini.jq-nav { 126 | width: 60px; 127 | } 128 | 129 | .jq-nav-mini.jq-nav .jq-nav-icon { /* margin-left:-2px; */ 130 | } 131 | 132 | .jq-nav-mini.jq-nav .jq-nav-item > a span { 133 | display: none; 134 | } 135 | 136 | .jq-nav-mini.jq-nav .jq-nav-more { 137 | margin-right: -20px; 138 | } 139 | 140 | .jq-nav-mini.jq-nav .jq-nav-item ul { 141 | position: absolute; 142 | top: 0; 143 | left: 60px; 144 | width: 180px; 145 | z-index: 99; 146 | background: #3C474C; 147 | overflow: hidden; 148 | } 149 | 150 | .jq-nav-mini.jq-nav .jq-nav-item:hover { 151 | background: rgba(255, 255, 255, .1); 152 | } 153 | 154 | .jq-nav-mini.jq-nav .jq-nav-item:hover .jq-nav-item a { 155 | color: #FFF; 156 | } 157 | 158 | .jq-nav-mini.jq-nav .jq-nav-item:hover a:before { 159 | opacity: 1; 160 | } 161 | 162 | .jq-nav-mini.jq-nav .jq-nav-item:hover ul { 163 | display: block; 164 | } 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /src/main/resources/assets/css/style.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | background-size: cover; 3 | margin: 0; 4 | padding: 0; 5 | background: #F5F5F5; 6 | min-height: 100vh; 7 | } 8 | 9 | .avatar { 10 | height: 4rem; 11 | width: 4rem; 12 | } 13 | 14 | .content-box { 15 | background: white; 16 | z-index: 1; 17 | } 18 | 19 | .center-vertical { 20 | position: absolute; 21 | top: 1rem; 22 | left: 0; 23 | right: 0; 24 | bottom: 3rem; 25 | height: auto; 26 | margin: auto; 27 | } 28 | 29 | .padding-0 { 30 | padding: 0; 31 | } 32 | 33 | .padding-top-0 { 34 | padding-top: 0; 35 | } 36 | 37 | .padding-top-1 { 38 | padding-top: 1%; 39 | } 40 | 41 | .padding-top-3 { 42 | padding-top: 3%; 43 | } 44 | 45 | .padding-right-0 { 46 | padding-right: 0; 47 | } 48 | 49 | .bottom { 50 | position: relative; 51 | left: 0; 52 | right: 0; 53 | bottom: 4rem; 54 | height: auto; 55 | margin: auto; 56 | } 57 | 58 | .text-justify-all { 59 | text-align: justify; 60 | text-align-last: justify; 61 | } 62 | 63 | .show { 64 | display: block; 65 | } 66 | 67 | .hide { 68 | display: none; 69 | } 70 | 71 | input[type=checkbox] { 72 | border: 1px solid #b4b9be; 73 | background: #fff; 74 | color: #555; 75 | clear: none; 76 | cursor: pointer; 77 | display: inline-block; 78 | line-height: 0; 79 | height: 16px; 80 | margin: -4px 4px 0 0; 81 | outline: 0; 82 | text-align: center; 83 | vertical-align: middle; 84 | box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1); 85 | transition: .05s border-color ease-in-out; 86 | } 87 | 88 | .font-1 { 89 | font-size: 1rem; 90 | } 91 | 92 | .width-60-vm { 93 | width: 60vw; 94 | } -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-brands-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-brands-400.eot -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-brands-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-brands-400.woff -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-regular-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-regular-400.eot -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-regular-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-regular-400.woff -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-solid-900.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-solid-900.eot -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-solid-900.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-solid-900.woff -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/glyphicons-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/glyphicons-regular.eot -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/glyphicons-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/glyphicons-regular.ttf -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/glyphicons-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/glyphicons-regular.woff -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/iconfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/iconfont.eot -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/iconfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/iconfont.ttf -------------------------------------------------------------------------------- /src/main/resources/assets/fonts/iconfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/fonts/iconfont.woff -------------------------------------------------------------------------------- /src/main/resources/assets/img/default-user.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/img/default-user.jpg -------------------------------------------------------------------------------- /src/main/resources/assets/img/efo-favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/img/efo-favicon.png -------------------------------------------------------------------------------- /src/main/resources/assets/img/loading-sm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/img/loading-sm.gif -------------------------------------------------------------------------------- /src/main/resources/assets/img/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/img/loading.gif -------------------------------------------------------------------------------- /src/main/resources/assets/img/mini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/img/mini.png -------------------------------------------------------------------------------- /src/main/resources/assets/js/default.js: -------------------------------------------------------------------------------- 1 | var footer = ""; 2 | 3 | var globalConfig = {}; 4 | 5 | var userConfig = {}; 6 | 7 | /** 8 | * 服务器响应提示 9 | */ 10 | function responseTip(data) { 11 | layer.closeAll(); 12 | var json = JSON.parse(data); 13 | if (json.status === "success") { 14 | layer.msg("保存成功"); 15 | } else { 16 | alerts("保存失败,请稍后重新尝试"); 17 | } 18 | } 19 | 20 | function checkPassword(password, passwordConfirm) { 21 | return password.length >= userConfig.password.minLength && password.length <= userConfig.password.maxLength && password === passwordConfirm; 22 | } 23 | 24 | function sendVerifyCode(email, eventSrc) { 25 | if (isEmail(email)) { 26 | layer.load(1); 27 | $.post("/common/" + email + "/code", function (data) { 28 | layer.closeAll(); 29 | var json = JSON.parse(data); 30 | if (json.status === "success") { 31 | layer.msg("发送成功,请前往邮箱查看"); 32 | $(eventSrc).attr("disabled", "disabled"); 33 | $(eventSrc).addClass("disabled"); 34 | setTimeout(function () { 35 | $(eventSrc).removeAttr("disabled"); 36 | $(eventSrc).removeClass("disabled"); 37 | }, 60000); 38 | } else { 39 | alerts("获取验证码失败,请联系管理员"); 40 | } 41 | }); 42 | } else { 43 | alerts("邮箱格式不合法"); 44 | } 45 | } 46 | 47 | $(document).ready(function () { 48 | layer.load(1); 49 | $.get("/config/global", function (data) { 50 | layer.closeAll(); 51 | globalConfig = JSON.parse(data); 52 | /** @namespace globalConfig.loadParticle */ 53 | if (globalConfig.loadParticle) { 54 | // 加载 particle粒子效果 55 | particlesJS.load('particles-js', 'js/particles.json', function () { 56 | console.log('callback - particles.js config loaded'); 57 | }); 58 | } 59 | /** @namespace globalConfig.background.useImage */ 60 | if (globalConfig.background.useImage) { 61 | /** @namespace globalConfig.background.listGenerator */ 62 | if (globalConfig.background.listGenerator.enable) { 63 | var start = globalConfig.background.listGenerator.start; 64 | var end = globalConfig.background.listGenerator.end; 65 | var len = end - start + 1; 66 | var list = new Array(len); 67 | for (var i = 0; i < len; i++) { 68 | /** @namespace globalConfig.background.listGenerator.suffix */ 69 | list[i] = globalConfig.background.listGenerator.prefix + (start++) + globalConfig.background.listGenerator.suffix; 70 | } 71 | globalConfig.background.imageList = list; 72 | } 73 | changeBackgroundImage(); 74 | } 75 | setCSS(); 76 | }); 77 | // 加载页脚 78 | $("#footer").html(footer); 79 | $("body").append(""); 82 | }); 83 | 84 | function changeBackgroundImage() { 85 | if (globalConfig.background.useImage) { 86 | var idx = 0; 87 | if (globalConfig.background.random) { 88 | idx = Math.floor(Math.random() * globalConfig.background.imageList.length); 89 | } else { 90 | /** @namespace globalConfig.background.imageIndex */ 91 | idx = globalConfig.background.imageIndex; 92 | } 93 | /** @namespace globalConfig.background.imageList */ 94 | var url = globalConfig.background.imageList[idx]; 95 | if (typeof url !== "undefined") { 96 | var body = $("body"); 97 | $(body).css("background", "url('" + url + "') no-repeat center center fixed"); 98 | $(body).css("background-size", "cover"); 99 | } 100 | } 101 | } 102 | 103 | function setCSS() { 104 | for (var m = 0; m < globalConfig.css.length; m++) { 105 | var node = globalConfig.css[m]; 106 | var tempElement = node.selector; 107 | var element = []; 108 | if (tempElement instanceof Array) { 109 | element = tempElement; 110 | } else { 111 | element = element.concat(tempElement); 112 | } 113 | var tempItem = node.style; 114 | var item = []; 115 | if (tempItem instanceof Array) { 116 | item = tempItem; 117 | } else { 118 | item = item.concat(tempItem); 119 | } 120 | for (var j = 0; j < element.length; j++) { 121 | for (var k = 0; k < item.length; k++) { 122 | var css = item[k].split(":"); 123 | $(element[j]).css(css[0].trim(), rtrim(css[1].trim(), ";")); 124 | } 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /src/main/resources/assets/js/mobile/layer.js: -------------------------------------------------------------------------------- 1 | /*! layer mobile-v2.0.0 Web弹层组件 MIT License http://layer.layui.com/mobile By 贤心 */ 2 | ;!function(e){"use strict";var t=document,n="querySelectorAll",i="getElementsByClassName",a=function(e){return t[n](e)},s={type:0,shade:!0,shadeClose:!0,fixed:!0,anim:"scale"},l={extend:function(e){var t=JSON.parse(JSON.stringify(s));for(var n in e)t[n]=e[n];return t},timer:{},end:{}};l.touch=function(e,t){e.addEventListener("click",function(e){t.call(this,e)},!1)};var r=0,o=["layui-m-layer"],c=function(e){var t=this;t.config=l.extend(e),t.view()};c.prototype.view=function(){var e=this,n=e.config,s=t.createElement("div");e.id=s.id=o[0]+r,s.setAttribute("class",o[0]+" "+o[0]+(n.type||0)),s.setAttribute("index",r);var l=function(){var e="object"==typeof n.title;return n.title?'

'+(e?n.title[0]:n.title)+"

":""}(),c=function(){"string"==typeof n.btn&&(n.btn=[n.btn]);var e,t=(n.btn||[]).length;return 0!==t&&n.btn?(e=''+n.btn[0]+"",2===t&&(e=''+n.btn[1]+""+e),'
'+e+"
"):""}();if(n.fixed||(n.top=n.hasOwnProperty("top")?n.top:100,n.style=n.style||"",n.style+=" top:"+(t.body.scrollTop+n.top)+"px"),2===n.type&&(n.content='

'+(n.content||"")+"

"),n.skin&&(n.anim="up"),"msg"===n.skin&&(n.shade=!1),s.innerHTML=(n.shade?"
':"")+'
"+l+'
'+n.content+"
"+c+"
",!n.type||2===n.type){var d=t[i](o[0]+n.type),y=d.length;y>=1&&layer.close(d[0].getAttribute("index"))}document.body.appendChild(s);var u=e.elem=a("#"+e.id)[0];n.success&&n.success(u),e.index=r++,e.action(n,u)},c.prototype.action=function(e,t){var n=this;e.time&&(l.timer[n.index]=setTimeout(function(){layer.close(n.index)},1e3*e.time));var a=function(){var t=this.getAttribute("type");0==t?(e.no&&e.no(),layer.close(n.index)):e.yes?e.yes(n.index):layer.close(n.index)};if(e.btn)for(var s=t[i]("layui-m-layerbtn")[0].children,r=s.length,o=0;odiv{line-height:22px;padding-top:7px;margin-bottom:20px;font-size:14px}.layui-m-layerbtn{display:box;display:-moz-box;display:-webkit-box;width:100%;height:50px;line-height:50px;font-size:0;border-top:1px solid #D0D0D0;background-color:#F2F2F2}.layui-m-layerbtn span{display:block;-moz-box-flex:1;box-flex:1;-webkit-box-flex:1;font-size:14px;cursor:pointer}.layui-m-layerbtn span[yes]{color:#40AFFE}.layui-m-layerbtn span[no]{border-right:1px solid #D0D0D0;border-radius:0 0 0 5px}.layui-m-layerbtn span:active{background-color:#F6F6F6}.layui-m-layerend{position:absolute;right:7px;top:10px;width:30px;height:30px;border:0;font-weight:400;background:0 0;cursor:pointer;-webkit-appearance:none;font-size:30px}.layui-m-layerend::after,.layui-m-layerend::before{position:absolute;left:5px;top:15px;content:'';width:18px;height:1px;background-color:#999;transform:rotate(45deg);-webkit-transform:rotate(45deg);border-radius:3px}.layui-m-layerend::after{transform:rotate(-45deg);-webkit-transform:rotate(-45deg)}body .layui-m-layer .layui-m-layer-footer{position:fixed;width:95%;max-width:100%;margin:0 auto;left:0;right:0;bottom:10px;background:0 0}.layui-m-layer-footer .layui-m-layercont{padding:20px;border-radius:5px 5px 0 0;background-color:rgba(255,255,255,.8)}.layui-m-layer-footer .layui-m-layerbtn{display:block;height:auto;background:0 0;border-top:none}.layui-m-layer-footer .layui-m-layerbtn span{background-color:rgba(255,255,255,.8)}.layui-m-layer-footer .layui-m-layerbtn span[no]{color:#FD482C;border-top:1px solid #c2c2c2;border-radius:0 0 5px 5px}.layui-m-layer-footer .layui-m-layerbtn span[yes]{margin-top:10px;border-radius:5px}body .layui-m-layer .layui-m-layer-msg{width:auto;max-width:90%;margin:0 auto;bottom:-150px;background-color:rgba(0,0,0,.7);color:#fff}.layui-m-layer-msg .layui-m-layercont{padding:10px 20px} -------------------------------------------------------------------------------- /src/main/resources/assets/js/nav.js: -------------------------------------------------------------------------------- 1 | $(function () { 2 | // nav收缩展开 3 | $('.jq-nav-item>a').on('click', function () { 4 | if (!$('.jq-nav').hasClass('jq-nav-mini')) { 5 | if ($(this).next().css('display') === "none") { 6 | //展开未展开 7 | $('.jq-nav-item').children('ul').slideUp(300); 8 | $(this).next('ul').slideDown(300); 9 | $(this).parent('li').addClass('jq-nav-show').siblings('li').removeClass('jq-nav-show'); 10 | } else { 11 | //收缩已展开 12 | $(this).next('ul').slideUp(300); 13 | $('.jq-nav-item.jq-nav-show').removeClass('jq-nav-show'); 14 | } 15 | } 16 | var tab = $(this).attr("href"); 17 | if (tab !== "filemanager") { 18 | $(".jq-tab").addClass("hide"); 19 | $(tab).removeClass("hide"); 20 | try { 21 | getTabInfo(tab); 22 | if (isMobile()) { 23 | $("#mini").click(); 24 | } 25 | } catch (e) { 26 | console.info("function 'getTabInfo' not found"); 27 | } 28 | } 29 | }); 30 | //nav-mini切换 31 | $('#mini').on('click', function () { 32 | var nav = $(".jq-nav"); 33 | if ($(nav).hasClass('jq-nav-mini')) { 34 | $(nav).removeClass('jq-nav-mini'); 35 | } else { 36 | $('.jq-nav-item.jq-nav-show').removeClass('jq-nav-show'); 37 | $('.jq-nav-item').children('ul').removeAttr('style'); 38 | $(nav).addClass('jq-nav-mini'); 39 | } 40 | calculateContentWidth(); 41 | }); 42 | }); 43 | 44 | calculateContentWidth(); 45 | 46 | function calculateContentWidth() { 47 | setTimeout(function () { 48 | $("#container").css("margin-left", $(".jq-nav").width() + "px"); 49 | }, 200); 50 | } -------------------------------------------------------------------------------- /src/main/resources/assets/js/particles.json: -------------------------------------------------------------------------------- 1 | { 2 | "particles": { 3 | "number": { 4 | "value": 60, 5 | "density": { 6 | "enable": true, 7 | "value_area": 1000 8 | } 9 | }, 10 | "color": { 11 | "value": "#0000FF" 12 | }, 13 | "shape": { 14 | "type": "circle", 15 | "stroke": { 16 | "width": 0, 17 | "color": "#000000" 18 | }, 19 | "polygon": { 20 | "nb_sides": 5 21 | }, 22 | "image": { 23 | "src": "img/github.svg", 24 | "width": 100, 25 | "height": 100 26 | } 27 | }, 28 | "opacity": { 29 | "value": 0.5, 30 | "random": false, 31 | "anim": { 32 | "enable": false, 33 | "speed": 1, 34 | "opacity_min": 0.1, 35 | "sync": false 36 | } 37 | }, 38 | "size": { 39 | "value": 2, 40 | "random": false, 41 | "anim": { 42 | "enable": false, 43 | "speed": 10, 44 | "size_min": 0.1, 45 | "sync": false 46 | } 47 | }, 48 | "line_linked": { 49 | "enable": true, 50 | "distance": 100, 51 | "color": "#0000FF", 52 | "opacity": 0.4, 53 | "width": 1 54 | }, 55 | "move": { 56 | "enable": true, 57 | "speed": 3, 58 | "direction": "none", 59 | "random": false, 60 | "straight": false, 61 | "out_mode": "out", 62 | "bounce": false, 63 | "attract": { 64 | "enable": false, 65 | "rotateX": 600, 66 | "rotateY": 100 67 | } 68 | } 69 | }, 70 | "interactivity": { 71 | "detect_on": "canvas", 72 | "events": { 73 | "onhover": { 74 | "enable": false, 75 | "mode": "repulse" 76 | }, 77 | "onclick": { 78 | "enable": true, 79 | "mode": "push" 80 | }, 81 | "resize": true 82 | }, 83 | "modes": { 84 | "grab": { 85 | "distance": 800, 86 | "line_linked": { 87 | "opacity": 1 88 | } 89 | }, 90 | "bubble": { 91 | "distance": 800, 92 | "size": 80, 93 | "duration": 2, 94 | "opacity": 0.8, 95 | "speed": 3 96 | }, 97 | "repulse": { 98 | "distance": 400, 99 | "duration": 0.4 100 | }, 101 | "push": { 102 | "particles_nb": 4 103 | }, 104 | "remove": { 105 | "particles_nb": 2 106 | } 107 | } 108 | }, 109 | "retina_detect": true 110 | } -------------------------------------------------------------------------------- /src/main/resources/assets/js/theme.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * bootstrap-fileinput v4.4.7 3 | * http://plugins.krajee.com/file-input 4 | * 5 | * Font Awesome icon theme configuration for bootstrap-fileinput. Requires font awesome assets to be loaded. 6 | * 7 | * Author: Kartik Visweswaran 8 | * Copyright: 2014 - 2018, Kartik Visweswaran, Krajee.com 9 | * 10 | * Licensed under the BSD 3-Clause 11 | * https://github.com/kartik-v/bootstrap-fileinput/blob/master/LICENSE.md 12 | */ 13 | (function ($) { 14 | "use strict"; 15 | 16 | $.fn.fileinputThemes.fa = { 17 | fileActionSettings: { 18 | removeIcon: '', 19 | uploadIcon: '', 20 | uploadRetryIcon: '', 21 | zoomIcon: '', 22 | dragIcon: '', 23 | indicatorNew: '', 24 | indicatorSuccess: '', 25 | indicatorError: '', 26 | indicatorLoading: '' 27 | }, 28 | layoutTemplates: { 29 | fileIcon: ' ' 30 | }, 31 | previewZoomButtonIcons: { 32 | prev: '', 33 | next: '', 34 | toggleheader: '', 35 | fullscreen: '', 36 | borderless: '', 37 | close: '' 38 | }, 39 | previewFileIcon: '', 40 | browseIcon: '', 41 | removeIcon: '', 42 | cancelIcon: '', 43 | uploadIcon: '', 44 | msgValidationErrorIcon: ' ' 45 | }; 46 | })(window.jQuery); 47 | -------------------------------------------------------------------------------- /src/main/resources/assets/js/theme/default/icon-ext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/js/theme/default/icon-ext.png -------------------------------------------------------------------------------- /src/main/resources/assets/js/theme/default/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/js/theme/default/icon.png -------------------------------------------------------------------------------- /src/main/resources/assets/js/theme/default/loading-0.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/js/theme/default/loading-0.gif -------------------------------------------------------------------------------- /src/main/resources/assets/js/theme/default/loading-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/js/theme/default/loading-1.gif -------------------------------------------------------------------------------- /src/main/resources/assets/js/theme/default/loading-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4everything/efo/d9871b2f2349079581386afd6f070b762e2e58fd/src/main/resources/assets/js/theme/default/loading-2.gif -------------------------------------------------------------------------------- /src/main/resources/assets/js/upload.js: -------------------------------------------------------------------------------- 1 | $("#file-input").fileinput({ 2 | uploadUrl: "/file", 3 | uploadAsync: true, 4 | maxFileCount: 100, 5 | previewFileType: ['image', 'html', 'text', 'video', 'audio', 'flash'], 6 | uploadExtraData: function () { 7 | return { 8 | categoryId: $("#category-id").val(), 9 | tag: $("#tag").val(), 10 | description: $("#description").val(), 11 | prefix: getQuery("prefix") 12 | }; 13 | }, 14 | maxFilePreviewSize: 51200 15 | }).on('fileuploaded', function (event, data, previewId, index) { 16 | var json = data.response; 17 | if (json.status === "success") { 18 | alerts("上传成功"); 19 | } else { 20 | alerts("上传失败,文件不合法"); 21 | } 22 | }); 23 | 24 | $(document).on('ready', function () { 25 | $("#file-input").fileinput({ 26 | maxFilePreviewSize: 10240 27 | }); 28 | }); 29 | 30 | $.get("/category/all", function (data) { 31 | var json = JSON.parse(data); 32 | var option = ""; 33 | $.each(json, function (i, category) { 34 | option += ""; 35 | }); 36 | if (!isEmpty(option)) { 37 | $("#category-id").html(option); 38 | } 39 | }); -------------------------------------------------------------------------------- /src/main/resources/assets/js/utils.js: -------------------------------------------------------------------------------- 1 | function boolToChinese(bool) { 2 | return bool ? "成功" : "失败"; 3 | } 4 | 5 | function setCheckboxesStatus(tableBody, status) { 6 | var cbx = $(tableBody).find("input[type='checkbox']"); 7 | for (var i = 0; i < cbx.length; i++) { 8 | cbx[i].checked = status; 9 | } 10 | } 11 | 12 | function getSelectedRows(tableBody) { 13 | var cbx = $(tableBody).find("input[type='checkbox']"); 14 | var trs = []; 15 | for (var i = 0; i < cbx.length; i++) { 16 | if (cbx[i].checked) { 17 | trs = trs.concat($(cbx[i]).parents("tr")); 18 | } 19 | } 20 | return trs; 21 | } 22 | 23 | function isMobile() { 24 | var userAgent = navigator.userAgent.toLowerCase(); 25 | var isPad = userAgent.indexOf("ipad") > -1; 26 | var isIpone = userAgent.indexOf("iphone") > -1; 27 | var isMidp = userAgent.indexOf("midp") > -1; 28 | var isUc = userAgent.indexOf("rv:1.2.3.4") > -1 || userAgent.indexOf("ucweb") > -1; 29 | var isAndroid = userAgent.indexOf("android") > -1; 30 | var isCe = userAgent.indexOf("windows ce") > -1; 31 | var isWm = userAgent.indexOf("windows mobile") > -1; 32 | return isPad || isIpone || isMidp || isUc || isAndroid || isCe || isWm || userAgent.indexOf("mobile") > -1; 33 | } 34 | 35 | function trimWith(string, trimStr) { 36 | return ltrim(rtrim(string, trimStr), trimStr); 37 | } 38 | 39 | function rtrim(string, trimStr) { 40 | var idx = string.length - trimStr.length; 41 | return string.lastIndexOf(trimStr) === idx ? rtrim(string.substr(0, idx), trimStr) : string; 42 | } 43 | 44 | function ltrim(string, trimStr) { 45 | return string.indexOf(trimStr) === 0 ? ltrim(string.substr(trimStr.length), trimStr) : string; 46 | } 47 | 48 | function formatSize(bytes) { 49 | var s = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; 50 | var e = Math.floor(Math.log(bytes) / Math.log(1024)); 51 | return (bytes / Math.pow(1024, Math.floor(e))).toFixed(2) + " " + s[e]; 52 | } 53 | 54 | function getQuery(key) { 55 | var queryString = location.search; 56 | if (queryString.indexOf("?") === 0) { 57 | queryString = queryString.substr(1); 58 | var query = queryString.split("&"); 59 | for (var i = 0; i < query.length; i++) { 60 | if (query[i].indexOf(key + "=") > -1) { 61 | return query[i].split("=")[1]; 62 | } 63 | } 64 | } 65 | return ""; 66 | } 67 | 68 | function getCookie(name) { 69 | if (document.cookie.length > 0) { 70 | var start = document.cookie.indexOf(name + "="); 71 | if (start !== -1) { 72 | start += name.length + 1; 73 | var end = document.cookie.indexOf(";", start); 74 | if (end === -1) { 75 | end = document.cookie.length; 76 | } 77 | return document.cookie.substring(start, end); 78 | } 79 | } 80 | return ""; 81 | } 82 | 83 | function isEmpty(string) { 84 | return typeof string === "undefined" || string.length < 1; 85 | } 86 | 87 | function isEmail(email) { 88 | return email.match(/^[0-9a-z\-]+([0-9a-z\-]|(\.[0-9a-z\-]+))*@[0-9a-z\-]+(\.[0-9a-z\-]+)+$/); 89 | } 90 | 91 | function alerts(msg, callback) { 92 | layer.alert(msg, { 93 | skin: 'layui-layer-molv' 94 | , closeBtn: 0 95 | }, callback); 96 | } 97 | 98 | Date.prototype.format = function (fmt) { //author: meizz 99 | var o = { 100 | "M+": this.getMonth() + 1, //月份 101 | "d+": this.getDate(), //日 102 | "h+": this.getHours(), //小时 103 | "m+": this.getMinutes(), //分 104 | "s+": this.getSeconds(), //秒 105 | "q+": Math.floor((this.getMonth() + 3) / 3), //季度 106 | "S": this.getMilliseconds() //毫秒 107 | }; 108 | if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 109 | for (var k in o) 110 | if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 111 | return fmt; 112 | }; -------------------------------------------------------------------------------- /src/main/resources/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "authentication": "shiro" 4 | }, 5 | "global": { 6 | "uploadPath": { 7 | "windows": "upload", 8 | "mac": "upload", 9 | "linux": "upload" 10 | }, 11 | "uploadForm": "yyyyMMdd", 12 | "tokenPath": { 13 | "windows": "token.json", 14 | "mac": "token.json", 15 | "linux": "token.json" 16 | }, 17 | "allowRegister": true, 18 | "allowLogin": true, 19 | "loadParticle": false, 20 | "anonymousUser": { 21 | "visible": true, 22 | "downloadable": true 23 | }, 24 | "css": [ 25 | { 26 | "selector": ".random-image", 27 | "style": [ 28 | "background-color: #800080", 29 | "color: #FFF300" 30 | ] 31 | }, 32 | { 33 | "selector": ".jq-nav-item a", 34 | "style": "color: #FFF300" 35 | }, 36 | { 37 | "selector": ".jq-nav", 38 | "style": "background-color: #800080" 39 | }, 40 | { 41 | "selector": [ 42 | ".content-box", 43 | ".form-control" 44 | ], 45 | "style": "background: rgba(255,255,255,0.8)" 46 | }, 47 | { 48 | "selector": ".btn", 49 | "style": "opacity: 0.8" 50 | } 51 | ], 52 | "background": { 53 | "useImage": true, 54 | "imageIndex": 0, 55 | "imageList": [ 56 | "https://fakedog.xyz/homedb/srcm/upload/20180123/bg_1.jpg", 57 | "https://fakedog.xyz/homedb/srcm/upload/20180123/bg_2.jpg", 58 | "https://fakedog.xyz/homedb/srcm/upload/20180123/bg_3.jpg" 59 | ], 60 | "random": true, 61 | "listGenerator": { 62 | "enable": true, 63 | "prefix": "https://fakedog.xyz/image/background/anime/bg_", 64 | "suffix": ".jpg", 65 | "start": 1, 66 | "end": 158 67 | } 68 | } 69 | }, 70 | "user": { 71 | "pageSize": 30, 72 | "password": { 73 | "minLength": 6, 74 | "maxLength": 20 75 | }, 76 | "emailVerify": false, 77 | "emailConfig": { 78 | "host": "mx1.hostinger.com.hk", 79 | "port": 587, 80 | "personal": "efo", 81 | "from": "efo-admin@fakedog.xyz", 82 | "key": "123456", 83 | "ssl": false 84 | }, 85 | "usernameMatch": { 86 | "pattern": "^[a-zA-Z][a-zA-Z0-9]{3,15}$", 87 | "description": "用户名只能使用长度为4到16位的英文字母和数字,且必须以字母开始" 88 | }, 89 | "defaultAuth": { 90 | "isDownloadable": true, 91 | "isUploadable": true, 92 | "isDeletable": false, 93 | "isUpdatable": false, 94 | "isVisible": true 95 | }, 96 | "orderBy": "id desc" 97 | }, 98 | "download": { 99 | "pageSize": 30, 100 | "orderBy": "id desc" 101 | }, 102 | "auth": { 103 | "pageSize": 30, 104 | "orderBy": "id desc", 105 | "default": { 106 | "isDownloadable": true, 107 | "isUploadable": true, 108 | "isDeletable": true, 109 | "isUpdatable": true, 110 | "isVisible": true 111 | } 112 | }, 113 | "file": { 114 | "pageSize": 30, 115 | "maxSize": "10240 MB", 116 | "tag": { 117 | "require": false, 118 | "maxLength": 5, 119 | "maxSize": 5 120 | }, 121 | "orderBy": "id desc", 122 | "coverIfExists": false, 123 | "linkRule": { 124 | "custom": "/{year}/{month}/{day}/{randomId}{fileSuffix}", 125 | "support": [ 126 | "{year}", 127 | "{month}", 128 | "{day}", 129 | "{author}", 130 | "{fileName}", 131 | "{categoryName}", 132 | "{randomId}", 133 | "{fileSuffix}" 134 | ] 135 | }, 136 | "suffixMatch": { 137 | "pattern": "[a-zA-Z0-9]{0,10}", 138 | "description": "文件后缀只能包括数字和字母且长度不超过10" 139 | }, 140 | "defaultAuth": { 141 | "isDownloadable": true, 142 | "isUploadable": true, 143 | "isDeletable": true, 144 | "isUpdatable": true, 145 | "isVisible": true 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.Target=System.out 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [%c]: %m%n -------------------------------------------------------------------------------- /src/main/resources/static/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 错误 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/resources/static/filemanager.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 远程文件管理 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/resources/static/upload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 上传 23 | 24 | 25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | 37 |
38 |
39 | 41 |
42 |
43 |
44 |
45 |
46 | 47 |
48 |

49 |
51 |
52 |
53 |
54 |
55 |
56 | 57 |
58 |
59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/EfoApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo; 2 | 3 | import com.zhazhapan.config.JsonParser; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | import java.io.IOException; 10 | 11 | @RunWith(SpringRunner.class) 12 | @SpringBootTest 13 | public class EfoApplicationTest { 14 | 15 | public static void setSettings() { 16 | try { 17 | EfoApplication.settings = new JsonParser(EfoApplicationTest.class.getResource("/config.json")); 18 | } catch (IOException e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | 23 | @Test 24 | public void contextLoads() { 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/common/CommonTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.common; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.EfoApplicationTest; 5 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 6 | import com.zhazhapan.util.FileExecutor; 7 | import com.zhazhapan.util.Formatter; 8 | import com.zhazhapan.util.MailSender; 9 | import org.junit.Test; 10 | 11 | import javax.swing.filechooser.FileSystemView; 12 | import java.io.File; 13 | 14 | /** 15 | * @author pantao 16 | * @since 2018/1/23 17 | */ 18 | public class CommonTest { 19 | 20 | @Test 21 | public void testSendEmail() throws Exception { 22 | EfoApplicationTest.setSettings(); 23 | MailSender.config(EfoApplication.settings.getObjectUseEval(ConfigConsts.EMAIL_CONFIG_OF_SETTINGS)); 24 | MailSender.sendMail("tao@zhazhapan.com", "test", "test"); 25 | } 26 | 27 | @Test 28 | public void testGetDriver() { 29 | FileSystemView fsv = FileSystemView.getFileSystemView(); 30 | File[] fs = File.listRoots(); 31 | for (File f : fs) { 32 | System.out.println(fsv.getSystemDisplayName(f)); 33 | System.out.print("总大小" + Formatter.formatSize(f.getTotalSpace())); 34 | System.out.println("剩余" + Formatter.formatSize(f.getFreeSpace())); 35 | System.out.println(f.isDirectory()); 36 | } 37 | } 38 | 39 | @Test 40 | public void testListRoot() { 41 | File[] files = FileExecutor.listFile("/c:/"); 42 | for (File file : files) { 43 | System.out.println(file.getName()); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/config/SettingConfigTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.config; 2 | 3 | import com.zhazhapan.efo.EfoApplication; 4 | import com.zhazhapan.efo.EfoApplicationTest; 5 | import com.zhazhapan.efo.modules.constant.ConfigConsts; 6 | import org.junit.Test; 7 | 8 | import java.util.regex.Pattern; 9 | 10 | /** 11 | * @author pantao 12 | * @since 2018/1/26 13 | */ 14 | public class SettingConfigTest { 15 | 16 | @Test 17 | public void testFileSuffixPattern() { 18 | EfoApplicationTest.setSettings(); 19 | assert Pattern.compile(EfoApplication.settings.getStringUseEval(ConfigConsts.FILE_SUFFIX_MATCH_OF_SETTING)).matcher("jpg").matches(); 20 | } 21 | 22 | @Test 23 | public void testGetStoragePath() { 24 | EfoApplicationTest.setSettings(); 25 | System.out.println(SettingConfig.getStoragePath(ConfigConsts.TOKEN_OF_SETTINGS)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/dao/AuthDAOTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.EfoApplicationTest; 4 | import com.zhazhapan.util.Formatter; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | /** 12 | * @author pantao 13 | * @since 2018/1/19 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class AuthDAOTest { 18 | 19 | static { 20 | EfoApplicationTest.setSettings(); 21 | } 22 | 23 | @Autowired 24 | private AuthDAO authDAO; 25 | 26 | @Test 27 | public void testGetAuthBy() { 28 | System.out.println(Formatter.listToJson(authDAO.listAuthBy(0, 0, 0, "", 0))); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/dao/CategoryDAOTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.util.Formatter; 4 | import com.zhazhapan.util.RandomUtils; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | /** 12 | * @author pantao 13 | * @since 2018/1/18 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class CategoryDAOTest { 18 | 19 | @Autowired 20 | CategoryDAO categoryDAO; 21 | 22 | @Test 23 | public void testInsertCategory() { 24 | for (int i = 0; i < 10; i++) { 25 | categoryDAO.insertCategory(RandomUtils.getRandomStringOnlyLowerCase(6)); 26 | } 27 | } 28 | 29 | @Test 30 | public void testRemoveCategoryById() { 31 | categoryDAO.removeCategoryById(1); 32 | } 33 | 34 | @Test 35 | public void testUpdateName() { 36 | categoryDAO.updateNameById(3, "update"); 37 | } 38 | 39 | @Test 40 | public void testGetAllCategory() { 41 | System.out.println(Formatter.listToJson(categoryDAO.listCategory())); 42 | } 43 | 44 | @Test 45 | public void testGetCategoryById() { 46 | System.out.println(categoryDAO.getCategoryById(6).toString()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/dao/DownloadedDAOTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.EfoApplicationTest; 4 | import com.zhazhapan.modules.constant.ValueConsts; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | /** 12 | * @author pantao 13 | * @since 2018/1/19 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class DownloadedDAOTest { 18 | 19 | static { 20 | EfoApplicationTest.setSettings(); 21 | } 22 | 23 | @Autowired 24 | DownloadedDAO downloadDAO; 25 | 26 | @Test 27 | public void testGetDownloadBy() { 28 | System.out.println(downloadDAO.listDownloadedBy(1, 1, "", ValueConsts.ZERO_INT, 0)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/dao/FileDAOTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.EfoApplicationTest; 4 | import com.zhazhapan.util.Formatter; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | /** 12 | * @author pantao 13 | * @since 2018/2/5 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class FileDAOTest { 18 | 19 | @Autowired 20 | FileDAO fileDAO; 21 | 22 | @Test 23 | public void testRemoveFile() { 24 | assert fileDAO.removeById(3); 25 | } 26 | 27 | @Test 28 | public void testGetUserDownloaded() { 29 | EfoApplicationTest.setSettings(); 30 | System.out.println(Formatter.listToJson(fileDAO.listUserDownloaded(2, 0, ""))); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/dao/UserDAOTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao; 2 | 3 | import com.zhazhapan.efo.EfoApplicationTest; 4 | import com.zhazhapan.efo.entity.User; 5 | import com.zhazhapan.util.Checker; 6 | import com.zhazhapan.util.Formatter; 7 | import com.zhazhapan.util.RandomUtils; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | /** 15 | * @author pantao 16 | * @since 2018/1/18 17 | */ 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | public class UserDAOTest { 21 | 22 | static { 23 | EfoApplicationTest.setSettings(); 24 | } 25 | 26 | @Autowired 27 | private UserDAO userDAO; 28 | 29 | @Test 30 | public void testUpdateUserAuth() { 31 | assert userDAO.updateAuthById(1, 1, 1, 1, 1, 1); 32 | } 33 | 34 | @Test 35 | public void testUpdateUserLoginTime() { 36 | assert userDAO.updateUserLoginTime(1); 37 | } 38 | 39 | @Test 40 | public void testDoLogin() { 41 | assert Checker.isNotNull(userDAO.login("system", "123456")); 42 | } 43 | 44 | @Test 45 | public void testInsertUser() { 46 | String username = RandomUtils.getRandomStringOnlyLowerCase(6); 47 | String realName = RandomUtils.getRandomStringOnlyLowerCase(6); 48 | String email = RandomUtils.getRandomEmail(); 49 | String password = RandomUtils.getRandomStringWithoutSymbol(16); 50 | User user = new User(username, realName, email, password); 51 | assert userDAO.insertUser(user); 52 | } 53 | 54 | @Test 55 | public void testGetAllUser() { 56 | System.out.println(Formatter.listToJson(userDAO.listUserBy(3, "", 0))); 57 | } 58 | 59 | @Test 60 | public void testGetUser() { 61 | System.out.println(userDAO.getUserById(1).toString()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/dao/sqlprovider/FileSqlProviderTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.dao.sqlprovider; 2 | 3 | import com.zhazhapan.efo.EfoApplicationTest; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | /** 11 | * @author pantao 12 | * @since 2018/2/6 13 | */ 14 | @RunWith(SpringRunner.class) 15 | @SpringBootTest 16 | public class FileSqlProviderTest { 17 | 18 | @Autowired 19 | FileSqlProvider fileSqlProvider; 20 | 21 | @Test 22 | public void updateAuthById() { 23 | System.out.println(fileSqlProvider.updateAuthById()); 24 | } 25 | 26 | @Test 27 | public void getAll() { 28 | EfoApplicationTest.setSettings(); 29 | System.out.println(fileSqlProvider.getAll(0, 0, "", "")); 30 | } 31 | 32 | @Test 33 | public void getUserUploaded() { 34 | System.out.println(fileSqlProvider.getUserUploaded(0, "")); 35 | } 36 | 37 | @Test 38 | public void getUserDownloaded() { 39 | System.out.println(fileSqlProvider.getUserDownloaded(0, "")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/zhazhapan/efo/service/CategoryServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.zhazhapan.efo.service; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | /** 10 | * @author pantao 11 | * @since 2018/2/9 12 | */ 13 | @RunWith(SpringRunner.class) 14 | @SpringBootTest 15 | public class CategoryServiceTest { 16 | 17 | @Autowired 18 | ICategoryService categoryService; 19 | 20 | @Test 21 | public void testGetIdByName() { 22 | System.out.println(categoryService.getIdByName("fff")); 23 | } 24 | } 25 | --------------------------------------------------------------------------------