From fe9f520995808782fa43cd6edc20f879fbc8331c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Fri, 16 Apr 2021 22:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7Es=E9=A9=B1=E5=8A=A8=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fangjia/script/gj/LogStat.groovy | 37 ++++++++++++------- .../fangjia/script/util/ElasticUtils.groovy | 2 +- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/LogStat.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/LogStat.groovy index 7c630dfa9..6305d35b9 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/LogStat.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/LogStat.groovy @@ -5,6 +5,7 @@ import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.util.DateUtils import com.fangjia.script.util.ElasticUtils import com.fangjia.script.util.ExcelUtils +import org.apache.lucene.queryparser.classic.QueryParser class LogStat { @@ -14,19 +15,17 @@ class LogStat { } def run(){ - def datas = ExcelUtils.read("D:\\数据\\建行\\建行匹配小区2.xlsx", 0, 1) - println datas.size() - ExcelUtils.multiThreadingModify("D:\\数据\\建行\\建行匹配小区2.xlsx",{ d -> - def calDate = DateUtil.parseDate(d['D'], "yyyy-MM-dd") + ExcelUtils.multiThreadingModify("D:\\data\\建行匹配小区2(1).xlsx",{ d -> + def calDate = DateUtil.parseDate(d['M'], "yyyy-MM-dd") def weekend = DateUtils.getFirstDayOfWeek(calDate) - def dbo = CommonDatautils.queryDistrictPrice(d['A'], d['B'], d['C'], weekend) + def dbo = CommonDatautils.queryDistrictPrice(d['N'], d['O'], d['P'], weekend) if(dbo){ d['E'] = dbo.avg_price } - def district = CommonDatautils.findDistrict(d['A'], d['B'], d['C'], "district") + def district = CommonDatautils.findDistrict(d['N'], d['O'], d['P'], "district") if(district){ - def startDate = DateUtil.addMonth(calDate, -6) + def startDate = DateUtil.addMonth(new Date(), -6) def start = startDate.replace("-","").toInteger() def end = DateUtil.formatByPattern(calDate,"yyyyMMdd").toInteger() def alias = [] @@ -38,8 +37,9 @@ class LogStat { }else{ alias << district.name } - def count = findHouses(d['A'], d['B'], d['C'], district.alias, start, end) + def count = findHouses(d['N'], d['O'], d['P'], alias, start, end) d['G'] = count + println(d) } },0) } @@ -47,13 +47,24 @@ class LogStat { def findHouses(def city, def region, def name, def alias, def startDate, def endDate){ - String sql = "select * from seawater-20* where cat=sell and city='${city}' and region='${region}' and district_name in (${alias.join(',')})" - def rets = [] + def aliasStr = escapeExprSpecialWord(alias.join("','")) + String sql = "select count(*) as c from latest_seawater where cat='sell' and city='${city}' and p_date > ${startDate} and region='${region}' and district_name in ('${aliasStr}')" + def count = 0 ElasticUtils.executeSqlQuery(sql,{data-> - rets << data - println data + count = data.c }) - return rets.size() + return count + } + + + /** + * 转义字符串中的特殊字符 + * 仅过滤Lucene regexps, 其他的勿用 + * @param keyword + * @return + */ + public static String escapeExprSpecialWord(String keyword) { + return QueryParser.escape(keyword); } // def findTestDatas(def city, def value) { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ElasticUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ElasticUtils.groovy index 3f43734e9..91cb7d57e 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ElasticUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/ElasticUtils.groovy @@ -44,7 +44,7 @@ class ElasticUtils { static getEsDataSource(String host){ EsDataSource dataSource = new EsDataSource (); - dataSource.setUrl("jdbc:es://${host}:9200?timezone=UTC&page.size=240&connect.timeout=240&network.timeout=600&page.timeout=240"); + dataSource.setUrl("jdbc:es://${host}:9200?timezone=UTC&page.size=240&connect.timeout=240000&network.timeout=60000&page.timeout=240000&query.timeout=90000"); Properties connectionProperties = new Properties(); connectionProperties.setProperty("user","developer"); connectionProperties.setProperty("password","5e8edd851d2fdfbd7415232c67367cc3");