KwtWaybillOrderMapper.xml 43 KB

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