修改代码生成模块

This commit is contained in:
jinqiming 2021-12-24 17:53:16 +08:00
parent 9db7adfd18
commit 7d4f28e037
16 changed files with 338 additions and 202 deletions

View File

@ -0,0 +1,24 @@
package com.snow.flowable;
import com.snow.JunitTestApplication;
import com.snow.generator.service.impl.GenTableServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author qimingjin
* @Title:
* @Description:
* @date 2021/12/24 11:21
*/
@Slf4j
public class GenTableTests extends JunitTestApplication {
@Autowired
private GenTableServiceImpl genTableServiceImpl;
@Test
public void createMenu(){
genTableServiceImpl.createMenu("sys_menu_c");
}
}

View File

@ -0,0 +1,35 @@
package com.snow.framework.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @author snow
*/
@Component
public class MybatisMetaObjectHandlerConfig implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
Object createTime = getFieldValByName("createTime", metaObject);
Object updateTime = getFieldValByName("updateTime", metaObject);
if (createTime == null){
setFieldValByName("createTime",new Date(), metaObject);
}
if (updateTime == null){
setFieldValByName("updateTime",new Date(), metaObject);
}
}
@Override
public void updateFill(MetaObject metaObject) {
Object updateTime = getFieldValByName("updateTime", metaObject);
if (updateTime == null) {
setFieldValByName("updateTime", new Date(), metaObject);
}
}
}

View File

@ -26,7 +26,7 @@
<!-- 通用工具--> <!-- 通用工具-->
<dependency> <dependency>
<groupId>com.snow</groupId> <groupId>com.snow</groupId>
<artifactId>snow-common</artifactId> <artifactId>snow-system</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1,30 +1,10 @@
package com.snow.generator.controller; package com.snow.generator.controller;
import java.io.IOException; import cn.hutool.core.util.StrUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.druid.DbType; import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils; import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement; import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
import com.snow.common.utils.sql.SqlUtil;
import com.snow.generator.domain.GenTable;
import com.snow.generator.domain.GenTableColumn;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.snow.common.annotation.Log; import com.snow.common.annotation.Log;
import com.snow.common.core.controller.BaseController; import com.snow.common.core.controller.BaseController;
@ -35,8 +15,25 @@ import com.snow.common.core.text.Convert;
import com.snow.common.enums.BusinessType; import com.snow.common.enums.BusinessType;
import com.snow.common.utils.StringUtils; import com.snow.common.utils.StringUtils;
import com.snow.common.utils.security.PermissionUtils; import com.snow.common.utils.security.PermissionUtils;
import com.snow.common.utils.sql.SqlUtil;
import com.snow.generator.domain.GenTable;
import com.snow.generator.domain.GenTableColumn;
import com.snow.generator.service.IGenTableColumnService; import com.snow.generator.service.IGenTableColumnService;
import com.snow.generator.service.IGenTableService; import com.snow.generator.service.IGenTableService;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/** /**
* 代码生成 操作处理 * 代码生成 操作处理
@ -150,7 +147,7 @@ public class GenController extends BaseController
for (SQLStatement sqlStatement : sqlStatements) { for (SQLStatement sqlStatement : sqlStatements) {
if (sqlStatement instanceof MySqlCreateTableStatement) { if (sqlStatement instanceof MySqlCreateTableStatement) {
MySqlCreateTableStatement createTableStatement = (MySqlCreateTableStatement) sqlStatement; MySqlCreateTableStatement createTableStatement = (MySqlCreateTableStatement) sqlStatement;
if (genTableService.createTable(createTableStatement.toString())) { if (genTableService.createTable(StrUtil.removeAll(String.valueOf(createTableStatement),'\r', '\n','\t'))) {
String tableName = createTableStatement.getTableName().replaceAll("`", ""); String tableName = createTableStatement.getTableName().replaceAll("`", "");
tableNames.add(tableName); tableNames.add(tableName);
} }
@ -178,6 +175,20 @@ public class GenController extends BaseController
genTableService.synchDb(tableName); genTableService.synchDb(tableName);
return AjaxResult.success(); return AjaxResult.success();
} }
/**
* 生成系统菜单
*/
@RequiresPermissions("tool:gen:createMenu")
@Log(title = "菜单生成", businessType = BusinessType.INSERT)
@GetMapping("/createMenu/{tableName}")
@ResponseBody
public AjaxResult createMenu(@PathVariable("tableName") String tableName)
{
genTableService.createMenu(tableName);
return AjaxResult.success();
}
/** /**
* 修改代码生成业务 * 修改代码生成业务
*/ */

