|  | @@ -1,7 +1,15 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.auth.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.dto.SysUserInfo;
 | 
	
		
			
				|  |  | -import com.ym.mec.auth.api.entity.LoginEntity;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.enums.YesOrNoEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.dal.dao.SysUserDao;
 | 
	
	
		
			
				|  | @@ -16,18 +24,6 @@ import com.ym.mec.common.service.IdGeneratorService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.im.ImFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.im.WebFeignService;
 | 
	
		
			
				|  |  | -import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | -import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | -import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | -import org.springframework.security.authentication.BadCredentialsException;
 | 
	
		
			
				|  |  | -import org.springframework.security.authentication.LockedException;
 | 
	
		
			
				|  |  | -import org.springframework.security.core.Authentication;
 | 
	
		
			
				|  |  | -import org.springframework.security.core.userdetails.UsernameNotFoundException;
 | 
	
		
			
				|  |  | -import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | -import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class SysUserServiceImpl extends BaseServiceImpl<Integer, SysUser> implements SysUserService {
 | 
	
	
		
			
				|  | @@ -49,8 +45,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<Integer, SysUser> implem
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private IdGeneratorService smsCodeService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	@Value("${message.autoRegister}")
 | 
	
		
			
				|  |  | -	private boolean autoRegister;
 | 
	
		
			
				|  |  |  	@Value("${auth.sysconfig.tenantId}")
 | 
	
		
			
				|  |  |  	private Integer lesseeOrganId;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -155,59 +149,33 @@ public class SysUserServiceImpl extends BaseServiceImpl<Integer, SysUser> implem
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	@Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -	public SysUserInfo initUser(String phone, String clientId,String isRegister,String isLessee) {
 | 
	
		
			
				|  |  | -		if("register".equals(isRegister)){
 | 
	
		
			
				|  |  | -			throw new UsernameNotFoundException("404.9");
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		if(StringUtils.isNotEmpty(isLessee) || autoRegister){
 | 
	
		
			
				|  |  | -			if(StringUtils.isNotEmpty(isLessee) && StringUtils.equalsIgnoreCase(clientId,"TEACHER")){
 | 
	
		
			
				|  |  | -				SysUser sysUser = new SysUser();
 | 
	
		
			
				|  |  | -				sysUser.setPhone(phone);
 | 
	
		
			
				|  |  | -				sysUser.setUserType("TEACHER");
 | 
	
		
			
				|  |  | -				sysUserDao.insert(sysUser);
 | 
	
		
			
				|  |  | -				//添加用户现金账户
 | 
	
		
			
				|  |  | -				imFeignService.register(new ImUserModel(sysUser.getId().toString(),phone,null));
 | 
	
		
			
				|  |  | -				userFeignService.createCashAccount(sysUser.getId());
 | 
	
		
			
				|  |  | -				//sysTenantAccount
 | 
	
		
			
				|  |  | -				sysUserDao.insertSysTenantAccount(sysUser.getId());
 | 
	
		
			
				|  |  | -				//创建teacher表
 | 
	
		
			
				|  |  | -				sysUserDao.insertTeacher(sysUser.getId(),lesseeOrganId);
 | 
	
		
			
				|  |  | -				return queryUserInfoByPhone(phone);
 | 
	
		
			
				|  |  | -			}else if(StringUtils.isNotEmpty(isLessee) && StringUtils.equalsIgnoreCase(clientId,"STUDENT")){
 | 
	
		
			
				|  |  | -				SysUser sysUser = new SysUser();
 | 
	
		
			
				|  |  | -				sysUser.setPhone(phone);
 | 
	
		
			
				|  |  | -				sysUser.setUserType("STUDENT");
 | 
	
		
			
				|  |  | -				sysUser.setOrganId(lesseeOrganId);
 | 
	
		
			
				|  |  | -				sysUserDao.insert(sysUser);
 | 
	
		
			
				|  |  | -				sysUserService.saveStudent(sysUser.getId());
 | 
	
		
			
				|  |  | -				//添加用户现金账户
 | 
	
		
			
				|  |  | -				imFeignService.register(new ImUserModel(sysUser.getId().toString(),phone,null));
 | 
	
		
			
				|  |  | -				userFeignService.createCashAccount(sysUser.getId());
 | 
	
		
			
				|  |  | -				return queryUserInfoByPhone(phone);
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | +	public SysUserInfo initUser(String phone, String clientId) {
 | 
	
		
			
				|  |  | +		if(StringUtils.equalsIgnoreCase(clientId,"TEACHER")){
 | 
	
		
			
				|  |  | +			SysUser sysUser = new SysUser();
 | 
	
		
			
				|  |  | +			sysUser.setPhone(phone);
 | 
	
		
			
				|  |  | +			sysUser.setUserType("TEACHER");
 | 
	
		
			
				|  |  | +			sysUserDao.insert(sysUser);
 | 
	
		
			
				|  |  | +			//添加用户现金账户
 | 
	
		
			
				|  |  | +			imFeignService.register(new ImUserModel(sysUser.getId().toString(),phone,null));
 | 
	
		
			
				|  |  | +			userFeignService.createCashAccount(sysUser.getId());
 | 
	
		
			
				|  |  | +			//sysTenantAccount
 | 
	
		
			
				|  |  | +			sysUserDao.insertSysTenantAccount(sysUser.getId());
 | 
	
		
			
				|  |  | +			//创建teacher表
 | 
	
		
			
				|  |  | +			sysUserDao.insertTeacher(sysUser.getId(),lesseeOrganId);
 | 
	
		
			
				|  |  | +			return queryUserInfoByPhone(phone);
 | 
	
		
			
				|  |  | +		}else if(StringUtils.equalsIgnoreCase(clientId,"STUDENT")){
 | 
	
		
			
				|  |  | +			SysUser sysUser = new SysUser();
 | 
	
		
			
				|  |  | +			sysUser.setPhone(phone);
 | 
	
		
			
				|  |  | +			sysUser.setUserType("STUDENT");
 | 
	
		
			
				|  |  | +			sysUser.setOrganId(lesseeOrganId);
 | 
	
		
			
				|  |  | +			sysUserDao.insert(sysUser);
 | 
	
		
			
				|  |  | +			sysUserService.saveStudent(sysUser.getId());
 | 
	
		
			
				|  |  | +			//添加用户现金账户
 | 
	
		
			
				|  |  | +			imFeignService.register(new ImUserModel(sysUser.getId().toString(),phone,null));
 | 
	
		
			
				|  |  | +			userFeignService.createCashAccount(sysUser.getId());
 | 
	
		
			
				|  |  | +			return queryUserInfoByPhone(phone);
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		throw new UsernameNotFoundException("404.9");
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	@Override
 | 
	
		
			
				|  |  | -	@Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -	public void retrieveUser(String phone, Authentication authentication) {
 | 
	
		
			
				|  |  | -		LoginEntity loginEntity = (LoginEntity) authentication.getCredentials();
 | 
	
		
			
				|  |  | -		SysUserInfo userInfo = sysUserService.queryUserInfoByPhone(loginEntity.getPhone());
 | 
	
		
			
				|  |  | -		if (userInfo == null) {
 | 
	
		
			
				|  |  | -			userInfo = sysUserService.initUser(loginEntity.getPhone(),loginEntity.getClientId(),loginEntity.getIsRegister(),loginEntity.getIsLessee());
 | 
	
		
			
				|  |  | -		}else if(StringUtils.isNotEmpty(loginEntity.getIsLessee())){
 | 
	
		
			
				|  |  | -			throw new LockedException("用户已存在");
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		if("EDUCATION".equals(loginEntity.getClientId())){
 | 
	
		
			
				|  |  | -			loginEntity.setClientId("SYSTEM");
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		if (!userInfo.getSysUser().getUserType().contains(loginEntity.getClientId())) {
 | 
	
		
			
				|  |  | -			throw new LockedException("用户不存在,请联系教务老师");
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -//			 验证码验证
 | 
	
		
			
				|  |  | -		boolean b = smsCodeService.verifyValidCode(loginEntity.getPhone(), loginEntity.getSmsCode());
 | 
	
		
			
				|  |  | -		if(!b) throw new BadCredentialsException("验证码校验失败");
 | 
	
		
			
				|  |  | +		return null;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
	
		
			
				|  | @@ -221,4 +189,14 @@ public class SysUserServiceImpl extends BaseServiceImpl<Integer, SysUser> implem
 | 
	
		
			
				|  |  |  		sysUserDao.saveStudent(userId);
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public void saveTeacher(Integer userId) {
 | 
	
		
			
				|  |  | +		sysUserDao.insertTeacher(userId, lesseeOrganId);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public Integer getLesseeOrganId() {
 | 
	
		
			
				|  |  | +		return lesseeOrganId;
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |