| | |
| | | import com.vincent.rsf.server.api.controller.erp.params.dto.CheckDiffDto; |
| | | import com.vincent.rsf.server.api.controller.erp.params.dto.TransferInfoDto; |
| | | import com.vincent.rsf.server.api.controller.erp.params.dto.WkOrderDto; |
| | | import com.vincent.rsf.server.api.utils.TimeConverterUtils; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.manager.controller.dto.LocStockDto; |
| | |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.vincent.rsf.server.manager.enums.OrderWorkType.*; |
| | | |
| | | /** |
| | | * @author Ryan |
| | |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private WarehouseAreasItemServiceImpl warehouseAreasItemService; |
| | | @Autowired |
| | | private LocItemService locItemService; |
| | | |
| | | |
| | | /** |
| | |
| | | if (Objects.isNull(one)) { |
| | | throw new CoolException("单据:" + syncOrder.getOrderNo() + ", 业务类型不存在!!"); |
| | | } |
| | | WkOrder order = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>() |
| | | WkOrder order = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>() |
| | | .eq(!Objects.isNull(syncOrder.getOrderId()), WkOrder::getPoId, syncOrder.getOrderId()) |
| | | .eq(WkOrder::getPoCode, syncOrder.getOrderNo())); |
| | | if (!Objects.isNull(order)) { |
| | |
| | | |
| | | //银座特供 |
| | | String orderNs = null; |
| | | if (rule.equals(SerialRuleCode.SYS_ASN_ORDER) || rule.equals(SerialRuleCode.SYS_OUT_STOCK_CODE) ){ |
| | | if (rule.equals(SerialRuleCode.SYS_ASN_ORDER) || rule.equals(SerialRuleCode.SYS_OUT_STOCK_CODE)) { |
| | | StringBuffer buffer = new StringBuffer(); |
| | | Object poCode = syncOrder.getOrderNo(); |
| | | orderNs = poCode == null ? "" : buffer.append(poCode).toString(); |
| | |
| | | .setWkType(one.getValue()) |
| | | .setAnfme(syncOrder.getAnfme()) |
| | | .setPoCode(syncOrder.getOrderNo()) |
| | | .setWorkQty(0.0) |
| | | .setQty(0.0) |
| | | .setWorkQty(0.0)//执行数量 |
| | | .setQty(0.0)//完成数量 |
| | | .setPoId(syncOrder.getOrderInternalCode()) |
| | | .setCode(ruleCode) |
| | | .setArrTime(syncOrder.getArrTime()) |
| | | .setId(null) |
| | | .setCreateTime(new Date()) |
| | | .setCreateTime(new TimeConverterUtils().timestampToDate(syncOrder.getCreateTime())) |
| | | .setBusinessTime(new TimeConverterUtils().timestampToDate(syncOrder.getBusinessTime())) |
| | | .setUpdateTime(new Date()) |
| | | .setCreateBy(loginUserId) |
| | | .setUpdateBy(loginUserId); |
| | | |
| | | if (syncOrder.getType().equals(OrderType.ORDER_OUT.type)){ |
| | | if (syncOrder.getType().equals(OrderType.ORDER_OUT.type)) { |
| | | wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val); |
| | | } |
| | | if (!asnOrderService.save(wkOrder)) { |
| | |
| | | } |
| | | AtomicReference<String> palletId = new AtomicReference<>(); |
| | | syncOrder.getOrderItems().forEach(orderItem -> { |
| | | if (Cools.isEmpty(palletId.get())){ |
| | | if (Cools.isEmpty(palletId.get())) { |
| | | palletId.set(orderItem.getPalletId()); |
| | | } else { |
| | | if (!palletId.get().equals(orderItem.getPalletId())){ |
| | | if (!palletId.get().equals(orderItem.getPalletId())) { |
| | | throw new CoolException("同一个单据明细中的托盘码必须一致!!!"); |
| | | } |
| | | } |
| | |
| | | map.put("model", orderItem.getModel()); |
| | | map.put("stockUnit", orderItem.getUnit()); |
| | | map.put("purUnit", orderItem.getUnit()); |
| | | map.put("baseUnit", orderItem.getBaseUnitId()); |
| | | map.put("useOrgId", orderItem.getUseOrgId()); |
| | | map.put("useOrgName", orderItem.getUseOrgName()); |
| | | map.put("erpClsId", orderItem.getErpClsId()); |
| | | map.put("priceUnitId", orderItem.getPriceUnitId()); |
| | | map.put("inStockType", orderItem.getInStockType()); |
| | | map.put("ownerTypeId", orderItem.getOwnerTypeId()); |
| | | map.put("ownerId", orderItem.getOwnerId()); |
| | | map.put("ownerName", orderItem.getOwnerName()); |
| | | map.put("keeperTypeId", orderItem.getKeeperTypeId()); |
| | | map.put("keeperId", orderItem.getKeeperId()); |
| | | map.put("keeperName", orderItem.getKeeperName()); |
| | | map.put("targetWarehouseId", orderItem.getTargetWarehouseId()); |
| | | map.put("sourceWarehouseId", orderItem.getSourceWarehouseId()); |
| | | map.put("createBy", loginUserId); |
| | | map.put("updateBy", loginUserId); |
| | | |
| | | if (!asnOrderItemService.fieldsSave(map, loginUserId)) { |
| | | throw new CoolException("明细保存失败!!"); |
| | |
| | | //组托 |
| | | WaitPakinParam pakinParam = new WaitPakinParam(); |
| | | pakinParam.setBarcode(palletId.get()); |
| | | CompletableFuture.runAsync(() -> { |
| | | try { |
| | | asyncMergeItemsWcs(pakinParam, syncOrder.getOrderNo(), loginUserId); |
| | | } catch (Exception e) { |
| | | log.warn("订单 {} 开始自动组托", syncOrder.getOrderNo()); |
| | | } |
| | | }); |
| | | pakinParam.setStaNo(syncOrder.getStationId()); |
| | | |
| | | boolean itemsCheck = waitPakinService.mergeItemsCheck(pakinParam, loginUserId); |
| | | if (itemsCheck) { |
| | | CompletableFuture.runAsync(() -> { |
| | | try { |
| | | asyncMergeItemsWcs(pakinParam, syncOrder.getOrderNo(), loginUserId); |
| | | } catch (Exception e) { |
| | | log.warn("订单 {} 开始自动组托", syncOrder.getOrderNo()); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | |
| | | int i = 0; |
| | | while (true) { |
| | | i++; |
| | | if (i>5) return; |
| | | if (i > 5) return; |
| | | Thread.sleep(3000); |
| | | List<WarehouseAreasItem> list = warehouseAreasItemService.list(new LambdaQueryWrapper<WarehouseAreasItem>() |
| | | .eq(WarehouseAreasItem::getAsnCode, orderNo)); |
| | |
| | | log.error("订单 {} 自动组托失败: {}", orderNo, e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/8/19 |
| | |
| | | |
| | | /** |
| | | * 基础物料信息变更 |
| | | * |
| | | * @param baseMatParms |
| | | * @return |
| | | */ |
| | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 库存查询明细(供open-api调用) |
| | | * |
| | | * @param condition 查询条件实体类 |
| | | * @return 库存明细列表 |
| | | */ |
| | | @Override |
| | | public R erpQueryInventoryDetails(InventoryQueryConditionParam condition) { |
| | | try { |
| | | // 参数验证 |
| | | if (condition == null) { |
| | | return R.error("查询条件不能为空"); |
| | | } |
| | | |
| | | // 将ERP参数映射为Java实体字段名(驼峰格式),PageParam会自动转换为数据库字段名(下划线格式) |
| | | Map<String, Object> queryMap = new HashMap<>(); |
| | | |
| | | // 从实体类中提取查询条件,映射为数据库字段名 |
| | | if (StringUtils.isNotBlank(condition.getLocId())) { |
| | | queryMap.put("locCode", condition.getLocId()); |
| | | } |
| | | if (StringUtils.isNotBlank(condition.getMatNr())) { |
| | | queryMap.put("matnrCode", condition.getMatNr()); |
| | | } |
| | | if (StringUtils.isNotBlank(condition.getPlanNo())) { |
| | | queryMap.put("trackCode", condition.getPlanNo()); |
| | | } |
| | | if (StringUtils.isNotBlank(condition.getBatch())) { |
| | | queryMap.put("batch", condition.getBatch()); |
| | | } |
| | | |
| | | BaseParam baseParam = new BaseParam(); |
| | | baseParam.syncMap(queryMap); |
| | | PageParam<LocItem, BaseParam> pageParam = new PageParam<>(baseParam, LocItem.class); |
| | | |
| | | QueryWrapper<LocItem> wrapper = pageParam.buildWrapper(false); |
| | | |
| | | // 订单号/工单号/MES工单号 |
| | | if (StringUtils.isNotBlank(condition.getOrderNo())) { |
| | | String orderNo = condition.getOrderNo(); |
| | | wrapper.and(w -> w.eq("plat_order_code", orderNo) |
| | | .or().eq("plat_work_code", orderNo)); |
| | | } |
| | | |
| | | // 物料组(需要通过物料表关联查询) |
| | | if (StringUtils.isNotBlank(condition.getMatGroup())) { |
| | | // 调用物料Service查询物料组对应的物料ID列表(复用已有方法) |
| | | LambdaQueryWrapper<Matnr> matnrWrapper = new LambdaQueryWrapper<>(); |
| | | matnrWrapper.eq(Matnr::getGroupId, condition.getMatGroup()); |
| | | List<Matnr> matnrs = matnrService.list(matnrWrapper); |
| | | if (!matnrs.isEmpty()) { |
| | | List<Long> matnrIds = matnrs.stream().map(Matnr::getId).collect(Collectors.toList()); |
| | | wrapper.in("matnr_id", matnrIds); |
| | | } else { |
| | | // 如果没有找到物料,返回空结果 |
| | | return R.ok().add(new ArrayList<>()); |
| | | } |
| | | } |
| | | |
| | | // 只查询正常状态的库存(status=1表示正常) |
| | | wrapper.eq("status", 1); |
| | | |
| | | pageParam.setCurrent(1); |
| | | pageParam.setSize(Integer.MAX_VALUE); |
| | | PageParam<LocItem, BaseParam> pageResult = locItemService.page(pageParam, wrapper); |
| | | List<LocItem> locItems = pageResult.getRecords(); |
| | | |
| | | if (locItems.isEmpty()) { |
| | | return R.ok().add(new ArrayList<>()); |
| | | } |
| | | |
| | | // 获取所有需要关联的ID |
| | | List<Long> locIds = locItems.stream() |
| | | .map(LocItem::getLocId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Long> warehouseIds = new ArrayList<>(); |
| | | List<Long> orderIds = locItems.stream() |
| | | .map(LocItem::getOrderId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 调用LocService查询库位信息(复用Service层方法) |
| | | Map<Long, Loc> locMap = new HashMap<>(); |
| | | if (!locIds.isEmpty()) { |
| | | List<Loc> locs = locService.listByIds(locIds); |
| | | locMap = locs.stream().collect(Collectors.toMap(Loc::getId, loc -> loc)); |
| | | |
| | | // 收集仓库ID |
| | | warehouseIds = locs.stream() |
| | | .map(Loc::getWarehouseId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | // 仓库编码过滤 |
| | | if (StringUtils.isNotBlank(condition.getWareHouseId())) { |
| | | String wareHouseId = condition.getWareHouseId(); |
| | | LambdaQueryWrapper<Warehouse> whWrapper = new LambdaQueryWrapper<>(); |
| | | whWrapper.eq(Warehouse::getCode, wareHouseId); |
| | | // 调用WarehouseService查询仓库信息(复用Service层方法) |
| | | List<Warehouse> warehouses = warehouseService.list(whWrapper); |
| | | if (!warehouses.isEmpty()) { |
| | | Long targetWarehouseId = warehouses.get(0).getId(); |
| | | // 过滤库位,只保留目标仓库的库位 |
| | | locMap = locMap.entrySet().stream() |
| | | .filter(entry -> Objects.equals(entry.getValue().getWarehouseId(), targetWarehouseId)) |
| | | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
| | | |
| | | // 过滤locItems,只保留目标仓库的 |
| | | Set<Long> validLocIds = locMap.keySet(); |
| | | locItems = locItems.stream() |
| | | .filter(item -> item.getLocId() != null && validLocIds.contains(item.getLocId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | warehouseIds = Collections.singletonList(targetWarehouseId); |
| | | } else { |
| | | return R.ok().add(new ArrayList<>()); |
| | | } |
| | | } |
| | | |
| | | // 调用WarehouseService查询仓库信息(复用Service层方法) |
| | | Map<Long, Warehouse> warehouseMap = new HashMap<>(); |
| | | if (!warehouseIds.isEmpty()) { |
| | | List<Warehouse> warehouses = warehouseService.listByIds(warehouseIds); |
| | | warehouseMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, wh -> wh)); |
| | | } |
| | | |
| | | // 调用AsnOrderService查询订单信息(复用Service层方法) |
| | | Map<Long, WkOrder> orderMap = new HashMap<>(); |
| | | if (!orderIds.isEmpty()) { |
| | | List<WkOrder> orders = asnOrderService.listByIds(orderIds); |
| | | orderMap = orders.stream().collect(Collectors.toMap(WkOrder::getId, order -> order)); |
| | | } |
| | | |
| | | // 转换结果 |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (LocItem locItem : locItems) { |
| | | Map<String, Object> details = convertToInventoryDetails(locItem, locMap, warehouseMap, orderMap); |
| | | if (details != null) { |
| | | result.add(details); |
| | | } |
| | | } |
| | | |
| | | return R.ok().add(result); |
| | | } catch (Exception e) { |
| | | log.error("库存查询明细失败", e); |
| | | return R.error("查询失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转换为库存明细对象 |
| | | */ |
| | | private Map<String, Object> convertToInventoryDetails(LocItem locItem, Map<Long, Loc> locMap, |
| | | Map<Long, Warehouse> warehouseMap, |
| | | Map<Long, WkOrder> orderMap) { |
| | | Map<String, Object> details = new HashMap<>(); |
| | | |
| | | // 库位编码 |
| | | details.put("locId", locItem.getLocCode()); |
| | | |
| | | // 仓库信息 |
| | | Loc loc = null; |
| | | if (locItem.getLocId() != null) { |
| | | loc = locMap.get(locItem.getLocId()); |
| | | } |
| | | |
| | | if (loc != null) { |
| | | // 托盘码(从库位的barcode获取) |
| | | details.put("palletId", loc.getBarcode()); |
| | | |
| | | // 仓库信息 |
| | | if (loc.getWarehouseId() != null && warehouseMap.containsKey(loc.getWarehouseId())) { |
| | | Warehouse warehouse = warehouseMap.get(loc.getWarehouseId()); |
| | | if (warehouse != null) { |
| | | details.put("wareHouseId", warehouse.getCode()); |
| | | details.put("wareHouseName", warehouse.getName()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 物料信息 |
| | | details.put("matNr", locItem.getMatnrCode()); |
| | | details.put("makTx", locItem.getMaktx()); |
| | | details.put("spec", locItem.getSpec()); |
| | | details.put("anfme", locItem.getAnfme()); |
| | | details.put("unit", locItem.getUnit()); |
| | | |
| | | // 库存状态:1-正常(可用),0-冻结 |
| | | if (locItem.getStatus() != null) { |
| | | details.put("status", locItem.getStatus() == 1 ? "可用" : "冻结"); |
| | | } |
| | | |
| | | // 批次号 |
| | | details.put("batch", locItem.getBatch()); |
| | | |
| | | // 计划跟踪号 |
| | | details.put("planNo", locItem.getTrackCode()); |
| | | |
| | | // 订单信息 |
| | | if (locItem.getOrderId() != null && orderMap.containsKey(locItem.getOrderId())) { |
| | | WkOrder order = orderMap.get(locItem.getOrderId()); |
| | | if (order != null) { |
| | | // 订单号 |
| | | details.put("orderNo", order.getCode()); |
| | | details.put("orderType", null); |
| | | // 订单类型:1-出库单,2-入库单,3-调拔单 |
| | | // 字符串类型映射:out->1(出库单), in->2(入库单), revise->(调拔单), check->(盘点单)) |
| | | if (StringUtils.isNotBlank(order.getType())) { |
| | | String orderTypeStr = order.getType().toLowerCase().trim(); |
| | | switch (orderTypeStr) { |
| | | case "out": |
| | | details.put("orderType", 1); |
| | | break; |
| | | case "in": |
| | | details.put("orderType", 2); |
| | | break; |
| | | case "revise": |
| | | break; |
| | | case "check": |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | //包含 备料单关键词就变成3 |
| | | if (StringUtils.isNotBlank(order.getWkType())) { |
| | | String workDesc = getWorkDesc(order.getWkType()); |
| | | if (workDesc != null && workDesc.contains("备料单")) { |
| | | details.put("orderType", 3); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 备料类型:根据业务类型判断 |
| | | // 正常领料(1),生产补料(2) |
| | | details.put("prepareType", 1); |
| | | if (StringUtils.isNotBlank(order.getWkType())) { |
| | | String workDesc = getWorkDesc(order.getWkType()); |
| | | if (workDesc != null && workDesc.contains("生产补料")) { |
| | | details.put("prepareType", 2); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果订单号为空,尝试从platOrderCode或platWorkCode获取 |
| | | if (!details.containsKey("orderNo") || details.get("orderNo") == null) { |
| | | if (StringUtils.isNotBlank(locItem.getPlatOrderCode())) { |
| | | details.put("orderNo", locItem.getPlatOrderCode()); |
| | | } else if (StringUtils.isNotBlank(locItem.getPlatWorkCode())) { |
| | | details.put("orderNo", locItem.getPlatWorkCode()); |
| | | } |
| | | } |
| | | |
| | | // 库存组织(从useOrgId获取) |
| | | details.put("stockOrgId", locItem.getUseOrgId()); |
| | | |
| | | return details; |
| | | } |
| | | } |