View File

@ -2,6 +2,7 @@ package com.snow.generator.mapper;
import java.util.List; import java.util.List;
import com.snow.generator.domain.GenTable; import com.snow.generator.domain.GenTable;
import org.apache.ibatis.annotations.Param;
/** /**
* 业务 数据层 * 业务 数据层
@ -88,5 +89,5 @@ public interface GenTableMapper
* @param sql * @param sql
* @return 结果 * @return 结果
*/ */
public int createTable(String sql); public int createTable(@Param("sql") String sql);
} }

View File

@ -1,23 +1,27 @@
package com.snow.generator.service.impl; package com.snow.generator.service.impl;
import java.io.ByteArrayOutputStream; import cn.hutool.core.util.StrUtil;
import java.io.File; import com.alibaba.fastjson.JSON;
import java.io.IOException; import com.alibaba.fastjson.JSONObject;
import java.io.StringWriter; import com.snow.common.constant.Constants;
import java.util.LinkedHashMap; import com.snow.common.constant.GenConstants;
import java.util.List; import com.snow.common.core.text.CharsetKit;
import java.util.Map; import com.snow.common.core.text.Convert;
import java.util.stream.Collectors; import com.snow.common.exception.BusinessException;
import java.util.zip.ZipEntry; import com.snow.common.utils.DateUtils;
import java.util.zip.ZipOutputStream; import com.snow.common.utils.StringUtils;
import com.snow.common.utils.file.FileUtils;
import com.aliyun.oss.ServiceException;
import com.snow.generator.domain.GenTable; import com.snow.generator.domain.GenTable;
import com.snow.generator.domain.GenTableColumn; import com.snow.generator.domain.GenTableColumn;
import com.snow.generator.mapper.GenTableColumnMapper;
import com.snow.generator.mapper.GenTableMapper;
import com.snow.generator.service.IGenTableService; import com.snow.generator.service.IGenTableService;
import com.snow.generator.util.GenUtils; import com.snow.generator.util.GenUtils;
import com.snow.generator.util.VelocityInitializer; import com.snow.generator.util.VelocityInitializer;
import com.snow.generator.util.VelocityUtils; import com.snow.generator.util.VelocityUtils;
import com.snow.system.domain.SysMenu;
import com.snow.system.service.ISysMenuService;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template; import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext; import org.apache.velocity.VelocityContext;
@ -27,17 +31,19 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import java.awt.*;
import com.snow.common.constant.Constants; import java.io.ByteArrayOutputStream;
import com.snow.common.constant.GenConstants; import java.io.File;
import com.snow.common.core.text.CharsetKit; import java.io.IOException;
import com.snow.common.core.text.Convert; import java.io.StringWriter;
import com.snow.common.exception.BusinessException; import java.util.Arrays;
import com.snow.common.utils.StringUtils; import java.util.LinkedHashMap;
import com.snow.common.utils.file.FileUtils; import java.util.List;
import com.snow.generator.mapper.GenTableColumnMapper; import java.util.Map;
import com.snow.generator.mapper.GenTableMapper; import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* 业务 服务层实现 * 业务 服务层实现
@ -55,6 +61,9 @@ public class GenTableServiceImpl implements IGenTableService
@Autowired @Autowired
private GenTableColumnMapper genTableColumnMapper; private GenTableColumnMapper genTableColumnMapper;
@Autowired
private ISysMenuService sysMenuService;
/** /**
* 查询业务信息 * 查询业务信息
* *
@ -145,7 +154,7 @@ public class GenTableServiceImpl implements IGenTableService
* @return 结果 * @return 结果
*/ */
@Override @Override
//@Transactional @Transactional
public void deleteGenTableByIds(String ids) public void deleteGenTableByIds(String ids)
{ {
genTableMapper.deleteGenTableByIds(Convert.toLongArray(ids)); genTableMapper.deleteGenTableByIds(Convert.toLongArray(ids));
@ -172,20 +181,69 @@ public class GenTableServiceImpl implements IGenTableService
setSubTable(table); setSubTable(table);
// 设置主键列信息 // 设置主键列信息
setPkColumn(table); setPkColumn(table);
VelocityInitializer.initVelocity(); //取父级菜单
VelocityContext context = VelocityUtils.prepareContext(table); String options = table.getOptions();
// 获取模板列表 JSONObject paramsObj = JSON.parseObject(options);
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); String parentMenuId = VelocityUtils.getParentMenuId(paramsObj);
for (String template : templates) { //保存菜单
if (StringUtils.contains(template, "sql.vm")) { SysMenu sysMenu=new SysMenu();
// 渲染模板 sysMenu.setMenuName(table.getFunctionName());
StringWriter sw = new StringWriter(); sysMenu.setParentId(Long.parseLong(parentMenuId));
Template tpl = Velocity.getTemplate(template, Constants.UTF8); sysMenu.setOrderNum("1");
tpl.merge(context, sw); sysMenu.setUrl(StrUtil.format("/{}/{}",table.getModuleName(),table.getBusinessName()));
log.info("@@生成菜单时组装的SQL:{}",sw.toString()); sysMenu.setMenuType("C");
genTableMapper.createTable(sw.toString()); sysMenu.setPerms(StrUtil.format("{}:view",VelocityUtils.getPermissionPrefix(table.getModuleName(), table.getBusinessName())));
} sysMenu.setRemark(StrUtil.format("{}菜单",table.getFunctionName()));
} sysMenu.setCreateBy(table.getCreateBy());
sysMenuService.save(sysMenu);
//保存权限
List<SysMenu> sysMenuList= Lists.newArrayList();
SysMenu queryMenu=new SysMenu();
queryMenu.setMenuName(StrUtil.format("{}查询",table.getFunctionName()));
queryMenu.setParentId(sysMenu.getMenuId());
queryMenu.setOrderNum("1");
queryMenu.setUrl("#");
queryMenu.setMenuType("F");
queryMenu.setPerms(StrUtil.format("{}:list",VelocityUtils.getPermissionPrefix(table.getModuleName(), table.getBusinessName())));
queryMenu.setRemark(StrUtil.format("{}查询",table.getFunctionName()));
sysMenuList.add(queryMenu);
SysMenu insertMenu=new SysMenu();
insertMenu.setMenuName(StrUtil.format("{}新增",table.getFunctionName()));
insertMenu.setParentId(sysMenu.getMenuId());
insertMenu.setOrderNum("2");
insertMenu.setUrl("#");
insertMenu.setMenuType("F");
insertMenu.setPerms(StrUtil.format("{}:add",VelocityUtils.getPermissionPrefix(table.getModuleName(), table.getBusinessName())));
insertMenu.setRemark(StrUtil.format("{}新增",table.getFunctionName()));
sysMenuList.add(insertMenu);
SysMenu editMenu=new SysMenu();
editMenu.setMenuName(StrUtil.format("{}修改",table.getFunctionName()));
editMenu.setParentId(sysMenu.getMenuId());
editMenu.setOrderNum("3");
editMenu.setUrl("#");
editMenu.setMenuType("F");
editMenu.setPerms(StrUtil.format("{}:edit",VelocityUtils.getPermissionPrefix(table.getModuleName(), table.getBusinessName())));
editMenu.setRemark(StrUtil.format("{}修改",table.getFunctionName()));
sysMenuList.add(editMenu);
SysMenu deleteMenu=new SysMenu();
deleteMenu.setMenuName(StrUtil.format("{}删除",table.getFunctionName()));
deleteMenu.setParentId(sysMenu.getMenuId());
deleteMenu.setOrderNum("4");
deleteMenu.setUrl("#");
deleteMenu.setMenuType("F");
deleteMenu.setPerms(StrUtil.format("{}:remove",VelocityUtils.getPermissionPrefix(table.getModuleName(), table.getBusinessName())));
deleteMenu.setRemark(StrUtil.format("{}删除",table.getFunctionName()));
sysMenuList.add(deleteMenu);
SysMenu exportMenu=new SysMenu();
exportMenu.setMenuName(StrUtil.format("{}导出",table.getFunctionName()));
exportMenu.setParentId(sysMenu.getMenuId());
exportMenu.setOrderNum("5");
exportMenu.setUrl("#");
exportMenu.setMenuType("F");
exportMenu.setPerms(StrUtil.format("{}:export",VelocityUtils.getPermissionPrefix(table.getModuleName(), table.getBusinessName())));
exportMenu.setRemark(StrUtil.format("{}导出",table.getFunctionName()));
sysMenuList.add(exportMenu);
sysMenuService.saveBatch(sysMenuList);
} }
/** /**
@ -222,22 +280,19 @@ public class GenTableServiceImpl implements IGenTableService
*/ */
@Override @Override
@Transactional @Transactional
public void synchDb(String tableName) public void synchDb(String tableName) {
{
GenTable table = genTableMapper.selectGenTableByName(tableName); GenTable table = genTableMapper.selectGenTableByName(tableName);
List<GenTableColumn> tableColumns = table.getColumns(); List<GenTableColumn> tableColumns = table.getColumns();
List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
if (StringUtils.isEmpty(dbTableColumns)) if (StringUtils.isEmpty(dbTableColumns)) {
{
throw new BusinessException("同步数据失败,原表结构不存在"); throw new BusinessException("同步数据失败,原表结构不存在");
} }
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
dbTableColumns.forEach(column -> { dbTableColumns.forEach(column -> {
if (!tableColumnNames.contains(column.getColumnName())) if (!tableColumnNames.contains(column.getColumnName())) {
{
GenUtils.initColumnField(column, table); GenUtils.initColumnField(column, table);
genTableColumnMapper.insertGenTableColumn(column); genTableColumnMapper.insertGenTableColumn(column);
} }
@ -245,8 +300,7 @@ public class GenTableServiceImpl implements IGenTableService
List<GenTableColumn> delColumns = tableColumns.stream() List<GenTableColumn> delColumns = tableColumns.stream()
.filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); .filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (StringUtils.isNotEmpty(delColumns)) if (StringUtils.isNotEmpty(delColumns)) {
{
genTableColumnMapper.deleteGenTableColumns(delColumns); genTableColumnMapper.deleteGenTableColumns(delColumns);
} }
} }

View File

@ -186,7 +186,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</delete> </delete>
<update id="createTable"> <update id="createTable" parameterType="string">
${sql} ${sql}
</update> </update>
</mapper> </mapper>

View File

@ -62,7 +62,7 @@
var removeFlag = [[${@permission.hasPermi('tool:gen:remove')}]]; var removeFlag = [[${@permission.hasPermi('tool:gen:remove')}]];
var previewFlag = [[${@permission.hasPermi('tool:gen:preview')}]]; var previewFlag = [[${@permission.hasPermi('tool:gen:preview')}]];
var codeFlag = [[${@permission.hasPermi('tool:gen:code')}]]; var codeFlag = [[${@permission.hasPermi('tool:gen:code')}]];
var createMenuFlag = [[${@permission.hasPermi('tool:gen:createMenu')}]];
$(function() { $(function() {
var options = { var options = {
url: prefix + "/list", url: prefix + "/list",
@ -130,6 +130,7 @@
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tableId + '\')"><i class="fa fa-remove"></i>删除</a> '); actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tableId + '\')"><i class="fa fa-remove"></i>删除</a> ');
actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="synchDb(\'' + row.tableName + '\')"><i class="fa fa-refresh"></i>同步</a> '); actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="synchDb(\'' + row.tableName + '\')"><i class="fa fa-refresh"></i>同步</a> ');
actions.push('<a class="btn btn-primary btn-xs ' + codeFlag + '" href="javascript:void(0)" onclick="genCode(\'' + row.tableName + '\',\'' + row.genType + '\')"><i class="fa fa-bug"></i>生成代码</a> '); actions.push('<a class="btn btn-primary btn-xs ' + codeFlag + '" href="javascript:void(0)" onclick="genCode(\'' + row.tableName + '\',\'' + row.genType + '\')"><i class="fa fa-bug"></i>生成代码</a> ');
actions.push('<a class="btn btn-warning btn-xs ' + createMenuFlag + '" href="javascript:void(0)" onclick="createMenu(\'' + row.tableName + '\')"><i class="fa fa-refresh"></i>生成菜单</a> ');
return actions.join(''); return actions.join('');
} }
}] }]
@ -180,6 +181,13 @@
}) })
} }
//生成菜单
function createMenu(tableName){
$.modal.confirm("确认要强制生成" + tableName + "功能菜单吗?", function() {
$.operate.get(prefix + "/createMenu/" + tableName);
})
}
// 批量生成代码 // 批量生成代码
function batchGenCode() { function batchGenCode() {
var rows = $.table.selectColumns("tableName"); var rows = $.table.selectColumns("tableName");

View File

@ -38,9 +38,6 @@ public class ${ClassName} extends ${Entity}
#else #else
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
#end #end
#if($column.isPk == '1')
@TableId(value = "$column.columnName", type = IdType.AUTO)
#end
#if($parentheseIndex != -1) #if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date') #elseif($column.javaType == 'Date')
@ -49,6 +46,9 @@ public class ${ClassName} extends ${Entity}
#else #else
@Excel(name = "${comment}") @Excel(name = "${comment}")
#end #end
#end
#if($column.isPk == '1')
@TableId(value = "$column.columnName", type = IdType.AUTO)
#end #end
private $column.javaType $column.javaField; private $column.javaType $column.javaField;

View File

@ -65,21 +65,21 @@ public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${C
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#if($column.query) #if($column.query)
#if($column.queryType == "EQ") #if($column.queryType == "EQ")
lambda.eq(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName}(),${className}.get${AttrName}()) lambda.eq(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName},${className}.get${AttrName}());
#elseif($queryType == "NE") #elseif($queryType == "NE")
lambda.ne(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName}(),${className}.get${AttrName}()) lambda.ne(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName},${className}.get${AttrName}());
#elseif($queryType == "GT") #elseif($queryType == "GT")
lambda.gt(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName}(),${className}.get${AttrName}()) lambda.gt(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName},${className}.get${AttrName}());
#elseif($queryType == "GTE") #elseif($queryType == "GTE")
lambda.ge(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName}(),${className}.get${AttrName}()) lambda.ge(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName},${className}.get${AttrName}());
#elseif($queryType == "LT") #elseif($queryType == "LT")
lambda.lt(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName}(),${className}.get${AttrName}()) lambda.lt(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName},${className}.get${AttrName}());
#elseif($queryType == "LTE") #elseif($queryType == "LTE")
lambda.le(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName}(),${className}.get${AttrName}()) lambda.le(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName},${className}.get${AttrName}());
#elseif($queryType == "LIKE") #elseif($queryType == "LIKE")
lambda.like(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName}(),${className}.get${AttrName}()) lambda.like(ObjectUtil.isNotNull(${className}.get${AttrName}()),${ClassName}::get${AttrName},${className}.get${AttrName}());
#elseif($queryType == "BETWEEN") #elseif($queryType == "BETWEEN")
lambda.between(ObjectUtil.isNotNull(${className}.get${AttrName}()),${className}::get${AttrName}(), ${className}.getParams().get("begin${AttrName}"), ${className}.getParams().get("end${AttrName}") ) lambda.between(ObjectUtil.isNotNull(${className}.get${AttrName}()),${className}::get${AttrName}, ${className}.getParams().get("begin${AttrName}"), ${className}.getParams().get("end${AttrName}"));
#end #end
#end #end
#end #end

