1. 完成代码生成的表和字段定义的编辑

2. 清理多余代码
This commit is contained in:
YunaiV 2021-02-10 13:41:00 +08:00
parent 9dd2bc95fb
commit 305090b7dc
39 changed files with 211 additions and 439 deletions

View File

@ -76,18 +76,6 @@ public class GenController extends BaseController {
return AjaxResult.success();
}
/**
* 修改保存代码生成业务
*/
@PreAuthorize("@ss.hasPermi('tool:gen:edit')")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult editSave(@Validated @RequestBody GenTable genTable) {
genTableService.validateEdit(genTable);
genTableService.updateGenTable(genTable);
return AjaxResult.success();
}
/**
* 删除代码生成
*/

View File

@ -50,27 +50,4 @@ public interface GenTableMapper {
*/
public GenTable selectGenTableByName(String tableName);
/**
* 新增业务
*
* @param genTable 业务信息
* @return 结果
*/
public int insertGenTable(GenTable genTable);
/**
* 修改业务
*
* @param genTable 业务信息
* @return 结果
*/
public int updateGenTable(GenTable genTable);
/**
* 批量删除业务
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteGenTableByIds(Long[] ids);
}

View File

@ -1,64 +0,0 @@
package com.ruoyi.generator.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.generator.domain.GenTableColumn;
import com.ruoyi.generator.mapper.GenTableColumnMapper;
/**
* 业务字段 服务层实现
*
* @author ruoyi
*/
@Service
public class GenTableColumnServiceImpl implements IGenTableColumnService {
@Autowired
private GenTableColumnMapper genTableColumnMapper;
/**
* 查询业务字段列表
*
* @param tableId 业务字段编号
* @return 业务字段集合
*/
@Override
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
}
/**
* 新增业务字段
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
@Override
public int insertGenTableColumn(GenTableColumn genTableColumn) {
return genTableColumnMapper.insertGenTableColumn(genTableColumn);
}
/**
* 修改业务字段
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
@Override
public int updateGenTableColumn(GenTableColumn genTableColumn) {
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
}
/**
* 删除业务字段对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteGenTableColumnByIds(String ids) {
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
}
}

View File

@ -1,44 +0,0 @@
package com.ruoyi.generator.service;
import java.util.List;
import com.ruoyi.generator.domain.GenTableColumn;
/**
* 业务字段 服务层
*
* @author ruoyi
*/
public interface IGenTableColumnService {
/**
* 查询业务字段列表
*
* @param tableId 业务字段编号
* @return 业务字段集合
*/
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
/**
* 新增业务字段
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
public int insertGenTableColumn(GenTableColumn genTableColumn);
/**
* 修改业务字段
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
public int updateGenTableColumn(GenTableColumn genTableColumn);
/**
* 删除业务字段信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteGenTableColumnByIds(String ids);
}

View File

@ -1,114 +0,0 @@
package com.ruoyi.generator.service;
import java.util.List;
import java.util.Map;
import com.ruoyi.generator.domain.GenTable;
/**
* 业务 服务层
*
* @author ruoyi
*/
public interface IGenTableService {
/**
* 查询业务列表
*
* @param genTable 业务信息
* @return 业务集合
*/
public List<GenTable> selectGenTableList(GenTable genTable);
/**
* 查询据库列表
*
* @param genTable 业务信息
* @return 数据库表集合
*/
public List<GenTable> selectDbTableList(GenTable genTable);
/**
* 查询据库列表
*
* @param tableNames 表名称组
* @return 数据库表集合
*/
public List<GenTable> selectDbTableListByNames(String[] tableNames);
/**
* 查询业务信息
*
* @param id 业务ID
* @return 业务信息
*/
public GenTable selectGenTableById(Long id);
/**
* 修改业务
*
* @param genTable 业务信息
* @return 结果
*/
public void updateGenTable(GenTable genTable);
/**
* 删除业务信息
*
* @param tableIds 需要删除的表数据ID
* @return 结果
*/
public void deleteGenTableByIds(Long[] tableIds);
/**
* 导入表结构
*
* @param tableList 导入表列表
*/
public void importGenTable(List<GenTable> tableList);
/**
* 预览代码
*
* @param tableId 表编号
* @return 预览数据列表
*/
public Map<String, String> previewCode(Long tableId);
/**
* 生成代码下载方式
*
* @param tableName 表名称
* @return 数据
*/
public byte[] downloadCode(String tableName);
/**
* 生成代码自定义路径
*
* @param tableName 表名称
* @return 数据
*/
public void generatorCode(String tableName);
/**
* 同步数据库
*
* @param tableName 表名称
*/
public void synchDb(String tableName);
/**
* 批量生成代码下载方式
*
* @param tableNames 表数组
* @return 数据
*/
public byte[] downloadCode(String[] tableNames);
/**
* 修改保存参数校验
*
* @param genTable 业务信息
*/
public void validateEdit(GenTable genTable);
}

View File

@ -54,67 +54,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where t.table_name = #{tableName} order by c.sort
</select>
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
insert into gen_table (
<if test="tableName != null">table_name,</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="className != null and className != ''">class_name,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="packageName != null and packageName != ''">package_name,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if>
<if test="functionName != null and functionName != ''">function_name,</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
<if test="genType != null and genType != ''">gen_type,</if>
<if test="genPath != null and genPath != ''">gen_path,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="tableName != null">#{tableName},</if>
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="className != null and className != ''">#{className},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if>
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
<if test="genType != null and genType != ''">#{genType},</if>
<if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateGenTable" parameterType="GenTable">
update gen_table
<set>
<if test="tableName != null">table_name = #{tableName},</if>
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
<if test="className != null and className != ''">class_name = #{className},</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
<if test="genType != null and genType != ''">gen_type = #{genType},</if>
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
<if test="options != null and options != ''">options = #{options},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
</set>
where table_id = #{tableId}
</update>
<delete id="deleteGenTableByIds" parameterType="Long">
delete from gen_table where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>
</delete>
</mapper>

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 获得表定义分页
export function getCodeGenTablePage(query) {
return request({
url: '/tool/codegen/page',
url: '/tool/codegen/table/page',
method: 'get',
params: query
})
@ -16,3 +16,12 @@ export function getCodeGenDetail(tableId) {
method: 'get',
})
}
// 修改代码生成信息
export function updateCodegen(data) {
return request({
url: '/tool/codegen/update',
method: 'put',
data: data
})
}

View File

@ -9,23 +9,6 @@ export function listDbTable(query) {
})
}
// 查询表详细信息
export function getGenTable(tableId) {
return request({
url: '/tool/gen/' + tableId,
method: 'get'
})
}
// 修改代码生成信息
export function updateGenTable(data) {
return request({
url: '/tool/gen',
method: 'put',
data: data
})
}
// 导入表
export function importTable(data) {
return request({

View File

@ -39,3 +39,12 @@ export const SysDataScopeEnum = {
DEPT_AND_CHILD: 4, // 部门及以下数据权限
DEPT_SELF: 5 // 仅本人数据权限
}
/**
* 代码生成模板类型
*/
export const ToolCodegenTemplateTypeEnum = {
CRUD: 1, // 基础 CRUD
TREE: 2, // 树形 CRUD
SUB: 3, // 主子表 CRUD
}

View File

@ -16,7 +16,9 @@ export const DICT_TYPE = {
SYS_LOGIN_RESULT: 'sys_login_result',
SYS_CONFIG_TYPE: 'sys_config_type',
INF_REDIS_TIMEOUT_TYPE: 'inf_redis_timeout_type'
INF_REDIS_TIMEOUT_TYPE: 'inf_redis_timeout_type',
TOOL_CODEGEN_TEMPLATE_TYPE: 'tool_codegen_template_type',
}
/**

View File

@ -98,13 +98,11 @@
<template slot-scope="scope">
<el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
<el-option
v-for="dict in dictOptions"
:key="dict.dictType"
:label="dict.dictName"
:value="dict.dictType">
<span style="float: left">{{ dict.dictName }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
</el-option>
v-for="dict in dictOptions"
:key="dict.id"
:label="dict.name"
:value="dict.type"
/>
</el-select>
</template>
</el-table-column>
@ -128,9 +126,8 @@
</el-card>
</template>
<script>
import { updateGenTable } from "@/api/tool/gen";
import { getCodeGenDetail } from "@/api/tool/codegen";
import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
import { getCodeGenDetail, updateCodegen } from "@/api/tool/codegen";
import { listAllSimple as listAllSimpleDictType } from "@/api/system/dict/type";
import { listMenu as getMenuTreeselect } from "@/api/system/menu";
import basicInfoForm from "./basicInfoForm";
import genInfoForm from "./genInfoForm";
@ -169,7 +166,7 @@ export default {
this.columns = res.data.columns;
});
/** 查询字典下拉列表 */
getDictOptionselect().then(response => {
listAllSimpleDictType().then(response => {
this.dictOptions = response.data;
});
/** 查询菜单下拉列表 */
@ -186,7 +183,8 @@ export default {
Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
const validateResult = res.every(item => !!item);
if (validateResult) {
const genTable = Object.assign({}, basicForm.model, genForm.model);
const genTable = {};
genTable.table = Object.assign({}, basicForm.model, genForm.model);
genTable.columns = this.columns;
genTable.params = {
treeCode: genTable.treeCode,
@ -194,11 +192,9 @@ export default {
treeParentCode: genTable.treeParentCode,
parentMenuId: genTable.parentMenuId
};
updateGenTable(genTable).then(res => {
this.msgSuccess(res.msg);
if (res.code === 200) {
this.close();
}
updateCodegen(genTable).then(res => {
this.msgSuccess("修改成功!");
this.close();
});
} else {
this.msgError("表单校验未通过,请重新检查提交内容");

View File

@ -4,31 +4,34 @@
<el-col :span="12">
<el-form-item prop="tplCategory">
<span slot="label">生成模板</span>
<el-select v-model="info.tplCategory" @change="tplSelectChange">
<el-option label="单表(增删改查)" value="crud" />
<el-option label="树表(增删改查)" value="tree" />
<el-option label="主子表(增删改查)" value="sub" />
<el-select v-model="info.templateType" @change="tplSelectChange">
<el-option
v-for="dict in this.getDictDatas(DICT_TYPE.TOOL_CODEGEN_TEMPLATE_TYPE)"
:key="parseInt(dict.value)"
:label="dict.label"
:value="parseInt(dict.value)"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item prop="packageName">
<span slot="label">
生成包路径
<el-tooltip content="生成在哪个java包下例如 com.ruoyi.system" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
</span>
<el-input v-model="info.packageName" />
</el-form-item>
</el-col>
<!-- <el-col :span="12">-->
<!-- <el-form-item prop="packageName">-->
<!-- <span slot="label">-->
<!-- 生成包路径-->
<!-- <el-tooltip content="生成在哪个java包下例如 com.ruoyi.system" placement="top">-->
<!-- <i class="el-icon-question"></i>-->
<!-- </el-tooltip>-->
<!-- </span>-->
<!-- <el-input v-model="info.packageName" />-->
<!-- </el-form-item>-->
<!-- </el-col>-->
<el-col :span="12">
<el-form-item prop="moduleName">
<span slot="label">
生成模块名
<el-tooltip content="可理解为子系统名,例如 system" placement="top">
模块名
<el-tooltip content="模块名,即一级目录,例如 system、infra、tool 等等" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
</span>
@ -39,8 +42,8 @@
<el-col :span="12">
<el-form-item prop="businessName">
<span slot="label">
生成业务名
<el-tooltip content="可理解为功能英文名,例如 user" placement="top">
业务名
<el-tooltip content="业务名,即二级目录,例如 user、permission、dict 等等" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
</span>
@ -49,14 +52,26 @@
</el-col>
<el-col :span="12">
<el-form-item prop="functionName">
<el-form-item prop="className">
<span slot="label">
生成功能名
类名称
<el-tooltip content="类名称首字母大写例如SysUser、SysMenu、SysDictData 等等" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
</span>
<el-input v-model="info.className" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item prop="classComment">
<span slot="label">
类描述
<el-tooltip content="用作类描述,例如 用户" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
</span>
<el-input v-model="info.functionName" />
<el-input v-model="info.classComment" />
</el-form-item>
</el-col>
@ -79,19 +94,6 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item prop="genType">
<span slot="label">
生成代码方式
<el-tooltip content="默认为zip压缩包下载也可以自定义生成路径" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
</span>
<el-radio v-model="info.genType" label="0">zip压缩包</el-radio>
<el-radio v-model="info.genType" label="1">自定义路径</el-radio>
</el-form-item>
</el-col>
<el-col :span="24" v-if="info.genType == '1'">
<el-form-item prop="genPath">
<span slot="label">
@ -238,20 +240,23 @@ export default {
return {
subColumns: [],
rules: {
tplCategory: [
templateType: [
{ required: true, message: "请选择生成模板", trigger: "blur" }
],
packageName: [
{ required: true, message: "请输入生成包路径", trigger: "blur" }
],
// packageName: [
// { required: true, message: "", trigger: "blur" }
// ],
moduleName: [
{ required: true, message: "请输入生成模块名", trigger: "blur" }
],
businessName: [
{ required: true, message: "请输入生成业务名", trigger: "blur" }
],
functionName: [
{ required: true, message: "请输入生成功能名", trigger: "blur" }
className: [
{ required: true, message: "请输入生成类名称", trigger: "blur" }
],
classComment: [
{ required: true, message: "请输入生成类描述", trigger: "blur" }
],
}
};

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.dal.redis.dao.auth;
package cn.iocoder.dashboard.modules.system.dal.redis.auth;
import cn.iocoder.dashboard.framework.security.core.LoginUser;
import cn.iocoder.dashboard.util.json.JsonUtils;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.dal.redis.dao.common;
package cn.iocoder.dashboard.modules.system.dal.redis.common;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

View File

@ -1,4 +0,0 @@
/**
* 提供 Redis 访问的 DAO
*/
package cn.iocoder.dashboard.modules.system.dal.redis.dao;

View File

@ -10,7 +10,7 @@ import cn.iocoder.dashboard.modules.system.controller.auth.vo.session.SysUserSes
import cn.iocoder.dashboard.modules.system.dal.mysql.auth.SysUserSessionMapper;
import cn.iocoder.dashboard.modules.system.dal.dataobject.auth.SysUserSessionDO;
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.dashboard.modules.system.dal.redis.dao.auth.SysLoginUserRedisDAO;
import cn.iocoder.dashboard.modules.system.dal.redis.auth.SysLoginUserRedisDAO;
import cn.iocoder.dashboard.modules.system.service.auth.SysUserSessionService;
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
import org.springframework.stereotype.Service;

View File

@ -6,7 +6,7 @@ import cn.hutool.core.util.IdUtil;
import cn.iocoder.dashboard.framework.captcha.config.CaptchaProperties;
import cn.iocoder.dashboard.modules.system.controller.common.vo.SysCaptchaImageRespVO;
import cn.iocoder.dashboard.modules.system.convert.common.SysCaptchaConvert;
import cn.iocoder.dashboard.modules.system.dal.redis.dao.common.SysCaptchaRedisDAO;
import cn.iocoder.dashboard.modules.system.dal.redis.common.SysCaptchaRedisDAO;
import cn.iocoder.dashboard.modules.system.service.common.SysCaptchaService;
import org.springframework.stereotype.Service;

View File

@ -3,8 +3,9 @@ package cn.iocoder.dashboard.modules.tool.controller.codegen;
import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenDetailRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTableRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO;
import cn.iocoder.dashboard.modules.tool.convert.codegen.ToolCodegenConvert;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
@ -30,7 +31,7 @@ public class ToolCodegenController {
private ToolCodegenService codegenService;
@ApiOperation("获得表定义分页")
@GetMapping("/page")
@GetMapping("/table/page")
// TODO 权限 @PreAuthorize("@ss.hasPermi('tool:gen:list')")
public CommonResult<PageResult<ToolCodegenTableRespVO>> getCodeGenTablePage(@Valid ToolCodegenTablePageReqVO pageReqVO) {
PageResult<ToolCodegenTableDO> pageResult = codegenService.getCodeGenTablePage(pageReqVO);
@ -50,8 +51,19 @@ public class ToolCodegenController {
@ApiOperation("基于数据库的表结构,创建代码生成器的表定义")
@PostMapping("/create")
// TODO 权限
public CommonResult<Long> createCodeGenTable(@RequestParam("tableName") String tableName) {
return success(codegenService.createCodegenTable(tableName));
public CommonResult<Long> createCodeGen(@RequestParam("tableName") String tableName) {
return success(codegenService.createCodegen(tableName));
}
/**
* 修改保存代码生成业务
*/
@ApiOperation("更新数据库的表和字段定义")
@PutMapping("/update")
// @PreAuthorize("@ss.hasPermi('tool:gen:edit')") TODO 权限
public CommonResult<Boolean> updateCodegen(@Valid @RequestBody ToolCodegenUpdateReqVO updateReqVO) {
codegenService.updateCodegen(updateReqVO);
return success(true);
}
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.column.ToolCodegenColumnRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

View File

@ -0,0 +1,49 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.column.ToolCodegenColumnBaseVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTableBaseVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
@ApiModel("代码生成表和字段的修改 Request VO")
@Data
public class ToolCodegenUpdateReqVO {
@Valid // 校验内嵌的字段
@NotNull(message = "表定义不能为空")
private Table table;
@Valid // 校验内嵌的字段
@NotNull(message = "字段定义不能为空")
private List<Column> columns;
@ApiModel("更新表定义")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public static class Table extends ToolCodegenTableBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1")
private Long id;
}
@ApiModel("更新表定义")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public static class Column extends ToolCodegenColumnBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1")
private Long id;
}
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo.column;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo.column;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table;
import cn.iocoder.dashboard.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,9 +1,10 @@
package cn.iocoder.dashboard.modules.tool.convert.codegen;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenColumnRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.column.ToolCodegenColumnRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenDetailRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTableRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO;
@ -38,6 +39,10 @@ public interface ToolCodegenConvert {
List<ToolCodegenColumnRespVO> convertList02(List<ToolCodegenColumnDO> list);
ToolCodegenTableDO convert(ToolCodegenUpdateReqVO.Table bean);
List<ToolCodegenColumnDO> convertList03(List<ToolCodegenUpdateReqVO.Column> columns);
// ========== 其它 ==========
default ToolCodegenDetailRespVO convert(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) {

View File

@ -43,7 +43,7 @@ public class ToolCodegenTableDO extends BaseDO {
/**
* 模块名即一级目录
*
* 例如说infrasystemtool 等等
* 例如说systeminfratool 等等
*/
private String moduleName;
/**

View File

@ -3,7 +3,7 @@ package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

View File

@ -12,10 +12,10 @@ import lombok.Getter;
@Getter
public enum ToolCodegenTemplateTypeEnum {
CRUD(1), // 基础 CRUD
TREE(2), // CRUD
CRUD(1), // 单表增删改查
TREE(2), // 增删改查
// TODO 主子表暂时不考虑支持原因是较为灵活形态较多很难评估
SUB(3) // 主子表 CRUD
SUB(3) // 主子表增删改查
;
/**

View File

@ -1,7 +1,8 @@
package cn.iocoder.dashboard.modules.tool.service.codegen;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
@ -20,7 +21,14 @@ public interface ToolCodegenService {
* @param tableName 表名称
* @return 表定义的编号
*/
Long createCodegenTable(String tableName);
Long createCodegen(String tableName);
/**
* 更新数据库的表和字段定义
*
* @param updateReqVO 更新信息
*/
void updateCodegen(ToolCodegenUpdateReqVO updateReqVO);
/**
* 获得表定义分页

View File

@ -2,7 +2,9 @@ package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.convert.codegen.ToolCodegenConvert;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenColumnMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenTableMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolInformationSchemaColumnMapper;
@ -42,7 +44,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Override
@Transactional
public Long createCodegenTable(String tableName) {
public Long createCodegen(String tableName) {
// 从数据库中获得数据库表结构
ToolInformationSchemaTableDO schemaTable = informationSchemaTableMapper.selectByTableName(tableName);
if (schemaTable == null) {
@ -69,6 +71,22 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
return table.getId();
}
@Override
@Transactional
public void updateCodegen(ToolCodegenUpdateReqVO updateReqVO) {
// 校验是否已经存在
if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) {
throw new RuntimeException(""); // TODO
}
// 更新 table 表定义
ToolCodegenTableDO updateTableObj = ToolCodegenConvert.INSTANCE.convert(updateReqVO.getTable());
codegenTableMapper.updateById(updateTableObj);
// 更新 column 字段定义
List<ToolCodegenColumnDO> updateColumnObjs = ToolCodegenConvert.INSTANCE.convertList03(updateReqVO.getColumns());
updateColumnObjs.forEach(updateColumnObj -> codegenColumnMapper.updateById(updateColumnObj));
}
@Override
public PageResult<ToolCodegenTableDO> getCodeGenTablePage(ToolCodegenTablePageReqVO pageReqVO) {
return codegenTableMapper.selectPage(pageReqVO);

View File

@ -39,8 +39,8 @@ spring:
write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳
fail-on-empty-beans: false # 允许序列化无属性的 Bean
main:
lazy-initialization: true # TODO 芋艿:本地开发环境,可以配置下 lazy 延迟加载
# main:
# lazy-initialization: true # TODO 芋艿:本地开发环境,可以配置下 lazy 延迟加载
# 芋道配置项,设置当前项目所有自定义的配置
yudao:

View File

@ -15,7 +15,7 @@ import ${CommonResultClassName};
import static ${CommonResultClassName}.success;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service;

View File

@ -7,7 +7,7 @@ import ${PageResultClassName};
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
/**
* ${table.classComment} Convert

View File

@ -1,4 +1,4 @@
package ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName};
package ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName};
import lombok.*;
import java.util.*;

View File

@ -1,9 +1,9 @@
package ${basePackage}.${table.moduleName}.dal.mysql.dao.${table.businessName};
package ${basePackage}.${table.moduleName}.dal.mysql.${table.businessName};
import ${PageResultClassName};
import ${QueryWrapperClassName};
import ${BaseMapperClassName};
import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
import org.apache.ibatis.annotations.Mapper;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.${table.className}PageReqVO;

View File

@ -3,7 +3,7 @@ package ${basePackage}.${table.moduleName}.service.${table.businessName};
import java.util.*;
import javax.validation.*;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
import ${PageResultClassName};
/**

View File

@ -7,11 +7,11 @@ import org.springframework.validation.annotation.Validated;
import java.util.*;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
import ${PageResultClassName};
import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
import ${basePackage}.${table.moduleName}.dal.mysql.dao.${table.businessName}.${table.className}Mapper;
import ${basePackage}.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service;
import ${ServiceExceptionUtilClassName};

View File

@ -6,8 +6,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ToolCodegenServiceImplTest {
@ -18,7 +16,7 @@ class ToolCodegenServiceImplTest {
public void tetCreateCodegenTable() {
// toolCodegenService.createCodegenTable("sys_test_demo");
// toolCodegenService.createCodegenTable("tool_codegen_table");
toolCodegenService.createCodegenTable("tool_codegen_column");
toolCodegenService.createCodegen("tool_codegen_column");
}
}