From 37bb58d1657588d86916e59771c8428703caf3ea Mon Sep 17 00:00:00 2001 From: Burce Date: Wed, 23 Oct 2019 11:57:10 +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 --- .../iformall/service/invest/InvestHelper.java | 8 ++++ .../service/invest/event/InvestListener.java | 17 ++++--- .../invest/impl/InvestBizServiceImpl.java | 47 ++++++++++++------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java index 8c9884955..3b3f90943 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java @@ -6,8 +6,10 @@ import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Multimaps; import com.iformall.common.ErrorCode; import com.iformall.domain.po.invest.InvestBaseEntity; +import com.iformall.domain.po.invest.InvestTaskEntity; import com.iformall.domain.vo.invest.InvestPageQuery; import com.iformall.exception.MallinkException; +import com.iformall.utils.JsonUtil; import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.Nullable; @@ -173,4 +175,10 @@ public class InvestHelper { public static Collection getIds(Collection dataList, Predicate predicate,Function mapper) { return dataList.parallelStream().filter(predicate).map(mapper).collect(Collectors.toList()); } + + public static String addContractId(String content,Long rentId) { + Map contentMap = JSON.parseObject(content, Map.class); + contentMap.put(InvestTaskEntity.KEY_CONTRACTID, rentId); + return JsonUtil.obj2Json(contentMap); + } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java b/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java index b7f80ee9e..de38b6aa4 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/event/InvestListener.java @@ -7,6 +7,7 @@ import com.iformall.domain.vo.RentEventInfo; import com.iformall.enums.EnumInvestType; import com.iformall.enums.EnumRentContractStatus; import com.iformall.enums.EnumTaskStatus; +import com.iformall.service.invest.InvestHelper; import com.iformall.service.invest.InvestTaskService; import com.iformall.utils.JsonUtil; import lombok.extern.slf4j.Slf4j; @@ -48,15 +49,17 @@ public class InvestListener implements ApplicationListener { status = EnumTaskStatus.FINISH; } else if (Objects.equals(EnumRentContractStatus.RENT_PAID, rentContractStatus)) { status = EnumTaskStatus.FINISH; + } else if (Objects.equals(EnumRentContractStatus.CONTRACT_END_SOON, rentContractStatus)) { + status = EnumTaskStatus.FINISH; } - for (InvestTaskEntity task : tasks) { - task.setStatus(status); - String content = task.getContent(); - Map contentMap = JSON.parseObject(content, Map.class); - contentMap.put(InvestTaskEntity.KEY_CONTRACTID, rentEventInfo.getRentId()); - task.setContent(JsonUtil.obj2Json(contentMap)); + if (status == EnumTaskStatus.FINISH) { + for (InvestTaskEntity task : tasks) { + task.setStatus(status); + task.setContent(InvestHelper.addContractId(task.getContent(),rentEventInfo.getRentId())); + } + taskService.updateBatchById(tasks); } - taskService.updateBatchById(tasks); + } } 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 b1ea7956e..268b1b32d 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 @@ -76,7 +76,7 @@ public class InvestBizServiceImpl implements InvestBizService { queryWrapperCustomer.in(ObjectUtils.allNotNull(params.getDemandOwner()), InvestCustomerEntity::getId, getIds(demandList, InvestDemandEntity::getCustomerId)); } else { - if(CollectionUtils.isEmpty(demandList)) { + if (CollectionUtils.isEmpty(demandList)) { return investPage; } else { queryWrapperCustomer.in(InvestCustomerEntity::getId, getIds(demandList, InvestDemandEntity::getCustomerId)); @@ -399,7 +399,7 @@ public class InvestBizServiceImpl implements InvestBizService { @Override public boolean saveCustomerAndDemand(InvestDemandDto demandDto) { InvestHelper.notNull(demandDto, demandDto.getCustomer(), demandDto.getDemand()); - InvestCustomerEntity customerEntity = demandDto.getCustomer() ; + InvestCustomerEntity customerEntity = demandDto.getCustomer(); customerService.save(customerEntity); InvestDemandEntity demandEntity = demandDto.getDemand(); demandEntity.setCustomerId(customerEntity.getId()); @@ -485,8 +485,7 @@ public class InvestBizServiceImpl implements InvestBizService { } //3、商品合同信息 - Map shopContractMap = rentContractService.selectRentContractByShopIds(Arrays.asList(shop.getId()), StringUtils.join(shop.getId(), "|"), - InvestUserContext.getUser().getTenantId()); + Map shopContractMap = getWxRentContractMap(shop); WxRentContract contract = shopContractMap.get(shop.getId()); if (Objects.nonNull(contract)) { shopVo.setStartdate(contract.getRentalStartDate()); @@ -498,6 +497,12 @@ public class InvestBizServiceImpl implements InvestBizService { return buildTaskItem(taskEntity, shopVo, usersMap); } + private Map getWxRentContractMap(WxShop shop) { + InvestHelper.notNull(shop, "商铺不存在"); + return rentContractService.selectRentContractByShopIds(Arrays.asList(shop.getId()), StringUtils.join(shop.getId(), "|"), + InvestUserContext.getUser().getTenantId()); + } + @Override public InvestRemindVo findRemindById(Long id) { InvestRemindEntity remindEntity = remindService.getByIdNotNull(id); @@ -574,16 +579,26 @@ public class InvestBizServiceImpl implements InvestBizService { } private void syncTargetStatus(InvestTaskEntity investTaskEntity) { - WxRentContract contractQuery = new WxRentContract(); - contractQuery.setTenantId(InvestUserContext.getUser().getTenantId()); - contractQuery.setShopId(investTaskEntity.getTargetId()); - contractQuery.setStatus(EnumRentContractStatus.INTENTION.getCode()); - int count = rentContractService.selectContractCountByShopId(contractQuery); - if (count > 0) { - investTaskEntity.setStatus(EnumTaskStatus.INTENTION); + if (!Objects.equals(investTaskEntity.getTargetType(), EnumInvestType.RENT)) { + return; + } + WxShop shop = shopService.getById(investTaskEntity.getTargetId()); + Map shopContractMap = getWxRentContractMap(shop); + WxRentContract contract = shopContractMap.get(shop.getId()); + if (Objects.nonNull(contract)) { + InvestHelper.addContractId(investTaskEntity.getContent(), contract.getId()); } else { - if (StringUtils.isNotBlank(investTaskEntity.getOwner())) { - investTaskEntity.setStatus(EnumTaskStatus.NEGOTIATING); + WxRentContract contractQuery = new WxRentContract(); + contractQuery.setTenantId(InvestUserContext.getUser().getTenantId()); + contractQuery.setShopId(investTaskEntity.getTargetId()); + contractQuery.setStatus(EnumRentContractStatus.INTENTION.getCode()); + int count = rentContractService.selectContractCountByShopId(contractQuery); + if (count > 0) { + investTaskEntity.setStatus(EnumTaskStatus.INTENTION); + } else { + if (StringUtils.isNotBlank(investTaskEntity.getOwner())) { + investTaskEntity.setStatus(EnumTaskStatus.NEGOTIATING); + } } } } @@ -723,7 +738,7 @@ public class InvestBizServiceImpl implements InvestBizService { //4、品牌 Map brandMap = getMap(brandService.getByIds(getIds(customers, InvestCustomerEntity::getBrandId)), WxBrand::getId); //5、用户 - Map usersMap = getMap(userInfoService.getByIds(getIds(demandList,InvestDemandEntity::getOwner)), MallUserInfo::getId); + Map usersMap = getMap(userInfoService.getByIds(getIds(demandList, InvestDemandEntity::getOwner)), MallUserInfo::getId); List resultList = new ArrayList<>(); for (InvestCustomerEntity costomerItem : customers) { @@ -753,8 +768,8 @@ public class InvestBizServiceImpl implements InvestBizService { } private Map getMap(Collection dataList, Function keyMapper) { - if(CollectionUtils.isEmpty(dataList)) { - return new HashMap<>() ; + if (CollectionUtils.isEmpty(dataList)) { + return new HashMap<>(); } return InvestHelper.getMap(dataList, keyMapper); }