| | |
| | | import com.xiaopeng.account.model.vo.CollectAddrTargetVO; |
| | | import com.xiaopeng.account.model.vo.XpAppUserCollectAddrVO; |
| | | import com.xiaopeng.account.service.IXpAppUserCollectAddrService; |
| | | import com.xiaopeng.api.dto.map.XpPointExportExcelQuery; |
| | | import com.xiaopeng.api.feignClient.map.XpStationClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpPointClient; |
| | | import com.xiaopeng.api.model.account.XpAppUserCollectAddr; |
| | | import com.xiaopeng.api.model.operation.XpPoint; |
| | | import com.xiaopeng.api.model.operation.XpStation; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | |
| | | private static final int ITEM_TYPE_STATION = 2; |
| | | private static final int COLLECT_LIMIT = 50; |
| | | |
| | | |
| | | @Resource |
| | | private XpPointClient xpPointClient; |
| | | |
| | | @Resource |
| | | private XpStationClient xpStationClient; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 收藏地址。 |
| | | * 收藏表显式保存 item_type / station_id: |
| | |
| | | @Override |
| | | public Boolean collectAddr(CollectAddrDTO dto, String uid) { |
| | | Long userId = Long.parseLong(uid); |
| | | CollectAddrTargetVO target = resolveCollectTarget(dto); |
| | | if (target == null || target.getPointId() == null || target.getItemType() == null) { |
| | | throw new ServiceException("收藏目标不存在"); |
| | | if(dto.getItemType() == 1){ |
| | | XpPointExportExcelQuery xpPointExportExcelQuery = new XpPointExportExcelQuery(); |
| | | xpPointExportExcelQuery.setPointIds(Arrays.asList(dto.getPointId())); |
| | | List<XpPoint> data = xpPointClient.getByIds(xpPointExportExcelQuery).getData(); |
| | | if(null == data || data.size() == 0){ |
| | | throw new ServiceException("站点不存在"); |
| | | } |
| | | } |
| | | if(dto.getItemType() == 2){ |
| | | XpStation data = xpStationClient.getXpStationById(dto.getStationId()).getData(); |
| | | if(null == data){ |
| | | throw new ServiceException("场站不存在"); |
| | | } |
| | | } |
| | | |
| | | LambdaQueryWrapper<XpAppUserCollectAddr> sameTargetWrapper = buildSameTargetWrapper(userId, target); |
| | | if (COLLECT_TYPE_ADD == dto.getType()) { |
| | | Long count = this.count(new LambdaQueryWrapper<XpAppUserCollectAddr>() |
| | | .eq(XpAppUserCollectAddr::getAppUserId, userId) |
| | | .eq(XpAppUserCollectAddr::getDeleted, 0)); |
| | | if (count >= COLLECT_LIMIT) { |
| | | throw new ServiceException("收藏夹已满,请先删除旧地址"); |
| | | } |
| | | if (this.count(sameTargetWrapper) > 0) { |
| | | return true; |
| | | } |
| | | |
| | | if(1 == dto.getType()){ |
| | | XpAppUserCollectAddr collectAddr = new XpAppUserCollectAddr(); |
| | | collectAddr.setAppUserId(userId); |
| | | collectAddr.setItemType(target.getItemType()); |
| | | collectAddr.setPointId(target.getPointId()); |
| | | collectAddr.setStationId(target.getStationId()); |
| | | collectAddr.setLongitude(target.getLongitude()); |
| | | collectAddr.setLatitude(target.getLatitude()); |
| | | collectAddr.setItemType(dto.getItemType()); |
| | | collectAddr.setPointId(dto.getPointId()); |
| | | collectAddr.setStationId(dto.getStationId()); |
| | | collectAddr.setLongitude(dto.getLongitude()); |
| | | collectAddr.setLatitude(dto.getLatitude()); |
| | | return this.save(collectAddr); |
| | | } |
| | | |
| | | if (COLLECT_TYPE_CANCEL == dto.getType()) { |
| | | XpAppUserCollectAddr collectAddr = this.getOne(sameTargetWrapper.last("limit 1")); |
| | | if (collectAddr == null) { |
| | | return true; |
| | | }else{ |
| | | if(dto.getItemType() == 1){ |
| | | return this.remove(new LambdaQueryWrapper<XpAppUserCollectAddr>().eq(XpAppUserCollectAddr::getAppUserId, userId) |
| | | .eq(XpAppUserCollectAddr::getPointId, dto.getPointId())); |
| | | } |
| | | return this.removeById(collectAddr.getId()); |
| | | } |
| | | if(dto.getItemType() == 2){ |
| | | return this.remove(new LambdaQueryWrapper<XpAppUserCollectAddr>().eq(XpAppUserCollectAddr::getAppUserId, userId) |
| | | .eq(XpAppUserCollectAddr::getStationId, dto.getStationId())); |
| | | } |
| | | |
| | | throw new ServiceException("不支持的操作类型"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | public PageInfo<XpAppUserCollectAddrVO> userCollectAddrList(XpUserCollectAddrListQuery query, String uid) { |
| | | Page<XpAppUserCollectAddrVO> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | Page<XpAppUserCollectAddrVO> pageData = this.baseMapper.userCollectAddrPageList(page, query, Long.parseLong(uid)); |
| | | pageData.getRecords().forEach(xpAppUserCollectAddrVO -> { |
| | | if(xpAppUserCollectAddrVO.getItemType() == 1){ |
| | | XpPointExportExcelQuery xpPointExportExcelQuery = new XpPointExportExcelQuery(); |
| | | xpPointExportExcelQuery.setPointIds(Arrays.asList(xpAppUserCollectAddrVO.getPointId())); |
| | | List<XpPoint> data = xpPointClient.getByIds(xpPointExportExcelQuery).getData(); |
| | | if(null != data && data.size() > 0){ |
| | | xpAppUserCollectAddrVO.setPointName(data.get(0).getPointName()); |
| | | xpAppUserCollectAddrVO.setPointAddress(data.get(0).getPointAddress()); |
| | | } |
| | | } |
| | | if(xpAppUserCollectAddrVO.getItemType() == 2){ |
| | | XpStation data = xpStationClient.getXpStationById(xpAppUserCollectAddrVO.getStationId()).getData(); |
| | | if(null != data){ |
| | | xpAppUserCollectAddrVO.setPointName(data.getStationName()); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | PageInfo<XpAppUserCollectAddrVO> resultPage = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | resultPage.setTotal(pageData.getTotal()); |