| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.page.BeanUtils; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.promotion.controller.management.dto.MgtPromotionWishListDTO; |
| | | import com.ruoyi.promotion.controller.management.dto.MgtPromotionWishListQuery; |
| | | import com.ruoyi.promotion.controller.management.vo.MgtPromotionWishListVO; |
| | | import com.ruoyi.promotion.domain.PromotionWishList; |
| | | import com.ruoyi.promotion.mapper.PromotionWishListMapper; |
| | | import com.ruoyi.promotion.service.IPromotionWishListService; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.dto.MemberDTO; |
| | | import com.ruoyi.system.api.domain.dto.PromotionWishListDTO; |
| | | import com.ruoyi.system.api.feignClient.MemberClient; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | * @since 2024-05-16 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class PromotionWishListServiceImpl extends ServiceImpl<PromotionWishListMapper, PromotionWishList> implements IPromotionWishListService { |
| | | |
| | | private final MemberClient memberClient; |
| | | |
| | | @Override |
| | | public PageDTO<PromotionWishList> getPromotionWishList(PromotionWishListDTO promotionWishListDTO) { |
| | |
| | | @Override |
| | | public PageDTO<MgtPromotionWishListVO> getPromotionWishListPage( |
| | | MgtPromotionWishListQuery query) { |
| | | return null; |
| | | // 封装会员条件查询对象 |
| | | MemberDTO memberDTO = new MemberDTO(); |
| | | if (StringUtils.isNotBlank(query.getNickname())) { |
| | | memberDTO.setNickname(query.getNickname()); |
| | | } |
| | | if (StringUtils.isNotBlank(query.getPhone())) { |
| | | memberDTO.setPhone(query.getPhone()); |
| | | } |
| | | // 远程调用会员服务进行条件查询 |
| | | List<Member> memberList = memberClient.getMemberListByCondition(memberDTO, |
| | | SecurityConstants.INNER).getData(); |
| | | Set<Long> memberIdSet = memberList.stream().map(Member::getId).collect(Collectors.toSet()); |
| | | // 分页查询心愿求购列表 |
| | | Page<PromotionWishList> page = this.lambdaQuery() |
| | | .eq(StringUtils.isNotNull(query.getReplyStatus()), |
| | | PromotionWishList::getReplyStatus, query.getReplyStatus()) |
| | | .in(StringUtils.isNotEmpty(memberIdSet), PromotionWishList::getMemberId, |
| | | memberIdSet).page(new Page<>(query.getPageCurr(), query |
| | | .getPageSize())); |
| | | if (StringUtils.isEmpty(page.getRecords())) { |
| | | return PageDTO.empty(page); |
| | | } |
| | | // 封装VO |
| | | PageDTO<MgtPromotionWishListVO> pageVO = PageDTO.of(page, |
| | | MgtPromotionWishListVO.class); |
| | | List<MgtPromotionWishListVO> MgtPromotionWishListVOList = pageVO.getList(); |
| | | Set<Long> memberIdSets = MgtPromotionWishListVOList.stream() |
| | | .map(MgtPromotionWishListVO::getMemberId) |
| | | .collect(Collectors.toSet()); |
| | | if (StringUtils.isNotEmpty(memberIdSets)) { |
| | | List<Member> data = memberClient.getMemberListByIds(memberIdSets, |
| | | SecurityConstants.INNER).getData(); |
| | | if (StringUtils.isNotEmpty(data)) { |
| | | Map<Long, Member> memberMap = data.stream() |
| | | .collect(Collectors.toMap(Member::getId, member -> member)); |
| | | for (MgtPromotionWishListVO mgtPromotionWishListVO : MgtPromotionWishListVOList) { |
| | | Member member = memberMap.get(mgtPromotionWishListVO.getMemberId()); |
| | | if (StringUtils.isNotNull(member)) { |
| | | mgtPromotionWishListVO.setNickname(member.getNickname()); |
| | | mgtPromotionWishListVO.setPhone(member.getPhone()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return pageVO; |
| | | } |
| | | |
| | | /** |
| | | * 查看详情 |
| | | * |
| | | * @param id 心愿求购id |
| | | * @return MgtPromotionWishListVO |
| | | */ |
| | | @Override |
| | | public MgtPromotionWishListVO getPromotionWishDetail(Long id) { |
| | | PromotionWishList promotionWishList = this.getById(id); |
| | | if (StringUtils.isNull(promotionWishList)) { |
| | | throw new ServiceException("该心愿求购不存在"); |
| | | } |
| | | MgtPromotionWishListVO mgtPromotionWishListVO = BeanUtils.copyBean(promotionWishList, |
| | | MgtPromotionWishListVO.class); |
| | | List<Member> data = memberClient.getMemberListByIds( |
| | | Lists.newArrayList(promotionWishList.getMemberId()), |
| | | SecurityConstants.INNER).getData(); |
| | | if (StringUtils.isNotEmpty(data)) { |
| | | mgtPromotionWishListVO.setPhone(data.get(0).getPhone()); |
| | | mgtPromotionWishListVO.setNickname(data.get(0).getNickname()); |
| | | } |
| | | return mgtPromotionWishListVO; |
| | | } |
| | | |
| | | /** |
| | | * 回复 |
| | | * |
| | | * @param dto 心愿求购数据传输对象 |
| | | */ |
| | | @Override |
| | | public void reply(MgtPromotionWishListDTO dto) { |
| | | PromotionWishList promotionWishList = this.getById(dto.getId()); |
| | | promotionWishList.setReplies(dto.getReplies()); |
| | | this.updateById(promotionWishList); |
| | | } |
| | | } |