|
|
@@ -4051,14 +4051,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
throw new RuntimeException("请选择明细数据");
|
|
|
}
|
|
|
PjOrder pjOrder = baseMapper.selectById(order.getId());
|
|
|
- if (ObjectUtils.isNotNull(pjOrder.getSharedCompanyId())) {
|
|
|
- pjOrder.setSharedCompanyId(pjOrder.getSharedCompanyId() + "," + order.getSharedCompanyId());
|
|
|
- pjOrder.setSharedCompanyName(pjOrder.getSharedCompanyName() + "," + order.getSharedCompanyName());
|
|
|
- } else {
|
|
|
- pjOrder.setSharedCompanyId(order.getSharedCompanyId());
|
|
|
- pjOrder.setSharedCompanyName(order.getSharedCompanyName());
|
|
|
- }
|
|
|
- baseMapper.updateById(pjOrder);
|
|
|
List<ShareSalesItems> shareSalesItemsList = new ArrayList<>();
|
|
|
List<SharePutOnShelves> sharePutOnShelvesList = new ArrayList<>();
|
|
|
if (ObjectUtils.isNull(pjOrder.getOldTrxId())) {
|
|
|
@@ -4098,6 +4090,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
shareSalesItems.setCreateTime(new Date());
|
|
|
shareSalesItems.setGoodsId(item.getGoodsId());
|
|
|
shareSalesItems.setGoodsName(item.getGoodsName());
|
|
|
+ shareSalesItems.setGoodsCode(item.getGoodsNo());
|
|
|
shareSalesItems.setGoodsNum(item.getOutGoodsTotalShipNum());
|
|
|
shareSalesItems.setPrice(item.getPrice());
|
|
|
shareSalesItems.setSubTotalMoney(item.getOutGoodsTotalShipNum().multiply(item.getPrice()));
|
|
|
@@ -4134,18 +4127,27 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
if (dept == null) {
|
|
|
throw new RuntimeException("未找到共享公司");
|
|
|
}
|
|
|
- PjCorpsDesc corpsDesc = corpsDescMapper.selectByName(dept.getDeptName(), dept.getTenantId());
|
|
|
+ R<Dept> res = sysClient.getDept(Long.parseLong(AuthUtil.getDeptId()));
|
|
|
+ if (!res.isSuccess() || ObjectUtils.isNull(res.getData())) {
|
|
|
+ throw new RuntimeException("未找到机构");
|
|
|
+ }
|
|
|
+ PjCorpsDesc corpsDesc = corpsDescMapper.selectByName(res.getData().getDeptName(), dept.getTenantId());
|
|
|
if (corpsDesc == null) {
|
|
|
corpsDesc = new PjCorpsDesc();
|
|
|
- corpsDesc.setCname(dept.getDeptName());
|
|
|
+ corpsDesc.setId(IdWorker.getId());
|
|
|
+ corpsDesc.setCname(res.getData().getDeptName());
|
|
|
+ corpsDesc.setCorpType("KH");
|
|
|
corpsDesc.setTenantId(dept.getTenantId());
|
|
|
- corpsDesc.setRemarks("来源共享共享公司:" + dept.getDeptName());
|
|
|
+ corpsDesc.setRemarks("来源共享共享公司:" + res.getData().getDeptName());
|
|
|
+ corpsDesc.setSalesCompanyId(dept.getId());
|
|
|
+ corpsDesc.setSalesCompanyName(dept.getDeptName());
|
|
|
int count = corpsDescMapper.insertCorps(corpsDesc);
|
|
|
if (count == 0) {
|
|
|
throw new RuntimeException("派发失败,创建客户错误");
|
|
|
}
|
|
|
}
|
|
|
PjOrder sharePjOrder = new PjOrder();
|
|
|
+ sharePjOrder.setRemarks("来源" + res.getData().getDeptName() + "销售单");
|
|
|
Long sharePjOrderId = IdWorker.getId();
|
|
|
sharePjOrder.setId(sharePjOrderId);
|
|
|
sharePjOrder.setTenantId(dept.getTenantId());
|
|
|
@@ -4168,15 +4170,18 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
sharePjOrder.setSalesCompanyName(dept.getDeptName());
|
|
|
sharePjOrder.setBusinessSource("共享销售");
|
|
|
sharePjOrder.setStatus("待确认");
|
|
|
- R<Dept> res = sysClient.getDept(Long.parseLong(AuthUtil.getDeptId()));
|
|
|
- if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
- sharePjOrder.setRemarks("来源" + res.getData().getDeptName() + "销售单");
|
|
|
- }
|
|
|
String goodsNo = orderItemsList.stream().map(PjOrderItems::getGoodsNo).distinct().collect(Collectors.joining(","));
|
|
|
List<PjGoodsDesc> goodsDescList = goodsDescMapper.selectListGoods(goodsNo, dept.getTenantId());
|
|
|
if (goodsDescList.isEmpty()) {
|
|
|
throw new RuntimeException("未查到对应商品信息");
|
|
|
}
|
|
|
+ List<PjProductLaunch> productLaunchList = productLaunchService.selectListProductLaunch(goodsNo, null, dept.getTenantId());
|
|
|
+ if (productLaunchList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到对应商品信息");
|
|
|
+ }
|
|
|
+ List<SharePutOnShelves> sharePutOnShelvesSrcList = sharePutOnShelvesService.selectSharePutOnShelvesList(goodsNo, null, dept.getTenantId());
|
|
|
+ List<PjProductLaunch> productLaunchListNew = new ArrayList<>();
|
|
|
+ List<SharePutOnShelves> sharePutOnShelvesSrcListNew = new ArrayList<>();
|
|
|
List<PjOrderItems> itemsList = new ArrayList<>();
|
|
|
for (PjOrderItems items : orderItemsList) {
|
|
|
PjOrderItems orderItems = new PjOrderItems();
|
|
|
@@ -4185,6 +4190,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
PjGoodsDesc goodsDesc = goodsDescList.stream().filter(e -> e.getCode().equals(items.getGoodsNo())).findFirst().orElse(null);
|
|
|
if (goodsDesc != null) {
|
|
|
+ orderItems.setCnameInt(goodsDesc.getCnameInt());
|
|
|
orderItems.setGoodsNo(goodsDesc.getCode());
|
|
|
orderItems.setGoodsName(goodsDesc.getCname());
|
|
|
orderItems.setGoodsId(goodsDesc.getId());
|
|
|
@@ -4197,6 +4203,30 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
} else {
|
|
|
throw new RuntimeException("商品编号:" + items.getGoodsNo() + "未查到");
|
|
|
}
|
|
|
+ PjProductLaunch pjProductLaunch = productLaunchList.stream().filter(e -> e.getCode().equals(items.getGoodsNo())).findFirst().orElse(null);
|
|
|
+ if (pjProductLaunch != null) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(pjProductLaunch.getInventory()) != 0
|
|
|
+ && pjProductLaunch.getInventory().compareTo(items.getOutGoodsTotalShipNum()) >= 0) {
|
|
|
+ pjProductLaunch.setInventory(pjProductLaunch.getInventory().subtract(items.getOutGoodsTotalShipNum()));
|
|
|
+ productLaunchListNew.add(pjProductLaunch);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + items.getGoodsNo() + "库存不足");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + items.getGoodsNo() + "未查到上架");
|
|
|
+ }
|
|
|
+ SharePutOnShelves sharePutOnShelves = sharePutOnShelvesSrcList.stream().filter(e -> e.getGoodsCode().equals(items.getGoodsNo())).findFirst().orElse(null);
|
|
|
+ if (sharePutOnShelves != null) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(sharePutOnShelves.getInventory()) != 0
|
|
|
+ && sharePutOnShelves.getInventory().compareTo(items.getOutGoodsTotalShipNum()) >= 0) {
|
|
|
+ sharePutOnShelves.setInventory(sharePutOnShelves.getInventory().subtract(items.getOutGoodsTotalShipNum()));
|
|
|
+ sharePutOnShelvesSrcListNew.add(sharePutOnShelves);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + items.getGoodsNo() + "库存不足");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + items.getGoodsNo() + "未查到上架");
|
|
|
+ }
|
|
|
orderItems.setDot(items.getDot());
|
|
|
orderItems.setSalesCompanyId(dept.getId());
|
|
|
orderItems.setSalesCompanyName(dept.getDeptName());
|
|
|
@@ -4218,12 +4248,26 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
}
|
|
|
itemsList.add(orderItems);
|
|
|
}
|
|
|
+ for (PjProductLaunch item : productLaunchListNew) {
|
|
|
+ int count = productLaunchService.updateProductLaunch(item);
|
|
|
+ if (count == 0) {
|
|
|
+ throw new RuntimeException("商品:" + item.getCname() + "修改上架库存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (SharePutOnShelves item : sharePutOnShelvesSrcListNew) {
|
|
|
+ int count = sharePutOnShelvesService.updateSharePutOnShelves(item);
|
|
|
+ if (count == 0) {
|
|
|
+ throw new RuntimeException("商品:" + item.getGoodsCode() + "修改上架库存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
BigDecimal amount = itemsList.stream().map(PjOrderItems::getSubTotalMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
BigDecimal goodsNum = itemsList.stream().map(PjOrderItems::getGoodsNum).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
sharePjOrder.setGoodsTotalNum(goodsNum);
|
|
|
sharePjOrder.setSalesAmount(amount);
|
|
|
sharePjOrder.setTotalMoney(amount);
|
|
|
sharePjOrder.setNumberRows(itemsList.size());
|
|
|
+ sharePjOrder.setGoodsNameJoin(itemsList.stream().map(PjOrderItems::getGoodsName).collect(Collectors.joining(",")));
|
|
|
+ sharePjOrder.setShortcutJoin(itemsList.stream().map(PjOrderItems::getCnameInt).collect(Collectors.joining(",")));
|
|
|
int count = baseMapper.insertOrder(sharePjOrder);
|
|
|
if (count == 0) {
|
|
|
throw new RuntimeException("保存销售单失败,请联系管理员");
|
|
|
@@ -4251,8 +4295,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
List<ShareSalesItems> shareSalesItemsList = shareSalesItemsService.list(new LambdaQueryWrapper<ShareSalesItems>()
|
|
|
.eq(ShareSalesItems::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(ShareSalesItems::getIsDeleted, 0)
|
|
|
- .eq(ShareSalesItems::getPid, order.getId())
|
|
|
- .apply("find_in_set(src_pid , '" + itemIds + "')"));
|
|
|
+ .eq(ShareSalesItems::getPid, order.getId()));
|
|
|
if (shareSalesItemsList.isEmpty()) {
|
|
|
throw new RuntimeException("未查到对应派发明细信息");
|
|
|
}
|
|
|
@@ -4271,6 +4314,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
throw new RuntimeException("未查到对应派发销售单据明细信息");
|
|
|
}
|
|
|
List<Long> goodsId = orderItemsList.stream().map(PjOrderItems::getGoodsId).collect(Collectors.toList());
|
|
|
+ String goodsNo = orderItemsList.stream().map(PjOrderItems::getGoodsNo).distinct().collect(Collectors.joining(","));
|
|
|
List<SharePutOnShelves> sharePutOnShelvesList = sharePutOnShelvesService.list(new LambdaQueryWrapper<SharePutOnShelves>()
|
|
|
.eq(SharePutOnShelves::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(SharePutOnShelves::getIsDeleted, 0)
|
|
|
@@ -4281,14 +4325,24 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
if (sharePutOnShelvesList.isEmpty()) {
|
|
|
throw new RuntimeException("未找到共享上架商品明细");
|
|
|
}
|
|
|
+ List<PjProductLaunch> productLaunchList = productLaunchService.selectListProductLaunch(goodsNo, sharedCompanyName, null);
|
|
|
+ if (productLaunchList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到对应商品信息");
|
|
|
+ }
|
|
|
+ List<SharePutOnShelves> selectSharePutOnShelvesList = sharePutOnShelvesService.selectSharePutOnShelvesList(goodsNo, sharedCompanyName, null);
|
|
|
+ if (productLaunchList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到对应商品信息");
|
|
|
+ }
|
|
|
List<SharePutOnShelves> sharePutOnShelvesListNew = new ArrayList<>();
|
|
|
- List<Long> shareOrderItemsListNew = new ArrayList<>();
|
|
|
- List<Long> shareOrderListNew = new ArrayList<>();
|
|
|
+ List<SharePutOnShelves> shareSharePutOnShelvesNew = new ArrayList<>();
|
|
|
+ List<PjProductLaunch> productLaunchListNew = new ArrayList<>();
|
|
|
for (PjOrderItems item : orderItemsList) {
|
|
|
item.setSendNum(new BigDecimal("0.00"));
|
|
|
item.setOutGoodsTotalShipNum(new BigDecimal("0.00"));
|
|
|
item.setUpdateUser(AuthUtil.getUserId());
|
|
|
item.setUpdateTime(new Date());
|
|
|
+ }
|
|
|
+ for (ShareSalesItems item : shareSalesItemsList) {
|
|
|
SharePutOnShelves sharePutOnShelves = sharePutOnShelvesList.stream()
|
|
|
.filter(e -> e.getGoodsId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (sharePutOnShelves == null) {
|
|
|
@@ -4298,19 +4352,51 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
sharePutOnShelves.setUpdateUser(AuthUtil.getUserId());
|
|
|
sharePutOnShelves.setUpdateTime(new Date());
|
|
|
sharePutOnShelvesListNew.add(sharePutOnShelves);
|
|
|
- PjOrderItems orderItems = shareOrderItemsList.stream().filter(e -> e.getGoodsNo().equals(item.getGoodsNo())).findFirst().orElse(null);
|
|
|
- if (orderItems != null) {
|
|
|
- shareOrderItemsListNew.add(orderItems.getId());
|
|
|
- shareOrderListNew.add(orderItems.getPid());
|
|
|
+ PjProductLaunch pjProductLaunch = productLaunchList.stream().filter(e -> e.getCode().equals(item.getGoodsCode())).findFirst().orElse(null);
|
|
|
+ if (pjProductLaunch != null) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(pjProductLaunch.getInventory()) != 0
|
|
|
+ && pjProductLaunch.getInventory().compareTo(item.getGoodsNum()) >= 0) {
|
|
|
+ pjProductLaunch.setInventory(pjProductLaunch.getInventory().add(item.getGoodsNum()));
|
|
|
+ productLaunchListNew.add(pjProductLaunch);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + item.getGoodsCode() + "库存不足");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + item.getGoodsCode() + "未查到上架");
|
|
|
+ }
|
|
|
+ SharePutOnShelves shelves = selectSharePutOnShelvesList.stream().filter(e -> e.getGoodsCode().equals(item.getGoodsCode())).findFirst().orElse(null);
|
|
|
+ if (shelves != null) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(shelves.getInventory()) != 0
|
|
|
+ && shelves.getInventory().compareTo(item.getGoodsNum()) >= 0) {
|
|
|
+ shelves.setInventory(shelves.getInventory().add(item.getGoodsNum()));
|
|
|
+ shareSharePutOnShelvesNew.add(shelves);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + item.getGoodsCode() + "库存不足");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品编号:" + item.getGoodsCode() + "未查到上架");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (PjProductLaunch item : productLaunchListNew) {
|
|
|
+ int count = productLaunchService.updateProductLaunch(item);
|
|
|
+ if (count == 0) {
|
|
|
+ throw new RuntimeException("商品:" + item.getCname() + "修改上架库存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (SharePutOnShelves item : shareSharePutOnShelvesNew) {
|
|
|
+ int count = sharePutOnShelvesService.updateSharePutOnShelves(item);
|
|
|
+ if (count == 0) {
|
|
|
+ throw new RuntimeException("商品:" + item.getGoodsName() + "修改上架库存失败");
|
|
|
}
|
|
|
}
|
|
|
orderItemsService.updateBatchById(orderItemsList);
|
|
|
- if (!shareOrderItemsListNew.isEmpty()) {
|
|
|
- orderItemsService.removeByIds(shareOrderItemsListNew);
|
|
|
+ if (!shareOrderItemsList.isEmpty()) {
|
|
|
+ List<Long> shareOrderItemsIds = shareOrderItemsList.stream().map(PjOrderItems::getId).distinct().collect(Collectors.toList());
|
|
|
+ orderItemsService.deleteByIds(shareOrderItemsIds);
|
|
|
}
|
|
|
- if (!shareOrderListNew.isEmpty()) {
|
|
|
- List<Long> shareOrderIds = shareOrderListNew.stream().distinct().collect(Collectors.toList());
|
|
|
- this.removeByIds(shareOrderIds);
|
|
|
+ if (!shareOrderList.isEmpty()) {
|
|
|
+ List<Long> shareOrderIds = shareOrderList.stream().map(PjOrder::getId).distinct().collect(Collectors.toList());
|
|
|
+ baseMapper.deleteByIds(shareOrderIds);
|
|
|
}
|
|
|
if (!sharePutOnShelvesListNew.isEmpty()) {
|
|
|
sharePutOnShelvesService.updateBatchById(sharePutOnShelvesListNew);
|
|
|
@@ -5092,8 +5178,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
|
|
|
pjShip.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
pjShip.setCreateUser(AuthUtil.getUserId());
|
|
|
pjShip.setCreateTime(new Date());
|
|
|
- pjShip.setSalesCompanyId(Long.parseLong(pjOrder.getSharedCompanyId()));
|
|
|
- pjShip.setSalesCompanyName(pjOrder.getSharedCompanyName());
|
|
|
+ pjShip.setSalesCompanyId(pjOrder.getSalesCompanyId());
|
|
|
+ pjShip.setSalesCompanyName(pjOrder.getSalesCompanyName());
|
|
|
pjShip.setSourceCompanyId(pjOrder.getSalesCompanyId());
|
|
|
pjShip.setSourceCompanyName(pjOrder.getSalesCompanyName());
|
|
|
shipMapper.insert(pjShip);
|