admin
2021-11-19 7511509c68bd2892aad48a0612d497387660214d
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package com.yeshi.location.app.service.impl.user;
 
import java.lang.Exception;
import javax.annotation.Resource;
 
import com.yeshi.location.app.entity.SystemEnum;
import com.yeshi.location.app.service.inter.user.QQUserInfoService;
import com.yeshi.location.app.service.inter.user.WXUserInfoService;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
 
import org.yeshi.utils.bean.BeanUtil;
 
import java.util.List;
 
import com.yeshi.location.app.dao.user.UserInfoDao;
import com.yeshi.location.app.entity.user.UserInfo;
import com.yeshi.location.app.service.inter.user.UserInfoService;
import com.yeshi.location.app.service.query.user.UserInfoQuery;
import com.yeshi.location.app.dao.user.UserInfoDao.DaoQuery;
import org.yeshi.utils.statistic.BaseStatisticMySQLTimeQuery;
import org.yeshi.utils.statistic.BaseStatisticTimeQuery;
import org.yeshi.utils.statistic.StatisticNumberResult;
 
@Service
public class UserInfoServiceImpl implements UserInfoService {
 
    @Resource
    private UserInfoDao userInfoMapper;
    @Resource
    private WXUserInfoService wxUserInfoService;
    @Resource
    private QQUserInfoService qqUserInfoService;
 
    @Override
    public List<UserInfo> list(UserInfoQuery userInfoQuery, int page, int pageSize) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(userInfoQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        return userInfoMapper.list(daoQuery);
    }
 
    @Override
    public long count(UserInfoQuery userInfoQuery) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(userInfoQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return userInfoMapper.count(daoQuery);
    }
 
    @Override
    public UserInfo get(Long id) {
        return userInfoMapper.selectByPrimaryKey(id);
    }
 
    @Override
    public void add(UserInfo userInfo) throws Exception {
        if (userInfo.getCreateTime() == null) {
            userInfo.setCreateTime(new Date());
        }
        if (userInfo.getStatus() == null) {
            userInfo.setStatus(UserInfo.STATUS_NORMAL);
        }
        //保存
        userInfoMapper.insertSelective(userInfo);
    }
 
    @Override
    public void update(UserInfo userInfo) {
        if (userInfo.getUpdateTime() == null) {
            userInfo.setUpdateTime(new Date());
        }
        //保存
        userInfoMapper.updateByPrimaryKey(userInfo);
    }
 
    @Override
    public void delete(List<Long> idList) {
        for (Long id : idList) {
            userInfoMapper.deleteByPrimaryKey(id);
        }
    }
 
    @Override
    public UserInfo getDetail(Long uid) {
        UserInfo user = get(uid);
        if (user == null) {
            return null;
        }
        if (user.getWxUser() != null && user.getWxUser().getId() != null) {
            //装载微信信息
            user.setWxUser(wxUserInfoService.get(user.getWxUser().getId()));
        }
 
        if (user.getQqUser() != null && user.getQqUser().getId() != null) {
            //装载QQ信息
            user.setQqUser(qqUserInfoService.get(user.getQqUser().getId()));
        }
 
        return user;
    }
 
    @Override
    public List<UserInfo> getDetailList(List<Long> uidList) {
        if (uidList == null) {
            return null;
        }
 
        List<UserInfo> userInfoList = new ArrayList<>();
        for (Long id : uidList) {
            userInfoList.add(getDetail(id));
        }
        return userInfoList;
    }
 
    @Override
    public UserInfo selectByPhoneAndSystemAndStatus(String phone, SystemEnum system, Integer status) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.phone = phone;
        daoQuery.system = system;
        daoQuery.status = status;
        daoQuery.count = 1;
        List<UserInfo> list = userInfoMapper.list(daoQuery);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    @Override
    public UserInfo selectByWXIdAndSystemAndStatus(Long wxId, SystemEnum system, Integer status) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.wxId = wxId;
        daoQuery.system = system;
        daoQuery.status = status;
        daoQuery.count = 1;
        List<UserInfo> list = userInfoMapper.list(daoQuery);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    @Override
    public UserInfo selectByQQIdAndSystemAndStatus(Long qqId, SystemEnum system, Integer status) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.qqId = qqId;
        daoQuery.system = system;
        daoQuery.status = status;
        daoQuery.count = 1;
        List<UserInfo> list = userInfoMapper.list(daoQuery);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    @Override
    public UserInfo selectByEmailAndSystemAndStatus(String email, SystemEnum system, Integer status) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.email = email;
        daoQuery.system = system;
        daoQuery.status = status;
        daoQuery.count = 1;
        List<UserInfo> list = userInfoMapper.list(daoQuery);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    @Override
    public SystemEnum getSystem(Long uid) {
        UserInfo userInfo = userInfoMapper.selectByPrimaryKey(uid);
        if (userInfo == null) {
            return null;
        }
        return userInfo.getSystem();
    }
 
    @Override
    public UserInfo getAvaiableUser(Long uid) {
        UserInfo userInfo = userInfoMapper.selectByPrimaryKey(uid);
        if (userInfo != null && userInfo.getStatus() == UserInfo.STATUS_NORMAL) {
            return userInfo;
        }
        return null;
    }
 
    @Override
    public List<StatisticNumberResult> statisticRegisterUser(SystemEnum system, BaseStatisticTimeQuery timeQuery) {
 
       return userInfoMapper.statisticByCreateTime(system, BaseStatisticMySQLTimeQuery.create(timeQuery));
 
    }
 
 
}