|
@@ -1,6 +1,7 @@
|
|
|
package com.fjhx.wms.service.stock.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -9,16 +10,22 @@ import com.fjhx.item.entity.product.IssueImportExcelBo;
|
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.entity.product.vo.ProductInfoVo;
|
|
|
+import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.wms.entity.stock.dto.StockCheckDto;
|
|
|
import com.fjhx.wms.entity.stock.dto.StockCheckSelectDto;
|
|
|
+import com.fjhx.wms.entity.stock.dto.StockSelectDto;
|
|
|
import com.fjhx.wms.entity.stock.po.Stock;
|
|
|
import com.fjhx.wms.entity.stock.po.StockCheck;
|
|
|
import com.fjhx.wms.entity.stock.po.StockCheckDetails;
|
|
|
+import com.fjhx.wms.entity.stock.po.StockCheckRegister;
|
|
|
import com.fjhx.wms.entity.stock.vo.StockCheckDetailsVo;
|
|
|
+import com.fjhx.wms.entity.stock.vo.StockCheckRegisterVo;
|
|
|
import com.fjhx.wms.entity.stock.vo.StockCheckVo;
|
|
|
+import com.fjhx.wms.entity.stock.vo.StockVo;
|
|
|
import com.fjhx.wms.mapper.stock.StockCheckMapper;
|
|
|
import com.fjhx.wms.service.stock.StockCheckDetailsService;
|
|
|
+import com.fjhx.wms.service.stock.StockCheckRegisterService;
|
|
|
import com.fjhx.wms.service.stock.StockCheckService;
|
|
|
import com.fjhx.wms.service.stock.StockService;
|
|
|
import com.fjhx.wms.service.warehouse.WarehouseService;
|
|
@@ -32,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -53,13 +61,17 @@ public class StockCheckServiceImpl extends ServiceImpl<StockCheckMapper, StockCh
|
|
|
private final ProductInfoService productInfoService;
|
|
|
private final WarehouseService warehouseService;
|
|
|
private final StockService stockService;
|
|
|
+ private final ProductClassifyService productClassifyService;
|
|
|
+ private final StockCheckRegisterService stockCheckRegisterService;
|
|
|
|
|
|
@Autowired
|
|
|
- public StockCheckServiceImpl(StockCheckDetailsService stockCheckDetailsService, ProductInfoService productInfoService, WarehouseService warehouseService, StockService stockService) {
|
|
|
+ public StockCheckServiceImpl(StockCheckDetailsService stockCheckDetailsService, ProductInfoService productInfoService, WarehouseService warehouseService, StockService stockService, ProductClassifyService productClassifyService, StockCheckRegisterService stockCheckRegisterService) {
|
|
|
this.stockCheckDetailsService = stockCheckDetailsService;
|
|
|
this.productInfoService = productInfoService;
|
|
|
this.warehouseService = warehouseService;
|
|
|
this.stockService = stockService;
|
|
|
+ this.productClassifyService = productClassifyService;
|
|
|
+ this.stockCheckRegisterService = stockCheckRegisterService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -176,4 +188,101 @@ public class StockCheckServiceImpl extends ServiceImpl<StockCheckMapper, StockCh
|
|
|
return issueImportExcelBos;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Page<StockVo> stockProductPage(StockSelectDto dto) {
|
|
|
+ IWrapper<Stock> wrapper = IWrapper.getWrapper();
|
|
|
+
|
|
|
+ //仓库过滤
|
|
|
+ wrapper.eq("s",Stock::getWarehouseId, dto.getWarehouseId());
|
|
|
+
|
|
|
+ //关键字
|
|
|
+ String keyword = dto.getKeyword();
|
|
|
+ if (ObjectUtil.isNotEmpty(keyword)) {
|
|
|
+ //根据 库存数量 产品自定义编码 产品名称 过滤
|
|
|
+ List<Long> productIds = productInfoService.listObject(ProductInfo::getId,
|
|
|
+ q -> q.like(ProductInfo::getCustomCode, keyword).or().like(ProductInfo::getName, keyword));
|
|
|
+ wrapper.and(q -> q.like("s",Stock::getQuantity, keyword).or().in("s",Stock::getProductId, productIds));
|
|
|
+ }
|
|
|
+
|
|
|
+ //已登记过滤
|
|
|
+ Integer isCheckRegister = dto.getIsCheckRegister();
|
|
|
+ if (ObjectUtil.isNotEmpty(isCheckRegister)) {
|
|
|
+ List<Long> sIds = stockCheckRegisterService.listObject(StockCheckRegister::getStockId, q -> q.orderByAsc(StockCheckRegister::getId));
|
|
|
+ sIds.add(-1L);
|
|
|
+ if (ObjectUtil.equals(isCheckRegister, 1)) {
|
|
|
+ //过滤已经登记
|
|
|
+ wrapper.in("s",Stock::getId, sIds);
|
|
|
+ } else {
|
|
|
+ //过滤没有登记
|
|
|
+ wrapper.notIn("s",Stock::getId, sIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.orderByDesc("s", Stock::getId);
|
|
|
+ Page<StockVo> page = baseMapper.stockProductPage(dto.getPage(), wrapper);
|
|
|
+ List<StockVo> records = page.getRecords();
|
|
|
+ if (ObjectUtil.isEmpty(records)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> ids = records.stream().map(Stock::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //赋值产品信息
|
|
|
+ productInfoService.attributeAssign(records, StockVo::getProductId, (item, productInfo) -> {
|
|
|
+ item.setProductCode(productInfo.getCode());
|
|
|
+ item.setProductUnit(productInfo.getUnit());
|
|
|
+ item.setProductType(productInfo.getType());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ item.setProductSpec(productInfo.getSpec());
|
|
|
+ item.setProductClassifyId(productInfo.getProductClassifyId());
|
|
|
+ item.setProductDefinition(productInfo.getDefinition());
|
|
|
+ item.setProductCustomCode(productInfo.getCustomCode());
|
|
|
+ });
|
|
|
+ //赋值产品分类
|
|
|
+ productClassifyService.attributeAssign(records, StockVo::getProductClassifyId, (item, productClassify) -> {
|
|
|
+ item.setProductClassifyName(productClassify.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ //赋值仓库名称
|
|
|
+ warehouseService.attributeAssign(records, StockVo::getWarehouseId, (item, warehouse) -> {
|
|
|
+ item.setWarehouseName(warehouse.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ //赋值盘点登记记录列表
|
|
|
+ List<StockCheckRegisterVo> stockCheckRegisterList = stockCheckRegisterService.getList(IWrapper.<StockCheckRegister>getWrapper()
|
|
|
+ .in(StockCheckRegister::getStockId, ids)
|
|
|
+ );
|
|
|
+ Map<Long, List<StockCheckRegisterVo>> checkRegisterMap = stockCheckRegisterList.stream().collect(Collectors.groupingBy(StockCheckRegister::getStockId));
|
|
|
+ for (StockVo stockVo : records) {
|
|
|
+ stockVo.setStockCheckRegisterList(checkRegisterMap.getOrDefault(stockVo.getId(),new ArrayList<>()));
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public void submitAll(){
|
|
|
+ List<StockCheckRegister> list = stockCheckRegisterService.list();
|
|
|
+ Map<Long, List<StockCheckRegister>> collect = list.stream().collect(Collectors.groupingBy(StockCheckRegister::getWarehouseId));
|
|
|
+ for (Map.Entry<Long, List<StockCheckRegister>> entry : collect.entrySet()) {
|
|
|
+ //生成盘点明细
|
|
|
+ List<StockCheckDetails> stockCheckDetailsList = new ArrayList<>();
|
|
|
+ for (StockCheckRegister stockCheckRegister : entry.getValue()) {
|
|
|
+ StockCheckDetails stockCheckDetails = new StockCheckDetails();
|
|
|
+ stockCheckDetails.setProductId(stockCheckRegister.getProductId());
|
|
|
+ stockCheckDetails.setQuantity(stockCheckRegister.getQuantity());
|
|
|
+ stockCheckDetails.setCheckQuantity(stockCheckRegister.getCheckQuantity());
|
|
|
+ stockCheckDetailsList.add(stockCheckDetails);
|
|
|
+ }
|
|
|
+
|
|
|
+ //提交盘点
|
|
|
+ StockCheckDto stockCheckDto = new StockCheckDto();
|
|
|
+ stockCheckDto.setWarehouseId(entry.getKey());
|
|
|
+ stockCheckDto.setList(stockCheckDetailsList);
|
|
|
+ add(stockCheckDto);
|
|
|
+ }
|
|
|
+ //删除盘点记录信息
|
|
|
+ stockCheckRegisterService.removeBatchByIds(list);
|
|
|
+ }
|
|
|
+
|
|
|
}
|