diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/IOuPaiFactoryService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/IOuPaiFactoryService.java index 637b3f52c..68ea10def 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/IOuPaiFactoryService.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/IOuPaiFactoryService.java @@ -11,4 +11,8 @@ public interface IOuPaiFactoryService { String saveOuPaiFactoryOrderDTOByCarCarNumber(String carNumber); + String saveOuPaiPackageStatusByCode(String orderCode,Integer event); + + String saveOuPaiOutGoingOrderByCode(String orderCode, Integer event); + } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryDataServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryDataServiceImpl.java index b574315d2..c129811b5 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryDataServiceImpl.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryDataServiceImpl.java @@ -5,6 +5,8 @@ import com.logpm.factory.oupai.service.IOuPaiFactoryService; import com.logpm.factory.oupai.vo.OuPaiDataPushVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.common.exception.CustomerException; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; @Service @@ -20,20 +22,33 @@ public class OuPaiFactoryDataServiceImpl implements IOuPaiFactoryDataService { @Override public String saveData(OuPaiDataPushVO ouPaiDataPushVO) { - - - // 需要判断 这个里面的事件是否为 - if(ouPaiDataPushVO.getEvent()==3 && "ReceivingOrder".equals(ouPaiDataPushVO.getTypeName())){ + Integer event = ouPaiDataPushVO.getEvent(); + String typeName = ouPaiDataPushVO.getTypeName(); + String orderCode = ouPaiDataPushVO.getOrderCode(); + String code = null; + if(StringUtil.isBlank(typeName)){ + log.info("#############saveData: 事件类型为空 typeName={}",typeName); + throw new CustomerException(403,"事件类型为空"); + } + if(event == 0){ + //收货单开始收货 + }else if(event == 1){ + //收货单完成收货 + }else if(event == 2){ + //包件收货 + code = ouPaiFactoryService.saveOuPaiPackageStatusByCode(orderCode,event); + }else if(event == 3){ + // 收货单创建 // 获取需要处理的数据并存入数据库 - String carNum =ouPaiFactoryService.saveOuPaiFactoryOrderDTOByCarCarNumber(ouPaiDataPushVO.getOrderCode()); - // 将需要将数据 - - return carNum; + code = ouPaiFactoryService.saveOuPaiFactoryOrderDTOByCarCarNumber(orderCode); + }else if(event == 4){ + //配送单发运 + code = ouPaiFactoryService.saveOuPaiOutGoingOrderByCode(orderCode,event); + }else if(event == 5){ + //签收单签收 + }else if(event == 6){ + //签收单部分签收 } - return ouPaiDataPushVO.getOrderCode(); - - - - + return code; } } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryServiceImpl.java index cb60ee1c1..afc5f85fe 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryServiceImpl.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/oupai/service/impl/OuPaiFactoryServiceImpl.java @@ -50,6 +50,118 @@ public class OuPaiFactoryServiceImpl implements IOuPaiFactoryService { } + @Override + public String saveOuPaiPackageStatusByCode(String orderCode,Integer event) { + // + String url = ouPaiProperties.getUri() + "tims_odata_api/api/odata/Package?$filter=Code eq '"+orderCode+"'&select=Code,PdaNumber," + + "FirstClassCode,FirstClassName,SecondClassCode,SecondClassName,ThirdClassCode,ThirdClassName,BuyIn,CosourcingCode," + + "CosourcingUnit,SortingCenter,DistributionCenter,Length,Width,Height,Weight,OrderDetail,Order," + + "PathIndex,PathDetail,DeliveryOrders,ReceivingOrders,LPN,LpnSerialNum,IsEntruck,ReservationOrder," + + "OutGoingOrderDetail,SignBill,IsInventory,Inventories,InventoryInDetails,Freeze," + + "OutGoingOrderDetailInventoryDetail,From,Creator,CreateTime,ShipTime,CarNumber,DeliveryMethod," + + "DeliveryReceiver,DeliveryReceiverPhone,ReturnNumber,GroupType,CarrierCode,CarrierName,PackageDetailNames," + + "ReceivingTime,SendTime,ExceptionSignRemark,Descript,SignTime,OutOrder,IsReceiveByHand,PackageStatus,PackageDetailNames"; + + handlePackageData(url,event); + return orderCode; + } + + @Override + public String saveOuPaiOutGoingOrderByCode(String orderCode, Integer event) { + // + String url = ouPaiProperties.getUri() + "tims_odata_api/api/odata/OutGoingOrder?$filter=Code eq 'PS20230802-6'" + + "&$select=Code,Status,Truck,DriverPhone,Platform,DeliveryDate,Creator,CreateTime,IsAdjust,SendTime," + + "Customers,Volume" + + "&$expand=Warehouse($select=Code,Name)" + + "&$expand=Truck($select=Plate,Type)" + + "&$expand=Driver($select=Contact,Phone)" + + "&$expand=ExpressCompany($select=CompanyName,CompanyCode)" + + "&$expand=OutGoingOrderDetails($select=Customer,IsPickUp,CustomerPhone,Province,City,CustomerAddress," + + "InstallationDate,DeliveryDate,ActualDeliveryDate,TimeFrame,Remark,CarrierRemark,Creator,CreateTime;" + + "$expand=Packages($select=Code,PdaNumber,FirstClassCode,FirstClassName,SecondClassCode,SecondClassName," + + "ThirdClassCode,ThirdClassName,BuyIn,CosourcingCode,CosourcingUnit,SortingCenter,DistributionCenter," + + "Length,Width,Height,Weight,OrderDetail,Order,PathIndex,PathDetail,DeliveryOrders,ReceivingOrders," + + "LPN,LpnSerialNum,IsEntruck,ReservationOrder,OutGoingOrderDetail,SignBill,IsInventory,Inventories," + + "InventoryInDetails,Freeze,OutGoingOrderDetailInventoryDetail,From,Creator,CreateTime," + + "ShipTime,CarNumber,DeliveryMethod,DeliveryReceiver,DeliveryReceiverPhone,ReturnNumber,GroupType," + + "CarrierCode,CarrierName,PackageDetailNames,ReceivingTime,SendTime,ExceptionSignRemark,Descript," + + "SignTime,OutOrder,IsReceiveByHand,PackageStatus,PackageDetailNames);" + + "$expand=OutGoingOrderDetailInventoryDetails($select=SendQty;" + + "$expand=ReservationOrderInventoryDetail($select=Qty;$expand=Inventory($select=SerialNumber,BatchCode," + + "Code,Name,Unit,Qty,HoldQty,SelectedQty,Location))))"; + + handleOutGoingOrderData(url,event); + return orderCode; + } + + private void handleOutGoingOrderData(String url, Integer event) { + OpOrderStatusLogEntity opOrderStatusLogEntity = sendRequestData(url,event); + + // 保存需要解析的数据 + // 获取返回内容 + try { + JSONObject jsonObject = JSONObject.parseObject(opOrderStatusLogEntity.getArgs()); + JSONArray resultArray = jsonObject.getJSONArray("value"); + log.info("############handlePackageData: 数据处理开始"); + + //TODO 这里需要添加处理配送发运单的逻辑 + + opOrderStatusLogEntity.setDataStatus(1); + } catch (Exception e) { + e.printStackTrace(); + log.error("############handlePackageData: {}", e.getMessage()); + opOrderStatusLogEntity.setDataStatus(2); + } + opOrderStatusLogService.saveOrUpdate(opOrderStatusLogEntity); + + } + + private void handlePackageData(String url,Integer event) { + + OpOrderStatusLogEntity opOrderStatusLogEntity = sendRequestData(url,event); + + // 保存需要解析的数据 + // 获取返回内容 + try { + JSONObject jsonObject = JSONObject.parseObject(opOrderStatusLogEntity.getArgs()); + JSONArray resultArray = jsonObject.getJSONArray("value"); + log.info("############handlePackageData: 数据处理开始"); + + //TODO 这里需要添加处理包件状态的逻辑 + + opOrderStatusLogEntity.setDataStatus(1); + } catch (Exception e) { + e.printStackTrace(); + log.error("############handlePackageData: {}", e.getMessage()); + opOrderStatusLogEntity.setDataStatus(2); + } + opOrderStatusLogService.saveOrUpdate(opOrderStatusLogEntity); + } + + private OpOrderStatusLogEntity sendRequestData(String url, Integer event) { + log.info("#################sendRequestData: 请求地址 url={}", url); + + String token = buildToken(); +// log.info(">>> Authorization token {}",token); + + HttpResponse httpResponse = HttpRequest.get(url).header("Authorization", token).execute(); + + String result = httpResponse.body(); + log.info("#################sendRequestData: 返回数据 result={}", result); + + OpOrderStatusLogEntity orderStatusLog = new OpOrderStatusLogEntity(); + orderStatusLog.setArgs(result); + orderStatusLog.setStatus(1); + orderStatusLog.setType(event); + orderStatusLog.setDataStatus(0); + orderStatusLog.setBrand("欧派"); + opOrderStatusLogService.save(orderStatusLog); + + + return orderStatusLog; + } + + /** * 处理返回的JSON数据 * @@ -401,7 +513,7 @@ public class OuPaiFactoryServiceImpl implements IOuPaiFactoryService { OpOrderStatusLogEntity orderStatusLog = new OpOrderStatusLogEntity(); orderStatusLog.setArgs(result); orderStatusLog.setStatus(1); - orderStatusLog.setType(1); + orderStatusLog.setType(3); orderStatusLog.setDataStatus(0); orderStatusLog.setBrand("欧派"); opOrderStatusLogService.save(orderStatusLog);