Merge branch 'script_gj' into 'master'

upate

See merge request !719
This commit is contained in:
2023-09-08 16:13:01 +08:00
2 changed files with 61 additions and 12 deletions
@@ -88,6 +88,7 @@ class DistrictSellStatBatch extends BaseBatch {
}
}else{
def q = new BasicDBObject("city", city).append("cat", "district").append("status", 0)
// q.put("name", "翠园楼")
if(day == 2){
districts = DbUtils.seaweed.find(q, keys).batchSize(2000)
}else{
@@ -135,8 +136,8 @@ class DistrictSellStatBatch extends BaseBatch {
def rets = new CopyOnWriteArrayList()
districts.each{dist->
// fixedThreadPool.execute(new Runnable() {
// void run() {
fixedThreadPool.execute(new Runnable() {
void run() {
try {
totalCount.addAndGet(1)
def key = dist.region +"##" + dist.name
@@ -152,12 +153,7 @@ class DistrictSellStatBatch extends BaseBatch {
mom = DataUtil.roundDouble(((weekendPriceObj.avg_price - lastMonthPriceObj.avg_price)/(double)lastMonthPriceObj.avg_price),4)
}
def curPrice = null;
if(curPriceObj){
curPrice = curPriceObj.avg_price
}else{
curPrice = weekendPriceObj.avg_price
}
def curPrice = weekendPriceObj.avg_price
if(weekendPriceObj.value_type!=1){
if(dist.city == "福州"){
@@ -198,7 +194,7 @@ class DistrictSellStatBatch extends BaseBatch {
data.put("commid", dist._id.toString())
data.put("mom", mom)
data.put("yoy", yoy)
data.put("avg_price", weekendPriceObj.avg_price)
data.put("avg_price",curPrice)
data.put("value_type", weekendPriceObj.value_type)
data.put("credit", weekendPriceObj.credit)
DISTRICT_SELL_STAT.update(new BasicDBObject("_id", curPriceObj._id) , new BasicDBObject('$set', data),true,false)
@@ -228,10 +224,10 @@ class DistrictSellStatBatch extends BaseBatch {
} finally {
latch.countDown()
}
// };
// })
};
})
}
// latch.await()
latch.await()
}
@@ -0,0 +1,53 @@
package com.fangjia.script.gj
import com.fangjia.script.util.ExcelUtils
import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
import java.util.concurrent.CountDownLatch
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicLong
DBCollection DISTRICT_SELL_STAT = MongoUtils.getCollectionByName("fangjia_stat", "district_sell_stat", "mongo.db.fangjia.com")
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(20)
File file = new File("d:\\Êý¾Ý\\ÃÀÍÅ\\FJW_COMM_20230815.csv");
def rows = [];
file.eachLine{
def d = it.split("@",-1)
if(d[1] && d[1]!='¸£ÖÝ' && d[7] && d[7].isNumber()){
rows << d
}
}
println rows.size()
def totalCount = new AtomicLong()
final CountDownLatch latch = new CountDownLatch(rows.size())
for(def i=0;i<rows.size();i++){
final def d = rows[i]
fixedThreadPool.execute(new Runnable() {
void run() {
try{
totalCount.addAndGet(1)
def q = new BasicDBObject()
q.put("city", d[1])
q.put("region", d[2])
q.put("district_name", d[3])
q.put("date", 202307)
def udata = new BasicDBObject()
udata.put("avg_price", d[7].toString().toDouble().toInteger())
udata.put("m_date", new Date())
DISTRICT_SELL_STAT.update(q, new BasicDBObject('$set', udata), false, true)
println totalCount.get() +" "+d[1] + " "+d[3]
} catch (Exception e) {
e.printStackTrace()
} finally {
latch.countDown()
}
}
});
}
latch.await()