Commit 19a369e9 by shenjinzhu

数据搜索优化

parent 46071e6c
......@@ -20,8 +20,8 @@ public interface DataDao {
public List<Data> findByMethod(Date startTime,Date endTime,String method,Object value);
public List<EasyNews> findBySourceFromLibrary(Date startTime, Date endTime, String source);
public List<EasyNews> findBySpId(Date startTime, Date endTime, String syId);
public int findBySourceFromLibrary(Date startTime, Date endTime, String source);
public int findBySpId(Date startTime, Date endTime, String syId);
/**
* 根据数据来源来搜索数据
* @param startTime
......@@ -33,7 +33,7 @@ public interface DataDao {
public List<EasyNews> findByAccurateType(Date startTime, Date endTime, String type);
public int findByAccurateType(Date startTime, Date endTime, String type);
/**
* 根据可视化模板的id去搜索数据
* @param startTime
......
......@@ -240,12 +240,12 @@ public class DataDaoImpl implements DataDao {
}
@Override
public List<EasyNews> findBySourceFromLibrary(Date startTime, Date endTime, String source) {
public int findBySourceFromLibrary(Date startTime, Date endTime, String source) {
Calendar c = Calendar.getInstance();
c.setTime(startTime);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
return mongo2.find(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("type").is(source)),
return (int) mongo2.count(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("type").is(source)),
EasyNews.class, "net_media_" + year + (month>9?""+month:"0"+month));
}
......@@ -277,12 +277,12 @@ public class DataDaoImpl implements DataDao {
}
@Override
public List<EasyNews> findByAccurateType(Date startTime, Date endTime, String type) {
public int findByAccurateType(Date startTime, Date endTime, String type) {
Calendar c = Calendar.getInstance();
c.setTime(startTime);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
return mongo2.find(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("type").is(type)),
return (int) mongo2.count(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("type").is(type)),
EasyNews.class, "net_media_" + year + (month>9?""+month:"0"+month));
}
......@@ -353,12 +353,12 @@ public class DataDaoImpl implements DataDao {
}
@Override
public List<EasyNews> findBySpId(Date startTime, Date endTime, String syId) {
public int findBySpId(Date startTime, Date endTime, String syId) {
Calendar c = Calendar.getInstance();
c.setTime(startTime);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
return mongo2.find(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("spyderInfoId").is(syId)),
return (int) mongo2.count(Query.query(Criteria.where("time").gte(startTime).lt(endTime).and("spyderInfoId").is(syId)),
EasyNews.class, "net_media_" + year + (month>9?""+month:"0"+month));
}
......
......@@ -18,15 +18,15 @@ public interface DataService {
public List<Data> findByMethod(Date startTime, Date endTime,String method,Object value);
public List<EasyNews> findBySourceFromLibrary(Date startTime, Date endTime, String source);
public int findBySourceFromLibrary(Date startTime, Date endTime, String source);
public List<EasyNews> findByAccurateSource(String startTime, String endTime, String source);
public List<EasyNews> findByAccurateSpId(String startTime, String endTime, String SpId);
public List<EasyNews> findByAccurateType(Date startTime, Date endTime, String type);
public int findByAccurateType(Date startTime, Date endTime, String type);
public List<EasyNews> findByTempName(Date startTime, Date endTime, String tempName);
public int findByTempName(Date startTime, Date endTime, String tempName);
public long findWeiboCount(Date start, Date end);
......
......@@ -59,7 +59,7 @@ public class DataServiceImpl implements DataService{
}
@Override
public List<EasyNews> findBySourceFromLibrary(Date startTime, Date endTime, String source) {
public int findBySourceFromLibrary(Date startTime, Date endTime, String source) {
return dataDao.findBySourceFromLibrary(startTime, endTime, source);
}
......@@ -74,7 +74,7 @@ public class DataServiceImpl implements DataService{
}
@Override
public List<EasyNews> findByAccurateType(Date startTime, Date endTime, String type) {
public int findByAccurateType(Date startTime, Date endTime, String type) {
return dataDao.findByAccurateType(startTime, endTime, type);
}
......@@ -94,7 +94,7 @@ public class DataServiceImpl implements DataService{
}
@Override
public List<EasyNews> findByTempName(Date startTime, Date endTime, String tempName) {
public int findByTempName(Date startTime, Date endTime, String tempName) {
String spId=crd.getSpIdByConfigName(tempName);
return dataDao.findBySpId(startTime, endTime, spId);
}
......
......@@ -89,25 +89,32 @@ public class DataController {
startd.setTimeInMillis(start);
endTime.setTimeInMillis(start);
}
Calendar ds=Calendar.getInstance();
ds.setTimeInMillis(end);
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startd.getTime()));
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ds.getTime()));
String source = "";
List<Data> list = new ArrayList<Data>();
startd.add(Calendar.HOUR, -8);
while (endTime.getTimeInMillis() < end) {
while (endTime.getTime().before(ds.getTime())) {
endTime.add(Calendar.HOUR, 1);
List<EasyNews> newsList = new ArrayList<>();
int count=0;
if(method.equals("type")){
source=(String) map.get("type");
newsList=dataService.findByAccurateType(startd.getTime(), endTime.getTime(), source);
count=dataService.findByAccurateType(startd.getTime(), endTime.getTime(), source);
}else{
if (method.equals("source")) {
source = (String) map.get("source");
newsList = dataService.findBySourceFromLibrary(startd.getTime(), endTime.getTime(), source);
count = dataService.findBySourceFromLibrary(startd.getTime(), endTime.getTime(), source);
} else {
source = (String) map.get("tempName");
newsList = dataService.findByTempName(startd.getTime(), endTime.getTime(), source);
count = dataService.findByTempName(startd.getTime(), endTime.getTime(), source);
}
}
Data data = Change.changeNewsToDate(newsList, startd.getTime());
Data data = new Data();
data.setCount(count);
data.setSource(source);
data.setTime(startd.getTime());
list.add(data);
startd.add(Calendar.HOUR, 1);
}
......
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