Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
klck
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
位宇华
klck
Commits
e054929f
Commit
e054929f
authored
Apr 16, 2024
by
lzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
循环清洗
parent
eb2f3726
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
105 additions
and
39 deletions
+105
-39
ruoyi-supplies/pom.xml
ruoyi-supplies/pom.xml
+4
-0
ruoyi-supplies/src/main/java/com/ruoyi/system/config/ThreadPoolConfiguration.java
...java/com/ruoyi/system/config/ThreadPoolConfiguration.java
+1
-1
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/ActReadDataServiceImpl.java
...com/ruoyi/system/service/impl/ActReadDataServiceImpl.java
+33
-34
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/Conversion/LkSpecialMethod.java
...ruoyi/system/service/impl/Conversion/LkSpecialMethod.java
+2
-0
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/Conversion/MineConver.java
.../com/ruoyi/system/service/impl/Conversion/MineConver.java
+63
-4
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/Conversion/OtherMethod.java
...com/ruoyi/system/service/impl/Conversion/OtherMethod.java
+2
-0
No files found.
ruoyi-supplies/pom.xml
View file @
e054929f
...
...
@@ -71,5 +71,9 @@
<artifactId>
spring-data-commons
</artifactId>
<version>
2.7.18
</version>
</dependency>
<dependency>
<groupId>
jakarta.validation
</groupId>
<artifactId>
jakarta.validation-api
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
ruoyi-supplies/src/main/java/com/ruoyi/system/config/ThreadPoolConfiguration.java
View file @
e054929f
...
...
@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
public
class
ThreadPoolConfiguration
{
@Bean
(
name
=
"defaultThreadPoolExecutor"
,
destroyMethod
=
"shutdown"
)
public
ThreadPoolExecutor
systemCheckPoolExecutorService
()
{
return
new
ThreadPoolExecutor
(
5
,
20
,
60
,
TimeUnit
.
SECONDS
,
return
new
ThreadPoolExecutor
(
2
,
5
,
60
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<
Runnable
>(
10000
));
}
}
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/ActReadDataServiceImpl.java
View file @
e054929f
package
com.ruoyi.system.service.impl
;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.system.domain.ActHistoryRoleTypeCodeModel
;
import
com.ruoyi.system.domain.ActReadHistoryModel
;
import
com.ruoyi.system.mapper.ActReadDataMapper
;
import
com.ruoyi.system.service.ActReadDataService
;
import
com.ruoyi.system.service.impl.Conversion.LkSpecialMethod
;
import
com.ruoyi.system.service.impl.Conversion.MineConver
;
import
com.ruoyi.system.service.impl.Conversion.OtherMetho
d
;
import
org.springframework.beans.factory.annotation.Autowire
d
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.Future
;
import
java.util.regex.Pattern
;
/**
...
...
@@ -20,6 +15,9 @@ import java.util.regex.Pattern;
*/
@Service
public
class
ActReadDataServiceImpl
implements
ActReadDataService
{
@Autowired
private
MineConver
mineConver
;
private
static
ActReadDataMapper
actReadDataMapper
;
public
ActReadDataServiceImpl
(
ActReadDataMapper
actReadDataMapper
)
{
...
...
@@ -30,6 +28,33 @@ public class ActReadDataServiceImpl implements ActReadDataService {
public
static
final
Pattern
PATTERN
=
Pattern
.
compile
(
"\\d+"
);
@Override
public
AjaxResult
read
(
String
mineId
)
{
//获取未清洗数据条数
int
count
=
actReadDataMapper
.
selectCleanToOne
(
mineId
);
if
(
count
<=
0
)
{
return
new
AjaxResult
(
500
,
"数据库没有:"
+
mineId
+
"数据,无法清洗"
);
}
else
{
//开启多线程,每次开启5个线程,执行完后
//lambda表达式,开启线程
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Future
<
String
>
future
=
mineConver
.
readToId
(
mineId
,
i
);
try
{
// 尝试获取结果,如果异步方法未完成,这里会抛出异常
future
.
get
();
System
.
out
.
println
(
"异步方法开启线程成功!"
+
i
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"异步方法开启线程失败!!!!!!!"
+
i
);
}
}
}
return
new
AjaxResult
(
200
,
"清洗成功"
);
}
/*
@Override
public AjaxResult read(String mineId) {
...
...
@@ -47,6 +72,7 @@ public class ActReadDataServiceImpl implements ActReadDataService {
}
return new AjaxResult(200, "清洗成功");
}
*/
/*@Async("defaultThreadPoolExecutor")
void readToId(String mineId, int c) {
...
...
@@ -78,31 +104,4 @@ public class ActReadDataServiceImpl implements ActReadDataService {
System.err.println("本次清洗了:" + list.size() + "条数据");
}
}*/
void
readToId
(
String
mineId
,
int
c
)
{
long
start
=
System
.
currentTimeMillis
();
System
.
err
.
println
(
"查询"
+
c
+
"条时间为:"
+
(
System
.
currentTimeMillis
()
-
start
));
Map
<
String
,
String
>
materialMap
=
new
HashMap
<>();
List
<
ActHistoryRoleTypeCodeModel
>
listMaterial
=
actReadDataMapper
.
selectMaterialCode
();
for
(
ActHistoryRoleTypeCodeModel
model
:
listMaterial
)
{
materialMap
.
putIfAbsent
(
model
.
getKey
(),
model
.
getValue
());
}
MineConver
mineConver
;
if
(
mineId
.
equals
(
LK
))
{
mineConver
=
new
MineConver
(
new
LkSpecialMethod
(
actReadDataMapper
));
}
else
{
mineConver
=
new
MineConver
(
new
OtherMethod
(
actReadDataMapper
));
}
List
<
ActReadHistoryModel
>
list
=
actReadDataMapper
.
readDateToHistory
(
mineId
,
1
);
mineConver
.
clean
(
list
.
get
(
0
),
materialMap
);
// for (ActReadHistoryModel actReadHistoryModel : list) {
// mineConver.clean(actReadHistoryModel, materialMap);
// }
long
end
=
System
.
currentTimeMillis
();
System
.
err
.
println
(
end
-
start
);
System
.
err
.
println
(
"本次清洗了:"
+
list
.
size
()
+
"条数据"
);
}
}
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/Conversion/LkSpecialMethod.java
View file @
e054929f
...
...
@@ -10,6 +10,7 @@ import com.ruoyi.system.mapper.ActReadDataMapper;
import
com.ruoyi.system.service.impl.ActReadDataServiceImpl
;
import
com.ruoyi.system.utils.DateUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.math.BigDecimal
;
...
...
@@ -20,6 +21,7 @@ import java.util.stream.IntStream;
/**
* 2024/3/27
*/
@Service
public
class
LkSpecialMethod
implements
MineConversion
{
private
final
ActReadDataMapper
actReadDataMapper
;
...
...
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/Conversion/MineConver.java
View file @
e054929f
package
com.ruoyi.system.service.impl.Conversion
;
import
com.ruoyi.system.domain.ActHistoryRoleTypeCodeModel
;
import
com.ruoyi.system.domain.ActReadHistoryModel
;
import
com.ruoyi.system.mapper.ActReadDataMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.AsyncResult
;
import
org.springframework.stereotype.Service
;
import
java.util.regex.Pattern
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.Future
;
/**
* 2024/3/27
*/
@Service
public
class
MineConver
{
private
MineConversion
mineConversion
;
/*
private MineConversion mineConversion;
public MineConver(MineConversion mineConversion) {
this.mineConversion = mineConversion;
}*/
@Autowired
private
OtherMethod
otherMethod
;
private
void
setOtherMethod
(
OtherMethod
otherMethod
)
{
this
.
otherMethod
=
otherMethod
;
}
@Autowired
private
LkSpecialMethod
lkSpecialMethod
;
public
void
clean
(
ActReadHistoryModel
actReadHistoryModel
,
Object
obj
){
mineConversion
.
conversion
(
actReadHistoryModel
,
obj
);
private
void
setLkSpecialMethod
(
LkSpecialMethod
lkSpecialMethod
)
{
this
.
lkSpecialMethod
=
lkSpecialMethod
;
}
@Autowired
private
ActReadDataMapper
actReadDataMapper
;
private
static
final
String
LK
=
"011702"
;
//@Async注解,注意:如果调用方法和被调用方法都在Service中,则不生效
@Async
(
"defaultThreadPoolExecutor"
)
//public void readToId(String mineId) {
public
Future
<
String
>
readToId
(
String
mineId
,
int
i
)
{
// 模拟耗时操作
try
{
Map
<
String
,
String
>
materialMap
=
new
HashMap
<>();
List
<
ActHistoryRoleTypeCodeModel
>
listMaterial
=
actReadDataMapper
.
selectMaterialCode
();
for
(
ActHistoryRoleTypeCodeModel
model
:
listMaterial
)
{
materialMap
.
putIfAbsent
(
model
.
getKey
(),
model
.
getValue
());
}
List
<
ActReadHistoryModel
>
list
=
actReadDataMapper
.
readDateToHistory
(
mineId
,
1
);
ActReadHistoryModel
historyModel
=
list
.
get
(
0
);
if
(
mineId
.
equals
(
LK
))
{
LkSpecialMethod
lkSpecialMethod
=
new
LkSpecialMethod
(
actReadDataMapper
);
//调用清洗方法
lkSpecialMethod
.
conversion
(
historyModel
,
materialMap
);
}
else
{
OtherMethod
otherMethod
=
new
OtherMethod
(
actReadDataMapper
);
//调用清洗方法
otherMethod
.
conversion
(
historyModel
,
materialMap
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
new
AsyncResult
<>(
"YES"
);
}
/*public void clean(ActReadHistoryModel actReadHistoryModel, Object obj){
mineConversion.conversion(actReadHistoryModel, obj);
}*/
}
ruoyi-supplies/src/main/java/com/ruoyi/system/service/impl/Conversion/OtherMethod.java
View file @
e054929f
...
...
@@ -10,6 +10,7 @@ import com.ruoyi.system.mapper.ActReadDataMapper;
import
com.ruoyi.system.service.impl.ActReadDataServiceImpl
;
import
com.ruoyi.system.utils.DateUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.math.BigDecimal
;
...
...
@@ -19,6 +20,7 @@ import java.util.stream.IntStream;
/**
* 2024/3/27
*/
@Service
public
class
OtherMethod
implements
MineConversion
{
private
final
ActReadDataMapper
actReadDataMapper
;
...
...
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