mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
基础代码
This commit is contained in:
37
pom.xml
37
pom.xml
@@ -58,6 +58,15 @@
|
||||
<!-- <artifactId>spring-boot-starter-quartz</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>1.5.5.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
@@ -197,10 +206,38 @@
|
||||
<artifactId>ortools-java</artifactId>
|
||||
<version>9.6.2534</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.28</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.5.5.Final</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.PermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/permission")
|
||||
@RestController
|
||||
public class PermissionController {
|
||||
|
||||
@Autowired
|
||||
PermissionService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public PermissionDto create(@RequestBody CreatePermissionDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public PermissionDto update(@RequestBody UpdatePermissionDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<PermissionDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public PermissionDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.ResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/resource")
|
||||
@RestController
|
||||
public class ResourceController {
|
||||
|
||||
@Autowired
|
||||
ResourceService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public ResourceDto create(@RequestBody CreateResourceDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResourceDto update(@RequestBody UpdateResourceDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<ResourceDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public ResourceDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.RoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/Role")
|
||||
@RestController
|
||||
public class RoleController {
|
||||
|
||||
@Autowired
|
||||
RoleService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public RoleDto create(@RequestBody CreateRoleDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public RoleDto update(@RequestBody UpdateRoleDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<RoleDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public RoleDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.dto.IdRequest;
|
||||
import cn.lihongjie.coal.dto.ChangeUserPwdDto;
|
||||
import cn.lihongjie.coal.dto.CreateUserDto;
|
||||
import cn.lihongjie.coal.dto.UpdateUserDto;
|
||||
import cn.lihongjie.coal.dto.UserDto;
|
||||
import cn.lihongjie.coal.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/user")
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
UserService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public UserDto create(@RequestBody CreateUserDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public UserDto update(@RequestBody UpdateUserDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/changePwd")
|
||||
public UserDto create(@RequestBody ChangeUserPwdDto dto) {
|
||||
return this.service.changePwd(dto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<UserDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public UserDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,4 +6,10 @@ import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface BaseRepository<T> extends JpaRepository<T, String>, JpaSpecificationExecutor<T> {
|
||||
|
||||
public default T get(String id){
|
||||
|
||||
return findById(id).orElseThrow(() -> new RuntimeException("数据不存在: " + id));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.PermissionEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PermissionRepository extends BaseRepository<PermissionEntity> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.ResourceEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ResourceRepository extends BaseRepository<ResourceEntity> {
|
||||
}
|
||||
8
src/main/java/cn/lihongjie/coal/dao/RoleRepository.java
Normal file
8
src/main/java/cn/lihongjie/coal/dao/RoleRepository.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.RoleEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface RoleRepository extends BaseRepository<RoleEntity> {
|
||||
}
|
||||
9
src/main/java/cn/lihongjie/coal/dao/UserRepository.java
Normal file
9
src/main/java/cn/lihongjie/coal/dao/UserRepository.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.DictionaryEntity;
|
||||
import cn.lihongjie.coal.entity.UserEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends BaseRepository<UserEntity> {
|
||||
}
|
||||
14
src/main/java/cn/lihongjie/coal/dto/ChangeUserPwdDto.java
Normal file
14
src/main/java/cn/lihongjie/coal/dto/ChangeUserPwdDto.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ChangeUserPwdDto extends CommonDto {
|
||||
|
||||
|
||||
|
||||
private String newPassword;
|
||||
private String newPassword2;
|
||||
|
||||
}
|
||||
16
src/main/java/cn/lihongjie/coal/dto/CreatePermissionDto.java
Normal file
16
src/main/java/cn/lihongjie/coal/dto/CreatePermissionDto.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreatePermissionDto extends CommonDto {
|
||||
|
||||
|
||||
|
||||
private List<String> resources;
|
||||
|
||||
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/CreateResourceDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/CreateResourceDto.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class CreateResourceDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("资源类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("资源地址")
|
||||
private String url;
|
||||
private String parent;
|
||||
}
|
||||
13
src/main/java/cn/lihongjie/coal/dto/CreateRoleDto.java
Normal file
13
src/main/java/cn/lihongjie/coal/dto/CreateRoleDto.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateRoleDto extends OrgCommonDto
|
||||
{
|
||||
|
||||
private List<String> permissions;
|
||||
}
|
||||
34
src/main/java/cn/lihongjie/coal/dto/CreateUserDto.java
Normal file
34
src/main/java/cn/lihongjie/coal/dto/CreateUserDto.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateUserDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("用户名")
|
||||
private String username;
|
||||
|
||||
@Comment("密码")
|
||||
private String password;
|
||||
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
private List<String> roles;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,13 +1,33 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class IdRequest {
|
||||
|
||||
@NotEmpty(message = "ids不能为空")
|
||||
private String id;
|
||||
private List<String> ids;
|
||||
|
||||
public List<String> getIds() {
|
||||
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return ids;
|
||||
} else if (CollectionUtils.isEmpty(ids)) {
|
||||
return Arrays.asList(id);
|
||||
}else {
|
||||
|
||||
|
||||
ArrayList<String> dup = new ArrayList<>(ids);
|
||||
dup.add(id);
|
||||
return dup;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
36
src/main/java/cn/lihongjie/coal/dto/PermissionDto.java
Normal file
36
src/main/java/cn/lihongjie/coal/dto/PermissionDto.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PermissionDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
private List<ResourceDto> resources;
|
||||
|
||||
@Data
|
||||
public static class ResourceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
@OneToMany(mappedBy = "parent")
|
||||
private List<ResourceDto> children;
|
||||
|
||||
|
||||
|
||||
@Comment("资源类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("资源地址")
|
||||
private String url;
|
||||
}
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/ResourceDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/ResourceDto.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class ResourceDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("资源类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("资源地址")
|
||||
private String url;
|
||||
|
||||
}
|
||||
18
src/main/java/cn/lihongjie/coal/dto/RoleDto.java
Normal file
18
src/main/java/cn/lihongjie/coal/dto/RoleDto.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class RoleDto extends OrgCommonDto
|
||||
{
|
||||
|
||||
private List<PermissionDto> permissions;
|
||||
|
||||
@Data
|
||||
public static class PermissionDto extends OrgCommonDto {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateCreateResourceDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("资源类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("资源地址")
|
||||
private String url;
|
||||
|
||||
|
||||
private String parent;
|
||||
|
||||
}
|
||||
16
src/main/java/cn/lihongjie/coal/dto/UpdatePermissionDto.java
Normal file
16
src/main/java/cn/lihongjie/coal/dto/UpdatePermissionDto.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdatePermissionDto extends CommonDto {
|
||||
|
||||
|
||||
|
||||
private List<String> resources;
|
||||
|
||||
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/UpdateResourceDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/UpdateResourceDto.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateResourceDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("资源类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("资源地址")
|
||||
private String url;
|
||||
private String parent;
|
||||
}
|
||||
13
src/main/java/cn/lihongjie/coal/dto/UpdateRoleDto.java
Normal file
13
src/main/java/cn/lihongjie/coal/dto/UpdateRoleDto.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdateRoleDto extends OrgCommonDto
|
||||
{
|
||||
|
||||
private List<String> permissions;
|
||||
}
|
||||
30
src/main/java/cn/lihongjie/coal/dto/UpdateUserDto.java
Normal file
30
src/main/java/cn/lihongjie/coal/dto/UpdateUserDto.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdateUserDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
private List<String> roles;
|
||||
|
||||
|
||||
|
||||
}
|
||||
40
src/main/java/cn/lihongjie/coal/dto/UserDto.java
Normal file
40
src/main/java/cn/lihongjie/coal/dto/UserDto.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import cn.lihongjie.coal.entity.PermissionEntity;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UserDto extends OrgCommonDto {
|
||||
@Comment("用户名")
|
||||
private String username;
|
||||
|
||||
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
|
||||
|
||||
|
||||
@Data
|
||||
public static class RoleDto extends OrgCommonDto{
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<RoleDto> roles;
|
||||
|
||||
}
|
||||
12
src/main/java/cn/lihongjie/coal/dto/base/BaseDto.java
Normal file
12
src/main/java/cn/lihongjie/coal/dto/base/BaseDto.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package cn.lihongjie.coal.dto.base;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class BaseDto {
|
||||
|
||||
private String id;
|
||||
|
||||
}
|
||||
31
src/main/java/cn/lihongjie/coal/dto/base/CommonDto.java
Normal file
31
src/main/java/cn/lihongjie/coal/dto/base/CommonDto.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package cn.lihongjie.coal.dto.base;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class CommonDto extends BaseDto {
|
||||
|
||||
|
||||
@Comment("名称")
|
||||
private String name;
|
||||
|
||||
@Comment("编码")
|
||||
private String code;
|
||||
|
||||
|
||||
@Comment("备注")
|
||||
private String remarks;
|
||||
|
||||
|
||||
|
||||
@Comment("排序键")
|
||||
private Integer sortKey;
|
||||
|
||||
|
||||
@Comment("常用状态 0 禁用 1 启用")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
10
src/main/java/cn/lihongjie/coal/dto/base/OrgCommonDto.java
Normal file
10
src/main/java/cn/lihongjie/coal/dto/base/OrgCommonDto.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package cn.lihongjie.coal.dto.base;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class OrgCommonDto extends CommonDto {
|
||||
private String organizationId;
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package cn.lihongjie.coal.entity;
|
||||
|
||||
import cn.lihongjie.coal.entity.base.CommonEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -18,17 +16,14 @@ public class DictionaryItemEntity extends CommonEntity {
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JsonBackReference
|
||||
private DictionaryEntity dictionary;
|
||||
|
||||
@OneToMany(mappedBy = "parent")
|
||||
@JsonManagedReference
|
||||
private List<DictionaryItemEntity> children;
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JsonBackReference
|
||||
@JoinColumn(name = "parent_id",foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
|
||||
private DictionaryItemEntity parent;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ public class PermissionEntity extends CommonEntity {
|
||||
|
||||
|
||||
@ManyToMany(mappedBy = "permissions")
|
||||
@JsonManagedReference
|
||||
private List<ResourceEntity> resources;
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package cn.lihongjie.coal.entity;
|
||||
|
||||
import cn.lihongjie.coal.entity.base.CommonEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
@@ -15,16 +13,13 @@ import java.util.List;
|
||||
public class ResourceEntity extends CommonEntity {
|
||||
|
||||
@ManyToMany
|
||||
@JsonBackReference
|
||||
private List<PermissionEntity> permissions;
|
||||
|
||||
|
||||
@OneToMany(mappedBy = "parent")
|
||||
@JsonManagedReference
|
||||
private List<ResourceEntity> children;
|
||||
|
||||
@ManyToOne
|
||||
@JsonBackReference
|
||||
@JoinColumn(name = "parent_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
|
||||
private ResourceEntity parent;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.lihongjie.coal.entity;
|
||||
|
||||
import cn.lihongjie.coal.entity.base.OrgBaseEntity;
|
||||
import cn.lihongjie.coal.entity.base.OrgCommonEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
@@ -10,7 +10,10 @@ import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class RoleEntity extends OrgBaseEntity {
|
||||
|
||||
public class RoleEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
|
||||
|
||||
@ManyToMany(mappedBy = "roles")
|
||||
|
||||
@@ -29,8 +29,7 @@ public class UserEntity extends OrgCommonEntity {
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@ManyToMany
|
||||
@JsonManagedReference
|
||||
@ManyToMany()
|
||||
private List<RoleEntity> roles;
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ import java.time.LocalDateTime;
|
||||
@Setter
|
||||
public class BaseEntity {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
private String id;
|
||||
|
||||
@@ -11,6 +11,7 @@ import lombok.Setter;
|
||||
@Setter
|
||||
public class OrgBaseEntity extends BaseEntity {
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "organization_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private OrganizationEntity organization;
|
||||
|
||||
74
src/main/java/cn/lihongjie/coal/mapper/CommonMapper.java
Normal file
74
src/main/java/cn/lihongjie/coal/mapper/CommonMapper.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
import cn.lihongjie.coal.entity.*;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface CommonMapper {
|
||||
|
||||
public default UserEntity createUser(String id) {
|
||||
|
||||
UserEntity user = new UserEntity();
|
||||
|
||||
user.setId(id);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
public default DictionaryEntity createDictionary(String id) {
|
||||
|
||||
DictionaryEntity e = new DictionaryEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
}
|
||||
|
||||
public default DictionaryItemEntity createDictionaryItem(String id) {
|
||||
|
||||
DictionaryItemEntity e = new DictionaryItemEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
}
|
||||
|
||||
public default OperationLog createOperat(String id) {
|
||||
|
||||
OperationLog e = new OperationLog();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
}
|
||||
|
||||
public default OrganizationEntity createOrganization(String id) {
|
||||
|
||||
OrganizationEntity e = new OrganizationEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
}
|
||||
|
||||
public default PermissionEntity createPermission(String id) {
|
||||
|
||||
PermissionEntity e = new PermissionEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
}
|
||||
|
||||
public default ResourceEntity createResource(String id) {
|
||||
|
||||
ResourceEntity e = new ResourceEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
}
|
||||
|
||||
public default RoleEntity createRole(String id) {
|
||||
|
||||
RoleEntity e = new RoleEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
|
||||
}
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/PermissionMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/PermissionMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreatePermissionDto;
|
||||
import cn.lihongjie.coal.dto.UpdatePermissionDto;
|
||||
import cn.lihongjie.coal.dto.PermissionDto;
|
||||
import cn.lihongjie.coal.entity.PermissionEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface PermissionMapper {
|
||||
PermissionDto toDto(PermissionEntity user);
|
||||
|
||||
PermissionEntity toEntity(CreatePermissionDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget PermissionEntity entity, UpdatePermissionDto dto);
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/ResourceMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/ResourceMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateResourceDto;
|
||||
import cn.lihongjie.coal.dto.UpdateResourceDto;
|
||||
import cn.lihongjie.coal.dto.ResourceDto;
|
||||
import cn.lihongjie.coal.entity.ResourceEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface ResourceMapper {
|
||||
ResourceDto toDto(ResourceEntity user);
|
||||
|
||||
ResourceEntity toEntity(CreateResourceDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget ResourceEntity entity, UpdateResourceDto dto);
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/RoleMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/RoleMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateRoleDto;
|
||||
import cn.lihongjie.coal.dto.UpdateRoleDto;
|
||||
import cn.lihongjie.coal.dto.RoleDto;
|
||||
import cn.lihongjie.coal.entity.RoleEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface RoleMapper {
|
||||
RoleDto toDto(RoleEntity user);
|
||||
|
||||
RoleEntity toEntity(CreateRoleDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget RoleEntity entity, UpdateRoleDto dto);
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/UserMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/UserMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateUserDto;
|
||||
import cn.lihongjie.coal.dto.UpdateUserDto;
|
||||
import cn.lihongjie.coal.dto.UserDto;
|
||||
import cn.lihongjie.coal.entity.UserEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface UserMapper {
|
||||
UserDto toDto(UserEntity user);
|
||||
|
||||
UserEntity toEntity(CreateUserDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget UserEntity entity, UpdateUserDto dto);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.PermissionRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.PermissionEntity;
|
||||
import cn.lihongjie.coal.mapper.PermissionMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PermissionService {
|
||||
|
||||
@Autowired
|
||||
PermissionRepository repository;
|
||||
|
||||
@Autowired
|
||||
PermissionMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public PermissionDto create(CreatePermissionDto request) {
|
||||
|
||||
|
||||
PermissionEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public PermissionDto update(UpdatePermissionDto request) {
|
||||
PermissionEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public PermissionDto getById(String id) {
|
||||
|
||||
PermissionEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<PermissionDto> list(CommonQuery query) {
|
||||
|
||||
Page<PermissionEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
|
||||
}
|
||||
}
|
||||
81
src/main/java/cn/lihongjie/coal/service/ResourceService.java
Normal file
81
src/main/java/cn/lihongjie/coal/service/ResourceService.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.ResourceRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.ResourceEntity;
|
||||
import cn.lihongjie.coal.mapper.ResourceMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ResourceService {
|
||||
|
||||
@Autowired
|
||||
ResourceRepository repository;
|
||||
|
||||
@Autowired
|
||||
ResourceMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ResourceDto create(CreateResourceDto request) {
|
||||
|
||||
|
||||
ResourceEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ResourceDto update(UpdateResourceDto request) {
|
||||
ResourceEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ResourceDto getById(String id) {
|
||||
|
||||
ResourceEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<ResourceDto> list(CommonQuery query) {
|
||||
|
||||
Page<ResourceEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
|
||||
}
|
||||
}
|
||||
81
src/main/java/cn/lihongjie/coal/service/RoleService.java
Normal file
81
src/main/java/cn/lihongjie/coal/service/RoleService.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.RoleRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.RoleEntity;
|
||||
import cn.lihongjie.coal.mapper.RoleMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RoleService {
|
||||
|
||||
@Autowired
|
||||
RoleRepository repository;
|
||||
|
||||
@Autowired
|
||||
RoleMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public RoleDto create(CreateRoleDto request) {
|
||||
|
||||
|
||||
RoleEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public RoleDto update(UpdateRoleDto request) {
|
||||
RoleEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public RoleDto getById(String id) {
|
||||
|
||||
RoleEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<RoleDto> list(CommonQuery query) {
|
||||
|
||||
Page<RoleEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
|
||||
}
|
||||
}
|
||||
120
src/main/java/cn/lihongjie/coal/service/UserService.java
Normal file
120
src/main/java/cn/lihongjie/coal/service/UserService.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.UserRepository;
|
||||
import cn.lihongjie.coal.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.dto.IdRequest;
|
||||
import cn.lihongjie.coal.dto.ChangeUserPwdDto;
|
||||
import cn.lihongjie.coal.dto.CreateUserDto;
|
||||
import cn.lihongjie.coal.dto.UpdateUserDto;
|
||||
import cn.lihongjie.coal.dto.UserDto;
|
||||
import cn.lihongjie.coal.entity.UserEntity;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.mapper.UserMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserService {
|
||||
|
||||
@Autowired
|
||||
UserRepository repository;
|
||||
|
||||
@Autowired
|
||||
UserMapper mapper;
|
||||
|
||||
private Pbkdf2PasswordEncoder passwordEncoder;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
|
||||
passwordEncoder = Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UserDto create(CreateUserDto request){
|
||||
|
||||
|
||||
UserEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public UserDto update(UpdateUserDto request){
|
||||
UserEntity user = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(user, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void delete(IdRequest request){
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UserDto getById(String id){
|
||||
|
||||
UserEntity user = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UserDto changePwd(ChangeUserPwdDto request){
|
||||
|
||||
|
||||
UserEntity user = repository.findById(request.getId()).orElseThrow(() -> new BizException("用户不存在"));
|
||||
|
||||
if (!StringUtils.equals(request.getNewPassword(), request.getNewPassword2())) {
|
||||
throw new BizException("两次输入的密码不一致");
|
||||
}
|
||||
|
||||
user.setPassword(passwordEncoder.encode(request.getNewPassword()));
|
||||
|
||||
repository.save(user);
|
||||
|
||||
return
|
||||
getById(request.getId());
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<UserDto> list(CommonQuery query) {
|
||||
|
||||
Page<UserEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user