From 9b08ac84961b8a9e162f6962c4f09f27b5834837 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sat, 2 Mar 2024 14:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ExcelGeneratorController.java | 52 +++++++ .../dto/CreateExcelGeneratorDto.java | 8 + .../excelGenerator/dto/ExcelGeneratorDto.java | 8 + .../dto/GenerateExcelRequest.java | 16 ++ .../dto/UpdateExcelGeneratorDto.java | 8 + .../entity/ExcelGeneratorEntity.java | 44 ++++++ .../mapper/ExcelGeneratorMapper.java | 23 +++ .../repository/ExcelGeneratorRepository.java | 9 ++ .../service/ExcelGeneratorService.java | 139 ++++++++++++++++++ .../ExcelGeneratorSheetInfoController.java | 54 +++++++ .../dto/CreateExcelGeneratorSheetInfoDto.java | 40 +++++ .../dto/ExcelGeneratorSheetInfoDto.java | 11 ++ .../dto/UpdateExcelGeneratorSheetInfoDto.java | 40 +++++ .../entity/ExcelGeneratorSheetInfoEntity.java | 73 +++++++++ .../mapper/ExcelGeneratorSheetInfoMapper.java | 23 +++ .../ExcelGeneratorSheetInfoRepository.java | 10 ++ .../ExcelGeneratorSheetInfoService.java | 71 +++++++++ .../controller/ExcelTemplateController.java | 52 +++++++ .../dto/CreateExcelTemplateDto.java | 8 + .../excelTemplate/dto/ExcelTemplateDto.java | 8 + .../dto/UpdateExcelTemplateDto.java | 8 + .../entity/ExcelTemplateEntity.java | 31 ++++ .../mapper/ExcelTemplateMapper.java | 23 +++ .../repository/ExcelTemplateRepository.java | 9 ++ .../service/ExcelTemplateService.java | 87 +++++++++++ src/main/resources/config/dictionary.json | 48 ++++++ .../dict/enum/excelGeneratorDict.groovy | 17 +++ .../enum/excelGeneratorSheetInfoDict.groovy | 17 +++ .../dict/enum/excelTemplateDict.groovy | 17 +++ 29 files changed, 954 insertions(+) create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/controller/ExcelGeneratorController.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/dto/CreateExcelGeneratorDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/dto/ExcelGeneratorDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/dto/GenerateExcelRequest.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/dto/UpdateExcelGeneratorDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/entity/ExcelGeneratorEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/mapper/ExcelGeneratorMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/repository/ExcelGeneratorRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGenerator/service/ExcelGeneratorService.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/controller/ExcelGeneratorSheetInfoController.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/CreateExcelGeneratorSheetInfoDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/ExcelGeneratorSheetInfoDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/UpdateExcelGeneratorSheetInfoDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/entity/ExcelGeneratorSheetInfoEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/mapper/ExcelGeneratorSheetInfoMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/repository/ExcelGeneratorSheetInfoRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/service/ExcelGeneratorSheetInfoService.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/controller/ExcelTemplateController.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/dto/CreateExcelTemplateDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/dto/ExcelTemplateDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/dto/UpdateExcelTemplateDto.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/entity/ExcelTemplateEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/mapper/ExcelTemplateMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/repository/ExcelTemplateRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/excelTemplate/service/ExcelTemplateService.java create mode 100644 src/main/resources/scripts/dict/enum/excelGeneratorDict.groovy create mode 100644 src/main/resources/scripts/dict/enum/excelGeneratorSheetInfoDict.groovy create mode 100644 src/main/resources/scripts/dict/enum/excelTemplateDict.groovy diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/controller/ExcelGeneratorController.java b/src/main/java/cn/lihongjie/coal/excelGenerator/controller/ExcelGeneratorController.java new file mode 100644 index 00000000..0e93a094 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/controller/ExcelGeneratorController.java @@ -0,0 +1,52 @@ +package cn.lihongjie.coal.excelGenerator.controller; + +import cn.lihongjie.coal.annotation.SysLog; +import cn.lihongjie.coal.base.dto.CommonQuery; +import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.excelGenerator.dto.CreateExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.dto.ExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.dto.UpdateExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.service.ExcelGeneratorService; + +import lombok.extern.slf4j.Slf4j; + +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; + +@RestController +@RequestMapping("/excelGenerator") +@SysLog(module = "Excel生成器") +@Slf4j +public class ExcelGeneratorController { + @Autowired private ExcelGeneratorService service; + + @PostMapping("/create") + public ExcelGeneratorDto create(@RequestBody CreateExcelGeneratorDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public ExcelGeneratorDto update(@RequestBody UpdateExcelGeneratorDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public ExcelGeneratorDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/dto/CreateExcelGeneratorDto.java b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/CreateExcelGeneratorDto.java new file mode 100644 index 00000000..3d102a8d --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/CreateExcelGeneratorDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.excelGenerator.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +@Data +public class CreateExcelGeneratorDto extends CommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/dto/ExcelGeneratorDto.java b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/ExcelGeneratorDto.java new file mode 100644 index 00000000..9529c8f5 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/ExcelGeneratorDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.excelGenerator.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +@Data +public class ExcelGeneratorDto extends CommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/dto/GenerateExcelRequest.java b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/GenerateExcelRequest.java new file mode 100644 index 00000000..6b4c11bd --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/GenerateExcelRequest.java @@ -0,0 +1,16 @@ +package cn.lihongjie.coal.excelGenerator.dto; + +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.CreateExcelGeneratorSheetInfoDto; + +import lombok.Data; + +import java.util.*; + +@Data +public class GenerateExcelRequest { + + private String templateCode; + + private List sheets; + +} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/dto/UpdateExcelGeneratorDto.java b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/UpdateExcelGeneratorDto.java new file mode 100644 index 00000000..8088fa05 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/dto/UpdateExcelGeneratorDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.excelGenerator.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +@Data +public class UpdateExcelGeneratorDto extends CommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/entity/ExcelGeneratorEntity.java b/src/main/java/cn/lihongjie/coal/excelGenerator/entity/ExcelGeneratorEntity.java new file mode 100644 index 00000000..f95e6f10 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/entity/ExcelGeneratorEntity.java @@ -0,0 +1,44 @@ +package cn.lihongjie.coal.excelGenerator.entity; + +import cn.lihongjie.coal.base.entity.CommonEntity; +import cn.lihongjie.coal.excelGeneratorSheetInfo.entity.ExcelGeneratorSheetInfoEntity; +import cn.lihongjie.coal.excelTemplate.entity.ExcelTemplateEntity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; + +import lombok.Data; + +import org.hibernate.annotations.Comment; + +import java.util.List; + +@Data +@Entity +public class ExcelGeneratorEntity extends CommonEntity { + + + @ManyToOne + private ExcelTemplateEntity template; + + @OneToMany(mappedBy = "generator", cascade = {CascadeType.ALL}) + private List sheets; + + + @Comment("数据源耗时") + private Long dataSourceCostTime; + + @Comment("模板耗时") + private Long templateCostTime; + + @Comment("生成耗时") + private Long generateCostTime; + + + + + + +} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/mapper/ExcelGeneratorMapper.java b/src/main/java/cn/lihongjie/coal/excelGenerator/mapper/ExcelGeneratorMapper.java new file mode 100644 index 00000000..becbcbb6 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/mapper/ExcelGeneratorMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.excelGenerator.mapper; + +import cn.lihongjie.coal.base.mapper.BaseMapper; +import cn.lihongjie.coal.base.mapper.CommonEntityMapper; +import cn.lihongjie.coal.base.mapper.CommonMapper; +import cn.lihongjie.coal.excelGenerator.dto.CreateExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.dto.ExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.dto.UpdateExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.entity.ExcelGeneratorEntity; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; + +@Mapper( + componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, + uses = {CommonMapper.class, CommonEntityMapper.class}, + mappingControl = DeepClone.class) +public interface ExcelGeneratorMapper + extends BaseMapper< + ExcelGeneratorEntity, + ExcelGeneratorDto, + CreateExcelGeneratorDto, + UpdateExcelGeneratorDto> {} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/repository/ExcelGeneratorRepository.java b/src/main/java/cn/lihongjie/coal/excelGenerator/repository/ExcelGeneratorRepository.java new file mode 100644 index 00000000..cc527a5a --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/repository/ExcelGeneratorRepository.java @@ -0,0 +1,9 @@ +package cn.lihongjie.coal.excelGenerator.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.excelGenerator.entity.ExcelGeneratorEntity; + +import org.springframework.stereotype.Repository; + +@Repository +public interface ExcelGeneratorRepository extends BaseRepository {} diff --git a/src/main/java/cn/lihongjie/coal/excelGenerator/service/ExcelGeneratorService.java b/src/main/java/cn/lihongjie/coal/excelGenerator/service/ExcelGeneratorService.java new file mode 100644 index 00000000..b0f91f4f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGenerator/service/ExcelGeneratorService.java @@ -0,0 +1,139 @@ +package cn.lihongjie.coal.excelGenerator.service; + +import cn.lihongjie.coal.base.dto.CommonQuery; +import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.base.service.BaseService; +import cn.lihongjie.coal.excelGenerator.dto.CreateExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.dto.ExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.dto.GenerateExcelRequest; +import cn.lihongjie.coal.excelGenerator.dto.UpdateExcelGeneratorDto; +import cn.lihongjie.coal.excelGenerator.entity.ExcelGeneratorEntity; +import cn.lihongjie.coal.excelGenerator.mapper.ExcelGeneratorMapper; +import cn.lihongjie.coal.excelGenerator.repository.ExcelGeneratorRepository; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.CreateExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelTemplate.entity.ExcelTemplateEntity; +import cn.lihongjie.coal.excelTemplate.service.ExcelTemplateService; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import lombok.Data; +import lombok.SneakyThrows; +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; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; + +@Service +@Slf4j +@Transactional +public class ExcelGeneratorService + extends BaseService { + @Autowired ExcelTemplateService excelTemplateService; + @Autowired ObjectMapper objectMapper; + @Autowired RequestMappingHandlerMapping requestMappingHandlerMapping; + @Autowired private ExcelGeneratorRepository repository; + @Autowired private ExcelGeneratorMapper mapper; + @Autowired private ConversionService conversionService; + + public ExcelGeneratorDto create(CreateExcelGeneratorDto request) { + ExcelGeneratorEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public ExcelGeneratorDto update(UpdateExcelGeneratorDto request) { + ExcelGeneratorEntity entity = this.repository.get(request.getId()); + this.mapper.updateEntity(entity, request); + + this.repository.save(entity); + + return getById(entity.getId()); + } + + public void delete(IdRequest request) { + this.repository.deleteAllById(request.getIds()); + } + + public ExcelGeneratorDto getById(String id) { + ExcelGeneratorEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + 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); + } + + @SneakyThrows + public void generate(GenerateExcelRequest request) { + + // 获取模板 + + ExcelTemplateEntity excelTemplate = + excelTemplateService.getByCode(request.getTemplateCode()); + + if (excelTemplate == null) { + throw new RuntimeException("模板不存在"); + } + + // 获取数据源 + + for (CreateExcelGeneratorSheetInfoDto sheet : request.getSheets()) { + + var sheetData = new SheetData(); + + sheetData.setSheetName(sheet.getName()); + switch (sheet.getDataSourceType()) { + case "0": + sheetData.setData( + sheet.getDataSourceParams() == null + ? null + : objectMapper.readTree(sheet.getDataSourceParams())); + break; + + case "1": + + // requestMappingHandlerMapping.match() + break; + + case "2": + break; + + case "3": + break; + + default: + throw new RuntimeException("不支持的数据源类型 " + sheet.getDataSourceType()); + } + + // 模板 + 数据源 生成xml + + // 生成excel + + // 保存excel + + } + } + + @Data + public static class SheetData { + + private String sheetName; + private Object data; + } +} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/controller/ExcelGeneratorSheetInfoController.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/controller/ExcelGeneratorSheetInfoController.java new file mode 100644 index 00000000..89a4b899 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/controller/ExcelGeneratorSheetInfoController.java @@ -0,0 +1,54 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.controller; + +import cn.lihongjie.coal.annotation.SysLog; +import cn.lihongjie.coal.base.dto.CommonQuery; +import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.CreateExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.ExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.UpdateExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.service.ExcelGeneratorSheetInfoService; + +import lombok.extern.slf4j.Slf4j; + +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; + +@RestController +@RequestMapping("/excelGeneratorSheetInfo") +@SysLog(module = "excel生成器sheet信息") +@Slf4j +public class ExcelGeneratorSheetInfoController { + @Autowired private ExcelGeneratorSheetInfoService service; + + @PostMapping("/create") + public ExcelGeneratorSheetInfoDto create( + @RequestBody CreateExcelGeneratorSheetInfoDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public ExcelGeneratorSheetInfoDto update( + @RequestBody UpdateExcelGeneratorSheetInfoDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public ExcelGeneratorSheetInfoDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/CreateExcelGeneratorSheetInfoDto.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/CreateExcelGeneratorSheetInfoDto.java new file mode 100644 index 00000000..982d3516 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/CreateExcelGeneratorSheetInfoDto.java @@ -0,0 +1,40 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +@Data +public class CreateExcelGeneratorSheetInfoDto extends CommonDto { + + @Comment("数据源类型") + private String dataSourceType; + + @Formula( + "(select i.name\n" + + "from t_dictionary d,\n" + + " t_dictionary_item i\n" + + "where d.id = i.dictionary_id\n" + + " and d.code = 'excel.generator.datasource.type'\n" + + " and i.code = data_source_type)") + private String dataSourceTypeName; + + + @Comment("数据源-url") + private String dataSourceUrl; + + + @Comment("数据源-请求方式") + private String dataSourceMethod; + + + @Comment("数据源-请求参数") + private String dataSourceParams; + + + @Comment("数据源-额外请求头") + private String dataSourceHeaders; +} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/ExcelGeneratorSheetInfoDto.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/ExcelGeneratorSheetInfoDto.java new file mode 100644 index 00000000..3401e6d5 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/ExcelGeneratorSheetInfoDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +@Data +public class ExcelGeneratorSheetInfoDto extends CommonDto { + + +} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/UpdateExcelGeneratorSheetInfoDto.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/UpdateExcelGeneratorSheetInfoDto.java new file mode 100644 index 00000000..3c30d9f9 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/dto/UpdateExcelGeneratorSheetInfoDto.java @@ -0,0 +1,40 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +@Data +public class UpdateExcelGeneratorSheetInfoDto extends CommonDto { + + @Comment("数据源类型") + private String dataSourceType; + + @Formula( + "(select i.name\n" + + "from t_dictionary d,\n" + + " t_dictionary_item i\n" + + "where d.id = i.dictionary_id\n" + + " and d.code = 'excel.generator.datasource.type'\n" + + " and i.code = data_source_type)") + private String dataSourceTypeName; + + + @Comment("数据源-url") + private String dataSourceUrl; + + + @Comment("数据源-请求方式") + private String dataSourceMethod; + + + @Comment("数据源-请求参数") + private String dataSourceParams; + + + @Comment("数据源-额外请求头") + private String dataSourceHeaders; +} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/entity/ExcelGeneratorSheetInfoEntity.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/entity/ExcelGeneratorSheetInfoEntity.java new file mode 100644 index 00000000..d935ab64 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/entity/ExcelGeneratorSheetInfoEntity.java @@ -0,0 +1,73 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.entity; + +import cn.lihongjie.coal.base.entity.CommonEntity; +import cn.lihongjie.coal.excelGenerator.entity.ExcelGeneratorEntity; + +import jakarta.persistence.Entity; +import jakarta.persistence.ManyToOne; + +import lombok.Data; + +import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +@Data +@Entity +public class ExcelGeneratorSheetInfoEntity extends CommonEntity { + + @ManyToOne + private ExcelGeneratorEntity generator; + + + @Comment("数据源类型") + private String dataSourceType; + + @Formula( + "(select i.name\n" + + "from t_dictionary d,\n" + + " t_dictionary_item i\n" + + "where d.id = i.dictionary_id\n" + + " and d.code = 'excel.generator.datasource.type'\n" + + " and i.code = data_source_type)") + private String dataSourceTypeName; + + + @Comment("数据源-url") + private String dataSourceUrl; + + + @Comment("数据源-请求方式") + private String dataSourceMethod; + + + @Comment("数据源-请求参数") + private String dataSourceParams; + + + @Comment("数据源-额外请求头") + private String dataSourceHeaders; + + + + @Comment("数据源耗时") + private Long dataSourceCostTime; + + @Comment("模板耗时") + private Long templateCostTime; + + @Comment("生成耗时") + private Long generateCostTime; + + + @Comment("生成状态") + private String execStatus; + + @Formula( + "(select i.name\n" + + "from t_dictionary d,\n" + + " t_dictionary_item i\n" + + "where d.id = i.dictionary_id\n" + + " and d.code = 'common.execStatus'\n" + + " and i.code = exec_status)") + private String execStatusName; +} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/mapper/ExcelGeneratorSheetInfoMapper.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/mapper/ExcelGeneratorSheetInfoMapper.java new file mode 100644 index 00000000..011a936b --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/mapper/ExcelGeneratorSheetInfoMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.mapper; + +import cn.lihongjie.coal.base.mapper.BaseMapper; +import cn.lihongjie.coal.base.mapper.CommonEntityMapper; +import cn.lihongjie.coal.base.mapper.CommonMapper; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.CreateExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.ExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.UpdateExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.entity.ExcelGeneratorSheetInfoEntity; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; + +@Mapper( + componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, + uses = {CommonMapper.class, CommonEntityMapper.class}, + mappingControl = DeepClone.class) +public interface ExcelGeneratorSheetInfoMapper + extends BaseMapper< + ExcelGeneratorSheetInfoEntity, + ExcelGeneratorSheetInfoDto, + CreateExcelGeneratorSheetInfoDto, + UpdateExcelGeneratorSheetInfoDto> {} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/repository/ExcelGeneratorSheetInfoRepository.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/repository/ExcelGeneratorSheetInfoRepository.java new file mode 100644 index 00000000..ec80233f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/repository/ExcelGeneratorSheetInfoRepository.java @@ -0,0 +1,10 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.excelGeneratorSheetInfo.entity.ExcelGeneratorSheetInfoEntity; + +import org.springframework.stereotype.Repository; + +@Repository +public interface ExcelGeneratorSheetInfoRepository + extends BaseRepository {} diff --git a/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/service/ExcelGeneratorSheetInfoService.java b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/service/ExcelGeneratorSheetInfoService.java new file mode 100644 index 00000000..f9224eb0 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelGeneratorSheetInfo/service/ExcelGeneratorSheetInfoService.java @@ -0,0 +1,71 @@ +package cn.lihongjie.coal.excelGeneratorSheetInfo.service; + +import cn.lihongjie.coal.base.dto.CommonQuery; +import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.base.service.BaseService; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.CreateExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.ExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.dto.UpdateExcelGeneratorSheetInfoDto; +import cn.lihongjie.coal.excelGeneratorSheetInfo.entity.ExcelGeneratorSheetInfoEntity; +import cn.lihongjie.coal.excelGeneratorSheetInfo.mapper.ExcelGeneratorSheetInfoMapper; +import cn.lihongjie.coal.excelGeneratorSheetInfo.repository.ExcelGeneratorSheetInfoRepository; + +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; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Slf4j +@Transactional +public class ExcelGeneratorSheetInfoService + extends BaseService { + @Autowired private ExcelGeneratorSheetInfoRepository repository; + + @Autowired private ExcelGeneratorSheetInfoMapper mapper; + + @Autowired private ConversionService conversionService; + + public ExcelGeneratorSheetInfoDto create(CreateExcelGeneratorSheetInfoDto request) { + ExcelGeneratorSheetInfoEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public ExcelGeneratorSheetInfoDto update(UpdateExcelGeneratorSheetInfoDto request) { + ExcelGeneratorSheetInfoEntity entity = this.repository.get(request.getId()); + this.mapper.updateEntity(entity, request); + + this.repository.save(entity); + + return getById(entity.getId()); + } + + public void delete(IdRequest request) { + this.repository.deleteAllById(request.getIds()); + } + + public ExcelGeneratorSheetInfoDto getById(String id) { + ExcelGeneratorSheetInfoEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + 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); + } +} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/controller/ExcelTemplateController.java b/src/main/java/cn/lihongjie/coal/excelTemplate/controller/ExcelTemplateController.java new file mode 100644 index 00000000..c399b5d1 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/controller/ExcelTemplateController.java @@ -0,0 +1,52 @@ +package cn.lihongjie.coal.excelTemplate.controller; + +import cn.lihongjie.coal.annotation.SysLog; +import cn.lihongjie.coal.base.dto.CommonQuery; +import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.excelTemplate.dto.CreateExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.dto.ExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.dto.UpdateExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.service.ExcelTemplateService; + +import lombok.extern.slf4j.Slf4j; + +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; + +@RestController +@RequestMapping("/excelTemplate") +@SysLog(module = "Excel模板生成服务") +@Slf4j +public class ExcelTemplateController { + @Autowired private ExcelTemplateService service; + + @PostMapping("/create") + public ExcelTemplateDto create(@RequestBody CreateExcelTemplateDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public ExcelTemplateDto update(@RequestBody UpdateExcelTemplateDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public ExcelTemplateDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/dto/CreateExcelTemplateDto.java b/src/main/java/cn/lihongjie/coal/excelTemplate/dto/CreateExcelTemplateDto.java new file mode 100644 index 00000000..6b62239f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/dto/CreateExcelTemplateDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.excelTemplate.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +@Data +public class CreateExcelTemplateDto extends CommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/dto/ExcelTemplateDto.java b/src/main/java/cn/lihongjie/coal/excelTemplate/dto/ExcelTemplateDto.java new file mode 100644 index 00000000..21fe2321 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/dto/ExcelTemplateDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.excelTemplate.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +@Data +public class ExcelTemplateDto extends CommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/dto/UpdateExcelTemplateDto.java b/src/main/java/cn/lihongjie/coal/excelTemplate/dto/UpdateExcelTemplateDto.java new file mode 100644 index 00000000..39ac8b57 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/dto/UpdateExcelTemplateDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.excelTemplate.dto; + +import cn.lihongjie.coal.base.dto.CommonDto; + +import lombok.Data; + +@Data +public class UpdateExcelTemplateDto extends CommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/entity/ExcelTemplateEntity.java b/src/main/java/cn/lihongjie/coal/excelTemplate/entity/ExcelTemplateEntity.java new file mode 100644 index 00000000..e1db8d25 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/entity/ExcelTemplateEntity.java @@ -0,0 +1,31 @@ +package cn.lihongjie.coal.excelTemplate.entity; + +import cn.lihongjie.coal.base.entity.CommonEntity; + +import jakarta.persistence.Entity; + +import lombok.Data; + +import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +@Data +@Entity +public class ExcelTemplateEntity extends CommonEntity { + + + + private String content; + + @Comment("模板类型") + private String templateType; + + @Formula( + "(select i.name\n" + + "from t_dictionary d,\n" + + " t_dictionary_item i\n" + + "where d.id = i.dictionary_id\n" + + " and d.code = 'excel.template.type'\n" + + " and i.code = template_type)") + private String templateTypeName; +} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/mapper/ExcelTemplateMapper.java b/src/main/java/cn/lihongjie/coal/excelTemplate/mapper/ExcelTemplateMapper.java new file mode 100644 index 00000000..5c294e3f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/mapper/ExcelTemplateMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.excelTemplate.mapper; + +import cn.lihongjie.coal.base.mapper.BaseMapper; +import cn.lihongjie.coal.base.mapper.CommonEntityMapper; +import cn.lihongjie.coal.base.mapper.CommonMapper; +import cn.lihongjie.coal.excelTemplate.dto.CreateExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.dto.ExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.dto.UpdateExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.entity.ExcelTemplateEntity; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; + +@Mapper( + componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, + uses = {CommonMapper.class, CommonEntityMapper.class}, + mappingControl = DeepClone.class) +public interface ExcelTemplateMapper + extends BaseMapper< + ExcelTemplateEntity, + ExcelTemplateDto, + CreateExcelTemplateDto, + UpdateExcelTemplateDto> {} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/repository/ExcelTemplateRepository.java b/src/main/java/cn/lihongjie/coal/excelTemplate/repository/ExcelTemplateRepository.java new file mode 100644 index 00000000..5a08b96a --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/repository/ExcelTemplateRepository.java @@ -0,0 +1,9 @@ +package cn.lihongjie.coal.excelTemplate.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.excelTemplate.entity.ExcelTemplateEntity; + +import org.springframework.stereotype.Repository; + +@Repository +public interface ExcelTemplateRepository extends BaseRepository {} diff --git a/src/main/java/cn/lihongjie/coal/excelTemplate/service/ExcelTemplateService.java b/src/main/java/cn/lihongjie/coal/excelTemplate/service/ExcelTemplateService.java new file mode 100644 index 00000000..55925aab --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/excelTemplate/service/ExcelTemplateService.java @@ -0,0 +1,87 @@ +package cn.lihongjie.coal.excelTemplate.service; + +import cn.lihongjie.coal.base.dto.CommonQuery; +import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.base.service.BaseService; +import cn.lihongjie.coal.excelTemplate.dto.CreateExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.dto.ExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.dto.UpdateExcelTemplateDto; +import cn.lihongjie.coal.excelTemplate.entity.ExcelTemplateEntity; +import cn.lihongjie.coal.excelTemplate.mapper.ExcelTemplateMapper; +import cn.lihongjie.coal.excelTemplate.repository.ExcelTemplateRepository; + +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; + +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.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Slf4j +@Transactional +public class ExcelTemplateService + extends BaseService { + @Autowired private ExcelTemplateRepository repository; + + @Autowired private ExcelTemplateMapper mapper; + + @Autowired private ConversionService conversionService; + + public ExcelTemplateDto create(CreateExcelTemplateDto request) { + ExcelTemplateEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public ExcelTemplateDto update(UpdateExcelTemplateDto request) { + ExcelTemplateEntity entity = this.repository.get(request.getId()); + this.mapper.updateEntity(entity, request); + + this.repository.save(entity); + + return getById(entity.getId()); + } + + public void delete(IdRequest request) { + this.repository.deleteAllById(request.getIds()); + } + + public ExcelTemplateDto getById(String id) { + ExcelTemplateEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + 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); + } + + public ExcelTemplateEntity getByCode(String templateCode) { + + return repository.findOne(new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { + return criteriaBuilder.equal(root.get("code"), templateCode); + } + }).orElse(null); + } +} diff --git a/src/main/resources/config/dictionary.json b/src/main/resources/config/dictionary.json index e2f6b4d5..6e7d2dd6 100644 --- a/src/main/resources/config/dictionary.json +++ b/src/main/resources/config/dictionary.json @@ -2004,6 +2004,54 @@ ] }, + + { + "code": "excel.template.type", + "name": "excel模板类型", + "item": [ + { + "code": "0", + "name": "xml" + }, + { + "code": "1", + "name": "freemarker" + }, + { + "code": "2", + "name": "groovy" + }, + { + "code": "3", + "name": "javascript" + } + + ] + }, + + { + "code": "excel.generator.datasource.type", + "name": "excel生成器数据源类型", + "item": [ + { + "code": "0", + "name": "inline" + }, + { + "code": "1", + "name": "local-http" + }, + { + "code": "2", + "name": "remote-http" + }, + { + "code": "3", + "name": "script" + } + + ] + }, { "code": "emp.record.type", "name": "员工档案记录类型", diff --git a/src/main/resources/scripts/dict/enum/excelGeneratorDict.groovy b/src/main/resources/scripts/dict/enum/excelGeneratorDict.groovy new file mode 100644 index 00000000..e6a9d487 --- /dev/null +++ b/src/main/resources/scripts/dict/enum/excelGeneratorDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.excelGenerator.controller.ExcelGeneratorController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(ExcelGeneratorController.class) + + + + +return controller.list(new CommonQuery()) + + diff --git a/src/main/resources/scripts/dict/enum/excelGeneratorSheetInfoDict.groovy b/src/main/resources/scripts/dict/enum/excelGeneratorSheetInfoDict.groovy new file mode 100644 index 00000000..d0f3989d --- /dev/null +++ b/src/main/resources/scripts/dict/enum/excelGeneratorSheetInfoDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.excelGeneratorSheetInfo.controller.ExcelGeneratorSheetInfoController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(ExcelGeneratorSheetInfoController.class) + + + + +return controller.list(new CommonQuery()) + + diff --git a/src/main/resources/scripts/dict/enum/excelTemplateDict.groovy b/src/main/resources/scripts/dict/enum/excelTemplateDict.groovy new file mode 100644 index 00000000..90384ebe --- /dev/null +++ b/src/main/resources/scripts/dict/enum/excelTemplateDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.excelTemplate.controller.ExcelTemplateController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(ExcelTemplateController.class) + + + + +return controller.list(new CommonQuery()) + +