first commit

This commit is contained in:
2023-07-03 22:16:16 +08:00
parent 4788b710e7
commit 065b60f851
10 changed files with 233 additions and 30 deletions

View File

@ -1,16 +1,27 @@
package com.qiaoba.module.generator.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.IoUtil;
import com.qiaoba.common.base.result.AjaxResult;
import com.qiaoba.common.database.entity.PageQuery;
import com.qiaoba.common.database.entity.TableDataInfo;
import com.qiaoba.module.generator.entity.GeneratorTable;
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
import com.qiaoba.module.generator.entity.dto.GeneratorTableDto;
import com.qiaoba.module.generator.entity.dto.TableDto;
import com.qiaoba.module.generator.service.GeneratorTableColumnService;
import com.qiaoba.module.generator.service.GeneratorTableService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import sun.nio.ch.IOUtil;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成 Web层
@ -26,6 +37,35 @@ import java.io.IOException;
public class GeneratorController {
private final GeneratorTableService generatorTableService;
private final GeneratorTableColumnService generatorTableColumnService;
/**
* 查询代码生成列表
*/
@GetMapping("/list")
@Operation(summary = "获取列表")
public TableDataInfo list(TableDto dto, PageQuery pageQuery) {
return generatorTableService.selectPageList(dto, pageQuery);
}
@GetMapping(value = "/{tableId}")
public AjaxResult getInfo(@PathVariable String tableId) {
GeneratorTable table = generatorTableService.selectById(tableId);
List<GeneratorTableColumn> list = generatorTableColumnService.selectListByTableId(tableId, false);
Map<String, Object> map = new HashMap<String, Object>(2);
map.put("info", table);
map.put("rows", list);
return AjaxResult.success(map);
}
@PutMapping
public AjaxResult edit(@RequestBody GeneratorTableDto dto) {
GeneratorTable generatorTable = BeanUtil.copyProperties(dto, GeneratorTable.class);
int result = generatorTableService.updateById(generatorTable);
generatorTableColumnService.updateBatchById(dto.getColumns());
return AjaxResult.toAjax(result);
}
/**
* 导入表结构(保存)
@ -36,8 +76,7 @@ public class GeneratorController {
}
@GetMapping("/download/{tableName}")
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
{
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
byte[] data = generatorTableService.downloadCode(tableName);
genCode(response, data);
}

View File

@ -0,0 +1,79 @@
package com.qiaoba.module.generator.entity.dto;
import com.baomidou.mybatisplus.annotation.TableId;
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.List;
/**
* 表字段信息
*
* @author ailanyin
* @version 1.0
* @since 2023/6/26 10:12
*/
@Getter
@Setter
public class GeneratorTableDto implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 编号
*/
@TableId
private String tableId;
/**
* 表名称
*/
private String tableName;
/**
* 表描述
*/
private String tableComment;
/**
* 实体类名称(首字母大写)
*/
private String className;
/**
* 生成包路径
*/
private String packageName;
/**
* 生成模块名
*/
private String moduleName;
/**
* 生成业务名
*/
private String businessName;
/**
* 生成功能名
*/
private String functionName;
/**
* 生成作者
*/
private String author;
/**
* 生成路径(不填默认项目路径)
*/
private String genPath;
/**
* 字段信息
*/
private List<GeneratorTableColumn> columns;
}

View File

@ -39,4 +39,11 @@ public interface GeneratorTableColumnService {
* @return 结果
*/
Integer insert(GeneratorTableColumn generatorTableColumn);
/**
* 批量根据ID更新
*
* @param columns columns
*/
void updateBatchById(List<GeneratorTableColumn> columns);
}

View File

@ -15,6 +15,31 @@ import com.qiaoba.module.generator.entity.vo.DbTableVo;
*/
public interface GeneratorTableService {
/**
* 查询业务列表
*
* @param dto 查询条件
* @param pageQuery 分页
* @return list
*/
TableDataInfo<GeneratorTable> selectPageList(TableDto dto, PageQuery pageQuery);
/**
* 根据ID查询业务
*
* @param tableId tableId
* @return info
*/
GeneratorTable selectById(String tableId);
/**
* 根据ID更新
*
* @param generatorTable generatorTable
* @return 结果
*/
int updateById(GeneratorTable generatorTable);
/**
* 分页查询数据库表
*
@ -48,4 +73,5 @@ public interface GeneratorTableService {
* @return 文件字节
*/
byte[] downloadCode(String tableName);
}

View File

@ -3,6 +3,7 @@ package com.qiaoba.module.generator.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.qiaoba.common.base.exceptions.ServiceException;
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
import com.qiaoba.module.generator.entity.vo.TableColumnVo;
@ -51,4 +52,9 @@ public class GeneratorTableColumnServiceImpl implements GeneratorTableColumnServ
public Integer insert(GeneratorTableColumn generatorTableColumn) {
return generatorTableColumnMapper.insert(generatorTableColumn);
}
@Override
public void updateBatchById(List<GeneratorTableColumn> columns) {
Db.updateBatchById(columns);
}
}

View File

@ -54,6 +54,25 @@ public class GeneratorTableServiceImpl implements GeneratorTableService {
private final GeneratorTableMapper generatorTableMapper;
private final GeneratorTableColumnService generatorTableColumnService;
@Override
public TableDataInfo<GeneratorTable> selectPageList(TableDto dto, PageQuery pageQuery) {
QueryWrapper<GeneratorTable> wrapper = new QueryWrapper<>();
wrapper.lambda()
.like(StrUtil.isNotBlank(dto.getTableName()), GeneratorTable::getTableName, dto.getTableName())
.like(StrUtil.isNotBlank(dto.getTableComment()), GeneratorTable::getTableComment, dto.getTableComment());
return TableDataInfo.build(generatorTableMapper.selectPage(pageQuery.build(), wrapper));
}
@Override
public GeneratorTable selectById(String tableId) {
return generatorTableMapper.selectById(tableId);
}
@Override
public int updateById(GeneratorTable generatorTable) {
return generatorTableMapper.updateById(generatorTable);
}
@Override
public TableDataInfo<DbTableVo> selectPageDbTableList(TableDto dto, PageQuery pageQuery) {
dto.setDbType(TenantDbTypeContext.getDefault());
@ -88,9 +107,6 @@ public class GeneratorTableServiceImpl implements GeneratorTableService {
@Override
public byte[] downloadCode(String tableName) {
for (int i = 0; i < 5; i++) {
System.out.println(new Snowflake().nextIdStr());
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
generatorCode(tableName, zip);