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
836fb0f9
Commit
836fb0f9
authored
Dec 13, 2023
by
覃振观
👶
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
23-12-13: 下班前提交
parent
f327ac0a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
83 deletions
+69
-83
productDetail.js
...un-xt/src/main/webapp/biz/topsun/product/productDetail.js
+18
-5
AppConfig.java
topsun/src/main/java/com/huigou/topsun/config/AppConfig.java
+0
-2
JPAUtils.java
topsun/src/main/java/com/huigou/topsun/config/JPAUtils.java
+0
-27
ProductApplicationImpl.java
...psun/product/application/impl/ProductApplicationImpl.java
+51
-49
No files found.
topsun-xt/src/main/webapp/biz/topsun/product/productDetail.js
View file @
836fb0f9
...
...
@@ -27,6 +27,9 @@ function initializeUI() {
function
faceGrid
(
elId
,
data
)
{
var
toolbarOptions
=
UICtrl
.
getDefaultToolbarOptions
({
addHandler
:
function
(){
UICtrl
.
addGridRow
(
gridManager
);
},
updateHandler
:
function
(){
updateHandler
();
},
...
...
@@ -38,17 +41,22 @@ function faceGrid(elId, data) {
});
var
gridManager
=
UICtrl
.
grid
(
elId
,
{
columns
:
[
{
display
:
"颜色名称"
,
name
:
"productFaceColorId"
,
width
:
140
,
minWidth
:
60
,
type
:
"string"
,
align
:
"left"
},
{
display
:
"油墨覆盖率(%)"
,
name
:
"coverageRate"
,
width
:
120
,
minWidth
:
60
,
type
:
"string"
,
align
:
"left"
}
{
display
:
"颜色名称"
,
name
:
"productFaceColorId"
,
width
:
140
,
minWidth
:
60
,
type
:
"string"
,
align
:
"left"
,
editor
:
{
type
:
'text'
,
required
:
true
}},
{
display
:
"油墨覆盖率(%)"
,
name
:
"coverageRate"
,
width
:
120
,
minWidth
:
60
,
type
:
"string"
,
align
:
"left"
,
editor
:
{
type
:
'text'
,
required
:
true
}
}
],
toolbar
:
toolbarOptions
,
dataType
:
"local"
,
data
:
data
,
// data 数据结构 data: ("Rows": [ {}, {} ])
enabledEdit
:
true
,
checkbox
:
true
,
usePager
:
false
,
width
:
"100%"
,
height
:
150
,
onDblClickRow
:
function
(
data
,
rowindex
,
rowobj
)
{
updateHandler
(
data
);
}
});
}
...
...
@@ -93,7 +101,7 @@ function loadDataTest() {
debugger
;
$
(
'#submitForm'
).
formSet
(
showData
);
var
fronData
=
{};
fronData
.
Rows
=
data
.
fronColors
;
fronData
.
Rows
=
data
.
rawData
.
fronColors
;
faceGrid
(
"#frontFaceGrid"
,
fronData
);
fronData
.
Rows
=
data
.
backColors
;
faceGrid
(
"#backFaceGrid"
,
fronData
);
...
...
@@ -120,6 +128,9 @@ var dataMapping = {
ProductPublishedConf
:
[
"rowNum"
,
"modulus"
],
fronColors
:
[
[
"productFaceColorId"
,
"coverageRate"
]
]
}
...
...
@@ -143,7 +154,6 @@ function mapping(dataMapping, rawData) {
entitySet
.
tryForEach
((
entity
,
index
)
=>
{
let
beanName
=
entity
[
0
];
if
(
!
isExist
(
rawData
,
beanName
))
{
throw
{};
}
debugger
;
let
entityData
=
rawData
[
beanName
];
let
propertyNames
=
entity
[
1
];
propertyNames
.
tryForEach
((
item
,
index
)
=>
{
...
...
@@ -154,6 +164,9 @@ function mapping(dataMapping, rawData) {
returnData
[
item
]
=
value
;
console
.
log
(
item
);
return
;
}
else
if
(
item
instanceof
Array
)
{
debugger
;
return
;
}
else
if
(
item
instanceof
Object
)
{
let
entry
=
Object
.
entries
(
item
)[
0
];
let
property
=
entry
[
0
];
...
...
topsun/src/main/java/com/huigou/topsun/config/AppConfig.java
View file @
836fb0f9
...
...
@@ -19,6 +19,4 @@ public class AppConfig {
return
new
ObjectMapper
();
}
@Bean
public
Snowflake
snowflake
()
{
return
new
Snowflake
(
1
);
}
}
\ No newline at end of file
topsun/src/main/java/com/huigou/topsun/config/JPAUtils.java
deleted
100644 → 0
View file @
f327ac0a
package
com
.
huigou
.
topsun
.
config
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManagerFactory
;
import
javax.persistence.Persistence
;
/**
* JPAUtils 用于管理 JPA EntityManager 创建工厂
*
* @author qinzhenguan
* @createDate 2023/11/28 08:58
**/
public
class
JPAUtils
{
public
static
EntityManagerFactory
emf
=
createEntityManagerFactory
();
private
static
EntityManagerFactory
createEntityManagerFactory
()
{
EntityManagerFactory
emf
=
Persistence
.
createEntityManagerFactory
(
"mysql-jpa"
);
return
emf
;
}
public
static
EntityManager
getEntityManger
(){
EntityManager
entityManager
=
emf
.
createEntityManager
();
return
entityManager
;
}
}
\ No newline at end of file
topsun/src/main/java/com/huigou/topsun/product/application/impl/ProductApplicationImpl.java
View file @
836fb0f9
...
...
@@ -2,7 +2,6 @@ package com.huigou.topsun.product.application.impl;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.huigou.topsun.config.JPAUtils
;
import
com.huigou.topsun.product.application.ProductApplication
;
import
com.huigou.topsun.product.domain.*
;
import
com.huigou.topsun.product.repository.*
;
...
...
@@ -10,10 +9,9 @@ import com.huigou.topsun.util.Snowflake;
import
lombok.RequiredArgsConstructor
;
import
org.apache.commons.beanutils.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityTransaction
;
import
javax.transaction.Transaction
;
import
javax.persistence.*
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
...
...
@@ -31,6 +29,10 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public
class
ProductApplicationImpl
implements
ProductApplication
{
@PersistenceContext
(
unitName
=
"system"
)
private
EntityManager
entityManager
;
// private final EntityManagerFactory entityManagerFactory;
private
final
ObjectMapper
objectMapper
;
private
final
ProductRepository
productRepository
;
private
final
ProductDetailRepository
detailRepository
;
...
...
@@ -94,11 +96,11 @@ public class ProductApplicationImpl implements ProductApplication {
entitys
.
add
(
publishedConfRepository
.
findByProductId
(
productId
));
entitys
.
add
(
productDetail
);
entitys
.
add
(
product
);
entitys
.
add
(
loss
);
entitys
.
add
(
material
);
HashMap
<
String
,
Object
>
listMaps
=
new
HashMap
<>(
100
);
resultMap
.
put
(
"rawData"
,
assembleResultOfForm
(
entitys
));
listMaps
.
put
(
"loss"
,
loss
);
listMaps
.
put
(
"material"
,
material
);
Map
<
String
,
Object
>
assemble
=
assembleResultOfForm
(
entitys
);
resultMap
.
put
(
"rawData"
,
assemble
);
// --------------------------------- 版面查询 ---------------------------------
if
(
productDetail
!=
null
)
{
...
...
@@ -106,24 +108,25 @@ public class ProductApplicationImpl implements ProductApplication {
ProductFace
frontFace
=
faceRepository
.
findByProductFaceIdEquals
(
productDetail
.
getBackProductFaceId
());
ArrayList
<
ProductFaceColor
>
fronColors
=
(
ArrayList
<
ProductFaceColor
>)
faceColorRepository
.
findByProductFaceId
(
productDetail
.
getBackProductFaceId
());
resultMap
.
put
(
"frontFace"
,
frontFace
);
listMaps
.
put
(
"fronColors"
,
fronColors
==
null
?
new
ArrayList
<>()
:
fronColors
);
assemble
.
put
(
"frontFace"
,
frontFace
);
assemble
.
put
(
"fronColors"
,
fronColors
==
null
?
new
ArrayList
<>()
:
fronColors
);
}
else
{
ProductFaceColor
fc
=
new
ProductFaceColor
();
fc
.
setProductFaceColorId
(
111L
);
ArrayList
<
ProductFaceColor
>
fronColors
=
new
ArrayList
<>();
fronColors
.
add
(
fc
);
listMaps
.
put
(
"fronColors"
,
fronColors
);
assemble
.
put
(
"fronColors"
,
fronColors
);
}
if
(
productDetail
.
getBackProductFaceId
()
!=
null
)
{
ProductFace
backFace
=
faceRepository
.
findByProductFaceIdEquals
(
productDetail
.
getBackProductFaceId
());
ArrayList
<
ProductFaceColor
>
backColors
=
(
ArrayList
<
ProductFaceColor
>)
faceColorRepository
.
findByProductFaceId
(
productDetail
.
getBackProductFaceId
());
resultMap
.
put
(
"backFace"
,
backFace
);
listMaps
.
put
(
"backColors"
,
backColors
==
null
?
new
ArrayList
<>()
:
backColors
);
assemble
.
put
(
"backFace"
,
backFace
);
assemble
.
put
(
"backColors"
,
backColors
==
null
?
new
ArrayList
<>()
:
backColors
);
}
}
HashMap
<
String
,
Object
>
listMaps
=
new
HashMap
<>(
100
);
listMaps
.
put
(
"selectedBrand"
,
objectMapper
.
convertValue
(
brands
,
List
.
class
));
listMaps
.
put
(
"selectedFactory"
,
objectMapper
.
convertValue
(
factorys
,
List
.
class
));
listMaps
.
put
(
"selectedColor"
,
objectMapper
.
convertValue
(
colors
,
List
.
class
));
...
...
@@ -138,66 +141,65 @@ public class ProductApplicationImpl implements ProductApplication {
}
@Override
@Transactional
(
transactionManager
=
"transactionManager"
)
public
HashMap
<
String
,
Object
>
saveOrUpdataOnAllDetail
(
HashMap
<
String
,
Object
>
newData
)
{
Product
product
=
objectMapper
.
convertValue
(
newData
.
get
(
"Product"
),
Product
.
class
);
ProductDetail
productDetail
=
objectMapper
.
convertValue
(
newData
.
get
(
"ProductDetail"
),
ProductDetail
.
class
);
ProductLooked
productLooked
=
objectMapper
.
convertValue
(
newData
.
get
(
"ProductLooked"
),
ProductLooked
.
class
);
EntityTransaction
transaction
=
null
;
EntityManager
manager
=
JPAUtils
.
getEntityManger
();
try
{
transaction
=
manager
.
getTransaction
();
transaction
.
begin
();
TypedQuery
<
Product
>
query
=
entityManager
.
createQuery
(
"SELECT s FROM Product s"
,
Product
.
class
);
List
<
Product
>
products
=
query
.
getResultList
();
if
(
product
!=
null
)
{
Long
id
=
product
.
getProductId
();
if
(
id
==
null
)
{
product
.
setProductId
(
Snowflake
.
nextId
());
manager
.
persist
(
product
);
}
if
(
product
!=
null
)
{
Long
id
=
product
.
getProductId
();
if
(
id
==
null
)
{
product
.
setProductId
(
Snowflake
.
nextId
());
entityManager
.
persist
(
product
);
}
if
(
productDetail
!=
null
)
{
Long
id
=
productDetail
.
getProductDetailId
();
if
(
id
==
null
)
{
productDetail
.
setProductDetailId
(
Snowflake
.
nextId
());
manager
.
persist
(
productDetail
);
}
entityManager
.
merge
(
product
);
}
if
(
productDetail
!=
null
)
{
Long
id
=
productDetail
.
getProductDetailId
();
if
(
id
==
null
)
{
productDetail
.
setProductDetailId
(
Snowflake
.
nextId
());
entityManager
.
persist
(
productDetail
);
}
if
(
productLooked
!=
null
)
{
Long
id
=
productLooked
.
getProductLookedId
();
if
(
id
==
null
)
{
productLooked
.
setProductLookedId
(
Snowflake
.
nextId
());
manager
.
persist
(
productLooked
);
}
entityManager
.
merge
(
productDetail
);
}
if
(
productLooked
!=
null
)
{
Long
id
=
productLooked
.
getProductLookedId
();
if
(
id
==
null
)
{
productLooked
.
setProductLookedId
(
Snowflake
.
nextId
());
entityManager
.
persist
(
productLooked
);
}
manager
.
flush
();
}
catch
(
Exception
e
)
{
assert
transaction
!=
null
;
transaction
.
rollback
();
throw
new
RuntimeException
(
e
);
}
finally
{
manager
.
close
();
entityManager
.
merge
(
productLooked
);
}
// String str = null;
// str.length();
entityManager
.
flush
();
return
null
;
}
/**
* description 返回页面 Form 所需的数据格式
* @param entitys 所有相关的 实体
(如果需要 update,保留这些实体。提交时候用于比较更新值。
)
* @param entitys 所有相关的 实体
。 必须为 JavaBean 调用了 .getClass().getSimpleName(
)
* @return java.util.HashMap<java.lang.String, java.lang.Object>
* @author qinzhenguan
* @createDate 2023/12/5 14:09
*/
public
Map
<
String
,
Object
>
assembleResultOfForm
(
Set
<
Object
>
entitys
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
1024
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
256
);
for
(
Object
item
:
entitys
)
{
if
(
item
==
null
)
{
continue
;
}
map
.
put
(
item
.
getClass
().
getSimpleName
(),
objectMapper
.
convertValue
(
item
,
new
TypeReference
<
Map
<?
extends
String
,
?>>()
{})
);
if
(
item
instanceof
List
)
{
map
.
put
((((
List
<?>)
item
).
get
(
0
)).
getClass
().
getSimpleName
(),
objectMapper
.
convertValue
(
item
,
List
.
class
));
}
else
{
map
.
put
(
item
.
getClass
().
getSimpleName
(),
objectMapper
.
convertValue
(
item
,
new
TypeReference
<
Map
<?
extends
String
,
?>>()
{})
);
}
// 这里要获取所有的属性名, 保存对应关系, 属性: 所属实体类;
//map.putAll(mapper.convertValue(item, new TypeReference<Map<? extends String, ?>>() {}));
...
...
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