Browse Source

增加数据状态推送失败后定时任务重新获取的功能

single_db
pref_mail@163.com 1 year ago
parent
commit
3ec5d3766f
  1. 2
      blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java
  2. 5
      blade-biz-common/src/main/java/org/springblade/common/constant/RedisKeyConstant.java
  3. 4
      blade-ops/blade-xxljob-admin/src/main/java/com/xxl/job/admin/JobAdminApplication.java
  4. 168
      blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/FactoryCommonServiceImpl.java
  5. 56
      blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/OrderPackageStatusFallJob.java
  6. 28
      blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/DealWithDataHandler.java

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

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

5
blade-biz-common/src/main/java/org/springblade/common/constant/RedisKeyConstant.java

@ -8,5 +8,10 @@ public class RedisKeyConstant {
*/ */
public static final String cache_oupai_key ="cache:oupai-key:"; public static final String cache_oupai_key ="cache:oupai-key:";
/**
* 缓存老系统没有解析成功的数据
*/
public static final String CACHE_OLD_SYSTEM_ORDERPACKAGE_KEY ="cache:old-system-orderpackage-key:";
} }

4
blade-ops/blade-xxljob-admin/src/main/java/com/xxl/job/admin/JobAdminApplication.java

@ -11,7 +11,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class JobAdminApplication { public class JobAdminApplication {
public static void main(String[] args) { public static void main(String[] args) {
BladeApplication.run(LauncherConstant.APPLICATION_XXLJOB_ADMIN_NAME, JobAdminApplication.class, args);
BladeApplication.run("blade-xxljob-pref", JobAdminApplication.class, args);
} }
} }

168
blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/FactoryCommonServiceImpl.java

