|
|
@@ -265,10 +265,25 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
@GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public R outboundWorkOrder(String ids) {
|
|
|
List<Long> shipIds = Func.toLongList(ids);
|
|
|
+ List<PjShip> pjShipList = baseMapper.selectList(new LambdaQueryWrapper<PjShip>()
|
|
|
+ .eq(PjShip::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjShip::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(id,'" + ids + "')"));
|
|
|
+ List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
+ List<PjShip> pjShips = new ArrayList<>();
|
|
|
+ if (!pjShipList.isEmpty()) {
|
|
|
+ List<Long> ordIds = pjShipList.stream().map(PjShip::getOrdId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ pjOrderItemsList = orderItemsService.list(new QueryWrapper<PjOrderItems>()
|
|
|
+ .in("pid", ordIds)
|
|
|
+ .eq("is_deleted", 0)
|
|
|
+ .apply("goods_num != send_num")
|
|
|
+ .eq("tenant_id", AuthUtil.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
for (Long id : shipIds) {
|
|
|
//获得出库任务数据
|
|
|
- PjShip rwShip = baseMapper.selectById(id);
|
|
|
- if (ObjectUtil.isEmpty(rwShip)) {
|
|
|
+ PjShip rwShip = pjShipList.stream().filter(e -> e.getId().equals(id)).findFirst().orElse(null);
|
|
|
+ if (rwShip == null) {
|
|
|
throw new RuntimeException("数据异常 请联系管理员");
|
|
|
}
|
|
|
|
|
|
@@ -292,17 +307,22 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
gdShip.setCreateTime(new Date());
|
|
|
gdShip.setTaskId(rwShip.getId());
|
|
|
gdShip.setSendTotalNum(new BigDecimal("0.00"));
|
|
|
- baseMapper.insert(gdShip);
|
|
|
+ pjShips.add(gdShip);
|
|
|
+ }
|
|
|
+ this.saveOrUpdateBatch(pjShips);
|
|
|
+ List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
+ List<PjShip> rwShipList = new ArrayList<>();
|
|
|
+ for (PjShip item : pjShips) {
|
|
|
+ //获得出库任务数据
|
|
|
+ PjShip rwShip = pjShipList.stream().filter(e -> e.getId().equals(item.getTaskId())).findFirst().orElse(null);
|
|
|
+ if (rwShip == null) {
|
|
|
+ throw new RuntimeException("数据异常 请联系管理员");
|
|
|
+ }
|
|
|
StringBuilder goodsNames = new StringBuilder();
|
|
|
|
|
|
//根据销售id获得销售明细数据
|
|
|
- List<PjOrderItems> list = orderItemsService.list(new QueryWrapper<PjOrderItems>()
|
|
|
- .eq("pid", rwShip.getOrdId())
|
|
|
- .eq("is_deleted", 0)
|
|
|
- .apply("goods_num != send_num")
|
|
|
- .eq("tenant_id", AuthUtil.getTenantId()));
|
|
|
+ List<PjOrderItems> list = pjOrderItemsList.stream().filter(e -> e.getPid().equals(item.getOrdId())).collect(Collectors.toList());
|
|
|
if (ObjectUtil.isNotEmpty(list)) {
|
|
|
- List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
for (PjOrderItems e : list) {
|
|
|
goodsNames.append(e.getGoodsName()).append(",");
|
|
|
//根据销售明细创建出库工单明细
|
|
|
@@ -310,7 +330,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
BeanUtil.copyProperties(e, shipItems);
|
|
|
|
|
|
shipItems.setId(null);
|
|
|
- shipItems.setPid(gdShip.getId());
|
|
|
+ shipItems.setPid(item.getId());
|
|
|
shipItems.setSrcItemId(e.getId());
|
|
|
shipItems.setCreateTime(new Date());
|
|
|
shipItems.setCreateUser(AuthUtil.getUserId());
|
|
|
@@ -319,18 +339,16 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if (e.getGoodsNum().compareTo(e.getSendNum()) != 0) {
|
|
|
shipItemsList.add(shipItems);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- shipItemsService.saveBatch(shipItemsList);
|
|
|
- gdShip.setNumberRows(list.size());
|
|
|
+ item.setNumberRows(list.size());
|
|
|
}
|
|
|
|
|
|
//修改出库任务状态
|
|
|
rwShip.setStatusName(OrderTypeEnum.DISPATCHED.getType());
|
|
|
- baseMapper.updateById(rwShip);
|
|
|
+ rwShipList.add(rwShip);
|
|
|
|
|
|
//生成出库工单历史记录
|
|
|
- saveHistory(gdShip.getId(), OrderTypeEnum.TOBESHIPPEDOUT.getType());
|
|
|
+ saveHistory(item.getId(), OrderTypeEnum.TOBESHIPPEDOUT.getType());
|
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
@@ -338,7 +356,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
//给角色为派工的人发送消息
|
|
|
if (ObjectUtils.isNotNull(rwShip.getStockClerkId())) {
|
|
|
Message sendMessage = new Message();
|
|
|
- sendMessage.setParameter(gdShip.getId() + "");
|
|
|
+ sendMessage.setParameter(item.getId() + "");
|
|
|
sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
sendMessage.setUserId(null);
|
|
|
sendMessage.setToUserId(rwShip.getStockClerkId());
|
|
|
@@ -350,7 +368,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
sendMessage.setUrl("/tirePartsMall/salesManagement/outboundWorkOrder/index");
|
|
|
sendMessage.setPageLabel("出库工单");
|
|
|
sendMessage.setPageStatus("this.$store.getters.domSaleStatus");
|
|
|
- sendMessage.setMessageBody("您有新的出库工单请及时处理!单号:" + gdShip.getBillno() + "时间:" + formatted);
|
|
|
+ sendMessage.setMessageBody("您有新的出库工单请及时处理!单号:" + item.getBillno() + "时间:" + formatted);
|
|
|
R save = messageClient.save(sendMessage);
|
|
|
System.out.println("发送结果:" + save);
|
|
|
if (!save.isSuccess()) {
|
|
|
@@ -360,12 +378,12 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
//给角色为派工的人发送消息
|
|
|
R<String> clientDeptIds = sysClient.getRoleIds(AuthUtil.getTenantId(), "库管");
|
|
|
if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|
|
|
- R<List<User>> userList = userClient.listUserByRoleId(Long.valueOf(clientDeptIds.getData()), AuthUtil.getTenantId(), gdShip.getSalesCompanyId());
|
|
|
+ R<List<User>> userList = userClient.listUserByRoleId(Long.valueOf(clientDeptIds.getData()), AuthUtil.getTenantId(), item.getSalesCompanyId());
|
|
|
if (userList.isSuccess() && CollectionUtils.isNotEmpty(userList.getData())) {
|
|
|
for (User datum : userList.getData()) {
|
|
|
//循环发送消息
|
|
|
Message sendMessage = new Message();
|
|
|
- sendMessage.setParameter(gdShip.getId() + "");
|
|
|
+ sendMessage.setParameter(item.getId() + "");
|
|
|
sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
sendMessage.setUserId(null);
|
|
|
sendMessage.setToUserId(datum.getId());
|
|
|
@@ -377,7 +395,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
sendMessage.setUrl("/tirePartsMall/salesManagement/outboundWorkOrder/index");
|
|
|
sendMessage.setPageLabel("出库工单");
|
|
|
sendMessage.setPageStatus("this.$store.getters.domSaleStatus");
|
|
|
- sendMessage.setMessageBody("您有新的出库工单请及时处理!单号:" + gdShip.getBillno() + "时间:" + formatted);
|
|
|
+ sendMessage.setMessageBody("您有新的出库工单请及时处理!单号:" + item.getBillno() + "时间:" + formatted);
|
|
|
R save = messageClient.save(sendMessage);
|
|
|
System.out.println("发送结果:" + save);
|
|
|
if (!save.isSuccess()) {
|
|
|
@@ -387,7 +405,6 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//给角色为财务的人发送消息
|
|
|
R<String> clientDeptIds = sysClient.getRoleIds(AuthUtil.getTenantId(), "客服");
|
|
|
StringBuilder openIds = new StringBuilder();
|
|
|
@@ -415,27 +432,27 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if (ObjectUtils.isNotNull(openIds)) {
|
|
|
R<List<WechatMessageConfigurationItem>> res = wechatClient.getTemplateType("1", AuthUtil.getTenantId());
|
|
|
if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
- gdShip.setDate(date1);
|
|
|
+ item.setDate(date1);
|
|
|
if (goodsNames.length() > 8) {
|
|
|
- gdShip.setGoodsNames(goodsNames.substring(0, 8));
|
|
|
+ item.setGoodsNames(goodsNames.substring(0, 8));
|
|
|
} else {
|
|
|
- gdShip.setGoodsNames(goodsNames.toString());
|
|
|
+ item.setGoodsNames(goodsNames.toString());
|
|
|
}
|
|
|
- if (gdShip.getCustomerName().length() > 8) {
|
|
|
- gdShip.setCustomerName(gdShip.getCustomerName().substring(0, 8));
|
|
|
+ if (item.getCustomerName().length() > 8) {
|
|
|
+ item.setCustomerName(item.getCustomerName().substring(0, 8));
|
|
|
}
|
|
|
List<WxMpTemplateData> data = new ArrayList<>();
|
|
|
- for (WechatMessageConfigurationItem item : res.getData()) {
|
|
|
+ for (WechatMessageConfigurationItem items : res.getData()) {
|
|
|
try {
|
|
|
// 根据方法名获取对应的Method对象
|
|
|
- Method method = gdShip.getClass().getMethod(item.getMethod());
|
|
|
+ Method method = item.getClass().getMethod(items.getMethod());
|
|
|
// 调用get方法并打印结果
|
|
|
- Object result = method.invoke(gdShip);
|
|
|
+ Object result = method.invoke(item);
|
|
|
System.out.println(result);
|
|
|
if (ObjectUtils.isNotNull(result)) {
|
|
|
- data.add(new WxMpTemplateData(item.getDataValue(), result.toString()));
|
|
|
+ data.add(new WxMpTemplateData(items.getDataValue(), result.toString()));
|
|
|
} else {
|
|
|
- data.add(new WxMpTemplateData(item.getDataValue(), "无"));
|
|
|
+ data.add(new WxMpTemplateData(items.getDataValue(), "无"));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -451,11 +468,11 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
System.out.println("=========发送返回值=========" + rest);
|
|
|
}
|
|
|
}
|
|
|
- /*String rest = wechatClient.sendMessage(openIds.substring(0, openIds.length() - 1), "订单出库通知", "订单出库通知", date1, gdShip.getCustomerName(), gdShip.getBillno(),
|
|
|
- "", "", goodsNames.toString(), new BigDecimal("0.00"), "1", AuthUtil.getTenantId());
|
|
|
- System.out.println("=========发送返回值=========" + rest);*/
|
|
|
}
|
|
|
}
|
|
|
+ this.saveOrUpdateBatch(rwShipList);
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
+
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
|
|
|
@@ -523,6 +540,24 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getStorageId, ship.getStorageId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds);
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(lambdaQueryWrapper);
|
|
|
+ List<Long> srcItemIds = ship.getShipItemsList().stream().map(PjShipItems::getSrcItemId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjOrderItems> pjOrderItems = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .in(PjOrderItems::getId, srcItemIds));
|
|
|
BigDecimal number = new BigDecimal("0.00");
|
|
|
for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
number = number.add(item.getSendNum());
|
|
|
@@ -539,7 +574,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
shipItemsList.add(item);
|
|
|
//获得商品
|
|
|
- PjGoodsDesc goodsDesc = goodsDescMapper.selectById(item.getGoodsId());
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
throw new RuntimeException("商品数据异常");
|
|
|
}
|
|
|
@@ -547,9 +582,8 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
throw new RuntimeException("商品:" + goodsDesc.getCname() + ",请求选择批次号");
|
|
|
}
|
|
|
|
|
|
- PjOrderItems orderItems = orderItemsService.getById(item.getSrcItemId());
|
|
|
- if (ObjectUtil.isNotEmpty(orderItems)) {
|
|
|
-
|
|
|
+ PjOrderItems orderItems = pjOrderItems.stream().filter(e -> e.getId().equals(item.getSrcItemId())).findFirst().orElse(null);
|
|
|
+ if (orderItems != null) {
|
|
|
if (orderItems.getGoodsNum().compareTo(orderItems.getSendNum().add(item.getSendNum())) < 0) {
|
|
|
throw new RuntimeException(orderItems.getGoodsName() + "剩余应发货数量" + orderItems.getGoodsNum().subtract(orderItems.getSendNum()));
|
|
|
} else {
|
|
|
@@ -559,23 +593,18 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
} else {
|
|
|
throw new RuntimeException("数据异常请联系管理员");
|
|
|
}
|
|
|
-
|
|
|
- //修改库存账
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, item.getGoodsId())
|
|
|
- .eq(PjStockDesc::getStorageId, ship.getStorageId());
|
|
|
//管理批次号
|
|
|
+ PjStockDesc stockOne = null;
|
|
|
if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getDot, item.getDot());
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
} else {
|
|
|
- lambdaQueryWrapper.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
}
|
|
|
-
|
|
|
- PjStockDesc stockOne = iStockDescService.getOne(lambdaQueryWrapper);
|
|
|
- if (ObjectUtil.isNotEmpty(stockOne)) {
|
|
|
+ if (stockOne != null) {
|
|
|
if (stockOne.getBalanceQuantity().compareTo(item.getSendNum()) < 0) {
|
|
|
throw new RuntimeException("库存不足,出库失败");
|
|
|
}
|
|
|
@@ -667,11 +696,29 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
List<PjShipItems> itemsList = new ArrayList<>();
|
|
|
List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getStorageId, ship.getStorageId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds);
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(lambdaQueryWrapper);
|
|
|
+ List<Long> srcItemIds = ship.getShipItemsList().stream().map(PjShipItems::getSrcItemId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjOrderItems> pjOrderItems = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .in(PjOrderItems::getId, srcItemIds));
|
|
|
BigDecimal number = new BigDecimal("0.00");
|
|
|
for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
number = number.add(item.getSendNum());
|
|
|
- PjOrderItems orderItems = orderItemsService.getById(item.getSrcItemId());
|
|
|
- if (ObjectUtil.isNotEmpty(orderItems)) {
|
|
|
+ PjOrderItems orderItems = pjOrderItems.stream().filter(e -> e.getId().equals(item.getSrcItemId())).findFirst().orElse(null);
|
|
|
+ if (orderItems != null) {
|
|
|
orderItems.setSendNum(orderItems.getSendNum().subtract(item.getSendNum()));
|
|
|
pjOrderItemsList.add(orderItems);
|
|
|
} else {
|
|
|
@@ -679,25 +726,22 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
|
|
|
//获得商品
|
|
|
- PjGoodsDesc goodsDesc = goodsDescMapper.selectById(item.getGoodsId());
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
throw new RuntimeException("商品数据异常");
|
|
|
}
|
|
|
- //修改库存账
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, item.getGoodsId())
|
|
|
- .eq(PjStockDesc::getStorageId, ship.getStorageId());
|
|
|
- if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {//管理批次号
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getDot, item.getDot());
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne = null;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
} else {
|
|
|
- lambdaQueryWrapper.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
}
|
|
|
-
|
|
|
- PjStockDesc stockOne = iStockDescService.getOne(lambdaQueryWrapper);
|
|
|
- if (ObjectUtil.isNotEmpty(stockOne)) {
|
|
|
+ if (stockOne != null) {
|
|
|
stockOne.setBalanceQuantity(stockOne.getBalanceQuantity().add(item.getSendNum()));
|
|
|
stockOne.setStoreInventory(stockOne.getBalanceQuantity());
|
|
|
stockOne.setInventoryAmount(stockOne.getInventoryAmount().add(item.getSendNum().multiply(stockOne.getInventoryCostPrice())));
|
|
|
@@ -764,9 +808,23 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
@GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public R generateWarehousing(String ids) {
|
|
|
List<Long> shipIds = Func.toLongList(ids);
|
|
|
+ List<PjShip> pjShipList = baseMapper.selectList(new LambdaQueryWrapper<PjShip>()
|
|
|
+ .eq(PjShip::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjShip::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(id,'" + ids + "')"));
|
|
|
+ List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
+ List<PjShip> pjShips = new ArrayList<>();
|
|
|
+ if (!pjShipList.isEmpty()) {
|
|
|
+ List<Long> ordIds = pjShipList.stream().map(PjShip::getOrdId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ pjOrderItemsList = orderItemsService.list(new QueryWrapper<PjOrderItems>()
|
|
|
+ .in("pid", ordIds)
|
|
|
+ .eq("is_deleted", 0)
|
|
|
+ .apply("goods_num != send_num")
|
|
|
+ .eq("tenant_id", AuthUtil.getTenantId()));
|
|
|
+ }
|
|
|
for (Long id : shipIds) {
|
|
|
//获得出库任务数据
|
|
|
- PjShip rwShip = baseMapper.selectById(id);
|
|
|
+ PjShip rwShip = pjShipList.stream().filter(e -> e.getId().equals(id)).findFirst().orElse(null);
|
|
|
if (ObjectUtil.isEmpty(rwShip)) {
|
|
|
throw new RuntimeException("数据异常 请联系管理员");
|
|
|
}
|
|
|
@@ -790,32 +848,35 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
gdShip.setCreateUser(AuthUtil.getUserId());
|
|
|
gdShip.setCreateTime(new Date());
|
|
|
gdShip.setTaskId(rwShip.getId());
|
|
|
- baseMapper.insert(gdShip);
|
|
|
-
|
|
|
+ pjShips.add(gdShip);
|
|
|
+ }
|
|
|
+ this.saveOrUpdateBatch(pjShips);
|
|
|
+ List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
+ List<PjShip> rwShipList = new ArrayList<>();
|
|
|
+ for (PjShip item : pjShips) {
|
|
|
+ //获得出库任务数据
|
|
|
+ PjShip rwShip = pjShipList.stream().filter(e -> e.getId().equals(item.getTaskId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isEmpty(rwShip)) {
|
|
|
+ throw new RuntimeException("数据异常 请联系管理员");
|
|
|
+ }
|
|
|
//根据采购id获得采购明细数据
|
|
|
- List<PjOrderItems> list = orderItemsService.list(new QueryWrapper<PjOrderItems>()
|
|
|
- .eq("pid", rwShip.getOrdId())
|
|
|
- .eq("is_deleted", 0)
|
|
|
- .apply("goods_num != send_num")
|
|
|
- .eq("tenant_id", AuthUtil.getTenantId()));
|
|
|
+ List<PjOrderItems> list = pjOrderItemsList.stream().filter(e -> e.getPid().equals(item.getOrdId())).collect(Collectors.toList());
|
|
|
if (ObjectUtil.isNotEmpty(list)) {
|
|
|
- List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
- list.forEach(e -> {
|
|
|
+ for (PjOrderItems e : list) {
|
|
|
//根据采购明细创建入库工单明细
|
|
|
PjShipItems shipItems = new PjShipItems();
|
|
|
BeanUtil.copyProperties(e, shipItems);
|
|
|
|
|
|
shipItems.setId(null);
|
|
|
- shipItems.setPid(gdShip.getId());
|
|
|
+ shipItems.setPid(item.getId());
|
|
|
shipItems.setSrcItemId(e.getId());
|
|
|
shipItems.setCreateTime(new Date());
|
|
|
shipItems.setCreateUser(AuthUtil.getUserId());
|
|
|
shipItems.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
shipItems.setSendNum(e.getGoodsNum().subtract(e.getSendNum()));
|
|
|
shipItemsList.add(shipItems);
|
|
|
- });
|
|
|
- shipItemsService.saveBatch(shipItemsList);
|
|
|
- gdShip.setNumberRows(list.size());
|
|
|
+ }
|
|
|
+ item.setNumberRows(list.size());
|
|
|
}
|
|
|
|
|
|
//修改入库任务状态
|
|
|
@@ -823,7 +884,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
baseMapper.updateById(rwShip);
|
|
|
|
|
|
//生成入库工单历史记录
|
|
|
- saveHistory(gdShip.getId(), OrderTypeEnum.TREATWAREHOUSING.getType());
|
|
|
+ saveHistory(item.getId(), OrderTypeEnum.TREATWAREHOUSING.getType());
|
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
@@ -831,7 +892,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
//给角色为派工的人发送消息
|
|
|
if (ObjectUtils.isNotNull(rwShip.getStockClerkId())) {
|
|
|
Message sendMessage = new Message();
|
|
|
- sendMessage.setParameter(gdShip.getId() + "");
|
|
|
+ sendMessage.setParameter(item.getId() + "");
|
|
|
sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
sendMessage.setUserId(null);
|
|
|
sendMessage.setToUserId(rwShip.getStockClerkId());
|
|
|
@@ -843,7 +904,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
sendMessage.setUrl("/tirePartsMall/purchasingManagement/warehouseEntryOrder/index");
|
|
|
sendMessage.setPageLabel("采购入库");
|
|
|
sendMessage.setPageStatus("this.$store.getters.domSaleStatus");
|
|
|
- sendMessage.setMessageBody("您有新的采购入库请及时处理!单号:" + gdShip.getBillno() + "时间:" + formatted);
|
|
|
+ sendMessage.setMessageBody("您有新的采购入库请及时处理!单号:" + item.getBillno() + "时间:" + formatted);
|
|
|
R save = messageClient.save(sendMessage);
|
|
|
System.out.println("发送结果:" + save);
|
|
|
if (!save.isSuccess()) {
|
|
|
@@ -853,12 +914,12 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
//给角色为派工的人发送消息
|
|
|
R<String> clientDeptIds = sysClient.getRoleIds(AuthUtil.getTenantId(), "库管");
|
|
|
if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|
|
|
- R<List<User>> userList = userClient.listUserByRoleId(Long.valueOf(clientDeptIds.getData()), AuthUtil.getTenantId(), gdShip.getSalesCompanyId());
|
|
|
+ R<List<User>> userList = userClient.listUserByRoleId(Long.valueOf(clientDeptIds.getData()), AuthUtil.getTenantId(), item.getSalesCompanyId());
|
|
|
if (userList.isSuccess() && CollectionUtils.isNotEmpty(userList.getData())) {
|
|
|
for (User datum : userList.getData()) {
|
|
|
//循环发送消息
|
|
|
Message sendMessage = new Message();
|
|
|
- sendMessage.setParameter(gdShip.getId() + "");
|
|
|
+ sendMessage.setParameter(item.getId() + "");
|
|
|
sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
sendMessage.setUserId(null);
|
|
|
sendMessage.setToUserId(datum.getId());
|
|
|
@@ -870,7 +931,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
sendMessage.setUrl("/tirePartsMall/purchasingManagement/warehouseEntryOrder/index");
|
|
|
sendMessage.setPageLabel("采购入库");
|
|
|
sendMessage.setPageStatus("this.$store.getters.domSaleStatus");
|
|
|
- sendMessage.setMessageBody("您有新的采购入库请及时处理!单号:" + gdShip.getBillno() + "时间:" + formatted);
|
|
|
+ sendMessage.setMessageBody("您有新的采购入库请及时处理!单号:" + item.getBillno() + "时间:" + formatted);
|
|
|
R save = messageClient.save(sendMessage);
|
|
|
System.out.println("发送结果:" + save);
|
|
|
if (!save.isSuccess()) {
|
|
|
@@ -881,7 +942,8 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ this.saveOrUpdateBatch(rwShipList);
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
|
|
|
@@ -921,7 +983,29 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
- ship.getShipItemsList().forEach(item -> {
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(new LambdaQueryWrapper<PjStockDesc>().eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds));
|
|
|
+ List<PjGoodsType> pjGoodsTypeList = goodsTypeMapper.selectList(new LambdaQueryWrapper<PjGoodsType>()
|
|
|
+ .eq(PjGoodsType::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsType::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsType::getId, goodIds)
|
|
|
+ );
|
|
|
+ List<Long> srcItemIds = ship.getShipItemsList().stream().map(PjShipItems::getSrcItemId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjOrderItems> pjOrderItems = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .in(PjOrderItems::getId, srcItemIds));
|
|
|
+ //获得仓库
|
|
|
+ PjStorageDesc storageDesc = storageDescMapper.selectById(ship.getStorageId());
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
if (item.getId() == null) {
|
|
|
item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
item.setCreateTime(new Date());
|
|
|
@@ -936,41 +1020,36 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
shipItemsList.add(item);
|
|
|
|
|
|
//获得商品
|
|
|
- PjGoodsDesc goodsDesc = goodsDescMapper.selectById(item.getGoodsId());
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
throw new RuntimeException("商品数据异常");
|
|
|
}
|
|
|
|
|
|
- PjOrderItems orderItems = orderItemsService.getById(item.getSrcItemId());
|
|
|
- if (ObjectUtil.isNotEmpty(orderItems)) {
|
|
|
+ PjOrderItems orderItems = pjOrderItems.stream().filter(e -> e.getId().equals(item.getSrcItemId())).findFirst().orElse(null);
|
|
|
+ if (orderItems != null) {
|
|
|
orderItems.setSendNum(orderItems.getSendNum().add(item.getSendNum()));
|
|
|
pjOrderItemsList.add(orderItems);
|
|
|
} else {
|
|
|
throw new RuntimeException("数据异常请联系管理员");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
//生成库存账
|
|
|
PjStockDesc stockDesc = new PjStockDesc();
|
|
|
-
|
|
|
stockDesc.setSalesCompanyId(ship.getSalesCompanyId());
|
|
|
stockDesc.setSalesCompanyName(ship.getSalesCompanyName());
|
|
|
stockDesc.setGoodsTypeId(goodsDesc.getGoodsTypeId());
|
|
|
if (ObjectUtils.isNotNull(goodsDesc.getGoodsTypeId())) {
|
|
|
- PjGoodsType goodsType = goodsTypeMapper.selectById(goodsDesc.getGoodsTypeId());
|
|
|
- if (ObjectUtils.isNotNull(goodsType)) {
|
|
|
+
|
|
|
+ PjGoodsType goodsType = pjGoodsTypeList.stream().filter(e -> (e.getId() + "").equals(goodsDesc.getGoodsTypeId())).findFirst().orElse(null);
|
|
|
+ if (goodsType != null) {
|
|
|
stockDesc.setGoodsTypeName(goodsType.getCname());
|
|
|
}
|
|
|
}
|
|
|
- //获得仓库
|
|
|
- PjStorageDesc storageDesc = storageDescMapper.selectById(ship.getStorageId());
|
|
|
if (ObjectUtil.isNotEmpty(storageDesc)) {
|
|
|
stockDesc.setStorageId(storageDesc.getId());
|
|
|
stockDesc.setStorageName(storageDesc.getCname());
|
|
|
} else {
|
|
|
throw new RuntimeException("仓库数据异常");
|
|
|
}
|
|
|
-
|
|
|
stockDesc.setGoodsId(goodsDesc.getId());
|
|
|
stockDesc.setCode(item.getGoodsNo());
|
|
|
stockDesc.setCname(goodsDesc.getCname());
|
|
|
@@ -983,23 +1062,20 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
stockDesc.setDot(item.getDot());
|
|
|
stockDesc.setTenantId(AuthUtil.getTenantId());
|
|
|
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, goodsDesc.getId())
|
|
|
- .eq(PjStockDesc::getStorageId, ship.getStorageId());
|
|
|
- if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {//管理批次号
|
|
|
- if (ObjectUtil.isEmpty(item.getDot())) {
|
|
|
- throw new RuntimeException(goodsDesc.getCname() + "已开启批次号管理,请填写批次号");
|
|
|
- }
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getDot, item.getDot());
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
} else {
|
|
|
- lambdaQueryWrapper.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
}
|
|
|
-
|
|
|
- PjStockDesc stockOne = iStockDescService.getOne(lambdaQueryWrapper);
|
|
|
- if (ObjectUtil.isEmpty(stockOne)) {
|
|
|
+ if (stockOne == null) {
|
|
|
stockDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
stockDesc.setCreateTime(new Date());
|
|
|
stockDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
@@ -1024,52 +1100,47 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
stockDesc.setVersion(stockOne.getVersion());
|
|
|
}
|
|
|
- boolean count = iStockDescService.saveOrUpdate(stockDesc);
|
|
|
+ /*boolean count = iStockDescService.saveOrUpdate(stockDesc);
|
|
|
if (!count) {
|
|
|
throw new RuntimeException(stockOne.getCname() + "该产品库存正在操作,请稍后刷新在进行操作!");
|
|
|
- }
|
|
|
+ }*/
|
|
|
pjStockDescArrayList.add(stockDesc);
|
|
|
- });
|
|
|
+ }
|
|
|
shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
-// iStockDescService.saveOrUpdateBatch(pjStockDescArrayList);
|
|
|
+ iStockDescService.saveOrUpdateBatch(pjStockDescArrayList);
|
|
|
orderItemsService.updateBatchById(pjOrderItemsList);
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .isNull(PjProductLaunch::getSourceId)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjProductLaunch::getGoodsId, goodIds);
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
number = number.add(item.getSendNum());
|
|
|
//获得商品
|
|
|
- PjGoodsDesc goodsDesc = goodsDescMapper.selectById(item.getGoodsId());
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
throw new RuntimeException("商品数据异常");
|
|
|
}
|
|
|
- /** ----------------------修改上架库存---------------------- */
|
|
|
-
|
|
|
- //查询所有该商品的库存
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperList = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapperList.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, goodsDesc.getId());
|
|
|
- List<PjStockDesc> stockDescList = iStockDescService.list(lambdaQueryWrapperList);
|
|
|
+ /* ----------------------修改上架库存---------------------- */
|
|
|
+ List<PjStockDesc> stockDescList = pjStockDescList.stream().filter(e -> e.getGoodsId().equals(goodsDesc.getId())).collect(Collectors.toList());
|
|
|
|
|
|
//库存总数量
|
|
|
BigDecimal balanceQuantity = stockDescList.stream().map(PjStockDesc::getBalanceQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ balanceQuantity = balanceQuantity.add(item.getSendNum());
|
|
|
|
|
|
- //查询所有上架商品
|
|
|
- LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
- .isNull(PjProductLaunch::getSourceId)
|
|
|
- .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjProductLaunch::getGoodsId, goodsDesc.getId());
|
|
|
- List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
+ List<PjProductLaunch> pjProductLaunches = productLaunch.stream().filter(e -> e.getGoodsId().equals(goodsDesc.getId())).collect(Collectors.toList());
|
|
|
//修改上架数量
|
|
|
- if (ObjectUtil.isNotEmpty(productLaunch)) {
|
|
|
- productLaunch.forEach(e -> {
|
|
|
+ if (!pjProductLaunches.isEmpty()) {
|
|
|
+ for (PjProductLaunch e : pjProductLaunches) {
|
|
|
e.setInventory(balanceQuantity);
|
|
|
pjProductLaunchList.add(e);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /** ----------------------修改上架库存---------------------- */
|
|
|
+ /* ----------------------修改上架库存---------------------- */
|
|
|
}
|
|
|
R res = productLaunchService.updateBatchById(pjProductLaunchList);
|
|
|
if (!res.isSuccess()) {
|
|
|
@@ -1222,13 +1293,31 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
ship.setUpdateTime(new Date());
|
|
|
baseMapper.updateById(ship);
|
|
|
}
|
|
|
-
|
|
|
// 保存订单明细
|
|
|
if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
- ship.getShipItemsList().forEach(item -> {
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(new LambdaQueryWrapper<PjStockDesc>().eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds));
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .isNull(PjProductLaunch::getSourceId)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjProductLaunch::getGoodsId, goodIds);
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
+
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
if (item.getId() == null) {
|
|
|
item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
item.setCreateTime(new Date());
|
|
|
@@ -1242,29 +1331,24 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
shipItemsList.add(item);
|
|
|
//获得商品
|
|
|
- PjGoodsDesc goodsDesc = goodsDescMapper.selectById(item.getGoodsId());
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
throw new RuntimeException("商品数据异常");
|
|
|
}
|
|
|
-
|
|
|
- //获得库存账
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, goodsDesc.getId())
|
|
|
- .eq(PjStockDesc::getStorageId, ship.getStorageId());
|
|
|
- if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {//管理批次号
|
|
|
- if (ObjectUtil.isEmpty(item.getDot())) {
|
|
|
- throw new RuntimeException(goodsDesc.getCname() + "已开启批次号管理,请填写批次号");
|
|
|
- }
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getDot, item.getDot());
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
} else {
|
|
|
- lambdaQueryWrapper.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
}
|
|
|
-
|
|
|
- PjStockDesc stockOne = iStockDescService.getOne(lambdaQueryWrapper);
|
|
|
- if (ObjectUtil.isEmpty(stockOne)) {
|
|
|
+ if (stockOne == null) {
|
|
|
throw new RuntimeException("获取库存账失败");
|
|
|
} else {
|
|
|
stockOne.setUpdateTime(new Date());
|
|
|
@@ -1278,38 +1362,22 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
stockOne.setInventoryCostPrice(stockOne.getInventoryAmount().divide(stockOne.getBalanceQuantity(), MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
pjStockDescArrayList.add(stockOne);
|
|
|
}
|
|
|
-
|
|
|
- /** ----------------------修改上架库存---------------------- */
|
|
|
-
|
|
|
+ /* ----------------------修改上架库存---------------------- */
|
|
|
//查询所有该商品的库存
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperList = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapperList.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, goodsDesc.getId());
|
|
|
- List<PjStockDesc> stockDescList = iStockDescService.list(lambdaQueryWrapperList);
|
|
|
-
|
|
|
+ List<PjStockDesc> stockDescList = pjStockDescList.stream().filter(e -> e.getGoodsId().equals(goodsDesc.getId())).collect(Collectors.toList());
|
|
|
//库存总数量
|
|
|
BigDecimal balanceQuantity = stockDescList.stream().map(PjStockDesc::getBalanceQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
//查询所有上架商品
|
|
|
- LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
- .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjProductLaunch::getGoodsId, stockOne.getGoodsId());
|
|
|
- List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
-
|
|
|
+ List<PjProductLaunch> pjProductLaunches = productLaunch.stream().filter(e -> e.getGoodsId().equals(goodsDesc.getId())).collect(Collectors.toList());
|
|
|
//修改上架数量
|
|
|
- if (ObjectUtil.isNotEmpty(productLaunch)) {
|
|
|
- productLaunch.forEach(e -> {
|
|
|
+ if (!pjProductLaunches.isEmpty()) {
|
|
|
+ for (PjProductLaunch e : pjProductLaunches) {
|
|
|
e.setInventory(balanceQuantity);
|
|
|
pjProductLaunchList.add(e);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- /** ----------------------修改上架库存---------------------- */
|
|
|
- });
|
|
|
+ /* ----------------------修改上架库存---------------------- */
|
|
|
+ }
|
|
|
shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
iStockDescService.saveOrUpdateBatch(pjStockDescArrayList);
|
|
|
R res = productLaunchService.updateBatchById(pjProductLaunchList);
|
|
|
@@ -1336,31 +1404,43 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
// 保存订单明细
|
|
|
BigDecimal number = new BigDecimal("0.00");
|
|
|
if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(new LambdaQueryWrapper<PjStockDesc>().eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds));
|
|
|
+ List<Long> srcItemIds = ship.getShipItemsList().stream().map(PjShipItems::getSrcItemId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjOrderItems> pjOrderItems = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .in(PjOrderItems::getId, srcItemIds));
|
|
|
List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
number = number.add(item.getSendNum());
|
|
|
//获得商品
|
|
|
- PjGoodsDesc goodsDesc = goodsDescMapper.selectById(item.getGoodsId());
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
throw new RuntimeException("商品数据异常");
|
|
|
}
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, goodsDesc.getId())
|
|
|
- .eq(PjStockDesc::getStorageId, ship.getStorageId());
|
|
|
- if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {//管理批次号
|
|
|
- if (ObjectUtil.isEmpty(item.getDot())) {
|
|
|
- throw new RuntimeException(goodsDesc.getCname() + "已开启批次号管理,请填写批次号");
|
|
|
- }
|
|
|
- lambdaQueryWrapper.eq(PjStockDesc::getDot, item.getDot());
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
} else {
|
|
|
- lambdaQueryWrapper.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
}
|
|
|
-
|
|
|
- PjStockDesc stockOne = iStockDescService.getOne(lambdaQueryWrapper);
|
|
|
- if (ObjectUtils.isNotNull(stockOne)) {
|
|
|
+ if (stockOne != null) {
|
|
|
if (stockOne.getBalanceQuantity().compareTo(item.getSendNum()) < 0) {
|
|
|
throw new RuntimeException(goodsDesc.getCname() + "库存不足,禁止撤销");
|
|
|
}
|
|
|
@@ -1375,28 +1455,30 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
stockOne.setInventoryCostPrice(stockOne.getInventoryAmount().divide(stockOne.getBalanceQuantity(), MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
stockOne.setVersion(stockOne.getVersion());
|
|
|
- R res = iStockDescService.updateByIdNew(stockOne);
|
|
|
+ /*R res = iStockDescService.updateByIdNew(stockOne);
|
|
|
if (!res.isSuccess()) {
|
|
|
throw new RuntimeException(res.getMsg());
|
|
|
- }
|
|
|
+ }*/
|
|
|
pjStockDescArrayList.add(stockOne);
|
|
|
}
|
|
|
}
|
|
|
+ iStockDescService.saveOrUpdateBatch(pjStockDescArrayList);
|
|
|
List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
- ship.getShipItemsList().forEach(item -> {
|
|
|
- /** ----------------------修改上架库存---------------------- */
|
|
|
-
|
|
|
- //查询所有该商品的库存
|
|
|
- LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperList = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapperList.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
- .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjStockDesc::getGoodsId, item.getGoodsId());
|
|
|
- List<PjStockDesc> stockDescList = iStockDescService.list(lambdaQueryWrapperList);
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .isNull(PjProductLaunch::getSourceId)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjProductLaunch::getGoodsId, goodIds);
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
|
|
|
- PjOrderItems orderItems = orderItemsService.getById(item.getSrcItemId());
|
|
|
- if (ObjectUtil.isNotEmpty(orderItems)) {
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ /* ----------------------修改上架库存---------------------- */
|
|
|
+ List<PjStockDesc> stockDescList = pjStockDescList.stream().filter(e -> e.getGoodsId().equals(item.getGoodsId())).collect(Collectors.toList());
|
|
|
+ PjOrderItems orderItems = pjOrderItems.stream().filter(e -> e.getId().equals(item.getSrcItemId())).findFirst().orElse(null);
|
|
|
+ if (orderItems != null) {
|
|
|
orderItems.setSendNum(orderItems.getSendNum().subtract(item.getSendNum()));
|
|
|
pjOrderItemsList.add(orderItems);
|
|
|
} else {
|
|
|
@@ -1406,22 +1488,16 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
//库存总数量
|
|
|
BigDecimal balanceQuantity = stockDescList.stream().map(PjStockDesc::getBalanceQuantity).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
- //查询所有上架商品
|
|
|
- LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
- .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
- .eq(PjProductLaunch::getGoodsId, item.getGoodsId());
|
|
|
- List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
+ List<PjProductLaunch> pjProductLaunches = productLaunch.stream().filter(e -> e.getGoodsId().equals(item.getGoodsId())).collect(Collectors.toList());
|
|
|
//修改上架数量
|
|
|
- if (ObjectUtil.isNotEmpty(productLaunch)) {
|
|
|
- productLaunch.forEach(e -> {
|
|
|
+ if (!pjProductLaunches.isEmpty()) {
|
|
|
+ for (PjProductLaunch e : pjProductLaunches) {
|
|
|
e.setInventory(balanceQuantity);
|
|
|
pjProductLaunchList.add(e);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
- /** ----------------------修改上架库存---------------------- */
|
|
|
- });
|
|
|
+ /* ----------------------修改上架库存---------------------- */
|
|
|
+ }
|
|
|
orderItemsService.updateBatchById(pjOrderItemsList);
|
|
|
R res = productLaunchService.updateBatchById(pjProductLaunchList);
|
|
|
if (!res.isSuccess()) {
|