SalesmanQuotationLineMapper.xml
6.12 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?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.lframework.xingyun.sc.procurement.mappers.quotation.SalesmanQuotationLineMapper">
<resultMap id="SalesmanQuotationLine" type="com.lframework.xingyun.sc.procurement.entity.SalesmanQuotationLine">
<id column="id" property="id"/>
<result column="quotation_id" property="quotationId"/>
<result column="product_id" property="productId"/>
<result column="product_name" property="productName"/>
<result column="product_code" property="productCode"/>
<result column="product_type" property="productType"/>
<result column="fixed_attrition_rate" property="fixedAttritionRate"/>
<result column="material_type" property="materialType"/>
<result column="quantity" property="quantity"/>
<result column="purchase_price" property="purchasePrice"/>
<result column="estimated_loss" property="estimatedLoss"/>
<result column="application_attrition" property="applicationAttrition"/>
<result column="paint_damage_ratio" property="paintDamageRatio"/>
<result column="item_id" property="itemId"/>
<result column="quote_time" property="quoteTime"/>
<result column="quoter_name" property="quoterName"/>
<result column="supplier_name" property="supplierName"/>
<result column="create_by_id" property="createById"/>
<result column="create_by" property="createBy"/>
<result column="update_by_id" property="updateById"/>
<result column="update_by" property="updateBy"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="SalesmanQuotationLineSql">
SELECT
tb.id,
tb.quotation_id,
tb.product_id,
br.product_name,
br.code AS product_code,
br.type AS product_type,
br.attrition_rate AS fixed_attrition_rate,
tb.material_type,
tb.quantity,
tb.purchase_price,
tb.estimated_loss,
tb.application_attrition,
tb.paint_damage_ratio,
tb.item_id,
tb.create_by_id,
tb.create_by,
tb.update_by_id,
tb.update_by,
tb.create_time,
tb.update_time
FROM procurement_salesman_quotation_line tb
LEFT JOIN base_data_breed_relationship br ON br.id = tb.product_id
</sql>
<select id="query" resultMap="SalesmanQuotationLine">
<include refid="SalesmanQuotationLineSql"/>
<where>
<if test="vo.quotationId != null and vo.quotationId != ''">
AND tb.quotation_id = #{vo.quotationId}
</if>
</where>
ORDER BY tb.create_time ASC
</select>
<sql id="SalesmanQuotationLineSql1">
SELECT
tb.id,
tb.quotation_id,
sq.quote_time,
sq.quoter_name,
pdc.unit_name AS supplier_name,
br.product_name,
tb.quantity,
tb.purchase_price,
tb.paint_damage_ratio,
tb.create_by_id,
tb.create_by,
tb.update_by_id,
tb.update_by,
tb.create_time,
tb.update_time
FROM procurement_salesman_quotation_line tb
LEFT JOIN base_data_breed_relationship br ON br.id = tb.product_id
LEFT JOIN procurement_salesman_quotation sq on sq.id=tb.quotation_id
LEFT JOIN procurement_domestic_customer_credit pdc ON pdc.id = sq.supplier_id
</sql>
<select id="queryCurrentDayList" resultMap="SalesmanQuotationLine">
<include refid="SalesmanQuotationLineSql1"/>
<where>
DATE(sq.create_time) = #{qvo.today}
<if test="qvo.status != null and qvo.status != ''">
AND sq.status = #{qvo.status}
</if>
<if test="qvo.searchKey != null and qvo.searchKey != ''">
AND (sq.quoter_name LIKE CONCAT('%', #{qvo.searchKey}, '%') OR pdc.unit_name LIKE CONCAT('%',
#{qvo.searchKey}, '%') OR br.product_name LIKE CONCAT('%',#{qvo.searchKey}, '%'))
</if>
<if test="qvo.quoteDateStart != null">
AND sq.quote_time >= #{qvo.quoteDateStart}
</if>
<if test="qvo.quoteDateEnd != null">
<![CDATA[
AND sq.quote_time <= #{qvo.quoteDateEnd}
]]>
</if>
</where>
ORDER BY tb.create_time DESC, tb.quotation_id DESC
</select>
<select id="statCurrentDayDealClosedByRegion"
resultType="com.lframework.xingyun.sc.procurement.dto.quotation.SalesmanQuotationDealRegionSummaryDto">
SELECT
sq.region AS regionId,
sd1.name AS regionName,
SUM(tb.quantity) AS quantity
FROM procurement_salesman_quotation_line tb
INNER JOIN procurement_salesman_quotation sq ON sq.id = tb.quotation_id
LEFT JOIN sys_dept sd1 ON sd1.id = sq.region
<where>
DATE(sq.create_time) = #{day}
AND sq.status = 'DEAL_CLOSED'
</where>
GROUP BY sq.region, sd1.name
ORDER BY quantity DESC
</select>
<select id="statCurrentDayDealClosedByProduct"
resultType="com.lframework.xingyun.sc.procurement.dto.quotation.SalesmanQuotationDealProductSummaryDto">
SELECT
tb.product_id AS productId,
br.product_name AS productName,
SUM(tb.quantity) AS quantity,
(SUM(tb.quantity * tb.purchase_price) / NULLIF(SUM(tb.quantity), 0)) AS price
FROM procurement_salesman_quotation_line tb
INNER JOIN procurement_salesman_quotation sq ON sq.id = tb.quotation_id
LEFT JOIN base_data_breed_relationship br ON br.id = tb.product_id
<where>
DATE(sq.create_time) = #{day}
AND sq.status = 'DEAL_CLOSED'
</where>
GROUP BY tb.product_id, br.product_name
ORDER BY quantity DESC
</select>
</mapper>