| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- <?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.logistics.mapper.LargeScreenReportMapper">
- <!-- 按照订单类型查询订单量-->
- <select id="queryOrderTypeReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT dict_label orderTypeName ,dict_value orderType,ifnull(num,0) num FROM (
- SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'logistics_type') a
- left join (
- SELECT
- order_type,
- count(1) num
- FROM
- biz_waybill_order d
- WHERE order_status != 6
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and d.dept_id = #{deptId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- GROUP BY
- order_type) b ON a.dict_value = b.order_type
- </select>
- <!-- 每日订单量-->
- <select id="queryDayOrdersReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- date_list.day_time AS time,
- IFNULL(t.order_num, 0) AS order_num,
- IFNULL(t.delivery_num, 0) AS delivery_num,
- IFNULL(t.proper_num, 0) AS proper_num
- FROM
- (
- SELECT
- DATE_FORMAT(
- DATE_ADD(#{startTime}, INTERVAL (a + 10*b + 100*c) DAY),
- '%Y-%m-%d'
- ) AS day_time
- FROM
- (SELECT 0 a UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) ta,
- (SELECT 0 b UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) tb,
- (SELECT 0 c UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) tc
- HAVING
- day_time<![CDATA[<=]]>#{endTime}
- ) date_list
- LEFT JOIN (
- SELECT
- DATE_FORMAT(create_time, '%Y-%m-%d') AS time,
- SUM(order_status != 6) AS order_num,
- SUM(order_status != 6 AND order_status != 5) AS delivery_num,
- SUM(order_status = 5) AS proper_num
- FROM biz_waybill_order d
- WHERE DATE_FORMAT(d.create_time, '%Y-%m-%d') >=#{startTime} AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="deptId != null and deptId != ''">
- and d.dept_id = #{deptId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- GROUP BY DATE_FORMAT(d.create_time, '%Y-%m-%d')
- ) t ON date_list.day_time = t.time
- ORDER BY date_list.day_time;
- </select>
- <!-- 按照省份查询订单量和金额(整合版)-->
- <select id="queryProvinceOrdersReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- province_name,
- merger_name,
- IFNULL(outflow_num, 0) AS outflowNum,
- IFNULL(inflow_num, 0) AS inflowNum,
- IFNULL(outflow_amount, 0) AS outflowAmount,
- IFNULL(inflow_amount, 0) AS inflowAmount
- FROM (
- SELECT
- a.NAME AS province_name,
- a.merger_name,
- -- 流出订单数(该省作为发货地)
- IFNULL(outflow_order.num, 0) AS outflow_num,
- -- 流入订单数(该省作为收货地)
- IFNULL(inflow_order.num, 0) AS inflow_num,
- -- 流出金额(该省作为发货地)
- IFNULL(outflow_cost.amt, 0) AS outflow_amount,
- -- 流入金额(该省作为收货地)
- IFNULL(inflow_cost.amt, 0) AS inflow_amount
- FROM
- (SELECT NAME, merger_name FROM sys_city WHERE `level` = 0) a
- LEFT JOIN (
- -- 流出订单统计
- SELECT
- sender_province,
- COUNT(1) AS num
- FROM biz_waybill_order d
- WHERE d.order_status != 6
- <if test="orderType != null and orderType != ''">
- AND d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- ${params.dataScope}
- GROUP BY sender_province
- ) outflow_order ON a.NAME = outflow_order.sender_province
- LEFT JOIN (
- -- 流入订单统计
- SELECT
- receiver_province,
- COUNT(1) AS num
- FROM biz_waybill_order d
- WHERE d.order_status != 6
- <if test="orderType != null and orderType != ''">
- AND d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- ${params.dataScope}
- GROUP BY receiver_province
- ) inflow_order ON a.NAME = inflow_order.receiver_province
- LEFT JOIN (
- -- 流出金额统计
- SELECT
- d.sender_province,
- IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0) AS amt
- FROM biz_waybill_order d
- LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
- WHERE d.order_status != 6
- <if test="orderType != null and orderType != ''">
- AND d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- ${params.dataScope}
- GROUP BY d.sender_province
- ) outflow_cost ON a.NAME = outflow_cost.sender_province
- LEFT JOIN (
- -- 流入金额统计
- SELECT
- d.receiver_province,
- IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0) AS amt
- FROM biz_waybill_order d
- LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
- WHERE d.order_status != 6
- <if test="orderType != null and orderType != ''">
- AND d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- ${params.dataScope}
- GROUP BY d.receiver_province
- ) inflow_cost ON a.NAME = inflow_cost.receiver_province
- ) t
- <if test="rankType != null and rankType != '' and rankType == 1">
- ORDER BY outflow_amount DESC
- </if>
- <if test="rankType != null and rankType != '' and rankType == 2">
- ORDER BY outflow_num DESC
- </if>
- </select>
- <!-- 供应商列表-->
- <select id="queryDeptList" parameterType="java.util.Map" resultType="java.util.HashMap" >
- select d.dept_id deptId,d.dept_name deptName
- from sys_dept d
- where d.status=0 and d.del_flag=0
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- </select>
- <!-- 省份列表-->
- <select id="queryProvinceList" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- a.name AS provinceName,
- a.lng,
- a.lat,
- IFNULL(SUM(CASE WHEN a.name = d.sender_province THEN 1 ELSE 0 END), 0) AS sendCount,
- IFNULL(SUM(CASE WHEN a.name = d.receiver_province THEN 1 ELSE 0 END), 0) AS recvCount
- FROM sys_city a
- LEFT JOIN biz_waybill_order d
- ON (a.name = d.sender_province OR a.name = d.receiver_province)
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and d.dept_id = #{deptId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- WHERE a.level = 0
- GROUP BY a.name, a.lng, a.lat
- ORDER BY sendCount DESC, recvCount DESC;
- </select>
- <!-- 物流轨迹省份查询流出-->
- <select id="queryLogisticsTrajectoryOutflow" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- d.receiver_province provinceName,
- b.lng,
- b.lat,
- count(1) num,
- IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0.00) amt
- FROM
- biz_waybill_order d
- LEFT JOIN sys_city b ON d.receiver_province = b.NAME
- LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
- WHERE
- b.LEVEL = 0
- and d.order_status != 6
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT( d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT( d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and d.dept_id = #{deptId}
- </if>
- <if test="searchProvince != null and searchProvince != ''">
- and d.sender_province = #{searchProvince}
- </if>
- ${params.dataScope}
- group by d.receiver_province
- </select>
- <!-- 物流轨迹省份查询流入-->
- <select id="queryLogisticsTrajectoryinflow" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- d.sender_province provinceName,
- b.lng,
- b.lat,
- count(1) num,
- IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0.00) amt
- FROM
- biz_waybill_order d
- LEFT JOIN sys_city b ON d.sender_province = b.NAME
- LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
- WHERE
- b.LEVEL = 0
- and d.order_status != 6
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and d.dept_id = #{deptId}
- </if>
- <if test="searchProvince != null and searchProvince != ''">
- and d.receiver_province = #{searchProvince}
- </if>
- ${params.dataScope}
- group by d.sender_province
- </select>
- <!-- 按照快递快运区分统计-->
- <select id="queryTransportTypeReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- c.dict_label typeName,
- ifnull( d.num, 0 ) num
- FROM
- ( SELECT DISTINCT dict_label FROM sys_dict_data WHERE dict_type = 'rjsd_logistics_product' ) c
- LEFT JOIN (
- SELECT
- dict_label typeName,
- count( 1 ) num
- FROM
- biz_waybill_order d
- LEFT JOIN ( SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'rjsd_logistics_product' ) b ON d.product_code = b.dict_value
- WHERE
- d.order_status != 6
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and d.dept_id = #{deptId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- GROUP BY
- dict_label
- ) d ON c.dict_label = d.typeName
- </select>
- <!-- 物流费用统计-->
- <select id="queryFreeOrdersReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- w.dict_label typeName,
- ifnull( q.rate_amount, 0.00 ) rateAmount
- FROM
- ( SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'logistics_type' ) w
- LEFT JOIN (
- SELECT
- sum(
- ifnull( a.adjust_amount, a.rate_amount )) rate_amount,
- order_type
- FROM
- biz_waybill_cost_details a
- LEFT JOIN biz_waybill_order d ON a.external_waybill_no = d.external_waybill_no
- WHERE
- d.order_status != 6
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and d.dept_id = #{deptId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- GROUP BY
- order_type
- ) q ON w.dict_value = q.order_type
- </select>
- <!--供应商按照金额排名-->
- <select id="queryOrdersReportByFree" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- t.dept_name deptName,
- t.rate_amount rateAmount,
- (@rank := @rank + 1) AS rankNum
- FROM (
- SELECT
- dept_name,
- IFNULL(rate_amount, 0) AS rate_amount
- FROM
- sys_dept w
- LEFT JOIN (
- SELECT
- SUM(IFNULL(a.adjust_amount, a.rate_amount)) AS rate_amount,
- a.dept_id
- FROM
- biz_waybill_cost_details a
- LEFT JOIN biz_waybill_order b
- ON a.external_waybill_no = b.external_waybill_no
- WHERE
- b.order_status != 6
- <if test="orderType != null and orderType != ''">
- and b.order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT(b.create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT(b.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and a.dept_id = #{deptId}
- </if>
- GROUP BY
- a.dept_id
- ) q ON w.dept_id = q.dept_id
- where w.del_flag='0'
- and w.status='0'
- ORDER BY
- rate_amount DESC
- ) t,
- (SELECT @rank := 0) r
- LIMIT 10;
- </select>
- <!--供应商按照订单量排名-->
- <select id="queryOrdersReportByNum" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- t.dept_name deptName,
- t.num,
- (@rank := @rank + 1) AS rankNum
- FROM (
- SELECT
- dept_name,
- IFNULL(num, 0) AS num
- FROM
- sys_dept w
- LEFT JOIN (
- SELECT
- COUNT(external_waybill_no) AS num,
- dept_id
- FROM
- biz_waybill_order
- WHERE
- order_status != 6
- <if test="orderType != null and orderType != ''">
- and order_type = #{orderType}
- </if>
- <if test="startTime != null and startTime != ''">
- and DATE_FORMAT(create_time, '%Y-%m-%d') >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and DATE_FORMAT(create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
- </if>
- <if test="deptId != null and deptId != ''">
- and dept_id = #{deptId}
- </if>
- GROUP BY
- dept_id
- ) q ON w.dept_id = q.dept_id
- where w.del_flag='0'
- and w.status='0'
- ORDER BY
- num DESC
- ) t,
- (SELECT @rank := 0) r
- LIMIT 10;
- </select>
- <!--供应商月度增长率-->
- <select id="queryDeptMonthlyGrowthRate" parameterType="java.util.Map" resultType="java.util.HashMap" >
- SELECT
- t1.month,
- t1.rate_amount,
- IFNULL(t2.rate_amount, 0) AS last_month_amount,
- CASE
- WHEN IFNULL(t2.rate_amount, 0) = 0 and IFNULL(t1.rate_amount, 0) = 0 then 0
- WHEN IFNULL(t2.rate_amount, 0) = 0 and IFNULL(t1.rate_amount, 0) !=0 then 100
- ELSE ROUND((t1.rate_amount - t2.rate_amount) / t2.rate_amount * 100 , 2)
- END AS growth_rate
- FROM (
- SELECT
- months.month,
- IFNULL(data.rate_amount, 0) AS rate_amount
- FROM (
- SELECT DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (a) MONTH), '%Y-%m') AS month
- FROM (
- SELECT 0 a UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5
- ) t
- ) months
- LEFT JOIN (
- SELECT
- SUM(IFNULL(a.adjust_amount, a.rate_amount)) rate_amount,
- DATE_FORMAT(d.create_time, '%Y-%m') AS month
- FROM biz_waybill_cost_details a
- LEFT JOIN biz_waybill_order d ON a.external_waybill_no = d.external_waybill_no
- WHERE d.order_status != 6
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startDate != null and startDate != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startDate}
- </if>
- <if test="endDate != null and endDate != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endDate}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- GROUP BY DATE_FORMAT(d.create_time, '%Y-%m')
- ) data ON months.month = data.month
- ) t1
- LEFT JOIN (
- SELECT
- months.month,
- IFNULL(data.rate_amount, 0) AS rate_amount
- FROM (
- SELECT DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (a) MONTH), '%Y-%m') AS month
- FROM (
- SELECT 0 a UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5
- ) t
- ) months
- LEFT JOIN (
- SELECT
- SUM(IFNULL(a.adjust_amount, a.rate_amount)) rate_amount,
- DATE_FORMAT(d.create_time, '%Y-%m') AS month
- FROM biz_waybill_cost_details a
- LEFT JOIN biz_waybill_order d ON a.external_waybill_no = d.external_waybill_no
- WHERE d.order_status != 6
- <if test="orderType != null and orderType != ''">
- and d.order_type = #{orderType}
- </if>
- <if test="startDate != null and startDate != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startDate}
- </if>
- <if test="endDate != null and endDate != ''">
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endDate}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- GROUP BY DATE_FORMAT(d.create_time, '%Y-%m')
- ) data ON months.month = data.month
- ) t2 ON t1.month = DATE_FORMAT(STR_TO_DATE(CONCAT(t2.month, '-01'), '%Y-%m-%d') + INTERVAL 1 MONTH, '%Y-%m')
- ORDER BY t1.month;
- </select>
- </mapper>
|