|
@@ -6,20 +6,27 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.base.Condition;
|
|
|
+import com.fjhx.constants.StatusConstant;
|
|
|
+import com.fjhx.entity.product.ProductCombination;
|
|
|
+import com.fjhx.entity.product.ProductInfo;
|
|
|
import com.fjhx.entity.stock.Stock;
|
|
|
+import com.fjhx.entity.warehouse.Warehouse;
|
|
|
import com.fjhx.enums.stock.InTypeEnum;
|
|
|
import com.fjhx.mapper.stock.StockMapper;
|
|
|
-import com.fjhx.params.stock.StockChangeVo;
|
|
|
-import com.fjhx.params.stock.StockVo;
|
|
|
+import com.fjhx.params.stock.*;
|
|
|
+import com.fjhx.service.product.ProductCombinationService;
|
|
|
import com.fjhx.service.stock.StockService;
|
|
|
import com.fjhx.utils.Assert;
|
|
|
import com.fjhx.utils.WrapperUtil;
|
|
|
+import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
|
+import com.fjhx.utils.wrapperUtil.KeywordData;
|
|
|
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.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -35,6 +42,9 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
@Autowired
|
|
|
private StockJournalServiceImpl stockJournalService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductCombinationService productCombinationService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<Stock> getPage(Map<String, Object> condition) {
|
|
|
|
|
@@ -80,6 +90,72 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
return baseMapper.pageByWarehouseId(condition.getPage(), warehouseId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Page<PageByWarehouseVo> pageByWarehouse(Condition condition) {
|
|
|
+
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper(condition);
|
|
|
+
|
|
|
+ wrapper.keyword(new KeywordData("w", Warehouse::getName),
|
|
|
+ new KeywordData("p", ProductInfo::getCode),
|
|
|
+ new KeywordData("p", ProductInfo::getName)
|
|
|
+ );
|
|
|
+
|
|
|
+ return baseMapper.pageByWarehouse(condition.getPage(), wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PageByProductVo> pageByProduct(Condition condition) {
|
|
|
+
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper(condition);
|
|
|
+
|
|
|
+ wrapper.keyword(
|
|
|
+ new KeywordData("p", ProductInfo::getCode),
|
|
|
+ new KeywordData("p", ProductInfo::getName))
|
|
|
+ .groupBy("pi.id");
|
|
|
+
|
|
|
+ return baseMapper.pageByProduct(condition.getPage(), wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PageByCombinationVo> pageByCombination(Condition condition) {
|
|
|
+
|
|
|
+ // TODO 临时接到通知,优先级低,后面补
|
|
|
+
|
|
|
+ // 获取产品组合
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper(condition)
|
|
|
+ .keyword(
|
|
|
+ new KeywordData("p", ProductInfo::getCode),
|
|
|
+ new KeywordData("p", ProductInfo::getName))
|
|
|
+ .eq("pi", ProductInfo::getCombination, StatusConstant.YES)
|
|
|
+ .groupBy("pi.id");
|
|
|
+ Page<PageByCombinationVo> page = baseMapper.pageByCombination(condition.getPage(), wrapper);
|
|
|
+
|
|
|
+ List<PageByCombinationVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> productIdList = records.stream().map(PageByCombinationVo::getProductId).collect(Collectors.toList());
|
|
|
+ // 组合产品关联表
|
|
|
+ List<ProductCombination> combinationList = productCombinationService.list(
|
|
|
+ q -> q.select(
|
|
|
+ ProductCombination::getProductId,
|
|
|
+ ProductCombination::getLinkProductId,
|
|
|
+ ProductCombination::getLinkQuantity
|
|
|
+ )
|
|
|
+ .in(ProductCombination::getProductId, productIdList));
|
|
|
+
|
|
|
+ // 获取组合关联的产品idList
|
|
|
+ List<Long> linkProductIdList = combinationList.stream().map(ProductCombination::getLinkProductId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询关联产品信息
|
|
|
+
|
|
|
+ wrapper.clear();
|
|
|
+
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 合并变更数量(如果同一种物品在出入库一个仓库,则合并数量)
|
|
|
*/
|