public OutboundOrderVO save(OutboundOrderAddDTO dto) {
int dataDependency = 0;
OutboundOrder model = BeanUtil.toBean(dto, OutboundOrder.class);
model.setCompanyId(SecurityUtils.getCompanyId());
model.setCreateId(SecurityUtils.getLoginUser().getStaffId());
// 判断仓库是否可以出入库
List<String> consumableIds = dto.getInfoList().stream().map(OutboundInfoAddDTO::getConsumableId).collect(Collectors.toList());
// 根据耗材id查询所在仓库
List<Consumables> consumablesList = consumablesService.listByIds(consumableIds);
Set<String> wareHouseIds = consumablesList.stream().map(Consumables::getWarehouseId).collect(Collectors.toSet());
List<String> lockingList = wareHouseService.findByIds(wareHouseIds, CommonConstant.WARE_HOUSE_LOCKING).stream().map(WareHouse::getId).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(lockingList)) {
// 所选耗材中存在仓库已经锁定,不能出库
dataDependency = 1;
List<Consumables> lockingConsumables = consumablesList.stream().filter(t -> lockingList.contains(t.getWarehouseId())).collect(Collectors.toList());
StringBuffer msg = new StringBuffer();
for (int i = 0; i < lockingConsumables.size(); i++) {
msg.append(lockingConsumables.get(i).getConsumablesName());
if (i != lockingConsumables.size() - 1) {
msg.append(",");
}
}
throw new BizException("耗材:" + msg + "所在仓库暂时禁止出入库");
}
dataDependency = 2;
// 获取流程审批单号单号
ProcedureAddDTO procedureAddDTO = dto.getProcedureAddDTO();
if (procedureAddDTO == null) {
throw new BizException("流程数据不能为空");
}
String processId= FlowCodeUtils.getFlowCode();
model.setProcessId(processId);
procedureAddDTO.setNumberId(processId);
boolean isOdoType = false;
if ((isOdoType = CommonConstant.ODO_TYPE.equals(model.getOdoType())) || CommonConstant.ODO_TYPE_SELF_APPLY.equals(model.getOdoType())) {
int y = dataDependency;
if(isOdoType){
model.setOdoCode(CommonConstant.CK_CHAR + CodeRandom.getRandom(CommonConstant.CODE_RANDOM_BIT));
}else {
model.setOdoCode(CommonConstant.ZZCK_CHAR + CodeRandom.getRandom(CommonConstant.CODE_RANDOM_BIT));
}
// 设置出库单的初始状态为:派发待确认
model.setOdoStatus(CommonConstant.ODO_DISTRIBUTION_CONFIRMING);
super.save(model);
try {
dataDependency = 3;
remoteFlowService.remoteSaveProduce(procedureAddDTO);
} catch (RuntimeException e) {
throw new BizException("发起流程失败,请联系管理员");
}
// 新增出库详情
String odoId = model.getId();
dto.getInfoList().forEach(e -> outboundInfoService.save(e, odoId));
return BeanUtil.toBean(model, OutboundOrderVO.class);
} else {
dataDependency = 4;
// 出库申请
return outApplySave(model, dto.getInfoList(),dto.getProcedureAddDTO());
}
}
dataDependency变量是我后面加的。没加之前出现了问题:
下面这句代码执行了,抛出了异常。这句代码在源代码中的前面
throw new BizException("耗材:" + msg + "所在仓库暂时禁止出入库");
但是在下面的这句代码也执行了,按道理下面这个去新增的代码不应该执行,或许是因为重排序。所以我用dataDependency 添加数据依赖防止重排序,但不确定是否正确。
remoteFlowService.remoteSaveProduce(procedureAddDTO);