diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/FileUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/FileUtils.groovy new file mode 100644 index 000000000..8c895b5c0 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/FileUtils.groovy @@ -0,0 +1,43 @@ +package com.fangjia.script.gj.ccb + +import org.apache.commons.lang.StringUtils + +class FileUtils { + static 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(); + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/HouseExport.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/HouseExport.groovy index a3bad5266..27f1870bb 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/HouseExport.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/HouseExport.groovy @@ -65,7 +65,7 @@ class HouseExport { def run(){ - def city = "重庆" + 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"]); @@ -318,43 +318,7 @@ class HouseExport { } - 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(); - }