From 1621b00476506b1fcbc880e9ef4256241f72cc83 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sat, 29 Jul 2023 23:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8curd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coal/controller/DepartmentController.java | 47 +++++++++++ .../controller/OrganizationController.java | 2 +- .../coal/controller/RoleController.java | 2 +- .../coal/dao/DepartmentRepository.java | 8 ++ .../coal/dto/CreateDepartmentDto.java | 11 +++ .../cn/lihongjie/coal/dto/DepartmentDto.java | 13 +++ .../java/cn/lihongjie/coal/dto/PagedData.java | 13 --- .../coal/dto/UpdateDepartmentDto.java | 11 +++ .../coal/entity/DepartmentEntity.java | 14 ++++ .../coal/mapper/DepartmentMapper.java | 24 ++++++ .../coal/service/DepartmentService.java | 81 +++++++++++++++++++ 11 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 src/main/java/cn/lihongjie/coal/controller/DepartmentController.java create mode 100644 src/main/java/cn/lihongjie/coal/dao/DepartmentRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/CreateDepartmentDto.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/DepartmentDto.java delete mode 100644 src/main/java/cn/lihongjie/coal/dto/PagedData.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/UpdateDepartmentDto.java create mode 100644 src/main/java/cn/lihongjie/coal/entity/DepartmentEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/mapper/DepartmentMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/service/DepartmentService.java diff --git a/src/main/java/cn/lihongjie/coal/controller/DepartmentController.java b/src/main/java/cn/lihongjie/coal/controller/DepartmentController.java new file mode 100644 index 00000000..f3ef404d --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/controller/DepartmentController.java @@ -0,0 +1,47 @@ +package cn.lihongjie.coal.controller; + +import cn.lihongjie.coal.dto.*; +import cn.lihongjie.coal.service.DepartmentService; +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("/department") +@RestController +public class DepartmentController { + + @Autowired + DepartmentService service; + + @PostMapping("/create") + public DepartmentDto create(@RequestBody CreateDepartmentDto dto) { + return this.service.create(dto); + } + + @PostMapping("/update") + public DepartmentDto update(@RequestBody UpdateDepartmentDto dto) { + return this.service.update(dto); + } + + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest dto) { + this.service.delete(dto); + return null; + } + + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery dto) { + return this.service.list(dto); + } + + + @PostMapping("/getById") + public DepartmentDto getById(@RequestBody IdRequest dto) { + return this.service.getById(dto.getId()); + } +} diff --git a/src/main/java/cn/lihongjie/coal/controller/OrganizationController.java b/src/main/java/cn/lihongjie/coal/controller/OrganizationController.java index b9a7c5d2..5afb31b8 100644 --- a/src/main/java/cn/lihongjie/coal/controller/OrganizationController.java +++ b/src/main/java/cn/lihongjie/coal/controller/OrganizationController.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@RequestMapping("/Organization") +@RequestMapping("/organization") @RestController public class OrganizationController { diff --git a/src/main/java/cn/lihongjie/coal/controller/RoleController.java b/src/main/java/cn/lihongjie/coal/controller/RoleController.java index 8db3055d..3d28e1da 100644 --- a/src/main/java/cn/lihongjie/coal/controller/RoleController.java +++ b/src/main/java/cn/lihongjie/coal/controller/RoleController.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@RequestMapping("/Role") +@RequestMapping("/role") @RestController public class RoleController { diff --git a/src/main/java/cn/lihongjie/coal/dao/DepartmentRepository.java b/src/main/java/cn/lihongjie/coal/dao/DepartmentRepository.java new file mode 100644 index 00000000..e52fbf30 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dao/DepartmentRepository.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.dao; + +import cn.lihongjie.coal.entity.DepartmentEntity; +import org.springframework.stereotype.Repository; + +@Repository +public interface DepartmentRepository extends BaseRepository { +} \ No newline at end of file diff --git a/src/main/java/cn/lihongjie/coal/dto/CreateDepartmentDto.java b/src/main/java/cn/lihongjie/coal/dto/CreateDepartmentDto.java new file mode 100644 index 00000000..d9ba0b1a --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/CreateDepartmentDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.dto; + +import cn.lihongjie.coal.dto.base.OrgCommonDto; +import lombok.Data; + +@Data +public class CreateDepartmentDto extends OrgCommonDto +{ + + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/DepartmentDto.java b/src/main/java/cn/lihongjie/coal/dto/DepartmentDto.java new file mode 100644 index 00000000..730da947 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/DepartmentDto.java @@ -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 DepartmentDto extends OrgCommonDto +{ + + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/PagedData.java b/src/main/java/cn/lihongjie/coal/dto/PagedData.java deleted file mode 100644 index 64631ff1..00000000 --- a/src/main/java/cn/lihongjie/coal/dto/PagedData.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.lihongjie.coal.dto; - -import java.util.List; - -public class PagedData { - - private List data; - - private Integer pageNo; - private Integer pageSize; - private Integer totalCount; - -} diff --git a/src/main/java/cn/lihongjie/coal/dto/UpdateDepartmentDto.java b/src/main/java/cn/lihongjie/coal/dto/UpdateDepartmentDto.java new file mode 100644 index 00000000..c41388ff --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/UpdateDepartmentDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.dto; + +import cn.lihongjie.coal.dto.base.OrgCommonDto; +import lombok.Data; + +@Data +public class UpdateDepartmentDto extends OrgCommonDto +{ + + +} diff --git a/src/main/java/cn/lihongjie/coal/entity/DepartmentEntity.java b/src/main/java/cn/lihongjie/coal/entity/DepartmentEntity.java new file mode 100644 index 00000000..32c3fd1b --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/entity/DepartmentEntity.java @@ -0,0 +1,14 @@ +package cn.lihongjie.coal.entity; + +import cn.lihongjie.coal.entity.base.OrgCommonEntity; +import jakarta.persistence.Entity; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.Comment; + +@Entity +@Comment("部门信息") +@Getter +@Setter +public class DepartmentEntity extends OrgCommonEntity { +} diff --git a/src/main/java/cn/lihongjie/coal/mapper/DepartmentMapper.java b/src/main/java/cn/lihongjie/coal/mapper/DepartmentMapper.java new file mode 100644 index 00000000..92067cc5 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/mapper/DepartmentMapper.java @@ -0,0 +1,24 @@ +package cn.lihongjie.coal.mapper; + + +import cn.lihongjie.coal.dto.CreateDepartmentDto; +import cn.lihongjie.coal.dto.UpdateDepartmentDto; +import cn.lihongjie.coal.dto.DepartmentDto; +import cn.lihongjie.coal.entity.DepartmentEntity; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.MappingTarget; + +@Mapper( + componentModel = MappingConstants.ComponentModel.SPRING, + uses = {CommonMapper.class} + +) +public interface DepartmentMapper { + DepartmentDto toDto(DepartmentEntity user); + + DepartmentEntity toEntity(CreateDepartmentDto request); + + + void updateEntity(@MappingTarget DepartmentEntity entity, UpdateDepartmentDto dto); +} diff --git a/src/main/java/cn/lihongjie/coal/service/DepartmentService.java b/src/main/java/cn/lihongjie/coal/service/DepartmentService.java new file mode 100644 index 00000000..fa31a5fd --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/service/DepartmentService.java @@ -0,0 +1,81 @@ +package cn.lihongjie.coal.service; + +import cn.lihongjie.coal.dao.DepartmentRepository; +import cn.lihongjie.coal.dto.*; +import cn.lihongjie.coal.entity.DepartmentEntity; +import cn.lihongjie.coal.mapper.DepartmentMapper; +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 DepartmentService { + + @Autowired + DepartmentRepository repository; + + @Autowired + DepartmentMapper mapper; + + + @PostConstruct + public void init() { + + + } + + + public DepartmentDto create(CreateDepartmentDto request) { + + + DepartmentEntity entity = mapper.toEntity(request); + + + this.repository.save(entity); + return getById(entity.getId()); + + } + + + public DepartmentDto update(UpdateDepartmentDto request) { + DepartmentEntity entity = this.repository.get(request.getId()); + this.mapper.updateEntity(entity, request); + + return null; + } + + + public void delete(IdRequest request) { + + this.repository.deleteAllById(request.getIds()); + + } + + + public DepartmentDto getById(String id) { + + DepartmentEntity entity = repository.get(id); + + + return mapper.toDto(entity); + } + + + @Autowired + ConversionService conversionService; + + public Page list(CommonQuery query) { + + Page page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders()))); + + + return page.map(this.mapper::toDto); + + } +}