Explorar o código

月度库存报表

yzc hai 1 ano
pai
achega
ee399e498c

+ 3 - 3
code/src/test/java/WmsDataSource.java

@@ -4,9 +4,9 @@ public class WmsDataSource {
 
     public static void main(String[] args) {
         GeneratorApplication.builder()
-                .url("jdbc:mysql://36.134.91.96:17330/bytesailing_wms?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true")
-                .username("fjhx2012mysql")
-                .password("3PN-Mzn#vnP&q6d")
+                .url("jdbc:mysql://36.134.91.96:12333/bytesailing_wms?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true")
+                .username("root")
+                .password("5fWD*oa^nso@kmKa")
                 .port(9989)
                 .module("hx-wms")
                 .parent("com.fjhx.wms")

+ 37 - 0
hx-wms/src/main/java/com/fjhx/wms/controller/monthly/MonthlyInventoryReportController.java

@@ -0,0 +1,37 @@
+package com.fjhx.wms.controller.monthly;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.wms.entity.monthly.dto.MonthlyInventoryReportSelectDto;
+import com.fjhx.wms.entity.monthly.vo.MonthlyInventoryReportVo;
+import com.fjhx.wms.service.monthly.MonthlyInventoryReportService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * <p>
+ * 月度库存报表 前端控制器
+ * </p>
+ *
+ * @author
+ * @since 2023-07-05
+ */
+@RestController
+@RequestMapping("/monthlyInventoryReport")
+public class MonthlyInventoryReportController {
+
+    @Autowired
+    private MonthlyInventoryReportService monthlyInventoryReportService;
+
+    /**
+     * 月度库存报表分页
+     */
+    @PostMapping("/page")
+    public Page<MonthlyInventoryReportVo> page(@RequestBody MonthlyInventoryReportSelectDto dto) {
+        return monthlyInventoryReportService.getPage(dto);
+    }
+
+}

+ 17 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/monthly/dto/MonthlyInventoryReportDto.java

@@ -0,0 +1,17 @@
+package com.fjhx.wms.entity.monthly.dto;
+
+import com.fjhx.wms.entity.monthly.po.MonthlyInventoryReport;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 月度库存报表新增编辑入参实体
+ *
+ * @author
+ * @since 2023-07-05
+ */
+@Getter
+@Setter
+public class MonthlyInventoryReportDto extends MonthlyInventoryReport {
+
+}

+ 17 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/monthly/dto/MonthlyInventoryReportSelectDto.java

@@ -0,0 +1,17 @@
+package com.fjhx.wms.entity.monthly.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 月度库存报表列表查询入参实体
+ *
+ * @author
+ * @since 2023-07-05
+ */
+@Getter
+@Setter
+public class MonthlyInventoryReportSelectDto extends BaseSelectDto {
+
+}

+ 69 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/monthly/po/MonthlyInventoryReport.java

@@ -0,0 +1,69 @@
+package com.fjhx.wms.entity.monthly.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.core.domain.BasePo;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * <p>
+ * 月度库存报表
+ * </p>
+ *
+ * @author
+ * @since 2023-07-05
+ */
+@Getter
+@Setter
+@TableName("monthly_inventory_report")
+public class MonthlyInventoryReport extends BasePo {
+
+    /**
+     * 仓库id
+     */
+    private Long warehouseId;
+
+    /**
+     * 产品数量
+     */
+    private Long productId;
+
+    /**
+     * 初期数量
+     */
+    private BigDecimal initialQuantity;
+
+    /**
+     * 入库数量
+     */
+    private BigDecimal receiptQuantity;
+
+    /**
+     * 出库数量
+     */
+    private BigDecimal outboundQuantity;
+
+    /**
+     * 结存数量
+     */
+    private BigDecimal balanceQuantity;
+
+    /**
+     * 结存单价
+     */
+    private BigDecimal balanceUnitPrice;
+
+    /**
+     * 结存金额
+     */
+    private BigDecimal balanceAmount;
+
+    /**
+     * 报表时间
+     */
+    private Date dailyReportDate;
+
+}

+ 17 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/monthly/vo/MonthlyInventoryReportVo.java

@@ -0,0 +1,17 @@
+package com.fjhx.wms.entity.monthly.vo;
+
+import com.fjhx.wms.entity.monthly.po.MonthlyInventoryReport;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 月度库存报表列表查询返回值实体
+ *
+ * @author
+ * @since 2023-07-05
+ */
+@Getter
+@Setter
+public class MonthlyInventoryReportVo extends MonthlyInventoryReport {
+
+}

+ 5 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/stock/po/Stock.java

@@ -40,4 +40,9 @@ public class Stock extends BasePo {
      */
     private String victoriatouristJson;
 
+    /**
+     * 结存单价
+     */
+    private BigDecimal unitPriceOfBalance;
+
 }

+ 39 - 0
hx-wms/src/main/java/com/fjhx/wms/mapper/monthly/MonthlyInventoryReportMapper.java

@@ -0,0 +1,39 @@
+package com.fjhx.wms.mapper.monthly;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.wms.entity.monthly.po.MonthlyInventoryReport;
+import com.fjhx.wms.entity.monthly.vo.MonthlyInventoryReportVo;
+import com.fjhx.wms.entity.stock.vo.StockJournalDetailsVo;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+
+/**
+ * <p>
+ * 月度库存报表 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2023-07-05
+ */
+public interface MonthlyInventoryReportMapper extends BaseMapper<MonthlyInventoryReport> {
+
+    /**
+     * 月度库存报表分页
+     */
+    Page<MonthlyInventoryReportVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<MonthlyInventoryReport> wrapper);
+
+    /**
+     * 获取上个月的出入库记录
+     */
+    List<StockJournalDetailsVo> getLastMonthStockJournal();
+
+    /**
+     * 获取上个月的报表
+     */
+    List<MonthlyInventoryReportVo> getLastMonthMonthlyInventoryReport();
+
+}

+ 25 - 0
hx-wms/src/main/java/com/fjhx/wms/service/monthly/MonthlyInventoryReportService.java

@@ -0,0 +1,25 @@
+package com.fjhx.wms.service.monthly;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+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.ruoyi.common.core.service.BaseService;
+
+
+/**
+ * <p>
+ * 月度库存报表 服务类
+ * </p>
+ *
+ * @author
+ * @since 2023-07-05
+ */
+public interface MonthlyInventoryReportService extends BaseService<MonthlyInventoryReport> {
+
+    /**
+     * 月度库存报表分页
+     */
+    Page<MonthlyInventoryReportVo> getPage(MonthlyInventoryReportSelectDto dto);
+
+}

+ 111 - 0
hx-wms/src/main/java/com/fjhx/wms/service/monthly/impl/MonthlyInventoryReportServiceImpl.java

@@ -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);
+    }
+
+}

