基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.shop.api.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.NotifyLog;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.NotifyLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Objects;
 
 
/**
 * @author lhd
 * @date 2020-05-12 08:21:24
 */
@RestController
@RequestMapping("/p/myNotifyLog")
@Tag(name = "消息接口")
public class NotifyLogController {
 
    @Autowired
    private NotifyLogService notifyLogService;
 
    @GetMapping("/unReadCount")
    @Operation(summary = "查询未读消息数量" , description = "查询未读消息数量")
    public ServerResponseEntity<Integer> getNotifyCount() {
        String userId = SecurityUtils.getUser().getUserId();
        return ServerResponseEntity.success(notifyLogService.countUnreadMsg(userId));
    }
 
    @GetMapping("/unReadCountList")
    @Operation(summary = "查询消息列表" , description = "查询消息列表")
    @Parameter(name = "status", description = "状态 0未读 1已读,默认为0" )
    public ServerResponseEntity<IPage<NotifyLog>> getUnReadCountList(PageParam<NotifyLog> page, Integer status) {
        String userId = SecurityUtils.getUser().getUserId();
        status = Objects.isNull(status) ? 0 : status;
        IPage<NotifyLog> notifyReminds = notifyLogService.page(page,
                new LambdaQueryWrapper<NotifyLog>()
                        .eq(NotifyLog::getRemindId, userId)
                        .eq(NotifyLog::getStatus, status)
                        .lt(NotifyLog::getSendType, 100)
                        .eq(NotifyLog::getRemindType, 3)
                        .orderByDesc(NotifyLog::getCreateTime));
        List<NotifyLog> records = notifyReminds.getRecords();
        records.forEach(record -> record.setStatus(1));
        if (CollectionUtils.isNotEmpty(records)) {
            notifyLogService.updateBatchById(records);
        }
        return ServerResponseEntity.success(notifyReminds);
    }
 
 
}