From aa7123b76b4bbca69a65856f55d0e85378fd593d Mon Sep 17 00:00:00 2001 From: Burce Date: Mon, 14 Oct 2019 20:12:22 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=9B=E5=95=86]adjust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invest/impl/InvestBizServiceImpl.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java index c6555bad4..7358a595a 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java @@ -60,12 +60,11 @@ public class InvestBizServiceImpl implements InvestBizService { InvestPageResult investPage = new InvestPageResult<>(); - LambdaQueryWrapper queryWrapperDemand = null; + LambdaQueryWrapper queryWrapperDemand = new LambdaQueryWrapper<>(demandParams); InvestPageResult customers = customerService.queryPage(buildPageQuery(params, customerParams)); if (CollectionUtils.isEmpty(customers.getRecords())) { return investPage; } - queryWrapperDemand = new LambdaQueryWrapper<>(demandParams); queryWrapperDemand.in(InvestDemandEntity::getCustomerId, getIds(customers.getRecords(), InvestCustomerEntity::getId)); List demandList = demandService.list(queryWrapperDemand); @@ -91,7 +90,6 @@ public class InvestBizServiceImpl implements InvestBizService { demandEntity.setOwner(params.getDemandOwner()); } - InvestDemandDto demandDto = new InvestDemandDto(); demandDto.setCustomer(customerEntity); demandDto.setDemand(demandEntity); @@ -130,9 +128,9 @@ public class InvestBizServiceImpl implements InvestBizService { Collection taskList = taskPage.getRecords(); //2、目标信息 Collection shops = shopService.getByIds(getIds(taskList, InvestTaskEntity::getTargetId)); - Map shopsMap = getMap(shops, WxShop::getId); + HashMap shopsMap = getMap(shops, WxShop::getId); //3、用户信息 - Map usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); + HashMap usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); List resultList = new ArrayList<>(); for (InvestTaskEntity item : taskList) { WxShop shop = shopsMap.get(item.getTargetId()); @@ -184,13 +182,13 @@ public class InvestBizServiceImpl implements InvestBizService { Collection recordList = recordPage.getRecords(); //2、用户信息 - Map usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); + HashMap usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); //3、客户 Collection customers = customerService.listByIds(getIds(recordList, InvestFollowRecordEntity::getCustomerId)); - Map customerMap = getMap(customers, InvestCustomerEntity::getId); + HashMap customerMap = getMap(customers, InvestCustomerEntity::getId); //4、 品牌 - Map brandMap = getMap(brandService.getByIds(getIds(customers, InvestCustomerEntity::getBrandId)), WxBrand::getId); + HashMap brandMap = getMap(brandService.getByIds(getIds(customers, InvestCustomerEntity::getBrandId)), WxBrand::getId); List resultList = new ArrayList<>(); for (InvestFollowRecordEntity item : recordList) { @@ -219,13 +217,13 @@ public class InvestBizServiceImpl implements InvestBizService { } //2、用户信息 - Map usersMap = getMap(userInfoService.getByIds(getIds(recordList, InvestRemindEntity::getOwner)), MallUserInfo::getId); + HashMap usersMap = getMap(userInfoService.getByIds(getIds(recordList, InvestRemindEntity::getOwner)), MallUserInfo::getId); //3、客户 Collection customers = customerService.listByIds(getIds(resultList, InvestRemindVo::getCustomerId)); - Map customerMap = getMap(customers, InvestCustomerEntity::getId); + HashMap customerMap = getMap(customers, InvestCustomerEntity::getId); //4、 品牌 - Map brandMap = getMap(brandService.getByIds(getIds(customers, InvestCustomerEntity::getBrandId)), WxBrand::getId); + HashMap brandMap = getMap(brandService.getByIds(getIds(customers, InvestCustomerEntity::getBrandId)), WxBrand::getId); for (InvestRemindVo remindVo : resultList) { InvestCustomerEntity customerEntity = customerMap.get(remindVo.getCustomerId()); @@ -293,7 +291,7 @@ public class InvestBizServiceImpl implements InvestBizService { InvestCustomerEntity customerEntity = customerService.getByIdNotNull(demandEntity.getCustomerId()); WxBrand brand = brandService.getById(customerEntity.getBrandId()); WxShop shop = shopService.getById(demandEntity.getTargetId()); - Map usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); + HashMap usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); return buildDemindItem(demandEntity, customerEntity, brand, shop, usersMap); } @@ -301,7 +299,7 @@ public class InvestBizServiceImpl implements InvestBizService { public InvestTaskVo findTaskById(Long id) { InvestTaskEntity taskEntity = taskService.getByIdNotNull(id); WxShop shop = shopService.getById(taskEntity.getTargetId()); - Map usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); + HashMap usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); return buildTaskItem(taskEntity, shop, usersMap); } @@ -323,7 +321,7 @@ public class InvestBizServiceImpl implements InvestBizService { @Override public InvestFollowRecordVo findFollowRecordById(Long id) { InvestFollowRecordEntity followRecordEntity = followRecordService.getByIdNotNull(id); - Map usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); + HashMap usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); InvestCustomerEntity customerEntity = customerService.getByIdNotNull(followRecordEntity.getCustomerId()); WxBrand brand = brandService.getById(customerEntity.getBrandId()); return buildFollowRecordItem(usersMap, followRecordEntity, customerEntity, brand); @@ -347,8 +345,10 @@ public class InvestBizServiceImpl implements InvestBizService { resultItemVo.setBrand(brand); resultItemVo.setCustomer(customer); resultItemVo.setTargetInfo(shop); - resultItemVo.setOwnerInfo(usersMap.get(item.getOwner())); - BeanUtils.copyProperties(item, resultItemVo); + if (Objects.nonNull(item)) { + resultItemVo.setOwnerInfo(usersMap.get(item.getOwner())); + BeanUtils.copyProperties(item, resultItemVo); + } return resultItemVo; } @@ -392,23 +392,26 @@ public class InvestBizServiceImpl implements InvestBizService { } private List getTargeInfoList(List demandList, Collection customers) { - Map demindsMap = getMap(demandList, InvestDemandEntity::getCustomerId); + HashMap demindsMap = getMap(demandList, InvestDemandEntity::getCustomerId); //3、目标信息 Collection shops = shopService.getByIds(getIds(demandList, InvestDemandEntity::getTargetId)); - Map shopsMap = getMap(shops, WxShop::getId); + HashMap shopsMap = getMap(shops, WxShop::getId); //4、品牌 - Map brandMap = getMap(brandService.getByIds(getIds(customers, InvestCustomerEntity::getBrandId)), WxBrand::getId); + HashMap brandMap = getMap(brandService.getByIds(getIds(customers, InvestCustomerEntity::getBrandId)), WxBrand::getId); //5、用户 - Map usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); + HashMap usersMap = getMap(userInfoService.findList(null), MallUserInfo::getId); List resultList = new ArrayList<>(); - for (InvestCustomerEntity item : customers) { - InvestDemandEntity demandItem = demindsMap.get(item.getId()); - WxShop shop = shopsMap.get(demandItem.getTargetId()); - WxBrand brand = brandMap.get(item.getBrandId()); - resultList.add(buildDemindItem(demandItem, item, brand, shop, usersMap)); + for (InvestCustomerEntity costomerItem : customers) { + InvestDemandEntity demandItem = demindsMap.get(costomerItem.getId()); + WxShop shop = null; + if (Objects.nonNull(demandItem)) { + shop = shopsMap.get(demandItem.getTargetId()); + } + WxBrand brand = brandMap.get(costomerItem.getBrandId()); + resultList.add(buildDemindItem(demandItem, costomerItem, brand, shop, usersMap)); } return resultList; } @@ -427,8 +430,9 @@ public class InvestBizServiceImpl implements InvestBizService { return function.apply(params); } - private Map getMap(Collection dataList, Function keyMapper) { - return dataList.parallelStream().collect(Collectors.toMap(keyMapper, entity -> entity)); + private HashMap getMap(Collection dataList, Function keyMapper) { + Map map = dataList.parallelStream().collect(Collectors.toMap(keyMapper, entity -> entity)); + return new HashMap<>(map); } private Collection getIds(Collection dataList, Function mapper) {