修复日期及重点城市查询bug
This commit is contained in:
+28
-22
@@ -1,5 +1,6 @@
|
||||
package com.fangjia.script.temp.shenjian
|
||||
|
||||
import com.fangjia.core.util.DateUtil
|
||||
import com.fangjia.script.BaseBatch
|
||||
import com.fangjia.script.BatchOwner
|
||||
import com.fangjia.script.Watcher
|
||||
@@ -7,7 +8,6 @@ import com.fangjia.script.util.ElasticUtils
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
import com.fangjia.script.yinjihaun.util.DingDingMessageUtil
|
||||
import org.apache.commons.lang.StringUtils
|
||||
import org.apache.commons.lang.time.DateUtils
|
||||
|
||||
/**
|
||||
* 抓取总量监控
|
||||
@@ -22,17 +22,17 @@ class SeawaterMonitor extends BaseBatch {
|
||||
// 运维组 运维警报
|
||||
static final access_token = "2307d2fec8314b3e8b4b83dd1d42da2e2051638e3e668f21e77ca01258bf682c"
|
||||
// 重点城市
|
||||
static final city = ["北京','唐山','天津','秦皇岛','石家庄','包头','太原','丹东','呼和浩特','锦州'," +
|
||||
"'沈阳','吉林','大连','牡丹江','长春','无锡','哈尔滨','扬州','上海','徐州'," +
|
||||
"'南京','温州','杭州','金华','宁波','蚌埠','合肥','安庆','福州','泉州'," +
|
||||
"'厦门','九江','南昌','赣州','济南','烟台','青岛','济宁','郑州','洛阳'," +
|
||||
"'武汉','平顶山','长沙','宜昌','广州','襄阳','深圳','岳阳','南宁','常德'," +
|
||||
"'海口','惠州','重庆','湛江','成都','韶关','贵阳','桂林','昆明','北海'," +
|
||||
"'西安','三亚','兰州','泸州','西宁','南充','银川','遵义','乌鲁木齐','大理'," +
|
||||
"'东莞','佛山','苏州','珠海','中山','台州','绍兴','南通','常州','嘉兴'," +
|
||||
"'淄博','株洲','镇江','肇庆','漳州','盐城','芜湖','泰州','汕头','清远'," +
|
||||
"'马鞍山','柳州','连云港','廊坊','淮安','湖州','沧州','保定','张家口','日照'," +
|
||||
"'拉萨','大同','文昌','陵水','保亭"];
|
||||
static final city = ["北京","唐山","天津","秦皇岛","石家庄","包头","太原","丹东","呼和浩特","锦州",
|
||||
"沈阳","吉林","大连","牡丹江","长春","无锡","哈尔滨","扬州","上海","徐州",
|
||||
"南京","温州","杭州","金华","宁波","蚌埠","合肥","安庆","福州","泉州",
|
||||
"厦门","九江","南昌","赣州","济南","烟台","青岛","济宁","郑州","洛阳",
|
||||
"武汉","平顶山","长沙","宜昌","广州","襄阳","深圳","岳阳","南宁","常德",
|
||||
"海口","惠州","重庆","湛江","成都","韶关","贵阳","桂林","昆明","北海",
|
||||
"西安","三亚","兰州","泸州","西宁","南充","银川","遵义","乌鲁木齐","大理",
|
||||
"东莞","佛山","苏州","珠海","中山","台州","绍兴","南通","常州","嘉兴",
|
||||
"淄博","株洲","镇江","肇庆","漳州","盐城","芜湖","泰州","汕头","清远",
|
||||
"马鞍山","柳州","连云港","廊坊","淮安","湖州","沧州","保定","张家口","日照",
|
||||
"拉萨","大同","文昌","陵水","保亭"];
|
||||
// 重点网站
|
||||
static final site = ["lianjia.com", "ke.com", "58.com", "zhuge.com", "fang.com"]
|
||||
|
||||
@@ -46,7 +46,7 @@ class SeawaterMonitor extends BaseBatch {
|
||||
*/
|
||||
static def monitorYesterdayCrawlNumber(def startDate, def endDate) {
|
||||
def total
|
||||
String sql = "select count(*) as total from latest_seawater where m_date between '${startDate}' and '${endDate}' "
|
||||
String sql = "select count(*) as total from seawater where m_date >= '${startDate}' and m_date < '${endDate}' "
|
||||
ElasticUtils.executeSqlQuery(sql,{data->
|
||||
total = data.total
|
||||
})
|
||||
@@ -65,7 +65,7 @@ class SeawaterMonitor extends BaseBatch {
|
||||
result << ['城市', '抓取量']
|
||||
// 统计近半个月各重点城市抓取量
|
||||
def cityFormatted = city.join("','")
|
||||
String sql = "select * from (select count(*) as total, city from latest_seawater where m_date between '${startDate}' and '${endDate}' and city in('${cityFormatted}') group by city) order by total desc "
|
||||
String sql = "select * from (select count(*) as total, city from seawater where m_date >= '${startDate}' and m_date < '${endDate}' and city in('${cityFormatted}') group by city) order by total desc "
|
||||
ElasticUtils.executeSqlQuery(sql,{data->
|
||||
result << [data.city, data.total]
|
||||
})
|
||||
@@ -78,14 +78,20 @@ class SeawaterMonitor extends BaseBatch {
|
||||
*/
|
||||
static def monitorCityCrawlNumber(def startDate, def endDate) {
|
||||
def msg = "【重点城市抓取异常】"
|
||||
def unNormal = []
|
||||
def set = new HashSet()
|
||||
def cityFormatted = city.join("','")
|
||||
String sql = "select * from " +
|
||||
" (select count(*) as total, city from latest_seawater where m_date between '${startDate}' and '${endDate}' and city in('${cityFormatted}') group by city) where total=0 "
|
||||
" (select count(*) as total, city from seawater where m_date >= '${startDate}' and m_date < '${endDate}' and city in('${cityFormatted}') group by city) where total>0 "
|
||||
//" order by total "
|
||||
ElasticUtils.executeSqlQuery(sql,{data->
|
||||
unNormal.add(data.city)
|
||||
set.add(data.city)
|
||||
})
|
||||
def unNormal = []
|
||||
for (def info : city) {
|
||||
if (!set.contains(info)) {
|
||||
unNormal.add(info)
|
||||
}
|
||||
}
|
||||
msg += unNormal.join("、") + " 抓取量为0"
|
||||
if (unNormal.size() > 0) {
|
||||
return msg
|
||||
@@ -101,7 +107,7 @@ class SeawaterMonitor extends BaseBatch {
|
||||
def set = new HashSet()
|
||||
def siteFormatted = site.join("','")
|
||||
String sql = "select * from " +
|
||||
" (select count(*) as total, root from latest_seawater where m_date between '${lastWeekDate}' and '${endDate}' and root in('${siteFormatted}') group by root) where total > 0 "
|
||||
" (select count(*) as total, root from seawater where m_date >= '${lastWeekDate}' and m_date < '${endDate}' and root in('${siteFormatted}') group by root) where total > 0 "
|
||||
//" order by total "
|
||||
ElasticUtils.executeSqlQuery(sql,{data->
|
||||
set.add(data.root)
|
||||
@@ -121,10 +127,10 @@ class SeawaterMonitor extends BaseBatch {
|
||||
|
||||
@Override
|
||||
void process(Object args) {
|
||||
def lastWeekDate = org.apache.commons.lang3.time.DateFormatUtils.format(DateUtils.addDays(new Date(), -7), "yyyy-MM-dd")
|
||||
def yesterday = org.apache.commons.lang3.time.DateFormatUtils.format(DateUtils.addDays(new Date(), -1), "yyyy-MM-dd")
|
||||
def startDate = yesterday + "T00:00:00"
|
||||
def endDate = yesterday + "T23:59:59"
|
||||
def lastWeekDate = DateUtil.add(DateUtil.truncateDay(new Date()), -7).getTime()
|
||||
def yesterday = DateUtil.formatToYYYYMMDD(DateUtil.add(DateUtil.truncateDay(new Date()), -1))
|
||||
def startDate = DateUtil.add(DateUtil.truncateDay(new Date()), -1).getTime();
|
||||
def endDate = DateUtil.truncateDay(new Date()).getTime()
|
||||
|
||||
def result = []
|
||||
def msg = monitorYesterdayCrawlNumber(startDate, endDate)
|
||||
|
||||
Reference in New Issue
Block a user