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
f327ac0a
Commit
f327ac0a
authored
Dec 12, 2023
by
覃振观
👶
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
23-12-12: 下班前提交
parent
88ffcd84
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
34 deletions
+84
-34
productDetail.js
...un-xt/src/main/webapp/biz/topsun/product/productDetail.js
+27
-16
productDetail.jsp
...n-xt/src/main/webapp/biz/topsun/product/productDetail.jsp
+2
-2
ProductApplicationImpl.java
...psun/product/application/impl/ProductApplicationImpl.java
+46
-9
Snowflake.java
topsun/src/main/java/com/huigou/topsun/util/Snowflake.java
+4
-4
TestSnowflake.java
...n/src/main/java/com/huigou/topsun/util/TestSnowflake.java
+5
-3
No files found.
topsun-xt/src/main/webapp/biz/topsun/product/productDetail.js
View file @
f327ac0a
...
...
@@ -55,12 +55,12 @@ function faceGrid(elId, data) {
function
save
()
{
checkUpdata
();
debugger
;
let
upData
=
window
.
dataSet
.
upData
;
if
(
!
upData
)
{
return
;
}
Public
.
ajax
(
web_app
.
name
+
"/product/save
ProductAnd
Detail.ajax"
,
{
Public
.
ajax
(
web_app
.
name
+
"/product/save
OrUpdataOnAll
Detail.ajax"
,
{
data
:
JSON
.
stringify
(
upData
)
},
function
(
data
)
{
debugger
;
});
}
...
...
@@ -90,6 +90,7 @@ function loadDataTest() {
data
:
params
.
get
(
"data"
)
},
function
(
data
)
{
var
showData
=
mapping
(
dataMapping
,
data
.
rawData
);
debugger
;
$
(
'#submitForm'
).
formSet
(
showData
);
var
fronData
=
{};
fronData
.
Rows
=
data
.
fronColors
;
...
...
@@ -116,17 +117,25 @@ var dataMapping = {
"productLength"
,
"productWidth"
],
// ProductLoss: [
// "customerName"
// ],
ProductPublishedConf
:
[
"rowNum"
,
"modulus"
]
}
/**
* 遍历映射配置,构建映射关系
* @param dataMapping 映射配置
* @param rawData 源数据
* @param rawData 源数据
: 若有此输入,将认为当前是更新动作、 无此输入则认为当前是插入动作
*/
function
mapping
(
dataMapping
,
rawData
)
{
window
.
dataSet
=
{};
if
(
!
rawData
)
{
window
.
dataSet
.
isInsert
=
true
;
var
rawData
=
{};
}
else
{
window
.
dataSet
.
isInsert
=
false
;
}
let
mapper
=
{};
delete
dataMapping
.
Mapper
;
let
entitySet
=
Object
.
entries
(
dataMapping
);
...
...
@@ -134,6 +143,7 @@ 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
)
=>
{
...
...
@@ -141,9 +151,6 @@ function mapping(dataMapping, rawData) {
if
(
!
isExist
(
entityData
,
item
,
beanName
))
{
throw
{};
}
let
value
=
entityData
[
item
];
mapper
[
item
]
=
beanName
;
if
(
item
===
"factoryName"
)
{
console
.
log
(
'1'
)
}
returnData
[
item
]
=
value
;
console
.
log
(
item
);
return
;
...
...
@@ -168,7 +175,6 @@ function mapping(dataMapping, rawData) {
// 这里写死 映射对象为:‘dataMapping’
window
.
dataMapping
=
dataMapping
;
// 这里写死 数据集:‘dataSet: { rawData: {}, newData: {} }’
window
.
dataSet
=
{};
window
.
dataSet
.
rawData
=
rawData
;
window
.
dataSet
.
newData
=
JSON
.
parse
(
JSON
.
stringify
(
dataSet
.
rawData
));
return
returnData
;
...
...
@@ -184,15 +190,20 @@ Array.prototype.tryForEach = function (callback, thisArg) {
* 检测数据中是否存在对应属性
* @param obj 需要检测数据
* @param property 需要检测的属性
* @param objName 检测的
类
名
* @param objName 检测的
对象
名
* @returns {boolean}
*/
function
isExist
(
obj
,
property
,
objName
)
{
if
(
!
objName
)
{
objName
=
'rawData'
;
}
// 这里注意,后端返回的类名是否与映射配置一致
if
(
!
obj
[
property
])
{
console
.
error
(
'No data for name of '
+
property
+
' in '
+
objName
+
' !'
);
return
false
;
if
(
window
.
dataSet
.
isInsert
)
{
obj
[
property
]
=
{};
return
true
;
}
else
{
if
(
!
objName
)
{
objName
=
'rawData'
;
}
// 这里注意,后端返回的类名是否与映射配置一致
if
(
!
obj
[
property
])
{
console
.
error
(
'No data for name of '
+
property
+
' in '
+
objName
+
' !'
);
return
false
;
}
}
return
true
;
}
...
...
topsun-xt/src/main/webapp/biz/topsun/product/productDetail.jsp
View file @
f327ac0a
...
...
@@ -40,13 +40,13 @@
<div
class=
"ui-tab-content"
style=
"padding: 2px; padding-right: 0;"
>
<div
class=
"layout"
id=
'detailFormDiv'
>
<x:inputC
name=
"factoryName"
required=
"true"
label=
"制造工厂"
labelCol=
"2"
maxLength=
"64"
fieldCol=
"4"
/>
<x:inputC
name=
"customerName"
required=
"true"
label=
"客户名称"
labelCol=
"2"
maxLength=
"64"
fieldCol=
"4"
/
>
<%-- <x:inputC name="customerName" required="true" label="客户名称" labelCol="2" maxLength="64" fieldCol="4" />--%
>
<x:title
title=
"外观描述"
name=
"group"
hideTable=
"#info"
/>
<x:inputC
name=
"productLength"
required=
"true"
label=
"长度"
labelCol=
"2"
maxLength=
"64"
fieldCol=
"4"
/>
<x:inputC
name=
"productWidth"
required=
"true"
label=
"宽度"
labelCol=
"2"
maxLength=
"64"
fieldCol=
"4"
/>
<x:title
title=
"排版参数"
name=
"group"
hideTable=
"#info"
/>
<x:inputC
name=
"modulus"
required=
"true"
label=
"模数"
labelCol=
"2"
maxLength=
"64"
fieldCol=
"4"
/>
<x:inputC
name=
"row
_n
um"
required=
"true"
label=
"行数"
labelCol=
"2"
maxLength=
"64"
fieldCol=
"4"
/>
<x:inputC
name=
"row
N
um"
required=
"true"
label=
"行数"
labelCol=
"2"
maxLength=
"64"
fieldCol=
"4"
/>
<div
id=
"layout"
style=
"height: 280px; display: contents;"
>
<div
position=
"left"
title=
"正面颜色"
>
...
...
topsun/src/main/java/com/huigou/topsun/product/application/impl/ProductApplicationImpl.java
View file @
f327ac0a
...
...
@@ -2,6 +2,7 @@ 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,6 +11,9 @@ import lombok.RequiredArgsConstructor;
import
org.apache.commons.beanutils.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityTransaction
;
import
javax.transaction.Transaction
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
...
...
@@ -17,25 +21,29 @@ import java.util.*;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
// @RequiredArgsConstructor 通过构造方法注入 ProductApplication(Class a) { this.a = a; }
/**
* @author 16508
* @description 针对表【product(产品)】的数据库操作Service实现
* @
@
createDate 2023-11-22 10:24:31
* @createDate 2023-11-22 10:24:31
*/
@Service
@RequiredArgsConstructor
//通过构造方法注入 ProductApplication(Class a) { this.a = a; }
@RequiredArgsConstructor
public
class
ProductApplicationImpl
implements
ProductApplication
{
private
final
ObjectMapper
objectMapper
;
private
final
Snowflake
snowflake
;
private
final
ProductRepository
productRepository
;
private
final
ProductDetailRepository
detailRepository
;
// 类型
private
final
BrandRepository
brandRepository
;
private
final
FactoryRepository
factoryRepository
;
private
final
ColorRepository
colorRepository
;
private
final
ProductCategoryRepository
categoryRepository
;
// 详细信息
private
final
ProductTypesetConfRepository
typesetConfRepository
;
private
final
ProductLookedRepository
lookedRepository
;
private
final
ProductPublishedConfRepository
publishedConfRepository
;
...
...
@@ -69,10 +77,6 @@ public class ProductApplicationImpl implements ProductApplication {
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>(
200
);
Long
productId
=
product
.
getProductId
();
ProductDetail
productDetail
=
detailRepository
.
findByProductId
(
productId
);
// EntityManager manager = JPAUtils.getEntityManger();
// manager.getTransaction().begin();
// manager.flush();
// manager.close();
// --------------------------------- 类别查询 ---------------------------------
ArrayList
<
Brand
>
brands
=
(
ArrayList
<
Brand
>)
brandRepository
.
findAll
();
...
...
@@ -138,8 +142,41 @@ public class ProductApplicationImpl implements ProductApplication {
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
);
if
(
product
!=
null
)
{
product
.
getProductId
();
EntityTransaction
transaction
=
null
;
EntityManager
manager
=
JPAUtils
.
getEntityManger
();
try
{
transaction
=
manager
.
getTransaction
();
transaction
.
begin
();
if
(
product
!=
null
)
{
Long
id
=
product
.
getProductId
();
if
(
id
==
null
)
{
product
.
setProductId
(
Snowflake
.
nextId
());
manager
.
persist
(
product
);
}
}
if
(
productDetail
!=
null
)
{
Long
id
=
productDetail
.
getProductDetailId
();
if
(
id
==
null
)
{
productDetail
.
setProductDetailId
(
Snowflake
.
nextId
());
manager
.
persist
(
productDetail
);
}
}
if
(
productLooked
!=
null
)
{
Long
id
=
productLooked
.
getProductLookedId
();
if
(
id
==
null
)
{
productLooked
.
setProductLookedId
(
Snowflake
.
nextId
());
manager
.
persist
(
productLooked
);
}
}
manager
.
flush
();
}
catch
(
Exception
e
)
{
assert
transaction
!=
null
;
transaction
.
rollback
();
throw
new
RuntimeException
(
e
);
}
finally
{
manager
.
close
();
}
return
null
;
...
...
topsun/src/main/java/com/huigou/topsun/util/Snowflake.java
View file @
f327ac0a
...
...
@@ -12,7 +12,7 @@ public class Snowflake {
// 开始时间
private
static
final
long
OFFSET
=
1686211627000L
;
private
static
long
WORKER_ID
;
private
static
long
WORKER_ID
=
1L
;
/** 机器ID位 **/
private
static
final
long
WORKER_ID_BITS
=
4L
;
...
...
@@ -28,9 +28,9 @@ public class Snowflake {
private
static
long
lastTimestamp
=
0L
;
private
static
long
sequence
=
0L
;
public
Snowflake
(
long
workerId
)
{
WORKER_ID
=
workerId
;
}
//
public Snowflake(long workerId) {
//
WORKER_ID = workerId;
//
}
public
static
synchronized
long
nextId
()
{
long
timestamp
=
timeGen
();
...
...
topsun/src/main/java/com/huigou/topsun/util/TestSnowflake.java
View file @
f327ac0a
...
...
@@ -18,7 +18,7 @@ public class TestSnowflake {
generateTest
();
new
Snowflake
(
1
);
//
new Snowflake(1);
final
Long
id
=
Snowflake
.
nextId
();
Date
date
=
new
Date
();
date
.
setTime
(
(
id
>>
18
)
+
1686211627000L
);
...
...
@@ -55,11 +55,12 @@ public class TestSnowflake {
public
class
TreadA
extends
Thread
{
@Override
public
void
run
()
{
super
.
run
();
//long timestamp = timeGen();
for
(
int
i
=
0
;
i
<
30000
;
i
++)
{
new
Snowflake
(
1
);
//
new Snowflake(1);
long
id
=
Snowflake
.
nextId
();
list
.
add
(
id
);
}
...
...
@@ -69,10 +70,11 @@ public class TestSnowflake {
public
class
TreadB
extends
Thread
{
@Override
public
void
run
()
{
super
.
run
();
for
(
int
i
=
0
;
i
<
30000
;
i
++)
{
new
Snowflake
(
1
);
//
new Snowflake(1);
long
id
=
Snowflake
.
nextId
();
list
.
add
(
id
);
}
...
...
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