KwtWaybillOrderMapper.xml 25 KB

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