@ -1,6 +1,7 @@
package com.logpm.factory.comfac.service.impl; package com.logpm.factory.comfac.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.logpm.basicdata.entity.BasicdataTrayEntity; import com.logpm.basicdata.entity.BasicdataTrayEntity;
import com.logpm.basicdata.entity.BasicdataWarehouseEntity; import com.logpm.basicdata.entity.BasicdataWarehouseEntity;
import com.logpm.basicdata.feign.IBasicdataTrayClient; import com.logpm.basicdata.feign.IBasicdataTrayClient;
@ -18,13 +19,16 @@ import com.logpm.warehouse.feign.IWarehouseTrayTypeClient;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.common.constant.OldSystemDataPushConfig; import org.springblade.common.constant.OldSystemDataPushConfig;
import org.springblade.common.constant.RedisKeyConstant;
import org.springblade.common.exception.CustomerException; import org.springblade.common.exception.CustomerException;
import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.sql.Wrapper;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -50,27 +54,27 @@ public class FactoryCommonServiceImpl implements IFactoryCommonService {
public void syncTrayTypeData(String unitNo, Integer trayId, String oldWarehouseId) { public void syncTrayTypeData(String unitNo, Integer trayId, String oldWarehouseId) {
//先判断是否两个数据已经执行完成 //先判断是否两个数据已经执行完成
String ruku = bladeRedis.get("arrive-"+unitNo); String ruku = bladeRedis.get("arrive-" + unitNo);
trayId = bladeRedis.get("tray-"+unitNo); trayId = bladeRedis.get("tray-" + unitNo);
if(StringUtil.isBlank(ruku) || Objects.isNull(trayId)){ if (StringUtil.isBlank(ruku) || Objects.isNull(trayId)) {
log.error("###############syncTrayTypeData: 数据不完整,暂不打托 ruku={} trayId={}",ruku,trayId); log.error("###############syncTrayTypeData: 数据不完整,暂不打托 ruku={} trayId={}", ruku, trayId);
throw new CustomerException(403,"数据不完整,暂不打托"); throw new CustomerException(403, "数据不完整,暂不打托");
} }
log.info("###############syncTrayTypeData: 包件打托开始 unitNo={} trayId={} oldWarehouseId={}",unitNo,trayId,oldWarehouseId); log.info("###############syncTrayTypeData: 包件打托开始 unitNo={} trayId={} oldWarehouseId={}", unitNo, trayId, oldWarehouseId);
//先判断新系统仓库信息是否存在 //先判断新系统仓库信息是否存在
BasicdataWarehouseEntity warehouseEntity = basicdataWarehouseClient.getWarehouseByOldId(Integer.parseInt(oldWarehouseId)); BasicdataWarehouseEntity warehouseEntity = basicdataWarehouseClient.getWarehouseByOldId(Integer.parseInt(oldWarehouseId));
if(Objects.isNull(warehouseEntity)){ if (Objects.isNull(warehouseEntity)) {
log.error("###############syncTrayTypeData: 仓库信息不存在 oldWarehouseId={}",oldWarehouseId); log.error("###############syncTrayTypeData: 仓库信息不存在 oldWarehouseId={}", oldWarehouseId);
throw new CustomerException(403,"仓库信息不存在"); throw new CustomerException(403, "仓库信息不存在");
} }
Long newWarehouseId = warehouseEntity.getId(); Long newWarehouseId = warehouseEntity.getId();
//判断托盘是否已经存在 //判断托盘是否已经存在
BasicdataTrayEntity basicdataTrayEntity = basicdataTrayClient.getTrayByTrayCode("T" + trayId); BasicdataTrayEntity basicdataTrayEntity = basicdataTrayClient.getTrayByTrayCode("T" + trayId);
if(Objects.isNull(basicdataTrayEntity)){ if (Objects.isNull(basicdataTrayEntity)) {
log.info("############syncTrayTypeData: 托盘信息不存在"); log.info("############syncTrayTypeData: 托盘信息不存在");
//如果托盘不存在就去同步该托盘 //如果托盘不存在就去同步该托盘
TrayEntity trayEntity = trayClient.getTrayById(trayId); TrayEntity trayEntity = trayClient.getTrayById(trayId);
@ -80,9 +84,9 @@ public class FactoryCommonServiceImpl implements IFactoryCommonService {
basicdataTrayEntity.setUpdateUser(1714696768639311873L); basicdataTrayEntity.setUpdateUser(1714696768639311873L);
basicdataTrayEntity.setCreateDept(1649331096241836033L); basicdataTrayEntity.setCreateDept(1649331096241836033L);
basicdataTrayEntity.setPalletName(trayEntity.getTrayNo()); basicdataTrayEntity.setPalletName(trayEntity.getTrayNo());
basicdataTrayEntity.setPalletCode("T"+trayEntity.getId()); basicdataTrayEntity.setPalletCode("T" + trayEntity.getId());
basicdataTrayEntity.setWarehouseId(newWarehouseId); basicdataTrayEntity.setWarehouseId(newWarehouseId);
basicdataTrayEntity.setTrayStatus(trayEntity.getStatus()+""); basicdataTrayEntity.setTrayStatus(trayEntity.getStatus() + "");
basicdataTrayEntity.setType(1); basicdataTrayEntity.setType(1);
basicdataTrayEntity.setOldId(trayId); basicdataTrayEntity.setOldId(trayId);
// basicdataTrayEntity.setNowWarehouseId(nowNewWarehouseId); // basicdataTrayEntity.setNowWarehouseId(nowNewWarehouseId);
@ -90,40 +94,40 @@ public class FactoryCommonServiceImpl implements IFactoryCommonService {
} }
//把包件打托到托盘上 //把包件打托到托盘上
TrayScanEntity trayScanEntity = trayScanClient.getEntityByTrayIdAndOldWarehouseIdAndBindStatus(trayId,oldWarehouseId,1); TrayScanEntity trayScanEntity = trayScanClient.getEntityByTrayIdAndOldWarehouseIdAndBindStatus(trayId, oldWarehouseId, 1);
String trayType = "100"; String trayType = "100";
if(!Objects.isNull(trayScanEntity)){ if (!Objects.isNull(trayScanEntity)) {
Integer type = trayScanEntity.getType(); Integer type = trayScanEntity.getType();
if(1==type){ if (1 == type) {
trayType = "60"; trayType = "60";
}else if(2==type){ } else if (2 == type) {
trayType = "30"; trayType = "30";
}else if(3==type){ } else if (3 == type) {
trayType = "50"; trayType = "50";
}else if(4==type){ } else if (4 == type) {
trayType = "100"; trayType = "100";
}else if(5==type){ } else if (5 == type) {
trayType = "10"; trayType = "10";
}else if(6==type){ } else if (6 == type) {
trayType = "20"; trayType = "20";
} }
} }
Map<String,Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("trayType",trayType); map.put("trayType", trayType);
map.put("trayCode","T"+trayId); map.put("trayCode", "T" + trayId);
map.put("warehouseId",newWarehouseId); map.put("warehouseId", newWarehouseId);
map.put("orderPackageCode",unitNo); map.put("orderPackageCode", unitNo);
//新系统保存打托方式 //新系统保存打托方式
boolean b = warehouseTrayTypeClient.orderScanOrderPackageCode(map); boolean b = warehouseTrayTypeClient.orderScanOrderPackageCode(map);
if(!b){ if (!b) {
log.error("################syncTrayTypeData: 包件打托失败 unitNo={} trayCode={}",unitNo,"T"+trayId); log.error("################syncTrayTypeData: 包件打托失败 unitNo={} trayCode={}", unitNo, "T" + trayId);
throw new CustomerException(403,"包件打托失败"); throw new CustomerException(403, "包件打托失败");
} }
log.info("################syncTrayTypeData: 包件打托成功 unitNo={}",unitNo); log.info("################syncTrayTypeData: 包件打托成功 unitNo={}", unitNo);
} }
@ -134,67 +138,69 @@ public class FactoryCommonServiceImpl implements IFactoryCommonService {
//查询destinationWarehouse logiBillNo plantId数据 //查询destinationWarehouse logiBillNo plantId数据
Map<String, String> supplyData = advanceDetailClient.getSupplyData(unitNo); Map<String, String> supplyData = advanceDetailClient.getSupplyData(unitNo);
if (supplyData == null) { if (!supplyData.isEmpty()) {
log.error("##############dealWithDataHandler: unitNo={} 没有查询到数据", unitNo); log.error("##############dealWithDataHandler: unitNo={} 没有查询到数据", unitNo);
// 保存到数据库 // 保存到数据库
// orderPackageStatusPushFailLogMapper.selectList() String destinationWarehouseId = supplyData.get("destinationWarehouseId");//目的仓id
if (StringUtil.isBlank(currentWarehouseId) || StringUtil.isBlank(destinationWarehouseId)) {
OrderPackageStatusPushFailLogEntity orderPackageStatusPushFailLogEntity=new OrderPackageStatusPushFailLogEntity(); log.warn("##############dealWithDataHandler: 仓库数据有问题currentWarehouseId={} destinationWarehouseId={}", currentWarehouseId, destinationWarehouseId);
orderPackageStatusPushFailLogEntity.setOrderPackageStatus(status); throw new CustomerException(405, "仓库数据有误");
orderPackageStatusPushFailLogEntity.setUnitNo(unitNo);
orderPackageStatusPushFailLogEntity.setWarehouseId(currentWarehouseId);
orderPackageStatusPushFailLogEntity.setOperationTime(operationTime);
orderPackageStatusPushFailLogEntity.setTrayId(trayId);
orderPackageStatusPushFailLogEntity.setDataStatus(0);
// 插入之前判断这条数据是否存在系统中
orderPackageStatusPushFailLogMapper.insert(orderPackageStatusPushFailLogEntity);
// 执行定时任务
return;
}
String destinationWarehouseId = supplyData.get("destinationWarehouseId");//目的仓id
if (StringUtil.isBlank(currentWarehouseId) || StringUtil.isBlank(destinationWarehouseId)) {
log.warn("##############dealWithDataHandler: 仓库数据有问题currentWarehouseId={} destinationWarehouseId={}", currentWarehouseId, destinationWarehouseId);
throw new CustomerException(405, "仓库数据有误");
} else {
if (!currentWarehouseId.equals(destinationWarehouseId)) {
log.info("##############dealWithDataHandler: 不用处理的状态 currentWarehouseId={} destinationWarehouseId={}", currentWarehouseId, destinationWarehouseId);
// channel.basicAck(deliveryTag,false);
} else { } else {
//真正的处理需要的数据 if (!currentWarehouseId.equals(destinationWarehouseId)) {
log.info("##############dealWithDataHandler: 不用处理的状态 currentWarehouseId={} destinationWarehouseId={}", currentWarehouseId, destinationWarehouseId);
if(OldSystemDataPushConfig.getWarehourseIdList().contains(currentWarehouseId)){ // channel.basicAck(deliveryTag,false);
} else {
try { //真正的处理需要的数据
if ("1".equals(status)) { if (OldSystemDataPushConfig.getWarehourseIdList().contains(currentWarehouseId)) {
try {
// 始发仓和目的仓入库 if ("1".equals(status)) {
panFactoryDataService.handleDataToPlatform(unitNo, operationTime);
bladeRedis.setEx("tray-" + unitNo, trayId, 30L); // 始发仓和目的仓入库
panFactoryDataService.handleDataToPlatform(unitNo, operationTime);
} else if ("4".equals(status)) { bladeRedis.setEx("tray-" + unitNo, trayId, 30L);
panFactoryDataService.handleDataToPlatform(unitNo, operationTime);
} else if ("2".equals(status)) { } else if ("4".equals(status)) {
bladeRedis.setEx("tray-" + unitNo, trayId, 30L); panFactoryDataService.handleDataToPlatform(unitNo, operationTime);
} else { } else if ("2".equals(status)) {
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>> 错误的状态"); bladeRedis.setEx("tray-" + unitNo, trayId, 30L);
} else {
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>> 错误的状态");
}
//同步打托数据
syncTrayTypeData(unitNo, trayId, currentWarehouseId);
} catch (Exception e) {
log.error(e.getMessage());
} }
//同步打托数据
syncTrayTypeData(unitNo, trayId, currentWarehouseId);
} catch (Exception e) {
log.error(e.getMessage());
} }
} }
} }
} else {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("unit_no", unitNo);
queryWrapper.eq("warehouse_id", currentWarehouseId);
List list = orderPackageStatusPushFailLogMapper.selectList(queryWrapper);
if (list == null || list.isEmpty()) {
OrderPackageStatusPushFailLogEntity orderPackageStatusPushFailLogEntity = new OrderPackageStatusPushFailLogEntity();
orderPackageStatusPushFailLogEntity.setOrderPackageStatus(status);
orderPackageStatusPushFailLogEntity.setUnitNo(unitNo);
orderPackageStatusPushFailLogEntity.setWarehouseId(currentWarehouseId);
orderPackageStatusPushFailLogEntity.setOperationTime(operationTime);
orderPackageStatusPushFailLogEntity.setTrayId(trayId);
orderPackageStatusPushFailLogEntity.setDataStatus(0);
// 插入之前判断这条数据是否存在系统中
log.info(">>>>>>>>>>>>>>>> 保存到定时任务队列");
orderPackageStatusPushFailLogMapper.insert(orderPackageStatusPushFailLogEntity);
}else{
throw new CustomerException(405, "失败的包件数据状态记录已存在");
}
} }
} else {
log.info("##############dealWithDataHandler: 不用处理的状态 status={}", status);
} }
} }
} }

