mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
机构增加有效期以及用户数量
This commit is contained in:
@@ -4,6 +4,10 @@ import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class CreateOrganizationDto extends CommonDto {
|
||||
|
||||
@@ -11,4 +15,14 @@ public class CreateOrganizationDto extends CommonDto {
|
||||
|
||||
private String orgAdminUserName;
|
||||
private String orgAdminPassword;
|
||||
|
||||
|
||||
|
||||
@Comment("最大用户数量")
|
||||
private Integer maxUser;
|
||||
|
||||
|
||||
|
||||
@Comment("过期时间")
|
||||
private LocalDateTime expireTime;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
package cn.lihongjie.coal.organization.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class OrganizationDto extends CommonDto {
|
||||
|
||||
private String parentId;
|
||||
|
||||
@Comment("最大用户数量")
|
||||
private Integer maxUser;
|
||||
|
||||
|
||||
|
||||
@Comment("过期时间")
|
||||
private LocalDateTime expireTime;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,21 @@ import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class UpdateOrganizationDto extends CommonDto {
|
||||
|
||||
private String parentId;
|
||||
|
||||
|
||||
@Comment("最大用户数量")
|
||||
private Integer maxUser;
|
||||
|
||||
|
||||
|
||||
@Comment("过期时间")
|
||||
private LocalDateTime expireTime;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import lombok.Setter;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@@ -28,4 +29,19 @@ public class OrganizationEntity extends CommonEntity {
|
||||
@JsonBackReference
|
||||
@JoinColumn(name = "parent_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
|
||||
private OrganizationEntity parent;
|
||||
|
||||
|
||||
@Comment("最大用户数量")
|
||||
private Integer maxUser;
|
||||
|
||||
|
||||
|
||||
@Comment("过期时间")
|
||||
private LocalDateTime expireTime;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@@ -107,6 +109,8 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
adminOrg.setParent(null);
|
||||
adminOrg.setName("管理员机构");
|
||||
adminOrg.setCode("adminOrg");
|
||||
adminOrg.setMaxUser(100);
|
||||
adminOrg.setExpireTime(LocalDateTime.now().plusYears(100));
|
||||
adminOrg.setStatus(1);
|
||||
|
||||
this.repository.save(adminOrg);
|
||||
|
||||
@@ -139,6 +139,10 @@ public class SessionService {
|
||||
throw new BizException("用户所在机构被禁用");
|
||||
}
|
||||
|
||||
if (organization.getExpireTime()!=null && organization.getExpireTime().isBefore(LocalDateTime.now())) {
|
||||
throw new BizException("用户所在机构已过期");
|
||||
}
|
||||
|
||||
if (!userService.isValidPassword(dto.getPassword(), user.getPassword())) {
|
||||
throw new BizException("用户名或者密码错误");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.lihongjie.coal.user.repository;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@@ -11,4 +12,7 @@ public interface UserRepository extends BaseRepository<UserEntity> {
|
||||
UserEntity findByUsername(String username);
|
||||
|
||||
int countByUsername(String username);
|
||||
|
||||
@Query("select count(u) from UserEntity u where u.organizationId = ?1")
|
||||
Integer countByOrganizationId(String organizationId);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import cn.lihongjie.coal.common.Constants;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.organization.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.organization.service.OrganizationService;
|
||||
import cn.lihongjie.coal.permission.dto.PermissionSimpleDto;
|
||||
import cn.lihongjie.coal.permission.entity.PermissionEntity;
|
||||
import cn.lihongjie.coal.permission.mapper.PermissionMapper;
|
||||
@@ -72,8 +73,20 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
||||
passwordEncoder = new Pbkdf2PasswordEncoder("", 8, 10000, 256);
|
||||
}
|
||||
|
||||
@Autowired OrganizationService organizationService;
|
||||
|
||||
public UserDto create(CreateUserDto request) {
|
||||
|
||||
String organizationId = Ctx.currentUser().getOrganizationId();
|
||||
|
||||
OrganizationEntity organization = organizationService.get(organizationId);
|
||||
|
||||
if (organization.getMaxUser() != null
|
||||
&& organization.getMaxUser() > 0
|
||||
&& organization.getMaxUser() <= repository.countByOrganizationId(organizationId)) {
|
||||
throw new BizException("用户数量已经达到上限 " + organization.getMaxUser() + " 个");
|
||||
}
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
|
||||
checkDuplicateUserName(request.getUsername());
|
||||
|
||||
Reference in New Issue
Block a user