Commit 4419d1f6 by admin

添加微博和微信推送信息

parent 97845ba8
...@@ -9,6 +9,8 @@ import java.util.List; ...@@ -9,6 +9,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import javax.print.Doc;
import org.bson.Document; import org.bson.Document;
import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
...@@ -27,6 +29,7 @@ import com.zhiwei.util.MongoConnection; ...@@ -27,6 +29,7 @@ import com.zhiwei.util.MongoConnection;
import com.zhiwei.util.ReadExcel; import com.zhiwei.util.ReadExcel;
import com.zw.entity.NewsResult; import com.zw.entity.NewsResult;
import weixin.popular.bean.menu.selfmenu.News;
/** /**
* es工具类 * es工具类
...@@ -36,14 +39,7 @@ import com.zw.entity.NewsResult; ...@@ -36,14 +39,7 @@ import com.zw.entity.NewsResult;
@Component @Component
public class ESUtil { public class ESUtil {
private static final Logger log = LoggerFactory.getLogger(ESUtil.class); private static final Logger log = LoggerFactory.getLogger(ESUtil.class);
private static String indexName; private static MongoConnection con = new MongoConnection();
private static String type;
private static MongoConnection con=new MongoConnection();
static {
indexName = Config.getVal("indexName");
type = Config.getVal("type");
}
/** /**
* 获取匹配时终止时间 * 获取匹配时终止时间
...@@ -58,7 +54,7 @@ public class ESUtil { ...@@ -58,7 +54,7 @@ public class ESUtil {
time = smf.format(date) + "T0" + (hour - 8) + ":00:00.000Z"; time = smf.format(date) + "T0" + (hour - 8) + ":00:00.000Z";
return time; return time;
} }
/** /**
* 格林尼治时间转换成标准时间 * 格林尼治时间转换成标准时间
* *
...@@ -80,25 +76,35 @@ public class ESUtil { ...@@ -80,25 +76,35 @@ public class ESUtil {
return result; return result;
} }
public static void main(String[] args) { public static void main(String[] args) {
// Calendar cal = Calendar.getInstance(); // Calendar cal = Calendar.getInstance();
// cal.add(Calendar.HOUR_OF_DAY, -20); // cal.add(Calendar.HOUR_OF_DAY, -20);
// Calendar cal2 = Calendar.getInstance(); // Calendar cal2 = Calendar.getInstance();
// cal2.add(Calendar.HOUR_OF_DAY, -4); // cal2.add(Calendar.HOUR_OF_DAY, -4);
// List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), cal2.getTime()); // List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(),
// System.out.println(list.size()); // cal2.getTime());
// String str = ""; // System.out.println(list.size());
// String url = "C:\\Users\\admin\\Desktop/shenjz.xls"; // String str = "";
// cal.add(Calendar.HOUR_OF_DAY, 9); // String url = "C:\\Users\\admin\\Desktop/shenjz.xls";
// try { // cal.add(Calendar.HOUR_OF_DAY, 9);
// new ExcelUtil().pushDataWithFinance(list, cal.getTime(), url); // try {
// } catch (Exception e) { // new ExcelUtil().pushDataWithFinance(list, cal.getTime(), url);
// e.printStackTrace(); // } catch (Exception e) {
// e.printStackTrace();
// }
List<String> sources = new ArrayList<String>();
String path = PushFinanceByTime.class.getClassLoader().getResource("pushFiles/weibo.xls").getPath();
// Document doc = con.find("financePush", "excelPath", new Document().append("name", "longSource"));
// if (doc != null) {
// if (doc.getString("url") != null) {
// path = doc.getString("url");
// }
// } // }
sources = new ReadExcel().getExcel(path);
Calendar cal = Calendar.getInstance();
// SendMailUtil.sendMessage("949131080@qq.com", url, "金融"); cal.add(Calendar.HOUR_OF_DAY, -10);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources, "weibo");
System.out.println(list.size());
} }
/** /**
...@@ -108,8 +114,8 @@ public class ESUtil { ...@@ -108,8 +114,8 @@ public class ESUtil {
* @param end * @param end
* @return * @return
*/ */
public List<NewsResult> pushByKey(Date start, Date end,List<String> sources) { public List<NewsResult> pushByKey(Date start, Date end, List<String> sources, String type) {
log.info("开始执行检索"); log.info("开始执行检索" + type + ":" + Config.getVal("indexName." + type));
List<NewsResult> result = new ArrayList<>(); List<NewsResult> result = new ArrayList<>();
List<NewsResult> lists = new ArrayList<>(); List<NewsResult> lists = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
...@@ -120,71 +126,89 @@ public class ESUtil { ...@@ -120,71 +126,89 @@ public class ESUtil {
endTime.setTime(end); endTime.setTime(end);
endTime.add(Calendar.HOUR, -8); endTime.add(Calendar.HOUR, -8);
System.out.println("==============="); System.out.println("===============");
int startHour=startTime.get(Calendar.HOUR_OF_DAY); int startHour = startTime.get(Calendar.HOUR_OF_DAY);
int endHour=endTime.get(Calendar.HOUR_OF_DAY); int endHour = endTime.get(Calendar.HOUR_OF_DAY);
System.out.println(); System.out.println(
System.out.println(sdf.format(startTime.getTime()) + "T" sdf.format(startTime.getTime()) + "T" + (startHour > 10 ? startHour : "0" + startHour) + ":00:00.000Z");
+ (startHour>10?startHour:"0"+startHour) System.out.println(
+ ":00:00.000Z"); sdf.format(endTime.getTime()) + "T" + (endHour > 10 ? endHour : "0" + endHour) + ":00:00.000Z");
System.out.println(sdf.format(endTime.getTime()) + "T"
+ (endHour>10?endHour:"0"+endHour)
+ ":00:00.000Z");
System.out.println("==============="); System.out.println("===============");
List<String> keys = new ArrayList<String>();
String path = "";
path = ESUtil.class.getClassLoader().getResource("pushFiles/pushkey.xls").getPath();
Document doc = con.find("financePush", "excelPath", new Document().append("name", "key"));
if (doc != null) {
if (doc.getString("url") != null) {
path = doc.getString("url");
}
}
keys = new ReadExcel().getExcel(path);
try { try {
log.info("推送检索开始");
Client esClient = ESClient.getInstance(); Client esClient = ESClient.getInstance();
List<String> keys = new ArrayList<String>();
String path = ESUtil.class.getClassLoader().getResource("pushFiles/pushkey.xls").getPath();
Document doc = con.find("financePush", "excelPath", new Document().append("name", "key"));
if (doc != null) {
if (doc.getString("url") != null) {
path = doc.getString("url");
}
}
keys = new ReadExcel().getExcel(path);
for (String key : keys) { for (String key : keys) {
// 搜索数据 // 搜索数据
SearchRequestBuilder srb = esClient.prepareSearch(indexName).setTypes(type); SearchRequestBuilder srb = esClient.prepareSearch(Config.getVal("indexName." + type));
BoolQueryBuilder bb = new BoolQueryBuilder(); BoolQueryBuilder bb = new BoolQueryBuilder();
QueryBuilder matchQuery = QueryBuilders.termQuery("content", key); if (type.equals("weibo")) {
bb.should(matchQuery); QueryBuilder matchQuery = QueryBuilders.termQuery("messages", key);
srb.setQuery(bb); bb.should(matchQuery);
srb.setQuery(bb);
} else {
QueryBuilder matchQuery = QueryBuilders.termQuery("content", key);
bb.should(matchQuery);
srb.setQuery(bb);
}
srb.setPostFilter(QueryBuilders.rangeQuery("time") srb.setPostFilter(QueryBuilders.rangeQuery("time")
.gte(sdf.format(startTime.getTime()) + "T" .gte(sdf.format(startTime.getTime()) + "T" + (startHour > 10 ? startHour : "0" + startHour)
+ (startHour>10?startHour:"0"+startHour)
+ ":00:00.000Z") + ":00:00.000Z")
.lte(sdf.format(endTime.getTime()) + "T" .lte(sdf.format(endTime.getTime()) + "T" + (endHour > 10 ? endHour : "0" + endHour)
+ (endHour>10?endHour:"0"+endHour)
+ ":00:00.000Z")); + ":00:00.000Z"));
srb.setSize(200); srb.setSize(500);
SearchResponse response = srb.execute().actionGet(); SearchResponse response = srb.execute().actionGet();
SearchHits searchHits = response.getHits(); SearchHits searchHits = response.getHits();
for (SearchHit hit : searchHits.getHits()) { for (SearchHit hit : searchHits.getHits()) {
Map<String, Object> map = hit.getSource(); Map<String, Object> map = hit.getSource();
NewsResult n = new NewsResult(); NewsResult n = new NewsResult();
SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String url = hit.getSource().get("url") != null ? String.valueOf(hit.getSource().get("url")) String url = hit.getSource().get("url") != null ? String.valueOf(hit.getSource().get("url"))
: String.valueOf(hit.getId()); : String.valueOf(hit.getId());
n.setUrl(url); if (type.equals("weibo")) {
n.setTitle(String.valueOf(map.get("title"))); n.setUrl(url);
SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (map.get("roottext") == null) {
try { n.setTitle(String.valueOf(map.get("text")));
Calendar cal = getStringToCal(map.get("time").toString()); } else {
n.setTime(myFmt.format(cal.getTime())); n.setTitle(String.valueOf(map.get("roottext")));
} catch (Exception e) { }
n.setTime(""); try {
n.setTime(map.get("time")+"");
} catch (Exception e) {
n.setTime("");
}
n.setSource(String.valueOf(map.get("username")));
result.add(n);
} else {
n.setUrl(url);
n.setTitle(String.valueOf(map.get("title")));
try {
Calendar cal = getStringToCal(map.get("time").toString());
n.setTime(myFmt.format(cal.getTime()));
} catch (Exception e) {
n.setTime("");
}
n.setSource(String.valueOf(map.get("source")));
result.add(n);
} }
n.setSource(String.valueOf(map.get("source")));
result.add(n);
} }
} }
log.info("金融结束"); log.info("金融结束");
} catch (Exception e) { } catch (Exception e) {
log.error("es检索出错,错误信息【{}】", e); log.error("es检索出错,错误信息【{}】", e);
} }
for (String source : sources) { for (NewsResult news : result) {
for (NewsResult news : result) { for (String source : sources) {
if (news.getSource().contains(source)) { if (news.getSource().contains(source)) {
lists.add(news); lists.add(news);
break;
} }
} }
} }
...@@ -198,35 +222,6 @@ public class ESUtil { ...@@ -198,35 +222,6 @@ public class ESUtil {
result.add(news); result.add(news);
} }
} }
// List<String> reduce = excelUtil
// .getExcel(ESUtil.class.getClassLoader().getResource("files/reduceIndex.xls").getPath());
// List<String> fm =
// excelUtil.getExcel(ESUtil.class.getClassLoader().getResource("files/fmindex.xls").getPath());
// for (NewsResult news : lists) {
// boolean b = false;
// String title = news.getTitle();
// for (String rt : reduce) {
// if (StringUtil.replaceMis(title).contains(rt)) {
// b = true;
// break;
// }
// }
// if (b) {
// continue;
// }
// b = true;
// for (String f : fm) {
// if (title.contains(f)) {
// b = false;
// break;
// }
// }
// if (b) {
// continue;
// }
// result.add(news);
// }
return result; return result;
} }
} }
...@@ -19,6 +19,7 @@ import com.zhiwei.util.StringUtil; ...@@ -19,6 +19,7 @@ import com.zhiwei.util.StringUtil;
import com.zw.entity.NewsResult; import com.zw.entity.NewsResult;
import sendmail.SendMailUtil; import sendmail.SendMailUtil;
@Component @Component
public class PushFinanceByTime extends Thread { public class PushFinanceByTime extends Thread {
...@@ -32,6 +33,9 @@ public class PushFinanceByTime extends Thread { ...@@ -32,6 +33,9 @@ public class PushFinanceByTime extends Thread {
public void run() { public void run() {
while (true) { while (true) {
List<String> sources = new ArrayList<String>(); List<String> sources = new ArrayList<String>();
List<String> wechat = new ArrayList<String>();
List<String> weibo = new ArrayList<String>();
log.info("推送检测");
String path = PushFinanceByTime.class.getClassLoader().getResource("pushFiles/pushSource.xls").getPath(); String path = PushFinanceByTime.class.getClassLoader().getResource("pushFiles/pushSource.xls").getPath();
Document doc = con.find("financePush", "excelPath", new Document().append("name", "longSource")); Document doc = con.find("financePush", "excelPath", new Document().append("name", "longSource"));
if (doc != null) { if (doc != null) {
...@@ -39,38 +43,61 @@ public class PushFinanceByTime extends Thread { ...@@ -39,38 +43,61 @@ public class PushFinanceByTime extends Thread {
path = doc.getString("url"); path = doc.getString("url");
} }
} }
log.info("推送检测");
sources = new ReadExcel().getExcel(path); sources = new ReadExcel().getExcel(path);
System.out.println(sources);
String path_wechat = PushFinanceByTime.class.getClassLoader().getResource("pushFiles/wechat.xls").getPath();
Document doc_wechat = con.find("financePush", "excelPath", new Document().append("name", "wechat"));
if (doc_wechat != null) {
if (doc_wechat.getString("url") != null) {
path_wechat = doc_wechat.getString("url");
}
}
wechat = new ReadExcel().getExcel(path_wechat);
System.out.println(wechat);
String path_weibo = PushFinanceByTime.class.getClassLoader().getResource("pushFiles/weibo.xls").getPath();
Document doc_weibo = con.find("financePush", "excelPath", new Document().append("name", "weibo"));
if (doc_weibo != null) {
if (doc_weibo.getString("url") != null) {
path_weibo = doc_weibo.getString("url");
}
}
weibo = new ReadExcel().getExcel(path_weibo);
System.out.println(weibo);
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
try { try {
if (cal.get(Calendar.HOUR_OF_DAY) == 8 && cal.get(Calendar.MINUTE) >= 30) { if (cal.get(Calendar.HOUR_OF_DAY) == 8 && cal.get(Calendar.MINUTE) >= 30) {
cal.add(Calendar.HOUR_OF_DAY, -16); cal.add(Calendar.HOUR_OF_DAY, -16);
cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MINUTE, 0);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources); 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");
String url = PushFinanceByTime.class.getClassLoader().getResource("/").getPath() + "/" String url = PushFinanceByTime.class.getClassLoader().getResource("/").getPath() + "/"
+ (int) (Math.random() * 5000) + "sends.xls"; + (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 16); cal.add(Calendar.HOUR_OF_DAY, 16);
sendsEmail(cal, list, url); sendsEmail(cal, list,wechat_,weibo_, url);
sleep(1000 * 60 * 60); sleep(1000 * 60 * 60);
} else if (cal.get(Calendar.HOUR_OF_DAY) == 11) { } else if (cal.get(Calendar.HOUR_OF_DAY) == 17) {// 11
cal.add(Calendar.HOUR_OF_DAY, -3); cal.add(Calendar.HOUR_OF_DAY, -10);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources); 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");
String url = PushFinanceByTime.class.getClassLoader().getResource("/").getPath() + "/" String url = PushFinanceByTime.class.getClassLoader().getResource("/").getPath() + "/"
+ (int) (Math.random() * 5000) + "sends.xls"; + (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 3); cal.add(Calendar.HOUR_OF_DAY, 3);
sendsEmail(cal, list, url); sendsEmail(cal, list,wechat_,weibo_, url);
sleep(1000 * 60 * 60); sleep(1000 * 60 * 60);
} }
if (cal.get(Calendar.DAY_OF_WEEK) == 1 || cal.get(Calendar.DAY_OF_WEEK) == 7) { if (cal.get(Calendar.DAY_OF_WEEK) == 1 || cal.get(Calendar.DAY_OF_WEEK) == 7) {
if (cal.get(Calendar.HOUR_OF_DAY) == 16 && cal.get(Calendar.MINUTE) >= 30) { if (cal.get(Calendar.HOUR_OF_DAY) == 16 && cal.get(Calendar.MINUTE) >= 30) {
cal.add(Calendar.HOUR_OF_DAY, -5); cal.add(Calendar.HOUR_OF_DAY, -5);
cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MINUTE, 0);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources); 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");
String url = PushFinanceByTime.class.getClassLoader().getResource("/").getPath() + "/" String url = PushFinanceByTime.class.getClassLoader().getResource("/").getPath() + "/"
+ (int) (Math.random() * 5000) + "sends.xls"; + (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 5); cal.add(Calendar.HOUR_OF_DAY, 5);
sendsEmail(cal, list, url); sendsEmail(cal, list,wechat_,weibo_, url);
sleep(1000 * 60 * 60); sleep(1000 * 60 * 60);
} }
} }
...@@ -86,20 +113,20 @@ public class PushFinanceByTime extends Thread { ...@@ -86,20 +113,20 @@ public class PushFinanceByTime extends Thread {
} }
} }
private void sendsEmail(Calendar cal, List<NewsResult> list, String url) { private void sendsEmail(Calendar cal, List<NewsResult> list, List<NewsResult> weixin, List<NewsResult> weibo, String url) {
try { try {
new ExcelUtil().pushDataWithFinance(list, cal.getTime(), url); new ExcelUtil().pushDataWithFinanceLong(list,weixin,weibo, cal.getTime(), url);
SendMailUtil.sendMessage("949131080@qq.com", url, "金融"); SendMailUtil.sendMessage("949131080@qq.com", url, "金融");
SendMailUtil.sendMessage("yuhualong@zhiweidata.com", url, "金融"); // SendMailUtil.sendMessage("yuhualong@zhiweidata.com", url, "金融");
SendMailUtil.sendMessage("ligaodie@zhiweidata.com", url, "金融"); // SendMailUtil.sendMessage("ligaodie@zhiweidata.com", url, "金融");
ExcelUtil.delete(url); ExcelUtil.delete(url);
} catch (Exception e) { } catch (Exception e) {
log.error("一号邮箱发送失败,尝试二号邮箱{}", e); log.error("一号邮箱发送失败,尝试二号邮箱{}", e);
try { try {
new ExcelUtil().pushDataWithFinance(list, cal.getTime(), url); new ExcelUtil().pushDataWithFinanceLong(list,weixin,weibo,cal.getTime(), url);
SendMailUtil.sendMessage2("949131080@qq.com", url, "金融"); SendMailUtil.sendMessage2("949131080@qq.com", url, "金融");
SendMailUtil.sendMessage2("yuhualong@zhiweidata.com", url, "金融"); // SendMailUtil.sendMessage2("yuhualong@zhiweidata.com", url, "金融");
SendMailUtil.sendMessage2("ligaodie@zhiweidata.com", url, "金融"); // SendMailUtil.sendMessage2("ligaodie@zhiweidata.com", url, "金融");
ExcelUtil.delete(url); ExcelUtil.delete(url);
} catch (Exception e2) { } catch (Exception e2) {
log.error("二号邮箱发送错误{}", e); log.error("二号邮箱发送错误{}", e);
......
...@@ -17,7 +17,7 @@ import com.zw.entity.NewsResult; ...@@ -17,7 +17,7 @@ import com.zw.entity.NewsResult;
import sendmail.SendMailUtil; import sendmail.SendMailUtil;
@Component //@Component
public class PushFinanceByTimeLess extends Thread { public class PushFinanceByTimeLess extends Thread {
private static final Log log = LogFactory.getLog(PushFinanceByTimeLess.class); private static final Log log = LogFactory.getLog(PushFinanceByTimeLess.class);
private static final MongoConnection con = new MongoConnection(); private static final MongoConnection con = new MongoConnection();
...@@ -44,7 +44,7 @@ public class PushFinanceByTimeLess extends Thread { ...@@ -44,7 +44,7 @@ public class PushFinanceByTimeLess extends Thread {
if (cal.get(Calendar.HOUR_OF_DAY) == 8 && cal.get(Calendar.MINUTE) >= 30) { if (cal.get(Calendar.HOUR_OF_DAY) == 8 && cal.get(Calendar.MINUTE) >= 30) {
cal.add(Calendar.HOUR_OF_DAY, -16); cal.add(Calendar.HOUR_OF_DAY, -16);
cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MINUTE, 0);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources); List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources,"media");
String url = PushFinanceByTimeLess.class.getClassLoader().getResource("/").getPath() + "/" String url = PushFinanceByTimeLess.class.getClassLoader().getResource("/").getPath() + "/"
+ (int) (Math.random() * 5000) + "sends.xls"; + (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 16); cal.add(Calendar.HOUR_OF_DAY, 16);
...@@ -52,7 +52,7 @@ public class PushFinanceByTimeLess extends Thread { ...@@ -52,7 +52,7 @@ public class PushFinanceByTimeLess extends Thread {
sleep(1000 * 60 * 60); sleep(1000 * 60 * 60);
} else if (cal.get(Calendar.HOUR_OF_DAY) == 11) { } else if (cal.get(Calendar.HOUR_OF_DAY) == 11) {
cal.add(Calendar.HOUR_OF_DAY, -3); cal.add(Calendar.HOUR_OF_DAY, -3);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources); List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources,"media");
String url = PushFinanceByTimeLess.class.getClassLoader().getResource("/").getPath() + "/" String url = PushFinanceByTimeLess.class.getClassLoader().getResource("/").getPath() + "/"
+ (int) (Math.random() * 5000) + "sends.xls"; + (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 3); cal.add(Calendar.HOUR_OF_DAY, 3);
...@@ -63,7 +63,7 @@ public class PushFinanceByTimeLess extends Thread { ...@@ -63,7 +63,7 @@ public class PushFinanceByTimeLess extends Thread {
if (cal.get(Calendar.HOUR_OF_DAY) == 16 && cal.get(Calendar.MINUTE) >= 30) { if (cal.get(Calendar.HOUR_OF_DAY) == 16 && cal.get(Calendar.MINUTE) >= 30) {
cal.add(Calendar.HOUR_OF_DAY, -5); cal.add(Calendar.HOUR_OF_DAY, -5);
cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MINUTE, 0);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources); List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources,"media");
String url = PushFinanceByTimeLess.class.getClassLoader().getResource("/").getPath() + "/" String url = PushFinanceByTimeLess.class.getClassLoader().getResource("/").getPath() + "/"
+ (int) (Math.random() * 5000) + "sends.xls"; + (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 5); cal.add(Calendar.HOUR_OF_DAY, 5);
......
...@@ -24,6 +24,7 @@ import jxl.write.WritableFont; ...@@ -24,6 +24,7 @@ import jxl.write.WritableFont;
import jxl.write.WritableHyperlink; import jxl.write.WritableHyperlink;
import jxl.write.WritableSheet; import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook; import jxl.write.WritableWorkbook;
import weixin.popular.bean.menu.selfmenu.News;
/** /**
* excel操作类 * excel操作类
...@@ -34,9 +35,10 @@ import jxl.write.WritableWorkbook; ...@@ -34,9 +35,10 @@ import jxl.write.WritableWorkbook;
@Component @Component
public class ExcelUtil { public class ExcelUtil {
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class); private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
/** /**
* 删除文件 * 删除文件
*
* @param url * @param url
* 文件的路径 * 文件的路径
*/ */
...@@ -50,6 +52,7 @@ public class ExcelUtil { ...@@ -50,6 +52,7 @@ public class ExcelUtil {
/** /**
* 日匹配所有新闻数据写入excel * 日匹配所有新闻数据写入excel
*
* @param list * @param list
* @param time * @param time
* @param fileName * @param fileName
...@@ -140,6 +143,90 @@ public class ExcelUtil { ...@@ -140,6 +143,90 @@ public class ExcelUtil {
WritableHyperlink link = new WritableHyperlink(1, row, 1, row, new URL(news.getUrl()), news.getTitle()); WritableHyperlink link = new WritableHyperlink(1, row, 1, row, new URL(news.getUrl()), news.getTitle());
sheet.addHyperlink(link); sheet.addHyperlink(link);
} catch (Exception e) { } catch (Exception e) {
System.out.println(news);
log.error("获取url失败,错误信息{}", e);
}
l = new Label(1, row, news.getTitle(), urlFormat);// 标题
sheet.addCell(l);
l = new Label(2, row, news.getTime(), detFormat);// 时间
sheet.addCell(l);
l = new Label(3, row, news.getSource(), detFormat);// 时间
sheet.addCell(l);
}
int column = 0;
sheet.setColumnView(column++, 10);
sheet.setColumnView(column++, 25);
sheet.setColumnView(column++, 20);
sheet.setColumnView(column++, 22);
sheet.setColumnView(column++, 22);
workbook.write();
workbook.close();
log.info("内容写入成功");
}
public void pushDataWithFinanceLong(List<NewsResult> list, List<NewsResult> wechat, List<NewsResult> weibo,
Date time, String fileName) throws Exception {
File tempFile = new File(fileName);
// 若是文件不存在就创建新文件
if (!tempFile.exists()) {
tempFile.createNewFile();
}
WritableWorkbook workbook = Workbook.createWorkbook(tempFile);
WritableSheet sheet = workbook.createSheet("table1", 0);
// 一些临时变量,用于写到excel中
Label l = null;
// 预定义的一些字体和格式,格式: 字形 大小 加粗 倾斜 下划线 颜色
WritableFont font1 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD, false,
UnderlineStyle.NO_UNDERLINE, Colour.WHITE);
WritableFont font2 = new WritableFont(WritableFont.ARIAL, 18, WritableFont.BOLD, false,
UnderlineStyle.NO_UNDERLINE, Colour.WHITE);
WritableCellFormat MainTitle = new WritableCellFormat(font2);
MainTitle.setAlignment(Alignment.CENTRE);
MainTitle.setBackground(Colour.BLUE_GREY);
MainTitle.setVerticalAlignment(VerticalAlignment.CENTRE);
// 财新数据标题格式
WritableCellFormat mainTitle = new WritableCellFormat(font1);
mainTitle.setAlignment(Alignment.CENTRE);
mainTitle.setBackground(Colour.BLUE_GREY);
// 标题格式
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
titleFormat.setAlignment(Alignment.CENTRE);
// 正文字体
WritableFont detFont = new WritableFont(WritableFont.ARIAL, 13, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat detFormat = new WritableCellFormat(detFont);
detFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
WritableFont urlf = new WritableFont(WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, Colour.BLUE);
WritableCellFormat urlFormat = new WritableCellFormat(urlf);
urlFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
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);
l = new Label(1, row, "标题", titleFormat);
sheet.addCell(l);
l = new Label(2, row, "时间", titleFormat);
sheet.addCell(l);
l = new Label(3, row, "来源", titleFormat);
sheet.addCell(l);
int num = 1;
for (NewsResult news : list) {
row = seq++;
l = new Label(0, row, String.valueOf(num++), detFormat);// 序号
sheet.addCell(l);
try {
WritableHyperlink link = new WritableHyperlink(1, row, 1, row, new URL(news.getUrl()), news.getTitle());
sheet.addHyperlink(link);
} catch (Exception e) {
log.error("获取url失败,错误信息{}", e); log.error("获取url失败,错误信息{}", e);
} }
l = new Label(1, row, news.getTitle(), urlFormat);// 标题 l = new Label(1, row, news.getTitle(), urlFormat);// 标题
...@@ -155,6 +242,87 @@ public class ExcelUtil { ...@@ -155,6 +242,87 @@ public class ExcelUtil {
sheet.setColumnView(column++, 20); sheet.setColumnView(column++, 20);
sheet.setColumnView(column++, 22); sheet.setColumnView(column++, 22);
sheet.setColumnView(column++, 22); sheet.setColumnView(column++, 22);
WritableSheet sheet2 = workbook.createSheet("wechat", 1);
seq = 0;
sheet2.mergeCells(0, seq, 7, seq + 1);
l = new Label(0, seq, "", mainTitle);
sheet2.addCell(l);
seq += 2;
row = seq++;
l = new Label(0, row, "序号", titleFormat);
sheet2.addCell(l);
l = new Label(1, row, "标题", titleFormat);
sheet2.addCell(l);
l = new Label(2, row, "时间", titleFormat);
sheet2.addCell(l);
l = new Label(3, row, "来源", titleFormat);
sheet2.addCell(l);
num = 1;
for (NewsResult news : wechat) {
row = seq++;
l = new Label(0, row, String.valueOf(num++), detFormat);// 序号
sheet2.addCell(l);
try {
WritableHyperlink link = new WritableHyperlink(1, row, 1, row, new URL(news.getUrl()), news.getTitle());
sheet2.addHyperlink(link);
} catch (Exception e) {
System.out.println(news);
log.error("获取url失败,错误信息{}", e);
}
l = new Label(1, row, news.getTitle(), urlFormat);// 标题
sheet2.addCell(l);
l = new Label(2, row, news.getTime(), detFormat);// 时间
sheet2.addCell(l);
l = new Label(3, row, news.getSource(), detFormat);// 时间
sheet2.addCell(l);
}
column = 0;
sheet2.setColumnView(column++, 10);
sheet2.setColumnView(column++, 25);
sheet2.setColumnView(column++, 20);
sheet2.setColumnView(column++, 22);
sheet2.setColumnView(column++, 22);
WritableSheet sheet3 = workbook.createSheet("weibo", 2);
seq = 0;
sheet3.mergeCells(0, seq, 7, seq + 1);
l = new Label(0, seq, "", mainTitle);
sheet3.addCell(l);
seq += 2;
row = seq++;
l = new Label(0, row, "序号", titleFormat);
sheet3.addCell(l);
l = new Label(1, row, "标题", titleFormat);
sheet3.addCell(l);
l = new Label(2, row, "时间", titleFormat);
sheet3.addCell(l);
l = new Label(3, row, "来源", titleFormat);
sheet3.addCell(l);
num = 1;
for (NewsResult news : weibo) {
row = seq++;
l = new Label(0, row, String.valueOf(num++), detFormat);// 序号
sheet3.addCell(l);
try {
WritableHyperlink link = new WritableHyperlink(1, row, 1, row, new URL(news.getUrl()), news.getTitle());
sheet3.addHyperlink(link);
} catch (Exception e) {
System.out.println(news);
log.error("获取url失败,错误信息{}", e);
}
l = new Label(1, row, news.getTitle(), urlFormat);// 标题
sheet3.addCell(l);
l = new Label(2, row, news.getTime(), detFormat);// 时间
sheet3.addCell(l);
l = new Label(3, row, news.getSource(), detFormat);// 时间
sheet3.addCell(l);
}
column = 0;
sheet3.setColumnView(column++, 10);
sheet3.setColumnView(column++, 25);
sheet3.setColumnView(column++, 20);
sheet3.setColumnView(column++, 22);
sheet3.setColumnView(column++, 22);
workbook.write(); workbook.write();
workbook.close(); workbook.close();
log.info("内容写入成功"); log.info("内容写入成功");
......
...@@ -119,11 +119,11 @@ public class SendMailUtil { ...@@ -119,11 +119,11 @@ public class SendMailUtil {
MimeMessage message = new MimeMessage(session); MimeMessage message = new MimeMessage(session);
SimpleDateFormat sfm = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sfm = new SimpleDateFormat("yyyyMMdd");
String str = sfm.format(new Date()); 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.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "UTF-8"));
message.setSubject(str + "数据结果", "UTF-8"); message.setSubject(str + "整点推送", "UTF-8");
BodyPart messageBodyPart = new MimeBodyPart(); BodyPart messageBodyPart = new MimeBodyPart();
String content = "你好"; String content = "";
messageBodyPart.setContent(content, "text/html; charset=utf-8"); messageBodyPart.setContent(content, "text/html; charset=utf-8");
// 创建多重消息 // 创建多重消息
Multipart multipart = new MimeMultipart(); Multipart multipart = new MimeMultipart();
......
...@@ -17,10 +17,11 @@ socketPort=10201 ...@@ -17,10 +17,11 @@ socketPort=10201
esPort=9300 esPort=9300
esIp=1.119.44.201 esIp=1.119.44.201
clusterName=Media-University clusterName=Media-University
indexName=mediaspider* indexName.media=mediaspider*
indexName.wechat=mediaspider*
indexName.weibo=network*
type=media type=media
openid=oTc_rssM56GjwdRgwTD2dfQMq4Rg openid=oTc_rssM56GjwdRgwTD2dfQMq4Rg
#,oTc_rsju0ZJsEnzFX3WRgZihNWpc,oTc_rsme_NjN1tVh3GSHLdHtq1o8 #,oTc_rsju0ZJsEnzFX3WRgZihNWpc,oTc_rsme_NjN1tVh3GSHLdHtq1o8
######################################## ########################################
...@@ -17,10 +17,11 @@ socketPort=10201 ...@@ -17,10 +17,11 @@ socketPort=10201
esPort=9300 esPort=9300
esIp=1.119.44.201 esIp=1.119.44.201
clusterName=Media-University clusterName=Media-University
indexName=mediaspider* indexName.media=mediaspider*
indexName.wechat=mediaspider*
indexName.weibo=network*
type=media type=media
openid=oTc_rssM56GjwdRgwTD2dfQMq4Rg openid=oTc_rssM56GjwdRgwTD2dfQMq4Rg
#,oTc_rsju0ZJsEnzFX3WRgZihNWpc,oTc_rsme_NjN1tVh3GSHLdHtq1o8 #,oTc_rsju0ZJsEnzFX3WRgZihNWpc,oTc_rsme_NjN1tVh3GSHLdHtq1o8
######################################## ########################################
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