|
@@ -1,19 +1,23 @@
|
|
|
package shop.alien.second.service.impl;
|
|
package shop.alien.second.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
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.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import io.swagger.models.auth.In;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import shop.alien.config.properties.RiskControlProperties;
|
|
import shop.alien.config.properties.RiskControlProperties;
|
|
|
|
|
+import shop.alien.config.redis.BaseRedisService;
|
|
|
import shop.alien.entity.result.BusinessException;
|
|
import shop.alien.entity.result.BusinessException;
|
|
|
import shop.alien.entity.second.*;
|
|
import shop.alien.entity.second.*;
|
|
|
import shop.alien.mapper.second.SecondRiskControlRecordMapper;
|
|
import shop.alien.mapper.second.SecondRiskControlRecordMapper;
|
|
@@ -34,10 +38,7 @@ import shop.alien.second.service.SecondTradeRecordService;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
|
|
import java.time.*;
|
|
import java.time.*;
|
|
|
-import java.util.Comparator;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -65,6 +66,7 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
|
|
|
private final LifeUserMapper lifeUserMapper;
|
|
private final LifeUserMapper lifeUserMapper;
|
|
|
private final AlienStoreFeign alienStoreFeign;
|
|
private final AlienStoreFeign alienStoreFeign;
|
|
|
private final StoreDictionaryMapper storeDictionaryMapper;
|
|
private final StoreDictionaryMapper storeDictionaryMapper;
|
|
|
|
|
+ private final BaseRedisService baseRedisService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RiskControlProperties riskControlProperties;
|
|
private RiskControlProperties riskControlProperties;
|
|
|
|
|
|
|
@@ -967,7 +969,119 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
|
|
|
throw new Exception("获取卖家评价列表失败: " + e.getMessage());
|
|
throw new Exception("获取卖家评价列表失败: " + e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void locationShareAdd(Integer otherUserId) throws Exception {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
|
|
|
|
|
+ String key = getKey(userId, otherUserId);
|
|
|
|
|
+
|
|
|
|
|
+ if (baseRedisService.hasKey(key)) {
|
|
|
|
|
+ JSONArray array = JSONArray.parseArray(baseRedisService.getString(key));
|
|
|
|
|
+ if (!array.contains(userId)) array.add(userId);
|
|
|
|
|
+ baseRedisService.setString(key, array.toJSONString());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
|
|
+ array.add(userId);
|
|
|
|
|
+ baseRedisService.setString(key, array.toJSONString());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("SecondTradeRecordServiceImpl.locationShareAdd(): Error Msg={}", e.getMessage(), e);
|
|
|
|
|
+ throw new Exception("添加位置共享失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void locationShareDel(Integer otherUserId) throws Exception {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
|
|
|
|
|
+ String key = getKey(userId, otherUserId);
|
|
|
|
|
+
|
|
|
|
|
+ // 存在key,则删除
|
|
|
|
|
+ if (baseRedisService.hasKey(key)) {
|
|
|
|
|
+ JSONArray array = JSONArray.parseArray(baseRedisService.getString(key));
|
|
|
|
|
+ array.remove(userId);
|
|
|
|
|
+ if (array.isEmpty()) {
|
|
|
|
|
+ baseRedisService.delete(key);
|
|
|
|
|
+ LifeUser user = lifeUserMapper.selectById(userId);
|
|
|
|
|
+ LifeUser otherUser = lifeUserMapper.selectById(otherUserId);
|
|
|
|
|
+ LambdaQueryWrapper<LifeMessage> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(LifeMessage::getType, 10);
|
|
|
|
|
+ wrapper.isNull(LifeMessage::getContent);
|
|
|
|
|
+ wrapper.apply("((receiver_id = 'user_" + otherUser.getUserPhone() + "' and sender_id = 'user_" + user.getUserPhone() + "') or (receiver_id = 'user_" + user.getUserPhone() + "' and sender_id = 'user_" + otherUser.getUserPhone() + "'))");
|
|
|
|
|
+ List<Integer> messageIds = lifeMessageMapper.selectList(wrapper).stream().map(LifeMessage::getId).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(messageIds)) {
|
|
|
|
|
+ // 修改消息状态
|
|
|
|
|
+ JSONObject messageJson = new JSONObject();
|
|
|
|
|
+ messageJson.put("cardType", 2);
|
|
|
|
|
+ LambdaUpdateWrapper<LifeMessage> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.in(LifeMessage::getId, messageIds);
|
|
|
|
|
+ updateWrapper.set(LifeMessage::getContent, messageJson.toJSONString());
|
|
|
|
|
+ lifeMessageMapper.update(null, updateWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 发起交易人信息
|
|
|
|
|
+ String phoneId = JwtUtil.getCurrentUserInfo().getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
|
|
|
|
|
+
|
|
|
|
|
+ // 获取交易对方信息
|
|
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(otherUserId);
|
|
|
|
|
+ String receiverId = "user_" + lifeUser.getUserPhone();
|
|
|
|
|
+
|
|
|
|
|
+ // 给买家与卖家发送交易消息
|
|
|
|
|
+ WebSocketVo webSocketVo = new WebSocketVo();
|
|
|
|
|
+ webSocketVo.setSenderId(phoneId);
|
|
|
|
|
+ webSocketVo.setReceiverId(receiverId);
|
|
|
|
|
+ webSocketVo.setCategory("message");
|
|
|
|
|
+ webSocketVo.setType("10");
|
|
|
|
|
+ webSocketVo.setIsRead(0);
|
|
|
|
|
+ webSocketVo.setText(messageJson.toJSONString());
|
|
|
|
|
+ webSocketVo.setMessageIdList(messageIds);
|
|
|
|
|
+
|
|
|
|
|
+ alienStoreFeign.sendMsgToClientByPhoneId(phoneId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
|
|
+ alienStoreFeign.sendMsgToClientByPhoneId(receiverId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ baseRedisService.setString(key, array.toJSONString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("SecondTradeRecordServiceImpl.locationShareDel(): Error Msg={}", e.getMessage(), e);
|
|
|
|
|
+ throw new Exception("删除位置共享失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean locationShareHas(Integer otherUserId) throws Exception {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
|
|
|
|
|
+ String key = getKey(userId, otherUserId);
|
|
|
|
|
+
|
|
|
|
|
+ // 是否存在定位信息
|
|
|
|
|
+ if (baseRedisService.hasKey(key) && !JSONArray.parseArray(baseRedisService.getString(key)).isEmpty()) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ baseRedisService.delete(key);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("SecondTradeRecordServiceImpl.locationShareHas(): Error Msg={}", e.getMessage(), e);
|
|
|
|
|
+ throw new Exception("获取位置共享状态失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getKey(Integer userId, Integer otherUserId) {
|
|
|
|
|
+ // 组合userId和otherUserId作为Redis的key
|
|
|
|
|
+ // 使用排序方式确保key的一致性(较小的ID在前)
|
|
|
|
|
+ String key;
|
|
|
|
|
+ if (userId.compareTo(otherUserId) < 0) {
|
|
|
|
|
+ key = "second_location_share:" + userId + ":" + otherUserId;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ key = "second_location_share:" + otherUserId + ":" + userId;
|
|
|
|
|
+ }
|
|
|
|
|
+ return key;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 计算用户风控评分等级
|
|
* 计算用户风控评分等级
|
|
|
* 根据用户违规次数计算等级:O(无记录) < A(1-2次) < B(3-5次) < C(6-9次) < D(10-14次) < E(≥15次)
|
|
* 根据用户违规次数计算等级:O(无记录) < A(1-2次) < B(3-5次) < C(6-9次) < D(10-14次) < E(≥15次)
|