56
blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/OrderPackageStatusFallJob.java

@ -0,0 +1,56 @@
package com.logpm.factory.jobhandler;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.logpm.factory.comfac.mapper.OrderPackageStatusPushFailLogMapper;
import com.logpm.factory.comfac.service.IFactoryCommonService;
import com.logpm.factory.entity.OrderPackageStatusPushFailLogEntity;
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 lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 处理包件老系统没有入库 这边无法获取的包件信息
*/
@Log4j2
@AllArgsConstructor
@Component
public class OrderPackageStatusFallJob {
private final OrderPackageStatusPushFailLogMapper orderPackageStatusPushFailLogMapper;
private final IFactoryCommonService factoryCommonService;
@XxlJob("getOrderPackageFromOldSystem")
public ReturnT<String> getOrderPackageFromOldSystem(String param) {
// 加载日志列表
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("data_status", 0);
List<OrderPackageStatusPushFailLogEntity> list = orderPackageStatusPushFailLogMapper.selectList(queryWrapper);
for (OrderPackageStatusPushFailLogEntity orderPackageStatusPushFailLogEntity : list) {
try {
// 重新获取数据
factoryCommonService.extracted(orderPackageStatusPushFailLogEntity.getOrderPackageStatus(),
orderPackageStatusPushFailLogEntity.getUnitNo(), orderPackageStatusPushFailLogEntity.getWarehouseId(),
orderPackageStatusPushFailLogEntity.getOperationTime(), orderPackageStatusPushFailLogEntity.getTrayId()
);
orderPackageStatusPushFailLogEntity.setDataStatus(1);
}catch (Exception e){
XxlJobLogger.log(e);
orderPackageStatusPushFailLogEntity.setDataStatus(2);
}
orderPackageStatusPushFailLogMapper.updateById(orderPackageStatusPushFailLogEntity);
}
return ReturnT.SUCCESS;
}
}

