init
This commit is contained in:
parent
478a68429e
commit
9e5d20a305
29
.gitignore
vendored
29
.gitignore
vendored
@ -1,23 +1,6 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
/.idea
|
||||
/scp-config/*.iml
|
||||
/release
|
||||
/scp-common/target
|
||||
/scp-config/target
|
||||
/*.log
|
||||
|
72
file-common/pom.xml
Normal file
72
file-common/pom.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.qiwen</groupId>
|
||||
<artifactId>file</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.qiwen</groupId>
|
||||
<artifactId>file-common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
||||
<!-- spring boot依赖包-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<version>RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<version>1.9.13</version>
|
||||
</dependency>-->
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--图片压缩-->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.8</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.12.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
<version>2.36.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
133
file-common/scp-common.iml
Normal file
133
file-common/scp-common.iml
Normal file
@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<webroots />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.11.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.11.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.23" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.17" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.17" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.17" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.16.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.3.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.coobird:thumbnailator:0.4.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit:2.36.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: xalan:xalan:2.7.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: xalan:serializer:2.7.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit-core-js:2.36.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:neko-htmlunit:2.36.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: xerces:xercesImpl:2.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit-cssparser:1.5.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-net:commons-net:3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.brotli:dec:0.1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-client:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.4.15.v20190215" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.28" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: mysql:mysql-connector-java:8.0.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.4.1.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.persistence:javax.persistence-api:2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.24.0-GA" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.9.12" level="project" />
|
||||
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.1.1.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss:jandex:2.0.5.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.1.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.glassfish.jaxb:jaxb-runtime:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.glassfish.jaxb:txw2:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.istack:istack-commons-runtime:3.0.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jvnet.staxex:stax-ex:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.xml.fastinfoset:FastInfoset:1.2.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.transaction:javax.transaction-api:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-orm:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aspects:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.9.3.RC1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.3.RC1" level="project" />
|
||||
<orderEntry type="library" name="Maven: cglib:cglib:3.2.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm:7.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.ant:ant:1.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.ant:ant-launcher:1.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-mail:2.1.4.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.6.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-dbcp2:2.5.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,60 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* 通信工具类
|
||||
*
|
||||
* @author ma116
|
||||
*/
|
||||
public class CollectUtil {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CollectUtil.class);
|
||||
|
||||
/**
|
||||
* java 后台获取访问客户端ip地址
|
||||
* @param request HttpServletRequest请求
|
||||
* @return IP地址
|
||||
*/
|
||||
public String getClientIpAddress(HttpServletRequest request) {
|
||||
String clientIp = request.getHeader("x-forwarded-for");
|
||||
if (clientIp == null || clientIp.length() == 0
|
||||
|| "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (clientIp == null || clientIp.length() == 0
|
||||
|| "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (clientIp == null || clientIp.length() == 0
|
||||
|| "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getRemoteAddr();
|
||||
}
|
||||
return clientIp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地IP
|
||||
* @return IP地址
|
||||
*/
|
||||
public String getLocalIp() {
|
||||
InetAddress addr = null;
|
||||
String ip = "";
|
||||
try {
|
||||
addr = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
LOG.error("获取本地IP失败");
|
||||
}
|
||||
if (addr != null) {
|
||||
ip = addr.getHostAddress().toString();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
}
|
124
file-common/src/main/java/com/mac/common/cbb/DateUtil.java
Normal file
124
file-common/src/main/java/com/mac/common/cbb/DateUtil.java
Normal file
@ -0,0 +1,124 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateUtil {
|
||||
/**
|
||||
* 获取系统当前时间
|
||||
*
|
||||
* @return 系统当前时间
|
||||
*/
|
||||
public static String getCurrentTime() {
|
||||
Date date = new Date();
|
||||
String stringDate = String.format("%tF %<tT", date);
|
||||
return stringDate;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param formatString 格式,如"yyyy-MM-dd"
|
||||
* @param stringDate 日期字符串,如"2000-03-19"
|
||||
* @return 日期
|
||||
* @throws ParseException 解析异常
|
||||
*/
|
||||
public static Date getDateByFormatString(String formatString, String stringDate) throws ParseException {
|
||||
DateFormat dateFormat = new SimpleDateFormat(formatString);
|
||||
Date date = dateFormat.parse(stringDate);
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化date
|
||||
*
|
||||
* @param formatString 格式,如"yyyy-MM-dd"
|
||||
* @param stringDate 日期字符串,如"2000-03-19"
|
||||
* @return SQL日期
|
||||
* @throws ParseException 解析异常
|
||||
*/
|
||||
public static java.sql.Date getSqlDateByFormatString(String formatString, String stringDate) throws ParseException {
|
||||
long longtime = DateUtil.getDateByFormatString("yyyyMMdd", stringDate).getTime();
|
||||
return new java.sql.Date(longtime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 两个日期相差天数
|
||||
* @param preDate 第一个时间日期
|
||||
* @param afterDate 第二个时间十七
|
||||
* @return 相差的天数
|
||||
*/
|
||||
public static int getDifferentDays(Date preDate, Date afterDate) {
|
||||
|
||||
int preYear = getYear(preDate);
|
||||
int afterYear = getYear(afterDate);
|
||||
int preDayOfYear = getDayOfYear(preDate);
|
||||
int afterDayOfYear = getDayOfYear(afterDate);
|
||||
|
||||
if (afterYear - preYear == 0){
|
||||
return afterDayOfYear - preDayOfYear;
|
||||
}
|
||||
else{
|
||||
int diffDay = 0;
|
||||
while (preYear < afterYear){
|
||||
if (diffDay == 0 && isLeapYear(preYear)) {
|
||||
diffDay = 366 - preDayOfYear;
|
||||
}else if (diffDay == 0 && !isLeapYear(preYear)) {
|
||||
diffDay = 365 - preDayOfYear;
|
||||
}else if (isLeapYear(preYear)){
|
||||
diffDay += 366;
|
||||
}else{
|
||||
diffDay += 365;
|
||||
}
|
||||
preYear++;
|
||||
}
|
||||
|
||||
diffDay += afterDayOfYear;
|
||||
return diffDay;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 一年中的第几天
|
||||
* @param date 日期
|
||||
* @return 第几天
|
||||
*/
|
||||
public static int getDayOfYear(Date date){
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
int day = cal.get(Calendar.DAY_OF_YEAR);
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年份
|
||||
* jdk推荐写法,date.getYear()已被废弃
|
||||
* @param date 日期
|
||||
* @return 年份
|
||||
*/
|
||||
public static int getYear(Date date){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
return year;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是闰年
|
||||
* @param year 年,如2010
|
||||
* @return 是否闰年
|
||||
*/
|
||||
public static boolean isLeapYear(int year){
|
||||
if ((year % 4 == 0 && year % 100 != 0)
|
||||
|| year % 400 ==0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2016/9/10.
|
||||
*/
|
||||
public class HibernateUtil {
|
||||
private static HibernateUtil me;
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
private HibernateUtil() {
|
||||
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
|
||||
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
|
||||
}
|
||||
|
||||
public static HibernateUtil getInstance() {
|
||||
if (me == null) {
|
||||
me = new HibernateUtil();
|
||||
}
|
||||
return me;
|
||||
}
|
||||
|
||||
public SessionFactory getSessionFactory() {
|
||||
return this.sessionFactory;
|
||||
}
|
||||
}
|
121
file-common/src/main/java/com/mac/common/cbb/HttpRequest.java
Normal file
121
file-common/src/main/java/com/mac/common/cbb/HttpRequest.java
Normal file
@ -0,0 +1,121 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mac.common.domain.ProxyBean;
|
||||
import com.mac.common.proxy.ProxyConstant;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.*;
|
||||
|
||||
public class HttpRequest {
|
||||
|
||||
public static List<ProxyBean> proxyBeans = new ArrayList<>();
|
||||
public HttpRequest(){
|
||||
String proxyRequest = getProxyRequestResult(ProxyConstant.SERVER_PROXY_COUNT);
|
||||
JSONObject resultObj = JSONObject.parseObject(proxyRequest);
|
||||
String requestJson = JSON.toJSONString(resultObj.getObject( "data", List.class));
|
||||
proxyBeans = JSONArray.parseArray(requestJson, ProxyBean.class);
|
||||
}
|
||||
|
||||
public String sendGet(String url, Map<String, String> param){
|
||||
ProxyBean proxyBean = null;
|
||||
int currentRandomIndex = 0;
|
||||
if (proxyBeans.size() <= 1) {
|
||||
return "没有可用的代理";
|
||||
} else{
|
||||
currentRandomIndex = new Random().nextInt(proxyBeans.size());
|
||||
proxyBean = (ProxyBean) proxyBeans.get(currentRandomIndex);
|
||||
}
|
||||
|
||||
boolean isRequestSuccess = false;
|
||||
Document doc = null;
|
||||
|
||||
try {
|
||||
doc = Jsoup.connect(url)
|
||||
.timeout(5000)
|
||||
.proxy(proxyBean.getProxyip(), proxyBean.getProxyport())
|
||||
.data(param)
|
||||
.ignoreContentType(true)
|
||||
.userAgent(ProxyConstant.userAgentArr[new Random().nextInt(ProxyConstant.userAgentArr.length)])
|
||||
.header("referer","http://www.sse.com.cn/assortment/stock/list/share/")//这个来源记得换..
|
||||
.get();
|
||||
isRequestSuccess = true;
|
||||
} catch (IOException e){
|
||||
isRequestSuccess = false;
|
||||
proxyBeans.remove(currentRandomIndex);
|
||||
System.out.println("此代理不通,正在重试。。" + JSON.toJSONString(proxyBean));
|
||||
}
|
||||
if (!isRequestSuccess){
|
||||
return sendGet(url, param);
|
||||
}
|
||||
|
||||
return doc.text();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取代理列表
|
||||
* @return 返回代理列表
|
||||
*/
|
||||
public static String getProxyRequestResult(int count) {
|
||||
StringBuffer requestResult = new StringBuffer();
|
||||
BufferedReader in = null;
|
||||
|
||||
try {
|
||||
URL realUrl = new URL("http://"+ProxyConstant.SERVER_IP+"/api/proxy/getproxylist?count="+count);
|
||||
// 打开和URL之间的连接
|
||||
URLConnection connection = realUrl.openConnection();
|
||||
// 设置通用的请求属性
|
||||
connection.setRequestProperty("accept", "*/*");
|
||||
connection.setRequestProperty("connection", "Keep-Alive");
|
||||
connection.setRequestProperty("user-agent",
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
// 建立实际的连接
|
||||
connection.connect();
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
in = new BufferedReader(new InputStreamReader(
|
||||
connection.getInputStream(), "utf-8"));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
requestResult.append(line);
|
||||
}
|
||||
}
|
||||
// 使用finally块来关闭输入流
|
||||
catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return requestResult.toString();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
//初始化对象
|
||||
HttpRequest httpRequest = new HttpRequest();
|
||||
//参数
|
||||
Map<String, String> param = new HashMap<>();
|
||||
param.put("v", "3.1.9y");
|
||||
//发送请求
|
||||
String result = httpRequest.sendGet("http://www.sse.com.cn/home/public/querySearch/queryConfig/map.js", param);
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
15
file-common/src/main/java/com/mac/common/cbb/MiniuiUtil.java
Normal file
15
file-common/src/main/java/com/mac/common/cbb/MiniuiUtil.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
|
||||
import com.mac.common.domain.TableQueryBean;
|
||||
|
||||
public class MiniuiUtil {
|
||||
|
||||
public static TableQueryBean getMiniuiTablePageQuery(TableQueryBean tableQueryBean) {
|
||||
int pageIndex = tableQueryBean.getPage();
|
||||
int pageSize = tableQueryBean.getLimit();
|
||||
int beginCount = (pageIndex - 1) * pageSize;
|
||||
tableQueryBean.setBeginCount(beginCount);
|
||||
return tableQueryBean;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
public class MyBatisUtil {
|
||||
private static SqlSessionFactory sqlSessionFactory = null;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MyBatisUtil.class);
|
||||
|
||||
static {
|
||||
String resource = "mybatis.xml";
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = Resources.getResourceAsReader(resource);
|
||||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
|
||||
} catch (IOException e) {
|
||||
LOG.error("mybatis读取资源文件失败!");
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("mybatis读取资源文件失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static SqlSessionFactory getSqlSessionFactory() {
|
||||
return sqlSessionFactory;
|
||||
}
|
||||
}
|
41
file-common/src/main/java/com/mac/common/cbb/RestResult.java
Normal file
41
file-common/src/main/java/com/mac/common/cbb/RestResult.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
public class RestResult<T> {
|
||||
private boolean success = true;
|
||||
private String errorCode;
|
||||
private String errorMessage;
|
||||
private T data;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(String errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
public class ScpConstant {
|
||||
|
||||
public static final String DOT = ".";
|
||||
}
|
127
file-common/src/main/java/com/mac/common/cbb/Test.java
Normal file
127
file-common/src/main/java/com/mac/common/cbb/Test.java
Normal file
@ -0,0 +1,127 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class Test {
|
||||
//获取代理ip,记得更换,我用的是蘑菇代理的,可以换成其他的网站的
|
||||
private final static String GET_IP_URL = "http://www.goubanjia.com/";
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
List<String> addrs = new LinkedList<String>();
|
||||
Map<String,Integer> addr_map = new HashMap<String,Integer>();
|
||||
Map<String,String> ipmap = new HashMap<String,String>();
|
||||
ExecutorService exe = Executors.newFixedThreadPool(10);
|
||||
for (int i=0 ;i<1;i++) {
|
||||
Document doc = null;
|
||||
try {
|
||||
Connection conn = Jsoup.connect(GET_IP_URL);
|
||||
Thread.sleep(1000);
|
||||
doc = conn.get();
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
}
|
||||
Elements eleTable = doc.getElementsByClass("port CFACE");
|
||||
System.out.println(eleTable);
|
||||
|
||||
for (int j = 0; j < eleTable.size(); j++){
|
||||
System.out.println(eleTable.get(j).text());
|
||||
}
|
||||
//System.out.println(eleTable);
|
||||
//JSONObject jsonObject = JSONObject.parseObject(doc.text());
|
||||
//List<Map<String,Object>> list = (List<Map<String,Object>>) jsonObject.get("msg");
|
||||
//int count = list.size();
|
||||
|
||||
// for (Map<String,Object> map : list ) {
|
||||
// String ip = (String)map.get("ip");
|
||||
// String port = (String)map.get("port") ;
|
||||
// ipmap.put(ip,"1");
|
||||
// checkIp a = new checkIp("120.78.225.5", 3128,count);
|
||||
// exe.execute(a);
|
||||
// }
|
||||
checkIp a = new checkIp("124.161.160.187", 8085,1);
|
||||
exe.execute(a);
|
||||
exe.shutdown();
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class checkIp implements Runnable {
|
||||
private static Logger logger = LoggerFactory.getLogger(checkIp.class);
|
||||
private static int suc=0;
|
||||
private static int total=0;
|
||||
private static int fail=0;
|
||||
|
||||
private String ip ;
|
||||
private int port;
|
||||
private int count;
|
||||
public checkIp(String ip, int port,int count) {
|
||||
super();
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Random r = new Random();
|
||||
String[] ua = {"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36 OPR/37.0.2178.32",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586",
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
|
||||
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
|
||||
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
|
||||
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.3 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36 Core/1.47.277.400 QQBrowser/9.4.7658.400",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 UBrowser/5.6.12150.8 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 TheWorld 7",
|
||||
"Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/60.0"};
|
||||
int i = r.nextInt(14);
|
||||
logger.info("检测中------ {}:{}",ip,port );
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("waybillNo","DD1838768852");
|
||||
try {
|
||||
total ++ ;
|
||||
long a = System.currentTimeMillis();
|
||||
//爬取的目标网站,url记得换下。。。!!!
|
||||
Document doc = Jsoup.connect("http://query.sse.com.cn/security/stock/getStockListData2.do?isPagination=true&stockCode=&csrcCode=&areaName=&stockType=1&pageHelp.cacheSize=1&pageHelp.beginPage=1&pageHelp.pageSize=3000&pageHelp.pageNo=1&_=1553181823571")
|
||||
.timeout(5000)
|
||||
.proxy(ip, port)
|
||||
.data(map)
|
||||
.ignoreContentType(true)
|
||||
.userAgent(ua[i])
|
||||
.header("referer","http://www.sse.com.cn/assortment/stock/list/share/")//这个来源记得换..
|
||||
.post();
|
||||
System.out.println(ip+":"+port+"访问时间:"+(System.currentTimeMillis() -a) + " 访问结果: "+doc.text());
|
||||
suc ++ ;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
fail ++ ;
|
||||
}finally {
|
||||
if (total == count ) {
|
||||
System.out.println("总次数:"+total);
|
||||
System.out.println("成功次数:"+suc);
|
||||
System.out.println("失败次数:"+fail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
208
file-common/src/main/java/com/mac/common/cbb/Uploader.java
Normal file
208
file-common/src/main/java/com/mac/common/cbb/Uploader.java
Normal file
@ -0,0 +1,208 @@
|
||||
package com.mac.common.cbb;
|
||||
|
||||
import com.mac.common.domain.UploadFile;
|
||||
import com.mac.common.operation.ImageOperation;
|
||||
import com.mac.common.util.FileUtil;
|
||||
import com.mac.common.util.PathUtil;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.fileupload.util.Streams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.*;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 文件上传辅助类
|
||||
*/
|
||||
public class Uploader {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Uploader.class);
|
||||
|
||||
|
||||
public static final String ROOT_PATH = "upload";
|
||||
|
||||
private StandardMultipartHttpServletRequest request = null;
|
||||
|
||||
// 文件允许格式
|
||||
private String[] allowFiles = {".rar", ".doc", ".docx", ".zip", ".pdf", ".txt", ".swf", ".wmv", ".gif", ".png", ".jpg", ".jpeg", ".bmp", "blob", ".mp4"};
|
||||
|
||||
|
||||
// 文件大小限制,单位KB
|
||||
private int maxSize = 10000000;
|
||||
|
||||
List<UploadFile> saveUploadFileList = new ArrayList<UploadFile>();
|
||||
|
||||
public Uploader(HttpServletRequest request) {
|
||||
this.request = (StandardMultipartHttpServletRequest) request;
|
||||
saveUploadFileList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<UploadFile> upload() {
|
||||
|
||||
// 判断enctype属性是否为multipart/form-data
|
||||
boolean isMultipart = ServletFileUpload.isMultipartContent(this.request);
|
||||
if (!isMultipart) {
|
||||
UploadFile uploadFile = new UploadFile();
|
||||
uploadFile.setSuccess(0);
|
||||
uploadFile.setMessage("未包含文件上传域");
|
||||
saveUploadFileList.add(uploadFile);
|
||||
return saveUploadFileList;
|
||||
}
|
||||
DiskFileItemFactory dff = new DiskFileItemFactory();//1、创建工厂
|
||||
String savePath = getSaveFilePath(ROOT_PATH);
|
||||
dff.setRepository(new File(savePath));
|
||||
try {
|
||||
ServletFileUpload sfu = new ServletFileUpload(dff);//2、创建文件上传解析器
|
||||
sfu.setSizeMax(this.maxSize * 1024L);
|
||||
sfu.setHeaderEncoding("utf-8");//3、解决文件名的中文乱码
|
||||
Iterator<String> iter = this.request.getFileNames();
|
||||
while (iter.hasNext()) {
|
||||
UploadFile uploadFile = new UploadFile();
|
||||
MultipartFile multipartfile = this.request.getFile(iter.next());
|
||||
InputStream inputStream = multipartfile.getInputStream();
|
||||
|
||||
String originalName = multipartfile.getOriginalFilename();
|
||||
// if (!this.checkFileType(originalName)) {
|
||||
// uploadFile.setSuccess(0);
|
||||
// uploadFile.setMessage("未包含文件上传域");
|
||||
// saveUploadFileList.add(uploadFile);
|
||||
// continue;
|
||||
// }
|
||||
String fileName = getFileName(originalName);
|
||||
String timeStampName = getTimeStampName();
|
||||
String fileType = FileUtil.getFileType(originalName);
|
||||
uploadFile.setFileName(fileName);
|
||||
uploadFile.setFileType(fileType);
|
||||
uploadFile.setTimeStampName(timeStampName);
|
||||
|
||||
String saveFilePath = savePath + File.separator + timeStampName + "." + fileType;
|
||||
String minFilePath = savePath + File.separator + timeStampName + "_min" + "." + fileType;
|
||||
uploadFile.setUrl(saveFilePath);
|
||||
File file = new File(PathUtil.getStaticPath() + File.separator + saveFilePath);
|
||||
File minFile = new File(PathUtil.getStaticPath() + File.separator + minFilePath);
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream out = null;
|
||||
BufferedOutputStream output = null;
|
||||
|
||||
try {
|
||||
in = new BufferedInputStream(inputStream);
|
||||
out = new FileOutputStream(file);
|
||||
output = new BufferedOutputStream(out);
|
||||
Streams.copy(in, output, true);
|
||||
if (FileUtil.isImageFile(uploadFile.getFileType())){
|
||||
ImageOperation.thumbnailsImage(file, minFile, 300);
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
LOG.error("文件没有发现" + e);
|
||||
} catch (IOException e) {
|
||||
LOG.error("文件读取失败" + e);
|
||||
} finally {
|
||||
closeStream(in, out, output);
|
||||
}
|
||||
uploadFile.setSuccess(1);
|
||||
uploadFile.setMessage("上传成功");
|
||||
uploadFile.setFileSize(file.length());
|
||||
saveUploadFileList.add(uploadFile);
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
UploadFile uploadFile = new UploadFile();
|
||||
uploadFile.setSuccess(1);
|
||||
uploadFile.setMessage("未知错误");
|
||||
saveUploadFileList.add(uploadFile);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return saveUploadFileList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void closeStream(BufferedInputStream in, FileOutputStream out,
|
||||
BufferedOutputStream output) throws IOException {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (output != null) {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件类型判断
|
||||
*
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
private boolean checkFileType(String fileName) {
|
||||
Iterator<String> type = Arrays.asList(this.allowFiles).iterator();
|
||||
while (type.hasNext()) {
|
||||
String ext = type.next();
|
||||
if (fileName.toLowerCase().endsWith(ext)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String getFileName(String fileName){
|
||||
return fileName.substring(0, fileName.lastIndexOf("."));
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据原始文件名生成新文件名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getTimeStampName() {
|
||||
try {
|
||||
SecureRandom number = SecureRandom.getInstance("SHA1PRNG");
|
||||
return "" + number.nextInt(10000)
|
||||
+ System.currentTimeMillis();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LOG.error("生成安全随机数失败");
|
||||
}
|
||||
return ""
|
||||
+ System.currentTimeMillis();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字符串创建本地目录 并按照日期建立子目录返回
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
private String getSaveFilePath(String path) {
|
||||
SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
|
||||
path = File.separator + path + File.separator + formater.format(new Date());
|
||||
File dir = new File(PathUtil.getStaticPath() + path);
|
||||
LOG.error(PathUtil.getStaticPath() + path);
|
||||
if (!dir.exists()) {
|
||||
try {
|
||||
boolean isSuccessMakeDir = dir.mkdirs();
|
||||
if (!isSuccessMakeDir) {
|
||||
LOG.error("文件创建失败:" + PathUtil.getStaticPath() + path);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("目录创建失败" + PathUtil.getStaticPath() + path);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.mac.common.domain;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 代理实体类
|
||||
*/
|
||||
|
||||
public class ProxyBean {
|
||||
private long proxyid;
|
||||
private String proxyip;
|
||||
private int proxyport;
|
||||
private int testresult;
|
||||
private String testtime;
|
||||
|
||||
public ProxyBean(){
|
||||
|
||||
}
|
||||
|
||||
public ProxyBean(String proxyip, int proxyport) {
|
||||
this.proxyip = proxyip;
|
||||
this.proxyport = proxyport;
|
||||
}
|
||||
|
||||
public String getProxyip() {
|
||||
return proxyip;
|
||||
}
|
||||
|
||||
public void setProxyip(String proxyip) {
|
||||
this.proxyip = proxyip;
|
||||
}
|
||||
|
||||
public long getProxyid() {
|
||||
return proxyid;
|
||||
}
|
||||
|
||||
public void setProxyid(long proxyid) {
|
||||
this.proxyid = proxyid;
|
||||
}
|
||||
|
||||
public int getProxyport() {
|
||||
return proxyport;
|
||||
}
|
||||
|
||||
public void setProxyport(int proxyport) {
|
||||
this.proxyport = proxyport;
|
||||
}
|
||||
|
||||
public int getTestresult() {
|
||||
return testresult;
|
||||
}
|
||||
|
||||
public void setTestresult(int testresult) {
|
||||
this.testresult = testresult;
|
||||
}
|
||||
|
||||
public String getTesttime() {
|
||||
return testtime;
|
||||
}
|
||||
|
||||
public void setTesttime(String testtime) {
|
||||
this.testtime = testtime;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.mac.common.domain;
|
||||
|
||||
public class TableData<T> {
|
||||
private T data;
|
||||
private int count;
|
||||
private String msg;
|
||||
private boolean success = true;
|
||||
private int code = 0;
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.mac.common.domain;
|
||||
|
||||
public class TableQueryBean {
|
||||
//key, pageIndex, pageSize, sortField, sortOrder
|
||||
|
||||
private int page;
|
||||
private int limit;
|
||||
private int beginCount;
|
||||
|
||||
/**
|
||||
* 搜索关键词
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String field;
|
||||
/**
|
||||
* 排序规则
|
||||
*/
|
||||
private String order;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public String getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(String order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public int getBeginCount() {
|
||||
return beginCount;
|
||||
}
|
||||
|
||||
public void setBeginCount(int beginCount) {
|
||||
this.beginCount = beginCount;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.mac.common.domain;
|
||||
|
||||
public class TaskProcess {
|
||||
private int totalCount;
|
||||
private int completeCount;
|
||||
private String taskInfo;
|
||||
/**
|
||||
* 是否任务运行
|
||||
*/
|
||||
private boolean isRunTask;
|
||||
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
public int getCompleteCount() {
|
||||
return completeCount;
|
||||
}
|
||||
|
||||
public void setCompleteCount(int completeCount) {
|
||||
this.completeCount = completeCount;
|
||||
}
|
||||
|
||||
public String getTaskInfo() {
|
||||
return taskInfo;
|
||||
}
|
||||
|
||||
public void setTaskInfo(String taskInfo) {
|
||||
this.taskInfo = taskInfo;
|
||||
}
|
||||
|
||||
public boolean isRunTask() {
|
||||
return isRunTask;
|
||||
}
|
||||
|
||||
public void setRunTask(boolean isRunTask) {
|
||||
this.isRunTask = isRunTask;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.mac.common.domain;
|
||||
|
||||
/**
|
||||
* md-edit插件上传图片返回数据实体类
|
||||
*
|
||||
* @author ma116
|
||||
*/
|
||||
public class UploadFile {
|
||||
private String fileName;
|
||||
private String fileType;
|
||||
private long fileSize;
|
||||
private String timeStampName;
|
||||
private int success;
|
||||
private String message;
|
||||
private String url;
|
||||
|
||||
public long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
public void setFileSize(long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
public String getTimeStampName() {
|
||||
return timeStampName;
|
||||
}
|
||||
|
||||
public void setTimeStampName(String timeStampName) {
|
||||
this.timeStampName = timeStampName;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileType() {
|
||||
return fileType;
|
||||
}
|
||||
|
||||
public void setFileType(String fileType) {
|
||||
this.fileType = fileType;
|
||||
}
|
||||
|
||||
public int getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(int success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.mac.common.domain;
|
||||
|
||||
public class sigarBean {
|
||||
private String userName;
|
||||
private String computerName;
|
||||
private String userDomain;
|
||||
private String hostAddress;
|
||||
private String hostName;
|
||||
private String totalMemory;
|
||||
private String freeMemory;
|
||||
}
|
246
file-common/src/main/java/com/mac/common/http/HttpsUtils.java
Normal file
246
file-common/src/main/java/com/mac/common/http/HttpsUtils.java
Normal file
@ -0,0 +1,246 @@
|
||||
package com.mac.common.http;
|
||||
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.TrustStrategy;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by xslde on 2018/7/21
|
||||
*/
|
||||
public class HttpsUtils {
|
||||
private static PoolingHttpClientConnectionManager connMgr;
|
||||
private static RequestConfig requestConfig;
|
||||
private static final int MAX_TIMEOUT = 7000;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HttpsUtils.class);
|
||||
|
||||
static {
|
||||
// 设置连接池
|
||||
connMgr = new PoolingHttpClientConnectionManager();
|
||||
// 设置连接池大小
|
||||
connMgr.setMaxTotal(100);
|
||||
connMgr.setDefaultMaxPerRoute(connMgr.getMaxTotal());
|
||||
// Validate connections after 1 sec of inactivity
|
||||
connMgr.setValidateAfterInactivity(1000);
|
||||
RequestConfig.Builder configBuilder = RequestConfig.custom();
|
||||
// 设置连接超时
|
||||
configBuilder.setConnectTimeout(MAX_TIMEOUT);
|
||||
// 设置读取超时
|
||||
configBuilder.setSocketTimeout(MAX_TIMEOUT);
|
||||
// 设置从连接池获取连接实例的超时
|
||||
configBuilder.setConnectionRequestTimeout(MAX_TIMEOUT);
|
||||
|
||||
requestConfig = configBuilder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 GET 请求(HTTP),不带输入数据
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static String doGet(String url) {
|
||||
return doGet(url, new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 GET 请求(HTTP),K-V形式
|
||||
*
|
||||
* @param url
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public static String doGet(String url, Map<String, Object> params) {
|
||||
String apiUrl = url;
|
||||
StringBuffer param = new StringBuffer();
|
||||
int i = 0;
|
||||
for (String key : params.keySet()) {
|
||||
if (i == 0)
|
||||
param.append("?");
|
||||
else
|
||||
param.append("&");
|
||||
param.append(key).append("=").append(params.get(key));
|
||||
i++;
|
||||
}
|
||||
apiUrl += param;
|
||||
String result = null;
|
||||
HttpClient httpClient = null;
|
||||
if (apiUrl.startsWith("https")) {
|
||||
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
|
||||
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
|
||||
} else {
|
||||
httpClient = HttpClients.createDefault();
|
||||
}
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet(apiUrl);
|
||||
HttpResponse response = httpClient.execute(httpGet);
|
||||
HttpEntity entity = response.getEntity();
|
||||
result = EntityUtils.toString(entity, "UTF-8");
|
||||
// if (entity != null) {
|
||||
// InputStream instream = entity.getContent();
|
||||
// result = new BufferedReader(new InputStreamReader(instream)).lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 POST 请求(HTTP),不带输入数据
|
||||
*
|
||||
* @param apiUrl
|
||||
* @return
|
||||
*/
|
||||
public static String doPost(String apiUrl) {
|
||||
return doPost(apiUrl, new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 POST 请求,K-V形式
|
||||
*
|
||||
* @param apiUrl API接口URL
|
||||
* @param params 参数map
|
||||
* @return
|
||||
*/
|
||||
public static String doPost(String apiUrl, Map<String, Object> params) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
if (apiUrl.startsWith("https")) {
|
||||
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
|
||||
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
|
||||
} else {
|
||||
httpClient = HttpClients.createDefault();
|
||||
}
|
||||
String httpStr = null;
|
||||
HttpPost httpPost = new HttpPost(apiUrl);
|
||||
CloseableHttpResponse response = null;
|
||||
|
||||
try {
|
||||
httpPost.setConfig(requestConfig);
|
||||
List<NameValuePair> pairList = new ArrayList<>(params.size());
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
|
||||
pairList.add(pair);
|
||||
}
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
|
||||
response = httpClient.execute(httpPost);
|
||||
HttpEntity entity = response.getEntity();
|
||||
httpStr = EntityUtils.toString(entity, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
} finally {
|
||||
if (response != null) {
|
||||
try {
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return httpStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 POST 请求,JSON形式
|
||||
*
|
||||
* @param apiUrl
|
||||
* @param json json对象
|
||||
* @return
|
||||
*/
|
||||
public static String doPost(String apiUrl, Object json) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
if (apiUrl.startsWith("https")) {
|
||||
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
|
||||
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
|
||||
} else {
|
||||
httpClient = HttpClients.createDefault();
|
||||
}
|
||||
String httpStr = null;
|
||||
HttpPost httpPost = new HttpPost(apiUrl);
|
||||
CloseableHttpResponse response = null;
|
||||
|
||||
try {
|
||||
httpPost.setConfig(requestConfig);
|
||||
StringEntity stringEntity = new StringEntity(json.toString(), "UTF-8");// 解决中文乱码问题
|
||||
stringEntity.setContentEncoding("UTF-8");
|
||||
stringEntity.setContentType("application/json");
|
||||
httpPost.setEntity(stringEntity);
|
||||
response = httpClient.execute(httpPost);
|
||||
HttpEntity entity = response.getEntity();
|
||||
httpStr = EntityUtils.toString(entity, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
} finally {
|
||||
if (response != null) {
|
||||
try {
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return httpStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建SSL安全连接
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static SSLConnectionSocketFactory createSSLConnSocketFactory() {
|
||||
SSLConnectionSocketFactory sslsf = null;
|
||||
try {
|
||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
||||
|
||||
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
return true;
|
||||
}
|
||||
}).build();
|
||||
sslsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
|
||||
|
||||
@Override
|
||||
public boolean verify(String arg0, SSLSession arg1) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} catch (GeneralSecurityException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return sslsf;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.mac.common.operation;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class EncryptOperation {
|
||||
|
||||
public static String encodeByMd5(String string) throws UnsupportedEncodingException {
|
||||
return DigestUtils.md5DigestAsHex(string.getBytes("utf-8"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,284 @@
|
||||
package com.mac.common.operation;
|
||||
|
||||
import com.mac.common.util.FileUtil;
|
||||
import com.mac.common.util.PathUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.Array;
|
||||
import java.sql.SQLOutput;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* 文件操作
|
||||
*/
|
||||
public class FileOperation {
|
||||
private static Logger logger = LoggerFactory.getLogger(FileOperation.class);
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
* @param fileUrl 文件路径
|
||||
* @return 新文件
|
||||
*/
|
||||
public static File newFile(String fileUrl) {
|
||||
File file = new File(fileUrl);
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param file 文件
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
public static boolean deleteFile(File file) {
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (file.isFile()){
|
||||
return file.delete();
|
||||
} else {
|
||||
for (File newfile: file.listFiles()){
|
||||
deleteFile(newfile);
|
||||
}
|
||||
}
|
||||
return file.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param fileUrl 文件路径
|
||||
* @return 删除是否成功
|
||||
*/
|
||||
public static boolean deleteFile(String fileUrl) {
|
||||
File file = newFile(fileUrl);
|
||||
return deleteFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到文件大小
|
||||
*
|
||||
* @param fileUrl 文件路径
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long getFileSize(String fileUrl) {
|
||||
File file = newFile(fileUrl);
|
||||
if (file.exists()){
|
||||
return file.length();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到文件大小
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long getFileSize(File file) {
|
||||
if (file == null) {
|
||||
return 0;
|
||||
}
|
||||
return file.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建目录
|
||||
* @param file 文件
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
public static boolean mkdir(File file) {
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.exists()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return file.mkdirs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建目录
|
||||
* @param fileUrl 文件路径
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
public static boolean mkdir(String fileUrl) {
|
||||
if (fileUrl == null) {
|
||||
return false;
|
||||
}
|
||||
File file = newFile(fileUrl);
|
||||
if (file.exists()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return file.mkdirs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件
|
||||
* @param fileInputStream 文件输入流
|
||||
* @param fileOutputStream 文件输出流
|
||||
* @throws IOException io异常
|
||||
*/
|
||||
public static void copyFile(FileInputStream fileInputStream, FileOutputStream fileOutputStream) throws IOException {
|
||||
try {
|
||||
byte[] buf = new byte[4096]; //8k的缓冲区
|
||||
|
||||
int len = fileInputStream.read(buf); //数据在buf中,len代表向buf中放了多少个字节的数据,-1代表读不到
|
||||
while (len != -1) {
|
||||
|
||||
fileOutputStream.write(buf, 0, len); //读多少个字节,写多少个字节
|
||||
|
||||
len = fileInputStream.read(buf);
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
try {
|
||||
fileInputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (fileOutputStream != null) {
|
||||
try {
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件
|
||||
* @param src 源文件
|
||||
* @param dest 目的文件
|
||||
* @throws IOException io异常
|
||||
*/
|
||||
public static void copyFile(File src, File dest) throws IOException {
|
||||
FileInputStream in = new FileInputStream(src);
|
||||
FileOutputStream out = new FileOutputStream(dest);
|
||||
|
||||
copyFile(in, out);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件
|
||||
* @param srcUrl 源路径
|
||||
* @param destUrl 目的路径
|
||||
* @throws IOException io异常
|
||||
*/
|
||||
public static void copyFile(String srcUrl, String destUrl) throws IOException {
|
||||
if (srcUrl == null || destUrl == null) {
|
||||
return;
|
||||
}
|
||||
File srcFile = newFile(srcUrl);
|
||||
File descFile = newFile(destUrl);
|
||||
copyFile(srcFile, descFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件解压缩
|
||||
* @param file 需要解压的文件
|
||||
* @param destDirPath 目的路径
|
||||
* @return 解压目录列表
|
||||
*/
|
||||
public static List<String> unzip(File file, String destDirPath) {
|
||||
ZipFile zipFile = null;
|
||||
Set<String> set = new HashSet<String>();
|
||||
// set.add("/");
|
||||
List<String> fileEntryNameList = new ArrayList<>();
|
||||
try {
|
||||
zipFile = new ZipFile(file);
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
|
||||
String[] nameStrArr = entry.getName().split("/");
|
||||
String nameStr = "/";
|
||||
for (int i = 0; i < nameStrArr.length; i++){
|
||||
if (!"".equals(nameStrArr[i])){
|
||||
nameStr =nameStr + "/" + nameStrArr[i];
|
||||
set.add(nameStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logger.info("解压" + entry.getName());
|
||||
String zipPath = "/" + entry.getName();
|
||||
fileEntryNameList.add(zipPath);
|
||||
//如果是文件夹,就创建个文件夹
|
||||
if (entry.isDirectory()) {
|
||||
String dirPath = destDirPath + File.separator + entry.getName();
|
||||
File dir = FileOperation.newFile(dirPath);
|
||||
|
||||
dir.mkdir();
|
||||
} else {
|
||||
//如果是文件,就先创建一个文件,然后用io流把内容拷过去
|
||||
File targetFile = new File(destDirPath + "/" + entry.getName());
|
||||
// 保证这个文件的父文件夹必须要存在
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
targetFile.createNewFile();
|
||||
// 将压缩文件内容写入到这个文件中
|
||||
InputStream is = zipFile.getInputStream(entry);
|
||||
FileOutputStream fos = new FileOutputStream(targetFile);
|
||||
int len;
|
||||
byte[] buf = new byte[2048];
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
// 关流顺序,先打开的后关闭
|
||||
fos.close();
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("unzip error from ZipUtils", e);
|
||||
} finally {
|
||||
if (zipFile != null) {
|
||||
try {
|
||||
zipFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> res = new ArrayList<>(set);
|
||||
return res ;
|
||||
}
|
||||
|
||||
public static long deleteFileFromDisk(String fileurl){
|
||||
String fileUrl = PathUtil.getStaticPath() + fileurl;
|
||||
String extendName = FileUtil.getFileType(fileUrl);
|
||||
String minFileUrl = fileUrl.replace("." + extendName, "_min." + extendName);
|
||||
long filesize = getFileSize(fileUrl);
|
||||
|
||||
FileOperation.deleteFile(fileUrl);
|
||||
FileOperation.deleteFile(minFileUrl);
|
||||
|
||||
return filesize;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.mac.common.operation;
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImageOperation {
|
||||
/**
|
||||
* 左旋
|
||||
* @param inFile 源文件
|
||||
* @param outFile 目的文件
|
||||
* @param angle 角度
|
||||
* @throws IOException io异常
|
||||
*/
|
||||
public static void leftTotation(File inFile, File outFile, int angle) throws IOException {
|
||||
Thumbnails.of(inFile).scale(1).outputQuality(1).rotate(-angle).toFile(outFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 右旋
|
||||
* @param inFile 源文件
|
||||
* @param outFile 目的文件
|
||||
* @param angle 角度
|
||||
* @throws IOException io异常
|
||||
*/
|
||||
public static void rightTotation(File inFile, File outFile, int angle) throws IOException {
|
||||
Thumbnails.of(inFile).scale(1).outputQuality(1).rotate(angle).toFile(outFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩
|
||||
* @param inFile 源文件
|
||||
* @param outFile 目的文件
|
||||
* @throws IOException io异常
|
||||
*/
|
||||
public static void thumbnailsImage(File inFile, File outFile, int imageSize) throws IOException {
|
||||
|
||||
Thumbnails.of(inFile).size(imageSize, imageSize)
|
||||
.toFile(outFile);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.mac.common.operation;
|
||||
|
||||
public class ReflectOperation {
|
||||
|
||||
public static Object createObjectByClassName(String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||
Class<?> object = Class.forName(classname);
|
||||
return object.newInstance();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.mac.common.proxy;
|
||||
|
||||
public class ProxyConstant {
|
||||
public static final String[] userAgentArr = {"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36 OPR/37.0.2178.32",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586",
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
|
||||
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
|
||||
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
|
||||
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.3 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36 Core/1.47.277.400 QQBrowser/9.4.7658.400",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 UBrowser/5.6.12150.8 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 TheWorld 7",
|
||||
"Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/60.0"};
|
||||
|
||||
/**
|
||||
* 获取代理IP列表的服务器地址
|
||||
*/
|
||||
public static final String SERVER_IP = "123.56.9.174";
|
||||
|
||||
/**
|
||||
* 获取代理IP的数量
|
||||
*/
|
||||
public static final int SERVER_PROXY_COUNT = 100;
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.mac.common.proxy;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ProxyOrigin {
|
||||
public static List<String> getConnectProxyList(){
|
||||
|
||||
final WebClient webClient = new WebClient(BrowserVersion.CHROME);//新建一个模拟谷歌Chrome浏览器的浏览器客户端对象
|
||||
|
||||
webClient.getOptions().setThrowExceptionOnScriptError(false);//当JS执行出错的时候是否抛出异常, 这里选择不需要
|
||||
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);//当HTTP的状态非200时是否抛出异常, 这里选择不需要
|
||||
webClient.getOptions().setActiveXNative(false);
|
||||
webClient.getOptions().setCssEnabled(false);//是否启用CSS, 因为不需要展现页面, 所以不需要启用
|
||||
webClient.getOptions().setJavaScriptEnabled(true); //很重要,启用JS
|
||||
webClient.setAjaxController(new NicelyResynchronizingAjaxController());//很重要,设置支持AJAX
|
||||
|
||||
HtmlPage page = null;
|
||||
try {
|
||||
page = webClient.getPage("http://www.goubanjia.com/");//尝试加载上面图片例子给出的网页
|
||||
webClient.waitForBackgroundJavaScript(1000);//异步JS执行需要耗时,所以这里线程要阻塞30秒,等待异步JS执行结束
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
webClient.close();
|
||||
}
|
||||
String pageXml = page.asXml();//直接将加载完成的页面转换成xml格式的字符串
|
||||
|
||||
pageXml = pageXml.replaceAll("<[a-z]+ style=\"display *: *none;\">[^<>]*</[a-z]+>", " ");
|
||||
|
||||
Document document = Jsoup.parse(pageXml);//获取html文档
|
||||
Elements ipElements = document.getElementsByClass("ip");
|
||||
List<String> proxyList = new ArrayList<String>();
|
||||
for (int i = 0; i < ipElements.size(); i++){
|
||||
proxyList.add(ipElements.get(i).text().replaceAll(" ", ""));
|
||||
|
||||
System.out.println(ipElements.get(i).text().replaceAll(" ", ""));
|
||||
}
|
||||
|
||||
return proxyList;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.mac.common.proxy;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ProxyUtil {
|
||||
|
||||
|
||||
public static boolean connectTest(String ip, int port){
|
||||
boolean isTestSuccess = true;
|
||||
try {
|
||||
Document doc = Jsoup.connect("http://www.ityouknow.com/")
|
||||
.timeout(5000)
|
||||
.proxy(ip, port)
|
||||
.get();
|
||||
} catch (IOException e) {
|
||||
isTestSuccess = false;
|
||||
}
|
||||
return isTestSuccess;
|
||||
}
|
||||
}
|
95
file-common/src/main/java/com/mac/common/util/FileUtil.java
Normal file
95
file-common/src/main/java/com/mac/common/util/FileUtil.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.mac.common.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static final String[] IMG_FILE = {"bmp", "jpg", "png", "tif", "gif", "jpeg"};
|
||||
public static final String[] DOC_FILE = {"doc", "docx", "txt", "hlp", "wps", "rtf", "html", "pdf"};
|
||||
public static final String[] VIDEO_FILE = {"avi", "mp4", "mpg", "mov", "swf"};
|
||||
public static final String[] MUSIC_FILE = {"wav", "aif", "au", "mp3", "ram", "wma", "mmf", "amr", "aac", "flac"};
|
||||
public static final int IMAGE_TYPE = 1;
|
||||
public static final int DOC_TYPE = 2;
|
||||
public static final int VIDEO_TYPE = 3;
|
||||
public static final int MUSIC_TYPE = 4;
|
||||
|
||||
public static List<String> getFileExtendsByType(int fileType) {
|
||||
|
||||
List<String> fileExtends;
|
||||
switch (fileType) {
|
||||
case IMAGE_TYPE:
|
||||
fileExtends = Arrays.asList(IMG_FILE);
|
||||
break;
|
||||
|
||||
case DOC_TYPE:
|
||||
fileExtends = Arrays.asList(DOC_FILE);
|
||||
break;
|
||||
case VIDEO_TYPE:
|
||||
fileExtends = Arrays.asList(VIDEO_FILE);
|
||||
break;
|
||||
case MUSIC_TYPE:
|
||||
fileExtends = Arrays.asList(MUSIC_FILE);
|
||||
break;
|
||||
default:
|
||||
fileExtends = new ArrayList<>();
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return fileExtends;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为图片文件
|
||||
*
|
||||
* @param extendName 文件扩展名
|
||||
* @return 是否为图片文件
|
||||
*/
|
||||
public static boolean isImageFile(String extendName) {
|
||||
for (int i = 0; i < IMG_FILE.length; i++) {
|
||||
if (extendName.equalsIgnoreCase(IMG_FILE[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String pathSplitFormat(String filePath) {
|
||||
String path = filePath.replace("///", "/")
|
||||
.replace("//", "/")
|
||||
.replace("\\\\\\", "\\")
|
||||
.replace("\\\\", "\\");
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件扩展名
|
||||
* @param fileName 文件名
|
||||
* @return 文件扩展名
|
||||
*/
|
||||
public static String getFileType(String fileName) {
|
||||
if (fileName.lastIndexOf(".") == -1) {
|
||||
return "";
|
||||
//这里暂时用jpg,后续应该去获取真实的文件类型
|
||||
}
|
||||
return fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不包含扩展名的文件名
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @return 文件名(不带扩展名)
|
||||
*/
|
||||
public static String getFileNameNotExtend(String fileName) {
|
||||
String fileType = getFileType(fileName);
|
||||
return fileName.replace("." + fileType, "");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.mac.common.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class PasswordUtil {
|
||||
public static String getSaltValue(){
|
||||
Random r = new Random();
|
||||
StringBuilder sb = new StringBuilder(16);
|
||||
sb.append(r.nextInt(99999999)).append(r.nextInt(99999999));
|
||||
int len = sb.length();
|
||||
if (len < 16){
|
||||
for (int i = 0; i < 16 - len; i++){
|
||||
sb.append("0");
|
||||
}
|
||||
}
|
||||
String salt = sb.toString();
|
||||
return salt;
|
||||
}
|
||||
}
|
93
file-common/src/main/java/com/mac/common/util/PathUtil.java
Normal file
93
file-common/src/main/java/com/mac/common/util/PathUtil.java
Normal file
@ -0,0 +1,93 @@
|
||||
package com.mac.common.util;
|
||||
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class PathUtil {
|
||||
/**
|
||||
* 获取项目所在的根目录路径 resources路径
|
||||
* @return
|
||||
*/
|
||||
public static String getProjectRootPath() {
|
||||
String absolutePath = null;
|
||||
try {
|
||||
String url = ResourceUtils.getURL("classpath:").getPath();
|
||||
absolutePath = urlDecode(new File(url).getAbsolutePath()) + File.separator;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 路径解码
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static String urlDecode(String url){
|
||||
String decodeUrl = null;
|
||||
try {
|
||||
decodeUrl = URLDecoder.decode(url, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return decodeUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到static路径
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getStaticPath() {
|
||||
String projectRootAbsolutePath = getProjectRootPath();
|
||||
|
||||
int index = projectRootAbsolutePath.indexOf("file:");
|
||||
if (index != -1){
|
||||
projectRootAbsolutePath = projectRootAbsolutePath.substring(0, index);
|
||||
}
|
||||
|
||||
return projectRootAbsolutePath + "static" + File.separator;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据原始文件名生成新文件名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getFileName(String fileName) {
|
||||
String getfileName = "";
|
||||
try {
|
||||
SecureRandom number = SecureRandom.getInstance("SHA1PRNG");
|
||||
return getfileName = "" + number.nextInt(10000)
|
||||
+ System.currentTimeMillis() + getFileExt(fileName);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
//LOG.error("生成安全随机数失败");
|
||||
}
|
||||
return getfileName = ""
|
||||
+ System.currentTimeMillis() + getFileExt(fileName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件扩展名
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static String getFileExt(String fileName) {
|
||||
if (fileName.lastIndexOf(".") == -1) {
|
||||
return ".png";
|
||||
//这里暂时用jpg,后续应该去获取真实的文件类型
|
||||
}
|
||||
return fileName.substring(fileName.lastIndexOf("."));
|
||||
}
|
||||
}
|
264
file-common/src/main/resources/conf/settings.xml
Normal file
264
file-common/src/main/resources/conf/settings.xml
Normal file
@ -0,0 +1,264 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
| This is the configuration file for Maven. It can be specified at two levels:
|
||||
|
|
||||
| 1. User Level. This settings.xml file provides configuration for a single user,
|
||||
| and is normally provided in ${user.home}/.m2/settings.xml.
|
||||
|
|
||||
| NOTE: This location can be overridden with the CLI option:
|
||||
|
|
||||
| -s /path/to/user/settings.xml
|
||||
|
|
||||
| 2. Global Level. This settings.xml file provides configuration for all Maven
|
||||
| users on a machine (assuming they're all using the same Maven
|
||||
| installation). It's normally provided in
|
||||
| ${maven.conf}/settings.xml.
|
||||
|
|
||||
| NOTE: This location can be overridden with the CLI option:
|
||||
|
|
||||
| -gs /path/to/global/settings.xml
|
||||
|
|
||||
| The sections in this sample file are intended to give you a running start at
|
||||
| getting the most out of your Maven installation. Where appropriate, the default
|
||||
| values (values used when the setting is not specified) are provided.
|
||||
|
|
||||
|-->
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<!-- localRepository
|
||||
| The path to the local repository maven will use to store artifacts.
|
||||
|
|
||||
| Default: ${user.home}/.m2/repository-->
|
||||
<localRepository>D:\maven-repository</localRepository>
|
||||
|
||||
|
||||
<!-- interactiveMode
|
||||
| This will determine whether maven prompts you when it needs input. If set to false,
|
||||
| maven will use a sensible default value, perhaps based on some other setting, for
|
||||
| the parameter in question.
|
||||
|
|
||||
| Default: true
|
||||
<interactiveMode>true</interactiveMode>
|
||||
-->
|
||||
|
||||
<!-- offline
|
||||
| Determines whether maven should attempt to connect to the network when executing a build.
|
||||
| This will have an effect on artifact downloads, artifact deployment, and others.
|
||||
|
|
||||
| Default: false
|
||||
<offline>false</offline>
|
||||
-->
|
||||
|
||||
<!-- pluginGroups
|
||||
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
|
||||
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
|
||||
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|
||||
|-->
|
||||
<pluginGroups>
|
||||
<!-- pluginGroup
|
||||
| Specifies a further group identifier to use for plugin lookup.
|
||||
<pluginGroup>com.your.plugins</pluginGroup>
|
||||
-->
|
||||
<pluginGroup>com.spotify</pluginGroup>
|
||||
</pluginGroups>
|
||||
|
||||
<!-- proxies
|
||||
| This is a list of proxies which can be used on this machine to connect to the network.
|
||||
| Unless otherwise specified (by system property or command-line switch), the first proxy
|
||||
| specification in this list marked as active will be used.
|
||||
|-->
|
||||
<proxies>
|
||||
<!-- proxy
|
||||
| Specification for one proxy, to be used in connecting to the network.
|
||||
|
|
||||
<proxy>
|
||||
<id>optional</id>
|
||||
<active>true</active>
|
||||
<protocol>http</protocol>
|
||||
<username>proxyuser</username>
|
||||
<password>proxypass</password>
|
||||
<host>proxy.host.net</host>
|
||||
<port>80</port>
|
||||
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
|
||||
</proxy>
|
||||
-->
|
||||
</proxies>
|
||||
|
||||
<!-- servers
|
||||
| This is a list of authentication profiles, keyed by the server-id used within the system.
|
||||
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|
||||
|-->
|
||||
<servers>
|
||||
<!-- server
|
||||
| Specifies the authentication information to use when connecting to a particular server, identified by
|
||||
| a unique name within the system (referred to by the 'id' attribute below).
|
||||
|
|
||||
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
|
||||
| used together.
|
||||
|
|
||||
<server>
|
||||
<id>deploymentRepo</id>
|
||||
<username>repouser</username>
|
||||
<password>repopwd</password>
|
||||
</server>
|
||||
-->
|
||||
|
||||
<!-- Another sample, using keys to authenticate.
|
||||
<server>
|
||||
<id>siteServer</id>
|
||||
<privateKey>/path/to/private/key</privateKey>
|
||||
<passphrase>optional; leave empty if not used.</passphrase>
|
||||
</server>
|
||||
-->
|
||||
</servers>
|
||||
|
||||
<!-- mirrors
|
||||
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
||||
|
|
||||
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
|
||||
| However, this repository may have problems with heavy traffic at times, so people have mirrored
|
||||
| it to several places.
|
||||
|
|
||||
| That repository definition will have a unique id, so we can create a mirror reference for that
|
||||
| repository, to be used as an alternate download site. The mirror site will be the preferred
|
||||
| server for that repository.
|
||||
|-->
|
||||
<mirrors>
|
||||
<!-- mirror
|
||||
| Specifies a repository mirror site to use instead of a given repository. The repository that
|
||||
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
|
||||
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
||||
|
|
||||
<mirror>
|
||||
<id>mirrorId</id>
|
||||
<mirrorOf>repositoryId</mirrorOf>
|
||||
<name>Human Readable Name for this Mirror.</name>
|
||||
<url>http://my.repository.com/repo/path</url>
|
||||
</mirror>
|
||||
-->
|
||||
<mirror>
|
||||
<id>alimaven</id>
|
||||
<name>aliyun maven</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<mirrorOf>central</mirrorOf>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
|
||||
<!-- profiles
|
||||
| This is a list of profiles which can be activated in a variety of ways, and which can modify
|
||||
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
|
||||
| specific paths and repository locations which allow the build to work in the local environment.
|
||||
|
|
||||
| For example, if you have an integration testing plugin - like cactus - that needs to know where
|
||||
| your Tomcat instance is installed, you can provide a variable here such that the variable is
|
||||
| dereferenced during the build process to configure the cactus plugin.
|
||||
|
|
||||
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
|
||||
| section of this document (settings.xml) - will be discussed later. Another way essentially
|
||||
| relies on the detection of a system property, either matching a particular value for the property,
|
||||
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
|
||||
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
|
||||
| Finally, the list of active profiles can be specified directly from the command line.
|
||||
|
|
||||
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
|
||||
| repositories, plugin repositories, and free-form properties to be used as configuration
|
||||
| variables for plugins in the POM.
|
||||
|
|
||||
|-->
|
||||
<profiles>
|
||||
<!-- profile
|
||||
| Specifies a set of introductions to the build process, to be activated using one or more of the
|
||||
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
|
||||
| or the command line, profiles have to have an ID that is unique.
|
||||
|
|
||||
| An encouraged best practice for profile identification is to use a consistent naming convention
|
||||
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
|
||||
| This will make it more intuitive to understand what the set of introduced profiles is attempting
|
||||
| to accomplish, particularly when you only have a list of profile id's for debug.
|
||||
|
|
||||
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
|
||||
<profile>
|
||||
<id>jdk-1.4</id>
|
||||
|
||||
<activation>
|
||||
<jdk>1.4</jdk>
|
||||
</activation>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jdk14</id>
|
||||
<name>Repository for JDK 1.4 builds</name>
|
||||
<url>http://www.myhost.com/maven/jdk14</url>
|
||||
<layout>default</layout>
|
||||
<snapshotPolicy>always</snapshotPolicy>
|
||||
</repository>
|
||||
</repositories>
|
||||
</profile>
|
||||
-->
|
||||
|
||||
<!--
|
||||
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
|
||||
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
|
||||
| might hypothetically look like:
|
||||
|
|
||||
| ...
|
||||
| <plugin>
|
||||
| <groupId>org.myco.myplugins</groupId>
|
||||
| <artifactId>myplugin</artifactId>
|
||||
|
|
||||
| <configuration>
|
||||
| <tomcatLocation>${tomcatPath}</tomcatLocation>
|
||||
| </configuration>
|
||||
| </plugin>
|
||||
| ...
|
||||
|
|
||||
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
|
||||
| anything, you could just leave off the <value/> inside the activation-property.
|
||||
|
|
||||
<profile>
|
||||
<id>env-dev</id>
|
||||
|
||||
<activation>
|
||||
<property>
|
||||
<name>target-env</name>
|
||||
<value>dev</value>
|
||||
</property>
|
||||
</activation>
|
||||
|
||||
<properties>
|
||||
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
|
||||
</properties>
|
||||
</profile>
|
||||
-->
|
||||
</profiles>
|
||||
|
||||
<!-- activeProfiles
|
||||
| List of profiles that are active for all builds.
|
||||
|
|
||||
<activeProfiles>
|
||||
<activeProfile>alwaysActiveProfile</activeProfile>
|
||||
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
|
||||
</activeProfiles>
|
||||
-->
|
||||
</settings>
|
34
file-common/src/main/resources/mybatis.xml
Normal file
34
file-common/src/main/resources/mybatis.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
|
||||
<configuration>
|
||||
<properties>
|
||||
<property name="driver" value="com.mysql.jdbc.Driver"/>
|
||||
<property name="url" value="jdbc:mysql://localhost:3306/scp?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8"/>
|
||||
<property name="username" value="root"/>
|
||||
<property name="password" value="ma123456"/>
|
||||
</properties>
|
||||
<environments default="dev">
|
||||
<environment id="dev">
|
||||
<transactionManager type="JDBC"></transactionManager>
|
||||
<dataSource type="POOLED">
|
||||
<property name="driver" value="${driver}"/>
|
||||
<property name="url" value="${url}"/>
|
||||
<property name="username" value="${username}"/>
|
||||
<property name="password" value="${password}"/>
|
||||
</dataSource>
|
||||
</environment>
|
||||
<environment id="product">
|
||||
<transactionManager type="JDBC"></transactionManager>
|
||||
<dataSource type="JNDI">
|
||||
<property name="initial_context" value="java:comp/env"/>
|
||||
<property name="date_source" value="jdbc/mac"/>
|
||||
</dataSource>
|
||||
</environment>
|
||||
</environments>
|
||||
<mappers>
|
||||
<mapper resource="mybatis/mapper/ChatMapper.xml"/>
|
||||
</mappers>
|
||||
</configuration>
|
BIN
file-common/target/classes/com/mac/common/cbb/CollectUtil.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/CollectUtil.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/DateUtil.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/DateUtil.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/HttpRequest.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/HttpRequest.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/MiniuiUtil.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/MiniuiUtil.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/MyBatisUtil.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/MyBatisUtil.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/RestResult.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/RestResult.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/ScpConstant.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/ScpConstant.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/Test.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/Test.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/Uploader.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/Uploader.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/cbb/checkIp.class
Normal file
BIN
file-common/target/classes/com/mac/common/cbb/checkIp.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/domain/ProxyBean.class
Normal file
BIN
file-common/target/classes/com/mac/common/domain/ProxyBean.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/domain/TableData.class
Normal file
BIN
file-common/target/classes/com/mac/common/domain/TableData.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/domain/sigarBean.class
Normal file
BIN
file-common/target/classes/com/mac/common/domain/sigarBean.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/http/HttpsUtils.class
Normal file
BIN
file-common/target/classes/com/mac/common/http/HttpsUtils.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/proxy/ProxyUtil.class
Normal file
BIN
file-common/target/classes/com/mac/common/proxy/ProxyUtil.class
Normal file
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/util/FileUtil.class
Normal file
BIN
file-common/target/classes/com/mac/common/util/FileUtil.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
file-common/target/classes/com/mac/common/util/PathUtil.class
Normal file
BIN
file-common/target/classes/com/mac/common/util/PathUtil.class
Normal file
Binary file not shown.
264
file-common/target/classes/conf/settings.xml
Normal file
264
file-common/target/classes/conf/settings.xml
Normal file
@ -0,0 +1,264 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
| This is the configuration file for Maven. It can be specified at two levels:
|
||||
|
|
||||
| 1. User Level. This settings.xml file provides configuration for a single user,
|
||||
| and is normally provided in ${user.home}/.m2/settings.xml.
|
||||
|
|
||||
| NOTE: This location can be overridden with the CLI option:
|
||||
|
|
||||
| -s /path/to/user/settings.xml
|
||||
|
|
||||
| 2. Global Level. This settings.xml file provides configuration for all Maven
|
||||
| users on a machine (assuming they're all using the same Maven
|
||||
| installation). It's normally provided in
|
||||
| ${maven.conf}/settings.xml.
|
||||
|
|
||||
| NOTE: This location can be overridden with the CLI option:
|
||||
|
|
||||
| -gs /path/to/global/settings.xml
|
||||
|
|
||||
| The sections in this sample file are intended to give you a running start at
|
||||
| getting the most out of your Maven installation. Where appropriate, the default
|
||||
| values (values used when the setting is not specified) are provided.
|
||||
|
|
||||
|-->
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<!-- localRepository
|
||||
| The path to the local repository maven will use to store artifacts.
|
||||
|
|
||||
| Default: ${user.home}/.m2/repository-->
|
||||
<localRepository>D:\maven-repository</localRepository>
|
||||
|
||||
|
||||
<!-- interactiveMode
|
||||
| This will determine whether maven prompts you when it needs input. If set to false,
|
||||
| maven will use a sensible default value, perhaps based on some other setting, for
|
||||
| the parameter in question.
|
||||
|
|
||||
| Default: true
|
||||
<interactiveMode>true</interactiveMode>
|
||||
-->
|
||||
|
||||
<!-- offline
|
||||
| Determines whether maven should attempt to connect to the network when executing a build.
|
||||
| This will have an effect on artifact downloads, artifact deployment, and others.
|
||||
|
|
||||
| Default: false
|
||||
<offline>false</offline>
|
||||
-->
|
||||
|
||||
<!-- pluginGroups
|
||||
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
|
||||
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
|
||||
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|
||||
|-->
|
||||
<pluginGroups>
|
||||
<!-- pluginGroup
|
||||
| Specifies a further group identifier to use for plugin lookup.
|
||||
<pluginGroup>com.your.plugins</pluginGroup>
|
||||
-->
|
||||
<pluginGroup>com.spotify</pluginGroup>
|
||||
</pluginGroups>
|
||||
|
||||
<!-- proxies
|
||||
| This is a list of proxies which can be used on this machine to connect to the network.
|
||||
| Unless otherwise specified (by system property or command-line switch), the first proxy
|
||||
| specification in this list marked as active will be used.
|
||||
|-->
|
||||
<proxies>
|
||||
<!-- proxy
|
||||
| Specification for one proxy, to be used in connecting to the network.
|
||||
|
|
||||
<proxy>
|
||||
<id>optional</id>
|
||||
<active>true</active>
|
||||
<protocol>http</protocol>
|
||||
<username>proxyuser</username>
|
||||
<password>proxypass</password>
|
||||
<host>proxy.host.net</host>
|
||||
<port>80</port>
|
||||
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
|
||||
</proxy>
|
||||
-->
|
||||
</proxies>
|
||||
|
||||
<!-- servers
|
||||
| This is a list of authentication profiles, keyed by the server-id used within the system.
|
||||
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|
||||
|-->
|
||||
<servers>
|
||||
<!-- server
|
||||
| Specifies the authentication information to use when connecting to a particular server, identified by
|
||||
| a unique name within the system (referred to by the 'id' attribute below).
|
||||
|
|
||||
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
|
||||
| used together.
|
||||
|
|
||||
<server>
|
||||
<id>deploymentRepo</id>
|
||||
<username>repouser</username>
|
||||
<password>repopwd</password>
|
||||
</server>
|
||||
-->
|
||||
|
||||
<!-- Another sample, using keys to authenticate.
|
||||
<server>
|
||||
<id>siteServer</id>
|
||||
<privateKey>/path/to/private/key</privateKey>
|
||||
<passphrase>optional; leave empty if not used.</passphrase>
|
||||
</server>
|
||||
-->
|
||||
</servers>
|
||||
|
||||
<!-- mirrors
|
||||
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
||||
|
|
||||
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
|
||||
| However, this repository may have problems with heavy traffic at times, so people have mirrored
|
||||
| it to several places.
|
||||
|
|
||||
| That repository definition will have a unique id, so we can create a mirror reference for that
|
||||
| repository, to be used as an alternate download site. The mirror site will be the preferred
|
||||
| server for that repository.
|
||||
|-->
|
||||
<mirrors>
|
||||
<!-- mirror
|
||||
| Specifies a repository mirror site to use instead of a given repository. The repository that
|
||||
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
|
||||
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
||||
|
|
||||
<mirror>
|
||||
<id>mirrorId</id>
|
||||
<mirrorOf>repositoryId</mirrorOf>
|
||||
<name>Human Readable Name for this Mirror.</name>
|
||||
<url>http://my.repository.com/repo/path</url>
|
||||
</mirror>
|
||||
-->
|
||||
<mirror>
|
||||
<id>alimaven</id>
|
||||
<name>aliyun maven</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<mirrorOf>central</mirrorOf>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
|
||||
<!-- profiles
|
||||
| This is a list of profiles which can be activated in a variety of ways, and which can modify
|
||||
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
|
||||
| specific paths and repository locations which allow the build to work in the local environment.
|
||||
|
|
||||
| For example, if you have an integration testing plugin - like cactus - that needs to know where
|
||||
| your Tomcat instance is installed, you can provide a variable here such that the variable is
|
||||
| dereferenced during the build process to configure the cactus plugin.
|
||||
|
|
||||
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
|
||||
| section of this document (settings.xml) - will be discussed later. Another way essentially
|
||||
| relies on the detection of a system property, either matching a particular value for the property,
|
||||
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
|
||||
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
|
||||
| Finally, the list of active profiles can be specified directly from the command line.
|
||||
|
|
||||
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
|
||||
| repositories, plugin repositories, and free-form properties to be used as configuration
|
||||
| variables for plugins in the POM.
|
||||
|
|
||||
|-->
|
||||
<profiles>
|
||||
<!-- profile
|
||||
| Specifies a set of introductions to the build process, to be activated using one or more of the
|
||||
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
|
||||
| or the command line, profiles have to have an ID that is unique.
|
||||
|
|
||||
| An encouraged best practice for profile identification is to use a consistent naming convention
|
||||
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
|
||||
| This will make it more intuitive to understand what the set of introduced profiles is attempting
|
||||
| to accomplish, particularly when you only have a list of profile id's for debug.
|
||||
|
|
||||
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
|
||||
<profile>
|
||||
<id>jdk-1.4</id>
|
||||
|
||||
<activation>
|
||||
<jdk>1.4</jdk>
|
||||
</activation>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jdk14</id>
|
||||
<name>Repository for JDK 1.4 builds</name>
|
||||
<url>http://www.myhost.com/maven/jdk14</url>
|
||||
<layout>default</layout>
|
||||
<snapshotPolicy>always</snapshotPolicy>
|
||||
</repository>
|
||||
</repositories>
|
||||
</profile>
|
||||
-->
|
||||
|
||||
<!--
|
||||
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
|
||||
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
|
||||
| might hypothetically look like:
|
||||
|
|
||||
| ...
|
||||
| <plugin>
|
||||
| <groupId>org.myco.myplugins</groupId>
|
||||
| <artifactId>myplugin</artifactId>
|
||||
|
|
||||
| <configuration>
|
||||
| <tomcatLocation>${tomcatPath}</tomcatLocation>
|
||||
| </configuration>
|
||||
| </plugin>
|
||||
| ...
|
||||
|
|
||||
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
|
||||
| anything, you could just leave off the <value/> inside the activation-property.
|
||||
|
|
||||
<profile>
|
||||
<id>env-dev</id>
|
||||
|
||||
<activation>
|
||||
<property>
|
||||
<name>target-env</name>
|
||||
<value>dev</value>
|
||||
</property>
|
||||
</activation>
|
||||
|
||||
<properties>
|
||||
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
|
||||
</properties>
|
||||
</profile>
|
||||
-->
|
||||
</profiles>
|
||||
|
||||
<!-- activeProfiles
|
||||
| List of profiles that are active for all builds.
|
||||
|
|
||||
<activeProfiles>
|
||||
<activeProfile>alwaysActiveProfile</activeProfile>
|
||||
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
|
||||
</activeProfiles>
|
||||
-->
|
||||
</settings>
|
34
file-common/target/classes/mybatis.xml
Normal file
34
file-common/target/classes/mybatis.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
|
||||
<configuration>
|
||||
<properties>
|
||||
<property name="driver" value="com.mysql.jdbc.Driver"/>
|
||||
<property name="url" value="jdbc:mysql://localhost:3306/scp?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8"/>
|
||||
<property name="username" value="root"/>
|
||||
<property name="password" value="ma123456"/>
|
||||
</properties>
|
||||
<environments default="dev">
|
||||
<environment id="dev">
|
||||
<transactionManager type="JDBC"></transactionManager>
|
||||
<dataSource type="POOLED">
|
||||
<property name="driver" value="${driver}"/>
|
||||
<property name="url" value="${url}"/>
|
||||
<property name="username" value="${username}"/>
|
||||
<property name="password" value="${password}"/>
|
||||
</dataSource>
|
||||
</environment>
|
||||
<environment id="product">
|
||||
<transactionManager type="JDBC"></transactionManager>
|
||||
<dataSource type="JNDI">
|
||||
<property name="initial_context" value="java:comp/env"/>
|
||||
<property name="date_source" value="jdbc/mac"/>
|
||||
</dataSource>
|
||||
</environment>
|
||||
</environments>
|
||||
<mappers>
|
||||
<mapper resource="mybatis/mapper/ChatMapper.xml"/>
|
||||
</mappers>
|
||||
</configuration>
|
BIN
file-common/target/file-common-0.0.1-SNAPSHOT.jar
Normal file
BIN
file-common/target/file-common-0.0.1-SNAPSHOT.jar
Normal file
Binary file not shown.
4
file-common/target/maven-archiver/pom.properties
Normal file
4
file-common/target/maven-archiver/pom.properties
Normal file
@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.6.1
|
||||
version=0.0.1-SNAPSHOT
|
||||
groupId=com.qiwen
|
||||
artifactId=file-common
|
@ -0,0 +1,30 @@
|
||||
com\mac\common\domain\TaskProcess.class
|
||||
com\mac\common\cbb\MyBatisUtil.class
|
||||
com\mac\common\domain\UploadFile.class
|
||||
com\mac\common\http\HttpsUtils$1.class
|
||||
com\mac\common\domain\TableQueryBean.class
|
||||
com\mac\common\cbb\MiniuiUtil.class
|
||||
com\mac\common\cbb\CollectUtil.class
|
||||
com\mac\common\cbb\RestResult.class
|
||||
com\mac\common\cbb\HttpRequest.class
|
||||
com\mac\common\domain\sigarBean.class
|
||||
com\mac\common\util\FileUtil.class
|
||||
com\mac\common\util\PathUtil.class
|
||||
com\mac\common\operation\ImageOperation.class
|
||||
com\mac\common\proxy\ProxyUtil.class
|
||||
com\mac\common\cbb\checkIp.class
|
||||
com\mac\common\operation\EncryptOperation.class
|
||||
com\mac\common\cbb\DateUtil.class
|
||||
com\mac\common\operation\FileOperation.class
|
||||
com\mac\common\cbb\ScpConstant.class
|
||||
com\mac\common\domain\ProxyBean.class
|
||||
com\mac\common\domain\TableData.class
|
||||
com\mac\common\operation\ReflectOperation.class
|
||||
com\mac\common\proxy\ProxyOrigin.class
|
||||
com\mac\common\cbb\Uploader.class
|
||||
com\mac\common\cbb\HibernateUtil.class
|
||||
com\mac\common\cbb\Test.class
|
||||
com\mac\common\http\HttpsUtils.class
|
||||
com\mac\common\proxy\ProxyConstant.class
|
||||
com\mac\common\util\PasswordUtil.class
|
||||
com\mac\common\http\HttpsUtils$2.class
|
@ -0,0 +1,27 @@
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\util\PasswordUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\proxy\ProxyUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\domain\sigarBean.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\HttpRequest.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\Test.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\MyBatisUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\domain\TableQueryBean.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\MiniuiUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\operation\ReflectOperation.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\proxy\ProxyOrigin.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\domain\ProxyBean.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\operation\FileOperation.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\proxy\ProxyConstant.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\DateUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\domain\TaskProcess.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\http\HttpsUtils.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\util\PathUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\domain\UploadFile.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\operation\ImageOperation.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\util\FileUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\HibernateUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\domain\TableData.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\operation\EncryptOperation.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\CollectUtil.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\Uploader.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\ScpConstant.java
|
||||
E:\ideaProject\qiwen-file\file-common\src\main\java\com\mac\common\cbb\RestResult.java
|
29
file-web/.gitignore
vendored
Normal file
29
file-web/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
197
file-web/pom.xml
Normal file
197
file-web/pom.xml
Normal file
@ -0,0 +1,197 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.qiwen</groupId>
|
||||
<artifactId>file</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.qiwen</groupId>
|
||||
<artifactId>file-web</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>web</name>
|
||||
<description>www.qiwenshare.com/file</description>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
|
||||
<skipTests>true</skipTests>
|
||||
<docker.image.prefix>scp</docker.image.prefix>
|
||||
<release-path>target/../../release</release-path>
|
||||
<app-name>${project.artifactId}-${project.version}</app-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- spring boot依赖包 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<version>RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--登陆认证和权限管理-->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<version>1.9.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.fusesource</groupId>
|
||||
<artifactId>sigar</artifactId>
|
||||
<version>1.6.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mac</groupId>
|
||||
<artifactId>scp-common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--redis-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
|
||||
<build>
|
||||
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
</plugin>
|
||||
<!--排除静态文件-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>static/**</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--ant插件执行自定义动作-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<copy file="target/${app-name}.jar" tofile="${release-path}/app/${project.artifactId}/${app-name}.jar" />
|
||||
<copy file="target/classes/script/startWeb.bat" tofile="${release-path}/startWeb.bat" />
|
||||
|
||||
<copy todir="${release-path}">
|
||||
<fileset dir="target/classes">
|
||||
<include name="**/static/**" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
<!-- Docker maven plugin -->
|
||||
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
||||
<dockerDirectory>src/main/docker</dockerDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Docker maven plugin -->
|
||||
|
||||
</plugins>
|
||||
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
4
file-web/src/main/docker/Dockerfile
Normal file
4
file-web/src/main/docker/Dockerfile
Normal file
@ -0,0 +1,4 @@
|
||||
FROM openjdk:8-jdk-alpine
|
||||
VOLUME /tmp
|
||||
ADD scp-web-0.0.1-SNAPSHOT.jar app.jar
|
||||
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
|
28
file-web/src/main/java/com/mac/scp/FileApplication.java
Normal file
28
file-web/src/main/java/com/mac/scp/FileApplication.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.mac.scp;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootApplication//(exclude={DataSourceAutoConfiguration.class})
|
||||
//@EnableCaching //开启ehcache缓存
|
||||
@MapperScan("com.mac.scp.mapper")
|
||||
@EnableScheduling //启用定时任务
|
||||
public class FileApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FileApplication.class, args);
|
||||
//SocketManager.getInstance();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
24
file-web/src/main/java/com/mac/scp/api/IFileService.java
Normal file
24
file-web/src/main/java/com/mac/scp/api/IFileService.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.mac.scp.api;
|
||||
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.scp.domain.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
public interface IFileService {
|
||||
|
||||
void insertFile(FileBean fileBean);
|
||||
void batchInsertFile(List<FileBean> fileBeanList);
|
||||
void updateFile(FileBean fileBean);
|
||||
FileBean selectFileById(FileBean fileBean);
|
||||
List<FileBean> selectFilePathTreeByUserid(FileBean fileBean);
|
||||
List<FileBean> selectFileList(FileBean fileBean);
|
||||
List<FileBean> selectFileListByIds(List<Integer> fileidList);
|
||||
|
||||
List<FileBean> selectFileTreeListLikeFilePath(String filePath);
|
||||
void deleteFile(FileBean fileBean);
|
||||
void deleteFileByIds(List<Integer> fileidList);
|
||||
void updateFilepathByFilepath(String oldfilepath, String newfilepath, String filename, String extendname);
|
||||
List<FileBean> selectFileByExtendName(List<String> filenameList, long userid);
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.mac.scp.api;
|
||||
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.scp.domain.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface IFiletransferService {
|
||||
|
||||
|
||||
/**
|
||||
* 删除用户头像通过id
|
||||
*
|
||||
* @param userImageBean 用户头像信息
|
||||
*/
|
||||
void deleteUserImageById(UserImageBean userImageBean);
|
||||
|
||||
|
||||
/**
|
||||
* 用户头像插入数据库
|
||||
*
|
||||
* @param userImageBean 用户头像信息
|
||||
* @return 插入结果
|
||||
*/
|
||||
RestResult<String> insertUserImage(UserImageBean userImageBean);
|
||||
|
||||
|
||||
/**
|
||||
* 上传头像
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 结果
|
||||
*/
|
||||
RestResult<String> uploadUserImage(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param request 请求
|
||||
* @param fileBean 文件信息
|
||||
*/
|
||||
void uploadFile(HttpServletRequest request, FileBean fileBean);
|
||||
|
||||
/**
|
||||
* 选择用户头像
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 返回用户头像列表
|
||||
*/
|
||||
RestResult<List<UserImageBean>> selectUserImage(long userId);
|
||||
|
||||
/**
|
||||
* 选择用户头像通过url
|
||||
*
|
||||
* @param url url路径
|
||||
* @return 头像列表
|
||||
*/
|
||||
List<UserImageBean> selectUserImageByUrl(String url);
|
||||
|
||||
|
||||
void deleteUserImageByIds(List<Integer> imageidList);
|
||||
|
||||
StorageBean selectStorageBean(StorageBean storageBean);
|
||||
|
||||
void insertStorageBean(StorageBean storageBean);
|
||||
|
||||
void updateStorageBean(StorageBean storageBean);
|
||||
|
||||
StorageBean selectStorageByUser(StorageBean storageBean);
|
||||
}
|
123
file-web/src/main/java/com/mac/scp/api/IUserService.java
Normal file
123
file-web/src/main/java/com/mac/scp/api/IUserService.java
Normal file
@ -0,0 +1,123 @@
|
||||
package com.mac.scp.api;
|
||||
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.common.domain.TableQueryBean;
|
||||
import com.mac.scp.domain.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IUserService {
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param userBean 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
RestResult<String> registerUser(UserBean userBean);
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
* @param userBean
|
||||
* @return
|
||||
*/
|
||||
RestResult<String> addUser(UserBean userBean);
|
||||
|
||||
/**
|
||||
* 用户登陆
|
||||
*
|
||||
* @param userBean 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
UserBean loginUser(UserBean userBean);
|
||||
|
||||
/**
|
||||
* 选择admin用户
|
||||
*
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<UserBean> selectAdminUserList();
|
||||
|
||||
/**
|
||||
* 删除用户信息
|
||||
*
|
||||
* @param userBean 用户信息
|
||||
*/
|
||||
void deleteUserInfo(UserBean userBean);
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserBean getUserInfoById(long userId);
|
||||
|
||||
/**
|
||||
* 通過openid得到用戶信息
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
UserBean selectUserByopenid(String openid);
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户信息
|
||||
*
|
||||
* @param UserName 用户名
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserBean findUserInfoByName(String UserName);
|
||||
|
||||
/**
|
||||
* 通过用户名和密码获取用户信息
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param password 密码
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserBean findUserInfoByNameAndPassword(String userName, String password);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
* @param userBean 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
RestResult<String> updateUserInfo(UserBean userBean);
|
||||
|
||||
/**
|
||||
* 选择所有用户列表
|
||||
*
|
||||
* @return 所有用户列表
|
||||
*/
|
||||
List<UserBean> selectAllUserList();
|
||||
|
||||
/**
|
||||
* 选择所有用户列表
|
||||
* @param tableQueryBean 查询条件
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<UserBean> selectUserList(TableQueryBean tableQueryBean);
|
||||
|
||||
/**
|
||||
* 选择所有用户角色
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<Role> selectRoleList();
|
||||
|
||||
/**
|
||||
* 选择所有用户角色
|
||||
* @param tableQueryBean 查询条件
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<Permission> selectPermissionList(TableQueryBean tableQueryBean);
|
||||
|
||||
/**
|
||||
* 获取用户数量
|
||||
* @param tableQueryBean 查询条件
|
||||
* @return 用户数量
|
||||
*/
|
||||
int selectUserCountByCondition(TableQueryBean tableQueryBean);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.mac.scp.config.cors;
|
||||
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistration;
|
||||
|
||||
public class MyCorsRegistration extends CorsRegistration {
|
||||
public MyCorsRegistration(String pathPattern) {
|
||||
super(pathPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CorsConfiguration getCorsConfiguration() {
|
||||
return super.getCorsConfiguration();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.mac.scp.config.exception;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Configuration
|
||||
public class ExceptionConfig {
|
||||
|
||||
/**
|
||||
* springMVC全局异常处理框架
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public SimpleMappingExceptionResolver resolver() {
|
||||
SimpleMappingExceptionResolver resolver = new SimpleMappingExceptionResolver();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("org.apache.shiro.authz.UnauthorizedException", "/403");
|
||||
resolver.setExceptionMappings(properties);
|
||||
return resolver;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.mac.scp.config.exception;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* 全局异常捕获
|
||||
*/
|
||||
//@ControllerAdvice
|
||||
//public class MyExceptionHandler {
|
||||
// private static Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);
|
||||
// @ExceptionHandler(value = Exception.class)
|
||||
// public void defaultExceptionHandler(HttpServletRequest req, HttpSession session,Exception e){
|
||||
// //String errorSource= session.getAttribute("errorSource").toString();
|
||||
// logger.error(e.getMessage());
|
||||
// //根据抓获的异常类型,做逻辑处理,并打印日志信息
|
||||
//
|
||||
// e.printStackTrace();
|
||||
// System.out.println("全局异常捕获中");
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
@ -0,0 +1,45 @@
|
||||
package com.mac.scp.config.redis;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.Duration;
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class RedisConfig extends CachingConfigurerSupport {
|
||||
|
||||
@Bean
|
||||
public KeyGenerator keyGenerator() {
|
||||
return new KeyGenerator() {
|
||||
@Override
|
||||
public Object generate(Object target, Method method, Object... params) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(target.getClass().getName());
|
||||
sb.append(method.getName());
|
||||
for (Object obj : params) {
|
||||
sb.append(obj.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofHours(1)); // 设置缓存有效期一小时
|
||||
return RedisCacheManager
|
||||
.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
|
||||
.cacheDefaults(redisCacheConfiguration).build();
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.mac.scp.config.shiro;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.mac.scp.domain.Permission;
|
||||
import com.mac.scp.domain.Role;
|
||||
import com.mac.scp.domain.UserBean;
|
||||
import com.mac.scp.service.UserService;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.util.ByteSource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MyShiroRealm extends AuthorizingRealm {
|
||||
@Resource
|
||||
private UserService userInfoService;
|
||||
|
||||
public static Map<String, UserBean> qqLoginInfoMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
System.out.println("权限配置-->MyShiroRealm.doGetAuthorizationInfo()");
|
||||
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
|
||||
UserBean userInfo = (UserBean) principals.getPrimaryPrincipal();
|
||||
for (Role role : userInfo.getRoleList()) {
|
||||
authorizationInfo.addRole(role.getRole());
|
||||
for (Permission p : role.getPermissions()) {
|
||||
authorizationInfo.addStringPermission(p.getPermission());
|
||||
}
|
||||
}
|
||||
return authorizationInfo;
|
||||
}
|
||||
|
||||
/*主要是用来进行身份认证的,也就是说验证用户输入的账号和密码是否正确。*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
|
||||
throws AuthenticationException {
|
||||
System.out.println("MyShiroRealm.doGetAuthenticationInfo()");
|
||||
//获取用户的输入的账号.
|
||||
String username = (String) token.getPrincipal();
|
||||
String password = new String((char[]) token.getCredentials());
|
||||
//String tempsalt = PasswordUtil.getSaltValue();
|
||||
//String newPassword = new SimpleHash("MD5", password, tempsalt, 1024).toHex();
|
||||
UserBean qquserinfo = qqLoginInfoMap.get(username + password);
|
||||
SimpleAuthenticationInfo authenticationInfo = null;
|
||||
if (qquserinfo != null){ //qq登录
|
||||
System.out.println(JSON.toJSONString(qquserinfo));
|
||||
// UserBean userInfo = new UserBean();
|
||||
// userInfo.setUsername(qquserinfo.getNickname());
|
||||
// userInfo.setAddrprovince(qquserinfo.getProvince());
|
||||
// userInfo.setAddrcity(qquserinfo.getCity());
|
||||
// userInfo.setBirthday(qquserinfo.getYear());
|
||||
// userInfo.setSex(qquserinfo.getGender());
|
||||
// ByteSource byteSourceSalt = ByteSource.Util.bytes(tempsalt);
|
||||
// authenticationInfo = new SimpleAuthenticationInfo(
|
||||
// userInfo, //用户名
|
||||
// newPassword, //密码
|
||||
// byteSourceSalt,
|
||||
// getName() //realm name
|
||||
// );
|
||||
UserBean userInfo = userInfoService.selectUserByopenid(password);
|
||||
System.out.println("----->>userInfo=" + userInfo);
|
||||
if (userInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ByteSource byteSourceSalt = ByteSource.Util.bytes(userInfo.getSalt());
|
||||
authenticationInfo = new SimpleAuthenticationInfo(
|
||||
userInfo, //用户名
|
||||
userInfo.getPassword(), //密码
|
||||
byteSourceSalt,
|
||||
getName() //realm name
|
||||
);
|
||||
}else {
|
||||
|
||||
UserBean userInfo = userInfoService.findUserInfoByName(username);
|
||||
System.out.println("----->>userInfo=" + userInfo);
|
||||
if (userInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ByteSource byteSourceSalt = ByteSource.Util.bytes(userInfo.getSalt());
|
||||
authenticationInfo = new SimpleAuthenticationInfo(
|
||||
userInfo, //用户名
|
||||
userInfo.getPassword(), //密码
|
||||
byteSourceSalt,
|
||||
getName() //realm name
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//mailService.sendLoginSafeMail(userInfo); //登录邮件
|
||||
|
||||
return authenticationInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
143
file-web/src/main/java/com/mac/scp/config/shiro/ShiroConfig.java
Normal file
143
file-web/src/main/java/com/mac/scp/config/shiro/ShiroConfig.java
Normal file
@ -0,0 +1,143 @@
|
||||
package com.mac.scp.config.shiro;
|
||||
|
||||
import com.mac.scp.config.cors.MyCorsRegistration;
|
||||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@Configuration
|
||||
public class ShiroConfig {
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
|
||||
System.out.println("ShiroConfiguration.shirFilter()" + "mac");
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||
//拦截器.
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
||||
|
||||
//配置退出过滤器
|
||||
filterChainDefinitionMap.put("/logout", "logout");
|
||||
|
||||
//<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
|
||||
filterChainDefinitionMap.put("/user/userlogin", "authc");
|
||||
|
||||
// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
|
||||
shiroFilterFactoryBean.setLoginUrl("/user/userlogin");
|
||||
// 登录成功后要跳转的链接
|
||||
shiroFilterFactoryBean.setSuccessUrl("/index");
|
||||
//未授权界面;
|
||||
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
|
||||
//filterChainDefinitionMap.put("/**", "perms");
|
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
||||
return shiroFilterFactoryBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 凭证匹配器
|
||||
* (由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了
|
||||
* )
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public HashedCredentialsMatcher hashedCredentialsMatcher() {
|
||||
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
|
||||
hashedCredentialsMatcher.setHashAlgorithmName("md5");//散列算法:这里使用MD5算法;
|
||||
hashedCredentialsMatcher.setHashIterations(1024);//散列的次数,比如散列两次,相当于 md5(md5(""));
|
||||
return hashedCredentialsMatcher;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MyShiroRealm myShiroRealm() {
|
||||
MyShiroRealm myShiroRealm = new MyShiroRealm();
|
||||
myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
|
||||
return myShiroRealm;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public SecurityManager securityManager() {
|
||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||
securityManager.setRealm(myShiroRealm());
|
||||
return securityManager;
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator(){
|
||||
// DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
// advisorAutoProxyCreator.setProxyTargetClass(true);
|
||||
// return advisorAutoProxyCreator;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 开启shiro aop注解支持.
|
||||
* 使用代理方式;所以需要开启代码支持;
|
||||
*
|
||||
* @param securityManager
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
|
||||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
||||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
||||
return authorizationAttributeSourceAdvisor;
|
||||
}
|
||||
|
||||
@Bean(name = "simpleMappingExceptionResolver")
|
||||
public SimpleMappingExceptionResolver
|
||||
createSimpleMappingExceptionResolver() {
|
||||
SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver();
|
||||
Properties mappings = new Properties();
|
||||
mappings.setProperty("DatabaseException", "databaseError");//数据库异常处理
|
||||
mappings.setProperty("UnauthorizedException", "403");
|
||||
r.setExceptionMappings(mappings); // None by default
|
||||
r.setDefaultErrorView("error"); // No default
|
||||
r.setExceptionAttribute("ex"); // Default is "exception"
|
||||
//r.setWarnLogCategory("example.MvcLogger"); // No default
|
||||
return r;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean filterRegistrationBean() {
|
||||
// 对响应头进行CORS授权
|
||||
MyCorsRegistration corsRegistration = new MyCorsRegistration("*");
|
||||
|
||||
corsRegistration
|
||||
//允许向该服务器提交请求的URI,*表示全部允许
|
||||
.allowedOrigins("*")
|
||||
//允许提交请求的方法,*表示全部允许
|
||||
.allowedMethods("*")
|
||||
//允许的头信息,*标识全部允许
|
||||
.allowedHeaders("*")
|
||||
//暴露的头信息
|
||||
.exposedHeaders("access-control-allow-headers",
|
||||
"access-control-allow-methods",
|
||||
"access-control-allow-origin",
|
||||
"access-control-max-age",
|
||||
"X-Frame-Options")
|
||||
//允许Cookie跨域,在做登录校验的时候有用CrossOrigin.DEFAULT_ALLOW_CREDENTIALS
|
||||
.allowCredentials(true);
|
||||
|
||||
// 注册CORS过滤器
|
||||
UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
|
||||
//第一个参数表示过滤的url,*表示过滤所有
|
||||
configurationSource.registerCorsConfiguration("/**", corsRegistration.getCorsConfiguration());
|
||||
CorsFilter corsFilter = new CorsFilter(configurationSource);
|
||||
|
||||
return new FilterRegistrationBean(corsFilter);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.mac.scp.config.shiro;
|
||||
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Order(-100)
|
||||
@Component
|
||||
@ServletComponentScan
|
||||
@WebFilter(urlPatterns = "/*",filterName = "shiroLoginFilter")
|
||||
public class ShiroLoginFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
// 允许哪些Origin发起跨域请求
|
||||
String orgin = request.getHeader("Origin");
|
||||
// response.setHeader( "Access-Control-Allow-Origin", config.getInitParameter( "AccessControlAllowOrigin" ) );
|
||||
response.setHeader( "Access-Control-Allow-Origin", orgin );
|
||||
// 允许请求的方法
|
||||
response.setHeader( "Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,PUT" );
|
||||
//多少秒内,不需要再发送预检验请求,可以缓存该结果
|
||||
response.setHeader( "Access-Control-Max-Age", "3600" );
|
||||
// 表明它允许跨域请求包含xxx头
|
||||
response.setHeader( "Access-Control-Allow-Headers", "x-auth-token,Origin,Access-Token,X-Requested-With,Content-Type, Accept" );
|
||||
//是否允许浏览器携带用户身份信息(cookie)
|
||||
response.setHeader( "Access-Control-Allow-Credentials", "true" );
|
||||
//prefight请求
|
||||
if (request.getMethod().equals( "OPTIONS" )) {
|
||||
response.setStatus( 200 );
|
||||
return;
|
||||
}
|
||||
chain.doFilter( servletRequest, response );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,399 @@
|
||||
package com.mac.scp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.mac.common.cbb.DateUtil;
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.common.operation.FileOperation;
|
||||
import com.mac.common.util.FileUtil;
|
||||
import com.mac.common.util.PathUtil;
|
||||
import com.mac.scp.api.IFileService;
|
||||
import com.mac.scp.api.IFiletransferService;
|
||||
import com.mac.scp.domain.*;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static com.mac.common.util.FileUtil.getFileExtendsByType;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
public class FileController {
|
||||
|
||||
@Resource
|
||||
IFileService fileService;
|
||||
@Resource
|
||||
IFiletransferService filetransferService;
|
||||
|
||||
/**
|
||||
* 是否开启共享文件模式
|
||||
*/
|
||||
public static Boolean isShareFile = true;
|
||||
|
||||
public static long treeid = 0;
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/fileindex")
|
||||
@ResponseBody
|
||||
public ModelAndView essayIndex() {
|
||||
ModelAndView mv = new ModelAndView("/file/fileIndex.html");
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/createfile")
|
||||
@ResponseBody
|
||||
public RestResult<String> createFile(FileBean fileBean) {
|
||||
RestResult<String> restResult = new RestResult<>();
|
||||
if (!operationCheck().isSuccess()){
|
||||
return operationCheck();
|
||||
}
|
||||
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
fileBean.setUserid(sessionUserBean.getUserId());
|
||||
|
||||
fileBean.setUploadtime(DateUtil.getCurrentTime());
|
||||
|
||||
fileService.insertFile(fileBean);
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
}
|
||||
|
||||
@RequestMapping("/getfilelist")
|
||||
@ResponseBody
|
||||
public RestResult<List<FileBean>> getFileList(FileBean fileBean){
|
||||
RestResult<List<FileBean>> restResult = new RestResult<>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
if(isShareFile){
|
||||
fileBean.setUserid(2);
|
||||
}else {
|
||||
fileBean.setUserid(sessionUserBean.getUserId());
|
||||
}
|
||||
|
||||
fileBean.setFilepath(PathUtil.urlDecode(fileBean.getFilepath()));
|
||||
List<FileBean> fileList = fileService.selectFileList(fileBean);
|
||||
|
||||
if ("/".equals(fileBean.getFilepath())){
|
||||
FileBean albumFile = new FileBean();
|
||||
albumFile.setFilename("我的相册");
|
||||
|
||||
albumFile.setFilepath("/");
|
||||
albumFile.setIsdir(1);
|
||||
fileList.add(albumFile);
|
||||
}
|
||||
|
||||
|
||||
restResult.setData(fileList);
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/batchdeletefile")
|
||||
@ResponseBody
|
||||
public String deleteImageByIds(String files) {
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
if (!operationCheck().isSuccess()){
|
||||
return JSON.toJSONString(operationCheck());
|
||||
}
|
||||
|
||||
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
||||
|
||||
for (FileBean fileBean : fileList) {
|
||||
fileService.deleteFile(fileBean);
|
||||
}
|
||||
|
||||
result.setData("批量删除文件成功");
|
||||
result.setSuccess(true);
|
||||
String resultJson = JSON.toJSONString(result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/deletefile")
|
||||
@ResponseBody
|
||||
public String deleteFile(FileBean fileBean) {
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
if (!operationCheck().isSuccess()){
|
||||
return JSON.toJSONString(operationCheck());
|
||||
}
|
||||
|
||||
fileService.deleteFile(fileBean);
|
||||
|
||||
result.setSuccess(true);
|
||||
String resultJson = JSON.toJSONString(result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/unzipfile")
|
||||
@ResponseBody
|
||||
public String unzipFile(FileBean fileBean){
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
if (!operationCheck().isSuccess()){
|
||||
return JSON.toJSONString(operationCheck());
|
||||
}
|
||||
|
||||
String zipFileUrl = PathUtil.getStaticPath() + fileBean.getFileurl();
|
||||
File file = FileOperation.newFile(zipFileUrl);
|
||||
String unzipUrl = file.getParent();
|
||||
|
||||
List<String> fileEntryNameList = FileOperation.unzip(file, unzipUrl);
|
||||
|
||||
List<FileBean> fileBeanList = new ArrayList<>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
for (int i = 0; i < fileEntryNameList.size(); i++){
|
||||
String entryName = fileEntryNameList.get(i);
|
||||
String totalFileUrl = unzipUrl + entryName;
|
||||
File currentFile = FileOperation.newFile(totalFileUrl);
|
||||
|
||||
FileBean tempFileBean = new FileBean();
|
||||
tempFileBean.setUploadtime(DateUtil.getCurrentTime());
|
||||
tempFileBean.setUserid(sessionUserBean.getUserId());
|
||||
tempFileBean.setFilepath(FileUtil.pathSplitFormat(fileBean.getFilepath() + entryName.replace(currentFile.getName(), "")));
|
||||
if (currentFile.isDirectory()){
|
||||
|
||||
tempFileBean.setIsdir(1);
|
||||
|
||||
tempFileBean.setFilename(currentFile.getName());
|
||||
tempFileBean.setTimestampname(currentFile.getName());
|
||||
//tempFileBean.setFileurl(File.separator + (file.getParent() + File.separator + currentFile.getName()).replace(PathUtil.getStaticPath(), ""));
|
||||
}else{
|
||||
|
||||
tempFileBean.setIsdir(0);
|
||||
|
||||
tempFileBean.setExtendname(FileUtil.getFileType(totalFileUrl));
|
||||
tempFileBean.setFilename(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
||||
tempFileBean.setFilesize(currentFile.length());
|
||||
tempFileBean.setTimestampname(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
||||
tempFileBean.setFileurl(File.separator + (currentFile.getPath()).replace(PathUtil.getStaticPath(), ""));
|
||||
}
|
||||
fileBeanList.add(tempFileBean);
|
||||
}
|
||||
fileService.batchInsertFile(fileBeanList);
|
||||
result.setSuccess(true);
|
||||
String resultJson = JSON.toJSONString(result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件移动
|
||||
* @param oldfilepath 源路径
|
||||
* @param newfilepath 目的路径
|
||||
* @param filename 文件名
|
||||
* @return 返回前台移动结果
|
||||
*/
|
||||
@RequestMapping("/movefile")
|
||||
@ResponseBody
|
||||
public RestResult<String> moveFile(String oldfilepath, String newfilepath, String filename, String extendname){
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
if (!operationCheck().isSuccess()){
|
||||
return operationCheck();
|
||||
}
|
||||
|
||||
fileService.updateFilepathByFilepath(oldfilepath, newfilepath, filename, extendname);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量移动文件
|
||||
* @param newfilepath 目的路径
|
||||
* @param files 需要移动的文件列表
|
||||
* @return 返回前台移动结果
|
||||
*/
|
||||
@RequestMapping("/batchmovefile")
|
||||
@ResponseBody
|
||||
public RestResult<String> batchMoveFile(String newfilepath, String files){
|
||||
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
if (!operationCheck().isSuccess()){
|
||||
return operationCheck();
|
||||
}
|
||||
|
||||
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
||||
|
||||
for (FileBean fileBean : fileList) {
|
||||
fileService.updateFilepathByFilepath(fileBean.getFilepath(), newfilepath, fileBean.getFilename(), fileBean.getExtendname());
|
||||
}
|
||||
|
||||
result.setData("批量移动文件成功");
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public RestResult<String> operationCheck(){
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
if (sessionUserBean == null){
|
||||
result.setSuccess(false);
|
||||
result.setErrorMessage("未登录");
|
||||
return result;
|
||||
}
|
||||
if (isShareFile){
|
||||
if (sessionUserBean.getUserId() > 2){
|
||||
result.setSuccess(false);
|
||||
result.setErrorMessage("没权限,请联系管理员!");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文件类型选择文件
|
||||
* @param fileType 文件类型
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/selectfilebyfiletype")
|
||||
@ResponseBody
|
||||
public RestResult<List<FileBean>> selectFileByFileType(int fileType){
|
||||
RestResult<List<FileBean>> result = new RestResult<List<FileBean>>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
long userid = sessionUserBean.getUserId();
|
||||
if (isShareFile){
|
||||
userid = 2;
|
||||
}
|
||||
List<FileBean> file = fileService.selectFileByExtendName(getFileExtendsByType(fileType), userid);
|
||||
result.setData(file);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件树
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getfiletree")
|
||||
@ResponseBody
|
||||
public RestResult<TreeNode> getFileTree(){
|
||||
RestResult<TreeNode> result = new RestResult<TreeNode>();
|
||||
FileBean fileBean = new FileBean();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
if (isShareFile){
|
||||
fileBean.setUserid(2);
|
||||
}else{
|
||||
fileBean.setUserid(sessionUserBean.getUserId());
|
||||
}
|
||||
|
||||
List<FileBean> filePathList = fileService.selectFilePathTreeByUserid(fileBean);
|
||||
TreeNode resultTreeNode = new TreeNode();
|
||||
resultTreeNode.setNodeName("/");
|
||||
|
||||
for (int i = 0; i < filePathList.size(); i++){
|
||||
String filePath = filePathList.get(i).getFilepath() + filePathList.get(i).getFilename() + "/";
|
||||
|
||||
Queue<String> queue = new LinkedList<>();
|
||||
|
||||
String[] strArr = filePath.split("/");
|
||||
for (int j = 0; j < strArr.length; j++){
|
||||
if (!"".equals(strArr[j]) && strArr[j] != null){
|
||||
queue.add(strArr[j]);
|
||||
}
|
||||
|
||||
}
|
||||
if (queue.size() == 0){
|
||||
continue;
|
||||
}
|
||||
resultTreeNode = insertTreeNode(resultTreeNode,"/", queue);
|
||||
|
||||
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setData(resultTreeNode);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public TreeNode insertTreeNode(TreeNode treeNode, String filepath, Queue<String> nodeNameQueue){
|
||||
|
||||
List<TreeNode> childrenTreeNodes = treeNode.getChildren();
|
||||
String currentNodeName = nodeNameQueue.peek();
|
||||
if (currentNodeName == null){
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
filepath = filepath + currentNodeName + "/";
|
||||
map.put("filepath", filepath);
|
||||
|
||||
if (!isExistPath(childrenTreeNodes, currentNodeName)){ //1、判断有没有该子节点,如果没有则插入
|
||||
//插入
|
||||
TreeNode resultTreeNode = new TreeNode();
|
||||
|
||||
|
||||
resultTreeNode.setAttributes(map);
|
||||
resultTreeNode.setNodeName(nodeNameQueue.poll());
|
||||
resultTreeNode.setId(treeid++);
|
||||
|
||||
childrenTreeNodes.add(resultTreeNode);
|
||||
|
||||
}else{ //2、如果有,则跳过
|
||||
nodeNameQueue.poll();
|
||||
}
|
||||
|
||||
if (nodeNameQueue.size() != 0) {
|
||||
for (int i = 0; i < childrenTreeNodes.size(); i++) {
|
||||
|
||||
TreeNode childrenTreeNode = childrenTreeNodes.get(i);
|
||||
if (currentNodeName.equals(childrenTreeNode.getLabel())){
|
||||
childrenTreeNode = insertTreeNode(childrenTreeNode, filepath, nodeNameQueue);
|
||||
childrenTreeNodes.remove(i);
|
||||
childrenTreeNodes.add(childrenTreeNode);
|
||||
treeNode.setChildNode(childrenTreeNodes);
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
treeNode.setChildNode(childrenTreeNodes);
|
||||
}
|
||||
|
||||
return treeNode;
|
||||
|
||||
}
|
||||
|
||||
public boolean isExistPath(List<TreeNode> childrenTreeNodes, String path){
|
||||
boolean isExistPath = false;
|
||||
|
||||
try {
|
||||
for (int i = 0; i < childrenTreeNodes.size(); i++){
|
||||
if (path.equals(childrenTreeNodes.get(i).getLabel())){
|
||||
isExistPath = true;
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return isExistPath;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,327 @@
|
||||
package com.mac.scp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.mac.common.operation.FileOperation;
|
||||
import com.mac.common.util.PathUtil;
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.common.operation.ImageOperation;
|
||||
import com.mac.scp.api.IFileService;
|
||||
import com.mac.scp.api.IFiletransferService;
|
||||
import com.mac.scp.domain.*;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/filetransfer")
|
||||
public class FiletransferController {
|
||||
|
||||
@Resource
|
||||
IFiletransferService filetransferService;
|
||||
@Resource
|
||||
IFileService fileService;
|
||||
|
||||
/**
|
||||
* 删除用户头像
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 删除结果
|
||||
*/
|
||||
@RequestMapping("/deleteuserimage")
|
||||
@ResponseBody
|
||||
public String deleteUserImage(HttpServletRequest request, UserImageBean userImageBean) {
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
String servletPath = request.getServletPath();
|
||||
String realPath = request.getSession().getServletContext().getRealPath(servletPath);
|
||||
|
||||
List<UserImageBean> userImageList = filetransferService.selectUserImageByUrl(userImageBean.getImageurl().replace("filetransfer/", ""));
|
||||
if (userImageList.size() <= 0) {
|
||||
result.setSuccess(false);
|
||||
result.setErrorMessage("文件路径不正确");
|
||||
return JSON.toJSONString(result);
|
||||
}
|
||||
String fileRealPath = new File(new File(realPath).getParent()).getParent() + "/" + userImageBean.getImageurl();
|
||||
File file = new File(fileRealPath);
|
||||
filetransferService.deleteUserImageById(userImageBean);
|
||||
|
||||
if (file.isFile() && file.exists()) {
|
||||
boolean isDeleteSuccess = file.delete();
|
||||
if (isDeleteSuccess) {
|
||||
result.setSuccess(true);
|
||||
} else {
|
||||
result.setSuccess(false);
|
||||
result.setErrorMessage("文件删除失败");
|
||||
}
|
||||
} else {
|
||||
result.setSuccess(true);
|
||||
result.setErrorMessage("文件不存在");
|
||||
}
|
||||
|
||||
String resultJson = JSON.toJSONString(result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 旋转图片
|
||||
* @param direction 方向
|
||||
* @param imageid 图片id
|
||||
* @return 返回结果
|
||||
*/
|
||||
@RequestMapping("/totationimage")
|
||||
@ResponseBody
|
||||
public RestResult<String> totationImage(String direction, int imageid){
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
FileBean fileBean = new FileBean();
|
||||
fileBean.setFileid(imageid);
|
||||
fileBean = fileService.selectFileById(fileBean);
|
||||
String imageUrl = fileBean.getFileurl();
|
||||
String extendName = fileBean.getExtendname();
|
||||
File file = FileOperation.newFile(PathUtil.getStaticPath() + imageUrl);
|
||||
File minfile = FileOperation.newFile(PathUtil.getStaticPath() + imageUrl.replace("." + extendName, "_min." + extendName));
|
||||
if ("left".equals(direction)){
|
||||
try {
|
||||
ImageOperation.leftTotation(file, file, 90);
|
||||
ImageOperation.leftTotation(minfile, minfile, 90);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else if ("right".equals(direction)){
|
||||
try {
|
||||
ImageOperation.rightTotation(file, file, 90);
|
||||
ImageOperation.rightTotation(minfile, minfile, 90);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除图片
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/deleteimagebyids")
|
||||
@ResponseBody
|
||||
public String deleteImageByIds(String imageids) {
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
List<Integer> imageidList = JSON.parseArray(imageids, Integer.class);
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
|
||||
long sessionUserId = sessionUserBean.getUserId();
|
||||
|
||||
// List<ImageBean> imageBeanList = filetransferService.selectUserImageByIds(imageidList);
|
||||
// filetransferService.deleteUserImageByIds(imageidList);
|
||||
List<FileBean> fileList = fileService.selectFileListByIds(imageidList);
|
||||
fileService.deleteFileByIds(imageidList);
|
||||
long totalFileSize = 0;
|
||||
for (FileBean fileBean : fileList) {
|
||||
String imageUrl = PathUtil.getStaticPath() + fileBean.getFileurl();
|
||||
String minImageUrl = imageUrl.replace("." + fileBean.getExtendname(), "_min." + fileBean.getExtendname());
|
||||
totalFileSize += FileOperation.getFileSize(imageUrl);
|
||||
FileOperation.deleteFile(imageUrl);
|
||||
FileOperation.deleteFile(minImageUrl);
|
||||
}
|
||||
StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(sessionUserId));
|
||||
if (storageBean != null){
|
||||
long updateFileSize = storageBean.getStoragesize() - totalFileSize;
|
||||
if (updateFileSize < 0){
|
||||
updateFileSize = 0;
|
||||
}
|
||||
storageBean.setStoragesize(updateFileSize);
|
||||
filetransferService.updateStorageBean(storageBean);
|
||||
|
||||
}
|
||||
|
||||
result.setData("删除文件成功");
|
||||
result.setSuccess(true);
|
||||
String resultJson = JSON.toJSONString(result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/deleteimage")
|
||||
@ResponseBody
|
||||
public String deleteImage(HttpServletRequest request, FileBean fileBean) {
|
||||
RestResult<String> result = new RestResult<String>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
long sessionUserId = sessionUserBean.getUserId();
|
||||
String imageUrl = PathUtil.getStaticPath() + fileBean.getFileurl();
|
||||
String minImageUrl = imageUrl.replace("." + fileBean.getExtendname(), "_min." + fileBean.getExtendname());
|
||||
long fileSize = FileOperation.getFileSize(imageUrl);
|
||||
fileBean.setIsdir(0);
|
||||
//filetransferService.deleteImageById(fileBean);
|
||||
fileService.deleteFile(fileBean);
|
||||
|
||||
FileOperation.deleteFile(imageUrl);
|
||||
FileOperation.deleteFile(minImageUrl);
|
||||
|
||||
|
||||
StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(sessionUserId));
|
||||
if (storageBean != null){
|
||||
long updateFileSize = storageBean.getStoragesize() - fileSize;
|
||||
if (updateFileSize < 0){
|
||||
updateFileSize = 0;
|
||||
}
|
||||
storageBean.setStoragesize(updateFileSize);
|
||||
filetransferService.updateStorageBean(storageBean);
|
||||
|
||||
}
|
||||
|
||||
String resultJson = JSON.toJSONString(result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传头像
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/uploadimg")
|
||||
@ResponseBody
|
||||
public String uploadImg(HttpServletRequest request) {
|
||||
RestResult<String> restResult = filetransferService.uploadUserImage(request);
|
||||
String resultJson = JSON.toJSONString(restResult);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/uploadfile")
|
||||
@ResponseBody
|
||||
public String uploadFile(HttpServletRequest request, FileBean fileBean) {
|
||||
RestResult<String> restResult = new RestResult<String>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
RestResult<String> operationCheckResult = new FileController().operationCheck();
|
||||
if (!operationCheckResult.isSuccess()){
|
||||
return JSON.toJSONString(operationCheckResult);
|
||||
}
|
||||
|
||||
fileBean.setUserid(sessionUserBean.getUserId());
|
||||
|
||||
filetransferService.uploadFile(request, fileBean);
|
||||
|
||||
restResult.setSuccess(true);
|
||||
String resultJson = JSON.toJSONString(restResult);
|
||||
return resultJson;
|
||||
}
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/downloadfile")
|
||||
public String downloadFile(HttpServletResponse response, FileBean fileBean){
|
||||
RestResult<String> restResult = new RestResult<>();
|
||||
String fileName = null;// 文件名
|
||||
try {
|
||||
fileName = new String(fileBean.getFilename().getBytes("utf-8"), "ISO-8859-1");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (fileName != null) {
|
||||
fileName = fileName + "." + fileBean.getExtendname();
|
||||
//设置文件路径
|
||||
File file = FileOperation.newFile(PathUtil.getStaticPath() + fileBean.getFileurl());
|
||||
if (file.exists()) {
|
||||
response.setContentType("application/force-download");// 设置强制下载不打开
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
|
||||
byte[] buffer = new byte[1024];
|
||||
FileInputStream fis = null;
|
||||
BufferedInputStream bis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
bis = new BufferedInputStream(fis);
|
||||
OutputStream os = response.getOutputStream();
|
||||
int i = bis.read(buffer);
|
||||
while (i != -1) {
|
||||
os.write(buffer, 0, i);
|
||||
i = bis.read(buffer);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到用户头像列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getuploadimglist")
|
||||
@ResponseBody
|
||||
public RestResult<List<UserImageBean>> getUploadImgList(HttpServletRequest request) {
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
RestResult<List<UserImageBean>> restResult = filetransferService.selectUserImage(sessionUserBean.getUserId());
|
||||
restResult.setSuccess(true);
|
||||
|
||||
return restResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getstorage")
|
||||
@ResponseBody
|
||||
public RestResult<StorageBean> getStorage() {
|
||||
RestResult<StorageBean> restResult = new RestResult<StorageBean>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
StorageBean storageBean = new StorageBean();
|
||||
if (FileController.isShareFile){
|
||||
storageBean.setUserid(2);
|
||||
}else{
|
||||
storageBean.setUserid(sessionUserBean.getUserId());
|
||||
}
|
||||
|
||||
StorageBean storage = filetransferService.selectStorageByUser(storageBean);
|
||||
restResult.setData(storage);
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.mac.scp.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
/**
|
||||
* 登录后将重定向到这里
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/index")
|
||||
//@ResponseBody
|
||||
public String index() {
|
||||
return "index.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/403")
|
||||
public String unauthorizedRole() {
|
||||
System.out.println("------没有权限-------");
|
||||
return "/common/403.html";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,244 @@
|
||||
package com.mac.scp.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
//import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
//import org.codehaus.jackson.type.TypeReference;
|
||||
//import org.springframework.stereotype.Controller;
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.common.domain.TableData;
|
||||
import com.mac.common.domain.TableQueryBean;
|
||||
import com.mac.scp.api.IUserService;
|
||||
|
||||
import com.mac.scp.domain.*;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* 用户控制类
|
||||
*
|
||||
* @author ma116
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
@Resource
|
||||
IUserService userService;
|
||||
|
||||
public static final int TEXT = 4;
|
||||
|
||||
/**
|
||||
* 当前模块
|
||||
*/
|
||||
public static final String CURRENT_MODULE = "用户管理";
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
//@MyLog(operation = "用户注册", module = CURRENT_MODULE)
|
||||
@RequestMapping("/userregister")
|
||||
@ResponseBody
|
||||
public ModelAndView userRegister() {
|
||||
ModelAndView mv = new ModelAndView("/user/userRegister.html");
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("/adduser")
|
||||
@ResponseBody
|
||||
public String addUser(UserBean userBean) {
|
||||
RestResult<String> result = userService.registerUser(userBean);
|
||||
|
||||
String resultJson = JSON.toJSONString(result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/userlogin")
|
||||
@ResponseBody
|
||||
public RestResult<UserBean> userLogin(HttpServletRequest request, Map<String, Object> map) {
|
||||
RestResult<UserBean> result = new RestResult<UserBean>();
|
||||
|
||||
System.out.println("HomeController.login()");
|
||||
// 登录失败从request中获取shiro处理的异常信息。
|
||||
// // shiroLoginFailure:就是shiro异常类的全类名.
|
||||
String exception = (String) request.getAttribute("shiroLoginFailure");
|
||||
System.out.println("exception=" + exception);
|
||||
String msg = "";
|
||||
if (exception != null) { //登录失败
|
||||
if (UnknownAccountException.class.getName().equals(exception)) {
|
||||
msg = "账号不存在";
|
||||
} else if (IncorrectCredentialsException.class.getName().equals(exception)) {
|
||||
msg = "密码不正确";
|
||||
} else if ("kaptchaValidateFailed".equals(exception)) {
|
||||
msg = "验证码错误";
|
||||
} else {
|
||||
msg = exception;
|
||||
}
|
||||
result.setSuccess(false);
|
||||
result.setErrorMessage(msg);
|
||||
}
|
||||
else{
|
||||
//登录成功
|
||||
result.setSuccess(true);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户登录信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/checkuserlogininfo")
|
||||
@ResponseBody
|
||||
public String checkUserLoginInfo(HttpServletRequest request) {
|
||||
RestResult<UserBean> restResult = new RestResult<UserBean>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
if (sessionUserBean != null) {
|
||||
UserBean userInfo = userService.getUserInfoById(sessionUserBean.getUserId());
|
||||
restResult.setData(userInfo);
|
||||
restResult.setSuccess(true);
|
||||
} else {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("用户暂未登录");
|
||||
}
|
||||
return JSON.toJSONString(restResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到用户信息通过id
|
||||
*
|
||||
* @param userid
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getuserinfobyid")
|
||||
@ResponseBody
|
||||
public String getUserInfoById(int userid) {
|
||||
RestResult<UserBean> restResult = new RestResult<UserBean>();
|
||||
|
||||
UserBean userBean = userService.getUserInfoById(userid);
|
||||
if (userBean == null) {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorCode("100001");
|
||||
restResult.setErrorMessage("用户不存在!");
|
||||
} else {
|
||||
restResult.setSuccess(true);
|
||||
restResult.setData(userBean);
|
||||
}
|
||||
String resultJson = JSON.toJSONString(restResult);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改用戶信息
|
||||
*
|
||||
* @param userBean
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/updateuserinfo")
|
||||
@ResponseBody
|
||||
public RestResult<String> updateUserInfo(HttpServletRequest request, UserBean userBean) {
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
userBean.setUserId(sessionUserBean.getUserId());
|
||||
RestResult<String> restResult = userService.updateUserInfo(userBean);
|
||||
|
||||
|
||||
return restResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到所有的用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/selectalluserlist")
|
||||
@ResponseBody
|
||||
public String selectAllUserList(TableQueryBean tableQueryBean) {
|
||||
|
||||
TableData<List<UserBean>> miniuiTableData = new TableData<List<UserBean>>();
|
||||
|
||||
String resultJson = "";
|
||||
|
||||
List<UserBean> userList = userService.selectUserList(tableQueryBean);
|
||||
int userCount = userService.selectUserCountByCondition(tableQueryBean);
|
||||
miniuiTableData.setData(userList);
|
||||
miniuiTableData.setCount(userCount);
|
||||
|
||||
|
||||
resultJson = JSON.toJSONString(miniuiTableData);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只获取管理员用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/selectadminuserlist")
|
||||
@ResponseBody
|
||||
public String selectAdminUserList() {
|
||||
|
||||
TableData<List<UserBean>> miniuiTableData = new TableData<List<UserBean>>();
|
||||
|
||||
String resultJson = "";
|
||||
|
||||
List<UserBean> userList = userService.selectAdminUserList();
|
||||
|
||||
miniuiTableData.setData(userList);
|
||||
|
||||
resultJson = JSON.toJSONString(miniuiTableData);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到所有的角色
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/selectrolelist")
|
||||
@ResponseBody
|
||||
public TableData<List<Role>> selectRoleList() {
|
||||
TableData<List<Role>> miniuiTableData = new TableData<List<Role>>();
|
||||
List<Role> result = userService.selectRoleList();
|
||||
miniuiTableData.setData(result);
|
||||
return miniuiTableData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到所有的权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/selectpermissionlist")
|
||||
@ResponseBody
|
||||
public TableData<List<Permission>> selectPermissionList(TableQueryBean tableQueryBean) {
|
||||
TableData<List<Permission>> miniuiTableData = new TableData<List<Permission>>();
|
||||
List<Permission> result = userService.selectPermissionList(tableQueryBean);
|
||||
miniuiTableData.setData(result);
|
||||
return miniuiTableData;
|
||||
}
|
||||
|
||||
}
|
135
file-web/src/main/java/com/mac/scp/domain/FileBean.java
Normal file
135
file-web/src/main/java/com/mac/scp/domain/FileBean.java
Normal file
@ -0,0 +1,135 @@
|
||||
package com.mac.scp.domain;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 相册实体类
|
||||
*
|
||||
* @author ma116
|
||||
*/
|
||||
@Table(name = "file", uniqueConstraints = {
|
||||
@UniqueConstraint(name = "fileindex", columnNames = {"filename", "filepath", "extendname"})})
|
||||
@Entity
|
||||
public class FileBean {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long fileid;
|
||||
|
||||
private long albumid;
|
||||
|
||||
private long essayid;
|
||||
|
||||
private long userid;
|
||||
|
||||
private String fileurl;
|
||||
|
||||
private String filepath;
|
||||
|
||||
private String uploadtime;
|
||||
|
||||
private String timestampname;
|
||||
|
||||
private String extendname;
|
||||
|
||||
private String filename;
|
||||
|
||||
private long filesize;
|
||||
|
||||
private int isdir;
|
||||
|
||||
public long getAlbumid() {
|
||||
return albumid;
|
||||
}
|
||||
|
||||
public void setAlbumid(long albumid) {
|
||||
this.albumid = albumid;
|
||||
}
|
||||
|
||||
public String getFilepath() {
|
||||
return filepath;
|
||||
}
|
||||
|
||||
public void setFilepath(String filepath) {
|
||||
this.filepath = filepath;
|
||||
}
|
||||
|
||||
public int getIsdir() {
|
||||
return isdir;
|
||||
}
|
||||
|
||||
public void setIsdir(int isdir) {
|
||||
this.isdir = isdir;
|
||||
}
|
||||
|
||||
public long getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(long userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public long getEssayid() {
|
||||
return essayid;
|
||||
}
|
||||
|
||||
public void setEssayid(long essayid) {
|
||||
this.essayid = essayid;
|
||||
}
|
||||
|
||||
public long getFileid() {
|
||||
return fileid;
|
||||
}
|
||||
|
||||
public void setFileid(long fileid) {
|
||||
this.fileid = fileid;
|
||||
}
|
||||
|
||||
public String getFileurl() {
|
||||
return fileurl;
|
||||
}
|
||||
|
||||
public void setFileurl(String fileurl) {
|
||||
this.fileurl = fileurl;
|
||||
}
|
||||
|
||||
public String getUploadtime() {
|
||||
return uploadtime;
|
||||
}
|
||||
|
||||
public void setUploadtime(String uploadtime) {
|
||||
this.uploadtime = uploadtime;
|
||||
}
|
||||
|
||||
public String getTimestampname() {
|
||||
return timestampname;
|
||||
}
|
||||
|
||||
public void setTimestampname(String timestampname) {
|
||||
this.timestampname = timestampname;
|
||||
}
|
||||
|
||||
public String getExtendname() {
|
||||
return extendname;
|
||||
}
|
||||
|
||||
public void setExtendname(String extendname) {
|
||||
this.extendname = extendname;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public long getFilesize() {
|
||||
return filesize;
|
||||
}
|
||||
|
||||
public void setFilesize(long filesize) {
|
||||
this.filesize = filesize;
|
||||
}
|
||||
}
|
102
file-web/src/main/java/com/mac/scp/domain/Permission.java
Normal file
102
file-web/src/main/java/com/mac/scp/domain/Permission.java
Normal file
@ -0,0 +1,102 @@
|
||||
package com.mac.scp.domain;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Table(name = "permission")
|
||||
@Entity
|
||||
public class Permission {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long permissionid;//主键.
|
||||
@Column
|
||||
private String name;//名称.
|
||||
@Column
|
||||
private String resourceType;//资源类型,[menu|button]
|
||||
@Column
|
||||
private String url;//资源路径.
|
||||
@Column
|
||||
private String permission; //权限字符串,menu例子:role:*,button例子:role:create,role:update,role:delete,role:view
|
||||
@Column
|
||||
private Long parentId; //父编号
|
||||
@Column
|
||||
private String parentIds; //父编号列表
|
||||
@Column
|
||||
private Boolean available = Boolean.FALSE;
|
||||
|
||||
@Transient
|
||||
private List<Role> roles;
|
||||
|
||||
public long getPermissionid() {
|
||||
return permissionid;
|
||||
}
|
||||
|
||||
public void setPermissionid(long permissionid) {
|
||||
this.permissionid = permissionid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
public void setResourceType(String resourceType) {
|
||||
this.resourceType = resourceType;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public Long getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(Long parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getParentIds() {
|
||||
return parentIds;
|
||||
}
|
||||
|
||||
public void setParentIds(String parentIds) {
|
||||
this.parentIds = parentIds;
|
||||
}
|
||||
|
||||
public Boolean getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void setAvailable(Boolean available) {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public List<Role> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(List<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
}
|
79
file-web/src/main/java/com/mac/scp/domain/Role.java
Normal file
79
file-web/src/main/java/com/mac/scp/domain/Role.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.mac.scp.domain;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Table(name = "role")
|
||||
@Entity
|
||||
public class Role {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long roleid; // 编号
|
||||
|
||||
private String role; // 角色标识程序中判断使用,如"admin",这个是唯一的:
|
||||
|
||||
private String description; // 角色描述,UI界面显示使用
|
||||
|
||||
private Boolean available = Boolean.FALSE; // 是否可用,如果不可用将不会添加给用户
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)//立即从数据库中进行加载数据
|
||||
@JoinTable(name = "role_permission",
|
||||
joinColumns = {@JoinColumn(name = "roleid")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "permissionid")})
|
||||
private List<Permission> permissions;
|
||||
|
||||
// @ManyToMany
|
||||
// @JoinTable(name = "role_permission",
|
||||
// joinColumns = {@JoinColumn(name="roleid")},
|
||||
// inverseJoinColumns = {@JoinColumn(name="permissionid")})
|
||||
// private List<UserBean> userList;// 一个角色对应多个用户
|
||||
|
||||
|
||||
public long getRoleid() {
|
||||
return roleid;
|
||||
}
|
||||
|
||||
public void setRoleid(long roleid) {
|
||||
this.roleid = roleid;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Boolean getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void setAvailable(Boolean available) {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public List<Permission> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(List<Permission> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
// public List<UserBean> getUserList() {
|
||||
// return userList;
|
||||
// }
|
||||
//
|
||||
// public void setUserList(List<UserBean> userList) {
|
||||
// this.userList = userList;
|
||||
// }
|
||||
}
|
47
file-web/src/main/java/com/mac/scp/domain/StorageBean.java
Normal file
47
file-web/src/main/java/com/mac/scp/domain/StorageBean.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.mac.scp.domain;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Table(name = "storage")
|
||||
@Entity
|
||||
public class StorageBean {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long storageid;
|
||||
|
||||
private long userid;
|
||||
|
||||
private long storagesize;
|
||||
|
||||
public StorageBean() {
|
||||
|
||||
}
|
||||
|
||||
public StorageBean(long userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public long getStorageid() {
|
||||
return storageid;
|
||||
}
|
||||
|
||||
public void setStorageid(long storageid) {
|
||||
this.storageid = storageid;
|
||||
}
|
||||
|
||||
public long getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(long userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public long getStoragesize() {
|
||||
return storagesize;
|
||||
}
|
||||
|
||||
public void setStoragesize(long storagesize) {
|
||||
this.storagesize = storagesize;
|
||||
}
|
||||
}
|
66
file-web/src/main/java/com/mac/scp/domain/TreeNode.java
Normal file
66
file-web/src/main/java/com/mac/scp/domain/TreeNode.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.mac.scp.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 树节点
|
||||
*/
|
||||
public class TreeNode {
|
||||
private long id;
|
||||
private String label;
|
||||
private int depth;
|
||||
private String state = "closed";
|
||||
private Map<String, String> attributes = new HashMap<>();
|
||||
private List<TreeNode> children = new ArrayList<>();
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(Map<String, String> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public void setDepth(int depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setNodeName(String nodeName) {
|
||||
this.label = nodeName;
|
||||
}
|
||||
|
||||
public List<TreeNode> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildNode(List<TreeNode> childNode) {
|
||||
this.children = childNode;
|
||||
}
|
||||
}
|
254
file-web/src/main/java/com/mac/scp/domain/UserBean.java
Normal file
254
file-web/src/main/java/com/mac/scp/domain/UserBean.java
Normal file
@ -0,0 +1,254 @@
|
||||
package com.mac.scp.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.websocket.Session;
|
||||
|
||||
/**
|
||||
* 用户基础信息类
|
||||
*
|
||||
* @author ma116
|
||||
*/
|
||||
@Table(name = "user", uniqueConstraints = {
|
||||
@UniqueConstraint(name = "openidIndex", columnNames = {"openid"})
|
||||
})
|
||||
@Entity
|
||||
public class UserBean{
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long userId;
|
||||
|
||||
private String openid; //qq登录使用
|
||||
|
||||
private String username;
|
||||
|
||||
private String realname;
|
||||
|
||||
private String password;
|
||||
|
||||
@Transient
|
||||
private String passwordAgain;
|
||||
|
||||
private String telephone;
|
||||
|
||||
private String sex;
|
||||
|
||||
private String birthday;
|
||||
|
||||
private String addrprovince;
|
||||
|
||||
private String addrcity;
|
||||
|
||||
private String addrarea;
|
||||
|
||||
private String industry;
|
||||
|
||||
private String position;
|
||||
|
||||
private String intro;
|
||||
|
||||
private String salt;//加密密码的盐
|
||||
//private byte state;//用户状态,0:创建未认证(比如没有激活,没有输入验证码等等)--等待验证的用户 , 1:正常状态,2:用户被锁定.
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)//立即从数据库中进行加载数据
|
||||
@JoinTable(name = "user_role",
|
||||
joinColumns = {@JoinColumn(name = "userId")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "roleid")})
|
||||
private List<Role> roleList;// 一个用户具有多个角色
|
||||
/**
|
||||
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||
*/
|
||||
@Transient
|
||||
private Session session;
|
||||
|
||||
/**
|
||||
* 消息未读数
|
||||
*/
|
||||
@Transient
|
||||
private int notReadCount;
|
||||
|
||||
@Transient
|
||||
private List<UserImageBean> imageBeanList;
|
||||
|
||||
public List<UserImageBean> getImageBeanList() {
|
||||
return imageBeanList;
|
||||
}
|
||||
|
||||
public void setImageBeanList(List<UserImageBean> imageBeanList) {
|
||||
this.imageBeanList = imageBeanList;
|
||||
}
|
||||
|
||||
public int getNotReadCount() {
|
||||
return notReadCount;
|
||||
}
|
||||
|
||||
public void setNotReadCount(int notReadCount) {
|
||||
this.notReadCount = notReadCount;
|
||||
}
|
||||
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getRealname() {
|
||||
return realname;
|
||||
}
|
||||
|
||||
public void setRealname(String realname) {
|
||||
this.realname = realname;
|
||||
}
|
||||
|
||||
public String getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public void setBirthday(String birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public String getAddrcity() {
|
||||
return addrcity;
|
||||
}
|
||||
|
||||
public void setAddrcity(String addrcity) {
|
||||
this.addrcity = addrcity;
|
||||
}
|
||||
|
||||
public String getAddrarea() {
|
||||
return addrarea;
|
||||
}
|
||||
|
||||
public void setAddrarea(String addrarea) {
|
||||
this.addrarea = addrarea;
|
||||
}
|
||||
|
||||
public String getIndustry() {
|
||||
return industry;
|
||||
}
|
||||
|
||||
public void setIndustry(String industry) {
|
||||
this.industry = industry;
|
||||
}
|
||||
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public String getIntro() {
|
||||
return intro;
|
||||
}
|
||||
|
||||
public void setIntro(String intro) {
|
||||
this.intro = intro;
|
||||
}
|
||||
|
||||
public String getAddrprovince() {
|
||||
return addrprovince;
|
||||
}
|
||||
|
||||
public void setAddrprovince(String addrprovince) {
|
||||
this.addrprovince = addrprovince;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
|
||||
// public byte getState() {
|
||||
// return state;
|
||||
// }
|
||||
//
|
||||
// public void setState(byte state) {
|
||||
// this.state = state;
|
||||
// }
|
||||
|
||||
public List<Role> getRoleList() {
|
||||
return roleList;
|
||||
}
|
||||
|
||||
public void setRoleList(List<Role> roleList) {
|
||||
this.roleList = roleList;
|
||||
}
|
||||
|
||||
public String getPasswordAgain() {
|
||||
return passwordAgain;
|
||||
}
|
||||
|
||||
public void setPasswordAgain(String passwordAgain) {
|
||||
this.passwordAgain = passwordAgain;
|
||||
}
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码盐.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getCredentialsSalt() {
|
||||
return this.username + this.salt;
|
||||
}
|
||||
//重新对盐重新进行了定义,用户名+salt,这样就更加不容易被破解
|
||||
}
|
66
file-web/src/main/java/com/mac/scp/domain/UserImageBean.java
Normal file
66
file-web/src/main/java/com/mac/scp/domain/UserImageBean.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.mac.scp.domain;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户头像实体类
|
||||
*
|
||||
* @author ma116
|
||||
*/
|
||||
@Table(name = "userimage")
|
||||
@Entity
|
||||
public class UserImageBean implements Serializable {
|
||||
/**
|
||||
* 序列id
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long imageid;
|
||||
@Column
|
||||
private long userid;
|
||||
@Column
|
||||
private String imageurl;
|
||||
@Column
|
||||
private String uploadtime;
|
||||
|
||||
|
||||
public String getUploadtime() {
|
||||
return uploadtime;
|
||||
}
|
||||
|
||||
public void setUploadtime(String uploadtime) {
|
||||
this.uploadtime = uploadtime;
|
||||
}
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public long getImageid() {
|
||||
return imageid;
|
||||
}
|
||||
|
||||
public void setImageid(long imageid) {
|
||||
this.imageid = imageid;
|
||||
}
|
||||
|
||||
public long getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(long userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getImageurl() {
|
||||
return imageurl;
|
||||
}
|
||||
|
||||
public void setImageurl(String imageurl) {
|
||||
this.imageurl = imageurl;
|
||||
}
|
||||
|
||||
|
||||
}
|
25
file-web/src/main/java/com/mac/scp/mapper/FileMapper.java
Normal file
25
file-web/src/main/java/com/mac/scp/mapper/FileMapper.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.mac.scp.mapper;
|
||||
|
||||
import com.mac.scp.domain.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public interface FileMapper {
|
||||
|
||||
void insertFile(FileBean fileBean);
|
||||
void batchInsertFile(List<FileBean> fileBeanList);
|
||||
void updateFile(FileBean fileBean);
|
||||
FileBean selectFileById(FileBean fileBean);
|
||||
List<FileBean> selectFilePathTreeByUserid(FileBean fileBean);
|
||||
List<FileBean> selectFileList(FileBean fileBean);
|
||||
List<FileBean> selectFileTreeListLikeFilePath(FileBean fileBean);
|
||||
void deleteFileById(FileBean fileBean);
|
||||
void deleteFileByIds(List<Integer> fileidList);
|
||||
List<FileBean> selectFileListByIds(List<Integer> fileidList);
|
||||
void updateFilepathByFilepath(String oldfilepath, String newfilepath);
|
||||
void updateFilepathByPathAndName(String oldfilepath, String newfilepath, String filename, String extendname);
|
||||
List<FileBean> selectFileByExtendName(@Param("filenameList") List<String> filenameList,
|
||||
@Param("userid") long userid);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.mac.scp.mapper;
|
||||
|
||||
import com.mac.scp.domain.*;
|
||||
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FiletransferMapper {
|
||||
|
||||
void deleteUserImageById(UserImageBean userImageBean);
|
||||
|
||||
/**
|
||||
* 插入用户头像
|
||||
*
|
||||
* @param userImageBean
|
||||
*/
|
||||
void insertUserImage(UserImageBean userImageBean);
|
||||
|
||||
List<UserImageBean> selectUserImage(long userId);
|
||||
|
||||
List<UserImageBean> selectUserImageByUrl(String url);
|
||||
|
||||
void deleteUserImageByIds(List<Integer> imageidList);
|
||||
|
||||
StorageBean selectStorageBean(StorageBean storageBean);
|
||||
|
||||
void insertStorageBean(StorageBean storageBean);
|
||||
|
||||
void updateStorageBean(StorageBean storageBean);
|
||||
|
||||
StorageBean selectStorageByUser(StorageBean storageBean);
|
||||
}
|
63
file-web/src/main/java/com/mac/scp/mapper/UserMapper.java
Normal file
63
file-web/src/main/java/com/mac/scp/mapper/UserMapper.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.mac.scp.mapper;
|
||||
|
||||
import com.mac.common.domain.TableQueryBean;
|
||||
import com.mac.scp.domain.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserMapper {
|
||||
int insertUser(UserBean userBean);
|
||||
|
||||
int insertUserRole(long userId, long roleid);
|
||||
|
||||
UserBean selectUser(UserBean userBean);
|
||||
|
||||
List<UserBean> selectAdminUserList();
|
||||
|
||||
/**
|
||||
* 通過id得到用戶信息
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
UserBean selectUserById(long userId);
|
||||
|
||||
/**
|
||||
* 通過openid得到用戶信息
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
UserBean selectUserByopenid(String openid);
|
||||
|
||||
/**
|
||||
* 批量删除用户信息
|
||||
*
|
||||
* @param userBean
|
||||
*/
|
||||
void deleteUserInfo(UserBean userBean);
|
||||
|
||||
/**
|
||||
* 修改用戶信息
|
||||
*
|
||||
* @param userBean
|
||||
*/
|
||||
void updateUserInfo(UserBean userBean);
|
||||
|
||||
UserBean selectUserByUserName(UserBean userBean);
|
||||
|
||||
UserBean selectUserByUserNameAndPassword(UserBean userBean);
|
||||
|
||||
List<UserBean> selectUserByTelephone(UserBean userBean);
|
||||
|
||||
List<UserBean> selectAllUserList();
|
||||
|
||||
List<UserBean> selectUserListByCondition(TableQueryBean tableQueryBean);
|
||||
|
||||
List<Role> selectRoleList();
|
||||
|
||||
List<Permission> selectPermissionListByCondition(TableQueryBean tableQueryBean);
|
||||
|
||||
int selectUserCountByCondition(TableQueryBean tableQueryBean);
|
||||
|
||||
List<Permission> getPermissionByRole(int roleid);
|
||||
}
|
141
file-web/src/main/java/com/mac/scp/service/FileService.java
Normal file
141
file-web/src/main/java/com/mac/scp/service/FileService.java
Normal file
@ -0,0 +1,141 @@
|
||||
package com.mac.scp.service;
|
||||
|
||||
import com.mac.common.cbb.DateUtil;
|
||||
import com.mac.common.operation.FileOperation;
|
||||
import com.mac.common.util.PathUtil;
|
||||
import com.mac.scp.api.IFileService;
|
||||
import com.mac.scp.domain.*;
|
||||
import com.mac.scp.mapper.FileMapper;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class FileService implements IFileService {
|
||||
|
||||
@Resource
|
||||
FileMapper fileMapper;
|
||||
@Resource
|
||||
FiletransferService filetransferService;
|
||||
|
||||
@Override
|
||||
public void insertFile(FileBean fileBean) {
|
||||
fileMapper.insertFile(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchInsertFile(List<FileBean> fileBeanList) {
|
||||
fileMapper.batchInsertFile(fileBeanList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFile(FileBean fileBean) {
|
||||
fileBean.setUploadtime(DateUtil.getCurrentTime());
|
||||
fileMapper.updateFile(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileBean selectFileById(FileBean fileBean) {
|
||||
return fileMapper.selectFileById(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileBean> selectFilePathTreeByUserid(FileBean fileBean) {
|
||||
return fileMapper.selectFilePathTreeByUserid(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileBean> selectFileList(FileBean fileBean) {
|
||||
return fileMapper.selectFileList(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileBean> selectFileListByIds(List<Integer> fileidList) {
|
||||
return fileMapper.selectFileListByIds(fileidList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileBean> selectFileTreeListLikeFilePath(String filePath) {
|
||||
FileBean fileBean = new FileBean();
|
||||
fileBean.setFilepath(filePath);
|
||||
|
||||
return fileMapper.selectFileTreeListLikeFilePath(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(FileBean fileBean) {
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(sessionUserBean.getUserId()));
|
||||
long deleteSize = 0;
|
||||
String fileUrl = PathUtil.getStaticPath() + fileBean.getFileurl();
|
||||
if (fileBean.getIsdir() == 1) {
|
||||
//1、先删除子目录
|
||||
String filePath = fileBean.getFilepath() + fileBean.getFilename() + "/";
|
||||
List<FileBean> fileList = selectFileTreeListLikeFilePath(filePath);
|
||||
|
||||
for (int i = 0; i < fileList.size(); i++){
|
||||
FileBean file = fileList.get(i);
|
||||
//1.1、删除数据库文件
|
||||
fileMapper.deleteFileById(file);
|
||||
//1.2、如果是文件,需要记录文件大小
|
||||
if (file.getIsdir() != 1){
|
||||
deleteSize += file.getFilesize();
|
||||
//1.3、删除服务器文件,只删除文件,目录是虚拟的
|
||||
if (file.getFileurl() != null && file.getFileurl().indexOf("upload") != -1){
|
||||
FileOperation.deleteFile(PathUtil.getStaticPath() + file.getFileurl());
|
||||
}
|
||||
}
|
||||
}
|
||||
//2、根目录单独删除
|
||||
fileMapper.deleteFileById(fileBean);
|
||||
}else{
|
||||
fileMapper.deleteFileById(fileBean);
|
||||
deleteSize = FileOperation.getFileSize(fileUrl);
|
||||
//删除服务器文件
|
||||
if (fileBean.getFileurl() != null && fileBean.getFileurl().indexOf("upload") != -1){
|
||||
FileOperation.deleteFile(fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (storageBean != null) {
|
||||
long updateFileSize = storageBean.getStoragesize() - deleteSize;
|
||||
if (updateFileSize < 0) {
|
||||
updateFileSize = 0;
|
||||
}
|
||||
storageBean.setStoragesize(updateFileSize);
|
||||
filetransferService.updateStorageBean(storageBean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFileByIds(List<Integer> fileidList) {
|
||||
fileMapper.deleteFileByIds(fileidList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateFilepathByFilepath(String oldfilepath, String newfilepath, String filename, String extendname) {
|
||||
if ("null".equals(extendname)){
|
||||
extendname = null;
|
||||
}
|
||||
//移动根目录
|
||||
fileMapper.updateFilepathByPathAndName(oldfilepath, newfilepath, filename, extendname);
|
||||
|
||||
//移动子目录
|
||||
oldfilepath = oldfilepath + filename + "/";
|
||||
newfilepath = newfilepath + filename + "/";
|
||||
|
||||
if (extendname == null) { //为null说明是目录,则需要移动子目录
|
||||
fileMapper.updateFilepathByFilepath(oldfilepath, newfilepath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileBean> selectFileByExtendName(List<String> filenameList, long userid) {
|
||||
return fileMapper.selectFileByExtendName(filenameList, userid);
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
package com.mac.scp.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.mac.common.cbb.DateUtil;
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.common.cbb.Uploader;
|
||||
import com.mac.common.domain.UploadFile;
|
||||
import com.mac.scp.api.IFiletransferService;
|
||||
|
||||
import com.mac.scp.domain.*;
|
||||
import com.mac.scp.mapper.FileMapper;
|
||||
import com.mac.scp.mapper.FiletransferMapper;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
public class FiletransferService implements IFiletransferService {
|
||||
|
||||
@Resource
|
||||
FiletransferMapper filetransferMapper;
|
||||
@Resource
|
||||
FileMapper fileMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteUserImageById(UserImageBean userImageBean) {
|
||||
filetransferMapper.deleteUserImageById(userImageBean);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加用户头像
|
||||
*/
|
||||
@Override
|
||||
public RestResult<String> insertUserImage(UserImageBean userImageBean) {
|
||||
RestResult<String> restResult = new RestResult<String>();
|
||||
filetransferMapper.insertUserImage(userImageBean);
|
||||
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找用户头像
|
||||
*/
|
||||
@Override
|
||||
public RestResult<List<UserImageBean>> selectUserImage(long userId) {
|
||||
RestResult<List<UserImageBean>> restResult = new RestResult<List<UserImageBean>>();
|
||||
List<UserImageBean> result = filetransferMapper.selectUserImage(userId);
|
||||
if (result == null) {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("没有头像");
|
||||
} else {
|
||||
restResult.setSuccess(true);
|
||||
restResult.setData(result);
|
||||
}
|
||||
return restResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
*/
|
||||
@Override
|
||||
public RestResult<String> uploadUserImage(HttpServletRequest request) {
|
||||
RestResult<String> restResult = new RestResult<String>();
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
UserImageBean userImageBean = new UserImageBean();
|
||||
UserBean userBean = null;
|
||||
//判断用户是否登陆
|
||||
if (sessionUserBean == null) {
|
||||
restResult.setErrorCode("用户未登陆");
|
||||
restResult.setSuccess(false);
|
||||
} else {
|
||||
Uploader uploader = null;
|
||||
uploader = new Uploader(request);
|
||||
List<UploadFile> uploadFile = uploader.upload();
|
||||
|
||||
String imageurl = uploadFile.get(0).getUrl();
|
||||
userBean = sessionUserBean;
|
||||
userImageBean.setUserid(userBean.getUserId());
|
||||
userImageBean.setImageurl(imageurl);
|
||||
userImageBean.setUploadtime(DateUtil.getCurrentTime());
|
||||
insertUserImage(userImageBean);
|
||||
restResult.setData("filetransfer/" + imageurl);
|
||||
restResult.setSuccess(true);
|
||||
}
|
||||
|
||||
return restResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserImageBean> selectUserImageByUrl(String url) {
|
||||
List<UserImageBean> result = filetransferMapper.selectUserImageByUrl(url);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteUserImageByIds(List<Integer> imageidList) {
|
||||
filetransferMapper.deleteUserImageByIds(imageidList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// public void insertFile(FileBean fileBean){
|
||||
// filetransferMapper.insertFile(fileBean);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void uploadFile(HttpServletRequest request, FileBean fileBean) {
|
||||
Uploader uploader = new Uploader(request);
|
||||
List<UploadFile> uploadFileList = uploader.upload();
|
||||
for (int i = 0; i < uploadFileList.size(); i++){
|
||||
UploadFile uploadFile = uploadFileList.get(i);
|
||||
if (uploadFile.getSuccess() == 1){
|
||||
fileBean.setFileurl(uploadFile.getUrl());
|
||||
fileBean.setFilesize(uploadFile.getFileSize());
|
||||
fileBean.setFilename(uploadFile.getFileName());
|
||||
fileBean.setExtendname(uploadFile.getFileType());
|
||||
fileBean.setTimestampname(uploadFile.getTimeStampName());
|
||||
fileBean.setUploadtime(DateUtil.getCurrentTime());
|
||||
|
||||
fileMapper.insertFile(fileBean);
|
||||
}
|
||||
|
||||
|
||||
synchronized (FiletransferService.class) {
|
||||
UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
|
||||
long sessionUserId = sessionUserBean.getUserId();
|
||||
StorageBean storageBean = selectStorageBean(new StorageBean(sessionUserId));
|
||||
if (storageBean == null) {
|
||||
StorageBean storage = new StorageBean(sessionUserId);
|
||||
storage.setStoragesize(fileBean.getFilesize());
|
||||
insertStorageBean(storage);
|
||||
} else {
|
||||
storageBean.setStoragesize(storageBean.getStoragesize() + uploadFile.getFileSize());
|
||||
updateStorageBean(storageBean);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageBean selectStorageBean(StorageBean storageBean) {
|
||||
return filetransferMapper.selectStorageBean(storageBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertStorageBean(StorageBean storageBean) {
|
||||
filetransferMapper.insertStorageBean(storageBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageBean(StorageBean storageBean) {
|
||||
filetransferMapper.updateStorageBean(storageBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageBean selectStorageByUser(StorageBean storageBean) {
|
||||
return filetransferMapper.selectStorageByUser(storageBean);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.mac.scp.service;
|
||||
|
||||
import javax.servlet.ServletRequestEvent;
|
||||
import javax.servlet.ServletRequestListener;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@WebListener
|
||||
public class RequestListener implements ServletRequestListener {
|
||||
|
||||
public void requestInitialized(ServletRequestEvent sre) {
|
||||
//将所有request请求都携带上httpSession
|
||||
((HttpServletRequest) sre.getServletRequest()).getSession();
|
||||
|
||||
}
|
||||
|
||||
public RequestListener() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void requestDestroyed(ServletRequestEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
277
file-web/src/main/java/com/mac/scp/service/UserService.java
Normal file
277
file-web/src/main/java/com/mac/scp/service/UserService.java
Normal file
@ -0,0 +1,277 @@
|
||||
package com.mac.scp.service;
|
||||
|
||||
import com.mac.common.cbb.MiniuiUtil;
|
||||
import com.mac.common.cbb.RestResult;
|
||||
import com.mac.common.domain.TableQueryBean;
|
||||
import com.mac.common.util.PasswordUtil;
|
||||
import com.mac.scp.api.IUserService;
|
||||
|
||||
import com.mac.scp.domain.*;
|
||||
import com.mac.scp.mapper.FiletransferMapper;
|
||||
import com.mac.scp.mapper.UserMapper;
|
||||
import org.apache.shiro.crypto.hash.SimpleHash;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
public class UserService implements IUserService {
|
||||
//private static final Logger log= Logger.getLogger(EssayService.class);
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
|
||||
@Resource
|
||||
FiletransferMapper filetransferMapper;
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*/
|
||||
@Override
|
||||
public RestResult<String> registerUser(UserBean userBean) {
|
||||
RestResult<String> restResult = new RestResult<String>();
|
||||
if (userBean.getTelephone() == null || "".equals(userBean.getTelephone())){
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("用户名不能为空!");
|
||||
return restResult;
|
||||
}
|
||||
if (userBean.getPassword() == null || "".equals(userBean.getPassword())){
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("密码不能为空!");
|
||||
return restResult;
|
||||
}
|
||||
if (userBean.getPasswordAgain() == null || "".equals(userBean.getPasswordAgain())){
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("确认密码不能为空!");
|
||||
return restResult;
|
||||
}
|
||||
if (userBean.getUsername() == null || "".equals(userBean.getUsername())){
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("用户名不能为空!");
|
||||
return restResult;
|
||||
}
|
||||
if (isUserNameExit(userBean)) {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("用户名已存在!");
|
||||
return restResult;
|
||||
}
|
||||
if (!isPhoneFormatRight(userBean.getTelephone())){
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("手机号格式不正确!");
|
||||
return restResult;
|
||||
}
|
||||
if (isPhoneExit(userBean)) {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("手机号已存在!");
|
||||
return restResult;
|
||||
}
|
||||
if (!userBean.getPassword().equals(userBean.getPasswordAgain())) {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorMessage("确认密码不一致!");
|
||||
return restResult;
|
||||
}
|
||||
|
||||
String salt = PasswordUtil.getSaltValue();
|
||||
String newPassword = new SimpleHash("MD5", userBean.getPassword(), salt, 1024).toHex();
|
||||
|
||||
userBean.setSalt(salt);
|
||||
|
||||
userBean.setPassword(newPassword);
|
||||
|
||||
int result = userMapper.insertUser(userBean);
|
||||
//UserBean userInsertResult = userMapper.selectUserByUserName(userBean);
|
||||
userMapper.insertUserRole(userBean.getUserId(), 2);
|
||||
UserImageBean userImageBean = new UserImageBean();
|
||||
userImageBean.setImageurl("");
|
||||
userImageBean.setUserid(userBean.getUserId());
|
||||
filetransferMapper.insertUserImage(userImageBean);
|
||||
if (result == 1) {
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
} else {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorCode("100000");
|
||||
restResult.setErrorMessage("注册用户失败,请检查输入信息!");
|
||||
return restResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*/
|
||||
@Override
|
||||
public RestResult<String> addUser(UserBean userBean) {
|
||||
RestResult<String> restResult = new RestResult<String>();
|
||||
|
||||
String salt = PasswordUtil.getSaltValue();
|
||||
String newPassword = new SimpleHash("MD5", userBean.getPassword(), salt, 1024).toHex();
|
||||
|
||||
userBean.setSalt(salt);
|
||||
|
||||
userBean.setPassword(newPassword);
|
||||
|
||||
int result = userMapper.insertUser(userBean);
|
||||
//UserBean userInsertResult = userMapper.selectUserByUserName(userBean);
|
||||
userMapper.insertUserRole(userBean.getUserId(), 2);
|
||||
UserImageBean userImageBean = new UserImageBean();
|
||||
userImageBean.setImageurl("");
|
||||
userImageBean.setUserid(userBean.getUserId());
|
||||
filetransferMapper.insertUserImage(userImageBean);
|
||||
if (result == 1) {
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
} else {
|
||||
restResult.setSuccess(false);
|
||||
restResult.setErrorCode("100000");
|
||||
restResult.setErrorMessage("注册用户失败,请检查输入信息!");
|
||||
return restResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户名是否存在
|
||||
*
|
||||
* @param userBean
|
||||
*/
|
||||
private Boolean isUserNameExit(UserBean userBean) {
|
||||
UserBean result = userMapper.selectUserByUserName(userBean);
|
||||
if (result != null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机号是否存在
|
||||
*
|
||||
* @param userBean
|
||||
* @return
|
||||
*/
|
||||
private Boolean isPhoneExit(UserBean userBean) {
|
||||
List<UserBean> resultList = userMapper.selectUserByTelephone(userBean);
|
||||
if (resultList.size() > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean isPhoneFormatRight(String phone){
|
||||
String regex = "^1\\d{10}";
|
||||
boolean isRight = Pattern.matches(regex, phone);
|
||||
return isRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户信息
|
||||
*
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
public UserBean findUserInfoByName(String userName) {
|
||||
UserBean userinfo = new UserBean();
|
||||
userinfo.setUsername(userName);
|
||||
return userMapper.selectUserByUserName(userinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户信息
|
||||
*
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
public UserBean findUserInfoByNameAndPassword(String userName, String password) {
|
||||
UserBean userinfo = new UserBean();
|
||||
userinfo.setUsername(userName);
|
||||
return userMapper.selectUserByUserName(userinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
@Override
|
||||
public UserBean loginUser(UserBean userBean) {
|
||||
RestResult<UserBean> restResult = new RestResult<UserBean>();
|
||||
if (userBean.getUsername() == null && userBean.getTelephone() != null) {
|
||||
userBean.setUsername(userBean.getTelephone());
|
||||
}
|
||||
if (userBean.getUsername() != null && userBean.getTelephone() == null) {
|
||||
userBean.setTelephone(userBean.getUsername());
|
||||
}
|
||||
UserBean result = userMapper.selectUser(userBean);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserBean> selectAdminUserList() {
|
||||
return userMapper.selectAdminUserList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserBean getUserInfoById(long userId) {
|
||||
UserBean userBean = userMapper.selectUserById(userId);
|
||||
|
||||
return userBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserBean selectUserByopenid(String openid) {
|
||||
UserBean userBean = userMapper.selectUserByopenid(openid);
|
||||
return userBean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*/
|
||||
@Override
|
||||
public RestResult<String> updateUserInfo(UserBean userBean) {
|
||||
RestResult<String> restResult = new RestResult<String>();
|
||||
userMapper.updateUserInfo(userBean);
|
||||
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有的用户
|
||||
*/
|
||||
@Override
|
||||
public List<UserBean> selectAllUserList() {
|
||||
return userMapper.selectAllUserList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserBean> selectUserList(TableQueryBean tableQueryBean) {
|
||||
TableQueryBean tablePageQuery = MiniuiUtil.getMiniuiTablePageQuery(tableQueryBean);
|
||||
return userMapper.selectUserListByCondition(tablePageQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Role> selectRoleList() {
|
||||
//TableQueryBean tablePageQuery = MiniuiUtil.getMiniuiTablePageQuery(tableQueryBean);
|
||||
return userMapper.selectRoleList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permission> selectPermissionList(TableQueryBean tableQueryBean) {
|
||||
TableQueryBean tablePageQuery = MiniuiUtil.getMiniuiTablePageQuery(tableQueryBean);
|
||||
return userMapper.selectPermissionListByCondition(tablePageQuery);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int selectUserCountByCondition(TableQueryBean tableQueryBean) {
|
||||
return userMapper.selectUserCountByCondition(tableQueryBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserInfo(UserBean userBean) {
|
||||
userMapper.deleteUserInfo(userBean);
|
||||
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user