From 57410d0d32165d6199bda125c9556ca0a4c19cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Wed, 4 Feb 2026 18:36:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=A4=A7=E8=B6=85=E6=97=B6=E8=AD=A6?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hubingliang/ApiInvokeStatistics.groovy | 19 +++++++++++-------- .../openApi/OpenApiLogAnalyBatch.groovy | 1 - 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/hubingliang/ApiInvokeStatistics.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/hubingliang/ApiInvokeStatistics.groovy index 17112f274..1d634d97f 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/hubingliang/ApiInvokeStatistics.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/hubingliang/ApiInvokeStatistics.groovy @@ -23,7 +23,6 @@ import com.mongodb.DBObject */ @BatchOwner(Watcher.Hubingliang) class ApiInvokeStatistics extends BaseBatch{ - final static def mongoDomain = "mongo.db.fangjia.com" public static final DBCollection OPEN_URI_LOG = com.fangjia.core.util.MongoUtils.getDbCollection(Constants.SEAWATER_MONGO_URI,"business", "open_uri_log") public static final DBCollection OPEN_URI_LOG_COUNT = MongoUtils.getCollectionByName("business", "api_invoke_statistical", "mongo.db.fangjia.com", 28017) static final dbFangjia = Sql.newInstance("jdbc:mysql://mysql.db.fangjia.com:4306/fangjia?autoReconnect=true&characterEncoding=utf-8&autoReconnect=true", "sa", "G00jia", "com.mysql.jdbc.Driver"); @@ -36,18 +35,22 @@ class ApiInvokeStatistics extends BaseBatch{ public void process(Object args) { ApiInvokeStatistics aiks = new ApiInvokeStatistics(); Date date = DateUtil.truncateDay(new Date()) - aiks.getYestodayLog(date, date - 1); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + def countDays = 10; + for(int i = 0; i < countDays; i++) { + Date today = calendar.getTime() + Date yesterday = DateUtil.add(today, -1) + aiks.getYestodayLog(today, yesterday); + calendar.add(Calendar.DAY_OF_MONTH, -1) + } } - - + def getYestodayLog(Date today,Date yestoday){ - //Date today = getToday(); - //Date yestoday = getNextDay(today) def deleteQuery = new BasicDBObject("statistical_date", yestoday) OPEN_URI_LOG_COUNT.remove(deleteQuery) - println "已删除 ${yestoday.format('yyyy-MM-dd')} 的旧统计数据" BasicDBObject query= new BasicDBObject("c_date", new BasicDBObject('$gte',yestoday).append('$lt', today)) -// DBCursor dbc=OPEN_URI_LOG.find(query).batchSize(10000).addOption(Bytes.QUERYOPTION_NOTIMEOUT) + println "已删除 ${yestoday.format('yyyy-MM-dd')} 的旧统计数据, 新查询条数: ${query}" DBCursor dbc = OPEN_URI_LOG.find(query, new BasicDBObject("res_map", 0)).batchSize(10000).addOption(Bytes.QUERYOPTION_NOTIMEOUT) def results = [:] diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/openApi/OpenApiLogAnalyBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/openApi/OpenApiLogAnalyBatch.groovy index 135c1b920..3ca7bfe07 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/openApi/OpenApiLogAnalyBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/openApi/OpenApiLogAnalyBatch.groovy @@ -80,7 +80,6 @@ class OpenApiLogAnalyBatch extends BaseBatch{ index++; println "[${index}]"+apiUser.id + " "+logs.count() if(logs){ - def urlCountMap = analyLogsByUrl(logs); saveAnalyLogs(apiUser, startDate, urlCountMap); }