admin
2019-07-30 573c491b4a1ba60e12a5678a01c1546c0077c1ee
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserExtraTaoBaoInfoServiceImpl.java
@@ -4,17 +4,19 @@
import java.util.List;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.user.UserExtraTaoBaoInfoMapper;
import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode;
import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserAccountBindingHistory;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.exception.user.UserExtraTaoBaoInfoException;
import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
import com.yeshi.fanli.service.inter.user.UserAccountBindingHistoryService;
import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -24,25 +26,27 @@
   @Resource
   private UserExtraTaoBaoInfoMapper userExtraTaoBaoInfoMapper;
   @Resource
   private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
   @Resource
   private UserAccountBindingHistoryService userAccountBindingHistoryService;
   @Transactional
   @Override
   public void addRelationId(Long uid, String relationId, String taoBaoUid,String nickName,
         boolean valid) throws UserExtraTaoBaoInfoException{
   public void addRelationId(Long uid, String relationId, String taoBaoUid, String nickName, boolean valid)
         throws UserExtraTaoBaoInfoException {
      if (uid == null || StringUtil.isNullOrEmpty(relationId) || StringUtil.isNullOrEmpty(taoBaoUid)) {
         throw new UserExtraTaoBaoInfoException(1, "传递参数为空");
      }
      // 验证taoBaoUid是否被封禁
      if(validateTaoBaoUidForbidden(taoBaoUid)) {
      if (validateTaoBaoUidForbidden(taoBaoUid)) {
         throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
      }
      UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo();
      taoBaoInfo.setUser(new UserInfo(uid));
      taoBaoInfo.setTaoBaoNickName(nickName);
@@ -50,10 +54,12 @@
      taoBaoInfo.setRelationId(relationId);
      taoBaoInfo.setRelationValid(valid);
      taoBaoInfo.setRelationUpdateTime(new Date());
      userExtraTaoBaoInfoMapper.clearUid(uid);
      List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid);
      if (list == null || list.size() == 0) {
         //新增
         // 新增
         taoBaoInfo.setCreateTime(new Date());
         userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo);
      } else {
@@ -61,30 +67,30 @@
         taoBaoInfo.setId(list.get(0).getId());
         taoBaoInfo.setUpdateTime(new Date());
         userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(taoBaoInfo);
         // 清空多余已绑定数据
         if (list.size() > 1) {
            for (int i = 1; i < list.size(); i++) {
               clearTaoBaoInfo(list.get(i));
            }
         }
         // // 清空多余已绑定数据
         // if (list.size() > 1) {
         // for (int i = 1; i < list.size(); i++) {
         // clearTaoBaoInfo(list.get(i));
         // }
         // }
      }
   }
   @Transactional
   @Override
   public void addSpecialId(Long uid, String specialId, String taoBaoUid, String nickName,
         boolean valid) throws UserExtraTaoBaoInfoException{
   public void addSpecialId(Long uid, String specialId, String taoBaoUid, String nickName, boolean valid)
         throws UserExtraTaoBaoInfoException {
      if (uid == null || StringUtil.isNullOrEmpty(specialId) || StringUtil.isNullOrEmpty(taoBaoUid)) {
         throw new UserExtraTaoBaoInfoException(1, "传递参数为空");
      }
      // 验证taoBaoUid是否被封禁
      if(validateTaoBaoUidForbidden(taoBaoUid)) {
      if (validateTaoBaoUidForbidden(taoBaoUid)) {
         throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
      }
      UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo();
      taoBaoInfo.setUser(new UserInfo(uid));
      taoBaoInfo.setTaoBaoNickName(nickName);
@@ -92,10 +98,12 @@
      taoBaoInfo.setSpecialValid(valid);
      taoBaoInfo.setSpecialId(specialId);
      taoBaoInfo.setSpecialUpdateTime(new Date());
      userExtraTaoBaoInfoMapper.clearUid(uid);
      List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid);
      if (list == null || list.size() == 0) {
         //新增
         // 新增
         taoBaoInfo.setCreateTime(new Date());
         userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo);
      } else {
@@ -103,7 +111,7 @@
         taoBaoInfo.setId(list.get(0).getId());
         taoBaoInfo.setUpdateTime(new Date());
         userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(taoBaoInfo);
         // 清空多余已绑定数据
         if (list.size() > 1) {
            for (int i = 1; i < list.size(); i++) {
@@ -115,19 +123,19 @@
   @Transactional
   @Override
   public void saveUserTaoBaoInfo(Long uid, String relationId, String specialId, String taoBaoUid,
         String nickName, boolean valid) throws UserExtraTaoBaoInfoException {
   public void saveUserTaoBaoInfo(Long uid, String relationId, String specialId, String taoBaoUid, String nickName,
         boolean valid) throws UserExtraTaoBaoInfoException {
      if (uid == null || StringUtil.isNullOrEmpty(relationId) || StringUtil.isNullOrEmpty(specialId)
            || StringUtil.isNullOrEmpty(taoBaoUid)) {
         throw new UserExtraTaoBaoInfoException(1, "传递参数部分为空");
      }
      // 验证taoBaoUid是否被封禁
      if(validateTaoBaoUidForbidden(taoBaoUid)) {
      if (validateTaoBaoUidForbidden(taoBaoUid)) {
         throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
      }
      UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo();
      taoBaoInfo.setTaoBaoUid(taoBaoUid);
      taoBaoInfo.setTaoBaoNickName(nickName);
@@ -142,8 +150,15 @@
      taoBaoInfo.setSpecialUpdateTime(new Date());
      List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid);
      // 判断之前用户是否绑定过
      UserExtraTaoBaoInfo info = userExtraTaoBaoInfoMapper.selectByUid(uid);
      // 清除之前的用户ID
      userExtraTaoBaoInfoMapper.clearUid(uid);
      if (list == null || list.size() == 0) {
         //新增
         // 新增
         taoBaoInfo.setCreateTime(new Date());
         userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo);
      } else {
@@ -151,7 +166,7 @@
         taoBaoInfo.setId(list.get(0).getId());
         taoBaoInfo.setUpdateTime(new Date());
         userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(taoBaoInfo);
         // 清空多余已绑定数据
         if (list.size() > 1) {
            for (int i = 1; i < list.size(); i++) {
@@ -159,43 +174,58 @@
            }
         }
      }
      // 加入绑定记录
      UserAccountBindingHistory history = new UserAccountBindingHistory();
      history.setContent(taoBaoUid);
      history.setType(UserAccountBindingHistory.TYPE_TB);
      history.setUid(uid);
      // 之前已经绑定电话号码
      if (info != null)
         history.setFirst(false);
      else
         history.setFirst(true);
      userAccountBindingHistoryService.addUserAccountBindingHistory(history);
   }
   /**
    * 验证taoBaoUid  是否被封
    * 验证taoBaoUid 是否被封
    *
    * @param taoBaoUid
    * @return
    */
   public boolean validateTaoBaoUidForbidden(String taoBaoUid) {
      boolean validate = false;
      ForbiddenUserIdentifyCode identifyCode = forbiddenUserIdentifyCodeService.listByTypeAndIdentifyCode(
            ForbiddenUserIdentifyCodeTypeEnum.taobaoUid, taoBaoUid);
      ForbiddenUserIdentifyCode identifyCode = forbiddenUserIdentifyCodeService
            .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.taobaoUid, taoBaoUid);
      // 账号被封
      if (identifyCode != null && identifyCode.getEffective() != null && identifyCode.getEffective()) {
         validate = true;
      }
      return validate;
   }
   /**
    * 清空多余绑定淘宝账号信息
    *
    * @param otherInfo
    */
   public void clearTaoBaoInfo(UserExtraTaoBaoInfo otherInfo ) {
   public void clearTaoBaoInfo(UserExtraTaoBaoInfo otherInfo) {
      otherInfo.setUser(null);
      otherInfo.setTaoBaoUid(null);
      otherInfo.setTaoBaoNickName(null);
      otherInfo.setRelationValid(null);
      otherInfo.setRelationId(null);
      otherInfo.setRelationUpdateTime(null);
      otherInfo.setSpecialValid(null);
      otherInfo.setSpecialId(null);
      otherInfo.setSpecialUpdateTime(new Date());
      userExtraTaoBaoInfoMapper.updateByPrimaryKey(otherInfo);
   }
   @Override
   public UserExtraTaoBaoInfo getByUid(Long uid) {
      return userExtraTaoBaoInfoMapper.selectByUid(uid);
@@ -242,4 +272,14 @@
      return userExtraTaoBaoInfoMapper.selectBySpecialIdWithUidNotNull(specialId);
   }
   @Override
   public String getRelationIdByUid(Long uid) {
      UserExtraTaoBaoInfo extraInfo = getByUid(uid);
      String relationId = null;
      if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
            && extraInfo.getRelationValid() == true)
         relationId = extraInfo.getRelationId();
      return relationId;
   }
}