添加导出模板.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.orion.ops.framework.common.utils;
|
||||
|
||||
import com.orion.lang.utils.time.Dates;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
|
||||
/**
|
||||
* 文件名称
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/8/31 17:57
|
||||
*/
|
||||
public class FileNames {
|
||||
|
||||
private FileNames() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出文件名称
|
||||
*
|
||||
* @param title title
|
||||
* @return name
|
||||
*/
|
||||
public static String exportName(String title) {
|
||||
return title + "-" + Dates.current(Dates.YMD_HMS2) + "." + Const.SUFFIX_XLSX;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -303,6 +303,8 @@ public class CodeGenerator {
|
||||
new String[]{"/templates/orion-server-module-entity-request-update.java.vm", "${type}UpdateRequest.java", "entity.request.${bizPackage}"},
|
||||
// query request 文件
|
||||
new String[]{"/templates/orion-server-module-entity-request-query.java.vm", "${type}QueryRequest.java", "entity.request.${bizPackage}"},
|
||||
// export 文件
|
||||
new String[]{"/templates/orion-server-module-entity-export.java.vm", "${type}Export.java", "entity.export"},
|
||||
// convert 文件
|
||||
new String[]{"/templates/orion-server-module-convert.java.vm", "${type}Convert.java", "convert"},
|
||||
// -------------------- 后端 - provider --------------------
|
||||
@@ -350,18 +352,17 @@ public class CodeGenerator {
|
||||
|
||||
// 构建文件
|
||||
List<CustomFile> customerFiles = Arrays.stream(customFileDefineArr)
|
||||
.map(s -> {
|
||||
return new CustomFile.Builder()
|
||||
// 覆盖文件
|
||||
.enableFileOverride()
|
||||
// 模板路径
|
||||
.templatePath(s[0])
|
||||
// 文件名
|
||||
.fileName(s[1])
|
||||
// 包名
|
||||
.packageName(s[2])
|
||||
.build();
|
||||
}).collect(Collectors.toList());
|
||||
.map(s -> new CustomFile.Builder()
|
||||
// 覆盖文件
|
||||
.enableFileOverride()
|
||||
// 模板路径
|
||||
.templatePath(s[0])
|
||||
// 文件名
|
||||
.fileName(s[1])
|
||||
// 包名
|
||||
.packageName(s[2])
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 注入配置
|
||||
return new InjectionConfig.Builder()
|
||||
|
||||
@@ -249,6 +249,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
||||
map.put("queryPage", "分页查询" + comment);
|
||||
map.put("deleteById", "通过 id 删除" + comment);
|
||||
map.put("batchDeleteByIdList", "通过 id 批量删除" + comment);
|
||||
map.put("export", "导出" + comment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,4 +70,16 @@ DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete-batch?idList=1,2,3
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
${httpComment} ${apiComment.export}
|
||||
POST {{baseUrl}}/${package.ModuleName}/${typeHyphen}/export
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
#foreach($field in ${table.fields})
|
||||
"${field.propertyName}": ""#if($foreach.hasNext),#end
|
||||
#end
|
||||
}
|
||||
|
||||
|
||||
${httpComment}
|
||||
|
||||
@@ -110,5 +110,13 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.batchDelete${type}ByIdList(idList);
|
||||
}
|
||||
|
||||
@PostMapping("/export")
|
||||
@Operation(summary = "${apiComment.export}")
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:export')")
|
||||
public void export${type}(@Validated @RequestBody ${type}QueryRequest request,
|
||||
HttpServletResponse response) throws IOException {
|
||||
${typeLower}Service.export${type}(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import ${package.Entity}.*;
|
||||
#foreach($pkg in ${customModuleFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 实体对象
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import com.orion.lang.utils.time.Dates;
|
||||
import com.orion.office.excel.annotation.ExportField;
|
||||
import com.orion.office.excel.annotation.ExportSheet;
|
||||
import com.orion.office.excel.annotation.ExportTitle;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 导出对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ExportTitle(title = ${type}Export.TITLE)
|
||||
@ExportSheet(name = "$!{table.comment}", filterHeader = true, freezeHeader = true, indexToSort = true)
|
||||
@Schema(name = "${type}Export", description = "$!{table.comment}导出对象")
|
||||
public class ${type}Export implements Serializable {
|
||||
|
||||
public static final String TITLE = "$!{table.comment}导出";
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
#if("$field.propertyType" == "Date")
|
||||
@ExportField(index = ${foreach.index}, header = "${field.comment}", width = 16, format = Dates.YMD_HMS)
|
||||
#else
|
||||
@ExportField(index = ${foreach.index}, header = "${field.comment}", width = 16)
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
@ExportField(index = $table.fields.size(), header = "创建时间", width = 16, format = Dates.YMD_HMS)
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
#set($updateTimeIndex=$table.fields.size() + 1)
|
||||
@Schema(description = "修改时间")
|
||||
@ExportField(index = $updateTimeIndex, header = "修改时间", width = 16, format = Dates.YMD_HMS)
|
||||
private Date updateTime;
|
||||
|
||||
#set($creatorIndex=$table.fields.size() + 2)
|
||||
@Schema(description = "创建人")
|
||||
@ExportField(index = $creatorIndex, header = "创建人", width = 16)
|
||||
private String creator;
|
||||
|
||||
#set($updaterIndex=$table.fields.size() + 3)
|
||||
@Schema(description = "修改人")
|
||||
@ExportField(index = $updaterIndex, header = "修改人", width = 16)
|
||||
private String updater;
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 创建请求对象
|
||||
|
||||
@@ -7,6 +7,7 @@ import lombok.*;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 查询请求对象
|
||||
|
||||
@@ -12,6 +12,7 @@ import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 更新请求对象
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.Serializable;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 视图响应对象
|
||||
|
||||
@@ -3,7 +3,9 @@ package ${package.ServiceImpl};
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.office.excel.writer.exporting.ExcelExport;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.FileNames;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
#foreach($pkg in ${customModuleFilePackages})
|
||||
@@ -12,10 +14,14 @@ import ${pkg}.*;
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import com.orion.web.servlet.web.Servlets;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -124,6 +130,24 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export${type}(${type}QueryRequest request, HttpServletResponse response) throws IOException {
|
||||
// 条件
|
||||
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request);
|
||||
// 查询
|
||||
List<${type}Export> rows = ${typeLower}DAO.of()
|
||||
.wrapper(wrapper)
|
||||
.list(${type}Convert.MAPPER::export);
|
||||
// 导出
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ExcelExport.create(${type}Export.class)
|
||||
.addRows(rows)
|
||||
.write(out)
|
||||
.close();
|
||||
// 传输
|
||||
Servlets.transfer(response, out.toByteArray(), FileNames.exportName(${type}Export.TITLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测对象是否存在
|
||||
*
|
||||
|
||||
@@ -88,4 +88,13 @@ public interface ${table.serviceName} {
|
||||
*/
|
||||
Integer batchDelete${type}ByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* ${apiComment.export}
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
void export${type}(${type}QueryRequest request, HttpServletResponse response) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import ${package.Entity}.*;
|
||||
#foreach($pkg in ${customModuleFilePackages})
|
||||
import ${pkg}.*;
|
||||
@@ -9,6 +7,9 @@ import ${pkg}.*;
|
||||
#foreach($pkg in ${customProviderEntityFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 创建请求业务对象
|
||||
|
||||
@@ -9,6 +9,7 @@ import lombok.NoArgsConstructor;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 查询请求业务对象
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 更新请求业务对象
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.io.Serializable;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 业务对象
|
||||
|
||||
@@ -25,4 +25,5 @@ VALUES
|
||||
(@TMP_SUB_ID, '查询$vue.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 10),
|
||||
(@TMP_SUB_ID, '创建$vue.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 20),
|
||||
(@TMP_SUB_ID, '修改$vue.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 30),
|
||||
(@TMP_SUB_ID, '删除$vue.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40);
|
||||
(@TMP_SUB_ID, '删除$vue.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40),
|
||||
(@TMP_SUB_ID, '导出$vue.comment', '${package.ModuleName}:${typeHyphen}:export', 3, 50);
|
||||
|
||||
@@ -131,3 +131,10 @@ export function batchDelete${vue.featureFirstUpper}(idList: Array<number>) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* $apiComment.export
|
||||
*/
|
||||
export function export${vue.featureFirstUpper}(request: ${vue.featureFirstUpper}QueryRequest) {
|
||||
return axios.post('/${package.ModuleName}/${typeHyphen}/export', request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user