Browse Source

消息、交易修改

qrs 3 weeks ago
parent
commit
27674e3f79

+ 10 - 4
alien-entity/src/main/java/shop/alien/mapper/LifeMessageMapper.java

@@ -38,13 +38,19 @@ public interface LifeMessageMapper extends BaseMapper<LifeMessage> {
             "        where delete_flag = 0 and (sender_id = #{phoneId} or receiver_id = #{phoneId}) " +
             "               and (instr(delete_phone_id, #{phoneId}) is null or instr(delete_phone_id, #{phoneId}) = 0)" +
             "    ) " +
-            "    select *, row_number() over (partition by phoneId order by created_time desc ) num " +
+            "    select *, row_number() over (partition by phoneId order by created_time desc ) num, " +
+            "           substring_index(phoneId, '_', 1) flag, substring_index(phoneId, '_', -1) phone " +
             "    from message " +
             ") " +
-            "select id, type, phoneId, content, created_time createdTime, is_read " +
-            "from message_num " +
+            "select message.id, message.type, message.phoneId, message.content, message.created_time createdTime, message.is_read, " +
+            "       if (message.flag = 'user', user.user_name, suser.name) userName, " +
+            "       if (message.flag = 'user', user.user_image, img.img_url) userImage " +
+            "from message_num message " +
+            "left join life_user user on message.flag = 'user' and message.phone = user.user_phone and user.delete_flag = 0 " +
+            "left join store_user suser on message.flag = 'store' and message.phone = suser.phone and suser.delete_flag = 0 " +
+            "left join store_img img on img.store_id = suser.store_id and img.img_type = '10' and img.delete_flag = 0 " +
             "${ew.customSqlSegment}")
-    IPage<LifeMessageVo> getLifeMessagePageByPhoneId(IPage<LifeMessageVo> iPage, @Param("phoneId") String phoneId, @Param(Constants.WRAPPER) QueryWrapper<LifeFansVo> dynamicsWrapper);
+    List<LifeMessageVo> getLifeMessagePageByPhoneId(@Param("phoneId") String phoneId, @Param(Constants.WRAPPER) QueryWrapper<LifeFansVo> dynamicsWrapper);
 
     @Update("update life_message set delete_phone_id = (if(delete_phone_id is null, #{receiverId}, concat(delete_phone_id, ',', #{receiverId}))) ,delete_flag = '1'" +
             "where (receiver_id = #{senderId} and sender_id = #{receiverId}) or (sender_id = #{senderId} and receiver_id = #{receiverId}) ")

+ 32 - 15
alien-second/src/main/java/shop/alien/second/controller/SecondTradeRecordController.java

@@ -10,6 +10,8 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.second.SecondTradeRecord;
 import shop.alien.second.service.SecondTradeRecordService;
 
