package doumeemes.service.system.impl; 
 | 
  
 | 
import com.alibaba.fastjson.JSONObject; 
 | 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
 | 
import com.iflytek.antelope.other.client.dto.resp.UserDTO; 
 | 
import doumeemes.biz.system.SystemDictDataBiz; 
 | 
import doumeemes.config.shiro.ShiroToken; 
 | 
import doumeemes.core.constants.ResponseStatus; 
 | 
import doumeemes.core.exception.BusinessException; 
 | 
import doumeemes.core.model.LoginUserInfo; 
 | 
import doumeemes.core.utils.Constants; 
 | 
import doumeemes.core.utils.Utils; 
 | 
import doumeemes.core.utils.dingding.DingDingUtil; 
 | 
import doumeemes.core.utils.dingding.LingyangUtil; 
 | 
import doumeemes.core.utils.edpg.EdgpServerUtil; 
 | 
import doumeemes.core.utils.edpg.EdgpUtil; 
 | 
import doumeemes.core.utils.edpg.bean.AppUserInfoModel; 
 | 
import doumeemes.dao.business.dto.CompanyInitDataDTO; 
 | 
import doumeemes.dao.business.model.Company; 
 | 
import doumeemes.dao.business.model.CompanyUser; 
 | 
import doumeemes.dao.ext.CompanyExtMapper; 
 | 
import doumeemes.dao.ext.CompanyUserExtMapper; 
 | 
import doumeemes.dao.ext.dto.QueryCompanyUserExtDTO; 
 | 
import doumeemes.dao.ext.vo.CompanyExtListVO; 
 | 
import doumeemes.dao.ext.vo.CompanyUserExtListVO; 
 | 
import doumeemes.dao.system.dto.LoginDTO; 
 | 
import doumeemes.dao.system.model.SystemLoginLog; 
 | 
import doumeemes.service.common.CaptchaService; 
 | 
import doumeemes.service.ext.CompanyExtService; 
 | 
import doumeemes.service.system.SystemLoginLogService; 
 | 
import doumeemes.service.system.SystemLoginService; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
import org.apache.shiro.SecurityUtils; 
 | 
import org.apache.shiro.authc.AuthenticationException; 
 | 
import org.apache.shiro.subject.Subject; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.beans.factory.annotation.Value; 
 | 
import org.springframework.context.annotation.Lazy; 
 | 
import org.springframework.stereotype.Service; 
 | 
  
 | 
import javax.servlet.http.HttpServletRequest; 
 | 
import java.util.Date; 
 | 
  
 | 
@Slf4j 
 | 
@Service 
 | 
public class SystemLoginServiceImpl implements SystemLoginService { 
 | 
  
 | 
    @Value("${project.version}") 
 | 
    private String systemVersion; 
 | 
  
 | 
    @Autowired 
 | 
    private CaptchaService captchaService; 
 | 
    @Lazy 
 | 
    @Autowired 
 | 
    private SystemDictDataBiz systemDictDataBiz; 
 | 
  
 | 
    @Autowired 
 | 
    private CompanyUserExtMapper companyUserExtMapper; 
 | 
    @Autowired 
 | 
    private CompanyExtMapper companyExtMapper; 
 | 
  
 | 
    @Autowired 
 | 
    private CompanyExtService companyExtService; 
 | 
  
 | 
    @Autowired 
 | 
    private SystemLoginLogService systemLoginLogService; 
 | 
  
 | 
    @Value("${captcha_check}") 
 | 
    private Boolean captchaCheck; 
 | 
  
