|  |  |  | 
|---|
|  |  |  | package com.doumee.service.system.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.doumee.config.jwt.JwtTokenUtil; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.model.LoginUserInfo; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.dao.SmsEmailMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Company; | 
|---|
|  |  |  | import com.doumee.dao.business.model.SmsEmail; | 
|---|
|  |  |  | import com.doumee.dao.system.SystemUserMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.dto.LoginByOpenidDTO; | 
|---|
|  |  |  | import com.doumee.dao.system.dto.LoginDTO; | 
|---|
|  |  |  | import com.doumee.dao.system.dto.LoginPhoneDTO; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Lazy | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemUserService systemUserService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemUserMapper systemUserMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SmsEmailMapper smsEmailMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | loginLog.setLoginTime(new Date()); | 
|---|
|  |  |  | loginLog.setSystemVersion(systemVersion); | 
|---|
|  |  |  | loginLog.setIp(Utils.User_Client.getIP(request)); | 
|---|
|  |  |  | loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | //        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.setLoginUsername(dto.getUsername()); | 
|---|
|  |  |  | loginLog.setLoginTime(new Date()); | 
|---|
|  |  |  | loginLog.setSystemVersion(systemVersion); | 
|---|
|  |  |  | loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | //        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | if(request!=null&&request.getHeaders()!=null && request.getHeaders().size()>0){ | 
|---|
|  |  |  | loginLog.setIp(Utils.User_Client.getIP(request)); | 
|---|
|  |  |  | loginLog.setPlatform(Utils.User_Client.getPlatform(request)); | 
|---|
|  |  |  | 
|---|
|  |  |  | loginLog.setOsInfo(Utils.User_Client.getOS(request)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | loginLog.setServerIp(Utils.Server.getIP()); | 
|---|
|  |  |  | if(isDebug == null  || !isDebug  && dto.getCheckCode()){ | 
|---|
|  |  |  | //        if(isDebug == null  || !isDebug  && dto.getCheckCode()){ | 
|---|
|  |  |  | // 校验验证码 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | captchaService.check(dto.getUuid(), dto.getCode()); | 
|---|
|  |  |  | 
|---|
|  |  |  | systemLoginLogService.create(loginLog); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT.getCode(),"对不起,验证码不正确!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // 根据用户名查询用户对象 | 
|---|
|  |  |  | SystemUser queryDto = new SystemUser(); | 
|---|
|  |  |  | queryDto.setUsername(dto.getUsername()); | 
|---|
|  |  |  | 
|---|
|  |  |  | if( !StringUtils.equals(pwd, user.getPassword())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | dealOpenIdBiz(user,dto.getOpenid()); | 
|---|
|  |  |  | Company company = new Company(); | 
|---|
|  |  |  | if(Objects.nonNull(user.getCompanyId())){ | 
|---|
|  |  |  | company = companyMapper.selectById(user.getCompanyId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | return  userInfo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void dealOpenIdBiz(SystemUser user, String openid) { | 
|---|
|  |  |  | if(StringUtils.isNotBlank(openid)){ | 
|---|
|  |  |  | //如果openId不为空,绑定该用户openid | 
|---|
|  |  |  | systemUserMapper.update(null,new UpdateWrapper<SystemUser>().lambda() | 
|---|
|  |  |  | .set(SystemUser::getOpenid,null) | 
|---|
|  |  |  | .set(SystemUser::getOpenidHkDate,null) | 
|---|
|  |  |  | .set(SystemUser::getOpenidHkInfo,null) | 
|---|
|  |  |  | .set(SystemUser::getOpenidHkStatus,Constants.ZERO) | 
|---|
|  |  |  | .eq(SystemUser::getOpenid,openid) | 
|---|
|  |  |  | .eq(SystemUser::getType,user.getType())); | 
|---|
|  |  |  | systemUserMapper.update(null,new UpdateWrapper<SystemUser>().lambda() | 
|---|
|  |  |  | .set(SystemUser::getOpenid,openid) | 
|---|
|  |  |  | .set(SystemUser::getOpenidHkStatus,Constants.ZERO) | 
|---|
|  |  |  | .set(SystemUser::getOpenidHkDate,null) | 
|---|
|  |  |  | .set(SystemUser::getOpenidHkInfo,null) | 
|---|
|  |  |  | .eq(SystemUser::getId,user.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | loginLog.setLoginUsername(dto.getPhone()); | 
|---|
|  |  |  | loginLog.setLoginTime(new Date()); | 
|---|
|  |  |  | loginLog.setSystemVersion(systemVersion); | 
|---|
|  |  |  | loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | //        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | if(request!=null&&request.getHeaders()!=null && request.getHeaders().size()>0){ | 
|---|
|  |  |  | loginLog.setIp(Utils.User_Client.getIP(request)); | 
|---|
|  |  |  | loginLog.setPlatform(Utils.User_Client.getPlatform(request)); | 
|---|
|  |  |  | 
|---|
|  |  |  | SystemLoginLog loginLog = new SystemLoginLog(); | 
|---|
|  |  |  | loginLog.setLoginUsername(dto.getUsername()); | 
|---|
|  |  |  | loginLog.setLoginTime(new Date()); | 
|---|
|  |  |  | loginLog.setReason("【公众号】司机端登陆:openid="+dto.getOpenid()); | 
|---|
|  |  |  | loginLog.setSystemVersion(systemVersion); | 
|---|
|  |  |  | loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | //        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | if(request!=null&&request.getHeaders()!=null && request.getHeaders().size()>0){ | 
|---|
|  |  |  | loginLog.setIp(Utils.User_Client.getIP(request)); | 
|---|
|  |  |  | loginLog.setPlatform(Utils.User_Client.getPlatform(request)); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (user == null) { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //注册司机/劳务人员 | 
|---|
|  |  |  | if((Constants.equalsInteger(user.getType(),Constants.ZERO)||Constants.equalsInteger(user.getType(),Constants.TWO)) && Objects.nonNull(user.getMemberId())){ | 
|---|
|  |  |  | if(Constants.equalsInteger(user.getType(),Constants.TWO)){ | 
|---|
|  |  |  | if(Objects.isNull(user.getCompanyId())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Company company = companyMapper.selectById(user.getCompanyId()); | 
|---|
|  |  |  | if(Objects.isNull(company) || Constants.equalsInteger(company.getType(),Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String pwd = Utils.Secure.encryptPassword(new String(dto.getPassword()), user.getSalt()); | 
|---|
|  |  |  | // 比较密码 | 
|---|
|  |  |  | if( !StringUtils.equals(pwd, user.getPassword())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | dealOpenIdBiz(user,dto.getOpenid()); | 
|---|
|  |  |  | Company company = new Company(); | 
|---|
|  |  |  | if(Objects.nonNull(user.getCompanyId())){ | 
|---|
|  |  |  | company = companyMapper.selectById(user.getCompanyId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | SystemLoginLog loginLog = new SystemLoginLog(); | 
|---|
|  |  |  | loginLog.setLoginTime(new Date()); | 
|---|
|  |  |  | loginLog.setSystemVersion(systemVersion); | 
|---|
|  |  |  | loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | //        loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
|---|
|  |  |  | loginLog.setServerIp(Utils.Server.getIP()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 根据用户名查询用户对象 | 
|---|