组织关系修改

master
wyj2080 6 years ago
parent 6b59c147dc
commit 11db4ef4ba

@ -16,10 +16,10 @@ public class CustomerViewShopVO {
private Long shopId; private Long shopId;
/**店铺名称*/ /**店铺名称*/
private String shopName; private String shopName;
/**零售公司id*/ /**客户组织id*/
private Long orgId; private Long customerId;
/**零售公司名称*/ /**客户组织名称*/
private String orgName; private String customerName;
/**新增好友数*/ /**新增好友数*/
private Integer newCustomerCount; private Integer newCustomerCount;
} }

@ -0,0 +1,31 @@
package com.kiisoo.ic.customer.entity;
import lombok.Data;
/**
* @Description: VO
* @Author: wangyinjia
* @Date: 2020/4/22
* @Company: kiisoo
* @Version: 1.0
*/
@Data
public class ShopOrgInfoVO {
/**店铺id*/
private Long shopId;
/**店铺名称*/
private String shopName;
/**客户id*/
private Long customerId;
/**客户*/
private String customerName;
/**零售公司id*/
private Long companyId;
/**零售公司*/
private String companyName;
/**区域id*/
private Long regionId;
/**区域*/
private String regionName;
}

@ -5,6 +5,7 @@ import com.kiisoo.ic.customer.entity.CustomerViewShopVO;
import com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO; import com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO;
import com.kiisoo.ic.customer.entity.OpCustomer; import com.kiisoo.ic.customer.entity.OpCustomer;
import com.kiisoo.ic.customer.bean.OpCustomerDTO; import com.kiisoo.ic.customer.bean.OpCustomerDTO;
import com.kiisoo.ic.customer.entity.ShopOrgInfoVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -48,10 +49,9 @@ public interface OpCustomerDOMapper extends BaseMapper<OpCustomer> {
Long selectCustomerCount(@Param("shopIds") List<Long> shopIds, @Param("type")Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate); Long selectCustomerCount(@Param("shopIds") List<Long> shopIds, @Param("type")Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate);
/** /**
* ids * ids
*/ */
List<CustomerViewShopVO> selectOrgByShopIds(@Param("shopIds") List<Long> shopIds); List<ShopOrgInfoVO> selectCustomerOrgByShopIds(@Param("shopIds") List<Long> shopIds, @Param("level")Integer level);
/** /**
* ids * ids

@ -41,6 +41,13 @@ public class CustomerViewService {
static final Integer TEN = 10; static final Integer TEN = 10;
/**区域*/
static final Integer LEVEL_REGION = 1;
/**零售公司*/
static final Integer LEVEL_COMPANY = 2;
/**客户*/
static final Integer LEVEL_CUSTOMER = 3;
@Autowired @Autowired
private RetailCompanyService retailCompanyService; private RetailCompanyService retailCompanyService;
/** /**
@ -192,6 +199,38 @@ public class CustomerViewService {
} }
} }
/**
* list
* @param shopIds ids
* @param companyFlag
* @param regionFlag
* @return list
*/
public List<ShopOrgInfoVO> getOrgInfoByShopIds(List<Long> shopIds, Boolean companyFlag, Boolean regionFlag){
//店铺-客户组织list
List<ShopOrgInfoVO> shopOrgInfoList = opCustomerDOMapper.selectCustomerOrgByShopIds(shopIds, LEVEL_CUSTOMER);
if(companyFlag == null || !companyFlag){
return shopOrgInfoList;
}
//零售公司list
List<Long> companyIds = shopOrgInfoList.stream().map(ShopOrgInfoVO::getCompanyId).collect(Collectors.toList());
List<PrivilageOrganizational> companyList = new ArrayList<>();
if(companyIds.size() > 0){
QueryWrapper<PrivilageOrganizational> orgWrapper = new QueryWrapper<>();
orgWrapper.eq("level", LEVEL_COMPANY);
orgWrapper.in("id", companyIds);
companyList = retailCompanyMapper.selectList(orgWrapper);
}
Map<Long, String> companyNameMap = companyList.stream().collect(Collectors.toMap(PrivilageOrganizational::getId, PrivilageOrganizational::getName));
shopOrgInfoList.stream().filter(shopOrgDO -> shopOrgDO.getCompanyId() != null).forEach(shopOrgDO -> shopOrgDO.setCompanyName(companyNameMap.get(shopOrgDO.getCompanyId())));
//区域list
if(regionFlag == null || !regionFlag){
return shopOrgInfoList;
}
return shopOrgInfoList;
}
/** /**
* list * list
* @param newCustimerList list * @param newCustimerList list
@ -206,17 +245,18 @@ public class CustomerViewService {
if(CollectionUtils.isEmpty(shopIds)){ if(CollectionUtils.isEmpty(shopIds)){
return orgNewCustomerList; return orgNewCustomerList;
} }
//公司id-公司店铺list map //零售公司id-公司店铺list map
Map<Long, List<CustomerViewShopVO>> orgShopListMap = opCustomerDOMapper.selectOrgByShopIds(shopIds).stream().distinct().collect(Collectors.groupingBy(CustomerViewShopVO::getOrgId)); List<ShopOrgInfoVO> shopOrgInfoList = getOrgInfoByShopIds(shopIds, true, null);
Map<Long, List<ShopOrgInfoVO>> companyShopListMap = shopOrgInfoList.stream().distinct().collect(Collectors.groupingBy(ShopOrgInfoVO::getCompanyId));
//每个公司新增数 //每个公司新增数
List<CustomerViewCompanyVO> tmpList = new ArrayList<>(); List<CustomerViewCompanyVO> tmpList = new ArrayList<>();
orgShopListMap.forEach((orgId,customerViewShopList) -> { companyShopListMap.forEach((companyId,companyShopList) -> {
CustomerViewCompanyVO orgViewDO = new CustomerViewCompanyVO(); CustomerViewCompanyVO orgViewDO = new CustomerViewCompanyVO();
orgViewDO.setOrgId(orgId); orgViewDO.setOrgId(companyId);
orgViewDO.setOrgName(customerViewShopList.get(0).getOrgName()); orgViewDO.setOrgName(companyShopList.get(0).getCompanyName());
AtomicInteger newCustomerCount = new AtomicInteger(0); AtomicInteger newCustomerCount = new AtomicInteger(0);
customerViewShopList.forEach(customerViewShopVO -> { companyShopList.forEach(companyShopVO -> {
Long shopId = customerViewShopVO.getShopId(); Long shopId = companyShopVO.getShopId();
int tmpCount = shopIdCountMap.get(shopId) == null ? 0 : Math.toIntExact(shopIdCountMap.get(shopId)); int tmpCount = shopIdCountMap.get(shopId) == null ? 0 : Math.toIntExact(shopIdCountMap.get(shopId));
newCustomerCount.updateAndGet(v -> v + tmpCount); newCustomerCount.updateAndGet(v -> v + tmpCount);
}); });
@ -262,16 +302,17 @@ public class CustomerViewService {
List<CustomerViewZeroExtendVO> zeroExtendList = new ArrayList<>(); List<CustomerViewZeroExtendVO> zeroExtendList = new ArrayList<>();
//有推广的店铺ids //有推广的店铺ids
List<Long> notZeroShopIds = newCustimerList.stream().map(OpCustomer::getShopId).distinct().collect(Collectors.toList()); List<Long> notZeroShopIds = newCustimerList.stream().map(OpCustomer::getShopId).distinct().collect(Collectors.toList());
//公司id-公司店铺list map //零售公司id-公司店铺list map
Map<Long, List<CustomerViewShopVO>> orgShopListMap = opCustomerDOMapper.selectOrgByShopIds(shopIds).stream().distinct().collect(Collectors.groupingBy(CustomerViewShopVO::getOrgId)); List<ShopOrgInfoVO> shopOrgInfoList = getOrgInfoByShopIds(shopIds, true, null);
Map<Long, List<ShopOrgInfoVO>> companyShopListMap = shopOrgInfoList.stream().distinct().collect(Collectors.groupingBy(ShopOrgInfoVO::getCompanyId));
List<CustomerViewZeroExtendVO> tmpZeroExtendList = new ArrayList<>(); List<CustomerViewZeroExtendVO> tmpZeroExtendList = new ArrayList<>();
orgShopListMap.forEach((orgId, orgShopRelationList) -> { companyShopListMap.forEach((companyId, companyShopList) -> {
List<Long> tmpShopIds = orgShopRelationList.stream().map(CustomerViewShopVO::getShopId).distinct().collect(Collectors.toList()); List<Long> tmpShopIds = companyShopList.stream().map(ShopOrgInfoVO::getShopId).distinct().collect(Collectors.toList());
int tmpShopCount = tmpShopIds.size(); int tmpShopCount = tmpShopIds.size();
CustomerViewZeroExtendVO zeroExtendVO = new CustomerViewZeroExtendVO(); CustomerViewZeroExtendVO zeroExtendVO = new CustomerViewZeroExtendVO();
zeroExtendVO.setOrgId(orgId); zeroExtendVO.setOrgId(companyId);
zeroExtendVO.setOrgName(orgShopRelationList.get(0).getOrgName()); zeroExtendVO.setOrgName(companyShopList.get(0).getCompanyName());
zeroExtendVO.setAllShopCount(tmpShopCount); zeroExtendVO.setAllShopCount(tmpShopCount);
//推广的店铺 //推广的店铺
tmpShopIds.retainAll(notZeroShopIds); tmpShopIds.retainAll(notZeroShopIds);

@ -100,17 +100,21 @@
</if> </if>
</select> </select>
<!--店铺ids→零售公司--> <!--店铺ids→客户组织-->
<select id="selectOrgByShopIds" resultType="com.kiisoo.ic.customer.entity.CustomerViewShopVO"> <select id="selectCustomerOrgByShopIds" resultType="com.kiisoo.ic.customer.entity.ShopOrgInfoVO">
select t1.id as orgId,t1.`name` as orgName, t3.entity_id as shopId select t1.id as customerId,t1.`name` as customerName, t1.parent_id as companyId, t3.entity_id as shopId, t4.`name` as shopName
from privilage_organizational t1, privilage_organizational_domain t2, privilage_domain_entity t3 from privilage_organizational t1, privilage_organizational_domain t2, privilage_domain_entity t3, poi_store t4
where t1.id = t2.org_id where t1.id = t2.org_id
and t2.domain_id = t3.domain_id and t2.domain_id = t3.domain_id
and t3.type = 3 and t3.type = 3
and t3.entity_id = t4.id
and t3.entity_id in and t3.entity_id in
<foreach collection="shopIds" separator="," item="item" index="index" close=")" open="("> <foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
#{item} #{item}
</foreach> </foreach>
<if test="level != null">
and t1.`level`=#{level}
</if>
</select> </select>
<!--店铺ids→零售公司信息--> <!--店铺ids→零售公司信息-->

Loading…
Cancel
Save