|
|
|
@@ -1,14 +1,8 @@ |
|
|
|
package com.iformall.service.invest.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.domain.vo.invest.InvestDemandVo; |
|
|
|
import com.iformall.domain.vo.invest.InvestPageQuery; |
|
|
|
import com.iformall.domain.vo.invest.InvestPageResult; |
|
|
|
import com.iformall.domain.vo.invest.InvestTaskVo; |
|
|
|
import com.iformall.domain.vo.invest.*; |
|
|
|
import com.iformall.service.MallUserInfoService; |
|
|
|
import com.iformall.service.WxBrandService; |
|
|
|
import com.iformall.service.WxShopService; |
|
|
|
@@ -20,8 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
@@ -31,6 +27,8 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
@Autowired |
|
|
|
private InvestTaskService taskService; |
|
|
|
@Autowired |
|
|
|
private InvestFollowRecordService followRecordService; |
|
|
|
@Autowired |
|
|
|
private WxShopService shopService; |
|
|
|
@Autowired |
|
|
|
private InvestCustomerService customerService; |
|
|
|
@@ -41,19 +39,12 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public InvestPageResult<InvestDemandVo> queryPageDemand(InvestPageQuery<InvestDemandEntity> params) { |
|
|
|
InvestHelper.allNotNull(params); |
|
|
|
Page<InvestDemandEntity> page = InvestHelper.buildQueryPage(params); |
|
|
|
InvestPageResult<InvestDemandEntity> demandPage = demandService.queryPage(params); |
|
|
|
InvestPageResult<InvestDemandVo> investPage = new InvestPageResult<>(); |
|
|
|
//1、客户需求 |
|
|
|
InvestDemandEntity queryTask = params.getQueryData(); |
|
|
|
LambdaQueryWrapper<InvestDemandEntity> queryWrapper = new LambdaQueryWrapper<>(queryTask); |
|
|
|
IPage<InvestDemandEntity> demandPage = demandService.page(page, queryWrapper); |
|
|
|
if (CollectionUtils.isEmpty(demandPage.getRecords())) { |
|
|
|
return investPage; |
|
|
|
} |
|
|
|
|
|
|
|
List<InvestDemandVo> resultList = getITargeInfoList(demandPage); |
|
|
|
|
|
|
|
List<InvestDemandVo> resultList = getTargeInfoList(demandPage); |
|
|
|
BeanUtils.copyProperties(demandPage, investPage); |
|
|
|
investPage.setRecords(resultList); |
|
|
|
return investPage; |
|
|
|
@@ -70,25 +61,64 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
} |
|
|
|
|
|
|
|
List<InvestTaskEntity> taskList = taskPage.getRecords(); |
|
|
|
|
|
|
|
//2、目标信息 |
|
|
|
Collection<WxShop> shops = shopService.getByIds(taskList.stream().map(InvestTaskEntity::getTargetId).collect(Collectors.toList())); |
|
|
|
Map<Long, WxShop> shopsMap = shops.stream().collect(Collectors.toMap(WxShop::getId, shop -> shop)); |
|
|
|
//3、用户信息 |
|
|
|
Map<Long, MallUserInfo> usersMap = getUserInfoMap(); |
|
|
|
|
|
|
|
List<InvestTaskVo> resultList = new ArrayList<>(); |
|
|
|
for (InvestTaskEntity item : taskList) { |
|
|
|
WxShop shop = shopsMap.get(item.getTargetId()); |
|
|
|
resultList.add(buildResultItem(item, shop, usersMap)); |
|
|
|
resultList.add(buildTaskItem(item, shop, usersMap)); |
|
|
|
} |
|
|
|
|
|
|
|
BeanUtils.copyProperties(taskPage, investPage); |
|
|
|
investPage.setRecords(resultList); |
|
|
|
investPage.setTotal(taskPage.getTotal()); |
|
|
|
return investPage; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public InvestPageResult<InvestFollowRecordVo> queryPageFollowRecord(InvestPageQuery<InvestFollowRecordEntity> params) { |
|
|
|
InvestPageResult<InvestFollowRecordEntity> recordPage = followRecordService.queryPage(params); |
|
|
|
|
|
|
|
InvestPageResult<InvestFollowRecordVo> investPage = new InvestPageResult<>(); |
|
|
|
if (CollectionUtils.isEmpty(recordPage.getRecords())) { |
|
|
|
return investPage; |
|
|
|
} |
|
|
|
|
|
|
|
List<InvestFollowRecordEntity> recordList = recordPage.getRecords(); |
|
|
|
|
|
|
|
//2、用户信息 |
|
|
|
Map<Long, MallUserInfo> usersMap = getUserInfoMap(); |
|
|
|
|
|
|
|
//3、客户 |
|
|
|
Collection<InvestCustomerEntity> customers = getCustomers(recordList.stream().map(InvestFollowRecordEntity::getCustomerId)); |
|
|
|
Map<Long, InvestCustomerEntity> customerMap = getCustomerMap(customers); |
|
|
|
//4、 品牌 |
|
|
|
Map<Long, WxBrand> brandMap = getBrandMap(customers.stream().map(InvestCustomerEntity::getBrandId).collect(Collectors.toList())); |
|
|
|
|
|
|
|
List<InvestFollowRecordVo> resultList = new ArrayList<>(); |
|
|
|
for (InvestFollowRecordEntity item : recordList) { |
|
|
|
InvestCustomerEntity customerEntity = customerMap.get(item.getCustomerId()); |
|
|
|
WxBrand brand = brandMap.get(customerEntity.getBrandId()); |
|
|
|
Map<String, Object> followContent = (Map<String, Object>) JSON.parseObject(item.getContent(), Map.class); |
|
|
|
String followMember = (String) followContent.get("member"); |
|
|
|
List<MallUserInfo> ownerInfo = getMallUserInfos(followMember, usersMap); |
|
|
|
InvestFollowRecordVo followRecordVo = InvestFollowRecordVo.builder() |
|
|
|
.customer(customerEntity) |
|
|
|
.memberInfo(ownerInfo) |
|
|
|
.brand(brand).build(); |
|
|
|
followRecordVo.setOwnerInfo(usersMap.get(item.getOwner())); |
|
|
|
BeanUtils.copyProperties(item, followRecordVo); |
|
|
|
resultList.add(followRecordVo); |
|
|
|
} |
|
|
|
|
|
|
|
BeanUtils.copyProperties(recordPage, investPage); |
|
|
|
investPage.setRecords(resultList); |
|
|
|
investPage.setTotal(recordPage.getTotal()); |
|
|
|
return investPage; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<MallUserInfo> queryUserList() { |
|
|
|
MallUserInfo query = new MallUserInfo(); |
|
|
|
@@ -126,7 +156,8 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
InvestCustomerEntity customerEntity = customerService.getByIdNotNull(demandEntity.getCustomerId()); |
|
|
|
WxBrand brand = brandService.getById(customerEntity.getBrandId()); |
|
|
|
WxShop shop = shopService.getById(demandEntity.getTargetId()); |
|
|
|
return buildResultItem(demandEntity, customerEntity, brand, shop); |
|
|
|
Map<Long, MallUserInfo> usersMap = getUserInfoMap(); |
|
|
|
return buildDemindItem(demandEntity, customerEntity, brand, shop,usersMap); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@@ -134,14 +165,15 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
InvestTaskEntity taskEntity = taskService.getByIdNotNull(id); |
|
|
|
WxShop shop = shopService.getById(taskEntity.getTargetId()); |
|
|
|
Map<Long, MallUserInfo> usersMap = getUserInfoMap(); |
|
|
|
return buildResultItem(taskEntity, shop, usersMap); |
|
|
|
return buildTaskItem(taskEntity, shop, usersMap); |
|
|
|
} |
|
|
|
|
|
|
|
private InvestDemandVo buildResultItem(InvestDemandEntity item, InvestCustomerEntity customer, WxBrand brand, WxShop shop) { |
|
|
|
private InvestDemandVo buildDemindItem(InvestDemandEntity item, InvestCustomerEntity customer, WxBrand brand, WxShop shop, Map<Long, MallUserInfo> usersMap) { |
|
|
|
InvestDemandVo resultItemVo = InvestDemandVo.builder() |
|
|
|
.brand(brand) |
|
|
|
.customer(customer) |
|
|
|
.targetInfo(shop) |
|
|
|
.ownerInfo(usersMap.get(item.getOwner())) |
|
|
|
.build(); |
|
|
|
BeanUtils.copyProperties(item, resultItemVo); |
|
|
|
return resultItemVo; |
|
|
|
@@ -152,14 +184,8 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
return users.parallelStream().collect(Collectors.toMap(MallUserInfo::getId, MallUserInfo -> MallUserInfo)); |
|
|
|
} |
|
|
|
|
|
|
|
private InvestTaskVo buildResultItem(InvestTaskEntity item, WxShop shop, Map<Long, MallUserInfo> usersMap) { |
|
|
|
List<MallUserInfo> ownerInfo = Lists.newArrayList(); |
|
|
|
List<Long> ownerList = JSON.parseArray(item.getOwner(), Long.class); |
|
|
|
if (CollectionUtils.isNotEmpty(ownerList)) { |
|
|
|
for (Long userId : ownerList) { |
|
|
|
ownerInfo.add(usersMap.get(userId)); |
|
|
|
} |
|
|
|
} |
|
|
|
private InvestTaskVo buildTaskItem(InvestTaskEntity item, WxShop shop, Map<Long, MallUserInfo> usersMap) { |
|
|
|
List<MallUserInfo> ownerInfo = getMallUserInfos(item.getOwner(), usersMap); |
|
|
|
InvestTaskVo resultItemVo = InvestTaskVo.builder() |
|
|
|
.targetInfo(shop) |
|
|
|
.ownerInfo(ownerInfo) |
|
|
|
@@ -168,20 +194,31 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
return resultItemVo; |
|
|
|
} |
|
|
|
|
|
|
|
private List<InvestDemandVo> getITargeInfoList(IPage<InvestDemandEntity> demandPage) { |
|
|
|
private List<MallUserInfo> getMallUserInfos(String userJson, Map<Long, MallUserInfo> usersMap) { |
|
|
|
List<MallUserInfo> ownerInfo = Lists.newArrayList(); |
|
|
|
List<Long> ownerList = JSON.parseArray(userJson, Long.class); |
|
|
|
if (CollectionUtils.isNotEmpty(ownerList)) { |
|
|
|
for (Long userId : ownerList) { |
|
|
|
ownerInfo.add(usersMap.get(userId)); |
|
|
|
} |
|
|
|
} |
|
|
|
return ownerInfo; |
|
|
|
} |
|
|
|
|
|
|
|
private List<InvestDemandVo> getTargeInfoList(InvestPageResult<InvestDemandEntity> demandPage) { |
|
|
|
List<InvestDemandEntity> demandList = demandPage.getRecords(); |
|
|
|
//2、客户信息 |
|
|
|
Collection<InvestCustomerEntity> customers = customerService.listByIds(demandList |
|
|
|
.stream().map(InvestDemandEntity::getCustomerId).collect(Collectors.toList())); |
|
|
|
Map<Long, InvestCustomerEntity> customersMap = customers.stream().collect(Collectors.toMap(InvestCustomerEntity::getId, customer -> customer)); |
|
|
|
Collection<InvestCustomerEntity> customers = getCustomers(demandList.stream().map(InvestDemandEntity::getCustomerId)); |
|
|
|
Map<Long, InvestCustomerEntity> customersMap = getCustomerMap(customers); |
|
|
|
|
|
|
|
//3、目标信息 |
|
|
|
Collection<WxShop> shops = shopService.getByIds(demandList.stream().map(InvestDemandEntity::getTargetId).collect(Collectors.toList())); |
|
|
|
Map<Long, WxShop> shopsMap = shops.stream().collect(Collectors.toMap(WxShop::getId, shop -> shop)); |
|
|
|
|
|
|
|
//4 品牌 |
|
|
|
Collection<WxBrand> brands = brandService.getByIds(customers.stream().map(InvestCustomerEntity::getBrandId).collect(Collectors.toList())); |
|
|
|
Map<Long, WxBrand> brandMap = brands.stream().collect(Collectors.toMap(WxBrand::getId, brand -> brand)); |
|
|
|
//4、品牌 |
|
|
|
Map<Long, WxBrand> brandMap = getBrandMap(customers.stream().map(InvestCustomerEntity::getBrandId).collect(Collectors.toList())); |
|
|
|
//5、用户 |
|
|
|
Map<Long, MallUserInfo> usersMap = getUserInfoMap(); |
|
|
|
|
|
|
|
List<InvestDemandVo> resultList = new ArrayList<>(); |
|
|
|
for (InvestDemandEntity item : demandList) { |
|
|
|
@@ -191,8 +228,22 @@ public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
if (Objects.nonNull(customer)) { |
|
|
|
brand = brandMap.get(customer.getBrandId()); |
|
|
|
} |
|
|
|
resultList.add(buildResultItem(item, customer, brand, shop)); |
|
|
|
resultList.add(buildDemindItem(item, customer, brand, shop, usersMap)); |
|
|
|
} |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
private Map<Long, WxBrand> getBrandMap(Collection<? extends Serializable> ids) { |
|
|
|
Collection<WxBrand> brands = brandService.getByIds(ids); |
|
|
|
return brands.stream().collect(Collectors.toMap(WxBrand::getId, brand -> brand)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map<Long, InvestCustomerEntity> getCustomerMap(Collection<InvestCustomerEntity> customers) { |
|
|
|
return customers.stream().collect(Collectors.toMap(InvestCustomerEntity::getId, customer -> customer)); |
|
|
|
} |
|
|
|
|
|
|
|
private Collection<InvestCustomerEntity> getCustomers(Stream<Long> longStream) { |
|
|
|
return customerService.listByIds(longStream.collect(Collectors.toList())); |
|
|
|
} |
|
|
|
} |