View File

@ -1,22 +1,13 @@
-- 菜单 SQL
insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}', '${parentMenuId}', '1', '/${moduleName}/${businessName}', 'C', '0', '${permissionPrefix}:view', '#', 'admin', NOW(), 'ry', NOW(), '${functionName}菜单'); values('${functionName}', '${parentMenuId}', '1', '/${moduleName}/${businessName}', 'C', '0', '${permissionPrefix}:view', '#', 'admin', NOW(), 'ry', NOW(), '${functionName}菜单');
-- 按钮父菜单ID
SELECT @parentId := LAST_INSERT_ID(); SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}查询', @parentId, '1', '#', 'F', '0', '${permissionPrefix}:list', '#', 'admin', NOW(), 'ry', NOW(), ''); values('${functionName}查询', @parentId, '1', '#', 'F', '0', '${permissionPrefix}:list', '#', 'admin', NOW(), 'ry', NOW(), '');
insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}新增', @parentId, '2', '#', 'F', '0', '${permissionPrefix}:add', '#', 'admin', NOW(), 'ry', NOW(), ''); values('${functionName}新增', @parentId, '2', '#', 'F', '0', '${permissionPrefix}:add', '#', 'admin', NOW(), 'ry', NOW(), '');
insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}修改', @parentId, '3', '#', 'F', '0', '${permissionPrefix}:edit', '#', 'admin', NOW(), 'ry', NOW(), ''); values('${functionName}修改', @parentId, '3', '#', 'F', '0', '${permissionPrefix}:edit', '#', 'admin', NOW(), 'ry', NOW(), '');
insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}删除', @parentId, '4', '#', 'F', '0', '${permissionPrefix}:remove', '#', 'admin', NOW(), 'ry', NOW(), ''); values('${functionName}删除', @parentId, '4', '#', 'F', '0', '${permissionPrefix}:remove', '#', 'admin', NOW(), 'ry', NOW(), '');
insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) insert into sys_menu (menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}导出', @parentId, '5', '#', 'F', '0', '${permissionPrefix}:export', '#', 'admin', NOW(), 'ry', NOW(), ''); values('${functionName}导出', @parentId, '5', '#', 'F', '0', '${permissionPrefix}:export', '#', 'admin', NOW(), 'ry', NOW(), '');

