admin
2019-12-06 cd637932a970e7935b17d41568fe89c92775bccc
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -13,6 +13,7 @@
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.entity.FileUploadResult;
@@ -193,6 +194,7 @@
      userInfoExtra.setFirstLoginTime(new Date());
      userInfoExtra.setCreateTime(new Date());
      userInfoExtra.setUpdateTime(new Date());
      userInfoExtra.setActiveTime(new Date());
      userInfoExtraMapper.insertSelective(userInfoExtra);
   }
@@ -403,8 +405,7 @@
      }
      // 获取微信信息
      WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(),
            wxAccount.getAppSecret());
      WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
      if (weiXinUser == null) {
         throw new UserInfoExtraException(1, "微信授权失败");
      }
@@ -445,14 +446,14 @@
            String headimgurl = weiXinUser.getHeadimgurl();
            InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl);
            if (asInputStream == null) {
               LogHelper.test("微信头像下载失败: " +weiXinUser.getUnionid()+ " " + headimgurl);
               LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl);
            } else {
               FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
                     String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
               FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(
                     "/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
               if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
                  headimgurl = result.getUrl();
               } else {
                  LogHelper.test("微信头像上传失败: " +weiXinUser.getUnionid()+ " " + headimgurl);
                  LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl);
               }
            }
            updateUserInfo.setPortrait(headimgurl);
@@ -517,7 +518,6 @@
      }
   }
   @Override
   public void activeInviteWX(Long uid, WeiXinUser weiXinUser) throws UserInfoExtraException {
      if (uid == null || weiXinUser == null) {
@@ -576,14 +576,14 @@
            String headimgurl = weiXinUser.getHeadimgurl();
            InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl);
            if (asInputStream == null) {
               LogHelper.test("微信头像下载失败: " +weiXinUser.getUnionid()+ " " + headimgurl);
               LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl);
            } else {
               FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
                     String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
               FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(
                     "/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
               if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
                  headimgurl = result.getUrl();
               } else {
                  LogHelper.test("微信头像上传失败: " +weiXinUser.getUnionid()+ " " + headimgurl);
                  LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl);
               }
            }
            updateUserInfo.setPortrait(headimgurl);
@@ -647,22 +647,35 @@
         userInfoExtraMapper.insertSelective(userInfoExtra);
      }
   }
   @Override
   public void updateActiveTime(Long uid, Date date) {
      UserInfoExtra userInfoExtra = new UserInfoExtra();
      userInfoExtra.setUserInfo(new UserInfo(uid));
      userInfoExtra.setActiveTime(date);
      userInfoExtraMapper.updateInfoExtraByUid(userInfoExtra);
   }
   @Override
   public UserInfoExtra getUserInfoExtra(Long uid) {
      return userInfoExtraMapper.getInfoExtraByUid(uid);
   }
   @Override
   public UserInfoExtra getUserALLInfo(Long uid) {
      return userInfoExtraMapper.gerUserRank(uid);
   }
   @Override
   public UserInfoExtra getByUidForUpdate(Long uid) {
      return userInfoExtraMapper.getByUidForUpdate(uid);
   }
   @Override
   public void updateGoldCoin(Long id, Integer goldCoin) {
      userInfoExtraMapper.updateGoldCoin(id, goldCoin);
   }
   @Override
   public UserInfoExtraVO getInfoExtraVOByUid(Long uid) {
      return userInfoExtraMapper.getInfoExtraVOByUid(uid);
@@ -797,5 +810,48 @@
      }
      return inviter;
   }
   @Override
   public void updateAutoExtract(Integer days) {
      userInfoExtraMapper.updateAutoExtract(days);
   }
   @Transactional
   @Override
   public void updateInviteCode(String inviteCode, Long uid) throws UserInfoExtraException {
      if (inviteCode.length() >= 6 && inviteCode.length() <= 12) {
         UserInfoExtra extra = getUserInfoExtra(uid);
         if (extra == null) {
            throw new UserInfoExtraException(2, "用户信息不存在");
         }
         if (StringUtil.isNullOrEmpty(extra.getInviteCode())) {
            throw new UserInfoExtraException(3, "邀请码尚未激活");
         }
         if (extra.getInviteCodeState() == null
               || extra.getInviteCodeState() != UserInfoExtra.INVITE_CODE_SATTE_VALID_NO_UPDATE) {
            throw new UserInfoExtraException(4, "只能修改一次");
         }
         if (inviteCode.equalsIgnoreCase(extra.getInviteCode())) {
            throw new UserInfoExtraException(5, "不能为原邀请码");
         }
         UserInfoExtra update = new UserInfoExtra();
         update.setId(extra.getId());
         extra = userInfoExtraMapper.selectByInviteCode(inviteCode);
         if (extra != null) {
            throw new UserInfoExtraException(6, "邀请码已存在");
         }
         update.setInviteCode(inviteCode);
         update.setInviteCodeState(UserInfoExtra.INVITE_CODE_SATTE_VALID_UPDATED);
         update.setUpdateTime(new Date());
         userInfoExtraMapper.updateByPrimaryKeySelective(update);
      } else {
         throw new UserInfoExtraException(1, "邀请码必须为6到12位");
      }
   }
}