content: package org.dhorse.infrastructure.strategy.login;
  
  import java.util.List;
  
  import org.dhorse.api.enums.RegisteredSourceEnum;
  import org.dhorse.api.enums.RoleTypeEnum;
  import org.dhorse.api.param.user.UserLoginParam;
  import org.dhorse.api.response.model.GlobalConfigAgg;
  import org.dhorse.api.response.model.SysUser;
  import org.dhorse.infrastructure.component.SpringBeanContext;
  import org.dhorse.infrastructure.param.SysUserParam;
  import org.dhorse.infrastructure.repository.SysUserRepository;
  import org.dhorse.infrastructure.repository.po.SysUserPO;
  import org.dhorse.infrastructure.strategy.login.dto.LoginUser;
  import org.springframework.security.crypto.password.PasswordEncoder;
  
  public class CasUserStrategy extends UserStrategy {
  
  	@Override
  	public LoginUser login(UserLoginParam userLoginParam, GlobalConfigAgg globalConfig, PasswordEncoder passwordEncoder) {
  		
  		LoginUser loginUser = new LoginUser();
  		loginUser.setLoginName(userLoginParam.getLoginName());
  		loginUser.setUserName(userLoginParam.getUserName());
  		
  		//保存用户到DHorse
  		SysUserRepository sysUserRepository = SpringBeanContext.getBean(SysUserRepository.class);
  		SysUserPO sysUserPO = sysUserRepository.queryByLoginName(userLoginParam.getLoginName());
  		if(sysUserPO == null) {
  			//如果用户第一次登录，登记到内部系统
  			SysUserParam bizParam = new SysUserParam();
  			bizParam.setLoginName(loginUser.getLoginName());
  			bizParam.setUserName(loginUser.getUserName());
  			bizParam.setEmail(loginUser.getEmail());
  			bizParam.setRegisteredSource(RegisteredSourceEnum.CAS.getCode());
  			bizParam.setRoleType(RoleTypeEnum.NORMAL.getCode());
  			loginUser.setId(sysUserRepository.add(bizParam));
  		}else{
  			loginUser.setRoleType(sysUserPO.getRoleType());
  			loginUser.setId(sysUserPO.getId());
  		}
  		
  		return loginUser;
  	}
  	
  	@Override
  	public List<SysUser> search(String userName, GlobalConfigAgg globalConfig) {
  		return null;
  	}
  }
  