commit
f6232423e0
@ -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<JSONObject> merchantByIndustry();
|
||||
|
||||
void transactionLoc();
|
||||
}
|
@ -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<JSONObject> merchantByIndustry() {
|
||||
List<JSONObject> partnersTypesAnalysis = partnersAnalysisService.getPartnersTypesAnalysis(new JSONObject());
|
||||
List<JSONObject> 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<JSONObject> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<JSONObject> getMerchantAnalysisByIndustry() {
|
||||
return datavService.merchantByIndustry();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付方与收款方的经纬度
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/payment/loc")
|
||||
public void getPaymentLonAndLat() {
|
||||
datavService.transactionLoc();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in new issue