diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ClientRatesAnalysisServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ClientRatesAnalysisServiceImpl.java index e87373d49..758293fa8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ClientRatesAnalysisServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ClientRatesAnalysisServiceImpl.java @@ -3,21 +3,28 @@ package au.com.royalpay.payment.manage.analysis.core.impls; import au.com.royalpay.payment.manage.analysis.beans.ClientRateQueryBean; import au.com.royalpay.payment.manage.analysis.core.ClientRatesAnalysisService; import au.com.royalpay.payment.manage.analysis.mappers.ClientRatesAnalysisMapper; +import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper; import au.com.royalpay.payment.manage.mappers.log.ClientReviewLogMapper; +import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper; import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; +import au.com.royalpay.payment.manage.mappers.system.OrgMapper; import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.organizations.core.OrgManager; import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.permission.enums.ManagerRole; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.Order; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.RequestParam; import java.text.ParseException; import java.util.ArrayList; @@ -45,8 +52,15 @@ public class ClientRatesAnalysisServiceImpl implements ClientRatesAnalysisServic @Resource private OrgManager orgManager; + @Resource + private OrgMapper orgMapper; + @Resource + private ClientBDMapper clientBDMapper; + @Resource + private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper; + @Override - public JSONObject listAnalysisOfBDUsers(JSONObject manager, String orgId, String orgId2,Date beginDate, Date endDate) { + public JSONObject listAnalysisOfBDUsers(JSONObject manager, String orgId, String orgId2, Date beginDate, Date endDate) { JSONObject params = new JSONObject(); if (orgId != null) { params.put("org_id", orgId); @@ -58,11 +72,46 @@ public class ClientRatesAnalysisServiceImpl implements ClientRatesAnalysisServic if (ManagerRole.BD_LEADER.hasRole(manager.getIntValue("role"))) { params.put("bd_group", manager.getString("manager_id")); } - params.put("begin", DateFormatUtils.format(beginDate,"yyyy-MM-dd")); - params.put("end", DateFormatUtils.format(endDate,"yyyy-MM-dd")); - orgManager.checkOrgIds(manager,params); + params.put("begin", DateFormatUtils.format(beginDate, "yyyy-MM-dd")); + params.put("end", DateFormatUtils.format(endDate, "yyyy-MM-dd")); + orgManager.checkOrgIds(manager, params); JSONObject result = new JSONObject(); - List bdAnalysis = clientRatesAnalysisMapper.analysisRatesForBDUsers(params); + // 原 数据直接查询 +// List bdAnalysis = clientRatesAnalysisMapper.analysisRatesForBDUsers(params); +// result.put("bds", bdAnalysis); + + // 新 数据查询 + // 根据时间查询所有的商户交易量 + List clientOrders = customerAndOrdersStatisticsMapper.findByTime(params); + // 查询所有的组织 + PageBounds sort = new PageBounds(Order.formString("sort_no.asc")); + List orgList = orgMapper.listOrgs(0, sort); + + List bdAnalysis = new ArrayList<>(); + // 查询组织下所有的bd + for (JSONObject org : orgList) { + List bds = managerMapper.findBdById(org.getString("org_id")); + for (JSONObject bd : bds) { + // 查出bd下的所有的商户,不为null的 set进 bdAnalysis + List clients = clientBDMapper.findTotalClientByBdId(bd.getString("manager_id")); + // 遍历商户 查看商户交易量 + if (!clients.isEmpty()) { + for (JSONObject client : clients) { + int i = 0; + for (JSONObject clientOrder : clientOrders) { + if (client.getString("client_id").equals(clientOrder.getString("client_id"))) { + // 判断交易量 + if (clientOrder.getInteger("order_count") != 0) { + bd.put("trade_clients", i++); + } + } + } + } + bd.put("total_clients", clients.size()); + bdAnalysis.add(bd); + } + } + } result.put("bds", bdAnalysis); result.put("total", clientRatesAnalysisMapper.analysisTotal(params)); return result; @@ -151,7 +200,7 @@ public class ClientRatesAnalysisServiceImpl implements ClientRatesAnalysisServic params.put("client_ids", clientIds); // result.put("total", clientRatesAnalysisMapper.analysisTotal(params)); - List clients = analysisClientRates(params,query); + List clients = analysisClientRates(params, query); result.put("clients", clients); @@ -165,7 +214,7 @@ public class ClientRatesAnalysisServiceImpl implements ClientRatesAnalysisServic client.put("sleep_days_limited", Math.min(client.getIntValue("sleep_days"), 30)); List events = new ArrayList<>(); for (ClientRateAnalysisEventLoader loader : eventLoaders) { - loader.loadEvents(client, events,query); + loader.loadEvents(client, events, query); } client.put("events", events); } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java index 73af49846..fa5a79a3c 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.java @@ -74,4 +74,6 @@ public interface CustomerAndOrdersStatisticsMapper { int countEnableChannel(JSONObject params); int countEnableAlipay(JSONObject params); + + List findByTime(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.java index b8e390f0b..aa609ab36 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.java @@ -40,4 +40,5 @@ public interface ClientBDMapper { List listBDByOrgId(@Param("org_id") int org_id); + List findTotalClientByBdId(@Param("bd_id")String manager_id); } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.java index 3a5ce6bcb..7617a0226 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.java @@ -70,4 +70,6 @@ public interface ManagerMapper { @Select("select wx_openid from sys_managers where is_valid=1 AND (role & 256 > 0 OR role & 4 > 0) AND (org_id = 1 or org_id is null) AND wx_openid IS NOT NULL") List listDevAndBdOpenId(); + + List findBdById(@Param("org_id")String org_id); } diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml index ea7811073..b223cc6f8 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml @@ -743,4 +743,19 @@ ) + + + + diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.xml index a80c8423e..6b85ccc3c 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientBDMapper.xml @@ -80,4 +80,10 @@ WHERE sysm.org_id = #{org_id} AND sysm.is_valid = 1) + + + + \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.xml index c6d046fd4..bc421783e 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ManagerMapper.xml @@ -102,5 +102,12 @@ ]]> +