+import java.util.List;
+
 /**
  * <p>
  * 二手交易记录表 前端控制器
@@ -31,27 +33,42 @@ public class SecondTradeRecordController {
 
     @ApiOperation("获取交易信息")
     @ApiOperationSupport(order = 1)
-    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query", required = true)})
+    @ApiImplicitParams({@ApiImplicitParam(name = "sideId", value = "对方的id", dataType = "Integer", paramType = "query", required = true)})
     @GetMapping("/getTradeRecord")
-    public R<SecondTradeRecord> getTradeRecord(@Param("id") Long id) {
-        log.error("SecondTradeRecordController.getTradeRecord?id={}", id);
-        return R.data(secondTradeRecordService.getTradeRecord(id));
+    public R<List<SecondTradeRecord>> getTradeRecord(@RequestParam int sideId) {
+        log.info("SecondTradeRecordController.getTradeRecord?sideId={}", sideId);
+        return R.data(secondTradeRecordService.getTradeRecord(sideId));
     }
 
-    @ApiOperation("保存或更新交易记录")
+    @ApiOperation("创建交易")
     @ApiOperationSupport(order = 2)
-    @PostMapping("/saveOrUpdate")
-    public R<Boolean> saveOrUpdate(@RequestBody SecondTradeRecord entity) {
-        log.error("SecondTradeRecordController.getTradeRecord?entity={}", entity.toString());
-        return R.data(secondTradeRecordService.saveOrUpdate(entity));
+    @PostMapping("/createTrade")
+    public R<Boolean> createTrade(@RequestBody SecondTradeRecord entity) {
+        log.info("SecondTradeRecordController.createTrade?entity={}", entity.toString());
+        if (secondTradeRecordService.createTrade(entity)) return R.success("创建成功");
+        return R.fail("创建失败");
     }
 
-    @ApiOperation("删除交易信息")
+    @ApiOperation("交易签到")
     @ApiOperationSupport(order = 3)
-    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query", required = true)})
-    @DeleteMapping("/deleteTradeRecord")
-    public R<Boolean> deleteTradeRecord(@Param("id") Long id) {
-        log.error("SecondTradeRecordController.deleteTradeRecord?id={}", id);
-        return R.data(secondTradeRecordService.removeById(id));
+    @ApiImplicitParams({@ApiImplicitParam(name = "tradeId", value = "交易id", dataType = "Integer", paramType = "query", required = true)})
+    @GetMapping("/tradeSignin")
+    public R<Boolean> tradeSignin(@RequestParam int tradeId) {
+        log.info("SecondTradeRecordController.tradeSignin?tradeId={}", tradeId);
+        if (secondTradeRecordService.tradeSignin(tradeId)) return R.success("签到成功");
+        return R.fail("签到失败");
+    }
+
+    @ApiOperation("交易确认")
+    @ApiOperationSupport(order = 4)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "tradeId", value = "交易id", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "type", value = "0-失败  1-成功", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "evaluate", value = "评价", dataType = "String", paramType = "query")})
+    @GetMapping("/tradeConfirm")
+    public R<Boolean> tradeConfirm(@RequestParam int tradeId, @RequestParam int type, @RequestParam String evaluate) {
+        log.info("SecondTradeRecordController.tradeConfirm?tradeId={}, type={}, evaluate={}", tradeId, type, evaluate);
+        if (secondTradeRecordService.tradeConfirm(tradeId, type, evaluate)) return R.success("交易确认成功");
+        return R.fail("交易确认失败");
     }
 }

+ 11 - 20
alien-second/src/main/java/shop/alien/second/service/SecondTradeRecordService.java

@@ -2,8 +2,11 @@ package shop.alien.second.service;
 
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import io.swagger.models.auth.In;
 import shop.alien.entity.second.SecondTradeRecord;
 
+import java.util.List;
+
 /**
  * <p>
  * 二手交易记录表 服务类
@@ -13,24 +16,12 @@ import shop.alien.entity.second.SecondTradeRecord;
  * @since 2025-07-07
  */
 public interface SecondTradeRecordService extends IService<SecondTradeRecord> {
-    /**
-     * 根据ID获取交易记录
-     * @param id 交易记录ID
-     * @return 交易记录对象
-     */
-    SecondTradeRecord getTradeRecord(Long id);
-
-    /**
-     * 保存或更新交易记录
-     * @param entity 交易记录对象
-     * @return 操作结果
-     */
-    boolean saveOrUpdate(SecondTradeRecord entity);
-
-    /**
-     * 根据ID删除交易记录
-     * @param id 交易记录ID
-     * @return 删除结果
-     */
-    boolean removeById(Long id);
+    List<SecondTradeRecord> getTradeRecord(int sideId);
+
+    boolean createTrade(SecondTradeRecord entity);
+
+    boolean tradeSignin(int tradeId);
+
+    boolean tradeConfirm(int tradeId, int type, String evaluate);
+
 }

+ 66 - 22
alien-second/src/main/java/shop/alien/second/service/impl/SecondTradeRecordServiceImpl.java

@@ -1,5 +1,6 @@
 package shop.alien.second.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -9,6 +10,10 @@ import shop.alien.entity.second.SecondTradeRecord;
 import shop.alien.mapper.second.SecondGoodsMapper;
 import shop.alien.mapper.second.SecondTradeRecordMapper;
 import shop.alien.second.service.SecondTradeRecordService;
+import shop.alien.util.common.JwtUtil;
+
+import java.util.List;
+import java.util.Objects;
 
 /**
  * <p>
@@ -27,42 +32,81 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
     private final SecondGoodsMapper secondGoodsMapper;
 
     @Override
-    public SecondTradeRecord getTradeRecord(Long id) {
-        return super.getById(id);
+    public List<SecondTradeRecord> getTradeRecord(int sideId) {
+        try {
+            int userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
+            QueryWrapper<SecondTradeRecord> wrapper = new QueryWrapper<>();
+            wrapper.apply("(buyer_id = '" + sideId + "' and seller_id = '" + userId + "') || (buyer_id = '" + userId + "' and seller_id = '" + sideId + "')");
+            wrapper.orderByDesc("created_time");
+            return secondTradeRecordMapper.selectList(wrapper);
+        } catch (Exception e) {
+            log.error("SecondTradeRecordServiceImpl.getTradeRecord===", e.fillInStackTrace());
+            return null;
+        }
     }
 
     /**
-     * 保存或更新交易记录
+     * 创建交易
      * @param entity 交易记录对象
      * @return 操作结果
      */
     @Override
