| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.server.api.controller.params.TaskInParam; |
| | | import com.vincent.rsf.server.manager.enums.*; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | |
| | | import com.vincent.rsf.server.manager.utils.LocManageUtil; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.enums.LocStsType; |
| | | import com.vincent.rsf.server.manager.enums.LocType; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import lombok.Synchronized; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | private BasStationService basStationService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private LocItemWorkingService locItemWorkingService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | complateInstock(task); |
| | | } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)) { |
| | | //53.拣料再入库 |
| | | |
| | | pickComplateInStock(task); |
| | | } |
| | | } else { |
| | | //出库任务 |
| | |
| | | //全托出库 |
| | | complateOutStock(task); |
| | | } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_IN.type)) { |
| | | //拣料出库, |
| | | taskService.pickTask(task.getId()); |
| | | //拣料出库 |
| | | pickTask(task.getId()); |
| | | //移除原始库存 |
| | | complateOutStock(task); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 拣料再入库 |
| | | * |
| | | * @param task |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void pickComplateInStock(Task task) throws Exception { |
| | | if (Objects.isNull(task)) { |
| | | return; |
| | | } |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())); |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("库存不存在!!"); |
| | | } |
| | | if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)) { |
| | | throw new CoolException("当前库位状态不处于S.入库预约,不可执行入库操作!"); |
| | | } |
| | | |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type).setBarcode(task.getBarcode()); |
| | | |
| | | if (!locService.updateById(loc)) { |
| | | throw new CoolException("库位信息更新失败!!"); |
| | | } |
| | | |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (taskItems.isEmpty()) { |
| | | throw new CoolException("任务明细不存在!!"); |
| | | } |
| | | List<LocItem> items = new ArrayList<>(); |
| | | for (TaskItem taskItem : taskItems) { |
| | | LocItem locItem = new LocItem(); |
| | | LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>() |
| | | .eq(LocItemWorking::getTaskId, taskItem.getTaskId()) |
| | | .eq(LocItemWorking::getLocCode, task.getTargLoc()) |
| | | .eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()) |
| | | .eq(StringUtils.isNoneBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex()) |
| | | .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())); |
| | | if (Objects.isNull(locWorking)) { |
| | | throw new CoolException("数据错误,作业中库存数据丢失!!"); |
| | | } |
| | | if (locWorking.getAnfme().compareTo(taskItem.getAnfme()) >= 0) { |
| | | locWorking.setAnfme(Math.round((locWorking.getAnfme() - taskItem.getAnfme()) * 10000) / 10000.0); |
| | | } else { |
| | | continue; |
| | | } |
| | | |
| | | BeanUtils.copyProperties(locWorking, locItem); |
| | | locItem.setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null); |
| | | items.add(locItem); |
| | | } |
| | | |
| | | if (!locItemService.saveBatch(items)) { |
| | | throw new CoolException("作业库存回写失败!!"); |
| | | } |
| | | |
| | | if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) { |
| | | throw new CoolException("作业中库存删除失败!!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R pickTask(Long id) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R pickTask(Long id) throws Exception { |
| | | Task task = this.getById(id); |
| | | if (Objects.isNull(task)) { |
| | | throw new CoolException("当前任务不存在!!"); |
| | |
| | | throw new CoolException("没有空库位!!"); |
| | | } |
| | | |
| | | List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); |
| | | if (locItems.isEmpty()) { |
| | | throw new CoolException("库位明细不存在!!"); |
| | | } |
| | | |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, task); |
| | | //更新任务主单 |
| | | task.setTaskCode(ruleCode) |
| | | .setTaskType(TaskType.TASK_TYPE_PICK_IN.type) |
| | | .setTargLoc(task.getOrgLoc()) //出库源库位变入库目标库位 |
| | | .setBarcode(task.getBarcode()) |
| | | .setTaskStatus(TaskStsType.GENERATE_IN.id); |
| | | //TODO 后续需根据仓库类型查找新库位,原始库位置空闲状态 { |
| | | // TaskInParam param = new TaskInParam(); |
| | | // param.setSourceStaNo(Integer.parseInt(task.getOrgSite())) |
| | | // .setIoType(Integer.parseInt(TaskType.TASK_TYPE_IN.type + "")); |
| | | //// .setLocType1(LocType.LOC_TYPE_LOW.type);} |
| | | |
| | | if (!this.updateById(task)) { |
| | | throw new CoolException("任务状态更新失败!!"); |
| | | } |
| | | |
| | | //修改库位状态 预约出库.R==>预约入库.S |
| | | loc.setUseStatus(StaUseStatusType.TYPE_S.type); |
| | | |
| | | if (!locService.updateById(loc)) { |
| | | throw new CoolException("库位状态更新失败!!"); |
| | | List<LocItemWorking> workings = new ArrayList<>(); |
| | | for (LocItem item : locItems) { |
| | | LocItemWorking working = new LocItemWorking(); |
| | | BeanUtils.copyProperties(item, working); |
| | | working.setId(null).setTaskId(task.getId()); |
| | | workings.add(working); |
| | | } |
| | | |
| | | if (!locItemWorkingService.saveBatch(workings)) { |
| | | throw new CoolException("临时库存保存失败!!"); |
| | | } |
| | | |
| | | return R.ok("拣货成功!!"); |
| | |
| | | * @description: 完成出库任务,更新出库库存信息 |
| | | * @version 1.0 |
| | | */ |
| | | @Synchronized |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized void complateOutStock(Task task) { |
| | | public void complateOutStock(Task task) throws Exception { |
| | | if (Objects.isNull(task)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | |
| | | } |
| | | try { |
| | | //更新库位明细 |
| | | subtractLocItem(taskItems, loc); |
| | | subtractLocItem(loc); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e.getMessage()); |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | |
| | | //添加出入库记录信息 |
| | |
| | | * @version 1.0 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void subtractLocItem(List<TaskItem> items, Loc loc) throws Exception { |
| | | public void subtractLocItem(Loc loc) throws Exception { |
| | | if (!locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()))) { |
| | | throw new CoolException("库存明细删除失败!!"); |
| | | } |
| | |
| | | if (Objects.isNull(task)) { |
| | | return; |
| | | } |
| | | |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())); |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("目标库位不存在!"); |
| | | } |
| | | |
| | | if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)) { |
| | | throw new CoolException("当前库位状态不处于S.入库预约,不可执行入库操作!"); |
| | | } |
| | | |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (taskItems.isEmpty()) { |
| | | throw new CoolException("任务明细不存在!!"); |