|
@@ -13,14 +13,12 @@ import com.hys.app.framework.context.user.AdminUserContext;
|
|
|
import com.hys.app.framework.database.WebPage;
|
|
|
import com.hys.app.framework.exception.ResourceNotFoundException;
|
|
|
import com.hys.app.framework.exception.ServiceException;
|
|
|
-import com.hys.app.framework.redis.RedisChannel;
|
|
|
import com.hys.app.framework.security.TokenManager;
|
|
|
-import com.hys.app.framework.security.message.UserDisableMsg;
|
|
|
import com.hys.app.framework.security.model.Admin;
|
|
|
-import com.hys.app.framework.security.model.Role;
|
|
|
import com.hys.app.framework.util.*;
|
|
|
import com.hys.app.mapper.system.AdminUserMapper;
|
|
|
-import com.hys.app.model.erp.entity.Company;
|
|
|
+import com.hys.app.mapper.system.DeptMapper;
|
|
|
+import com.hys.app.model.erp.entity.CompanyErp;
|
|
|
import com.hys.app.model.errorcode.SystemErrorCode;
|
|
|
import com.hys.app.model.support.LogClient;
|
|
|
import com.hys.app.model.support.validator.annotation.LogLevel;
|
|
@@ -31,9 +29,8 @@ import com.hys.app.model.system.dos.SystemLogs;
|
|
|
import com.hys.app.model.system.dto.AdminUserDTO;
|
|
|
import com.hys.app.model.system.vo.AdminLoginVO;
|
|
|
import com.hys.app.model.system.vo.AdminUserVO;
|
|
|
-import com.hys.app.service.erp.CompanyManager;
|
|
|
+import com.hys.app.service.erp.CompanyErpManager;
|
|
|
import com.hys.app.service.system.AdminUserManager;
|
|
|
-import com.hys.app.service.system.DeptManager;
|
|
|
import com.hys.app.service.system.RoleManager;
|
|
|
import com.hys.app.service.system.SystemLogsManager;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -69,7 +66,9 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
@Autowired
|
|
|
private SystemLogsManager systemLogsManager;
|
|
|
@Autowired
|
|
|
- private CompanyManager companyManager;
|
|
|
+ private CompanyErpManager companyManager;
|
|
|
+ @Autowired
|
|
|
+ private DeptMapper deptMapper;
|
|
|
private List<Long> ids = new ArrayList<>();
|
|
|
|
|
|
/**
|
|
@@ -82,8 +81,12 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
*/
|
|
|
@Override
|
|
|
public WebPage list(long page, long pageSize, String keyword, Integer userState) {
|
|
|
-
|
|
|
- IPage<AdminUserDTO> iPage = adminUserMapper.selectPageDto(new Page<>(page, pageSize), keyword, userState);
|
|
|
+ IPage<AdminUserDTO> iPage;
|
|
|
+ if (ObjectUtil.isNotNull(AdminUserContext.getCompanyId())) {
|
|
|
+ iPage = adminUserMapper.selectPageDto(new Page<>(page, pageSize), keyword, userState, AdminUserContext.getCompanyId());
|
|
|
+ } else {
|
|
|
+ iPage = adminUserMapper.selectPageDto(new Page<>(page, pageSize), keyword, userState, null);
|
|
|
+ }
|
|
|
return PageConvert.convert(iPage);
|
|
|
}
|
|
|
|
|
@@ -101,6 +104,12 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
if (!bool) {
|
|
|
throw new ServiceException(SystemErrorCode.E917.code(), "密码格式不正确");
|
|
|
}
|
|
|
+ DeptDO deptDO = deptMapper.selectById(adminUserVO.getDeptId());
|
|
|
+ if (ObjectUtil.isNull(deptDO)) {
|
|
|
+ throw new ServiceException("部门不存在");
|
|
|
+ }
|
|
|
+ adminUserVO.setRoleId(deptDO.getRoleId());
|
|
|
+
|
|
|
//校验用户名称是否重复
|
|
|
QueryWrapper<AdminUser> wrapper = new QueryWrapper<>();
|
|
|
wrapper.eq("username", adminUserVO.getUsername()).eq("user_state", 0);
|
|
@@ -116,18 +125,23 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
// throw new ResourceNotFoundException("所属权限不存在");
|
|
|
// }
|
|
|
// }
|
|
|
- Company company = companyManager.getById(AdminUserContext.getCompanyId());
|
|
|
+ CompanyErp company = companyManager.getById(AdminUserContext.getCompanyId());
|
|
|
+ Long count = adminUserMapper.selectCount(new LambdaQueryWrapper<AdminUser>().eq(AdminUser::getCompanyId, company.getId()));
|
|
|
+ if (count + 1 > company.getUserNum()) {
|
|
|
+ throw new ServiceException("超过最大账号创建数量,如有需要请联系平台管理员更换套餐");
|
|
|
+ }
|
|
|
//管理员信息入库
|
|
|
String password = adminUserVO.getPassword();
|
|
|
AdminUser adminUser = new AdminUser();
|
|
|
adminUser.setCompanyId(company.getId());
|
|
|
- adminUser.setRoleId(company.getRoleId());
|
|
|
BeanUtil.copyProperties(adminUserVO, adminUser);
|
|
|
adminUser.setPassword(StringUtil.md5(password + adminUser.getUsername().toLowerCase()));
|
|
|
adminUser.setDateLine(DateUtil.getDateline());
|
|
|
adminUser.setUserState(0);
|
|
|
+ adminUser.setFounder(0);
|
|
|
adminUserMapper.insert(adminUser);
|
|
|
|
|
|
+
|
|
|
return adminUser;
|
|
|
}
|
|
|
|
|
@@ -144,25 +158,25 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
//对要修改的管理员是否存在进行校验
|
|
|
AdminUser adminUser = this.getModel(id);
|
|
|
if (adminUser == null) {
|
|
|
- throw new ResourceNotFoundException("当前管理员不存在");
|
|
|
+ throw new ResourceNotFoundException("需要修改的账号不存在");
|
|
|
}
|
|
|
- if (!Objects.equals(AdminUserContext.getAdminUserId(), id)){
|
|
|
- throw new ServiceException("你无权修改此账号");
|
|
|
+ if (!Objects.equals(AdminUserContext.getCompanyId(), adminUser.getCompanyId())) {
|
|
|
+ throw new ServiceException("只能修改自己公司的账号");
|
|
|
}
|
|
|
- if ("admin".equals(adminUser.getUsername()) && !"admin".equals(adminUserVO.getUsername())){
|
|
|
+ if ("admin".equals(adminUser.getUsername()) && !"admin".equals(adminUserVO.getUsername())) {
|
|
|
throw new ServiceException("admin 登录名称不允许修改");
|
|
|
}
|
|
|
- //如果修改的是从超级管理员到普通管理员 需要校验此管理员是否是最后一个超级管理员
|
|
|
- if (adminUser.getFounder().equals(1) && !adminUserVO.getFounder().equals(1)) {
|
|
|
-
|
|
|
- QueryWrapper<AdminUser> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("founder", 1).eq("user_state", 0);
|
|
|
- List<AdminUser> adminUsers = adminUserMapper.selectList(wrapper);
|
|
|
-
|
|
|
- if (adminUsers.size() <= 1) {
|
|
|
- throw new ServiceException(SystemErrorCode.E916.code(), "必须保留一个超级管理员");
|
|
|
- }
|
|
|
- }
|
|
|
+// //如果修改的是从超级管理员到普通管理员 需要校验此管理员是否是最后一个超级管理员
|
|
|
+// if (adminUser.getFounder().equals(1) && !adminUserVO.getFounder().equals(1)) {
|
|
|
+//
|
|
|
+// QueryWrapper<AdminUser> wrapper = new QueryWrapper<>();
|
|
|
+// wrapper.eq("founder", 1).eq("user_state", 0);
|
|
|
+// List<AdminUser> adminUsers = adminUserMapper.selectList(wrapper);
|
|
|
+//
|
|
|
+// if (adminUsers.size() <= 1) {
|
|
|
+// throw new ServiceException(SystemErrorCode.E916.code(), "必须保留一个超级管理员");
|
|
|
+// }
|
|
|
+// }
|
|
|
// if (!adminUserVO.getFounder().equals(1)) {
|
|
|
// RoleDO roleDO = roleManager.getModel(adminUserVO.getRoleId());
|
|
|
// if (roleDO == null) {
|
|
@@ -204,25 +218,25 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
if (adminUser == null) {
|
|
|
throw new ResourceNotFoundException("当前管理员不存在");
|
|
|
}
|
|
|
- if ("admin".equals(adminUser.getUsername())){
|
|
|
+ if ("admin".equals(adminUser.getUsername())) {
|
|
|
throw new ResourceNotFoundException("管理员不能删除");
|
|
|
}
|
|
|
- //校验要删除的管理员是否是最后一个超级管理员
|
|
|
- QueryWrapper<AdminUser> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("founder", 1).eq("user_state", 0);
|
|
|
- List<AdminUser> adminUsers = adminUserMapper.selectList(wrapper);
|
|
|
-
|
|
|
- if (adminUsers.size() <= 1 && adminUser.getFounder().equals(1)) {
|
|
|
- throw new ServiceException(SystemErrorCode.E916.code(), "必须保留一个超级管理员");
|
|
|
- }
|
|
|
+// //校验要删除的管理员是否是最后一个超级管理员
|
|
|
+// QueryWrapper<AdminUser> wrapper = new QueryWrapper<>();
|
|
|
+// wrapper.eq("founder", 1).eq("user_state", 0);
|
|
|
+// List<AdminUser> adminUsers = adminUserMapper.selectList(wrapper);
|
|
|
+//
|
|
|
+// if (adminUsers.size() <= 1 && adminUser.getFounder().equals(1)) {
|
|
|
+// throw new ServiceException(SystemErrorCode.E916.code(), "必须保留一个超级管理员");
|
|
|
+// }
|
|
|
// 设置管理员状态为删除
|
|
|
adminUser.setUserState(-1);
|
|
|
adminUserMapper.updateById(adminUser);
|
|
|
|
|
|
- //发送redis订阅消息,通知各个节点此用户已经禁用
|
|
|
- UserDisableMsg userDisableMsg = new UserDisableMsg(id, Role.ADMIN, UserDisableMsg.ADD);
|
|
|
- String msgJson = JsonUtil.objectToJson(userDisableMsg);
|
|
|
- redisTemplate.convertAndSend(RedisChannel.USER_DISABLE, msgJson);
|
|
|
+// //发送redis订阅消息,通知各个节点此用户已经禁用
|
|
|
+// UserDisableMsg userDisableMsg = new UserDisableMsg(id, Role.ADMIN, UserDisableMsg.ADD);
|
|
|
+// String msgJson = JsonUtil.objectToJson(userDisableMsg);
|
|
|
+// redisTemplate.convertAndSend(RedisChannel.USER_DISABLE, msgJson);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -253,35 +267,44 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public AdminLoginVO login(String name, String password,String companyName) {
|
|
|
+ public AdminLoginVO login(String name, String password, Long companyId, String type) {
|
|
|
+
|
|
|
//查询管理员信息
|
|
|
- QueryWrapper<AdminUser> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("username", name).eq("password", StringUtil.md5(password + name.toLowerCase())).eq("user_state", 0);
|
|
|
- AdminUser adminUser = adminUserMapper.selectOne(wrapper);
|
|
|
+ LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<AdminUser>()
|
|
|
+ .eq(AdminUser::getUsername, name)
|
|
|
+ .eq(AdminUser::getPassword, password).eq(AdminUser::getUserState, 0);
|
|
|
+ if ("com".equals(type) && ObjectUtil.isNotNull(companyId)) {
|
|
|
+ queryWrapper.eq(AdminUser::getCompanyId, companyId);
|
|
|
+ }
|
|
|
+ AdminUser adminUser = adminUserMapper.selectOne(queryWrapper);
|
|
|
//管理员信息不存在
|
|
|
if (adminUser == null || !StringUtil.equals(adminUser.getUsername(), name)) {
|
|
|
throw new ServiceException(SystemErrorCode.E918.code(), "管理员账号密码错误");
|
|
|
}
|
|
|
- Company company=null;
|
|
|
- if (adminUser.getFounder() != 1){
|
|
|
- if (ObjectUtil.isNull(companyName)){
|
|
|
+ CompanyErp company = null;
|
|
|
+ if (adminUser.getFounder() != 1) {
|
|
|
+ if (ObjectUtil.isNull(companyId)) {
|
|
|
throw new ServiceException("非平台工作人员公司必填");
|
|
|
}
|
|
|
- company = companyManager.getOne(new LambdaQueryWrapper<Company>().eq(Company::getName,companyName));
|
|
|
- if (ObjectUtil.isNull(company)){
|
|
|
+ company = companyManager.getById(companyId);
|
|
|
+ if (ObjectUtil.isNull(company)) {
|
|
|
throw new ServiceException("该公司未注册");
|
|
|
}
|
|
|
- if (adminUser.getCompanyId() != company.getCompanyId()){
|
|
|
+ if (!adminUser.getCompanyId().equals(company.getId())) {
|
|
|
throw new ServiceException("此账号不属于该公司");
|
|
|
}
|
|
|
- if (LocalDateTime.now().isAfter(company.getEndUseTime())){
|
|
|
+
|
|
|
+ if (new Date().compareTo(company.getEndUseTime()) > 0) {
|
|
|
throw new ServiceException("该公司使用已到期,请续费");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+// if ("admin".equals(name) && password.equals(adminUser.getFirstPassword())){
|
|
|
+// throw new ServiceException("第一次登录需修改密码");
|
|
|
+// }
|
|
|
//返回管理员信息
|
|
|
AdminLoginVO adminLoginVO = new AdminLoginVO();
|
|
|
adminLoginVO.setUid(adminUser.getId());
|
|
|
+
|
|
|
adminLoginVO.setUsername(name);
|
|
|
adminLoginVO.setCompanyVo(company);
|
|
|
adminLoginVO.setDepartment(adminUser.getDepartment());
|
|
@@ -289,7 +312,11 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
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();
|
|
@@ -352,8 +379,6 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
admin.setUid(adminUser.getId());
|
|
|
admin.setCompanyId(adminUser.getCompanyId());
|
|
|
admin.setUsername(adminUser.getUsername());
|
|
|
-// admin.setPlatformShopId(platform.getShopId());
|
|
|
-// admin.setPlatformShopName(platform.getShopName());
|
|
|
admin.setFounder(adminUser.getFounder());
|
|
|
if (adminUser.getFounder().equals(1)) {
|
|
|
admin.add("SUPER_ADMIN");
|
|
@@ -361,7 +386,6 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
RoleDO roleDO = this.roleManager.getModel(adminUser.getRoleId());
|
|
|
admin.add(roleDO.getRoleName());
|
|
|
}
|
|
|
-
|
|
|
return tokenManager.create(admin);
|
|
|
|
|
|
}
|
|
@@ -399,10 +423,10 @@ public class AdminUserManagerImpl implements AdminUserManager {
|
|
|
adminUser.setUserState(0);
|
|
|
adminUserMapper.updateById(adminUser);
|
|
|
|
|
|
- //发送redis订阅消息,通知各个节点此用户已经恢复
|
|
|
- UserDisableMsg userDisableMsg = new UserDisableMsg(id, Role.ADMIN, UserDisableMsg.DELETE);
|
|
|
- String msgJson = JsonUtil.objectToJson(userDisableMsg);
|
|
|
- redisTemplate.convertAndSend(RedisChannel.USER_DISABLE, msgJson);
|
|
|
+// //发送redis订阅消息,通知各个节点此用户已经恢复
|
|
|
+// UserDisableMsg userDisableMsg = new UserDisableMsg(id, Role.ADMIN, UserDisableMsg.DELETE);
|
|
|
+// String msgJson = JsonUtil.objectToJson(userDisableMsg);
|
|
|
+// redisTemplate.convertAndSend(RedisChannel.USER_DISABLE, msgJson);
|
|
|
}
|
|
|
|
|
|
@Override
|