yujian
2019-09-27 c833ab8f5968c755ded82eea5e8ce2aca841a0cb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.yeshi.fanli.service.impl.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.MsgOtherDetailMapper;
import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail;
import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum;
import com.yeshi.fanli.exception.msg.MsgOtherDetailException;
import com.yeshi.fanli.service.inter.msg.MsgOtherDetailService;
import com.yeshi.fanli.service.inter.msg.UserMsgReadStateService;
import com.yeshi.fanli.util.Constant;
 
@Service
public class MsgOtherDetailServiceImpl implements MsgOtherDetailService {
 
    @Resource
    private MsgOtherDetailMapper msgOtherDetailMapper;
 
    @Resource
    private UserMsgReadStateService userMsgReadStateService;
 
    @Override
    public void addMsgOtherDetail(MsgOtherDetail detail) throws MsgOtherDetailException {
        if (detail.getType() == MsgTypeOtherTypeEnum.couponMianDan
                || detail.getType() == MsgTypeOtherTypeEnum.couponReward
                || detail.getType() == MsgTypeOtherTypeEnum.couponWelfareMianDan) {
            if (detail.getCoupnContent() == null)
                throw new MsgOtherDetailException(1, "内容为空");
            detail.setContent(new Gson().toJson(detail.getCoupnContent()));
            if (detail.getCreateTime() == null)
                detail.setCreateTime(new Date());
            msgOtherDetailMapper.insertSelective(detail);
            userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1);
        } else if (detail.getType() == MsgTypeOtherTypeEnum.taoLiJin) {
            msgOtherDetailMapper.insertSelective(detail);
            userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1);
        } else if (detail.getType() == MsgTypeOtherTypeEnum.give) {
            msgOtherDetailMapper.insertSelective(detail);
            userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1);
        } else if (detail.getType() == MsgTypeOtherTypeEnum.exchange) {
            msgOtherDetailMapper.insertSelective(detail);
            userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1);
        } else if (detail.getType() == MsgTypeOtherTypeEnum.couponActivate) {
            msgOtherDetailMapper.insertSelective(detail);
            userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1);
        } else if (detail.getType() == MsgTypeOtherTypeEnum.firstOrderReward) {
            msgOtherDetailMapper.insertSelective(detail);
            userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1);
        }else if (detail.getType() == MsgTypeOtherTypeEnum.systemGive) {
            msgOtherDetailMapper.insertSelective(detail);
            userMsgReadStateService.addOtherMsgUnReadCount(detail.getUser().getId(), 1);
        }
    }
 
    @Override
    public void updateMsgOtherDetail(MsgOtherDetail detail) throws MsgOtherDetailException {
        if (detail.getType() == MsgTypeOtherTypeEnum.couponMianDan
                || detail.getType() == MsgTypeOtherTypeEnum.couponReward
                || detail.getType() == MsgTypeOtherTypeEnum.couponWelfareMianDan) {
            if (detail.getId() == null)
                throw new MsgOtherDetailException(2, "主键为空");
            if (detail.getCoupnContent() == null)
                throw new MsgOtherDetailException(1, "内容为空");
            detail.setContent(new Gson().toJson(detail.getCoupnContent()));
            if(detail.getUpdateTime()==null)
            detail.setUpdateTime(new Date());
            msgOtherDetailMapper.updateByPrimaryKeySelective(detail);
        }
    }
 
    @Override
    public List<MsgOtherDetail> listMsgOtherDetail(Long uid, int page) {
        return msgOtherDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
    }
 
    @Override
    public long countMsgOtherDetail(Long uid) {
        return msgOtherDetailMapper.countByUid(uid);
    }
 
    @Override
    public void readMsgByUid(Long uid) {
        msgOtherDetailMapper.setMsgReadByUid(uid);
    }
 
}