LargeScreenReportMapper.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.logistics.mapper.LargeScreenReportMapper">
  6. <!-- 按照订单类型查询订单量-->
  7. <select id="queryOrderTypeReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
  8. SELECT dict_label orderTypeName ,dict_value orderType,ifnull(num,0) num FROM (
  9. SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'logistics_type') a
  10. left join (
  11. SELECT
  12. order_type,
  13. count(1) num
  14. FROM
  15. biz_waybill_order d
  16. WHERE order_status != 6
  17. <if test="orderType != null and orderType != ''">
  18. and d.order_type = #{orderType}
  19. </if>
  20. <if test="startTime != null and startTime != ''">
  21. and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  22. </if>
  23. <if test="endTime != null and endTime != ''">
  24. and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  25. </if>
  26. <if test="deptId != null and deptId != ''">
  27. and d.dept_id = #{deptId}
  28. </if>
  29. <!-- 数据范围过滤 -->
  30. ${params.dataScope}
  31. GROUP BY
  32. order_type) b ON a.dict_value = b.order_type
  33. </select>
  34. <!-- 每日订单量-->
  35. <select id="queryDayOrdersReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
  36. SELECT
  37. date_list.day_time AS time,
  38. IFNULL(t.order_num, 0) AS order_num,
  39. IFNULL(t.delivery_num, 0) AS delivery_num,
  40. IFNULL(t.proper_num, 0) AS proper_num
  41. FROM
  42. (
  43. SELECT
  44. DATE_FORMAT(
  45. DATE_ADD(#{startTime}, INTERVAL (a + 10*b + 100*c) DAY),
  46. '%Y-%m-%d'
  47. ) AS day_time
  48. FROM
  49. (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,
  50. (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,
  51. (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
  52. HAVING
  53. day_time<![CDATA[<=]]>#{endTime}
  54. ) date_list
  55. LEFT JOIN (
  56. SELECT
  57. DATE_FORMAT(create_time, '%Y-%m-%d') AS time,
  58. SUM(order_status != 6) AS order_num,
  59. SUM(order_status != 6 AND order_status != 5) AS delivery_num,
  60. SUM(order_status = 5) AS proper_num
  61. FROM biz_waybill_order d
  62. WHERE DATE_FORMAT(d.create_time, '%Y-%m-%d') >=#{startTime} AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
  63. <if test="orderType != null and orderType != ''">
  64. and d.order_type = #{orderType}
  65. </if>
  66. <if test="deptId != null and deptId != ''">
  67. and d.dept_id = #{deptId}
  68. </if>
  69. <!-- 数据范围过滤 -->
  70. ${params.dataScope}
  71. GROUP BY DATE_FORMAT(d.create_time, '%Y-%m-%d')
  72. ) t ON date_list.day_time = t.time
  73. ORDER BY date_list.day_time;
  74. </select>
  75. <!-- 按照省份查询订单量和金额(整合版)-->
  76. <select id="queryProvinceOrdersReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
  77. SELECT
  78. province_name,
  79. merger_name,
  80. IFNULL(outflow_num, 0) AS outflowNum,
  81. IFNULL(inflow_num, 0) AS inflowNum,
  82. IFNULL(outflow_amount, 0) AS outflowAmount,
  83. IFNULL(inflow_amount, 0) AS inflowAmount
  84. FROM (
  85. SELECT
  86. a.NAME AS province_name,
  87. a.merger_name,
  88. -- 流出订单数(该省作为发货地)
  89. IFNULL(outflow_order.num, 0) AS outflow_num,
  90. -- 流入订单数(该省作为收货地)
  91. IFNULL(inflow_order.num, 0) AS inflow_num,
  92. -- 流出金额(该省作为发货地)
  93. IFNULL(outflow_cost.amt, 0) AS outflow_amount,
  94. -- 流入金额(该省作为收货地)
  95. IFNULL(inflow_cost.amt, 0) AS inflow_amount
  96. FROM
  97. (SELECT NAME, merger_name FROM sys_city WHERE `level` = 0) a
  98. LEFT JOIN (
  99. -- 流出订单统计
  100. SELECT
  101. sender_province,
  102. COUNT(1) AS num
  103. FROM biz_waybill_order d
  104. WHERE d.order_status != 6
  105. <if test="orderType != null and orderType != ''">
  106. AND d.order_type = #{orderType}
  107. </if>
  108. <if test="startTime != null and startTime != ''">
  109. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  110. </if>
  111. <if test="endTime != null and endTime != ''">
  112. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
  113. </if>
  114. <if test="deptId != null and deptId != ''">
  115. AND d.dept_id = #{deptId}
  116. </if>
  117. ${params.dataScope}
  118. GROUP BY sender_province
  119. ) outflow_order ON a.NAME = outflow_order.sender_province
  120. LEFT JOIN (
  121. -- 流入订单统计
  122. SELECT
  123. receiver_province,
  124. COUNT(1) AS num
  125. FROM biz_waybill_order d
  126. WHERE d.order_status != 6
  127. <if test="orderType != null and orderType != ''">
  128. AND d.order_type = #{orderType}
  129. </if>
  130. <if test="startTime != null and startTime != ''">
  131. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  132. </if>
  133. <if test="endTime != null and endTime != ''">
  134. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
  135. </if>
  136. <if test="deptId != null and deptId != ''">
  137. AND d.dept_id = #{deptId}
  138. </if>
  139. ${params.dataScope}
  140. GROUP BY receiver_province
  141. ) inflow_order ON a.NAME = inflow_order.receiver_province
  142. LEFT JOIN (
  143. -- 流出金额统计
  144. SELECT
  145. d.sender_province,
  146. IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0) AS amt
  147. FROM biz_waybill_order d
  148. LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
  149. WHERE d.order_status != 6
  150. <if test="orderType != null and orderType != ''">
  151. AND d.order_type = #{orderType}
  152. </if>
  153. <if test="startTime != null and startTime != ''">
  154. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  155. </if>
  156. <if test="endTime != null and endTime != ''">
  157. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
  158. </if>
  159. <if test="deptId != null and deptId != ''">
  160. AND d.dept_id = #{deptId}
  161. </if>
  162. ${params.dataScope}
  163. GROUP BY d.sender_province
  164. ) outflow_cost ON a.NAME = outflow_cost.sender_province
  165. LEFT JOIN (
  166. -- 流入金额统计
  167. SELECT
  168. d.receiver_province,
  169. IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0) AS amt
  170. FROM biz_waybill_order d
  171. LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
  172. WHERE d.order_status != 6
  173. <if test="orderType != null and orderType != ''">
  174. AND d.order_type = #{orderType}
  175. </if>
  176. <if test="startTime != null and startTime != ''">
  177. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  178. </if>
  179. <if test="endTime != null and endTime != ''">
  180. AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
  181. </if>
  182. <if test="deptId != null and deptId != ''">
  183. AND d.dept_id = #{deptId}
  184. </if>
  185. ${params.dataScope}
  186. GROUP BY d.receiver_province
  187. ) inflow_cost ON a.NAME = inflow_cost.receiver_province
  188. ) t
  189. <if test="rankType != null and rankType != '' and rankType == 1">
  190. ORDER BY outflow_amount DESC
  191. </if>
  192. <if test="rankType != null and rankType != '' and rankType == 2">
  193. ORDER BY outflow_num DESC
  194. </if>
  195. </select>
  196. <!-- 供应商列表-->
  197. <select id="queryDeptList" parameterType="java.util.Map" resultType="java.util.HashMap" >
  198. select d.dept_id deptId,d.dept_name deptName
  199. from sys_dept d
  200. where d.status=0 and d.del_flag=0
  201. <!-- 数据范围过滤 -->
  202. ${params.dataScope}
  203. </select>
  204. <!-- 省份列表-->
  205. <select id="queryProvinceList" parameterType="java.util.Map" resultType="java.util.HashMap" >
  206. SELECT
  207. a.name AS provinceName,
  208. a.lng,
  209. a.lat,
  210. IFNULL(SUM(CASE WHEN a.name = d.sender_province THEN 1 ELSE 0 END), 0) AS sendCount,
  211. IFNULL(SUM(CASE WHEN a.name = d.receiver_province THEN 1 ELSE 0 END), 0) AS recvCount
  212. FROM sys_city a
  213. LEFT JOIN biz_waybill_order d
  214. ON (a.name = d.sender_province OR a.name = d.receiver_province)
  215. <if test="orderType != null and orderType != ''">
  216. and d.order_type = #{orderType}
  217. </if>
  218. <if test="startTime != null and startTime != ''">
  219. and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  220. </if>
  221. <if test="endTime != null and endTime != ''">
  222. and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  223. </if>
  224. <if test="deptId != null and deptId != ''">
  225. and d.dept_id = #{deptId}
  226. </if>
  227. <!-- 数据范围过滤 -->
  228. ${params.dataScope}
  229. WHERE a.level = 0
  230. GROUP BY a.name, a.lng, a.lat
  231. ORDER BY sendCount DESC, recvCount DESC;
  232. </select>
  233. <!-- 物流轨迹省份查询流出-->
  234. <select id="queryLogisticsTrajectoryOutflow" parameterType="java.util.Map" resultType="java.util.HashMap" >
  235. SELECT
  236. d.receiver_province provinceName,
  237. b.lng,
  238. b.lat,
  239. count(1) num,
  240. IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0.00) amt
  241. FROM
  242. biz_waybill_order d
  243. LEFT JOIN sys_city b ON d.receiver_province = b.NAME
  244. LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
  245. WHERE
  246. b.LEVEL = 0
  247. and d.order_status != 6
  248. <if test="orderType != null and orderType != ''">
  249. and d.order_type = #{orderType}
  250. </if>
  251. <if test="startTime != null and startTime != ''">
  252. and DATE_FORMAT( d.create_time, '%Y-%m-%d') >= #{startTime}
  253. </if>
  254. <if test="endTime != null and endTime != ''">
  255. and DATE_FORMAT( d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  256. </if>
  257. <if test="deptId != null and deptId != ''">
  258. and d.dept_id = #{deptId}
  259. </if>
  260. <if test="searchProvince != null and searchProvince != ''">
  261. and d.sender_province = #{searchProvince}
  262. </if>
  263. ${params.dataScope}
  264. group by d.receiver_province
  265. </select>
  266. <!-- 物流轨迹省份查询流入-->
  267. <select id="queryLogisticsTrajectoryinflow" parameterType="java.util.Map" resultType="java.util.HashMap" >
  268. SELECT
  269. d.sender_province provinceName,
  270. b.lng,
  271. b.lat,
  272. count(1) num,
  273. IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0.00) amt
  274. FROM
  275. biz_waybill_order d
  276. LEFT JOIN sys_city b ON d.sender_province = b.NAME
  277. LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
  278. WHERE
  279. b.LEVEL = 0
  280. and d.order_status != 6
  281. <if test="orderType != null and orderType != ''">
  282. and d.order_type = #{orderType}
  283. </if>
  284. <if test="startTime != null and startTime != ''">
  285. and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  286. </if>
  287. <if test="endTime != null and endTime != ''">
  288. and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  289. </if>
  290. <if test="deptId != null and deptId != ''">
  291. and d.dept_id = #{deptId}
  292. </if>
  293. <if test="searchProvince != null and searchProvince != ''">
  294. and d.receiver_province = #{searchProvince}
  295. </if>
  296. ${params.dataScope}
  297. group by d.sender_province
  298. </select>
  299. <!-- 按照快递快运区分统计-->
  300. <select id="queryTransportTypeReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
  301. SELECT
  302. c.dict_label typeName,
  303. ifnull( d.num, 0 ) num
  304. FROM
  305. ( SELECT DISTINCT dict_label FROM sys_dict_data WHERE dict_type = 'rjsd_logistics_product' ) c
  306. LEFT JOIN (
  307. SELECT
  308. dict_label typeName,
  309. count( 1 ) num
  310. FROM
  311. biz_waybill_order d
  312. 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
  313. WHERE
  314. d.order_status != 6
  315. <if test="orderType != null and orderType != ''">
  316. and d.order_type = #{orderType}
  317. </if>
  318. <if test="startTime != null and startTime != ''">
  319. and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  320. </if>
  321. <if test="endTime != null and endTime != ''">
  322. and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  323. </if>
  324. <if test="deptId != null and deptId != ''">
  325. and d.dept_id = #{deptId}
  326. </if>
  327. <!-- 数据范围过滤 -->
  328. ${params.dataScope}
  329. GROUP BY
  330. dict_label
  331. ) d ON c.dict_label = d.typeName
  332. </select>
  333. <!-- 物流费用统计-->
  334. <select id="queryFreeOrdersReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
  335. SELECT
  336. w.dict_label typeName,
  337. ifnull( q.rate_amount, 0.00 ) rateAmount
  338. FROM
  339. ( SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'logistics_type' ) w
  340. LEFT JOIN (
  341. SELECT
  342. sum(
  343. ifnull( a.adjust_amount, a.rate_amount )) rate_amount,
  344. order_type
  345. FROM
  346. biz_waybill_cost_details a
  347. LEFT JOIN biz_waybill_order d ON a.external_waybill_no = d.external_waybill_no
  348. WHERE
  349. d.order_status != 6
  350. <if test="orderType != null and orderType != ''">
  351. and d.order_type = #{orderType}
  352. </if>
  353. <if test="startTime != null and startTime != ''">
  354. and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
  355. </if>
  356. <if test="endTime != null and endTime != ''">
  357. and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  358. </if>
  359. <if test="deptId != null and deptId != ''">
  360. and d.dept_id = #{deptId}
  361. </if>
  362. <!-- 数据范围过滤 -->
  363. ${params.dataScope}
  364. GROUP BY
  365. order_type
  366. ) q ON w.dict_value = q.order_type
  367. </select>
  368. <!--供应商按照金额排名-->
  369. <select id="queryOrdersReportByFree" parameterType="java.util.Map" resultType="java.util.HashMap" >
  370. SELECT
  371. t.dept_name deptName,
  372. t.rate_amount rateAmount,
  373. (@rank := @rank + 1) AS rankNum
  374. FROM (
  375. SELECT
  376. dept_name,
  377. IFNULL(rate_amount, 0) AS rate_amount
  378. FROM
  379. sys_dept w
  380. LEFT JOIN (
  381. SELECT
  382. SUM(IFNULL(a.adjust_amount, a.rate_amount)) AS rate_amount,
  383. a.dept_id
  384. FROM
  385. biz_waybill_cost_details a
  386. LEFT JOIN biz_waybill_order b
  387. ON a.external_waybill_no = b.external_waybill_no
  388. WHERE
  389. b.order_status != 6
  390. <if test="orderType != null and orderType != ''">
  391. and b.order_type = #{orderType}
  392. </if>
  393. <if test="startTime != null and startTime != ''">
  394. and DATE_FORMAT(b.create_time, '%Y-%m-%d') >= #{startTime}
  395. </if>
  396. <if test="endTime != null and endTime != ''">
  397. and DATE_FORMAT(b.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  398. </if>
  399. <if test="deptId != null and deptId != ''">
  400. and a.dept_id = #{deptId}
  401. </if>
  402. GROUP BY
  403. a.dept_id
  404. ) q ON w.dept_id = q.dept_id
  405. where w.del_flag='0'
  406. and w.status='0'
  407. ORDER BY
  408. rate_amount DESC
  409. ) t,
  410. (SELECT @rank := 0) r
  411. LIMIT 10;
  412. </select>
  413. <!--供应商按照订单量排名-->
  414. <select id="queryOrdersReportByNum" parameterType="java.util.Map" resultType="java.util.HashMap" >
  415. SELECT
  416. t.dept_name deptName,
  417. t.num,
  418. (@rank := @rank + 1) AS rankNum
  419. FROM (
  420. SELECT
  421. dept_name,
  422. IFNULL(num, 0) AS num
  423. FROM
  424. sys_dept w
  425. LEFT JOIN (
  426. SELECT
  427. COUNT(external_waybill_no) AS num,
  428. dept_id
  429. FROM
  430. biz_waybill_order
  431. WHERE
  432. order_status != 6
  433. <if test="orderType != null and orderType != ''">
  434. and order_type = #{orderType}
  435. </if>
  436. <if test="startTime != null and startTime != ''">
  437. and DATE_FORMAT(create_time, '%Y-%m-%d') >= #{startTime}
  438. </if>
  439. <if test="endTime != null and endTime != ''">
  440. and DATE_FORMAT(create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
  441. </if>
  442. <if test="deptId != null and deptId != ''">
  443. and dept_id = #{deptId}
  444. </if>
  445. GROUP BY
  446. dept_id
  447. ) q ON w.dept_id = q.dept_id
  448. where w.del_flag='0'
  449. and w.status='0'
  450. ORDER BY
  451. num DESC
  452. ) t,
  453. (SELECT @rank := 0) r
  454. LIMIT 10;
  455. </select>
  456. <!--供应商月度增长率-->
  457. <select id="queryDeptMonthlyGrowthRate" parameterType="java.util.Map" resultType="java.util.HashMap" >
  458. SELECT
  459. t1.month,
  460. t1.rate_amount,
  461. IFNULL(t2.rate_amount, 0) AS last_month_amount,
  462. CASE
  463. WHEN IFNULL(t2.rate_amount, 0) = 0 and IFNULL(t1.rate_amount, 0) = 0 then 0
  464. WHEN IFNULL(t2.rate_amount, 0) = 0 and IFNULL(t1.rate_amount, 0) !=0 then 100
  465. ELSE ROUND((t1.rate_amount - t2.rate_amount) / t2.rate_amount * 100 , 2)
  466. END AS growth_rate
  467. FROM (
  468. SELECT
  469. months.month,
  470. IFNULL(data.rate_amount, 0) AS rate_amount
  471. FROM (
  472. SELECT DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (a) MONTH), '%Y-%m') AS month
  473. FROM (
  474. SELECT 0 a UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5
  475. ) t
  476. ) months
  477. LEFT JOIN (
  478. SELECT
  479. SUM(IFNULL(a.adjust_amount, a.rate_amount)) rate_amount,
  480. DATE_FORMAT(d.create_time, '%Y-%m') AS month
  481. FROM biz_waybill_cost_details a
  482. LEFT JOIN biz_waybill_order d ON a.external_waybill_no = d.external_waybill_no
  483. WHERE d.order_status != 6
  484. <if test="orderType != null and orderType != ''">
  485. and d.order_type = #{orderType}
  486. </if>
  487. <if test="startDate != null and startDate != ''">
  488. and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startDate}
  489. </if>
  490. <if test="endDate != null and endDate != ''">
  491. and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endDate}
  492. </if>
  493. <if test="deptId != null and deptId != ''">
  494. AND d.dept_id = #{deptId}
  495. </if>
  496. <!-- 数据范围过滤 -->
  497. ${params.dataScope}
  498. GROUP BY DATE_FORMAT(d.create_time, '%Y-%m')
  499. ) data ON months.month = data.month
  500. ) t1
  501. LEFT JOIN (
  502. SELECT
  503. months.month,
  504. IFNULL(data.rate_amount, 0) AS rate_amount
  505. FROM (
  506. SELECT DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (a) MONTH), '%Y-%m') AS month
  507. FROM (
  508. SELECT 0 a UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5
  509. ) t
  510. ) months
  511. LEFT JOIN (
  512. SELECT
  513. SUM(IFNULL(a.adjust_amount, a.rate_amount)) rate_amount,
  514. DATE_FORMAT(d.create_time, '%Y-%m') AS month
  515. FROM biz_waybill_cost_details a
  516. LEFT JOIN biz_waybill_order d ON a.external_waybill_no = d.external_waybill_no
  517. WHERE d.order_status != 6
  518. <if test="orderType != null and orderType != ''">
  519. and d.order_type = #{orderType}
  520. </if>
  521. <if test="startDate != null and startDate != ''">
  522. and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startDate}
  523. </if>
  524. <if test="endDate != null and endDate != ''">
  525. and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endDate}
  526. </if>
  527. <if test="deptId != null and deptId != ''">
  528. AND d.dept_id = #{deptId}
  529. </if>
  530. <!-- 数据范围过滤 -->
  531. ${params.dataScope}
  532. GROUP BY DATE_FORMAT(d.create_time, '%Y-%m')
  533. ) data ON months.month = data.month
  534. ) t2 ON t1.month = DATE_FORMAT(STR_TO_DATE(CONCAT(t2.month, '-01'), '%Y-%m-%d') + INTERVAL 1 MONTH, '%Y-%m')
  535. ORDER BY t1.month;
  536. </select>
  537. </mapper>