From 573c491b4a1ba60e12a5678a01c1546c0077c1ee Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 30 七月 2019 09:07:42 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java | 525 +++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 358 insertions(+), 167 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java index a6a4b69..b74410c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java @@ -1,5 +1,7 @@ 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; @@ -18,10 +20,16 @@ import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.Session; +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.BindingAccountMapper; @@ -31,17 +39,29 @@ 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.admin.UserInfoAdmin; import com.yeshi.fanli.entity.bus.user.BindingAccount; +import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode; +import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum; 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.System; +import com.yeshi.fanli.entity.system.BusinessSystem; +import com.yeshi.fanli.exception.ThreeSaleException; +import com.yeshi.fanli.exception.user.ForbiddenUserIdentifyCodeException; +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.hongbao.HongBaoService; +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.BindingAccountService; +import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService; +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.UserInfoService; +import com.yeshi.fanli.service.inter.user.UserRankService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.ThreadUtil; @@ -49,21 +69,21 @@ import com.yeshi.fanli.util.Utils; import com.yeshi.fanli.util.account.UserUtil; import com.yeshi.fanli.util.wx.WXLoginUtil; -import org.yeshi.utils.HttpUtil; -import org.yeshi.utils.NumberUtil; -import org.yeshi.utils.tencentcloud.COSManager; +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 HongBaoService hongBaoService; @Resource private ConfigService configService; @@ -73,23 +93,45 @@ @Resource private UserInfoMapper userInfoMapper; - + @Resource private BindingAccountMapper bindingAccountMapper; - + @Resource private PayInfoMapper payInfoMapper; - + @Resource private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper; - + @Resource private ScanHistoryMapper scanHistoryMapper; - + @Resource private ShareMapper shareMapper; - - + + @Resource + private HongBaoV2CountService hongBaoV2CountService; + + @Resource + private UserRankService userRankService; + + @Resource + private UserActiveLogService userActiveLogService; + + @Resource + private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; + + @Resource + private TaoBaoUnionAuthRecordService taoBaoUnionAuthRecordService; + + @Resource + private SpreadUserImgService spreadUserImgService; + + @Resource + private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; + + @Resource + private BindingAccountService bindingAccountService; public UserInfo getUserByLoginTypeAndOpenId(int loginType, String openid, String appid) { List<UserInfo> list = null; @@ -100,6 +142,16 @@ list = userInfoDao.list("from UserInfo u where u.wxUnionId=? and u.appId = ? ", new Serializable[] { openid, appid }); } + + if (list != null) + for (int i = 0; i < list.size(); i++) { + if (list.get(i).getState() == UserInfo.STATE_DELETE + || list.get(i).getState() == UserInfo.STATE_DELETE_OUT_OF_DATE) { + list.remove(i); + i--; + } + } + if (list != null && list.size() > 0) { return list.get(0); } @@ -146,8 +198,6 @@ return form; } - if (form.getSystem().getId() != 7) - hongBaoService.setNewUserHongBao(form, 1); LogHelper.userInfo("娣诲姞鐢ㄦ埛:" + form); if (form.getLoginType() == Constant.WEIXIN) { // final UserInfo temp = form; @@ -420,13 +470,15 @@ } 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(); + 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()); @@ -434,20 +486,18 @@ find.setLoginType(Constant.WEIXIN); find.setRank(0); find.setWxOpenId(weiXinUser.getOpenid()); - System system = new System(Constant.FANLI); + BusinessSystem system = new BusinessSystem(Constant.FANLI); system.setPlatform(1); find.setSystem(system); - UserInfo addUser = null; - synchronized (UserInfo.class) { - addUser = addUser(find, Constant.APPID); - if (addUser != null && addUser.getId() > 1) { - threeSaleSerivce.bind(find, inviter); - return true; - } - } } - return false; + try { + threeSaleSerivce.bind(find, inviter); + return true; + } catch (ThreeSaleException e) { + e.printStackTrace(); + return false; + } } @Transactional @@ -551,7 +601,8 @@ 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`=? ORDER BY t.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id") + "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); } @@ -562,7 +613,8 @@ 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 ORDER BY tt.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id") + "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); } @@ -596,12 +648,12 @@ @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); + 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"); + + id + " AND tt.`id` IS NOT NULL AND (tt.expire = 0 OR tt.expire IS NULL)"); } @Override @@ -610,149 +662,148 @@ } @Override - public BigDecimal getMyHB(Long id) { - return userInfoMapper.getMyHB(id); - } - - @Override public UserInfo getUserByIdWithMybatis(long uid) { - UserInfo user = userInfoMapper.selectByPrimaryKey(uid); + UserInfo user = userInfoMapper.selectByPKey(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); + } @Override - public List<UserInfoAdmin> query(long start, int count, String key, Integer userType, - Integer days, String startTime, String endTime, Integer orderField,Integer orderMode) { + 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) { - List<UserInfoAdmin> adminList = new ArrayList<UserInfoAdmin>(); + List<UserInfoVO> userList = userInfoMapper.query(start, count, userState, key, keyType, userRank, days, + startTime, endTime, orderField, orderMode); - List<UserInfo> userList = userInfoMapper.query(start, count, key, userType, days, - startTime, endTime, orderField,orderMode); if (userList == null || userList.size() == 0) { return null; } - for (UserInfo userInfo : userList) { - - UserInfoAdmin userInfoAdmin = new UserInfoAdmin(); - - Long lastLoginTime = userInfo.getLastLoginTime(); - if (lastLoginTime == null) { - userInfo.setLastLoginTime(0L); - } - - - userInfoAdmin.setUserInfo(userInfo); - - String wxName = userInfo.getWxName(); - if (StringUtil.isNullOrEmpty(wxName)) { - userInfoAdmin.setWxNameState(1); - } else { - userInfoAdmin.setWxNameState(2); - } - - String phone = userInfo.getPhone(); - if (StringUtil.isNullOrEmpty(phone)) { - userInfoAdmin.setPhoneState(1); - } else { - userInfoAdmin.setPhoneState(2); - } - - String tbName = userInfo.getTbName(); - if (StringUtil.isNullOrEmpty(tbName)) { - userInfoAdmin.setTbNameState(1); - } else { - userInfoAdmin.setTbNameState(2); - } - - - - Long uid = userInfo.getId(); - - /* 缁戝畾璐﹀彿淇℃伅 */ - List<BindingAccount> account = bindingAccountMapper.selectByUid(uid); - if (account != null && account.size() > 0) { - BindingAccount bindingAccount = account.get(0); - Integer type = bindingAccount.getType(); - if (type != null && type == 1) { - // 鏀粯瀹� - userInfoAdmin.setAccountAlipay(bindingAccount.getAccount()); - userInfoAdmin.setAccountName(bindingAccount.getName()); - userInfoAdmin.setAccountBindId(bindingAccount.getId()); - - } else if (type != null && type == 2) { - // 寰俊 - userInfoAdmin.setAccountWX(bindingAccount.getAccount()); - userInfoAdmin.setAccountNameWX(bindingAccount.getName()); - userInfoAdmin.setAccountBindIdWX(bindingAccount.getId()); - } - } - - - // 鏈�鍚庝竴娆′笅鍗曟椂闂� - Long lastOrderTime = hongBaoService.getLastOrderTime(uid); - if (lastOrderTime == null) { - userInfoAdmin.setLastOrderTime(0); - } else { - userInfoAdmin.setLastOrderTime(lastOrderTime); - } - - - // 鍘嗗彶鎬昏鍗� - long totalOrder = hongBaoService.countByUidSelf(uid, null, null); - // 浠婃棩鎬昏鍗� - long todayOrder = hongBaoService.countByUidSelf(uid, 1, null); - // 鏈湀鎬昏鍗� - long monthOrder = hongBaoService.countByUidSelf(uid, null, 1); - - userInfoAdmin.setTotalOrder(totalOrder); - userInfoAdmin.setTodayOrder(todayOrder); - userInfoAdmin.setMonthOrder(monthOrder); - - // 鏀粯瀹濊处鍙� 绱杞处鎬婚噾棰� - double totalMoney = payInfoMapper.sumMoneyByUid(uid); - userInfoAdmin.setTotalMoney(totalMoney); - - // 绱鎻愮幇 (鏆傛湭璁″叆寰俊) - userInfoAdmin.setTotalExtract(totalMoney); - - // 鏈鍙栫孩鍖� 寰呭叆璐﹂噾棰� - double unaccountedMoney = hongBaoService.countForecastMoneysByUid(uid); - userInfoAdmin.setUnaccountedMoney(unaccountedMoney); - - // 鍘嗗彶鎬绘敹鐩� - double totalMoneyHistory = hongBaoService.countReceiveMoneysByUid(uid); - userInfoAdmin.setTotalMoneyHistory(totalMoneyHistory); - - - // 缁熻鍒嗕韩涓暟 - long countUserShares = userShareGoodsHistoryMapper.countUserShares(uid); - userInfoAdmin.setCountUserShares(countUserShares); - - // 缁熻娴忚瓒宠抗 - long countScanHistory = scanHistoryMapper.countUserScanHistory(uid); - userInfoAdmin.setCountScanHistory(countScanHistory); - - // 涓�搴﹂槦鍛樻暟閲� - int firstTeamCount = shareMapper.myFirstTeamCount(uid +""); - userInfoAdmin.setCountLevelOne(firstTeamCount); - - // 浜屽害闃熷憳鏁伴噺 - int secondTeamCount = shareMapper.mySecondTeamCount(uid +""); - userInfoAdmin.setCountLevelTwo(secondTeamCount); - adminList.add(userInfoAdmin); + for (UserInfoVO userInfoVO : userList) { + // 鏁版嵁鍔犲伐澶勭悊 + convertUserInfoVOData(userInfoVO); } - return adminList; - + return userList; } - @Override - public long queryCount(String key, Integer userType, Integer days, String startTime, String endTime) { - return userInfoMapper.queryCount(key, userType, days, startTime, endTime); + public void convertUserInfoVOData(UserInfoVO userInfoVO) { + + String rankName = userInfoVO.getRankName(); + if (rankName == null || rankName.trim().length() == 0) { + userInfoVO.setRankName("闈掗摐"); + userInfoVO.setRankPicture("http://img.flqapp.com/resource/rank/rank_picture_new_1.png"); + } + + String f_alipayAccount = userInfoVO.getAlipayAccountInvalid(); + if (f_alipayAccount != null && f_alipayAccount.trim().length() > 0) { + userInfoVO.setAlipayAccountState(1); + } + + String f_phone = userInfoVO.getPhoneInvalid(); + if (f_phone != null && f_phone.trim().length() > 0) { + userInfoVO.setPhoneState(1); + } + + String f_taobaoUid = userInfoVO.getTaobaoUidInvalid(); + if (f_taobaoUid != null && f_taobaoUid.trim().length() > 0) { + userInfoVO.setTaobaoUidState(1); + } + + String f_wxUnionId = userInfoVO.getWxUnionIdInvalid(); + if (f_wxUnionId != null && f_wxUnionId.trim().length() > 0) { + userInfoVO.setWxUnionIdState(1); + } + + // 鏈�杩戠櫥褰曟椂闂� + Long lastLoginTime = userInfoVO.getLastLoginTime(); + if (lastLoginTime != null && lastLoginTime == 0) { + 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); } + */ + + Long uid = userInfoVO.getId(); + + /* 缁戝畾鏀舵璐﹀彿淇℃伅 */ + List<BindingAccount> account = bindingAccountMapper.selectByUid(uid); + if (account != null && account.size() > 0) { + BindingAccount bindingAccount = account.get(0); + Integer type = bindingAccount.getType(); + if (type != null && type == 1) { + // 鏀粯瀹� + userInfoVO.setAccountAlipay(bindingAccount.getAccount()); + userInfoVO.setAccountName(bindingAccount.getName()); + userInfoVO.setAccountBindId(bindingAccount.getId()); + + } else if (type != null && type == 2) { + // 寰俊 + userInfoVO.setAccountWX(bindingAccount.getAccount()); + userInfoVO.setAccountNameWX(bindingAccount.getName()); + userInfoVO.setAccountBindIdWX(bindingAccount.getId()); + } + } + + // 鏈�杩戜竴娆′笅鍗曟椂闂� + Date lastOrderTime = hongBaoV2CountService.getLastHongBaoTime(uid); + if (lastOrderTime != null && lastOrderTime.getTime() != 0) { + userInfoVO.setLastOrderTime(lastOrderTime.getTime()); + } + + // 浠婃棩鎬昏鍗� + long todayOrder = hongBaoV2CountService.countValidNumberByUid(uid, 1); + userInfoVO.setTodayOrder(todayOrder); + + // 鏈鍙栫孩鍖� 寰呭叆璐﹂噾棰� + BigDecimal unaccountedMoney = hongBaoV2CountService.countWillGetMoneyByUid(uid); + if (unaccountedMoney == null) { + unaccountedMoney = new BigDecimal(0); + } + userInfoVO.setUnaccountedMoney(unaccountedMoney.toString()); + + // 鍘嗗彶鎬绘敹鐩� + BigDecimal totalMoneyHistory = hongBaoV2CountService.countMoneyByUidAndState(uid, 3); + if (totalMoneyHistory == null) { + totalMoneyHistory = new BigDecimal(0); + } + userInfoVO.setTotalMoneyHistory(totalMoneyHistory.toString()); + + // 鏀粯瀹濊处鍙� 绱杞处鎬婚噾棰� + double totalMoney = payInfoMapper.sumMoneyByUid(uid); + userInfoVO.setTotalMoney(totalMoney); + + // 绱鎻愮幇 (鏆傛湭璁″叆寰俊) + userInfoVO.setTotalExtract(totalMoney); + + // 缁熻鍒嗕韩涓暟 + long countUserShares = userShareGoodsHistoryMapper.countUserShares(uid); + userInfoVO.setCountUserShares(countUserShares); + + // 缁熻娴忚瓒宠抗 + long countScanHistory = scanHistoryMapper.countUserScanHistory(uid); + userInfoVO.setCountScanHistory(countScanHistory); + + // 涓�搴﹂槦鍛樻暟閲� + int firstTeamCount = shareMapper.myFirstTeamCount(uid + ""); + userInfoVO.setCountLevelOne(firstTeamCount); + + // 浜屽害闃熷憳鏁伴噺 + int secondTeamCount = shareMapper.mySecondTeamCount(uid + ""); + userInfoVO.setCountLevelTwo(secondTeamCount); } - + @Override public double querySumMoney(String key, Integer userType, Integer days, String startTime, String endTime) { return userInfoMapper.querySumMoney(key, userType, days, startTime, endTime); @@ -762,12 +813,12 @@ public UserInfo selectByPKey(Long id) { return userInfoMapper.selectByPKey(id); } - + @Override public int updateByPrimaryKeySelective(UserInfo record) { return userInfoMapper.updateByPrimaryKeySelective(record); } - + @Override @Transactional public void deleteBindInfo(UserInfo user, int type) { @@ -796,11 +847,151 @@ userInfoMapper.updateByPrimaryKeySelective(user); } - - + @Override - public List<Long> longTimeNoLogin(int daysNum, List<Long> list ) { + public List<Long> longTimeNoLogin(int daysNum, List<Long> list) { return userInfoMapper.longTimeNoLogin(daysNum, list); } + /** + * 鏍规嵁鐢佃瘽鍙风爜銆侀個璇风爜鑾峰彇閭�璇风敤鎴� + * + * @param phone + * @param inviteCode + * @return + */ + @Override + public UserInfo getInfoByPhoneOrInviteCode(String phone, String inviteCode) { + return userInfoMapper.getInfoByPhoneOrInviteCode(phone, inviteCode); + } + + @Override + public UserInfo getEffectiveUserInfoByPhone(String phone) { + return userInfoMapper.getEffectiveUserInfoByPhone(phone); + } + + @Override + public UserInfo getEffectiveUserInfoByWXUnionId(String unionId) { + return userInfoMapper.getEffectiveUserInfoByWXUnionId(unionId); + } + + @Override + public UserInfo getUserInfo(Long uid) throws UserInfoException { + if (uid == null) { + throw new UserInfoException(1, "璇锋眰鍙傛暟涓虹┖"); + } + + UserInfo userInfo = userInfoMapper.selectByPKey(uid); + if (userInfo == null) { + throw new UserInfoException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + if (userInfo.getState() == UserInfo.STATE_FORBIDDEN) { + throw new UserInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); + } + + if (userInfo.getState() != UserInfo.STATE_NORMAL) { + throw new UserInfoException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + // 娣樺疂鏄电О 缁勭粐 + boolean clearOpenid = true; + UserExtraTaoBaoInfo extraTaoBaoInfo = userExtraTaoBaoInfoService.getByUid(uid); + if (extraTaoBaoInfo != null) { + String specialId = extraTaoBaoInfo.getSpecialId(); + String relationId = extraTaoBaoInfo.getRelationId(); + String taoBaoNickName = extraTaoBaoInfo.getTaoBaoNickName(); + + if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) { + clearOpenid = false; + userInfo.setOpenid(extraTaoBaoInfo.getTaoBaoUid()); + + if (!StringUtil.isNullOrEmpty(taoBaoNickName)) { + userInfo.setTbName(taoBaoNickName); + } else { + String taoBaoUserNick = taoBaoUnionAuthRecordService.getTaoBaoUserNick(uid); + if (!StringUtil.isNullOrEmpty(taoBaoUserNick)) { + userInfo.setTbName(taoBaoUserNick); + } + } + } + } + + if (clearOpenid) { + userInfo.setOpenid(null); + } + + return userInfo; + } + + @Override + public BigDecimal getBalance(Long uid) { + UserInfo user = userInfoMapper.selectByPKey(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) { + throw new UserInfoException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + // 璋锋瓕鍘嬬缉鍥剧墖 + String targetPath = FileUtil.getCacheDir() + "/uploadPortrait_" + uid + "_" + System.currentTimeMillis() + + ".jpg"; + Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath); + + // 鎵ц涓婁紶 + String filePath = "/img/user/" + 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) && portrait.contains("/img/user/")) { + COSManager.getInstance().deleteFile(portrait); + } + + executor.execute(new Runnable() { + @Override + public void run() { + try { + // 鍒犻櫎鍒嗕韩澶村儚淇℃伅 + spreadUserImgService.deleteImgUrl(uid); + } catch (Exception e) { + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + }); + } + + @Override + public void saveUserInfo(String nickName, Long uid) throws UserInfoException { + UserInfo userInfo = userInfoMapper.selectByPKey(uid); + if (userInfo == null) { + throw new UserInfoException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + userInfo.setNickName(nickName); + userInfoMapper.updateByPrimaryKeySelective(userInfo); + } + } -- Gitblit v1.8.0