package com.ks.app.service.impl.user;
|
|
import java.lang.Exception;
|
import javax.annotation.Resource;
|
|
import com.ks.app.entity.SystemEnum;
|
import com.ks.app.service.inter.user.QQUserInfoService;
|
import com.ks.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.ks.app.dao.user.UserInfoDao;
|
import com.ks.app.entity.user.UserInfo;
|
import com.ks.app.service.inter.user.UserInfoService;
|
import com.ks.app.service.query.user.UserInfoQuery;
|
import com.ks.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 List<UserInfo> list(List<Long> uidList) {
|
if(uidList==null||uidList.size()==0) {
|
return new ArrayList<>();
|
}
|
return userInfoMapper.listByUids(uidList);
|
}
|
|
@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));
|
|
}
|
|
@Override
|
public UserInfo selectValidByPhone(SystemEnum system, String phone) {
|
DaoQuery daoQuery = new DaoQuery();
|
daoQuery.phone = phone;
|
daoQuery.system = system;
|
daoQuery.count = 1;
|
List<UserInfo> userInfos = userInfoMapper.list(daoQuery);
|
return userInfos != null && userInfos.size() > 0 ? userInfos.get(0) : null;
|
}
|
|
|
}
|