Commit 91f583d9 by shenjinzhu

更新操作

parent ea51b12a
......@@ -27,6 +27,7 @@ import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.WriteResult;
......@@ -141,7 +142,7 @@ public class DataDaoImpl implements DataDao {
int year = c.get(Calendar.YEAR);
Criteria criteria = new Criteria();
criteria.and("spyderInfoId").is(SpId);
criteria.and("time").gt(startTime).lt(endTime);
criteria.and("time").gte(startTime).lt(endTime);
return mongo2.find(Query.query(criteria), EasyNews.class,
"net_media_" + year + (month > 9 ? "" + month : "0" + month));
}
......@@ -263,12 +264,19 @@ public class DataDaoImpl implements DataDao {
public static void main(String[] args) {
// 连接到数据库
ServerAddress sa = new ServerAddress("115.236.59.91", 27017);
MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder();
MongoClientOptions options = optionsBuilder.build();
List<MongoCredential> credentials = new ArrayList<>();
MongoCredential credential = MongoCredential.createCredential("WX_datas", "wx_datas", "JDK_weixin66".toCharArray());
credentials.add(credential);
List<ServerAddress> serverAddresses = new ArrayList<>();
serverAddresses.add(new ServerAddress("47.104.99.236", Integer.valueOf("2708")));
List<MongoCredential> mongoCredentialList = new ArrayList<MongoCredential>();
MongoClient mongoClient = new MongoClient(sa, mongoCredentialList);
MongoDatabase mongo = mongoClient.getDatabase("mediaspider");
MongoCollection<Document> col = mongo.getCollection("net_media_201801");
System.out.println(col.count());
MongoClient mongoClient = new MongoClient(serverAddresses, credentials, options);
MongoDatabase mongo = mongoClient.getDatabase("wx_datas");
MongoCollection<Document> col = mongo.getCollection("wx_datas");
col.insertOne(new Document("k","bv"));
}
@Override
......@@ -391,7 +399,7 @@ public class DataDaoImpl implements DataDao {
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
return (int) mongo2.count(
Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("spyderInfoId").is(syId)),
Query.query(Criteria.where("time").gt(startTime).lt(endTime).and("spyderInfoId").is(syId)),
EasyNews.class, "net_media_" + year + (month > 9 ? "" + month : "0" + month));
}
......
......@@ -4,11 +4,13 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -136,9 +138,15 @@ public class MainThread extends Thread {
}
}
public static boolean delete(String templateId) {
allTmp.remove(templateId);
return true;
public static void removeAll() {
allTmp = new ConcurrentHashMap<String, Template>();
mainMap = new ConcurrentHashMap<String, Template>();
DelayedThread.runMap = new ConcurrentHashMap<String, NewsDelayed>();
DelayedThread.queue = new LinkedBlockingQueue<NewsDelayed>(500);
FieldThread.runMap = new ConcurrentHashMap<String, FieldIntegerity>();
FieldThread.queue = new LinkedBlockingQueue<FieldIntegerity>(500);
PingThread.runMap = new ConcurrentHashMap<String, PingUrl>();
PingThread.queue = new LinkedBlockingQueue<PingUrl>(500);
}
@Override
......@@ -158,9 +166,7 @@ public class MainThread extends Thread {
Calendar start = Calendar.getInstance();
if (start.get(Calendar.HOUR_OF_DAY) < 1) {
Calendar end = Calendar.getInstance();
Date d = null;
try {
d = sdf.parse(today);
// start.setTime(sdf2.parse(sdf2.format(start.getTime())));
// if (start.get(Calendar.HOUR_OF_DAY) > 1) {
// start.add(Calendar.HOUR_OF_DAY, -1);
......@@ -170,7 +176,6 @@ public class MainThread extends Thread {
// }
start.add(Calendar.DATE, -1);
end.setTime(sdf2.parse(today));
end.add(Calendar.HOUR_OF_DAY, -1);
} catch (ParseException e2) {
e2.printStackTrace();
}
......
......@@ -46,14 +46,7 @@ public class TemplateController {
@RequestMapping(value = "/stopAll", produces = "application/json;charset=utf-8")
@ResponseBody
public String stopAll() {
Set<String> ids=MainThread.mainMap.keySet();
for(String id:ids) {
try {
MainThread.removeMap(id);
}catch(Exception e) {
log.error("停止失败{}",e);
}
}
MainThread.removeAll();
JsonResult result = new JsonResult(true, 200, "停止成功");
return JSON.toJSONString(result);
}
......@@ -96,7 +89,7 @@ public class TemplateController {
String results = "";
for (String l : templateId) {
isDelete = ts.delete(l, pt);
MainThread.delete(l);
MainThread.removeMap(l);
results += l + "\n";
}
JsonResult result = new JsonResult(true, 200, results + "删除" + (isDelete == false ? "成功" : "失败"));
......
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