| | |
| | | package com.yeshi.fanli.service.impl.taobao;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoBuyRelationMapMapper;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoBuyRelationMap;
|
| | | import com.yeshi.fanli.exception.taobao.TaoBaoBuyRelationMapException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | | public class TaoBaoBuyRelationMapServiceImpl implements TaoBaoBuyRelationMapService {
|
| | |
|
| | | @Resource
|
| | | private TaoBaoBuyRelationMapMapper taoBaoBuyRelationMapMapper;
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public String getRelationId(Long uid) throws TaoBaoBuyRelationMapException {
|
| | | TaoBaoBuyRelationMap relationMap = taoBaoBuyRelationMapMapper.selectByUid(uid);
|
| | | if (relationMap != null)
|
| | | return relationMap.getRelationId();
|
| | |
|
| | | String relationId = null;
|
| | |
|
| | | // 总共尝试3次分配
|
| | |
|
| | | for (int i = 0; i < 3; i++) {
|
| | | if (!StringUtil.isNullOrEmpty(relationId))
|
| | | break;
|
| | | try {
|
| | | List<String> list = taoBaoBuyRelationMapMapper.listValidRelaionId(uid, 1);
|
| | | if (list == null || list.size() == 0)
|
| | | throw new TaoBaoBuyRelationMapException(1, "渠道ID库存不足");
|
| | | TaoBaoBuyRelationMap map = new TaoBaoBuyRelationMap();
|
| | | map.setCreateTime(new Date());
|
| | | map.setRelationId(list.get(0));
|
| | | map.setUid(uid);
|
| | | taoBaoBuyRelationMapMapper.insertSelective(map);
|
| | | relationId = map.getRelationId();
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(relationId))
|
| | | throw new TaoBaoBuyRelationMapException(2, "渠道ID分配失败");
|
| | | return relationId;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Long selectUidByRelationId(String relationId) {
|
| | | TaoBaoBuyRelationMap map = taoBaoBuyRelationMapMapper.selectByRelationId(relationId);
|
| | | if (map != null)
|
| | | return map.getUid();
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.taobao; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoBuyRelationMapMapper; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoBuyRelationMap; |
| | | import com.yeshi.fanli.exception.taobao.TaoBaoBuyRelationMapException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | @Service |
| | | public class TaoBaoBuyRelationMapServiceImpl implements TaoBaoBuyRelationMapService { |
| | | |
| | | @Resource |
| | | private TaoBaoBuyRelationMapMapper taoBaoBuyRelationMapMapper; |
| | | |
| | | @Transactional(rollbackFor=Exception.class) |
| | | @Override |
| | | public String getRelationId(Long uid) throws TaoBaoBuyRelationMapException { |
| | | TaoBaoBuyRelationMap relationMap = taoBaoBuyRelationMapMapper.selectByUid(uid); |
| | | if (relationMap != null) |
| | | return relationMap.getRelationId(); |
| | | |
| | | String relationId = null; |
| | | |
| | | // 总共尝试3次分配 |
| | | |
| | | for (int i = 0; i < 3; i++) { |
| | | if (!StringUtil.isNullOrEmpty(relationId)) |
| | | break; |
| | | try { |
| | | List<String> list = taoBaoBuyRelationMapMapper.listValidRelaionId(uid, 1); |
| | | if (list == null || list.size() == 0) |
| | | throw new TaoBaoBuyRelationMapException(1, "渠道ID库存不足"); |
| | | TaoBaoBuyRelationMap map = new TaoBaoBuyRelationMap(); |
| | | map.setCreateTime(new Date()); |
| | | map.setRelationId(list.get(0)); |
| | | map.setUid(uid); |
| | | taoBaoBuyRelationMapMapper.insertSelective(map); |
| | | relationId = map.getRelationId(); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(relationId)) |
| | | throw new TaoBaoBuyRelationMapException(2, "渠道ID分配失败"); |
| | | return relationId; |
| | | } |
| | | |
| | | @Override |
| | | public Long selectUidByRelationId(String relationId) { |
| | | TaoBaoBuyRelationMap map = taoBaoBuyRelationMapMapper.selectByRelationId(relationId); |
| | | if (map != null) |
| | | return map.getUid(); |
| | | return null; |
| | | } |
| | | |
| | | } |