+ 49 - 0
hx-wms/src/main/resources/mapper/monthly/MonthlyInventoryReportMapper.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fjhx.wms.mapper.monthly.MonthlyInventoryReportMapper">
+    <select id="getPage" resultType="com.fjhx.wms.entity.monthly.vo.MonthlyInventoryReportVo">
+        select mir.id,
+               mir.warehouse_id,
+               mir.product_id,
+               mir.initial_quantity,
+               mir.receipt_quantity,
+               mir.outbound_quantity,
+               mir.balance_quantity,
+               mir.balance_unit_price,
+               mir.balance_amount,
+               mir.create_user,
+               mir.create_time,
+               mir.update_user,
+               mir.update_time
+        from monthly_inventory_report mir
+            ${ew.customSqlSegment}
+    </select>
+    <select id="getLastMonthStockJournal" resultType="com.fjhx.wms.entity.stock.vo.StockJournalDetailsVo">
+        SELECT sj.warehouse_id toWarehouseId,
+               sjd.product_id,
+               sjd.quantity,
+               sj.op_type
+        FROM stock_journal_details sjd
+                 LEFT JOIN stock_journal sj ON sjd.stock_journal_id = sj.id
+        WHERE DATE_FORMAT(sjd.create_time, '%Y-%m') = DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y-%m')
+    </select>
+    <select id="getLastMonthMonthlyInventoryReport"
+            resultType="com.fjhx.wms.entity.monthly.vo.MonthlyInventoryReportVo">
+        select mir.id,
+               mir.warehouse_id,
+               mir.product_id,
+               mir.initial_quantity,
+               mir.receipt_quantity,
+               mir.outbound_quantity,
+               mir.balance_quantity,
+               mir.balance_unit_price,
+               mir.balance_amount,
+               mir.create_user,
+               mir.create_time,
+               mir.update_user,
+               mir.update_time
+        from monthly_inventory_report mir
+        where DATE_FORMAT(mir.daily_report_date, '%Y-%m') = DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y-%m')
+    </select>
+
+</mapper>