mitao
7 天以前 21488a55ba76ae4f1296b608fbcdf1f06036db64
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
74
75
76
77
78
package com.panzhihua.sangeshenbian.service.impl;
 
import cn.hutool.core.bean.BeanUtil;
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.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.sangeshenbian.dao.MessageNotificationMapper;
import com.panzhihua.sangeshenbian.model.entity.MessageNotification;
import com.panzhihua.sangeshenbian.model.entity.SystemUser;
import com.panzhihua.sangeshenbian.model.query.BasePage;
import com.panzhihua.sangeshenbian.model.vo.MessageNotificationVO;
import com.panzhihua.sangeshenbian.service.IMessageNotificationService;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
import com.panzhihua.sangeshenbian.warpper.MessageNotificationList;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import java.util.Optional;
 
/**
 * @author zhibing.pu
 * @Date 2025/2/23 3:04
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class MessageNotificationServiceImpl extends ServiceImpl<MessageNotificationMapper, MessageNotification> implements IMessageNotificationService {
    private final ISystemUserService systemUserService;
    
    @Override
    public IPage<MessageNotification> list(MessageNotificationList query) {
        Page page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());
        IPage<MessageNotification> list = this.baseMapper.list(page, query);
        return list;
    }
 
    @Override
    public Page<MessageNotificationVO> getMessageList(BasePage basePage, Long userId) {
        //TODO 待完善
        Page<MessageNotification> page = lambdaQuery().page(new Page<>(basePage.getPageNum(),basePage.getPageSize()));
        return (Page<MessageNotificationVO>) page.convert(item-> BeanUtil.copyProperties(item, MessageNotificationVO.class));
    }
 
    /**
     * 标记已读
     * @param loginUserInfoVO
     */
    @Override
    public void read(LoginUserInfoVO loginUserInfoVO) {
        String undertakerUserId = "";
        Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone());
        if (systemUserByPhone.isPresent()) {
            SystemUser systemUser = systemUserByPhone.get();
            if (systemUser.getIsAdmin().equals(1)){
                switch (systemUser.getAccountLevel()) {
                    case 1:
                        undertakerUserId = "510400";//默认市级
                        break;
                    case 2:
                        undertakerUserId = systemUser.getDistrictsCode();
                        break;
                    case 3:
                        undertakerUserId = systemUser.getStreetId();
                        break;
                    case 4:
                        undertakerUserId = systemUser.getCommunityId().toString();
                        break;
                }
            }
        }else {
            undertakerUserId = loginUserInfoVO.getUserId().toString();
        }
        this.lambdaUpdate().eq(MessageNotification::getUndertakerUserId, undertakerUserId).set(MessageNotification::getReadStatus, 1).update();
    }
}