|
|
@@ -1,26 +1,38 @@
|
|
|
package shop.alien.store.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.util.StringUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.second.SecondGoods;
|
|
|
+import shop.alien.entity.second.vo.SecondCommentVo;
|
|
|
+import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
|
|
|
+import shop.alien.entity.second.vo.SecondGoodsVo;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.vo.StoreInfoVo;
|
|
|
import shop.alien.mapper.*;
|
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
|
+import shop.alien.mapper.second.SecondRecommendMapper;
|
|
|
import shop.alien.store.annotation.TrackEvent;
|
|
|
import shop.alien.store.config.GaoDeMapUtil;
|
|
|
+import shop.alien.store.service.LifeDiscountCouponService;
|
|
|
+import shop.alien.util.common.Constants;
|
|
|
+import shop.alien.util.common.JwtUtil;
|
|
|
import shop.alien.util.common.ListToPage;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -38,6 +50,11 @@ public class LifeCollectController {
|
|
|
|
|
|
private final LifeCollectMapper lifeCollectMapper;
|
|
|
|
|
|
+
|
|
|
+ private SecondRecommendMapper secondRecommendMapper;
|
|
|
+
|
|
|
+ private final LifeUserMapper lifeUserMapper;
|
|
|
+
|
|
|
private final SecondGoodsMapper secondGoodsMapper;
|
|
|
|
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
|
@@ -290,4 +307,85 @@ public class LifeCollectController {
|
|
|
return R.success("取消收藏成功");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @ApiOperation("收藏商品列表")
|
|
|
+ @PostMapping("/collectSecondGoodsByPage")
|
|
|
+ public R<IPage<SecondGoodsRecommendVo>> collectSecondGoodsByPage(
|
|
|
+ @RequestParam(value = "pageNum", required = false) Integer pageNum,
|
|
|
+ @RequestParam(value = "pageSize", required = false) Integer pageSize,
|
|
|
+ @RequestParam(value = "longitude", required = false) String longitude,
|
|
|
+ @RequestParam(value = "latitude", required = false) String latitude) throws Exception {
|
|
|
+ log.info("LifeCollectController.cancelCollect?pageNum={},pageSize={},longitude={},latitude={}", pageNum, pageSize, longitude, latitude);
|
|
|
+ try {
|
|
|
+ IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
|
|
|
+ JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
+ String phoneId = null;
|
|
|
+ Integer userId = null;
|
|
|
+ if (data != null) {
|
|
|
+ phoneId = data.getString("phone");
|
|
|
+ userId = data.getInteger("userId");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(phoneId)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(userId);
|
|
|
+ // 获取商品屏蔽列表
|
|
|
+ List<SecondGoods> shieldedGoodsList = getShieldedGoodsList(userId);
|
|
|
+ // 提取屏蔽商品ID
|
|
|
+ List<Integer> shieldedGoodsIds = shieldedGoodsList.stream()
|
|
|
+ .map(SecondGoods::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+// QueryWrapper<SecondGoodsVo> queryWrapper = new QueryWrapper<>();
|
|
|
+// queryWrapper
|
|
|
+// // 可以查看已删除的商品数据
|
|
|
+// .eq("sg.delete_flag", Constants.DeleteFlag.NOT_DELETED)
|
|
|
+// .eq("lc.delete_flag", Constants.DeleteFlag.NOT_DELETED)
|
|
|
+// .notIn(CollectionUtil.isNotEmpty(shieldedGoodsIds), "sg.id", shieldedGoodsIds)
|
|
|
+// .eq("lc.user_id", "user_"+lifeUser.getUserPhone())
|
|
|
+// .orderByDesc("lc.created_time");
|
|
|
+
|
|
|
+ IPage<SecondGoodsRecommendVo> list = lifeCollectMapper.collectSecondGoodsByPage(page, userId, "user_" + phoneId, longitude + "," + latitude, shieldedGoodsIds);
|
|
|
+ List<Integer> idList = list.getRecords().stream() // 创建流
|
|
|
+ .map(obj -> obj.getId()) // 提取每个元素的 ID
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isEmpty(idList)) {
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+// List<SecondCommentVo> commentList =secondRecommendMapper.querySecondCommentInfo(idList);
|
|
|
+ list.getRecords().forEach(item -> {
|
|
|
+ // 距离拼接
|
|
|
+ if (StringUtil.isNotBlank(item.getDist())) {
|
|
|
+ item.setPosition("距离" + item.getDist() + "km");
|
|
|
+ }
|
|
|
+ // 价格保留两位小数
|
|
|
+ item.setPrice(item.getAmount() != null ? item.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP).toString() : null);
|
|
|
+
|
|
|
+ // 评论列表
|
|
|
+// List<SecondCommentVo> cList = new ArrayList<>();
|
|
|
+// commentList.forEach(comment -> {
|
|
|
+// if (item.getId().equals(comment.getBusinessId())) {
|
|
|
+// cList.add(comment);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// if (cList.size() > 0) {
|
|
|
+// item.setCommentList(cList);
|
|
|
+// }
|
|
|
+ });
|
|
|
+ return R.data(list);
|
|
|
+ } catch (Exception e){
|
|
|
+ log.error("收藏商品列表 Error Mgs={}", e.getMessage());
|
|
|
+ throw new Exception(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取商品屏蔽列表
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @return 商品屏蔽列表
|
|
|
+ */
|
|
|
+ private List<SecondGoods> getShieldedGoodsList(Integer userId) {
|
|
|
+ // 调用mapper方法
|
|
|
+ return secondGoodsMapper.getShieldedGoodsList(userId);
|
|
|
+ }
|
|
|
}
|