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

2. 清理多余代码
pull/2/head
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(); 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); 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 where t.table_name = #{tableName} order by c.sort
</select> </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> </mapper>

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 获得表定义分页 // 获得表定义分页
export function getCodeGenTablePage(query) { export function getCodeGenTablePage(query) {
return request({ return request({
url: '/tool/codegen/page', url: '/tool/codegen/table/page',
method: 'get', method: 'get',
params: query params: query
}) })
@ -16,3 +16,12 @@ export function getCodeGenDetail(tableId) {
method: 'get', 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) { export function importTable(data) {
return request({ return request({

View File

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

View File

@ -4,31 +4,34 @@
<el-col :span="12"> <el-col :span="12">
<el-form-item prop="tplCategory"> <el-form-item prop="tplCategory">
<span slot="label">生成模板</span> <span slot="label">生成模板</span>
<el-select v-model="info.tplCategory" @change="tplSelectChange"> <el-select v-model="info.templateType" @change="tplSelectChange">
<el-option label="单表(增删改查)" value="crud" /> <el-option
<el-option label="树表(增删改查)" value="tree" /> v-for="dict in this.getDictDatas(DICT_TYPE.TOOL_CODEGEN_TEMPLATE_TYPE)"
<el-option label="主子表(增删改查)" value="sub" /> :key="parseInt(dict.value)"
:label="dict.label"
:value="parseInt(dict.value)"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <!-- <el-col :span="12">-->
<el-form-item prop="packageName"> <!-- <el-form-item prop="packageName">-->
<span slot="label"> <!-- <span slot="label">-->
生成包路径 <!-- 生成包路径-->
<el-tooltip content="生成在哪个java包下例如 com.ruoyi.system" placement="top"> <!-- <el-tooltip content="生成在哪个java包下例如 com.ruoyi.system" placement="top">-->
<i class="el-icon-question"></i> <!-- <i class="el-icon-question"></i>-->
</el-tooltip> <!-- </el-tooltip>-->
</span> <!-- </span>-->
<el-input v-model="info.packageName" /> <!-- <el-input v-model="info.packageName" />-->
</el-form-item> <!-- </el-form-item>-->
</el-col> <!-- </el-col>-->
<el-col :span="12"> <el-col :span="12">
<el-form-item prop="moduleName"> <el-form-item prop="moduleName">
<span slot="label"> <span slot="label">
生成模块名 模块名
<el-tooltip content="可理解为子系统名,例如 system" placement="top"> <el-tooltip content="模块名,即一级目录,例如 system、infra、tool 等等" placement="top">
<i class="el-icon-question"></i> <i class="el-icon-question"></i>
</el-tooltip> </el-tooltip>
</span> </span>
@ -39,8 +42,8 @@
<el-col :span="12"> <el-col :span="12">
<el-form-item prop="businessName"> <el-form-item prop="businessName">
<span slot="label"> <span slot="label">
生成业务名 业务名
<el-tooltip content="可理解为功能英文名,例如 user" placement="top"> <el-tooltip content="业务名,即二级目录,例如 user、permission、dict 等等" placement="top">
<i class="el-icon-question"></i> <i class="el-icon-question"></i>
</el-tooltip> </el-tooltip>
</span> </span>
@ -49,14 +52,26 @@
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item prop="functionName"> <el-form-item prop="className">
<span slot="label"> <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"> <el-tooltip content="用作类描述,例如 用户" placement="top">
<i class="el-icon-question"></i> <i class="el-icon-question"></i>
</el-tooltip> </el-tooltip>
</span> </span>
<el-input v-model="info.functionName" /> <el-input v-model="info.classComment" />
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -79,19 +94,6 @@
</el-form-item> </el-form-item>
</el-col> </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-col :span="24" v-if="info.genType == '1'">
<el-form-item prop="genPath"> <el-form-item prop="genPath">
<span slot="label"> <span slot="label">
@ -238,20 +240,23 @@ export default {
return { return {
subColumns: [], subColumns: [],
rules: { rules: {
tplCategory: [ templateType: [
{ required: true, message: "请选择生成模板", trigger: "blur" } { required: true, message: "请选择生成模板", trigger: "blur" }
], ],
packageName: [ // packageName: [
{ required: true, message: "请输入生成包路径", trigger: "blur" } // { required: true, message: "", trigger: "blur" }
], // ],
moduleName: [ moduleName: [
{ required: true, message: "请输入生成模块名", trigger: "blur" } { required: true, message: "请输入生成模块名", trigger: "blur" }
], ],
businessName: [ businessName: [
{ required: true, message: "请输入生成业务名", trigger: "blur" } { required: true, message: "请输入生成业务名", trigger: "blur" }
], ],
functionName: [ className: [
{ required: true, message: "请输入生成功能名", trigger: "blur" } { 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.framework.security.core.LoginUser;
import cn.iocoder.dashboard.util.json.JsonUtils; 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.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository; 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.mysql.auth.SysUserSessionMapper;
import cn.iocoder.dashboard.modules.system.dal.dataobject.auth.SysUserSessionDO; 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.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.auth.SysUserSessionService;
import cn.iocoder.dashboard.modules.system.service.user.SysUserService; import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
import org.springframework.stereotype.Service; 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.framework.captcha.config.CaptchaProperties;
import cn.iocoder.dashboard.modules.system.controller.common.vo.SysCaptchaImageRespVO; 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.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 cn.iocoder.dashboard.modules.system.service.common.SysCaptchaService;
import org.springframework.stereotype.Service; 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.CommonResult;
import cn.iocoder.dashboard.common.pojo.PageResult; 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.ToolCodegenDetailRespVO;
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.ToolCodegenTableRespVO; 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.convert.codegen.ToolCodegenConvert;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO; 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.ToolCodegenTableDO;
@ -30,7 +31,7 @@ public class ToolCodegenController {
private ToolCodegenService codegenService; private ToolCodegenService codegenService;
@ApiOperation("获得表定义分页") @ApiOperation("获得表定义分页")
@GetMapping("/page") @GetMapping("/table/page")
// TODO 权限 @PreAuthorize("@ss.hasPermi('tool:gen:list')") // TODO 权限 @PreAuthorize("@ss.hasPermi('tool:gen:list')")
public CommonResult<PageResult<ToolCodegenTableRespVO>> getCodeGenTablePage(@Valid ToolCodegenTablePageReqVO pageReqVO) { public CommonResult<PageResult<ToolCodegenTableRespVO>> getCodeGenTablePage(@Valid ToolCodegenTablePageReqVO pageReqVO) {
PageResult<ToolCodegenTableDO> pageResult = codegenService.getCodeGenTablePage(pageReqVO); PageResult<ToolCodegenTableDO> pageResult = codegenService.getCodeGenTablePage(pageReqVO);
@ -50,8 +51,19 @@ public class ToolCodegenController {
@ApiOperation("基于数据库的表结构,创建代码生成器的表定义") @ApiOperation("基于数据库的表结构,创建代码生成器的表定义")
@PostMapping("/create") @PostMapping("/create")
// TODO 权限 // TODO 权限
public CommonResult<Long> createCodeGenTable(@RequestParam("tableName") String tableName) { public CommonResult<Long> createCodeGen(@RequestParam("tableName") String tableName) {
return success(codegenService.createCodegenTable(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; 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.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; 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 io.swagger.annotations.ApiModelProperty;
import lombok.Data; 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.ApiModel;
import io.swagger.annotations.ApiModelProperty; 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 io.swagger.annotations.ApiModelProperty;
import lombok.Data; 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 cn.iocoder.dashboard.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; 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.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;

View File

@ -1,9 +1,10 @@
package cn.iocoder.dashboard.modules.tool.convert.codegen; package cn.iocoder.dashboard.modules.tool.convert.codegen;
import cn.iocoder.dashboard.common.pojo.PageResult; 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.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.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO; import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO;
@ -38,6 +39,10 @@ public interface ToolCodegenConvert {
List<ToolCodegenColumnRespVO> convertList02(List<ToolCodegenColumnDO> list); 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) { default ToolCodegenDetailRespVO convert(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) {

View File

@ -43,7 +43,7 @@ public class ToolCodegenTableDO extends BaseDO {
/** /**
* *
* *
* infrasystemtool * systeminfratool
*/ */
private String moduleName; 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.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; 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 cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;

View File

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

View File

@ -1,7 +1,8 @@
package cn.iocoder.dashboard.modules.tool.service.codegen; package cn.iocoder.dashboard.modules.tool.service.codegen;
import cn.iocoder.dashboard.common.pojo.PageResult; 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.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
@ -20,7 +21,14 @@ public interface ToolCodegenService {
* @param tableName * @param tableName
* @return * @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.hutool.core.collection.CollUtil;
import cn.iocoder.dashboard.common.pojo.PageResult; 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.ToolCodegenColumnMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenTableMapper; import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenTableMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolInformationSchemaColumnMapper; import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolInformationSchemaColumnMapper;
@ -42,7 +44,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Override @Override
@Transactional @Transactional
public Long createCodegenTable(String tableName) { public Long createCodegen(String tableName) {
// 从数据库中,获得数据库表结构 // 从数据库中,获得数据库表结构
ToolInformationSchemaTableDO schemaTable = informationSchemaTableMapper.selectByTableName(tableName); ToolInformationSchemaTableDO schemaTable = informationSchemaTableMapper.selectByTableName(tableName);
if (schemaTable == null) { if (schemaTable == null) {
@ -69,6 +71,22 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
return table.getId(); 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 @Override
public PageResult<ToolCodegenTableDO> getCodeGenTablePage(ToolCodegenTablePageReqVO pageReqVO) { public PageResult<ToolCodegenTableDO> getCodeGenTablePage(ToolCodegenTablePageReqVO pageReqVO) {
return codegenTableMapper.selectPage(pageReqVO); return codegenTableMapper.selectPage(pageReqVO);

View File

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

View File

@ -15,7 +15,7 @@ import ${CommonResultClassName};
import static ${CommonResultClassName}.success; import static ${CommonResultClassName}.success;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; 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}.convert.${table.businessName}.${table.className}Convert;
import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service; 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.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; 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 * ${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 lombok.*;
import java.util.*; 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 ${PageResultClassName};
import ${QueryWrapperClassName}; import ${QueryWrapperClassName};
import ${BaseMapperClassName}; 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 org.apache.ibatis.annotations.Mapper;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.${table.className}PageReqVO; 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 java.util.*;
import javax.validation.*; import javax.validation.*;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; 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 ${PageResultClassName};
/** /**

View File

@ -7,11 +7,11 @@ import org.springframework.validation.annotation.Validated;
import java.util.*; import java.util.*;
import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; 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 ${PageResultClassName};
import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; 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 ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service;
import ${ServiceExceptionUtilClassName}; import ${ServiceExceptionUtilClassName};

View File

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