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:
@@ -1,12 +1,47 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.dao.OrganizationRepository;
|
||||
import cn.lihongjie.coal.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.OrganizationService;
|
||||
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("/Organization")
|
||||
@RestController
|
||||
@RequestMapping("/organization")
|
||||
public class OrganizationController extends BaseController<OrganizationRepository, OrganizationService, OrganizationEntity> {
|
||||
public class OrganizationController {
|
||||
|
||||
@Autowired
|
||||
OrganizationService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public OrganizationDto create(@RequestBody CreateOrganizationDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public OrganizationDto update(@RequestBody UpdateOrganizationDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<OrganizationDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public OrganizationDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateOrganizationDto extends CommonDto {
|
||||
|
||||
private String parentId;
|
||||
}
|
||||
10
src/main/java/cn/lihongjie/coal/dto/OrganizationDto.java
Normal file
10
src/main/java/cn/lihongjie/coal/dto/OrganizationDto.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrganizationDto extends CommonDto {
|
||||
|
||||
private String parentId;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.CommonDto;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateOrganizationDto extends CommonDto {
|
||||
|
||||
private String parentId;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateOrganizationDto;
|
||||
import cn.lihongjie.coal.dto.UpdateOrganizationDto;
|
||||
import cn.lihongjie.coal.dto.OrganizationDto;
|
||||
import cn.lihongjie.coal.entity.OrganizationEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface OrganizationMapper {
|
||||
OrganizationDto toDto(OrganizationEntity user);
|
||||
|
||||
OrganizationEntity toEntity(CreateOrganizationDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget OrganizationEntity entity, UpdateOrganizationDto dto);
|
||||
}
|
||||
@@ -1,11 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.OrganizationRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.mapper.OrganizationMapper;
|
||||
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 OrganizationService extends BaseService<OrganizationEntity, OrganizationRepository> {
|
||||
public class OrganizationService {
|
||||
|
||||
@Autowired
|
||||
OrganizationRepository repository;
|
||||
|
||||
@Autowired
|
||||
OrganizationMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public OrganizationDto create(CreateOrganizationDto request) {
|
||||
|
||||
|
||||
OrganizationEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public OrganizationDto update(UpdateOrganizationDto request) {
|
||||
OrganizationEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public OrganizationDto getById(String id) {
|
||||
|
||||
OrganizationEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<OrganizationDto> list(CommonQuery query) {
|
||||
|
||||
Page<OrganizationEntity> 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