Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
iBiz商业中心
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz商业套件
iBiz商业中心
提交
c8f8e7b4
提交
c8f8e7b4
编写于
11月 03, 2020
作者:
misaka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
外键信息回填
上级
dc3b2d84
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
147 行增加
和
0 行删除
+147
-0
BackFillPropertyAspect.java
...inesscentral/core/util/aspect/BackFillPropertyAspect.java
+125
-0
BackFillProperty.java
...lab/businesscentral/util/annotation/BackFillProperty.java
+22
-0
未找到文件。
businesscentral-core/src/main/java/cn/ibizlab/businesscentral/core/util/aspect/BackFillPropertyAspect.java
0 → 100644
浏览文件 @
c8f8e7b4
package
cn
.
ibizlab
.
businesscentral
.
core
.
util
.
aspect
;
import
cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_model_fields
;
import
cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_property
;
import
cn.ibizlab.businesscentral.core.odoo_ir.filter.Ir_propertySearchContext
;
import
cn.ibizlab.businesscentral.core.odoo_ir.service.IIr_model_fieldsService
;
import
cn.ibizlab.businesscentral.core.odoo_ir.service.IIr_propertyService
;
import
cn.ibizlab.businesscentral.core.util.helper.EBSServiceImpl
;
import
cn.ibizlab.businesscentral.util.annotation.BackFillProperty
;
import
cn.ibizlab.businesscentral.util.annotation.DynaProperty
;
import
cn.ibizlab.businesscentral.util.domain.EntityBase
;
import
cn.ibizlab.businesscentral.util.domain.EntityMP
;
import
cn.ibizlab.businesscentral.util.helper.CaseFormatMethod
;
import
cn.ibizlab.businesscentral.util.helper.DEFieldCacheMap
;
import
cn.ibizlab.businesscentral.util.security.SpringContextHolder
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ExpressionParser
;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.NumberUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.sql.Timestamp
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 回填属性切面
*/
@Aspect
@Component
@EnableAspectJAutoProxy
(
exposeProxy
=
true
,
proxyTargetClass
=
true
)
public
class
BackFillPropertyAspect
{
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
@Before
(
value
=
"execution(* cn.ibizlab.businesscentral.core.*.service.*.*.create(..)) && args(entity,..) "
)
public
void
create
(
EntityMP
entity
)
throws
Throwable
{
Map
<
String
,
Object
>
refEntityMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
refEntityServiceMap
=
new
HashMap
<>();
Map
<
String
,
BackFillProperty
>
backFillPropertyFields
=
DEFieldCacheMap
.
getBackFillropertyFields
(
entity
.
getClass
());
if
(
backFillPropertyFields
.
size
()
==
0
)
return
;
for
(
Map
.
Entry
<
String
,
BackFillProperty
>
entry
:
backFillPropertyFields
.
entrySet
())
{
Field
field
=
DEFieldCacheMap
.
getField
(
entity
.
getClass
(),
entry
.
getKey
());
BackFillProperty
backFillProperty
=
entry
.
getValue
();
String
fieldProperty
=
CaseFormatMethod
.
exec
(
field
.
getName
(),
"lC2l_u"
);
if
(
entity
.
get
(
backFillProperty
.
referenceName
())
==
null
)
continue
;
Object
refEntity
=
null
;
if
(!
refEntityMap
.
containsKey
(
backFillProperty
.
referenceKey
()))
{
refEntity
=
backFillProperty
.
reference
().
newInstance
();
setRefEntityValue
(
refEntity
,
backFillProperty
.
referenceKey
(),
entity
.
get
(
backFillProperty
.
referenceName
()));
refEntityMap
.
put
(
backFillProperty
.
referenceKey
(),
refEntity
);
refEntityServiceMap
.
put
(
backFillProperty
.
referenceKey
(),
SpringContextHolder
.
getBean
(
backFillProperty
.
referenceService
()));
}
refEntity
=
refEntityMap
.
get
(
backFillProperty
.
referenceKey
());
if
(
entity
.
getFocusNull
().
contains
(
fieldProperty
)
||
entity
.
get
(
fieldProperty
)
!=
null
)
setRefEntityValue
(
refEntity
,
backFillProperty
.
backFillName
(),
entity
.
get
(
fieldProperty
));
}
//refEntity 更新处理
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
refEntityMap
.
entrySet
())
{
updateRefEntity
(
refEntityServiceMap
.
get
(
entry
.
getKey
()),
entry
.
getValue
());
}
return
;
}
@Before
(
"execution(* cn.ibizlab.businesscentral.core.*.service.*.*.update(..)) && args(entity,..)"
)
public
void
update
(
EntityMP
entity
)
throws
Throwable
{
Map
<
String
,
Object
>
refEntityMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
refEntityServiceMap
=
new
HashMap
<>();
Map
<
String
,
BackFillProperty
>
backFillPropertyFields
=
DEFieldCacheMap
.
getBackFillropertyFields
(
entity
.
getClass
());
if
(
backFillPropertyFields
.
size
()
==
0
)
return
;
for
(
Map
.
Entry
<
String
,
BackFillProperty
>
entry
:
backFillPropertyFields
.
entrySet
())
{
Field
field
=
DEFieldCacheMap
.
getField
(
entity
.
getClass
(),
entry
.
getKey
());
BackFillProperty
backFillProperty
=
entry
.
getValue
();
String
fieldProperty
=
CaseFormatMethod
.
exec
(
field
.
getName
(),
"lC2l_u"
);
if
(
entity
.
get
(
backFillProperty
.
referenceName
())
==
null
)
continue
;
Object
refEntity
=
null
;
if
(!
refEntityMap
.
containsKey
(
backFillProperty
.
referenceKey
()))
{
refEntity
=
backFillProperty
.
reference
().
newInstance
();
setRefEntityValue
(
refEntity
,
backFillProperty
.
referenceKey
(),
entity
.
get
(
backFillProperty
.
referenceName
()));
refEntityMap
.
put
(
backFillProperty
.
referenceKey
(),
refEntity
);
refEntityServiceMap
.
put
(
backFillProperty
.
referenceKey
(),
SpringContextHolder
.
getBean
(
backFillProperty
.
referenceService
()));
}
refEntity
=
refEntityMap
.
get
(
backFillProperty
.
referenceKey
());
if
(
entity
.
getFocusNull
().
contains
(
fieldProperty
)
||
entity
.
get
(
fieldProperty
)
!=
null
)
setRefEntityValue
(
refEntity
,
backFillProperty
.
backFillName
(),
entity
.
get
(
fieldProperty
));
}
//refEntity 更新处理
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
refEntityMap
.
entrySet
())
{
updateRefEntity
(
refEntityServiceMap
.
get
(
entry
.
getKey
()),
entry
.
getValue
());
}
return
;
}
private
void
setRefEntityValue
(
Object
refEntity
,
String
property
,
Object
value
)
throws
Exception
{
refEntity
.
getClass
().
getMethod
(
"set"
,
String
.
class
,
Object
.
class
).
invoke
(
refEntity
,
property
,
value
);
}
private
void
updateRefEntity
(
Object
refEntityService
,
Object
refEntity
)
throws
Exception
{
refEntityService
.
getClass
().
getMethod
(
"update"
,
refEntity
.
getClass
()).
invoke
(
refEntityService
,
refEntity
);
}
}
\ No newline at end of file
businesscentral-util/src/main/java/cn/ibizlab/businesscentral/util/annotation/BackFillProperty.java
0 → 100644
浏览文件 @
c8f8e7b4
package
cn
.
ibizlab
.
businesscentral
.
util
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
FIELD
})
public
@interface
BackFillProperty
{
Class
reference
()
;
Class
referenceService
()
;
String
referenceKey
();
String
referenceName
()
default
""
;
String
backFillName
()
default
""
;
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录