Jelajahi Sumber

添加 双方是否存在拉黑关系 方法

qrs 4 bulan lalu
induk
melakukan
abc9a6c9b3

+ 8 - 0
alien-store/src/main/java/shop/alien/store/controller/LifeBlacklistController.java

@@ -75,4 +75,12 @@ public class LifeBlacklistController {
             return R.data("取消拉黑成功");
         }
     }
+
+    @ApiOperation("双方是否存在拉黑关系")
+    @ApiOperationSupport(order = 5)
+    @GetMapping("/hasBlackList")
+    public R<Boolean> hasBlackList(String otherSidePhoneId) throws Exception {
+        log.info("LifeBlacklistController.hasBlackList?otherSidePhoneId={}", otherSidePhoneId);
+        return R.data(lifeBlacklistService.hasBlackList(otherSidePhoneId));
+    }
 }

+ 2 - 0
alien-store/src/main/java/shop/alien/store/service/LifeBlacklistService.java

@@ -24,4 +24,6 @@ public interface LifeBlacklistService extends IService<LifeBlacklist> {
     Boolean isBlackListUser(LifeBlacklist lifeBlacklist);
 
     int cancelBlacklist(LifeBlacklist lifeBlacklist);
+
+    boolean hasBlackList(String otherSidePhoneId) throws Exception;
 }

+ 19 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeBlacklistServiceImpl.java

@@ -1,8 +1,10 @@
 package shop.alien.store.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import shop.alien.entity.store.LifeBlacklist;
@@ -16,10 +18,12 @@ import shop.alien.mapper.StoreImgMapper;
 import shop.alien.mapper.StoreUserMapper;
 import shop.alien.store.config.BaseRedisService;
 import shop.alien.store.service.LifeBlacklistService;
+import shop.alien.util.common.JwtUtil;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * <p>
@@ -30,6 +34,7 @@ import java.util.List;
  * @author ssk
  * @since 2025-04-30
  */
+@Slf4j
 @Service
 @RequiredArgsConstructor
 public class LifeBlacklistServiceImpl extends ServiceImpl<LifeBlacklistMapper, LifeBlacklist> implements LifeBlacklistService {
@@ -151,5 +156,19 @@ public class LifeBlacklistServiceImpl extends ServiceImpl<LifeBlacklistMapper, L
         return lifeBlacklistMapper.deleteById(black.getId());
     }
 
+    @Override
+    public boolean hasBlackList(String otherSidePhoneId) throws Exception {
+        try {
+            String phoneId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
+            LambdaQueryWrapper<LifeBlacklist> wrapper = new LambdaQueryWrapper<>();
+            wrapper.apply("((blocker_phone_id='" + otherSidePhoneId + "' and blocked_phone_id='" + phoneId + "')" +
+                    " or (blocker_phone_id='" + phoneId + "' and blocked_phone_id='" + otherSidePhoneId + "'))");
+            return lifeBlacklistMapper.selectCount(wrapper) > 0;
+        } catch (Exception e) {
+            log.error("LifeBlacklistServiceImpl.hasBlackList() error={}", e.getMessage());
+            throw new Exception(e);
+        }
+    }
+
 
 }