-    public boolean saveOrUpdate(SecondTradeRecord entity) {
+    public boolean createTrade(SecondTradeRecord entity) {
         try {
-            if (null == entity.getId()) {
-                super.saveOrUpdate(entity);
-                SecondGoods goods = new SecondGoods();
-                goods.setId(entity.getGoodsId());
-                goods.setTradeId(entity.getId());
-                secondGoodsMapper.updateById(goods);
-            } else {
-                super.saveOrUpdate(entity);
-            }
+            secondTradeRecordMapper.insert(entity);
+            SecondGoods goods = new SecondGoods();
+            goods.setId(entity.getGoodsId());
+            goods.setTradeId(entity.getId());
+            secondGoodsMapper.updateById(goods);
             return true;
         } catch (Exception e) {
-            log.error("SecondTradeRecordServiceImpl.saveOrUpdate?error={}", e.getMessage());
+            log.error("SecondTradeRecordServiceImpl.createTrade===", e.fillInStackTrace());
         }
-
         return false;
     }
 
-    /**
-     * 根据ID删除交易记录
-     * @param id 交易记录ID
-     * @return 删除结果
-     */
     @Override
-    public boolean removeById(Long id) {
-        return super.removeById(id);
+    public boolean tradeSignin(int tradeId) {
+        try {
+            int userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
+            SecondTradeRecord tradeRecord = secondTradeRecordMapper.selectById(tradeId);
+            SecondTradeRecord record = new SecondTradeRecord();
+            record.setId(tradeId);
+            if (userId == tradeRecord.getBuyerId()) {
+                record.setBuyerSignin(1);
+            } else if (userId == tradeRecord.getSellerId()) {
+                record.setSellerSignin(1);
+            } else {
+                return false;
+            }
+            secondTradeRecordMapper.updateById(record);
+        } catch (Exception e) {
+            log.error("SecondTradeRecordServiceImpl.tradeSignin===", e.fillInStackTrace());
+        }
+        return true;
+    }
+
+    @Override
+    public boolean tradeConfirm(int tradeId, int type, String evaluate) {
+        try {
+            int userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
+            SecondTradeRecord tradeRecord = secondTradeRecordMapper.selectById(tradeId);
+            SecondTradeRecord record = new SecondTradeRecord();
+            record.setId(tradeId);
+            if (userId == tradeRecord.getBuyerId()) {
+                record.setBuyerTransactionStatus(type);
+                record.setBuyerEvaluate(evaluate);
+            } else if (userId == tradeRecord.getSellerId()) {
+                record.setSellerTransactionStatus(type);
+                record.setSellerEvaluate(evaluate);
+                record.setTradeStatus(type);
+            } else {
+                return false;
+            }
+            secondTradeRecordMapper.updateById(record);
+        } catch (Exception e) {
+            log.error("SecondTradeRecordServiceImpl.tradeConfirm===", e.fillInStackTrace());
+        }
+        return true;
     }
 }

+ 21 - 11
alien-store/src/main/java/shop/alien/store/controller/LifeMessageController.java

@@ -34,18 +34,28 @@ public class LifeMessageController {
     @ApiOperation("消息列表")
     @ApiOperationSupport(order = 1)
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "page", value = "分页页数", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = true),
             @ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query"),
-            @ApiImplicitParam(name = "friendType", value = "好友类型 1-好友 2-好友以外", dataType = "Integer", paramType = "query")})
+            @ApiImplicitParam(name = "friendType", value = "聊天类型 1-聊过 2-未聊过", dataType = "Integer", paramType = "query"),
+            @ApiImplicitParam(name = "search", value = "搜索字段", dataType = "Integer", paramType = "query")})
     @GetMapping("/getMessageList")
