Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-reptiles
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
梁辉
car-reptiles
Commits
010404dc
Commit
010404dc
authored
Jan 09, 2021
by
landerliang@163.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
不使用Quartz管理定时任务了,改为纯Scheduled,根据多少个任务开多少个线程,目前站点能够正常使用
parent
18d6e520
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
447 additions
and
110 deletions
+447
-110
car-reptiles-common/pom.xml
+1
-2
car-reptiles-system/src/main/java/me/zhengjie/AppRun.java
+1
-1
car-reptiles-system/src/main/java/me/zhengjie/config/thread/AsyncTaskExecutePool.java
+6
-2
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/config/CustomAbortPolicy.java
+29
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/config/JobRunner.java
+5
-5
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/config/QuartzConfig.java
+39
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java
+1
-1
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/task/TestTask.java
+60
-7
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java
+5
-4
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java
+2
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/system/constants/MyConstants.java
+12
-9
car-reptiles-system/src/main/java/me/zhengjie/modules/system/domain/QuartzJob.java
+83
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/system/interceptor/HtmlToPdfInterceptor.java
+4
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/system/repository/JobMapper.java
+12
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/system/service/ReportService.java
+44
-41
car-reptiles-system/src/main/java/me/zhengjie/modules/system/task/Task.java
+107
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/system/util/CarReportUtil.java
+0
-0
car-reptiles-system/src/main/java/me/zhengjie/modules/system/util/PdfUtil.java
+16
-3
car-reptiles-system/src/main/resources/config/application.yml
+4
-3
car-reptiles-system/src/main/resources/logback.xml
+1
-1
car-reptiles-system/src/test/java/me/zhengjie/BackendApplicationTests.java
+4
-4
car-reptiles-system/src/test/java/me/zhengjie/LoginCacheTest.java
+11
-27
No files found.
car-reptiles-common/pom.xml
View file @
010404dc
...
...
@@ -63,4 +63,4 @@
<artifactId>
commons-codec
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
car-reptiles-system/src/main/java/me/zhengjie/AppRun.java
View file @
010404dc
...
...
@@ -39,7 +39,7 @@ import org.springframework.web.client.RestTemplate;
* @date 2018/11/15 9:20:19
*/
@MapperScan
(
"me.zhengjie.modules.system.repository"
)
//
@EnableAsync
@EnableAsync
@RestController
@Api
(
hidden
=
true
)
@EnableScheduling
...
...
car-reptiles-system/src/main/java/me/zhengjie/config/thread/AsyncTaskExecutePool.java
View file @
010404dc
...
...
@@ -40,7 +40,7 @@ public class AsyncTaskExecutePool implements AsyncConfigurer {
}
@Override
public
Executor
getAsyncExecutor
()
{
public
ThreadPoolTask
Executor
getAsyncExecutor
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
//核心线程池大小
executor
.
setCorePoolSize
(
config
.
getCorePoolSize
());
...
...
@@ -50,11 +50,15 @@ public class AsyncTaskExecutePool implements AsyncConfigurer {
executor
.
setQueueCapacity
(
config
.
getQueueCapacity
());
//活跃时间
executor
.
setKeepAliveSeconds
(
config
.
getKeepAliveSeconds
());
//优雅关闭线程 用来设置线程池关闭的时候等待所有任务都完成再继续销毁其他的Bean
executor
.
setWaitForTasksToCompleteOnShutdown
(
true
);
//线程名字前缀
executor
.
setThreadNamePrefix
(
"el-async-"
);
//当pool已经达到最大size则丢弃前面的任务,不抛出异常
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
DiscardPolicy
());
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
//
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor
.
initialize
();
return
executor
;
}
...
...
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/config/CustomAbortPolicy.java
0 → 100644
View file @
010404dc
package
me
.
zhengjie
.
modules
.
quartz
.
config
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.concurrent.RejectedExecutionHandler
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
* @author Lander
*/
@Slf4j
public
class
CustomAbortPolicy
implements
RejectedExecutionHandler
{
public
void
CustomAbortPolicy
()
{
}
@Override
public
void
rejectedExecution
(
Runnable
r
,
ThreadPoolExecutor
executor
)
{
System
.
out
.
println
(
"进入拒绝策略。。。。。。。。。。"
);
if
(!
executor
.
isShutdown
())
{
try
{
log
.
error
(
"full-->>线程池已满,执行拒绝策略"
);
while
(
executor
.
getQueue
().
remainingCapacity
()
==
0
);
executor
.
execute
(
r
);
}
catch
(
Exception
e
)
{
log
.
error
(
"rejectedExecutionException====>>>>>"
+
e
.
toString
());
}
}
}
}
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/config/JobRunner.java
View file @
010404dc
...
...
@@ -32,11 +32,11 @@ import java.util.List;
* @date 2019-01-07
*/
@Component
@RequiredArgsConstructor
//
@RequiredArgsConstructor
public
class
JobRunner
implements
ApplicationRunner
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
JobRunner
.
class
);
private
final
QuartzJobRepository
quartzJobRepository
;
private
final
QuartzManage
quartzManage
;
//
private final QuartzJobRepository quartzJobRepository;
//
private final QuartzManage quartzManage;
/**
* 项目启动时重新激活启用的定时任务
...
...
@@ -46,8 +46,8 @@ public class JobRunner implements ApplicationRunner {
@Override
public
void
run
(
ApplicationArguments
applicationArguments
)
{
log
.
info
(
"--------------------注入定时任务---------------------"
);
List
<
QuartzJob
>
quartzJobs
=
quartzJobRepository
.
findByIsPauseIsFalse
();
quartzJobs
.
forEach
(
quartzManage:
:
addJob
);
//
List<QuartzJob> quartzJobs = quartzJobRepository.findByIsPauseIsFalse();
//
quartzJobs.forEach(quartzManage::addJob);
log
.
info
(
"--------------------定时任务注入完成---------------------"
);
}
}
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/config/QuartzConfig.java
View file @
010404dc
...
...
@@ -15,11 +15,16 @@
*/
package
me
.
zhengjie
.
modules
.
quartz
.
config
;
import
com.google.common.util.concurrent.ThreadFactoryBuilder
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.config.thread.AsyncTaskExecutePool
;
import
me.zhengjie.config.thread.AsyncTaskProperties
;
import
org.quartz.Scheduler
;
import
org.quartz.spi.TriggerFiredBundle
;
import
org.springframework.beans.factory.config.AutowireCapableBeanFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.scheduling.quartz.AdaptableJobFactory
;
import
org.springframework.scheduling.quartz.SchedulerFactoryBean
;
import
org.springframework.stereotype.Component
;
...
...
@@ -29,9 +34,17 @@ import org.springframework.stereotype.Component;
* @author /
* @date 2019-01-07
*/
@Slf4j
@Configuration
public
class
QuartzConfig
{
/** 注入配置类 */
private
final
AsyncTaskProperties
config
;
private
final
AsyncTaskExecutePool
asyncTaskExecutePool
;
public
QuartzConfig
(
AsyncTaskProperties
config
,
AsyncTaskExecutePool
asyncTaskExecutePool
)
{
this
.
config
=
config
;
this
.
asyncTaskExecutePool
=
asyncTaskExecutePool
;
}
/**
* 解决Job中注入Spring Bean为null的问题
*/
...
...
@@ -54,6 +67,32 @@ public class QuartzConfig {
}
}
@Bean
(
name
=
"quartzTaskExecutor"
)
public
ThreadPoolTaskExecutor
threadPoolTaskExecutor
(){
/*ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数
executor.setCorePoolSize(config.getCorePoolSize());
// 最大线程数
executor.setMaxPoolSize(config.getMaxPoolSize());
// 任务队列大小
executor.setQueueCapacity(config.getQueueCapacity());
// 线程前缀名
executor.setThreadNamePrefix("CartReptiles-Quartz");
// 线程的空闲时间
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
executor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("Quartz定时任务-runner-%d").build());
// 拒绝策略
executor.setRejectedExecutionHandler(new CustomAbortPolicy());
executor.setWaitForTasksToCompleteOnShutdown(true);
// 线程初始化
//executor.initialize();
return executor;*/
return
asyncTaskExecutePool
.
getAsyncExecutor
();
}
/**
* 注入scheduler到spring
* @param quartzJobFactory /
...
...
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java
View file @
010404dc
...
...
@@ -145,7 +145,7 @@ public class QuartzJobServiceImpl implements QuartzJobService {
}
}
//
@Async
@Async
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
executionSubJob
(
String
[]
tasks
)
throws
InterruptedException
{
...
...
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/task/TestTask.java
View file @
010404dc
...
...
@@ -27,15 +27,68 @@ import org.springframework.stereotype.Component;
@Component
public
class
TestTask
{
/*private final JobMapper jobMapper;
private final ReportService reportService;
@Autowired
public TestTask(JobMapper jobMapper, ReportService reportService) {
this.jobMapper = jobMapper;
this.reportService = reportService;
}*/
public
void
run
(){
log
.
info
(
"run 执行成功"
);
}
public
void
run1
(
String
str
){
log
.
info
(
"run1 执行成功,参数为: {}"
+
str
);
}
/* log.info(">>> ================================ 开始自动爬取新的检测报告进行下载、签章、上传 ====================================");
//查询全部非管理员任务 且 状态为 执行中的
QueryWrapper<QuartzJob> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(i -> {
i.notIn(QuartzJob::getDeptId,19)
.eq(QuartzJob::getIsPause,0);
});
List<QuartzJob> quartzJobs = jobMapper.selectList(queryWrapper);
try {
quartzJobs.forEach( quartzJob -> {
String params = quartzJob.getParams();
if(StrUtil.isNotBlank(params)){
JSONObject jsonParam = JSONObject.parseObject(params);
public
void
run2
(){
log
.
info
(
"run2 执行成功"
);
log.info(">>> 环保账户: {}, 环保密码:{}, 授权人签名盘符:{}, 批准人签名盘符:{}, 公章签名盘符:{}, 部门编号:{}",
jsonParam.getString("account"),jsonParam.getString("password"),
jsonParam.getString("snKey1"),jsonParam.getString("snKey2"),jsonParam.getString("snKey3"),jsonParam.getInteger("deptId"));
AssertUtil.isNotNull(jsonParam.get("account"),"缺少环保系统账户,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("password"),"缺少环保系统密码,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snKey1"),"缺少授权人签名盘符,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snKey2"),"缺少批准人签名盘符,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snKey3"),"缺少公章签名盘符,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snKey4"),"缺少MA章签名盘符,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snName1"),"缺少授权人签章名称,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snName2"),"缺少批准人签章名称,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snName3"),"缺少公章签章名称,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("snName4"),"缺少MA章名称,自动任务执行终止!");
AssertUtil.isNotNull(jsonParam.get("deptId"),"缺少部门id,自动任务执行终止!");
reportService.autoDownloadAndSignAndUploadReport(jsonParam.getString("account"),jsonParam.getString("password"),
jsonParam.getString("snKey1"),jsonParam.getString("snKey2"),jsonParam.getString("snKey3"),
jsonParam.getString("snName1"),jsonParam.getString("snName2"),jsonParam.getString("snName3")
,jsonParam.getString("snKey4"),jsonParam.getString("snName4"),jsonParam.getInteger("deptId"));
}
});
} catch (Exception e) {
log.error(e.getMessage());
}
log.info(">> ========================================== 本次自动签章任务执行完毕 ==========================================");*/
}
}
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java
View file @
010404dc
...
...
@@ -32,6 +32,7 @@ import me.zhengjie.utils.StringUtils;
import
me.zhengjie.utils.ThrowableUtil
;
import
org.quartz.JobExecutionContext
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
java.util.*
;
import
java.util.concurrent.*
;
...
...
@@ -41,12 +42,10 @@ import java.util.concurrent.*;
* @author /
* @date 2019-01-07
*/
//
@Async
@Async
@SuppressWarnings
({
"unchecked"
,
"all"
})
public
class
ExecutionJob
extends
QuartzJobBean
{
/** 该处仅供参考 */
private
final
static
ThreadPoolExecutor
EXECUTOR
=
ThreadPoolExecutorUtil
.
getPoll
();
private
final
ThreadPoolTaskExecutor
EXECUTOR
=
(
ThreadPoolTaskExecutor
)
SpringContextHolder
.
getBean
(
"quartzTaskExecutor"
);
@Override
public
void
executeInternal
(
JobExecutionContext
context
)
{
...
...
@@ -70,6 +69,7 @@ public class ExecutionJob extends QuartzJobBean {
// 执行任务
System
.
out
.
println
(
"--------------------------------------------------------------"
);
System
.
out
.
println
(
"任务开始执行,任务名称:"
+
quartzJob
.
getJobName
());
System
.
out
.
println
(
"-------------------当前线程池大小:"
+
EXECUTOR
.
getPoolSize
()
+
",线程池最大数:"
+
EXECUTOR
.
getMaxPoolSize
()
+
"---------------------"
);
QuartzRunnable
task
=
new
QuartzRunnable
(
quartzJob
.
getBeanName
(),
quartzJob
.
getMethodName
(),
quartzJob
.
getParams
());
Future
<?>
future
=
EXECUTOR
.
submit
(
task
);
...
...
@@ -93,6 +93,7 @@ public class ExecutionJob extends QuartzJobBean {
if
(
StringUtils
.
isNotBlank
(
uuid
))
{
redisUtils
.
set
(
uuid
,
false
);
}
System
.
out
.
println
(
"任务执行失败,任务名称:"
+
quartzJob
.
getJobName
());
System
.
out
.
println
(
"--------------------------------------------------------------"
);
long
times
=
System
.
currentTimeMillis
()
-
startTime
;
...
...
car-reptiles-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java
View file @
010404dc
...
...
@@ -51,6 +51,7 @@ public class QuartzManage {
.
withSchedule
(
CronScheduleBuilder
.
cronSchedule
(
quartzJob
.
getCronExpression
()))
.
build
();
cronTrigger
.
getJobDataMap
().
put
(
QuartzJob
.
JOB_KEY
,
quartzJob
);
//重置启动时间
...
...
@@ -63,6 +64,7 @@ public class QuartzManage {
if
(
quartzJob
.
getIsPause
())
{
pauseJob
(
quartzJob
);
}
}
catch
(
Exception
e
){
log
.
error
(
"创建定时任务失败"
,
e
);
throw
new
BadRequestException
(
"创建定时任务失败"
);
...
...
car-reptiles-system/src/main/java/me/zhengjie/modules/system/constants/MyConstants.java
View file @
010404dc
...
...
@@ -23,26 +23,29 @@ public class MyConstants {
/**
* 身份证文件名后缀
*/
public
static
final
String
IDCARD_SUFFIX
=
"_sfz.jpg"
;
public
static
final
String
IDCARD_SUFFIX
=
"\\IMG_0000.jpg"
;
/**
*
检测申请表
文件后缀
*
行驶证1
文件后缀
*/
public
static
final
String
APPLY_SUFFIX
=
"_jcsqb
.jpg"
;
public
static
final
String
DRIVER_SUFFIX1
=
"\\IMG_0001
.jpg"
;
/**
*
维修凭证
文件后缀
*
行驶证2
文件后缀
*/
public
static
final
String
CERTIFICATE_SUFFIX
=
"_wxpz.jpg"
;
public
static
final
String
DRIVER_SUFFIX2
=
"\\IMG_0002.jpg"
;
/**
*
行驶证1
文件后缀
*
检测申请表
文件后缀
*/
public
static
final
String
DRIVER_SUFFIX1
=
"_xsz1
.jpg"
;
public
static
final
String
APPLY_SUFFIX
=
"\\IMG_0003
.jpg"
;
/**
*
行驶证2
文件后缀
*
维修凭证
文件后缀
*/
public
static
final
String
DRIVER_SUFFIX2
=
"_xsz2.jpg"
;
public
static
final
String
CERTIFICATE_SUFFIX
=
"\\IMG_0004.jpg"
;
}
car-reptiles-system/src/main/java/me/zhengjie/modules/system/domain/QuartzJob.java
0 → 100644
View file @
010404dc
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
me
.
zhengjie
.
modules
.
system
.
domain
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.persistence.Transient
;
import
javax.validation.constraints.NotBlank
;
/**
* @author Zheng Jie
* @date 2019-01-07
*/
@Data
@TableName
(
"sys_quartz_job"
)
public
class
QuartzJob
{
public
static
final
String
JOB_KEY
=
"JOB_KEY"
;
@TableId
(
type
=
IdType
.
AUTO
)
private
Long
jobId
;
@TableField
(
exist
=
false
)
@ApiModelProperty
(
value
=
"用于子任务唯一标识"
,
hidden
=
true
)
private
String
uuid
;
@ApiModelProperty
(
value
=
"定时器名称"
)
private
String
jobName
;
@NotBlank
@ApiModelProperty
(
value
=
"Bean名称"
)
private
String
beanName
;
@ApiModelProperty
(
value
=
"方法名称"
)
private
String
methodName
;
@ApiModelProperty
(
value
=
"参数"
)
private
String
params
;
@ApiModelProperty
(
value
=
"cron表达式"
)
private
String
cronExpression
;
@ApiModelProperty
(
value
=
"状态,暂时或启动"
)
private
Boolean
isPause
=
false
;
@ApiModelProperty
(
value
=
"负责人"
)
private
String
personInCharge
;
@ApiModelProperty
(
value
=
"报警邮箱"
)
private
String
email
;
@ApiModelProperty
(
value
=
"子任务"
)
private
String
subTask
;
@ApiModelProperty
(
value
=
"失败后暂停"
)
private
Boolean
pauseAfterFailure
;
@ApiModelProperty
(
value
=
"备注"
)
private
String
description
;
@ApiModelProperty
(
"部门id"
)
private
Long
deptId
;
}
car-reptiles-system/src/main/java/me/zhengjie/modules/system/interceptor/HtmlToPdfInterceptor.java
View file @
010404dc
...
...
@@ -33,4 +33,8 @@ public class HtmlToPdfInterceptor extends Thread{
}
}
}
car-reptiles-system/src/main/java/me/zhengjie/modules/system/repository/JobMapper.java
0 → 100644
View file @
010404dc
package
me
.
zhengjie
.
modules
.
system
.
repository
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
me.zhengjie.modules.system.domain.QuartzJob
;
import
org.springframework.stereotype.Repository
;
/**
* @author Lander
*/
@Repository
public
interface
JobMapper
extends
BaseMapper
<
QuartzJob
>
{
}
car-reptiles-system/src/main/java/me/zhengjie/modules/system/service/ReportService.java
View file @
010404dc
...
...
@@ -36,14 +36,9 @@ import org.springframework.security.core.context.SecurityContextHolder;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.multipart.MultipartFile
;
import
sun.misc.BASE64Encoder
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
/**
* 检测报告service
...
...
@@ -71,6 +66,8 @@ public class ReportService {
private
static
List
<
TestReportVo
>
reportVoList
;
private
final
TaskErrorMapper
taskErrorMapper
;
@Value
(
"${uploadFilePath}"
)
private
String
uploadFilePath
;
@Autowired
public
ReportService
(
UserMapper
userMapper
,
DeptMapper
deptMapper
,
CarReportUtil
carReportUtil
,
ReportPdfMapper
reportPdfMapper
,
SignatureService
signatureService
,
RestTemplate
restTemplate
,
TaskErrorMapper
taskErrorMapper
)
{
...
...
@@ -123,7 +120,7 @@ public class ReportService {
* 自动下载检测报告并签章上传
*
*/
public
synchronized
void
autoDownloadAndSignAndUploadReport
(
String
account
,
String
password
,
String
snKey1
,
String
snKey2
,
String
snKey3
,
public
void
autoDownloadAndSignAndUploadReport
(
String
account
,
String
password
,
String
snKey1
,
String
snKey2
,
String
snKey3
,
String
snName1
,
String
snName2
,
String
snName3
,
String
snKey4
,
String
snName4
,
Integer
deptId
){
...
...
@@ -142,34 +139,38 @@ public class ReportService {
//下载报告pdf 并写入数据库
reportPdfVo
=
new
ReportPdfVo
();
String
path
=
carReportUtil
.
downloadReport
(
account
,
password
,
reportDetailsReqVo
);
reportPdfVo
.
setPath
(
path
);
reportPdfVo
.
setVehicleId
(
testReportVo
.
getVehicleID
());
reportPdfVo
.
setUniqueString
(
testReportVo
.
getUniqueString
());
reportPdfVo
.
setReportName
(
testReportVo
.
getInspectionReportNo
()
+
".pdf"
);
reportPdfVo
.
setReportNum
(
testReportVo
.
getInspectionReportNo
());
reportPdfVo
.
setBusinessKey
(
StrUtil
.
isNotBlank
(
testReportVo
.
getBusinessKey
())?
testReportVo
.
getBusinessKey
():
testReportVo
.
getInspectionNum
());
reportPdfVo
.
setCreateTime
(
DateUtil
.
date
());
reportPdfVo
.
setCarNum
(
testReportVo
.
getVLPN
());
//根据snKey查询签章信息
SignatureVo
signatureVo1
=
signatureService
.
getBySnKeyAndSnName
(
snKey1
,
snName1
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo1
,
"找不到snKey为: "
+
snKey1
+
"的签名章"
);
SignatureVo
signatureVo2
=
signatureService
.
getBySnKeyAndSnName
(
snKey2
,
snName2
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo2
,
"找不到snKey为: "
+
snKey2
+
"的签名章"
);
SignatureVo
signatureVo3
=
signatureService
.
getBySnKeyAndSnName
(
snKey3
,
snName3
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo3
,
"找不到snKey为: "
+
snKey3
+
"的公章"
);
SignatureVo
signatureVo4
=
signatureService
.
getBySnKeyAndSnName
(
snKey4
,
snName4
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo3
,
"找不到snKey为: "
+
snKey4
+
"的公章"
);
//进行签章
CarSignatureReqVo
carSignatureReqVo
=
new
CarSignatureReqVo
();
carSignatureReqVo
.
setReportPdfVo
(
reportPdfVo
);
carSignatureReqVo
.
setSignature1
(
signatureVo1
);
carSignatureReqVo
.
setSignature2
(
signatureVo2
);
carSignatureReqVo
.
setSignature3
(
signatureVo3
);
carSignatureReqVo
.
setSignature4
(
signatureVo4
);
String
path
=
carReportUtil
.
authDownloadReport
(
account
,
password
,
reportDetailsReqVo
);
//如果下载成功
if
(
StrUtil
.
isNotBlank
(
path
)){
reportPdfVo
.
setPath
(
path
);
reportPdfVo
.
setVehicleId
(
testReportVo
.
getVehicleID
());
reportPdfVo
.
setUniqueString
(
testReportVo
.
getUniqueString
());
reportPdfVo
.
setReportName
(
testReportVo
.
getInspectionReportNo
()
+
".pdf"
);
reportPdfVo
.
setReportNum
(
testReportVo
.
getInspectionReportNo
());
reportPdfVo
.
setBusinessKey
(
StrUtil
.
isNotBlank
(
testReportVo
.
getBusinessKey
())?
testReportVo
.
getBusinessKey
():
testReportVo
.
getInspectionNum
());
reportPdfVo
.
setCreateTime
(
DateUtil
.
date
());
reportPdfVo
.
setCarNum
(
testReportVo
.
getVLPN
());
//根据snKey查询签章信息
SignatureVo
signatureVo1
=
signatureService
.
getBySnKeyAndSnName
(
snKey1
,
snName1
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo1
,
"找不到snKey为: "
+
snKey1
+
"的签名章"
);
SignatureVo
signatureVo2
=
signatureService
.
getBySnKeyAndSnName
(
snKey2
,
snName2
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo2
,
"找不到snKey为: "
+
snKey2
+
"的签名章"
);
SignatureVo
signatureVo3
=
signatureService
.
getBySnKeyAndSnName
(
snKey3
,
snName3
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo3
,
"找不到snKey为: "
+
snKey3
+
"的公章"
);
SignatureVo
signatureVo4
=
signatureService
.
getBySnKeyAndSnName
(
snKey4
,
snName4
,
deptId
);
AssertUtil
.
isNotNull
(
signatureVo3
,
"找不到snKey为: "
+
snKey4
+
"的公章"
);
//进行签章
CarSignatureReqVo
carSignatureReqVo
=
new
CarSignatureReqVo
();
carSignatureReqVo
.
setReportPdfVo
(
reportPdfVo
);
carSignatureReqVo
.
setSignature1
(
signatureVo1
);
carSignatureReqVo
.
setSignature2
(
signatureVo2
);
carSignatureReqVo
.
setSignature3
(
signatureVo3
);
carSignatureReqVo
.
setSignature4
(
signatureVo4
);
HttpEntity
<
CarSignatureReqVo
>
httpEntity
=
new
HttpEntity
<>(
carSignatureReqVo
);
ResponseEntity
<
ResultVo
>
responseEntity
=
this
.
restTemplate
.
exchange
(
...
...
@@ -189,20 +190,18 @@ public class ReportService {
reportPdfVo
.
setPath
(
signatureReport
.
getPath
());
reportPdfVo
.
setReportName
(
signatureReport
.
getReportName
());
//上传文件 (连同检测报告全部文件)
Integer
success
=
carReportUtil
.
autoUploadReportPost
(
account
,
password
,
reportPdfVo
,
signatureVo1
.
getDeptId
());
//上传成功的文件小于2个则视为上传失败,清除下载记录
/*if(success < 2){
deleteReportPdf(signatureReport.getReportNum());
}*/
if
(
success
>=
2
){
log
.
info
(
">> 成功自动上传:{} 个文件,本次上传任务完成!"
,
success
);
//写入pdf下载记录
reportPdfMapper
.
insert
(
reportPdfVo
);
}
}
else
{
log
.
error
(
">> 自动下载检测报告失败!"
);
}
}
}
}
catch
(
Exception
e
)
{
...
...
@@ -370,6 +369,10 @@ public class ReportService {
reportPdfMapper
.
updateById
(
reportPdfVo
);
}
if
(!
FileUtil
.
exist
(
uploadFilePath
+
detailsReqVo
)){
FileUtil
.
mkdir
(
uploadFilePath
+
detailsReqVo
);
}
return
reportPdfVo
;
}
}
...
...
car-reptiles-system/src/main/java/me/zhengjie/modules/system/task/Task.java
0 → 100644
View file @
010404dc
package
me
.
zhengjie
.
modules
.
system
.
task
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.modules.system.domain.QuartzJob
;
import
me.zhengjie.modules.system.repository.JobMapper
;
import
me.zhengjie.modules.system.service.ReportService
;
import
me.zhengjie.utils.AssertUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
@Slf4j
@Component
public
class
Task
{
@Autowired
private
JobMapper
jobMapper
;
@Autowired
private
ReportService
reportService
;
@Scheduled
(
initialDelay
=
2000
,
fixedDelay
=
20000
)
public
void
run
(){
log
.
info
(
">>> ================================ 开始自动爬取新的检测报告进行下载、签章、上传 ===================================="
);
//查询全部非管理员任务 且 状态为 执行中的
QueryWrapper
<
QuartzJob
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
lambda
().
and
(
i
->
{
i
.
notIn
(
QuartzJob:
:
getDeptId
,
19
)
.
eq
(
QuartzJob:
:
getIsPause
,
0
);
});
List
<
QuartzJob
>
quartzJobs
=
jobMapper
.
selectList
(
queryWrapper
);
try
{
quartzJobs
.
forEach
(
quartzJob
->
{
AutoScanReportThread
autoScanReportThread
=
new
AutoScanReportThread
();
autoScanReportThread
.
setParams
(
quartzJob
.
getParams
());
autoScanReportThread
.
start
();
});
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
}
log
.
info
(
">> ========================================== 本次自动签章任务执行完毕 =========================================="
);
}
/**
* 自动扫描线程
*/
class
AutoScanReportThread
extends
Thread
{
private
String
params
;
public
String
getParams
()
{
return
params
;
}
public
void
setParams
(
String
params
)
{
this
.
params
=
params
;
}
@Override
public
void
run
()
{
if
(
StrUtil
.
isNotBlank
(
params
)){
JSONObject
jsonParam
=
JSONObject
.
parseObject
(
params
);
log
.
info
(
">>> 环保账户: {}, 环保密码:{}, 授权人签名盘符:{}, 批准人签名盘符:{}, 公章签名盘符:{}, 部门编号:{}"
,
jsonParam
.
getString
(
"account"
),
jsonParam
.
getString
(
"password"
),
jsonParam
.
getString
(
"snKey1"
),
jsonParam
.
getString
(
"snKey2"
),
jsonParam
.
getString
(
"snKey3"
),
jsonParam
.
getInteger
(
"deptId"
));
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"account"
),
"缺少环保系统账户,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"password"
),
"缺少环保系统密码,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snKey1"
),
"缺少授权人签名盘符,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snKey2"
),
"缺少批准人签名盘符,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snKey3"
),
"缺少公章签名盘符,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snKey4"
),
"缺少MA章签名盘符,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snName1"
),
"缺少授权人签章名称,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snName2"
),
"缺少批准人签章名称,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snName3"
),
"缺少公章签章名称,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"snName4"
),
"缺少MA章名称,自动任务执行终止!"
);
AssertUtil
.
isNotNull
(
jsonParam
.
get
(
"deptId"
),
"缺少部门id,自动任务执行终止!"
);
reportService
.
autoDownloadAndSignAndUploadReport
(
jsonParam
.
getString
(
"account"
),
jsonParam
.
getString
(
"password"
),
jsonParam
.
getString
(
"snKey1"
),
jsonParam
.
getString
(
"snKey2"
),
jsonParam
.
getString
(
"snKey3"
),
jsonParam
.
getString
(
"snName1"
),
jsonParam
.
getString
(
"snName2"
),
jsonParam
.
getString
(
"snName3"
)
,
jsonParam
.
getString
(
"snKey4"
),
jsonParam
.
getString
(
"snName4"
),
jsonParam
.
getInteger
(
"deptId"
));
}
}
}
}
car-reptiles-system/src/main/java/me/zhengjie/modules/system/util/CarReportUtil.java
View file @
010404dc
This diff is collapsed.
Click to expand it.
car-reptiles-system/src/main/java/me/zhengjie/modules/system/util/PdfUtil.java
View file @
010404dc
...
...
@@ -4,7 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import
me.zhengjie.modules.system.interceptor.HtmlToPdfInterceptor
;
import
org.springframework.stereotype.Component
;
import
java.io.
File
;
import
java.io.
*
;
/**
* @author Lander
...
...
@@ -14,6 +14,19 @@ import java.io.File;
public
class
PdfUtil
{
public
static
void
run
(
InputStream
is
){
try
{
InputStreamReader
isr
=
new
InputStreamReader
(
is
,
"UTF-8"
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
String
line
=
null
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
log
.
info
(
">> HTML转PDF INFO :{}"
,
line
.
toString
());
//输出内容
}
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
}
/**
* html转pdf
...
...
@@ -54,9 +67,9 @@ public class PdfUtil {
try
{
Process
proc
=
Runtime
.
getRuntime
().
exec
(
cmd
.
toString
());
HtmlToPdfInterceptor
error
=
new
HtmlToPdfInterceptor
(
proc
.
getErrorStream
());
HtmlToPdfInterceptor
out
put
=
new
HtmlToPdfInterceptor
(
proc
.
getInputStream
());
HtmlToPdfInterceptor
out
=
new
HtmlToPdfInterceptor
(
proc
.
getInputStream
());
error
.
start
();
out
put
.
start
();
out
.
start
();
proc
.
waitFor
();
}
catch
(
Exception
e
)
{
result
=
false
;
...
...
car-reptiles-system/src/main/resources/config/application.yml
View file @
010404dc
...
...
@@ -35,16 +35,17 @@ spring:
max-file-size
:
100MB
max-request-size
:
100MB
#最大请求文件的大小
task
:
pool
:
# 核心线程池大小
core-pool-size
:
10
core-pool-size
:
25
# 最大线程数
max-pool-size
:
30
# 活跃时间
keep-alive-seconds
:
6
0
keep-alive-seconds
:
5
0
# 队列容量
queue-capacity
:
5
0
queue-capacity
:
3
0
#七牛云
qiniu
:
...
...
car-reptiles-system/src/main/resources/logback.xml
View file @
010404dc
...
...
@@ -22,7 +22,7 @@
<appender-ref
ref=
"console"
/>
</logger>
<logger
name=
"jdbc.resultset"
level=
"
ERROR
"
additivity=
"false"
>
<logger
name=
"jdbc.resultset"
level=
"
INFO
"
additivity=
"false"
>
<appender-ref
ref=
"console"
/>
</logger>
...
...
car-reptiles-system/src/test/java/me/zhengjie/BackendApplicationTests.java
View file @
010404dc
...
...
@@ -166,8 +166,8 @@ class BackendApplicationTests {
});
log
.
info
(
">> 检测报告下载完成!"
);
frameDriver
.
close
();
driver
.
close
();
frameDriver
.
quit
();
driver
.
quit
();
}
...
...
@@ -315,8 +315,8 @@ class BackendApplicationTests {
//点击上传已勾选的文件
frameDriver
.
findElement
(
new
By
.
ById
(
"Button3"
)).
click
();
frameDriver
.
close
();
driver
.
close
();
frameDriver
.
quit
();
driver
.
quit
();
log
.
info
(
">> ======== 资料已上传完成 =========== <<"
);
}
...
...
car-reptiles-system/src/test/java/me/zhengjie/LoginCacheTest.java
View file @
010404dc
package
me
.
zhengjie
;
import
cn.hutool.core.img.Img
;
import
cn.hutool.core.io.FileUtil
;
import
me.zhengjie.modules.security.service.UserDetailsServiceImpl
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -16,38 +18,20 @@ public class LoginCacheTest {
@Resource
(
name
=
"userDetailsService"
)
private
UserDetailsServiceImpl
userDetailsService
;
public
synchronized
void
testSyncronized
(
Integer
i
){
System
.
out
.
println
(
i
+
"进入同步方法"
);
}
public
void
testSync
(
Integer
i
){
System
.
out
.
println
(
i
+
"开始异步执行同步方法。。。"
);
if
(
i
==
2
){
try
{
Thread
.
sleep
(
10000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
testSyncronized
(
i
);
@Test
public
void
testCreateFileDirect
(){
String
dir
=
"666"
;
if
(!
FileUtil
.
exist
(
"C:\\reptiles\\uploadPicture\\"
+
dir
)){
FileUtil
.
mkdir
(
"C:\\reptiles\\uploadPicture\\"
+
dir
);
}
}
@Test
public
void
testCache
()
{
long
start1
=
System
.
currentTimeMillis
();
int
size
=
10000
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
userDetailsService
.
loadUserByUsername
(
"admin"
);
}
long
end1
=
System
.
currentTimeMillis
();
//关闭缓存
userDetailsService
.
setEnableCache
(
false
);
long
start2
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
userDetailsService
.
loadUserByUsername
(
"admin"
);
}
long
end2
=
System
.
currentTimeMillis
();
System
.
out
.
print
(
"使用缓存:"
+
(
end1
-
start1
)
+
"毫秒\n 不使用缓存:"
+
(
end2
-
start2
)
+
"毫秒"
);
Img
.
from
(
FileUtil
.
file
(
"C:\\Users\\Lander.LAPTOP-6VMQUJS1\\Desktop\\test-report\\桂BFF605_xsz2.jpg"
))
.
setQuality
(
0.8
)
//压缩比率
.
write
(
FileUtil
.
file
(
"C:\\Users\\Lander.LAPTOP-6VMQUJS1\\Desktop\\test-report\\桂BFF605_xsz2.jpg"
));
}
@Test
...
...
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