 | 
    @Override 
 | 
    public String loginByPassword(LoginDTO dto, HttpServletRequest request) { 
 | 
        SystemLoginLog loginLog = new SystemLoginLog(); 
 | 
        loginLog.setLoginUsername(dto.getUsername()); 
 | 
        loginLog.setLoginTime(new Date()); 
 | 
        loginLog.setSystemVersion(systemVersion); 
 | 
        loginLog.setIp(Utils.User_Client.getIP(request)); 
 | 
        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); 
 | 
        loginLog.setPlatform(Utils.User_Client.getPlatform(request)); 
 | 
        loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); 
 | 
        loginLog.setOsInfo(Utils.User_Client.getOS(request)); 
 | 
        loginLog.setServerIp(Utils.Server.getIP()); 
 | 
        // 校验验证码 
 | 
        if(captchaCheck){ 
 | 
            try { 
 | 
                captchaService.check(dto.getUuid(), dto.getCode()); 
 | 
            } catch (Exception e) { 
 | 
                log.error(e.getMessage(), e); 
 | 
                loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
                loginLog.setSuccess(Boolean.FALSE); 
 | 
                systemLoginLogService.create(loginLog); 
 | 
                throw e; 
 | 
            } 
 | 
        } 
 | 
        // 校验用户名和密码 
 | 
        Subject subject = SecurityUtils.getSubject(); 
 | 
        ShiroToken token = new ShiroToken(dto.getCompanyId(),dto.getUsername(), dto.getPassword(),false); 
 | 
        try { 
 | 
            subject.login(token); 
 | 
            LoginUserInfo loginUser = ((LoginUserInfo)subject.getPrincipal()); 
 | 
            loginLog.setUserId(loginUser.getId()); 
 | 
            loginLog.setCompanyId(loginUser.getCompany()!=null?loginUser.getCompany().getId():null); 
 | 
            loginLog.setCompanyUserId(loginUser.getCompanyUser()!=null?loginUser.getCompanyUser().getId():null); 
 | 
            loginLog.setSuccess(Boolean.TRUE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            return (String)subject.getSession().getId(); 
 | 
        }catch (AuthenticationException e) { 
 | 
            BusinessException ee = null; 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            if(e.getCause()!=null && e.getCause() instanceof  BusinessException){ 
 | 
                ee =   (BusinessException)e.getCause(); 
 | 
                loginLog.setReason(ee.getMessage().length() > 200 ? (ee.getMessage().substring(0, 190) + "...") : ee.getMessage()); 
 | 
                log.error(ee.getMessage(), e); 
 | 
            }else{ 
 | 
                log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
                loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
                ee = new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw  ee; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public String platformLogin(LoginDTO dto, HttpServletRequest request) { 
 | 
  
 | 
        SystemLoginLog loginLog = new SystemLoginLog(); 
 | 
        loginLog.setLoginUsername(dto.getUsername()); 
 | 
        loginLog.setLoginTime(new Date()); 
 | 
        loginLog.setSystemVersion(systemVersion); 
 | 
        loginLog.setIp(Utils.User_Client.getIP(request)); 
 | 
        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); 
 | 
        loginLog.setPlatform(Utils.User_Client.getPlatform(request)); 
 | 
        loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); 
 | 
        loginLog.setOsInfo(Utils.User_Client.getOS(request)); 
 | 
        loginLog.setServerIp(Utils.Server.getIP()); 
 | 
        // 校验验证码 
 | 
        if(captchaCheck){ 
 | 
            try { 
 | 
                captchaService.check(dto.getUuid(), dto.getCode()); 
 | 
            } catch (Exception e) { 
 | 
                log.error(e.getMessage(), e); 
 | 
                loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
                loginLog.setSuccess(Boolean.FALSE); 
 | 
                systemLoginLogService.create(loginLog); 
 | 
                throw e; 
 | 
            } 
 | 
        } 
 | 
        // 校验用户名和密码 
 | 
        Subject subject = SecurityUtils.getSubject(); 
 | 
        ShiroToken token = new ShiroToken(dto.getCompanyId(),dto.getUsername(), dto.getPassword(),false); 
 | 
        try { 
 | 
            subject.login(token); 
 | 
            LoginUserInfo loginUser = ((LoginUserInfo)subject.getPrincipal()); 
 | 
            loginLog.setUserId(loginUser.getId()); 
 | 
            loginLog.setCompanyId(loginUser.getCompany()!=null?loginUser.getCompany().getId():null); 
 | 
            loginLog.setCompanyUserId(loginUser.getCompanyUser()!=null?loginUser.getCompanyUser().getId():null); 
 | 
            loginLog.setSuccess(Boolean.TRUE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            return (String)subject.getSession().getId(); 
 | 
        }catch (AuthenticationException e) { 
 | 
            BusinessException ee = null; 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            if(e.getCause()!=null && e.getCause() instanceof  BusinessException){ 
 | 
                ee =   (BusinessException)e.getCause(); 
 | 
                loginLog.setReason(ee.getMessage().length() > 200 ? (ee.getMessage().substring(0, 190) + "...") : ee.getMessage()); 
 | 
                log.error(ee.getMessage(), e); 
 | 
            }else{ 
 | 
                log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
                loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
                ee = new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw  ee; 
 | 
        } 
 | 
    } 
 | 
    @Override 
 | 
    public   String getDingdingCorpId(Integer companyId){ 
 | 
        CompanyExtListVO company =     companyExtService.getModelById(companyId); 
 | 
        if(company == null){ 
 | 
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"企业信息不存在!"); 
 | 
        } 
 | 
        try { 
 | 
            String ddinfo = company.getDingdingInfo(); 
 | 
            JSONObject j = JSONObject.parseObject(ddinfo); 
 | 
            String r = j .getString("corpId"); 
 | 
            if(StringUtils.isBlank(r)){ 
 | 
                throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"企业配置信息有误!"); 
 | 
            } 
 | 
            return  r; 
 | 
        }catch (Exception e){ 
 | 
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"企业配置信息有误!"); 
 | 
        } 
 | 
    } 
 | 
    @Override 
 | 
    public String loginByDingdingCode(Integer companyId ,String code, HttpServletRequest request) { 
 | 
        SystemLoginLog loginLog = new SystemLoginLog(); 
 | 
        loginLog.setLoginUsername(companyId+"_dd_"+code); 
 | 
        loginLog.setLoginTime(new Date()); 
 | 
        loginLog.setSystemVersion(systemVersion); 
 | 
  
 | 
        loginLog.setOrgin(Constants.USER_LOGIN_ORIGIN.dingding); 
 | 
        loginLog.setIp(Utils.User_Client.getIP(request)); 
 | 
        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); 
 | 
        loginLog.setPlatform(Utils.User_Client.getPlatform(request)); 
 | 
        loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); 
 | 
        loginLog.setOsInfo(Utils.User_Client.getOS(request)); 
 | 
        loginLog.setServerIp(Utils.Server.getIP()); 
 | 
        try { 
 | 
            String mobile = null; 
 | 
            CompanyUser user = DingDingUtil.getUserInfoByCode(companyExtService.getDingdingToken(companyId),code); 
 | 
            if(user == null){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            QueryCompanyUserExtDTO qUser = new QueryCompanyUserExtDTO(); 
 | 
            qUser.setDeleted(Constants.ZERO); 
 | 
            qUser.setDdUserid(user.getDdUserid()); 
 | 
            qUser.setDdUnionid(user.getDdUnionid()); 
 | 
            //查询用户数据 
 | 
            CompanyUserExtListVO model = companyUserExtMapper.selectModel(qUser); 
 | 
            if(model != null&& StringUtils.isNotBlank(model.getPhone())){ 
 | 
                mobile=model.getPhone(); 
 | 
            }else{ 
 | 
                //获取用户手机号 
 | 
                mobile= DingDingUtil.getUserMobileByUserId(companyExtService.getDingdingToken(companyId),user.getDdUserid()); 
 | 
            } 
 | 
            loginLog.setLoginUsername(mobile); 
 | 
            // 校验用户名和密码 
 | 
            Subject subject = SecurityUtils.getSubject(); 
 | 
            // 钉钉登录 
 | 
            ShiroToken token = new ShiroToken(companyId,mobile, null,true); 
 | 
  
 | 
            subject.login(token); 
 | 
            LoginUserInfo loginUser =(LoginUserInfo)subject.getPrincipal(); 
 | 
            loginLog.setUserId(user.getId()); 
 | 
            loginLog.setCompanyId(loginUser.getCompany()!=null?loginUser.getCompany().getId():null); 
 | 
            loginLog.setCompanyUserId(loginUser.getCompanyUser()!=null?loginUser.getCompanyUser().getId():null); 
 | 
            loginLog.setSuccess(Boolean.TRUE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            user.setId(loginUser.getCompanyUser().getId()); 
 | 
            //更新用户绑定的钉钉信息 
 | 
            companyUserExtMapper.updateById(user); 
 | 
            return (String)subject.getSession().getId(); 
 | 
        } catch (AuthenticationException e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        }catch (Exception e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        } 
 | 
    } 
 | 
    @Override 
 | 
    public  String loginLingYangDemo(String token, HttpServletRequest request  ) { 
 | 
        Integer companyId = null; 
 | 
        SystemLoginLog loginLog = new SystemLoginLog(); 
 | 
        loginLog.setLoginTime(new Date()); 
 | 
        loginLog.setSystemVersion(systemVersion); 
 | 
        loginLog.setIp(Utils.User_Client.getIP(request)); 
 | 
        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); 
 | 
        loginLog.setPlatform(Utils.User_Client.getPlatform(request)); 
 | 
        loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); 
 | 
        loginLog.setOsInfo(Utils.User_Client.getOS(request)); 
 | 
        loginLog.setServerIp(Utils.Server.getIP()); 
 | 
         companyId= Integer.parseInt(systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_DEMO_COMPANY).getCode()); 
 | 
        loginLog.setLoginUsername(companyId+"_lingyangDemo_"+token); 
 | 
        try { 
 | 
            String mobile = null; 
 | 
            CompanyExtListVO com = companyExtService.getModelById(companyId); 
 | 
            if(com == null || StringUtils.isBlank(com.getLingyangInfo())){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            LingyangUtil lingyangUtil = new LingyangUtil(systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_AESKEY).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_APPKEY).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_SECRET).getCode()); 
 | 
            UserDTO  user = lingyangUtil.getUserInfoByToken(token); 
 | 
            if(user == null){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            QueryCompanyUserExtDTO qUser = new QueryCompanyUserExtDTO(); 
 | 
            qUser.setDeleted(Constants.ZERO); 
 | 
//            qUser.setCompanyId(companyId); 
 | 
            qUser.setLingyangUserid(user.getUserId()); 
 | 
            //查询用户数据 
 | 
            CompanyUserExtListVO model = companyUserExtMapper.selectModel(qUser); 
 | 
            //如果没有绑定过 或者手机号为空 
 | 
            mobile=   systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_DEMO_USER).getCode(); 
 | 
            loginLog.setLoginUsername(mobile); 
 | 
            // 校验用户名和密码 
 | 
            Subject subject = SecurityUtils.getSubject(); 
 | 
            // 钉钉登录 
 | 
            ShiroToken atoken = new ShiroToken(companyId,mobile, null,true); 
 | 
            subject.login(atoken); 
 | 
            LoginUserInfo loginUser =(LoginUserInfo)subject.getPrincipal(); 
 | 
            loginUser.getCompanyUser().setName(user.getName()); 
 | 
            loginLog.setUserId(loginUser.getId()); 
 | 
            loginLog.setCompanyId(loginUser.getCompany()!=null?loginUser.getCompany().getId():null); 
 | 
            loginLog.setCompanyUserId(loginUser.getCompanyUser()!=null?loginUser.getCompanyUser().getId():null); 
 | 
            loginLog.setSuccess(Boolean.TRUE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            CompanyUser cu = new CompanyUser(); 
 | 
            cu.setLingyangUserid(user.getUserId()); 
 | 
            cu.setId(loginUser.getCompanyUser().getId()); 
 | 
            cu.setName(user.getName());//同步羚羊的名字 
 | 
            cu.setUpdateTime(new Date()); 
 | 
            //更新用户绑定的钉钉信息 
 | 
            companyUserExtMapper.updateById(cu); 
 | 
            return (String)subject.getSession().getId(); 
 | 
        } catch (AuthenticationException e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        }catch (Exception e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        } 
 | 
    } 
 | 
    @Override 
 | 
    public  String  loginEdgpDemo(  String token, HttpServletRequest request ) { 
 | 
       Integer companyId = null; 
 | 
        SystemLoginLog loginLog = new SystemLoginLog(); 
 | 
        loginLog.setLoginTime(new Date()); 
 | 
        loginLog.setSystemVersion(systemVersion); 
 | 
        loginLog.setIp(Utils.User_Client.getIP(request)); 
 | 
        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); 
 | 
        loginLog.setPlatform(Utils.User_Client.getPlatform(request)); 
 | 
        loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); 
 | 
        loginLog.setOsInfo(Utils.User_Client.getOS(request)); 
 | 
        loginLog.setServerIp(Utils.Server.getIP()); 
 | 
        companyId= Integer.parseInt(systemDictDataBiz.queryByCode(Constants.EDGP_PARAM,Constants.EDGP_DEMO_COMPANY).getCode()); 
 | 
        loginLog.setLoginUsername(companyId+"_edgpDemo_"+token); 
 | 
        try { 
 | 
            String mobile = null; 
 | 
            CompanyExtListVO com = companyExtService.getModelById(companyId); 
 | 
            if(com == null || StringUtils.isBlank(com.getLingyangInfo())){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            EdgpServerUtil edgpServerUtil = new EdgpServerUtil( 
 | 
                    systemDictDataBiz.queryByCode(Constants.EDGP_PARAM,Constants.EDGP_SERVER_URL).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.EDGP_PARAM,Constants.EDGP_APPKEY).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.EDGP_PARAM,Constants.EDGP_SECRET).getCode()); 
 | 
            AppUserInfoModel user = edgpServerUtil.getUserInfoByToken(token); 
 | 
            if(user == null){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            QueryCompanyUserExtDTO qUser = new QueryCompanyUserExtDTO(); 
 | 
            qUser.setDeleted(Constants.ZERO); 
 | 
//            qUser.setCompanyId(companyId); 
 | 
            qUser.setEdgpUserId(user.getId()+""); 
 | 
            //查询用户数据 
 | 
            CompanyUserExtListVO model = companyUserExtMapper.selectModel(qUser); 
 | 
            //如果没有绑定过 或者手机号为空 
 | 
            mobile=   systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_DEMO_USER).getCode(); 
 | 
            loginLog.setLoginUsername(mobile); 
 | 
            // 校验用户名和密码 
 | 
            Subject subject = SecurityUtils.getSubject(); 
 | 
            // 钉钉登录 
 | 
            ShiroToken atoken = new ShiroToken(companyId,mobile, null,true); 
 | 
            subject.login(atoken); 
 | 
            LoginUserInfo loginUser =(LoginUserInfo)subject.getPrincipal(); 
 | 
            loginLog.setUserId(loginUser.getId()); 
 | 
            loginLog.setCompanyId(loginUser.getCompany()!=null?loginUser.getCompany().getId():null); 
 | 
            loginLog.setCompanyUserId(loginUser.getCompanyUser()!=null?loginUser.getCompanyUser().getId():null); 
 | 
            loginUser.getCompanyUser().setName(user.getName()); 
 | 
            loginLog.setSuccess(Boolean.TRUE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            CompanyUser cu = new CompanyUser(); 
 | 
            cu.setEdgpUserId(user.getId()+""); 
 | 
            cu.setId(loginUser.getCompanyUser().getId()); 
 | 
            cu.setName(user.getName());//同步羚羊的名字 
 | 
            cu.setUpdateTime(new Date()); 
 | 
            //更新用户绑定的钉钉信息 
 | 
            companyUserExtMapper.updateById(cu); 
 | 
            return (String)subject.getSession().getId(); 
 | 
        } catch (AuthenticationException e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        }catch (Exception e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        } 
 | 
    } 
 | 
    @Override 
 | 
    public   String loginAutoType(  String token,int type, HttpServletRequest request,boolean isDemo){ 
 | 
      String result = null; 
 | 
        switch (type){ 
 | 
            case 0: 
 | 
                //羚羊注册自动登录 
 | 
                result =  loginAutoBylingyangToken(  token,   request, isDemo); 
 | 
                break; 
 | 
            case 1: 
 | 
                //Edgp自动登录 
 | 
                result =  loginAutoByEdgp(  token,   request, isDemo); 
 | 
                break; 
 | 
        } 
 | 
        return  result; 
 | 
    } 
 | 
    @Override 
 | 
    public  String loginAutoBylingyangToken(String token, HttpServletRequest request,boolean isDemo){ 
 | 
        SystemLoginLog loginLog = new SystemLoginLog(); 
 | 
        loginLog.setLoginUsername("lingyangAuto_"+token); 
 | 
        loginLog.setLoginTime(new Date()); 
 | 
        loginLog.setOrgin(Constants.USER_LOGIN_ORIGIN.lingyang); 
 | 
        loginLog.setSystemVersion(systemVersion); 
 | 
        loginLog.setIp(Utils.User_Client.getIP(request)); 
 | 
        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); 
 | 
        loginLog.setPlatform(Utils.User_Client.getPlatform(request)); 
 | 
        loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); 
 | 
        loginLog.setOsInfo(Utils.User_Client.getOS(request)); 
 | 
        loginLog.setServerIp(Utils.Server.getIP()); 
 | 
        try { 
 | 
            String mobile = null; 
 | 
            LingyangUtil lingyangUtil = new LingyangUtil(systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_AESKEY).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_APPKEY).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.LINGYANG_PARAM,Constants.LINGYANG_SECRET).getCode()); 
 | 
            UserDTO  user = lingyangUtil.getUserInfoByToken(token); 
 | 
            if(user == null){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            //查询企业信息 
 | 
            Company com =  companyExtService.createByLingyang(user,systemDictDataBiz.queryByCode(Constants.DEFAULT,Constants.USER_PWD).getCode()); 
 | 
            if(com == null){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            //企业用户信息 
 | 
            CompanyUserExtListVO model =com.getUserModel(); 
 | 
            if(model != null && StringUtils.isNotBlank(model.getPhone())){ 
 | 
                mobile=model.getPhone(); 
 | 
            }else{ 
 | 
                //获取羚羊手机号 
 | 
                mobile= user.getPhone(); 
 | 
            } 
 | 
            loginLog.setLoginUsername(mobile); 
 | 
            // 校验用户名和密码 
 | 
            Subject subject = SecurityUtils.getSubject(); 
 | 
            // 钉钉登录 
 | 
            ShiroToken atoken = new ShiroToken(com.getId(),mobile, null,true); 
 | 
            subject.login(atoken); 
 | 
            LoginUserInfo loginUser =(LoginUserInfo)subject.getPrincipal(); 
 | 
            loginUser.getCompanyUser().setName(user.getName()); 
 | 
            loginLog.setUserId(loginUser.getId()); 
 | 
            loginLog.setCompanyId(loginUser.getCompany()!=null?loginUser.getCompany().getId():null); 
 | 
            loginLog.setCompanyUserId(loginUser.getCompanyUser()!=null?loginUser.getCompanyUser().getId():null); 
 | 
            loginLog.setSuccess(Boolean.TRUE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            CompanyUser cu = new CompanyUser(); 
 | 
            cu.setLingyangUserid(user.getUserId()); 
 | 
            cu.setId(loginUser.getCompanyUser().getId()); 
 | 
            cu.setName(user.getName());//同步羚羊的名字 
 | 
            cu.setUpdateTime(new Date()); 
 | 
            //更新用户绑定的钉钉信息 
 | 
            companyUserExtMapper.updateById(cu); 
 | 
            return (String)subject.getSession().getId(); 
 | 
        } catch (AuthenticationException e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        }catch (Exception e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        } 
 | 
    } 
 | 
    @Override 
 | 
    public  String loginAutoByEdgp(String token, HttpServletRequest request,boolean isDemo){ 
 | 
        SystemLoginLog loginLog = new SystemLoginLog(); 
 | 
        loginLog.setLoginUsername("lingyangAuto_"+token); 
 | 
        loginLog.setLoginTime(new Date()); 
 | 
        loginLog.setOrgin(Constants.USER_LOGIN_ORIGIN.edgp); 
 | 
        loginLog.setSystemVersion(systemVersion); 
 | 
        loginLog.setIp(Utils.User_Client.getIP(request)); 
 | 
        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); 
 | 
        loginLog.setPlatform(Utils.User_Client.getPlatform(request)); 
 | 
        loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); 
 | 
        loginLog.setOsInfo(Utils.User_Client.getOS(request)); 
 | 
        loginLog.setServerIp(Utils.Server.getIP()); 
 | 
        try { 
 | 
            String mobile = null; 
 | 
            EdgpServerUtil edgpServerUtil = new EdgpServerUtil( 
 | 
                    systemDictDataBiz.queryByCode(Constants.EDGP_PARAM,Constants.EDGP_SERVER_URL).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.EDGP_PARAM,Constants.EDGP_APPKEY).getCode(), 
 | 
                    systemDictDataBiz.queryByCode(Constants.EDGP_PARAM,Constants.EDGP_SECRET).getCode()); 
 | 
            AppUserInfoModel user = edgpServerUtil.getUserInfoByToken(token); 
 | 
            if(user == null){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            //查询企业信息 
 | 
            Company com =  companyExtService.createByEdgp(user,systemDictDataBiz.queryByCode(Constants.DEFAULT,Constants.USER_PWD).getCode()); 
 | 
            if(com == null){ 
 | 
                throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
            } 
 | 
            //企业用户信息 
 | 
            CompanyUserExtListVO model =com.getUserModel(); 
 | 
            if(model != null && StringUtils.isNotBlank(model.getPhone())){ 
 | 
                mobile=model.getPhone(); 
 | 
            }else{ 
 | 
                //获取羚羊手机号 
 | 
                mobile= user.getPhone(); 
 | 
            } 
 | 
            loginLog.setLoginUsername(mobile); 
 | 
            // 校验用户名和密码 
 | 
            Subject subject = SecurityUtils.getSubject(); 
 | 
            // 钉钉登录 
 | 
            ShiroToken atoken = new ShiroToken(com.getId(),mobile, null,true); 
 | 
            subject.login(atoken); 
 | 
            LoginUserInfo loginUser =(LoginUserInfo)subject.getPrincipal(); 
 | 
            loginUser.getCompanyUser().setName(user.getName()); 
 | 
            loginLog.setUserId(loginUser.getId()); 
 | 
            loginLog.setCompanyId(loginUser.getCompany()!=null?loginUser.getCompany().getId():null); 
 | 
            loginLog.setCompanyUserId(loginUser.getCompanyUser()!=null?loginUser.getCompanyUser().getId():null); 
 | 
            loginLog.setSuccess(Boolean.TRUE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            CompanyUser cu = new CompanyUser(); 
 | 
            cu.setEdgpUserId(user.getId()+""); 
 | 
            cu.setId(loginUser.getCompanyUser().getId()); 
 | 
            cu.setName(user.getName());//同步羚羊的名字 
 | 
            cu.setUpdateTime(new Date()); 
 | 
            //更新用户绑定的钉钉信息 
 | 
            companyUserExtMapper.updateById(cu); 
 | 
            return (String)subject.getSession().getId(); 
 | 
        } catch (AuthenticationException e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        }catch (Exception e) { 
 | 
            log.error(ResponseStatus.ACCOUNT_INCORRECT.getMessage(), e); 
 | 
            loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); 
 | 
            loginLog.setSuccess(Boolean.FALSE); 
 | 
            systemLoginLogService.create(loginLog); 
 | 
            throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); 
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |