From 6b58f0a85629eeed95a9d400d9c4cfe18d7c5690 Mon Sep 17 00:00:00 2001 From: sjshenjian Date: Thu, 1 Jul 2021 18:19:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EPOI=E6=8A=93=E5=8F=96?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/dingding/ScoreExport.groovy | 3 - .../temp/shenjian/poi/StatisticsPoi.groovy | 59 +++++++++++++++++++ .../temp/shenjian/util/ExcelUtils.groovy | 48 +++++++++++++++ .../temp/shenjian/util/MyStringUtils.groovy | 40 +++++++++++++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/StatisticsPoi.groovy create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/MyStringUtils.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/dingding/ScoreExport.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/dingding/ScoreExport.groovy index 6a10fff7c..2218e2ec6 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/dingding/ScoreExport.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/dingding/ScoreExport.groovy @@ -69,9 +69,6 @@ public class ScoreExport { } if (taskDetail.getRealityEndDate() != null && taskDetail.getRealityEndDate() > monthStartTime && taskDetail.getRealityEndDate() < endTime) { boolean find = false - if (taskDetail.getResponse().getName() == '穆良书' && taskDetail.getName() == "模型级联算法方案设计") { - println('穆良书') - } for (int i = 4; i < sortedResult[0].size(); i++) { // 找到该项目下该负责人,则加工时 if (sortedResult[0][i] == taskDetail.getResponse().getName()) { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/StatisticsPoi.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/StatisticsPoi.groovy new file mode 100644 index 000000000..cc0cb39dd --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/StatisticsPoi.groovy @@ -0,0 +1,59 @@ +package com.fangjia.script.temp.shenjian.poi + +import com.fangjia.script.temp.shenjian.util.MyStringUtils +import com.fangjia.script.util.ElasticUtils +import com.fangjia.script.util.ExcelUtils + +/** + * @author shenjian* @since 2021/7/7 + */ +class StatisticsPoi { + static final cities = ["北京","上海","广州","深圳","重庆","郑州","长沙","西安","成都","东莞","佛山","杭州","合肥","南京", + "青岛","沈阳","苏州","天津","武汉","珠海","中山","长春","扬州","烟台","徐州","无锡","温州","太原", + "台州","石家庄","绍兴","厦门","泉州","宁波","南通","南宁","南昌","兰州","常州","大连","福州","贵阳", + "哈尔滨","海口","惠州","济南","嘉兴","金华","昆明","遵义","淄博","株洲","镇江","肇庆","漳州","湛江", + "岳阳","银川","宜昌","盐城","芜湖","乌鲁木齐","唐山","泰州","汕头","三亚","清远","秦皇岛","马鞍山","洛阳", + "柳州","连云港","廊坊","九江","吉林","淮安","湖州","呼和浩特","沧州","保定","安庆","张家口","西宁","日照", + "拉萨","锦州","大同","常德","北海","文昌","陵水","保亭"] + + + static final types = ['地铁', '公交', '医院', '写字楼', '学校', '银行', '大型超市', '商场', '餐饮', '旅游景点', '图书馆'] + + static void main(String[] args) { + def result = [] + + result << ['城市', '数据量', '地铁', '公交', '医院', '写字楼', '学校', '银行', '大型超市', '商场', '餐饮', '旅游景点', '图书馆'] + for (def city in cities) { + def ret = [] + def total + String sql = "select count(*) total from amap_poi where cityname = '" + city + "' and status <> 1 " + ElasticUtils.executeSqlQuery(sql,{ data-> + total = data.total + }) + ret << city + ret << total + for (def type in types) { + def typeCode = SeaweedAroundPoi.KEYWORDS_MAP.get(type) + def typeCodeArr = typeCode.split("\\|") + String val = "" + String sqlType = "" + if (typeCodeArr[0].size() <= 4) { + val = MyStringUtils.joinLikeSql(typeCodeArr) + sqlType = "select count(*) total from amap_poi where cityname = '" + city + "' and (" + val + ") and status <> 1 " + } else { + val = MyStringUtils.joinInSql(typeCodeArr) + sqlType = "select count(*) total from amap_poi where cityname = '" + city + "' and typecode in (" + val + ") and status <> 1 " + } + + ElasticUtils.executeSqlQuery(sqlType,{ data-> + total = data.total + }) + ret << total + } + result << ret + println(city) + } + + ExcelUtils.write("F:\\工作\\房产估值模型及数据招标\\交付工作\\POI信息抓取情况总结.xlsx", result, "POI统计") + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy new file mode 100644 index 000000000..229499b80 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy @@ -0,0 +1,48 @@ +package com.fangjia.script.temp.shenjian.util + +import com.alibaba.excel.EasyExcelFactory +import com.alibaba.excel.ExcelReader +import com.alibaba.excel.context.AnalysisContext +import com.alibaba.excel.event.AnalysisEventListener + +/** + * excel工具类 + * + * @author shenjian + * @since 2021/5/15 + */ +class ExcelUtils { + + static List> read(String filePath) { + SimpleExcelListener listener = new SimpleExcelListener(filePath); + ExcelReader excelReader = EasyExcelFactory.read(filePath, null, listener).headRowNumber(0).build(); + excelReader.readAll() + List> dataList = listener.getDataList(); + excelReader.finish() + return dataList; + } + + class SimpleExcelListener extends AnalysisEventListener { + + private List> dataList = new ArrayList<>() + + @Override + void invoke(Object o, AnalysisContext analysisContext) { + Map map = o; + dataList.add(new ArrayList(map.values())) + } + + @Override + void doAfterAllAnalysed(AnalysisContext analysisContext) { + + } + + List> getDataList() { + return dataList + } + + void setDataList(List> dataList) { + this.dataList = dataList + } + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/MyStringUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/MyStringUtils.groovy new file mode 100644 index 000000000..36eb6c935 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/MyStringUtils.groovy @@ -0,0 +1,40 @@ +package com.fangjia.script.temp.shenjian.util + +/** + * @author shenjian* @since 2021/7/7 + */ +public class MyStringUtils { + + public static joinSql(String[] str) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < str.size(); i++) { + sb.append("'").append(str[i]).append("'") + if (i != str.size() - 1) { + sb.append(",") + } + } + return sb.toString() + } + + public static joinInSql(String[] str) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < str.size(); i++) { + sb.append("'").append(str[i]).append("'") + if (i != str.size() - 1) { + sb.append(",") + } + } + return sb.toString() + } + + public static joinLikeSql(String[] str) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < str.size(); i++) { + sb.append(" typecode like '").append(str[i]).append("%' ") + if (i != str.size() - 1) { + sb.append(" or ") + } + } + return sb.toString() + } +}