feat(codegen): 添加代码生成器批量操作功能
This commit is contained in:
parent
4f1215ad12
commit
e0f78da62e
@ -7,6 +7,18 @@
|
||||
<artifactId>mes-module-infra</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>mes-module-infra-biz</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@ -6,10 +6,6 @@ import com.ningxia.yunxi.chemmes.framework.common.pojo.CommonResult;
|
||||
import com.ningxia.yunxi.chemmes.framework.common.pojo.PageResult;
|
||||
import com.ningxia.yunxi.chemmes.framework.common.util.object.BeanUtils;
|
||||
import com.ningxia.yunxi.chemmes.framework.common.util.servlet.ServletUtils;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.convert.codegen.CodegenConvert;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.service.codegen.CodegenService;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.controller.admin.codegen.vo.CodegenCreateListReqVO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.controller.admin.codegen.vo.CodegenDetailRespVO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.controller.admin.codegen.vo.CodegenPreviewRespVO;
|
||||
@ -17,10 +13,14 @@ import com.ningxia.yunxi.chemmes.module.infra.controller.admin.codegen.vo.Codege
|
||||
import com.ningxia.yunxi.chemmes.module.infra.controller.admin.codegen.vo.table.CodegenTablePageReqVO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.controller.admin.codegen.vo.table.CodegenTableRespVO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.controller.admin.codegen.vo.table.DatabaseTableRespVO;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.convert.codegen.CodegenConvert;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
||||
import com.ningxia.yunxi.chemmes.module.infra.service.codegen.CodegenService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -31,8 +31,10 @@ import javax.validation.Valid;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ningxia.yunxi.chemmes.framework.common.pojo.CommonResult.success;
|
||||
import static com.ningxia.yunxi.chemmes.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
@ -46,6 +48,37 @@ public class CodegenController {
|
||||
@Resource
|
||||
private CodegenService codegenService;
|
||||
|
||||
// CodegenController.java 需要添加:
|
||||
|
||||
@Operation(summary = "批量删除数据库的表和字段定义")
|
||||
@DeleteMapping("/delete-list")
|
||||
@PreAuthorize("@ss.hasPermission('infra:codegen:delete')")
|
||||
public CommonResult<Boolean> deleteCodegenList(@RequestBody List<Long> tableIds) {
|
||||
codegenService.deleteCodegenList(tableIds);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "批量下载生成代码")
|
||||
@GetMapping("/download-list")
|
||||
@PreAuthorize("@ss.hasPermission('infra:codegen:download')")
|
||||
public void downloadCodegenList(String tableIds, HttpServletResponse response) throws IOException {
|
||||
if (tableIds == null || tableIds.isEmpty()) {
|
||||
throw new IllegalArgumentException("表ID列表不能为空");
|
||||
}
|
||||
String[] split = tableIds.trim().split(",");
|
||||
//数组转换为List
|
||||
List<Long> list = Arrays.stream(split).map(Long::parseLong).collect(Collectors.toList());
|
||||
Map<String, String> codes = codegenService.generationCodesList(list);
|
||||
|
||||
String[] paths = codes.keySet().toArray(new String[0]);
|
||||
ByteArrayInputStream[] ins = codes.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipUtil.zip(outputStream, paths, ins);
|
||||
ServletUtils.writeAttachment(response, "codegen-batch.zip", outputStream.toByteArray());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/db/table/list")
|
||||
@Operation(summary = "获得数据库自带的表定义列表", description = "会过滤掉已经导入 Codegen 的表")
|
||||
@Parameters({
|
||||
|
||||
@ -98,4 +98,9 @@ public interface CodegenService {
|
||||
*/
|
||||
List<DatabaseTableRespVO> getDatabaseTableList(Long dataSourceConfigId, String name, String comment);
|
||||
|
||||
// CodegenService.java 需要添加:
|
||||
|
||||
void deleteCodegenList(List<Long> tableIds);
|
||||
Map<String, String> generationCodesList(List<Long> tableIds);
|
||||
|
||||
}
|
||||
|
||||
@ -285,4 +285,26 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
return BeanUtils.toBean(tables, DatabaseTableRespVO.class);
|
||||
}
|
||||
|
||||
// CodegenServiceImpl.java 需要添加:
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCodegenList(List<Long> tableIds) {
|
||||
for (Long tableId : tableIds) {
|
||||
deleteCodegen(tableId);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Map<String, String> generationCodesList(List<Long> tableIds) {
|
||||
Map<String, String> allCodes = new LinkedHashMap<>();
|
||||
for (Long tableId : tableIds) {
|
||||
Map<String, String> codes = generationCodes(tableId);
|
||||
allCodes.putAll(codes);
|
||||
}
|
||||
return allCodes;
|
||||
}
|
||||
|
||||
// ... existing code ...
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ mes:
|
||||
codegen:
|
||||
base-package: ${mes.info.base-package}
|
||||
db-schemas: ${spring.datasource.dynamic.datasource.master.name}
|
||||
front-type: 10 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
|
||||
front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
|
||||
error-code: # 错误码相关配置项 - com.ningxia.yunxi.chemmes.module.majoys.enums.ErrorCodeConstants
|
||||
constants-class-list:
|
||||
- com.ningxia.yunxi.chemmes.module.infra.enums.ErrorCodeConstants
|
||||
|
||||
@ -121,3 +121,13 @@ export const createCodegenList = (data) => {
|
||||
export const deleteCodegenTable = (id: number) => {
|
||||
return request.delete({ url: '/infra/codegen/delete?tableId=' + id })
|
||||
}
|
||||
|
||||
// 批量删除代码生成表定义
|
||||
export const deleteCodegenTableList = (ids: number[]) => {
|
||||
return request.delete({ url: '/infra/codegen/delete-list', data: ids })
|
||||
}
|
||||
|
||||
// 批量下载生成代码
|
||||
export const downloadCodegenList = (ids: number[]) => {
|
||||
return request.download({ url: '/infra/codegen/download-list?tableIds=' + ids.join(',') })
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ const props = defineProps({
|
||||
const formRef = ref()
|
||||
const formData = ref({
|
||||
templateType: null,
|
||||
frontType: null,
|
||||
frontType: 20,
|
||||
scene: null,
|
||||
moduleName: '',
|
||||
businessName: '',
|
||||
|
||||
@ -55,13 +55,32 @@
|
||||
<Icon class="mr-5px" icon="ep:zoom-in" />
|
||||
导入
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPermi="['infra:codegen:delete']"
|
||||
:disabled="selectedIds.length === 0"
|
||||
type="danger"
|
||||
@click="handleDeleteAll"
|
||||
>
|
||||
<Icon class="mr-5px" icon="ep:delete" />
|
||||
批量删除
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPermi="['infra:codegen:download']"
|
||||
:disabled="selectedIds.length === 0"
|
||||
type="primary"
|
||||
@click="handleGenTableAll"
|
||||
>
|
||||
<Icon class="mr-5px" icon="ep:download" />
|
||||
批量生成代码
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list">
|
||||
<el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column align="center" label="数据源">
|
||||
<template #default="scope">
|
||||
{{
|
||||
@ -168,6 +187,7 @@ const { push } = useRouter() // 路由跳转
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const total = ref(0) // 列表的总页数
|
||||
const list = ref([]) // 列表的数据
|
||||
const selectedIds = ref<number[]>([]) // 选中的表ID数组
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
@ -249,6 +269,28 @@ const handleGenTable = async (row: CodegenApi.CodegenTableVO) => {
|
||||
download.zip(res, 'codegen-' + row.className + '.zip')
|
||||
}
|
||||
|
||||
/** 多选变化处理 */
|
||||
const handleSelectionChange = (val: CodegenApi.CodegenTableVO[]) => {
|
||||
selectedIds.value = val.map((item) => item.id)
|
||||
}
|
||||
|
||||
/** 批量删除操作 */
|
||||
const handleDeleteAll = async () => {
|
||||
try {
|
||||
await message.delConfirm()
|
||||
await CodegenApi.deleteCodegenTableList(selectedIds.value)
|
||||
message.success(t('common.delSuccess'))
|
||||
selectedIds.value = []
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 批量生成代码操作 */
|
||||
const handleGenTableAll = async () => {
|
||||
const res = await CodegenApi.downloadCodegenList(selectedIds.value)
|
||||
download.zip(res, 'codegen-batch.zip')
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(async () => {
|
||||
await getList()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user