Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibizlab-generator
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibizlab-generator
提交
7d1e1652
提交
7d1e1652
编写于
8月 11, 2022
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
qx
上级
d7223463
变更
10
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
235 行增加
和
79 行删除
+235
-79
ApiMethodModel.java
...rc/main/java/cn/ibizlab/codegen/model/ApiMethodModel.java
+48
-3
EntityModel.java
...e/src/main/java/cn/ibizlab/codegen/model/EntityModel.java
+32
-24
{{entities@SQL}}Mapper.java.hbs
...}/core/{{modules}}/mapper/{{entities@SQL}}Mapper.java.hbs
+5
-0
{{entities@SQL}}ServiceBase.java.hbs
...dules}}/service/impl/{{entities@SQL}}ServiceBase.java.hbs
+10
-12
{{entities@ServiceAPI}}ServiceBase.java.hbs
.../service/impl/{{entities@ServiceAPI}}ServiceBase.java.hbs
+1
-5
{{entities@SQL}}Service.java.hbs
...core/{{modules}}/service/{{entities@SQL}}Service.java.hbs
+20
-8
{{entities@ServiceAPI}}Service.java.hbs
...modules}}/service/{{entities@ServiceAPI}}Service.java.hbs
+16
-4
AuditAspect.java.hbs
...ain/java/{{packageName}}/util/aspect/AuditAspect.java.hbs
+85
-12
{{apiEntities}}Resource.java.hbs
...kageName}}/{{apis}}/rest/{{apiEntities}}Resource.java.hbs
+3
-11
{{entities@SQL}}Mapper.xml.hbs
...r/{{modules}}/{{entities}}/{{entities@SQL}}Mapper.xml.hbs
+15
-0
未找到文件。
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/model/ApiMethodModel.java
浏览文件 @
7d1e1652
...
...
@@ -22,7 +22,7 @@ import java.util.*;
public
class
ApiMethodModel
extends
BaseModel
{
private
static
String
[]
ignoreMethodNames
=
new
String
[]{
"GET"
,
"CREATE"
,
"UPDATE"
,
"REMOVE"
};
private
static
String
[]
booleanMethodNames
=
new
String
[]{
"CREATE"
,
"UPDATE"
,
"REMOVE"
,
"SAVE"
,
"CREATEBATCH"
,
"UPDATEBATCH"
,
"REMOVEBATCH"
,
"SAVEBATCH"
};
private
static
String
[]
booleanMethodNames
=
new
String
[]{
"CREATE"
,
"UPDATE"
,
"SAVE"
,
"CREATEBATCH"
,
"UPDATEBATCH"
,
"REMOVEBATCH"
,
"SAVEBATCH"
};
private
static
Map
<
String
,
String
>
lang
=
new
HashMap
<
String
,
String
>(){{
put
(
"GET"
,
"获取"
);
...
...
@@ -155,7 +155,7 @@ public class ApiMethodModel extends BaseModel {
if
(
iPSDEServiceAPIMethodInput
!=
null
&&
iPSDEServiceAPIMethodInput
.
getPSDEMethodDTO
()!=
null
)
param
=
iPSDEServiceAPIMethodInput
.
getPSDEMethodDTO
().
getName
().
replace
(
"FilterDTO"
,
"SearchContext"
);
if
(
"KEYFIELD"
.
equalsIgnoreCase
(
iPSDEServiceAPIMethodInput
.
getType
())){
if
(
"KEYFIELD"
.
equalsIgnoreCase
(
iPSDEServiceAPIMethodInput
.
getType
())
||
this
.
getName
().
equalsIgnoreCase
(
"Remove"
)
){
param
=
""
;
inParam2
=
getApiEntity
().
getEntity
().
getKeyField
().
getType
().
java
;
inParamName
=
StringAdvUtils
.
camelcase
(
apiEntity
.
getEntity
().
getKeyField
().
getCodeName
());
...
...
@@ -245,7 +245,12 @@ public class ApiMethodModel extends BaseModel {
if
(
getPSDEServiceAPIMethod
().
getPSDEServiceAPIMethodReturn
()!=
null
&&
getPSDEServiceAPIMethod
().
getPSDEServiceAPIMethodReturn
().
getPSDEMethodDTO
()!=
null
)
param
=
getPSDEServiceAPIMethod
().
getPSDEServiceAPIMethodReturn
().
getPSDEMethodDTO
().
getName
();
if
(
"VOID"
.
equalsIgnoreCase
(
getPSDEServiceAPIMethod
().
getPSDEServiceAPIMethodReturn
().
getType
()))
{
if
(
"Remove"
.
equalsIgnoreCase
(
getName
()))
{
needDomain2Dto
=
false
;
param
=
"Boolean"
;
outParam2
=
"Boolean"
;
}
else
if
(
"VOID"
.
equalsIgnoreCase
(
getPSDEServiceAPIMethod
().
getPSDEServiceAPIMethodReturn
().
getType
()))
{
needDomain2Dto
=
isNeedDto2Domain
();
param
=
getInParam
();
outParam2
=
getInParam2
();
...
...
@@ -278,4 +283,44 @@ public class ApiMethodModel extends BaseModel {
return
outParam
;
}
private
Map
permission
;
public
Map
getPermission
()
{
if
(
this
.
getName
().
equalsIgnoreCase
(
"CheckKey"
)||
this
.
getName
().
equalsIgnoreCase
(
"GetDraft"
)||
(
this
.
getPSDEServiceAPIMethod
().
getPSDEAction
()!=
null
&&
this
.
getPSDEServiceAPIMethod
().
getPSDEAction
().
getPSDEOPPriv
()!=
null
&&
"NONE"
.
equalsIgnoreCase
(
this
.
getPSDEServiceAPIMethod
().
getPSDEAction
().
getPSDEOPPriv
().
getName
()))||
(
this
.
getPSDEServiceAPIMethod
().
getPSDEDataSet
()!=
null
&&
this
.
getPSDEServiceAPIMethod
().
getPSDEDataSet
().
getPSDEOPPriv
()!=
null
&&
"NONE"
.
equalsIgnoreCase
(
this
.
getPSDEServiceAPIMethod
().
getPSDEDataSet
().
getPSDEOPPriv
().
getName
()))
)
return
null
;
permission
=
new
HashMap
();
permission
.
put
(
"ano"
,
"PreAuthorize"
);
this
.
getInParam
();
if
(
this
.
getApiEntity
()==
null
||
this
.
getApiEntity
().
getEntity
()==
null
||(!
this
.
getApiEntity
().
getEntity
().
isHasScopes
()))
{
permission
.
put
(
"cond"
,
"hasAnyAuthority('ROLE_SUPERADMIN','"
+
this
.
getApiEntity
().
getEntity
().
getSystem
().
getProjectName
()+
"-"
+
this
.
getApiEntity
().
getEntity
().
getCodeName
()+
"-"
+
this
.
getName
()+
"-all')"
);
}
else
if
(
"FETCH"
.
equalsIgnoreCase
(
getPSDEServiceAPIMethod
().
getMethodType
()))
{
permission
.
put
(
"cond"
,
"hasAnyAuthority('ROLE_SUPERADMIN','"
+
this
.
getApiEntity
().
getEntity
().
getSystem
().
getProjectName
()+
"-"
+
this
.
getApiEntity
().
getEntity
().
getCodeName
()+
"-"
+
this
.
getName
().
replace
(
"Fetch"
,
"search"
)+
"-all')"
+
" and hasPermission(#"
+
this
.
getInParamName
()+
",'"
+
this
.
getApiEntity
().
getEntity
().
getSystem
().
getProjectName
()+
"-"
+
this
.
getApiEntity
().
getEntity
().
getCodeName
()+
"-Get')"
);
}
else
if
(
this
.
getName
().
equalsIgnoreCase
(
"Get"
))
{
permission
.
put
(
"ano"
,
"PostAuthorize"
);
permission
.
put
(
"cond"
,
"hasPermission(this.$"
+
StringAdvUtils
.
camelcase
(
this
.
getApiEntity
().
getDefaultDto
().
getCodeName
())+
"Mapping.toDomain(returnObject.body),'"
+
this
.
getApiEntity
().
getEntity
().
getSystem
().
getProjectName
()+
"-"
+
this
.
getApiEntity
().
getEntity
().
getCodeName
()+
"-"
+
this
.
getName
()+
"')"
);
}
else
if
(
this
.
getName
().
equalsIgnoreCase
(
"Update"
)||
this
.
getName
().
equalsIgnoreCase
(
"Remove"
)||
ObjectUtils
.
isEmpty
(
this
.
getInParam
()))
{
permission
.
put
(
"cond"
,
"hasPermission(this.$"
+
StringAdvUtils
.
camelcase
(
this
.
getApiEntity
().
getEntity
().
getCodeName
())+
"Service.get(#"
+
this
.
getInParamName2
()+
"),'"
+
this
.
getApiEntity
().
getEntity
().
getSystem
().
getProjectName
()+
"-"
+
this
.
getApiEntity
().
getEntity
().
getCodeName
()+
"-"
+
this
.
getName
()+
"')"
);
}
else
if
(
this
.
getName
().
equalsIgnoreCase
(
"Create"
)||
this
.
getName
().
equalsIgnoreCase
(
"Save"
)||
this
.
isNeedDto2Domain
())
{
permission
.
put
(
"cond"
,
"hasPermission(this.$"
+
StringAdvUtils
.
camelcase
(
this
.
getApiEntity
().
getDefaultDto
().
getCodeName
())+
"Mapping.toDomain(#"
+
this
.
getInParamName
()+
"),'"
+
this
.
getApiEntity
().
getEntity
().
getSystem
().
getProjectName
()+
"-"
+
this
.
getApiEntity
().
getEntity
().
getCodeName
()+
"-"
+
this
.
getName
()+
"')"
);
}
return
permission
;
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/model/EntityModel.java
浏览文件 @
7d1e1652
...
...
@@ -514,37 +514,45 @@ public class EntityModel extends BaseModel {
return
publishers
;
}
private
List
<
OptionItem
>
dataScopes
;
public
List
<
OptionItem
>
getDataScopes
()
{
List
<
OptionItem
>
dataScopes
=
new
ArrayList
<>();
dataScopes
.
add
(
new
OptionItem
().
setId
(
"all"
).
setName
(
"全部数据"
));
boolean
hasOrgId
=
false
,
hasDetpId
=
false
,
hasCreateBy
=
false
;
for
(
FieldModel
field:
getFields
())
if
(
dataScopes
==
null
)
{
if
(
"ORGID"
.
equalsIgnoreCase
(
field
.
getDataEntityField
().
getPredefinedType
()))
hasOrgId
=
true
;
else
if
(
"ORGSECTORID"
.
equalsIgnoreCase
(
field
.
getDataEntityField
().
getPredefinedType
()))
hasDetpId
=
true
;
else
if
(
"CREATEMAN"
.
equalsIgnoreCase
(
field
.
getDataEntityField
().
getPredefinedType
()))
hasCreateBy
=
true
;
}
if
(
hasOrgId
)
{
dataScopes
.
add
(
new
OptionItem
().
setId
(
"curorg"
).
setName
(
"当前单位"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"porg"
).
setName
(
"上级单位"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"sorg"
).
setName
(
"下级单位"
));
}
if
(
hasDetpId
)
{
dataScopes
.
add
(
new
OptionItem
().
setId
(
"curorgdept"
).
setName
(
"当前部门"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"porgdept"
).
setName
(
"上级部门"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"sorgdept"
).
setName
(
"下级部门"
));
dataScopes
=
new
ArrayList
<>();
dataScopes
.
add
(
new
OptionItem
().
setId
(
"all"
).
setName
(
"全部数据"
));
boolean
hasOrgId
=
false
,
hasDetpId
=
false
,
hasCreateBy
=
false
;
for
(
FieldModel
field:
getFields
())
{
if
(
"ORGID"
.
equalsIgnoreCase
(
field
.
getDataEntityField
().
getPredefinedType
()))
hasOrgId
=
true
;
else
if
(
"ORGSECTORID"
.
equalsIgnoreCase
(
field
.
getDataEntityField
().
getPredefinedType
()))
hasDetpId
=
true
;
else
if
(
"CREATEMAN"
.
equalsIgnoreCase
(
field
.
getDataEntityField
().
getPredefinedType
()))
hasCreateBy
=
true
;
}
if
(
hasOrgId
)
{
dataScopes
.
add
(
new
OptionItem
().
setId
(
"curorg"
).
setName
(
"当前单位"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"porg"
).
setName
(
"上级单位"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"sorg"
).
setName
(
"下级单位"
));
}
if
(
hasDetpId
)
{
dataScopes
.
add
(
new
OptionItem
().
setId
(
"curorgdept"
).
setName
(
"当前部门"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"porgdept"
).
setName
(
"上级部门"
));
dataScopes
.
add
(
new
OptionItem
().
setId
(
"sorgdept"
).
setName
(
"下级部门"
));
}
if
(
hasCreateBy
)
dataScopes
.
add
(
new
OptionItem
().
setId
(
"createman"
).
setName
(
"创建人"
));
}
if
(
hasCreateBy
)
dataScopes
.
add
(
new
OptionItem
().
setId
(
"createman"
).
setName
(
"创建人"
));
return
dataScopes
;
}
public
boolean
isHasScopes
()
{
return
getDataScopes
().
size
()>
1
;
}
private
Map
<
String
,
POSchema
>
poSchemas
;
public
POSchema
getDefaultPOSchema
()
...
...
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/mapper/{{entities@SQL}}Mapper.java.hbs
浏览文件 @
7d1e1652
...
...
@@ -66,6 +66,11 @@ public interface {{entity.codeName}}Mapper extends BaseMapper<{{entity.codeName}
{{/
enableEntityCache
}}
int deleteById(Serializable id);
{{#
enableEntityCache
}}
@CacheEvict(value = "
{{
lowerCase
entity
.
codeName
}}
", allEntries = true)
{{/
enableEntityCache
}}
int deleteEntities(@Param("list") List
<
{{
entity
.
codeName
}}
>
list);
/**
* 自定义查询SQL
* @param sql
...
...
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/impl/{{entities@SQL}}ServiceBase.java.hbs
浏览文件 @
7d1e1652
...
...
@@ -58,10 +58,6 @@ import {{packageName}}.core.{{module}}.service.{{codeName}}Service;
@Service("
{{
entity
.
codeName
}}
Service")
public class
{{
entity
.
codeName
}}
ServiceBase extends ServiceImpl
<
{{
entity
.
codeName
}}
Mapper
,
{{
entity
.
codeName
}}
>
implements
{{
entity
.
codeName
}}
Service {
protected
{{
entity
.
codeName
}}
Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{#
entity
.
relEntities
}}
{{#
neq
storage
"NONE"
}}
@Autowired
...
...
@@ -314,17 +310,19 @@ public class {{entity.codeName}}ServiceBase extends ServiceImpl<{{entity.codeNam
{{/if}}
return true ;
}
{{#
eq
entity
.
actions
.
remove
.
transactionMode
"GLOBAL"
}}
@GlobalTransactional
{{/
eq
}}{{#
eq
entity
.
actions
.
remove
.
transactionMode
"DEFAULT"
}}
@Transactional
{{/
eq
}}
public boolean removeBatch(Collection
<
{{
entity
.
keyField
.
type
.
java
}}
>
ids) {
{{#if
(
or
entity
.
actions
.
update
.
psDEActionLogics
entity
.
isIndexSubDE
(
not
entity
.
keyField
.
phisicalDEField
)
entity
.
hasPSDERsMapping
)
}}
for (
{{
entity
.
keyField
.
type
.
java
}}
et : ids)
getSelf().remove(et);
public boolean removeByEntities(List
<
{{
entity
.
codeName
}}
>
entities) {
{{#if
(
or
entity
.
actions
.
update
.
psDEActionLogics
entity
.
isIndexSubDE
entity
.
hasPSDERsMapping
)
}}
for (
{{
entity
.
codeName
}}
et : entities) {
if(!getSelf().remove(et))
return false;
}
return true;
{{else}}
if(!removeByIds(ids))
return false;
{{/if}}
this.baseMapper.deleteEntities(entities);
return true;
{{/if}}
}
{{#
entity
.
extActions
}}
...
...
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/impl/{{entities@ServiceAPI}}ServiceBase.java.hbs
浏览文件 @
7d1e1652
...
...
@@ -49,10 +49,6 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
@Service("
{{
entity
.
codeName
}}
Service")
public class
{{
entity
.
codeName
}}
ServiceBase implements
{{
entity
.
codeName
}}
Service {
protected
{{
entity
.
codeName
}}
Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{#
entity
.
relEntities
}}
{{#
neq
storage
"NONE"
}}
@Autowired
...
...
@@ -159,7 +155,7 @@ public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Servic
}
{{#
eq
entity
.
actions
.
remove
.
transactionMode
"GLOBAL"
}}
@GlobalTransactional
{{/
eq
}}{{#
eq
entity
.
actions
.
remove
.
transactionMode
"DEFAULT"
}}
@Transactional
{{/
eq
}}
public boolean removeB
atch(Collection
<
{{
entity
.
keyField
.
type
.
java
}}
>
id
s) {
public boolean removeB
yEntities(List
<
{{
entity
.
codeName
}}
>
entitie
s) {
return false;
}
...
...
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/{{entities@SQL}}Service.java.hbs
浏览文件 @
7d1e1652
...
...
@@ -18,6 +18,7 @@ import org.springframework.cache.annotation.CacheEvict;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.dynamic.datasource.annotation.DS;
import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.security.SpringContextHolder;
import
{{
packageName
}}
.core.
{{
entity
.
module
}}
.domain.
{{
entity
.
codeName
}}
;
import
{{
packageName
}}
.core.
{{
entity
.
module
}}
.filter.
{{
entity
.
codeName
}}
SearchContext;
...
...
@@ -26,11 +27,15 @@ import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchCo
{{/
dsName
}}
public interface
{{
entity
.
codeName
}}
Service extends IService
<
{{
entity
.
codeName
}}
>
{
default
{{
entity
.
codeName
}}
Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{
entity
.
codeName
}}
get(
{{
entity
.
codeName
}}
et);
default
{{
entity
.
codeName
}}
get(
{{
entity
.
keyField
.
type
.
java
}}
key) {
{{
entity
.
codeName
}}
et = new
{{
entity
.
codeName
}}
();
et.set
{{
pascalCase
entity
.
keyField
.
codeName
}}
(key);
return get(et);
return get
Self().get
(et);
}
default List
<
{{
entity
.
codeName
}}
>
getByIds(Collection
<
{{
entity
.
keyField
.
type
.
java
}}
>
ids) {
List
<
{{
entity
.
codeName
}}
>
entities =new ArrayList();
...
...
@@ -39,7 +44,7 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}
et.set
{{
pascalCase
entity
.
keyField
.
codeName
}}
(key);
entities.add(et);
});
return getByEntities(entities);
return get
Self().get
ByEntities(entities);
}
List
<
{{
entity
.
codeName
}}
>
getByEntities(List
<
{{
entity
.
codeName
}}
>
entities);
...
...
@@ -68,17 +73,24 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}
default boolean remove(
{{
entity
.
keyField
.
type
.
java
}}
key) {
{{
entity
.
codeName
}}
et = new
{{
entity
.
codeName
}}
();
et.set
{{
pascalCase
entity
.
keyField
.
codeName
}}
(key);
return remove(et);
return
getSelf().
remove(et);
}
default boolean remove(List
<
{{
entity
.
keyField
.
type
.
java
}}
>
key) {
return removeBatch(key);
}
boolean remove(
{{
entity
.
codeName
}}
et);
{{#
enableEntityCache
}}
@CacheEvict(value = "
{{
lowerCase
entity
.
codeName
}}
", allEntries = true)
{{/
enableEntityCache
}}
boolean removeBatch(Collection
<
{{
entity
.
keyField
.
type
.
java
}}
>
ids);
default boolean removeBatch(Collection
<
{{
entity
.
keyField
.
type
.
java
}}
>
ids) {
List
<
{{
entity
.
codeName
}}
>
entities =new ArrayList();
ids.forEach(key -> {
{{
entity
.
codeName
}}
et = new
{{
entity
.
codeName
}}
();
et.set
{{
pascalCase
entity
.
keyField
.
codeName
}}
(key);
entities.add(et);
});
return getSelf().removeByEntities(entities);
}
boolean removeByEntities(List
<
{{
entity
.
codeName
}}
>
entities);
{{#
each
entity
.
extActions
}}
default
{{
outParam
}}
{{
camelCase
codeName
}}
(
{{
inParam
}}
{{
inParamName
}}
) {
...
...
@@ -115,7 +127,7 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}
default boolean saveBy
{{
pascalCase
fkField
.
codeName
}}
(
{{
fkField
.
type
.
java
}}
{{
camelCase
fkField
.
codeName
}}
,List
<
{{
entity
.
codeName
}}
>
list) {
{{
packageName
}}
.core.
{{
module
}}
.domain.
{{
entityCodeName
}}
et = new
{{
packageName
}}
.core.
{{
module
}}
.domain.
{{
entityCodeName
}}
();
et.set
{{
pascalCase
relEntity
.
keyField
.
codeName
}}
(
{{
camelCase
fkField
.
codeName
}}
);
return saveBy
{{
pascalCase
fkField
.
codeName
}}
(et,list);
return
getSelf().
saveBy
{{
pascalCase
fkField
.
codeName
}}
(et,list);
}
{{/
entity
.
references
}}
...
...
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/{{entities@ServiceAPI}}Service.java.hbs
浏览文件 @
7d1e1652
...
...
@@ -18,6 +18,7 @@ import org.springframework.cache.annotation.CacheEvict;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.dynamic.datasource.annotation.DS;
import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.security.SpringContextHolder;
import
{{
packageName
}}
.core.
{{
entity
.
module
}}
.domain.
{{
entity
.
codeName
}}
;
import
{{
packageName
}}
.core.
{{
entity
.
module
}}
.filter.
{{
entity
.
codeName
}}
SearchContext;
...
...
@@ -26,6 +27,10 @@ import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchCo
{{/
dsName
}}
public interface
{{
entity
.
codeName
}}
Service {
default
{{
entity
.
codeName
}}
Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{
entity
.
codeName
}}
get(
{{
entity
.
codeName
}}
et);
default
{{
entity
.
codeName
}}
get(
{{
entity
.
keyField
.
type
.
java
}}
key) {
{{
entity
.
codeName
}}
et = new
{{
entity
.
codeName
}}
();
...
...
@@ -75,10 +80,17 @@ public interface {{entity.codeName}}Service {
}
boolean remove(
{{
entity
.
codeName
}}
et);
{{#
enableEntityCache
}}
@CacheEvict(value = "
{{
lowerCase
entity
.
codeName
}}
", allEntries = true)
{{/
enableEntityCache
}}
boolean removeBatch(Collection
<
{{
entity
.
keyField
.
type
.
java
}}
>
ids);
default boolean removeBatch(Collection
<
{{
entity
.
keyField
.
type
.
java
}}
>
ids) {
List
<
{{
entity
.
codeName
}}
>
entities =new ArrayList();
ids.forEach(key -> {
{{
entity
.
codeName
}}
et = new
{{
entity
.
codeName
}}
();
et.set
{{
pascalCase
entity
.
keyField
.
codeName
}}
(key);
entities.add(et);
});
return getSelf().removeByEntities(entities);
}
boolean removeByEntities(List
<
{{
entity
.
codeName
}}
>
entities);
{{#
each
entity
.
extActions
}}
default
{{
outParam
}}
{{
camelCase
codeName
}}
(
{{
inParam
}}
{{
inParamName
}}
) {
...
...
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/java/{{packageName}}/util/aspect/AuditAspect.java.hbs
浏览文件 @
7d1e1652
...
...
@@ -23,7 +23,7 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.
Map
;
import java.util.
*
;
/**
* 实体数据审计切面类
...
...
@@ -41,7 +41,7 @@ public class AuditAspect
* 实体数据建立切面,在成功创建数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置)
* @param point
*/
@AfterReturning(value = "execution(*
{{
packageName
}}
.core.*.service.*.create(..))
{{#
system
.
enableES
}}
&&
!execution(*
{{
packageName
}}
.core.es.service.*.create*(..))
{{/
system
.
enableES
}}
")
@AfterReturning(value = "execution(*
{{
packageName
}}
.core.*.service.*.create
*
(..))
{{#
system
.
enableES
}}
&&
!execution(*
{{
packageName
}}
.core.es.service.*.create*(..))
{{/
system
.
enableES
}}
")
@SneakyThrows
public void create(JoinPoint point) {
HttpServletRequest request = null;
...
...
@@ -60,6 +60,13 @@ public class AuditAspect
if(BeanCache.hasAudit(entity.getClass()))
dataAuditService.createAudit(request, entity, null);
}
else if(serviceParam instanceof List
&&
!ObjectUtils.isEmpty(serviceParam)) {
List list=(List
<
?
>
) serviceParam;
if(list.get(0) instanceof EntityBase
&&
BeanCache.hasAudit(list.get(0).getClass())) {
for(Object entity:list)
dataAuditService.createAudit(request, (EntityBase)entity, null);
}
}
}
/**
...
...
@@ -67,7 +74,7 @@ public class AuditAspect
* 使用环切【@Around】获取到更新前后的实体数据并进行差异比较,并将差异内容记入审计日志内
* @param point
*/
@Around("execution(*
{{
packageName
}}
.core.*.service.*.update(..))
{{#
system
.
enableES
}}
&&
!execution(*
{{
packageName
}}
.core.es.service.*.update*(..))
{{/
system
.
enableES
}}
")
@Around("execution(*
{{
packageName
}}
.core.*.service.*.update
*
(..))
{{#
system
.
enableES
}}
&&
!execution(*
{{
packageName
}}
.core.es.service.*.update*(..))
{{/
system
.
enableES
}}
")
public Object update(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
...
...
@@ -79,11 +86,9 @@ public class AuditAspect
if(ObjectUtils.isEmpty(args) || args.length==0) {
return point.proceed();
}
Object arg = args[0];
if(arg instanceof EntityBase) {
EntityBase entity = (EntityBase) arg;
Object serviceParam = args[0];
if(serviceParam instanceof EntityBase) {
EntityBase entity = (EntityBase) serviceParam;
if(BeanCache.hasAudit(entity.getClass()))
{
String idField = BeanCache.getKeyField(entity.getClass());
...
...
@@ -99,16 +104,72 @@ public class AuditAspect
//执行更新操作
point.proceed();
//记录审计日志
dataAuditService.updateAudit(request, beforeEntity , entity, null);
if(beforeEntity!=null)
dataAuditService.updateAudit(request, beforeEntity , entity, null);
return true;
}
else
}
else if(serviceParam instanceof List
&&
!ObjectUtils.isEmpty(serviceParam)) {
List list=(List
<
?
>
) serviceParam;
if(list.get(0) instanceof EntityBase
&&
BeanCache.hasAudit(list.get(0).getClass())) {
EntityBase first=(EntityBase)list.get(0);
String idField = BeanCache.getKeyField(first.getClass());
if(ObjectUtils.isEmpty(idField)) {
return point.proceed();
}
List
<EntityBase>
beforeList=getEntitys(serviceObj,list,first.getClass());
Map
<Object
,
EntityBase
>
beforeMap=new LinkedHashMap
<>
();
beforeList.forEach(before->{
beforeMap.put(before.get(idField),before);
});
point.proceed();
return true;
for(Object obj:list) {
EntityBase entity=(EntityBase)obj;
Object idValue=entity.get(idField);
EntityBase before=beforeMap.get(idValue);
if(before!=null)
dataAuditService.updateAudit(request, before, entity, idValue);
}
return true;
}
}
return point.proceed();
}
/**
* 实体数据更新切面,在成功更新数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置)
* 使用环切【@Around】获取要删除的完整数据,并将审计属性相关信息记录到审计日志中
* @param point
* @return
* @throws Throwable
*/
@AfterReturning(value = "execution(*
{{
packageName
}}
.core.*.service.*.remove*(..))
{{#
system
.
enableES
}}
&&
!execution(*
{{
packageName
}}
.core.es.service.*.remove*(..))
{{/
system
.
enableES
}}
")
@SneakyThrows
public void remove(JoinPoint point) {
HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if(requestAttributes!=null) {
request = ((ServletRequestAttributes)requestAttributes).getRequest();
}
Object [] args = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0) {
return;
}
Object serviceParam = args[0];
if(serviceParam instanceof EntityBase) {
EntityBase entity = (EntityBase)serviceParam;
//记录审计日志
if(BeanCache.hasAudit(entity.getClass()))
dataAuditService.removeAudit(request, entity, null);
}
else if(serviceParam instanceof List
&&
!ObjectUtils.isEmpty(serviceParam)) {
List list=(List
<
?
>
) serviceParam;
if(list.get(0) instanceof EntityBase
&&
BeanCache.hasAudit(list.get(0).getClass())) {
for(Object entity:list)
dataAuditService.removeAudit(request, (EntityBase)entity, null);
}
}
}
/**
* 获取实体
...
...
@@ -127,4 +188,16 @@ public class AuditAspect
}
return null;
}
@SneakyThrows
private
<T
extends
EntityBase
>
List
<T>
getEntitys(Object service, List
<T>
list, Class
<T>
clazz) {
if(!ObjectUtils.isEmpty(service)) {
EvaluationContext oldContext = new StandardEvaluationContext();
oldContext.setVariable("service", service);
oldContext.setVariable("list", list);
Expression oldExp = parser.parseExpression("#service.getByEntities(#list)");
return oldExp.getValue(oldContext, ArrayList.class);
}
return null;
}
}
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/java/{{packageName}}/{{apis}}/rest/{{apiEntities}}Resource.java.hbs
浏览文件 @
7d1e1652
...
...
@@ -9,7 +9,6 @@ import java.math.BigInteger;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.http.ResponseEntity;
...
...
@@ -57,17 +56,16 @@ public class {{apiEntity.codeName}}Resource {
{{#
each
apiEntity
.
methods
}}
{{#
neq
name
"Select"
}}
@ApiOperation(value = "
{{
apiName
}}
", tags = {"
{{
tags
}}
" }, notes = "
{{
notes
}}
")
{{#if
permission
}}
@
{{
permission
.
ano
}}
("
{{
permission
.
cond
}}
")
{{/if}}
{{#
eq
methodType
"DEACTION"
}}
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','
{{
projectName
}}
-
{{
apiEntity
.
entity
.
codeName
}}
-
{{
name
}}
-all')")
{{#
eq
name
"Update"
}}
{{#if
apiEntity
.
entity
.
lastModifyField
}}
@VersionCheck(entity = "
{{
lowerCase
apiEntity
.
entity
.
codeName
}}
" , versionfield = "
{{
camelCase
apiEntity
.
entity
.
lastModifyField
.
codeName
}}
")
{{/if}}
{{/
eq
}}
{{/
eq
}}
{{#
eq
methodType
"FETCH"
}}
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','
{{
projectName
}}
-
{{
apiEntity
.
entity
.
codeName
}}
-
{{
replace
name
"Fetch"
"search"
}}
-all')")
{{/
eq
}}
@RequestMapping(method = RequestMethod.
{{
requestMethod
}}
, value = "
{{
requestPath
}}
")
public ResponseEntity
<
{{
outParam
}}
>
{{
camelCase
name
}}{{#
each
pathVariables
}}{{#if
@first
}}
By
{{else}}
And
{{/if}}{{
pascalCase
name
}}{{/
each
}}
(
{{#
each
pathVariables
}}{{#
unless
@first
}}
,
{{/
unless
}}
@PathVariable("
{{
camelCase
name
}}
")
{{
type
.
java
}}
{{
camelCase
name
}}{{/
each
}}{{#if
body
}}{{#if
pathVariables
}}
,
{{/if}}{{#
neq
requestMethod
'GET'
}}
@Validated @RequestBody
{{/
neq
}}{{
body
}}{{/if}}
) {
...
...
@@ -90,12 +88,6 @@ public class {{apiEntity.codeName}}Resource {
{{/if}}
{{/if}}
{{#if
booleanReturn
}}
{{#
eq
name
"Remove"
}}
if(ObjectUtils.isEmpty(list)) {
list=new ArrayList
<>
();
list.add(
{{#
each
pathVariables
}}{{#if
@last
}}{{
camelCase
name
}}{{/if}}{{/
each
}}
);
}
{{/
eq
}}
{{
camelCase
apiEntity
.
entity
.
codeName
}}
Service.
{{
camelCase
name
}}
(
{{
inParamName2
}}
);
{{
outParam2
}}
rt =
{{
inParamName2
}}
;
{{else}}
...
...
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-core/src/main/resources/mapper/{{modules}}/{{entities}}/{{entities@SQL}}Mapper.xml.hbs
浏览文件 @
7d1e1652
...
...
@@ -101,6 +101,21 @@
in (
<foreach
collection=
"list"
item=
"item"
index=
"index"
separator=
","
>
(
{{#
each
entity
.
keyFields
as
|
field
|
}}{{#
unless
@first
}}
,
{{/
unless
}}
#{ item.
{{
camelCase
field
.
codeName
}}
}
{{/
each
}}
)
</foreach>
)
</select>
<delete
id=
"deleteEntities"
parameterType=
"java.util.List"
>
{{#if
entity
.
logicValid
}}
update
{{
entity
.
tableName
}}
set
{{#if
entity
.
logicValidField
.
type
.
number
}}
{{
entity
.
logicValidField
.
columnName
}}
=
{{
entity
.
inValidLogicValue
}}
{{else}}
{{
entity
.
logicValidField
.
columnName
}}
= '
{{
entity
.
inValidLogicValue
}}
'
{{/if}}
{{else}}
delete from
{{
entity
.
tableName
}}
{{/if}}
where (
{{#
each
entity
.
keyFields
as
|
field
|
}}{{#
unless
@first
}}
,
{{/
unless
}}{{
field
.
columnName
}}{{/
each
}}
)
in (
<foreach
collection=
"list"
item=
"item"
index=
"index"
separator=
","
>
(
{{#
each
entity
.
keyFields
as
|
field
|
}}{{#
unless
@first
}}
,
{{/
unless
}}
#{ item.
{{
camelCase
field
.
codeName
}}
}
{{/
each
}}
)
</foreach>
)
</delete>
{{#
each
entity
.
dataQueries
}}
<sql
id=
"
{{
camelCase
codeName
}}
"
databaseId=
"
{{
dsType
}}
"
>
<
![
CDATA
[
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录