From fc0297fdec661cc6475322ebb7f9f4e2216f624a Mon Sep 17 00:00:00 2001 From: LegnaYet <1023868505@qq.com> Date: Fri, 29 May 2020 17:54:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E5=BA=97=E5=8F=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/service/CustomerViewService.java | 10 +-- .../service/RetailCompanyService.java | 42 ++++-------- .../resources/mapper/OpCustomerDOMapper.xml | 39 ++++++----- .../OpSellerCustomerRelationDOMapper.xml | 5 +- .../mapper/StorePromotionDataDOMapper.xml | 64 +++++++++---------- 5 files changed, 69 insertions(+), 91 deletions(-) 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 630b682..e9e7ba2 100644 --- a/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java +++ b/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java @@ -647,8 +647,9 @@ public class CustomerViewService { //店长 if(privilageRoleDO.getCode().equals(RoleEnum.ROLE_CODE_DZ.getRoleCode())) { shopIdList = poiStoreStaffDOMapper.selectByUserId(userId); - Long storeAll = privilageCpUserDOMapper.selectStoresCountById(shopIdList); - Long storeDis = privilageCpUserDOMapper.selectDistinctStoresCountById(shopIdList); + String cpUserId = privilageCpUserStoreDOMapper.selectCpUserIdByStoreId(shopIdList.get(0)); + Long storeAll = privilageCpUserDOMapper.selectStoreCount(cpUserId); + Long storeDis = privilageCpUserDOMapper.selectDistinctStoreCount(cpUserId); result.setAllCustomer(storeAll); result.setAllValidCustomer(storeDis); @@ -662,8 +663,9 @@ public class CustomerViewService { //查询零售公司的门店 List list1 = retailCompanyService.selectShopByCompany(pm.get(0).getOrgId()); shopIdList = list1.stream().map(PoiStore::getId).collect(Collectors.toList()); - Long all = privilageCpUserDOMapper.selectStoresCountById(shopIdList); - Long dis = privilageCpUserDOMapper.selectDistinctStoresCountById(shopIdList); + List cpUserIds = privilageCpUserStoreDOMapper.selectCpUserIdsByStoreIds(shopIdList); + Long all = privilageCpUserDOMapper.selectStoresCount(cpUserIds); + Long dis = privilageCpUserDOMapper.selectDistinctStoresCount(cpUserIds); result.setAllCustomer(all); result.setAllValidCustomer(dis); diff --git a/src/main/java/com/kiisoo/ic/generalize/service/RetailCompanyService.java b/src/main/java/com/kiisoo/ic/generalize/service/RetailCompanyService.java index 2e8c03e..e2d6436 100644 --- a/src/main/java/com/kiisoo/ic/generalize/service/RetailCompanyService.java +++ b/src/main/java/com/kiisoo/ic/generalize/service/RetailCompanyService.java @@ -376,12 +376,12 @@ public class RetailCompanyService { long count = opRelations.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count(); organizationalVO.setAllCustomer((int) count); //组织成员的客户有效个数 - QueryWrapper wrapper4 = new QueryWrapper<>(); - wrapper4.in("store_id", stores); - wrapper4.eq("type", 1); - Integer countAble = opSellerCustomerRelationDOMapper.selectCount(wrapper4); -// long countAble = opRelations1.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count(); - organizationalVO.setEffectiveCustomer(countAble); +// QueryWrapper wrapper4 = new QueryWrapper<>(); +// wrapper4.in("store_id", stores); +// wrapper4.eq("type", 1); +// Integer countAble = opSellerCustomerRelationDOMapper.selectCount(wrapper4); + long countAble = opRelations.stream().filter(item -> item.getType() == 1).map(OpSellerCustomerRelation::getCustomerId).distinct().count(); + organizationalVO.setEffectiveCustomer((int)countAble); //计算新增客户数据 newCustomerStore(startTime, endTime, organizationalVO, stores); @@ -469,37 +469,23 @@ public class RetailCompanyService { //最初时间的总客户人数 QueryWrapper wrapper2 = new QueryWrapper<>(); wrapper2.in("store_id", storeIds); - wrapper2.lt("create_time", startTime); + wrapper2.gt("create_time", startTime); + wrapper2.lt("create_time", l.plus(1, ChronoUnit.DAYS)); List opRelations = opSellerCustomerRelationDOMapper.selectList(wrapper2); long count = opRelations.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count(); //最初时间的有效总客户人数 - wrapper2.in("store_id", storeIds); - wrapper2.eq("type", 1); - wrapper2.lt("create_time", startTime); - List opRelations2 = opSellerCustomerRelationDOMapper.selectList(wrapper2); - long count2 = opRelations2.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count(); - //最后时间的总客户人数 - QueryWrapper wrapper3 = new QueryWrapper<>(); - wrapper3.in("store_id", storeIds); - wrapper3.lt("create_time", l.plus(1, ChronoUnit.DAYS)); - List opRelationsEnd = opSellerCustomerRelationDOMapper.selectList(wrapper3); - long countEnd = opRelationsEnd.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count(); - //最后时间的有效总客户人数 - wrapper3.in("store_id", storeIds); - wrapper3.eq("type", 1); - wrapper3.lt("create_time", l.plus(1, ChronoUnit.DAYS)); - List opRelationsEnd2 = opSellerCustomerRelationDOMapper.selectList(wrapper3); - long countEnd2 = opRelationsEnd2.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count(); + long count2 = opRelations.stream().filter(item -> item.getType() == 1).map(OpSellerCustomerRelation::getCustomerId).distinct().count(); + //计算两个时间间隔用于计算平均值 LocalDate start = LocalDate.parse(startTime); LocalDate end = LocalDate.parse(endTime); long days = start.until(end, ChronoUnit.DAYS) + 1; - organizationalVO.setNewCustomer((int) (countEnd - count)); - organizationalVO.setNewEffectiveCustomer((int) (countEnd2 - count2)); - organizationalVO.setAvgNewCustomer(check1(countEnd - count, days)); - organizationalVO.setAvgNewEffectiveCustomer(check1(countEnd2 - count2, days)); + organizationalVO.setNewCustomer((int) count); + organizationalVO.setNewEffectiveCustomer((int) count2); + organizationalVO.setAvgNewCustomer(check1( count, days)); + organizationalVO.setAvgNewEffectiveCustomer(check1(count2, days)); } /** diff --git a/src/main/resources/mapper/OpCustomerDOMapper.xml b/src/main/resources/mapper/OpCustomerDOMapper.xml index c796637..538dcd6 100644 --- a/src/main/resources/mapper/OpCustomerDOMapper.xml +++ b/src/main/resources/mapper/OpCustomerDOMapper.xml @@ -56,15 +56,13 @@ diff --git a/src/main/resources/mapper/OpSellerCustomerRelationDOMapper.xml b/src/main/resources/mapper/OpSellerCustomerRelationDOMapper.xml index d3804ce..e1de24d 100644 --- a/src/main/resources/mapper/OpSellerCustomerRelationDOMapper.xml +++ b/src/main/resources/mapper/OpSellerCustomerRelationDOMapper.xml @@ -139,12 +139,11 @@ t2.avatar_url AS avatar , t3. LEVEL AS vipFlag FROM - op_seller_customer_relation t1 - join op_customer t2 on t1.customer_id = t2.id + op_seller_customer_relation t1, op_customer t2 LEFT JOIN op_vip t3 ON t2.member_id = t3.id AND t3. STATUS = 1 WHERE - 1 = 1 + t1.customer_id = t2.id and t3.id is not null diff --git a/src/main/resources/mapper/StorePromotionDataDOMapper.xml b/src/main/resources/mapper/StorePromotionDataDOMapper.xml index 18a555d..4072fef 100644 --- a/src/main/resources/mapper/StorePromotionDataDOMapper.xml +++ b/src/main/resources/mapper/StorePromotionDataDOMapper.xml @@ -89,10 +89,10 @@ poi_store t1 LEFT JOIN op_seller_customer_relation t4 on t1.id = t4.store_id - and DATE_FORMAT(t4.create_time,'%Y-%m-%d') >= DATE_FORMAT(#{startDate},'%Y-%m-%d') + and t4.create_time >= #{startDate} - and DATE_FORMAT(t4.create_time,'%Y-%m-%d') <= DATE_FORMAT(#{endDate},'%Y-%m-%d') + and t4.create_time <= #{endDate} , poi_store_region t2 WHERE @@ -169,10 +169,10 @@ poi_store_staff t1 LEFT JOIN op_seller_customer_relation t2 ON t1.id = t2.user_id - and DATE_FORMAT(t4.create_time,'%Y-%m-%d') >= DATE_FORMAT(#{startDate},'%Y-%m-%d') + and t4.create_time >= #{startDate} - and DATE_FORMAT(t4.create_time,'%Y-%m-%d') <= DATE_FORMAT(#{endDate},'%Y-%m-%d') + and t4.create_time <= #{endDate} , privilage_user t3, poi_store_region t4 @@ -290,29 +290,28 @@ @@ -326,15 +325,14 @@ user_id AS id, count( customer_id ) AS cusNum FROM - `op_seller_customer_relation` t,op_customer t2 + `op_seller_customer_relation` t WHERE - t.customer_id = t2.id - and t. store_id = #{storeId} + t. store_id = #{storeId} - and date(t.create_time) >= #{startDate} + and t.create_time >= #{startDate} - and date(t.create_time) <= #{endDate} + and t.create_time <= #{endDate} GROUP BY t.user_id @@ -365,23 +363,20 @@ ( SELECT count( t2.customer_id ) AS newCusNum, - t1.id AS storeId + t2.store_id AS storeId FROM - poi_store t1 - JOIN `op_seller_customer_relation` t2 ON t1.id = t2.store_id - JOIN op_customer t3 on t2.customer_id = t3.id + `op_seller_customer_relation` t2 + where 1=1 - and date(t2.create_time) >= #{startDate} + and t2.create_time >= #{startDate} - and date(t2.create_time) <= #{endDate} + and t2.create_time <= #{endDate} - WHERE - t1.STATUS = 1 GROUP BY - storeId + t2.store_id ORDER BY - newCusNum DESC, storeId DESC + newCusNum DESC, t2.store_id DESC ) a, ( SELECT @rank := 0 ) b @@ -392,18 +387,17 @@ @rank := @rank + 1 AS rankNo FROM ( SELECT count( t2.customer_id ) AS newCusNum, t1.user_id AS userId FROM - poi_store_staff t1 - LEFT JOIN `op_seller_customer_relation` t2 ON t1.id = t2.user_id - left join op_customer t3 on t2.customer_id = t3.id + poi_store_staff t1, `op_seller_customer_relation` t2 + where t1.id = t2.user_id - and date(t2.create_time) >= #{startDate} + and t2.create_time >= #{startDate} - and date(t2.create_time) <= #{endDate} + and t2.create_time <= #{endDate} - where t1.store_id = #{storeId} + and t1.store_id = #{storeId} and t1.type = 4 - GROUP BY userId,t3.id ORDER BY newCusNum DESC, userId DESC ) a, + GROUP BY userId,t2.customer_id ORDER BY newCusNum DESC, userId DESC ) a, ( SELECT @rank := 0 ) b