Commit 4ec6ab5c by shenjinzhu

试试水

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>change4weixin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.zeroturnaround.eclipse.rebelXmlBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.zeroturnaround.eclipse.jrebelNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="D:/ZhiWei/change4weixin/target/classes">
</dir>
</classpath>
<web>
<link target="/">
<dir name="D:/ZhiWei/change4weixin/src/main/webapp">
</dir>
</link>
</web>
</application>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="change4weixin">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="change4weixin"/>
<property name="java-output-path" value="/change4weixin/target/classes"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Apache Tomcat v7.0"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Window
\ No newline at end of file
disabled=06target
eclipse.preferences.version=1
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>change4weixin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.zeroturnaround.eclipse.rebelXmlBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.zeroturnaround.eclipse.jrebelNature</nature>
</natures>
</projectDescription>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
$(function() {
getTime();
setInterval("getTime()", 10 * 1000);
});
function getTime() {
var time = $('#time').empty();
$.ajax({
url : '/change4weixin/show',
success : function(result) {
var list = JSON.parse(result);
console.log(list);
console.log(list.length);
var time = $('#time').empty();
var t = 0;
for (var i = 0; i < list.length; i++) {
if (i > 0) {
t += list[i].need;
var addem = '<span>位置编号:' + (i + 1) + ','
+ list[i].mail + '需要等待的时间:' + (t + 2 * (i + 1))
+ '分钟</span><br>';
} else {
var addem = '<span>位置编号:' + (i + 1) + ','
+ list[i].mail + '开始时间:' + list[i].date
+ '需要的时间:' + (list[i].need + 2 * (i + 1))
+ '分钟</span><br>';
}
time.append(addem);
}
}
});
}
</script>
</head>
<body>
<div>
<span>有时候显示有点问题,耐心等待</span>
</div>
<div id="time"></div>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="D:/ZhiWei/change4weixin/target/classes">
</dir>
</classpath>
<web>
<link target="/">
<dir name="D:/ZhiWei/change4weixin/target/m2e-wtp/web-resources">
<exclude name="/"/>
</dir>
</link>
<link target="/">
<dir name="D:/ZhiWei/change4weixin/src/main/webapp">
</dir>
</link>
</web>
</application>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>change4weixin</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>java</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:servletContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>java</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
">
<context:property-placeholder ignore-unresolvable="true" location="classpath:datasource.properties" />
</beans>
\ No newline at end of file
package com.zw.entity;
import java.io.Serializable;
import java.util.Date;
public class Excels implements Serializable{
private String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
private String mail;
private String name;
private String date;
private double need;
private int num;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public double getNeed() {
return need;
}
public void setNeed(double need) {
this.need = need;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
@Override
public String toString() {
return "Excels [url=" + url + ", mail=" + mail + ", name=" + name + ", date=" + date + ", need=" + need + "]";
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h2>文件格式有问题,请确认有地址一栏</h2>
</body>
</html>
\ No newline at end of file
<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>
<groupId>com.zhiwei</groupId>
<artifactId>change4weixin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.24</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.29</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>com.github.liyiorg</groupId>
<artifactId>weixin-popular</artifactId>
<version>2.8.10</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<!-- mongodb -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.zhiwei.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.zhiwei.chendong.ExcelReadAndWrite;
import com.zhiwei.chendong.ReaderExcel;
import com.zw.entity.Excels;
import com.zw.entity.Weixin;
@Controller
public class MainController {
private final static Log log = LogFactory.getLog(MainController.class);
public static List<Excels> lists = new ArrayList<Excels>();
@RequestMapping("/scanExcel")
public String mian() {
return "test";
}
@RequestMapping("/show")
@ResponseBody
public String shows(HttpServletRequest req, HttpServletResponse res) throws IOException {
if (lists.size() > 0) {
Excels e = lists.get(0);
if (e.getNum() == 1) {
} else {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
e.setNum(1);
e.setDate(sdf.format(new Date()));
}
}
String str = JSON.toJSONString(lists);
return str;
}
@RequestMapping("/sh")
public String showPage() {
return "show";
}
@RequestMapping(value="/return")
public String returns(){
return "test";
}
@RequestMapping(value = "/up")
public String up(HttpServletRequest req, HttpServletResponse res, MultipartFile file, String mail,String mail2)
throws Exception {
if(!mail.equals(mail2)){
return "error";
}
System.out.println(mail);
// 得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String fileName = file.getOriginalFilename();
if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String path = MainController.class.getClassLoader().getResource("file").getPath() + "/" + fileName;
Excels excel = new Excels();
excel.setDate(sdf.format(new Date()));
excel.setMail(mail);
excel.setName(fileName);
excel.setUrl(path);
excel.setNum(lists.size() - 1);
ExcelReadAndWrite.q.offer(excel);
int num = 0;
// String fileName = new Date().getTime()+".jpg";
System.out.println(path);
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(path);
List<Weixin> list = ReaderExcel.getExcel(path);
for (Weixin l : list) {
if (null!=l.getUrl()&&l.getUrl().startsWith("http://mp.weixin.qq.com/s?src")) {
num++;
}
}
excel.setNeed(num * 4 * 1.0 / 60);
lists.add(excel);
if (ExcelReadAndWrite.q.size() > 1) {
// try {
// out.println("任务正在运行,需等待,需要查看进度
// http://192.168.0.216:8082/change4weixin/show ");
// out.flush();
// } catch (Exception e) {
//
// } finally {
// if (out != null) {
// out.close();
// }
// }
return "show";
} else {
Thread t = new Thread() {
public void run() {
try {
ExcelReadAndWrite.save();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
return "show";
}
}
return "error";
}
}
log4j.rootLogger=debug,LOG,ERROR
#log4j.logger.com.zhiwei.step.core.MsgSender=debug,RECORD
#LOG(All log)
log4j.appender.LOG=org.apache.log4j.ConsoleAppender
log4j.appender.LOG.Threshold=info
log4j.appender.LOG.Target=System.out
log4j.appender.LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.LOG.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %m%n
#ERROR
log4j.appender.ERROR=org.apache.log4j.RollingFileAppender
log4j.appender.ERROR.Threshold=error
log4j.appender.ERROR.File=${catalina.home}/log/error.log
log4j.appender.ERROR.MaxFileSize=10MB
log4j.appender.ERROR.MaxBackupIndex=10
log4j.appender.ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.ERROR.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} [%t] [%c] [%p] - %m%n
#RECORD
log4j.appender.RECORD=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RECORD.File=${catalina.home}/log/msg_record.log
log4j.appender.RECORD.layout=org.apache.log4j.PatternLayout
log4j.appender.RECORD.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %m%n
\ No newline at end of file
package com.zhiwei.chendong;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.zhiwei.servlet.MainController;
public class MongoForChenDong {
private final static Log log = LogFactory.getLog(MongoForChenDong.class);
private MongoClient mongoClient = null;
private static MongoForChenDong mongoDBPool = new MongoForChenDong(); // 饿汉式
// 单例模式
public MongoForChenDong() {
if (mongoClient == null) {
MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder();
optionsBuilder.connectionsPerHost(100); // 与目标数据库可创建的最大连接数
optionsBuilder.connectTimeout(1000 * 60 * 40); // 与数据库建立连接的超时时间
optionsBuilder.maxWaitTime(1000 * 60 * 5); // 一个线程成功获取到一个可用数据库连接之前的最大等待时间
optionsBuilder.threadsAllowedToBlockForConnectionMultiplier(100);// 等待一个连接
// 允许阻塞的线程数
optionsBuilder.maxConnectionIdleTime(0);
optionsBuilder.maxConnectionLifeTime(0);
optionsBuilder.socketKeepAlive(true);
optionsBuilder.socketTimeout(1000 * 20);
MongoClientOptions options = optionsBuilder.build();
char[] passwords = "1q2w3e4r".toCharArray();
List<MongoCredential> credentials = new ArrayList<>();
MongoCredential credential = MongoCredential.createCredential("zhiweidata", "spyPlat", passwords);
credentials.add(credential);
List<ServerAddress> serverAddresses = new ArrayList<>();
serverAddresses.add(new ServerAddress("106.14.249.240", 26807));
mongoClient = new MongoClient(serverAddresses, credentials, options);
}
}
public DB getDB(String dbName) {
return mongoClient.getDB(dbName);
}
/**
* 添加mongo名称和集合名称
*
* @param dbName
* @param collectionName
* @return
*/
public DBCollection getCollection(String dbName, String collectionName) {
DB db = mongoClient.getDB(dbName);
return db.getCollection(collectionName);
}
public List<Map<String, Object>> find() {
DB db = mongoClient.getDB("spyPlat");
DBCollection dbCollection = db.getCollection("Result");
DBObject obj = new BasicDBObject();
DBCursor dbCursor = dbCollection.find();
List<Map<String, Object>> list = new ArrayList<>();
while (dbCursor.hasNext()) {
list.add((Map<String, Object>) dbCursor.next());
}
return list;
}
public void insert(List<String> list) {
DB db = mongoClient.getDB("spyPlat");
DBCollection dbCollection = db.getCollection("RawUrl");
for (String l : list) {
DBObject obj = new BasicDBObject();
obj.put("_id", l);
obj.put("url", l);
try {
dbCollection.insert(obj);
} catch (Exception e) {
log.info(l);
}
}
}
public static void main(String[] args) {
MongoForChenDong m = new MongoForChenDong();
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="/change4weixin/up" enctype="multipart/form-data" method="post">
文件<input type="file" name="file" /> 邮箱号<input type="text" name="mail">
重复邮箱号<input type="text" name="mail2">
<input type="submit" value="提交" />
</form>
</body>
</html>
\ No newline at end of file
package com.zhiwei.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.zhiwei.chendong.ExcelReadAndWrite;
import com.zhiwei.chendong.ReaderExcel;
import com.zw.entity.Excels;
import com.zw.entity.Weixin;
@Controller
public class MainController {
private final static Log log = LogFactory.getLog(MainController.class);
public static List<Excels> lists = new ArrayList<Excels>();
@RequestMapping("/scanExcel")
public String mian() {
return "test";
}
@RequestMapping("/show")
@ResponseBody
public String shows(HttpServletRequest req, HttpServletResponse res) throws IOException {
if (lists.size() > 0) {
Excels e = lists.get(0);
if (e.getNum() == 1) {
} else {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
e.setNum(1);
e.setDate(sdf.format(new Date()));
}
}
String str = JSON.toJSONString(lists);
return str;
}
@RequestMapping("/sh")
public String showPage() {
return "show";
}
@RequestMapping(value = "/return")
public String returns() {
return "test";
}
@RequestMapping(value = "/up")
public String up(HttpServletRequest req, HttpServletResponse res, MultipartFile file, String mail, String mail2)
throws Exception {
if (!mail.equals(mail2)) {
return "error";
}
System.out.println(mail);
log.info(mail);
// 得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String fileName = file.getOriginalFilename();
if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {//是否是excel结尾的
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String path = "/home/nbzhiwei/upload"+ "/" + fileName;
log.info(path);
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
Excels excel = new Excels();
List<Weixin> list = ReaderExcel.getExcel(path);
if(list.size()==0){
return "error2";
}
excel.setNeed((list.size() * 2 * 1.0 +120)/ 60);
excel.setDate(sdf.format(new Date()));
excel.setMail(mail);
excel.setName(fileName);
excel.setUrl(path);
excel.setNum(lists.size());
ExcelReadAndWrite.q.offer(excel);
lists.add(excel);
if (ExcelReadAndWrite.q.size() > 1 && ExcelReadAndWrite.state == 1) {
} else {
Thread t = new Thread() {
public void run() {
try {
ExcelReadAndWrite.save();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
}
return "redirect:sh";
}
return "error3";
}
}
package com.zw.entity;
public class Person {
public int id;
public String name;
public boolean isMen;
public Character ch;
public Float float_;
public Double double_;
public Long long_;
public Short short_;
public Byte byte_;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean getIsMen() {
return isMen;
}
public void setIsMen(boolean isMen) {
this.isMen = isMen;
}
public Character getCh() {
return ch;
}
public void setCh(Character ch) {
this.ch = ch;
}
public Float getFloat_() {
return float_;
}
public void setFloat_(Float float_) {
this.float_ = float_;
}
public Double getDouble_() {
return double_;
}
public void setDouble_(Double double_) {
this.double_ = double_;
}
public Long getLong_() {
return long_;
}
public void setLong_(Long long_) {
this.long_ = long_;
}
public Short getShort_() {
return short_;
}
public void setShort_(Short short_) {
this.short_ = short_;
}
public Byte getByte_() {
return byte_;
}
public void setByte_(Byte byte_) {
this.byte_ = byte_;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
package sendmail;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.annotation.Resource;
import javax.mail.BodyPart;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 閭欢鍙戯拷?锟藉伐鍏风被
*
* @author shenjinzhu
*/
public class SendMailUtil {
private final static Log log=LogFactory.getLog(SendMailUtil.class);
// 发送邮件的邮箱号(若有授权码则密码输入授权码)
public static String myEmailAccount = "ccxe4zhishu@126.com";
public static String myEmailPassword = "1q2w3e4r5t";
// public static String myEmailAccount = "ccxerisk@sina.com";
// public static String myEmailPassword = "1q2w3e4r";
// 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
// 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
public static String myEmailSMTPHost = "smtp.126.com";
/**
*
* @param mail
* 接收者的邮箱号
* @param url
* 本地的附件地址
*/
public static void sendMessage(String mail, String url,String str) {
log.info(mail+","+url+","+str);
// 创建参数配置, 用于连接邮件服务器的参数配置
Properties props = new Properties();
// 使用的协议(JavaMail规范要求)
props.setProperty("mail.transport.protocol", "smtp");
// 发件人的邮箱的 SMTP 服务器地址
props.setProperty("mail.smtp.host", myEmailSMTPHost);
// 需要请求认证
props.setProperty("mail.smtp.auth", "true");
final String smtpPort = "465";
props.setProperty("mail.smtp.port", smtpPort);
props.setProperty("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.socketFactory.port", smtpPort);
// PopupAuthenticator popAuthenticator=new PopupAuthenticator();
// PasswordAuthentication pop = popAuthenticator.performCheck("wanghongshuai@ccxe.com.cn","tt67z890zh");
// Session mysession = Session.getInstance(props, popAuthenticator);
//
// PS: 某些邮箱服务器要求 SMTP 连接需要使用 SSL 安全认证 (为了提高安全性, 邮箱支持SSL连接, 也可以自己开启),
// 如果无法连接邮件服务器, 仔细查看控制台打印的 log, 如果有有类似 “连接失败, 要求 SSL 安全连接” 等错误,
/*
* // SMTP 服务器的端口 ( SSL 连接的端口一般默认为 25, 可以不添加, 如果开启了 SSL 连接, //
* 需要改为对应邮箱的 SMTP 服务器的端口, 具体可查看对应邮箱服务的帮助, // QQ邮箱的SMTP(SLL)端口为465587,
* 其他邮箱自行去查看) final String smtpPort = "465";
* props.setProperty("mail.smtp.port", smtpPort);
* props.setProperty("mail.smtp.socketFactory.class",
* "javax.net.ssl.SSLSocketFactory");
* props.setProperty("mail.smtp.socketFactory.fallback", "false");
* props.setProperty("mail.smtp.socketFactory.port", smtpPort);
*/
// 根据配置创建会话对象, 用于和邮件服务器交互
Session session = Session.getDefaultInstance(props);
session.setDebug(false); // 设置为debug模式, 可以查看详细的发送 log
// 创建邮件
MimeMessage message;
try {
message = createMimeMessage(session, myEmailAccount, mail, url,str);
// 根据 Session 获取邮件传输对象
Transport transport = session.getTransport();
/*
* 使用 邮箱账号 密码 连接邮件服务器, 这里认证的邮箱必须与 message 中的发件人邮箱一致, 否则报错 PS_02:
* 连接失败的原因通常为以下几点, 仔细检查代码: (1) 邮箱没有开启 SMTP 服务; (2) 邮箱密码错误,
* 例如某些邮箱开启了独立密码; (3) 邮箱服务器要求必须要使用 SSL 安全连接; (4) 请求过于频繁或其他原因,
* 被邮件服务器拒绝服务; (5) 如果以上几点都确定无误, 到邮件服务器网站查找帮助。
*/
transport.connect(myEmailAccount, myEmailPassword);
// 发送邮件
transport.sendMessage(message, message.getAllRecipients());
// 关闭连接
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 创建一封只包含文本的简单邮件
*
* @param session
* 和服务器交互的会话
* @param sendMail
* 发件人邮箱
* @param receiveMail
* 收件人邮箱
* @param url
* 本地文件地址
* @return
* @throws Exception
*/
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String url,String strtitle)
throws Exception {
// 创建邮件
MimeMessage message = new MimeMessage(session);
SimpleDateFormat sfm = new SimpleDateFormat("yyyyMMdd");
String str = sfm.format(new Date());
// From: 发件人
message.setFrom(new InternetAddress(sendMail, "陈栋", "UTF-8"));
// To: 收件人(可以增加多个收件人、抄送、密送)
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "UTF-8"));
// Subject: 邮件主题
message.setSubject(str + "数据结果", "UTF-8");
/*
* Content: 邮件正文(可以使用html标签) message.setContent(
* "XX用户你好, 今天全场5折, 快来抢购, 错过今天再等一年。。。", "text/html;charset=UTF-8");
*/
// 创建消息部分
BodyPart messageBodyPart = new MimeBodyPart();
String content = "你好";
// content=new MailContent().getHtml();
// 正文消息消息
messageBodyPart.setContent(content,"text/html; charset=utf-8");
// 创建多重消息
Multipart multipart = new MimeMultipart();
// 设置文本消息部分
multipart.addBodyPart(messageBodyPart);
// 附件部分
messageBodyPart = new MimeBodyPart();
// 文件本地地址
String filename = url;
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
String hourstr = "";
if (new Date().getHours() <= 10) {
hourstr = "09";
} else if(new Date().getHours()<=13){
hourstr = "12";
} else{
hourstr = "16";
}
// 年月日时
messageBodyPart.setFileName(sfm.format(new Date()) + hourstr + ".xls");
multipart.addBodyPart(messageBodyPart);
// 发送完整消息
message.setContent(multipart);
// 设置发件时间
message.setSentDate(new Date());
// 保存设置
message.saveChanges();
return message;
}
public static void main(String[] args) {
SendMailUtil.sendMessage("shenjinzhu999@163.com", "C:/Users/Administrator/Desktop/new.xls","ccxe");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
">
<context:annotation-config />
<context:component-scan base-package="com.zhiwei.servlet" />
<mvc:default-servlet-handler />
<mvc:annotation-driven />
<!-- ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600"/>
<property name="maxInMemorySize" value="4096"/>
</bean>
</beans>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h2>文件类型错误</h2>
</body>
</html>
\ No newline at end of file
package sendmail;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.annotation.Resource;
import javax.mail.BodyPart;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
/**
* 閭欢鍙戯拷?锟藉伐鍏风被
*
* @author shenjinzhu
*/
public class SendMailUtil {
// 发送邮件的邮箱号(若有授权码则密码输入授权码)
public static String myEmailAccount = "ccxe4zhishu@126.com";
public static String myEmailPassword = "1q2w3e4r5t";
// public static String myEmailAccount = "ccxerisk@sina.com";
// public static String myEmailPassword = "1q2w3e4r";
// 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
// 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
public static String myEmailSMTPHost = "smtp.126.com";
/**
*
* @param mail
* 接收者的邮箱号
* @param url
* 本地的附件地址
*/
public static void sendMessage(String mail, String url,String str) {
System.out.println(mail+","+url+","+str);
// 创建参数配置, 用于连接邮件服务器的参数配置
Properties props = new Properties();
// 使用的协议(JavaMail规范要求)
props.setProperty("mail.transport.protocol", "smtp");
// 发件人的邮箱的 SMTP 服务器地址
props.setProperty("mail.smtp.host", myEmailSMTPHost);
// 需要请求认证
props.setProperty("mail.smtp.auth", "true");
final String smtpPort = "465";
props.setProperty("mail.smtp.port", smtpPort);
props.setProperty("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.socketFactory.port", smtpPort);
// PopupAuthenticator popAuthenticator=new PopupAuthenticator();
// PasswordAuthentication pop = popAuthenticator.performCheck("wanghongshuai@ccxe.com.cn","tt67z890zh");
// Session mysession = Session.getInstance(props, popAuthenticator);
//
// PS: 某些邮箱服务器要求 SMTP 连接需要使用 SSL 安全认证 (为了提高安全性, 邮箱支持SSL连接, 也可以自己开启),
// 如果无法连接邮件服务器, 仔细查看控制台打印的 log, 如果有有类似 “连接失败, 要求 SSL 安全连接” 等错误,
/*
* // SMTP 服务器的端口 ( SSL 连接的端口一般默认为 25, 可以不添加, 如果开启了 SSL 连接, //
* 需要改为对应邮箱的 SMTP 服务器的端口, 具体可查看对应邮箱服务的帮助, // QQ邮箱的SMTP(SLL)端口为465587,
* 其他邮箱自行去查看) final String smtpPort = "465";
* props.setProperty("mail.smtp.port", smtpPort);
* props.setProperty("mail.smtp.socketFactory.class",
* "javax.net.ssl.SSLSocketFactory");
* props.setProperty("mail.smtp.socketFactory.fallback", "false");
* props.setProperty("mail.smtp.socketFactory.port", smtpPort);
*/
// 根据配置创建会话对象, 用于和邮件服务器交互
Session session = Session.getDefaultInstance(props);
session.setDebug(false); // 设置为debug模式, 可以查看详细的发送 log
// 创建邮件
MimeMessage message;
try {
message = createMimeMessage(session, myEmailAccount, mail, url,str);
// 根据 Session 获取邮件传输对象
Transport transport = session.getTransport();
/*
* 使用 邮箱账号 密码 连接邮件服务器, 这里认证的邮箱必须与 message 中的发件人邮箱一致, 否则报错 PS_02:
* 连接失败的原因通常为以下几点, 仔细检查代码: (1) 邮箱没有开启 SMTP 服务; (2) 邮箱密码错误,
* 例如某些邮箱开启了独立密码; (3) 邮箱服务器要求必须要使用 SSL 安全连接; (4) 请求过于频繁或其他原因,
* 被邮件服务器拒绝服务; (5) 如果以上几点都确定无误, 到邮件服务器网站查找帮助。
*/
transport.connect(myEmailAccount, myEmailPassword);
// 发送邮件
transport.sendMessage(message, message.getAllRecipients());
// 关闭连接
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 创建一封只包含文本的简单邮件
*
* @param session
* 和服务器交互的会话
* @param sendMail
* 发件人邮箱
* @param receiveMail
* 收件人邮箱
* @param url
* 本地文件地址
* @return
* @throws Exception
*/
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String url,String strtitle)
throws Exception {
// 创建邮件
MimeMessage message = new MimeMessage(session);
SimpleDateFormat sfm = new SimpleDateFormat("yyyyMMdd");
String str = sfm.format(new Date());
// From: 发件人
message.setFrom(new InternetAddress(sendMail, "陈栋", "UTF-8"));
// To: 收件人(可以增加多个收件人、抄送、密送)
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "UTF-8"));
// Subject: 邮件主题
message.setSubject(str + "数据结果", "UTF-8");
/*
* Content: 邮件正文(可以使用html标签) message.setContent(
* "XX用户你好, 今天全场5折, 快来抢购, 错过今天再等一年。。。", "text/html;charset=UTF-8");
*/
// 创建消息部分
BodyPart messageBodyPart = new MimeBodyPart();
String content = "你好";
// content=new MailContent().getHtml();
// 正文消息消息
messageBodyPart.setContent(content,"text/html; charset=utf-8");
// 创建多重消息
Multipart multipart = new MimeMultipart();
// 设置文本消息部分
multipart.addBodyPart(messageBodyPart);
// 附件部分
messageBodyPart = new MimeBodyPart();
// 文件本地地址
String filename = url;
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
String hourstr = "";
if (new Date().getHours() <= 10) {
hourstr = "09";
} else if(new Date().getHours()<=13){
hourstr = "12";
} else{
hourstr = "16";
}
// 年月日时
messageBodyPart.setFileName(sfm.format(new Date()) + hourstr + ".xls");
multipart.addBodyPart(messageBodyPart);
// 发送完整消息
message.setContent(multipart);
// 设置发件时间
message.setSentDate(new Date());
// 保存设置
message.saveChanges();
return message;
}
public static void main(String[] args) {
SendMailUtil.sendMessage("shenjinzhu999@163.com", "C:/Users/Administrator/Desktop/new.xls","ccxe");
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h3>邮箱号输入有误</h3>
<form action="/change4weixin/return" method="post">
<input type="submit" value="返回">
</form>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="D:/ZhiWei/change4weixin/target/classes">
</dir>
</classpath>
<web>
<link target="/">
<dir name="D:/ZhiWei/change4weixin/src/main/webapp">
</dir>
</link>
</web>
</application>
package com.zw.entity;
import java.io.Serializable;
/**
* 微博信息
* @author Administrator
*
*/
public class Weibo implements Serializable{
private String idTitle; //标题
private String sex; //性别
private String place; //地点
private String mainUrl; //主站
private String uid;
private String brief_introduction;//简介
private String achievement;//成就
private String fans; //粉丝
private String flower; //关注
private String publish; //发表微博
private String label;
private String teach;
private String authentication;//认证
private String job;
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getTeach() {
return teach;
}
public void setTeach(String teach) {
this.teach = teach;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getIdTitle() {
return idTitle;
}
public void setIdTitle(String idTitle) {
this.idTitle = idTitle;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public String getMainUrl() {
return mainUrl;
}
public void setMainUrl(String mainUrl) {
this.mainUrl = mainUrl;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getBrief_introduction() {
return brief_introduction;
}
public void setBrief_introduction(String brief_introduction) {
this.brief_introduction = brief_introduction;
}
public String getAchievement() {
return achievement;
}
public void setAchievement(String achievement) {
this.achievement = achievement;
}
public String getFans() {
return fans;
}
public void setFans(String fans) {
this.fans = fans;
}
public String getFlower() {
return flower;
}
public void setFlower(String flower) {
this.flower = flower;
}
public String getPublish() {
return publish;
}
public void setPublish(String publish) {
this.publish = publish;
}
public String getAuthentication() {
return authentication;
}
public void setAuthentication(String authentication) {
this.authentication = authentication;
}
@Override
public String toString() {
return "Weibo [idTitle=" + idTitle + ", sex=" + sex + ", place=" + place + ", mainUrl=" + mainUrl + ", uid="
+ uid + ", brief_introduction=" + brief_introduction + ", achievement=" + achievement + ", fans=" + fans
+ ", flower=" + flower + ", publish=" + publish + ", label=" + label + ", teach=" + teach
+ ", authentication=" + authentication + ", job=" + job + "]";
}
}
package com.zhiwei.chendong;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import com.zhiwei.servlet.MainController;
import com.zw.entity.Weixin;
public class ReaderExcel {
private final static Log log = LogFactory.getLog(ReaderExcel.class);
public static void main(String[] args) throws IOException {
for (Weixin w : getExcel("")) {
log.info(w);
}
}
public static List<Weixin> getExcel(String url) throws IOException {
// String url="C:/Users/Administrator/Desktop/jd.xls";
List<Weixin> list = new ArrayList<>();
Workbook book = null;
book = getExcelWorkbook(url);
Sheet sheet = getSheetByNum(book, 0);
int lastRowNum = sheet.getLastRowNum();
log.info("last number is " + lastRowNum);
for (int i = 1; i <= lastRowNum; i++) {
Row row = null;
row = sheet.getRow(i);
if (row != null) {
int lastCellNum = row.getLastCellNum();
Cell cell = null;
Weixin w = new Weixin();
for (int j = 0; j < lastCellNum; j++) {
cell = row.getCell(j);
if (cell != null) {
cell.setCellType(Cell.CELL_TYPE_STRING);
String str = cell.getStringCellValue();
if (str != null) {
if(sheet.getRow(0).getCell(j)==null){
continue;
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("来源")) {
w.setSource(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("时间")) {
w.setTime(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("标题")) {
w.setTitle(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("地址")) {
w.setUrl(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("内容")) {
w.setConetent(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("关键词")) {
w.setKeyValue(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("阅读数")) {
w.setRead(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("点赞数")) {
w.setZan(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("用户昵称")) {
w.setNickname(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("简介")) {
w.setJianjie(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("历史标注情况")) {
w.setHistory(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("长地址")) {
w.setLongUrl(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("mark")) {
w.setMark(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("mark_time")) {
w.setMark_time(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("markname")) {
w.setMarkname(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("真实阅读数")) {
w.setTrueRead(str == null ? "null" : str);
}
}
}
}
if (w != null)
list.add(w);
}
}
return list;
}
public static Sheet getSheetByNum(Workbook book, int number) {
Sheet sheet = null;
try {
sheet = book.getSheetAt(number);
// if(sheet == null){
// sheet = book.createSheet("Sheet"+number);
// }
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return sheet;
}
public static Workbook getExcelWorkbook(String filePath) throws IOException {
Workbook book = null;
File file = null;
FileInputStream fis = null;
try {
file = new File(filePath);
if (!file.exists()) {
throw new RuntimeException("文件不存在");
} else {
fis = new FileInputStream(file);
book = WorkbookFactory.create(fis);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
} finally {
if (fis != null) {
fis.close();
}
}
return book;
}
}
package com.zhiwei.chendong;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import com.zw.entity.Weixin;
public class ReaderExcel {
public static void main(String[] args) throws IOException {
for (Weixin w : getExcel("C:/Users/Administrator/Desktop/jd.xls")) {
System.out.println(w);
}
}
public static List<Weixin> getExcel(String url) throws IOException {
List<Weixin> list = new ArrayList<>();
Workbook book = null;
book = getExcelWorkbook(url);
Sheet sheet = getSheetByNum(book, 0);
int lastRowNum = sheet.getLastRowNum();
System.out.println("last number is " + lastRowNum);
for (int i = 1; i <= lastRowNum; i++) {
Row row = null;
row = sheet.getRow(i);
if (row != null) {
int lastCellNum = row.getLastCellNum();
Cell cell = null;
Weixin w = new Weixin();
for (int j = 0; j < lastCellNum; j++) {
cell = row.getCell(j);
if (cell != null) {
cell.setCellType(Cell.CELL_TYPE_STRING);
String str = cell.getStringCellValue();
if (str != null) {
if(sheet.getRow(0).getCell(j)==null){
continue;
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("来源")) {
w.setSource(str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("时间")) {
w.setTime(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("标题")) {
w.setTitle(str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("地址")) {
w.setUrl(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("内容")) {
w.setConetent(str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("关键词")) {
w.setKeyValue(str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("阅读数")) {
w.setRead(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("点赞数")) {
w.setZan(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("用户昵称")) {
w.setNickname(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("简介")) {
w.setJianjie(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("历史标注情况")) {
w.setHistory(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("长地址")) {
w.setLongUrl(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("mark")) {
w.setMark(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("mark_time")) {
w.setMark_time(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("markname")) {
w.setMarkname(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("真实阅读数")) {
w.setTrueRead(str == null ? "null" : str);
}
}
}
}
if (w != null)
list.add(w);
}
}
return list;
}
public static Sheet getSheetByNum(Workbook book, int number) {
Sheet sheet = null;
try {
sheet = book.getSheetAt(number);
// if(sheet == null){
// sheet = book.createSheet("Sheet"+number);
// }
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return sheet;
}
public static Workbook getExcelWorkbook(String filePath) throws IOException {
Workbook book = null;
File file = null;
FileInputStream fis = null;
try {
file = new File(filePath);
if (!file.exists()) {
throw new RuntimeException("文件不存在");
} else {
fis = new FileInputStream(file);
book = WorkbookFactory.create(fis);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
} finally {
if (fis != null) {
fis.close();
}
}
return book;
}
}
package com.zw.entity;
public class Weixin {
private String source;
private String url;
private String getUrl;
private String title;
private String time;
private String conetent;
private String keyValue;
//微博
private String read;
private String zan;
private String nickname;
private String jianjie;
private String history;
private String longUrl;
private String mark;
private String mark_time;
private String markname;
private String trueRead;
public String getRead() {
return read;
}
public void setRead(String read) {
this.read = read;
}
public String getZan() {
return zan;
}
public void setZan(String zan) {
this.zan = zan;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getJianjie() {
return jianjie;
}
public void setJianjie(String jianjie) {
this.jianjie = jianjie;
}
public String getHistory() {
return history;
}
public void setHistory(String history) {
this.history = history;
}
public String getLongUrl() {
return longUrl;
}
public void setLongUrl(String longUrl) {
this.longUrl = longUrl;
}
public String getMark() {
return mark;
}
public void setMark(String mark) {
this.mark = mark;
}
public String getMark_time() {
return mark_time;
}
public void setMark_time(String mark_time) {
this.mark_time = mark_time;
}
public String getMarkname() {
return markname;
}
public void setMarkname(String markname) {
this.markname = markname;
}
public String getTrueRead() {
return trueRead;
}
public void setTrueRead(String trueRead) {
this.trueRead = trueRead;
}
public String getKeyValue() {
return keyValue;
}
public void setKeyValue(String keyValue) {
this.keyValue = keyValue;
}
public String getConetent() {
return conetent;
}
public void setConetent(String conetent) {
this.conetent = conetent;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getGetUrl() {
return getUrl;
}
public void setGetUrl(String getUrl) {
this.getUrl = getUrl;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
@Override
public String toString() {
return "Weixin [source=" + source + ", url=" + url + ", getUrl=" + getUrl + ", title=" + title + ", time="
+ time + ", conetent=" + conetent + ", keyValue=" + keyValue + ", read=" + read + ", zan=" + zan
+ ", nickname=" + nickname + ", jianjie=" + jianjie + ", history=" + history + ", longUrl=" + longUrl
+ ", mark=" + mark + ", mark_time=" + mark_time + ", markname=" + markname + ", trueRead=" + trueRead
+ "]";
}
}
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
rootLogger.level = info
rootLogger.appenderRef.console.ref = console
\ No newline at end of file
package com.zw.entity;
import java.io.Serializable;
/**
* 根据openid获取到的用户信息
* @author SJZ
*/
public class UserInfo implements Serializable{
private String subscribe;//用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。
private String openid;//用户的标识,对当前公众号唯一
private String nickname;//用户的昵称
private String sex;//用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
private String language;//用户的语言,简体中文为zh_CN
private String city;//用户所在城市
private String province;//用户所在省份
private String country;//用户所在国家
private String headimgurl;//用户头像,最后一个数值代表正方形头像大小(有0466496132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。
private String subscribe_time;//用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
private String groupid;//用户所在的分组ID(兼容旧的用户分组接口)
private String unionid;//只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
private String tagid_list;//用户被打上的标签ID列表
private String remark;//公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注
public String getSubscribe() {
return subscribe;
}
public void setSubscribe(String subscribe) {
this.subscribe = subscribe;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getHeadimgurl() {
return headimgurl;
}
public void setHeadimgurl(String headimgurl) {
this.headimgurl = headimgurl;
}
public String getSubscribe_time() {
return subscribe_time;
}
public void setSubscribe_time(String subscribe_time) {
this.subscribe_time = subscribe_time;
}
public String getGroupid() {
return groupid;
}
public void setGroupid(String groupid) {
this.groupid = groupid;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
public String getTagid_list() {
return tagid_list;
}
public void setTagid_list(String tagid_list) {
this.tagid_list = tagid_list;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "UserInfo [subscribe=" + subscribe + ", openid=" + openid + ", nickname=" + nickname + ", sex=" + sex
+ ", language=" + language + ", city=" + city + ", province=" + province + ", country=" + country
+ ", headimgurl=" + headimgurl + ", subscribe_time=" + subscribe_time + ", groupid=" + groupid
+ ", unionid=" + unionid + ", tagid_list=" + tagid_list + ", remark=" + remark + "]";
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
$(function() {
getTime();
setInterval("getTime()", 10*1000);
});
function getTime() {
var time = $('#time').empty();
$.ajax({
url : '/change4weixin/show',
success : function(result) {
var list = JSON.parse(result);
console.log(list);
console.log(list.length);
var time = $('#time').empty();
var t = 0;
for (var i = 0; i < list.length; i++) {
t += list[i].need;
if (i > 0) {
var addem ='<span>位置编号:'+(i+1)+','+list[i].mail+'需要等待的时间:' + (t+2*(i+1))
+ '分钟</span><br>';
} else {
var addem = '<span>位置编号:'+(i+1)+','+list[i].mail+'开始时间:' + list[i].date
+ '需要的时间:' + (list[i].need+2*(i+1))
+ '分钟</span><br>';
}
time.append(addem);
}
}
});
}
</script>
</head>
<body>
<div><span>有时候显示有点问题,耐心等待</span></div>
<div id="time"></div>
</body>
</html>
\ No newline at end of file
package com.zhiwei.chendong;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
public class MongoForChenDong {
private MongoClient mongoClient = null;
private static MongoForChenDong mongoDBPool = new MongoForChenDong(); // 饿汉式
// 单例模式
public MongoForChenDong() {
if (mongoClient == null) {
MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder();
optionsBuilder.connectionsPerHost(100); // 与目标数据库可创建的最大连接数
optionsBuilder.connectTimeout(1000 * 60 * 40); // 与数据库建立连接的超时时间
optionsBuilder.maxWaitTime(1000 * 60 * 5); // 一个线程成功获取到一个可用数据库连接之前的最大等待时间
optionsBuilder.threadsAllowedToBlockForConnectionMultiplier(100);// 等待一个连接
// 允许阻塞的线程数
optionsBuilder.maxConnectionIdleTime(0);
optionsBuilder.maxConnectionLifeTime(0);
optionsBuilder.socketKeepAlive(true);
optionsBuilder.socketTimeout(1000 * 20);
MongoClientOptions options = optionsBuilder.build();
char[] passwords = "1q2w3e4r".toCharArray();
List<MongoCredential> credentials = new ArrayList<>();
MongoCredential credential = MongoCredential.createCredential("zhiweidata", "spyPlat", passwords);
credentials.add(credential);
List<ServerAddress> serverAddresses = new ArrayList<>();
serverAddresses.add(new ServerAddress("106.14.249.240", 26807));
mongoClient = new MongoClient(serverAddresses, credentials, options);
}
}
public DB getDB(String dbName) {
return mongoClient.getDB(dbName);
}
/**
* 添加mongo名称和集合名称
*
* @param dbName
* @param collectionName
* @return
*/
public DBCollection getCollection(String dbName, String collectionName) {
DB db = mongoClient.getDB(dbName);
return db.getCollection(collectionName);
}
public List<Map<String, Object>> find() {
DB db = mongoClient.getDB("spyPlat");
DBCollection dbCollection = db.getCollection("Result");
DBObject obj = new BasicDBObject();
DBCursor dbCursor = dbCollection.find();
List<Map<String, Object>> list = new ArrayList<>();
while (dbCursor.hasNext()) {
list.add((Map<String, Object>) dbCursor.next());
}
return list;
}
public void insert(List<String> list) {
DB db = mongoClient.getDB("spyPlat");
DBCollection dbCollection = db.getCollection("RawUrl");
for (String l : list) {
DBObject obj = new BasicDBObject();
obj.put("_id", l);
obj.put("url", l);
try {
dbCollection.insert(obj);
} catch (Exception e) {
System.out.println(l);
}
}
}
public static void main(String[] args) {
MongoForChenDong m = new MongoForChenDong();
}
}
File added
<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>
<groupId>com.zhiwei</groupId>
<artifactId>change4weixin</artifactId>
<version>3.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.24</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.29</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>com.github.liyiorg</groupId>
<artifactId>weixin-popular</artifactId>
<version>2.8.10</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<!-- mongodb -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.zhiwei.chendong;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import com.zw.entity.ExcelFile;
@Component
public class FileThread extends Thread{
private static final Log log=LogFactory.getLog(FileThread.class);
private static MongoForChenDong m=new MongoForChenDong();
public FileThread(){
this.start();
}
public void run(){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
while(true){
Calendar c=Calendar.getInstance();
if(c.get(Calendar.HOUR_OF_DAY)==1){
c.add(Calendar.DATE, -7);
List<String> removeList=new ArrayList<String>();
List<ExcelFile> list=m.findFile();
for(ExcelFile ex:list){
try {
if(sdf.parse(ex.getDate()).before(c.getTime())){
removeList.add(ex.getId());
ExcelReadAndWrite.delete(ex.getUrl());
}
} catch (ParseException e) {
log.info("时间格式转换出错{FileThread.39}");
}
}
for(String url:removeList){
m.delete(url);
}
try {
Thread.sleep(1000*3600);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
try {
Thread.sleep(1000*60*30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
package com.zhiwei.chendong;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bson.types.ObjectId;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.zhiwei.servlet.MainController;
import com.zhiwei.util.Config;
import com.zw.entity.ExcelFile;
import com.zw.entity.Excels;
public class MongoForChenDong {
private final static Log log = LogFactory.getLog(MongoForChenDong.class);
private MongoClient mongoClient = null;
private static MongoForChenDong mongoDBPool = new MongoForChenDong(); // 饿汉式
// 单例模式
public MongoForChenDong() {
if (mongoClient == null) {
MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder();
optionsBuilder.connectionsPerHost(100); // 与目标数据库可创建的最大连接数
optionsBuilder.connectTimeout(1000 * 60 * 40); // 与数据库建立连接的超时时间
optionsBuilder.maxWaitTime(1000 * 60 * 5); // 一个线程成功获取到一个可用数据库连接之前的最大等待时间
optionsBuilder.threadsAllowedToBlockForConnectionMultiplier(100);// 等待一个连接
// //
// 允许阻塞的线程数
optionsBuilder.maxConnectionIdleTime(0);
optionsBuilder.maxConnectionLifeTime(0);
optionsBuilder.socketKeepAlive(true);
optionsBuilder.socketTimeout(1000 * 20);
MongoClientOptions options = optionsBuilder.build();
char[] passwords = Config.getVal("password").toCharArray();
List<MongoCredential> credentials = new ArrayList<>();
MongoCredential credential = MongoCredential.createCredential(Config.getVal("user"),
Config.getVal("dbName"), passwords);
credentials.add(credential);
List<ServerAddress> serverAddresses = new ArrayList<>();
serverAddresses.add(new ServerAddress(Config.getVal("host"), Integer.valueOf(Config.getVal("port"))));
mongoClient = new MongoClient(serverAddresses, credentials, options);
}
}
public DB getDB(String dbName) {
return mongoClient.getDB(dbName);
}
/**
* 添加mongo名称和集合名称
*
* @param dbName
* @param collectionName
* @return
*/
public DBCollection getCollection(String dbName, String collectionName) {
DB db = mongoClient.getDB(dbName);
return db.getCollection(collectionName);
}
public List<Map<String, Object>> find() {
DB db = mongoClient.getDB(Config.getVal("dbName"));
DBCollection dbCollection = db.getCollection("Result");
DBObject obj = new BasicDBObject();
DBCursor dbCursor = dbCollection.find();
List<Map<String, Object>> list = new ArrayList<>();
while (dbCursor.hasNext()) {
list.add((Map<String, Object>) dbCursor.next());
}
return list;
}
public void insert(List<String> list) {
DB db = mongoClient.getDB(Config.getVal("dbName"));
DBCollection dbCollection = db.getCollection("RawUrl");
for (String l : list) {
DBObject obj = new BasicDBObject();
obj.put("_id", l);
obj.put("url", l);
try {
dbCollection.insert(obj);
} catch (Exception e) {
log.info(l);
}
}
}
public int getNum() {
DB db = mongoClient.getDB(Config.getVal("dbName"));
DBCollection dbCollection = db.getCollection("RawUrl");
DBCursor dbCursor = dbCollection.find();
List<Map<String, Object>> list = new ArrayList<>();
while (dbCursor.hasNext()) {
list.add((Map<String, Object>) dbCursor.next());
}
return list.size();
}
/**
* 微信转链接的文件地址入库
*/
public void insertFile(ExcelFile excel) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DB db = mongoClient.getDB(Config.getVal("dbName"));
DBCollection dbCollection = db.getCollection("changeUrlFile");
DBObject obj = new BasicDBObject();
obj.put("url", excel.getUrl());
obj.put("mail", excel.getMail());
obj.put("date", sdf.format(new Date()));
dbCollection.insert(obj);
}
/**
* 获取信息
* @return
*/
public List<ExcelFile> findFile() {
List<ExcelFile> list = new ArrayList<ExcelFile>();
DB db = mongoClient.getDB(Config.getVal("dbName"));
DBCollection dbCollection = db.getCollection("changeUrlFile");
DBCursor dbCursor = dbCollection.find().sort(new BasicDBObject("date",-1));
System.out.println("size"+dbCursor.size());
while (dbCursor.hasNext()) {
Map<String, Object> map = (Map<String, Object>) dbCursor.next();
ExcelFile ef = new ExcelFile();
ef.setId(String.valueOf(map.get("_id")));
ef.setUrl(String.valueOf(map.get("url")));
ef.setMail(String.valueOf(map.get("mail")));
ef.setDate(String.valueOf(map.get("date")));
list.add(ef);
}
System.out.println(list.size());
return list;
}
public void delete(String id){
DB db = mongoClient.getDB(Config.getVal("dbName"));
DBCollection dbCollection = db.getCollection("changeUrlFile");
dbCollection.remove(new BasicDBObject("_id",new ObjectId(id)));
}
public String findByid(String id){
DB db = mongoClient.getDB(Config.getVal("dbName"));
DBCollection dbCollection = db.getCollection("changeUrlFile");
DBObject obj=dbCollection.findOne(new BasicDBObject("_id",new ObjectId(id)));
return String.valueOf(obj.get("url"));
}
}
package com.zhiwei.chendong;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import com.zhiwei.servlet.MainController;
import com.zw.entity.Weixin;
public class ReaderExcel {
private final static Log log = LogFactory.getLog(ReaderExcel.class);
public static void main(String[] args) throws IOException {
for (Weixin w : getExcel("")) {
log.info(w);
}
}
public static List<Weixin> getExcel(String url) throws IOException {
// String url="C:/Users/Administrator/Desktop/jd.xls";
List<Weixin> list = new ArrayList<>();
Workbook book = null;
book = getExcelWorkbook(url);
Sheet sheet = getSheetByNum(book, 0);
int lastRowNum = sheet.getLastRowNum();
log.info("last number is " + lastRowNum);
for (int i = 1; i <= lastRowNum; i++) {
Row row = null;
row = sheet.getRow(i);
if (row != null) {
int lastCellNum = row.getLastCellNum();
Cell cell = null;
Weixin w = new Weixin();
for (int j = 0; j < lastCellNum; j++) {
cell = row.getCell(j);
if (cell != null) {
cell.setCellType(Cell.CELL_TYPE_STRING);
String str = cell.getStringCellValue();
if (str != null) {
if(sheet.getRow(0).getCell(j)==null){
continue;
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("来源")) {
w.setSource(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("时间")) {
w.setTime(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("标题")) {
w.setTitle(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("地址")) {
w.setUrl(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("内容")) {
w.setConetent(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("关键词")) {
w.setKeyValue(str== null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("阅读数")) {
w.setRead(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("点赞数")) {
w.setZan(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("用户昵称")) {
w.setNickname(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("简介")) {
w.setJianjie(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("历史标注情况")) {
w.setHistory(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("长地址")) {
w.setLongUrl(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("mark")) {
w.setMark(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("mark_time")) {
w.setMark_time(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("markname")) {
w.setMarkname(str == null ? "null" : str);
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("真实阅读数")) {
w.setTrueRead(str == null ? "null" : str);
}
}
}
}
if (w != null)
list.add(w);
}
}
return list;
}
public static Sheet getSheetByNum(Workbook book, int number) {
Sheet sheet = null;
try {
sheet = book.getSheetAt(number);
// if(sheet == null){
// sheet = book.createSheet("Sheet"+number);
// }
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return sheet;
}
public static Workbook getExcelWorkbook(String filePath) throws IOException {
Workbook book = null;
File file = null;
FileInputStream fis = null;
try {
file = new File(filePath);
if (!file.exists()) {
throw new RuntimeException("文件不存在");
} else {
fis = new FileInputStream(file);
book = WorkbookFactory.create(fis);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
} finally {
if (fis != null) {
fis.close();
}
}
return book;
}
}
package com.zhiwei.servlet;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.zhiwei.chendong.ExcelReadAndWrite;
import com.zhiwei.chendong.ReaderExcel;
import com.zhiwei.util.Config;
import com.zw.entity.ExcelFile;
import com.zw.entity.Excels;
import com.zw.entity.Weixin;
@Controller
public class MainController {
private final static Log log = LogFactory.getLog(MainController.class);
public static Vector<Excels> lists = new Vector<Excels>();
public static Excels excel = null;
@RequestMapping("/scanExcel")
public String mian() {
return "test";
}
@RequestMapping(value = "/show")
public void shows(HttpServletRequest request, HttpServletResponse response) throws IOException {
System.out.println(lists.size());
try {
for (int i = 0; i < lists.size(); i++) {
Excels e = lists.get(i);
e.setSite(i + 1);
}
response.setContentType("text/plain;charset=utf-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Access-Control-Allow-Origin", "*");
PrintWriter out = response.getWriter();
String jsonpCallback = request.getParameter("callback");// 客户端请求参数
out.println(JSON.toJSONString(lists));// 返回jsonp格式数据
out.flush();
out.close();
System.out.println(lists.size());
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping(value = "/downLode")
public void downLode(HttpServletRequest request, HttpServletResponse response) {
System.out.println(ExcelReadAndWrite.findEf());
try {
response.setContentType("text/plain;charset=utf-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Access-Control-Allow-Origin", "*");
PrintWriter out = response.getWriter();
// String jsonpCallback = request.getParameter("callback");//
// 客户端请求参数
out.println(JSON.toJSONString(ExcelReadAndWrite.findEf()));//
// 返回jsonp格式数据
out.flush();
out.close();
System.out.println(lists.size());
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping(value = "/downLodeFile")
public void downFile(HttpServletRequest request, HttpServletResponse response,String id) {
System.out.println(ExcelReadAndWrite.findEf());
try {
response.setContentType("application/msexcel;");
response.setHeader("Content-Disposition",
new String(("attachment;filename=" + "downLode.xls").getBytes("GB2312"), "UTF-8"));
File f = new File(ExcelReadAndWrite.findById(id));
// File f = new File(targetFolder.getPath()+File.separator+fName);
FileInputStream in = new FileInputStream(f);
byte b[] = new byte[1024];
int i = 0;
ServletOutputStream out = response.getOutputStream();
while ((i = in.read(b)) != -1) {
out.write(b, 0, i);
}
out.flush();
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping(value = "/delete")
public void delete(HttpServletRequest request, HttpServletResponse response, String id) {
Map<String, Boolean> map = new HashMap<String, Boolean>();
boolean b = false;
List<Excels> list = new ArrayList<Excels>();
if (id != null)
for (Excels ex : lists) {
if (ex.getId().equals(id)) {
list.add(ex);
b = true;
}
}
for (Excels e : list) {
lists.remove(e);
}
response.setContentType("text/plain;charset=utf-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Access-Control-Allow-Origin", "*");
PrintWriter out;
map.put("result", b);
try {
out = response.getWriter();
out.println(JSON.toJSONString(map));// 返回jsonp格式数据
out.flush();
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
@RequestMapping(value = "cutQ")
public void cutQ(HttpServletRequest request, HttpServletResponse response, String id) {
Map<String, Boolean> map = new HashMap<String, Boolean>();
boolean b = false;
if (ExcelReadAndWrite.cut) {
} else {
if (id != null) {
String msg = ExcelReadAndWrite.startCut(id);
if (msg.contains("ok"))
;
b = true;
}
}
response.setContentType("text/plain;charset=utf-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Access-Control-Allow-Origin", "*");
PrintWriter out;
map.put("result", b);
try {
out = response.getWriter();
out.println(JSON.toJSONString(map));// 返回jsonp格式数据
out.flush();
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
@RequestMapping("/sh")
public String showPage() {
return "dataTable";
}
@RequestMapping("/admin")
public String showPageAdmin() {
return "dataTable2";
}
@RequestMapping("/down")
public String down() {
return "dataTable3";
}
@RequestMapping(value = "/up")
public String up(HttpServletRequest req, HttpServletResponse res, MultipartFile file, String mail, String mail2)
throws Exception {
if (!mail.equals(mail2)) {
return "error";
}
System.out.println(mail);
log.info(mail);
// 得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String fileName = file.getOriginalFilename();
if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {// 是否是excel结尾的
String path = Config.getVal("timefileUrl") + "/" + mail + fileName;
log.info(path);
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
Excels excel = new Excels();
List<Weixin> list = ReaderExcel.getExcel(path);
if (list.size() == 0) {
return "error2";
}
excel.setId((int) (Math.random() * 50000) + "k");
excel.setNeed((list.size() * 5 + 40) / 60);
excel.setMail(mail);
excel.setUrl(path);
excel.setSite(0);
excel.setSurplusCount(list.size());
excel.setStartDate("未开始");
lists.add(excel);
if (!ExcelReadAndWrite.runStrat) {
Thread t = new Thread() {
public void run() {
try {
ExcelReadAndWrite.save2();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
}
return "redirect:sh";
}
return "error3";
}
}
package com.zhiwei.util;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Properties;
public class Config {
public static Properties p=new Properties();
static {
String fileurl = Config.class.getClassLoader().getResource("datasource.properties").getPath();
p = new Properties();
try {
InputStreamReader in = new InputStreamReader(new FileInputStream(fileurl),"utf-8");
p.load(in); /// 加载属性列表
in.close();
}catch(Exception e){
}
}
public static String getVal(String key){
return p.getProperty(key);
}
}
package com.zw.entity;
import java.io.Serializable;
import java.util.Date;
import com.mongodb.connection.Server;
public class ExcelFile implements Serializable{
private String id;
private String url;
private String mail;
private String date;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
@Override
public String toString() {
return "ExcelFile [url=" + url + ", mail=" + mail + ", date=" + date + "]";
}
}
package com.zw.entity;
import java.io.Serializable;
import java.util.Date;
public class Excels implements Serializable {
private String id;
private String url;
private String mail;// 上传者
private String startDate;// 开始运行
private double need;// 所需要时间
private int site;// 当前位置
private int surplusCount;// 剩余条数
private String state;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public double getNeed() {
return need;
}
public void setNeed(double need) {
this.need = need;
}
public int getSite() {
return site;
}
public void setSite(int site) {
this.site = site;
}
public int getSurplusCount() {
return surplusCount;
}
public void setSurplusCount(int surplusCount) {
this.surplusCount = surplusCount;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}
package com.zw.entity;
public class Person {
public int id;
public String name;
public boolean isMen;
public Character ch;
public Float float_;
public Double double_;
public Long long_;
public Short short_;
public Byte byte_;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean getIsMen() {
return isMen;
}
public void setIsMen(boolean isMen) {
this.isMen = isMen;
}
public Character getCh() {
return ch;
}
public void setCh(Character ch) {
this.ch = ch;
}
public Float getFloat_() {
return float_;
}
public void setFloat_(Float float_) {
this.float_ = float_;
}
public Double getDouble_() {
return double_;
}
public void setDouble_(Double double_) {
this.double_ = double_;
}
public Long getLong_() {
return long_;
}
public void setLong_(Long long_) {
this.long_ = long_;
}
public Short getShort_() {
return short_;
}
public void setShort_(Short short_) {
this.short_ = short_;
}
public Byte getByte_() {
return byte_;
}
public void setByte_(Byte byte_) {
this.byte_ = byte_;
}
}
package com.zw.entity;
import java.io.Serializable;
/**
* 根据openid获取到的用户信息
* @author SJZ
*/
public class UserInfo implements Serializable{
private String subscribe;//用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。
private String openid;//用户的标识,对当前公众号唯一
private String nickname;//用户的昵称
private String sex;//用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
private String language;//用户的语言,简体中文为zh_CN
private String city;//用户所在城市
private String province;//用户所在省份
private String country;//用户所在国家
private String headimgurl;//用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。
private String subscribe_time;//用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
private String groupid;//用户所在的分组ID(兼容旧的用户分组接口)
private String unionid;//只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
private String tagid_list;//用户被打上的标签ID列表
private String remark;//公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注
public String getSubscribe() {
return subscribe;
}
public void setSubscribe(String subscribe) {
this.subscribe = subscribe;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getHeadimgurl() {
return headimgurl;
}
public void setHeadimgurl(String headimgurl) {
this.headimgurl = headimgurl;
}
public String getSubscribe_time() {
return subscribe_time;
}
public void setSubscribe_time(String subscribe_time) {
this.subscribe_time = subscribe_time;
}
public String getGroupid() {
return groupid;
}
public void setGroupid(String groupid) {
this.groupid = groupid;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
public String getTagid_list() {
return tagid_list;
}
public void setTagid_list(String tagid_list) {
this.tagid_list = tagid_list;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "UserInfo [subscribe=" + subscribe + ", openid=" + openid + ", nickname=" + nickname + ", sex=" + sex
+ ", language=" + language + ", city=" + city + ", province=" + province + ", country=" + country
+ ", headimgurl=" + headimgurl + ", subscribe_time=" + subscribe_time + ", groupid=" + groupid
+ ", unionid=" + unionid + ", tagid_list=" + tagid_list + ", remark=" + remark + "]";
}
}
package com.zw.entity;
import java.io.Serializable;
/**
* 微博信息
* @author Administrator
*
*/
public class Weibo implements Serializable{
private String idTitle; //标题
private String sex; //性别
private String place; //地点
private String mainUrl; //主站
private String uid;
private String brief_introduction;//简介
private String achievement;//成就
private String fans; //粉丝
private String flower; //关注
private String publish; //发表微博
private String label;
private String teach;
private String authentication;//认证
private String job;
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getTeach() {
return teach;
}
public void setTeach(String teach) {
this.teach = teach;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getIdTitle() {
return idTitle;
}
public void setIdTitle(String idTitle) {
this.idTitle = idTitle;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public String getMainUrl() {
return mainUrl;
}
public void setMainUrl(String mainUrl) {
this.mainUrl = mainUrl;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getBrief_introduction() {
return brief_introduction;
}
public void setBrief_introduction(String brief_introduction) {
this.brief_introduction = brief_introduction;
}
public String getAchievement() {
return achievement;
}
public void setAchievement(String achievement) {
this.achievement = achievement;
}
public String getFans() {
return fans;
}
public void setFans(String fans) {
this.fans = fans;
}
public String getFlower() {
return flower;
}
public void setFlower(String flower) {
this.flower = flower;
}
public String getPublish() {
return publish;
}
public void setPublish(String publish) {
this.publish = publish;
}
public String getAuthentication() {
return authentication;
}
public void setAuthentication(String authentication) {
this.authentication = authentication;
}
@Override
public String toString() {
return "Weibo [idTitle=" + idTitle + ", sex=" + sex + ", place=" + place + ", mainUrl=" + mainUrl + ", uid="
+ uid + ", brief_introduction=" + brief_introduction + ", achievement=" + achievement + ", fans=" + fans
+ ", flower=" + flower + ", publish=" + publish + ", label=" + label + ", teach=" + teach
+ ", authentication=" + authentication + ", job=" + job + "]";
}
}
package com.zw.entity;
public class Weixin {
private String source;
private String url;
private String getUrl;
private String title;
private String time;
private String conetent;
private String keyValue;
//微博
private String read;
private String zan;
private String nickname;
private String jianjie;
private String history;
private String longUrl;
private String mark;
private String mark_time;
private String markname;
private String trueRead;
public String getRead() {
return read;
}
public void setRead(String read) {
this.read = read;
}
public String getZan() {
return zan;
}
public void setZan(String zan) {
this.zan = zan;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getJianjie() {
return jianjie;
}
public void setJianjie(String jianjie) {
this.jianjie = jianjie;
}
public String getHistory() {
return history;
}
public void setHistory(String history) {
this.history = history;
}
public String getLongUrl() {
return longUrl;
}
public void setLongUrl(String longUrl) {
this.longUrl = longUrl;
}
public String getMark() {
return mark;
}
public void setMark(String mark) {
this.mark = mark;
}
public String getMark_time() {
return mark_time;
}
public void setMark_time(String mark_time) {
this.mark_time = mark_time;
}
public String getMarkname() {
return markname;
}
public void setMarkname(String markname) {
this.markname = markname;
}
public String getTrueRead() {
return trueRead;
}
public void setTrueRead(String trueRead) {
this.trueRead = trueRead;
}
public String getKeyValue() {
return keyValue;
}
public void setKeyValue(String keyValue) {
this.keyValue = keyValue;
}
public String getConetent() {
return conetent;
}
public void setConetent(String conetent) {
this.conetent = conetent;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getGetUrl() {
return getUrl;
}
public void setGetUrl(String getUrl) {
this.getUrl = getUrl;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
@Override
public String toString() {
return "Weixin [source=" + source + ", url=" + url + ", getUrl=" + getUrl + ", title=" + title + ", time="
+ time + ", conetent=" + conetent + ", keyValue=" + keyValue + ", read=" + read + ", zan=" + zan
+ ", nickname=" + nickname + ", jianjie=" + jianjie + ", history=" + history + ", longUrl=" + longUrl
+ ", mark=" + mark + ", mark_time=" + mark_time + ", markname=" + markname + ", trueRead=" + trueRead
+ "]";
}
}
package sendmail;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.annotation.Resource;
import javax.mail.BodyPart;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 閭欢鍙戯拷?锟藉伐鍏风被
*
* @author shenjinzhu
*/
public class SendMailUtil {
private final static Log log=LogFactory.getLog(SendMailUtil.class);
// 发送邮件的邮箱号(若有授权码则密码输入授权码)
public static String myEmailAccount = "ccxe4zhishu@126.com";
public static String myEmailPassword = "1q2w3e4r5t";
// public static String myEmailAccount = "ccxerisk@sina.com";
// public static String myEmailPassword = "1q2w3e4r";
// 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
// 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
public static String myEmailSMTPHost = "smtp.126.com";
/**
*
* @param mail
* 接收者的邮箱号
* @param url
* 本地的附件地址
*/
public static void sendMessage(String mail, String url,String str) {
log.info(mail+","+url+","+str);
// 创建参数配置, 用于连接邮件服务器的参数配置
Properties props = new Properties();
// 使用的协议(JavaMail规范要求)
props.setProperty("mail.transport.protocol", "smtp");
// 发件人的邮箱的 SMTP 服务器地址
props.setProperty("mail.smtp.host", myEmailSMTPHost);
// 需要请求认证
props.setProperty("mail.smtp.auth", "true");
final String smtpPort = "465";
props.setProperty("mail.smtp.port", smtpPort);
props.setProperty("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.socketFactory.port", smtpPort);
// PopupAuthenticator popAuthenticator=new PopupAuthenticator();
// PasswordAuthentication pop = popAuthenticator.performCheck("wanghongshuai@ccxe.com.cn","tt67z890zh");
// Session mysession = Session.getInstance(props, popAuthenticator);
//
// PS: 某些邮箱服务器要求 SMTP 连接需要使用 SSL 安全认证 (为了提高安全性, 邮箱支持SSL连接, 也可以自己开启),
// 如果无法连接邮件服务器, 仔细查看控制台打印的 log, 如果有有类似 “连接失败, 要求 SSL 安全连接” 等错误,
/*
* // SMTP 服务器的端口 (非 SSL 连接的端口一般默认为 25, 可以不添加, 如果开启了 SSL 连接, //
* 需要改为对应邮箱的 SMTP 服务器的端口, 具体可查看对应邮箱服务的帮助, // QQ邮箱的SMTP(SLL)端口为465或587,
* 其他邮箱自行去查看) final String smtpPort = "465";
* props.setProperty("mail.smtp.port", smtpPort);
* props.setProperty("mail.smtp.socketFactory.class",
* "javax.net.ssl.SSLSocketFactory");
* props.setProperty("mail.smtp.socketFactory.fallback", "false");
* props.setProperty("mail.smtp.socketFactory.port", smtpPort);
*/
// 根据配置创建会话对象, 用于和邮件服务器交互
Session session = Session.getDefaultInstance(props);
session.setDebug(false); // 设置为debug模式, 可以查看详细的发送 log
// 创建邮件
MimeMessage message;
try {
message = createMimeMessage(session, myEmailAccount, mail, url,str);
// 根据 Session 获取邮件传输对象
Transport transport = session.getTransport();
/*
* 使用 邮箱账号 和 密码 连接邮件服务器, 这里认证的邮箱必须与 message 中的发件人邮箱一致, 否则报错 PS_02:
* 连接失败的原因通常为以下几点, 仔细检查代码: (1) 邮箱没有开启 SMTP 服务; (2) 邮箱密码错误,
* 例如某些邮箱开启了独立密码; (3) 邮箱服务器要求必须要使用 SSL 安全连接; (4) 请求过于频繁或其他原因,
* 被邮件服务器拒绝服务; (5) 如果以上几点都确定无误, 到邮件服务器网站查找帮助。
*/
transport.connect(myEmailAccount, myEmailPassword);
// 发送邮件
transport.sendMessage(message, message.getAllRecipients());
// 关闭连接
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 创建一封只包含文本的简单邮件
*
* @param session
* 和服务器交互的会话
* @param sendMail
* 发件人邮箱
* @param receiveMail
* 收件人邮箱
* @param url
* 本地文件地址
* @return
* @throws Exception
*/
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String url,String strtitle)
throws Exception {
// 创建邮件
MimeMessage message = new MimeMessage(session);
SimpleDateFormat sfm = new SimpleDateFormat("yyyyMMdd");
String str = sfm.format(new Date());
// From: 发件人
message.setFrom(new InternetAddress(sendMail, "有新短消息:连接转完了", "UTF-8"));
// To: 收件人(可以增加多个收件人、抄送、密送)
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "UTF-8"));
// Subject: 邮件主题
message.setSubject(str + "数据结果", "UTF-8");
/*
* Content: 邮件正文(可以使用html标签) message.setContent(
* "XX用户你好, 今天全场5折, 快来抢购, 错过今天再等一年。。。", "text/html;charset=UTF-8");
*/
// 创建消息部分
BodyPart messageBodyPart = new MimeBodyPart();
String content = "你好";
// content=new MailContent().getHtml();
// 正文消息消息
messageBodyPart.setContent(content,"text/html; charset=utf-8");
// 创建多重消息
Multipart multipart = new MimeMultipart();
// 设置文本消息部分
multipart.addBodyPart(messageBodyPart);
// 附件部分
messageBodyPart = new MimeBodyPart();
// 文件本地地址
String filename = url;
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
String hourstr = "";
if (new Date().getHours() <= 10) {
hourstr = "09";
} else if(new Date().getHours()<=13){
hourstr = "12";
} else{
hourstr = "16";
}
// 年月日时
messageBodyPart.setFileName(sfm.format(new Date()) + hourstr + ".xls");
multipart.addBodyPart(messageBodyPart);
// 发送完整消息
message.setContent(multipart);
// 设置发件时间
message.setSentDate(new Date());
// 保存设置
message.saveChanges();
return message;
}
public static void main(String[] args) {
SendMailUtil.sendMessage("shenjinzhu999@163.com", "C:/Users/Administrator/Desktop/zhishu.xls","ccxe");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
">
<context:property-placeholder ignore-unresolvable="true" location="classpath:datasource.properties" />
</beans>
\ No newline at end of file
basefile=/home/nbzhiwei/upload/new.xls
#basefile=C:/Users/Administrator/Desktop/news222.xls
timefileUrl=/home/nbzhiwei/upload
#timefileUrl=C:/Users/Administrator/Desktop
host=106.14.249.240
port=26807
password=1q2w3e4r
user=zhiweidata
dbName=spyPlat
socketIp=192.168.0.243
socketPort=10201
\ No newline at end of file
log4j.rootLogger=debug,LOG,ERROR
#log4j.logger.com.zhiwei.step.core.MsgSender=debug,RECORD
#LOG(All log)
log4j.appender.LOG=org.apache.log4j.ConsoleAppender
log4j.appender.LOG.Threshold=info
log4j.appender.LOG.Target=System.out
log4j.appender.LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.LOG.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %m%n
#ERROR
log4j.appender.ERROR=org.apache.log4j.RollingFileAppender
log4j.appender.ERROR.Threshold=error
log4j.appender.ERROR.File=${catalina.home}/log/error.log
log4j.appender.ERROR.MaxFileSize=10MB
log4j.appender.ERROR.MaxBackupIndex=10
log4j.appender.ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.ERROR.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} [%t] [%c] [%p] - %m%n
#RECORD
log4j.appender.RECORD=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RECORD.File=${catalina.home}/log/msg_record.log
log4j.appender.RECORD.layout=org.apache.log4j.PatternLayout
log4j.appender.RECORD.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %m%n
\ No newline at end of file
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
rootLogger.level = info
rootLogger.appenderRef.console.ref = console
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="D:/ZhiWei/change4weixin/target/classes">
</dir>
</classpath>
<web>
<link target="/">
<dir name="D:/ZhiWei/change4weixin/src/main/webapp">
</dir>
</link>
</web>
</application>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
">
<context:annotation-config />
<context:component-scan base-package="com.zhiwei.servlet" />
<mvc:default-servlet-handler />
<mvc:annotation-driven />
<!-- ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/" />
<property name="suffix" value=".html" />
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600"/>
<property name="maxInMemorySize" value="4096"/>
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>change4weixin</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>java</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:servletContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>java</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
!function() {
function o(w, v, i) {
return w.getAttribute(v) || i
}
function j(i) {
return document.getElementsByTagName(i)
}
function l() {
var i = j("script")
, w = i.length
, v = i[w - 1];
return {
l: w,
z: o(v, "zIndex", 1),
o: o(v, "opacity", 1),
c: o(v, "color", "255,255,153"),
n: o(v, "count", 190)
}
}
function k() {
r = u.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
n = u.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
pp.height = n
pp.width = r
if ($(window).width() <= 1280) {
$('#sidebar').addClass('mobile');
e.clearRect(0, 0, r, n);
t = []
} else {
$('#sidebar').removeClass('mobile');
}
}
function b() {
e.clearRect(0, 0, r, n);
var w = [f].concat(t);
var x, v, A, B, z, y;
t.forEach(function(i) {
i.x += i.xa,
i.y += i.ya,
i.xa *= i.x > r || i.x < 0 ? -1 : 1,
i.ya *= i.y > n || i.y < 0 ? -1 : 1,
e.fillRect(i.x - 0.5, i.y - 0.5, 1, 1);
for (v = 0; v < w.length; v++) {
x = w[v];
if (i !== x && null !== x.x && null !== x.y) {
B = i.x - x.x,
z = i.y - x.y,
y = B * B + z * z;
// if (y < x.max) {
// if (x === f && y >= x.max / 2) {
// i.x -= 0.03 * B,
// i.y -= 0.03 * z
// }
// A = (x.max - y) / x.max,
// e.beginPath(),
// e.lineWidth = A / 2,
// e.strokeStyle = "rgba(" + s.c + "," + (A + 0.2) + ")",
// e.moveTo(i.x, i.y),
// e.lineTo(x.x, x.y),
// e.stroke()
// }
y < x.max && (x === f && y >= x.max / 2 && (i.x -= 0.03 * B,
i.y -= 0.03* z),
A = (x.max - y) / x.max,
e.beginPath(),
e.lineWidth = A / 2,
e.strokeStyle = "rgba(" + s.c + "," + (A + 0.2) + ")",
e.moveTo(i.x, i.y),
e.lineTo(x.x, x.y),
e.stroke())
}
}
w.splice(w.indexOf(i), 1)
}),
m(b)
}
var pp = document.getElementById('c_n149')
var u = document.createElement("canvas"), s = l(), c = "c_n" + s.l, e = u.getContext("2d"), r, n, m = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(i) {
window.setTimeout(i, 1000 / 45)
}
, a = Math.random, f = {
x: null,
y: null,
max: 20000
};
u.id = c;
u.style.cssText = "position:fixed;top:0;left:0;z-index:" + s.z + ";opacity:" + s.o;
j("body")[0].appendChild(u);
k(),
window.onresize = k;
window.onmousemove = function(i) {
i = i || window.event,
f.x = i.clientX,
f.y = i.clientY
}
,
window.onmouseout = function() {
f.x = null,
f.y = null
}
;
for (var t = [], p = 0; s.n > p; p++) {
var h = a() * r
, g = a() * n
, q = 2 * a() - 1
, d = 2 * a() - 1;
t.push({
x: h,
y: g,
xa: q,
ya: d,
max: 6000
})
}
setTimeout(function() {
b()
}, 100)
}();
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Table</title>
<link rel="stylesheet"
href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script
src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
body {
background-image: url("./2.jpg");
}
#timeCanvas {
position: absolute;
top: 3%;
right: 3%;
height: 30px;
width: 210px;
}
.table {
position: absolute;
left: 15%;
top: 7%;
width: 70%;
z-index: 100;
}
.table tr {
background-color: transparent !important;
}
.table tr td {
border-color: #000 !important;
}
h5 {
position: relative;
z-index: 2000;
}
</style>
</head>
<body>
<h5>如需下载,请至<a href="/change4weixin/down" target="_blank">下载页</a></h5>
<canvas id="timeCanvas"></canvas>
<canvas id="c_n149" width="1920" height="1080"
style="position: fixed; top: 0px; right: 0px;z-index: -1;"></canvas>
<script src="./time.js"></script>
<script src="./canvas.js"></script>
<h5>如需插队运行,请联系------陈栋(674945328)/沈金柱(949131080)</h5>
<table class="table table-striped">
<thead>
<tr>
<td>编号</td>
<td>提交者</td>
<td>运行需要时间(分)</td>
<td>开始时间</td>
<td>状态</td>
<td>当前剩余的条数</td>
</tr>
</thead>
<tbody class="data"></tbody>
</table>
<script>
$(function () {
var tbody = $('.data')
var d = []
function getData() {
$(tbody).empty();
d = []
$.ajax({
type: 'get',
datatype: 'json',
url: '/change4weixin/show ',
success: function (data) {
data = JSON.parse(data)
d = data
data.forEach((e, index) => {
let tr = `<tr class="TR">
<td class="id">${e.site}</td>
<td>${e.mail}</td>
<td>${e.surplusCount/12}</td>
<td>${e.startDate}</td>
<td>${e.state}</td>
<td>${e.surplusCount}</td>
</tr>`
tbody.append(tr)
})
}
})
}
getData()
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Table</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
body {
background-image: url("./2.jpg");
}
#timeCanvas {
position: absolute;
top: 3%;
right: 3%;
height: 30px;
width: 210px;
}
.table {
position: absolute;
left: 15%;
top: 7%;
width: 70%;
z-index: 100;
}
.table tr {
background-color: transparent !important;
}
.table tr td {
border-color: #000 !important;
}
</style>
</head>
<body>
<table class="table table-striped">
<thead>
<tr>
<td>id</td>
<td>编号</td>
<td>提交者</td>
<td>运行需要时间</td>
<td>开始时间</td>
<td>状态</td>
<td>当前剩余的条数</td>
<td>操作</td>
</tr>
</thead>
<tbody class="data"></tbody>
</table>
<canvas id="timeCanvas"></canvas>
<canvas id="c_n149" width="1920" height="1080" style="position: fixed; top: 0px; right: 0px;"></canvas>
<script src="./time.js"></script>
<script src="./canvas.js"></script>
<script>
$(function () {
var tbody = $('.data')
var d = []
function getData() {
$(tbody).empty();
d = []
$.ajax({
type: 'get',
datatype: 'json',
url: '/change4weixin/show ',
success: function (data) {
data = JSON.parse(data)
d = data
data.forEach((e, index) => {
let tr = `<tr class="TR">
<td class="id">${e.id}</td>
<td>${e.site}</td>
<td>${e.mail}</td>
<td>${e.surplusCount/12}</td>
<td>${e.startDate}</td>
<td>${e.state}</td>
<td>${e.surplusCount}</td>
<td>
<button class="btn btn-info del">删除</button>
<button class="btn btn-success insert">插队</button>
</td>
</tr>`
tbody.append(tr)
})
}
})
}
$('.table').delegate(".del","click",function(){
let id = $(this).parents('.TR').children('.id').eq(0).text()
$.ajax({
type: 'get',
datatype: 'json',
data: {
id: id
},
url: '/change4weixin/delete',
success: function (data) {
data = JSON.parse(data)
if (data.result) {
alert('删除成功')
getData()
} else {
alert('删除失败')
}
}
})
})
$('.table').delegate(".insert","click",function(){
let id = $(this).parents('.TR').children('.id').eq(0).text()
if (id === d[0].id) {
alert('第一个不能插队')
return false
}
$.ajax({
type: 'get',
datatype: 'text',
data: {
id: id
},
url: '/change4weixin/cutQ',
success: function (data) {
data = JSON.parse(data)
if (data.result) {
alert('插队成功')
getData()
} else {
alert('插队失败')
}
}
})
})
getData()
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Table</title>
<link rel="stylesheet"
href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script
src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
body {
background-image: url("./2.jpg");
}
#timeCanvas {
position: absolute;
top: 3%;
right: 3%;
height: 30px;
width: 210px;
}
.table {
position: absolute;
left: 15%;
top: 7%;
width: 70%;
z-index: 100;
}
.table tr {
background-color: transparent !important;
}
.table tr td {
border-color: #000 !important;
}
</style>
</head>
<body>
<canvas id="timeCanvas"></canvas>
<canvas id="c_n149" width="1920" height="1080"
style="position: fixed; top: 0px; right: 0px;"></canvas>
<script src="./time.js"></script>
<script src="./canvas.js"></script>
<h5>如需插队运行,请联系------陈栋(674945328)/沈金柱(949131080)</h5>
<table class="table table-striped">
<thead>
<tr>
<td>编号</td>
<td>邮箱</td>
<td>日期</td>
<td>状态</td>
</tr>
</thead>
<tbody class="data"></tbody>
</table>
<script>
$(function () {
var tbody = $('.data')
var d = []
function getData() {
$(tbody).empty();
d = []
$.ajax({
type: 'get',
datatype: 'json',
url: '/change4weixin/downLode',
success: function (data) {
data = JSON.parse(data)
d = data
data.forEach((e, index) => {
let tr = `<tr class="TR">
<td>${e.id}</td>
<td>${e.mail}</td>
<td>${e.date}</td>
<td><a href='/change4weixin/downLodeFile?id=${e.id}'>下载</a></td>
</tr>`
tbody.append(tr)
})
}
})
}
getData()
})
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h3>邮箱号输入有误</h3>
<form action="/change4weixin/return" method="post">
<input type="submit" value="返回">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h2>文件格式有问题,请确认有地址一栏</h2>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h2>文件类型错误</h2>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link rel="stylesheet"
href="https://cdn.bootcss.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"
integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb"
crossorigin="anonymous">
<script
src="https://cdn.bootcss.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"
integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ"
crossorigin="anonymous"></script>
<script src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
$(function() {
getTime();
setInterval("getTime()", 10 * 1000);
});
function getTime() {
var time = $('#time').empty();
$.ajax({
url : '/change4weixin/show',
success : function(result) {
var list = JSON.parse(result);
if (list.length > 0) {
console.log(list);
console.log(list.length);
var t = 0;
var tab = $('#tab')
tab.empty();
var head = '<thead><tr>'
+'<th>编号</th>'
+ '<th>提交者</th>'
+ '<th>运行需要时间</th>'
+ '<th>开始时间</th>'
+ '<th>当前剩余转的条数</th>'
+ '<th>操作</th>'
+ '</tr>'
+ '</thead>';
tab.append(head);
var tbody = $('tbody');
for (var i = 0; i < list.length; i++) {
var addem = '<tr class="success">'
+ '<td>'+list[i].site+'</td>'
+ '<td>'+list[i].mail+'</td>'
+ '<td>'+list[i].need+'</td>'
+ '<td>'+list[i].startDate+'</td>'
+ '<td>'+list[i].surplusCount+'</td>'
+ '<td>删除,插队</td>'
+ '</tr>';
tbody.append(addem);
}
tab.append(tbody);
} else {
var time = $('#time').empty();
var addem = '暂无运行的文件';
time.append(addem);
}
}
});
}
</script>
</head>
<body>
<div>
<span>有时候显示有点问题,耐心等待</span>
</div>
<div id="time"></div>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table" id="tab">
<thead>
<tr>
<th>编号</th>
<th>提交者</th>
<th>运行需要时间</th>
<th>开始时间</th>
<th>当前剩余转的条数</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>TB - Monthly</td>
<td>01/04/2012</td>
<td>Default</td>
</tr>
<tr class="success">
<td>1</td>
<td>TB - Monthly</td>
<td>01/04/2012</td>
<td>Approved</td>
</tr>
<tr class="error">
<td>2</td>
<td>TB - Monthly</td>
<td>02/04/2012</td>
<td>Declined</td>
</tr>
<tr class="warning">
<td>3</td>
<td>TB - Monthly</td>
<td>03/04/2012</td>
<td>Pending</td>
</tr>
<tr class="info">
<td>4</td>
<td>TB - Monthly</td>
<td>04/04/2012</td>
<td>Call in to confirm</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style type="text/css">
body {
background-image: url("./2.jpg");
}
form {
width: 20%;
margin: 200px auto;
}
.form-group {
margin-top: 20px;
}
#submit:hover {
color: #66afe9;
}
</style>
</head>
<body>
<h5>如需插队,请联系陈栋(674945328)/沈金柱(949131080)</h5>
<form action="/change4weixin/up" enctype="multipart/form-data" method="post">
<span>文件</span>
<input type="file" name="file"/>
<div class="form-group">
<label for="email">邮箱号</label>
<input type="text" name="mail" class="form-control" id="email">
</div>
<div class="form-group">
<label for="emailAgain">重复邮箱号</label>
<input type="text" name="mail2" class="form-control" id="emailAgain">
</div>
<div class="form-group">
<input type="submit" value="提交" class="form-control" id="submit" />
</div>
</form>
</body>
</html>
\ No newline at end of file
(function(){
var digit=
[
[
[0,0,1,1,1,0,0],
[0,1,1,0,1,1,0],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[0,1,1,0,1,1,0],
[0,0,1,1,1,0,0]
],//0
[
[0,0,0,1,1,0,0],
[0,1,1,1,1,0,0],
[0,0,0,1,1,0,0],
[0,0,0,1,1,0,0],
[0,0,0,1,1,0,0],
[0,0,0,1,1,0,0],
[0,0,0,1,1,0,0],
[0,0,0,1,1,0,0],
[0,0,0,1,1,0,0],
[1,1,1,1,1,1,1]
],//1
[
[0,1,1,1,1,1,0],
[1,1,0,0,0,1,1],
[0,0,0,0,0,1,1],
[0,0,0,0,1,1,0],
[0,0,0,1,1,0,0],
[0,0,1,1,0,0,0],
[0,1,1,0,0,0,0],
[1,1,0,0,0,0,0],
[1,1,0,0,0,1,1],
[1,1,1,1,1,1,1]
],//2
[
[1,1,1,1,1,1,1],
[0,0,0,0,0,1,1],
[0,0,0,0,1,1,0],
[0,0,0,1,1,0,0],
[0,0,1,1,1,0,0],
[0,0,0,0,1,1,0],
[0,0,0,0,0,1,1],
[0,0,0,0,0,1,1],
[1,1,0,0,0,1,1],
[0,1,1,1,1,1,0]
],//3
[
[0,0,0,0,1,1,0],
[0,0,0,1,1,1,0],
[0,0,1,1,1,1,0],
[0,1,1,0,1,1,0],
[1,1,0,0,1,1,0],
[1,1,1,1,1,1,1],
[0,0,0,0,1,1,0],
[0,0,0,0,1,1,0],
[0,0,0,0,1,1,0],
[0,0,0,1,1,1,1]
],//4
[
[1,1,1,1,1,1,1],
[1,1,0,0,0,0,0],
[1,1,0,0,0,0,0],
[1,1,1,1,1,1,0],
[0,0,0,0,0,1,1],
[0,0,0,0,0,1,1],
[0,0,0,0,0,1,1],
[0,0,0,0,0,1,1],
[1,1,0,0,0,1,1],
[0,1,1,1,1,1,0]
],//5
[
[0,0,0,0,1,1,0],
[0,0,1,1,0,0,0],
[0,1,1,0,0,0,0],
[1,1,0,0,0,0,0],
[1,1,0,1,1,1,0],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[0,1,1,1,1,1,0]
],//6
[
[1,1,1,1,1,1,1],
[1,1,0,0,0,1,1],
[0,0,0,0,1,1,0],
[0,0,0,0,1,1,0],
[0,0,0,1,1,0,0],
[0,0,0,1,1,0,0],
[0,0,1,1,0,0,0],
[0,0,1,1,0,0,0],
[0,0,1,1,0,0,0],
[0,0,1,1,0,0,0]
],//7
[
[0,1,1,1,1,1,0],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[0,1,1,1,1,1,0],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[0,1,1,1,1,1,0]
],//8
[
[0,1,1,1,1,1,0],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[1,1,0,0,0,1,1],
[0,1,1,1,0,1,1],
[0,0,0,0,0,1,1],
[0,0,0,0,0,1,1],
[0,0,0,0,1,1,0],
[0,0,0,1,1,0,0],
[0,1,1,0,0,0,0]
],//9
[
[0,0,0,0,0,0,0],
[0,0,1,1,1,0,0],
[0,0,1,1,1,0,0],
[0,0,1,1,1,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,1,1,1,0,0],
[0,0,1,1,1,0,0],
[0,0,1,1,1,0,0],
[0,0,0,0,0,0,0]
]//:
];
var canvas = document.getElementById('timeCanvas');
if(canvas.getContext){
var cxt = canvas.getContext('2d');
//声明canvas的宽高
var H = 100,W = 700;
canvas.height = H;
canvas.width = W;
cxt.fillStyle = '#f00';
cxt.fillRect(10,10,50,50);
//存储时间数据
var data = [];
//存储运动的小球
var balls = [];
//设置粒子半径
var R = canvas.height/20-1;
(function(){
var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
//存储时间数字,由十位小时、个位小时、冒号、十位分钟、个位分钟、冒号、十位秒钟、个位秒钟这7个数字组成
data.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
})();
/*生成点阵数字*/
function renderDigit(index,num){
for(var i = 0; i < digit[num].length; i++){
for(var j = 0; j < digit[num][i].length; j++){
if(digit[num][i][j] == 1){
cxt.beginPath();
cxt.arc(14*(R+2)*index + j*2*(R+1)+(R+1),i*2*(R+1)+(R+1),R,0,2*Math.PI);
cxt.closePath();
cxt.fill();
}
}
}
}
/*更新时钟*/
function updateDigitTime(){
var changeNumArray = [];
var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
var NewData = [];
NewData.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
for(var i = data.length-1; i >=0 ; i--){
//时间发生变化
if(NewData[i] !== data[i]){
//将变化的数字值和在data数组中的索引存储在changeNumArray数组中
changeNumArray.push(i+'_'+(Number(data[i])+1)%10);
}
}
//增加小球
for(var i = 0; i< changeNumArray.length; i++){
addBalls.apply(this,changeNumArray[i].split('_'));
}
data = NewData.concat();
}
/*更新小球状态*/
function updateBalls(){
for(var i = 0; i < balls.length; i++){
balls[i].stepY += balls[i].disY;
balls[i].x += balls[i].stepX;
balls[i].y += balls[i].stepY;
if(balls[i].x > W + R || balls[i].y > H + R){
balls.splice(i,1);
i--;
}
}
}
/*增加要运动的小球*/
function addBalls(index,num){
var numArray = [1,2,3];
var colorArray = ["#3BE","#09C","#A6C","#93C","#9C0","#690","#FB3","#F80","#F44","#C00"];
for(var i = 0; i < digit[num].length; i++){
for(var j = 0; j < digit[num][i].length; j++){
if(digit[num][i][j] == 1){
var ball = {
x:14*(R+2)*index + j*2*(R+1)+(R+1),
y:i*2*(R+1)+(R+1),
stepX:0.4*Math.floor(Math.random() * 4 -2),
stepY:-0.5*numArray[Math.floor(Math.random()*numArray.length)],
color:colorArray[Math.floor(Math.random()*colorArray.length)],
disY:0.2
};
balls.push(ball);
}
}
}
}
/*渲染*/
function render(){
//重置画布宽度,达到清空画布的效果
canvas.height = 100;
//渲染时钟
for(var i = 0; i < data.length; i++){
renderDigit(i,data[i]);
}
//渲染小球
for(var i = 0; i < balls.length; i++){
cxt.beginPath();
cxt.arc(balls[i].x,balls[i].y,R,0,2*Math.PI);
cxt.fillStyle = balls[i].color;
cxt.closePath();
cxt.fill();
}
}
function update () {
//更新时钟
updateDigitTime();
//更新小球状态
updateBalls();
//渲染
render();
m(update)
}
var m = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(i) {
window.setTimeout(i, 1000 / 45)
}
setTimeout(function() {
update()
}, 100)
// clearInterval(oTimer);
// var oTimer = setInterval(function(){
// //更新时钟
// updateDigitTime();
// //更新小球状态
// updateBalls();
// //渲染
// render();
// }, 50);
}
})();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment