Browse Source

在库订单统计

dist.1.3.0
chenlong 9 months ago
parent
commit
86373ed48e
  1. 2
      blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java
  2. 2
      blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataDriverArteryEntity.java
  3. 2
      blade-service-api/logpm-factory-api/src/main/java/com/logpm/factory/mt/entity/MtOrderLogEntity.java
  4. 58
      blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/MtOrderLogFailRetryJob.java
  5. 29
      blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/OpFailPackageRetryJob.java
  6. 16
      blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtOrderLogFailRetryMapper.java
  7. 32
      blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtOrderLogFailRetryMapper.xml
  8. 9
      blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/service/MtOrderLogFailRetryService.java
  9. 93
      blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/service/impl/MtOrderLogFailRetryServiceImpl.java
  10. 27
      blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OpPushFailedPackageRecordServiceImpl.java

2
blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java

@ -9,7 +9,7 @@ public interface ModuleNameConstant {
/**
* 如果不需要 ""
*/
public static final String DEVAUTH ="";
public static final String DEVAUTH ="-chenlong";
/**
* 工厂对接服务名称

2
blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataDriverArteryEntity.java

@ -62,7 +62,7 @@ public class BasicdataDriverArteryEntity extends TenantEntity {
/**
* 职务类型;1-干线,2-配送
*/
@ApiModelProperty(value = "职务类型;1-干线,2-配送")
@ApiModelProperty(value = "职务类型;1-干线,2-配送,3-全部")
private String jobType;
/**
* 准驾车型;1-A1,2-A2,3-A3,4-B1,5-B2,6-C1,7-C2

2
blade-service-api/logpm-factory-api/src/main/java/com/logpm/factory/mt/entity/MtOrderLogEntity.java

@ -55,4 +55,6 @@ public class MtOrderLogEntity extends BaseEntity {
@ApiModelProperty(value = "关联值")
private String refCode;
@ApiModelProperty(value = "推送状态:1=失败,2=成功,3=失败且不在推送")
private Integer push_status;
}

58
blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/MtOrderLogFailRetryJob.java

@ -0,0 +1,58 @@
package com.logpm.factory.jobhandler;
import com.logpm.factory.mt.entity.MtOrderLogEntity;
import com.logpm.factory.mt.mapper.MtOrderLogFailRetryMapper;
import com.logpm.factory.mt.service.MtOrderLogFailRetryService;
import com.logpm.factory.oupai.entity.OpFailRetryPushPackageEntity;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
@AllArgsConstructor
public class MtOrderLogFailRetryJob {
private final MtOrderLogFailRetryService mtOrderLogFailRetryService;
private final MtOrderLogFailRetryMapper mtOrderLogFailRetryMapper;
// 多次循环处理的时候,每次最大处理的数据量
private static final Integer loopHandleQuantity = 500;
/**
* 梦天数据推送失败的进行定时重推
* @return
*/
@XxlJob("MtOrderLogFailRetryJob")
public ReturnT<String> execute(String param) {
try {
batchHandleData(null, loopHandleQuantity);
}catch (Exception exception){
log.error("OpFailPackageRetryJob error:{}",exception.getMessage());
}
return ReturnT.SUCCESS;
}
/**
* 批次处理
* @param startId
* @param quantity
*/
private void batchHandleData(Long startId, Integer quantity) {
List<MtOrderLogEntity> batchData = mtOrderLogFailRetryMapper.selectWaitData(quantity, startId);
mtOrderLogFailRetryService.retry(batchData);
if (batchData.size() == quantity) {
batchHandleData(batchData.get(quantity - 1).getId(), quantity);
}
}
}

29
blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/OpFailPackageRetryJob.java

@ -24,11 +24,8 @@ public class OpFailPackageRetryJob {
private OpFailRetryPushPackageMapper opFailRetryPushPackageMapper;
// 是否开启多线程处理
private static final boolean IsMultithreadingHandle = false;
// 多线程批次处理的时候,每次最大处理的数据量
private static final Integer batchHandleQuantity = 1000;
// 多次循环处理的时候,每次最大处理的数据量
private static final Integer loopHandleQuantity = 500;
/**
* 欧派数据推送失败的进行定时重推
@ -38,14 +35,7 @@ public class OpFailPackageRetryJob {
public ReturnT<String> execute(String param) {
try {
if (IsMultithreadingHandle) {
batchHandleData(null);
} else {
HashMap<String, Object> condition = new HashMap<>();
condition.put("push_status", PushStatus.wait.getValue());
List<OpFailRetryPushPackageEntity> opFailRetryPushPackageEntities = opFailRetryPushPackageMapper.selectByMap(condition);
opFailRetryPushPackageService.retry(opFailRetryPushPackageEntities);
}
batchHandleData(null, loopHandleQuantity);
}catch (Exception exception){
log.error("OpFailPackageRetryJob error:{}",exception.getMessage());
}
@ -56,14 +46,15 @@ public class OpFailPackageRetryJob {
/**
* 批次处理
* @param startId
* @param quantity
*/
private void batchHandleData(Long startId) {
List<OpFailRetryPushPackageEntity> batchData = opFailRetryPushPackageMapper.selectWaitData(batchHandleQuantity, startId);
if (batchData.size() == batchHandleQuantity) {
batchHandleData(batchData.get(batchHandleQuantity - 1).getId());
}
private void batchHandleData(Long startId, Integer quantity) {
List<OpFailRetryPushPackageEntity> batchData = opFailRetryPushPackageMapper.selectWaitData(quantity, startId);
opFailRetryPushPackageService.retry(batchData);
if (batchData.size() == quantity) {
batchHandleData(batchData.get(quantity - 1).getId(), quantity);
}
}
}

16
blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtOrderLogFailRetryMapper.java

@ -0,0 +1,16 @@
package com.logpm.factory.mt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.logpm.factory.mt.entity.MtOrderLogEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface MtOrderLogFailRetryMapper extends BaseMapper<MtOrderLogEntity>{
void updateStatusToCompleteByIds(List<Long> ids);
void updateStatusToExpireByIds(List<Long> ids, String date);
List<MtOrderLogEntity> selectWaitData(Integer limit, Long startId);
}

32
blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtOrderLogFailRetryMapper.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.logpm.factory.mt.mapper.MtOrderLogFailRetryMapper">
<update id="updateStatusToCompleteByIds">
UPDATE logpm_factory.mt_order_log
SET push_status = 2
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")" >
#{id}
</foreach>
</update>
<update id="updateStatusToExpireByIds">
UPDATE logpm_factory.mt_order_log
SET push_status = 3
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")" >
#{id}
</foreach>
AND create_time <![CDATA[ < ]]> #{date}
</update>
<select id="selectWaitData" resultType="com.logpm.factory.mt.entity.MtOrderLogEntity">
SELECT * FROM logpm_factory.mt_order_log
WHERE push_status = 1
<if test="startId != null">
id > #{startId}
</if>
ORDER BY id
LIMIT #{limit}
</select>
</mapper>

9
blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/service/MtOrderLogFailRetryService.java

@ -0,0 +1,9 @@
package com.logpm.factory.mt.service;
import com.logpm.factory.mt.entity.MtOrderLogEntity;
import java.util.List;
public interface MtOrderLogFailRetryService {
void retry(List<MtOrderLogEntity> waitData);
}

93
blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/service/impl/MtOrderLogFailRetryServiceImpl.java

@ -0,0 +1,93 @@
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.logpm.factory.mt.entity.MtOrderLogEntity;
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 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;
@Slf4j
@Service
@AllArgsConstructor
public class MtOrderLogFailRetryServiceImpl implements MtOrderLogFailRetryService {
protected OpFailRetryPushPackageMapper opFailRetryPushPackageMapper;
protected IOuPaiFactoryService ouPaiFactoryService;
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<>();
waitData.forEach(opFailRetryPushPackageEntity -> executeRetry(opFailRetryPushPackageEntity, completeIds, failIds));
updatePushStatus(completeIds, failIds);
}
/**
* 更新推送状态
* @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());
}
}
/**
* 获取过期的时间
*
* @return
*/
protected String getExpireTime(){
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");
return sdf.format(calendar.getTime());
}
/**
* 执行重试
* @param mtOrderLogEntity
* @param completeIds
*/
protected void executeRetry(MtOrderLogEntity mtOrderLogEntity, ArrayList<Long> completeIds, ArrayList<Long> failIds) {
try {
OrderStatusDTO orderStatusDTO = new Gson().fromJson(mtOrderLogEntity.getResBody(), OrderStatusDTO.class);
boolean res = ouPaiFactoryService.retryHandleStatusData(orderStatusDTO);
if (res) {
completeIds.add(mtOrderLogEntity.getId());
} else {
failIds.add(mtOrderLogEntity.getId());
}
} catch (Exception e) {
log.error("executeRetry error: {}", e.getMessage());
}
}
}

27
blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OpPushFailedPackageRecordServiceImpl.java

@ -11,7 +11,6 @@ import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
@Slf4j
@Service
@ -19,6 +18,17 @@ import java.util.HashMap;
public class OpPushFailedPackageRecordServiceImpl extends BaseServiceImpl<OpFailRetryPushPackageMapper,OpFailRetryPushPackageEntity> implements OpPushFailedPackageRecordService {
/**
* 入库类型
*/
public static final Integer IN_OF_WAREHOUSE_TYPE = 1;
/**
* 出库类型
*/
public static final Integer OUT_OF_WAREHOUSE_TYPE = 2;
/**
* 记录失败的数据
*
@ -35,6 +45,21 @@ public class OpPushFailedPackageRecordServiceImpl extends BaseServiceImpl<OpFai
opFailRetryPushPackageEntity.setParams(new Gson().toJson(orderStatusDTO));
opFailRetryPushPackageEntity.setCreateTime(new Date());
/*
* 状态14=入库7=出库
*/
if ("1".equals(orderStatusDTO.getStatus()) || "4".equals(orderStatusDTO.getStatus())) {
opFailRetryPushPackageEntity.setType(IN_OF_WAREHOUSE_TYPE);
}
if ("7".equals(orderStatusDTO.getStatus())) {
opFailRetryPushPackageEntity.setType(OUT_OF_WAREHOUSE_TYPE);
}
// 没有设置类型时(无法判断出库入库),跳过,不保存
if (opFailRetryPushPackageEntity.getType() == null) {
return;
}
// 判重
// HashMap<String, Object> queryMap = new HashMap<>();
// queryMap.put("orderPackageCode", orderPackageCode);

Loading…
Cancel
Save