Commit 141b898f by guanchen

只在userService中保留找上级的方法

parent b6605338
......@@ -7,6 +7,7 @@ import com.lanren.huhu.partner.model.AgentRewardMessage;
import com.lanren.huhu.partner.model.ParentAgent;
import com.lanren.huhu.partner.result.Result;
import com.lanren.huhu.partner.service.UserAgentService;
import com.lanren.huhu.partner.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -31,6 +32,8 @@ public class AgentManager {
UserAgentService userAgentService;
@Autowired
StringRedisTemplate redisTemplate;
@Autowired
UserService userService;
/***
* * 获取代理商等级 1 总代, 2 大区, 3 省, 4 市
......@@ -82,7 +85,8 @@ public class AgentManager {
* @date 2019-07-04 14:48
*/
public Result<ArrayList<ParentAgent>> getHierarchyParentList(Integer agentId) {
ArrayList<ParentAgent> parentAgents = (ArrayList<ParentAgent>) userAgentService.getParentAgentListByAgentId(agentId, PARENT_COLUMN_NAME_CENGJI);
UserAgent userAgent = userAgentService.getOneByAgentId(agentId);
ArrayList<ParentAgent> parentAgents = (ArrayList<ParentAgent>) userService.getAgentListByUserId(userAgent.getUserId(), PARENT_COLUMN_NAME_CENGJI);
Result<ArrayList<ParentAgent>> result = new Result<ArrayList<ParentAgent>>();
result.setData(parentAgents);
return result;
......@@ -93,7 +97,8 @@ public class AgentManager {
* @date 2019-07-04 14:48
*/
public Result<ArrayList<ParentAgent>> getPingtuiParentList(Integer agentId) {
ArrayList<ParentAgent> parentAgents = (ArrayList<ParentAgent>) userAgentService.getParentAgentListByAgentId(agentId, PARENT_COLUMN_NAME_PINGTUI);
UserAgent userAgent = userAgentService.getOneByAgentId(agentId);
ArrayList<ParentAgent> parentAgents = (ArrayList<ParentAgent>) userService.getAgentListByUserId(userAgent.getUserId(), PARENT_COLUMN_NAME_PINGTUI);
Result<ArrayList<ParentAgent>> result = new Result<ArrayList<ParentAgent>>();
result.setData(parentAgents);
return result;
......
......@@ -120,7 +120,7 @@ public class AgentRewardQueueTask {
* 这里的逻辑有问题, 不能用这个接口找上级, 因为会先找一次直接邀请人,
* 只能按message.getAgentId()的代理商id, 找user_agent表里的平推关系
*/
ArrayList<ParentAgent> parentList = (ArrayList<ParentAgent>) userAgentService.getParentAgentListByAgentId(userAgent.getAgentId(), PARENT_COLUMN_NAME_PINGTUI);
ArrayList<ParentAgent> parentList = (ArrayList<ParentAgent>) userService.getAgentListByUserId(userAgent.getUserId(), PARENT_COLUMN_NAME_PINGTUI);
if (parentList.size() > 0) {
/**
* 扫描agentlist中的平推城市代理
......
......@@ -2,7 +2,6 @@ package com.lanren.huhu.partner.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lanren.huhu.partner.domain.UserAgent;
import com.lanren.huhu.partner.model.ParentAgent;
import java.util.List;
......@@ -23,16 +22,16 @@ public interface UserAgentService extends IService<UserAgent> {
*/
UserAgent getOneByAgentId(Integer agentId);
/**
* @description: 查找一个用户的直接代理商上级, 根据字段presenter_id
* @param agentId
* @return ParentAgent
*/
ParentAgent getParentAgentByAgentId(Integer agentId, String parentColumnName);
/**
* @description: 查找一个用户的全部直属代理商上级, 根据字段presenter_id
* @param agentId
* @return List<ParentAgent>
*/
List<ParentAgent> getParentAgentListByAgentId(Integer agentId, String parentColumnName);
// /**
// * @description: 查找一个用户的直接代理商上级, 根据字段presenter_id
// * @param agentId
// * @return ParentAgent
// */
// ParentAgent getParentAgentByAgentId(Integer agentId, String parentColumnName);
// /**
// * @description: 查找一个用户的全部直属代理商上级, 根据字段presenter_id
// * @param agentId
// * @return List<ParentAgent>
// */
// List<ParentAgent> getParentAgentListByAgentId(Integer agentId, String parentColumnName);
}
......@@ -4,13 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanren.huhu.partner.dao.UserAgentMapper;
import com.lanren.huhu.partner.domain.UserAgent;
import com.lanren.huhu.partner.model.ParentAgent;
import com.lanren.huhu.partner.service.UserAgentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -52,41 +50,41 @@ public class UserAgentServiceImpl extends ServiceImpl<UserAgentMapper, UserAgent
return baseMapper.selectOne(queryWrapper);
}
@Override
public List<ParentAgent> getParentAgentListByAgentId(Integer agentId, String parentColumnName) {
List<ParentAgent> parentList = new ArrayList<ParentAgent>();
int loogAgentId = agentId;
int loopTimes = 0;
while (true) {
ParentAgent parentAgent = getParentAgentByAgentId(loogAgentId, parentColumnName);
if (null == parentAgent) {
break;
} else {
if (parentList.contains(parentAgent) || parentAgent.getAgentId() == agentId) {
logger.info("发现互为上级的代理关系 代理商({})", parentAgent.getAgentId());
logger.info("退出循环, 不再继续查找");
break;
}
parentList.add(parentAgent);
loogAgentId = parentAgent.getAgentId();
loopTimes++;
if (loopTimes > 500) {
parentList.clear();
logger.error("代理商:{} 邀请关系异常, 已超500层", agentId);
break;
}
}
}
return parentList;
}
@Override
public ParentAgent getParentAgentByAgentId(Integer agentId, String parentColumnName) {
UserAgent userAgent = baseMapper.getParentAgent(agentId, parentColumnName);
if (userAgent != null) {
return new ParentAgent(userAgent.getUserId(), userAgent.getAgentId(), userAgent.getAgentLevel());
} else {
return null;
}
}
// @Override
// public List<ParentAgent> getParentAgentListByAgentId(Integer agentId, String parentColumnName) {
// List<ParentAgent> parentList = new ArrayList<ParentAgent>();
// int loogAgentId = agentId;
// int loopTimes = 0;
// while (true) {
// ParentAgent parentAgent = getParentAgentByAgentId(loogAgentId, parentColumnName);
// if (null == parentAgent) {
// break;
// } else {
// if (parentList.contains(parentAgent) || parentAgent.getAgentId() == agentId) {
// logger.info("发现互为上级的代理关系 代理商({})", parentAgent.getAgentId());
// logger.info("退出循环, 不再继续查找");
// break;
// }
// parentList.add(parentAgent);
// loogAgentId = parentAgent.getAgentId();
// loopTimes++;
// if (loopTimes > 500) {
// parentList.clear();
// logger.error("代理商:{} 邀请关系异常, 已超500层", agentId);
// break;
// }
// }
// }
// return parentList;
// }
//
// @Override
// public ParentAgent getParentAgentByAgentId(Integer agentId, String parentColumnName) {
// UserAgent userAgent = baseMapper.getParentAgent(agentId, parentColumnName);
// if (userAgent != null) {
// return new ParentAgent(userAgent.getUserId(), userAgent.getAgentId(), userAgent.getAgentLevel());
// } else {
// return null;
// }
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment