From 047467f6c29984e622c9d54363291bd9f27a7263 Mon Sep 17 00:00:00 2001 From: gaojuan Date: Wed, 1 Jun 2022 13:47:06 +0800 Subject: [PATCH] update --- .../ccbevaluation/data/CcbDataStat.groovy | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDataStat.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDataStat.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDataStat.groovy new file mode 100644 index 000000000..1aa5a391f --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDataStat.groovy @@ -0,0 +1,155 @@ +package com.fangjia.script.ccbevaluation.data + +import com.fangjia.script.ccbevaluation.CcbCommonUtils +import com.fangjia.script.common.DataHandleUtils +import com.fangjia.script.util.DateUtils +import com.fangjia.script.util.ExcelUtils +import com.fangjia.script.util.MongoUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection +import groovy.sql.Sql + +class CcbDataStat { + + public static final DBCollection DEAL_PRICE_COLL = MongoUtils.getCollectionByName("fangjia", "deal_price", "mongo.db.fangjia.com") + + def sqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", + "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") + + static main(args) { + def task = new CcbDataStat() +// task.run() + task.tradeRun() + } + + def tradeRun(){ + def ccbCitys = CcbCommonUtils.citys; + def startDate = DateUtils.parseFromTightByPattern("2021-01-01","yyyy-MM-dd") + def endDate = DateUtils.parseFromTightByPattern("2022-01-01","yyyy-MM-dd") + ExcelUtils.multiThreadingModify("D:\\数据\\建行\\成交案例统计_0531.xlsx", { d -> + if(d['A']){ + if(ccbCitys.contains(d['A'])){ + d['D'] = findOracleTotalCount(d['A']) + }else{ + def totalcount = findAllTradeCount(d['A'], startDate, endDate) + def repeatCount = findRepeatCount(d['A'], startDate, endDate) + def matchTotalCount = findMatchTradeCount(d['A'], startDate, endDate) + def matchRepeatTotalCount = findMatchRepeatTradeCount(d['A'], startDate, endDate) + d['B'] = totalcount + d['C'] = repeatCount + d['D'] = matchTotalCount + d['E'] = matchRepeatTotalCount + } + + } + }) + } + + + + def findRepeatCount(city, startDate, endDate){ + def q = new BasicDBObject() + q.put("city", city) + q.put("trade_date", new BasicDBObject('$gte', startDate).append('$lt',endDate)) + + def dbcursor = DEAL_PRICE_COLL.find(q) + def set = new HashSet() + for(def d : dbcursor){ + def key = d.region+"##"+d.district_name+"##"+d.avg_price+"##"+d.area+"##"+DateUtils.formatDateByPattern(d.trade_date,"yyyyMMdd") + if(!set.contains(key)){ + set << key + } + } + return set.size() + } + + def findMatchRepeatTradeCount(city, startDate, endDate){ + def q = new BasicDBObject() + q.put("city", city) + q.put("trade_date", new BasicDBObject('$gte', startDate).append('$lt',endDate)) + q.put("match_id", new BasicDBObject('$exists', true)) + def dbcursor = DEAL_PRICE_COLL.find(q) + def set = new HashSet() + for(def d : dbcursor){ + def key = d.match_id+"#"+d.avg_price+"##"+d.area+"##"+DateUtils.formatDateByPattern(d.trade_date,"yyyyMMdd") + if(!set.contains(key)){ + set << key + } + } + return set.size() + } + + + def findMatchTradeCount(city, startDate, endDate){ + def q = new BasicDBObject() + q.put("city", city) + q.put("trade_date", new BasicDBObject('$gte', startDate).append('$lt',endDate)) + q.put("match_id", new BasicDBObject('$exists', true)) + def count = DEAL_PRICE_COLL.count(q) + return count + } + + + public static def findAllTradeCount(city, startDate, endDate){ + def q = new BasicDBObject() + q.put("city", city) + q.put("trade_date", new BasicDBObject('$gte', startDate).append('$lt',endDate)) +// q.put("match_id", new BasicDBObject('$exists', false)) + def total = DEAL_PRICE_COLL.count(q) + return total + } + + def findOracleTotalCount(city){ + def sql = "select count(*) as count from bigdata_deal_gj where cityname='${city}' and dealdate>=to_date('2021-01-01','yyyy-MM-dd') and dealdate + count = r.count + }) + return count + } + + def run(){ + def cityCodeDataMap = CcbCommonUtils.findCityCodeValue() + ExcelUtils.multiThreadingModify("D:\\数据\\建行\\建行成交\\92个城市字段覆盖率情况.xlsx",{ d-> + if(d['A']) { + def citycode = cityCodeDataMap.get(d['A']) + def total = findTotalCount(citycode) + def f_count = findDistFinishDate(citycode) + def b_count = findBuildTypeCount(citycode) + def f_pre = DataHandleUtils.getDoubleRound(2, f_count*100/total) + def b_pre = DataHandleUtils.getDoubleRound(2, b_count*100/total) + d['C'] = f_pre + d['D'] = b_pre + d['E'] = total + println d['A'] +" "+ total +" "+f_count+" "+b_count + } + }) + } + + def findTotalCount(citycode){ + def sql = "select count(*) as count from bigdata_community_gj where cityid='${citycode}' and status=0";//where cityId in (350200,150100) + def count = 0 + sqlInstance.eachRow(sql, { r -> + count = r.count + }) + return count + } + + def findDistFinishDate(citycode){ + def sql = "select count(*) as count from bigdata_community_gj where cityid='${citycode}' and status=0 and BUILDYEAR>0";//where cityId in (350200,150100) + def count = 0 + sqlInstance.eachRow(sql, { r -> + count = r.count + }) + return count + } + + def findBuildTypeCount(citycode){ + def sql = "select count(*) as count from (select commid, count(commid) as count from bigdata_commbuildtype_gj where cityid='${citycode}' and BUILDTYPE!='0199' group by commid)";//where cityId in (350200,150100) + def count = 0 + sqlInstance.eachRow(sql, { r -> + count = r.count + }) + return count + } +}