Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
iBiz商业中心
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz商业套件
iBiz商业中心
提交
ed9528c0
提交
ed9528c0
编写于
11月 02, 2020
作者:
misaka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
946a1b13
变更
3
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
307 行增加
和
0 行删除
+307
-0
DynaPropertyAspect.java
.../businesscentral/core/util/aspect/DynaPropertyAspect.java
+271
-0
EBSServiceImpl.java
...zlab/businesscentral/core/util/helper/EBSServiceImpl.java
+16
-0
DynaProperty.java
...ibizlab/businesscentral/util/annotation/DynaProperty.java
+20
-0
未找到文件。
businesscentral-core/src/main/java/cn/ibizlab/businesscentral/core/util/aspect/DynaPropertyAspect.java
0 → 100644
浏览文件 @
ed9528c0
package
cn
.
ibizlab
.
businesscentral
.
core
.
util
.
aspect
;
import
cn.ibizlab.businesscentral.core.odoo_base.domain.Res_supplier
;
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.Audit
;
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.CachedBeanCopier
;
import
cn.ibizlab.businesscentral.util.helper.CaseFormatMethod
;
import
cn.ibizlab.businesscentral.util.helper.DEFieldCacheMap
;
import
cn.ibizlab.businesscentral.util.security.SpringContextHolder
;
import
cn.ibizlab.businesscentral.util.service.IBZDataAuditService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
lombok.SneakyThrows
;
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
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.lang.reflect.Field
;
import
java.sql.Timestamp
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* 动态属性切面
*/
@Aspect
@Component
@EnableAspectJAutoProxy
(
exposeProxy
=
true
,
proxyTargetClass
=
true
)
public
class
DynaPropertyAspect
{
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
@Autowired
IIr_propertyService
ir_propertyService
;
@Autowired
IIr_model_fieldsService
ir_model_fieldsService
;
@AfterReturning
(
value
=
"execution(* cn.ibizlab.businesscentral.core.*.service.*.*.get(..)) && args(id)"
,
returning
=
"entity"
)
public
void
get
(
Long
id
,
EntityMP
entity
)
{
Map
<
String
,
DynaProperty
>
dynaPropertyFields
=
DEFieldCacheMap
.
getDynaPropertyFields
(
entity
.
getClass
());
for
(
Map
.
Entry
<
String
,
DynaProperty
>
entry
:
dynaPropertyFields
.
entrySet
())
{
Field
field
=
DEFieldCacheMap
.
getField
(
entity
.
getClass
(),
entry
.
getKey
());
String
fieldProperty
=
CaseFormatMethod
.
exec
(
field
.
getName
(),
"lC2l_u"
);
DynaProperty
dynaProperty
=
entry
.
getValue
();
Ir_propertySearchContext
ctx
=
new
Ir_propertySearchContext
();
ctx
.
setN_name_eq
(
fieldProperty
);
ctx
.
setN_res_id_eq
(
String
.
format
(
"%s,%s"
,
dynaProperty
.
res_model
(),
id
));
List
<
Ir_property
>
ir_properties
=
ir_propertyService
.
searchDefault
(
ctx
).
getContent
();
if
(
ir_properties
.
size
()
==
0
)
continue
;
Ir_property
property
=
ir_properties
.
get
(
0
);
if
(
property
.
getType
().
equals
(
"many2one"
))
{
Long
refId
=
NumberUtils
.
parseNumber
((
property
.
getValueReference
().
split
(
","
))[
1
],
Long
.
class
);
entity
.
set
(
fieldProperty
,
refId
);
if
(!
StringUtils
.
isEmpty
(
dynaProperty
.
pickup_text
()))
{
EntityMP
refEntity
=
getEntity
(
SpringContextHolder
.
getBean
(
dynaProperty
.
reference
()),
refId
);
entity
.
set
(
dynaProperty
.
pickup_text
(),
refEntity
.
get
(
dynaProperty
.
reference_field
()));
}
}
else
if
(
property
.
getType
().
equals
(
"float"
)
||
property
.
getType
().
equals
(
"monetary"
))
{
entity
.
set
(
fieldProperty
,
property
.
getValueFloat
());
}
else
if
(
property
.
getType
().
equals
(
"integer"
))
{
entity
.
set
(
fieldProperty
,
property
.
getValueInteger
());
}
else
if
(
property
.
getType
().
equals
(
"date"
)
||
property
.
getType
().
equals
(
"datetime"
))
{
entity
.
set
(
fieldProperty
,
property
.
getValueDatetime
());
}
else
{
entity
.
set
(
fieldProperty
,
property
.
getValueText
());
}
}
}
@Around
(
value
=
"execution(* cn.ibizlab.businesscentral.core.*.service.*.*.create(..)) "
)
public
Object
create
(
ProceedingJoinPoint
point
)
throws
Throwable
{
Object
[]
args
=
point
.
getArgs
();
if
(
ObjectUtils
.
isEmpty
(
args
)
||
args
.
length
==
0
)
return
point
.
proceed
();
Object
arg
=
args
[
0
];
if
(
arg
instanceof
EntityBase
)
{
EntityBase
entity
=
(
EntityBase
)
arg
;
Map
<
String
,
DynaProperty
>
dynaPropertyFields
=
DEFieldCacheMap
.
getDynaPropertyFields
(
entity
.
getClass
());
if
(
dynaPropertyFields
.
size
()
==
0
)
return
point
.
proceed
();
Map
<
String
,
Object
>
keyMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
String
,
DynaProperty
>
entry
:
dynaPropertyFields
.
entrySet
())
{
Field
field
=
DEFieldCacheMap
.
getField
(
entity
.
getClass
(),
entry
.
getKey
());
String
fieldProperty
=
CaseFormatMethod
.
exec
(
field
.
getName
(),
"lC2l_u"
);
if
(!
StringUtils
.
isEmpty
(
entity
.
get
(
fieldProperty
)))
{
keyMap
.
put
(
fieldProperty
,
entity
.
get
(
fieldProperty
));
}
}
point
.
proceed
();
for
(
Map
.
Entry
<
String
,
DynaProperty
>
entry
:
dynaPropertyFields
.
entrySet
())
{
Field
field
=
DEFieldCacheMap
.
getField
(
entity
.
getClass
(),
entry
.
getKey
());
DynaProperty
dynaProperty
=
entry
.
getValue
();
String
fieldProperty
=
CaseFormatMethod
.
exec
(
field
.
getName
(),
"lC2l_u"
);
if
(
keyMap
.
containsKey
(
fieldProperty
))
{
Ir_model_fields
ir_model_fields
=
ir_model_fieldsService
.
getOne
(
new
QueryWrapper
<
Ir_model_fields
>().
eq
(
"name"
,
fieldProperty
).
eq
(
"model"
,
dynaProperty
.
res_model
()));
if
(
ir_model_fields
==
null
)
continue
;
Ir_property
property
=
new
Ir_property
();
property
.
setName
(
fieldProperty
);
property
.
setType
(
ir_model_fields
.
getTtype
());
property
.
setFieldsId
(
ir_model_fields
.
getId
());
property
.
setResId
(
String
.
format
(
"%s,%s"
,
dynaProperty
.
res_model
(),
entity
.
get
(
"id"
)));
if
(
ir_model_fields
.
getTtype
().
equals
(
"many2one"
))
{
Long
refId
=
NumberUtils
.
parseNumber
(
keyMap
.
get
(
fieldProperty
).
toString
(),
Long
.
class
);
entity
.
set
(
fieldProperty
,
refId
);
EBSServiceImpl
refServiceImpl
=
(
EBSServiceImpl
)
SpringContextHolder
.
getBean
(
dynaProperty
.
reference
());
if
(!
StringUtils
.
isEmpty
(
dynaProperty
.
pickup_text
()))
{
EntityMP
refEntity
=
getEntity
(
refServiceImpl
,
refId
);
entity
.
set
(
dynaProperty
.
pickup_text
(),
refEntity
.
get
(
dynaProperty
.
reference_field
()));
}
property
.
setValueReference
(
String
.
format
(
"%s,%s"
,
refServiceImpl
.
getIrModel
(),
entity
.
get
(
fieldProperty
)));
}
else
if
(
ir_model_fields
.
getTtype
().
equals
(
"float"
)
||
ir_model_fields
.
getTtype
().
equals
(
"monetary"
))
{
property
.
setValueFloat
((
Double
)
keyMap
.
get
(
fieldProperty
));
}
else
if
(
ir_model_fields
.
getTtype
().
equals
(
"integer"
))
{
property
.
setValueInteger
((
Integer
)
keyMap
.
get
(
fieldProperty
));
}
else
if
(
ir_model_fields
.
getTtype
().
equals
(
"date"
)
||
ir_model_fields
.
getTtype
().
equals
(
"datetime"
))
{
property
.
setValueDatetime
((
Timestamp
)
keyMap
.
get
(
fieldProperty
));
}
else
{
property
.
setValueText
(
keyMap
.
get
(
fieldProperty
).
toString
());
}
ir_propertyService
.
create
(
property
);
}
}
}
return
point
.
proceed
();
}
@Before
(
"execution(* cn.ibizlab.businesscentral.core.*.service.*.*.update(..)) && args(entity,..)"
)
public
void
update
(
EntityMP
entity
)
throws
Throwable
{
Map
<
String
,
DynaProperty
>
dynaPropertyFields
=
DEFieldCacheMap
.
getDynaPropertyFields
(
entity
.
getClass
());
if
(
dynaPropertyFields
.
size
()
==
0
)
return
;
for
(
Map
.
Entry
<
String
,
DynaProperty
>
entry
:
dynaPropertyFields
.
entrySet
())
{
Field
field
=
DEFieldCacheMap
.
getField
(
entity
.
getClass
(),
entry
.
getKey
());
DynaProperty
dynaProperty
=
entry
.
getValue
();
String
fieldProperty
=
CaseFormatMethod
.
exec
(
field
.
getName
(),
"lC2l_u"
);
if
(
entity
.
getFocusNull
().
contains
(
fieldProperty
))
{
ir_propertyService
.
getBaseMapper
().
delete
(
new
QueryWrapper
<
Ir_property
>().
eq
(
"name"
,
fieldProperty
).
eq
(
"res_id"
,
String
.
format
(
"%s,%s"
,
dynaProperty
.
res_model
(),
entity
.
get
(
"id"
))));
entity
.
getFocusNull
().
remove
(
fieldProperty
);
}
else
{
if
(
StringUtils
.
isEmpty
(
entity
.
get
(
fieldProperty
))){
continue
;
}
Ir_propertySearchContext
ctx
=
new
Ir_propertySearchContext
();
ctx
.
setN_name_eq
(
fieldProperty
);
ctx
.
setN_res_id_eq
(
String
.
format
(
"%s,%s"
,
dynaProperty
.
res_model
(),
entity
.
get
(
"id"
)));
List
<
Ir_property
>
ir_properties
=
ir_propertyService
.
searchDefault
(
ctx
).
getContent
();
if
(
ir_properties
.
size
()
==
0
){
Ir_model_fields
ir_model_fields
=
ir_model_fieldsService
.
getOne
(
new
QueryWrapper
<
Ir_model_fields
>().
eq
(
"name"
,
fieldProperty
).
eq
(
"model"
,
dynaProperty
.
res_model
()));
if
(
ir_model_fields
==
null
)
continue
;
Ir_property
property
=
new
Ir_property
();
property
.
setName
(
fieldProperty
);
property
.
setType
(
ir_model_fields
.
getTtype
());
property
.
setFieldsId
(
ir_model_fields
.
getId
());
property
.
setResId
(
String
.
format
(
"%s,%s"
,
dynaProperty
.
res_model
(),
entity
.
get
(
"id"
)));
if
(
ir_model_fields
.
getTtype
().
equals
(
"many2one"
))
{
Long
refId
=
NumberUtils
.
parseNumber
(
entity
.
get
(
fieldProperty
).
toString
(),
Long
.
class
);
entity
.
set
(
fieldProperty
,
refId
);
EBSServiceImpl
refServiceImpl
=
(
EBSServiceImpl
)
SpringContextHolder
.
getBean
(
dynaProperty
.
reference
());
if
(!
StringUtils
.
isEmpty
(
dynaProperty
.
pickup_text
()))
{
EntityMP
refEntity
=
getEntity
(
refServiceImpl
,
refId
);
entity
.
set
(
dynaProperty
.
pickup_text
(),
refEntity
.
get
(
dynaProperty
.
reference_field
()));
}
property
.
setValueReference
(
String
.
format
(
"%s,%s"
,
refServiceImpl
.
getIrModel
(),
entity
.
get
(
fieldProperty
)));
}
else
if
(
ir_model_fields
.
getTtype
().
equals
(
"float"
)
||
ir_model_fields
.
getTtype
().
equals
(
"monetary"
))
{
property
.
setValueFloat
((
Double
)
entity
.
get
(
fieldProperty
));
}
else
if
(
ir_model_fields
.
getTtype
().
equals
(
"integer"
))
{
property
.
setValueInteger
((
Integer
)
entity
.
get
(
fieldProperty
));
}
else
if
(
ir_model_fields
.
getTtype
().
equals
(
"date"
)
||
ir_model_fields
.
getTtype
().
equals
(
"datetime"
))
{
property
.
setValueDatetime
((
Timestamp
)
entity
.
get
(
fieldProperty
));
}
else
{
property
.
setValueText
(
entity
.
get
(
fieldProperty
).
toString
());
}
ir_propertyService
.
create
(
property
);
return
;
}
Ir_property
property
=
ir_properties
.
get
(
0
);
if
(
property
.
getType
().
equals
(
"many2one"
))
{
Long
refId
=
NumberUtils
.
parseNumber
(
entity
.
get
(
fieldProperty
).
toString
(),
Long
.
class
);
String
oldValue
=
property
.
getValueReference
();
property
.
setValueReference
(
String
.
format
(
"%s,%s"
,
oldValue
.
substring
(
0
,
oldValue
.
indexOf
(
","
)),
entity
.
get
(
fieldProperty
)));
}
else
if
(
property
.
getType
().
equals
(
"float"
)
||
property
.
getType
().
equals
(
"monetary"
))
{
property
.
setValueFloat
((
Double
)
entity
.
get
(
fieldProperty
));
}
else
if
(
property
.
getType
().
equals
(
"integer"
))
{
property
.
setValueInteger
((
Integer
)
entity
.
get
(
fieldProperty
));
}
else
if
(
property
.
getType
().
equals
(
"date"
)
||
property
.
getType
().
equals
(
"datetime"
))
{
property
.
setValueDatetime
((
Timestamp
)
entity
.
get
(
fieldProperty
));
}
else
{
property
.
setValueText
(
entity
.
get
(
fieldProperty
).
toString
());
}
ir_propertyService
.
update
(
property
);
}
}
return
;
}
@AfterReturning
(
"execution(* cn.ibizlab.businesscentral.core.*.*.service.*.remove(..))"
)
public
void
remove
(
JoinPoint
point
)
throws
Throwable
{
EBSServiceImpl
serviceImpl
=
(
EBSServiceImpl
)
point
.
getTarget
();
EntityMP
entity
=
this
.
getEntity
(
serviceImpl
,
point
.
getArgs
()[
0
]);
Map
<
String
,
DynaProperty
>
dynaPropertyFields
=
DEFieldCacheMap
.
getDynaPropertyFields
(
entity
.
getClass
());
if
(
dynaPropertyFields
.
size
()
==
0
)
return
;
for
(
Map
.
Entry
<
String
,
DynaProperty
>
entry
:
dynaPropertyFields
.
entrySet
())
{
Field
field
=
DEFieldCacheMap
.
getField
(
entity
.
getClass
(),
entry
.
getKey
());
DynaProperty
dynaProperty
=
entry
.
getValue
();
String
fieldProperty
=
CaseFormatMethod
.
exec
(
field
.
getName
(),
"lC2l_u"
);
ir_propertyService
.
getBaseMapper
().
delete
(
new
QueryWrapper
<
Ir_property
>().
eq
(
"name"
,
fieldProperty
).
eq
(
"res_id"
,
String
.
format
(
"%s,%s"
,
dynaProperty
.
res_model
(),
point
.
getArgs
()[
0
])));
}
return
;
}
private
EntityMP
getEntity
(
Object
service
,
Object
id
)
{
EntityMP
entity
=
null
;
if
(!
ObjectUtils
.
isEmpty
(
service
))
{
EvaluationContext
oldContext
=
new
StandardEvaluationContext
();
oldContext
.
setVariable
(
"service"
,
service
);
oldContext
.
setVariable
(
"id"
,
id
);
Expression
oldExp
=
parser
.
parseExpression
(
"#service.get(#id)"
);
return
oldExp
.
getValue
(
oldContext
,
EntityMP
.
class
);
}
return
entity
;
}
}
\ No newline at end of file
businesscentral-core/src/main/java/cn/ibizlab/businesscentral/core/util/helper/EBSServiceImpl.java
浏览文件 @
ed9528c0
...
@@ -8,6 +8,12 @@ import org.javers.core.diff.Diff;
...
@@ -8,6 +8,12 @@ import org.javers.core.diff.Diff;
public
class
EBSServiceImpl
<
M
extends
BaseMapper
<
T
>,
T
extends
EntityMP
>
extends
ServiceImpl
<
M
,
T
>
{
public
class
EBSServiceImpl
<
M
extends
BaseMapper
<
T
>,
T
extends
EntityMP
>
extends
ServiceImpl
<
M
,
T
>
{
/**
* 获取消息子类型
* @param et
* @param diff
* @return
*/
public
Mail_message_subtype
getMessageSubType
(
T
et
,
Diff
diff
){
public
Mail_message_subtype
getMessageSubType
(
T
et
,
Diff
diff
){
Mail_message_subtype
message_subtype
=
new
Mail_message_subtype
();
Mail_message_subtype
message_subtype
=
new
Mail_message_subtype
();
message_subtype
.
setId
(
2
l
);
message_subtype
.
setId
(
2
l
);
...
@@ -18,4 +24,14 @@ public class EBSServiceImpl<M extends BaseMapper<T>, T extends EntityMP> extends
...
@@ -18,4 +24,14 @@ public class EBSServiceImpl<M extends BaseMapper<T>, T extends EntityMP> extends
return
""
;
return
""
;
}
}
/**
* 获取实体实例
* @param clazz
* @return
* @throws Exception
*/
public
T
getInstance
(
Class
<
T
>
clazz
)
throws
Exception
{
return
clazz
.
newInstance
();
}
}
}
businesscentral-util/src/main/java/cn/ibizlab/businesscentral/util/annotation/DynaProperty.java
0 → 100644
浏览文件 @
ed9528c0
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
DynaProperty
{
String
res_model
()
default
""
;
Class
reference
()
;
String
reference_field
()
;
String
pickup_text
()
;
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录