推广为0

master
wangweijia 6 years ago
parent 588e1b218c
commit 1f405979c1

@ -2,6 +2,7 @@ package com.kiisoo.ic.customer.controller;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.customer.entity.CustomerViewVO;
import com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO;
import com.kiisoo.ic.customer.service.CustomerViewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
@ -53,5 +55,31 @@ public class CustomerViewController extends BaseController {
}
}
/**
* 广0
* @param userId id
* @param regionId id
* @param companyId id
* @param customerId id
* @param startTime
* @param endTime
* @param pageNum
* @param pageSize
* @return
*/
@ResponseBody
@RequestMapping(value = "/all/zero", method = RequestMethod.GET)
public Map<String,Object> getMainData(@RequestParam("userId") long userId, Long regionId , Long companyId, Long customerId,
String startTime, String endTime, @RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize){
try{
List<CustomerViewZeroExtendVO> result = customerViewService.zeroExtendList(userId, regionId, companyId, customerId, startTime, endTime, pageNum,pageSize);
return data(result);
}catch (Exception e){
log.error("查询推广为0店铺出错", e);
return fail();
}
}
}

@ -20,4 +20,24 @@ public class CustomerViewZeroExtendVO {
private Integer allShopCount;
/**零推广店铺数*/
private Integer zeroShopCount;
/**店铺名称*/
private String shopName;
/**店铺编码*/
private String shopCode;
/**店铺id*/
private Long shopId;
/**大区*/
private String region;
/**零售公司*/
private String company;
/**客户*/
private String customer;
/**推广数*/
private Integer numb;
/**序号*/
private Integer number;
/*
*
*/
private long totalSize;
}

@ -2,6 +2,7 @@ package com.kiisoo.ic.customer.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kiisoo.ic.customer.entity.CustomerViewShopVO;
import com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO;
import com.kiisoo.ic.customer.entity.OpCustomer;
import com.kiisoo.ic.customer.bean.OpCustomerDTO;
import org.apache.ibatis.annotations.Param;
@ -51,4 +52,10 @@ public interface OpCustomerDOMapper extends BaseMapper<OpCustomer> {
*/
List<CustomerViewShopVO> selectOrgByShopIds(@Param("shopIds") List<Long> shopIds);
/**
* ids
*/
List<CustomerViewZeroExtendVO> selectOrgInfoByShopIds(@Param("shopIds") List<Long> shopIds);
}

