Commit 4419d1f6 by admin

添加微博和微信推送信息

parent 97845ba8
......@@ -9,6 +9,8 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import javax.print.Doc;
import org.bson.Document;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
......@@ -27,6 +29,7 @@ import com.zhiwei.util.MongoConnection;
import com.zhiwei.util.ReadExcel;
import com.zw.entity.NewsResult;
import weixin.popular.bean.menu.selfmenu.News;
/**
* es工具类
......@@ -36,14 +39,7 @@ import com.zw.entity.NewsResult;
@Component
public class ESUtil {
private static final Logger log = LoggerFactory.getLogger(ESUtil.class);
private static String indexName;
private static String type;
private static MongoConnection con=new MongoConnection();
static {
indexName = Config.getVal("indexName");
type = Config.getVal("type");
}
private static MongoConnection con = new MongoConnection();
/**
* 获取匹配时终止时间
......@@ -80,25 +76,35 @@ public class ESUtil {
return result;
}
public static void main(String[] args) {
// Calendar cal = Calendar.getInstance();
// cal.add(Calendar.HOUR_OF_DAY, -20);
// Calendar cal2 = Calendar.getInstance();
// cal2.add(Calendar.HOUR_OF_DAY, -4);
// List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), cal2.getTime());
// System.out.println(list.size());
// String str = "";
// String url = "C:\\Users\\admin\\Desktop/shenjz.xls";
// cal.add(Calendar.HOUR_OF_DAY, 9);
// try {
// new ExcelUtil().pushDataWithFinance(list, cal.getTime(), url);
// } catch (Exception e) {
// e.printStackTrace();
// Calendar cal = Calendar.getInstance();
// cal.add(Calendar.HOUR_OF_DAY, -20);
// Calendar cal2 = Calendar.getInstance();
// cal2.add(Calendar.HOUR_OF_DAY, -4);
// List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(),
// cal2.getTime());
// System.out.println(list.size());
// String str = "";
// String url = "C:\\Users\\admin\\Desktop/shenjz.xls";
// cal.add(Calendar.HOUR_OF_DAY, 9);
// try {
// new ExcelUtil().pushDataWithFinance(list, cal.getTime(), url);
// } 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");
// }
// SendMailUtil.sendMessage("949131080@qq.com", url, "金融");
// }
sources = new ReadExcel().getExcel(path);
Calendar cal = Calendar.getInstance();
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 {
* @param end
* @return
*/
public List<NewsResult> pushByKey(Date start, Date end,List<String> sources) {
log.info("开始执行检索");
public List<NewsResult> pushByKey(Date start, Date end, List<String> sources, String type) {
log.info("开始执行检索" + type + ":" + Config.getVal("indexName." + type));
List<NewsResult> result = new ArrayList<>();
List<NewsResult> lists = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
......@@ -120,21 +126,16 @@ public class ESUtil {
endTime.setTime(end);
endTime.add(Calendar.HOUR, -8);
System.out.println("===============");
int startHour=startTime.get(Calendar.HOUR_OF_DAY);
int endHour=endTime.get(Calendar.HOUR_OF_DAY);
System.out.println();
System.out.println(sdf.format(startTime.getTime()) + "T"
+ (startHour>10?startHour:"0"+startHour)
+ ":00:00.000Z");
System.out.println(sdf.format(endTime.getTime()) + "T"
+ (endHour>10?endHour:"0"+endHour)
+ ":00:00.000Z");
int startHour = startTime.get(Calendar.HOUR_OF_DAY);
int endHour = endTime.get(Calendar.HOUR_OF_DAY);
System.out.println(
sdf.format(startTime.getTime()) + "T" + (startHour > 10 ? startHour : "0" + startHour) + ":00:00.000Z");
System.out.println(
sdf.format(endTime.getTime()) + "T" + (endHour > 10 ? endHour : "0" + endHour) + ":00:00.000Z");
System.out.println("===============");
try {
log.info("推送检索开始");
Client esClient = ESClient.getInstance();
List<String> keys = new ArrayList<String>();
String path = ESUtil.class.getClassLoader().getResource("pushFiles/pushkey.xls").getPath();
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) {
......@@ -142,31 +143,52 @@ public class ESUtil {
}
}
keys = new ReadExcel().getExcel(path);
try {
Client esClient = ESClient.getInstance();
for (String key : keys) {
// 搜索数据
SearchRequestBuilder srb = esClient.prepareSearch(indexName).setTypes(type);
SearchRequestBuilder srb = esClient.prepareSearch(Config.getVal("indexName." + type));
BoolQueryBuilder bb = new BoolQueryBuilder();
if (type.equals("weibo")) {
QueryBuilder matchQuery = QueryBuilders.termQuery("messages", key);
bb.should(matchQuery);
srb.setQuery(bb);
} else {
QueryBuilder matchQuery = QueryBuilders.termQuery("content", key);
bb.should(matchQuery);
srb.setQuery(bb);
}
srb.setPostFilter(QueryBuilders.rangeQuery("time")
.gte(sdf.format(startTime.getTime()) + "T"
+ (startHour>10?startHour:"0"+startHour)
.gte(sdf.format(startTime.getTime()) + "T" + (startHour > 10 ? startHour : "0" + startHour)
+ ":00:00.000Z")
.lte(sdf.format(endTime.getTime()) + "T"
+ (endHour>10?endHour:"0"+endHour)
.lte(sdf.format(endTime.getTime()) + "T" + (endHour > 10 ? endHour : "0" + endHour)
+ ":00:00.000Z"));
srb.setSize(200);
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();
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 (type.equals("weibo")) {
n.setUrl(url);
if (map.get("roottext") == null) {
n.setTitle(String.valueOf(map.get("text")));
} else {
n.setTitle(String.valueOf(map.get("roottext")));
}
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")));
SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Calendar cal = getStringToCal(map.get("time").toString());
n.setTime(myFmt.format(cal.getTime()));
......@@ -177,14 +199,16 @@ public class ESUtil {
result.add(n);
}
}
}
log.info("金融结束");
} catch (Exception e) {
log.error("es检索出错,错误信息【{}】", e);
}
for (String source : sources) {
for (NewsResult news : result) {
for (String source : sources) {
if (news.getSource().contains(source)) {
lists.add(news);
break;
}
}
}
......@@ -198,35 +222,6 @@ public class ESUtil {
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;
}
}
......@@ -19,6 +19,7 @@ import com.zhiwei.util.StringUtil;
import com.zw.entity.NewsResult;
import sendmail.SendMailUtil;
@Component
public class PushFinanceByTime extends Thread {
......@@ -32,6 +33,9 @@ public class PushFinanceByTime extends Thread {
public void run() {
while (true) {
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();
Document doc = con.find("financePush", "excelPath", new Document().append("name", "longSource"));
if (doc != null) {
......@@ -39,38 +43,61 @@ public class PushFinanceByTime extends Thread {
path = doc.getString("url");
}
}
log.info("推送检测");
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();
try {
if (cal.get(Calendar.HOUR_OF_DAY) == 8 && cal.get(Calendar.MINUTE) >= 30) {
cal.add(Calendar.HOUR_OF_DAY, -16);
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() + "/"
+ (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 16);
sendsEmail(cal, list, url);
sendsEmail(cal, list,wechat_,weibo_, url);
sleep(1000 * 60 * 60);
} else if (cal.get(Calendar.HOUR_OF_DAY) == 11) {
cal.add(Calendar.HOUR_OF_DAY, -3);
List<NewsResult> list = new ESUtil().pushByKey(cal.getTime(), new Date(), sources);
} else if (cal.get(Calendar.HOUR_OF_DAY) == 17) {// 11
cal.add(Calendar.HOUR_OF_DAY, -10);
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() + "/"
+ (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 3);
sendsEmail(cal, list, url);
sendsEmail(cal, list,wechat_,weibo_, url);
sleep(1000 * 60 * 60);
}
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) {
cal.add(Calendar.HOUR_OF_DAY, -5);
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() + "/"
+ (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 5);
sendsEmail(cal, list, url);
sendsEmail(cal, list,wechat_,weibo_, url);
sleep(1000 * 60 * 60);
}
}
......@@ -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 {
new ExcelUtil().pushDataWithFinance(list, cal.getTime(), url);
new ExcelUtil().pushDataWithFinanceLong(list,weixin,weibo, cal.getTime(), url);
SendMailUtil.sendMessage("949131080@qq.com", url, "金融");
SendMailUtil.sendMessage("yuhualong@zhiweidata.com", url, "金融");
SendMailUtil.sendMessage("ligaodie@zhiweidata.com", url, "金融");
// SendMailUtil.sendMessage("yuhualong@zhiweidata.com", url, "金融");
// SendMailUtil.sendMessage("ligaodie@zhiweidata.com", url, "金融");
ExcelUtil.delete(url);
} catch (Exception e) {
log.error("一号邮箱发送失败,尝试二号邮箱{}", e);
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("yuhualong@zhiweidata.com", url, "金融");
SendMailUtil.sendMessage2("ligaodie@zhiweidata.com", url, "金融");
// SendMailUtil.sendMessage2("yuhualong@zhiweidata.com", url, "金融");
// SendMailUtil.sendMessage2("ligaodie@zhiweidata.com", url, "金融");
ExcelUtil.delete(url);
} catch (Exception e2) {
log.error("二号邮箱发送错误{}", e);
......
......@@ -17,7 +17,7 @@ import com.zw.entity.NewsResult;
import sendmail.SendMailUtil;
@Component
//@Component
public class PushFinanceByTimeLess extends Thread {
private static final Log log = LogFactory.getLog(PushFinanceByTimeLess.class);
private static final MongoConnection con = new MongoConnection();
......@@ -44,7 +44,7 @@ public class PushFinanceByTimeLess extends Thread {
if (cal.get(Calendar.HOUR_OF_DAY) == 8 && cal.get(Calendar.MINUTE) >= 30) {
cal.add(Calendar.HOUR_OF_DAY, -16);
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() + "/"
+ (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 16);
......@@ -52,7 +52,7 @@ public class PushFinanceByTimeLess extends Thread {
sleep(1000 * 60 * 60);
} else if (cal.get(Calendar.HOUR_OF_DAY) == 11) {
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() + "/"
+ (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 3);
......@@ -63,7 +63,7 @@ public class PushFinanceByTimeLess extends Thread {
if (cal.get(Calendar.HOUR_OF_DAY) == 16 && cal.get(Calendar.MINUTE) >= 30) {
cal.add(Calendar.HOUR_OF_DAY, -5);
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() + "/"
+ (int) (Math.random() * 5000) + "sends.xls";
cal.add(Calendar.HOUR_OF_DAY, 5);
......
......@@ -24,6 +24,7 @@ import jxl.write.WritableFont;
import jxl.write.WritableHyperlink;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import weixin.popular.bean.menu.selfmenu.News;
/**
* excel操作类
......@@ -37,6 +38,7 @@ public class ExcelUtil {
/**
* 删除文件
*
* @param url
* 文件的路径
*/
......@@ -50,6 +52,7 @@ public class ExcelUtil {
/**
* 日匹配所有新闻数据写入excel
*
* @param list
* @param time
* @param fileName
......@@ -140,6 +143,7 @@ public class ExcelUtil {
WritableHyperlink link = new WritableHyperlink(1, row, 1, row, new URL(news.getUrl()), news.getTitle());
sheet.addHyperlink(link);
} catch (Exception e) {
System.out.println(news);
log.error("获取url失败,错误信息{}", e);
}
l = new Label(1, row, news.getTitle(), urlFormat);// 标题
......@@ -159,4 +163,168 @@ public class ExcelUtil {
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);
}
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);
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.close();
log.info("内容写入成功");
}
}
......@@ -119,11 +119,11 @@ 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 = "你好";
String content = "";
messageBodyPart.setContent(content, "text/html; charset=utf-8");
// 创建多重消息
Multipart multipart = new MimeMultipart();
......
......@@ -17,10 +17,11 @@ socketPort=10201
esPort=9300
esIp=1.119.44.201
clusterName=Media-University
indexName=mediaspider*
indexName.media=mediaspider*
indexName.wechat=mediaspider*
indexName.weibo=network*
type=media
openid=oTc_rssM56GjwdRgwTD2dfQMq4Rg
#,oTc_rsju0ZJsEnzFX3WRgZihNWpc,oTc_rsme_NjN1tVh3GSHLdHtq1o8
########################################
......@@ -17,10 +17,11 @@ socketPort=10201
esPort=9300
esIp=1.119.44.201
clusterName=Media-University
indexName=mediaspider*
indexName.media=mediaspider*
indexName.wechat=mediaspider*
indexName.weibo=network*
type=media
openid=oTc_rssM56GjwdRgwTD2dfQMq4Rg
#,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