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
Springboot Plus
Commits
71995bc5
Commit
71995bc5
authored
Apr 28, 2018
by
xiandafu
Browse files
代码生成的时候选择自动配置工能点
parent
50e9562e
Changes
4
Hide whitespace changes
Inline
Side-by-side
admin-core/src/main/java/com/ibeetl/admin/core/gen/model/Entity.java
View file @
71995bc5
...
...
@@ -13,9 +13,12 @@ public class Entity {
Attribute
nameAttribute
;
String
comment
;
String
system
;
//是否生成excel导入导出按钮
boolean
includeExcel
=
false
;
//是否包含附件信息
boolean
attachment
=
false
;
//是否生成代码,也同时生成功能点
boolean
autoAddFunction
=
false
;
public
String
getName
()
{
return
name
;
}
...
...
@@ -97,5 +100,11 @@ public class Entity {
public
void
setAttachment
(
boolean
attachment
)
{
this
.
attachment
=
attachment
;
}
public
boolean
isAutoAddFunction
()
{
return
autoAddFunction
;
}
public
void
setAutoAddFunction
(
boolean
autoAddFunction
)
{
this
.
autoAddFunction
=
autoAddFunction
;
}
}
admin-core/src/main/java/com/ibeetl/admin/core/service/CoreCodeGenService.java
View file @
71995bc5
package
com.ibeetl.admin.core.service
;
import
org.beetl.core.Configuration
;
import
org.beetl.core.GroupTemplate
;
import
org.beetl.core.Template
;
import
org.beetl.core.resource.ClasspathResourceLoader
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
org.beetl.sql.core.JavaType
;
import
org.beetl.sql.core.NameConversion
;
import
org.beetl.sql.core.SQLManager
;
...
...
@@ -11,20 +12,13 @@ import org.beetl.sql.core.db.ClassDesc;
import
org.beetl.sql.core.db.ColDesc
;
import
org.beetl.sql.core.db.MetadataManager
;
import
org.beetl.sql.core.db.TableDesc
;
import
org.beetl.sql.ext.gen.GenConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ibeetl.admin.core.entity.CoreFunction
;
import
com.ibeetl.admin.core.gen.model.Attribute
;
import
com.ibeetl.admin.core.gen.model.Entity
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.PrintStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
/**
* 代码生成,用于根据表或者视图生成entity,mapper,service,conroller
* 未来可以生成swagger api,界面
...
...
@@ -34,6 +28,8 @@ import java.util.Set;
public
class
CoreCodeGenService
{
@Autowired
SQLManager
sqlManager
;
@Autowired
CorePlatformService
platformService
;
public
List
<
Entity
>
getAllEntityInfo
(){
MetadataManager
meta
=
sqlManager
.
getMetaDataManager
();
...
...
@@ -107,6 +103,74 @@ public class CoreCodeGenService {
return
e
;
}
public
boolean
insertFunction
(
Entity
data
,
String
urlBase
){
String
preffix
=
urlBase
.
replace
(
'/'
,
'.'
);
String
functionCode
=
preffix
+
"."
+
data
.
getCode
();
String
indexFunctonCode
=
functionCode
+
".query"
;
CoreFunction
query
=
new
CoreFunction
();
query
.
setCode
(
indexFunctonCode
);
Object
o
=
sqlManager
.
templateOne
(
query
);
if
(
o
!=
null
){
return
true
;
}
//设置功能点
CoreFunction
rootFunction
=
new
CoreFunction
();
rootFunction
.
setName
(
data
.
getDisplayName
());
rootFunction
.
setCode
(
functionCode
);
rootFunction
.
setCreateTime
(
new
Date
());
rootFunction
.
setParentId
(
0L
);
rootFunction
.
setType
(
"FN0"
);
sqlManager
.
insert
(
rootFunction
,
true
);
Long
parentId
=
rootFunction
.
getId
();
//设置曾删改查功能点
CoreFunction
indexFunction
=
new
CoreFunction
();
indexFunction
.
setName
(
"查询"
+
data
.
getDisplayName
());
indexFunction
.
setCode
(
indexFunctonCode
);
indexFunction
.
setCreateTime
(
new
Date
());
indexFunction
.
setParentId
(
parentId
);
indexFunction
.
setAccessUrl
(
"/"
+
urlBase
+
"/"
+
data
.
getCode
()+
"/index.do"
);
//设置为查询功能
indexFunction
.
setType
(
"FN1"
);
sqlManager
.
insert
(
indexFunction
,
true
);
CoreFunction
upateFunction
=
new
CoreFunction
();
String
updateFunctonCode
=
functionCode
+
".edit"
;
upateFunction
.
setName
(
"修改"
+
data
.
getDisplayName
());
upateFunction
.
setCode
(
updateFunctonCode
);
upateFunction
.
setCreateTime
(
new
Date
());
upateFunction
.
setParentId
(
parentId
);
upateFunction
.
setType
(
"FN0"
);
sqlManager
.
insert
(
upateFunction
,
true
);
CoreFunction
addFunction
=
new
CoreFunction
();
String
addFunctionCode
=
functionCode
+
".add"
;
addFunction
.
setName
(
"添加"
+
data
.
getDisplayName
());
addFunction
.
setCode
(
addFunctionCode
);
addFunction
.
setCreateTime
(
new
Date
());
addFunction
.
setParentId
(
parentId
);
addFunction
.
setType
(
"FN0"
);
sqlManager
.
insert
(
addFunction
,
true
);
CoreFunction
delFunction
=
new
CoreFunction
();
String
delFunctionCode
=
functionCode
+
".add"
;
delFunction
.
setName
(
"删除"
+
data
.
getDisplayName
());
delFunction
.
setCode
(
delFunctionCode
);
delFunction
.
setCreateTime
(
new
Date
());
delFunction
.
setParentId
(
parentId
);
delFunction
.
setType
(
"FN0"
);
sqlManager
.
insert
(
addFunction
,
true
);
//刷新缓存
platformService
.
clearFunctionCache
();
return
true
;
}
//根据类名提供一个变量名
private
String
getEntityCode
(
String
s
)
{
//找到最后一个大写字母,以此为变量名
...
...
admin-core/src/main/java/com/ibeetl/admin/core/web/CoreCodeGenController.java
View file @
71995bc5
...
...
@@ -208,6 +208,12 @@ public class CoreCodeGenController {
MdGen
mdGen
=
new
MdGen
();
mdGen
.
make
(
target
,
entity
);
if
(
entity
.
isAutoAddFunction
())
{
//自动增加功能点
this
.
codeGenService
.
insertFunction
(
entity
,
urlBase
);
}
return
JsonResult
.
success
();
}
...
...
@@ -313,6 +319,7 @@ public class CoreCodeGenController {
entity
.
setSystem
(
info
.
getSystem
());
entity
.
setAttachment
(
data
.
entity
.
isAttachment
());
entity
.
setIncludeExcel
(
data
.
entity
.
isIncludeExcel
());
entity
.
setAutoAddFunction
(
info
.
isAutoAddFunction
());
for
(
int
i
=
0
;
i
<
entity
.
getList
().
size
();
i
++)
{
Attribute
attr
=
entity
.
getList
().
get
(
i
);
attr
.
setDisplayName
(
info
.
getList
().
get
(
i
).
getDisplayName
());
...
...
admin-core/src/main/resources/templates/core/codeGen/edit.html
View file @
71995bc5
...
...
@@ -141,6 +141,14 @@
</div>
</div>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<input
type=
"checkbox"
name=
"entity.autoAddFunction"
lay-skin=
"primary"
value=
"true"
title=
"自动配置到功能点"
/>
</div>
</div>
</div>
</div>
...
...
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