Commit 141b898f by guanchen

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

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