|
@@ -2,28 +2,43 @@ package shop.alien.second.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.flogger.Flogger;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.util.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
|
|
|
+import shop.alien.entity.store.LifeFans;
|
|
|
import shop.alien.entity.store.StoreComment;
|
|
|
+import shop.alien.entity.store.StoreImg;
|
|
|
+import shop.alien.mapper.LifeFansMapper;
|
|
|
+import shop.alien.mapper.StoreImgMapper;
|
|
|
import shop.alien.mapper.second.SecondRecommendMapper;
|
|
|
import shop.alien.second.service.SecondRecommendService;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 二手商品服务实现类
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMapper, SecondGoodsRecommendVo> implements SecondRecommendService {
|
|
|
|
|
|
@Autowired
|
|
|
private SecondRecommendMapper mapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StoreImgMapper storeImgMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LifeFansMapper lifeFansMapper;
|
|
|
/**
|
|
|
* 获取二手商品推荐列表
|
|
|
* @param page 分页信息
|
|
@@ -31,26 +46,28 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
|
|
|
*/
|
|
|
@Override
|
|
|
public IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(
|
|
|
- IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId) {
|
|
|
- JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
- Integer userId = null;
|
|
|
- if (data != null) {
|
|
|
- userId = data.getInteger("userId");
|
|
|
- }
|
|
|
- if (userId == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- IPage<SecondGoodsRecommendVo> result = mapper.getSecondRecommendByPage(page, userId, longitude + "," + latitude, typeId);
|
|
|
- for (SecondGoodsRecommendVo row : result.getRecords()){
|
|
|
- if (StringUtil.isNotBlank(row.getDist())) {
|
|
|
- row.setPosition("距离" + row.getDist() + "km");
|
|
|
+ IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId) throws Exception {
|
|
|
+ try{
|
|
|
+ JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
+ Integer userId = null;
|
|
|
+ if (data != null) {
|
|
|
+ userId = data.getInteger("userId");
|
|
|
+ log.info("获取用户ID:userId={}", userId);
|
|
|
}
|
|
|
- if (StringUtil.isNotBlank(row.getTopic())) {
|
|
|
- List<String> topicList = Arrays.asList(row.getTopic().split(","));
|
|
|
- row.setTopicList(topicList);
|
|
|
+ if (userId == null) {
|
|
|
+ return null;
|
|
|
}
|
|
|
+ IPage<SecondGoodsRecommendVo> result = mapper.getSecondRecommendByPage(page, userId, longitude + "," + latitude, typeId);
|
|
|
+ for (SecondGoodsRecommendVo row : result.getRecords()) {
|
|
|
+ if (StringUtil.isNotBlank(row.getDist())) {
|
|
|
+ row.setPosition("距离" + row.getDist() + "km");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondRecommendServiceImpl.getSecondRecommendByPage Error Mgs={}", e.getMessage());
|
|
|
+ throw new Exception(e);
|
|
|
}
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -59,45 +76,46 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
|
|
|
* @return 关注列表
|
|
|
*/
|
|
|
public IPage<SecondGoodsRecommendVo> querySecondConcernByPage(
|
|
|
- IPage<SecondGoodsRecommendVo> page, String position) {
|
|
|
- JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
- String phoneId = null;
|
|
|
- if (data != null) {
|
|
|
- phoneId = data.getString("phone");
|
|
|
- }
|
|
|
- if (StringUtil.isBlank(phoneId)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- IPage<SecondGoodsRecommendVo> list = mapper.querySecondConcernByPage(page, "user_" + phoneId, position);
|
|
|
- List<Integer> idList = list.getRecords().stream() // 创建流
|
|
|
- .map(obj -> obj.getId()) // 提取每个元素的 ID
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (CollectionUtil.isEmpty(idList)) {
|
|
|
- return list;
|
|
|
- }
|
|
|
- List<StoreComment> commentList =mapper.querySecondCommentInfo(idList);
|
|
|
- list.getRecords().forEach(item -> {
|
|
|
- // 距离拼接
|
|
|
- if (StringUtil.isNotBlank(item.getDist())) {
|
|
|
- item.setPosition("距离" + item.getDist() + "km");
|
|
|
+ IPage<SecondGoodsRecommendVo> page, String position) throws Exception {
|
|
|
+ try {
|
|
|
+ JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
+ String phoneId = null;
|
|
|
+ if (data != null) {
|
|
|
+ phoneId = data.getString("phone");
|
|
|
}
|
|
|
- // 话题列表
|
|
|
- if (StringUtil.isNotBlank(item.getTopic())) {
|
|
|
- List<String> topicList = Arrays.asList(item.getTopic().split(","));
|
|
|
- item.setTopicList(topicList);
|
|
|
+ if (StringUtil.isBlank(phoneId)) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- // 评论列表
|
|
|
- List<StoreComment> cList = new ArrayList<>();
|
|
|
- commentList.forEach(comment -> {
|
|
|
- if (item.getId() == comment.getBusinessId()) {
|
|
|
- cList.add(comment);
|
|
|
+ IPage<SecondGoodsRecommendVo> list = mapper.querySecondConcernByPage(page, "user_" + phoneId, position);
|
|
|
+ List<Integer> idList = list.getRecords().stream() // 创建流
|
|
|
+ .map(obj -> obj.getId()) // 提取每个元素的 ID
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isEmpty(idList)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ List<StoreComment> commentList =mapper.querySecondCommentInfo(idList);
|
|
|
+ list.getRecords().forEach(item -> {
|
|
|
+ // 距离拼接
|
|
|
+ if (StringUtil.isNotBlank(item.getDist())) {
|
|
|
+ item.setPosition("距离" + item.getDist() + "km");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 评论列表
|
|
|
+ List<StoreComment> cList = new ArrayList<>();
|
|
|
+ commentList.forEach(comment -> {
|
|
|
+ if (item.getId() == comment.getBusinessId()) {
|
|
|
+ cList.add(comment);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (cList.size() > 0) {
|
|
|
+ item.setCommentList(cList);
|
|
|
}
|
|
|
});
|
|
|
- if (cList.size() > 0) {
|
|
|
- item.setCommentList(cList);
|
|
|
- }
|
|
|
- });
|
|
|
- return list;
|
|
|
+ return list;
|
|
|
+ } catch (Exception e){
|
|
|
+ log.error("SecondRecommendServiceImpl.querySecondConcernByPage Error Mgs={}", e.getMessage());
|
|
|
+ throw new Exception(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -107,70 +125,94 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
|
|
|
* @return 关注列表
|
|
|
*/
|
|
|
public IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(
|
|
|
- IPage<SecondGoodsRecommendVo> page, String position) {
|
|
|
- JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
- String phoneId = null;
|
|
|
- String userId = null;
|
|
|
- if (data != null) {
|
|
|
- phoneId = data.getString("phone");
|
|
|
- userId = data.getString("userId");
|
|
|
- }
|
|
|
- if (StringUtil.isBlank(phoneId)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- IPage<SecondGoodsRecommendVo> list = mapper.querySecondNewGoodsByPage(page, userId,"user_" + phoneId, position);
|
|
|
- List<Integer> idList = list.getRecords().stream() // 创建流
|
|
|
- .map(obj -> obj.getId()) // 提取每个元素的 ID
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (CollectionUtil.isEmpty(idList)) {
|
|
|
- return list;
|
|
|
- }
|
|
|
- List<StoreComment> commentList =mapper.querySecondCommentInfo(idList);
|
|
|
- list.getRecords().forEach(item -> {
|
|
|
- // 距离拼接
|
|
|
- if (StringUtil.isNotBlank(item.getDist())) {
|
|
|
- item.setPosition("距离" + item.getDist() + "km");
|
|
|
+ IPage<SecondGoodsRecommendVo> page, String position) throws Exception{
|
|
|
+ try {
|
|
|
+ JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
+ String phoneId = null;
|
|
|
+ String userId = null;
|
|
|
+ if (data != null) {
|
|
|
+ phoneId = data.getString("phone");
|
|
|
+ userId = data.getString("userId");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(phoneId)) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- // 话题列表
|
|
|
- if (StringUtil.isNotBlank(item.getTopic())) {
|
|
|
- List<String> topicList = Arrays.asList(item.getTopic().split(","));
|
|
|
- item.setTopicList(topicList);
|
|
|
+ IPage<SecondGoodsRecommendVo> list = mapper.querySecondNewGoodsByPage(page, userId,"user_" + phoneId, position);
|
|
|
+ List<Integer> idList = list.getRecords().stream() // 创建流
|
|
|
+ .map(obj -> obj.getId()) // 提取每个元素的 ID
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isEmpty(idList)) {
|
|
|
+ return list;
|
|
|
}
|
|
|
- // 评论列表
|
|
|
- List<StoreComment> cList = new ArrayList<>();
|
|
|
- commentList.forEach(comment -> {
|
|
|
- if (item.getId() == comment.getBusinessId()) {
|
|
|
- cList.add(comment);
|
|
|
+ List<StoreComment> commentList = mapper.querySecondCommentInfo(idList);
|
|
|
+ list.getRecords().forEach(item -> {
|
|
|
+ // 距离拼接
|
|
|
+ if (StringUtil.isNotBlank(item.getDist())) {
|
|
|
+ item.setPosition("距离" + item.getDist() + "km");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 评论列表
|
|
|
+ List<StoreComment> cList = new ArrayList<>();
|
|
|
+ commentList.forEach(comment -> {
|
|
|
+ if (item.getId() == comment.getBusinessId()) {
|
|
|
+ cList.add(comment);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (cList.size() > 0) {
|
|
|
+ item.setCommentList(cList);
|
|
|
}
|
|
|
});
|
|
|
- if (cList.size() > 0) {
|
|
|
- item.setCommentList(cList);
|
|
|
- }
|
|
|
- });
|
|
|
- return list;
|
|
|
+ return list;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondRecommendServiceImpl.querySecondNewGoodsByPage Error Mgs={}", e.getMessage());
|
|
|
+ throw new Exception(e);
|
|
|
+ }
|
|
|
}
|
|
|
- public static void main(String[] args) {
|
|
|
- List<Map<String, Object>> list = new ArrayList<>();
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("id", 1);
|
|
|
- map.put("name", "张三");
|
|
|
- list.add(map);
|
|
|
- Map<String, Object> map1 = new HashMap<>();
|
|
|
- map1.put("id", 2);
|
|
|
- map1.put("name", "张三");
|
|
|
- list.add(map1);
|
|
|
- Map<String, Object> map2 = new HashMap<>();
|
|
|
- map2.put("id", 3);
|
|
|
- map2.put("name", "张三");
|
|
|
- list.add(map2);
|
|
|
- Map<String, Object> map3 = new HashMap<>();
|
|
|
- map3.put("id", 4);
|
|
|
- map3.put("name", "张三");
|
|
|
- list.add(map3);
|
|
|
- List<String> idList = list.stream() // 创建流
|
|
|
- .map(obj -> obj.get("id").toString()) // 提取每个元素的 ID
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
- System.out.println(idList);
|
|
|
+ public SecondGoodsRecommendVo querySecondGoodsDetail(Integer goodsId, String position) throws Exception {
|
|
|
+ try {
|
|
|
+ JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
+ String phoneId = null;
|
|
|
+ if (data != null) {
|
|
|
+ phoneId = data.getString("phone");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(phoneId)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SecondGoodsRecommendVo item = mapper.querySecondGoodsDetail(goodsId, "user_" + phoneId, position);
|
|
|
+
|
|
|
+ // 设置图片信息
|
|
|
+ QueryWrapper<StoreImg> query = new QueryWrapper<>();
|
|
|
+ query.lambda()
|
|
|
+ .eq(StoreImg::getImgType, 18) // 商品 图片
|
|
|
+ .eq(StoreImg::getDeleteFlag, 0)
|
|
|
+ .eq(StoreImg::getStoreId, goodsId);
|
|
|
+ List<StoreImg> storeImgs = storeImgMapper.selectList(query);
|
|
|
+ // 设置图片信息
|
|
|
+ if (storeImgs.size() > 0) {
|
|
|
+ item.setImgList(storeImgs.stream().map(StoreImg::getImgUrl).toArray(String[]::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查看是否关注
|
|
|
+ QueryWrapper<LifeFans> query1 = new QueryWrapper<>();
|
|
|
+ query1.lambda()
|
|
|
+ .eq(LifeFans::getFollowedId, item.getUserPhone()) // 商品 图片
|
|
|
+ .eq(LifeFans::getDeleteFlag, 0)
|
|
|
+ .eq(LifeFans::getFansId, "user_" + phoneId);
|
|
|
+ List<LifeFans> lifeFans = lifeFansMapper.selectList(query1);
|
|
|
+ // 关注状态添加
|
|
|
+ if (lifeFans.size() > 0) {
|
|
|
+ item.setFansStatus(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 距离拼接
|
|
|
+ if (StringUtil.isNotBlank(item.getDist())) {
|
|
|
+ item.setPosition("距离" + item.getDist() + "km");
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondRecommendServiceImpl.querySecondGoodsDetail Error Mgs={}", e.getMessage());
|
|
|
+ throw new Exception(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|