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,52 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.ScriptService;
|
||||
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("/Script")
|
||||
@RestController
|
||||
@SysLog(module = "")
|
||||
public class ScriptController {
|
||||
|
||||
@Autowired
|
||||
ScriptService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(action = "新增")
|
||||
public ScriptDto create(@RequestBody CreateScriptDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(action = "编辑")
|
||||
public ScriptDto update(@RequestBody UpdateScriptDto dto) {
|
||||
return this.service.update(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@SysLog(action = "删除")
|
||||
public Object delete(@RequestBody IdRequest dto) {
|
||||
this.service.delete(dto);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<ScriptDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public ScriptDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.ScriptEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ScriptRepository extends BaseRepository<ScriptEntity> {
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/CreateScriptDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/CreateScriptDto.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
|
||||
@Comment("脚本")
|
||||
public class CreateScriptDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("脚本内容")
|
||||
private String content;
|
||||
|
||||
@Comment("脚本类型")
|
||||
private String scriptType;
|
||||
|
||||
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/ScriptDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/ScriptDto.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
|
||||
@Comment("脚本")
|
||||
public class ScriptDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("脚本内容")
|
||||
private String content;
|
||||
|
||||
@Comment("脚本类型")
|
||||
private String scriptType;
|
||||
|
||||
|
||||
}
|
||||
19
src/main/java/cn/lihongjie/coal/dto/UpdateScriptDto.java
Normal file
19
src/main/java/cn/lihongjie/coal/dto/UpdateScriptDto.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
|
||||
@Comment("脚本")
|
||||
public class UpdateScriptDto extends CommonDto {
|
||||
|
||||
|
||||
@Comment("脚本内容")
|
||||
private String content;
|
||||
|
||||
@Comment("脚本类型")
|
||||
private String scriptType;
|
||||
|
||||
|
||||
}
|
||||
21
src/main/java/cn/lihongjie/coal/entity/ScriptEntity.java
Normal file
21
src/main/java/cn/lihongjie/coal/entity/ScriptEntity.java
Normal file
@@ -0,0 +1,21 @@
|
||||
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 ScriptEntity extends CommonEntity {
|
||||
|
||||
|
||||
@Comment("脚本内容")
|
||||
private String content;
|
||||
|
||||
@Comment("脚本类型")
|
||||
private String scriptType;
|
||||
|
||||
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/ScriptMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/ScriptMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateScriptDto;
|
||||
import cn.lihongjie.coal.dto.ScriptDto;
|
||||
import cn.lihongjie.coal.dto.UpdateScriptDto;
|
||||
import cn.lihongjie.coal.entity.ScriptEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface ScriptMapper {
|
||||
ScriptDto toDto(ScriptEntity user);
|
||||
|
||||
ScriptEntity toEntity(CreateScriptDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget ScriptEntity entity, UpdateScriptDto dto);
|
||||
}
|
||||
81
src/main/java/cn/lihongjie/coal/service/ScriptService.java
Normal file
81
src/main/java/cn/lihongjie/coal/service/ScriptService.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.ScriptRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.ScriptEntity;
|
||||
import cn.lihongjie.coal.mapper.ScriptMapper;
|
||||
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 ScriptService extends BaseService<ScriptEntity, ScriptRepository> {
|
||||
|
||||
@Autowired
|
||||
ScriptRepository repository;
|
||||
|
||||
@Autowired
|
||||
ScriptMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ScriptDto create(CreateScriptDto request) {
|
||||
|
||||
|
||||
ScriptEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ScriptDto update(UpdateScriptDto request) {
|
||||
ScriptEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ScriptDto getById(String id) {
|
||||
|
||||
ScriptEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<ScriptDto> list(CommonQuery query) {
|
||||
|
||||
Page<ScriptEntity> 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