View File

@ -3,6 +3,10 @@ package com.snow.system.domain;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.snow.common.core.domain.BaseEntity; import com.snow.common.core.domain.BaseEntity;
@ -17,6 +21,7 @@ public class SysMenu extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 菜单ID */ /** 菜单ID */
@TableId(value = "menu_id",type= IdType.AUTO)
private Long menuId; private Long menuId;
/** 菜单名称 */ /** 菜单名称 */
@ -54,6 +59,7 @@ public class SysMenu extends BaseEntity
/** 子菜单 */ /** 子菜单 */
@TableField(exist = false)
private List<SysMenu> children = new ArrayList<SysMenu>(); private List<SysMenu> children = new ArrayList<SysMenu>();
public Long getMenuId() public Long getMenuId()

View File

@ -1,6 +1,8 @@
package com.snow.system.mapper; package com.snow.system.mapper;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import com.snow.system.domain.SysMenu; import com.snow.system.domain.SysMenu;
@ -9,7 +11,7 @@ import com.snow.system.domain.SysMenu;
* *
* @author snow * @author snow
*/ */
public interface SysMenuMapper public interface SysMenuMapper extends BaseMapper<SysMenu>
{ {
/** /**
* 查询系统所有菜单含按钮 * 查询系统所有菜单含按钮

View File

@ -1,19 +1,21 @@
package com.snow.system.service; package com.snow.system.service;
import java.util.List; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Map;
import java.util.Set;
import com.snow.common.core.domain.Ztree; import com.snow.common.core.domain.Ztree;
import com.snow.system.domain.SysMenu; import com.snow.system.domain.SysMenu;
import com.snow.system.domain.SysRole; import com.snow.system.domain.SysRole;
import com.snow.system.domain.SysUser; import com.snow.system.domain.SysUser;
import java.util.List;
import java.util.Map;
import java.util.Set;
/** /**
* 菜单 业务层 * 菜单 业务层
* *
* @author snow * @author snow
*/ */
public interface ISysMenuService public interface ISysMenuService extends IService<SysMenu>
{ {
/** /**
* 根据用户ID查询菜单 * 根据用户ID查询菜单

View File

@ -10,6 +10,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snow.system.service.ISysMenuService; import com.snow.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -28,7 +29,7 @@ import com.snow.system.mapper.SysRoleMenuMapper;
* @author snow * @author snow
*/ */
@Service @Service
public class SysMenuServiceImpl implements ISysMenuService public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper,SysMenu> implements ISysMenuService
{ {
public static final String PREMISSION_STRING = "perms[\"{0}\"]"; public static final String PREMISSION_STRING = "perms[\"{0}\"]";