KwtWaybillOrderMapper.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.sckw.transport.dao.KwtWaybillOrderMapper">
  4. <resultMap id="BaseResultMap" type="com.sckw.transport.model.KwtWaybillOrder">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="ent_id" jdbcType="BIGINT" property="entId"/>
  7. <result column="l_order_id" jdbcType="BIGINT" property="lOrderId"/>
  8. <result column="w_order_no" jdbcType="VARCHAR" property="wOrderNo"/>
  9. <result column="truck_no" jdbcType="VARCHAR" property="truckNo"/>
  10. <result column="type" jdbcType="VARCHAR" property="type"/>
  11. <result column="driver_id" jdbcType="BIGINT" property="driverId"/>
  12. <result column="driver_name" jdbcType="VARCHAR" property="driverName"/>
  13. <result column="driver_phone" jdbcType="VARCHAR" property="driverPhone"/>
  14. <result column="driver_idcard" jdbcType="VARCHAR" property="driverIdcard"/>
  15. <result column="entrust_amount" jdbcType="DECIMAL" property="entrustAmount"/>
  16. <result column="unload_amount" jdbcType="DECIMAL" property="unloadAmount"/>
  17. <result column="load_amount" jdbcType="DECIMAL" property="loadAmount"/>
  18. <result column="deficit_amount" jdbcType="DECIMAL" property="deficitAmount"/>
  19. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  20. <result column="status" jdbcType="INTEGER" property="status"/>
  21. <result column="create_by" jdbcType="BIGINT" property="createBy"/>
  22. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  23. <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
  24. <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
  25. <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
  26. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  27. <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
  28. </resultMap>
  29. <sql id="Base_Column_List">
  30. id
  31. , ent_id, l_order_id, w_order_no, truck_no, driver_id, entrust_amount, unload_amount,
  32. load_amount, deficit_amount, remark, `status`, create_by, create_time, update_by,
  33. update_time, del_flag,start_time,end_time
  34. </sql>
  35. <select id="selectWaybillOrderCarList" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  36. SELECT a.id as wOrderId,
  37. a.w_order_no as wOrderNo,
  38. a.driver_id as driverId,
  39. a.driver_name as driverName,
  40. a.driver_phone as driverPhone,
  41. a.driver_idcard as driverCard,
  42. a.truck_no as truckNo,
  43. a.l_order_id as lOrderId,
  44. b.l_order_no as lOrderNo,
  45. b.t_order_id as tOrderId,
  46. b.t_order_no as tOrderNo
  47. FROM kwt_waybill_order a
  48. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  49. WHERE a.del_flag = '0'
  50. and b.del_flag = '0'
  51. and b.t_order_id = #{id,jdbcType=VARCHAR} limit #{page}
  52. , #{pageSize}
  53. </select>
  54. <select id="selectWaybillOrderCarCount" resultType="java.lang.Long">
  55. SELECT count(a.id)
  56. FROM kwt_waybill_order a
  57. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  58. WHERE a.del_flag = '0'
  59. and b.del_flag = '0'
  60. and b.t_order_id = #{id,jdbcType=VARCHAR}
  61. </select>
  62. <select id="selectDriverOrder" resultType="java.lang.Long">
  63. SELECT a.l_order_id as lOrderId
  64. FROM kwt_waybill_order a
  65. LEFT JOIN kwt_waybill_order_track b ON a.id = b.w_order_id
  66. AND a.del_flag = '0'
  67. AND b.del_flag = '0'
  68. AND a.type='0'
  69. <where>
  70. <if test="id != null and id !=''">
  71. a.driver_id = #{id,jdbcType=BIGINT}
  72. </if>
  73. <if test="status != null and status.size() > 0">
  74. AND a.`status` IN
  75. <foreach collection="status" item="item" open="(" close=")" separator=",">
  76. #{item}
  77. </foreach>
  78. </if>
  79. </where>
  80. group by lOrderId
  81. </select>
  82. <select id="getWaybillData" resultType="com.sckw.transport.model.vo.WaybillDetailVO">
  83. </select>
  84. <select id="selectWaybillRelate" resultType="com.sckw.transport.model.dto.WayBillDetailDTO">
  85. SELECT `order`.`id` AS `wOrderId`,
  86. `order`.`w_order_no` AS `wOrderNo`,
  87. `order`.`truck_no` AS `truckNo`,
  88. `order`.`entrust_amount` AS `entrustAmount`,
  89. `order`.`truck_id` AS `truckId`,
  90. `order`.`driver_id` AS `driverId`,
  91. `order`.`driver_name` AS `driverName`,
  92. `order`.`driver_phone` AS `driverPhone`,
  93. `order`.`driver_idcard` AS `driverIdcard`,
  94. `order`.`type`,
  95. `order`.`start_time` AS `startTime`,
  96. `order`.`end_time` AS `endTime`,
  97. `order`.`create_by` AS `createBy`,
  98. `logistics`.`id` AS `lOrderId`,
  99. `logistics`.`l_order_no` AS `lOrderNo`,
  100. `logistics`.`price_type` AS `priceType`,
  101. `goods`.`goods_name` AS goodsName
  102. FROM `kwt_waybill_order` `order`
  103. LEFT JOIN `kwt_logistics_order` `logistics` ON `logistics`.`id` = `order`.`l_order_id`
  104. LEFT JOIN `kwt_logistics_order_goods` `goods` ON `goods`.`l_order_id` = `order`.`l_order_id`
  105. WHERE `order`.`id` = #{id,jdbcType=BIGINT}
  106. </select>
  107. <select id="statistics" resultType="com.sckw.mongo.model.TableTops">
  108. SELECT count(a.id) AS total
  109. FROM kwt_waybill_order a
  110. LEFT JOIN kwt_waybill_order_track b ON a.id = b.w_order_id
  111. AND a.del_flag = '0'
  112. AND b.del_flag = '0'
  113. <where>
  114. <if test="id != null and id !=''">
  115. a.driver_id = #{id,jdbcType=BIGINT}
  116. </if>
  117. <if test="status != null and status.size() > 0">
  118. AND b.`status` IN
  119. <foreach collection="status" item="item" open="(" close=")" separator=",">
  120. #{item}
  121. </foreach>
  122. </if>
  123. </where>
  124. </select>
  125. <select id="selectDataByLorderId" resultType="int">
  126. SELECT
  127. COUNT(b.id)
  128. FROM
  129. kwt_waybill_order a
  130. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  131. AND a.del_flag = 0
  132. AND b.del_flag = 0
  133. <where>
  134. <if test="id != null and id !=''">
  135. and b.id = #{id}
  136. </if>
  137. <if test="statusList != null and statusList.size() >0">
  138. AND a.`status` IN
  139. <foreach collection="statusList" item="item" open="(" close=")" separator=",">
  140. #{item}
  141. </foreach>
  142. </if>
  143. </where>
  144. </select>
  145. <select id="findWaybillOrderCount" resultType="com.sckw.transport.model.vo.WaybillCountVo"
  146. parameterType="java.util.Map">
  147. SELECT
  148. count(case when wo.status = 8 then 1 end) totalComplete,
  149. count(case when wo.status not in (1, 9, 10, 11) then 1 end) totalTake,
  150. count(case when wo.status in (3, 4, 5, 6) then 1 end) totalExecute,
  151. count(DISTINCT case when lo.status in (0, 1, 2, 3) then lo.id end) totalUnfinished,
  152. IFNULL(SUM(wo.entrust_amount), 0.0) entrustAmount, IFNULL(SUM(wo.load_amount), 0.0) loadAmount,
  153. IFNULL(SUM(wo.unload_amount), 0.0) unloadAmount, IFNULL(SUM(wo.deficit_amount), 0.0) deficitAmount,
  154. MIN(wot1.operate_time) loadTime, MAX(wot2.operate_time) unloadTime
  155. from kwt_waybill_order wo
  156. left join kwt_waybill_order_ticket wot1 on wot1.w_order_id = wo.id and wot1.type = 1 and wo.unit = wot1.unit and wot1.type = 1 and wot1.del_flag = 0
  157. left join kwt_waybill_order_ticket wot2 on wot2.w_order_id = wo.id and wot2.type = 2 and wo.unit = wot2.unit and wot1.type = 2 and wot2.del_flag = 0
  158. left join kwt_logistics_order lo on lo.id = wo.l_order_id
  159. where wo.del_flag = 0 and lo.del_flag = 0
  160. <if test="driverId != null and driverId != ''">
  161. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  162. </if>
  163. <if test="truckId != null and truckId != ''">
  164. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  165. </if>
  166. <if test="passStatus != null and passStatus != ''">
  167. and wo.status = 8
  168. </if>
  169. <if test="loadCountStatus != null and loadCountStatus != ''">
  170. and wo.status in (5, 6, 7, 8, 12, 13)
  171. </if>
  172. <if test="unloadCountStatus != null and unloadCountStatus != ''">
  173. and wo.status in (7, 8, 12, 13)
  174. </if>
  175. <if test="tOrderId != null and tOrderId != ''">
  176. and lo.t_order_id = #{tOrderId, jdbcType=BIGINT}
  177. </if>
  178. <if test="lOrderId != null and lOrderId != ''">
  179. and lo.id = #{lOrderId, jdbcType=BIGINT}
  180. </if>
  181. <if test="logisticsStatus != null and logisticsStatus != ''">
  182. and lo.status = #{logisticsStatus, jdbcType=INTEGER}
  183. </if>
  184. <if test="upperlOrderId != null and upperlOrderId != ''">
  185. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, lo.pids)
  186. </if>
  187. <if test="belowlOrderId != null and belowlOrderId != ''">
  188. and FIND_IN_SET(lo.id, #{belowlOrderId, jdbcType=VARCHAR})
  189. </if>
  190. <if test="ownOrderId != null and ownOrderId != ''">
  191. and lo.id != #{ownOrderId, jdbcType=BIGINT}
  192. </if>
  193. </select>
  194. <select id="findWaybillOrderTicketCount" parameterType="java.util.Map">
  195. SELECT IFNULL(SUM(wot.amount), 0.0) amount from
  196. kwt_waybill_order_ticket wot
  197. left join kwt_waybill_order wo on wot.w_order_id = wo.id
  198. left join kwt_logistics_order lo on lo.id = wo.l_order_id
  199. where wot.del_flag = 0 and wo.del_flag = 0 and lo.del_flag = 0
  200. <if test="driverId != null and driverId != ''">
  201. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  202. </if>
  203. <if test="truckId != null and truckId != ''">
  204. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  205. </if>
  206. <if test="passStatus != null and passStatus != ''">
  207. and wo.status = 8
  208. </if>
  209. <if test="loadCountStatus != null and loadCountStatus != ''">
  210. and wo.status in (5, 6, 7, 8, 12, 13)
  211. </if>
  212. <if test="unloadCountStatus != null and unloadCountStatus != ''">
  213. and wo.status in (7, 8, 12, 13)
  214. </if>
  215. <if test="unit != null and unit != ''">
  216. and wot.unit = #{unit, jdbcType=VARCHAR}
  217. </if>
  218. <if test="type != null and type != ''">
  219. and wot.type = #{type, jdbcType=VARCHAR}
  220. </if>
  221. <if test="tOrderId != null and tOrderId != ''">
  222. and lo.t_order_id = #{tOrderId, jdbcType=BIGINT}
  223. </if>
  224. <if test="lOrderId != null and lOrderId != ''">
  225. and lo.id = #{lOrderId, jdbcType=BIGINT}
  226. </if>
  227. <if test="logisticsStatus != null and logisticsStatus != ''">
  228. and lo.status = #{logisticsStatus, jdbcType=INTEGER}
  229. </if>
  230. <if test="upperlOrderId != null and upperlOrderId != ''">
  231. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, lo.pids)
  232. </if>
  233. <if test="belowlOrderId != null and belowlOrderId != ''">
  234. and FIND_IN_SET(lo.id, #{belowlOrderId, jdbcType=VARCHAR})
  235. </if>
  236. <if test="ownOrderId != null and ownOrderId != ''">
  237. and lo.id != #{ownOrderId, jdbcType=BIGINT}
  238. </if>
  239. </select>
  240. <select id="selectWaybillOrderCarListGroupByTruckNo" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  241. SELECT
  242. a.truck_no AS truckNo,
  243. COUNT( a.truck_no ) AS count,
  244. a.driver_id AS driverId,
  245. a.driver_name AS driverName,
  246. a.driver_phone AS driverPhone,
  247. a.driver_idcard AS driverCard
  248. FROM
  249. `kwt_waybill_order` a
  250. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  251. AND B.del_flag = 0
  252. AND b.del_flag = 0
  253. <where>
  254. <if test="ids != null and ids.size() > 0">
  255. and a.l_order_id in
  256. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  257. #{item}
  258. </foreach>
  259. </if>
  260. <if test="statusList != null and statusList.size() > 0">
  261. and a.status in
  262. <foreach collection="statusList" item="item" open="(" close=")" separator=",">
  263. #{item}
  264. </foreach>
  265. </if>
  266. </where>
  267. GROUP BY
  268. a.truck_no
  269. limit #{page},#{pageSize}
  270. </select>
  271. <select id="findStatisticsCountByDriver" resultType="java.util.Map" parameterType="java.util.Map">
  272. select tabA.total + tabB.total as waitTotal,
  273. tabC.total departureTotal,
  274. tabD.total executeTotal,
  275. tabE.total endTotal
  276. from (SELECT count(1) total,
  277. 0 indexNum
  278. FROM kwt_logistics_order_circulate loc
  279. LEFT JOIN kwt_logistics_order lo on lo.id = loc.l_order_id
  280. where loc.del_flag = 0
  281. and lo.del_flag = 0
  282. and loc.status = 0
  283. and loc.w_order_id is null
  284. and loc.driver_id = #{driverId, jdbcType=BIGINT}
  285. <if test="specialEntIds != null and specialEntIds.size() > 0">
  286. and loc.ent_id in
  287. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  288. #{item,jdbcType=BIGINT}
  289. </foreach>
  290. </if>
  291. ) tabA
  292. left join
  293. (SELECT count(1) total,
  294. 0 indexNum
  295. FROM kwt_waybill_order wo
  296. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  297. where wo.del_flag = 0
  298. and lo.del_flag = 0
  299. and wo.status = 1
  300. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  301. <if test="specialEntIds != null and specialEntIds.size() > 0">
  302. and wo.ent_id in
  303. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  304. #{item,jdbcType=BIGINT}
  305. </foreach>
  306. </if>
  307. ) tabB on tabB.indexNum = tabA.indexNum
  308. left join
  309. (SELECT count(1) total,
  310. 0 indexNum
  311. FROM kwt_waybill_order wo
  312. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  313. where wo.del_flag = 0
  314. and lo.del_flag = 0
  315. and wo.status = 2
  316. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  317. <if test="specialEntIds != null and specialEntIds.size() > 0">
  318. and wo.ent_id in
  319. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  320. #{item,jdbcType=BIGINT}
  321. </foreach>
  322. </if>
  323. ) tabC on tabC.indexNum = tabA.indexNum
  324. left join
  325. (SELECT count(1) total,
  326. 0 indexNum
  327. FROM kwt_waybill_order wo
  328. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  329. where wo.del_flag = 0
  330. and lo.del_flag = 0
  331. and wo.status in (3, 4, 5, 6)
  332. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  333. <if test="specialEntIds != null and specialEntIds.size() > 0">
  334. and wo.ent_id in
  335. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  336. #{item,jdbcType=BIGINT}
  337. </foreach>
  338. </if>
  339. ) tabD on tabD.indexNum = tabA.indexNum
  340. left join
  341. (SELECT count(1) total,
  342. 0 indexNum
  343. FROM kwt_waybill_order wo
  344. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  345. where wo.del_flag = 0
  346. and lo.del_flag = 0
  347. and wo.status in (7, 8, 9, 10, 12, 13)
  348. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  349. <if test="specialEntIds != null and specialEntIds.size() > 0">
  350. and wo.ent_id in
  351. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  352. #{item,jdbcType=BIGINT}
  353. </foreach>
  354. </if>
  355. ) tabE on tabE.indexNum = tabA.indexNum
  356. </select>
  357. <select id="findStatisticsSumByDriver" resultType="java.util.Map" parameterType="java.util.Map">
  358. SELECT
  359. count(1) total, IFNULL(sum(wo.entrust_amount), 0.0) entrustAmount, IFNULL(sum(wo.load_amount), 0.0) loadAmount,
  360. IFNULL(sum(wo.unload_amount), 0.0) unloadAmount, IFNULL(sum(wo.deficit_amount), 0.0) deficitAmount,
  361. IFNULL(sum(wo.deficit_price), 0.0) deficitPrice
  362. FROM kwt_waybill_order wo
  363. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  364. where wo.del_flag = 0 and lo.del_flag = 0
  365. <if test="busStatus != null and busStatus == 4">
  366. and wo.status in (7, 8, 9, 10, 12, 13)
  367. </if>
  368. <if test="driverId != null and driverId != ''">
  369. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  370. </if>
  371. <if test="month != null and month != ''">
  372. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  373. </if>
  374. <if test="startTime != null and startTime != ''">
  375. and DATE(wo.create_time) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  376. </if>
  377. <if test="endTime != null and endTime != ''">
  378. and DATE(wo.create_time) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  379. </if>
  380. <if test="specialEntIds != null and specialEntIds.size() > 0">
  381. and wo.ent_id in
  382. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  383. #{item,jdbcType=BIGINT}
  384. </foreach>
  385. </if>
  386. </select>
  387. <select id="deficitLossAmountByDriver" parameterType="java.util.Map">
  388. SELECT
  389. <!-- FORMAT(IFNULL(sum(deficitLossAmount), 0.0), 2) deficitLossAmount-->
  390. IFNULL(sum(deficitLossAmount), 0.0) deficitLossAmount
  391. from (
  392. SELECT
  393. <!-- ( deficitAmount - FORMAT((loadAmount * loss / lossUnit),2) ) deficitLossAmount-->
  394. ( deficitAmount - (loadAmount * loss / lossUnit) ) deficitLossAmount
  395. from (
  396. SELECT
  397. IFNULL(wo.deficit_amount, 0.0) deficitAmount,
  398. IFNULL(lo.loss, 0.0) loss,
  399. IFNULL(wo.load_amount, 0.0) loadAmount,
  400. case when lo.loss_unit = 0 then 1000 when lo.loss_unit = 0 then 100 ELSE 0 end as lossUnit
  401. from kwt_waybill_order wo
  402. left join kwt_logistics_order lo on lo.id = wo.l_order_id
  403. where wo.del_flag = 0 and lo.del_flag = 0
  404. <if test="busStatus != null and busStatus == 4">
  405. and wo.status in (7, 8, 9, 10, 12, 13)
  406. and wo.deficit_amount > 0
  407. </if>
  408. <if test="driverId != null and driverId != ''">
  409. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  410. </if>
  411. <if test="month != null and month != ''">
  412. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  413. </if>
  414. <if test="startTime != null and startTime != ''">
  415. and DATE(wo.create_time) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  416. </if>
  417. <if test="endTime != null and endTime != ''">
  418. and DATE(wo.create_time) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  419. </if>
  420. <if test="specialEntIds != null and specialEntIds.size() > 0">
  421. and wo.ent_id in
  422. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  423. #{item,jdbcType=BIGINT}
  424. </foreach>
  425. </if>
  426. ) tab
  427. ) tab1
  428. </select>
  429. <select id="findWaitWaybillOrderByDriver" resultType="com.sckw.transport.model.vo.WaybillOrderDriverVo"
  430. parameterType="java.util.Map">
  431. SELECT *
  432. from (SELECT wo.id wOrderId,
  433. wo.w_order_no wOrderNo,
  434. wo.l_order_id lOrderId,
  435. lo.l_order_no lOrderNo,
  436. wo.type,
  437. lo.amount - lo.entrust_amount - lo.subcontract_amount residueAmount,
  438. lo.unit,
  439. lo.loss_unit lossUnit,
  440. wo.ent_id carrierEntId,
  441. 'xxxxx' carrierFirmName,
  442. log.goods_name goodsName,
  443. wo.start_time startTime,
  444. wo.end_time endTime,
  445. wo.entrust_amount entrustAmount,
  446. woa1.name loadName,
  447. woa1.city_code loadCityCode,
  448. woa1.city_name loadCityName,
  449. woa1.detail_address loadDetailAddress,
  450. woa2.name unloadName,
  451. woa2.city_code unloadCityCode,
  452. woa2.city_name unloadCityName,
  453. woa2.detail_address unloadDetailAddress,
  454. IFNULL(wo.load_amount, 0.0) loadAmount,
  455. IFNULL(wo.unload_amount, 0.0) unloadAmount,
  456. IFNULL(wo.deficit_amount, 0.0) deficitAmount,
  457. IFNULL(wo.deficit_price, 0.0) deficitPrice,
  458. wo.truck_no truckNo,
  459. wo.status,
  460. wo.create_time createTime
  461. FROM kwt_waybill_order wo
  462. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  463. LEFT JOIN kwt_waybill_order_address woa1 on woa1.w_order_id = wo.id and woa1.address_type = 1
  464. LEFT JOIN kwt_waybill_order_address woa2 on woa2.w_order_id = wo.id and woa2.address_type = 2
  465. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = wo.l_order_id
  466. where wo.del_flag = 0
  467. and lo.del_flag = 0
  468. and wo.status = 1
  469. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  470. <if test="specialEntIds != null and specialEntIds.size() > 0">
  471. and wo.ent_id in
  472. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  473. #{item,jdbcType=BIGINT}
  474. </foreach>
  475. </if>
  476. UNION
  477. SELECT loc.id wOrderId,
  478. null wOrderNo,
  479. loc.l_order_id lOrderId,
  480. lo.l_order_no lOrderNo,
  481. loc.type,
  482. lo.amount - lo.entrust_amount - lo.subcontract_amount residueAmount,
  483. lo.unit,
  484. lo.loss_unit lossUnit,
  485. loc.ent_id carrierEntId,
  486. 'xxxxx' carrierFirmName,
  487. log.goods_name goodsName,
  488. loc.start_time startTime,
  489. loc.end_time endTime,
  490. loc.entrust_amount entrustAmount,
  491. loa1.name loadName,
  492. loa1.city_code loadCityCode,
  493. loa1.city_name loadCityName,
  494. loa1.detail_address loadDetailAddress,
  495. loa2.name unloadName,
  496. loa2.city_code unloadCityCode,
  497. loa2.city_name unloadCityName,
  498. loa2.detail_address unloadDetailAddress,
  499. 0.0 loadAmount,
  500. 0.0 unloadAmount,
  501. 0.0 deficitAmount,
  502. 0.0 deficitPrice,
  503. loc.truck_no truckNo,
  504. 1 status,
  505. loc.update_time createTime
  506. FROM kwt_logistics_order_circulate loc
  507. LEFT JOIN kwt_logistics_order lo on lo.id = loc.l_order_id
  508. LEFT JOIN kwt_logistics_order_address loa1 on loa1.l_order_id = lo.id and loa1.address_type = 1
  509. LEFT JOIN kwt_logistics_order_address loa2 on loa2.l_order_id = lo.id and loa2.address_type = 2
  510. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = loc.l_order_id
  511. where loc.del_flag = 0
  512. and lo.del_flag = 0
  513. and loc.status = 0
  514. and loc.w_order_id is null
  515. and loc.driver_id = #{driverId, jdbcType=BIGINT}
  516. <if test="specialEntIds != null and specialEntIds.size() > 0">
  517. and loc.ent_id in
  518. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  519. #{item,jdbcType=BIGINT}
  520. </foreach>
  521. </if>
  522. ) tab
  523. order by startTime
  524. </select>
  525. <select id="findOtherWaybillOrderByDriver" resultType="com.sckw.transport.model.vo.WaybillOrderDriverVo"
  526. parameterType="java.util.Map">
  527. SELECT
  528. wo.id wOrderId, wo.w_order_no wOrderNo, wo.l_order_id lOrderId, lo.l_order_no lOrderNo,
  529. lo.unit, lo.loss, lo.loss_unit lossUnit, wo.type,
  530. wo.ent_id carrierEntId, 'xxxxx' carrierFirmName, log.goods_name goodsName, wo.start_time startTime,
  531. wo.end_time endTime, wo.entrust_amount entrustAmount, woa1.name loadName, woa1.city_code loadCityCode,
  532. woa1.city_name loadCityName, woa1.detail_address loadDetailAddress, woa2.name unloadName, woa2.city_code
  533. unloadCityCode, woa2.city_name unloadCityName, woa2.detail_address unloadDetailAddress, IFNULL(wo.load_amount, 0.0) loadAmount,
  534. IFNULL(wo.unload_amount, 0.0) unloadAmount, IFNULL(wo.deficit_amount, 0.0) deficitAmount, IFNULL(wo.deficit_price, 0.0) deficitPrice,
  535. wo.truck_no truckNo, wo.status, wo.create_time createTime
  536. FROM kwt_waybill_order wo
  537. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  538. LEFT JOIN kwt_waybill_order_address woa1 on woa1.w_order_id = wo.id and woa1.address_type = 1
  539. LEFT JOIN kwt_waybill_order_address woa2 on woa2.w_order_id = wo.id and woa2.address_type = 2
  540. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = wo.l_order_id
  541. where wo.del_flag = 0 and lo.del_flag = 0
  542. <if test="specialEntIds != null and specialEntIds.size() > 0">
  543. and wo.ent_id in
  544. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  545. #{item,jdbcType=BIGINT}
  546. </foreach>
  547. </if>
  548. <if test="driverId != null and driverId != ''">
  549. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  550. </if>
  551. <if test="busStatus != null and busStatus == 2">
  552. and wo.status = 2
  553. </if>
  554. <if test="busStatus != null and busStatus == 3">
  555. and wo.status in (3, 4, 5, 6)
  556. </if>
  557. <if test="busStatus != null and busStatus == 4">
  558. and wo.status in (7, 8, 9, 10, 12, 13)
  559. </if>
  560. <if test="month != null and month != ''">
  561. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  562. </if>
  563. <if test="startTime != null and startTime != ''">
  564. and DATE(wo.create_time) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  565. </if>
  566. <if test="endTime != null and endTime != ''">
  567. and DATE(wo.create_time) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  568. </if>
  569. <if test="busStatus != null and busStatus == 2">
  570. ORDER BY wo.start_time
  571. </if>
  572. <if test="busStatus != null and busStatus == 4">
  573. ORDER BY CASE WHEN wo.status = 12 THEN wo.status * -1 ELSE wo.status END ASC,
  574. wo.update_time desc
  575. </if>
  576. </select>
  577. <select id="selectWaybillOrderCarListNotPage" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  578. SELECT a.id as wOrderId,
  579. a.w_order_no as wOrderNo,
  580. a.driver_id as driverId,
  581. a.driver_name as driverName,
  582. a.driver_phone as driverPhone,
  583. a.driver_idcard as driverCard,
  584. a.truck_no as truckNo,
  585. a.status as status,
  586. a.l_order_id as lOrderId,
  587. b.l_order_no as lOrderNo,
  588. b.t_order_id as tOrderId,
  589. b.t_order_no as tOrderNo
  590. FROM kwt_waybill_order a
  591. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  592. WHERE a.del_flag = '0'
  593. and b.del_flag = '0'
  594. and b.t_order_id = #{id,jdbcType=VARCHAR}
  595. </select>
  596. <select id="selectWaybillOrderCarListByTradeOrderId" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  597. SELECT a.id as wOrderId,
  598. a.w_order_no as wOrderNo,
  599. a.driver_id as driverId,
  600. a.driver_name as driverName,
  601. a.driver_phone as driverPhone,
  602. a.driver_idcard as driverCard,
  603. a.truck_no as truckNo,
  604. a.status as status,
  605. a.l_order_id as lOrderId,
  606. b.l_order_no as lOrderNo,
  607. b.t_order_id as tOrderId,
  608. b.t_order_no as tOrderNo
  609. FROM kwt_waybill_order a
  610. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  611. WHERE a.del_flag = 0
  612. and b.del_flag = 0
  613. <if test="ids != null and ids.size() > 0">
  614. and b.t_order_id in
  615. <foreach collection="ids" item="item" close=")" open="(" separator=",">
  616. #{item,jdbcType=BIGINT}
  617. </foreach>
  618. </if>
  619. </select>
  620. <select id="selectWaybillOrderCountByStatus" resultType="java.lang.Long">
  621. SELECT COUNT(id)
  622. FROM kwt_waybill_order
  623. WHERE ent_id = #{entId}
  624. AND del_flag = 0
  625. <if test="createBys != null and createBys.size() > 0">
  626. AND create_by IN
  627. <foreach collection="createBys" item="item" open="(" close=")" separator=",">
  628. #{item}
  629. </foreach>
  630. </if>
  631. <if test="statuses != null and statuses.size() > 0">
  632. AND status IN
  633. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  634. #{item}
  635. </foreach>
  636. </if>
  637. <if test="keyword != null and keyword != ''">
  638. AND (
  639. w_order_no LIKE concat('%',#{keyword},'%')
  640. OR truck_no LIKE concat('%',#{keyword},'%')
  641. OR driver_name LIKE concat('%',#{keyword},'%')
  642. OR driver_phone LIKE concat('%',#{keyword},'%')
  643. )
  644. </if>
  645. </select>
  646. <select id="selectOrderByOrderId" resultType="java.util.Map">
  647. SELECT COUNT(id) total,IFNULL(SUM(entrust_amount),0) AS amount
  648. FROM
  649. kwt_waybill_order
  650. WHERE
  651. l_order_id = #{orderId}
  652. AND type = #{type} and del_flag = 0
  653. <if test="statusList != null and statusList.size() > 0">
  654. and status not in
  655. <foreach collection="statusList" open="(" close=")" separator="," item="item">
  656. #{item}
  657. </foreach>
  658. </if>
  659. </select>
  660. <select id="selectWaybillOrderAmountByStatus" resultType="java.util.Map">
  661. SELECT
  662. COUNT(id) total,
  663. SUM(load_amount) loadAmount,
  664. SUM(unload_amount) unloadAmount,
  665. SUM(load_amount - unload_amount) lossAmount,
  666. SUM( IF(load_amount - unload_amount - deficit_amount > 0, load_amount - unload_amount - deficit_amount , 0) ) deficitRealAmount
  667. FROM
  668. kwt_waybill_order
  669. WHERE ent_id = #{entId}
  670. AND del_flag = 0
  671. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  672. AND create_time BETWEEN #{startDate} AND #{endDate}
  673. </if>
  674. <if test="keyword != null and keyword != ''">
  675. AND (
  676. w_order_no LIKE concat('%',#{keyword},'%')
  677. OR truck_no LIKE concat('%',#{keyword},'%')
  678. OR driver_name LIKE concat('%',#{keyword},'%')
  679. OR driver_phone LIKE concat('%',#{keyword},'%')
  680. )
  681. </if>
  682. <if test="statuses != null and statuses.size() > 0">
  683. AND status IN
  684. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  685. #{item}
  686. </foreach>
  687. </if>
  688. </select>
  689. <select id="selectWaybillOrdersByStatus" resultType="com.sckw.transport.model.dto.WaybillAmountDTO">
  690. SELECT
  691. wo.load_amount as loadAmount,
  692. wo.unload_amount as unloadAmount,
  693. wo.deficit_amount as DeficitAmount,
  694. lo.loss as loss,
  695. lo.loss_unit as lossUnit
  696. FROM
  697. kwt_waybill_order AS wo
  698. LEFT JOIN kwt_logistics_order AS lo
  699. ON lo.id = wo.l_order_id
  700. WHERE wo.ent_id = #{entId}
  701. AND wo.del_flag = 0
  702. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  703. AND wo.create_time BETWEEN #{startDate} AND #{endDate}
  704. </if>
  705. <if test="createBys != null and createBys.size() > 0">
  706. AND wo.create_by IN
  707. <foreach collection="createBys" item="item" open="(" close=")" separator=",">
  708. #{item}
  709. </foreach>
  710. </if>
  711. <if test="statuses != null and statuses.size() > 0">
  712. AND wo.status IN
  713. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  714. #{item}
  715. </foreach>
  716. </if>
  717. <if test="keyword != null and keyword != ''">
  718. AND (
  719. wo.w_order_no LIKE concat('%',#{keyword},'%')
  720. OR wo.truck_no LIKE concat('%',#{keyword},'%')
  721. OR wo.driver_name LIKE concat('%',#{keyword},'%')
  722. OR wo.driver_phone LIKE concat('%',#{keyword},'%')
  723. )
  724. </if>
  725. </select>
  726. <select id="getMaxOrderNo" resultType="java.lang.String">
  727. SELECT w_order_no FROM `kwt_waybill_order` WHERE w_order_no LIKE concat(#{lOrderNo},'%') ORDER BY w_order_no DESC LIMIT 1
  728. </select>
  729. <select id="findWaybillOrder" resultType="com.sckw.transport.model.KwtWaybillOrder" parameterType="java.util.Map">
  730. SELECT
  731. kwo.id worderId, kwo.w_order_no worderNo, kwo.l_order_id lOrderId, kwo.type, kwo.ent_id carrierEntId, kwo.start_time startTime,
  732. kwo.end_time endTime, kwo.entrust_amount entrustAmount, kwo.load_amount loadAmount, kwo.unload_amount unloadAmount,
  733. kwo.deficit_amount deficitAmount, kwo.deficit_price deficitPrice, kwo.truck_id truckId, kwo.truck_no truckNo, kwo.status,
  734. kwo.create_time createTime, kwo.driver_id driverId, kwo.driver_name driverName, kwo.driver_phone driverPhone, kwo.ent_id entId
  735. FROM kwt_waybill_order kwo
  736. where kwo.del_flag = 0
  737. <if test="tOrderId != null and tOrderId != ''">
  738. and kwo.t_order_id = #{tOrderId, jdbcType=BIGINT}
  739. </if>
  740. <if test="lOrderId != null and lOrderId != ''">
  741. and kwo.l_order_id = #{lOrderId, jdbcType=BIGINT}
  742. </if>
  743. <if test="driverId != null and driverId != ''">
  744. and kwo.driver_id = #{driverId, jdbcType=BIGINT}
  745. </if>
  746. <if test="truckNo != null and truckNo != ''">
  747. and kwo.truck_no = #{truckNo, jdbcType=VARCHAR}
  748. </if>
  749. <if test="status != null and status != ''">
  750. and kwo.status = #{status, jdbcType=INTEGER}
  751. </if>
  752. <if test="busStatus != null and busStatus == 2">
  753. and kwo.status = 2
  754. </if>
  755. <if test="busStatus != null and busStatus == 3">
  756. and kwo.status in (3, 4, 5, 6)
  757. </if>
  758. <if test="busStatus != null and busStatus == 4">
  759. and kwo.status in (7, 8, 9, 10, 12, 13)
  760. </if>
  761. <choose>
  762. <when test="lOrderIds != null and lOrderIds != '' and lOrderIds.size() > 0">
  763. and kwo.l_order_id in
  764. <foreach collection="lOrderIds" item="lOrderId" open="(" close=")" separator=",">
  765. #{lOrderId,jdbcType=BIGINT}
  766. </foreach>
  767. </when>
  768. </choose>
  769. </select>
  770. <select id="selectInvalidWaybillOrderCarListGroupByTruckNo" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  771. SELECT
  772. a.truck_no AS truckNo,
  773. COUNT( a.truck_no ) AS count,
  774. a.driver_id AS driverId,
  775. a.driver_name AS driverName,
  776. a.driver_phone AS driverPhone,
  777. a.driver_idcard AS driverCard
  778. FROM
  779. `kwt_waybill_order` a
  780. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  781. AND B.del_flag = 0
  782. AND b.del_flag = 0
  783. <where>
  784. <if test="ids != null and ids.size() > 0">
  785. and a.l_order_id in
  786. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  787. #{item}
  788. </foreach>
  789. </if>
  790. <if test="statusList != null and statusList.size() > 0">
  791. and a.status not in
  792. <foreach collection="statusList" item="item" open="(" close=")" separator=",">
  793. #{item}
  794. </foreach>
  795. </if>
  796. </where>
  797. GROUP BY
  798. a.truck_no
  799. limit #{page},#{pageSize}
  800. </select>
  801. </mapper>