From 43b3a65fc91e8cd501e4270abe1ac7c1a5f3fa36 Mon Sep 17 00:00:00 2001 From: wyj2080 <1603068044@qq.com> Date: Wed, 29 Apr 2020 17:36:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=8F=B8=E5=BA=97=E5=9D=87=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=9F=B1=E7=8A=B6=E5=9B=BE=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ic/customer/entity/CustomerViewVO.java | 3 + .../customer/service/CustomerViewService.java | 65 +++++++++++++++++-- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/kiisoo/ic/customer/entity/CustomerViewVO.java b/src/main/java/com/kiisoo/ic/customer/entity/CustomerViewVO.java index acde79d..8746f74 100644 --- a/src/main/java/com/kiisoo/ic/customer/entity/CustomerViewVO.java +++ b/src/main/java/com/kiisoo/ic/customer/entity/CustomerViewVO.java @@ -27,6 +27,9 @@ public class CustomerViewVO { /**会员总数*/ private Long allVipCount; + /**零售公司店均新增柱状图*/ + List companyShopAverageNewCustomerList; + /**好友list*/ List customerList; /**好友(去重)list*/ diff --git a/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java b/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java index b057088..c8acea2 100644 --- a/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java +++ b/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java @@ -44,6 +44,7 @@ public class CustomerViewService { static final Integer LEVEL_REGION = 1; /**零售公司*/ static final Integer LEVEL_COMPANY = 2; + static final Long LEVEL_COMPANY_L = 2L; /**客户*/ static final Integer LEVEL_CUSTOMER = 3; @@ -114,13 +115,16 @@ public class CustomerViewService { //会员总数 Long vipCount = opVipDOMapper.selectVipCount(shopIds, null, null); - //设置柱状图list + List newCustimerList = customerList.stream().filter(customerDO -> filterCustomerByRegisterTime(customerDO, selectStartTime, selectEndTime)).collect(Collectors.toList()); + //零售公司店均新增 + List shopAverageNewCustomerList = getOrgShopAvgNewCustomerList(newCustimerList, userId); + customerViewVO.setCompanyShopAverageNewCustomerList(shopAverageNewCustomerList); + //设置趋势柱状图list List validCustomerList = customerList.stream().filter(customerDO -> VALID.equals(customerDO.getValidType())).collect(Collectors.toList()); handleChartData(customerList, validCustomerList, customerViewVO); - //设置新增好友,好友总数,拉黑数,vip人数,柱状图list等数据 + //设置新增好友,好友总数,拉黑数,vip人数 setCustomerViewData(customerViewVO, customerCount, validCustomerCount, validDeleteCustomerCount, vipCount, customerList, validCustomerList, selectStartTime, selectEndTime); //前十名排行list等 - List newCustimerList = customerList.stream().filter(customerDO -> filterCustomerByRegisterTime(customerDO, selectStartTime, selectEndTime)).collect(Collectors.toList()); List orgNewCustomerList = getOrgNewCustomerList(newCustimerList); List shopNewCustomerList = getShopNewCustomerList(newCustimerList); List zeroExtendList = getZeroExtendList(newCustimerList, shopIds); @@ -141,7 +145,7 @@ public class CustomerViewService { } /** - * 新增好友,好友总数,拉黑数,vip人数,柱状图list等数据 + * 新增好友,好友总数,拉黑数,vip人数 * @param customerViewVO 客户概览VO * @param customerCount 好友总数 * @param validCustomerCount 好友总数(去重) @@ -228,7 +232,56 @@ public class CustomerViewService { } /** - * 柱状图数据 + * 公司店均新增柱状图 + * @param newCustimerList 好友list + * @param userId 用户id + * @return 公司店均新增list + */ + public List getOrgShopAvgNewCustomerList(List newCustimerList, Long userId){ + List orgShopAvgNewCustomerList = new ArrayList<>(); + //初始化所有零售公司 + List companyList = retailCompanyService.listOfRetailOrg(userId, null, null, null).stream().filter(org -> LEVEL_COMPANY_L.equals(org.getLevel())).distinct().collect(Collectors.toList()); + companyList.forEach(companyDO -> { + CustomerViewCompanyVO companyVO = new CustomerViewCompanyVO(); + companyVO.setOrgId(companyDO.getId()); + companyVO.setOrgName(companyDO.getName()); + companyVO.setNewCustomerCount(0); + orgShopAvgNewCustomerList.add(companyVO); + }); + //店铺id-新增好友数map + Map shopIdCountMap = newCustimerList.stream().collect(Collectors.groupingBy(OpCustomer::getShopId, Collectors.counting())); + //店铺id→零售公司名称 + List shopIds = newCustimerList.stream().map(OpCustomer::getShopId).collect(Collectors.toList()); + if(CollectionUtils.isEmpty(shopIds)){ + return orgShopAvgNewCustomerList; + } + //零售公司id-公司店铺list map + List shopOrgInfoList = getOrgInfoByShopIds(shopIds, true, null); + Map> companyShopListMap = shopOrgInfoList.stream().distinct().collect(Collectors.groupingBy(ShopOrgInfoVO::getCompanyId)); + //每个公司店均新增数 + companyShopListMap.forEach((companyId,companyShopList) -> { + CustomerViewCompanyVO orgViewDO = new CustomerViewCompanyVO(); + orgViewDO.setOrgId(companyId); + orgViewDO.setOrgName(companyShopList.get(0).getCompanyName()); + AtomicInteger newCustomerCount = new AtomicInteger(0); + companyShopList.forEach(companyShopVO -> { + Long shopId = companyShopVO.getShopId(); + int tmpCount = shopIdCountMap.get(shopId) == null ? 0 : Math.toIntExact(shopIdCountMap.get(shopId)); + newCustomerCount.updateAndGet(v -> v + tmpCount); + }); + //平均 + if(companyShopList.size() > 0){ + newCustomerCount.updateAndGet(v -> Math.round(v / (float)companyShopList.size())); + } + orgViewDO.setNewCustomerCount(newCustomerCount.get()); + orgShopAvgNewCustomerList.stream().filter(orgShopAvg -> orgShopAvg.getOrgName().equals(orgViewDO.getOrgName())).forEach(orgShopAvg -> orgShopAvg.setNewCustomerCount(orgViewDO.getNewCustomerCount())); + }); + //公司店均 + return orgShopAvgNewCustomerList; + } + + /** + * 趋势柱状图数据 * @param customerList 好友list * @param validCustomerList 好友(去重)list * @param customerViewVO 概览VO @@ -272,7 +325,7 @@ public class CustomerViewService { //零售公司id-公司店铺list map List shopOrgInfoList = getOrgInfoByShopIds(shopIds, true, null); Map> companyShopListMap = shopOrgInfoList.stream().distinct().collect(Collectors.groupingBy(ShopOrgInfoVO::getCompanyId)); - //每个公司新增数 + //每个公司店均新增数 List tmpList = new ArrayList<>(); companyShopListMap.forEach((companyId,companyShopList) -> { CustomerViewCompanyVO orgViewDO = new CustomerViewCompanyVO();