Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
RuoYi Vue
Commits
fee8a595
Commit
fee8a595
authored
Dec 02, 2019
by
RuoYi
Browse files
若依 2.0
parent
cef26e77
Changes
76
Hide whitespace changes
Inline
Side-by-side
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java
View file @
fee8a595
...
...
@@ -57,7 +57,6 @@ public class SysDeptController extends BaseController
/**
* 获取部门下拉树列表
*/
@PreAuthorize
(
"@ss.hasPermi('system:dept:query')"
)
@GetMapping
(
"/treeselect"
)
public
AjaxResult
treeselect
(
SysDept
dept
)
{
...
...
@@ -68,7 +67,6 @@ public class SysDeptController extends BaseController
/**
* 加载对应角色部门列表树
*/
@PreAuthorize
(
"@ss.hasPermi('system:dept:query')"
)
@GetMapping
(
value
=
"/roleDeptTreeselect/{roleId}"
)
public
AjaxResult
roleDeptTreeselect
(
@PathVariable
(
"roleId"
)
Long
roleId
)
{
...
...
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDictDataController.java
View file @
fee8a595
...
...
@@ -66,7 +66,6 @@ public class SysDictDataController extends BaseController
/**
* 根据字典类型查询字典数据信息
*/
@PreAuthorize
(
"@ss.hasPermi('system:dict:query')"
)
@GetMapping
(
value
=
"/dictType/{dictType}"
)
public
AjaxResult
dictType
(
@PathVariable
String
dictType
)
{
...
...
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDictTypeController.java
View file @
fee8a595
...
...
@@ -106,4 +106,14 @@ public class SysDictTypeController extends BaseController
{
return
toAjax
(
dictTypeService
.
deleteDictTypeByIds
(
dictIds
));
}
/**
* 获取字典选择框列表
*/
@GetMapping
(
"/optionselect"
)
public
AjaxResult
optionselect
()
{
List
<
SysDictType
>
dictTypes
=
dictTypeService
.
selectDictTypeAll
();
return
AjaxResult
.
success
(
dictTypes
);
}
}
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java
View file @
fee8a595
...
...
@@ -57,7 +57,6 @@ public class SysMenuController extends BaseController
/**
* 获取菜单下拉树列表
*/
@PreAuthorize
(
"@ss.hasPermi('system:menu:query')"
)
@GetMapping
(
"/treeselect"
)
public
AjaxResult
treeselect
(
SysMenu
dept
)
{
...
...
@@ -68,7 +67,6 @@ public class SysMenuController extends BaseController
/**
* 加载对应角色菜单列表树
*/
@PreAuthorize
(
"@ss.hasPermi('system:menu:query')"
)
@GetMapping
(
value
=
"/roleMenuTreeselect/{roleId}"
)
public
AjaxResult
roleMenuTreeselect
(
@PathVariable
(
"roleId"
)
Long
roleId
)
{
...
...
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysUserController.java
View file @
fee8a595
...
...
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.utils.SecurityUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.poi.ExcelUtil
;
import
com.ruoyi.framework.aspectj.lang.annotation.Log
;
import
com.ruoyi.framework.aspectj.lang.enums.BusinessType
;
...
...
@@ -69,12 +70,18 @@ public class SysUserController extends BaseController
* 根据用户编号获取详细信息
*/
@PreAuthorize
(
"@ss.hasPermi('system:user:query')"
)
@GetMapping
(
value
=
"/{userId}"
)
public
AjaxResult
getInfo
(
@PathVariable
Long
userId
)
@GetMapping
(
value
=
{
"/"
,
"/{userId}"
}
)
public
AjaxResult
getInfo
(
@PathVariable
(
value
=
"userId"
,
required
=
false
)
Long
userId
)
{
AjaxResult
ajax
=
AjaxResult
.
success
(
userService
.
selectUserById
(
userId
));
ajax
.
put
(
"postIds"
,
postService
.
selectPostListByUserId
(
userId
));
ajax
.
put
(
"roleIds"
,
roleService
.
selectRoleListByUserId
(
userId
));
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"roles"
,
roleService
.
selectRoleAll
());
ajax
.
put
(
"posts"
,
postService
.
selectPostAll
());
if
(
StringUtils
.
isNotNull
(
userId
))
{
ajax
.
put
(
AjaxResult
.
DATA_TAG
,
userService
.
selectUserById
(
userId
));
ajax
.
put
(
"postIds"
,
postService
.
selectPostListByUserId
(
userId
));
ajax
.
put
(
"roleIds"
,
roleService
.
selectRoleListByUserId
(
userId
));
}
return
ajax
;
}
...
...
ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java
View file @
fee8a595
...
...
@@ -116,11 +116,10 @@ public class SysMenuServiceImpl implements ISysMenuService
for
(
SysMenu
menu
:
menus
)
{
RouterVo
router
=
new
RouterVo
();
router
.
setName
(
menu
.
getMenuName
(
));
router
.
setName
(
StringUtils
.
capitalize
(
menu
.
getPath
()
));
router
.
setPath
(
getRouterPath
(
menu
));
router
.
setComponent
(
StringUtils
.
isEmpty
(
menu
.
getComponent
())
?
"Layout"
:
menu
.
getComponent
());
router
.
setMeta
(
new
MetaVo
(
menu
.
getMenuName
(),
menu
.
getIcon
()));
router
.
setName
(
menu
.
getMenuName
());
List
<
SysMenu
>
cMenus
=
menu
.
getChildren
();
if
(!
cMenus
.
isEmpty
()
&&
cMenus
.
size
()
>
0
&&
"M"
.
equals
(
menu
.
getMenuType
()))
{
...
...
ruoyi/src/main/java/com/ruoyi/project/tool/gen/controller/GenController.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.controller
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
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.PutMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ruoyi.common.utils.text.Convert
;
import
com.ruoyi.framework.aspectj.lang.annotation.Log
;
import
com.ruoyi.framework.aspectj.lang.enums.BusinessType
;
import
com.ruoyi.framework.web.controller.BaseController
;
import
com.ruoyi.framework.web.domain.AjaxResult
;
import
com.ruoyi.framework.web.page.TableDataInfo
;
import
com.ruoyi.project.tool.gen.domain.GenTable
;
import
com.ruoyi.project.tool.gen.domain.GenTableColumn
;
import
com.ruoyi.project.tool.gen.service.IGenTableColumnService
;
import
com.ruoyi.project.tool.gen.service.IGenTableService
;
/**
* 代码生成 操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping
(
"/tool/gen"
)
public
class
GenController
extends
BaseController
{
@Autowired
private
IGenTableService
genTableService
;
@Autowired
private
IGenTableColumnService
genTableColumnService
;
/**
* 查询代码生成列表
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:list')"
)
@GetMapping
(
"/list"
)
public
TableDataInfo
genList
(
GenTable
genTable
)
{
startPage
();
List
<
GenTable
>
list
=
genTableService
.
selectGenTableList
(
genTable
);
return
getDataTable
(
list
);
}
/**
* 修改代码生成业务
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:query')"
)
@GetMapping
(
value
=
"/{talbleId}"
)
public
AjaxResult
getInfo
(
@PathVariable
Long
talbleId
)
{
GenTable
table
=
genTableService
.
selectGenTableById
(
talbleId
);
List
<
GenTableColumn
>
list
=
genTableColumnService
.
selectGenTableColumnListByTableId
(
talbleId
);
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"info"
,
table
);
map
.
put
(
"rows"
,
list
);
return
AjaxResult
.
success
(
map
);
}
/**
* 查询数据库列表
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:list')"
)
@GetMapping
(
"/db/list"
)
public
TableDataInfo
dataList
(
GenTable
genTable
)
{
startPage
();
List
<
GenTable
>
list
=
genTableService
.
selectDbTableList
(
genTable
);
return
getDataTable
(
list
);
}
/**
* 查询数据表字段列表
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:list')"
)
@GetMapping
(
value
=
"/column/{talbleId}"
)
public
TableDataInfo
columnList
(
Long
tableId
)
{
TableDataInfo
dataInfo
=
new
TableDataInfo
();
List
<
GenTableColumn
>
list
=
genTableColumnService
.
selectGenTableColumnListByTableId
(
tableId
);
dataInfo
.
setRows
(
list
);
dataInfo
.
setTotal
(
list
.
size
());
return
dataInfo
;
}
/**
* 导入表结构(保存)
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:list')"
)
@Log
(
title
=
"代码生成"
,
businessType
=
BusinessType
.
IMPORT
)
@PostMapping
(
"/importTable"
)
public
AjaxResult
importTableSave
(
String
tables
)
{
String
[]
tableNames
=
Convert
.
toStrArray
(
tables
);
// 查询表信息
List
<
GenTable
>
tableList
=
genTableService
.
selectDbTableListByNames
(
tableNames
);
genTableService
.
importGenTable
(
tableList
);
return
AjaxResult
.
success
();
}
/**
* 修改保存代码生成业务
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:edit')"
)
@Log
(
title
=
"代码生成"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
public
AjaxResult
editSave
(
@Validated
@RequestBody
GenTable
genTable
)
{
System
.
out
.
println
(
genTable
.
getParams
().
size
());
genTableService
.
validateEdit
(
genTable
);
genTableService
.
updateGenTable
(
genTable
);
return
AjaxResult
.
success
();
}
@PreAuthorize
(
"@ss.hasPermi('tool:gen:remove')"
)
@Log
(
title
=
"代码生成"
,
businessType
=
BusinessType
.
DELETE
)
@DeleteMapping
(
"/{tableIds}"
)
public
AjaxResult
remove
(
@PathVariable
Long
[]
tableIds
)
{
genTableService
.
deleteGenTableByIds
(
tableIds
);
return
AjaxResult
.
success
();
}
/**
* 预览代码
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:preview')"
)
@GetMapping
(
"/preview/{tableId}"
)
public
AjaxResult
preview
(
@PathVariable
(
"tableId"
)
Long
tableId
)
throws
IOException
{
Map
<
String
,
String
>
dataMap
=
genTableService
.
previewCode
(
tableId
);
return
AjaxResult
.
success
(
dataMap
);
}
/**
* 生成代码
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:code')"
)
@Log
(
title
=
"代码生成"
,
businessType
=
BusinessType
.
GENCODE
)
@GetMapping
(
"/genCode/{tableName}"
)
public
void
genCode
(
HttpServletResponse
response
,
@PathVariable
(
"tableName"
)
String
tableName
)
throws
IOException
{
byte
[]
data
=
genTableService
.
generatorCode
(
tableName
);
genCode
(
response
,
data
);
}
/**
* 批量生成代码
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:code')"
)
@Log
(
title
=
"代码生成"
,
businessType
=
BusinessType
.
GENCODE
)
@GetMapping
(
"/batchGenCode"
)
public
void
batchGenCode
(
HttpServletResponse
response
,
String
tables
)
throws
IOException
{
String
[]
tableNames
=
Convert
.
toStrArray
(
tables
);
byte
[]
data
=
genTableService
.
generatorCode
(
tableNames
);
genCode
(
response
,
data
);
}
/**
* 生成zip文件
*/
private
void
genCode
(
HttpServletResponse
response
,
byte
[]
data
)
throws
IOException
{
response
.
reset
();
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\"ruoyi.zip\""
);
response
.
addHeader
(
"Content-Length"
,
""
+
data
.
length
);
response
.
setContentType
(
"application/octet-stream; charset=UTF-8"
);
IOUtils
.
write
(
data
,
response
.
getOutputStream
());
}
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/domain/GenTable.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.domain
;
import
java.util.List
;
import
javax.validation.Valid
;
import
javax.validation.constraints.NotBlank
;
import
com.ruoyi.common.constant.GenConstants
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.framework.web.domain.BaseEntity
;
/**
* 业务表 gen_table
*
* @author ruoyi
*/
public
class
GenTable
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
/** 编号 */
private
Long
tableId
;
/** 表名称 */
@NotBlank
(
message
=
"表名称不能为空"
)
private
String
tableName
;
/** 表描述 */
@NotBlank
(
message
=
"表描述不能为空"
)
private
String
tableComment
;
/** 实体类名称(首字母大写) */
@NotBlank
(
message
=
"实体类名称不能为空"
)
private
String
className
;
/** 使用的模板(crud单表操作 tree树表操作) */
private
String
tplCategory
;
/** 生成包路径 */
@NotBlank
(
message
=
"生成包路径不能为空"
)
private
String
packageName
;
/** 生成模块名 */
@NotBlank
(
message
=
"生成模块名不能为空"
)
private
String
moduleName
;
/** 生成业务名 */
@NotBlank
(
message
=
"生成业务名不能为空"
)
private
String
businessName
;
/** 生成功能名 */
@NotBlank
(
message
=
"生成功能名不能为空"
)
private
String
functionName
;
/** 生成作者 */
@NotBlank
(
message
=
"作者不能为空"
)
private
String
functionAuthor
;
/** 主键信息 */
private
GenTableColumn
pkColumn
;
/** 表列信息 */
@Valid
private
List
<
GenTableColumn
>
columns
;
/** 其它生成选项 */
private
String
options
;
/** 树编码字段 */
private
String
treeCode
;
/** 树父编码字段 */
private
String
treeParentCode
;
/** 树名称字段 */
private
String
treeName
;
public
Long
getTableId
()
{
return
tableId
;
}
public
void
setTableId
(
Long
tableId
)
{
this
.
tableId
=
tableId
;
}
public
String
getTableName
()
{
return
tableName
;
}
public
void
setTableName
(
String
tableName
)
{
this
.
tableName
=
tableName
;
}
public
String
getTableComment
()
{
return
tableComment
;
}
public
void
setTableComment
(
String
tableComment
)
{
this
.
tableComment
=
tableComment
;
}
public
String
getClassName
()
{
return
className
;
}
public
void
setClassName
(
String
className
)
{
this
.
className
=
className
;
}
public
String
getTplCategory
()
{
return
tplCategory
;
}
public
void
setTplCategory
(
String
tplCategory
)
{
this
.
tplCategory
=
tplCategory
;
}
public
String
getPackageName
()
{
return
packageName
;
}
public
void
setPackageName
(
String
packageName
)
{
this
.
packageName
=
packageName
;
}
public
String
getModuleName
()
{
return
moduleName
;
}
public
void
setModuleName
(
String
moduleName
)
{
this
.
moduleName
=
moduleName
;
}
public
String
getBusinessName
()
{
return
businessName
;
}
public
void
setBusinessName
(
String
businessName
)
{
this
.
businessName
=
businessName
;
}
public
String
getFunctionName
()
{
return
functionName
;
}
public
void
setFunctionName
(
String
functionName
)
{
this
.
functionName
=
functionName
;
}
public
String
getFunctionAuthor
()
{
return
functionAuthor
;
}
public
void
setFunctionAuthor
(
String
functionAuthor
)
{
this
.
functionAuthor
=
functionAuthor
;
}
public
GenTableColumn
getPkColumn
()
{
return
pkColumn
;
}
public
void
setPkColumn
(
GenTableColumn
pkColumn
)
{
this
.
pkColumn
=
pkColumn
;
}
public
List
<
GenTableColumn
>
getColumns
()
{
return
columns
;
}
public
void
setColumns
(
List
<
GenTableColumn
>
columns
)
{
this
.
columns
=
columns
;
}
public
String
getOptions
()
{
return
options
;
}
public
void
setOptions
(
String
options
)
{
this
.
options
=
options
;
}
public
String
getTreeCode
()
{
return
treeCode
;
}
public
void
setTreeCode
(
String
treeCode
)
{
this
.
treeCode
=
treeCode
;
}
public
String
getTreeParentCode
()
{
return
treeParentCode
;
}
public
void
setTreeParentCode
(
String
treeParentCode
)
{
this
.
treeParentCode
=
treeParentCode
;
}
public
String
getTreeName
()
{
return
treeName
;
}
public
void
setTreeName
(
String
treeName
)
{
this
.
treeName
=
treeName
;
}
public
boolean
isTree
()
{
return
isTree
(
this
.
tplCategory
);
}
public
static
boolean
isTree
(
String
tplCategory
)
{
return
tplCategory
!=
null
&&
StringUtils
.
equals
(
GenConstants
.
TPL_TREE
,
tplCategory
);
}
public
boolean
isCrud
()
{
return
isCrud
(
this
.
tplCategory
);
}
public
static
boolean
isCrud
(
String
tplCategory
)
{
return
tplCategory
!=
null
&&
StringUtils
.
equals
(
GenConstants
.
TPL_CRUD
,
tplCategory
);
}
public
boolean
isSuperColumn
(
String
javaField
)
{
return
isSuperColumn
(
this
.
tplCategory
,
javaField
);
}
public
static
boolean
isSuperColumn
(
String
tplCategory
,
String
javaField
)
{
if
(
isTree
(
tplCategory
))
{
StringUtils
.
equalsAnyIgnoreCase
(
javaField
,
GenConstants
.
TREE_ENTITY
);
}
return
StringUtils
.
equalsAnyIgnoreCase
(
javaField
,
GenConstants
.
BASE_ENTITY
);
}
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/domain/GenTableColumn.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.domain
;
import
javax.validation.constraints.NotBlank
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.framework.web.domain.BaseEntity
;
/**
* 代码生成业务字段表 gen_table_column
*
* @author ruoyi
*/
public
class
GenTableColumn
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
/** 编号 */
private
Long
columnId
;
/** 归属表编号 */
private
Long
tableId
;
/** 列名称 */
private
String
columnName
;
/** 列描述 */
private
String
columnComment
;
/** 列类型 */
private
String
columnType
;
/** JAVA类型 */
private
String
javaType
;
/** JAVA字段名 */
@NotBlank
(
message
=
"Java属性不能为空"
)
private
String
javaField
;
/** 是否主键(1是) */
private
String
isPk
;
/** 是否自增(1是) */
private
String
isIncrement
;
/** 是否必填(1是) */
private
String
isRequired
;
/** 是否为插入字段(1是) */
private
String
isInsert
;
/** 是否编辑字段(1是) */
private
String
isEdit
;
/** 是否列表字段(1是) */
private
String
isList
;
/** 是否查询字段(1是) */
private
String
isQuery
;
/** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */
private
String
queryType
;
/** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件) */
private
String
htmlType
;
/** 字典类型 */
private
String
dictType
;
/** 排序 */
private
Integer
sort
;
public
void
setColumnId
(
Long
columnId
)
{
this
.
columnId
=
columnId
;
}
public
Long
getColumnId
()
{
return
columnId
;
}
public
void
setTableId
(
Long
tableId
)
{
this
.
tableId
=
tableId
;
}
public
Long
getTableId
()
{
return
tableId
;
}
public
void
setColumnName
(
String
columnName
)
{
this
.
columnName
=
columnName
;
}
public
String
getColumnName
()
{
return
columnName
;
}
public
void
setColumnComment
(
String
columnComment
)
{
this
.
columnComment
=
columnComment
;
}
public
String
getColumnComment
()
{
return
columnComment
;
}
public
void
setColumnType
(
String
columnType
)
{
this
.
columnType
=
columnType
;
}
public
String
getColumnType
()
{
return
columnType
;
}
public
void
setJavaType
(
String
javaType
)
{
this
.
javaType
=
javaType
;
}
public
String
getJavaType
()
{
return
javaType
;
}
public
void
setJavaField
(
String
javaField
)
{
this
.
javaField
=
javaField
;
}
public
String
getJavaField
()
{
return
javaField
;
}
public
void
setIsPk
(
String
isPk
)
{
this
.
isPk
=
isPk
;
}
public
String
getIsPk
()
{
return
isPk
;
}
public
boolean
isPk
()
{
return
isPk
(
this
.
isPk
);
}
public
boolean
isPk
(
String
isPk
)
{
return
isPk
!=
null
&&
StringUtils
.
equals
(
"1"
,
isPk
);
}
public
String
getIsIncrement
()
{
return
isIncrement
;
}
public
void
setIsIncrement
(
String
isIncrement
)
{
this
.
isIncrement
=
isIncrement
;
}
public
boolean
isIncrement
()
{
return
isIncrement
(
this
.
isIncrement
);
}
public
boolean
isIncrement
(
String
isIncrement
)
{
return
isIncrement
!=
null
&&
StringUtils
.
equals
(
"1"
,
isIncrement
);
}
public
void
setIsRequired
(
String
isRequired
)
{
this
.
isRequired
=
isRequired
;
}
public
String
getIsRequired
()
{
return
isRequired
;
}
public
boolean
isRequired
()
{
return
isRequired
(
this
.
isRequired
);
}
public
boolean
isRequired
(
String
isRequired
)
{
return
isRequired
!=
null
&&
StringUtils
.
equals
(
"1"
,
isRequired
);
}
public
void
setIsInsert
(
String
isInsert
)
{
this
.
isInsert
=
isInsert
;
}
public
String
getIsInsert
()
{
return
isInsert
;
}
public
boolean
isInsert
()
{
return
isInsert
(
this
.
isInsert
);
}
public
boolean
isInsert
(
String
isInsert
)
{
return
isInsert
!=
null
&&
StringUtils
.
equals
(
"1"
,
isInsert
);
}
public
void
setIsEdit
(
String
isEdit
)
{
this
.
isEdit
=
isEdit
;
}
public
String
getIsEdit
()
{
return
isEdit
;
}
public
boolean
isEdit
()
{
return
isInsert
(
this
.
isEdit
);
}
public
boolean
isEdit
(
String
isEdit
)
{
return
isEdit
!=
null
&&
StringUtils
.
equals
(
"1"
,
isEdit
);
}
public
void
setIsList
(
String
isList
)
{
this
.
isList
=
isList
;
}
public
String
getIsList
()
{
return
isList
;
}
public
boolean
isList
()
{
return
isList
(
this
.
isList
);
}
public
boolean
isList
(
String
isList
)
{
return
isList
!=
null
&&
StringUtils
.
equals
(
"1"
,
isList
);
}
public
void
setIsQuery
(
String
isQuery
)
{
this
.
isQuery
=
isQuery
;
}
public
String
getIsQuery
()
{
return
isQuery
;
}
public
boolean
isQuery
()
{
return
isQuery
(
this
.
isQuery
);
}
public
boolean
isQuery
(
String
isQuery
)
{
return
isQuery
!=
null
&&
StringUtils
.
equals
(
"1"
,
isQuery
);
}
public
void
setQueryType
(
String
queryType
)
{
this
.
queryType
=
queryType
;
}
public
String
getQueryType
()
{
return
queryType
;
}
public
String
getHtmlType
()
{
return
htmlType
;
}
public
void
setHtmlType
(
String
htmlType
)
{
this
.
htmlType
=
htmlType
;
}
public
void
setDictType
(
String
dictType
)
{
this
.
dictType
=
dictType
;
}
public
String
getDictType
()
{
return
dictType
;
}
public
void
setSort
(
Integer
sort
)
{
this
.
sort
=
sort
;
}
public
Integer
getSort
()
{
return
sort
;
}
public
boolean
isSuperColumn
()
{
return
isSuperColumn
(
this
.
javaField
);
}
public
static
boolean
isSuperColumn
(
String
javaField
)
{
return
StringUtils
.
equalsAnyIgnoreCase
(
javaField
,
// BaseEntity
"createBy"
,
"createTime"
,
"updateBy"
,
"updateTime"
,
"remark"
,
// TreeEntity
"parentName"
,
"parentId"
,
"orderNum"
,
"ancestors"
);
}
public
boolean
isUsableColumn
()
{
return
isUsableColumn
(
javaField
);
}
public
static
boolean
isUsableColumn
(
String
javaField
)
{
// isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
return
StringUtils
.
equalsAnyIgnoreCase
(
javaField
,
"parentId"
,
"orderNum"
);
}
public
String
readConverterExp
()
{
String
remarks
=
StringUtils
.
substringBetween
(
this
.
columnComment
,
"("
,
")"
);
StringBuffer
sb
=
new
StringBuffer
();
if
(
StringUtils
.
isNotEmpty
(
remarks
))
{
for
(
String
value
:
remarks
.
split
(
" "
))
{
if
(
StringUtils
.
isNotEmpty
(
value
))
{
Object
startStr
=
value
.
subSequence
(
0
,
1
);
String
endStr
=
value
.
substring
(
1
);
sb
.
append
(
""
).
append
(
startStr
).
append
(
"="
).
append
(
endStr
).
append
(
","
);
}
}
return
sb
.
deleteCharAt
(
sb
.
length
()
-
1
).
toString
();
}
else
{
return
this
.
columnComment
;
}
}
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/mapper/GenTableColumnMapper.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.mapper
;
import
java.util.List
;
import
com.ruoyi.project.tool.gen.domain.GenTableColumn
;
/**
* 业务字段 数据层
*
* @author ruoyi
*/
public
interface
GenTableColumnMapper
{
/**
* 根据表名称查询列信息
*
* @param tableName 表名称
* @return 列信息
*/
public
List
<
GenTableColumn
>
selectDbTableColumnsByName
(
String
tableName
);
/**
* 查询业务字段列表
*
* @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
(
Long
[]
ids
);
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/mapper/GenTableMapper.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.mapper
;
import
java.util.List
;
import
com.ruoyi.project.tool.gen.domain.GenTable
;
/**
* 业务 数据层
*
* @author ruoyi
*/
public
interface
GenTableMapper
{
/**
* 查询业务列表
*
* @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
);
/**
* 查询表ID业务信息
*
* @param id 业务ID
* @return 业务信息
*/
public
GenTable
selectGenTableById
(
Long
id
);
/**
* 查询表名称业务信息
*
* @param tableName 表名称
* @return 业务信息
*/
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
);
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableColumnServiceImpl.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.service
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ruoyi.common.utils.text.Convert
;
import
com.ruoyi.project.tool.gen.domain.GenTableColumn
;
import
com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper
;
/**
* 业务字段 服务层实现
*
* @author ruoyi
*/
@Service
public
class
GenTableColumnServiceImpl
implements
IGenTableColumnService
{
@Autowired
private
GenTableColumnMapper
genTableColumnMapper
;
/**
* 查询业务字段列表
*
* @param genTableColumn 业务字段编号
* @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
));
}
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableServiceImpl.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.service
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.StringWriter
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.velocity.Template
;
import
org.apache.velocity.VelocityContext
;
import
org.apache.velocity.app.Velocity
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.constant.GenConstants
;
import
com.ruoyi.common.exception.CustomException
;
import
com.ruoyi.common.utils.SecurityUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.project.tool.gen.domain.GenTable
;
import
com.ruoyi.project.tool.gen.domain.GenTableColumn
;
import
com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper
;
import
com.ruoyi.project.tool.gen.mapper.GenTableMapper
;
import
com.ruoyi.project.tool.gen.util.GenUtils
;
import
com.ruoyi.project.tool.gen.util.VelocityInitializer
;
import
com.ruoyi.project.tool.gen.util.VelocityUtils
;
/**
* 业务 服务层实现
*
* @author ruoyi
*/
@Service
public
class
GenTableServiceImpl
implements
IGenTableService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
GenTableServiceImpl
.
class
);
@Autowired
private
GenTableMapper
genTableMapper
;
@Autowired
private
GenTableColumnMapper
genTableColumnMapper
;
/**
* 查询业务信息
*
* @param id 业务ID
* @return 业务信息
*/
@Override
public
GenTable
selectGenTableById
(
Long
id
)
{
GenTable
genTable
=
genTableMapper
.
selectGenTableById
(
id
);
setTableFromOptions
(
genTable
);
return
genTable
;
}
/**
* 查询业务列表
*
* @param genTable 业务信息
* @return 业务集合
*/
@Override
public
List
<
GenTable
>
selectGenTableList
(
GenTable
genTable
)
{
return
genTableMapper
.
selectGenTableList
(
genTable
);
}
/**
* 查询据库列表
*
* @param genTable 业务信息
* @return 数据库表集合
*/
public
List
<
GenTable
>
selectDbTableList
(
GenTable
genTable
)
{
return
genTableMapper
.
selectDbTableList
(
genTable
);
}
/**
* 查询据库列表
*
* @param tableNames 表名称组
* @return 数据库表集合
*/
public
List
<
GenTable
>
selectDbTableListByNames
(
String
[]
tableNames
)
{
return
genTableMapper
.
selectDbTableListByNames
(
tableNames
);
}
/**
* 修改业务
*
* @param genTable 业务信息
* @return 结果
*/
@Override
@Transactional
public
void
updateGenTable
(
GenTable
genTable
)
{
String
options
=
JSON
.
toJSONString
(
genTable
.
getParams
());
genTable
.
setOptions
(
options
);
int
row
=
genTableMapper
.
updateGenTable
(
genTable
);
if
(
row
>
0
)
{
for
(
GenTableColumn
cenTableColumn
:
genTable
.
getColumns
())
{
genTableColumnMapper
.
updateGenTableColumn
(
cenTableColumn
);
}
}
}
/**
* 删除业务对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
@Transactional
public
void
deleteGenTableByIds
(
Long
[]
tableIds
)
{
genTableMapper
.
deleteGenTableByIds
(
tableIds
);
genTableColumnMapper
.
deleteGenTableColumnByIds
(
tableIds
);
}
/**
* 导入表结构
*
* @param tableList 导入表列表
*/
@Override
@Transactional
public
void
importGenTable
(
List
<
GenTable
>
tableList
)
{
String
operName
=
SecurityUtils
.
getUsername
();
for
(
GenTable
table
:
tableList
)
{
try
{
String
tableName
=
table
.
getTableName
();
GenUtils
.
initTable
(
table
,
operName
);
int
row
=
genTableMapper
.
insertGenTable
(
table
);
if
(
row
>
0
)
{
// 保存列信息
List
<
GenTableColumn
>
genTableColumns
=
genTableColumnMapper
.
selectDbTableColumnsByName
(
tableName
);
for
(
GenTableColumn
column
:
genTableColumns
)
{
GenUtils
.
initColumnField
(
column
,
table
);
genTableColumnMapper
.
insertGenTableColumn
(
column
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"表名 "
+
table
.
getTableName
()
+
" 导入失败:"
,
e
);
}
}
}
/**
* 预览代码
*
* @param tableId 表编号
* @return 预览数据列表
*/
public
Map
<
String
,
String
>
previewCode
(
Long
tableId
)
{
Map
<
String
,
String
>
dataMap
=
new
LinkedHashMap
<>();
// 查询表信息
GenTable
table
=
genTableMapper
.
selectGenTableById
(
tableId
);
// 查询列信息
List
<
GenTableColumn
>
columns
=
table
.
getColumns
();
setPkColumn
(
table
,
columns
);
VelocityInitializer
.
initVelocity
();
VelocityContext
context
=
VelocityUtils
.
prepareContext
(
table
);
// 获取模板列表
List
<
String
>
templates
=
VelocityUtils
.
getTemplateList
(
table
.
getTplCategory
());
for
(
String
template
:
templates
)
{
// 渲染模板
StringWriter
sw
=
new
StringWriter
();
Template
tpl
=
Velocity
.
getTemplate
(
template
,
Constants
.
UTF8
);
tpl
.
merge
(
context
,
sw
);
dataMap
.
put
(
template
,
sw
.
toString
());
}
return
dataMap
;
}
/**
* 生成代码
*
* @param tableName 表名称
* @return 数据
*/
@Override
public
byte
[]
generatorCode
(
String
tableName
)
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ZipOutputStream
zip
=
new
ZipOutputStream
(
outputStream
);
generatorCode
(
tableName
,
zip
);
IOUtils
.
closeQuietly
(
zip
);
return
outputStream
.
toByteArray
();
}
/**
* 批量生成代码
*
* @param tableNames 表数组
* @return 数据
*/
@Override
public
byte
[]
generatorCode
(
String
[]
tableNames
)
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ZipOutputStream
zip
=
new
ZipOutputStream
(
outputStream
);
for
(
String
tableName
:
tableNames
)
{
generatorCode
(
tableName
,
zip
);
}
IOUtils
.
closeQuietly
(
zip
);
return
outputStream
.
toByteArray
();
}
/**
* 查询表信息并生成代码
*/
private
void
generatorCode
(
String
tableName
,
ZipOutputStream
zip
)
{
// 查询表信息
GenTable
table
=
genTableMapper
.
selectGenTableByName
(
tableName
);
// 查询列信息
List
<
GenTableColumn
>
columns
=
table
.
getColumns
();
setPkColumn
(
table
,
columns
);
VelocityInitializer
.
initVelocity
();
VelocityContext
context
=
VelocityUtils
.
prepareContext
(
table
);
// 获取模板列表
List
<
String
>
templates
=
VelocityUtils
.
getTemplateList
(
table
.
getTplCategory
());
for
(
String
template
:
templates
)
{
// 渲染模板
StringWriter
sw
=
new
StringWriter
();
Template
tpl
=
Velocity
.
getTemplate
(
template
,
Constants
.
UTF8
);
tpl
.
merge
(
context
,
sw
);
try
{
// 添加到zip
zip
.
putNextEntry
(
new
ZipEntry
(
VelocityUtils
.
getFileName
(
template
,
table
)));
IOUtils
.
write
(
sw
.
toString
(),
zip
,
Constants
.
UTF8
);
IOUtils
.
closeQuietly
(
sw
);
zip
.
closeEntry
();
}
catch
(
IOException
e
)
{
log
.
error
(
"渲染模板失败,表名:"
+
table
.
getTableName
(),
e
);
}
}
}
/**
* 修改保存参数校验
*
* @param genTable 业务信息
*/
public
void
validateEdit
(
GenTable
genTable
)
{
if
(
GenConstants
.
TPL_TREE
.
equals
(
genTable
.
getTplCategory
()))
{
String
options
=
JSON
.
toJSONString
(
genTable
.
getParams
());
JSONObject
paramsObj
=
JSONObject
.
parseObject
(
options
);
if
(
StringUtils
.
isEmpty
(
paramsObj
.
getString
(
GenConstants
.
TREE_CODE
)))
{
throw
new
CustomException
(
"树编码字段不能为空"
);
}
else
if
(
StringUtils
.
isEmpty
(
paramsObj
.
getString
(
GenConstants
.
TREE_PARENT_CODE
)))
{
throw
new
CustomException
(
"树父编码字段不能为空"
);
}
else
if
(
StringUtils
.
isEmpty
(
paramsObj
.
getString
(
GenConstants
.
TREE_NAME
)))
{
throw
new
CustomException
(
"树名称字段不能为空"
);
}
}
}
/**
* 设置主键列信息
*
* @param genTable 业务表信息
* @param columns 业务字段列表
*/
public
void
setPkColumn
(
GenTable
table
,
List
<
GenTableColumn
>
columns
)
{
for
(
GenTableColumn
column
:
columns
)
{
if
(
column
.
isPk
())
{
table
.
setPkColumn
(
column
);
break
;
}
}
if
(
StringUtils
.
isNull
(
table
.
getPkColumn
()))
{
table
.
setPkColumn
(
columns
.
get
(
0
));
}
}
/**
* 设置代码生成其他选项值
*
* @param genTable 设置后的生成对象
*/
public
void
setTableFromOptions
(
GenTable
genTable
)
{
JSONObject
paramsObj
=
JSONObject
.
parseObject
(
genTable
.
getOptions
());
if
(
StringUtils
.
isNotNull
(
paramsObj
))
{
String
treeCode
=
paramsObj
.
getString
(
GenConstants
.
TREE_CODE
);
String
treeParentCode
=
paramsObj
.
getString
(
GenConstants
.
TREE_PARENT_CODE
);
String
treeName
=
paramsObj
.
getString
(
GenConstants
.
TREE_NAME
);
genTable
.
setTreeCode
(
treeCode
);
genTable
.
setTreeParentCode
(
treeParentCode
);
genTable
.
setTreeName
(
treeName
);
}
}
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/IGenTableColumnService.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.service
;
import
java.util.List
;
import
com.ruoyi.project.tool.gen.domain.GenTableColumn
;
/**
* 业务字段 服务层
*
* @author ruoyi
*/
public
interface
IGenTableColumnService
{
/**
* 查询业务字段列表
*
* @param genTableColumn 业务字段编号
* @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
);
}
ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/IGenTableService.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.service
;
import
java.util.List
;
import
java.util.Map
;
import
com.ruoyi.project.tool.gen.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
[]
generatorCode
(
String
tableName
);
/**
* 批量生成代码
*
* @param tableNames 表数组
* @return 数据
*/
public
byte
[]
generatorCode
(
String
[]
tableNames
);
/**
* 修改保存参数校验
*
* @param genTable 业务信息
*/
public
void
validateEdit
(
GenTable
genTable
);
}
ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/GenUtils.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.util
;
import
java.util.Arrays
;
import
org.apache.commons.lang3.RegExUtils
;
import
com.ruoyi.common.constant.GenConstants
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.framework.config.GenConfig
;
import
com.ruoyi.project.tool.gen.domain.GenTable
;
import
com.ruoyi.project.tool.gen.domain.GenTableColumn
;
/**
* 代码生成器 工具类
*
* @author ruoyi
*/
public
class
GenUtils
{
/**
* 初始化表信息
*/
public
static
void
initTable
(
GenTable
genTable
,
String
operName
)
{
genTable
.
setClassName
(
convertClassName
(
genTable
.
getTableName
()));
genTable
.
setPackageName
(
GenConfig
.
getPackageName
());
genTable
.
setModuleName
(
getModuleName
(
GenConfig
.
getPackageName
()));
genTable
.
setBusinessName
(
getBusinessName
(
genTable
.
getTableName
()));
genTable
.
setFunctionName
(
replaceText
(
genTable
.
getTableComment
()));
genTable
.
setFunctionAuthor
(
GenConfig
.
getAuthor
());
genTable
.
setCreateBy
(
operName
);
}
/**
* 初始化列属性字段
*/
public
static
void
initColumnField
(
GenTableColumn
column
,
GenTable
table
)
{
String
dataType
=
getDbType
(
column
.
getColumnType
());
String
columnName
=
column
.
getColumnName
();
column
.
setTableId
(
table
.
getTableId
());
column
.
setCreateBy
(
table
.
getCreateBy
());
// 设置java字段名
column
.
setJavaField
(
StringUtils
.
toCamelCase
(
columnName
));
if
(
arraysContains
(
GenConstants
.
COLUMNTYPE_STR
,
dataType
))
{
column
.
setJavaType
(
GenConstants
.
TYPE_STRING
);
// 字符串长度超过500设置为文本域
Integer
columnLength
=
getColumnLength
(
column
.
getColumnType
());
String
htmlType
=
columnLength
>=
500
?
GenConstants
.
HTML_TEXTAREA
:
GenConstants
.
HTML_INPUT
;
column
.
setHtmlType
(
htmlType
);
}
else
if
(
arraysContains
(
GenConstants
.
COLUMNTYPE_TIME
,
dataType
))
{
column
.
setJavaType
(
GenConstants
.
TYPE_DATE
);
column
.
setHtmlType
(
GenConstants
.
HTML_DATETIME
);
}
else
if
(
arraysContains
(
GenConstants
.
COLUMNTYPE_NUMBER
,
dataType
))
{
column
.
setHtmlType
(
GenConstants
.
HTML_INPUT
);
// 如果是浮点型
String
[]
str
=
StringUtils
.
split
(
StringUtils
.
substringBetween
(
column
.
getColumnType
(),
"("
,
")"
),
","
);
if
(
str
!=
null
&&
str
.
length
==
2
&&
Integer
.
parseInt
(
str
[
1
])
>
0
)
{
column
.
setJavaType
(
GenConstants
.
TYPE_DOUBLE
);
}
// 如果是整形
else
if
(
str
!=
null
&&
str
.
length
==
1
&&
Integer
.
parseInt
(
str
[
0
])
<=
10
)
{
column
.
setJavaType
(
GenConstants
.
TYPE_INTEGER
);
}
// 长整形
else
{
column
.
setJavaType
(
GenConstants
.
TYPE_LONG
);
}
}
// 插入字段(默认所有字段都需要插入)
column
.
setIsInsert
(
GenConstants
.
REQUIRE
);
// 编辑字段
if
(!
arraysContains
(
GenConstants
.
COLUMNNAME_NOT_EDIT
,
columnName
)
&&
!
column
.
isPk
())
{
column
.
setIsEdit
(
GenConstants
.
REQUIRE
);
}
// 列表字段
if
(!
arraysContains
(
GenConstants
.
COLUMNNAME_NOT_LIST
,
columnName
)
&&
!
column
.
isPk
())
{
column
.
setIsList
(
GenConstants
.
REQUIRE
);
}
// 查询字段
if
(!
arraysContains
(
GenConstants
.
COLUMNNAME_NOT_QUERY
,
columnName
)
&&
!
column
.
isPk
())
{
column
.
setIsQuery
(
GenConstants
.
REQUIRE
);
}
// 查询字段类型
if
(
StringUtils
.
endsWithIgnoreCase
(
columnName
,
"name"
))
{
column
.
setQueryType
(
GenConstants
.
QUERY_LIKE
);
}
// 状态字段设置单选框
if
(
StringUtils
.
endsWithIgnoreCase
(
columnName
,
"status"
))
{
column
.
setHtmlType
(
GenConstants
.
HTML_RADIO
);
}
// 类型&性别字段设置下拉框
else
if
(
StringUtils
.
endsWithIgnoreCase
(
columnName
,
"type"
)
||
StringUtils
.
endsWithIgnoreCase
(
columnName
,
"sex"
))
{
column
.
setHtmlType
(
GenConstants
.
HTML_SELECT
);
}
}
/**
* 校验数组是否包含指定值
*
* @param arr 数组
* @param targetValue 值
* @return 是否包含
*/
public
static
boolean
arraysContains
(
String
[]
arr
,
String
targetValue
)
{
return
Arrays
.
asList
(
arr
).
contains
(
targetValue
);
}
/**
* 获取模块名
*
* @param packageName 包名
* @return 模块名
*/
public
static
String
getModuleName
(
String
packageName
)
{
int
lastIndex
=
packageName
.
lastIndexOf
(
"."
);
int
nameLength
=
packageName
.
length
();
String
moduleName
=
StringUtils
.
substring
(
packageName
,
lastIndex
+
1
,
nameLength
);
return
moduleName
;
}
/**
* 获取业务名
*
* @param tableName 表名
* @return 业务名
*/
public
static
String
getBusinessName
(
String
tableName
)
{
int
lastIndex
=
tableName
.
lastIndexOf
(
"_"
);
int
nameLength
=
tableName
.
length
();
String
businessName
=
StringUtils
.
substring
(
tableName
,
lastIndex
+
1
,
nameLength
);
return
businessName
;
}
/**
* 表名转换成Java类名
*
* @param tableName 表名称
* @return 类名
*/
public
static
String
convertClassName
(
String
tableName
)
{
boolean
autoRemovePre
=
GenConfig
.
getAutoRemovePre
();
String
tablePrefix
=
GenConfig
.
getTablePrefix
();
if
(
autoRemovePre
&&
StringUtils
.
isNotEmpty
(
tablePrefix
))
{
String
[]
searchList
=
StringUtils
.
split
(
tablePrefix
,
","
);
String
[]
replacementList
=
emptyList
(
searchList
.
length
);
tableName
=
StringUtils
.
replaceEach
(
tableName
,
searchList
,
replacementList
);
}
return
StringUtils
.
convertToCamelCase
(
tableName
);
}
/**
* 关键字替换
*
* @param name 需要被替换的名字
* @return 替换后的名字
*/
public
static
String
replaceText
(
String
text
)
{
return
RegExUtils
.
replaceAll
(
text
,
"(?:表|若依)"
,
""
);
}
/**
* 获取数据库类型字段
*
* @param columnType 列类型
* @return 截取后的列类型
*/
public
static
String
getDbType
(
String
columnType
)
{
if
(
StringUtils
.
indexOf
(
columnType
,
"("
)
>
0
)
{
return
StringUtils
.
substringBefore
(
columnType
,
"("
);
}
else
{
return
columnType
;
}
}
/**
* 获取字段长度
*
* @param columnType 列类型
* @return 截取后的列类型
*/
public
static
Integer
getColumnLength
(
String
columnType
)
{
if
(
StringUtils
.
indexOf
(
columnType
,
"("
)
>
0
)
{
String
length
=
StringUtils
.
substringBetween
(
columnType
,
"("
,
")"
);
return
Integer
.
valueOf
(
length
);
}
else
{
return
0
;
}
}
/**
* 获取空数组列表
*
* @param length 长度
* @return 数组信息
*/
public
static
String
[]
emptyList
(
int
length
)
{
String
[]
values
=
new
String
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
values
[
i
]
=
StringUtils
.
EMPTY
;
}
return
values
;
}
}
\ No newline at end of file
ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityInitializer.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.util
;
import
java.util.Properties
;
import
org.apache.velocity.app.Velocity
;
import
com.ruoyi.common.constant.Constants
;
/**
* VelocityEngine工厂
*
* @author RuoYi
*/
public
class
VelocityInitializer
{
/**
* 初始化vm方法
*/
public
static
void
initVelocity
()
{
Properties
p
=
new
Properties
();
try
{
// 加载classpath目录下的vm文件
p
.
setProperty
(
"file.resource.loader.class"
,
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"
);
// 定义字符集
p
.
setProperty
(
Velocity
.
ENCODING_DEFAULT
,
Constants
.
UTF8
);
p
.
setProperty
(
Velocity
.
OUTPUT_ENCODING
,
Constants
.
UTF8
);
// 初始化Velocity引擎,指定配置Properties
Velocity
.
init
(
p
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java
0 → 100644
View file @
fee8a595
package
com.ruoyi.project.tool.gen.util
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
org.apache.velocity.VelocityContext
;
import
com.alibaba.fastjson.JSONObject
;
import
com.ruoyi.common.constant.GenConstants
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.project.tool.gen.domain.GenTable
;
import
com.ruoyi.project.tool.gen.domain.GenTableColumn
;
public
class
VelocityUtils
{
/** 项目空间路径 */
private
static
final
String
PROJECT_PATH
=
"main/java"
;
/** mybatis空间路径 */
private
static
final
String
MYBATIS_PATH
=
"main/resources/mybatis"
;
/**
* 设置模板变量信息
*
* @return 模板列表
*/
public
static
VelocityContext
prepareContext
(
GenTable
genTable
)
{
String
moduleName
=
genTable
.
getModuleName
();
String
businessName
=
genTable
.
getBusinessName
();
String
packageName
=
genTable
.
getPackageName
();
String
tplCategory
=
genTable
.
getTplCategory
();
String
functionName
=
genTable
.
getFunctionName
();
VelocityContext
velocityContext
=
new
VelocityContext
();
velocityContext
.
put
(
"tplCategory"
,
genTable
.
getTplCategory
());
velocityContext
.
put
(
"tableName"
,
genTable
.
getTableName
());
velocityContext
.
put
(
"functionName"
,
StringUtils
.
isNotEmpty
(
functionName
)
?
functionName
:
"【请填写功能名称】"
);
velocityContext
.
put
(
"ClassName"
,
genTable
.
getClassName
());
velocityContext
.
put
(
"className"
,
StringUtils
.
uncapitalize
(
genTable
.
getClassName
()));
velocityContext
.
put
(
"moduleName"
,
genTable
.
getModuleName
());
velocityContext
.
put
(
"BusinessName"
,
StringUtils
.
capitalize
(
genTable
.
getBusinessName
()));
velocityContext
.
put
(
"businessName"
,
genTable
.
getBusinessName
());
velocityContext
.
put
(
"basePackage"
,
getPackagePrefix
(
packageName
));
velocityContext
.
put
(
"packageName"
,
packageName
);
velocityContext
.
put
(
"author"
,
genTable
.
getFunctionAuthor
());
velocityContext
.
put
(
"datetime"
,
DateUtils
.
getDate
());
velocityContext
.
put
(
"pkColumn"
,
genTable
.
getPkColumn
());
velocityContext
.
put
(
"importList"
,
getImportList
(
genTable
.
getColumns
()));
velocityContext
.
put
(
"permissionPrefix"
,
getPermissionPrefix
(
moduleName
,
businessName
));
velocityContext
.
put
(
"columns"
,
genTable
.
getColumns
());
velocityContext
.
put
(
"table"
,
genTable
);
if
(
GenConstants
.
TPL_TREE
.
equals
(
tplCategory
))
{
setTreeVelocityContext
(
velocityContext
,
genTable
);
}
return
velocityContext
;
}
public
static
void
setTreeVelocityContext
(
VelocityContext
context
,
GenTable
genTable
)
{
String
options
=
genTable
.
getOptions
();
JSONObject
paramsObj
=
JSONObject
.
parseObject
(
options
);
String
treeCode
=
getTreecode
(
paramsObj
);
String
treeParentCode
=
getTreeParentCode
(
paramsObj
);
String
treeName
=
getTreeName
(
paramsObj
);
context
.
put
(
"treeCode"
,
treeCode
);
context
.
put
(
"treeParentCode"
,
treeParentCode
);
context
.
put
(
"treeName"
,
treeName
);
context
.
put
(
"expandColumn"
,
getExpandColumn
(
genTable
));
if
(
paramsObj
.
containsKey
(
GenConstants
.
TREE_PARENT_CODE
))
{
context
.
put
(
"tree_parent_code"
,
paramsObj
.
getString
(
GenConstants
.
TREE_PARENT_CODE
));
}
if
(
paramsObj
.
containsKey
(
GenConstants
.
TREE_NAME
))
{
context
.
put
(
"tree_name"
,
paramsObj
.
getString
(
GenConstants
.
TREE_NAME
));
}
}
/**
* 获取模板信息
*
* @return 模板列表
*/
public
static
List
<
String
>
getTemplateList
(
String
tplCategory
)
{
List
<
String
>
templates
=
new
ArrayList
<
String
>();
templates
.
add
(
"vm/java/domain.java.vm"
);
templates
.
add
(
"vm/java/mapper.java.vm"
);
templates
.
add
(
"vm/java/service.java.vm"
);
templates
.
add
(
"vm/java/serviceImpl.java.vm"
);
templates
.
add
(
"vm/java/controller.java.vm"
);
templates
.
add
(
"vm/xml/mapper.xml.vm"
);
templates
.
add
(
"vm/sql/sql.vm"
);
templates
.
add
(
"vm/js/api.js.vm"
);
templates
.
add
(
"vm/vue/index.vue.vm"
);
return
templates
;
}
/**
* 获取文件名
*/
public
static
String
getFileName
(
String
template
,
GenTable
genTable
)
{
// 文件名称
String
fileName
=
""
;
// 包路径
String
packageName
=
genTable
.
getPackageName
();
// 模块名
String
moduleName
=
genTable
.
getModuleName
();
// 大写类名
String
className
=
genTable
.
getClassName
();
// 业务名称
String
businessName
=
genTable
.
getBusinessName
();
String
javaPath
=
PROJECT_PATH
+
"/"
+
StringUtils
.
replace
(
packageName
,
"."
,
"/"
);
String
mybatisPath
=
MYBATIS_PATH
+
"/"
+
moduleName
;
String
vuePath
=
"vue"
;
if
(
template
.
contains
(
"domain.java.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/domain/{}.java"
,
javaPath
,
className
);
}
else
if
(
template
.
contains
(
"mapper.java.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/mapper/{}Mapper.java"
,
javaPath
,
className
);
}
else
if
(
template
.
contains
(
"service.java.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/service/I{}Service.java"
,
javaPath
,
className
);
}
else
if
(
template
.
contains
(
"serviceImpl.java.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/service/impl/{}ServiceImpl.java"
,
javaPath
,
className
);
}
else
if
(
template
.
contains
(
"controller.java.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/controller/{}Controller.java"
,
javaPath
,
className
);
}
else
if
(
template
.
contains
(
"mapper.xml.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/{}Mapper.xml"
,
mybatisPath
,
className
);
}
else
if
(
template
.
contains
(
"sql.vm"
))
{
fileName
=
businessName
+
"Menu.sql"
;
}
else
if
(
template
.
contains
(
"js.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/api/{}/{}.js"
,
vuePath
,
moduleName
,
businessName
);
}
else
if
(
template
.
contains
(
"vue.vm"
))
{
fileName
=
StringUtils
.
format
(
"{}/views/{}/{}/index.vue"
,
vuePath
,
moduleName
,
businessName
);
}
return
fileName
;
}
/**
* 获取包前缀
*
* @param packageName 包名称
* @return 包前缀名称
*/
public
static
String
getPackagePrefix
(
String
packageName
)
{
int
lastIndex
=
packageName
.
lastIndexOf
(
"."
);
String
basePackage
=
StringUtils
.
substring
(
packageName
,
0
,
lastIndex
);
return
basePackage
;
}
/**
* 根据列类型获取导入包
*
* @param column 列集合
* @return 返回需要导入的包列表
*/
public
static
HashSet
<
String
>
getImportList
(
List
<
GenTableColumn
>
columns
)
{
HashSet
<
String
>
importList
=
new
HashSet
<
String
>();
for
(
GenTableColumn
column
:
columns
)
{
if
(!
column
.
isSuperColumn
()
&&
GenConstants
.
TYPE_DATE
.
equals
(
column
.
getJavaType
()))
{
importList
.
add
(
"java.util.Date"
);
}
else
if
(!
column
.
isSuperColumn
()
&&
GenConstants
.
TYPE_BIGDECIMAL
.
equals
(
column
.
getJavaType
()))
{
importList
.
add
(
"java.math.BigDecimal"
);
}
}
return
importList
;
}
/**
* 获取权限前缀
*
* @param moduleName 模块名称
* @param businessName 业务名称
* @return 返回权限前缀
*/
public
static
String
getPermissionPrefix
(
String
moduleName
,
String
businessName
)
{
return
StringUtils
.
format
(
"{}:{}"
,
moduleName
,
businessName
);
}
/**
* 获取树编码
*
* @param options 生成其他选项
* @return 树编码
*/
public
static
String
getTreecode
(
JSONObject
paramsObj
)
{
if
(
paramsObj
.
containsKey
(
GenConstants
.
TREE_CODE
))
{
return
StringUtils
.
toCamelCase
(
paramsObj
.
getString
(
GenConstants
.
TREE_CODE
));
}
return
""
;
}
/**
* 获取树父编码
*
* @param options 生成其他选项
* @return 树父编码
*/
public
static
String
getTreeParentCode
(
JSONObject
paramsObj
)
{
if
(
paramsObj
.
containsKey
(
GenConstants
.
TREE_PARENT_CODE
))
{
return
StringUtils
.
toCamelCase
(
paramsObj
.
getString
(
GenConstants
.
TREE_PARENT_CODE
));
}
return
""
;
}
/**
* 获取树名称
*
* @param options 生成其他选项
* @return 树名称
*/
public
static
String
getTreeName
(
JSONObject
paramsObj
)
{
if
(
paramsObj
.
containsKey
(
GenConstants
.
TREE_NAME
))
{
return
StringUtils
.
toCamelCase
(
paramsObj
.
getString
(
GenConstants
.
TREE_NAME
));
}
return
""
;
}
/**
* 获取需要在哪一列上面显示展开按钮
*
* @param genTable 业务表对象
* @return 展开按钮列序号
*/
public
static
int
getExpandColumn
(
GenTable
genTable
)
{
String
options
=
genTable
.
getOptions
();
JSONObject
paramsObj
=
JSONObject
.
parseObject
(
options
);
String
treeName
=
paramsObj
.
getString
(
GenConstants
.
TREE_NAME
);
int
num
=
0
;
for
(
GenTableColumn
column
:
genTable
.
getColumns
())
{
if
(
column
.
isList
())
{
num
++;
String
columnName
=
column
.
getColumnName
();
if
(
columnName
.
equals
(
treeName
))
{
break
;
}
}
}
return
num
;
}
}
\ No newline at end of file
ruoyi/src/main/resources/application.yml
View file @
fee8a595
...
...
@@ -3,7 +3,7 @@ ruoyi:
# 名称
name
:
RuoYi
# 版本
version
:
1.1
.0
version
:
2.0
.0
# 版权年份
copyrightYear
:
2019
# 实例演示开关
...
...
@@ -106,4 +106,15 @@ xss:
# 排除链接(多个用逗号分隔)
excludes
:
/system/notice/*
# 匹配链接
urlPatterns
:
/system/*,/monitor/*,/tool/*
\ No newline at end of file
urlPatterns
:
/system/*,/monitor/*,/tool/*
# 代码生成
gen
:
# 作者
author
:
ruoyi
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
packageName
:
com.ruoyi.project.system
# 自动去除表前缀,默认是true
autoRemovePre
:
false
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
tablePrefix
:
sys_
\ No newline at end of file
ruoyi/src/main/resources/mybatis/monitor/SysLogininforMapper.xml
View file @
fee8a595
...
...
@@ -33,11 +33,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"userName != null and userName != ''"
>
AND user_name like concat('%', #{userName}, '%')
</if>
<if
test=
"
params.
beginTime != null and
params.
beginTime != ''"
>
<!-- 开始时间检索 -->
and date_format(login_time,'%y%m%d')
>
= date_format(#{
params.
beginTime},'%y%m%d')
<if
test=
"beginTime != null and beginTime != ''"
>
<!-- 开始时间检索 -->
and date_format(login_time,'%y%m%d')
>
= date_format(#{beginTime},'%y%m%d')
</if>
<if
test=
"
params.
endTime != null and
params.
endTime != ''"
>
<!-- 结束时间检索 -->
and date_format(login_time,'%y%m%d')
<
= date_format(#{
params.
endTime},'%y%m%d')
<if
test=
"endTime != null and endTime != ''"
>
<!-- 结束时间检索 -->
and date_format(login_time,'%y%m%d')
<
= date_format(#{endTime},'%y%m%d')
</if>
</where>
</select>
...
...
Prev
1
2
3
4
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment