From 082f7fff2080af428ca5b91ec2c472ff9dc32575 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 19:42:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/poi/SeaweedPoiDetail.groovy | 15 +++---- .../temp/shenjian/util/CommonDtoUtils.groovy | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy index dbdd337aa..3ae943007 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject import com.fangjia.script.lixue.util.DBUtils import com.fangjia.script.statistics.poi.AmapPoi import com.fangjia.script.statistics.poi.AmapPoiDetail +import com.fangjia.script.temp.shenjian.util.CommonDtoUtils import com.fangjia.script.temp.shenjian.util.GaoDeUtils import com.fangjia.script.temp.shenjian.util.HttpUtils import com.fangjia.script.temp.shenjian.util.SeaweedUtils @@ -81,13 +82,13 @@ class SeaweedPoiDetail { pois = GaoDeUtils.searchPoi(city, name, region, typecodes) } - List detailList = new ArrayList<>() - for (AmapPoi amapPoi : pois) { - List amapPoiList = GaoDeUtils.getAmapDetailById(amapPoi.getId()); - if (CollectionUtils.isNotEmpty(amapPoiList)) { - detailList.addAll(amapPoiList) - } - } + List detailList = CommonDtoUtils.transformListV(AmapPoiDetail.class, pois); +// for (AmapPoi amapPoi : pois) { +// List amapPoiList = GaoDeUtils.getAmapDetailById(amapPoi.getId()); +// if (CollectionUtils.isNotEmpty(amapPoiList)) { +// detailList.addAll(amapPoiList) +// } +// } if (CollectionUtils.isNotEmpty(detailList)) { String jsonStr = JSONObject.toJSONString(detailList) HttpUtils.postForJson(URL, jsonStr) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy new file mode 100644 index 000000000..89dda4684 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy @@ -0,0 +1,40 @@ +package com.fangjia.script.temp.shenjian.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +/** + * 通用实体与DTO互相转换工具类 + * + * @author shenjian + * @date 2021/06/16 + */ +public class CommonDtoUtils { + + public static T transformV(Class targetClass, Object source) { + if (source == null) { + return null; + } else { + try { + String jsonSource = JSON.toJSONString(source); + return JSONObject.parseObject(jsonSource, targetClass); + } catch (Exception var3) { + throw var3; + } + } + } + + public static List transformListV(Class targetClass, List listSource) { + if (listSource == null) { + return null; + } else { + try { + String jsonSource = JSON.toJSONString(listSource); + return JSONArray.parseArray(jsonSource, targetClass); + } catch (Exception var3) { + throw var3; + } + } + } +} \ No newline at end of file