From d9de74472f1c512e7296542902d71cc2e24b92b6 Mon Sep 17 00:00:00 2001 From: yangkai Date: Thu, 27 Jun 2019 16:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99datav=E6=8F=90=E4=BE=9B=E9=A3=9E?= =?UTF-8?q?=E7=BA=BF=E5=B1=82=E6=95=B0=E6=8D=AE=E3=80=81=E5=95=86=E5=AE=B6?= =?UTF-8?q?=E5=88=86=E5=B8=83=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/datav/core/DatavService.java | 12 ++ .../datav/core/Impl/DatavServiceImpl.java | 119 ++++++++++++++++++ .../manage/datav/web/DatavController.java | 36 ++++++ .../manage/mappers/payment/OrderMapper.java | 2 + .../system/ClientAndCustomerLocation.java | 17 +++ .../manage/task/OrderIpAnalysisTask.java | 25 ++++ .../manage/mappers/payment/OrderMapper.xml | 18 +++ 7 files changed, 229 insertions(+) create mode 100644 src/main/java/au/com/royalpay/payment/manage/datav/core/DatavService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/datav/core/Impl/DatavServiceImpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/datav/web/DatavController.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientAndCustomerLocation.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/task/OrderIpAnalysisTask.java diff --git a/src/main/java/au/com/royalpay/payment/manage/datav/core/DatavService.java b/src/main/java/au/com/royalpay/payment/manage/datav/core/DatavService.java new file mode 100644 index 000000000..394fe9c0a --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/datav/core/DatavService.java @@ -0,0 +1,12 @@ +package au.com.royalpay.payment.manage.datav.core; + + +import com.alibaba.fastjson.JSONObject; + +import java.util.List; + +public interface DatavService { + List merchantByIndustry(); + + void transactionLoc(); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/datav/core/Impl/DatavServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/datav/core/Impl/DatavServiceImpl.java new file mode 100644 index 000000000..ae4015685 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/datav/core/Impl/DatavServiceImpl.java @@ -0,0 +1,119 @@ +package au.com.royalpay.payment.manage.datav.core.Impl; + +import au.com.royalpay.payment.manage.analysis.core.PartnersAnalysisService; +import au.com.royalpay.payment.manage.datav.core.DatavService; +import au.com.royalpay.payment.manage.mappers.payment.OrderMapper; +import au.com.royalpay.payment.manage.mappers.system.ClientAndCustomerLocation; +import au.com.royalpay.payment.tools.env.PlatformEnvironment; +import cn.yixblog.platform.http.HttpRequestGenerator; +import cn.yixblog.platform.http.HttpRequestResult; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.time.DateUtils; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.annotation.Resource; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class DatavServiceImpl implements DatavService { + + @Resource + private PartnersAnalysisService partnersAnalysisService; + @Resource + private OrderMapper orderMapper; + @Resource + private ClientAndCustomerLocation clientAndCustomerLocation; + @Override + public List merchantByIndustry() { + List partnersTypesAnalysis = partnersAnalysisService.getPartnersTypesAnalysis(new JSONObject()); + List analysis = new ArrayList<>(); + JSONObject result; + for(JSONObject partner : partnersTypesAnalysis) { + result = new JSONObject(); + result.put("value", partner.getIntValue("count_value")); + switch (partner.getIntValue("mccCode")){ + case 1: + result.put("type", "旅游出行"); + break; + case 2: + result.put("type", "餐饮"); + break; + case 3: + result.put("type", "教育"); + break; + case 4: + result.put("type", "商务咨询"); + break; + case 5: + result.put("type", "传媒"); + break; + case 6: + result.put("type", "医美"); + break; + case 7: + result.put("type", "零售"); + break; + case 8: + result.put("type", "休闲娱乐"); + break; + case 9: + result.put("type", "其他服务类"); + break; + case 10: + result.put("type", "酒店"); + break; + case 11: + result.put("type", "出口贸易"); + break; + case 12: + result.put("type", "家居建材"); + break; + } + analysis.add(result); + } + return analysis; + } + + @Override + public void transactionLoc() { + JSONObject params = new JSONObject(); + long time = 60*60*1000;//60分钟 + Date now = new Date(); + Date beforeDate = new Date(now .getTime() - time);//60分钟前的时间 + params.put("begin", beforeDate); + params.put("end", now); + params.put("limit", 40); + List customerLoc = orderMapper.getClientAndCustomerLoc(params); + JSONObject obj; + for (JSONObject customer : customerLoc) { + //判断数据库是否已经存在该条ip解析 + obj = clientAndCustomerLocation.findByIp(customer.getString("customer_ip")); + if (obj == null) { + try { + HttpRequestResult result = new HttpRequestGenerator("https://ipinfo.io/" + customer.getString("customer_ip") +"/json?token=7fac65b5953bb1", RequestMethod.GET).execute(); + if (result.isSuccess()) { + obj = result.getResponseContentJSONObj(); + String[] locArr = obj.getString("loc").split(","); + obj.put("ip_longitude", locArr[1]); + obj.put("ip_latitude", locArr[0]); + obj.put("moniker_longitude", customer.getString("longitude")); + obj.put("moniker_latitude", customer.getString("latitude")); + } + } catch (IOException | URISyntaxException e) { + e.printStackTrace(); + } + } + + if (obj != null && !customer.getString("order_id").equals(obj.get("order_id"))) { + obj.put("order_id", customer.getString("order_id")); + obj.put("create_time", new Date()); + clientAndCustomerLocation.save(obj); + } + } + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/datav/web/DatavController.java b/src/main/java/au/com/royalpay/payment/manage/datav/web/DatavController.java new file mode 100644 index 000000000..34155a772 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/datav/web/DatavController.java @@ -0,0 +1,36 @@ +package au.com.royalpay.payment.manage.datav.web; + + +import au.com.royalpay.payment.manage.datav.core.DatavService; +import com.alibaba.fastjson.JSONObject; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +@RestController +@RequestMapping("/api/v1.0/datav") +public class DatavController { + + @Resource + private DatavService datavService; + + /** + * 各类型商家分布 + * @return + */ + @RequestMapping("/merchant/industry") + public List getMerchantAnalysisByIndustry() { + return datavService.merchantByIndustry(); + } + + /** + * 获取支付方与收款方的经纬度 + * @return + */ + @RequestMapping("/payment/loc") + public void getPaymentLonAndLat() { + datavService.transactionLoc(); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java index 88c534e0d..761715ce8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java @@ -71,4 +71,6 @@ public interface OrderMapper { List listNewYearOrdersByOpenId(@Param("customer_id") String open_id,@Param("transaction_date") String date); List listGatewayByClientId(@Param("client_id") int clientId); + + List getClientAndCustomerLoc(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientAndCustomerLocation.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientAndCustomerLocation.java new file mode 100644 index 000000000..c9a560b25 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientAndCustomerLocation.java @@ -0,0 +1,17 @@ +package au.com.royalpay.payment.manage.mappers.system; + +import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; +import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; +import cn.yixblog.support.mybatis.autosql.annotations.SqlType; +import com.alibaba.fastjson.JSONObject; +import org.apache.ibatis.annotations.Param; + +@AutoMapper(tablename = "sys_clients_customer_locations", pkName = {"id"}) +public interface ClientAndCustomerLocation { + + @AutoSql(type = SqlType.SELECT) + JSONObject findByIp(@Param(value = "ip") String ip); + + @AutoSql(type = SqlType.INSERT) + void save(JSONObject params); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/task/OrderIpAnalysisTask.java b/src/main/java/au/com/royalpay/payment/manage/task/OrderIpAnalysisTask.java new file mode 100644 index 000000000..aae5981af --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/task/OrderIpAnalysisTask.java @@ -0,0 +1,25 @@ +package au.com.royalpay.payment.manage.task; + +import au.com.royalpay.payment.manage.datav.core.DatavService; +import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@ConditionalOnProperty(value = "app.run-tasks", havingValue = "true") +public class OrderIpAnalysisTask { + @Resource + private DatavService datavService; + @Resource + private SynchronizedScheduler synchronizedScheduler; + + @Scheduled(cron = "0 0 */1 * * ?") + public void ipAnalysis() { + synchronizedScheduler.executeProcess("datav_task:ip_analysis", 300_000, () -> { + datavService.transactionLoc(); + }); + } +} diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml index e5f0f0017..79ede0a7b 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml @@ -852,4 +852,22 @@ AND client_id = #{client_id} GROUP BY gateway + +