fix 重构最近未交易子商户号逻辑\新增最后交易时间\时间区间选择

master
luoyang 6 years ago
parent 8257104937
commit b331a217a5

@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
@ -44,5 +45,7 @@ public interface ClientAnalysisMapper {
List<JSONObject> notTradeSubMerchantId();
List<JSONObject> tradeSubMerchantIdBy60Days(@Param("begin")Date begin);
List<JSONObject> countClientsSettlementCycle(JSONObject params);
}

@ -1,11 +1,13 @@
package au.com.royalpay.payment.manage.mappers.client;
import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect;
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 com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@ -14,6 +16,8 @@ public interface ClientSubMerchantIdMapper {
@AutoSql(type = SqlType.SELECT)
List<JSONObject> listSubMerchantId(PageBounds pageBounds);
List<JSONObject> listSubMerchantIdByDiffDays(@Param("begin") int begin,@Param("end") int end);
@AutoSql(type = SqlType.INSERT)
void save(JSONObject subMerchantId);
@ -22,4 +26,7 @@ public interface ClientSubMerchantIdMapper {
@AutoSql(type = SqlType.DELETE)
void delete(@Param("sub_merchant_id") String sub_merchant_id);
@AutoSql(type = SqlType.DELETE)
void deleteAll();
}

@ -13,7 +13,7 @@ public interface MerchantIdManageService {
void generateClientsSunMerchantId();
JSONObject listNotTradeSubMerchantId(JSONObject manager);
JSONObject listNotTradeSubMerchantId(int type, JSONObject manager);
List<JSONObject> showClientMoniker(JSONObject manager,String sub_merchant_id);

@ -19,19 +19,18 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -66,22 +65,41 @@ public class MerchantIdManageServiceImpl implements MerchantIdManageService {
return getClientMap(clients);
}
@Override
public JSONObject listNotTradeSubMerchantId(JSONObject manager) {
List<JSONObject> clients = clientSubMerchantIdMapper.listSubMerchantId(new PageBounds(Order.formString("create_time.desc")));
public JSONObject listNotTradeSubMerchantId(int type, JSONObject manager) {
List<JSONObject> clients = new ArrayList<>();
switch (type) {
case 0: //all
clients = clientSubMerchantIdMapper.listSubMerchantId(new PageBounds(Order.formString("diff_days.desc")));
break;
case 1://0~15天
clients = clientSubMerchantIdMapper.listSubMerchantIdByDiffDays(0,15);
break;
case 2://15~30天
clients = clientSubMerchantIdMapper.listSubMerchantIdByDiffDays(15,30);
break;
case 3://30~45天
clients = clientSubMerchantIdMapper.listSubMerchantIdByDiffDays(30,45);
break;
case 4://45~60天
clients = clientSubMerchantIdMapper.listSubMerchantIdByDiffDays(45,60);
break;
default:
break;
}
Map<String, List<JSONObject>> merchantIdMap = clients.stream().filter(t->t.containsKey("merchant_id")).filter(t->t.containsKey("sub_merchant_id")).collect(Collectors.groupingBy(t->t.getString("merchant_id")));
JSONObject returnJason = new JSONObject();
returnJason.put("merchant_id_map",merchantIdMap);
returnJason.put("refresh_time",clients.size()>0?clients.get(0).getDate("create_time"):"");
return returnJason;
}
@Override
public void generateClientsSunMerchantId() {
//重构未交易商户号逻辑
String tempSubMerchantIds = sysConfigManager.getSysConfig().getString("temp_sub_mch_id");
List<JSONObject> clients = clientAnalysisMapper.notTradeSubMerchantId();
List<JSONObject> clientSubMerchantId = clientSubMerchantIdMapper.listSubMerchantId(new PageBounds(Order.formString("create_time.desc")));
Map<String, JSONObject> subMerchantIdMapFromDB = new HashMap<>();
for (JSONObject id : clientSubMerchantId) {
subMerchantIdMapFromDB.put(id.getString("sub_merchant_id"), id);
List<JSONObject> clients = clientAnalysisMapper.tradeSubMerchantIdBy60Days(DateUtils.addDays(new Date(), -60));
if (clients.size() > 0) {
clientSubMerchantIdMapper.deleteAll();
}
for (JSONObject client: clients) {
String subMerchantId = client.getString("sub_merchant_id");
@ -90,15 +108,7 @@ public class MerchantIdManageServiceImpl implements MerchantIdManageService {
}
String id = client.getString("sub_merchant_id");
client.put("create_time",new Date());
if (subMerchantIdMapFromDB.containsKey(id)) {
subMerchantIdMapFromDB.remove(id);
clientSubMerchantIdMapper.update(client);
} else {
clientSubMerchantIdMapper.save(client);
}
}
for (String id : subMerchantIdMapFromDB.keySet()) {
clientSubMerchantIdMapper.delete(id);
clientSubMerchantIdMapper.save(client);
}
}

@ -38,8 +38,8 @@ public class MerchantIdManageController {
@RequestMapping(method = RequestMethod.GET,value = "/trade")
@RequireManager(role = {ManagerRole.OPERATOR})
public JSONObject listNotTradeSubMerchantId(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
return merchantIdManageService.listNotTradeSubMerchantId(manager);
public JSONObject listNotTradeSubMerchantId(int type,@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
return merchantIdManageService.listNotTradeSubMerchantId(type, manager);
}
@RequestMapping(method = RequestMethod.POST,value = "/refresh")

@ -251,6 +251,26 @@
]]>
GROUP by c.sub_merchant_id
</select>
<select id="tradeSubMerchantIdBy60Days" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT COUNT(DISTINCT c.client_id) client_count,
c.sub_merchant_id,
c.merchant_id,
tmp.create_time last_trade_time,
datediff(now(), tmp.create_time) diff_days
FROM sys_clients c INNER JOIN (SELECT sub_merchant_id, max(create_time) create_time
FROM pmt_orders where status>=5 and create_time>=#{begin} and create_time<=now()
and channel='Wechat'
GROUP BY sub_merchant_id
) tmp on c.sub_merchant_id = tmp.sub_merchant_id
WHERE
c.sub_merchant_id IS not null AND c.merchant_id IS NOT NULL
AND (c.approve_result = 1 OR c.approve_result= 2) AND c.is_valid = 1
AND c.enable_wechat = 1
]]>
GROUP BY c.sub_merchant_id ORDER BY diff_days desc
</select>
<select id="countClientsSettlementCycle" resultType="com.alibaba.fastjson.JSONObject">
SELECT COUNT(DISTINCT c.client_id) client_count,

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="au.com.royalpay.payment.manage.mappers.client.ClientSubMerchantIdMapper">
<select id="listSubMerchantIdByDiffDays" resultType="com.alibaba.fastjson.JSONObject">
select * from cli_sub_merchant_id
where diff_days >=#{begin}
and diff_days &lt;=#{end}
order by diff_days desc
</select>
</mapper>

@ -92,9 +92,10 @@ define(['angular', 'static/commons/commons', 'uiBootstrap', 'uiRouter', 'ngBootS
// 初始化索引是30
$scope.initEndIndex = 30;
$scope.loadNotTradeClient = function () {
$scope.loadNotTradeClient = function (type) {
$scope.disable_button = true;
$http.get('/sys/merchant_id/trade').then(function (resp) {
$http.get('/sys/merchant_id/trade?type=' + type).then(function (resp) {
$scope.notTradeClientsMap = resp.data.merchant_id_map;
$scope.refresh_time = resp.data.refresh_time;
$scope.disable_button = false;
@ -110,12 +111,12 @@ define(['angular', 'static/commons/commons', 'uiBootstrap', 'uiRouter', 'ngBootS
}
});
};
$scope.loadNotTradeClient();
$scope.loadNotTradeClient(0);
$scope.refresh = function () {
$scope.disable_button = true;
$http.post('/sys/merchant_id/refresh').then(function () {
$scope.loadNotTradeClient();
$scope.loadNotTradeClient(0);
});
};

@ -67,7 +67,7 @@
<a ui-sref="merchant_id_manage">商户号列表</a>
</li>
<li ui-sref-active="active">
<a ui-sref=".no_trace_list">25天未交易商户号</a>
<a ui-sref=".no_trace_list">60天未交易商户号</a>
</li>
<li ui-sref-active="active">
<a ui-sref=".temp_list">通用子商户号</a>

@ -2,6 +2,26 @@
<div class="box-body">
<div class="col-sm-12 col-xs-12" style="padding-right: 30px;margin-bottom: 5px">
<div class="pull-right">
<div class="btn-group">
<a role="button" class="btn btn-default btn-sm"
ng-click="loadNotTradeClient(0)">ALL</a>
</div>
<div class="btn-group">
<a role="button" class="btn btn-default btn-sm"
ng-click="loadNotTradeClient(1)">0-15天</a>
</div>
<div class="btn-group">
<a role="button" class="btn btn-default btn-sm"
ng-click="loadNotTradeClient(2)">15-30天</a>
</div>
<div class="btn-group">
<a role="button" class="btn btn-default btn-sm"
ng-click="loadNotTradeClient(3)">30-45天</a>
</div>
<div class="btn-group">
<a role="button" class="btn btn-default btn-sm"
ng-click="loadNotTradeClient(4)">45-60天</a>
</div>
<span ng-if="refresh_time">
<span>上次刷新时间:</span><span><em><b>{{refresh_time}}</b></em></span>
</span>&nbsp;&nbsp;
@ -26,9 +46,9 @@
</a>
-->
<a class="list-group-item col-sm-2 col-xs-6 cursor"
ng-repeat="client in clients.slice(0, endIndexMap[key]) | orderBy:'client_count':true"
ng-repeat="client in clients.slice(0, endIndexMap[key]) | orderBy:'-diff_days'"
ng-click="showClient(client.sub_merchant_id)">
<span>{{client.sub_merchant_id}}&nbsp;
<span>{{client.sub_merchant_id}}&nbsp;<span style="color:green">(last_trade:{{client.last_trade_time|limitTo:10}})</span>
<i class="fa fa-clock-o text-danger"
title="Temp Sub Merchant ID"
ng-if="client.temp_sub_merchant">

Loading…
Cancel
Save