mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
部门curd
This commit is contained in:
@@ -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<DepartmentDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public DepartmentDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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<DepartmentEntity> {
|
||||
}
|
||||
11
src/main/java/cn/lihongjie/coal/dto/CreateDepartmentDto.java
Normal file
11
src/main/java/cn/lihongjie/coal/dto/CreateDepartmentDto.java
Normal file
@@ -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
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
13
src/main/java/cn/lihongjie/coal/dto/DepartmentDto.java
Normal file
13
src/main/java/cn/lihongjie/coal/dto/DepartmentDto.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 DepartmentDto extends OrgCommonDto
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PagedData <T>{
|
||||
|
||||
private List<T> data;
|
||||
|
||||
private Integer pageNo;
|
||||
private Integer pageSize;
|
||||
private Integer totalCount;
|
||||
|
||||
}
|
||||
11
src/main/java/cn/lihongjie/coal/dto/UpdateDepartmentDto.java
Normal file
11
src/main/java/cn/lihongjie/coal/dto/UpdateDepartmentDto.java
Normal file
@@ -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
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
14
src/main/java/cn/lihongjie/coal/entity/DepartmentEntity.java
Normal file
14
src/main/java/cn/lihongjie/coal/entity/DepartmentEntity.java
Normal file
@@ -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 {
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/DepartmentMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/DepartmentMapper.java
Normal file
@@ -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);
|
||||
}
|
||||
@@ -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<DepartmentDto> list(CommonQuery query) {
|
||||
|
||||
Page<DepartmentEntity> 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