| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.gs.xiaomi.dto.BCS101Request; |
| | | import com.gs.xiaomi.dto.BCS101Response; |
| | | import com.gs.xiaomi.dto.CartonListItemDto; |
| | | import com.gs.xiaomi.dto.SnListItemDto; |
| | | import com.gs.xiaomi.entity.CartonListItem; |
| | | import com.gs.xiaomi.entity.DeliveryMain; |
| | | import com.gs.xiaomi.entity.SnListItem; |
| | | import com.gs.xiaomi.util.CartonListItemConverter; |
| | | import com.gs.xiaomi.util.SnListItemConverter; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.slf4j.Logger; |
| | |
| | | private final BCS101ApiService bcs101ApiService; |
| | | private final DeliveryMainService deliveryMainService; |
| | | private final SnListItemService snListItemService; |
| | | private final CartonListItemService cartonListItemService; |
| | | |
| | | /** |
| | | * 根据送货单号获取BCS101条码数据并持久化 |
| | |
| | | } else { |
| | | log.warn("【BCS101数据同步】响应中没有SN数据, 送货单: {}", asn); |
| | | } |
| | | |
| | | // 获取cartonList数据 |
| | | List<CartonListItemDto> cartonList = response.getBody().getCartonList(); |
| | | |
| | | if (cartonList != null && !cartonList.isEmpty()) { |
| | | log.info("【BCS101数据同步】获取到 {} 条箱数据,开始持久化...", cartonList.size()); |
| | | |
| | | // 转换DTO为Entity,并设置关联信息 |
| | | List<CartonListItem> cartonEntityList = CartonListItemConverter.toEntityList( |
| | | cartonList, |
| | | deliveryMain.getId(), // deliveryMainId - 送货单主表ID |
| | | deliveryMain.getZzasn() // zzasn - 送货单号 |
| | | ); |
| | | |
| | | // 先删除该送货单已有的箱数据(避免重复) |
| | | cartonListItemService.lambdaUpdate() |
| | | .eq(CartonListItem::getZzasn, deliveryMain.getZzasn()) |
| | | .remove(); |
| | | |
| | | // 批量保存到数据库 |
| | | boolean cartonSaved = cartonListItemService.saveBatch(cartonEntityList); |
| | | |
| | | if (cartonSaved) { |
| | | log.info("【BCS101数据同步成功】成功保存 {} 条箱数据到数据库, 送货单: {}", cartonEntityList.size(), asn); |
| | | |
| | | deliveryMainService.callPdaReceiptBtn1("送货单签收[BTNOK[PL017[" + deliveryMain.getZzasn(), ""); |
| | | |
| | | } else { |
| | | log.error("【BCS101数据同步失败】保存箱数据失败, 送货单: {}", asn); |
| | | throw new RuntimeException("保存箱数据失败"); |
| | | } |
| | | } else { |
| | | log.warn("【BCS101数据同步】响应中没有箱数据, 送货单: {}", asn); |
| | | } |
| | | } else { |
| | | log.error("【BCS101数据同步失败】接口调用失败, 送货单: {}, 错误: {}", asn, response.getErrorDesc()); |
| | | throw new RuntimeException("BCS101接口调用失败: " + response.getErrorDesc()); |