|
|
|
@ -1,19 +1,18 @@
|
|
|
|
|
package com.logpm.factory.mt.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.Gson; |
|
|
|
|
import com.logpm.factory.comfac.dto.OrderStatusDTO; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.logpm.factory.mt.entity.MtOrderLogEntity; |
|
|
|
|
import com.logpm.factory.mt.mapper.MtOrderLogFailRetryMapper; |
|
|
|
|
import com.logpm.factory.mt.service.IMtFactoryDataService; |
|
|
|
|
import com.logpm.factory.mt.service.IMtOrderLogService; |
|
|
|
|
import com.logpm.factory.mt.service.MtOrderLogFailRetryService; |
|
|
|
|
import com.logpm.factory.oupai.entity.OpFailRetryPushPackageEntity; |
|
|
|
|
import com.logpm.factory.oupai.mapper.OpFailRetryPushPackageMapper; |
|
|
|
|
import com.logpm.factory.oupai.service.IOuPaiFactoryService; |
|
|
|
|
import com.logpm.factory.props.MtFactoryProperties; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Calendar; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
@ -22,72 +21,105 @@ import java.util.List;
|
|
|
|
|
@Service |
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class MtOrderLogFailRetryServiceImpl implements MtOrderLogFailRetryService { |
|
|
|
|
protected OpFailRetryPushPackageMapper opFailRetryPushPackageMapper; |
|
|
|
|
protected final MtOrderLogFailRetryMapper mtOrderLogFailRetryMapper; |
|
|
|
|
|
|
|
|
|
protected IOuPaiFactoryService ouPaiFactoryService; |
|
|
|
|
protected final IMtFactoryDataService mtFactoryDataService; |
|
|
|
|
protected final MtFactoryProperties mtFactoryProperties; |
|
|
|
|
private final IMtOrderLogService mtOrderLogService; |
|
|
|
|
|
|
|
|
|
protected final int MAX_RETRY_TIMES = 7; |
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
|
@Override |
|
|
|
|
public void retry(List<MtOrderLogEntity> waitData){ |
|
|
|
|
ArrayList<Long> completeIds = new ArrayList<>(); |
|
|
|
|
ArrayList<Long> failIds = new ArrayList<>(); |
|
|
|
|
/** |
|
|
|
|
* 收获入库 |
|
|
|
|
*/ |
|
|
|
|
protected final Integer SH_IN_OF_WAREHOUSE_TYPE = 1; |
|
|
|
|
|
|
|
|
|
waitData.forEach(opFailRetryPushPackageEntity -> executeRetry(opFailRetryPushPackageEntity, completeIds, failIds)); |
|
|
|
|
/** |
|
|
|
|
* 入库 |
|
|
|
|
*/ |
|
|
|
|
protected final Integer IN_OF_WAREHOUSE_TYPE = 2; |
|
|
|
|
|
|
|
|
|
updatePushStatus(completeIds, failIds); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 卸车确认 |
|
|
|
|
*/ |
|
|
|
|
protected final Integer UNLOAD_CAR_CONFIRM_TYPE = 4; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 更新推送状态 |
|
|
|
|
* @param completeIds |
|
|
|
|
* @param failIds |
|
|
|
|
* 文员确认 |
|
|
|
|
*/ |
|
|
|
|
protected void updatePushStatus(ArrayList<Long> completeIds, ArrayList<Long> failIds){ |
|
|
|
|
if (!completeIds.isEmpty()) { |
|
|
|
|
opFailRetryPushPackageMapper.updateStatusToCompleteByIds(completeIds); |
|
|
|
|
} |
|
|
|
|
if (!failIds.isEmpty()) { |
|
|
|
|
opFailRetryPushPackageMapper.updateStatusToExpireByIds(failIds, getExpireTime()); |
|
|
|
|
} |
|
|
|
|
protected final Integer VOLUNTEER_CONFIRM_TYPE = 5; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 签收 |
|
|
|
|
*/ |
|
|
|
|
protected final Integer SIGN_TYPE = 6; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
|
@Override |
|
|
|
|
public void retry(List<MtOrderLogEntity> waitData){ |
|
|
|
|
waitData.forEach(this::executeRetry); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取过期的时间 |
|
|
|
|
* |
|
|
|
|
* 判断是否过期 |
|
|
|
|
* @param date |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
protected String getExpireTime(){ |
|
|
|
|
protected boolean isExpire(Date date){ |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
Date date = new Date(); |
|
|
|
|
|
|
|
|
|
calendar.setTime(date); |
|
|
|
|
calendar.add(Calendar.DATE, -MAX_RETRY_TIMES); |
|
|
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
calendar.add(Calendar.DATE, MAX_RETRY_TIMES); |
|
|
|
|
|
|
|
|
|
return sdf.format(calendar.getTime()); |
|
|
|
|
return calendar.getTimeInMillis() < System.currentTimeMillis(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 执行重试 |
|
|
|
|
* @param mtOrderLogEntity |
|
|
|
|
* @param completeIds |
|
|
|
|
*/ |
|
|
|
|
protected void executeRetry(MtOrderLogEntity mtOrderLogEntity, ArrayList<Long> completeIds, ArrayList<Long> failIds) { |
|
|
|
|
protected void executeRetry(MtOrderLogEntity mtOrderLogEntity) { |
|
|
|
|
try { |
|
|
|
|
OrderStatusDTO orderStatusDTO = new Gson().fromJson(mtOrderLogEntity.getResBody(), OrderStatusDTO.class); |
|
|
|
|
String requestUrl = getRequestUrl(mtOrderLogEntity); |
|
|
|
|
|
|
|
|
|
String result = mtFactoryDataService.retryPushMtFactoryData(requestUrl, mtOrderLogEntity.getReqArgs()); |
|
|
|
|
|
|
|
|
|
boolean res = ouPaiFactoryService.retryHandleStatusData(orderStatusDTO); |
|
|
|
|
mtOrderLogEntity.setResBody(result); |
|
|
|
|
|
|
|
|
|
if (res) { |
|
|
|
|
completeIds.add(mtOrderLogEntity.getId()); |
|
|
|
|
Integer PUSH_STATUS_SUCCESS = 1; |
|
|
|
|
Integer PUSH_STATUS_FAIL = 2; |
|
|
|
|
Integer PUSH_STATUS_EXPIRE = 3; |
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result); |
|
|
|
|
|
|
|
|
|
if (jsonObject == null || jsonObject.isEmpty() || 0 != jsonObject.getInteger("code")) { |
|
|
|
|
mtOrderLogEntity.setPushStatus( |
|
|
|
|
isExpire(mtOrderLogEntity.getCreateTime()) ? PUSH_STATUS_EXPIRE : PUSH_STATUS_FAIL |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
failIds.add(mtOrderLogEntity.getId()); |
|
|
|
|
mtOrderLogEntity.setPushStatus(PUSH_STATUS_SUCCESS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 由于要存储每次的响应结果,所以每次请求后都立即保存
|
|
|
|
|
mtOrderLogService.save(mtOrderLogEntity); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("executeRetry error: {}", e.getMessage()); |
|
|
|
|
log.error("梦天重推 error: {}", e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getRequestUrl(MtOrderLogEntity mtOrderLogEntity) { |
|
|
|
|
String url = null; |
|
|
|
|
if (IN_OF_WAREHOUSE_TYPE.equals(mtOrderLogEntity.getType()) || SH_IN_OF_WAREHOUSE_TYPE.equals(mtOrderLogEntity.getType()) ) { |
|
|
|
|
url = mtFactoryProperties.getUrl() + "/ZXCFaHuoDan/ShouHuoRuKu"; |
|
|
|
|
}else if (UNLOAD_CAR_CONFIRM_TYPE.equals(mtOrderLogEntity.getType())) { |
|
|
|
|
url = mtFactoryProperties.getUrl() + "/ZXCFaHuoDan/QueRenShouHuo"; |
|
|
|
|
}else if (VOLUNTEER_CONFIRM_TYPE.equals(mtOrderLogEntity.getType())){ |
|
|
|
|
url = mtFactoryProperties.getUrl() + "/ZXCFaHuoDan/QianShouDanNew"; |
|
|
|
|
}else if (SIGN_TYPE.equals(mtOrderLogEntity.getType())){ |
|
|
|
|
url = mtFactoryProperties.getUrl() + "/ZXCFaHuoDan/QianShouScan"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return url; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|