| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.cfg.CoercionAction; |
| | | import com.fasterxml.jackson.databind.cfg.CoercionInputShape; |
| | |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.client.HttpStatusCodeException; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.stream.Collectors; |
| | |
| | | throw new CoolException("任务保存失败!!"); |
| | | } |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) { |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type) |
| | | .set(Loc::getBarcode, pakin.getBarcode()) |
| | | .set(Loc::getWeight, task.getWeight()))) { |
| | | throw new CoolException("库位预约失败!!"); |
| | | } |
| | | /**获取组拖明细**/ |
| | |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()) |
| | | .set(Loc::getBarcode, pakin.getBarcode()))) { |
| | | .set(Loc::getBarcode, pakin.getBarcode()) |
| | | .set(Loc::getWeight, task.getWeight()))) { |
| | | throw new CoolException("库位预约失败!!"); |
| | | } |
| | | /**获取组拖明细**/ |
| | |
| | | |
| | | |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) { |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type) |
| | | .set(Loc::getBarcode, pakin.getBarcode()) |
| | | .set(Loc::getWeight, task.getWeight()))) { |
| | | throw new CoolException("库位预约失败!!"); |
| | | } |
| | | /**获取组拖明细**/ |
| | |
| | | // 将库位状态设为空(O状态) |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .set(Loc::getBarcode, null) |
| | | .set(Loc::getWeight, null) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()) |
| | |
| | | /**修改库位状态为F.在库*/ |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .set(Loc::getBarcode, task.getBarcode()) |
| | | .set(Loc::getWeight, task.getWeight()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()) |
| | |
| | | |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .set(Loc::getBarcode, null) |
| | | .set(Loc::getWeight, null) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type) |
| | |
| | | // } |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type) |
| | | .setBarcode(task.getBarcode()) |
| | | .setWeight(task.getWeight()) |
| | | .setUpdateBy(loginUserId).setUpdateTime(new Date()); |
| | | |
| | | if (!locService.updateById(loc)) { |
| | |
| | | List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, |
| | | TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_EMPITY_IN.type, TaskType.TASK_TYPE_LOC_MOVE.type, |
| | | TaskType.TASK_TYPE_EMPITY_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type); |
| | | List<Task> allTasks = this.list(new LambdaQueryWrapper<Task>() |
| | | .in(Task::getTaskType, list) |
| | | .in(Task::getId, (Object[]) ids)); |
| | | |
| | | if (allTasks.isEmpty()) { |
| | | List<Task> tasksById = this.list(new LambdaQueryWrapper<Task>().in(Task::getId, (Object[]) ids)); |
| | | if (tasksById.isEmpty()) { |
| | | throw new CoolException("任务不存在!!"); |
| | | } |
| | | |
| | | // 拣料出库/盘点出库进入再入库阶段后禁止取消(任务类型已由 103/107 变为再入库) |
| | | for (Task t : tasksById) { |
| | | if (TaskType.TASK_TYPE_PICK_IN.type.equals(t.getTaskType()) |
| | | || TaskType.TASK_TYPE_CHECK_IN.type.equals(t.getTaskType())) { |
| | | throw new CoolException("拣料/盘点出库已进入再入库阶段,禁止取消!!"); |
| | | } |
| | | } |
| | | List<Task> allTasks = tasksById.stream() |
| | | .filter(t -> list.contains(t.getTaskType())) |
| | | .collect(Collectors.toList()); |
| | | if (allTasks.isEmpty()) { |
| | | throw new CoolException("当前任务类型不支持取消!!"); |
| | | } |
| | | |
| | | // 收集需要取消的RCS任务编号和批次编号(不限制状态,只要已下发到RCS就需要取消) |
| | | List<String> rcsTaskCodes = new ArrayList<>(); |
| | | String batchNo = null; |
| | |
| | | log.info("RCS取消任务响应状态码:{}", exchange.getStatusCode()); |
| | | log.info("RCS取消任务响应体:{}", exchange.getBody()); |
| | | |
| | | if (!exchange.getStatusCode().is2xxSuccessful()) { |
| | | throw new CoolException("RCS取消任务失败:HTTP " + exchange.getStatusCode().value()); |
| | | } |
| | | |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | log.error("RCS取消任务失败:响应体为空"); |
| | | throw new CoolException("RCS取消任务失败:响应体为空"); |
| | |
| | | } |
| | | } |
| | | |
| | | // 可取消状态:原 1/101(不含 199);拣料/盘点出库 RCS 执行中(<198);拣料/盘点再入库(53/57)不支持取消 |
| | | // 可取消状态:原 1/101(不含 199);拣料/盘点出库 RCS 执行中(<198);再入库(53/57)在方法入口已禁止取消 |
| | | List<Task> tasks = this.list(new LambdaQueryWrapper<Task>() |
| | | .in(Task::getTaskType, list) |
| | | .in(Task::getId, (Object[]) ids) |
| | |
| | | } |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .eq(Loc::getCode, task.getTargLoc()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type))) { |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type) |
| | | .set(Loc::getBarcode, null) |
| | | .set(Loc::getWeight, null))) { |
| | | throw new CoolException("移库目标库位状态修改失败!!"); |
| | | } |
| | | |
| | |
| | | } |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type) |
| | | .setBarcode(task.getBarcode()) |
| | | .setWeight(task.getWeight()) |
| | | .setUpdateBy(loginUserId) |
| | | .setUpdateTime(new Date()); |
| | | if (!locService.updateById(loc)) { |
| | |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTaskType() < TaskStsType.UPDATED_IN.id ? task.getTargLoc() : task.getOrgLoc())); |
| | | if (null != loc && (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type) |
| | | || loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type))) { |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type); |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type) |
| | | .setBarcode(null) |
| | | .setWeight(null); |
| | | if (!locService.updateById(loc)) { |
| | | throw new CoolException("更新库位状态失败!!"); |
| | | } |
| | |
| | | throw new CoolException("临时库存更新失败!!"); |
| | | } |
| | | } |
| | | loc1.setUseStatus(LocStsType.LOC_STS_TYPE_S.type); |
| | | loc1.setUseStatus(LocStsType.LOC_STS_TYPE_S.type) |
| | | .setWeight(task.getWeight()); |
| | | locService.updateById(loc1); |
| | | // if (!locService.updateById(loc1)) { |
| | | // throw new CoolException("库位预约入库失败!!"); |
| | |
| | | if (!workings.isEmpty()) { |
| | | locItemWorkingService.saveBatch(workings); |
| | | } |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type); |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type) |
| | | .setWeight(first.getWeight()); |
| | | locService.updateById(loc); |
| | | } else { |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type); |
| | | loc.setBarcode(null); |
| | | loc.setWeight(null); |
| | | loc.setUpdateBy(loginUserId); |
| | | loc.setUpdateTime(new Date()); |
| | | locService.updateById(loc); |
| | |
| | | .eq(Loc::getId, loc.getId()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type) |
| | | .set(Loc::getBarcode, null) |
| | | .set(Loc::getWeight, null) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()))) { |
| | | throw new CoolException("空板出库库位状态更新失败!!"); |
| | |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type) |
| | | .set(Loc::getBarcode, null) |
| | | .set(Loc::getWeight, null) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()) |
| | | .eq(Loc::getId, loc.getId()))) { |
| | |
| | | log.error("RCS资源访问异常,任务下发失败!任务编码:{},错误信息:{}", task.getTaskCode(), errorMsg); |
| | | } |
| | | continue; |
| | | } catch (HttpStatusCodeException e) { |
| | | long endTime = System.currentTimeMillis(); |
| | | log.error("========== RCS任务下发异常 =========="); |
| | | log.error("请求RCS-HTTP状态异常,耗时:{}ms,任务编码:{},status:{},body:{}", (endTime - startTime), task.getTaskCode(), e.getRawStatusCode(), e.getResponseBodyAsString(), e); |
| | | log.error("请求RCS-地址:{}", pubTakUrl); |
| | | log.error("请求RCS-参数:{}", JSONObject.toJSONString(taskParams)); |
| | | continue; |
| | | } catch (Exception e) { |
| | | long endTime = System.currentTimeMillis(); |
| | | log.error("========== RCS任务下发异常 =========="); |
| | |
| | | if (TaskType.TASK_TYPE_EMPITY_IN.type.equals(task.getTaskType())) { |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type) |
| | | .set(Loc::getWeight, task.getWeight()) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()))) { |
| | | throw new CoolException("空板入库库位状态修改失败!!"); |
| | |
| | | } |
| | | |
| | | /**修改库位状态为F.在库*/ |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).eq(Loc::getCode, task.getTargLoc()))) { |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type) |
| | | .set(Loc::getWeight, task.getWeight()) |
| | | .eq(Loc::getCode, task.getTargLoc()))) { |
| | | throw new CoolException("库位状态修改失败!!"); |
| | | } |
| | | if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) { |
| | |
| | | } else { |
| | | stock.setLocCode(task.getOrgLoc()); |
| | | } |
| | | BigDecimal trayWeight = task.getWeight(); |
| | | BigDecimal groupWeight = null; |
| | | if (trayWeight != null && sum > 0) { |
| | | List<TaskItem> allLines = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | double totalQty = allLines.stream().mapToDouble(t -> t.getAnfme() != null ? t.getAnfme() : 0.0).sum(); |
| | | if (totalQty > 0) { |
| | | groupWeight = trayWeight.multiply(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(totalQty), 4, RoundingMode.HALF_UP); |
| | | } else { |
| | | groupWeight = trayWeight; |
| | | } |
| | | stock.setWeight(groupWeight); |
| | | } |
| | | if (!stockService.save(stock)) { |
| | | throw new CoolException("库存保存失败!!"); |
| | | } |
| | | |
| | | List<StockItem> stockItems = new ArrayList<>(); |
| | | for (TaskItem item : items) { |
| | | BigDecimal allocatedWeight = BigDecimal.ZERO; |
| | | BigDecimal sumBd = sum > 0 ? BigDecimal.valueOf(sum) : null; |
| | | for (int i = 0; i < items.size(); i++) { |
| | | TaskItem item = items.get(i); |
| | | /**通过任务明细中的taskId查询,获取TASK的目标库位信息*/ |
| | | StockItem stockItem = new StockItem(); |
| | | BeanUtils.copyProperties(item, stockItem); |
| | |
| | | .setUpdateBy(loginUserId) |
| | | .setId(null) |
| | | .setStockId(stock.getId()); |
| | | if (groupWeight != null && sumBd != null) { |
| | | if (i == items.size() - 1) { |
| | | stockItem.setWeight(groupWeight.subtract(allocatedWeight)); |
| | | } else { |
| | | double lineQty = item.getAnfme() != null ? item.getAnfme() : 0.0; |
| | | BigDecimal lineW = groupWeight.multiply(BigDecimal.valueOf(lineQty)).divide(sumBd, 4, RoundingMode.HALF_UP); |
| | | stockItem.setWeight(lineW); |
| | | allocatedWeight = allocatedWeight.add(lineW); |
| | | } |
| | | } |
| | | stockItems.add(stockItem); |
| | | } |
| | | if (!stockItemService.saveBatch(stockItems)) { |
| | |
| | | .setLocId(locId) |
| | | .setMatNr(item.getMatnrCode()) |
| | | .setQty(item.getAnfme() != null ? String.valueOf(item.getAnfme()) : "0") |
| | | .setBatch(item.getBatch()); |
| | | .setBatch(item.getBatch()) |
| | | .setInbound(isInbound) |
| | | .setBarcode(task.getBarcode()); |
| | | try { |
| | | String requestBody = om.writeValueAsString(param); |
| | | CloudWmsNotifyLog notifyLog = new CloudWmsNotifyLog() |