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.SysConfigService;
|
||||
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("/sysConfig")
|
||||
@RestController
|
||||
public class SysConfigController {
|
||||
|
||||
@Autowired
|
||||
SysConfigService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public SysConfigDto create(@RequestBody CreateSysConfigDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public SysConfigDto update(@RequestBody UpdateSysConfigDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<SysConfigDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public SysConfigDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.SysConfigEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SysConfigRepository extends BaseRepository<SysConfigEntity> {
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/CreateSysConfigDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/CreateSysConfigDto.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 CreateSysConfigDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("配置类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("值")
|
||||
private String configVal;
|
||||
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/SysConfigDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/SysConfigDto.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 SysConfigDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("配置类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("值")
|
||||
private String configVal;
|
||||
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/UpdateSysConfigDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/UpdateSysConfigDto.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 UpdateSysConfigDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("配置类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("值")
|
||||
private String configVal;
|
||||
|
||||
}
|
||||
32
src/main/java/cn/lihongjie/coal/entity/SysConfigEntity.java
Normal file
32
src/main/java/cn/lihongjie/coal/entity/SysConfigEntity.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package cn.lihongjie.coal.entity;
|
||||
|
||||
import cn.lihongjie.coal.entity.base.CommonEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Comment("系统配置")
|
||||
public class SysConfigEntity extends CommonEntity {
|
||||
|
||||
|
||||
|
||||
@Comment("配置类型")
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
@Comment("值")
|
||||
private String configVal;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/SysConfigMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/SysConfigMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateSysConfigDto;
|
||||
import cn.lihongjie.coal.dto.UpdateSysConfigDto;
|
||||
import cn.lihongjie.coal.dto.SysConfigDto;
|
||||
import cn.lihongjie.coal.entity.SysConfigEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface SysConfigMapper {
|
||||
SysConfigDto toDto(SysConfigEntity user);
|
||||
|
||||
SysConfigEntity toEntity(CreateSysConfigDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget SysConfigEntity entity, UpdateSysConfigDto dto);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.SysConfigRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.SysConfigEntity;
|
||||
import cn.lihongjie.coal.mapper.SysConfigMapper;
|
||||
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 SysConfigService {
|
||||
|
||||
@Autowired
|
||||
SysConfigRepository repository;
|
||||
|
||||
@Autowired
|
||||
SysConfigMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SysConfigDto create(CreateSysConfigDto request) {
|
||||
|
||||
|
||||
SysConfigEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SysConfigDto update(UpdateSysConfigDto request) {
|
||||
SysConfigEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SysConfigDto getById(String id) {
|
||||
|
||||
SysConfigEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<SysConfigDto> list(CommonQuery query) {
|
||||
|
||||
Page<SysConfigEntity> 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