mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-03-25 12:53:43 +08:00
fix bugs
This commit is contained in:
@@ -6,12 +6,14 @@ import com.zl.mjga.dto.PageRequestDto;
|
||||
import com.zl.mjga.dto.PageResponseDto;
|
||||
import com.zl.mjga.dto.department.DepartmentQueryDto;
|
||||
import com.zl.mjga.dto.department.DepartmentRespDto;
|
||||
import com.zl.mjga.dto.department.DepartmentWithParentDto;
|
||||
import com.zl.mjga.repository.DepartmentRepository;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.generated.mjga.tables.pojos.Department;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@@ -21,6 +23,30 @@ public class DepartmentService {
|
||||
|
||||
private final DepartmentRepository departmentRepository;
|
||||
|
||||
public List<Department> queryAvailableParentDepartmentsBy(Long id) {
|
||||
List<Department> allDepartments = departmentRepository.findAll();
|
||||
if (id != null) {
|
||||
List<DepartmentWithParentDto> departmentWithParentList = queryDepartmentAndSubsBy(id);
|
||||
allDepartments.removeIf(
|
||||
department -> {
|
||||
return departmentWithParentList.stream()
|
||||
.anyMatch(
|
||||
(departmentWithParentDto -> {
|
||||
return departmentWithParentDto.getId().equals(department.getId());
|
||||
}));
|
||||
});
|
||||
}
|
||||
return allDepartments;
|
||||
}
|
||||
|
||||
public void upsertDepartment(Department department) {
|
||||
departmentRepository.merge(department);
|
||||
}
|
||||
|
||||
public List<DepartmentWithParentDto> queryDepartmentAndSubsBy(Long id) {
|
||||
return departmentRepository.queryDepartmentAndSubsBy(id);
|
||||
}
|
||||
|
||||
public PageResponseDto<List<DepartmentRespDto>> pageQueryDepartment(
|
||||
PageRequestDto pageRequestDto, DepartmentQueryDto departmentQueryDto) {
|
||||
Result<Record> records = departmentRepository.pageFetchBy(pageRequestDto, departmentQueryDto);
|
||||
|
||||
@@ -27,10 +27,13 @@ public class SignService {
|
||||
public Long signIn(SignInDto signInDto) {
|
||||
User user = userRepository.fetchOneByUsername(signInDto.getUsername());
|
||||
if (user == null) {
|
||||
throw new BusinessException(String.format("%s user not found", signInDto.getUsername()));
|
||||
throw new BusinessException("用户名不存在");
|
||||
}
|
||||
if (!passwordEncoder.matches(signInDto.getPassword(), user.getPassword())) {
|
||||
throw new BusinessException("password invalid");
|
||||
throw new BusinessException("密码错误");
|
||||
}
|
||||
if (!user.getEnable()) {
|
||||
throw new BusinessException("用户被禁用");
|
||||
}
|
||||
return user.getId();
|
||||
}
|
||||
@@ -38,8 +41,7 @@ public class SignService {
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public void signUp(SignUpDto signUpDto) {
|
||||
if (identityAccessService.isUsernameDuplicate(signUpDto.getUsername())) {
|
||||
throw new BusinessException(
|
||||
String.format("username %s already exist", signUpDto.getUsername()));
|
||||
throw new BusinessException("用户名已存在");
|
||||
}
|
||||
User user = new User();
|
||||
user.setUsername(signUpDto.getUsername());
|
||||
|
||||
Reference in New Issue
Block a user