-    public R<IPage<LifeMessageVo>> getMessageList(@RequestParam String receiverId, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size, int friendType) {
-        log.info("LifeMessageController.getMessageList?receiverId={}, page={}, size={}, friendType={}", receiverId, page, size, friendType);
-        return R.data(lifeMessageService.getMessageList(receiverId, page, size, friendType));
+    public R<List<LifeMessageVo>> getMessageList(@RequestParam String receiverId,
+                                                  @RequestParam int friendType,
+                                                  @RequestParam String search) {
+        log.info("LifeMessageController.getMessageList?receiverId={}, friendType={}, search={}", receiverId, friendType, search);
+        return R.data(lifeMessageService.getMessageList(receiverId, friendType, search));
+    }
+
+    @ApiOperation("未聊过的消息数据")
+    @ApiOperationSupport(order = 2)
+    @ApiImplicitParams({@ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query")})
+    @GetMapping("/getStrangerMessageNum")
+    public R<LifeMessageVo> getStrangerMessageNum(@RequestParam String receiverId) {
+        log.info("LifeMessageController.getStrangerMessageNum?receiverId={}", receiverId);
+        return R.data(lifeMessageService.getStrangerMessageNum(receiverId));
     }
 
     @ApiOperation("未关注人的消息数据")
-    @ApiOperationSupport(order = 1)
+    @ApiOperationSupport(order = 3)
     @ApiImplicitParams({@ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query")})
     @GetMapping("/getNoFriendMessage")
     public R<LifeMessageVo> getNoFriendMessage(@RequestParam String receiverId) {
@@ -54,7 +64,7 @@ public class LifeMessageController {
     }
 
     @ApiOperation("消息详情")
-    @ApiOperationSupport(order = 2)
+    @ApiOperationSupport(order = 4)
     @ApiImplicitParams({@ApiImplicitParam(name = "当前登录人", value = "receiverId", dataType = "String", paramType = "query"), @ApiImplicitParam(name = "senderId", value = "聊天对方", dataType = "String", paramType = "query")})
     @GetMapping("/getMessageListByReceiverId")
     public R<List<LifeMessageVo>> getMessageListByReceiverId(@RequestParam String receiverId, @RequestParam String senderId) {
@@ -63,7 +73,7 @@ public class LifeMessageController {
     }
 
     @ApiOperation("消息已读")
-    @ApiOperationSupport(order = 3)
+    @ApiOperationSupport(order = 5)
     @ApiImplicitParams({@ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query"), @ApiImplicitParam(name = "senderId", value = "聊天对方", dataType = "String", paramType = "query")})
     @GetMapping("/read")
     public R<Boolean> read(@RequestParam String receiverId, @RequestParam String senderId) {
@@ -73,7 +83,7 @@ public class LifeMessageController {
     }
 
     @ApiOperation("未读消息数量")
-    @ApiOperationSupport(order = 4)
+    @ApiOperationSupport(order = 6)
     @ApiImplicitParams({@ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query")})
     @GetMapping("/noReadCount")
     public R<Integer> noReadCount(@RequestParam String receiverId) {
@@ -82,7 +92,7 @@ public class LifeMessageController {
     }
 
     @ApiOperation("删除消息")
-    @ApiOperationSupport(order = 5)
+    @ApiOperationSupport(order = 7)
     @ApiImplicitParams({@ApiImplicitParam(name = "senderId", value = "聊天对方", dataType = "String", paramType = "query"), @ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query")})
     @GetMapping("/deleteMessageByPhoneId")
     public R<Integer> deleteMessageByPhoneId(@RequestParam String senderId, @RequestParam String receiverId) {

+ 9 - 9
alien-store/src/main/java/shop/alien/store/controller/LifeNoticeController.java

@@ -12,6 +12,8 @@ import shop.alien.entity.store.vo.LifeNoticeVo;
 import shop.alien.mapper.LifeNoticeMapper;
 import shop.alien.store.service.LifeNoticeService;
 
+import java.util.List;
+
 @Api(tags = {"一期-公告"})
 @Slf4j
 @RestController
@@ -27,15 +29,13 @@ public class LifeNoticeController {
     @GetMapping("/getNoticeByPhoneId")
     @ApiOperation("通知列表")
     @ApiOperationSupport(order = 1)
-    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页页数", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query")})
-    public R<IPage<LifeNoticeVo>> getNoticeByPhoneId(@RequestParam String receiverId,
-                                                     @RequestParam(defaultValue = "0") int noticeType,
-                                                     @RequestParam(defaultValue = "1") int page,
-                                                     @RequestParam(defaultValue = "10") int size) {
-        log.info("LifeNoticeController.getNoticeByPhoneId?receiverId={},page={},size={}, noticeType={}", receiverId, page, size, noticeType);
-        return R.data(lifeNoticeService.getNoticeList(receiverId, noticeType, page, size));
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "receiverId", value = "当前登录人", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "noticeType", value = "0-系统通知和订单提醒之外的类型 1-系统通知 2-订单提醒", dataType = "Integer", paramType = "query")})
+    public R<List<LifeNoticeVo>> getNoticeByPhoneId(@RequestParam String receiverId,
+                                                    @RequestParam(defaultValue = "0") int noticeType) {
+        log.info("LifeNoticeController.getNoticeByPhoneId?receiverId={}, noticeType={}", receiverId, noticeType);
+        return R.data(lifeNoticeService.getNoticeList(receiverId, noticeType));
     }
 
     @GetMapping("/getSystemAndOrderNoticeSum")

+ 5 - 1
alien-store/src/main/java/shop/alien/store/service/LifeMessageService.java

@@ -9,7 +9,9 @@ import java.util.List;
 
 public interface LifeMessageService extends IService<LifeMessage> {
 
-    IPage<LifeMessageVo> getMessageList(String receiverId, int page, int size, int friendType);
+    List<LifeMessageVo> getMessageList(String receiverId, int friendType, String search);
+
+    LifeMessageVo getStrangerMessageNum(String receiverId);
 
     LifeMessageVo getNoFriendMessageNum(String receiverId);
 
@@ -20,4 +22,6 @@ public interface LifeMessageService extends IService<LifeMessage> {
     int noReadCount(String receiverId);
 
     int deleteMessageByPhoneId(String senderId, String receiverId);
+
+    boolean notDisturb(String receiverId, int disturbId, int type);
 }

+ 3 - 1
alien-store/src/main/java/shop/alien/store/service/LifeNoticeService.java

@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import shop.alien.entity.store.LifeNotice;
 import shop.alien.entity.store.vo.LifeNoticeVo;
 
+import java.util.List;
+
 public interface LifeNoticeService extends IService<LifeNotice> {
 
-    IPage<LifeNoticeVo> getNoticeList(String receiverId, int noticeType, int page, int size);
+    List<LifeNoticeVo> getNoticeList(String receiverId, int noticeType);
 
     JSONObject getSystemAndOrderNoticeSum(String receiverId);
 

+ 122 - 47
alien-store/src/main/java/shop/alien/store/service/impl/LifeMessageServiceImpl.java

@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 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.github.pagehelper.util.StringUtil;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 import shop.alien.entity.store.*;
 import shop.alien.entity.store.vo.LifeFansVo;
 import shop.alien.entity.store.vo.LifeMessageVo;
@@ -17,9 +19,11 @@ import shop.alien.mapper.LifeMessageMapper;
 import shop.alien.mapper.LifeUserMapper;
 import shop.alien.store.service.LifeMessageService;
 import shop.alien.store.service.LifeUserService;
+import shop.alien.util.common.JwtUtil;
 
 import java.util.Comparator;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
@@ -37,43 +41,77 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
 
 
     @Override
-    public IPage<LifeMessageVo> getMessageList(String receiverId, int page, int size, int friendType) {
+    public List<LifeMessageVo> getMessageList(String receiverId, int friendType, String search) {
         // 查询所有好友
+//        QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
+//        wrapper.groupBy("foll.phoneId");
+
+//        if ("user".equals(receiverId.split("_")[0])) {
+//            String myselfUserPhone = receiverId.split("_")[1];
+//            blockerType = "2";
+//            LifeUser myLifeUser = lifeUserService.getUserByPhone(myselfUserPhone);
+//            blockerId = String.valueOf(myLifeUser.getId());
+//        } else {
+//            String myselfStorePhone = receiverId.split("_")[1];
+//            blockerType = "1";
+//            StoreUser myStoreUser = storeUserService.getUserByPhone(myselfStorePhone);
+//            blockerId = String.valueOf(myStoreUser.getId());
+//        }
+
+//        List<LifeFansVo> lifeFansList = lifeFansMapper.getMutualAttention(new Page<>(1, Integer.MAX_VALUE), receiverId, blockerType, blockerId, wrapper).getRecords();
+//        List<String> friendsIds = lifeFansList.stream().map(LifeFansVo::getPhoneId).filter(item -> !item.equals(receiverId)).collect(Collectors.toList());
+//        String friendsIdsStr = "'" + String.join("','", friendsIds) + "'";
+
+//        wrapper = new QueryWrapper<>();
+//        wrapper.eq("num", 1);
+//        if (1 == friendType) {
+//            // 当前用户的所有好友消息
+//            wrapper.apply("(sender_id in (" + friendsIdsStr + ") or receiver_id in (" + friendsIdsStr + "))");
+//        } else {
+//            // 当前用户的所有未关注人消息
+//            wrapper.apply("(sender_id not in (" + friendsIdsStr + ") and receiver_id not in (" + friendsIdsStr + "))");
+//        }
+
+        String blockerType = "user".equals(Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType")) ? "2" : "1";
+        String blockerId = JwtUtil.getCurrentUserInfo().getString("userId");
         QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
-        wrapper.groupBy("foll.phoneId");
-        String blockerType = "";
-        String blockerId = "";
-        if ("user".equals(receiverId.split("_")[0])) {
-            String myselfUserPhone = receiverId.split("_")[1];
-            blockerType = "2";
-            LifeUser myLifeUser = lifeUserService.getUserByPhone(myselfUserPhone);
-            blockerId = String.valueOf(myLifeUser.getId());
-        } else {
-            String myselfStorePhone = receiverId.split("_")[1];
-            blockerType = "1";
-            StoreUser myStoreUser = storeUserService.getUserByPhone(myselfStorePhone);
-            blockerId = String.valueOf(myStoreUser.getId());
+        wrapper.eq("message.num", 1);
+        // 过滤拉黑
+        wrapper.apply("(user.id not in ( " +
+                            "     select blocked_id from life_blacklist " +
+                            "     where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '2' and delete_flag = 0 " +
+                            ") or user.id is null)");
+        wrapper.apply("(suser.id not in ( " +
+                            "     select blocked_id from life_blacklist " +
+                            "     where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '1' and delete_flag = 0 " +
+                            ") or suser.id is null)");
+
+        // 通过搜索查询的情况下  不区分是否聊过  搜索所有消息
+        if (0 == friendType && StringUtil.isNotEmpty(search)) {
+            wrapper.apply("(user.user_name like '%" + search + "%' or suser.name like '%" + search + "%')");
+        // 聊过
+        } else if (1 == friendType) {
+            wrapper.apply("message.phoneId in ( " +
+                    "    select receiver_id " +
+                    "    from life_message " +
+                    "    where sender_id = '" + receiverId + "'" +
+                    "    group by receiver_id " +
+                    ")");
+        // 没聊过
+        } else if (2 == friendType) {
+            wrapper.apply("message.phoneId not in ( " +
+                    "    select receiver_id " +
+                    "    from life_message " +
+                    "    where sender_id = '" + receiverId + "'" +
+                    "    group by receiver_id " +
+                    ")");
         }
-
-        List<LifeFansVo> lifeFansList = lifeFansMapper.getMutualAttention(new Page<>(1, Integer.MAX_VALUE), receiverId, blockerType, blockerId, wrapper).getRecords();
-        List<String> friendsIds = lifeFansList.stream().map(LifeFansVo::getPhoneId).filter(item -> !item.equals(receiverId)).collect(Collectors.toList());
-        String friendsIdsStr = "'" + String.join("','", friendsIds) + "'";
-
-        wrapper = new QueryWrapper<>();
-        wrapper.eq("num", 1);
-        if (1 == friendType) {
-            // 当前用户的所有好友消息
-            wrapper.apply("(sender_id in (" + friendsIdsStr + ") or receiver_id in (" + friendsIdsStr + "))");
-        } else {
-            // 当前用户的所有未关注人消息
-            wrapper.apply("(sender_id not in (" + friendsIdsStr + ") and receiver_id not in (" + friendsIdsStr + "))");
-        }
-        wrapper.orderByDesc("created_time");
-        IPage<LifeMessageVo> ipage = new Page<>(page, size);
-        IPage<LifeMessageVo> lifeMessagePageList = messageMapper.getLifeMessagePageByPhoneId(ipage, receiverId, wrapper);
-        if (!CollectionUtils.isEmpty(lifeMessagePageList.getRecords())) {
+        wrapper.orderByDesc("message.created_time");
+//        IPage<LifeMessageVo> ipage = new Page<>(page, size);
+        List<LifeMessageVo> lifeMessagePageList = messageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
+        if (!CollectionUtils.isEmpty(lifeMessagePageList)) {
             // 取出所有发送消息的用户
-            List<String> phoneIdList = lifeMessagePageList.getRecords().stream().map(LifeMessageVo::getPhoneId).filter(item -> item.contains("_")).collect(Collectors.toList());
+//            List<String> phoneIdList = lifeMessagePageList.stream().map(LifeMessageVo::getPhoneId).filter(item -> item.contains("_")).collect(Collectors.toList());
 
             // 当前用户的所有关注
             LambdaQueryWrapper<LifeFans> followWrapper = new LambdaQueryWrapper<>();
@@ -97,18 +135,18 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
             messageWrapper.eq(LifeMessage::getDeleteFlag, 0);
             List<LifeMessage> noReadList = messageMapper.selectList(messageWrapper);
 
-            // 根据手机号查询发送人信息
-            List<String> storePhoneList = phoneIdList.stream().filter(item -> "store".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
-            List<String> userPhoneList = phoneIdList.stream().filter(item -> "user".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
-            String storePhones = "'" + String.join("','", storePhoneList) + "'";
-            String userPhones = "'" + String.join("','", userPhoneList) + "'";
-            List<LifeMessageVo> userList = messageMapper.getLifeUserAndStoreUserByPhone(storePhones, userPhones);
+//            // 根据手机号查询发送人信息
+//            List<String> storePhoneList = phoneIdList.stream().filter(item -> "store".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
+//            List<String> userPhoneList = phoneIdList.stream().filter(item -> "user".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
+//            String storePhones = "'" + String.join("','", storePhoneList) + "'";
+//            String userPhones = "'" + String.join("','", userPhoneList) + "'";
+//            List<LifeMessageVo> userList = messageMapper.getLifeUserAndStoreUserByPhone(storePhones, userPhones);
 
-            for (LifeMessageVo messageVo : lifeMessagePageList.getRecords()) {
-                // 发送人信息
-                LifeMessageVo user = userList.stream().filter(item -> item.getPhoneId().equals(messageVo.getPhoneId())).findFirst().orElse(null);
-                messageVo.setUserName(null == user ? "" : user.getUserName());
-                messageVo.setUserImage(null == user ? "" : user.getUserImage());
+            for (LifeMessageVo messageVo : lifeMessagePageList) {
+//                // 发送人信息
+//                LifeMessageVo user = userList.stream().filter(item -> item.getPhoneId().equals(messageVo.getPhoneId())).findFirst().orElse(null);
+//                messageVo.setUserName(null == user ? "" : user.getUserName());
+//                messageVo.setUserImage(null == user ? "" : user.getUserImage());
 
                 // 未读消息数量
                 messageVo.setNotReadCount(noReadList.stream().filter(item -> item.getSenderId().equals(messageVo.getPhoneId())).count());
@@ -137,11 +175,43 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
             }
         }
 
-
         return lifeMessagePageList;
     }
 
     @Override
+    public LifeMessageVo getStrangerMessageNum(String receiverId) {
+        String blockerType = "user".equals(Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType")) ? "2" : "1";
+        String blockerId = JwtUtil.getCurrentUserInfo().getString("userId");
+        QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
+        // 过滤拉黑
+        wrapper.apply("(user.id not in ( " +
+                "     select blocked_id from life_blacklist " +
+                "     where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '2' and delete_flag = 0 " +
+                ") or user.id is null)");
+        wrapper.apply("(suser.id not in ( " +
+                "     select blocked_id from life_blacklist " +
+                "     where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '1' and delete_flag = 0 " +
+                ") or suser.id is null)");
+        // 没聊过
+        wrapper.apply("message.phoneId not in ( " +
+                "    select receiver_id " +
+                "    from life_message " +
+                "    where sender_id = '" + receiverId + "'" +
+                "    group by receiver_id " +
+                ")");
+        wrapper.orderByDesc("message.created_time");
+//        IPage<LifeMessageVo> ipage = new Page<>(1, Integer.MAX_VALUE);
+        List<LifeMessageVo> lifeMessagePageList = messageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
+        LifeMessageVo vo = new LifeMessageVo();
+        if (!CollectionUtils.isEmpty(lifeMessagePageList)) {
+            vo.setUserName(lifeMessagePageList.get(0).getUserName());
+            vo.setNotReadCount(lifeMessagePageList.stream().filter(item -> 0 == item.getIsRead()).count());
+        }
+
+        return vo;
+    }
+
+    @Override
     public LifeMessageVo getNoFriendMessageNum(String receiverId) {
         // 查询所有好友
         QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
@@ -169,8 +239,8 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
         wrapper.eq("num", 1);
         wrapper.apply("(sender_id not in (" + friendsIdsStr + ") and receiver_id not in (" + friendsIdsStr + "))");
         wrapper.orderByDesc("created_time");
-        IPage<LifeMessageVo> ipage = new Page<>(1, Integer.MAX_VALUE);
-        List<LifeMessageVo> lifeMessageVoList = messageMapper.getLifeMessagePageByPhoneId(ipage, receiverId, wrapper).getRecords();
+//        IPage<LifeMessageVo> ipage = new Page<>(1, Integer.MAX_VALUE);
+        List<LifeMessageVo> lifeMessageVoList = messageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
 
         LifeMessageVo messageVo = lifeMessageVoList.stream().max(Comparator.comparing(LifeMessageVo::getCreatedTime)).orElse(null);
         if (messageVo != null) {
@@ -276,4 +346,9 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
     public int deleteMessageByPhoneId(String senderId, String receiverId) {
         return messageMapper.deleteMessageByPhoneId(senderId, receiverId);
     }
+
+    @Override
+    public boolean notDisturb(String receiverId, int disturbId, int type) {
+        return false;
+    }
 }

+ 15 - 14
alien-store/src/main/java/shop/alien/store/service/impl/LifeNoticeServiceImpl.java

@@ -1,5 +1,6 @@
 package shop.alien.store.service.impl;
 
+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.update.LambdaUpdateWrapper;
@@ -30,17 +31,17 @@ public class LifeNoticeServiceImpl extends ServiceImpl<LifeNoticeMapper, LifeNot
     private final LifeMessageMapper lifeMessageMapper;
 
     @Override
-    public IPage<LifeNoticeVo> getNoticeList(String receiverId, int noticeType, int page, int size) {
-        IPage<LifeNotice> ipage = new Page<>(page, size);
+    public List<LifeNoticeVo> getNoticeList(String receiverId, int noticeType) {
+//        IPage<LifeNotice> ipage = new Page<>(page, size);
         LambdaQueryWrapper<LifeNotice> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(LifeNotice::getReceiverId, receiverId);
         queryWrapper.eq(LifeNotice::getNoticeType, noticeType);
         queryWrapper.eq(LifeNotice::getDeleteFlag, 0);
-        IPage<LifeNotice> lifeNoticeList = lifeNoticeMapper.selectPage(ipage, queryWrapper);
+        List<LifeNotice> lifeNoticeList = lifeNoticeMapper.selectList(queryWrapper);
 
         List<String> senderIdList = new ArrayList<>();
-        if (lifeNoticeList != null && lifeNoticeList.getRecords() != null) {
-            senderIdList = lifeNoticeList.getRecords().stream()
+        if (CollectionUtil.isNotEmpty(lifeNoticeList)) {
+            senderIdList = lifeNoticeList.stream()
                     .map(LifeNotice::getSenderId)
                     .filter(item -> item != null && !"system".equals(item) && item.contains("_"))
                     .map(item -> item.split("_")[1])
@@ -52,8 +53,8 @@ public class LifeNoticeServiceImpl extends ServiceImpl<LifeNoticeMapper, LifeNot
         List<LifeMessageVo> userList = lifeMessageMapper.getLifeUserAndStoreUserByPhone(senderIds, "''");
 
         List<LifeNoticeVo> noticeVoList = new ArrayList<>();
-        if (lifeNoticeList != null && lifeNoticeList.getRecords() != null) {
-            lifeNoticeList.getRecords().forEach(item -> {
+        if (CollectionUtil.isNotEmpty(lifeNoticeList)) {
+            lifeNoticeList.forEach(item -> {
                 LifeNoticeVo noticeVo = new LifeNoticeVo();
                 BeanUtils.copyProperties(item, noticeVo);
                 LifeMessageVo userinfo = userList.stream().filter(user -> user.getPhoneId().equals(item.getSenderId())).findFirst().orElse(null);
@@ -65,14 +66,14 @@ public class LifeNoticeServiceImpl extends ServiceImpl<LifeNoticeMapper, LifeNot
             });
         }
 
-        IPage<LifeNoticeVo> result = new Page<>();
-        result.setRecords(noticeVoList);
-        result.setCurrent(lifeNoticeList.getCurrent());
-        result.setSize(lifeNoticeList.getSize());
-        result.setTotal(lifeNoticeList.getTotal());
-        result.setPages(lifeNoticeList.getPages());
+//        IPage<LifeNoticeVo> result = new Page<>();
+//        result.setRecords(noticeVoList);
+//        result.setCurrent(lifeNoticeList.getCurrent());
+//        result.setSize(lifeNoticeList.getSize());
+//        result.setTotal(lifeNoticeList.getTotal());
+//        result.setPages(lifeNoticeList.getPages());
 
-        return result;
+        return noticeVoList;
     }
 
     @Override