Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-module-job
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-module-job
Commits
6f5c754d
提交
6f5c754d
authored
3月 05, 2026
作者:
窦馨雨
浏览文件
操作
浏览文件
下载
差异文件
合并分支 'dxy' 到 'qa'
勤策订单明细定时功能更新时间获取方式 查看合并请求
!134
上级
298b8b05
7efbf871
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
64 行增加
和
15 行删除
+64
-15
IQinceOrderInformationSyncService.java
.../job/service/order/IQinceOrderInformationSyncService.java
+2
-0
QinceOrderInformationSyncServiceImpl.java
...vice/order/impl/QinceOrderInformationSyncServiceImpl.java
+50
-3
QinCeUtils.java
src/main/java/com/sfa/job/util/QinCeUtils.java
+10
-11
QinceOrderInformationTask.java
...a/com/sfa/job/xxljob/order/QinceOrderInformationTask.java
+2
-1
没有找到文件。
src/main/java/com/sfa/job/service/order/IQinceOrderInformationSyncService.java
浏览文件 @
6f5c754d
package
com
.
sfa
.
job
.
service
.
order
;
package
com
.
sfa
.
job
.
service
.
order
;
import
java.time.LocalDateTime
;
/**
/**
* @Author: DouXinYu
* @Author: DouXinYu
* @Date: 2026-02-27 18:33
* @Date: 2026-02-27 18:33
...
...
src/main/java/com/sfa/job/service/order/impl/QinceOrderInformationSyncServiceImpl.java
浏览文件 @
6f5c754d
...
@@ -8,9 +8,14 @@ import com.sfa.job.service.order.IQinceOrderInformationSyncService;
...
@@ -8,9 +8,14 @@ import com.sfa.job.service.order.IQinceOrderInformationSyncService;
import
com.sfa.job.util.QinCeUtils
;
import
com.sfa.job.util.QinCeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
/**
/**
* @Author: DouXinYu
* @Author: DouXinYu
...
@@ -27,6 +32,12 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
...
@@ -27,6 +32,12 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
@Autowired
@Autowired
IQinceOrderCoreDao
qinceOrderCoreDao
;
IQinceOrderCoreDao
qinceOrderCoreDao
;
@Autowired
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
// Redis断点key(自定义,用于存储上一次拉取的结束时间)
private
static
final
String
QC_ORDER_BREAKPOINT_KEY
=
"qc:order:pull:breakpoint"
;
private
static
final
DateTimeFormatter
FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
/**
/**
* 同步勤策订单信息
* 同步勤策订单信息
...
@@ -34,10 +45,13 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
...
@@ -34,10 +45,13 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
@Override
@Override
public
void
syncQinceOrderInformation
()
{
public
void
syncQinceOrderInformation
()
{
log
.
info
(
"================= 开始同步勤策订单信息 =================="
);
log
.
info
(
"================= 开始同步勤策订单信息 =================="
);
// 1. 获取上一次的断点(首次为昨天0点)
LocalDateTime
startTime
=
getBreakpoint
();
LocalDateTime
endTime
=
LocalDateTime
.
now
();
log
.
info
(
"开始拉取勤策订单,断点起始时间:{}"
,
startTime
.
format
(
FORMATTER
));
try
{
try
{
log
.
info
(
"================ 开始查询
前1天所有
订单 ==================="
);
log
.
info
(
"================ 开始查询订单 ==================="
);
JSONArray
orderList
=
qinCeUtils
.
queryLastDayAllOrder
();
JSONArray
orderList
=
qinCeUtils
.
queryLastDayAllOrder
(
startTime
);
log
.
info
(
"查询前1天所有订单完成,订单数:{}"
,
orderList
.
size
());
log
.
info
(
"查询前1天所有订单完成,订单数:{}"
,
orderList
.
size
());
if
(
CollectionUtils
.
isEmpty
(
orderList
)){
if
(
CollectionUtils
.
isEmpty
(
orderList
)){
...
@@ -53,6 +67,9 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
...
@@ -53,6 +67,9 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
log
.
info
(
"处理第{}条订单数据完成"
,
i
+
1
);
log
.
info
(
"处理第{}条订单数据完成"
,
i
+
1
);
}
}
log
.
info
(
"================== 处理订单数据完成 ===================="
);
log
.
info
(
"================== 处理订单数据完成 ===================="
);
updateBreakpoint
(
endTime
);
log
.
info
(
"================== 断点更新完成,新断点:{} ===================="
,
endTime
.
format
(
FORMATTER
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
@@ -60,6 +77,36 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
...
@@ -60,6 +77,36 @@ public class QinceOrderInformationSyncServiceImpl implements IQinceOrderInformat
}
}
/**
* 获取Redis中的断点(上一次拉取的结束时间)
* 首次/断点解析失败时,返回昨天0点
*/
private
LocalDateTime
getBreakpoint
()
{
try
{
String
breakpointStr
=
redisTemplate
.
opsForValue
().
get
(
QC_ORDER_BREAKPOINT_KEY
);
if
(
breakpointStr
!=
null
&&
!
breakpointStr
.
isEmpty
())
{
return
LocalDateTime
.
parse
(
breakpointStr
,
FORMATTER
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"解析Redis断点失败,初始化断点为昨天0点"
,
e
);
}
// 首次/解析失败:断点为昨天0点
LocalDate
yesterday
=
LocalDate
.
now
().
minusDays
(
1
);
return
yesterday
.
atStartOfDay
();
}
/**
* 更新断点到Redis(存储本次拉取的结束时间)
*/
private
void
updateBreakpoint
(
LocalDateTime
endTime
)
{
try
{
redisTemplate
.
opsForValue
().
set
(
QC_ORDER_BREAKPOINT_KEY
,
endTime
.
format
(
FORMATTER
));
}
catch
(
Exception
e
)
{
log
.
error
(
"更新Redis断点失败"
,
e
);
throw
new
RuntimeException
(
"更新订单拉取断点失败:"
+
e
.
getMessage
(),
e
);
}
}
private
void
processAndSaveData
(
JSONObject
order
)
{
private
void
processAndSaveData
(
JSONObject
order
)
{
qinceOrderCoreDao
.
save
(
order
);
qinceOrderCoreDao
.
save
(
order
);
...
...
src/main/java/com/sfa/job/util/QinCeUtils.java
浏览文件 @
6f5c754d
...
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
...
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.*
;
...
@@ -241,18 +242,16 @@ public class QinCeUtils {
...
@@ -241,18 +242,16 @@ public class QinCeUtils {
return
postQC
(
url
,
params
);
return
postQC
(
url
,
params
);
}
}
public
Map
<
String
,
Object
>
queryLastDayOrderParams
(
Integer
pageNum
,
Integer
rows
)
{
public
Map
<
String
,
Object
>
queryLastDayOrderParams
(
Integer
pageNum
,
Integer
rows
,
LocalDateTime
startTime
)
{
// 计算前一天
// 计算前一天
LocalDate
today
=
LocalDate
.
now
();
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDate
yesterday
=
today
.
minusDays
(
1
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
String
startTime
=
yesterday
.
atStartOfDay
().
format
(
formatter
);
String
endTime
=
now
.
format
(
formatter
);
String
endTime
=
yesterday
.
atTime
(
23
,
59
,
59
).
format
(
formatter
);
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"page_number"
,
String
.
valueOf
(
pageNum
));
params
.
put
(
"page_number"
,
String
.
valueOf
(
pageNum
));
params
.
put
(
"page_length"
,
String
.
valueOf
(
rows
));
params
.
put
(
"page_length"
,
String
.
valueOf
(
rows
));
params
.
put
(
"start_modify_date"
,
startTime
);
params
.
put
(
"start_modify_date"
,
startTime
.
format
(
formatter
)
);
params
.
put
(
"end_modify_date"
,
endTime
);
params
.
put
(
"end_modify_date"
,
endTime
);
return
params
;
return
params
;
}
}
...
@@ -260,16 +259,16 @@ public class QinCeUtils {
...
@@ -260,16 +259,16 @@ public class QinCeUtils {
/**
/**
* 拉取前一天所有订单
* 拉取前一天所有订单
*/
*/
public
JSONArray
queryLastDayAllOrder
()
throws
Exception
{
public
JSONArray
queryLastDayAllOrder
(
LocalDateTime
startTime
)
throws
Exception
{
JSONArray
allOrders
=
new
JSONArray
();
JSONArray
allOrders
=
new
JSONArray
();
int
currentPage
=
1
;
int
currentPage
=
1
;
int
pageSize
=
1000
;
int
pageSize
=
1000
;
// 循环分页拉取,直到无数据返回
// 循环分页拉取,直到无数据返回
while
(
true
)
{
while
(
true
)
{
Map
<
String
,
Object
>
params
=
queryLastDayOrderParams
(
currentPage
,
pageSize
);
Map
<
String
,
Object
>
params
=
queryLastDayOrderParams
(
currentPage
,
pageSize
,
startTime
);
String
url
=
builderUrl
(
QUERY_ORDER_DETAIL
,
params
);
String
url
=
builderUrl
(
QUERY_ORDER_DETAIL
,
params
);
log
.
info
(
"自动查询
前一天
订单 - 第{}页,请求URL:{}"
,
currentPage
,
url
);
log
.
info
(
"自动查询订单 - 第{}页,请求URL:{}"
,
currentPage
,
url
);
try
{
try
{
JSONObject
resp
=
postQC
(
url
,
params
);
JSONObject
resp
=
postQC
(
url
,
params
);
...
@@ -277,7 +276,7 @@ public class QinCeUtils {
...
@@ -277,7 +276,7 @@ public class QinCeUtils {
// 终止条件:当前页无数据,退出循环
// 终止条件:当前页无数据,退出循环
if
(
pageData
==
null
||
pageData
.
isEmpty
())
{
if
(
pageData
==
null
||
pageData
.
isEmpty
())
{
log
.
info
(
"
前一天
订单查询完成,共拉取{}页,总订单数:{}"
,
currentPage
-
1
,
allOrders
.
size
());
log
.
info
(
"订单查询完成,共拉取{}页,总订单数:{}"
,
currentPage
-
1
,
allOrders
.
size
());
break
;
break
;
}
}
...
@@ -286,7 +285,7 @@ public class QinCeUtils {
...
@@ -286,7 +285,7 @@ public class QinCeUtils {
currentPage
++;
currentPage
++;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"自动查询
前一天
订单第{}页失败"
,
currentPage
,
e
);
log
.
error
(
"自动查询订单第{}页失败"
,
currentPage
,
e
);
throw
new
RuntimeException
(
"自动分页拉取订单数据失败,页码:"
+
currentPage
,
e
);
throw
new
RuntimeException
(
"自动分页拉取订单数据失败,页码:"
+
currentPage
,
e
);
}
}
}
}
...
...
src/main/java/com/sfa/job/xxljob/order/QinceOrderInformationTask.java
浏览文件 @
6f5c754d
...
@@ -19,7 +19,7 @@ public class QinceOrderInformationTask {
...
@@ -19,7 +19,7 @@ public class QinceOrderInformationTask {
/**
/**
* 同步勤策订单数据
* 同步勤策订单数据
* 每
天 00:45:00 执行 0 45 0 * * ?
* 每
2小时拉取一次数据 00:45:00
*/
*/
@XxlJob
(
"sync_qc_order_information"
)
@XxlJob
(
"sync_qc_order_information"
)
public
void
syncQcOrderInformation
(){
public
void
syncQcOrderInformation
(){
...
@@ -31,6 +31,7 @@ public class QinceOrderInformationTask {
...
@@ -31,6 +31,7 @@ public class QinceOrderInformationTask {
XxlJobHelper
.
log
(
"xxl-job同步-勤策订单数据异常"
);
XxlJobHelper
.
log
(
"xxl-job同步-勤策订单数据异常"
);
XxlJobHelper
.
log
(
"失败信息如下:"
);
XxlJobHelper
.
log
(
"失败信息如下:"
);
XxlJobHelper
.
log
(
e
);
XxlJobHelper
.
log
(
e
);
XxlJobHelper
.
handleFail
(
"同步勤策订单失败:"
+
e
.
getMessage
());
}
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论