优化dou订单拉取

This commit is contained in:
启航
2026-01-22 09:19:57 +08:00
parent 3b924ad2ac
commit d04a16b7fa
7 changed files with 119 additions and 80 deletions
+1 -1
View File
@@ -118,7 +118,7 @@
<artifactId>open-sdk</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/open-sdk-2.1.9.jar</systemPath>
<systemPath>${project.basedir}/libs/open-sdk-2.1.10.jar</systemPath>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
@@ -7,4 +7,5 @@ public class DouPullRequest {
private Long shopId;//店铺Id
private Integer pullType;//拉取类型:0或不传全量;1更新(用于拉取商品的条件)
private String orderId;
private String orderDate;
}
@@ -24,6 +24,7 @@ import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.time.Duration;
@@ -33,6 +34,8 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 订单更新
@@ -48,6 +51,10 @@ public class DouOrderApiController {
private final MqUtils mqUtils;
private final OShopPullLogsService pullLogsService;
private final OShopPullLasttimeService pullLasttimeService;
private final String DATE_PATTERN =
"^(?:(?:(?:\\d{4}-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|1\\d|2[0-8]))|(?:(?:(?:\\d{2}(?:0[48]|[2468][048]|[13579][26])|(?:(?:0[48]|[2468][048]|[13579][26])00))-0?2-29))$)|(?:(?:(?:\\d{4}-(?:0?[13578]|1[02]))-(?:0?[1-9]|[12]\\d|30))$)|(?:(?:(?:\\d{4}-0?[13-9]|1[0-2])-(?:0?[1-9]|[1-2]\\d|30))$)|(?:(?:(?:\\d{2}(?:0[48]|[13579][26]|[2468][048])|(?:(?:0[48]|[13579][26]|[2468][048])00))-0?2-29))$)$";
private final Pattern DATE_FORMAT = Pattern.compile(DATE_PATTERN);
/**
* 增量更新订单
* @param req
@@ -61,6 +68,18 @@ public class DouOrderApiController {
if (req.getShopId() == null || req.getShopId() <= 0) {
return AjaxResult.error(HttpStatus.PARAMS_ERROR, "参数错误,没有店铺Id");
}
if(StringUtils.isEmpty(req.getOrderDate())) return AjaxResult.error("参数错误,没有下单日期");
String orderDate = null;
if(StringUtils.hasText(req.getOrderDate())) {
// 判断时间格式
Matcher matcher = DATE_FORMAT.matcher(req.getOrderDate());
boolean b = matcher.find();
if (!b) {
return AjaxResult.error("下单日期格式错误");
}
orderDate = req.getOrderDate();
}
Date currDateTime = new Date();
Long currTimeMillis = System.currentTimeMillis();
@@ -73,34 +92,37 @@ public class DouOrderApiController {
String appSecret = checkResult.getData().getAppSecret();
Long douShopId = checkResult.getData().getSellerId();
String accessToken = checkResult.getData().getAccessToken();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 获取最后更新时间
LocalDateTime startTime = null;
LocalDateTime endTime = null;
OShopPullLasttime lasttime = pullLasttimeService.getLasttimeByShop(req.getShopId(), "ORDER");
if(lasttime == null){
endTime = LocalDateTime.now();
startTime = endTime.minusDays(1);
}else {
startTime = lasttime.getLasttime().minusHours(1);//取上次结束一个小时前
Duration duration = Duration.between(startTime, LocalDateTime.now());
long hours = duration.toHours();
if (hours > 24) {
// 大于24小时,只取24小时
endTime = startTime.plusHours(24);
} else {
endTime = LocalDateTime.now();
}
// endTime = startTime.plusDays(1);//取24小时
// if(endTime.isAfter(LocalDateTime.now())){
startTime = LocalDateTime.parse(orderDate + " 00:00:01", formatter);
endTime = LocalDateTime.parse(orderDate + " 23:59:59", formatter);
// OShopPullLasttime lasttime = pullLasttimeService.getLasttimeByShop(req.getShopId(), "ORDER");
// if(lasttime == null){
// endTime = LocalDateTime.now();
// startTime = endTime.minusDays(1);
// }else {
// startTime = lasttime.getLasttime().minusHours(1);//取上次结束一个小时前
// Duration duration = Duration.between(startTime, LocalDateTime.now());
// long hours = duration.toHours();
// if (hours > 24) {
// // 大于24小时,只取24小时
// endTime = startTime.plusHours(24);
// } else {
// endTime = LocalDateTime.now();
// }
}
String startTimeStr = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String endTimeStr = endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//// endTime = startTime.plusDays(1);//取24小时
//// if(endTime.isAfter(LocalDateTime.now())){
//// endTime = LocalDateTime.now();
//// }
// }
// String startTimeStr = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
// String endTimeStr = endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
Long startTimestamp = startTime.toEpochSecond(ZoneOffset.ofHours(8));
Long endTimestamp = endTime.toEpochSecond(ZoneOffset.ofHours(8));
String pullParams = "{startTime:"+startTime+",endTime:"+endTime+"}";
String pullParams = "{startTime:"+startTime.format(formatter)+",endTime:"+endTime.format(formatter)+"}";
// ApiResultVo<Token> token = DouTokenApiHelper.getToken(appKey, appSecret,checkResult.getData().getSellerId());
//
// if(token.getCode()==0) {
@@ -176,25 +198,25 @@ public class DouOrderApiController {
}
}
if(totalError==0) {
if (lasttime == null) {
// 新增
OShopPullLasttime insertLasttime = new OShopPullLasttime();
insertLasttime.setShopId(req.getShopId());
insertLasttime.setCreateTime(new Date());
insertLasttime.setLasttime(endTime);
insertLasttime.setPullType("ORDER");
pullLasttimeService.save(insertLasttime);
} else {
// 修改
OShopPullLasttime updateLasttime = new OShopPullLasttime();
updateLasttime.setId(lasttime.getId());
updateLasttime.setUpdateTime(new Date());
updateLasttime.setLasttime(endTime);
pullLasttimeService.updateById(updateLasttime);
}
}
// if(totalError==0) {
// if (lasttime == null) {
// // 新增
// OShopPullLasttime insertLasttime = new OShopPullLasttime();
// insertLasttime.setShopId(req.getShopId());
// insertLasttime.setCreateTime(new Date());
// insertLasttime.setLasttime(endTime);
// insertLasttime.setPullType("ORDER");
// pullLasttimeService.save(insertLasttime);
//
// } else {
// // 修改
// OShopPullLasttime updateLasttime = new OShopPullLasttime();
// updateLasttime.setId(lasttime.getId());
// updateLasttime.setUpdateTime(new Date());
// updateLasttime.setLasttime(endTime);
// pullLasttimeService.updateById(updateLasttime);
// }
// }
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
OShopPullLogs logs = new OShopPullLogs();
logs.setShopType(EnumShopType.DOU.getIndex());
@@ -28,7 +28,7 @@ public class DouOrderContoller extends BaseController {
private final DouOrderService orderService;
private final MqUtils mqUtils;
@RequestMapping(value = "/list", method = RequestMethod.GET)
public TableDataInfo goodsList(DouOrderBo bo, PageQuery pageQuery) {
public TableDataInfo orderList(DouOrderBo bo, PageQuery pageQuery) {
PageResult<DouOrder> result = orderService.queryPageList(bo, pageQuery);
return getDataTable(result);
@@ -26,6 +26,9 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
@@ -52,31 +55,38 @@ public class DouOrderServiceImpl extends ServiceImpl<DouOrderMapper, DouOrder>
private final Pattern DATE_FORMAT = Pattern.compile(DATE_PATTERN);
@Override
public PageResult<DouOrder> queryPageList(DouOrderBo bo, PageQuery pageQuery) {
long startTimeStamp = 0;
long endTimeStamp = 0;
if(StringUtils.hasText(bo.getStartTime())){
Matcher matcher = DATE_FORMAT.matcher(bo.getStartTime());
boolean b = matcher.find();
if(b){
bo.setStartTime(bo.getStartTime()+" 00:00:00");
startTimeStamp = DateUtils.dateTimeStrToTimeStamp(null,bo.getStartTime());
}
}
if(StringUtils.hasText(bo.getEndTime())){
Matcher matcher = DATE_FORMAT.matcher(bo.getEndTime());
boolean b = matcher.find();
if(b){
bo.setEndTime(bo.getEndTime()+" 23:59:59");
endTimeStamp = DateUtils.dateTimeStrToTimeStamp(null,bo.getEndTime());
}
}else{
bo.setEndTime(bo.getStartTime()+" 23:59:59");
}
if(StringUtils.hasText(bo.getStartTime())){
Matcher matcher = DATE_FORMAT.matcher(bo.getStartTime());
boolean b = matcher.find();
if(b){
bo.setStartTime(bo.getStartTime()+" 00:00:00");
}
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startTime = LocalDateTime.parse(bo.getStartTime(), formatter);
LocalDateTime endTime = LocalDateTime.parse(bo.getEndTime(), formatter);
Long startTimestamp = startTime.toEpochSecond(ZoneOffset.ofHours(8));
Long endTimestamp = endTime.toEpochSecond(ZoneOffset.ofHours(8));
LambdaQueryWrapper<DouOrder> queryWrapper = new LambdaQueryWrapper<DouOrder>()
.eq(bo.getShopId()!=null,DouOrder::getShopId,bo.getShopId())
.eq(StringUtils.hasText(bo.getOrderId()),DouOrder::getOrderId,bo.getOrderId())
.eq(StringUtils.hasText(bo.getOrderStatus()),DouOrder::getOrderStatus,bo.getOrderStatus())
.ge(StringUtils.hasText(bo.getStartTime()),DouOrder::getCreateTime, startTimeStamp)
.le(StringUtils.hasText(bo.getEndTime()),DouOrder::getCreateTime,endTimeStamp)
.ge(StringUtils.hasText(bo.getStartTime()),DouOrder::getCreateTime, startTimestamp)
.le(StringUtils.hasText(bo.getEndTime()),DouOrder::getCreateTime,endTimestamp)
;
pageQuery.setOrderByColumn("create_time");
pageQuery.setIsAsc("desc");
+32 -26
View File
@@ -458,34 +458,40 @@ export default {
this.multiple = !selection.length
},
handlePull() {
if(this.queryParams.shopId){
this.pullLoading = true
pullOrder({shopId:this.queryParams.shopId,updType:0}).then(response => {
console.log('拉取dou订单接口返回=====',response)
if(response.code === 1401) {
MessageBox.confirm('Token已过期,需要重新授权!请前往店铺列表重新获取授权!', '系统提示', { confirmButtonText: '前往授权', cancelButtonText: '取消', type: 'warning' }).then(() => {
this.$router.push({path:"/shop/shop_list",query:{type:400}})
// isRelogin.show = false;
// store.dispatch('LogOut').then(() => {
// location.href = response.data.tokenRequestUrl+'?shopId='+this.queryParams.shopId
// })
}).catch(() => {
isRelogin.show = false;
});
// return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
}else{
this.$modal.msgSuccess(JSON.stringify(response));
this.getList()
this.pullLoading = false
}
this.pullLoading = false
})
}else{
this.$modal.msgSuccess("请先选择店铺");
if (!this.queryParams.shopId) {
this.$modal.msgError("请先选择店铺");
return
}
if (!this.queryParams.startTime) {
this.$modal.msgError("请选择下单时间")
return
}
this.pullLoading = true
pullOrder({ shopId: this.queryParams.shopId, updType: 0,orderDate: this.queryParams.startTime }).then(response => {
console.log('拉取dou订单接口返回=====', response)
if (response.code === 1401) {
MessageBox.confirm('Token已过期,需要重新授权!请前往店铺列表重新获取授权!', '系统提示', {
confirmButtonText: '前往授权',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$router.push({ path: "/shop/shop_list", query: { type: 400 } })
// isRelogin.show = false;
// store.dispatch('LogOut').then(() => {
// location.href = response.data.tokenRequestUrl+'?shopId='+this.queryParams.shopId
// })
}).catch(() => {
isRelogin.show = false;
});
// this.$modal.msgSuccess("请先配置API");
// return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
} else {
this.$modal.msgSuccess(JSON.stringify(response));
this.getList()
this.pullLoading = false
}
this.pullLoading = false
})
},
handlePullUpdate(row) {
// 接口拉取订单并更新