第三方均价表修改区域
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
package com.fangjia.script.gj.data_handle
|
||||
|
||||
import com.fangjia.script.commData.CommonDatautils
|
||||
import com.fangjia.script.util.MongoUtils
|
||||
import com.mongodb.BasicDBObject
|
||||
import com.mongodb.DBCollection
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
//更新第三方均价表中小区区域
|
||||
class RegionUpdateBatch {
|
||||
|
||||
public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(50)
|
||||
|
||||
static final DBCollection AVERAGE_STATISTICS = MongoUtils.getCollectionByName("fangjia", "average_statistics", "192.168.0.43")
|
||||
|
||||
static main(args) {
|
||||
def task = new RegionUpdateBatch()
|
||||
task.run()
|
||||
|
||||
}
|
||||
def run(){
|
||||
def citys = CommonDatautils.findAllCity()
|
||||
for(def city : citys){
|
||||
def districtMap = CommonDatautils.findAllDistricMaptByCity(city, "district", ["city","region", "name"])
|
||||
def keys = new BasicDBObject()
|
||||
keys.put("city", 1)
|
||||
keys.put("region", 1)
|
||||
keys.put("name", 1)
|
||||
keys.put("seaweed_id", 1)
|
||||
def statistics = AVERAGE_STATISTICS.find(new BasicDBObject("city", city), keys)
|
||||
def total = statistics.size()
|
||||
final CountDownLatch latch = new CountDownLatch(total)
|
||||
def totalCount = new AtomicLong()
|
||||
for(def i=0;i<statistics.size();i++){
|
||||
final def d = statistics[i]
|
||||
fixedThreadPool.execute(new Runnable() {
|
||||
void run() {
|
||||
try{
|
||||
totalCount.addAndGet(1)
|
||||
def dist = districtMap.get(d.seaweed_id)
|
||||
if(dist && dist.region!=d.region){
|
||||
def udata = new BasicDBObject()
|
||||
udata.put("region", dist.region)
|
||||
AVERAGE_STATISTICS.update(new BasicDBObject("_id", d._id), new BasicDBObject('$set', udata),false,false)
|
||||
}
|
||||
println totalCount.get() + " / "+total + " "+ d.city
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
latch.countDown()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
latch.await()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user