@ -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.beans.ClientRateQueryBean ;
import au.com.royalpay.payment.manage.analysis.core.ClientRatesAnalysisService ;
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.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.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.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.merchants.core.ClientManager ;
import au.com.royalpay.payment.manage.organizations.core.OrgManager ;
import au.com.royalpay.payment.manage.organizations.core.OrgManager ;
import au.com.royalpay.payment.tools.exceptions.BadRequestException ;
import au.com.royalpay.payment.tools.exceptions.BadRequestException ;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole ;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
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.StringUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
import org.apache.commons.lang3.time.DateUtils ;
import org.apache.commons.lang3.time.DateUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.util.Assert ;
import org.springframework.util.Assert ;
import org.springframework.web.bind.annotation.RequestParam ;
import java.text.ParseException ;
import java.text.ParseException ;
import java.util.ArrayList ;
import java.util.ArrayList ;
@ -45,6 +52,13 @@ public class ClientRatesAnalysisServiceImpl implements ClientRatesAnalysisServic
@Resource
@Resource
private OrgManager orgManager ;
private OrgManager orgManager ;
@Resource
private OrgMapper orgMapper ;
@Resource
private ClientBDMapper clientBDMapper ;
@Resource
private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper ;
@Override
@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 ( ) ;
JSONObject params = new JSONObject ( ) ;
@ -62,7 +76,42 @@ public class ClientRatesAnalysisServiceImpl implements ClientRatesAnalysisServic
params . put ( "end" , DateFormatUtils . format ( endDate , "yyyy-MM-dd" ) ) ;
params . put ( "end" , DateFormatUtils . format ( endDate , "yyyy-MM-dd" ) ) ;
orgManager . checkOrgIds ( manager , params ) ;
orgManager . checkOrgIds ( manager , params ) ;
JSONObject result = new JSONObject ( ) ;
JSONObject result = new JSONObject ( ) ;
List < JSONObject > bdAnalysis = clientRatesAnalysisMapper . analysisRatesForBDUsers ( params ) ;
// 原 数据直接查询
// List<JSONObject> bdAnalysis = clientRatesAnalysisMapper.analysisRatesForBDUsers(params);
// result.put("bds", bdAnalysis);
// 新 数据查询
// 根据时间查询所有的商户交易量
List < JSONObject > clientOrders = customerAndOrdersStatisticsMapper . findByTime ( params ) ;
// 查询所有的组织
PageBounds sort = new PageBounds ( Order . formString ( "sort_no.asc" ) ) ;
List < JSONObject > orgList = orgMapper . listOrgs ( 0 , sort ) ;
List < JSONObject > bdAnalysis = new ArrayList < > ( ) ;
// 查询组织下所有的bd
for ( JSONObject org : orgList ) {
List < JSONObject > bds = managerMapper . findBdById ( org . getString ( "org_id" ) ) ;
for ( JSONObject bd : bds ) {
// 查出bd下的所有的商户, 不为null的 set进 bdAnalysis
List < JSONObject > 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 ( "bds" , bdAnalysis ) ;
result . put ( "total" , clientRatesAnalysisMapper . analysisTotal ( params ) ) ;
result . put ( "total" , clientRatesAnalysisMapper . analysisTotal ( params ) ) ;
return result ;
return result ;