Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
topsun-bpm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
鲁鑫
topsun-bpm
Commits
0ba4686a
Commit
0ba4686a
authored
Dec 30, 2023
by
覃振观
👶
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码位置调整
parent
05fa5b26
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
424 additions
and
333 deletions
+424
-333
listeningFromData.js
...xt/src/main/webapp/biz/topsun/common/listeningFromData.js
+85
-58
productDetail.js
...un-xt/src/main/webapp/biz/topsun/product/productDetail.js
+2
-3
ProductApplicationImpl.java
...psun/product/application/impl/ProductApplicationImpl.java
+10
-272
EntityConvertUtil.java
...c/main/java/com/huigou/topsun/util/EntityConvertUtil.java
+202
-0
PersistTool.java
topsun/src/main/java/com/huigou/topsun/util/PersistTool.java
+120
-0
TestSnowflake.java
...n/src/main/java/com/huigou/topsun/util/TestSnowflake.java
+5
-0
No files found.
topsun-xt/src/main/webapp/biz/topsun/common/listeningFromData.js
View file @
0ba4686a
This diff is collapsed.
Click to expand it.
topsun-xt/src/main/webapp/biz/topsun/product/productDetail.js
View file @
0ba4686a
...
...
@@ -223,9 +223,8 @@ function faceGrid(elId, data) {
});
var
gridManager
=
listeningGrid
(
elId
,
{
columns
:
[
{
display
:
"颜色名称"
,
name
:
"colorName"
,
width
:
140
,
minWidth
:
60
,
type
:
"string"
,
align
:
"left"
,
editor
:
{
type
:
'select'
,
fillProperty
:
'colorId'
}},
{
display
:
"颜色名称"
,
name
:
"colorName"
,
width
:
140
,
minWidth
:
60
,
type
:
"string"
,
align
:
"left"
,
editor
:
{
type
:
'select'
,
fillProperty
:
'colorId'
}
},
{
display
:
"油墨覆盖率(%)"
,
name
:
"coverageRate"
,
width
:
120
,
minWidth
:
60
,
type
:
"string"
,
align
:
"left"
,
editor
:
{
type
:
'text'
}
}
],
toolbar
:
toolbarOptions
,
...
...
topsun/src/main/java/com/huigou/topsun/product/application/impl/ProductApplicationImpl.java
View file @
0ba4686a
This diff is collapsed.
Click to expand it.
topsun/src/main/java/com/huigou/topsun/util/EntityConvertUtil.java
0 → 100644
View file @
0ba4686a
package
com
.
huigou
.
topsun
.
util
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.apache.commons.beanutils.BeanUtils
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* EntityConvertUtil 数据类型转换工具
*
* @author qinzhenguan
* @createDate 2023/12/30 10:56
**/
public
class
EntityConvertUtil
{
private
static
final
ObjectMapper
OBJECT_MAPPER
=
new
ObjectMapper
();
/**
* description 返回页面 Form 所需的数据格式
* @param entitys 所有相关的 实体。 必须为 JavaBean 调用了 .getClass().getSimpleName()
* @return java.util.HashMap<java.lang.String, java.lang.Object>
* @author qinzhenguan
* @createDate 2023/12/5 14:09
*/
public
static
Map
<
String
,
Object
>
assembleResultOfForm
(
Set
<
Object
>
entitys
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
256
);
for
(
Object
item
:
entitys
)
{
if
(
item
==
null
)
{
continue
;
}
if
(
item
instanceof
List
)
{
if
(((
List
<?>)
item
).
size
()
>
0
)
{
map
.
put
((((
List
<?>)
item
).
get
(
0
)).
getClass
().
getSimpleName
(),
OBJECT_MAPPER
.
convertValue
(
item
,
List
.
class
));
}
}
else
{
map
.
put
(
item
.
getClass
().
getSimpleName
(),
OBJECT_MAPPER
.
convertValue
(
item
,
new
TypeReference
<
Map
<?
extends
String
,
?>>()
{})
);
}
// 这里要获取所有的属性名, 保存对应关系, 属性: 所属实体类;
//map.putAll(mapper.convertValue(item, new TypeReference<Map<? extends String, ?>>() {}));
}
return
map
;
}
/**
* description
* @param clazz Bean
* @param displayProperty 需要显示的属性
* @param valueProperty 连接的属性
* @param list 需要转换的 List
* @return java.util.Map<java.lang.Object, java.lang.Object>
* @author qinzhenguan
* @createDate 2023/12/1 16:09
*/
public
static
Map
<
Object
,
Object
>
convertToMap
(
Class
<?>
clazz
,
String
displayProperty
,
String
valueProperty
,
List
<?>
list
)
{
Set
<
String
>
set
=
new
HashSet
<>();
set
.
add
(
displayProperty
);
set
.
add
(
valueProperty
);
if
(
checkClassesAndProperties
(
clazz
,
set
,
list
.
size
()))
{
LinkedList
<
Map
<
String
,
Object
>>
mapList
=
OBJECT_MAPPER
.
convertValue
(
list
,
new
TypeReference
<
LinkedList
<
Map
<
String
,
Object
>>>()
{});
return
mapList
.
stream
().
collect
(
Collectors
.
toMap
(
map
->
map
.
get
(
displayProperty
),
map
->
map
.
get
(
valueProperty
),
(
oldV
,
newV
)
->
oldV
));
}
return
null
;
}
/**
* description 只检查传入属性是否合法
* @param clazz Bean
* @param set 需要检查的 Propertys
* @param listSize 需要检查的 ListSize
* @return java.lang.Boolean true of false
* @author qinzhenguan
* @createDate 2023/12/1 15:58
*/
public
static
Boolean
checkClassesAndProperties
(
Class
<?>
clazz
,
Set
<
String
>
set
,
int
listSize
)
{
if
(
listSize
==
0
)
{
System
.
err
.
println
(
"[checkClassesAndProperties] : List< "
+
clazz
.
getName
()+
" > 需要转换的列表没有元素。请检查~!"
);
return
false
;
}
Field
[]
fields
=
clazz
.
getDeclaredFields
();
Method
[]
methods
=
clazz
.
getDeclaredMethods
();
for
(
String
item
:
set
)
{
Field
field
=
Arrays
.
stream
(
fields
).
filter
(
f
->
item
.
equals
(
f
.
getName
())).
findFirst
().
orElse
(
null
);
if
(
field
==
null
)
{
System
.
err
.
println
(
"[checkClassesAndProperties] : "
+
clazz
.
getName
()
+
" 无法找到 : "
+
item
+
" "
+
"该属性。请检查~!"
);
return
false
;
}
Method
method
=
Arrays
.
stream
(
methods
)
.
filter
(
m
->
m
.
getName
().
toLowerCase
().
contains
(
"get"
+
item
.
toLowerCase
())).
findFirst
().
orElse
(
null
);
if
(
method
==
null
)
{
System
.
err
.
println
(
"[checkClassesAndProperties] : "
+
item
+
" 该属性无法找到构造方法。请检查~!"
);
return
false
;
}
}
return
true
;
}
/**
* description 转换成 Map 不需要转换为实体
* @param clazz Bean
* @param propertyName 连接的 property
* @param list 需要转换的 List
* @return java.util.Map<java.lang.Object, java.lang.Object>
* @author qinzhenguan
* @createDate 2023/11/29 11:36
*/
public
static
Map
<
Object
,
Object
>
convertToMap
(
Class
<?>
clazz
,
String
propertyName
,
List
<?>
list
)
{
return
convertToMap
(
clazz
,
propertyName
,
list
,
false
);
}
/**
* description 转换成 Map 保留映射
* @param clazz Bean
* @param propertyName 连接的 property
* @param list 需要转换的 List
* @param isBean 是否需要转换为实体 (当前应用不需要返回实体)
* @return java.util.Map<java.lang.Object, java.lang.Object>
* @author qinzhenguan
* @createDate 2023/11/29 11:34
*/
public
static
Map
<
Object
,
Object
>
convertToMap
(
Class
<?>
clazz
,
String
propertyName
,
List
<?>
list
,
boolean
isBean
)
{
Map
<
String
,
Object
>
checkMap
=
checkClassesAndProperties
(
clazz
,
propertyName
,
list
.
size
());
String
ok
=
"isOk"
;
if
(!(
Boolean
)
checkMap
.
get
(
ok
))
{
return
null
;
}
Method
method
=
(
Method
)
checkMap
.
get
(
"method"
);
LinkedList
<
Map
<
String
,
Object
>>
mapList
=
OBJECT_MAPPER
.
convertValue
(
list
,
new
TypeReference
<
LinkedList
<
Map
<
String
,
Object
>>>()
{});
Map
<
Object
,
Object
>
resultMap
=
new
HashMap
<>(
10
);
Map
<
Object
,
Object
>
convert
=
new
HashMap
<>(
1024
);
if
(
isBean
)
{
// --------------------------------- 实体 ---------------------------------
try
{
for
(
int
i
=
0
;
i
<
mapList
.
size
();
i
++)
{
Object
o
=
clazz
.
newInstance
();
BeanUtils
.
populate
(
o
,
mapList
.
get
(
i
));
Object
key
=
method
.
invoke
(
o
);
convert
.
put
(
key
,
o
);
}
}
catch
(
InstantiationException
|
IllegalAccessException
|
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
else
{
// --------------------------------- 非实体 ---------------------------------
convert
=
mapList
.
stream
().
collect
(
Collectors
.
toMap
(
map
->
map
.
get
(
propertyName
),
Function
.
identity
(),
(
oldV
,
newV
)
->
oldV
));
//此处仍需处理 Key == null;
}
resultMap
.
put
(
"map"
,
convert
);
resultMap
.
put
(
"list"
,
list
);
return
resultMap
;
}
/**
* description 检查传入参数是否合法 并返回构造方法
*
* @param clazz javaBean
* @param propertyName property
* @return java.util.HashMap<java.lang.String, java.lang.Object> { "isOk" : 是否通过检查, "method":获取得到的 method }
* @author qinzhenguan
* @createDate 2023/11/29 11:05
*/
public
static
HashMap
<
String
,
Object
>
checkClassesAndProperties
(
Class
<?>
clazz
,
String
propertyName
,
int
listSize
)
{
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>(
33
);
if
(
listSize
==
0
)
{
System
.
err
.
println
(
"[checkClassesAndProperties] : List< "
+
clazz
.
getName
()+
" > 需要转换的列表没有元素。请检查~!"
);
map
.
put
(
"isOk"
,
false
);
return
map
;
}
Field
[]
fields
=
clazz
.
getDeclaredFields
();
Field
field
=
Arrays
.
stream
(
fields
).
filter
(
f
->
propertyName
.
equals
(
f
.
getName
())).
findFirst
().
orElse
(
null
);
if
(
field
==
null
)
{
System
.
err
.
println
(
"[checkClassesAndProperties] : "
+
clazz
.
getName
()
+
" 无法找到 : "
+
propertyName
+
" "
+
"该属性。请检查~!"
);
map
.
put
(
"isOk"
,
false
);
return
map
;
}
Method
[]
methods
=
clazz
.
getDeclaredMethods
();
Method
method
=
Arrays
.
stream
(
methods
)
.
filter
(
m
->
m
.
getName
().
toLowerCase
().
contains
(
"get"
+
propertyName
.
toLowerCase
())).
findFirst
().
orElse
(
null
);
if
(
method
==
null
)
{
System
.
err
.
println
(
"[checkClassesAndProperties] : "
+
propertyName
+
" 该属性无法找到构造方法。请检查~!"
);
map
.
put
(
"isOk"
,
false
);
return
map
;
}
map
.
put
(
"isOk"
,
true
);
map
.
put
(
"method"
,
method
);
return
map
;
}
}
\ No newline at end of file
topsun/src/main/java/com/huigou/topsun/util/PersistTool.java
0 → 100644
View file @
0ba4686a
package
com
.
huigou
.
topsun
.
util
;
import
org.springframework.stereotype.Component
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
java.lang.reflect.Field
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* PersistUtil 持久化工具
*
* @author qinzhenguan
* @createDate 2023/12/30 10:49
**/
@Component
public
class
PersistTool
{
@PersistenceContext
(
unitName
=
"system"
)
private
EntityManager
entityManager
;
/**
* description 持久化数据. <br>
* Entity 时,如果 ID 为空执行 Persist,否则执行 Merge <br>
* List 时,要求数据集格式 : <br>
* HashMap {”add“: List< Entity >,”up“: List< Entity >,”del“: List< Entity >}
* @param entitys 持久化数据集合 Set { Entity, HashMap }
* @author qinzhenguan
* @createDate 2023/12/26 16:44
*/
public
void
persistEntitys
(
Set
<
Object
>
entitys
)
{
entitys
=
entitys
.
stream
().
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toSet
());
for
(
Object
item
:
entitys
)
{
if
(
item
instanceof
Map
)
{
persistList
(
uncheckedCast
(((
Map
<?,
?>)
item
).
get
(
"add"
)),
"save"
);
persistList
(
uncheckedCast
(((
Map
<?,
?>)
item
).
get
(
"up"
)),
"save"
);
persistList
(
uncheckedCast
(((
Map
<?,
?>)
item
).
get
(
"del"
)),
"remove"
);
}
else
{
persistEntity
(
item
);
}
entityManager
.
flush
();
entityManager
.
clear
();
}
}
/***
* description 持久化 List
* @param list 操作的 List
* @param type 操作类似 save, remove
* @author qinzhenguan
* @createDate 2023/12/26 16:33
*/
public
void
persistList
(
List
<
Class
<?>>
list
,
String
type
)
{
if
(
list
==
null
||
list
.
isEmpty
())
{
return
;
}
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
if
(
"remove"
.
equals
(
type
))
{
removeEntity
(
list
.
get
(
i
));
}
else
{
persistEntity
(
list
.
get
(
i
));
}
if
(
i
%
80
==
0
||
i
==
(
list
.
size
()
-
1
))
{
entityManager
.
flush
();
entityManager
.
clear
();
}
}
}
/***
* description 持久化实体 (无 ID 时执行插入,有 ID 时执行更新)
* @param entity 操作的 Entity
* @author qinzhenguan
* @createDate 2023/12/26 16:32
*/
public
void
persistEntity
(
Object
entity
)
{
Class
<?>
clazz
=
entity
.
getClass
();
for
(
Field
field
:
clazz
.
getDeclaredFields
())
{
if
(
"id"
.
equals
(
field
.
getName
()))
{
try
{
field
.
setAccessible
(
true
);
BigDecimal
id
=
(
BigDecimal
)
field
.
get
(
entity
);
if
(
id
==
null
){
field
.
set
(
entity
,
String
.
valueOf
(
Snowflake
.
nextId
()));
entityManager
.
persist
(
entity
);
}
else
{
entityManager
.
merge
(
entity
);
}
}
catch
(
IllegalAccessException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
/***
* description 移除实体
* @param entity 操作的 Entity
* @author qinzhenguan
* @createDate 2023/12/26 16:31
*/
public
void
removeEntity
(
Object
entity
)
{
if
(
entity
==
null
)
{
return
;
}
entityManager
.
remove
(
entity
);
}
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
uncheckedCast
(
Object
obj
)
{
if
(
obj
!=
null
)
{
return
(
T
)
obj
;
}
return
null
;
}
}
\ No newline at end of file
topsun/src/main/java/com/huigou/topsun/util/TestSnowflake.java
View file @
0ba4686a
...
...
@@ -28,6 +28,11 @@ public class TestSnowflake {
}
/**
* description 测试当前生成策略极限。
* @author qinzhenguan
* @createDate 2023/12/30 10:42
*/
public
void
generateTest
()
throws
InterruptedException
{
TreadA
t1
=
new
TreadA
();
...
...
Write
Preview
Markdown
is supported
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