|  |  |  | 
|---|
|  |  |  | 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.api.controller.erp.params.TaskInParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.entity.dto.InTaskMsgDto; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.service.WcsService; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.constant.Constants; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.utils.SystemAuthUtils; | 
|---|
|  |  |  | import lombok.Synchronized; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | import java.util.stream.Stream; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service("taskService") | 
|---|
|  |  |  | public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Objects.isNull(deviceSite)) { | 
|---|
|  |  |  | throw new CoolException("站点不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(Integer.valueOf(deviceSite.getSite()))); | 
|---|
|  |  |  | DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(deviceSite.getSite())); | 
|---|
|  |  |  | if (Cools.isEmpty(deviceBind)) { | 
|---|
|  |  |  | throw new CoolException("库位规则未知"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!this.save(task)) { | 
|---|
|  |  |  | throw new CoolException("任务保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, deviceSite.getSite())); | 
|---|
|  |  |  | if (Objects.isNull(station) || station.getUseStatus() != LocStsType.LOC_STS_TYPE_O.type) { | 
|---|
|  |  |  | throw new CoolException("站点不存在或站点不处于空库状态!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (basStationService.updateById(station)) { | 
|---|
|  |  |  | 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()))) { | 
|---|
|  |  |  | throw new CoolException("库位预约失败!!"); | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void complateInTask(List<Task> tasks) throws Exception { | 
|---|
|  |  |  | Long loginUserId = SystemAuthUtils.getLoginUserId(); | 
|---|
|  |  |  | for (Task task : tasks) { | 
|---|
|  |  |  | //            if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) { | 
|---|
|  |  |  | //                //53.拣料再入库 | 
|---|
|  |  |  | //                //57.盘点再入库 | 
|---|
|  |  |  | //                pickComplateInStock(task, loginUserId); | 
|---|
|  |  |  | //            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) { | 
|---|
|  |  |  | //                //移库 | 
|---|
|  |  |  | //                moveInStock(task, loginUserId); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //1.入库 | 
|---|
|  |  |  | complateInstock(task, loginUserId); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) { | 
|---|
|  |  |  | //1.入库 | 
|---|
|  |  |  | complateInstock(task, loginUserId); | 
|---|
|  |  |  | } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) { | 
|---|
|  |  |  | //53.拣料再入库 | 
|---|
|  |  |  | //57.盘点再入库 | 
|---|
|  |  |  | pickComplateInStock(task, loginUserId); | 
|---|
|  |  |  | } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) { | 
|---|
|  |  |  | //移库 | 
|---|
|  |  |  | moveInStock(task, loginUserId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception ex) { | 
|---|
|  |  |  | log.error(ex.getMessage(), ex); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //更新库位明细 | 
|---|
|  |  |  | saveLocItem(taskItems, task.getId(), loginUserId); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException("库位明细更新失败!!"); | 
|---|
|  |  |  | throw new CoolException("任务号:" + task.getTaskCode() +  "库位明细更新失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocCode, task.getOrgLoc()))) { | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void completeTask(List<Task> tasks) { | 
|---|
|  |  |  | Long loginUserId = SystemAuthUtils.getLoginUserId(); | 
|---|
|  |  |  | for (Task task : tasks) { | 
|---|
|  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | complateOutStock(task, loginUserId); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | log.error(e.getMessage(), e); | 
|---|
|  |  |  | //                throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //保存入出库流水 | 
|---|
|  |  |  | saveStockItems(taskItems, task, null, null, taskItem.getWkType(), taskItem.getOrderType(), loginUserId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) { | 
|---|
|  |  |  | throw new CoolException("作业中库存删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | task.setTaskStatus(TaskStsType.UPDATED_IN.id).setUpdateTime(new Date()).setUpdateBy(loginUserId); | 
|---|
|  |  |  | if (!taskService.updateById(task)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | .setTaskStatus(TaskStsType.GENERATE_IN.id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TaskInParam param = new TaskInParam(); | 
|---|
|  |  |  | param.setSourceStaNo(Integer.parseInt(task.getTargSite())) | 
|---|
|  |  |  | param.setSourceStaNo(task.getTargSite()) | 
|---|
|  |  |  | .setIoType(type) | 
|---|
|  |  |  | .setLocType1(Integer.parseInt(loc.getType())); | 
|---|
|  |  |  | //获取新库位 | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Objects.isNull(locInfo)) { | 
|---|
|  |  |  | throw new CoolException("获取库位失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | task.setTargLoc(locInfo.getLocNo()); | 
|---|
|  |  |  | task.setTargLoc(locInfo.getLocNo()) | 
|---|
|  |  |  | .setOrgSite(task.getTargSite()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!this.updateById(task)) { | 
|---|
|  |  |  | throw new CoolException("任务状态更新失败!!"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val) | 
|---|
|  |  |  | || task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) { | 
|---|
|  |  |  | } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) { | 
|---|
|  |  |  | WkOrderItem orderItem = asnOrderItemService.getById(key); | 
|---|
|  |  |  | if (Objects.isNull(orderItem)) { | 
|---|
|  |  |  | throw new CoolException("单据明细不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | saveOutStockItem(maps.get(key), orderItem, null, null, loginUserId); | 
|---|
|  |  |  | saveOutStockItem(maps.get(key), orderItem,  loginUserId); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) { | 
|---|
|  |  |  | WkOrderItem orderItem = asnOrderItemService.getById(key); | 
|---|
|  |  |  | if (Objects.isNull(orderItem)) { | 
|---|
|  |  |  | throw new CoolException("单据明细不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | saveOutStockItem(maps.get(key), null, null, orderItem, loginUserId); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void saveOutStockItem(List<TaskItem> taskItems, CheckDiffItem diffItem, Long loginUserId) { | 
|---|
|  |  |  | public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem diffItem, Long loginUserId) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | saveOutStockItem(taskItems, null, null, diffItem, loginUserId); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem orderItem, WaveItem waveItem, CheckDiffItem diffItem, Long loginUserId) throws Exception { | 
|---|
|  |  |  | public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem orderItem, WaveItem waveItem, WkOrderItem diffItem, Long loginUserId) throws Exception { | 
|---|
|  |  |  | Stock stock = new Stock(); | 
|---|
|  |  |  | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null); | 
|---|
|  |  |  | if (StringUtils.isBlank(ruleCode)) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WkOrder order = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>().eq(WkOrder::getCode, code)); | 
|---|
|  |  |  | if (!Objects.isNull(order)) { | 
|---|
|  |  |  | Double qty = Math.round((order.getQty() + sum) * 10000) / 10000.0; | 
|---|
|  |  |  | order.setQty(qty).setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_EXCE.val); | 
|---|
|  |  |  | //            Double qty = Math.round((order.getQty() + sum) * 10000) / 10000.0; | 
|---|
|  |  |  | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_EXCE.val); | 
|---|
|  |  |  | if (!asnOrderService.updateById(order)) { | 
|---|
|  |  |  | throw new CoolException("入库单状态修改失败!!"); | 
|---|
|  |  |  | } | 
|---|