|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
package com.logpm.factory.jobhandler; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.logpm.factory.snm.dto.GroupByPackagesDTO; |
|
|
|
|
import com.logpm.factory.snm.entity.OrderLogEntity; |
|
|
|
@ -18,16 +18,21 @@ import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob; |
|
|
|
|
import com.xxl.job.core.log.XxlJobLogger; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springblade.common.constant.LogpmDataStatusEnum; |
|
|
|
|
import org.springblade.common.constant.PackagesTypeEnum; |
|
|
|
|
import org.springblade.common.exception.CustomerException; |
|
|
|
|
import org.springblade.common.utils.CommonUtil; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.ZoneOffset; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -69,20 +74,57 @@ public class FactoryXxlJob {
|
|
|
|
|
@XxlJob("factoryJobHandler") |
|
|
|
|
public ReturnT<String> factoryJobHandler(String param) throws Exception { |
|
|
|
|
// 获取当前时间
|
|
|
|
|
LocalDate date ; |
|
|
|
|
LocalDate date = LocalDate.now(); |
|
|
|
|
List<StationlinenumEntity> ls = stationlinenumService.lambdaQuery().eq(StationlinenumEntity::getIsDeleted, 0).eq(StationlinenumEntity::getStatus, LogpmDataStatusEnum.OPEN.getValue()).list(); |
|
|
|
|
if (!ObjectUtils.isEmpty(ls)) { |
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(param)){ |
|
|
|
|
date = LocalDate.parse(param); |
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
|
|
String startTime; |
|
|
|
|
String endTime; |
|
|
|
|
int type = 1; |
|
|
|
|
if (StringUtils.isNotBlank(param)){ |
|
|
|
|
String[] split = param.split("/"); |
|
|
|
|
if(split.length == 2){ |
|
|
|
|
startTime = split[0]; |
|
|
|
|
endTime = split[1]; |
|
|
|
|
}else{ |
|
|
|
|
throw new CustomerException(401,"参数传入有误!"); |
|
|
|
|
} |
|
|
|
|
//判断时间格式是否正确
|
|
|
|
|
boolean flagStart = CommonUtil.checkDateFormat(startTime,"yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
boolean flagEnd = CommonUtil.checkDateFormat(endTime,"yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
if(!flagStart || !flagEnd){ |
|
|
|
|
throw new CustomerException(401,"参数传入有误!"); |
|
|
|
|
} |
|
|
|
|
//设置类型为2手动
|
|
|
|
|
type = 2; |
|
|
|
|
}else{ |
|
|
|
|
date = LocalDate.now(); |
|
|
|
|
//如果参数传入为空就用当前时间作为结束时间,上一次拉取的最后一条数的结束时间为本次的开始时间
|
|
|
|
|
endTime = LocalDateTime.now().format(formatter); |
|
|
|
|
//获取最后一条数据
|
|
|
|
|
OrderLogEntity lastOne = orderLogService.selectOrderLogLastOne(); |
|
|
|
|
if (Objects.isNull(lastOne)){ |
|
|
|
|
//如果为空就暂时还没有拉取过的数据就用当天的0点为开始时间
|
|
|
|
|
Long zeroTime = LocalDate.now() |
|
|
|
|
.atStartOfDay(ZoneOffset.ofHours(8)) |
|
|
|
|
.toInstant() |
|
|
|
|
.toEpochMilli(); |
|
|
|
|
startTime = CommonUtil.datoLongToString(zeroTime, "yyyy-MM-dd HH:mm:ss", null); |
|
|
|
|
}else{ |
|
|
|
|
//如果不为空则开始时间为上一条数据的结束时间
|
|
|
|
|
String reqArgs = lastOne.getReqArgs(); |
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(reqArgs); |
|
|
|
|
startTime = jsonObject.getJSONObject("data").getString("dispatch_time_end"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//查询配置站点
|
|
|
|
|
int finalType = type; |
|
|
|
|
ls.forEach(stationlinenumEntity -> { |
|
|
|
|
// 根据站点id和当前时间调用service 请求对方接口获取数据插入到我们的数据库
|
|
|
|
|
XxlJobLogger.log("站点线路编号{}", stationlinenumEntity.getLogisticsLineNumber()); |
|
|
|
|
orderService.synOrderByLineNumData(stationlinenumEntity.getLogisticsLineNumber(), date); |
|
|
|
|
orderService.synOrderByLineNumData(stationlinenumEntity.getLogisticsLineNumber(), startTime,endTime, finalType); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
return ReturnT.SUCCESS; |
|
|
|
|