This commit is contained in:
2023-04-07 18:49:52 +08:00
parent 3dd084d77d
commit dadd63c819
2 changed files with 84 additions and 4 deletions
@@ -7,6 +7,7 @@ import com.fangjia.script.common.DataHandleUtils
import com.fangjia.script.gj.ccb.FileUtils
import com.fangjia.script.util.DateUtils
import com.fangjia.script.util.ElasticUtils
import com.fangjia.script.util.ExcelUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBObject
import groovy.sql.Sql
@@ -459,14 +460,19 @@ class BigdataCitypriceBatch extends BaseBatch{
def dealYoy = ''
if(allLastMonthMap){
def dealMarkupMap = allLastMonthMap.get(dist._id.toString())
if(dealMarkupMap && dealMarkupMap.deal_count && dealMarkupMap.deal_count>0){
def markup = (dealCount-dealMarkupMap.deal_count)*100/dealMarkupMap.deal_count
dealMarkup = DataHandleUtils.getDoubleRound(2, markup)
try{
if(dealCount && dealMarkupMap && dealMarkupMap.deal_count && dealMarkupMap.deal_count>0){
def markup = (dealCount-dealMarkupMap.deal_count)*100/dealMarkupMap.deal_count
dealMarkup = DataHandleUtils.getDoubleRound(2, markup)
}
}catch(Exception e){
e.printStackTrace()
}
}
if(allLastYearMap){
def dealYoyMap = allLastYearMap.get(dist._id.toString())
if(dealYoyMap && dealYoyMap.deal_count && dealYoyMap.deal_count>0){
if(dealCount && dealYoyMap && dealYoyMap.deal_count && dealYoyMap.deal_count>0){
def markup = (dealCount-dealYoyMap.deal_count)*100/dealYoyMap.deal_count
dealYoy = DataHandleUtils.getDoubleRound(2, markup)
}
@@ -0,0 +1,74 @@
package com.fangjia.script.ccbevaluation.ronghe
import com.fangjia.script.ccbevaluation.CcbCommonUtils
import com.fangjia.script.commData.CommonDatautils
import com.fangjia.script.util.DateUtils
import groovy.sql.Sql
class UpdateCommPrice {
def pgsqlInstance = Sql.newInstance("jdbc:postgresql://192.168.0.236:5432/warehouse?stringtype=unspecified",
"postgres", "postgres", "org.postgresql.Driver")
def oracleSqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl",
"GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver")
public static def cityCodeMap = CcbCommonUtils.findCityCodeValue()
static main(args) {
def task = new UpdateCommPrice()
task.run(args)
}
def run(Object args){
def citys = CcbCommonUtils.citys_all
def curDate = new Date()
if(args){
def dateStr = args[0]
curDate = DateUtils.parseFromTightByPattern(dateStr,"yyyy-MM-dd")//2022-03-01
}
def curRunDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(curDate,-1), "yyyyMM").toInteger();
def startDate = DateUtils.formatDateByPattern(DateUtils.getFirstDayOfMonth(curDate,-1), "yyyyMMdd").toInteger();
def dealStartDate = DateUtils.addMonth(DateUtils.parseFromTightByPattern(startDate.toString(), "yyyyMMdd"), -1)
process(citys, dealStartDate, startDate, curRunDate)
}
def process(citys, dealStartDate, startDate, curRunDate){
def rets = []
def allDistricts = []
def allDealCountMap = [:]
for(def city : citys) {
def districts = CcbCommonUtils.findAllDistrictByCity(city, "district", ["city", "region", "name", "lng", "estate_type2", "name_cat", "address", "alias"]);
allDistricts.addAll(districts)
def cityCode = cityCodeMap.get(city)
def dealCountMap = findDealDatesByCity(cityCode, dealStartDate, startDate)
allDealCountMap = allDealCountMap + dealCountMap
}
for(def i=0;i<allDistricts.size();i++) {
final def dist = allDistricts[i];
def dealCount = allDealCountMap.get(dist._id.toString())
if(dealCount){
updateDealCount(dist._id.toString(), dealCount, curRunDate)
}
}
}
def updateDealCount(def dist_id, count, month){
def sql = "update bigdata_commprice_fjw set deal_count=${count} where ymid=${month} and commid='${dist_id}'"
oracleSqlInstance.execute(sql)
}
def findDealDatesByCity(cityCode, startDate, endDate){
def sql = "SELECT gujia_comm_id,count(1) from base.t0831_bigdata_deal_gj_h WHERE urbn_id='${cityCode}' and txn_dt>='${startDate}' and txn_dt<'${endDate}' GROUP BY gujia_comm_id";
def rMap = [:]
pgsqlInstance.eachRow(sql, { r ->
rMap.put(r.gujia_comm_id, r.count)
})
return rMap;
}
}