mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 12:28:10 +00:00
update 代码生成sql模板适配雪花id
This commit is contained in:
@@ -11,7 +11,6 @@ import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
import com.ruoyi.gen.domain.GenTable;
|
||||
import com.ruoyi.gen.domain.GenTableColumn;
|
||||
import com.ruoyi.gen.service.IGenTableColumnService;
|
||||
import com.ruoyi.gen.service.IGenTableService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -38,7 +37,6 @@ import java.util.Map;
|
||||
public class GenController extends BaseController {
|
||||
|
||||
private final IGenTableService genTableService;
|
||||
private final IGenTableColumnService genTableColumnService;
|
||||
|
||||
/**
|
||||
* 查询代码生成列表
|
||||
@@ -59,7 +57,7 @@ public class GenController extends BaseController {
|
||||
public R<Map<String, Object>> getInfo(@PathVariable Long tableId) {
|
||||
GenTable table = genTableService.selectGenTableById(tableId);
|
||||
List<GenTable> tables = genTableService.selectGenTableAll();
|
||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
||||
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("info", table);
|
||||
map.put("rows", list);
|
||||
@@ -84,7 +82,7 @@ public class GenController extends BaseController {
|
||||
@GetMapping(value = "/column/{tableId}")
|
||||
public TableDataInfo<GenTableColumn> columnList(Long tableId) {
|
||||
TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>();
|
||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
||||
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
|
||||
dataInfo.setRows(list);
|
||||
dataInfo.setTotal(list.size());
|
||||
return dataInfo;
|
||||
|
@@ -153,6 +153,12 @@ public class GenTable extends BaseEntity {
|
||||
@TableField(exist = false)
|
||||
private String treeName;
|
||||
|
||||
/*
|
||||
* 菜单id列表
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<Long> menuIds;
|
||||
|
||||
/**
|
||||
* 上级菜单ID字段
|
||||
*/
|
||||
|
@@ -1,69 +0,0 @@
|
||||
package com.ruoyi.gen.service;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.gen.domain.GenTableColumn;
|
||||
import com.ruoyi.gen.mapper.GenTableColumnMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
||||
|
||||
private final GenTableColumnMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
||||
return baseMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
|
||||
.eq(GenTableColumn::getTableId, tableId)
|
||||
.orderByAsc(GenTableColumn::getSort));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn) {
|
||||
return baseMapper.insert(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn) {
|
||||
return baseMapper.updateById(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务字段对象
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteGenTableColumnByIds(String ids) {
|
||||
return baseMapper.deleteBatchIds(Arrays.asList(Convert.toLongArray(ids)));
|
||||
}
|
||||
}
|
@@ -3,6 +3,8 @@ package com.ruoyi.gen.service;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -31,7 +33,6 @@ import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -57,6 +58,19 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
private final GenTableMapper baseMapper;
|
||||
private final GenTableColumnMapper genTableColumnMapper;
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
||||
return genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
|
||||
.eq(GenTableColumn::getTableId, tableId)
|
||||
.orderByAsc(GenTableColumn::getSort));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询业务信息
|
||||
*
|
||||
@@ -158,7 +172,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateGenTable(GenTable genTable) {
|
||||
String options = JsonUtils.toJsonString(genTable.getParams());
|
||||
genTable.setOptions(options);
|
||||
@@ -177,7 +190,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteGenTableByIds(Long[] tableIds) {
|
||||
List<Long> ids = Arrays.asList(tableIds);
|
||||
baseMapper.deleteBatchIds(ids);
|
||||
@@ -190,7 +202,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
* @param tableList 导入表列表
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importGenTable(List<GenTable> tableList) {
|
||||
String operName = LoginHelper.getUsername();
|
||||
try {
|
||||
@@ -227,6 +238,12 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
// 查询表信息
|
||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
||||
Snowflake snowflake = IdUtil.getSnowflake();
|
||||
List<Long> menuIds = new ArrayList<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
menuIds.add(snowflake.nextId());
|
||||
}
|
||||
table.setMenuIds(menuIds);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
@@ -271,6 +288,12 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
public void generatorCode(String tableName) {
|
||||
// 查询表信息
|
||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||
Snowflake snowflake = IdUtil.getSnowflake();
|
||||
List<Long> menuIds = new ArrayList<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
menuIds.add(snowflake.nextId());
|
||||
}
|
||||
table.setMenuIds(menuIds);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
@@ -304,7 +327,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void synchDb(String tableName) {
|
||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||
List<GenTableColumn> tableColumns = table.getColumns();
|
||||
|
@@ -1,44 +0,0 @@
|
||||
package com.ruoyi.gen.service;
|
||||
|
||||
import com.ruoyi.gen.domain.GenTableColumn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IGenTableColumnService {
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 删除业务字段信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteGenTableColumnByIds(String ids);
|
||||
}
|
@@ -3,6 +3,7 @@ package com.ruoyi.gen.service;
|
||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
import com.ruoyi.gen.domain.GenTable;
|
||||
import com.ruoyi.gen.domain.GenTableColumn;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -14,6 +15,14 @@ import java.util.Map;
|
||||
*/
|
||||
public interface IGenTableService {
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
|
||||
TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery);
|
||||
|
||||
TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery);
|
||||
|
@@ -1,22 +1,19 @@
|
||||
-- 菜单 SQL
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
|
||||
|
||||
-- 按钮父菜单ID
|
||||
SELECT @parentId := LAST_INSERT_ID();
|
||||
|
||||
-- 按钮 SQL
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('${functionName}查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('${functionName}新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('${functionName}修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('${functionName}删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values('${functionName}导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', sysdate(), '', null, '');
|
||||
-- 菜单 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values(${table.menuIds[0]}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
|
||||
|
||||
-- 按钮 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values(${table.menuIds[1]}, '${functionName}查询', ${table.menuIds[0]}, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values(${table.menuIds[2]}, '${functionName}新增', ${table.menuIds[0]}, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values(${table.menuIds[3]}, '${functionName}修改', ${table.menuIds[0]}, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values(${table.menuIds[4]}, '${functionName}删除', ${table.menuIds[0]}, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', sysdate(), '', null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||
values(${table.menuIds[5]}, '${functionName}导出', ${table.menuIds[0]}, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', sysdate(), '', null, '');
|
||||
|
Reference in New Issue
Block a user