|
|
|
@@ -0,0 +1,131 @@ |
|
|
|
package com.iformall.service.invest.impl; |
|
|
|
|
|
|
|
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.InvestCustomerEntity; |
|
|
|
import com.iformall.domain.po.InvestDemandEntity; |
|
|
|
import com.iformall.domain.po.WxBrand; |
|
|
|
import com.iformall.domain.po.WxShop; |
|
|
|
import com.iformall.domain.vo.invest.InvestDemandVo; |
|
|
|
import com.iformall.domain.vo.invest.InvestPageQuery; |
|
|
|
import com.iformall.domain.vo.invest.InvestPageResult; |
|
|
|
import com.iformall.service.WxBrandService; |
|
|
|
import com.iformall.service.WxShopService; |
|
|
|
import com.iformall.service.invest.InvestBizService; |
|
|
|
import com.iformall.service.invest.InvestCustomerService; |
|
|
|
import com.iformall.service.invest.InvestDemandService; |
|
|
|
import com.iformall.service.invest.InvestHelper; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class InvestBizServiceImpl implements InvestBizService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private InvestDemandService demandService; |
|
|
|
@Autowired |
|
|
|
private WxShopService shopService; |
|
|
|
@Autowired |
|
|
|
private InvestCustomerService customerService; |
|
|
|
@Autowired |
|
|
|
private WxBrandService brandService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public InvestPageResult<InvestDemandVo> queryPage(InvestPageQuery<InvestDemandEntity> params) { |
|
|
|
InvestHelper.allNotNull(params); |
|
|
|
Page<InvestDemandEntity> page = InvestHelper.buildQueryPage(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); |
|
|
|
|
|
|
|
BeanUtils.copyProperties(demandPage, investPage); |
|
|
|
investPage.setRecords(resultList); |
|
|
|
return investPage; |
|
|
|
} |
|
|
|
|
|
|
|
private List<InvestDemandVo> getITargeInfoList(IPage<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)); |
|
|
|
|
|
|
|
//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)); |
|
|
|
|
|
|
|
List<InvestDemandVo> resultList = new ArrayList<>(); |
|
|
|
for (InvestDemandEntity item : demandList) { |
|
|
|
InvestCustomerEntity customer = customersMap.get(item.getCustomerId()); |
|
|
|
WxShop shop = shopsMap.get(item.getTargetId()); |
|
|
|
WxBrand brand = null; |
|
|
|
if (Objects.nonNull(customer)) { |
|
|
|
brand = brandMap.get(customer.getBrandId()); |
|
|
|
} |
|
|
|
resultList.add(buildResultItem(item, customer, brand, shop)); |
|
|
|
} |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) { |
|
|
|
InvestHelper.allNotNull(customerDemandVo); |
|
|
|
InvestHelper.allNotNull(customerDemandVo.getBrand(), customerDemandVo.getCustomer()); |
|
|
|
InvestCustomerEntity customerEntity = customerDemandVo.getCustomer(); |
|
|
|
customerService.save(customerEntity); |
|
|
|
InvestDemandEntity demandEntity = new InvestDemandEntity(); |
|
|
|
BeanUtils.copyProperties(customerDemandVo, demandEntity); |
|
|
|
return demandService.save(demandEntity); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) { |
|
|
|
InvestHelper.allNotNull(customerDemandVo); |
|
|
|
InvestHelper.allNotNull(customerDemandVo.getBrand(), customerDemandVo.getCustomer()); |
|
|
|
InvestCustomerEntity customerEntity = customerDemandVo.getCustomer(); |
|
|
|
customerService.updateById(customerEntity); |
|
|
|
InvestDemandEntity demandEntity = new InvestDemandEntity(); |
|
|
|
BeanUtils.copyProperties(customerDemandVo, demandEntity); |
|
|
|
return demandService.updateById(demandEntity); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public InvestDemandVo findById(Long id) { |
|
|
|
InvestHelper.allNotNull(id); |
|
|
|
InvestDemandEntity demandEntity = demandService.getByIdNotNull(id); |
|
|
|
InvestCustomerEntity customerEntity = customerService.getByIdNotNull(demandEntity.getCustomerId()); |
|
|
|
WxBrand brand = brandService.getById(customerEntity.getBrandId()); |
|
|
|
WxShop shop = shopService.getById(demandEntity.getTargetId()); |
|
|
|
return buildResultItem(demandEntity, customerEntity, brand, shop); |
|
|
|
} |
|
|
|
|
|
|
|
private InvestDemandVo buildResultItem(InvestDemandEntity item, InvestCustomerEntity customer, WxBrand brand, WxShop shop) { |
|
|
|
InvestDemandVo resultItemVo = InvestDemandVo.builder() |
|
|
|
.brand(brand) |
|
|
|
.customer(customer) |
|
|
|
.targetInfo(shop) |
|
|
|
.build(); |
|
|
|
BeanUtils.copyProperties(item, resultItemVo); |
|
|
|
return resultItemVo; |
|
|
|
} |
|
|
|
} |