2.1
yujian
2020-03-17 d0f12da013131cd291cec6e81a12d661c02c4bf4
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
79
package com.yeshi.fanli.service.impl.user.msg;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.google.gson.Gson;
import com.yeshi.fanli.dao.mybatis.msg.MsgAccountDetailMapper;
import com.yeshi.fanli.dto.msg.MsgAccountVipDTO;
import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail;
import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail.MsgTypeAccountTypeEnum;
import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.exception.msg.MsgAccountDetailException;
import com.yeshi.fanli.exception.msg.MsgOtherDetailException;
import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService;
import com.yeshi.fanli.service.inter.user.msg.MsgAccountDetailService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class MsgAccountDetailServiceImpl implements MsgAccountDetailService {
 
    @Resource
    private MsgAccountDetailMapper msgAccountDetailMapper;
 
    @Resource
    private UserMsgReadStateService userMsgReadStateService;
 
    @Override
    public void addMsgAccountDetail(MsgAccountDetail detail) throws MsgAccountDetailException {
        if (detail == null)
            throw new MsgAccountDetailException(1, "消息为空");
        if (StringUtil.isNullOrEmpty(detail.getTitle()) || StringUtil.isNullOrEmpty(detail.getContent())
                || detail.getType() == null || detail.getUser() == null)
            throw new MsgAccountDetailException(2, "消息内容不完整");
        // 持久化到数据库
        detail.setCreateTime(new Date());
        detail.setUpdateTime(new Date());
        detail.setRead(false);
        msgAccountDetailMapper.insertSelective(detail);
        userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1);
    }
 
    @Override
    public List<MsgAccountDetail> listMsgAccountDetail(Long uid, int page) {
        return msgAccountDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
    }
 
    @Override
    public long countMsgAccountDetail(Long uid) {
        return msgAccountDetailMapper.countByUid(uid);
    }
 
    @Override
    public void readMsgByUid(Long uid) {
        msgAccountDetailMapper.setMsgReadByUid(uid);
    }
 
    
    @Override
    public void addMsgVIP(Long uid, String title, String beiZhu, MsgAccountVipDTO dto) {
        MsgAccountDetail detail = new MsgAccountDetail();
        detail.setTitle(title);
        detail.setBeiZhu(beiZhu);
        detail.setCreateTime(new Date());
        detail.setUpdateTime(new Date());
        detail.setRead(false);
        detail.setUser(new UserInfo(uid));
        detail.setContent(new Gson().toJson(dto));
        detail.setType(MsgTypeAccountTypeEnum.vipPgrade);
        msgAccountDetailMapper.insertSelective(detail);
        
        userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1);
    }
}