|
@@ -0,0 +1,111 @@
|
|
|
+package com.fjhx.wms.service.monthly.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.wms.entity.monthly.dto.MonthlyInventoryReportSelectDto;
|
|
|
+import com.fjhx.wms.entity.monthly.po.MonthlyInventoryReport;
|
|
|
+import com.fjhx.wms.entity.monthly.vo.MonthlyInventoryReportVo;
|
|
|
+import com.fjhx.wms.entity.stock.po.Stock;
|
|
|
+import com.fjhx.wms.entity.stock.vo.StockJournalDetailsVo;
|
|
|
+import com.fjhx.wms.mapper.monthly.MonthlyInventoryReportMapper;
|
|
|
+import com.fjhx.wms.service.monthly.MonthlyInventoryReportService;
|
|
|
+import com.fjhx.wms.service.stock.StockService;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 月度库存报表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-07-05
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MonthlyInventoryReportServiceImpl extends ServiceImpl<MonthlyInventoryReportMapper, MonthlyInventoryReport> implements MonthlyInventoryReportService {
|
|
|
+ @Autowired
|
|
|
+ private StockService stockService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<MonthlyInventoryReportVo> getPage(MonthlyInventoryReportSelectDto dto) {
|
|
|
+ IWrapper<MonthlyInventoryReport> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("mir", MonthlyInventoryReport::getId);
|
|
|
+ Page<MonthlyInventoryReportVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每月1日0点自动生成上月报表
|
|
|
+ */
|
|
|
+ public void generateReport() {
|
|
|
+ List<MonthlyInventoryReport> monthlyInventoryReportList = new ArrayList<>();
|
|
|
+
|
|
|
+ //获取上月的报表获取初期数量
|
|
|
+ List<MonthlyInventoryReportVo> olDmonthlyInventoryReportList = baseMapper.getLastMonthMonthlyInventoryReport();
|
|
|
+
|
|
|
+ List<StockJournalDetailsVo> lastMonthStockJournal = baseMapper.getLastMonthStockJournal();
|
|
|
+
|
|
|
+ List<Stock> stockList = stockService.list();
|
|
|
+ for (Stock stock : stockList) {
|
|
|
+ //计算初期数量
|
|
|
+ List<MonthlyInventoryReport> initialQuantityList = olDmonthlyInventoryReportList.stream()
|
|
|
+ .filter(it -> stock.getWarehouseId().equals(it.getWarehouseId()))
|
|
|
+ .filter(it -> stock.getProductId().equals(it.getProductId())).collect(Collectors.toList());
|
|
|
+ //计算入库数量
|
|
|
+ List<StockJournalDetailsVo> receiptQuantityList = lastMonthStockJournal.stream()
|
|
|
+ .filter(it -> stock.getWarehouseId().equals(it.getToWarehouseId()))
|
|
|
+ .filter(it -> stock.getProductId().equals(it.getProductId()))
|
|
|
+ .filter(it -> it.getOpType() == 1).collect(Collectors.toList());
|
|
|
+ BigDecimal receiptQuantity = receiptQuantityList.stream().map(StockJournalDetailsVo::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //计算出库数量
|
|
|
+ List<StockJournalDetailsVo> outboundQuantityList = lastMonthStockJournal.stream()
|
|
|
+ .filter(it -> stock.getWarehouseId().equals(it.getToWarehouseId()))
|
|
|
+ .filter(it -> stock.getProductId().equals(it.getProductId()))
|
|
|
+ .filter(it -> it.getOpType() == 2).collect(Collectors.toList());
|
|
|
+ BigDecimal outboundQuantity = outboundQuantityList.stream().map(StockJournalDetailsVo::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ MonthlyInventoryReport monthlyInventoryReport = new MonthlyInventoryReport();
|
|
|
+ monthlyInventoryReport.setWarehouseId(stock.getWarehouseId());
|
|
|
+ monthlyInventoryReport.setProductId(stock.getProductId());
|
|
|
+ monthlyInventoryReport.setInitialQuantity(BigDecimal.ZERO);//初期数量
|
|
|
+ if (ObjectUtil.isNotEmpty(initialQuantityList)) {
|
|
|
+ //初期数量=上月日报 结存数量
|
|
|
+ monthlyInventoryReport.setInitialQuantity(initialQuantityList.get(0).getBalanceQuantity());
|
|
|
+ }
|
|
|
+ monthlyInventoryReport.setReceiptQuantity(receiptQuantity);//入库数量
|
|
|
+ monthlyInventoryReport.setOutboundQuantity(outboundQuantity);//出库数量
|
|
|
+ monthlyInventoryReport.setBalanceQuantity(BigDecimal.ZERO);//结存数量
|
|
|
+ if (ObjectUtil.isNotEmpty(stock.getQuantity())) {
|
|
|
+ monthlyInventoryReport.setBalanceQuantity(stock.getQuantity());//结存数量
|
|
|
+ }
|
|
|
+ monthlyInventoryReport.setBalanceUnitPrice(BigDecimal.ZERO);//结存单价
|
|
|
+ BigDecimal unitPriceOfBalance = stock.getUnitPriceOfBalance();
|
|
|
+ if (ObjectUtil.isNotEmpty(unitPriceOfBalance)) {
|
|
|
+ monthlyInventoryReport.setBalanceUnitPrice(unitPriceOfBalance);//结存单价
|
|
|
+ }
|
|
|
+ BigDecimal multiply = monthlyInventoryReport.getBalanceQuantity().multiply(monthlyInventoryReport.getBalanceUnitPrice());
|
|
|
+ monthlyInventoryReport.setBalanceAmount(multiply);//结存金额
|
|
|
+
|
|
|
+ //赋值上月第一天
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.add(Calendar.MONTH, -1);
|
|
|
+ cal.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date startTime = cal.getTime();//上个月第一天
|
|
|
+ monthlyInventoryReport.setDailyReportDate(startTime);
|
|
|
+
|
|
|
+ monthlyInventoryReportList.add(monthlyInventoryReport);
|
|
|
+ }
|
|
|
+ this.saveBatch(monthlyInventoryReportList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|