admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
package com.yeshi.fanli.service.impl.user;
 
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
import com.yeshi.fanli.entity.bus.user.AccountMessage;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.system.SystemZnx;
import com.yeshi.fanli.service.inter.user.AccountMessageService;
import com.yeshi.fanli.service.inter.user.SystemZnxService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
 
@Service
public class AccountMessageServiceImpl implements AccountMessageService {
 
    @Resource
    private AccountMessageMapper accountMessageMapper;
    @Resource
    private UserInfoService userInfoService;
    
    @Resource
    private SystemZnxService systemZnxService;
 
    @Override
    public List<AccountMessage> findAccountMessageList(long uid, int page) {
        return accountMessageMapper.listByUidOrderByIdDesc(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
    }
 
    @Override
    public int getCount(long uid) {
        return (int) accountMessageMapper.countByUidAndOpen(uid, null);
 
    }
 
    @Override
    public void open(long id) {
        AccountMessage find = accountMessageMapper.selectByPrimaryKey(id);
        if (find != null) {
            AccountMessage update = new AccountMessage();
            update.setId(id);
            update.setIsOpen(true);
            accountMessageMapper.updateByPrimaryKeySelective(update);
        }
    }
 
    @Override
    public int getCanOpenCount(long uid) {
        return (int) accountMessageMapper.countByUidAndOpen(uid, false);
    }
 
    @Override
    public void save(AccountMessage accountMessage) {
        if (accountMessage != null)
            accountMessageMapper.insertSelective(accountMessage);
    }
 
    @Override
    public void syncSystemZnx(long uid) {
        UserInfo userInfo = userInfoService.selectByPKey(uid);
        if (userInfo == null)
            return;
        
        List<SystemZnx> list = systemZnxService.listbyUidAndCreateTime(uid, userInfo.getCreatetime());
 
        if (list != null)
            for (SystemZnx systemZnx : list) {
                AccountMessage accountMessage = new AccountMessage();
                accountMessage.setTitle(systemZnx.getTitle());
                accountMessage.setContent(systemZnx.getContent());
                accountMessage.setCreateTime(systemZnx.getCreateTime());
                accountMessage.setIsOpen(false);
                accountMessage.setUserInfo(new UserInfo(uid));
                accountMessage.setSystemMsgId(systemZnx.getId());
                save(accountMessage);
            }
    }
 
}