mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善
This commit is contained in:
@@ -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<ExcelGeneratorDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -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 {}
|
||||
@@ -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<CreateExcelGeneratorSheetInfoDto> sheets;
|
||||
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -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<ExcelGeneratorSheetInfoEntity> sheets;
|
||||
|
||||
|
||||
@Comment("数据源耗时")
|
||||
private Long dataSourceCostTime;
|
||||
|
||||
@Comment("模板耗时")
|
||||
private Long templateCostTime;
|
||||
|
||||
@Comment("生成耗时")
|
||||
private Long generateCostTime;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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> {}
|
||||
@@ -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<ExcelGeneratorEntity> {}
|
||||
@@ -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<ExcelGeneratorEntity, ExcelGeneratorRepository> {
|
||||
@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<ExcelGeneratorDto> list(CommonQuery query) {
|
||||
Page<ExcelGeneratorEntity> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<ExcelGeneratorSheetInfoDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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> {}
|
||||
@@ -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<ExcelGeneratorSheetInfoEntity> {}
|
||||
@@ -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<ExcelGeneratorSheetInfoEntity, ExcelGeneratorSheetInfoRepository> {
|
||||
@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<ExcelGeneratorSheetInfoDto> list(CommonQuery query) {
|
||||
Page<ExcelGeneratorSheetInfoEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -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<ExcelTemplateDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -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 {}
|
||||
@@ -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 {}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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> {}
|
||||
@@ -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<ExcelTemplateEntity> {}
|
||||
@@ -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<ExcelTemplateEntity, ExcelTemplateRepository> {
|
||||
@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<ExcelTemplateDto> list(CommonQuery query) {
|
||||
Page<ExcelTemplateEntity> 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<ExcelTemplateEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<ExcelTemplateEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.equal(root.get("code"), templateCode);
|
||||
}
|
||||
}).orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -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": "员工档案记录类型",
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user