demand: tms-统计报表-月结客户出货统计-销售联系人不准确问题修复

committer: heyu
This commit is contained in:
aike 2025-11-13 09:54:24 +08:00
parent 36e2e496d8
commit e330d16f2f

View File

@ -4014,7 +4014,7 @@
IFNULL(SUM(CASE WHEN a.receive_country != '0086' AND NOT (a.send_country = '0086' AND tl.trans_type IN ('1','2','3','4','5')) THEN a.bill_weight ELSE 0 END), 0) AS otherWeight
FROM emis_waybill a
LEFT JOIN emis_trans_line tl ON a.trans_line_type = tl.line_code AND tl.del_flag = '0'
LEFT JOIN emis_customer_user cu ON a.customer_code = cu.customer_code AND cu.del_flag = '0'
LEFT JOIN emis_customer_user cu ON a.cust_no = cu.monthly_pay_code AND cu.del_flag = '0'
<where>
a.del_flag = '0'
AND a.order_status !='0'
@ -4051,7 +4051,121 @@
</if>
<!-- 目的国家 -->
<if test="receiveCountry != null and receiveCountry != ''">
AND a.receive_country = #{receiveCountry}
<choose>
<when test="receiveCountry == 'other'">
AND a.receive_country NOT IN ('0086','0084','0855','0095','0880','0856','0066')
</when>
<otherwise>
AND a.receive_country = #{receiveCountry}
</otherwise>
</choose>
</if>
<!-- 销售主管 -->
<if test="salesExecutive != null and salesExecutive != ''">
AND cu.sales_executive LIKE CONCAT('%', #{salesExecutive}, '%')
</if>
<!-- 销售支持 -->
<if test="salesSupport != null and salesSupport != ''">
AND cu.sales_support LIKE CONCAT('%', #{salesSupport}, '%')
</if>
<!-- 销售联系人 -->
<if test="salesmen != null and salesmen != ''">
AND cu.salesmen LIKE CONCAT('%', #{salesmen}, '%')
</if>
<!-- 权限控制 -->
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
AND (
cu.sales_executive = #{params.privEmpName}
OR cu.sales_support = #{params.privEmpName}
OR cu.salesmen = #{params.privEmpName}
OR cu.salesmen IN (
SELECT salesmen FROM emis_salesmen_rel esr
WHERE esr.del_flag = '0'
AND esr.bl_open = '1'
AND NOW() <![CDATA[ >= ]]> esr.start_date
AND NOW() <![CDATA[ <= ]]> esr.end_date
AND esr.sales_ass = #{params.privEmpName}
)
)
</if>
</where>
GROUP BY a.cust_no
ORDER BY a.cust_name
</select>
<!-- 按目的国家查询月结客户出货统计 -->
<select id="selectMonthlyCustomerShipmentStatByCountry" parameterType="EmisWaybill" resultType="map">
SELECT
a.customer_code AS customerCode,
a.cust_name AS customerName,
a.cust_no AS custNo,
COUNT(DISTINCT a.bill_code) AS totalTickets,
IFNULL(SUM(a.bill_weight), 0) AS totalWeight,
GROUP_CONCAT(DISTINCT cu.salesmen ORDER BY a.order_date SEPARATOR '/') AS salesmen,
SUM(CASE WHEN a.receive_country = '0086' THEN 1 ELSE 0 END) AS chinaTickets,
IFNULL(SUM(CASE WHEN a.receive_country = '0086' THEN a.bill_weight ELSE 0 END), 0) AS chinaWeight,
SUM(CASE WHEN a.receive_country = '0084' THEN 1 ELSE 0 END) AS vietnamTickets,
IFNULL(SUM(CASE WHEN a.receive_country = '0084' THEN a.bill_weight ELSE 0 END), 0) AS vietnamWeight,
SUM(CASE WHEN a.receive_country = '0855' THEN 1 ELSE 0 END) AS cambodiaTickets,
IFNULL(SUM(CASE WHEN a.receive_country = '0855' THEN a.bill_weight ELSE 0 END), 0) AS cambodiaWeight,
SUM(CASE WHEN a.receive_country = '0095' THEN 1 ELSE 0 END) AS myanmarTickets,
IFNULL(SUM(CASE WHEN a.receive_country = '0095' THEN a.bill_weight ELSE 0 END), 0) AS myanmarWeight,
SUM(CASE WHEN a.receive_country = '0880' THEN 1 ELSE 0 END) AS bangladeshTickets,
IFNULL(SUM(CASE WHEN a.receive_country = '0880' THEN a.bill_weight ELSE 0 END), 0) AS bangladeshWeight,
SUM(CASE WHEN a.receive_country = '0856' THEN 1 ELSE 0 END) AS laosTickets,
IFNULL(SUM(CASE WHEN a.receive_country = '0856' THEN a.bill_weight ELSE 0 END), 0) AS laosWeight,
SUM(CASE WHEN a.receive_country = '0066' THEN 1 ELSE 0 END) AS thailandTickets,
IFNULL(SUM(CASE WHEN a.receive_country = '0066' THEN a.bill_weight ELSE 0 END), 0) AS thailandWeight,
SUM(CASE WHEN a.receive_country NOT IN ('0086','0084','0855','0095','0880','0856','0066') THEN 1 ELSE 0 END) AS otherTickets,
IFNULL(SUM(CASE WHEN a.receive_country NOT IN ('0086','0084','0855','0095','0880','0856','0066') THEN a.bill_weight ELSE 0 END), 0) AS otherWeight,
0 AS importTickets,
0 AS importWeight
FROM emis_waybill a
LEFT JOIN emis_customer_user cu ON a.cust_no = cu.monthly_pay_code AND cu.del_flag = '0'
<where>
a.del_flag = '0'
AND a.order_status !='0'
AND a.order_status!='2'
AND a.cust_no IS NOT NULL
AND a.cust_no != ''
<!-- 剔除问题件类型为面单删除、出口虚拟单、返货虚拟单的运单 -->
AND NOT EXISTS (
SELECT 1 FROM emis_waybill_problem_info ewpi
WHERE ewpi.bill_code = a.bill_code
AND ewpi.del_flag = '0'
AND ewpi.problem_type IN (151, 170, 173)
)
<!-- 寄件日期范围 -->
<if test="params.beginSendDate != null and params.beginSendDate != ''">
AND a.send_date <![CDATA[ >= ]]> #{params.beginSendDate}
</if>
<if test="params.endSendDate != null and params.endSendDate != ''">
AND a.send_date <![CDATA[ <= ]]> #{params.endSendDate}
</if>
<!-- 客户名称 -->
<if test="customerName != null and customerName != ''">
AND a.cust_name LIKE CONCAT('%', #{custName}, '%')
</if>
<if test="customerCode != null and customerCode != ''">
AND a.customer_code = #{customerCode}
</if>
<if test="custNo != null and custNo != ''">
AND a.cust_no = #{custNo}
</if>
<!-- 寄件国家 -->
<if test="sendCountry != null and sendCountry != ''">
AND a.send_country = #{sendCountry}
</if>
<!-- 目的国家 -->
<if test="receiveCountry != null and receiveCountry != ''">
<choose>
<when test="receiveCountry == 'other'">
AND a.receive_country NOT IN ('0086','0084','0855','0095','0880','0856','0066')
</when>
<otherwise>
AND a.receive_country = #{receiveCountry}
</otherwise>
</choose>
</if>
<!-- 销售主管 -->
<if test="salesExecutive != null and salesExecutive != ''">
@ -4125,7 +4239,14 @@
</if>
<!-- 目的国家 -->
<if test="receiveCountry != null and receiveCountry != ''">
AND a.receive_country = #{receiveCountry}
<choose>
<when test="receiveCountry == 'other'">
AND a.receive_country NOT IN ('0086','0084','0855','0095','0880','0856','0066')
</when>
<otherwise>
AND a.receive_country = #{receiveCountry}
</otherwise>
</choose>
</if>
<!-- 销售主管 -->
<if test="salesExecutive != null and salesExecutive != ''">
@ -4170,7 +4291,7 @@
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
AND EXISTS (
SELECT 1 FROM emis_customer_user cu
WHERE a.customer_code = cu.customer_code
WHERE a.cust_no = cu.monthly_pay_code
AND cu.del_flag = '0'
AND (
cu.sales_executive = #{params.privEmpName}