|
@@ -1,19 +1,23 @@
|
|
package shop.alien.second.service.impl;
|
|
package shop.alien.second.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
import shop.alien.entity.second.SecondGoods;
|
|
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.entity.second.vo.SecondGoodsVo;
|
|
|
|
+import shop.alien.entity.store.LifeAppealManage;
|
|
|
|
+import shop.alien.entity.store.StoreImg;
|
|
|
|
+import shop.alien.entity.store.vo.LifeAppealManageVo;
|
|
|
|
+import shop.alien.entity.store.vo.LifeUserVo;
|
|
|
|
+import shop.alien.mapper.LifeBlacklistMapper;
|
|
import shop.alien.mapper.LifeUserMapper;
|
|
import shop.alien.mapper.LifeUserMapper;
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
-import shop.alien.mapper.StoreInfoMapper;
|
|
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
import shop.alien.second.service.SecondGoodsService;
|
|
import shop.alien.second.service.SecondGoodsService;
|
|
import shop.alien.util.common.netease.ImageCheckUtil;
|
|
import shop.alien.util.common.netease.ImageCheckUtil;
|
|
@@ -48,6 +52,11 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
private final StoreImgMapper storeImgMapper;
|
|
private final StoreImgMapper storeImgMapper;
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 黑名单Mapper
|
|
|
|
+ */
|
|
|
|
+ private final LifeBlacklistMapper lifeBlacklistMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 保存商品为草稿状态
|
|
* 保存商品为草稿状态
|
|
* @param goods 商品实体
|
|
* @param goods 商品实体
|
|
* @return 是否成功保存
|
|
* @return 是否成功保存
|
|
@@ -304,44 +313,110 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
|
|
|
/**
|
|
/**
|
|
* 搜索商品列表
|
|
* 搜索商品列表
|
|
|
|
+ *
|
|
* @param page 分页参数
|
|
* @param page 分页参数
|
|
- * @param currentLatitude 当前位置纬度
|
|
|
|
- * @param currentLongitude 当前位置经度
|
|
|
|
- * @param orderData 排序字段
|
|
|
|
- * @param orderType 排序方式
|
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
+ * @param secondGoodsVo 搜索参数
|
|
* @return 商品列表
|
|
* @return 商品列表
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public IPage<SecondGoodsVo> searchGoodsList(IPage<SecondGoodsVo> page, Double currentLatitude, Double currentLongitude, String orderData, Integer orderType, Integer userId) {
|
|
|
|
|
|
+ public IPage<SecondGoodsVo> searchGoodsList(IPage<SecondGoodsVo> page,Integer userId, SecondGoodsVo secondGoodsVo) {
|
|
// 获取商品屏蔽列表
|
|
// 获取商品屏蔽列表
|
|
- List<SecondGoods> shieldedGoodsList = getShieldedGoodsList(userId);
|
|
|
|
|
|
+ List<SecondGoods> shieldedGoodsList = getShieldedGoodsList(userId);
|
|
// 提取屏蔽商品ID
|
|
// 提取屏蔽商品ID
|
|
List<Integer> shieldedGoodsIds = shieldedGoodsList.stream()
|
|
List<Integer> shieldedGoodsIds = shieldedGoodsList.stream()
|
|
.map(SecondGoods::getId)
|
|
.map(SecondGoods::getId)
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
+ if (CollectionUtil.isEmpty(shieldedGoodsIds)) {
|
|
|
|
+ shieldedGoodsIds = Collections.emptyList();
|
|
|
|
+ }
|
|
// 获取拉黑列表
|
|
// 获取拉黑列表
|
|
- List<Integer> userIdList = lifeBlackMapper.getBlackList(userId);
|
|
|
|
|
|
+ List<Integer> userIdList = lifeBlacklistMapper.getBlackList(userId);
|
|
if (CollectionUtil.isEmpty(userIdList)) {
|
|
if (CollectionUtil.isEmpty(userIdList)) {
|
|
userIdList = Collections.emptyList();
|
|
userIdList = Collections.emptyList();
|
|
}
|
|
}
|
|
|
|
+ secondGoodsVo.setShieldedGoodsIds(shieldedGoodsIds);
|
|
|
|
+ secondGoodsVo.setUserIdList(userIdList);
|
|
|
|
+
|
|
|
|
+ // 获取搜索结果分页列表
|
|
|
|
+ IPage<SecondGoodsVo> searchGoodsList = getSecondGoodsVoIPage(page, secondGoodsVo, shieldedGoodsIds, userIdList);
|
|
|
|
|
|
- IPage<SecondGoodsVo> searchGoodsList = secondGoodsMapper.searchGoodsList(page, currentLatitude, currentLongitude, orderData, orderType,shieldedGoodsIds, userIdList);
|
|
|
|
// 批量设置商品图片信息
|
|
// 批量设置商品图片信息
|
|
batchSetGoodsImages(searchGoodsList);
|
|
batchSetGoodsImages(searchGoodsList);
|
|
// 批量设置用户信息
|
|
// 批量设置用户信息
|
|
|
|
+
|
|
batchSetUserInfo(searchGoodsList);
|
|
batchSetUserInfo(searchGoodsList);
|
|
return searchGoodsList;
|
|
return searchGoodsList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 查询搜索结果
|
|
|
|
+ * @param page 分页参数
|
|
|
|
+ * @param secondGoodsVo 查询参数
|
|
|
|
+ * @param shieldedGoodsIds 屏蔽商品id
|
|
|
|
+ * @param userIdList 屏蔽用户id
|
|
|
|
+ * @return IPage<SecondGoodsVo> 搜索结果
|
|
|
|
+ */
|
|
|
|
+ private IPage<SecondGoodsVo> getSecondGoodsVoIPage(IPage<SecondGoodsVo> page, SecondGoodsVo secondGoodsVo, List<Integer> shieldedGoodsIds, List<Integer> userIdList) {
|
|
|
|
+ QueryWrapper<SecondGoodsVo> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.notIn(CollectionUtil.isNotEmpty(shieldedGoodsIds), "sg.id", shieldedGoodsIds)
|
|
|
|
+ .notIn(CollectionUtil.isNotEmpty(userIdList), "sg.user_id", userIdList)
|
|
|
|
+ .eq("sg.delete_flag", 0)
|
|
|
|
+ .orderByAsc("distance");
|
|
|
|
+ // 添加对 searchData 的模糊查询
|
|
|
|
+ if (!StringUtils.isEmpty(secondGoodsVo.getSearchData())) {
|
|
|
|
+ String searchData = "%" + secondGoodsVo.getSearchData() + "%";
|
|
|
|
+ queryWrapper.and(wrapper -> wrapper
|
|
|
|
+ .like("sg.label", searchData)
|
|
|
|
+ .or()
|
|
|
|
+ .like("sg.title", searchData)
|
|
|
|
+ .or()
|
|
|
|
+ .like("sg.describe", searchData)
|
|
|
|
+ .or()
|
|
|
|
+ .like("sgc1.category_name", searchData)
|
|
|
|
+ .or()
|
|
|
|
+ .like("sgc2.category_name", searchData)
|
|
|
|
+ .or()
|
|
|
|
+ .like("sg.topic", searchData)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ // 正序
|
|
|
|
+ if (secondGoodsVo.getOrderType() == 1){
|
|
|
|
+ queryWrapper.orderByAsc(secondGoodsVo.getOrderData());
|
|
|
|
+ }
|
|
|
|
+ // 倒序
|
|
|
|
+ if (secondGoodsVo.getOrderType() == 2){
|
|
|
|
+ queryWrapper.orderByDesc(secondGoodsVo.getOrderData());
|
|
|
|
+ }
|
|
|
|
+ // 返回分页结果
|
|
|
|
+ IPage<SecondGoodsVo> searchGoodsList = secondGoodsMapper.searchGoodsList(page, secondGoodsVo.getCurrentLatitude(), secondGoodsVo.getCurrentLongitude() ,queryWrapper);
|
|
|
|
+ searchGoodsList.getRecords().forEach(secondGoods -> {
|
|
|
|
+ secondGoods.setPosition(secondGoods.getSearchData());
|
|
|
|
+ });
|
|
|
|
+ return searchGoodsList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量设置用户信息
|
|
|
|
+ * @param searchGoodsList 搜索结果
|
|
|
|
+ */
|
|
private void batchSetUserInfo(IPage<SecondGoodsVo> searchGoodsList) {
|
|
private void batchSetUserInfo(IPage<SecondGoodsVo> searchGoodsList) {
|
|
// 批量获取用户信息(头像,用户姓名,用户id)
|
|
// 批量获取用户信息(头像,用户姓名,用户id)
|
|
if (CollectionUtil.isNotEmpty(searchGoodsList.getRecords())) {
|
|
if (CollectionUtil.isNotEmpty(searchGoodsList.getRecords())) {
|
|
List<Integer> userIds = searchGoodsList.getRecords().stream()
|
|
List<Integer> userIds = searchGoodsList.getRecords().stream()
|
|
.map(SecondGoodsVo::getUserId)
|
|
.map(SecondGoodsVo::getUserId)
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
- Map<Integer, LifeUser> userInfoMap = lifeUserMapper.getUserByIds(userIds);
|
|
|
|
|
|
+ // 批量获取用户信息
|
|
|
|
+ QueryWrapper<LifeUserVo> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.in("id", userIds); // 使用字符串 "user_id" 直接指定数据库列名
|
|
|
|
+ queryWrapper.in("delete_flag", 0);
|
|
|
|
+ List<LifeUserVo> userInfoList = lifeUserMapper.getUserByIds(queryWrapper);
|
|
|
|
+ // 根据用户id进行分组 返回map
|
|
|
|
+ Map<Integer, LifeUserVo> userInfoMap = userInfoList.stream()
|
|
|
|
+ .collect(Collectors.toMap(LifeUserVo::getId, lifeUserVo -> lifeUserVo));
|
|
|
|
+ // 获取用户信息
|
|
for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
|
|
for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
|
|
- LifeUser userInfo = userInfoMap.get(goods.getUserId());
|
|
|
|
|
|
+ LifeUserVo userInfo = userInfoMap.get(goods.getUserId());
|
|
if (userInfo != null){
|
|
if (userInfo != null){
|
|
// 用户名称
|
|
// 用户名称
|
|
goods.setUserName(userInfo.getUserName());
|
|
goods.setUserName(userInfo.getUserName());
|
|
@@ -368,7 +443,16 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
List<Integer> goodsIds = searchGoodsList.getRecords().stream()
|
|
List<Integer> goodsIds = searchGoodsList.getRecords().stream()
|
|
.map(SecondGoodsVo::getId)
|
|
.map(SecondGoodsVo::getId)
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
- Map<Integer, List<StoreImg>> imagesMap = storeImgMapper.getImgsByGoodsIds(goodsIds);
|
|
|
|
|
|
+ // 批量获取图片信息
|
|
|
|
+ QueryWrapper<StoreImg> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda()
|
|
|
|
+ .eq(StoreImg::getImgType, 18) // 商品 图片
|
|
|
|
+ .eq(StoreImg::getDeleteFlag, 0)
|
|
|
|
+ .in(StoreImg::getStoreId, goodsIds);
|
|
|
|
+ List<StoreImg> imagesList= storeImgMapper.getImgsByGoodsIds(queryWrapper);
|
|
|
|
+ // 集合根據商品id进行分组返回map
|
|
|
|
+ Map<Integer, List<StoreImg>> imagesMap = imagesList.stream().collect(Collectors.groupingBy(StoreImg::getStoreId));
|
|
|
|
+ // 遍历
|
|
for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
|
|
for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
|
|
// 提取图片url
|
|
// 提取图片url
|
|
List<StoreImg> images = imagesMap.get(goods.getId());
|
|
List<StoreImg> images = imagesMap.get(goods.getId());
|