月度均价修改
This commit is contained in:
+101
-20
@@ -4,11 +4,13 @@ import com.fangjia.core.util.DataUtil
|
|||||||
import com.fangjia.script.BaseBatch
|
import com.fangjia.script.BaseBatch
|
||||||
import com.fangjia.script.BatchOwner
|
import com.fangjia.script.BatchOwner
|
||||||
import com.fangjia.script.Watcher
|
import com.fangjia.script.Watcher
|
||||||
|
import com.fangjia.script.commData.CommonDatautils
|
||||||
import com.fangjia.script.util.CommonUtils
|
import com.fangjia.script.util.CommonUtils
|
||||||
import com.fangjia.script.util.DateUtils
|
import com.fangjia.script.util.DateUtils
|
||||||
import com.fangjia.script.util.MongoUtils
|
import com.fangjia.script.util.MongoUtils
|
||||||
import com.mongodb.BasicDBObject
|
import com.mongodb.BasicDBObject
|
||||||
import com.mongodb.DBCollection
|
import com.mongodb.DBCollection
|
||||||
|
import com.mongodb.MongoClient
|
||||||
|
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
import java.util.concurrent.CopyOnWriteArrayList
|
||||||
@@ -26,6 +28,8 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
static DBCollection DISTRICT_SELL_STAT = MongoUtils.getCollectionByName("fangjia_stat", "district_sell_stat", "mongo.db.fangjia.com")
|
static DBCollection DISTRICT_SELL_STAT = MongoUtils.getCollectionByName("fangjia_stat", "district_sell_stat", "mongo.db.fangjia.com")
|
||||||
static final DBCollection FZ_DIST_COLL = MongoUtils.getCollectionByName("business", "fz_district", "mongo.db.fangjia.com")
|
static final DBCollection FZ_DIST_COLL = MongoUtils.getCollectionByName("business", "fz_district", "mongo.db.fangjia.com")
|
||||||
|
|
||||||
|
public static final DBCollection COMMAND_COLL = MongoUtils.getCollectionByName("fangjia_log", "calc_command", "log.mongo.db.fangjia.com",52002)
|
||||||
|
|
||||||
public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(20)
|
public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(20)
|
||||||
|
|
||||||
public static final DBCollection SEAWEED_MONGO_COLL = MongoUtils.getCollectionByName("fangjia", "seaweed", "mongo.db.fangjia.com")
|
public static final DBCollection SEAWEED_MONGO_COLL = MongoUtils.getCollectionByName("fangjia", "seaweed", "mongo.db.fangjia.com")
|
||||||
@@ -37,14 +41,46 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void process(Object args) {
|
void process(Object args) {
|
||||||
def months = DateUtils.getMonthList(202510)
|
// def months = DateUtils.getMonthList(202510)
|
||||||
months = months[0..(months.size()-1)]
|
// months = months[0..(months.size()-1)]
|
||||||
println months
|
// println months
|
||||||
for(def month : months){
|
// for(def month : months){
|
||||||
def curDate = DateUtils.parseFromTightByPattern(month.toString()+"01", "yyyyMMdd")
|
// def curDate = DateUtils.parseFromTightByPattern(month.toString()+"01", "yyyyMMdd")
|
||||||
calcMonthlyPrice(curDate)
|
// calcMonthlyPrice(curDate)
|
||||||
|
// }
|
||||||
|
|
||||||
|
def date = new Date()
|
||||||
|
def day = date.getDate()
|
||||||
|
def hours = date.getHours()
|
||||||
|
if(day == 4 && hours<24){
|
||||||
|
calcMonthlyPrice() //正常算一期
|
||||||
|
}else{
|
||||||
|
//根据calc_type算历史
|
||||||
|
def q = new BasicDBObject("category" ,"sell_month")
|
||||||
|
def commands = COMMAND_COLL.find(q)
|
||||||
|
println "共 【"+commands.size()+"】 个小区重算 "+new Date()
|
||||||
|
for(def command : commands){
|
||||||
|
def calc_type = command.calc_type
|
||||||
|
def id = command._id
|
||||||
|
if(calc_type==1){
|
||||||
|
//找出第一次均价计算的时间
|
||||||
|
def obj = CommonDatautils.queryFirstOrLastDistrictPrice(command.city, command.region, command.name, 1)
|
||||||
|
if(obj){
|
||||||
|
def weekend = obj.weekend
|
||||||
|
def startMonth = DateUtils.formatDateByPattern(weekend, "yyyyMM").toInteger()
|
||||||
|
def months = DateUtils.getMonthList(startMonth)
|
||||||
|
months = months[1..(months.size()-1)]
|
||||||
|
println months
|
||||||
|
for(def month : months){
|
||||||
|
def curDate = DateUtils.parseFromTightByPattern(month.toString()+"01", "yyyyMMdd")
|
||||||
|
calcMonthlyPriceByName(curDate, command.city, command.region, command.name)
|
||||||
|
}
|
||||||
|
//删除命令
|
||||||
|
COMMAND_COLL.remove(new BasicDBObject("_id", id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// calcMonthlyPrice()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +105,7 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
if(!curDate){
|
if(!curDate){
|
||||||
curDate = new Date()
|
curDate = new Date()
|
||||||
}
|
}
|
||||||
def citys = ["上海"]//CommonUtils.findAllCity()
|
def citys = CommonUtils.findAllCity()
|
||||||
// citys.remove("上海")
|
// citys.remove("上海")
|
||||||
// citys.remove("福州")
|
// citys.remove("福州")
|
||||||
def keys = new BasicDBObject("city", 1).append("name", 1).append("region", 1).append("estate_type2", 1).append("status", 1)
|
def keys = new BasicDBObject("city", 1).append("name", 1).append("region", 1).append("estate_type2", 1).append("status", 1)
|
||||||
@@ -92,15 +128,15 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
|
|
||||||
def districts = []
|
def districts = []
|
||||||
if(city == "福州"){
|
if(city == "福州"){
|
||||||
if(day == 29){
|
// if(day == 15){
|
||||||
districts = FZ_DIST_COLL.find(new BasicDBObject("city", city), keys).toList()
|
districts = FZ_DIST_COLL.find(new BasicDBObject("city", city), keys).toList()
|
||||||
}else{
|
// }else{
|
||||||
districts = FZ_DIST_COLL.find(new BasicDBObject("city", city).append("m_date", new BasicDBObject('$gte',startMDate).append('$lt', endMDate)), keys).toList()
|
// districts = FZ_DIST_COLL.find(new BasicDBObject("city", city).append("m_date", new BasicDBObject('$gte',startMDate).append('$lt', endMDate)), keys).toList()
|
||||||
}
|
// }
|
||||||
}else{
|
}else{
|
||||||
def q = new BasicDBObject("city", city).append("cat", "district").append("status", 0)
|
def q = new BasicDBObject("city", city).append("cat", "district").append("status", 0)
|
||||||
// q.put("name", "越华路小区")
|
// q.put("name", "越华路小区")
|
||||||
// if(day == 30){
|
// if(day == 2){
|
||||||
districts = SEAWEED_MONGO_COLL.find(q, keys).batchSize(2000).toList()
|
districts = SEAWEED_MONGO_COLL.find(q, keys).batchSize(2000).toList()
|
||||||
// }else{
|
// }else{
|
||||||
// q.put("m_date", new BasicDBObject('$gte',startMDate).append('$lt', endMDate))
|
// q.put("m_date", new BasicDBObject('$gte',startMDate).append('$lt', endMDate))
|
||||||
@@ -113,10 +149,10 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
def startDate = DateUtils.getFirstDayOfMonth(curDate, -1);
|
def startDate = DateUtils.getFirstDayOfMonth(curDate, -1);
|
||||||
def endDate = DateUtils.getLastDayOfMonth(curDate, -1);
|
def endDate = DateUtils.getLastDayOfMonth(curDate, -1);
|
||||||
if(districts.size()>0){
|
if(districts.size()>0){
|
||||||
def weekendPriceMap = findPriceMap(city, startDate, endDate)//上个月小区均价
|
def weekendPriceMap = findPriceMap(city, startDate, endDate, null, null)//上个月小区均价
|
||||||
def curMonthlyPriceMap = findMonthlyPrice(city, curMonth)//当月小区月均价
|
def curMonthlyPriceMap = findMonthlyPrice(city, curMonth, null, null)//当月小区月均价
|
||||||
def lastMonthlyPriceMap = findMonthlyPrice(city, monDate)//上个月小区月均价
|
def lastMonthlyPriceMap = findMonthlyPrice(city, monDate, null, null)//上个月小区月均价
|
||||||
def lastYearPriceMap = findMonthlyPrice(city, yoyDate)//去年小区月均价
|
def lastYearPriceMap = findMonthlyPrice(city, yoyDate, null, null)//去年小区月均价
|
||||||
if(weekendPriceMap){
|
if(weekendPriceMap){
|
||||||
running(curMonth, districts, weekendPriceMap, curMonthlyPriceMap, lastMonthlyPriceMap, lastYearPriceMap)
|
running(curMonth, districts, weekendPriceMap, curMonthlyPriceMap, lastMonthlyPriceMap, lastYearPriceMap)
|
||||||
}
|
}
|
||||||
@@ -124,6 +160,44 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def calcMonthlyPriceByName(curDate, city, region, name) {
|
||||||
|
//只有福州使用tob价格,改为所有城市都使用2B价格,除人工指导价除外
|
||||||
|
if (!curDate) {
|
||||||
|
curDate = new Date()
|
||||||
|
}
|
||||||
|
|
||||||
|
def keys = new BasicDBObject("city", 1).append("name", 1).append("region", 1).append("estate_type2", 1).append("status", 1)
|
||||||
|
|
||||||
|
def curMonth = Integer.parseInt(DateUtils.addMonth(DateUtils.formatDateByPattern(curDate, "yyyyMM"), -1, "yyyyMM"));
|
||||||
|
def monDate = getMomDate(curMonth)
|
||||||
|
def yoyDate = getYoyDate(curMonth)
|
||||||
|
|
||||||
|
def q = new BasicDBObject("city", city).append("cat", "district").append("status", 0).append("region", region).append("name", name)
|
||||||
|
|
||||||
|
def districts = SEAWEED_MONGO_COLL.find(q, keys).toList()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def startDate = DateUtils.getFirstDayOfMonth(curDate, -1);
|
||||||
|
def endDate = DateUtils.getLastDayOfMonth(curDate, -1);
|
||||||
|
if (districts.size() > 0) {
|
||||||
|
def weekendPriceMap = findPriceMap(city, startDate, endDate, region, name)//上个月小区均价
|
||||||
|
def curMonthlyPriceMap = findMonthlyPrice(city, curMonth, region, name)//当月小区月均价
|
||||||
|
def lastMonthlyPriceMap = findMonthlyPrice(city, monDate, region, name)//上个月小区月均价
|
||||||
|
def lastYearPriceMap = findMonthlyPrice(city, yoyDate, region, name)//去年小区月均价
|
||||||
|
if (weekendPriceMap) {
|
||||||
|
running(curMonth, districts, weekendPriceMap, curMonthlyPriceMap, lastMonthlyPriceMap, lastYearPriceMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def running(districts){
|
def running(districts){
|
||||||
def totalCount = new AtomicLong()
|
def totalCount = new AtomicLong()
|
||||||
final CountDownLatch latch = new CountDownLatch(districts.size())
|
final CountDownLatch latch = new CountDownLatch(districts.size())
|
||||||
@@ -284,10 +358,13 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def findPriceMap(city, startDate, endDate){
|
def findPriceMap(city, startDate, endDate, region, name){
|
||||||
def q = new BasicDBObject()
|
def q = new BasicDBObject()
|
||||||
q.put("city", city)
|
q.put("city", city)
|
||||||
// q.put("district_name","长春铺")
|
if(name){
|
||||||
|
q.put("region", region)
|
||||||
|
q.put("district_name", name)
|
||||||
|
}
|
||||||
q.put("weekend", new BasicDBObject('$lte', endDate).append('$gte', startDate))
|
q.put("weekend", new BasicDBObject('$lte', endDate).append('$gte', startDate))
|
||||||
def dbcursor = DISTRICT_STAT.find(q).sort(new BasicDBObject().append("weekend", -1))
|
def dbcursor = DISTRICT_STAT.find(q).sort(new BasicDBObject().append("weekend", -1))
|
||||||
def priceMap = [:]
|
def priceMap = [:]
|
||||||
@@ -308,10 +385,14 @@ class DistrictSellStatBatch extends BaseBatch {
|
|||||||
return priceMap
|
return priceMap
|
||||||
}
|
}
|
||||||
|
|
||||||
def findMonthlyPrice(city, monDate){
|
def findMonthlyPrice(city, monDate, region, name){
|
||||||
def q = new BasicDBObject()
|
def q = new BasicDBObject()
|
||||||
q.put("city", city)
|
q.put("city", city)
|
||||||
q.put("date", monDate)
|
q.put("date", monDate)
|
||||||
|
if(name){
|
||||||
|
q.put("region", region)
|
||||||
|
q.put("district_name", name)
|
||||||
|
}
|
||||||
def dbcursor = DISTRICT_SELL_STAT.find(q)
|
def dbcursor = DISTRICT_SELL_STAT.find(q)
|
||||||
def priceMap = [:]
|
def priceMap = [:]
|
||||||
for(def d : dbcursor){
|
for(def d : dbcursor){
|
||||||
|
|||||||
Reference in New Issue
Block a user