建行数据导出
This commit is contained in:
@@ -147,4 +147,18 @@ class CcbCodeUtils {
|
||||
static def getHouseStructureCode(){
|
||||
return null
|
||||
}
|
||||
|
||||
//租赁方式 整租:0 合租:1 转租:2
|
||||
static def getRentTypeCode(def rentType){
|
||||
if(rentType){
|
||||
if(rentType.contains("整租")){
|
||||
return 0;
|
||||
}else if(rentType.contains("合租")){
|
||||
return 1;
|
||||
}else if(rentType.contains("转租")){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,705 @@
|
||||
package com.fangjia.script.gj.ccb
|
||||
|
||||
import com.fangjia.core.RegionData
|
||||
import com.fangjia.core.util.DataUtil
|
||||
import com.fangjia.core.util.DateUtil
|
||||
import com.fangjia.script.commData.CommonDatautils
|
||||
import com.fangjia.script.util.DateUtils
|
||||
import com.fangjia.script.util.DbUtils
|
||||
import com.fangjia.script.util.ElasticUtils
|
||||
import com.fangjia.script.util.ExcelUtils
|
||||
import com.mongodb.BasicDBObject
|
||||
import com.mongodb.DBObject
|
||||
import org.apache.commons.lang.StringUtils
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder
|
||||
import org.elasticsearch.index.query.QueryBuilder
|
||||
import org.elasticsearch.index.query.QueryBuilders
|
||||
import org.elasticsearch.xpack.sql.jdbc.jdbcx.JdbcDataSource
|
||||
|
||||
import java.sql.ResultSet
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
import com.fangjia.script.util.FangJiaAreaMapUtils
|
||||
|
||||
class HouseExport {
|
||||
|
||||
|
||||
public static JdbcDataSource dataSource = new JdbcDataSource()
|
||||
private static final String address = "jdbc:es://http://seawater.es.db.fangjia.com:9200/timezone=UTC&page.size=250&connect.timeout=120s&network.timeout=120s&page.timeout=120s"
|
||||
static {
|
||||
dataSource.setUrl(address)
|
||||
Properties connectionProperties = new Properties()
|
||||
connectionProperties.put("user", "developer")
|
||||
connectionProperties.put("password", "5e8edd851d2fdfbd7415232c67367cc3")
|
||||
dataSource.setProperties(connectionProperties)
|
||||
}
|
||||
|
||||
static def DIRECTIONS = ["东北", "西北", "东南", "西南", "南北", "东西", "东", "南", "西", "北"]
|
||||
private static final HashMap<String, List<String>> FITMENTS_TYPES_MAPS = new HashMap<String, List<String>>()
|
||||
static{
|
||||
FITMENTS_TYPES_MAPS.put("毛坯", ["毛坯", "清水", "无装修", "独栋毛坯", "毛胚", "白坯", "旧装", "坯", "原房", "毛坏"])
|
||||
FITMENTS_TYPES_MAPS.put("简装", ["简装", "普通装修", "普通", "简单装修", "简易装修", "普装", "一般装修", "一般", "简", "粗装修"])
|
||||
FITMENTS_TYPES_MAPS.put("精装", ["精装", "全装修", "全装", "中等装修", "中装", "中档装修", "精致装修", "中档", "中等", "精", "中修", "优质装修", "时尚装修", "良装", "中高挡"])
|
||||
FITMENTS_TYPES_MAPS.put("豪装", ["豪华装修", "高档", "豪华", "豪装", "高级装修", "高装", "奢侈"])
|
||||
}
|
||||
|
||||
|
||||
public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(30)
|
||||
static def totalCount = new AtomicLong()
|
||||
|
||||
def cityCodeMap = ["北京":"110100","重庆":"500100", "哈尔滨":"230100"]
|
||||
def regionCodeMap = [:]
|
||||
|
||||
static main(args) {
|
||||
def task = new HouseExport();
|
||||
|
||||
task.run()
|
||||
|
||||
}
|
||||
|
||||
def run(){
|
||||
|
||||
def city = "重庆"
|
||||
getRegionCodeByCity(city)
|
||||
def districts = CommonDatautils.findAllDistricts(city, "district", ["city", "region", "name", "alias","finish_building_date","house_property","property_life","build_type","estate_type2","build_structure"]);
|
||||
|
||||
|
||||
exportSellCSV(city, districts);
|
||||
// exportRentCSV(city, districts);
|
||||
|
||||
}
|
||||
|
||||
def exportSellCSV(city, districts){
|
||||
final CountDownLatch latch = new CountDownLatch(districts.size())
|
||||
println city +" 小区量:"+districts.size()
|
||||
def datas = []
|
||||
|
||||
def retMap = new ConcurrentHashMap()
|
||||
for(def i=0;i<districts.size();i++){
|
||||
final def rMap = districts[i];
|
||||
fixedThreadPool.execute(new Runnable() {
|
||||
void run() {
|
||||
try {
|
||||
totalCount.addAndGet(1)
|
||||
def ret = findHouses(city, "sell", 20170801,20180901, rMap.name, rMap.alias)
|
||||
if(ret){
|
||||
def cityCode = cityCodeMap.get(city)
|
||||
def regionCode = regionCodeMap.get(city +"-"+rMap.region)
|
||||
def buildYear = CcbCodeUtils.parseBuildYear(rMap.finish_building_date)
|
||||
def housePro = CcbCodeUtils.parseHouseProperty(rMap.house_property)
|
||||
def propertyYear = CcbCodeUtils.parseHousePropertyYear(rMap.property_life)
|
||||
def estateType = CcbCodeUtils.parseHouseEstateType(rMap.build_type);
|
||||
def struCode = CcbCodeUtils.getBuildStructureCode(rMap.build_structure);
|
||||
for(def m : ret){
|
||||
m.city_code = cityCode
|
||||
m.region_code = regionCode
|
||||
m.district_id = rMap.get("_id").toString()
|
||||
m.district_name = rMap.name
|
||||
m.build_year = buildYear;
|
||||
m.proptype = housePro
|
||||
m.propyears = propertyYear;
|
||||
m.estate_type = estateType
|
||||
m.house_type = CcbCodeUtils.getHouseTypeCode(rMap.estate_type2, m.room, m.hall);
|
||||
m.direction_code = CcbCodeUtils.getDirectionCode(m.direction)
|
||||
m.fitment_code = CcbCodeUtils.getFitmentCode(m.fitment);
|
||||
m.build_structure_code = struCode
|
||||
m.house_structure_code = null//getHouseStructureCode();
|
||||
m.source = "fjw"
|
||||
retMap.put(m.houseId, m)
|
||||
}
|
||||
}
|
||||
println totalCount.get() +" "+city+" "+rMap.region+" "+rMap.name+" size:"+ret.size()+" "+new Date().toLocaleString()
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
latch.countDown()
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
latch.await()
|
||||
println " 去重后:"+retMap.values()
|
||||
def allDatas = createSellDatas(retMap.values());
|
||||
def headers = ["城市ID","出售ID","挂牌房屋ID","城市名称","行政区ID","行政区名称","小区ID","小区名称","楼栋ID","楼栋编号","楼栋名称","单元ID","单元编号","单元名称","户ID","详细地址","建筑年代","权属","权属年限","单价","总价","出售付款方式","所在楼层","总楼层","建筑类型","室内结构","建筑结构","建筑面积","套内面积","户型","室","厅","厨","卫","朝向","装修情况","是否有电梯","几梯几户","发布时间","到期时间","是否首发","房源数据来源","中介公司ID","中介公司名称","发布人","发布人电话","描述信息","备注","创建时间","更新时间","来源公司"]
|
||||
batchCreateFile(allDatas, "d:\\数据\\建行\\bigdata_forsale_${cityCodeMap[city]}.csv",headers, "utf-8");
|
||||
println city +" [sell]生成完成!"
|
||||
|
||||
}
|
||||
|
||||
|
||||
def exportRentCSV(city, districts){
|
||||
final CountDownLatch latch = new CountDownLatch(districts.size())
|
||||
println city +" 小区量:"+districts.size()
|
||||
|
||||
|
||||
def retMap = new ConcurrentHashMap()
|
||||
for(def i=0;i<districts.size();i++){
|
||||
final def rMap = districts[i];
|
||||
fixedThreadPool.execute(new Runnable() {
|
||||
void run() {
|
||||
try {
|
||||
totalCount.addAndGet(1)
|
||||
def ret = findHouses(city, "rent", 20170801,20180901, rMap.name, rMap.alias)
|
||||
if(ret){
|
||||
def cityCode = cityCodeMap.get(city)
|
||||
def regionCode = regionCodeMap.get(city +"-"+rMap.region)
|
||||
def buildYear = CcbCodeUtils.parseBuildYear(rMap.finish_building_date)
|
||||
def housePro = CcbCodeUtils.parseHouseProperty(rMap.house_property)
|
||||
def propertyYear = CcbCodeUtils.parseHousePropertyYear(rMap.property_life)
|
||||
def estateType = CcbCodeUtils.parseHouseEstateType(rMap.build_type);
|
||||
def struCode = CcbCodeUtils.getBuildStructureCode(rMap.build_structure);
|
||||
for(def m : ret){
|
||||
m.city_code = cityCode
|
||||
m.region_code = regionCode
|
||||
m.district_id = rMap.get("_id").toString()
|
||||
m.district_name = rMap.name
|
||||
m.build_year = buildYear;
|
||||
m.proptype = housePro
|
||||
m.propyears = propertyYear;
|
||||
m.estate_type = estateType
|
||||
m.house_type = CcbCodeUtils.getHouseTypeCode(rMap.estate_type2, m.room, m.hall);
|
||||
m.direction_code = CcbCodeUtils.getDirectionCode(m.direction)
|
||||
m.fitment_code = CcbCodeUtils.getFitmentCode(m.fitment);
|
||||
m.rent_type_code = CcbCodeUtils.getRentTypeCode(m.rent_type);
|
||||
m.build_structure_code = struCode
|
||||
m.house_structure_code = null//getHouseStructureCode();
|
||||
m.source = "fjw"
|
||||
retMap.put(m.houseId, m)
|
||||
}
|
||||
}
|
||||
|
||||
println totalCount.get() +" "+city+" "+rMap.region+" "+rMap.name+" size:"+ret.size()+" total:"+rMap.size()+" "+new Date().toLocaleString()
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
latch.countDown()
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
latch.await()
|
||||
println " 去重后:"+retMap.values()
|
||||
def allDatas = createRentDatas(retMap.values());
|
||||
def headers = ["城市ID","出售ID","挂牌房屋ID","城市名称","行政区ID","行政区名称","小区ID","小区名称","楼栋ID","楼栋编号","楼栋名称","单元ID","单元编号","单元名称","户ID","详细地址","建筑年代","权属","权属年限","出租面积","单价","总价","租赁方式","出租付款方式","所在楼层","总楼层","建筑类型","室内结构","建筑结构","建筑面积","套内面积","户型","室","厅","厨","卫","朝向","装修情况","是否有电梯","几梯几户","发布时间","到期时间","是否首发","房源数据来源","中介公司ID","中介公司名称","发布人","发布人电话","描述信息","备注","创建时间","更新时间","来源公司"]
|
||||
batchCreateFile(allDatas, "d:\\数据\\建行\\bigdata_forrent_${cityCodeMap[city]}.csv", headers, "utf-8");
|
||||
println city +" [rent]生成完成!"
|
||||
|
||||
}
|
||||
|
||||
def createSellDatas(def list){
|
||||
def datas = []
|
||||
for(def m : list){
|
||||
def data = []
|
||||
data << m.city_code
|
||||
data << m.houseId
|
||||
data << ""
|
||||
data << m.city
|
||||
data << m.region_code
|
||||
data << m.region
|
||||
data << m.district_id
|
||||
data << m.district_name
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << m.address==null?"":m.address==null
|
||||
data << m.build_year==null?"":m.build_year
|
||||
data << m.proptype==null?"":m.proptype
|
||||
data << m.propyears==null?"":m.propyears
|
||||
data << m.avg_price==null?"":m.avg_price
|
||||
data << m.total_price==null?"":m.total_price
|
||||
data << ""
|
||||
data << m.floor==null?"":m.floor
|
||||
data << m.height==null?"":m.height
|
||||
data << m.estate_type==null?"":m.estate_type
|
||||
data << m.house_structure_code==null?"":m.house_structure_code
|
||||
data << m.build_structure_code==null?"":m.build_structure_code
|
||||
data << m.area==null?"":m.area
|
||||
data << ""
|
||||
data << m.house_type==null?"":m.house_type
|
||||
data << m.room==null?"":m.room
|
||||
data << m.hall==null?"":m.hall
|
||||
data << ""
|
||||
data << m.toilet==null?"":m.toilet
|
||||
data << m.direction_code==null?"":m.direction_code
|
||||
data << m.fitment_code==null?"":m.fitment_code
|
||||
data << ""
|
||||
data << ""
|
||||
data << m.p_date==null?"":m.p_date
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << m.c_date==null?"":m.c_date
|
||||
data << m.m_date==null?"":m.m_date
|
||||
data << m.source
|
||||
|
||||
datas << data
|
||||
}
|
||||
return datas ;
|
||||
}
|
||||
|
||||
|
||||
def createRentDatas(def list){
|
||||
def datas = []
|
||||
for(def m : list){
|
||||
def data = []
|
||||
data << m.city_code
|
||||
data << m.houseId
|
||||
data << ""
|
||||
data << m.city
|
||||
data << m.region_code
|
||||
data << m.region
|
||||
data << m.district_id
|
||||
data << m.district_name
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << m.address==null?"":m.address==null
|
||||
data << m.build_year==null?"":m.build_year
|
||||
data << m.proptype==null?"":m.proptype
|
||||
data << m.propyears==null?"":m.propyears
|
||||
data << m.area==null?"":m.area
|
||||
data << m.avg_price==null?"":m.avg_price
|
||||
data << m.total_price==null?"":m.total_price
|
||||
data << m.rent_type_code==null?"":m.rent_type_code
|
||||
data << ""
|
||||
data << m.floor==null?"":m.floor
|
||||
data << m.height==null?"":m.height
|
||||
data << m.estate_type==null?"":m.estate_type
|
||||
data << m.house_structure_code==null?"":m.house_structure_code
|
||||
data << m.build_structure_code==null?"":m.build_structure_code
|
||||
data << m.area==null?"":m.area
|
||||
data << ""
|
||||
data << m.house_type==null?"":m.house_type
|
||||
data << m.room==null?"":m.room
|
||||
data << m.hall==null?"":m.hall
|
||||
data << ""
|
||||
data << m.toilet==null?"":m.toilet
|
||||
data << m.direction_code==null?"":m.direction_code
|
||||
data << m.fitment_code==null?"":m.fitment_code
|
||||
data << ""
|
||||
data << ""
|
||||
data << m.p_date==null?"":m.p_date
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << ""
|
||||
data << m.c_date==null?"":m.c_date
|
||||
data << m.m_date==null?"":m.m_date
|
||||
data << m.source
|
||||
|
||||
datas << data
|
||||
}
|
||||
return datas ;
|
||||
}
|
||||
|
||||
|
||||
def batchCreateFile(ret, fileName, headers,charset){
|
||||
File file = new File(fileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
OutputStream out = new FileOutputStream(fileName);
|
||||
def sb = new StringBuffer();
|
||||
|
||||
sb.append(headers.join("@|@"))
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
|
||||
out.write(sb.toString().getBytes(charset));
|
||||
sb.setLength(0)
|
||||
|
||||
def index = 0
|
||||
for(def row : ret){
|
||||
index++
|
||||
sb.append(StringUtils.join(row.toArray(), "|@|"))
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
println index
|
||||
|
||||
if(index%10000==0){
|
||||
println index+"开始写入CSV "+new Date().toLocaleString()
|
||||
out.write(sb.toString().getBytes(charset));
|
||||
sb.setLength(0)
|
||||
println index+"结束写入CSV "+new Date().toLocaleString()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(sb.length()>0){
|
||||
out.write(sb.toString().getBytes(charset));
|
||||
sb.setLength(0)
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def writeCSV(def list, def path) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file.append("城市ID|@|", "UTF-8")
|
||||
file.append("出售ID|@|", "UTF-8")
|
||||
file.append("挂牌房屋ID|@|", "UTF-8")
|
||||
file.append("城市名称|@|", "UTF-8")
|
||||
file.append("行政区ID|@|", "UTF-8")
|
||||
file.append("行政区名称|@|", "UTF-8")
|
||||
file.append("小区ID|@|", "UTF-8")
|
||||
file.append("小区名称|@|", "UTF-8")
|
||||
file.append("楼栋ID|@|", "UTF-8")
|
||||
file.append("楼栋编号|@|", "UTF-8")
|
||||
file.append("楼栋名称|@|", "UTF-8")
|
||||
file.append("单元ID|@|", "UTF-8")
|
||||
file.append("单元编号|@|", "UTF-8")
|
||||
file.append("单元名称|@|", "UTF-8")
|
||||
file.append("户ID|@|", "UTF-8")
|
||||
file.append("详细地址|@|", "UTF-8")
|
||||
file.append("建筑年代|@|", "UTF-8")
|
||||
file.append("权属|@|", "UTF-8")
|
||||
file.append("权属年限|@|", "UTF-8")
|
||||
file.append("单价|@|", "UTF-8")
|
||||
file.append("总价|@|", "UTF-8")
|
||||
file.append("出售付款方式|@|", "UTF-8")
|
||||
file.append("所在楼层|@|", "UTF-8")
|
||||
file.append("总楼层|@|", "UTF-8")
|
||||
file.append("建筑类型|@|", "UTF-8")
|
||||
file.append("室内结构|@|", "UTF-8")
|
||||
file.append("建筑结构|@|", "UTF-8")
|
||||
file.append("建筑面积|@|", "UTF-8")
|
||||
file.append("套内面积|@|", "UTF-8")
|
||||
file.append("户型|@|", "UTF-8")
|
||||
file.append("室|@|", "UTF-8")
|
||||
file.append("厅|@|", "UTF-8")
|
||||
file.append("厨|@|", "UTF-8")
|
||||
file.append("卫|@|", "UTF-8")
|
||||
file.append("朝向|@|", "UTF-8")
|
||||
file.append("装修情况|@|", "UTF-8")
|
||||
file.append("是否有电梯|@|", "UTF-8")
|
||||
file.append("几梯几户|@|", "UTF-8")
|
||||
file.append("发布时间|@|", "UTF-8")
|
||||
file.append("到期时间|@|", "UTF-8")
|
||||
file.append("是否首发|@|", "UTF-8")
|
||||
file.append("房源数据来源|@|", "UTF-8")
|
||||
file.append("中介公司ID|@|", "UTF-8")
|
||||
file.append("中介公司名称|@|", "UTF-8")
|
||||
file.append("发布人|@|", "UTF-8")
|
||||
file.append("发布人电话|@|", "UTF-8")
|
||||
file.append("描述信息|@|", "UTF-8")
|
||||
file.append("备注|@|", "UTF-8")
|
||||
file.append("创建时间|@|", "UTF-8")
|
||||
file.append("更新时间|@|", "UTF-8")
|
||||
file.append("来源公司|@|", "UTF-8")
|
||||
|
||||
file.append(System.getProperty("line.separator"));
|
||||
def index = 0
|
||||
for(def m : list) {
|
||||
index ++
|
||||
if(index<1000){
|
||||
file.append(m.city_code + "|@|", "UTF-8")
|
||||
file.append(m.houseId + "|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append(m.city+"|@|", "UTF-8")
|
||||
file.append(m.region_code+"|@|", "UTF-8")
|
||||
file.append(m.region+"|@|", "UTF-8")
|
||||
file.append(m.district_id+"|@|", "UTF-8")
|
||||
file.append(m.district_name+"|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append(m.address+"|@|", "UTF-8")
|
||||
file.append(m.build_year+"|@|", "UTF-8")
|
||||
file.append(m.proptype+"|@|", "UTF-8")
|
||||
file.append(m.propyears+"|@|", "UTF-8")
|
||||
file.append(m.avg_price+"|@|", "UTF-8")
|
||||
file.append(m.total_price+"|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append(m.floor+"|@|", "UTF-8")
|
||||
file.append(m.height+"|@|", "UTF-8")
|
||||
file.append(m.estate_type+"|@|", "UTF-8")
|
||||
file.append( m.house_structure_code+"|@|", "UTF-8")
|
||||
file.append(m.build_structure_code+"|@|", "UTF-8")
|
||||
file.append(m.area+"|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append(m.house_type+"|@|", "UTF-8")
|
||||
file.append(m.room+"|@|", "UTF-8")
|
||||
file.append(m.hall+"|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append(m.toilet+"|@|", "UTF-8")
|
||||
file.append(m.direction_code+"|@|", "UTF-8")
|
||||
file.append(m.fitment_code+"|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append(m.p_date+"|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append("|@|", "UTF-8")
|
||||
file.append(m.c_date+"|@|", "UTF-8")
|
||||
file.append(m.m_date+"|@|", "UTF-8")
|
||||
file.append(m.source+"|@|", "UTF-8")
|
||||
|
||||
file.append(System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getRegionCodeByCity(def city){
|
||||
def datas = FangJiaAreaMapUtils.convertToOfficials(city);
|
||||
for(def d : datas){
|
||||
regionCodeMap.put(city+"-"+d.fangjia_district, d.district_code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def findHouses(def city, def cat, def startDate, def endDate, def name, def alias){
|
||||
|
||||
QueryBuilder date_range = QueryBuilders.rangeQuery("p_date").from(startDate).to(endDate).includeLower(true).includeUpper(false);
|
||||
QueryBuilder area_range = QueryBuilders.rangeQuery("area").from(20).to(500).includeLower(true).includeUpper(false);
|
||||
|
||||
QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery("city", city)).must(QueryBuilders.termQuery("cat", "sell"))
|
||||
.must(date_range).must(area_range)
|
||||
|
||||
if(!alias){
|
||||
alias = []
|
||||
}
|
||||
if(!alias.contains(name)){
|
||||
alias.add(name)
|
||||
}
|
||||
|
||||
if(alias && alias.size()>0){
|
||||
BoolQueryBuilder inBuilder = QueryBuilders.boolQuery();
|
||||
for(def s : alias){
|
||||
inBuilder.should(QueryBuilders.matchQuery("district_name", s));
|
||||
}
|
||||
queryBuilder.must(inBuilder)
|
||||
}
|
||||
|
||||
|
||||
def rets = []
|
||||
def houses = ElasticUtils.executeSimpleQuery("192.168.0.206", "seawater-20*", queryBuilder);
|
||||
if(houses){
|
||||
for (int k=0;k<houses.size();k++) {
|
||||
def map = houses[k];
|
||||
DBObject seawater = new BasicDBObject(map)
|
||||
|
||||
if(!seawater.height){
|
||||
seawater.height = null
|
||||
}
|
||||
if(seawater.height && seawater.height<1){
|
||||
continue;
|
||||
}
|
||||
if(seawater.height && seawater.height>60){
|
||||
continue;
|
||||
}
|
||||
|
||||
// if(!seawater.room){
|
||||
// continue;
|
||||
// }
|
||||
if(seawater.room && (seawater.room>=5 || seawater.room<1)){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!seawater.hall){
|
||||
seawater.hall = null
|
||||
}
|
||||
if(seawater.hall && (seawater.hall>=5 || seawater.hall<1)){
|
||||
continue;
|
||||
}
|
||||
if(!seawater.toilet){
|
||||
seawater.toilet = null
|
||||
}
|
||||
if(seawater.toilet && (seawater.toilet>=5 || seawater.toilet<1)){
|
||||
continue;
|
||||
}
|
||||
|
||||
def floor = parseFloor(seawater.floor_info)
|
||||
if(seawater.height && floor && floor.isNumber()){
|
||||
if(floor.toInteger()>seawater.height){
|
||||
floor = null
|
||||
seawater.height = null
|
||||
}
|
||||
}
|
||||
|
||||
def rowMap = [:];
|
||||
if(cat == "rent"){
|
||||
rowMap.rent_type = seawater.rent_type
|
||||
}
|
||||
rowMap.houseId = seawater.id
|
||||
rowMap.city = city
|
||||
rowMap.region =seawater.region
|
||||
rowMap.address = seawater.address
|
||||
|
||||
|
||||
rowMap.area = seawater.area
|
||||
rowMap.total_price = seawater.total_price
|
||||
rowMap.avg_price = seawater.avg_price
|
||||
rowMap.height = seawater.height=="null"?null:seawater.height
|
||||
rowMap.floor = floor=="null"?null:floor
|
||||
rowMap.room = seawater.room=="null"?null:seawater.room
|
||||
rowMap.hall = seawater.hall=="null"?null:seawater.hall
|
||||
rowMap.toilet = seawater.toilet=="null"?null:seawater.toilet
|
||||
|
||||
def direction = parseDirection(seawater.direction)
|
||||
rowMap.direction = direction=="null"?null:direction
|
||||
|
||||
def fitment = parseFitment(seawater.fitment)
|
||||
rowMap.fitment = fitment=="null"?null:fitment
|
||||
|
||||
rowMap.p_date = DateUtils.formatDateByPattern(DateUtils.parseFromTightYYYYMMDD2(seawater.p_date.toString()), "yyyy-MM-dd HH:mm:ss")
|
||||
rowMap.c_date = DateUtils.getConverDate(seawater.m_date)
|
||||
rowMap.m_date = DateUtils.getConverDate(seawater.m_date)
|
||||
rets << rowMap
|
||||
}
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
static def parseFloor(def floorDesc){
|
||||
if(floorDesc){
|
||||
floorDesc = floorDesc.replaceAll("[\\s ]+", "")
|
||||
if(floorDesc){
|
||||
Pattern pat1 = Pattern.compile("第(\\d{1,2})层");
|
||||
Matcher matcher1 = pat1.matcher(floorDesc);
|
||||
if (matcher1.find()) {
|
||||
return matcher1.group(1)
|
||||
}
|
||||
pat1 = Pattern.compile("(\\d{1,2})层?(/|\\()共?\\d{1,2}(层|F)?");
|
||||
matcher1 = pat1.matcher(floorDesc);
|
||||
if (matcher1.find()) {
|
||||
return matcher1.group(1)
|
||||
}
|
||||
if(floorDesc.contains("中楼层") || floorDesc.contains("中层")){
|
||||
return "中层"
|
||||
}
|
||||
|
||||
if(floorDesc.contains("高楼层") || floorDesc.contains("高层")){
|
||||
return "高层"
|
||||
}
|
||||
|
||||
|
||||
if(floorDesc.contains("低楼层") || floorDesc.contains("低层")){
|
||||
return "低层"
|
||||
}
|
||||
if(floorDesc.isNumber()){
|
||||
return floorDesc;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String csvHandlerStr(String str) {
|
||||
//csv格式如果有逗号,整体用双引号括起来;如果里面还有双引号就替换成两个双引号,这样导出来的格式就不会有问题了
|
||||
String tempDescription=str;
|
||||
//如果有逗号
|
||||
if(str.contains(",")||str.contains(",")){
|
||||
//如果还有双引号,先将双引号转义,避免两边加了双引号后转义错误
|
||||
if(str.contains("\"")){
|
||||
// tempDescription=str.replace("\"", "\"\"");
|
||||
tempDescription=str.replace("\"", "");
|
||||
}
|
||||
//在将逗号转义
|
||||
tempDescription="\""+tempDescription+"\"";
|
||||
}
|
||||
return tempDescription;
|
||||
}
|
||||
|
||||
|
||||
static String parseFitment(String fitmentDesc) {
|
||||
if (fitmentDesc == null) {
|
||||
return null
|
||||
}
|
||||
fitmentDesc = fitmentDesc.replaceAll("[\\s ]+", "")
|
||||
if (fitmentDesc.equals("非毛坯")) {
|
||||
return null
|
||||
}
|
||||
Iterator<Map.Entry<String, List<String>>> it = FITMENTS_TYPES_MAPS
|
||||
.entrySet().iterator()
|
||||
Map.Entry<String, List<String>> entry
|
||||
while (it.hasNext()) {
|
||||
entry = it.next()
|
||||
if (fitmentDesc.contains(entry.getKey())) {
|
||||
return entry.getKey()
|
||||
}
|
||||
for (String fitmentKey : entry.getValue()) {
|
||||
if (fitmentDesc.contains(fitmentKey)) {
|
||||
return entry.getKey()
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
}
|
||||
|
||||
static String parseDirection(String directionDesc) {
|
||||
if (directionDesc == null) {
|
||||
return null
|
||||
}
|
||||
directionDesc = directionDesc.replaceAll("(\\(|(|《|\"|“|【|〔).+?(\\)|》|)|\"|”|】|〕)", "#_#")
|
||||
StringBuffer sb = new StringBuffer()
|
||||
for (int i = 0; i < directionDesc.length(); i++) {
|
||||
String c = directionDesc.substring(i, i + 1)
|
||||
if (DIRECTIONS.contains(c)) {
|
||||
if (directionDesc.substring(i).startsWith(c + "#_#")) {
|
||||
sb.append(c + " ")
|
||||
} else {
|
||||
sb.append(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String d : DIRECTIONS) {
|
||||
if (sb.toString().startsWith(d)) {
|
||||
return d
|
||||
}
|
||||
}
|
||||
for (String d : DIRECTIONS) {
|
||||
if (sb.toString().contains(d)) {
|
||||
return d
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -765,6 +765,19 @@ class DateUtils {
|
||||
long t = currMills + mills;
|
||||
return new Date(t)
|
||||
}
|
||||
|
||||
static String getConverDate(def mills){
|
||||
String s = null
|
||||
if(mills instanceof String){
|
||||
s = mills.replace("T"," ").replace(".000Z","")
|
||||
}else if(mills instanceof Long){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date(mills);
|
||||
s = dateFormat.format(date);
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
static def setToday(d){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
+4
@@ -19,4 +19,8 @@ class FangJiaAreaMapUtils {
|
||||
return (BasicDBObject)FANGJIA_OFFICIAL_AREA_MAP.findOne(new BasicDBObject("district_code", districtCode.toString()))
|
||||
}
|
||||
|
||||
static def convertToOfficials(String city){
|
||||
return FANGJIA_OFFICIAL_AREA_MAP.find(new BasicDBObject("fangjia_city", city).append("district_code", new BasicDBObject('$ne', null)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user