移除不必要的代码

This commit is contained in:
2024-04-18 16:27:24 +08:00
parent dd2aa08e61
commit 7d8cef30bf
25 changed files with 0 additions and 855 deletions

View File

@@ -1,52 +0,0 @@
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);
}
}

View File

@@ -1,8 +0,0 @@
package cn.lihongjie.coal.excelGenerator.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class CreateExcelGeneratorDto extends CommonDto {}

View File

@@ -1,8 +0,0 @@
package cn.lihongjie.coal.excelGenerator.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class ExcelGeneratorDto extends CommonDto {}

View File

@@ -1,16 +0,0 @@
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;
}

View File

@@ -1,8 +0,0 @@
package cn.lihongjie.coal.excelGenerator.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class UpdateExcelGeneratorDto extends CommonDto {}

View File

@@ -1,44 +0,0 @@
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;
}

View File

@@ -1,23 +0,0 @@
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> {}

View File

@@ -1,9 +0,0 @@
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> {}

View File

@@ -1,139 +0,0 @@
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;
}
}

View File

@@ -1,54 +0,0 @@
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);
}
}

View File

@@ -1,40 +0,0 @@
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;
}

View File

@@ -1,11 +0,0 @@
package cn.lihongjie.coal.excelGeneratorSheetInfo.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class ExcelGeneratorSheetInfoDto extends CommonDto {
}

View File

@@ -1,40 +0,0 @@
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;
}

View File

@@ -1,73 +0,0 @@
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;
}

View File

@@ -1,23 +0,0 @@
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> {}

View File

@@ -1,10 +0,0 @@
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> {}

View File

@@ -1,71 +0,0 @@
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);
}
}

View File

@@ -1,52 +0,0 @@
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);
}
}

View File

@@ -1,8 +0,0 @@
package cn.lihongjie.coal.excelTemplate.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class CreateExcelTemplateDto extends CommonDto {}

View File

@@ -1,8 +0,0 @@
package cn.lihongjie.coal.excelTemplate.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class ExcelTemplateDto extends CommonDto {}

View File

@@ -1,8 +0,0 @@
package cn.lihongjie.coal.excelTemplate.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class UpdateExcelTemplateDto extends CommonDto {}

View File

@@ -1,31 +0,0 @@
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;
}

View File

@@ -1,23 +0,0 @@
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> {}

View File

@@ -1,9 +0,0 @@
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> {}

View File

@@ -1,87 +0,0 @@
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);
}
}