@ -1,12 +1,16 @@
package com.kiisoo.ic.customer.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kiisoo.ic.customer.bean.OpCustomerDTO;
import com.kiisoo.ic.customer.entity.*;
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
import com.kiisoo.ic.domain.service.PrivilageDomainService;
import com.kiisoo.ic.generalize.entity.PoiCustomerContactDataStat;
import com.kiisoo.ic.generalize.mapper.PoiCustomerContactDataStatMapper;
import com.kiisoo.ic.generalize.service.RetailCompanyService;
import com.kiisoo.ic.store.entity.PoiStore;
import com.kiisoo.ic.store.mapper.PoiStoreDOMapper;
import lombok.extern.slf4j.Slf4j;
@ -35,6 +39,8 @@ public class CustomerViewService {
static final Integer TEN = 10;
@Autowired
private RetailCompanyService retailCompanyService;
/**
* mapper
*/
@ -271,4 +277,81 @@ public class CustomerViewService {
return zeroExtendList;
}
/**
* 广list
* @param newCustimerList list
* @param shopIds ids
* @return 广list
*/
List<CustomerViewZeroExtendVO> getZeroExtendList2(List<OpCustomer> newCustimerList, List<Long> shopIds, int pageNum, int pageSize){
//有推广的店铺ids
List<Long> notZeroShopIds = newCustimerList.stream().map(OpCustomer::getShopId).distinct().collect(Collectors.toList());
//无推广id
shopIds.removeAll(notZeroShopIds);
PageHelper.startPage(pageNum,pageSize);
List<CustomerViewZeroExtendVO> list = opCustomerDOMapper.selectOrgInfoByShopIds(shopIds);
AtomicInteger number = new AtomicInteger(1 + ((pageNum-1) * pageSize));
//求分页总数
Page<CustomerViewZeroExtendVO> pageList = (Page<CustomerViewZeroExtendVO>)list;
Long totalSize = pageList.getTotal();
list.forEach(item -> {
item.setTotalSize(totalSize);
item.setNumb(0);
item.setNumber(number.get());
number.incrementAndGet();
});
return list;
}
/**
* 广0
* @param regionId id
* @param companyId id
* @param customerId id
* @param startTime
* @param endTime
* @return
*/
public List<CustomerViewZeroExtendVO> zeroExtendList(long userId, Long regionId , Long companyId, Long customerId,
String startTime, String endTime, int pageNum, int pageSize){
Set<Long> shopIds;
//根据店铺查询所有扫码客户信息
if(customerId != null){
shopIds = getCompanyShop(customerId, userId);
}else if(companyId != null){
shopIds = getCompanyShop(companyId, userId);
} else if(regionId != null){
shopIds = getCompanyShop(regionId, userId);
}else{
//查询用户权限店铺
shopIds = new HashSet<>(privilageDomainService.listUserDatePermission(userId));
}
if(CollectionUtils.isEmpty(shopIds)){
return new ArrayList<>();
}
//柱状图好友list
List<OpCustomer> customerList = opCustomerDOMapper.selectCustomerList(new ArrayList<>(shopIds), null, null, startTime, endTime);
List<CustomerViewZeroExtendVO> zeroExtendList = getZeroExtendList2(customerList, new ArrayList<>(shopIds),pageNum,pageSize);
return zeroExtendList;
}
public Set<Long> getCompanyShop(Long companyId, long userId){
//找到最小公司
Set<Long> param = new HashSet<>();
param.add(companyId);
Set<Long> minCompany = retailCompanyService.getMinCompany(param);
//找到公司店铺
List<PoiStore> shops = new ArrayList<>();
minCompany.forEach(item -> {
shops.addAll(retailCompanyService.selectShopByCompany(companyId));
});
//公司店铺和权限做交集
Set<Long> shopIds = shops.stream().map(p -> p.getId()).collect(Collectors.toSet());
List<Long> userAllShops = privilageDomainService.listUserDatePermission(userId);
shopIds.retainAll(userAllShops);
return shopIds;
}
}

@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Set;
@Repository
public interface RetailCompanyMapper extends BaseMapper<PrivilageOrganizational> {
@ -15,4 +16,9 @@ public interface RetailCompanyMapper extends BaseMapper<PrivilageOrganizational>
List<CompanyStoreDO> selectShopIdByRetail(@Param("orgId") Long orgId, @Param("shopId") Long shopId);
List<Long> selectSellerIdsByShop(@Param("orgId") Long orgId,@Param("shopId") Long shopId,@Param("sellerId") Long sellerId);
/**
*
*/
Set<Long> selectChildList(@Param("companys") Set<Long> companys);
}

@ -27,9 +27,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -382,4 +380,20 @@ public class RetailCompanyService {
}
return vo;
}
/**
*
*/
public Set<Long> getMinCompany(Set<Long> companys){
Set<Long> minest = new HashSet<>();
Set<Long> listOfOrg = retailCompanyMapper.selectChildList(companys);
//增加最小公司
if(listOfOrg.size() > 0){
companys.removeAll(listOfOrg);
minest.addAll(getMinCompany(companys));
}else{
minest.addAll(companys);
}
return minest;
}
}

@ -113,4 +113,17 @@
</foreach>
</select>
<!--店铺ids→零售公司-->
<select id="selectOrgInfoByShopIds" resultType="com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO">
select t1.id as orgId,t1.`name` as orgName, t3.entity_id as shopId, t4.name as shopName, t4.code as shopCode
from privilage_organizational t1, privilage_organizational_domain t2, privilage_domain_entity t3, poi_store t4
where t1.id = t2.org_id
and t2.domain_id = t3.domain_id
and t3.type = 3 and t3.entity_id = t4.id
and t3.entity_id in
<foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
order by t3.entity_id,t1.id asc
</select>
</mapper>

@ -37,4 +37,19 @@
and t4.user_id = #{sellerId}
</if>
</select>
<select id="selectChildList" resultType="Long">
select id from privilage_organizational where
<choose>
<when test="companys != null and companys.size > 0">
parent_id in
<foreach collection="companys" item="item" index="index" close=")" open="(" separator=",">
#{item}
</foreach>
</when>
<otherwise>
1 = 0
</otherwise>
</choose>
</select>
</mapper>

Loading…
Cancel
Save