|  | @@ -1,11 +1,17 @@
 | 
	
		
			
				|  |  |  package cn.newfeifan.mall.module.distri.service.user;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.system.service.user.AdminUserService;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import org.springframework.validation.annotation.Validated;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.distri.controller.admin.user.vo.*;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.distri.dal.dataobject.user.UserDO;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.framework.common.pojo.PageResult;
 | 
	
	
		
			
				|  | @@ -29,6 +35,10 @@ public class UserServiceImpl implements UserService {
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      private UserMapper userMapper;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private AdminUserService adminUserService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public Long createUser(UserSaveReqVO createReqVO) {
 | 
	
		
			
				|  |  |          // 插入
 | 
	
	
		
			
				|  | @@ -68,7 +78,50 @@ public class UserServiceImpl implements UserService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public PageResult<UserDO> getUserPage(UserPageReqVO pageReqVO) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /*@Query(value = "
 | 
	
		
			
				|  |  | +        SELECT DISTINCT d.* FROM Distributors d INNER JOIN DistributorPaths dp ON d.id = dp.descendant WHERE dp.ancestor
 | 
	
		
			
				|  |  | +        IN (SELECT dp2.ancestor FROM DistributorPaths dp2 WHERE dp2.descendant = :distributorId AND dp2.depth = 1)
 | 
	
		
			
				|  |  | +        AND dp.depth = 1 AND d.id < :distributorId", nativeQuery = true)
 | 
	
		
			
				|  |  | +         */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return userMapper.selectPage(pageReqVO);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void addDistributor(Long distributor, Long parent) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        int i = userMapper.hasParent(distributor);
 | 
	
		
			
				|  |  | +        if (i >0){
 | 
	
		
			
				|  |  | +            throw exception(IS_EXISTS);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        AdminUserDO user = adminUserService.getUser(distributor);
 | 
	
		
			
				|  |  | +        if (user != null) {
 | 
	
		
			
				|  |  | +            // 创建分销人员表
 | 
	
		
			
				|  |  | +            // 判断当前推销人是否有数据, 如果没有, 同样需要创建一个新的分销用户
 | 
	
		
			
				|  |  | +            UserDO distributorDO = new UserDO().setUserId(distributor).setName(user.getUsername()).setMobile(user.getMobile());
 | 
	
		
			
				|  |  | +            userMapper.insert(distributorDO);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        UserDO userDO = selectByUserId(parent);
 | 
	
		
			
				|  |  | +        if (userDO == null) {
 | 
	
		
			
				|  |  | +            AdminUserDO parentUser = adminUserService.getUser(parent);
 | 
	
		
			
				|  |  | +            if (parentUser != null){
 | 
	
		
			
				|  |  | +                UserDO parentDO = new UserDO().setUserId(parent).setName(parentUser.getUsername()).setMobile(parentUser.getMobile());
 | 
	
		
			
				|  |  | +                userMapper.insert(parentDO);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public UserDO selectByUserId(Long userId) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return userMapper.selectOne(new LambdaQueryWrapperX<UserDO>().eqIfPresent(UserDO::getUserId, userId));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |