6 天以前 d90a45a49ddb0ae512ef97b5e6fc981caab5e158
src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -84,7 +84,7 @@
        p.product_name,
        si.batch_no,
        si.customer,
        rp.product_name AS root_product_name,
        rp.product_type AS productScope,
        si.production_date
        FROM
        stock_inventory si
@@ -108,11 +108,15 @@
            <if test="ew.productScope != null and ew.productScope != ''">
                <choose>
                    <when test="ew.productScope == '成品'">
                        AND rp.product_name = '成品'
                        AND rp.product_type = '成品'
                    </when>
                    <otherwise>
                        AND rp.product_name != '成品'
                    </otherwise>
                    <when test="ew.productScope == '半成品'">
                        AND rp.product_type = '半成品'
                    </when>
                    <when test="ew.productScope == '原材料'">
                        AND (rp.product_type IS NULL
                        OR (rp.product_type != '成品' AND rp.product_type != '半成品'))
                    </when>
                </choose>
            </if>
        </where>
@@ -261,27 +265,65 @@
    </select>
    <select id="selectDailyStockInCounts" resultType="java.util.Map">
        WITH RECURSIVE get_root AS (SELECT id,
                                           parent_id,
                                           id AS root_id
                                    FROM product
                                    WHERE parent_id IS NULL
                                    UNION ALL
                                    SELECT p.id,
                                           p.parent_id,
                                           gr.root_id
                                    FROM product p
                                             INNER JOIN get_root gr ON p.parent_id = gr.id)
        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}
          AND sir.create_time &lt;= #{endDate}
                 JOIN get_root gr ON gr.id = p.id
                 JOIN product rp ON rp.id = gr.root_id
        WHERE
        <choose>
            <when test="productScope == '成品'">rp.product_type = '成品'</when>
            <when test="productScope == '半成品'">rp.product_type = '半成品'</when>
            <otherwise>(rp.product_type IS NULL
                OR (rp.product_type != '成品' AND rp.product_type != '半成品'))</otherwise>
        </choose>
        AND 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">
        WITH RECURSIVE get_root AS (SELECT id,
                                           parent_id,
                                           id AS root_id
                                    FROM product
                                    WHERE parent_id IS NULL
                                    UNION ALL
                                    SELECT p.id,
                                           p.parent_id,
                                           gr.root_id
                                    FROM product p
                                             INNER JOIN get_root gr ON p.parent_id = gr.id)
        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}
          AND sor.create_time &lt;= #{endDate}
                 JOIN get_root gr ON gr.id = p.id
                 JOIN product rp ON rp.id = gr.root_id
        WHERE
        <choose>
            <when test="productScope == '成品'">rp.product_type = '成品'</when>
            <when test="productScope == '半成品'">rp.product_type = '半成品'</when>
            <otherwise>(rp.product_type IS NULL
                OR (rp.product_type != '成品' AND rp.product_type != '半成品'))</otherwise>
        </choose>
        AND sor.create_time &gt;= #{startDate}
        AND sor.create_time &lt;= #{endDate}
        GROUP BY DATE(sor.create_time)
        ORDER BY DATE(sor.create_time) ASC
    </select>
@@ -359,7 +401,9 @@
            p.parent_id AS parent_id,
            p1.product_name AS parentName,
            si.batch_no,
            si.customer
            si.customer,
            si.production_date,
            pm.validity_period
            FROM
            stock_inventory si
            LEFT JOIN product_model pm ON si.product_model_id = pm.id