| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.Serializable;
|
| | | import java.math.BigDecimal;
|
| | | import java.math.BigInteger;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.hibernate.HibernateException;
|
| | | import org.hibernate.Query;
|
| | | import org.hibernate.SQLQuery;
|
| | | import org.hibernate.Session;
|
| | | import org.springframework.context.annotation.Lazy;
|
| | | import org.springframework.core.task.TaskExecutor;
|
| | | import org.springframework.orm.hibernate4.HibernateCallback;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Propagation;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.FileUtil;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | |
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserShareGoodsHistoryMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.share.ShareMapper;
|
| | | import com.yeshi.fanli.dao.user.UserInfoDao;
|
| | | import com.yeshi.fanli.entity.bus.user.BindingAccount;
|
| | | import com.yeshi.fanli.entity.bus.user.InviteUser;
|
| | | import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.WeiXinUser;
|
| | | import com.yeshi.fanli.entity.system.BusinessSystem;
|
| | | import com.yeshi.fanli.exception.ThreeSaleException;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum;
|
| | | import com.yeshi.fanli.exception.user.UserInfoException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionAuthRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
|
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService;
|
| | | import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserRankService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.user.tb.TaoBaoUnionAuthRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.FilePathEnum;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.ThreadUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.Utils;
|
| | | import com.yeshi.fanli.util.account.UserUtil;
|
| | | import com.yeshi.fanli.util.wx.WXLoginUtil;
|
| | | import com.yeshi.fanli.util.user.UserLevelUtil;
|
| | | import com.yeshi.fanli.vo.user.UserInfoVO;
|
| | |
|
| | | import net.coobird.thumbnailator.Thumbnails;
|
| | |
|
| | | @Service
|
| | | public class UserInfoServiceImpl implements UserInfoService {
|
| | |
|
| | | @Resource(name = "taskExecutor")
|
| | | private TaskExecutor executor;
|
| | | |
| | | @Resource
|
| | | private UserInfoDao userInfoDao;
|
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | |
| | | @Resource
|
| | | private HongBaoV2CountService hongBaoV2CountService;
|
| | |
|
| | | @Resource
|
| | | private UserRankService userRankService;
|
| | |
|
| | | @Resource
|
| | | private UserActiveLogService userActiveLogService;
|
| | |
|
| | | @Resource
|
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionAuthRecordService taoBaoUnionAuthRecordService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private SpreadUserImgService spreadUserImgService;
|
| | | |
| | | |
| | |
|
| | | @Lazy
|
| | | @Resource
|
| | | private UserInfoModifyRecordService userInfoModifyRecordService;
|
| | |
|
| | | public UserInfo getUserByLoginTypeAndOpenId(int loginType, String openid, String appid) {
|
| | | List<UserInfo> list = null;
|
| | | if (loginType == 1) {
|
| | | list = userInfoDao.list("from UserInfo u where u.openid=? and u.appId = ? ",
|
| | | new Serializable[] { openid, appid });
|
| | | list = userInfoMapper.listByAppIdAndTaoBaoOpenId(appid, openid);
|
| | | } else {
|
| | | list = userInfoDao.list("from UserInfo u where u.wxUnionId=? and u.appId = ? ",
|
| | | new Serializable[] { openid, appid });
|
| | | list = userInfoMapper.listByAppIdAndWXUnionId(appid, openid);
|
| | | }
|
| | |
|
| | | if (list != null)
|
| | |
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | //
|
| | | // public UserInfo getUserByLoginTypeAndOpenIdByMybatis(int loginType,
|
| | | // String openid, String appid) {
|
| | | // List<UserInfo> list = null;
|
| | | // if (loginType == 1) {
|
| | | // list = userInfoDao.list("from UserInfo u where u.openid=? and u.appId = ?
|
| | | // ",
|
| | | // new Serializable[] { openid, appid });
|
| | | // } else {
|
| | | // list = userInfoDao.list("from UserInfo u where u.wxUnionId=? and u.appId
|
| | | // = ? ",
|
| | | // new Serializable[] { openid, appid });
|
| | | // }
|
| | | // if (list != null && list.size() > 0) {
|
| | | // return list.get(0);
|
| | | // }
|
| | | // return null;
|
| | | // }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
| | | public UserInfo addUser(UserInfo form, String appid) {
|
| | |
| | |
|
| | | LogHelper.userInfo("添加用户:" + form);
|
| | | if (form.getLoginType() == Constant.WEIXIN) {
|
| | | // final UserInfo temp = form;
|
| | | ThreadUtil.run(new Runnable() {
|
| | | public void run() {
|
| | | UserInfo temp = userInfoDao.find(UserInfo.class, form.getId());
|
| | | UserInfo temp = userInfoMapper.selectByPrimaryKey(form.getId());
|
| | | COSManager cosManager = COSManager.getInstance();
|
| | | InputStream inputStream = HttpUtil.getAsInputStream(temp.getPortrait());
|
| | | String uploadFile = cosManager.uploadFile(inputStream, UUID.randomUUID().toString()).getUrl();
|
| | | temp.setPortrait(uploadFile);
|
| | | userInfoDao.update(temp);
|
| | | String uploadFile = cosManager.uploadFile(inputStream, FilePathEnum.userPortrait.getPath() + UUID.randomUUID().toString()).getUrl();
|
| | | UserInfo updateTemp = new UserInfo(temp.getId());
|
| | | updateTemp.setPortrait(uploadFile);
|
| | | userInfoMapper.updateByPrimaryKeySelective(updateTemp);
|
| | | }
|
| | | });
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | public boolean createUser(UserInfo form, String appid) {
|
| | | Long id = (Long) userInfoDao.excute(new HibernateCallback<Long>() {
|
| | | public Long doInHibernate(Session session) throws HibernateException {
|
| | | SQLQuery query = session.createSQLQuery("SELECT IFNULL(MAX(id),100000) FROM yeshi_ec_user ");
|
| | | List list = query.list();
|
| | | long dd = (long) (Math.random() * 100);
|
| | | if (dd == 0) {
|
| | | dd = 1;
|
| | | }
|
| | | long bid = Long.parseLong(list.get(0) + "");
|
| | | return bid + dd;
|
| | | }
|
| | | });
|
| | |
|
| | | long maxUid = userInfoMapper.getMaxUid();
|
| | |
|
| | | long dd = (long) (Math.random() * 100);
|
| | | if (dd == 0) {
|
| | | dd = 1;
|
| | | }
|
| | | long bid = maxUid;
|
| | | long id = bid + dd;
|
| | |
|
| | | form.setId(id);
|
| | | form.setAppId(appid);
|
| | | userInfoDao.save(form);
|
| | | userInfoMapper.insertSelective(form);
|
| | | return true;
|
| | | }
|
| | |
|
| | | public UserInfo getUserById(long uid) {
|
| | | UserInfo user = userInfoDao.find(UserInfo.class, uid);
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | if (user.getState() != null && user.getState() != UserInfo.STATE_NORMAL)
|
| | | return null;
|
| | | if (user != null) {
|
| | |
| | |
|
| | | @Transactional
|
| | | public void update(UserInfo user) {
|
| | | userInfoDao.update(user);
|
| | | userInfoMapper.updateByPrimaryKeySelective(user);
|
| | | }
|
| | |
|
| | | public long getUserCount() {
|
| | | return userInfoDao.getCount("select count(*) from UserInfo");
|
| | | return userInfoMapper.countAvaiableUser();
|
| | | }
|
| | |
|
| | | public List<UserInfo> getUserList(int index, String key) {
|
| | |
|
| | | int start = index * Constant.PAGE_SIZE;
|
| | |
|
| | | if (NumberUtil.isNumeric(key)) {
|
| | | long l = Long.parseLong(key);
|
| | | return userInfoDao.list("from UserInfo u where u.id = ? or u.nickName like ? order by u.id desc", start,
|
| | | Constant.PAGE_SIZE, new Serializable[] { l, "%" + key + "%" });
|
| | | }
|
| | |
|
| | | return userInfoDao.list("from UserInfo u where u.nickName like ? order by u.id desc ", start,
|
| | | Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%" });
|
| | |
|
| | | }
|
| | |
|
| | | public int getUserCount(String key) {
|
| | | if (NumberUtil.isNumeric(key)) {
|
| | | long lk = Long.parseLong(key);
|
| | | return (int) userInfoDao.getCount("select count(u.id) from UserInfo u where u.id = ? or u.nickName like ? ",
|
| | | new Serializable[] { lk, "%" + key + "%" });
|
| | | }
|
| | | Long lcount = userInfoDao.getCount("select count(u.id) from UserInfo u where u.nickName like ? ",
|
| | | new Serializable[] { "%" + key + "%" });
|
| | | return lcount.intValue();
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | public Map<String, Integer> getnewUserByDate(final int days, Date date) {
|
| | |
|
| | | final Map<String, Integer> map = new HashMap<String, Integer>();
|
| | | long timestampms = date.getTime();
|
| | | final long timestamps = timestampms / 1000;
|
| | | List<String> list = TimeUtil.getEmupDate(days, timestampms);
|
| | | for (String dataStr : list) {
|
| | | map.put(dataStr, 0);
|
| | | }
|
| | | return (Map<String, Integer>) userInfoDao.excute(new HibernateCallback<Map<String, Integer>>() {
|
| | |
|
| | | public Map<String, Integer> doInHibernate(Session session) throws HibernateException {
|
| | | SQLQuery sqlQuery = session.createSQLQuery(
|
| | | "SELECT DATE(FROM_UNIXTIME(createtime/1000)) c,COUNT(*) FROM yeshi_ec_user WHERE DATE_SUB(FROM_UNIXTIME(?), INTERVAL ? DAY) <= DATE(FROM_UNIXTIME(createtime/1000)) AND DATE(FROM_UNIXTIME(createtime/1000)) <= FROM_UNIXTIME(?) GROUP BY c");
|
| | | sqlQuery.setParameter(0, timestamps);
|
| | | sqlQuery.setParameter(1, days);
|
| | | sqlQuery.setParameter(2, timestamps);
|
| | | List<Object[]> list = sqlQuery.list();
|
| | | for (Object[] objArr : list) {
|
| | | map.put(TimeUtil.getSimpleDate((Date) objArr[0]), ((BigInteger) objArr[1]).intValue());
|
| | | }
|
| | | return map;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | public Map<String, Integer> getnewUserByMonth(final int months, final Date endDate) {
|
| | | List<String> monthList = Utils.getDateMonthList(months, endDate);
|
| | | final Map<String, Integer> map = new HashMap<String, Integer>();
|
| | | for (String monthStr : monthList) {
|
| | | map.put(monthStr, 0);
|
| | | }
|
| | | return (Map<String, Integer>) userInfoDao.excute(new HibernateCallback<Map<String, Integer>>() {
|
| | |
|
| | | public Map<String, Integer> doInHibernate(Session session) throws HibernateException {
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(endDate);
|
| | | calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + 1);
|
| | | calendar.set(Calendar.DAY_OF_MONTH, 1);
|
| | | long curTime = (calendar.getTime().getTime()) / 1000;
|
| | | SQLQuery sqlQuery = session.createSQLQuery(
|
| | | "SELECT DATE_FORMAT(FROM_UNIXTIME(createtime/1000),'%Y-%m') months,COUNT(*) FROM yeshi_ec_user WHERE DATE(FROM_UNIXTIME(createtime/1000)) >= DATE_SUB(FROM_UNIXTIME(?),INTERVAL ? MONTH) AND DATE(FROM_UNIXTIME(createtime/1000)) < FROM_UNIXTIME(?) GROUP BY months");
|
| | | sqlQuery.setParameter(0, curTime);
|
| | | sqlQuery.setParameter(1, months);
|
| | | sqlQuery.setParameter(2, curTime);
|
| | | List<Object[]> list = sqlQuery.list();
|
| | | for (Object[] objArr : list) {
|
| | | map.put((String) objArr[0], ((BigInteger) objArr[1]).intValue());
|
| | | }
|
| | | return map;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | public Map<String, Integer> getUserTotalByDate(final int days, Date date) {
|
| | |
|
| | | final Map<String, Integer> map = new HashMap<String, Integer>();
|
| | | long timestampms = date.getTime();
|
| | | final List<String> list = TimeUtil.getEmupDate(days, timestampms);
|
| | | for (String dataStr : list) {
|
| | | map.put(dataStr, 0);
|
| | | }
|
| | | return (Map<String, Integer>) userInfoDao.excute(new HibernateCallback<Map<String, Integer>>() {
|
| | |
|
| | | public Map<String, Integer> doInHibernate(Session session) throws HibernateException {
|
| | | StringBuffer sb = new StringBuffer();
|
| | | int ii = 0;
|
| | | for (String day : list) {
|
| | | if (ii == 0) {
|
| | | sb.append("SELECT '" + day + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_user_day a WHERE a.c<= '"
|
| | | + day + "' ");
|
| | | } else {
|
| | | sb.append("UNION ALL SELECT '" + day
|
| | | + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_user_day a WHERE a.c<= '" + day + "' ");
|
| | | }
|
| | | ii++;
|
| | | }
|
| | |
|
| | | SQLQuery sqlQuery = session.createSQLQuery(sb.toString());
|
| | | List<Object[]> list = sqlQuery.list();
|
| | | for (Object[] objArr : list) {
|
| | | map.put(String.valueOf(objArr[0]), ((BigDecimal) objArr[1]).intValue());
|
| | | }
|
| | | return map;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | public Map<String, Integer> getUserTotalByMonth(int months, Date date) {
|
| | | final List<String> monthList = Utils.getDateMonthList(months, date);
|
| | | final Map<String, Integer> map = new HashMap<String, Integer>();
|
| | | for (String monthStr : monthList) {
|
| | | map.put(monthStr, 0);
|
| | | }
|
| | | return (Map<String, Integer>) userInfoDao.excute(new HibernateCallback<Map<String, Integer>>() {
|
| | |
|
| | | public Map<String, Integer> doInHibernate(Session session) throws HibernateException {
|
| | |
|
| | | StringBuffer sb = new StringBuffer();
|
| | | int ii = 0;
|
| | | for (String month : monthList) {
|
| | | if (ii == 0) {
|
| | | sb.append("SELECT '" + month
|
| | | + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_user_month a WHERE a.months<= '" + month
|
| | | + "' ");
|
| | | } else {
|
| | | sb.append("UNION ALL SELECT '" + month
|
| | | + "' AS t,IFNULL(SUM(a.s),0) FROM yeshi_ec_user_month a WHERE a.months<= '" + month
|
| | | + "' ");
|
| | | }
|
| | | ii++;
|
| | | }
|
| | |
|
| | | SQLQuery sqlQuery = session.createSQLQuery(sb.toString());
|
| | | List<Object[]> list = sqlQuery.list();
|
| | | for (Object[] objArr : list) {
|
| | | map.put((String) objArr[0], ((BigDecimal) objArr[1]).intValue());
|
| | | }
|
| | | return map;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public List<UserInfo> getUserListByUid(long uid) {
|
| | | List<UserInfo> list = userInfoDao.list("from UserInfo u where u.id = ? ", new Serializable[] { uid });
|
| | | return list;
|
| | | }
|
| | |
|
| | | public double getFreezeAssets(final double min) {
|
| | | return (Double) userInfoDao.excute(new HibernateCallback<Double>() {
|
| | |
|
| | | public Double doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createSQLQuery(
|
| | | "select IFNULL(sum(u.my_hongBao),0) from yeshi_ec_user u where u.my_hongBao < ? ");
|
| | | query.setParameter(0, min);
|
| | | Double result = Double.parseDouble(query.uniqueResult() + "");
|
| | | return result.doubleValue();
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public double getCanAssets(final double min) {
|
| | | return (Double) userInfoDao.excute(new HibernateCallback<Double>() {
|
| | |
|
| | | public Double doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createSQLQuery(
|
| | | "select IFNULL(sum(u.my_hongBao),0) from yeshi_ec_user u where u.my_hongBao >= ? ");
|
| | | query.setParameter(0, min);
|
| | | Double result = Double.parseDouble(query.uniqueResult() + "");
|
| | | return result.doubleValue();
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public long getRandomShamUser() {
|
| | | return (Long) userInfoDao.excute(new HibernateCallback<Long>() {
|
| | |
|
| | | public Long doInHibernate(Session session) throws HibernateException {
|
| | | SQLQuery sqlQuery = session
|
| | | .createSQLQuery("SELECT id FROM yeshi_ec_user WHERE login_type=-1 ORDER BY RAND() LIMIT 1");
|
| | | List list = sqlQuery.list();
|
| | | if (list.size() > 0) {
|
| | | long id = Long.parseLong(list.get(0) + "");
|
| | | return id;
|
| | | }
|
| | | return (long) 0;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public boolean inviteWXUserInfo(String code, UserInfo inviter) {
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinWYUser(code);
|
| | | if (weiXinUser == null) {
|
| | | return false;
|
| | | }
|
| | | String wxUnionId = weiXinUser.getUnionid();
|
| | | UserInfo find = getUserByLoginTypeAndOpenId(Constant.WEIXIN, wxUnionId, Constant.APPID);
|
| | |
|
| | | if (find == null) {
|
| | | find = new UserInfo();
|
| | | find.setAppId(Constant.APPID);
|
| | | find.setWxUnionId(weiXinUser.getUnionid());
|
| | | String wxHeadImg = COSManager.getInstance()
|
| | | .uploadFile(HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl()),
|
| | | Constant.WXHEADURL + UUID.randomUUID().toString())
|
| | | .getUrl();
|
| | | find.setPortrait(wxHeadImg);
|
| | | find.setWxPic(wxHeadImg);
|
| | | find.setNickName(weiXinUser.getNickname());
|
| | | find.setWxName(weiXinUser.getNickname());
|
| | | find.setLoginType(Constant.WEIXIN);
|
| | | find.setRank(0);
|
| | | find.setWxOpenId(weiXinUser.getOpenid());
|
| | | BusinessSystem system = new BusinessSystem(Constant.FANLI);
|
| | | system.setPlatform(1);
|
| | | find.setSystem(system);
|
| | | }
|
| | |
|
| | | try {
|
| | | threeSaleSerivce.bind(find, inviter);
|
| | | return true;
|
| | | } catch (ThreeSaleException e) {
|
| | | e.printStackTrace();
|
| | | return false;
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | @Transactional
|
| | | public void unBindUserInfo(UserInfo user, int type) {
|
| | |
| | | user.setPortrait(user.getTbPic());
|
| | | }
|
| | | }
|
| | | userInfoDao.update(user);
|
| | | userInfoMapper.updateByPrimaryKeySelective(user);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void addMoney(UserInfo userInfo, BigDecimal money) {
|
| | |
|
| | | userInfoDao.excute(new HibernateCallback() {
|
| | | @Override
|
| | | public Object doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createQuery("update UserInfo u set u.myHongBao = u.myHongBao + ? where u.id = ?");
|
| | | query.setParameter(0, money);
|
| | | query.setParameter(1, userInfo.getId());
|
| | | query.executeUpdate();
|
| | | return null;
|
| | | }
|
| | | });
|
| | |
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public List<UserInfo> findFriends(long id, int type) {
|
| | | List<UserInfo> list;
|
| | | if (type == 1) {
|
| | | list = userInfoDao.list("select ts.worker from ThreeSale ts where ts.boss.id = ?",
|
| | | new Serializable[] { id });
|
| | | } else {
|
| | | list = (List<UserInfo>) userInfoDao.excute(new HibernateCallback<List<UserInfo>>() {
|
| | | @Override
|
| | | public List<UserInfo> doInHibernate(Session session) throws HibernateException {
|
| | | SQLQuery query = session.createSQLQuery(
|
| | | "select uu.* from yeshi_ec_user uu left join (SELECT trw.`worker_id` as id FROM yeshi_ec_threesale trw RIGHT JOIN "
|
| | | + "(SELECT tr.`worker_id` AS id FROM `yeshi_ec_threesale` tr LEFT JOIN `yeshi_ec_user` u ON tr.`boss_id`=u.`id` WHERE tr.`boss_id`=?) nu ON nu.id = trw.`boss_id`"
|
| | | + "WHERE nu.id = trw.`boss_id`) u on uu.id=u.id where uu.id=u.id");
|
| | | query.setParameter(0, id);
|
| | | query.addEntity(UserInfo.class);
|
| | | return query.list();
|
| | | }
|
| | | });
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int findFriendsCount(long id, int type) {
|
| | | if (type == 1) {
|
| | | return (int) userInfoDao.getCount("select count(*) from ThreeSale ts where ts.boss.id = ? and ts.state=1",
|
| | | new Serializable[] { id });
|
| | | } else {
|
| | | return (int) userInfoDao.getCountSQL(" from yeshi_ec_threesale trw RIGHT JOIN "
|
| | | + "(SELECT tr.`worker_id` AS id FROM `yeshi_ec_threesale` tr LEFT JOIN `yeshi_ec_user` u ON tr.`boss_id`=u.`id` WHERE tr.`boss_id`=? and tr.state=1) nu ON nu.id = trw.`boss_id`"
|
| | | + "WHERE nu.id = trw.`boss_id` and trw.state=1", new Serializable[] { id });
|
| | | }
|
| | | userInfoMapper.addHongBaoByUid(userInfo.getId(), money);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateLoginInfo(UserInfo user) {
|
| | | userInfoDao.excute(new HibernateCallback() {
|
| | | @Override
|
| | | public Object doInHibernate(Session session) throws HibernateException {
|
| | | SQLQuery query = session
|
| | | .createSQLQuery("update yeshi_ec_user u set u.loginip=?,u.last_logintime=? where u.id = ?");
|
| | | query.setParameter(0, user.getLastLoginIp());
|
| | | query.setParameter(1, user.getLastLoginTime());
|
| | | query.setParameter(2, user.getId());
|
| | | return query.executeUpdate();
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<InviteUser> getFriendsList(final long id, int type, int page, int pageSize) {
|
| | | List<InviteUser> list = null;
|
| | | if (type == 1) {
|
| | | list = userInfoDao.getHibernateTemplate().execute(new HibernateCallback<List<InviteUser>>() {
|
| | | @Override
|
| | | public List<InviteUser> doInHibernate(Session session) throws HibernateException {
|
| | | List list = session
|
| | | .createSQLQuery(
|
| | | "SELECT u.id,u.`nick_name`,u.`portrait`,uu.state FROM (SELECT t.* FROM `yeshi_ec_threesale` t "
|
| | | + "WHERE t.`boss_id`=? AND (t.expire = 0 OR t.expire IS NULL) ORDER BY t.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id")
|
| | | .setParameter(0, id).setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list();
|
| | | return covertToInviteUserList(list);
|
| | | }
|
| | | });
|
| | | } else {
|
| | | list = userInfoDao.getHibernateTemplate().execute(new HibernateCallback<List<InviteUser>>() {
|
| | | @Override
|
| | | public List<InviteUser> doInHibernate(Session session) throws HibernateException {
|
| | | List list = session
|
| | | .createSQLQuery(
|
| | | "SELECT u.id,u.`nick_name`,u.`portrait`,uu.state FROM (SELECT tt.* FROM `yeshi_ec_threesale` t LEFT JOIN yeshi_ec_threesale tt ON tt.`boss_id`=t.`worker_id` "
|
| | | + " WHERE t.`boss_id`=? AND tt.`id` IS NOT NULL AND (tt.expire = 0 OR tt.expire IS NULL) ORDER BY tt.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id")
|
| | | .setParameter(0, id).setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list();
|
| | | return covertToInviteUserList(list);
|
| | | }
|
| | | });
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | private List<InviteUser> covertToInviteUserList(List list) {
|
| | | List<InviteUser> ilist = new ArrayList<>();
|
| | | if (list != null)
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | Object[] objs = (Object[]) list.get(i);
|
| | | InviteUser inviteUser = new InviteUser();
|
| | | UserInfo user = new UserInfo();
|
| | | user.setId(Long.parseLong(objs[0] + ""));
|
| | | user.setNickName(objs[1] + "");
|
| | | user.setPortrait(objs[2] + "");
|
| | | inviteUser.setUserInfo(user);
|
| | | inviteUser.setValid(Boolean.parseBoolean(objs[3] + ""));
|
| | | ilist.add(inviteUser);
|
| | | }
|
| | | return ilist;
|
| | | UserInfo update = new UserInfo(user.getId());
|
| | | update.setLastLoginIp(user.getLastLoginIp());
|
| | | update.setLastLoginTime(user.getLastLoginTime());
|
| | | userInfoMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void cleanPassword(long id) {
|
| | | userInfoMapper.cleanPassword(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long getFriendsListCount(long id, int type) {
|
| | | if (type == 1)
|
| | | return userInfoDao.getCountSQL("SELECT COUNT(t.`id`) FROM `yeshi_ec_threesale` t WHERE t.`boss_id`= " + id
|
| | | + " AND (t.expire = 0 OR t.expire IS NULL)");
|
| | | else
|
| | | return userInfoDao.getCountSQL(
|
| | | "SELECT COUNT(tt.id) FROM `yeshi_ec_threesale` t LEFT JOIN yeshi_ec_threesale tt ON tt.`boss_id`=t.`worker_id` WHERE t.`boss_id`="
|
| | | + id + " AND tt.`id` IS NOT NULL AND (tt.expire = 0 OR tt.expire IS NULL)");
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | @Override
|
| | | public UserInfo getUserByIdWithMybatis(long uid) {
|
| | | UserInfo user = userInfoMapper.selectByPKey(uid);
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | return UserUtil.filterForClientUser(user);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long queryCount(Integer userState, String key, Integer keyType, String userRank, Integer days,
|
| | | String startTime, String endTime) {
|
| | | return userInfoMapper.queryCount(userState, key, keyType, userRank, days, startTime, endTime);
|
| | | String startTime, String endTime,Integer userType, String level, Integer activeCode) {
|
| | | return userInfoMapper.queryCount(userState, key, keyType, userRank, days, startTime, endTime,userType, level, activeCode);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserInfoVO> query(long start, int count, Integer userState, String key, Integer keyType,
|
| | | String userRank, Integer days, String startTime, String endTime, Integer orderField, Integer orderMode) {
|
| | | String userRank, Integer days, String startTime, String endTime, Integer orderField, Integer orderMode,
|
| | | Integer userType, String level, Integer activeCode) {
|
| | |
|
| | | List<UserInfoVO> userList = userInfoMapper.query(start, count, userState, key, keyType, userRank, days,
|
| | | startTime, endTime, orderField, orderMode);
|
| | | startTime, endTime, orderField, orderMode,userType, level, activeCode);
|
| | |
|
| | | if (userList == null || userList.size() == 0) {
|
| | | return null;
|
| | |
| | | }
|
| | |
|
| | | public void convertUserInfoVOData(UserInfoVO userInfoVO) {
|
| | |
|
| | | String rankName = userInfoVO.getRankName();
|
| | | if (rankName == null || rankName.trim().length() == 0) {
|
| | | userInfoVO.setRankName("青铜");
|
| | |
| | | userInfoVO.setLastLoginTime(null);
|
| | | }
|
| | |
|
| | | /*
|
| | | * 显示用户微信 淘宝 老版本存在 String wxUnionId = userInfoVO.getWxUnionId(); if
|
| | | * (wxUnionId == null || wxUnionId.trim().length() == 0) {
|
| | | * userInfoVO.setWxName(null); }
|
| | | * |
| | | * String taoBaoUid = userInfoVO.getTaoBaoUid(); if (taoBaoUid == null
|
| | | * || taoBaoUid.trim().length() == 0) { userInfoVO.setTbName(null); }
|
| | | */
|
| | | // 显示用户微信 淘宝 老版本存在
|
| | | String wxUnionId = userInfoVO.getWxUnionId();
|
| | | if (wxUnionId == null || wxUnionId.trim().length() == 0) {
|
| | | userInfoVO.setWxName(null);
|
| | | }
|
| | |
|
| | | // 是否绑定支付宝(购买 + 分享权限)
|
| | | String taoBaoUid = userInfoVO.getTaoBaoUid();
|
| | | String tbSpecialId = userInfoVO.getTbSpecialId();
|
| | | String tbRelationId = userInfoVO.getTbRelationId();
|
| | | if (StringUtil.isNullOrEmpty(taoBaoUid) || StringUtil.isNullOrEmpty(tbSpecialId)
|
| | | || StringUtil.isNullOrEmpty(tbRelationId)) {
|
| | | userInfoVO.setTbName(null);
|
| | | userInfoVO.setTaoBaoUid(null);
|
| | | }
|
| | |
|
| | | Long uid = userInfoVO.getId();
|
| | |
|
| | | /* 绑定收款账号信息 */
|
| | | List<BindingAccount> account = bindingAccountMapper.selectByUid(uid);
|
| | | if (account != null && account.size() > 0) {
|
| | |
| | | // 二度队员数量
|
| | | int secondTeamCount = shareMapper.mySecondTeamCount(uid + "");
|
| | | userInfoVO.setCountLevelTwo(secondTeamCount);
|
| | | |
| | | String userLevel = userInfoVO.getUserLevel();
|
| | | if (!StringUtil.isNullOrEmpty(userLevel)) {
|
| | | userInfoVO.setUserLevel(UserLevelUtil.getByEnumName(userLevel).getName());
|
| | | }
|
| | | |
| | | String inviteCode = userInfoVO.getInviteCode();
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | userInfoVO.setInviteCode("已激活");
|
| | | } else {
|
| | | userInfoVO.setInviteCode("未激活");
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | @Override
|
| | | public UserInfo selectByPKey(Long id) {
|
| | | return userInfoMapper.selectByPKey(id);
|
| | | return userInfoMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public UserInfo getInfoByPhoneOrInviteCode(String phone, String inviteCode) {
|
| | | return userInfoMapper.getInfoByPhoneOrInviteCode(phone, inviteCode);
|
| | | public UserInfo getUserInfoByInviteCode(String inviteCode) {
|
| | | return userInfoMapper.getUserInfoByInviteCode(inviteCode);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | throw new UserInfoException(1, "请求参数为空");
|
| | | }
|
| | |
|
| | | UserInfo userInfo = userInfoMapper.selectByPKey(uid);
|
| | | UserInfo userInfo = userInfoMapper.selectByPrimaryKey(uid);
|
| | | if (userInfo == null) {
|
| | | throw new UserInfoException(1, "用户不存在");
|
| | | }
|
| | |
| | | throw new UserInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
|
| | | }
|
| | |
|
| | | if (userInfo.getState() != UserInfo.STATE_NORMAL) {
|
| | | throw new UserInfoException(1, "用户不存在");
|
| | | if (userInfo.getState() == UserInfo.STATE_DELETE || userInfo.getState() == UserInfo.STATE_DELETE_OUT_OF_DATE) {
|
| | | throw new UserInfoException(Constant.CODE_FORBIDDEN_USER, "帐户已被删除,请重新登录");
|
| | | }
|
| | |
|
| | | // 淘宝昵称 组织
|
| | |
| | |
|
| | | @Override
|
| | | public BigDecimal getBalance(Long uid) {
|
| | | UserInfo user = userInfoMapper.selectByPKey(uid);
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | if (user != null)
|
| | | return user.getMyHongBao();
|
| | | return null;
|
| | |
| | |
|
| | | @Override
|
| | | public void uploadPortrait(MultipartFile file, Long uid) throws UserInfoException, IOException {
|
| | | |
| | | UserInfo userInfo = userInfoMapper.selectByPKey(uid);
|
| | | if(userInfo == null) {
|
| | |
|
| | | UserInfo userInfo = userInfoMapper.selectByPrimaryKey(uid);
|
| | | if (userInfo == null) {
|
| | | throw new UserInfoException(1, "用户不存在");
|
| | | }
|
| | | |
| | | String portrait = userInfo.getPortrait();
|
| | | if (portrait != null && portrait.trim().length() > 0 && portrait.contains("/img/user/")) {
|
| | | COSManager.getInstance().deleteFile(portrait);
|
| | | }
|
| | | |
| | | |
| | | // 文件解析 |
| | | InputStream inputStream = file.getInputStream();
|
| | | String contentType = file.getContentType();
|
| | | String type = contentType.substring(contentType.indexOf("/") + 1);
|
| | | |
| | | // 文件路径
|
| | | String filePath="/img/user/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | |
|
| | | // 谷歌压缩图片
|
| | | String targetPath = FileUtil.getCacheDir() + "/uploadPortrait_" + uid + "_" + System.currentTimeMillis()
|
| | | + ".jpg";
|
| | | Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath);
|
| | |
|
| | | // 执行上传
|
| | | String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
|
| | | |
| | | String filePath =FilePathEnum.userPortrait.getPath() + UUID.randomUUID().toString().replace("-", "") + ".jpg";
|
| | | String fileLink = COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl();
|
| | |
|
| | | // 删除本地图片
|
| | | if (new File(targetPath).exists()) {
|
| | | new File(targetPath).delete();
|
| | | }
|
| | |
|
| | | // 原头像
|
| | | String portrait = userInfo.getPortrait();
|
| | |
|
| | | // 更新信息
|
| | | userInfo.setPortrait(fileLink);
|
| | | userInfoMapper.updateByPrimaryKeySelective(userInfo);
|
| | | |
| | | |
| | |
|
| | | // 删除原头像
|
| | | if (!StringUtil.isNullOrEmpty(portrait)) {
|
| | | COSManager.getInstance().deleteFile(portrait);
|
| | | }
|
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.portrait, fileLink);
|
| | |
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | // 删除分享头像信息
|
| | | spreadUserImgService.deleteImgUrl(uid);
|
| | | spreadUserImgService.deleteImgUrl(uid);
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | |
| | | }
|
| | | }
|
| | | });
|
| | | |
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public void saveUserInfo(String nickName, Long uid) throws UserInfoException {
|
| | | UserInfo userInfo = userInfoMapper.selectByPKey(uid);
|
| | | if(userInfo == null) {
|
| | | UserInfo userInfo = userInfoMapper.selectByPrimaryKey(uid);
|
| | | if (userInfo == null) {
|
| | | throw new UserInfoException(1, "用户不存在");
|
| | | }
|
| | | |
| | |
|
| | | userInfo.setNickName(nickName);
|
| | | userInfoMapper.updateByPrimaryKeySelective(userInfo);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserInfo> getAutoExtractUser(int start, int count, BigDecimal minSurplus, String beganDate,
|
| | | String endDate) {
|
| | | return userInfoMapper.getAutoExtractUser(start, count, minSurplus, beganDate, endDate);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserInfo> listByType(int type, int page, int count) {
|
| | | return userInfoMapper.listByType(type, (page - 1) * count, count);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countByType(int type) {
|
| | | return userInfoMapper.countByType(type);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserInfo> getAutoExtractUserTo1212(int start, int count) {
|
| | | return userInfoMapper.getAutoExtractUserTo1212(start, count);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public UserInfo selectAvailableByPrimaryKey(Long uid) {
|
| | | return userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | }
|
| | |
|
| | |
|
| | | }
|