|
|
@@ -34,6 +34,7 @@ import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.salesPart.corps.mapper.CorpsDescMapper;
|
|
|
import org.springblade.salesPart.entity.*;
|
|
|
import org.springblade.salesPart.enums.OrderTypeEnum;
|
|
|
import org.springblade.salesPart.excel.PjShipStockDetails;
|
|
|
@@ -95,6 +96,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
private final ISysClient sysClient;
|
|
|
private final IStockDescService iStockDescService;
|
|
|
private final GoodsDescMapper goodsDescMapper;
|
|
|
+ private final CorpsDescMapper corpsDescMapper;
|
|
|
private final GoodsTypeMapper goodsTypeMapper;
|
|
|
private final IProductLaunchService productLaunchService;
|
|
|
private final HistoryMapper historyMapper;
|
|
|
@@ -1484,4 +1486,263 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
history.setOperateStatus(status);
|
|
|
historyMapper.insert(history);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R submitTransferAllocate(PjShip order) {
|
|
|
+ // 获取系统编号
|
|
|
+ R billNo = serialClient.getBillNo(order.getBizTypeName(), order.getBizTypeName(), order.getBizTypeName());
|
|
|
+ if (billNo.getCode() != 200) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成系统编号失败");
|
|
|
+ }
|
|
|
+ //仓库名称
|
|
|
+ if (ObjectUtils.isNotNull(order.getStorageId())) {
|
|
|
+ order.setStorageName(storageDescMapper.selectById(order.getStorageId()).getCname());
|
|
|
+ }
|
|
|
+ //仓库名称
|
|
|
+ if (ObjectUtils.isNotNull(order.getCallInStorageId())) {
|
|
|
+ order.setCallInStorageName(storageDescMapper.selectById(order.getCallInStorageId()).getCname());
|
|
|
+ }
|
|
|
+ if (order.getId() == null) {
|
|
|
+ order.setBillno((String) billNo.getData());
|
|
|
+ order.setCreateTime(new Date());
|
|
|
+ order.setCreateUser(AuthUtil.getUserId());
|
|
|
+ order.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ order.setTenantId(AuthUtil.getTenantId());
|
|
|
+ order.setStatusName(OrderTypeEnum.XSLR.getType());
|
|
|
+ //所属公司
|
|
|
+ R<Dept> dept = sysClient.getDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ if (ObjectUtil.isNotEmpty(dept)) {
|
|
|
+ order.setSalesCompanyId(dept.getData().getId());
|
|
|
+ order.setSalesCompanyName(dept.getData().getFullName());
|
|
|
+ } else {
|
|
|
+ throw new SecurityException("未维护所属公司");
|
|
|
+ }
|
|
|
+ baseMapper.insert(order);
|
|
|
+ } else {
|
|
|
+ order.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ order.setUpdateTime(new Date());
|
|
|
+ baseMapper.updateById(order);
|
|
|
+ }
|
|
|
+ // 保存订单明细
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getShipItemsList())) {
|
|
|
+ order.getShipItemsList().forEach(item -> {
|
|
|
+ //计算小计
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(order.getId());
|
|
|
+ item.setTenantId(AuthUtil.getTenantId());
|
|
|
+ } else {
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(order.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ shipItemsService.saveOrUpdateBatch(order.getShipItemsList());
|
|
|
+ order.setNumberRows(order.getShipItemsList().size());//行数
|
|
|
+ //明细总数量
|
|
|
+ order.setGoodsTotalNum(order.getShipItemsList().stream().filter(e -> e.getGoodsNum() != null).map(PjShipItems::getGoodsNum).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ baseMapper.updateById(order);
|
|
|
+ return R.data(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R confirmTransferAllocate(PjShip order) {
|
|
|
+ if (order.getId() == null) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ PjShip detail = baseMapper.selectById(order.getId());
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getShipItemsList())) {
|
|
|
+ List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ List<PjStockDesc> pjStockDescList = new ArrayList<>();
|
|
|
+ for (PjShipItems orderItems : order.getShipItemsList()) {
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = goodsDescMapper.selectById(orderItems.getGoodsId());
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ if ("1".equals(goodsDesc.getWhether()) && ObjectUtils.isNull(orderItems.getDot())) {
|
|
|
+ throw new RuntimeException("商品:" + goodsDesc.getCname() + ",请求选择批次号");
|
|
|
+ }
|
|
|
+ //调拨出库
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperC = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapperC.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, detail.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getGoodsId, orderItems.getGoodsId())
|
|
|
+ .eq(PjStockDesc::getStorageId, detail.getStorageId());
|
|
|
+ //管理批次号
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ lambdaQueryWrapperC.eq(PjStockDesc::getDot, orderItems.getDot());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapperC.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ }
|
|
|
+
|
|
|
+ PjStockDesc stockOneC = iStockDescService.getOne(lambdaQueryWrapperC);
|
|
|
+ if (ObjectUtil.isNotEmpty(stockOneC)) {
|
|
|
+ stockOneC.setBalanceQuantity(stockOneC.getBalanceQuantity().subtract(orderItems.getGoodsNum()));
|
|
|
+ stockOneC.setStoreInventory(stockOneC.getBalanceQuantity());
|
|
|
+ stockOneC.setInventoryAmount(stockOneC.getInventoryAmount().subtract(orderItems.getGoodsNum()
|
|
|
+ .multiply(stockOneC.getInventoryCostPrice())));
|
|
|
+ stockOneC.setVersion(stockOneC.getVersion());
|
|
|
+ pjStockDescArrayList.add(stockOneC);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未查到库存账");
|
|
|
+ }
|
|
|
+ //调拨入库
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperR = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapperR.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, detail.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getGoodsId, orderItems.getGoodsId())
|
|
|
+ .eq(PjStockDesc::getStorageId, detail.getCallInStorageId());
|
|
|
+ //管理批次号
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ lambdaQueryWrapperR.eq(PjStockDesc::getDot, orderItems.getDot());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapperR.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ }
|
|
|
+
|
|
|
+ PjStockDesc stockOneR = iStockDescService.getOne(lambdaQueryWrapperR);
|
|
|
+ if (ObjectUtil.isNotEmpty(stockOneR)) {
|
|
|
+ stockOneR.setBalanceQuantity(stockOneR.getBalanceQuantity().add(orderItems.getGoodsNum()));
|
|
|
+ stockOneR.setStoreInventory(stockOneR.getBalanceQuantity());
|
|
|
+ stockOneR.setInventoryAmount(stockOneR.getInventoryAmount().add(orderItems.getGoodsNum()
|
|
|
+ .multiply(stockOneR.getInventoryCostPrice())));
|
|
|
+ stockOneR.setInventoryCostPrice(stockOneR.getInventoryAmount().divide(stockOneR.getBalanceQuantity(), 2, RoundingMode.HALF_UP));
|
|
|
+ stockOneR.setVersion(stockOneR.getVersion());
|
|
|
+ pjStockDescArrayList.add(stockOneR);
|
|
|
+ } else {
|
|
|
+ PjStockDesc stockDesc = new PjStockDesc();
|
|
|
+ stockDesc.setStorageId(detail.getCallInStorageId());
|
|
|
+ stockDesc.setStorageName(detail.getCallInStorageName());
|
|
|
+ stockDesc.setGoodsId(orderItems.getGoodsId());
|
|
|
+ stockDesc.setCode(goodsDesc.getCode());
|
|
|
+ stockDesc.setCname(goodsDesc.getCname());
|
|
|
+ stockDesc.setBrandId(goodsDesc.getBrandId());
|
|
|
+ stockDesc.setBrandName(goodsDesc.getBrandName());
|
|
|
+ stockDesc.setTypeno(goodsDesc.getSpecificationAndModel());
|
|
|
+ stockDesc.setBrandItem(goodsDesc.getBrandItem());
|
|
|
+ stockDesc.setProductDescription(goodsDesc.getGoodsDescription());
|
|
|
+ stockDesc.setGoodsTypeId(goodsDesc.getGoodsTypeId());
|
|
|
+ stockDesc.setGoodsTypeName(goodsDesc.getGoodsTypeName());
|
|
|
+ stockDesc.setBalanceQuantity(orderItems.getGoodsNum());
|
|
|
+ stockDesc.setStoreInventory(orderItems.getGoodsNum());
|
|
|
+ stockDesc.setInventoryAmount(orderItems.getSubTotalMoney());
|
|
|
+ stockDesc.setInventoryCostPrice(orderItems.getPrice());
|
|
|
+ stockDesc.setSalesCompanyId(detail.getSalesCompanyId());
|
|
|
+ stockDesc.setSalesCompanyName(detail.getSalesCompanyName());
|
|
|
+ stockDesc.setDot(orderItems.getDot());
|
|
|
+ stockDesc.setCreateDept(detail.getCreateDept());
|
|
|
+ stockDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
+ stockDesc.setCreateTime(new Date());
|
|
|
+ stockDesc.setTenantId(AuthUtil.getTenantId());
|
|
|
+ pjStockDescList.add(stockDesc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ R res = iStockDescService.updateBatchByIdNew(pjStockDescArrayList);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ throw new RuntimeException(res.getMsg());
|
|
|
+ }
|
|
|
+ if (pjStockDescList.size() > 0) {
|
|
|
+ iStockDescService.saveOrUpdateBatch(pjStockDescList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail.setStatusName("确认调拨");
|
|
|
+ baseMapper.updateById(detail);
|
|
|
+ return R.data(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R revokeTransferAllocate(PjShip order) {
|
|
|
+ if (order.getId() == null) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ PjShip detail = baseMapper.selectById(order.getId());
|
|
|
+ if (CollectionUtils.isNotEmpty(order.getShipItemsList())) {
|
|
|
+ List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ for (PjShipItems orderItems : order.getShipItemsList()) {
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = goodsDescMapper.selectById(orderItems.getGoodsId());
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ if ("1".equals(goodsDesc.getWhether()) && ObjectUtils.isNull(orderItems.getDot())) {
|
|
|
+ throw new RuntimeException("商品:" + goodsDesc.getCname() + ",请求选择批次号");
|
|
|
+ }
|
|
|
+ //调拨出库
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperC = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapperC.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, detail.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getGoodsId, orderItems.getGoodsId())
|
|
|
+ .eq(PjStockDesc::getStorageId, detail.getStorageId());
|
|
|
+ //管理批次号
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ lambdaQueryWrapperC.eq(PjStockDesc::getDot, orderItems.getDot());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapperC.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ }
|
|
|
+
|
|
|
+ PjStockDesc stockOneC = iStockDescService.getOne(lambdaQueryWrapperC);
|
|
|
+ if (ObjectUtil.isNotEmpty(stockOneC)) {
|
|
|
+ stockOneC.setBalanceQuantity(stockOneC.getBalanceQuantity().add(orderItems.getGoodsNum()));
|
|
|
+ stockOneC.setStoreInventory(stockOneC.getBalanceQuantity());
|
|
|
+ stockOneC.setInventoryAmount(stockOneC.getInventoryAmount().add(orderItems.getGoodsNum()
|
|
|
+ .multiply(stockOneC.getInventoryCostPrice())));
|
|
|
+ stockOneC.setVersion(stockOneC.getVersion());
|
|
|
+ pjStockDescArrayList.add(stockOneC);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未查到库存账");
|
|
|
+ }
|
|
|
+ //调拨入库
|
|
|
+ LambdaQueryWrapper<PjStockDesc> lambdaQueryWrapperR = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapperR.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, detail.getSalesCompanyId())
|
|
|
+ .eq(PjStockDesc::getGoodsId, orderItems.getGoodsId())
|
|
|
+ .eq(PjStockDesc::getStorageId, detail.getCallInStorageId());
|
|
|
+ //管理批次号
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ lambdaQueryWrapperR.eq(PjStockDesc::getDot, orderItems.getDot());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapperR.and(i -> i.eq(PjStockDesc::getDot, "").or().isNull(PjStockDesc::getDot));
|
|
|
+ }
|
|
|
+
|
|
|
+ PjStockDesc stockOneR = iStockDescService.getOne(lambdaQueryWrapperR);
|
|
|
+ if (ObjectUtil.isNotEmpty(stockOneR)) {
|
|
|
+ stockOneR.setBalanceQuantity(stockOneR.getBalanceQuantity().subtract(orderItems.getGoodsNum()));
|
|
|
+ stockOneR.setStoreInventory(stockOneR.getBalanceQuantity());
|
|
|
+ stockOneR.setInventoryAmount(stockOneR.getInventoryAmount().subtract(orderItems.getGoodsNum()
|
|
|
+ .multiply(stockOneR.getInventoryCostPrice())));
|
|
|
+ if (stockOneR.getInventoryAmount().compareTo(new BigDecimal("0.00")) == 0 ||
|
|
|
+ stockOneR.getBalanceQuantity().compareTo(new BigDecimal("0.00")) == 0){
|
|
|
+ stockOneR.setInventoryCostPrice(new BigDecimal("0.00"));
|
|
|
+ }else{
|
|
|
+ stockOneR.setInventoryCostPrice(stockOneR.getInventoryAmount().divide(stockOneR.getBalanceQuantity(), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ stockOneR.setDot("");
|
|
|
+ stockOneR.setVersion(stockOneR.getVersion());
|
|
|
+ pjStockDescArrayList.add(stockOneR);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未查到库存账");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ R res = iStockDescService.updateBatchByIdNew(pjStockDescArrayList);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ throw new RuntimeException(res.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail.setStatusName("录入");
|
|
|
+ baseMapper.updateById(detail);
|
|
|
+ return R.data(detail);
|
|
|
+ }
|
|
|
+
|
|
|
}
|