Commit 1d624ef2 by shenjinzhu

完整的数据修改

parent 4fba4f5c
...@@ -28,6 +28,7 @@ import com.mongodb.DBObject; ...@@ -28,6 +28,7 @@ import com.mongodb.DBObject;
import com.mongodb.Mongo; import com.mongodb.Mongo;
import com.mongodb.MongoClient; import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions; import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential; import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress; import com.mongodb.ServerAddress;
import com.mongodb.WriteResult; import com.mongodb.WriteResult;
...@@ -83,24 +84,25 @@ public class DataDaoImpl implements DataDao { ...@@ -83,24 +84,25 @@ public class DataDaoImpl implements DataDao {
@Override @Override
public void insert(Data data) { public void insert(Data data) {
Data d = null; Data d = null;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date today=null; Date today = null;
try { try {
today=sdf.parse(sdf.format(data.getTime())); today = sdf.parse(sdf.format(data.getTime()));
} catch (ParseException e1) { } catch (ParseException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
if (data.getTempName() != null) { if (data.getTempName() != null) {
d = mongo.findOne(Query.query(Criteria.where("time").is(today)
.andOperator(Criteria.where("tempName").is(data.getTempName()))), Data.class);
} else {
d = mongo.findOne(Query.query( d = mongo.findOne(Query.query(
Criteria.where("time").is(today).andOperator(Criteria.where("pt").is(data.getPt()))), Criteria.where("time").is(today).andOperator(Criteria.where("tempName").is(data.getTempName()))),
Data.class);
} else {
d = mongo.findOne(
Query.query(Criteria.where("time").is(today).andOperator(Criteria.where("pt").is(data.getPt()))),
Data.class); Data.class);
} }
if (d == null) { if (d == null) {
mongo.insert(data, "Data"); mongo.insert(data, "Data");
}else { } else {
d.setCount(data.getCount()); d.setCount(data.getCount());
Update update = new Update(); Update update = new Update();
Field[] fields = d.getClass().getDeclaredFields(); Field[] fields = d.getClass().getDeclaredFields();
...@@ -109,7 +111,7 @@ public class DataDaoImpl implements DataDao { ...@@ -109,7 +111,7 @@ public class DataDaoImpl implements DataDao {
try { try {
if (fields[j].getName().equals("dataId")) { if (fields[j].getName().equals("dataId")) {
continue; continue;
}else if(fields[j].getName().equals("time")) { } else if (fields[j].getName().equals("time")) {
update.set(fields[j].getName(), today); update.set(fields[j].getName(), today);
} }
if (fields[j].get(d) != null) if (fields[j].get(d) != null)
...@@ -118,8 +120,7 @@ public class DataDaoImpl implements DataDao { ...@@ -118,8 +120,7 @@ public class DataDaoImpl implements DataDao {
e.printStackTrace(); e.printStackTrace();
} }
} }
mongo.updateFirst(Query.query(Criteria.where("_id").is(d.getDataId())), update, mongo.updateFirst(Query.query(Criteria.where("_id").is(d.getDataId())), update, Data.class);
Data.class);
} }
} }
...@@ -161,10 +162,12 @@ public class DataDaoImpl implements DataDao { ...@@ -161,10 +162,12 @@ public class DataDaoImpl implements DataDao {
} }
int resultCount = 0; int resultCount = 0;
if (col == null) { if (col == null) {
MongoClient mongoClient = null;
ServerBean ser = mongo.findOne( ServerBean ser = mongo.findOne(
Query.query(Criteria.where("pt").is(pt).andOperator(Criteria.where("other").is("data"))), Query.query(Criteria.where("pt").is(pt).andOperator(Criteria.where("other").is("data"))),
ServerBean.class); ServerBean.class);
MongoClient mongoClient = new MongoClient(ser.getDbHost(), ser.getDbPort()); mongoClient = new MongoClient(new MongoClientURI(
"mongodb://sjzno:sjzno1q2w3e4r@" + ser.getDbHost() + ":" + ser.getDbPort() + "/admin"));
// 连接到数据库 // 连接到数据库
MongoDatabase mongo = mongoClient.getDatabase(ser.getDbName()); MongoDatabase mongo = mongoClient.getDatabase(ser.getDbName());
for (int i = 1; i < 6; i++) { for (int i = 1; i < 6; i++) {
...@@ -222,16 +225,25 @@ public class DataDaoImpl implements DataDao { ...@@ -222,16 +225,25 @@ public class DataDaoImpl implements DataDao {
end = cal.get(Calendar.YEAR) + "" + (month > 9 ? "" + month : "0" + month); end = cal.get(Calendar.YEAR) + "" + (month > 9 ? "" + month : "0" + month);
System.out.println(end); System.out.println(end);
} }
MongoClient mongoClient = null; MongoClient mongoClient =null;
if (ser.getDbUsername() != null && ser.getDbUsername().length() > 2) { if(ser.getPt().equals("微信全量")){
ServerAddress sa = new ServerAddress(ser.getDbHost(), ser.getDbPort()); mongoClient = new MongoClient(new MongoClientURI("mongodb://sjzzc:sjzzc1q2w3e4r@"+ser.getDbHost()+":"+ser.getDbPort()+"/admin"));
List<MongoCredential> mongoCredentialList = new ArrayList<MongoCredential>(); }else{
mongoCredentialList.add(MongoCredential.createMongoCRCredential(ser.getDbUsername(), mongoClient = new MongoClient(new MongoClientURI("mongodb://sjzno:sjzno1q2w3e4r@"+ser.getDbHost()+":"+ser.getDbPort()+"/admin"));
ser.getDbName(), ser.getDbPassword().toCharArray())); }
new MongoClient(sa, mongoCredentialList); // if (ser.getDbUsername() != null &&
mongoClient = new MongoClient(sa, mongoCredentialList); // ser.getDbUsername().length() > 2) {
} else // ServerAddress sa = new ServerAddress(ser.getDbHost(),
mongoClient = new MongoClient(ser.getDbHost(), ser.getDbPort()); // ser.getDbPort());
// List<MongoCredential> mongoCredentialList = new
// ArrayList<MongoCredential>();
// mongoCredentialList.add(MongoCredential.createMongoCRCredential(ser.getDbUsername(),
// ser.getDbName(), ser.getDbPassword().toCharArray()));
// new MongoClient(sa, mongoCredentialList);
// mongoClient = new MongoClient(sa, mongoCredentialList);
// } else
// mongoClient = new MongoClient(ser.getDbHost(),
// ser.getDbPort());
// 连接到数据库 // 连接到数据库
MongoDatabase mongo = mongoClient.getDatabase(ser.getDbName()); MongoDatabase mongo = mongoClient.getDatabase(ser.getDbName());
DbDepot.dataCol.put(pt, mongo.getCollection(ser.getCollection() + end)); DbDepot.dataCol.put(pt, mongo.getCollection(ser.getCollection() + end));
...@@ -263,19 +275,13 @@ public class DataDaoImpl implements DataDao { ...@@ -263,19 +275,13 @@ public class DataDaoImpl implements DataDao {
} }
public static void main(String[] args) { public static void main(String[] args) {
// 连接到数据库 MongoClient mongoClient = new MongoClient(
MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder(); new MongoClientURI("mongodb://sjzno:sjzno1q2w3e4r@115.236.59.91:27017/admin"));
MongoClientOptions options = optionsBuilder.build(); DB db = mongoClient.getDB("mediaspider");
List<MongoCredential> credentials = new ArrayList<>(); DBCollection col = db.getCollection("net_media_201804");
MongoCredential credential = MongoCredential.createCredential("WX_datas", "wx_datas", "JDK_weixin66".toCharArray()); Date d = new Date();
credentials.add(credential); d.setHours(2);
List<ServerAddress> serverAddresses = new ArrayList<>(); System.out.println(col.count(new BasicDBObject("time", new BasicDBObject("$gte", d))));
serverAddresses.add(new ServerAddress("47.104.99.236", Integer.valueOf("2708")));
List<MongoCredential> mongoCredentialList = new ArrayList<MongoCredential>();
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"));
} }
...@@ -322,7 +328,8 @@ public class DataDaoImpl implements DataDao { ...@@ -322,7 +328,8 @@ public class DataDaoImpl implements DataDao {
c.setTime(startTime); c.setTime(startTime);
int year = c.get(Calendar.YEAR); int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1; int month = c.get(Calendar.MONTH) + 1;
return (int) mongo2.count(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("type").is(type)), "net_media_" + year + (month > 9 ? "" + month : "0" + month)); return (int) mongo2.count(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("type").is(type)),
"net_media_" + year + (month > 9 ? "" + month : "0" + month));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
......
...@@ -31,8 +31,6 @@ public class NewsDaoImpl implements NewsDao { ...@@ -31,8 +31,6 @@ public class NewsDaoImpl implements NewsDao {
@Resource(name = "newmongoTemplate") @Resource(name = "newmongoTemplate")
private MongoTemplate mongo; private MongoTemplate mongo;
@Resource(name = "newmongoTemplate")
private MongoTemplate spiderMongo;
@Override @Override
public List<News> findByNew(int delayedCount, String type, String source) { public List<News> findByNew(int delayedCount, String type, String source) {
...@@ -127,7 +125,7 @@ public class NewsDaoImpl implements NewsDao { ...@@ -127,7 +125,7 @@ public class NewsDaoImpl implements NewsDao {
int month = cal.get(Calendar.MONTH) + 1; int month = cal.get(Calendar.MONTH) + 1;
String end = cal.get(Calendar.YEAR) + "" + (month > 9 ? month : "0" + month); String end = cal.get(Calendar.YEAR) + "" + (month > 9 ? month : "0" + month);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
DBCollection con = spiderMongo.getCollection(collection + end); DBCollection con = mongo.getCollection(collection + end);
if (id != null && !id.equals("")) { if (id != null && !id.equals("")) {
DBCursor cur = con.find(new BasicDBObject("spyderInfoId", id)).sort(new BasicDBObject("rsid", -1)) DBCursor cur = con.find(new BasicDBObject("spyderInfoId", id)).sort(new BasicDBObject("rsid", -1))
.limit(count); .limit(count);
...@@ -146,10 +144,4 @@ public class NewsDaoImpl implements NewsDao { ...@@ -146,10 +144,4 @@ public class NewsDaoImpl implements NewsDao {
return list; return list;
} }
public static void main(String[] args) {
MongoClient mongoClient = new MongoClient("115.236.59.91", 27017);
MongoDatabase mongo = mongoClient.getDatabase("mediaspider");
MongoCollection<Document> col = mongo.getCollection("");
}
} }
...@@ -48,6 +48,7 @@ public class MainThread extends Thread { ...@@ -48,6 +48,7 @@ public class MainThread extends Thread {
/** /**
* 加入执行map * 加入执行map
*
* @param template * @param template
*/ */
public static boolean pushMap(String templateId) { public static boolean pushMap(String templateId) {
......
...@@ -167,6 +167,7 @@ public class DataController { ...@@ -167,6 +167,7 @@ public class DataController {
chan.setValue(chan.getValue()); chan.setValue(chan.getValue());
list.add(chan); list.add(chan);
} }
System.out.println(list);
JsonResult result = new JsonResult(true, 200, "请求成功", list); JsonResult result = new JsonResult(true, 200, "请求成功", list);
return JSON.toJSONString(result); return JSON.toJSONString(result);
} else { } else {
...@@ -179,10 +180,9 @@ public class DataController { ...@@ -179,10 +180,9 @@ public class DataController {
for(Channel chan:channel){ for(Channel chan:channel){
List<Data> weixin = dataService.findByPt(startTime.getTime(), endTime.getTime(), chan.getPt()); List<Data> weixin = dataService.findByPt(startTime.getTime(), endTime.getTime(), chan.getPt());
chan.setList(weixin); chan.setList(weixin);
chan.setPt(chan.getPt());
chan.setValue(chan.getValue());
list.add(chan); list.add(chan);
} }
System.out.println("kil2:"+list);
JsonResult result = new JsonResult(true, 200, "请求成功", list); JsonResult result = new JsonResult(true, 200, "请求成功", list);
return JSON.toJSONString(result); return JSON.toJSONString(result);
} }
......
...@@ -32,7 +32,6 @@ public class PersonController { ...@@ -32,7 +32,6 @@ public class PersonController {
@RequestMapping(value = "/login", produces = "application/json;charset=utf-8") @RequestMapping(value = "/login", produces = "application/json;charset=utf-8")
@ResponseBody @ResponseBody
public String login(HttpServletRequest req, HttpServletResponse res, @RequestBody Map<String, Object> map) { public String login(HttpServletRequest req, HttpServletResponse res, @RequestBody Map<String, Object> map) {
boolean isRemember = (boolean) map.get("isRemember");
String username = (String) map.get("username"); String username = (String) map.get("username");
String password = (String) map.get("password"); String password = (String) map.get("password");
Person p = personService.login(username, password); Person p = personService.login(username, password);
...@@ -129,7 +128,7 @@ public class PersonController { ...@@ -129,7 +128,7 @@ public class PersonController {
for (Cookie cookie : cookies) { for (Cookie cookie : cookies) {
System.out.println(cookie.getName()); System.out.println(cookie.getName());
if (cookie.getName().equals(person.getUsername())) { if (cookie.getName().equals(person.getUsername())) {
JsonResult result = new JsonResult(false, 200, "该用户在线,不允许删除"); JsonResult result = new JsonResult(false, 200, "该用户在线,添加同名");
return JSON.toJSONString(result); return JSON.toJSONString(result);
} }
} }
......
...@@ -117,7 +117,15 @@ public class ServerController { ...@@ -117,7 +117,15 @@ public class ServerController {
@ResponseBody @ResponseBody
public String findAllChannel(){ public String findAllChannel(){
List<Channel> list=ss.findDisChannel(); List<Channel> list=ss.findDisChannel();
if(list==null||list.size()==0){
Channel c=new Channel();
c.setId("1");
c.setPt("网媒");
c.setValue("wangmei");
list.add(c);
}
JsonResult result=new JsonResult(true, 200, "获取成功",list); JsonResult result=new JsonResult(true, 200, "获取成功",list);
System.out.println(result);
return JSON.toJSONString(result); return JSON.toJSONString(result);
} }
......
...@@ -42,26 +42,21 @@ ...@@ -42,26 +42,21 @@
</constructor-arg> </constructor-arg>
</bean> </bean>
<mongo:mongo id="mongoMongo" host="${mongo.serverMongoIp}" <mongo:mongo-client id="MongoCl" host="${mongo.serverMongoIp}" port="${mongo.serverMongoPort}"
port="${mongo.serverMongoPort}" write-concern="SAFE" /> credentials="${mongo.username}:${mongo.password}@${mongo.spyPlatData.dbName}" >
<mongo:client-options write-concern="SAFE"/>
</mongo:mongo-client>
<mongo:db-factory id="mongoFactory" dbname="${mongo.spyPlatData.dbName1}" <mongo:db-factory id="mongoFactory" dbname="${mongo.spyPlatData.dbName1}"
mongo-ref="mongoMongo" /> mongo-ref="MongoCl" />
<mongo:template id="mongoTemplate" db-factory-ref="mongoFactory" /> <mongo:template id="mongoTemplate" db-factory-ref="mongoFactory" />
<mongo:mongo id="newmongoMongo" host="${mongo2.serverMongoIp}" <mongo:db-factory id="newmongoFactory" dbname="${mongo.spyPlatData.dbName2}"
port="${mongo2.serverMongoPort}" write-concern="SAFE" /> mongo-ref="MongoCl" />
<mongo:db-factory id="newmongoFactory" dbname="${mongo2.spyPlatData.dbName1}"
mongo-ref="newmongoMongo" />
<mongo:template id="newmongoTemplate" db-factory-ref="newmongoFactory" /> <mongo:template id="newmongoTemplate" db-factory-ref="newmongoFactory" />
<mongo:db-factory id="wbmongoFactory" dbname="${mongo.spyPlatData.dbName3}"
mongo-ref="MongoCl" />
<mongo:mongo id="weibomongoMongo" host="${weibomongo.serverMongoIp}" <mongo:template id="weibomongoTemplate" db-factory-ref="wbmongoFactory" />
port="${weibomongo.serverMongoPort}" write-concern="SAFE" />
<mongo:db-factory id="weibomongoFactory"
dbname="${weibomongo.spyPlatData.dbName1}" mongo-ref="weibomongoMongo" />
<mongo:template id="weibomongoTemplate" db-factory-ref="weibomongoFactory" />
</beans> </beans>
\ No newline at end of file
###生产环境 ###生产环境
#修改模板线程的注释 #权限认证
#mongo.serverMongoIp=192.168.0.101
mongo.serverMongoIp=115.236.59.91 mongo.serverMongoIp=115.236.59.91
mongo.serverMongoPort=27017 mongo.serverMongoPort=27017
mongo.spyPlatData.dbName1=dataMonitoring mongo.serverMongoIp2=1.119.44.206
mongo.serverMongoPort2=30000
#mongo.spyPlatData.dbName1=dataMonitoring
mongo.spyPlatData.dbName=admin
mongo.username=sjzno
mongo.password=sjzno1q2w3e4r
############################################## ##############################################
mongo2.serverMongoIp=115.236.59.91 mongo.spyPlatData.dbName1=dataMonitoring
mongo2.serverMongoPort=27017 ##############################################
mongo2.spyPlatData.dbName1=mediaspider mongo.spyPlatData.dbName2=mediaspider
############################################## ##############################################
weibomongo.serverMongoIp=115.236.59.91 mongo.spyPlatData.dbName3=NetWork
weibomongo.serverMongoPort=27017
weibomongo.spyPlatData.dbName1=NetWork
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