| | |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.entity.dto.ContainerWaveDto; |
| | | import com.vincent.rsf.server.api.entity.params.ContainerWaveParam; |
| | | import com.vincent.rsf.server.api.service.PdaOutStockService; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.TaskStsType; |
| | | import com.vincent.rsf.server.manager.enums.WaveExceStatus; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R saveWavePick(List<ContainerWaveDto> containerWaveDtos) { |
| | | if (null == containerWaveDtos || containerWaveDtos.size() <= 0){ |
| | | public R saveWavePick(ContainerWaveParam containerWaveParam, Long loginUserId) { |
| | | if (null == containerWaveParam || containerWaveParam.getContainerWaveDtos().size() <= 0){ |
| | | return R.error("参数错误"); |
| | | } |
| | | Task task = taskService.getById(containerWaveDtos.get(0).getTaskItem().getTaskId()); |
| | | Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode,containerWaveParam.getContainer())); |
| | | if (null == task){ |
| | | return R.error("未找到托盘对应的任务"); |
| | | } |
| | | |
| | | for (ContainerWaveDto containerWaveDto : containerWaveDtos) { |
| | | for (ContainerWaveDto containerWaveDto : containerWaveParam.getContainerWaveDtos()) { |
| | | //做一次校验,判断前端所有出库数量是否超过本托出库数量 |
| | | double sum = containerWaveDto.getAsnOrderItems().stream().mapToDouble(AsnOrderItem::getDemandQty).sum(); |
| | | BigDecimal total = new BigDecimal(String.valueOf(sum)); |
| | |
| | | throw new CoolException("播种数量不等于容器出库数量,请检查"); |
| | | } |
| | | for (AsnOrderItem orderItem : containerWaveDto.getAsnOrderItems()) { |
| | | if (Double.compare(orderItem.getDemandQty(), 0.0) == 0) { |
| | | continue; |
| | | } |
| | | BigDecimal num = new BigDecimal(orderItem.getWorkQty().toString()).subtract(new BigDecimal(orderItem.getQty().toString())); |
| | | BigDecimal orderDemandQty = new BigDecimal(orderItem.getDemandQty().toString()); |
| | | if (num.compareTo(orderDemandQty) < 0){ |
| | |
| | | if (!asnOrderItemService.updateById(orderItem)){ |
| | | throw new CoolException("单据明细更新失败"); |
| | | } |
| | | //检查单据是否完成 |
| | | Boolean orderChecked = checkOrderComplete(orderItem); |
| | | if (orderChecked){ |
| | | AsnOrder asnOrder = asnOrderService.getById(orderItem.getAsnId()); |
| | | if (Cools.isEmpty(asnOrder)){ |
| | | throw new CoolException("出库单主单未找到"); |
| | | } |
| | | asnOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_DONE.val); |
| | | if (!asnOrderService.updateById(asnOrder)){ |
| | | throw new CoolException("出库单更新状态失败"); |
| | | } |
| | | } |
| | | } |
| | | //检查波次是否完成 |
| | | Boolean waveChecked = checkWaveComplete(containerWaveDto.getTaskItem()); |
| | | if (waveChecked){ |
| | | Wave wave = waveService.getById(containerWaveDto.getTaskItem().getSourceId()); |
| | | if (null == wave){ |
| | | throw new CoolException("未找到容器号对应波次"); |
| | | } |
| | | wave.setExceStatus(WaveExceStatus.WAVE_EXCE_STATUS_DONE.val); |
| | | if (!waveService.updateById(wave)){ |
| | | throw new CoolException("波次单更新状态失败"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); |
| | | if (!taskService.updateById(task)){ |
| | | throw new CoolException("任务状态更新失败"); |
| | | } |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | private Boolean checkWaveComplete(TaskItem taskItem) { |
| | | Wave wave = waveService.getById(taskItem.getSourceId()); |
| | | List<AsnOrder> asnOrderList = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getWaveId, wave.getId())); |
| | | return asnOrderList.stream().allMatch(item -> new BigDecimal(item.getAnfme().toString()).equals(new BigDecimal(item.getQty().toString()))); |
| | | } |
| | | |
| | | private Boolean checkOrderComplete(AsnOrderItem orderItem) { |
| | | List<AsnOrderItem> asnOrderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnCode, orderItem.getAsnCode())); |
| | | return asnOrderItems.stream().allMatch(item -> new BigDecimal(item.getAnfme().toString()).equals(new BigDecimal(item.getQty().toString()))); |
| | | } |
| | | } |