From d4c8d5ad1335d83b4242ac45a1a2c469907f49ea Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Wed, 2 Aug 2023 17:59:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=84=9A=E6=9C=ACcurd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coal/controller/ScriptController.java | 52 ++++++++++++ .../lihongjie/coal/dao/ScriptRepository.java | 8 ++ .../lihongjie/coal/dto/CreateScriptDto.java | 19 +++++ .../java/cn/lihongjie/coal/dto/ScriptDto.java | 19 +++++ .../lihongjie/coal/dto/UpdateScriptDto.java | 19 +++++ .../lihongjie/coal/entity/ScriptEntity.java | 21 +++++ .../lihongjie/coal/mapper/ScriptMapper.java | 24 ++++++ .../lihongjie/coal/service/ScriptService.java | 81 +++++++++++++++++++ 8 files changed, 243 insertions(+) create mode 100644 src/main/java/cn/lihongjie/coal/controller/ScriptController.java create mode 100644 src/main/java/cn/lihongjie/coal/dao/ScriptRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/CreateScriptDto.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/ScriptDto.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/UpdateScriptDto.java create mode 100644 src/main/java/cn/lihongjie/coal/entity/ScriptEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/mapper/ScriptMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/service/ScriptService.java diff --git a/src/main/java/cn/lihongjie/coal/controller/ScriptController.java b/src/main/java/cn/lihongjie/coal/controller/ScriptController.java new file mode 100644 index 00000000..28e99580 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/controller/ScriptController.java @@ -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 list(@RequestBody CommonQuery dto) { + return this.service.list(dto); + } + + + @PostMapping("/getById") + public ScriptDto getById(@RequestBody IdRequest dto) { + return this.service.getById(dto.getId()); + } +} diff --git a/src/main/java/cn/lihongjie/coal/dao/ScriptRepository.java b/src/main/java/cn/lihongjie/coal/dao/ScriptRepository.java new file mode 100644 index 00000000..4e4fb6b6 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dao/ScriptRepository.java @@ -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 { +} \ No newline at end of file diff --git a/src/main/java/cn/lihongjie/coal/dto/CreateScriptDto.java b/src/main/java/cn/lihongjie/coal/dto/CreateScriptDto.java new file mode 100644 index 00000000..bf8880c9 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/CreateScriptDto.java @@ -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; + + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/ScriptDto.java b/src/main/java/cn/lihongjie/coal/dto/ScriptDto.java new file mode 100644 index 00000000..13045abd --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/ScriptDto.java @@ -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; + + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/UpdateScriptDto.java b/src/main/java/cn/lihongjie/coal/dto/UpdateScriptDto.java new file mode 100644 index 00000000..e7935cdb --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/UpdateScriptDto.java @@ -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; + + +} diff --git a/src/main/java/cn/lihongjie/coal/entity/ScriptEntity.java b/src/main/java/cn/lihongjie/coal/entity/ScriptEntity.java new file mode 100644 index 00000000..8c50962a --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/entity/ScriptEntity.java @@ -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; + + +} diff --git a/src/main/java/cn/lihongjie/coal/mapper/ScriptMapper.java b/src/main/java/cn/lihongjie/coal/mapper/ScriptMapper.java new file mode 100644 index 00000000..38490ee3 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/mapper/ScriptMapper.java @@ -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); +} diff --git a/src/main/java/cn/lihongjie/coal/service/ScriptService.java b/src/main/java/cn/lihongjie/coal/service/ScriptService.java new file mode 100644 index 00000000..10a44a3a --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/service/ScriptService.java @@ -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 { + + @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 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); + + } +}