|
@@ -3,9 +3,9 @@ package com.fjhx.wms.service.stock.impl;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fjhx.item.entity.product.po.ProductClassify;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
@@ -19,7 +19,6 @@ import com.fjhx.wms.entity.stock.po.Stock;
|
|
|
import com.fjhx.wms.entity.stock.po.StockJournal;
|
|
|
import com.fjhx.wms.entity.stock.po.StockJournalDetails;
|
|
|
import com.fjhx.wms.entity.stock.vo.StockVo;
|
|
|
-import com.fjhx.wms.entity.stock.vo.StockWaitVo;
|
|
|
import com.fjhx.wms.entity.warehouse.po.Warehouse;
|
|
|
import com.fjhx.wms.mapper.stock.StockMapper;
|
|
|
import com.fjhx.wms.service.stock.StockJournalDetailsService;
|
|
@@ -32,7 +31,6 @@ import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
@@ -68,7 +66,8 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
wrapper.orderByDesc("s", Stock::getId);
|
|
|
wrapper.eq(Stock::getWarehouseId, dto.getId());
|
|
|
wrapper.like(Stock::getQuantity, dto.getKeyword());
|
|
|
- wrapper.in(Stock::getProductId,dto.getProductIds());
|
|
|
+ wrapper.in(Stock::getProductId, dto.getProductIds());
|
|
|
+ wrapper.eq("pi.definition", dto.getDefinition());
|
|
|
|
|
|
Page<StockVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
List<StockVo> stockVos = page.getRecords();
|
|
@@ -80,13 +79,14 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
item.setProductName(productInfo.getName());
|
|
|
item.setProductSpec(productInfo.getSpec());
|
|
|
item.setProductClassifyId(productInfo.getProductClassifyId());
|
|
|
+ item.setProductDefinition(productInfo.getDefinition());
|
|
|
});
|
|
|
//赋值产品分类
|
|
|
productClassifyService.attributeAssign(stockVos, StockVo::getProductClassifyId, (item, productClassify) -> {
|
|
|
item.setProductClassifyName(productClassify.getName());
|
|
|
});
|
|
|
//赋值仓库名称
|
|
|
- productClassifyService.attributeAssign(stockVos, StockVo::getWarehouseId, (item, warehouse) -> {
|
|
|
+ warehouseService.attributeAssign(stockVos, StockVo::getWarehouseId, (item, warehouse) -> {
|
|
|
item.setWarehouseName(warehouse.getName());
|
|
|
});
|
|
|
return page;
|
|
@@ -107,13 +107,11 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
productInfoService.attributeAssign(stockVos, StockVo::getProductId, (item, productInfo) -> {
|
|
|
//赋值维多利亚扩展产品信息
|
|
|
String victoriatouristJson = item.getVictoriatouristJson();
|
|
|
- if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
|
|
|
- JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
- json.put("code", productInfo.getCode());
|
|
|
- json.put("spec", productInfo.getSpec());
|
|
|
- json.put("unit", productInfo.getUnit());
|
|
|
- item.setVictoriatouristJson(json.toJSONString());
|
|
|
- }
|
|
|
+ JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
+ json.put("code", productInfo.getCode());
|
|
|
+ json.put("spec", productInfo.getSpec());
|
|
|
+ json.put("unit", productInfo.getUnit());
|
|
|
+ item.setVictoriatouristJson(json.toJSONString());
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -135,12 +133,10 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
Map<Long, String> warehouseMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
|
|
|
for (StockVo stockVo : stockVos) {
|
|
|
String victoriatouristJson = stockVo.getVictoriatouristJson();
|
|
|
- if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
|
|
|
- JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
- String warehouseName = warehouseMap.get(json.getLong("warehouseId"));
|
|
|
- json.put("warehouseName", warehouseName);
|
|
|
- stockVo.setVictoriatouristJson(json.toJSONString());
|
|
|
- }
|
|
|
+ JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
+ String warehouseName = warehouseMap.get(json.getLong("warehouseId"));
|
|
|
+ json.put("warehouseName", warehouseName);
|
|
|
+ stockVo.setVictoriatouristJson(json.toJSONString());
|
|
|
}
|
|
|
return page;
|
|
|
}
|
|
@@ -151,27 +147,36 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
wrapper.orderByDesc("s", Stock::getId);
|
|
|
wrapper.eq(Stock::getWarehouseId, dto.getId());
|
|
|
wrapper.like(Stock::getQuantity, dto.getKeyword());
|
|
|
+ wrapper.eq("pi.definition", dto.getDefinition());
|
|
|
|
|
|
Page<StockVo> page = this.baseMapper.pageByProduct(dto.getPage(), wrapper);
|
|
|
List<StockVo> stockVos = page.getRecords();
|
|
|
- //获取产品id列表
|
|
|
- List<Long> productIds = stockVos.stream().map(Stock::getProductId).collect(Collectors.toList());
|
|
|
- if (ObjectUtil.isNotEmpty(productIds)) {
|
|
|
- //赋值产品名称
|
|
|
- productInfoService.attributeAssign(stockVos, StockVo::getProductId, (item, productInfo) -> {
|
|
|
- item.setType(productInfo.getType());
|
|
|
- item.setProductName(productInfo.getName());
|
|
|
- //赋值维多利亚扩展产品信息
|
|
|
- String victoriatouristJson = item.getVictoriatouristJson();
|
|
|
- if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
|
|
|
- JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
- json.put("code", productInfo.getCode());
|
|
|
- json.put("spec", productInfo.getSpec());
|
|
|
- json.put("unit", productInfo.getUnit());
|
|
|
- item.setVictoriatouristJson(json.toJSONString());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
+ //赋值产品名称
|
|
|
+ productInfoService.attributeAssign(stockVos, StockVo::getProductId, (item, productInfo) -> {
|
|
|
+ item.setType(productInfo.getType());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ item.setProductCode(productInfo.getCode());
|
|
|
+ item.setProductUnit(productInfo.getUnit());
|
|
|
+ item.setProductType(productInfo.getType());
|
|
|
+ item.setProductSpec(productInfo.getSpec());
|
|
|
+ item.setProductClassifyId(productInfo.getProductClassifyId());
|
|
|
+ item.setProductDefinition(productInfo.getDefinition());
|
|
|
+
|
|
|
+ //赋值维多利亚扩展产品信息
|
|
|
+ String victoriatouristJson = item.getVictoriatouristJson();
|
|
|
+ JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
+ json.put("code", productInfo.getCode());
|
|
|
+ json.put("spec", productInfo.getSpec());
|
|
|
+ json.put("unit", productInfo.getUnit());
|
|
|
+ item.setVictoriatouristJson(json.toJSONString());
|
|
|
+ });
|
|
|
+
|
|
|
+ //赋值仓库名称
|
|
|
+ warehouseService.attributeAssign(stockVos, StockVo::getWarehouseId, (item, warehouse) -> {
|
|
|
+ item.setWarehouseName(warehouse.getName());
|
|
|
+ });
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|
|
@@ -181,13 +186,13 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @DSTransactional
|
|
|
public void add(StockDto stockDto) {
|
|
|
//创建出入库记录
|
|
|
StockJournal stockJournal = new StockJournal();
|
|
|
stockJournal.setOpType(stockDto.getType());
|
|
|
stockJournal.setType(stockDto.getType());
|
|
|
- stockJournal.setCode(stockDto.getType()==1? CodeEnum.SIN_CODE.getCode() : CodeEnum.SOUT_CODE.getCode());
|
|
|
+ stockJournal.setCode(stockDto.getType() == 1 ? CodeEnum.SIN_CODE.getCode() : CodeEnum.SOUT_CODE.getCode());
|
|
|
stockJournal.setWarehouseId(stockDto.getWarehouseId());
|
|
|
stockJournal.setBusinessId(stockDto.getBusinessId());
|
|
|
//保存出入库记录
|
|
@@ -199,12 +204,12 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @DSTransactional
|
|
|
public void edit(StockDto stockDto) {
|
|
|
//创建出入库记录
|
|
|
StockJournal stockJournal = new StockJournal();
|
|
|
stockJournal.setOpType(stockDto.getType());
|
|
|
- stockJournal.setCode(stockDto.getType()==1? CodeEnum.SIN_CODE.getCode() : CodeEnum.SOUT_CODE.getCode());
|
|
|
+ stockJournal.setCode(stockDto.getType() == 1 ? CodeEnum.SIN_CODE.getCode() : CodeEnum.SOUT_CODE.getCode());
|
|
|
stockJournal.setType(stockDto.getType());
|
|
|
stockJournal.setWarehouseId(stockDto.getWarehouseId());
|
|
|
stockJournal.setBusinessId(stockDto.getBusinessId());
|
|
@@ -217,39 +222,6 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void stockTransfer(StockDto stockDto) {
|
|
|
- //创建出库记录
|
|
|
- StockJournal stockJournal = new StockJournal();
|
|
|
- stockJournal.setCode(CodeEnum.STOCK_TRANSFER.getCode());
|
|
|
- stockJournal.setOpType(2);//出库
|
|
|
- stockJournal.setType(JournalType.ADJUSTING_OUT.getDetailType());//调仓入库
|
|
|
- stockJournal.setWarehouseId(stockDto.getWarehouseId());
|
|
|
- stockJournal.setToWarehouseId(stockDto.getToWarehouseId());
|
|
|
- //保存出入库记录
|
|
|
- stockJournalService.save(stockJournal);
|
|
|
- //操作库存
|
|
|
- List<StockJournalDetails> stockJournalDetailsList = ModifyInventory(stockJournal.getId(), 2, stockDto.getList(), stockDto.getWarehouseId());
|
|
|
- //保存出入库明细
|
|
|
- stockJournalDetailsService.saveBatch(stockJournalDetailsList);
|
|
|
-
|
|
|
- //创建入库记录
|
|
|
- StockJournal stockJournal1 = new StockJournal();
|
|
|
- stockJournal1.setCode(CodeEnum.STOCK_TRANSFER.getCode());
|
|
|
- stockJournal1.setOpType(1);//入库
|
|
|
- stockJournal1.setType(JournalType.ADJUSTING_IN.getDetailType());//调仓出库
|
|
|
- stockJournal1.setWarehouseId(stockDto.getWarehouseId());
|
|
|
- stockJournal1.setToWarehouseId(stockDto.getToWarehouseId());
|
|
|
- //保存出入库记录
|
|
|
- stockJournalService.save(stockJournal1);
|
|
|
-
|
|
|
- //入库操作
|
|
|
- List<StockJournalDetails> stockJournalDetailsList1 = ModifyInventory(stockJournal1.getId(), 1, stockDto.getList(), stockDto.getToWarehouseId());
|
|
|
- //保存出入库明细
|
|
|
- stockJournalDetailsService.saveBatch(stockJournalDetailsList1);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
public void delete(Long id) {
|
|
|
this.removeById(id);
|
|
|
}
|
|
@@ -275,6 +247,10 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
Stock newStocks = new Stock();
|
|
|
newStocks.setWarehouseId(warehouseId);
|
|
|
newStocks.setProductId(stock.getProductId());
|
|
|
+ if(ObjectUtil.isEmpty(stock.getQuantity())){
|
|
|
+ //判断传操作的库存是否为空 空赋值0
|
|
|
+ stock.setQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
newStocks.setQuantity(stock.getQuantity());
|
|
|
|
|
|
//合并库存数量
|
|
@@ -291,14 +267,14 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
if (quantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw new ServiceException("库存不足无法出库");
|
|
|
}
|
|
|
- }else if(type==3){
|
|
|
+ } else if (type == 3) {
|
|
|
//维多利亚入库增加冻结库存
|
|
|
String victoriatouristJson = oldStocks.getVictoriatouristJson();
|
|
|
JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
BigDecimal frozenQuantity = json.getBigDecimal("frozen_quantity");
|
|
|
- frozenQuantity = frozenQuantity==null?BigDecimal.ZERO:frozenQuantity;
|
|
|
+ frozenQuantity = frozenQuantity == null ? BigDecimal.ZERO : frozenQuantity;
|
|
|
frozenQuantity = frozenQuantity.add(stock.getQuantity());
|
|
|
- json.put("frozen_quantity",frozenQuantity);
|
|
|
+ json.put("frozen_quantity", frozenQuantity);
|
|
|
newStocks.setVictoriatouristJson(json.toJSONString());
|
|
|
} else {
|
|
|
throw new ServiceException("未知库存操作类型");
|
|
@@ -306,7 +282,8 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
newStocks.setId(oldStocks.getId());
|
|
|
newStocks.setQuantity(quantity);
|
|
|
} else if (type == 2) {
|
|
|
- throw new ServiceException("以下商品库存不足,无法出库:" + stock.getProductId());
|
|
|
+ ProductInfo productInfo = productInfoService.getById(stock.getProductId());
|
|
|
+ throw new ServiceException("以下商品库存不足,无法出库:" + productInfo.getName());
|
|
|
}
|
|
|
|
|
|
data.add(newStocks);
|
|
@@ -435,7 +412,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
private Long addJournal(Long warehouseId, JournalType journalType, Long businessId) {
|
|
|
StockJournal stockJournal = new StockJournal();
|
|
|
stockJournal.setType(journalType.getDetailType());
|
|
|
- switch (journalType.getDetailType()){
|
|
|
+ switch (journalType.getDetailType()) {
|
|
|
case 1:
|
|
|
stockJournal.setOpType(1);//入库
|
|
|
stockJournal.setCode(CodeEnum.SIN_CODE.getCode());
|