gongchunyi
13 小时以前 875adbd59a28453cdf443c3244e2691ad1dd02ac
fix: 产品父类名称适配
已修改4个文件
78 ■■■■■ 文件已修改
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sales/SalesLedgerProductMapper.xml 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/stock/StockInventoryMapper.xml 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -1088,26 +1088,17 @@
    @Override
    public List<Map<String, Object>> productInOutAnalysis(Integer type) {
        String targetName;
        // 0-原材料 1-半成品 2-成品
        Integer modelType;
        if (type == 1) {
            targetName = "原材料";
            modelType = 0;
        } else if (type == 2) {
            targetName = "成品";
            modelType = 2;
        } else if (type == 3) {
            targetName = "半成品";
            modelType = 1;
        } else {
            return new ArrayList<>();
        }
        LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Product::getProductName, targetName).isNull(Product::getParentId);
        Product rootCategory = productMapper.selectOne(queryWrapper);
        if (rootCategory == null) {
            log.warn("未找到名称为 {} 的顶级产品分类", targetName);
            return new ArrayList<>();
        }
        Long rootCategoryId = rootCategory.getId();
        LocalDate now = LocalDate.now();
        DateTimeFormatter displayDtf = DateTimeFormatter.ofPattern("M/d");
@@ -1115,10 +1106,10 @@
        String startDate = now.minusDays(6).toString();
        String endDate = now.toString();
        List<Map<String, Object>> inCounts = stockInventoryMapper.selectDailyStockInCounts(rootCategoryId, startDate,
        List<Map<String, Object>> inCounts = stockInventoryMapper.selectDailyStockInCounts(modelType, startDate,
                endDate + " 23:59:59");
        List<Map<String, Object>> outCounts = stockInventoryMapper.selectDailyStockOutCounts(rootCategoryId, startDate,
        List<Map<String, Object>> outCounts = stockInventoryMapper.selectDailyStockOutCounts(modelType, startDate,
                endDate + " 23:59:59");
        Map<LocalDate, BigDecimal> inMap = inCounts.stream()
src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java
@@ -45,9 +45,9 @@
    int selectStorageProductCountByDate(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
    List<Map<String, Object>> selectDailyStockInCounts(@Param("rootCategoryId") Long rootCategoryId, @Param("startDate") String startDate, @Param("endDate") String endDate);
    List<Map<String, Object>> selectDailyStockInCounts(@Param("modelType") Integer modelType, @Param("startDate") String startDate, @Param("endDate") String endDate);
    List<Map<String, Object>> selectDailyStockOutCounts(@Param("rootCategoryId") Long rootCategoryId, @Param("startDate") String startDate, @Param("endDate") String endDate);
    List<Map<String, Object>> selectDailyStockOutCounts(@Param("modelType") Integer modelType, @Param("startDate") String startDate, @Param("endDate") String endDate);
    BigDecimal selectTotalByDate(@Param("now") LocalDate now);
src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -187,6 +187,14 @@
    </select>
    <select id="selectRawMaterialPurchaseAnalysis" resultType="java.util.Map">
        WITH RECURSIVE product_tree AS (SELECT id
                                        FROM product
                                        WHERE parent_id IS NULL
                                          AND product_name LIKE '%原材料%'
                                        UNION ALL
                                        SELECT p.id
                                        FROM product p
                                                 INNER JOIN product_tree pt ON p.parent_id = pt.id)
        SELECT
            pr.product_name AS name,
            SUM( slp.tax_inclusive_total_price ) AS value
@@ -195,7 +203,7 @@
            JOIN product pr ON slp.product_id = pr.id
        WHERE
            slp.type = 2
            AND pr.parent_id = ( SELECT id FROM product WHERE product_name = '原材料' )
            AND pr.id IN ( SELECT id FROM product_tree )
        GROUP BY
            pr.id,
            pr.product_name
@@ -206,20 +214,25 @@
    <select id="selectProductCountByTypeAndDate" resultType="int">
        SELECT IFNULL(COUNT(*), 0)
        FROM sales_ledger_product
        WHERE type = #{type}
        FROM sales_ledger_product slp
                 LEFT JOIN sales_ledger sl
                           ON slp.type = 1 AND sl.id = slp.sales_ledger_id
                 LEFT JOIN purchase_ledger pl
                           ON slp.type = 2 AND pl.id = slp.sales_ledger_id
        WHERE slp.type = #{type}
        <if test="startDate != null">
            AND register_date &gt;= #{startDate}
            AND IFNULL(IF(slp.type = 1, sl.entry_date, pl.entry_date), slp.register_date) &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            AND register_date &lt;= #{endDate}
            AND IFNULL(IF(slp.type = 1, sl.entry_date, pl.entry_date), slp.register_date) &lt;= #{endDate}
        </if>
    </select>
    <select id="selectRawMaterialExpense" resultType="java.math.BigDecimal">
        WITH RECURSIVE product_tree AS (SELECT id
                                        FROM product
                                        WHERE product_name = '原材料'
                                        WHERE parent_id IS NULL
                                          AND product_name LIKE '%原材料%'
                                        UNION ALL
src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -264,27 +264,41 @@
                AND create_time &lt;= #{endDate}) AS combined_counts
    </select>
    <!-- 产品库根节点分类:0-原材料 1-半成品 2-成品(先匹配半成品,避免被成品包含) -->
    <sql id="productTypeTree">
        WITH RECURSIVE product_tree AS (SELECT id
                                        FROM product
                                        WHERE parent_id IS NULL
                                          AND ((#{modelType} = 0 AND product_name LIKE '%原材料%')
                                            OR (#{modelType} = 1 AND product_name LIKE '%半成品%')
                                            OR (#{modelType} = 2 AND product_name LIKE '%成品%' AND product_name NOT LIKE '%半成品%'))
                                        UNION ALL
                                        SELECT p.id
                                        FROM product p
                                                 INNER JOIN product_tree pt ON p.parent_id = pt.id)
    </sql>
    <select id="selectDailyStockInCounts" resultType="java.util.Map">
        <include refid="productTypeTree"/>
        SELECT DATE(sir.create_time) AS date,
               SUM(sir.stock_in_num) AS count
        FROM stock_in_record sir
                 JOIN product_model pm ON sir.product_model_id = pm.id
                 JOIN product p ON pm.product_id = p.id
        WHERE (p.parent_id = #{rootCategoryId} OR p.id = #{rootCategoryId})
          AND sir.create_time &gt;= #{startDate}
                 JOIN product_tree pt ON pt.id = pm.product_id
        WHERE sir.create_time &gt;= #{startDate}
          AND sir.create_time &lt;= #{endDate}
        GROUP BY DATE(sir.create_time)
        ORDER BY DATE(sir.create_time) ASC
    </select>
    <select id="selectDailyStockOutCounts" resultType="java.util.Map">
        <include refid="productTypeTree"/>
        SELECT DATE(sor.create_time)  AS date,
               SUM(sor.stock_out_num) AS count
        FROM stock_out_record sor
                 JOIN product_model pm ON sor.product_model_id = pm.id
                 JOIN product p ON pm.product_id = p.id
        WHERE (p.parent_id = #{rootCategoryId} OR p.id = #{rootCategoryId})
          AND sor.create_time &gt;= #{startDate}
                 JOIN product_tree pt ON pt.id = pm.product_id
        WHERE sor.create_time &gt;= #{startDate}
          AND sor.create_time &lt;= #{endDate}
        GROUP BY DATE(sor.create_time)
        ORDER BY DATE(sor.create_time) ASC