28
blade-service/logpm-factory/src/main/java/com/logpm/factory/receiver/DealWithDataHandler.java

@ -1,7 +1,10 @@
package com.logpm.factory.receiver; package com.logpm.factory.receiver;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.logpm.factory.comfac.dto.OrderStatusDTO; import com.logpm.factory.comfac.dto.OrderStatusDTO;
import com.logpm.factory.comfac.mapper.OrderPackageStatusPushFailLogMapper;
import com.logpm.factory.comfac.service.IFactoryCommonService; import com.logpm.factory.comfac.service.IFactoryCommonService;
import com.logpm.factory.entity.OrderPackageStatusPushFailLogEntity;
import com.logpm.factory.pan.service.IPanFactoryDataService; import com.logpm.factory.pan.service.IPanFactoryDataService;
import com.logpm.oldproject.feign.IAdvanceDetailClient; import com.logpm.oldproject.feign.IAdvanceDetailClient;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
@ -18,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
@ -35,6 +39,10 @@ public class DealWithDataHandler {
@Autowired @Autowired
private IFactoryCommonService factoryCommonService; private IFactoryCommonService factoryCommonService;
@Autowired
private OrderPackageStatusPushFailLogMapper orderPackageStatusPushFailLogMapper;
@RabbitHandler @RabbitHandler
public void dealWithDataHandler(Map map, Message message, Channel channel) throws IOException { public void dealWithDataHandler(Map map, Message message, Channel channel) throws IOException {
@ -48,6 +56,26 @@ public class DealWithDataHandler {
String currentWarehouseId = orderStatusDTO.getCurrentWarehouse();//当前仓Id String currentWarehouseId = orderStatusDTO.getCurrentWarehouse();//当前仓Id
factoryCommonService.extracted(status, unitNo, currentWarehouseId, operationTime, trayId); factoryCommonService.extracted(status, unitNo, currentWarehouseId, operationTime, trayId);
extracted(unitNo,currentWarehouseId);
}
/**
* 更新包件状态
* @param unitNo
* @param currentWarehouseId
*/
private void extracted(String unitNo, String currentWarehouseId) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("unit_no", unitNo);
queryWrapper.eq("warehouse_id", currentWarehouseId);
List<OrderPackageStatusPushFailLogEntity> list = orderPackageStatusPushFailLogMapper.selectList(queryWrapper);
for (OrderPackageStatusPushFailLogEntity orderPackageStatusPushFailLogEntity : list) {
orderPackageStatusPushFailLogEntity.setDataStatus(1);
orderPackageStatusPushFailLogMapper.updateById(orderPackageStatusPushFailLogEntity);
}
} }

Loading…
Cancel
Save