KwtWaybillOrderMapper.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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="findWaitWaybillOrderByDriver" resultType="com.sckw.transport.model.vo.WaybillOrderDriverVo"
  301. parameterType="java.util.Map">
  302. SELECT *
  303. from (SELECT wo.id wOrderId,
  304. wo.w_order_no wOrderNo,
  305. wo.l_order_id lOrderId,
  306. lo.l_order_no lOrderNo,
  307. wo.type,
  308. lo.amount - lo.entrust_amount - lo.subcontract_amount residueAmount,
  309. lo.unit,
  310. lo.loss_unit lossUnit,
  311. wo.ent_id carrierEntId,
  312. 'xxxxx' carrierFirmName,
  313. log.goods_name goodsName,
  314. wo.start_time startTime,
  315. wo.end_time endTime,
  316. wo.entrust_amount entrustAmount,
  317. woa1.name loadName,
  318. woa1.city_code loadCityCode,
  319. woa1.city_name loadCityName,
  320. woa1.detail_address loadDetailAddress,
  321. woa2.name unloadName,
  322. woa2.city_code unloadCityCode,
  323. woa2.city_name unloadCityName,
  324. woa2.detail_address unloadDetailAddress,
  325. wo.load_amount loadAmount,
  326. wo.unload_amount unloadAmount,
  327. wo.deficit_amount deficitAmount,
  328. wo.deficit_price deficitPrice,
  329. wo.truck_no truckNo,
  330. wo.status,
  331. wo.create_time createTime
  332. FROM kwt_waybill_order wo
  333. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  334. LEFT JOIN kwt_waybill_order_address woa1 on woa1.w_order_id = wo.id and woa1.address_type = 1
  335. LEFT JOIN kwt_waybill_order_address woa2 on woa2.w_order_id = wo.id and woa2.address_type = 2
  336. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = wo.l_order_id
  337. where wo.del_flag = 0
  338. and lo.del_flag = 0
  339. and wo.status = 1
  340. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  341. UNION
  342. SELECT loc.id wOrderId,
  343. null wOrderNo,
  344. loc.l_order_id lOrderId,
  345. lo.l_order_no lOrderNo,
  346. loc.type,
  347. lo.amount - lo.entrust_amount - lo.subcontract_amount residueAmount,
  348. lo.unit,
  349. lo.loss_unit lossUnit,
  350. loc.ent_id carrierEntId,
  351. 'xxxxx' carrierFirmName,
  352. log.goods_name goodsName,
  353. loc.start_time startTime,
  354. loc.end_time endTime,
  355. loc.entrust_amount entrustAmount,
  356. woa1.name loadName,
  357. woa1.city_code loadCityCode,
  358. woa1.city_name loadCityName,
  359. woa1.detail_address loadDetailAddress,
  360. woa2.name unloadName,
  361. woa2.city_code unloadCityCode,
  362. woa2.city_name unloadCityName,
  363. woa2.detail_address unloadDetailAddress,
  364. null loadAmount,
  365. null unloadAmount,
  366. null deficitAmount,
  367. null deficitPrice,
  368. loc.truck_no truckNo,
  369. 1 status,
  370. loc.update_time createTime
  371. FROM kwt_logistics_order_circulate loc
  372. LEFT JOIN kwt_logistics_order lo on lo.id = loc.l_order_id
  373. LEFT JOIN kwt_waybill_order_address woa1 on woa1.w_order_id = lo.id and woa1.address_type = 1
  374. LEFT JOIN kwt_waybill_order_address woa2 on woa2.w_order_id = lo.id and woa2.address_type = 2
  375. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = loc.l_order_id
  376. where loc.del_flag = 0
  377. and lo.del_flag = 0
  378. and loc.status = 0
  379. and loc.w_order_id is null
  380. and loc.driver_id = #{driverId, jdbcType=BIGINT}) tab
  381. order by createTime desc
  382. </select>
  383. <select id="findOtherWaybillOrderByDriver" resultType="com.sckw.transport.model.vo.WaybillOrderDriverVo"
  384. parameterType="java.util.Map">
  385. SELECT
  386. wo.id wOrderId, wo.w_order_no wOrderNo, wo.l_order_id lOrderId, lo.l_order_no lOrderNo,
  387. lo.unit, lo.loss_unit lossUnit, wo.type,
  388. wo.ent_id carrierEntId, 'xxxxx' carrierFirmName, log.goods_name goodsName, wo.start_time startTime,
  389. wo.end_time endTime, wo.entrust_amount entrustAmount, woa1.name loadName, woa1.city_code loadCityCode,
  390. woa1.city_name loadCityName, woa1.detail_address loadDetailAddress, woa2.name unloadName, woa2.city_code
  391. unloadCityCode, woa2.city_name unloadCityName, woa2.detail_address unloadDetailAddress, wo.load_amount loadAmount,
  392. wo.unload_amount unloadAmount, wo.deficit_amount deficitAmount, wo.deficit_price deficitPrice, wo.truck_no truckNo,
  393. wo.status, wo.create_time createTime
  394. FROM kwt_waybill_order wo
  395. LEFT JOIN kwt_logistics_order lo on lo.id = wo.l_order_id
  396. LEFT JOIN kwt_waybill_order_address woa1 on woa1.w_order_id = wo.id and woa1.address_type = 1
  397. LEFT JOIN kwt_waybill_order_address woa2 on woa2.w_order_id = wo.id and woa2.address_type = 2
  398. LEFT JOIN kwt_logistics_order_goods log on log.l_order_id = wo.l_order_id
  399. where wo.del_flag = 0 and lo.del_flag = 0
  400. <if test="driverId != null and driverId != ''">
  401. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  402. </if>
  403. <if test="busStatus != null and busStatus == 2">
  404. and wo.status = 2
  405. </if>
  406. <if test="busStatus != null and busStatus == 3">
  407. and wo.status in (3, 4, 5, 6)
  408. </if>
  409. <if test="busStatus != null and busStatus == 4">
  410. and wo.status in (7, 8, 9, 10, 12, 13)
  411. </if>
  412. <if test="month != null and month != ''">
  413. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  414. </if>
  415. <if test="startTime != null and startTime != ''">
  416. and DATE(wo.create_time) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  417. </if>
  418. <if test="endTime != null and endTime != ''">
  419. and DATE(wo.create_time) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  420. </if>
  421. </select>
  422. <select id="selectWaybillOrderCarListNotPage" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  423. SELECT a.id as wOrderId,
  424. a.w_order_no as wOrderNo,
  425. a.driver_id as driverId,
  426. a.driver_name as driverName,
  427. a.driver_phone as driverPhone,
  428. a.driver_idcard as driverCard,
  429. a.truck_no as truckNo,
  430. a.l_order_id as lOrderId,
  431. b.l_order_no as lOrderNo,
  432. b.t_order_id as tOrderId,
  433. b.t_order_no as tOrderNo
  434. FROM kwt_waybill_order a
  435. LEFT JOIN kwt_logistics_order b ON a.l_order_id = b.id
  436. WHERE a.del_flag = '0'
  437. and b.del_flag = '0'
  438. and b.t_order_id = #{id,jdbcType=VARCHAR}
  439. </select>
  440. <select id="selectWaybillOrderCountByStatus">
  441. SELECT COUNT(id)
  442. FROM kwt_waybill_order
  443. WHERE ent_id = #{entId}
  444. AND del_flag = 0
  445. <if test="keyword != null and keyword != ''">
  446. AND (
  447. w_order_no LIKE concat('%',#{keyword},'%')
  448. OR truck_no LIKE concat('%',#{keyword},'%')
  449. OR driver_name LIKE concat('%',#{keyword},'%')
  450. OR driver_phone LIKE concat('%',#{keyword},'%')
  451. )
  452. </if>
  453. <if test="statuses != null and statuses.size() > 0">
  454. AND status IN
  455. <foreach collection="statuses" item="item" open="(" close=")" separator=",">
  456. #{item}
  457. </foreach>
  458. </if>
  459. </select>
  460. <select id="selectOrderByOrderId" resultType="java.util.Map">
  461. SELECT COUNT(id) total,IFNULL(SUM(entrust_amount),0) AS amount
  462. FROM
  463. kwt_waybill_order
  464. WHERE
  465. l_order_id = #{orderId}
  466. AND type = #{type} and del_flag = 0
  467. <if test="statusList != null and statusList.size() > 0">
  468. and status not in
  469. <foreach collection="statusList" open="(" close=")" separator="," item="item">
  470. #{item}
  471. </foreach>
  472. </if>
  473. </select>
  474. <select id="selectWaybillOrderAmountByStatus" resultType="java.util.Map">
  475. SELECT
  476. COUNT(id) total,
  477. SUM(load_amount) loadAmount,
  478. SUM(unload_amount) unloadAmount,
  479. SUM(load_amount - unload_amount) lossAmount,
  480. SUM( IF(load_amount - unload_amount - deficit_amount > 0, load_amount - unload_amount - deficit_amount , 0) ) deficitRealAmount
  481. FROM
  482. kwt_waybill_order
  483. WHERE ent_id = #{entId}
  484. AND del_flag = 0
  485. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  486. AND create_time BETWEEN #{startDate} AND #{endDate}
  487. </if>
  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="getMaxOrderNo" resultType="java.lang.String">
  504. SELECT w_order_no FROM `kwt_waybill_order` WHERE w_order_no LIKE concat(#{lOrderNo},'%') ORDER BY w_order_no DESC LIMIT 1
  505. </select>
  506. <select id="findWaybillOrder" resultType="com.sckw.transport.model.KwtWaybillOrder" parameterType="java.util.Map">
  507. SELECT
  508. kwo.id worderId, kwo.w_order_no worderNo, kwo.l_order_id lOrderId, kwo.type, kwo.ent_id carrierEntId, kwo.start_time startTime,
  509. kwo.end_time endTime, kwo.entrust_amount entrustAmount, kwo.load_amount loadAmount, kwo.unload_amount unloadAmount,
  510. kwo.deficit_amount deficitAmount, kwo.deficit_price deficitPrice, kwo.truck_id truckId, kwo.truck_no truckNo, kwo.status,
  511. kwo.create_time createTime, kwo.driver_id driverId, kwo.driver_name driverName, kwo.driver_phone driverPhone
  512. FROM kwt_waybill_order kwo
  513. where kwo.del_flag = 0
  514. <if test="tOrderId != null and tOrderId != ''">
  515. and kwo.t_order_id = #{tOrderId, jdbcType=BIGINT}
  516. </if>
  517. <if test="lOrderId != null and lOrderId != ''">
  518. and kwo.id = #{lOrderId, jdbcType=BIGINT}
  519. </if>
  520. <if test="driverId != null and driverId != ''">
  521. and kwo.driver_id = #{driverId, jdbcType=BIGINT}
  522. </if>
  523. <if test="truckNo != null and truckNo != ''">
  524. and kwo.truck_no = #{truckNo, jdbcType=VARCHAR}
  525. </if>
  526. <if test="status != null and status != ''">
  527. and kwo.status = #{status, jdbcType=INTEGER}
  528. </if>
  529. <if test="busStatus != null and busStatus == 2">
  530. and kwo.status = 2
  531. </if>
  532. <if test="busStatus != null and busStatus == 3">
  533. and kwo.status in (3, 4, 5, 6)
  534. </if>
  535. <if test="busStatus != null and busStatus == 4">
  536. and kwo.status in (7, 8, 9, 10, 12, 13)
  537. </if>
  538. </select>
  539. </mapper>