Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
change4weixin
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenjinzhu
change4weixin
Commits
38c6dcd6
Commit
38c6dcd6
authored
May 04, 2018
by
admin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信微博数据匹配添加
parent
4419d1f6
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
212 deletions
+67
-212
src/main/java/com/zhiwei/finance/ESUtil.java
+4
-1
src/main/java/com/zhiwei/finance/PushFinanceByTime.java
+2
-2
src/main/java/com/zhiwei/servlet/FianceController.java
+44
-0
src/main/java/com/zhiwei/util/ESUtil.java
+0
-176
src/main/java/com/zhiwei/util/ExcelUtil.java
+1
-31
src/main/java/sendmail/SendMailUtil.java
+2
-2
src/main/resources/pushFiles/wechat.xls
+0
-0
src/main/resources/pushFiles/weibo.xls
+0
-0
src/main/webapp/upExcelWithFinance.html
+14
-0
No files found.
src/main/java/com/zhiwei/finance/ESUtil.java
View file @
38c6dcd6
...
...
@@ -102,7 +102,7 @@ public class ESUtil {
// }
sources
=
new
ReadExcel
().
getExcel
(
path
);
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
10
);
cal
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
3
);
List
<
NewsResult
>
list
=
new
ESUtil
().
pushByKey
(
cal
.
getTime
(),
new
Date
(),
sources
,
"weibo"
);
System
.
out
.
println
(
list
.
size
());
}
...
...
@@ -172,6 +172,9 @@ public class ESUtil {
SimpleDateFormat
myFmt
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
url
=
hit
.
getSource
().
get
(
"url"
)
!=
null
?
String
.
valueOf
(
hit
.
getSource
().
get
(
"url"
))
:
String
.
valueOf
(
hit
.
getId
());
if
(!
url
.
contains
(
"http"
))
{
url
=
String
.
valueOf
(
map
.
get
(
"id"
));
}
if
(
type
.
equals
(
"weibo"
))
{
n
.
setUrl
(
url
);
if
(
map
.
get
(
"roottext"
)
==
null
)
{
...
...
src/main/java/com/zhiwei/finance/PushFinanceByTime.java
View file @
38c6dcd6
...
...
@@ -76,8 +76,8 @@ public class PushFinanceByTime extends Thread {
cal
.
add
(
Calendar
.
HOUR_OF_DAY
,
16
);
sendsEmail
(
cal
,
list
,
wechat_
,
weibo_
,
url
);
sleep
(
1000
*
60
*
60
);
}
else
if
(
cal
.
get
(
Calendar
.
HOUR_OF_DAY
)
==
1
7
)
{
// 11
cal
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
10
);
}
else
if
(
cal
.
get
(
Calendar
.
HOUR_OF_DAY
)
==
1
1
)
{
// 11
cal
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
3
);
List
<
NewsResult
>
list
=
new
ESUtil
().
pushByKey
(
cal
.
getTime
(),
new
Date
(),
sources
,
"media"
);
List
<
NewsResult
>
wechat_
=
new
ESUtil
().
pushByKey
(
cal
.
getTime
(),
new
Date
(),
wechat
,
"wechat"
);
List
<
NewsResult
>
weibo_
=
new
ESUtil
().
pushByKey
(
cal
.
getTime
(),
new
Date
(),
weibo
,
"weibo"
);
...
...
src/main/java/com/zhiwei/servlet/FianceController.java
View file @
38c6dcd6
...
...
@@ -93,6 +93,50 @@ public class FianceController {
return
"showfinance"
;
}
@RequestMapping
(
value
=
"/upFinanceWechat"
)
public
String
upFinanceWechat
(
MultipartFile
file
)
{
String
fileName
=
file
.
getOriginalFilename
();
if
(
fileName
.
endsWith
(
".xls"
)
||
fileName
.
endsWith
(
".xlsx"
))
{
// 是否是excel结尾的
String
path
=
Config
.
getVal
(
"timefileUrl"
)
+
"/"
+
sdf
.
format
(
new
Date
())
+
fileName
;
log
.
info
(
path
);
String
beforeUrl
=
service
.
getPath
(
"wechat"
);
if
(!
StringUtil
.
isEmpty
(
beforeUrl
))
{
ExcelUtil
.
delete
(
beforeUrl
);
}
fileSave
(
file
,
path
);
ExcelsUrl
eUrl
=
new
ExcelsUrl
();
eUrl
.
setType
(
"微信来源"
);
eUrl
.
setName
(
"wechat"
);
eUrl
.
setUrl
(
path
);
service
.
insert
(
eUrl
);
}
else
{
return
"excelError"
;
}
return
"showfinance"
;
}
@RequestMapping
(
value
=
"/upFinanceWeibo"
)
public
String
upFinanceWeibo
(
MultipartFile
file
)
{
String
fileName
=
file
.
getOriginalFilename
();
if
(
fileName
.
endsWith
(
".xls"
)
||
fileName
.
endsWith
(
".xlsx"
))
{
// 是否是excel结尾的
String
path
=
Config
.
getVal
(
"timefileUrl"
)
+
"/"
+
sdf
.
format
(
new
Date
())
+
fileName
;
log
.
info
(
path
);
String
beforeUrl
=
service
.
getPath
(
"weibo"
);
if
(!
StringUtil
.
isEmpty
(
beforeUrl
))
{
ExcelUtil
.
delete
(
beforeUrl
);
}
fileSave
(
file
,
path
);
ExcelsUrl
eUrl
=
new
ExcelsUrl
();
eUrl
.
setType
(
"微博来源"
);
eUrl
.
setName
(
"weibo"
);
eUrl
.
setUrl
(
path
);
service
.
insert
(
eUrl
);
}
else
{
return
"excelError"
;
}
return
"showfinance"
;
}
@RequestMapping
(
value
=
"/upFinanceLess"
)
public
String
upFinanceLess
(
MultipartFile
file
)
{
String
fileName
=
file
.
getOriginalFilename
();
...
...
src/main/java/com/zhiwei/util/ESUtil.java
deleted
100644 → 0
View file @
4419d1f6
package
com
.
zhiwei
.
util
;
import
java.io.IOException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TimeZone
;
import
org.elasticsearch.action.search.SearchRequestBuilder
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.search.SearchType
;
import
org.elasticsearch.client.Client
;
import
org.elasticsearch.client.transport.TransportClient
;
import
org.elasticsearch.common.unit.TimeValue
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.SearchHits
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
weixin.popular.bean.menu.selfmenu.News
;
/**
* es工具类
*
* @author admin
*/
public
class
ESUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ESUtil
.
class
);
private
static
String
indexName
;
private
static
String
type
;
private
static
String
endWithTime
=
"T01:00:00.000Z"
;
static
{
indexName
=
Config
.
getVal
(
"indexName"
);
type
=
Config
.
getVal
(
"type"
);
}
/**
* 获取匹配时起始时间
*
* @param hour
* @return
*/
public
static
String
getTimeMin
(
int
hour
)
{
SimpleDateFormat
smf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
date1
=
new
Date
();
String
time
=
""
;
if
(
hour
==
9
)
{
date1
.
setDate
(
date1
.
getDate
()
-
1
);
time
=
smf
.
format
(
date1
)
+
"T08:00:00.000Z"
;
}
if
(
hour
==
12
)
{
time
=
smf
.
format
(
date1
)
+
"T01:00:00.000Z"
;
}
if
(
hour
==
16
)
{
time
=
smf
.
format
(
date1
)
+
"T04:00:00.000Z"
;
}
return
time
;
}
public
static
String
getWedTimeByCj
(
int
hour
)
{
SimpleDateFormat
smf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
date1
=
new
Date
();
String
time
=
""
;
date1
.
setDate
(
date1
.
getDate
()
-
1
);
time
=
smf
.
format
(
date1
)
+
"T08:00:00.000Z"
;
return
time
;
}
/**
* 获取匹配时终止时间
*
* @param hour
* @return
*/
public
static
String
getTimeMax
(
int
hour
)
{
SimpleDateFormat
smf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
date
=
new
Date
();
String
time
=
""
;
time
=
smf
.
format
(
date
)
+
"T0"
+
(
hour
-
8
)
+
":00:00.000Z"
;
return
time
;
}
// public List<NewsResult> getNewsForWechatWithMechanism(Date start,Date end){
// SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd日HH:mm:ss");
// Calendar startTime=Calendar.getInstance();
// startTime.setTime(start);
// startTime.add(Calendar.HOUR, -8);
// Calendar endTime=Calendar.getInstance();
// endTime.setTime(end);
// endTime.add(Calendar.HOUR, -8);
// List<Mechanism> list = new ReadExcel()
// .getInstitution(SendEmail.class.getClassLoader().getResource("files/jrjg.xls").getPath());
// List<NewsResult> mechanism = new ArrayList<NewsResult>();
// try {
// log.info("金融检索开始");
// Client esClient = ESClient.getInstance();
// List<String> snByNeedFull = excelUtil
// .getOrgName(ESUtil.class.getClassLoader().getResource("files/matchOrgName.xls").getPath());
// Map<String, String> maps = new HashMap<String, String>();
// for (String sn : snByNeedFull) {// 需要全称匹配的
// maps.put(sn, "yes");
// }
// for (Mechanism scan : list) {
// // 搜索数据
// SearchRequestBuilder srb = esClient.prepareSearch(indexName).setTypes(type);
// BoolQueryBuilder bb = new BoolQueryBuilder();
// if (maps.get(scan.getShortName()) != null) {
// if (scan.getFullName() == null) {
// continue;
// }
// } else {
// QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery("title", scan.getShortName());
// QueryBuilder matchQuery1 = QueryBuilders.matchPhraseQuery("content", scan.getShortName());
// bb.should(matchQuery);
// bb.should(matchQuery1);
// }
// if (scan.getFullName() != null) {
// QueryBuilder matchQuery2 = QueryBuilders.matchPhraseQuery("content", scan.getFullName());
// bb.should(matchQuery2);
// }
// srb.setQuery(bb);
// srb.setPostFilter(QueryBuilders.rangeQuery("time").gte(sdf.format(startTime.getTime()).replace("日", "T")+".000Z")
// .lte(sdf.format(endTime.getTime()).replace("日", "T")+".000Z"));
// srb.setSize(500);
// SearchResponse response = srb.execute().actionGet();
// SearchHits searchHits = response.getHits();
// for (SearchHit hit : searchHits.getHits()) {
// Map<String, Object> map = hit.getSource();
// NewsResult n = new NewsResult();
// n.setCode(scan.getCodeAndP());
// n.setShortName(scan.getShortName());
// String url = hit.getSource().get("url") != null ? String.valueOf(hit.getSource().get("url"))
// : String.valueOf(hit.getId());
// n.setUrl(url);
// n.setRsid(String.valueOf(map.get("rsid")));
// n.setTitle(String.valueOf(map.get("title")));
// n.setContent(String.valueOf(map.get("content")));
// SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// try {
// Calendar cal = getStringToCal(map.get("time").toString());
// Date date = new Date(cal.getTimeInMillis());
// n.setTime(myFmt.format(date));
// } catch (Exception e) {
// n.setTime("");
// }
// n.setPt(String.valueOf(map.get("pt")));
// n.setSource(String.valueOf(map.get("source")));
// n.setOrgChiName(scan.getFullName() == null ? "" : scan.getFullName());
// n.setType(scan.getType());
// mechanism.add(n);
// }
// }
// mechanism = getFmNews(mechanism);
// log.info("金融结束");
// } catch (Exception e) {
// log.error("es检索出错,错误信息【{}】", e);
// }
// return mechanism;
// }
}
src/main/java/com/zhiwei/util/ExcelUtil.java
View file @
38c6dcd6
...
...
@@ -97,33 +97,7 @@ public class ExcelUtil {
WritableCellFormat
urlFormat
=
new
WritableCellFormat
(
urlf
);
urlFormat
.
setVerticalAlignment
(
VerticalAlignment
.
CENTRE
);
int
seq
=
0
;
seq
=
0
;
sheet
.
mergeCells
(
0
,
seq
,
7
,
seq
+
2
);
l
=
new
Label
(
0
,
seq
,
"金融负面新闻数据"
,
MainTitle
);
sheet
.
addCell
(
l
);
// 上方3个单位合并
seq
+=
3
;
l
=
new
Label
(
0
,
seq
,
"时间"
);
sheet
.
addCell
(
l
);
l
=
new
Label
(
1
,
seq
,
sdf
.
format
(
time
));
sheet
.
addCell
(
l
);
sheet
.
mergeCells
(
2
,
seq
,
4
,
seq
);
l
=
new
Label
(
2
,
seq
,
""
);
sheet
.
addCell
(
l
);
sheet
.
mergeCells
(
5
,
seq
,
7
,
seq
);
l
=
new
Label
(
5
,
seq
,
"推送"
);
sheet
.
addCell
(
l
);
seq
+=
2
;
sheet
.
mergeCells
(
0
,
seq
,
7
,
seq
+
1
);
l
=
new
Label
(
0
,
seq
,
"概览"
,
mainTitle
);
sheet
.
addCell
(
l
);
seq
+=
3
;
seq
+=
3
;
sheet
.
mergeCells
(
0
,
seq
,
7
,
seq
+
1
);
l
=
new
Label
(
0
,
seq
,
""
,
mainTitle
);
sheet
.
addCell
(
l
);
seq
+=
2
;
seq
=
1
;
int
row
=
seq
++;
l
=
new
Label
(
0
,
row
,
"序号"
,
titleFormat
);
sheet
.
addCell
(
l
);
...
...
@@ -205,10 +179,6 @@ public class ExcelUtil {
int
seq
=
0
;
seq
=
0
;
seq
++;
sheet
.
mergeCells
(
0
,
seq
,
7
,
seq
+
1
);
l
=
new
Label
(
0
,
seq
,
""
,
mainTitle
);
sheet
.
addCell
(
l
);
seq
+=
2
;
int
row
=
seq
++;
l
=
new
Label
(
0
,
row
,
"序号"
,
titleFormat
);
sheet
.
addCell
(
l
);
...
...
src/main/java/sendmail/SendMailUtil.java
View file @
38c6dcd6
...
...
@@ -119,9 +119,9 @@ public class SendMailUtil {
MimeMessage
message
=
new
MimeMessage
(
session
);
SimpleDateFormat
sfm
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
String
str
=
sfm
.
format
(
new
Date
());
message
.
setFrom
(
new
InternetAddress
(
sendMail
,
"
金融信息
"
,
"UTF-8"
));
message
.
setFrom
(
new
InternetAddress
(
sendMail
,
"
匹配信息结束
"
,
"UTF-8"
));
message
.
setRecipient
(
MimeMessage
.
RecipientType
.
TO
,
new
InternetAddress
(
receiveMail
,
"UTF-8"
));
message
.
setSubject
(
str
+
"
整点推送
"
,
"UTF-8"
);
message
.
setSubject
(
str
+
"
数据结果
"
,
"UTF-8"
);
BodyPart
messageBodyPart
=
new
MimeBodyPart
();
String
content
=
""
;
messageBodyPart
.
setContent
(
content
,
"text/html; charset=utf-8"
);
...
...
src/main/resources/pushFiles/wechat.xls
0 → 100644
View file @
38c6dcd6
File added
src/main/resources/pushFiles/weibo.xls
0 → 100644
View file @
38c6dcd6
File added
src/main/webapp/upExcelWithFinance.html
View file @
38c6dcd6
...
...
@@ -88,5 +88,19 @@ form {
<input
type=
"submit"
value=
"提交"
class=
"form-control"
id=
"submit"
/>
</div>
</form>
<form
action=
"/change4weixin/finance/upFinanceWechat"
enctype=
"multipart/form-data"
method=
"post"
>
<span>
微信来源
</span>
<input
type=
"file"
name=
"file"
/>
<div
class=
"form-group"
>
<input
type=
"submit"
value=
"提交"
class=
"form-control"
id=
"submit"
/>
</div>
</form>
<form
action=
"/change4weixin/finance/upFinanceWeibo"
enctype=
"multipart/form-data"
method=
"post"
>
<span>
微博来源
</span>
<input
type=
"file"
name=
"file"
/>
<div
class=
"form-group"
>
<input
type=
"submit"
value=
"提交"
class=
"form-control"
id=
"submit"
/>
</div>
</form>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment