From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/tb/UserExtraTaoBaoInfoServiceImpl.java | 687 +++++++++++++++++++++++++++++--------------------------- 1 files changed, 353 insertions(+), 334 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/tb/UserExtraTaoBaoInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/tb/UserExtraTaoBaoInfoServiceImpl.java index b9de108..dabeeb5 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/tb/UserExtraTaoBaoInfoServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/tb/UserExtraTaoBaoInfoServiceImpl.java @@ -1,334 +1,353 @@ -package com.yeshi.fanli.service.impl.user.tb; - -import java.util.Date; -import java.util.List; - -import javax.annotation.Resource; - -import com.yeshi.fanli.entity.SystemEnum; -import com.yeshi.fanli.service.inter.user.UserInfoService; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.aliyun.openservices.ons.api.Message; -import com.aliyun.openservices.ons.api.Producer; -import com.yeshi.fanli.dao.mybatis.user.UserExtraTaoBaoInfoMapper; -import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; -import com.yeshi.fanli.dto.mq.user.body.TaoBaoBindSuccessMQMsg; -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.tb.UserExtraTaoBaoInfoService; -import com.yeshi.fanli.service.manger.msg.RocketMQManager; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; -import com.yeshi.fanli.util.rocketmq.MQTopicName; - -@Service -public class UserExtraTaoBaoInfoServiceImpl implements UserExtraTaoBaoInfoService { - - @Resource - private UserExtraTaoBaoInfoMapper userExtraTaoBaoInfoMapper; - - @Resource - private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; - - @Resource - private UserAccountBindingHistoryService userAccountBindingHistoryService; - - @Resource - private RocketMQManager rocketMQManager; - - @Resource - private UserInfoService userInfoService; - - @Transactional(rollbackFor = Exception.class) - @Override - 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)) { - throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); - } - - //娓呴櫎璇ョ敤鎴风殑鎺堟潈淇℃伅 -// userExtraTaoBaoInfoMapper.clearUid(uid); - SystemEnum system = userInfoService.getUserSystem(uid); - List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid,system); - UserExtraTaoBaoInfo existInfo = null; - if (list != null) - for (UserExtraTaoBaoInfo tb : list) { - SystemEnum se = userInfoService.getUserSystem(tb.getUser().getId()); - if (se == system) { - existInfo = tb; - break; - } - } - UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo(); - taoBaoInfo.setUser(new UserInfo(uid)); - taoBaoInfo.setTaoBaoNickName(nickName); - taoBaoInfo.setTaoBaoUid(taoBaoUid); - taoBaoInfo.setRelationId(relationId); - taoBaoInfo.setRelationValid(valid); - taoBaoInfo.setRelationUpdateTime(new Date()); - - - if (existInfo==null) { - // 鏂板 - taoBaoInfo.setCreateTime(new Date()); - userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo); - } else { - // 鍙栫涓�涓浛鎹id 绛変俊鎭� - taoBaoInfo.setId(existInfo.getId()); - taoBaoInfo.setUpdateTime(new Date()); - userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(taoBaoInfo); - - // // 娓呯┖澶氫綑宸茬粦瀹氭暟鎹� - // if (list.size() > 1) { - // for (int i = 1; i < list.size(); i++) { - // clearTaoBaoInfo(list.get(i)); - // } - // } - } - } - - @Transactional(rollbackFor = Exception.class) - @Override - 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)) { - throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); - } - -// userExtraTaoBaoInfoMapper.clearUid(uid); - SystemEnum system = userInfoService.getUserSystem(uid); - - UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo(); - taoBaoInfo.setUser(new UserInfo(uid)); - taoBaoInfo.setTaoBaoNickName(nickName); - taoBaoInfo.setTaoBaoUid(taoBaoUid); - taoBaoInfo.setSpecialValid(valid); - taoBaoInfo.setSpecialId(specialId); - taoBaoInfo.setSpecialUpdateTime(new Date()); - - userExtraTaoBaoInfoMapper.clearUid(uid); - - List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid,system); - if (list == null || list.size() == 0) { - // 鏂板 - taoBaoInfo.setCreateTime(new Date()); - userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo); - } else { - // 鍙栫涓�涓浛鎹id 绛変俊鎭� - 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)); - } - } - } - } - - @Transactional(rollbackFor = Exception.class) - @Override - 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)) { - throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); - } - - SystemEnum system=userInfoService.getUserSystem(uid); - - UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo(); - taoBaoInfo.setTaoBaoUid(taoBaoUid); - taoBaoInfo.setTaoBaoNickName(nickName); - taoBaoInfo.setUser(new UserInfo(uid)); - // 娓犻亾 - taoBaoInfo.setRelationValid(valid); - taoBaoInfo.setRelationId(relationId); - taoBaoInfo.setRelationUpdateTime(new Date()); - // 缁戝畾 - taoBaoInfo.setSpecialValid(valid); - taoBaoInfo.setSpecialId(specialId); - taoBaoInfo.setSpecialUpdateTime(new Date()); - - List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid,system); - - // 鍒ゆ柇涔嬪墠鐢ㄦ埛鏄惁缁戝畾杩� - UserExtraTaoBaoInfo info = userExtraTaoBaoInfoMapper.selectByUid(uid); - - // 娓呴櫎涔嬪墠鐨勭敤鎴稩D - userExtraTaoBaoInfoMapper.clearUid(uid); - Long fromUid = null; - - if (list == null || list.size() == 0) { - // 鏂板 - taoBaoInfo.setCreateTime(new Date()); - userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo); - } else { - if (list.get(0).getUser() != null) - fromUid = list.get(0).getUser().getId(); - // 鍙栫涓�涓浛鎹id 绛変俊鎭� - 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)); - } - } - } - - // 鍔犲叆缁戝畾璁板綍 - 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); - - Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.taobaoBindSuccess, - new TaoBaoBindSuccessMQMsg(uid, fromUid, taoBaoUid, new Date())); - - rocketMQManager.sendNormalMsg(message, null); - } - - /** - * 楠岃瘉taoBaoUid 鏄惁琚皝 - * - * @param taoBaoUid - * @return - */ - public boolean validateTaoBaoUidForbidden(String taoBaoUid) { - boolean validate = false; - 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) { - 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); - } - - @Override - public void updateSelective(UserExtraTaoBaoInfo ue) { - if (ue == null || ue.getId() == null) - return; - userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(ue); - } - - @Override - public void unBindUid(Long uid) { - userExtraTaoBaoInfoMapper.clearUid(uid); - } - - @Override - public void bindTaoBaoOrderEnd6Num(String taoBaoUid, String orderId) { - if (taoBaoUid == null || StringUtil.isNullOrEmpty(orderId)) - return; - UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoMapper.selectByTaoBaoUid(taoBaoUid,null); - if (extraInfo != null) { - UserExtraTaoBaoInfo update = new UserExtraTaoBaoInfo(); - update.setId(extraInfo.getId()); - update.setTaoBaoOrderEnd6Num(orderId); - update.setUpdateTime(new Date()); - userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(update); - } - - } - - @Override - public UserExtraTaoBaoInfo getByRelationId(String relationId,SystemEnum system) { - if (StringUtil.isNullOrEmpty(relationId)) - return null; - return userExtraTaoBaoInfoMapper.selectByRelationIdWithUidNotNull(relationId,system); - } - - @Override - public UserExtraTaoBaoInfo getBySpecialId(String specialId,SystemEnum system) { - if (StringUtil.isNullOrEmpty(specialId)) - return null; - return userExtraTaoBaoInfoMapper.selectBySpecialIdWithUidNotNull(specialId,system); - } - - @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; - } - - @Override - public String getSpecialIdByUid(Long uid) { - UserExtraTaoBaoInfo extraInfo = getByUid(uid); - String specialId = null; - if (extraInfo != null && extraInfo.getSpecialId() != null && extraInfo.getSpecialValid() != null - && extraInfo.getSpecialValid() == true) - specialId = extraInfo.getSpecialId(); - return specialId; - } - -} +package com.yeshi.fanli.service.impl.user.tb; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.service.inter.user.UserInfoService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.aliyun.openservices.ons.api.Message; +import com.aliyun.openservices.ons.api.Producer; +import com.yeshi.fanli.dao.mybatis.user.UserExtraTaoBaoInfoMapper; +import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; +import com.yeshi.fanli.dto.mq.user.body.TaoBaoBindSuccessMQMsg; +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.tb.UserExtraTaoBaoInfoService; +import com.yeshi.fanli.service.manger.msg.RocketMQManager; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; +import com.yeshi.fanli.util.rocketmq.MQTopicName; + +@Service +public class UserExtraTaoBaoInfoServiceImpl implements UserExtraTaoBaoInfoService { + + @Resource + private UserExtraTaoBaoInfoMapper userExtraTaoBaoInfoMapper; + + @Resource + private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; + + @Resource + private UserAccountBindingHistoryService userAccountBindingHistoryService; + + @Resource + private RocketMQManager rocketMQManager; + + @Resource + private UserInfoService userInfoService; + + @Transactional(rollbackFor = Exception.class) + @Override + 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)) { + throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); + } + + //娓呴櫎璇ョ敤鎴风殑鎺堟潈淇℃伅 +// userExtraTaoBaoInfoMapper.clearUid(uid); + SystemEnum system = userInfoService.getUserSystem(uid); + List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid, system); + UserExtraTaoBaoInfo existInfo = null; + if (list != null) + for (UserExtraTaoBaoInfo tb : list) { + SystemEnum se = userInfoService.getUserSystem(tb.getUser().getId()); + if (se == system) { + existInfo = tb; + break; + } + } + UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo(); + taoBaoInfo.setUser(new UserInfo(uid)); + taoBaoInfo.setTaoBaoNickName(nickName); + taoBaoInfo.setTaoBaoUid(taoBaoUid); + taoBaoInfo.setRelationId(relationId); + taoBaoInfo.setRelationValid(valid); + taoBaoInfo.setRelationUpdateTime(new Date()); + + + if (existInfo == null) { + // 鏂板 + taoBaoInfo.setCreateTime(new Date()); + userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo); + } else { + // 鍙栫涓�涓浛鎹id 绛変俊鎭� + taoBaoInfo.setId(existInfo.getId()); + taoBaoInfo.setUpdateTime(new Date()); + userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(taoBaoInfo); + + // // 娓呯┖澶氫綑宸茬粦瀹氭暟鎹� + // if (list.size() > 1) { + // for (int i = 1; i < list.size(); i++) { + // clearTaoBaoInfo(list.get(i)); + // } + // } + } + } + + @Transactional(rollbackFor = Exception.class) + @Override + 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)) { + throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); + } + +// userExtraTaoBaoInfoMapper.clearUid(uid); + SystemEnum system = userInfoService.getUserSystem(uid); + + UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo(); + taoBaoInfo.setUser(new UserInfo(uid)); + taoBaoInfo.setTaoBaoNickName(nickName); + taoBaoInfo.setTaoBaoUid(taoBaoUid); + taoBaoInfo.setSpecialValid(valid); + taoBaoInfo.setSpecialId(specialId); + taoBaoInfo.setSpecialUpdateTime(new Date()); + + userExtraTaoBaoInfoMapper.clearUid(uid); + + List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid, system); + if (list == null || list.size() == 0) { + // 鏂板 + taoBaoInfo.setCreateTime(new Date()); + userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo); + } else { + // 鍙栫涓�涓浛鎹id 绛変俊鎭� + 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)); + } + } + } + } + + @Transactional(rollbackFor = Exception.class) + @Override + 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)) { + throw new UserExtraTaoBaoInfoException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); + } + + SystemEnum system = userInfoService.getUserSystem(uid); + + UserExtraTaoBaoInfo taoBaoInfo = new UserExtraTaoBaoInfo(); + taoBaoInfo.setTaoBaoUid(taoBaoUid); + taoBaoInfo.setTaoBaoNickName(nickName); + taoBaoInfo.setUser(new UserInfo(uid)); + // 娓犻亾 + taoBaoInfo.setRelationValid(valid); + taoBaoInfo.setRelationId(relationId); + taoBaoInfo.setRelationUpdateTime(new Date()); + // 缁戝畾 + taoBaoInfo.setSpecialValid(valid); + taoBaoInfo.setSpecialId(specialId); + taoBaoInfo.setSpecialUpdateTime(new Date()); + + List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.listByTaoBaoUid(taoBaoUid, system); + + // 鍒ゆ柇涔嬪墠鐢ㄦ埛鏄惁缁戝畾杩� + UserExtraTaoBaoInfo info = userExtraTaoBaoInfoMapper.selectByUid(uid); + + // 娓呴櫎涔嬪墠鐨勭敤鎴稩D + userExtraTaoBaoInfoMapper.clearUid(uid); + Long fromUid = null; + + if (list == null || list.size() == 0) { + // 鏂板 + taoBaoInfo.setCreateTime(new Date()); + userExtraTaoBaoInfoMapper.insertSelective(taoBaoInfo); + } else { + if (list.get(0).getUser() != null) + fromUid = list.get(0).getUser().getId(); + // 鍙栫涓�涓浛鎹id 绛変俊鎭� + 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)); + } + } + } + + // 鍔犲叆缁戝畾璁板綍 + 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); + + Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.taobaoBindSuccess, + new TaoBaoBindSuccessMQMsg(uid, fromUid, taoBaoUid, new Date())); + + rocketMQManager.sendNormalMsg(message, null); + } + + /** + * 楠岃瘉taoBaoUid 鏄惁琚皝 + * + * @param taoBaoUid + * @return + */ + public boolean validateTaoBaoUidForbidden(String taoBaoUid) { + boolean validate = false; + 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) { + 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); + } + + @Override + public void updateSelective(UserExtraTaoBaoInfo ue) { + if (ue == null || ue.getId() == null) + return; + userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(ue); + } + + @Override + public void unBindUid(Long uid) { + userExtraTaoBaoInfoMapper.clearUid(uid); + } + + @Override + public void bindTaoBaoOrderEnd6Num(String taoBaoUid, String orderId) { + if (taoBaoUid == null || StringUtil.isNullOrEmpty(orderId)) + return; + UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoMapper.selectByTaoBaoUid(taoBaoUid, null); + if (extraInfo != null) { + UserExtraTaoBaoInfo update = new UserExtraTaoBaoInfo(); + update.setId(extraInfo.getId()); + update.setTaoBaoOrderEnd6Num(orderId); + update.setUpdateTime(new Date()); + userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(update); + } + + } + + @Override + public UserExtraTaoBaoInfo getByRelationId(String relationId, List<SystemEnum> systemList) { + if (StringUtil.isNullOrEmpty(relationId)) + return null; + return userExtraTaoBaoInfoMapper.selectByRelationIdWithUidNotNull(relationId, systemList); + } + + @Override + public UserExtraTaoBaoInfo getBySpecialId(String specialId, List<SystemEnum> systemList) { + if (StringUtil.isNullOrEmpty(specialId)) + return null; + List<UserExtraTaoBaoInfo> list = userExtraTaoBaoInfoMapper.selectBySpecialIdWithUidNotNull(specialId, systemList); + if (list == null || list.size() == 0) { + return null; + } + if (list.size() == 1) { + return list.get(0); + } + //澶氫釜绯荤粺閲囩敤缁熶竴PID鐨勬儏鍐� + //uid杈冨皬鐨勫湪鍓� + Comparator<UserExtraTaoBaoInfo> comparator = new Comparator<UserExtraTaoBaoInfo>() { + @Override + public int compare(UserExtraTaoBaoInfo o1, UserExtraTaoBaoInfo o2) { + //uid浠庡皬鍒板ぇ鎺掑垪 + return (int) (o1.getUser().getId().longValue() - o2.getUser().getId().longValue()); + } + }; + Collections.sort(list, comparator); + return list.get(0); + } + + @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; + } + + @Override + public String getSpecialIdByUid(Long uid) { + UserExtraTaoBaoInfo extraInfo = getByUid(uid); + String specialId = null; + if (extraInfo != null && extraInfo.getSpecialId() != null && extraInfo.getSpecialValid() != null + && extraInfo.getSpecialValid() == true) + specialId = extraInfo.getSpecialId(); + return specialId; + } + +} -- Gitblit v1.8.0