admin
2022-04-09 ce3420676d9ccf4a2bdf87aeb7ad1494b5e5d26c
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
package com.yeshi.makemoney.app.service.impl.user;
 
import com.yeshi.makemoney.app.dao.user.UserExtraInfoDao;
import com.yeshi.makemoney.app.entity.user.UserExtraInfo;
import com.yeshi.makemoney.app.service.inter.user.UserExtraInfoService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
 
@Service
public class UserExtraInfoServiceImpl implements UserExtraInfoService {
 
    @Resource
    private UserExtraInfoDao userExtraInfoDao;
 
 
    @Override
    public UserExtraInfo get(Long uid) {
        return init(uid);
    }
 
    @Override
    public UserExtraInfo init(Long uid) {
        UserExtraInfo extraInfo = userExtraInfoDao.get(uid);
        if (extraInfo != null) {
            return extraInfo;
        }
 
        extraInfo = new UserExtraInfo();
        extraInfo.setId(uid);
        extraInfo.setCreateTime(new Date());
        userExtraInfoDao.save(extraInfo);
        return extraInfo;
    }
 
    @Override
    public void addUnReadMsgCount(Long uid, int count) {
        UserExtraInfo extraInfo = init(uid);
        if (extraInfo.getUnReadMsgCount() == null) {
            extraInfo.setUnReadMsgCount(count);
        } else {
            extraInfo.setUnReadMsgCount(extraInfo.getUnReadMsgCount() + count);
        }
        userExtraInfoDao.updateSelective(extraInfo);
    }
 
    @Override
    public void setMsgRead(Long uid) {
        init(uid);
        UserExtraInfo update = new UserExtraInfo();
        update.setId(uid);
        update.setUnReadMsgCount(0);
        userExtraInfoDao.updateSelective(update);
    }
 
    @Override
    public void setInviteCode(Long uid, String code) {
        init(uid);
        UserExtraInfo update = new UserExtraInfo();
        update.setId(uid);
        update.setInviteCode(code);
        userExtraInfoDao.updateSelective(update);
    }
}