| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | |
| | | PageResult<CrmFollowUpRecordDO> pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO); |
| | | // 1.1 查询联系人和商机 |
| | | Map<Long, CrmContactDO> contactMap = contactService.getContactMap( |
| | | convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream())); |
| | | convertSetByFlatMap(pageResult.getList(), item -> { |
| | | List<Long> contactIds = item.getContactIds(); |
| | | return contactIds != null ? contactIds.stream() : Stream.empty(); |
| | | })); |
| | | Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap( |
| | | convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream())); |
| | | convertSetByFlatMap(pageResult.getList(), item -> { |
| | | List<Long> businessIds = item.getBusinessIds(); |
| | | return businessIds != null ? businessIds.stream() : Stream.empty(); |
| | | })); |
| | | // 1.2 查询用户 |
| | | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( |
| | | convertSet(pageResult.getList(), item -> Long.valueOf(item.getCreator()))); |
| | | convertSet(pageResult.getList(), item -> { |
| | | String creator = item.getCreator(); |
| | | return creator != null && !creator.isEmpty() ? Long.valueOf(creator) : null; |
| | | })); |
| | | // 2. 拼接数据 |
| | | PageResult<CrmFollowUpRecordRespVO> voPageResult = BeanUtils.toBean(pageResult, CrmFollowUpRecordRespVO.class, record -> { |
| | | // 2.1 设置联系人和商机信息 |
| | | record.setBusinesses(new ArrayList<>()).setContacts(new ArrayList<>()); |
| | | record.getContactIds().forEach(id -> MapUtils.findAndThen(contactMap, id, contact -> |
| | | List<Long> contactIds = record.getContactIds(); |
| | | if (contactIds != null) { |
| | | contactIds.forEach(id -> MapUtils.findAndThen(contactMap, id, contact -> |
| | | record.getContacts().add(new CrmBusinessRespVO().setId(contact.getId()).setName(contact.getName())))); |
| | | record.getBusinessIds().forEach(id -> MapUtils.findAndThen(businessMap, id, business -> |
| | | } |
| | | List<Long> businessIds = record.getBusinessIds(); |
| | | if (businessIds != null) { |
| | | businessIds.forEach(id -> MapUtils.findAndThen(businessMap, id, business -> |
| | | record.getBusinesses().add(new CrmBusinessRespVO().setId(business.getId()).setName(business.getName())))); |
| | | } |
| | | // 2.2 设置用户信息 |
| | | MapUtils.findAndThen(userMap, Long.valueOf(record.getCreator()), user -> record.setCreatorName(user.getNickname())); |
| | | String creator = record.getCreator(); |
| | | if (creator != null && !creator.isEmpty()) { |
| | | MapUtils.findAndThen(userMap, Long.valueOf(creator), user -> record.setCreatorName(user.getNickname())); |
| | | } |
| | | }); |
| | | return success(voPageResult); |
| | | } |