|
@@ -3,17 +3,23 @@ package shop.alien.second.service.impl;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import shop.alien.entity.second.SecondGoods;
|
|
|
+import shop.alien.entity.store.LifeUser;
|
|
|
import shop.alien.entity.store.StoreImg;
|
|
|
import shop.alien.entity.second.vo.SecondGoodsVo;
|
|
|
+import shop.alien.mapper.LifeUserMapper;
|
|
|
+import shop.alien.mapper.StoreImgMapper;
|
|
|
+import shop.alien.mapper.StoreInfoMapper;
|
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
|
import shop.alien.second.service.SecondGoodsService;
|
|
|
import shop.alien.util.common.netease.ImageCheckUtil;
|
|
|
import shop.alien.util.common.netease.TextCheckUtil;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -23,10 +29,24 @@ import java.util.stream.Collectors;
|
|
|
* 二手商品服务实现类
|
|
|
*/
|
|
|
@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, SecondGoods> implements SecondGoodsService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private SecondGoodsMapper secondGoodsMapper;
|
|
|
+ /**
|
|
|
+ * 二手商品Mapper
|
|
|
+ */
|
|
|
+ private final SecondGoodsMapper secondGoodsMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户信息Mapper
|
|
|
+ */
|
|
|
+ private final LifeUserMapper lifeUserMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 店铺信息Mapper
|
|
|
+ */
|
|
|
+ private final StoreImgMapper storeImgMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 保存商品为草稿状态
|
|
|
* @param goods 商品实体
|
|
@@ -281,4 +301,84 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
public IPage<SecondGoods> getShieldedGoodsListByType(IPage<SecondGoods> page, Integer userId, Integer shieldType) {
|
|
|
return secondGoodsMapper.getShieldedGoodsListByType(page, userId, shieldType);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 搜索商品列表
|
|
|
+ * @param page 分页参数
|
|
|
+ * @param currentLatitude 当前位置纬度
|
|
|
+ * @param currentLongitude 当前位置经度
|
|
|
+ * @param orderData 排序字段
|
|
|
+ * @param orderType 排序方式
|
|
|
+ * @return 商品列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<SecondGoodsVo> searchGoodsList(IPage<SecondGoodsVo> page, Double currentLatitude, Double currentLongitude, String orderData, Integer orderType, Integer userId) {
|
|
|
+ // 获取商品屏蔽列表
|
|
|
+ List<SecondGoods> shieldedGoodsList = getShieldedGoodsList(userId);
|
|
|
+ // 提取屏蔽商品ID
|
|
|
+ List<Integer> shieldedGoodsIds = shieldedGoodsList.stream()
|
|
|
+ .map(SecondGoods::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 获取拉黑列表
|
|
|
+ List<Integer> userIdList = lifeBlackMapper.getBlackList(userId);
|
|
|
+ if (CollectionUtil.isEmpty(userIdList)) {
|
|
|
+ userIdList = Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ IPage<SecondGoodsVo> searchGoodsList = secondGoodsMapper.searchGoodsList(page, currentLatitude, currentLongitude, orderData, orderType,shieldedGoodsIds, userIdList);
|
|
|
+ // 批量设置商品图片信息
|
|
|
+ batchSetGoodsImages(searchGoodsList);
|
|
|
+ // 批量设置用户信息
|
|
|
+ batchSetUserInfo(searchGoodsList);
|
|
|
+ return searchGoodsList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void batchSetUserInfo(IPage<SecondGoodsVo> searchGoodsList) {
|
|
|
+ // 批量获取用户信息(头像,用户姓名,用户id)
|
|
|
+ if (CollectionUtil.isNotEmpty(searchGoodsList.getRecords())) {
|
|
|
+ List<Integer> userIds = searchGoodsList.getRecords().stream()
|
|
|
+ .map(SecondGoodsVo::getUserId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Integer, LifeUser> userInfoMap = lifeUserMapper.getUserByIds(userIds);
|
|
|
+ for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
|
|
|
+ LifeUser userInfo = userInfoMap.get(goods.getUserId());
|
|
|
+ if (userInfo != null){
|
|
|
+ // 用户名称
|
|
|
+ goods.setUserName(userInfo.getUserName());
|
|
|
+ // 用户真实姓名
|
|
|
+ goods.setRealName(userInfo.getRealName());
|
|
|
+ // 用户头像
|
|
|
+ goods.setUserImage(userInfo.getUserImage());
|
|
|
+ // 用户id
|
|
|
+ goods.setUserId(userInfo.getId());
|
|
|
+ // 用户手机号
|
|
|
+ goods.setUserPhone(userInfo.getUserPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量设置商品图片信息
|
|
|
+ * @param searchGoodsList 商品列表
|
|
|
+ */
|
|
|
+ private void batchSetGoodsImages(IPage<SecondGoodsVo> searchGoodsList) {
|
|
|
+ // 批量获取图片信息
|
|
|
+ if (CollectionUtil.isNotEmpty(searchGoodsList.getRecords())) {
|
|
|
+ List<Integer> goodsIds = searchGoodsList.getRecords().stream()
|
|
|
+ .map(SecondGoodsVo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Integer, List<StoreImg>> imagesMap = storeImgMapper.getImgsByGoodsIds(goodsIds);
|
|
|
+ for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
|
|
|
+ // 提取图片url
|
|
|
+ List<StoreImg> images = imagesMap.get(goods.getId());
|
|
|
+ if (images != null) {
|
|
|
+ goods.setImgUrl(images.stream()
|
|
|
+ .map(StoreImg::getImgUrl)
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|