|
@@ -2,6 +2,7 @@ package com.hys.app.service.system.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -264,6 +265,85 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
return adminUserMapper.selectOne(wrapper);
|
|
return adminUserMapper.selectOne(wrapper);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public AdminLoginVO loginByPhone(String phone, String companyName, String type) {
|
|
|
|
+ CompanyErp company = null;
|
|
|
|
+ if ("com".equals(type) && StrUtil.isNotBlank(companyName)) {
|
|
|
|
+ if (StrUtil.isBlank(companyName)) {
|
|
|
|
+ throw new ServiceException("非平台工作人员公司必填");
|
|
|
|
+ }
|
|
|
|
+ company = companyManager.getOne(new LambdaQueryWrapper<CompanyErp>().eq(CompanyErp::getName,companyName));
|
|
|
|
+ if (ObjectUtil.isNull(company)) {
|
|
|
|
+ throw new ServiceException("该公司未注册");
|
|
|
|
+ }
|
|
|
|
+ //0
|
|
|
|
+ if (company.getStatus() != 1) {
|
|
|
|
+ throw new ServiceException("公司状态异常,限制登录,联系管理员申请解除限制");
|
|
|
|
+ }
|
|
|
|
+ if (new Date().compareTo(company.getEndUseTime()) > 0) {
|
|
|
|
+ throw new ServiceException("该公司使用已到期,请续费");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询管理员信息
|
|
|
|
+ LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<AdminUser>()
|
|
|
|
+ .eq(AdminUser::getPhone, phone)
|
|
|
|
+ .eq(AdminUser::getUserState, 0);
|
|
|
|
+ if ("com".equals(type)) {
|
|
|
|
+ queryWrapper.eq(AdminUser::getCompanyId, company.getId());
|
|
|
|
+ }else if ("sys".equals(type)){
|
|
|
|
+ queryWrapper.isNull(AdminUser::getCompanyId);
|
|
|
|
+ queryWrapper.eq(AdminUser::getFounder,1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ AdminUser adminUser = adminUserMapper.selectOne(queryWrapper);
|
|
|
|
+ //管理员信息不存在
|
|
|
|
+ if (adminUser == null ) {
|
|
|
|
+ throw new ServiceException(SystemErrorCode.E918.code(), "账号不存在");
|
|
|
|
+ }
|
|
|
|
+ if (adminUser.getFounder() != 1) {
|
|
|
|
+ if (!adminUser.getCompanyId().equals(company.getId())) {
|
|
|
|
+ throw new ServiceException("此账号不属于该公司");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+// if ("admin".equals(name) && password.equals(adminUser.getFirstPassword())){
|
|
|
|
+// throw new ServiceException("第一次登录需修改密码");
|
|
|
|
+// }
|
|
|
|
+ //返回管理员信息
|
|
|
|
+ AdminLoginVO adminLoginVO = new AdminLoginVO();
|
|
|
|
+ adminLoginVO.setUid(adminUser.getId());
|
|
|
|
+
|
|
|
|
+ adminLoginVO.setUsername(adminUser.getUsername());
|
|
|
|
+ adminLoginVO.setCompanyVo(company);
|
|
|
|
+ adminLoginVO.setDepartment(adminUser.getDepartment());
|
|
|
|
+ adminLoginVO.setFace(adminUser.getFace());
|
|
|
|
+ adminLoginVO.setRoleId(adminUser.getRoleId());
|
|
|
|
+ adminLoginVO.setFounder(adminUser.getFounder());
|
|
|
|
+ adminLoginVO.setDeptId(adminUser.getDeptId());
|
|
|
|
+ adminLoginVO.setHasDeptManager(adminUser.getHasDeptManager());
|
|
|
|
+ // 设置访问token的失效时间维持管理员在线状态
|
|
|
|
+ if (adminUser.getFounder() != 1) {
|
|
|
|
+ adminUser.setCompanyId(company.getId());
|
|
|
|
+ }
|
|
|
|
+ Token token = createToken(adminUser);
|
|
|
|
+
|
|
|
|
+ String accessToken = token.getAccessToken();
|
|
|
|
+ String refreshToken = token.getRefreshToken();
|
|
|
|
+
|
|
|
|
+ adminLoginVO.setAccessToken(accessToken);
|
|
|
|
+ adminLoginVO.setRefreshToken(refreshToken);
|
|
|
|
+
|
|
|
|
+ //记录登录日志
|
|
|
|
+ addLoginLog(adminUser, phone, null);
|
|
|
|
+
|
|
|
|
+ return adminLoginVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 管理员登录
|
|
* 管理员登录
|
|
*
|
|
*
|
|
@@ -272,16 +352,32 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public AdminLoginVO login(String name, String password, Long companyId, String type) {
|
|
|
|
|
|
+ public AdminLoginVO login(String name, String password, String companyName, String type) {
|
|
|
|
+
|
|
|
|
+ CompanyErp company = null;
|
|
|
|
+ if ("com".equals(type) && StrUtil.isNotBlank(companyName)) {
|
|
|
|
+ if (StrUtil.isBlank(companyName)) {
|
|
|
|
+ throw new ServiceException("非平台工作人员公司必填");
|
|
|
|
+ }
|
|
|
|
+ company = companyManager.getOne(new LambdaQueryWrapper<CompanyErp>().eq(CompanyErp::getName,companyName));
|
|
|
|
+ if (ObjectUtil.isNull(company)) {
|
|
|
|
+ throw new ServiceException("该公司未注册");
|
|
|
|
+ }
|
|
|
|
+ if (company.getStatus() != 1) {
|
|
|
|
+ throw new ServiceException("公司状态异常,限制登录,联系管理员申请解除限制");
|
|
|
|
+ }
|
|
|
|
+ if (new Date().compareTo(company.getEndUseTime()) > 0) {
|
|
|
|
+ throw new ServiceException("该公司使用已到期,请续费");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- String lowerCase = StringUtil.md5(name + password + companyId).toLowerCase();
|
|
|
|
//查询管理员信息
|
|
//查询管理员信息
|
|
LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<AdminUser>()
|
|
LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<AdminUser>()
|
|
.eq(AdminUser::getUsername, name)
|
|
.eq(AdminUser::getUsername, name)
|
|
.eq(AdminUser::getUserState, 0);
|
|
.eq(AdminUser::getUserState, 0);
|
|
- if ("com".equals(type) && ObjectUtil.isNotNull(companyId)) {
|
|
|
|
- queryWrapper.eq(AdminUser::getCompanyId, companyId);
|
|
|
|
- queryWrapper.eq(AdminUser::getPassword, StringUtil.md5(name + password + companyId).toLowerCase());
|
|
|
|
|
|
+ if ("com".equals(type)) {
|
|
|
|
+ queryWrapper.eq(AdminUser::getCompanyId, company.getId());
|
|
|
|
+ queryWrapper.eq(AdminUser::getPassword, StringUtil.md5(name + password + company.getId()).toLowerCase());
|
|
} else {
|
|
} else {
|
|
queryWrapper.eq(AdminUser::getPassword, StringUtil.md5(name + password).toLowerCase());
|
|
queryWrapper.eq(AdminUser::getPassword, StringUtil.md5(name + password).toLowerCase());
|
|
}
|
|
}
|
|
@@ -290,26 +386,10 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
if (adminUser == null || !StringUtil.equals(adminUser.getUsername(), name)) {
|
|
if (adminUser == null || !StringUtil.equals(adminUser.getUsername(), name)) {
|
|
throw new ServiceException(SystemErrorCode.E918.code(), "管理员账号密码错误");
|
|
throw new ServiceException(SystemErrorCode.E918.code(), "管理员账号密码错误");
|
|
}
|
|
}
|
|
- CompanyErp company = null;
|
|
|
|
if (adminUser.getFounder() != 1) {
|
|
if (adminUser.getFounder() != 1) {
|
|
- if (ObjectUtil.isNull(companyId)) {
|
|
|
|
- throw new ServiceException("非平台工作人员公司必填");
|
|
|
|
- }
|
|
|
|
- company = companyManager.getById(companyId);
|
|
|
|
- if (ObjectUtil.isNull(company)) {
|
|
|
|
- throw new ServiceException("该公司未注册");
|
|
|
|
- }
|
|
|
|
- if (!company.getStatus()) {
|
|
|
|
- throw new ServiceException("公司状态异常,限制登录,联系管理员申请解除限制");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (!adminUser.getCompanyId().equals(company.getId())) {
|
|
if (!adminUser.getCompanyId().equals(company.getId())) {
|
|
throw new ServiceException("此账号不属于该公司");
|
|
throw new ServiceException("此账号不属于该公司");
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (new Date().compareTo(company.getEndUseTime()) > 0) {
|
|
|
|
- throw new ServiceException("该公司使用已到期,请续费");
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
// if ("admin".equals(name) && password.equals(adminUser.getFirstPassword())){
|
|
// if ("admin".equals(name) && password.equals(adminUser.getFirstPassword())){
|
|
// throw new ServiceException("第一次登录需修改密码");
|
|
// throw new ServiceException("第一次登录需修改密码");
|
|
@@ -487,6 +567,7 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 记录登录日志
|
|
* 记录登录日志
|
|
*
|
|
*
|
|
@@ -506,6 +587,7 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
systemLogs.setSellerId(0L);
|
|
systemLogs.setSellerId(0L);
|
|
systemLogs.setLevel(LogLevel.important.name());
|
|
systemLogs.setLevel(LogLevel.important.name());
|
|
systemLogs.setClient(LogClient.admin.name());
|
|
systemLogs.setClient(LogClient.admin.name());
|
|
|
|
+ systemLogs.setCompanyId(AdminUserContext.getCompanyId());
|
|
systemLogsManager.add(systemLogs);
|
|
systemLogsManager.add(systemLogs);
|
|
}
|
|
}
|
|
}
|
|
}
|