KwtWaybillOrderMapper.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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 not 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 wot1.del_flag = 0
  157. left join kwt_waybill_order_ticket wot2 on wot2.w_order_id = wo.id and wot2.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="tOrderId != null and tOrderId != ''">
  161. and lo.t_order_id = #{tOrderId, jdbcType=BIGINT}
  162. </if>
  163. <if test="lOrderId != null and lOrderId != ''">
  164. and lo.id = #{lOrderId, jdbcType=BIGINT}
  165. </if>
  166. <if test="driverId != null and driverId != ''">
  167. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  168. </if>
  169. <if test="truckId != null and truckId != ''">
  170. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  171. </if>
  172. <if test="logisticsStatus != null and logisticsStatus != ''">
  173. and lo.status = #{logisticsStatus, jdbcType=INTEGER}
  174. </if>
  175. <if test="passStatus != null and passStatus != ''">
  176. and wo.status = 8
  177. </if>
  178. <if test="loadCountStatus != null and loadCountStatus != ''">
  179. and wo.status in (5, 6, 7, 8, 12, 13)
  180. </if>
  181. <if test="unloadCountStatus != null and unloadCountStatus != ''">
  182. and wo.status in (7, 8, 12, 13)
  183. </if>
  184. <if test="upperlOrderId != null and upperlOrderId != ''">
  185. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, pids)
  186. </if>
  187. <if test="belowlOrderId != null and belowlOrderId != ''">
  188. and FIND_IN_SET(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="selectWaybillOrderCarListGroupByTruckNo" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  195. SELECT
  196. a.truck_no AS truckNo,
  197. COUNT( a.truck_no ) AS count,
  198. a.driver_id AS driverId,
  199. a.driver_name AS driverName,
  200. a.driver_phone AS driverPhone,
  201. a.driver_idcard AS driverCard
  202. FROM
  203. `kwt_waybill_order` a
  204. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  205. AND B.del_flag = 0
  206. AND b.del_flag = 0
  207. <where>
  208. <if test="ids != null and ids.size() > 0">
  209. and a.l_order_id in
  210. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  211. #{item}
  212. </foreach>
  213. </if>
  214. <if test="statusList != null and statusList.size() > 0">
  215. and a.status in
  216. <foreach collection="statusList" item="item" open="(" close=")" separator=",">
  217. #{item}
  218. </foreach>
  219. </if>
  220. </where>
  221. GROUP BY
  222. a.truck_no
  223. limit #{page},#{pageSize}
  224. </select>
  225. <select id="findStatisticsCountByDriver" resultType="java.util.Map">
  226. select tabA.total + tabB.total as waitTotal,
  227. tabC.total departureTotal,
  228. tabD.total executeTotal,
  229. tabE.total endTotal
  230. from (SELECT count(1) total,
  231. 0 indexNum
  232. FROM kwt_logistics_order_circulate loc
  233. LEFT JOIN kwt_logistics_order lo on lo.id = loc.l_order_id
  234. where loc.del_flag = 0
  235. and lo.del_flag = 0
  236. and loc.status = 0
  237. and loc.w_order_id is null
  238. and loc.driver_id = #{driverId, jdbcType=BIGINT}) tabA
  239. left join
  240. (SELECT count(1) total,
  241. 0 indexNum
  242. FROM kwt_waybill_order wo
  243. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  244. where wo.del_flag = 0
  245. and lo.del_flag = 0
  246. and wo.status = 1
  247. and wo.driver_id = #{driverId, jdbcType=BIGINT}) tabB on tabB.indexNum = tabA.indexNum
  248. left join
  249. (SELECT count(1) total,
  250. 0 indexNum
  251. FROM kwt_waybill_order wo
  252. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  253. where wo.del_flag = 0
  254. and lo.del_flag = 0
  255. and wo.status = 2
  256. and wo.driver_id = #{driverId, jdbcType=BIGINT}) tabC on tabC.indexNum = tabA.indexNum
  257. left join
  258. (SELECT count(1) total,
  259. 0 indexNum
  260. FROM kwt_waybill_order wo
  261. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  262. where wo.del_flag = 0
  263. and lo.del_flag = 0
  264. and wo.status in (3, 4, 5, 6)
  265. and wo.driver_id = #{driverId, jdbcType=BIGINT}) tabD on tabD.indexNum = tabA.indexNum
  266. left join
  267. (SELECT count(1) total,
  268. 0 indexNum
  269. FROM kwt_waybill_order wo
  270. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  271. where wo.del_flag = 0
  272. and lo.del_flag = 0
  273. and wo.status in (7, 8, 9, 10, 12, 13)
  274. and wo.driver_id = #{driverId, jdbcType=BIGINT}) tabE on tabE.indexNum = tabA.indexNum
  275. </select>
  276. <select id="findStatisticsSumByDriver" resultType="java.util.Map" parameterType="java.util.Map">
  277. SELECT
  278. count(1) total, IFNULL(sum(wo.entrust_amount), 0.0) entrustAmount, IFNULL(sum(wo.load_amount), 0.0) loadAmount,
  279. IFNULL(sum(wo.unload_amount), 0.0) unloadAmount, IFNULL(sum(wo.deficit_amount), 0.0) deficitAmount,
  280. IFNULL(sum(wo.deficit_price), 0.0) deficitPrice
  281. FROM kwt_waybill_order wo
  282. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  283. where wo.del_flag = 0 and lo.del_flag = 0
  284. <if test="busStatus != null and busStatus == 4">
  285. and wo.status in (7, 8, 9, 10, 12, 13)
  286. </if>
  287. <if test="driverId != null and driverId != ''">
  288. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  289. </if>
  290. <if test="month != null and month != ''">
  291. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  292. </if>
  293. <if test="startTime != null and startTime != ''">
  294. and DATE(wo.create_time) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  295. </if>
  296. <if test="endTime != null and endTime != ''">
  297. and DATE(wo.create_time) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  298. </if>
  299. </select>
  300. <select id="deficitLossAmountByDriver" parameterType="java.util.Map">
  301. SELECT
  302. <!-- FORMAT(IFNULL(sum(deficitLossAmount), 0.0), 2) deficitLossAmount-->
  303. IFNULL(sum(deficitLossAmount), 0.0) deficitLossAmount
  304. from (
  305. SELECT
  306. <!-- ( deficitAmount - FORMAT((loadAmount * loss / lossUnit),2) ) deficitLossAmount-->
  307. ( deficitAmount - (loadAmount * loss / lossUnit) ) deficitLossAmount
  308. from (
  309. SELECT
  310. IFNULL(wo.deficit_amount, 0.0) deficitAmount,
  311. IFNULL(lo.loss, 0.0) loss,
  312. IFNULL(wo.load_amount, 0.0) loadAmount,
  313. case when lo.loss_unit = 0 then 1000 when lo.loss_unit = 0 then 100 ELSE 0 end as lossUnit
  314. from kwt_waybill_order wo
  315. left join kwt_logistics_order lo on lo.id = wo.l_order_id
  316. where wo.del_flag = 0 and lo.del_flag = 0
  317. <if test="busStatus != null and busStatus == 4">
  318. and wo.status in (7, 8, 9, 10, 12, 13)
  319. </if>
  320. <if test="driverId != null and driverId != ''">
  321. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  322. </if>
  323. <if test="month != null and month != ''">
  324. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  325. </if>
  326. <if test="startTime != null and startTime != ''">
  327. and DATE(wo.create_time) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  328. </if>
  329. <if test="endTime != null and endTime != ''">
  330. and DATE(wo.create_time) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  331. </if>
  332. ) tab
  333. ) tab1
  334. </select>
  335. <select id="findWaitWaybillOrderByDriver" resultType="com.sckw.transport.model.vo.WaybillOrderDriverVo"
  336. parameterType="java.util.Map">
  337. SELECT *
  338. from (SELECT wo.id wOrderId,
  339. wo.w_order_no wOrderNo,
  340. wo.l_order_id lOrderId,
  341. lo.l_order_no lOrderNo,
  342. wo.type,
  343. lo.amount - lo.entrust_amount - lo.subcontract_amount residueAmount,
  344. lo.unit,
  345. lo.loss_unit lossUnit,
  346. wo.ent_id carrierEntId,
  347. 'xxxxx' carrierFirmName,
  348. log.goods_name goodsName,
  349. wo.start_time startTime,
  350. wo.end_time endTime,
  351. wo.entrust_amount entrustAmount,
  352. woa1.name loadName,
  353. woa1.city_code loadCityCode,
  354. woa1.city_name loadCityName,
  355. woa1.detail_address loadDetailAddress,
  356. woa2.name unloadName,
  357. woa2.city_code unloadCityCode,
  358. woa2.city_name unloadCityName,
  359. woa2.detail_address unloadDetailAddress,
  360. IFNULL(wo.load_amount, 0.0) loadAmount,
  361. IFNULL(wo.unload_amount, 0.0) unloadAmount,
  362. IFNULL(wo.deficit_amount, 0.0) deficitAmount,
  363. IFNULL(wo.deficit_price, 0.0) deficitPrice,
  364. wo.truck_no truckNo,
  365. wo.status,
  366. wo.create_time createTime
  367. FROM kwt_waybill_order wo
  368. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  369. LEFT JOIN kwt_waybill_order_address woa1 on woa1.w_order_id = wo.id and woa1.address_type = 1
  370. LEFT JOIN kwt_waybill_order_address woa2 on woa2.w_order_id = wo.id and woa2.address_type = 2
  371. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = wo.l_order_id
  372. where wo.del_flag = 0
  373. and lo.del_flag = 0
  374. and wo.status = 1
  375. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  376. UNION
  377. SELECT loc.id wOrderId,
  378. null wOrderNo,
  379. loc.l_order_id lOrderId,
  380. lo.l_order_no lOrderNo,
  381. loc.type,
  382. lo.amount - lo.entrust_amount - lo.subcontract_amount residueAmount,
  383. lo.unit,
  384. lo.loss_unit lossUnit,
  385. loc.ent_id carrierEntId,
  386. 'xxxxx' carrierFirmName,
  387. log.goods_name goodsName,
  388. loc.start_time startTime,
  389. loc.end_time endTime,
  390. loc.entrust_amount entrustAmount,
  391. loa1.name loadName,
  392. loa1.city_code loadCityCode,
  393. loa1.city_name loadCityName,
  394. loa1.detail_address loadDetailAddress,
  395. loa2.name unloadName,
  396. loa2.city_code unloadCityCode,
  397. loa2.city_name unloadCityName,
  398. loa2.detail_address unloadDetailAddress,
  399. 0.0 loadAmount,
  400. 0.0 unloadAmount,
  401. 0.0 deficitAmount,
  402. 0.0 deficitPrice,
  403. loc.truck_no truckNo,
  404. 1 status,
  405. loc.update_time createTime
  406. FROM kwt_logistics_order_circulate loc
  407. LEFT JOIN kwt_logistics_order lo on lo.id = loc.l_order_id
  408. LEFT JOIN kwt_logistics_order_address loa1 on loa1.l_order_id = lo.id and loa1.address_type = 1
  409. LEFT JOIN kwt_logistics_order_address loa2 on loa2.l_order_id = lo.id and loa2.address_type = 2
  410. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = loc.l_order_id
  411. where loc.del_flag = 0
  412. and lo.del_flag = 0
  413. and loc.status = 0
  414. and loc.w_order_id is null
  415. and loc.driver_id = #{driverId, jdbcType=BIGINT}
  416. ) tab
  417. order by startTime
  418. </select>
  419. <select id="findOtherWaybillOrderByDriver" resultType="com.sckw.transport.model.vo.WaybillOrderDriverVo"
  420. parameterType="java.util.Map">
  421. SELECT
  422. wo.id wOrderId, wo.w_order_no wOrderNo, wo.l_order_id lOrderId, lo.l_order_no lOrderNo,
  423. lo.unit, lo.loss_unit lossUnit, wo.type,
  424. wo.ent_id carrierEntId, 'xxxxx' carrierFirmName, log.goods_name goodsName, wo.start_time startTime,
  425. wo.end_time endTime, wo.entrust_amount entrustAmount, woa1.name loadName, woa1.city_code loadCityCode,
  426. woa1.city_name loadCityName, woa1.detail_address loadDetailAddress, woa2.name unloadName, woa2.city_code
  427. unloadCityCode, woa2.city_name unloadCityName, woa2.detail_address unloadDetailAddress, IFNULL(wo.load_amount, 0.0) loadAmount,
  428. IFNULL(wo.unload_amount, 0.0) unloadAmount, IFNULL(wo.deficit_amount, 0.0) deficitAmount, IFNULL(wo.deficit_price, 0.0) deficitPrice,
  429. wo.truck_no truckNo, wo.status, wo.create_time createTime
  430. FROM kwt_waybill_order wo
  431. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  432. LEFT JOIN kwt_waybill_order_address woa1 on woa1.w_order_id = wo.id and woa1.address_type = 1
  433. LEFT JOIN kwt_waybill_order_address woa2 on woa2.w_order_id = wo.id and woa2.address_type = 2
  434. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = wo.l_order_id
  435. where wo.del_flag = 0 and lo.del_flag = 0
  436. <if test="driverId != null and driverId != ''">
  437. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  438. </if>
  439. <if test="busStatus != null and busStatus == 2">
  440. and wo.status = 2
  441. </if>
  442. <if test="busStatus != null and busStatus == 3">
  443. and wo.status in (3, 4, 5, 6)
  444. </if>
  445. <if test="busStatus != null and busStatus == 4">
  446. and wo.status in (7, 8, 9, 10, 12, 13)
  447. </if>
  448. <if test="month != null and month != ''">
  449. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  450. </if>
  451. <if test="startTime != null and startTime != ''">
  452. and DATE(wo.create_time) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  453. </if>
  454. <if test="endTime != null and endTime != ''">
  455. and DATE(wo.create_time) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  456. </if>
  457. <if test="busStatus != null and busStatus == 2">
  458. ORDER BY wo.start_time
  459. </if>
  460. <if test="busStatus != null and busStatus == 4">
  461. ORDER BY wo.update_time desc
  462. </if>
  463. </select>
  464. <select id="selectWaybillOrderCarListNotPage" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  465. SELECT a.id as wOrderId,
  466. a.w_order_no as wOrderNo,
  467. a.driver_id as driverId,
  468. a.driver_name as driverName,
  469. a.driver_phone as driverPhone,
  470. a.driver_idcard as driverCard,
  471. a.truck_no as truckNo,
  472. a.status as status,
  473. a.l_order_id as lOrderId,
  474. b.l_order_no as lOrderNo,
  475. b.t_order_id as tOrderId,
  476. b.t_order_no as tOrderNo
  477. FROM kwt_waybill_order a
  478. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  479. WHERE a.del_flag = '0'
  480. and b.del_flag = '0'
  481. and b.t_order_id = #{id,jdbcType=VARCHAR}
  482. </select>
  483. <select id="selectWaybillOrderCountByStatus">
  484. SELECT COUNT(id)
  485. FROM kwt_waybill_order
  486. WHERE ent_id = #{entId}
  487. AND del_flag = 0
  488. <if test="keyword != null and keyword != ''">
  489. AND (
  490. w_order_no LIKE concat('%',#{keyword},'%')
  491. OR truck_no LIKE concat('%',#{keyword},'%')
  492. OR driver_name LIKE concat('%',#{keyword},'%')
  493. OR driver_phone LIKE concat('%',#{keyword},'%')
  494. )
  495. </if>
  496. <if test="statuses != null and statuses.size() > 0">
  497. AND status IN
  498. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  499. #{item}
  500. </foreach>
  501. </if>
  502. </select>
  503. <select id="selectOrderByOrderId" resultType="java.util.Map">
  504. SELECT COUNT(id) total,IFNULL(SUM(entrust_amount),0) AS amount
  505. FROM
  506. kwt_waybill_order
  507. WHERE
  508. l_order_id = #{orderId}
  509. AND type = #{type} and del_flag = 0
  510. <if test="statusList != null and statusList.size() > 0">
  511. and status not in
  512. <foreach collection="statusList" open="(" close=")" separator="," item="item">
  513. #{item}
  514. </foreach>
  515. </if>
  516. </select>
  517. <select id="selectWaybillOrderAmountByStatus" resultType="java.util.Map">
  518. SELECT
  519. COUNT(id) total,
  520. SUM(load_amount) loadAmount,
  521. SUM(unload_amount) unloadAmount,
  522. SUM(load_amount - unload_amount) lossAmount,
  523. SUM( IF(load_amount - unload_amount - deficit_amount > 0, load_amount - unload_amount - deficit_amount , 0) ) deficitRealAmount
  524. FROM
  525. kwt_waybill_order
  526. WHERE ent_id = #{entId}
  527. AND del_flag = 0
  528. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  529. AND create_time BETWEEN #{startDate} AND #{endDate}
  530. </if>
  531. <if test="keyword != null and keyword != ''">
  532. AND (
  533. w_order_no LIKE concat('%',#{keyword},'%')
  534. OR truck_no LIKE concat('%',#{keyword},'%')
  535. OR driver_name LIKE concat('%',#{keyword},'%')
  536. OR driver_phone LIKE concat('%',#{keyword},'%')
  537. )
  538. </if>
  539. <if test="statuses != null and statuses.size() > 0">
  540. AND status IN
  541. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  542. #{item}
  543. </foreach>
  544. </if>
  545. </select>
  546. <select id="getMaxOrderNo" resultType="java.lang.String">
  547. SELECT w_order_no FROM `kwt_waybill_order` WHERE w_order_no LIKE concat(#{lOrderNo},'%') ORDER BY w_order_no DESC LIMIT 1
  548. </select>
  549. <select id="findWaybillOrder" resultType="com.sckw.transport.model.KwtWaybillOrder" parameterType="java.util.Map">
  550. SELECT
  551. kwo.id worderId, kwo.w_order_no worderNo, kwo.l_order_id lOrderId, kwo.type, kwo.ent_id carrierEntId, kwo.start_time startTime,
  552. kwo.end_time endTime, kwo.entrust_amount entrustAmount, kwo.load_amount loadAmount, kwo.unload_amount unloadAmount,
  553. kwo.deficit_amount deficitAmount, kwo.deficit_price deficitPrice, kwo.truck_id truckId, kwo.truck_no truckNo, kwo.status,
  554. kwo.create_time createTime, kwo.driver_id driverId, kwo.driver_name driverName, kwo.driver_phone driverPhone
  555. FROM kwt_waybill_order kwo
  556. where kwo.del_flag = 0
  557. <if test="tOrderId != null and tOrderId != ''">
  558. and kwo.t_order_id = #{tOrderId, jdbcType=BIGINT}
  559. </if>
  560. <if test="lOrderId != null and lOrderId != ''">
  561. and kwo.id = #{lOrderId, jdbcType=BIGINT}
  562. </if>
  563. <if test="driverId != null and driverId != ''">
  564. and kwo.driver_id = #{driverId, jdbcType=BIGINT}
  565. </if>
  566. <if test="truckNo != null and truckNo != ''">
  567. and kwo.truck_no = #{truckNo, jdbcType=VARCHAR}
  568. </if>
  569. <if test="status != null and status != ''">
  570. and kwo.status = #{status, jdbcType=INTEGER}
  571. </if>
  572. <if test="busStatus != null and busStatus == 2">
  573. and kwo.status = 2
  574. </if>
  575. <if test="busStatus != null and busStatus == 3">
  576. and kwo.status in (3, 4, 5, 6)
  577. </if>
  578. <if test="busStatus != null and busStatus == 4">
  579. and kwo.status in (7, 8, 9, 10, 12, 13)
  580. </if>
  581. </select>
  582. </mapper>