liding
15 小时以前 c7ce2c2342f427bbad0263ab9e35585f6b98ee93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?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.ruoyi.sales.mapper.SalesLedgerProductMapper">
 
    <select id="selectSalesLedgerProductList" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct">
        SELECT
        T1.*,
        t3.shipping_car_number,
        t3.shipping_date
        FROM
        sales_ledger_product T1
        left join shipping_info t3 on T1.id = t3.sales_ledger_product_id
        <where>
            1=1
            <if test="salesLedgerProduct.salesLedgerId != null and salesLedgerProduct.salesLedgerId != '' ">
                AND  T1.sales_ledger_id = #{salesLedgerProduct.salesLedgerId}
            </if>
            <if test="salesLedgerProduct.type != null and salesLedgerProduct.type != '' ">
                AND  T1.type = #{salesLedgerProduct.type}
            </if>
        </where>
    </select>
    <select id="selectSalesLedgerProductByMainId" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct">
        select slp.*
        from quality_inspect qi
                 left join production_product_main ppm on qi.product_main_id = ppm.id
                 left join product_work_order pwo on ppm.work_order_id = pwo.id
                 left join product_order  po on pwo.product_order_id = po.id
                 left join sales_ledger_product slp on po.product_model_id = slp.id
        where qi.product_main_id = #{productMainId}
 
 
    </select>
    <select id="listPage" resultType="com.ruoyi.sales.dto.SalesLedgerProductDto">
        select slp.*,
        sl.project_name,
        sl.customer_name,
        sl.sales_contract_no,
        sl.customer_contract_no
        from sales_ledger_product slp
        left join sales_ledger sl on slp.sales_ledger_id = sl.id
        <where>
            slp.type = 1
            <if test="req.salesContractNo != null and req.salesContractNo != '' ">
                AND  sl.sales_contract_no like concat('%',#{req.salesContractNo},'%')
            </if>
            <if test="req.customerContractNo != null and req.customerContractNo != '' ">
                AND  sl.customer_contract_no like concat('%',#{req.customerContractNo},'%')
            </if>
            <if test="req.projectName != null and req.projectName != '' ">
                AND  sl.project_name like concat('%',#{req.projectName},'%')
            </if>
            <if test="req.customerName != null and req.customerName != '' ">
                AND  sl.customer_name like concat('%',#{req.customerName},'%')
            </if>
            <if test="req.productCategory != null and req.productCategory != '' ">
                AND  slp.product_category like concat('%',#{req.productCategory},'%')
            </if>
            <if test="req.status != null and req.status ">
                AND  slp.pending_invoice_total &gt; 0
            </if>
        </where>
        order by slp.register_date desc
    </select>
    <select id="listPagePurchaseLedger" resultType="com.ruoyi.sales.dto.SalesLedgerProductDto">
        select slp.*,
        sl.project_name,
        sl.supplier_name,
        sl.supplier_id,
        sl.sales_contract_no,
        sl.purchase_contract_number
        from sales_ledger_product slp
        left join purchase_ledger sl on slp.sales_ledger_id = sl.id
        <where>
            slp.type = 2
            <if test="req.purchaseContractNumber != null and req.purchaseContractNumber != '' ">
                AND  sl.purchase_contract_number like concat('%',#{req.purchaseContractNumber},'%')
            </if>
            <if test="req.customerContractNo != null and req.customerContractNo != '' ">
                AND  sl.customer_contract_no like concat('%',#{req.customerContractNo},'%')
            </if>
            <if test="req.projectName != null and req.projectName != '' ">
                AND  sl.project_name like concat('%',#{req.projectName},'%')
            </if>
            <if test="req.customerName != null and req.customerName != '' ">
                AND  sl.customer_name like concat('%',#{req.customerName},'%')
            </if>
            <if test="req.productCategory != null and req.productCategory != '' ">
                AND  slp.product_category like concat('%',#{req.productCategory},'%')
            </if>
            <if test="req.status != null and req.status ">
                AND  slp.pending_invoice_total &gt; 0
            </if>
        </where>
        order by slp.register_date desc
    </select>
    <select id="procurementBusinessSummaryListPage"
            resultType="com.ruoyi.purchase.dto.ProcurementBusinessSummaryDto">
        SELECT
        slp.product_category AS productCategory,
        slp.specification_model AS specificationModel,
        sl.supplier_name AS supplierName,
        SUM(slp.quantity) AS purchaseNum,
        SUM(slp.tax_inclusive_total_price) AS purchaseAmount,
        COUNT(DISTINCT slp.sales_ledger_id) AS purchaseTimes,
        <!-- 平均单价 = 总采购金额/总采购数量,保留2位小数,避免除0 -->
        ROUND(IF(SUM(slp.quantity) = 0, 0, SUM(slp.tax_inclusive_total_price) / SUM(slp.quantity)), 2) AS averagePrice,
        <!-- 该产品大类下最后一个录入日期(取台账主表的entry_date) -->
        MAX(sl.entry_date) AS entryDate
        FROM sales_ledger_product slp
        <!-- 关联台账主表:获取录入日期entry_date -->
        LEFT JOIN purchase_ledger sl ON slp.sales_ledger_id = sl.id
        WHERE slp.type = 2 <!-- 固定筛选:采购台账(type=2) -->
        <!-- 采购日期筛选:可选条件 -->
        <if test="req.entryDateStart != null and req.entryDateEnd != null">
            AND sl.entry_date BETWEEN #{req.entryDateStart} AND #{req.entryDateEnd} <!-- 时间范围:非空有效 -->
        </if>
        <!-- 产品大类筛选:可选条件 -->
        <if test="req.productCategory != null and req.productCategory != ''">
            AND slp.product_category = #{req.productCategory}
        </if>
        <!-- 按产品大类分组聚合 -->
        GROUP BY slp.product_category
        <!-- 按产品大类排序 -->
        ORDER BY slp.product_category
    </select>
</mapper>