admin
2020-04-21 0b57cfd62e842b309d03467b96a331c673ecad7c
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
package com.yeshi.fanli.service.impl.user.vip;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.user.vip.UserLevelUpgradedNotifyDao;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelUpgradedNotify;
import com.yeshi.fanli.service.inter.user.vip.UserLevelUpgradedNotifyService;
 
@Service
public class UserLevelUpgradedNotifyServiceImpl implements UserLevelUpgradedNotifyService {
 
    @Resource
    private UserLevelUpgradedNotifyDao userLevelUpgradedNotifyDao;
 
    @Override
    public void addUserLevelUpgradedNotify(UserLevelUpgradedNotify notify) {
        if (notify == null || notify.getUid() == null || notify.getToLevel() == null || notify.getFromLevel() == null) {
            return;
        }
 
        // 查询是否有当前提醒
        List<UserLevelEnum> levels = new ArrayList<>();
        levels.add(notify.getToLevel());
        List<UserLevelUpgradedNotify> list = userLevelUpgradedNotifyDao.listToLevelsByUid(notify.getUid(), levels);
        if (list != null)
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getValid() == false)
                    list.remove(i--);
            }
 
        if (list != null && list.size() > 0)
            return;
 
        if (notify.getNotified() == null)
            notify.setNotified(false);
 
        if (notify.getValid() == null)
            notify.setValid(true);
 
        if (notify.getCreateTime() == null)
            notify.setCreateTime(new Date());
 
        if (notify.getId() == null)
            notify.setId(UUID.randomUUID().toString());
 
        userLevelUpgradedNotifyDao.save(notify);
    }
 
    @Override
    public void setNotified(String id) {
        UserLevelUpgradedNotify notify = userLevelUpgradedNotifyDao.get(id);
        if (notify == null)
            return;
        // 查询低等级的是否已读,如若未读则设为已读
        if (notify.getToLevel() == UserLevelEnum.highVIP || notify.getToLevel() == UserLevelEnum.superVIP) {
            List<UserLevelEnum> levels = new ArrayList<>();
            if (notify.getToLevel() == UserLevelEnum.superVIP) {
                levels.add(UserLevelEnum.highVIP);
            }
 
            List<UserLevelUpgradedNotify> list = userLevelUpgradedNotifyDao.listToLevelsByUid(notify.getUid(), levels);
            if (list != null)
                for (UserLevelUpgradedNotify item : list) {
                    item.setValid(false);
                    item.setUpdateTime(new Date());
                    userLevelUpgradedNotifyDao.save(item);
                }
        }
        notify.setUpdateTime(new Date());
        notify.setNotified(true);
        notify.setReadTime(new Date());
        userLevelUpgradedNotifyDao.save(notify);
    }
 
    @Override
    public UserLevelUpgradedNotify getNeedNotifyByUid(Long uid) {
        List<UserLevelUpgradedNotify> uidList = userLevelUpgradedNotifyDao.listNotNotifiedByUid(uid);
        if (uidList != null && uidList.size() > 0)
            return uidList.get(0);
        return null;
    }
 
}