KwtWaybillOrderV1Mapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.KwtWaybillOrderV1Mapper">
  4. <select id="statistics" resultType="com.sckw.core.model.vo.TableTop"
  5. parameterType="com.sckw.transport.model.dto.WaybillOrderQueryDto">
  6. SELECT
  7. wo.status 'value',
  8. count(1) total
  9. from kwt_waybill_order wo
  10. where wo.del_flag = 0
  11. <if test="entId != null and entId != ''">
  12. and wo.ent_id = #{entId, jdbcType=VARCHAR}
  13. </if>
  14. <if test="(loadCityCode != null and loadCityCode != '') or (unloadCityCode != null and unloadCityCode != '')">
  15. and wo.id in (
  16. SELECT w_order_id from kwt_waybill_order_address where del_flag = 0
  17. <if test="loadCityCode != null and loadCityCode != ''">
  18. address_type = 1
  19. and left(city_code, #{loadCityCodeLevel, jdbcType=INTEGER}) = left( #{loadCityCode, jdbcType=INTEGER}, #{loadCityCodeLevel, jdbcType=INTEGER} )
  20. </if>
  21. <if test="unloadCityCode != null and unloadCityCode != ''">
  22. address_type = 2
  23. and left(city_code, #{loadCityCodeLevel, jdbcType=INTEGER}) = left( #{unloadCityCode, jdbcType=INTEGER}, #{loadCityCodeLevel, jdbcType=INTEGER} )
  24. </if>
  25. )
  26. </if>
  27. <if test="(startLoadTime != null and startLoadTime != '') or (endLoadTime != null and endLoadTime != '')
  28. or (startUnloadTime != null and startUnloadTime != '') or (endUnloadTime != null and endUnloadTime != '')">
  29. and wo.id in (
  30. SELECT w_order_id from kwt_waybill_order_subtask where del_flag = 0
  31. <if test="startLoadTime != null and startLoadTime != ''">
  32. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  33. </if>
  34. <if test="endLoadTime != null and endLoadTime != ''">
  35. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  36. </if>
  37. <if test="startUnloadTime != null and startUnloadTime != ''">
  38. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  39. </if>
  40. <if test="endUnloadTime != null and endUnloadTime != ''">
  41. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  42. </if>
  43. )
  44. </if>
  45. <if test="startSendCarTime != null and startSendCarTime != '' " >
  46. and DATE( wo.create_time) <![CDATA[ >= ]]> #{startSendCarTime,jdbcType=TIMESTAMP}
  47. </if>
  48. <if test="startSendCarTime != null and startSendCarTime != '' " >
  49. and DATE( wo.create_time ) <![CDATA[ <= ]]> #{endSendCarTime,jdbcType=TIMESTAMP}
  50. </if>
  51. <if test="keywords != null and keywords != ''">
  52. and (
  53. wo.w_order_no like concat('%',#{keywords},'%')
  54. or wo.truck_no like concat('%',#{keywords},'%')
  55. or wo.driver_name like concat('%',#{keywords},'%')
  56. )
  57. </if>
  58. GROUP BY wo.status
  59. </select>
  60. <select id="findListPage" resultType="com.sckw.transport.model.vo.WaybillOrderSelectVo"
  61. parameterType="com.sckw.transport.model.dto.WaybillOrderQueryDto">
  62. SELECT
  63. wo.id wOrderId, wo.ent_id entId, wo.w_order_no wOrderNo, wo.truck_no truckNo, wo.driver_name driverName, wo.driver_phone driverPhone,
  64. wo.type, wo.create_time sendCarTime, wo.create_by createBy, wo.create_time createTime, wo.update_time updateTime, wo.status
  65. from kwt_waybill_order wo
  66. where wo.del_flag = 0
  67. <if test="entId != null and entId != ''">
  68. and wo.ent_id = #{entId, jdbcType=VARCHAR}
  69. </if>
  70. <if test="queryWstatus != null and queryWstatus != ''">
  71. and wo.status in (#{queryWstatus, jdbcType=VARCHAR})
  72. </if>
  73. <if test="(loadCityCode != null and loadCityCode != '') or (unloadCityCode != null and unloadCityCode != '')">
  74. and wo.id in (
  75. SELECT w_order_id from kwt_waybill_order_address where del_flag = 0
  76. <if test="loadCityCode != null and loadCityCode != ''">
  77. address_type = 1
  78. and left(city_code, #{loadCityCodeLevel, jdbcType=INTEGER}) = left( #{loadCityCode, jdbcType=INTEGER}, #{loadCityCodeLevel, jdbcType=INTEGER} )
  79. </if>
  80. <if test="unloadCityCode != null and unloadCityCode != ''">
  81. address_type = 2
  82. and left(city_code, #{loadCityCodeLevel, jdbcType=INTEGER}) = left( #{unloadCityCode, jdbcType=INTEGER}, #{loadCityCodeLevel, jdbcType=INTEGER} )
  83. </if>
  84. )
  85. </if>
  86. <if test="(startLoadTime != null and startLoadTime != '') or (endLoadTime != null and endLoadTime != '')
  87. or (startUnloadTime != null and startUnloadTime != '') or (endUnloadTime != null and endUnloadTime != '')">
  88. and wo.id in (
  89. SELECT w_order_id from kwt_waybill_order_subtask where del_flag = 0
  90. <if test="startLoadTime != null and startLoadTime != ''">
  91. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  92. </if>
  93. <if test="endLoadTime != null and endLoadTime != ''">
  94. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  95. </if>
  96. <if test="startUnloadTime != null and startUnloadTime != ''">
  97. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  98. </if>
  99. <if test="endUnloadTime != null and endUnloadTime != ''">
  100. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  101. </if>
  102. )
  103. </if>
  104. <if test="startSendCarTime != null and startSendCarTime != '' " >
  105. and DATE( wo.create_time) <![CDATA[ >= ]]> #{startSendCarTime,jdbcType=TIMESTAMP}
  106. </if>
  107. <if test="endSendCarTime != null and endSendCarTime != '' " >
  108. and DATE( wo.create_time ) <![CDATA[ <= ]]> #{endSendCarTime,jdbcType=TIMESTAMP}
  109. </if>
  110. <if test="keywords != null and keywords != ''">
  111. and (
  112. wo.w_order_no like concat('%',#{keywords},'%')
  113. or wo.truck_no like concat('%',#{keywords},'%')
  114. or wo.driver_name like concat('%',#{keywords},'%')
  115. )
  116. </if>
  117. order by wo.update_time desc
  118. </select>
  119. <select id="findStatisticsCountByDriver" resultType="java.util.Map">
  120. SELECT
  121. count(case when wo.status = 101 then 1 end) waitTotal,
  122. count(case when wo.status = 201 then 1 end) departureTotal,
  123. count(case when wo.status in (203, 301, 302, 401, 402) then 1 end) executeTotal,
  124. count(case when wo.status in (501, 502, 503, 504, 103, 202) then 1 end) endTotal
  125. from kwt_waybill_order wo
  126. where wo.del_flag = 0
  127. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  128. <if test="specialEntIds != null and specialEntIds.size() > 0">
  129. and wo.ent_id in
  130. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  131. #{item,jdbcType=BIGINT}
  132. </foreach>
  133. </if>
  134. </select>
  135. <select id="findWaybillOrderByDriver" resultType="com.sckw.transport.model.KwtWaybillOrderV1" parameterType="java.util.Map">
  136. SELECT
  137. wo.id, wo.id wOrderId, wo.ent_id entId, wo.w_order_no wOrderNo, wo.truck_no truckNo, wo.driver_name driverName, wo.driver_phone driverPhone,
  138. wo.type, wo.create_time sendCarTime, wo.create_time createTime, wo.update_time updateTime, wo.status
  139. from kwt_waybill_order wo
  140. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  141. where wo.del_flag = 0 and wos.del_flag = 0
  142. <if test="entId != null and entId != ''">
  143. and wo.ent_id = #{entId, jdbcType=VARCHAR}
  144. </if>
  145. <if test="specialEntIds != null and specialEntIds.size() > 0">
  146. and wo.ent_id in
  147. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  148. #{item,jdbcType=BIGINT}
  149. </foreach>
  150. </if>
  151. <if test="driverId != null and driverId != ''">
  152. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  153. </if>
  154. <if test="busStatus != null and busStatus == 1">
  155. and wo.status = 101
  156. </if>
  157. <if test="busStatus != null and busStatus == 2">
  158. and wo.status = 201
  159. </if>
  160. <if test="busStatus != null and busStatus == 3">
  161. and wo.status in (203, 301, 302, 401, 402)
  162. </if>
  163. <if test="busStatus != null and busStatus == 4">
  164. and wo.status in (103, 202, 501, 502, 503, 504)
  165. </if>
  166. <if test="month != null and month != ''">
  167. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  168. </if>
  169. <if test="startTime != null and startTime != ''">
  170. and LEFT(wo.create_time, 10) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  171. </if>
  172. <if test="endTime != null and endTime != ''">
  173. and LEFT(wo.create_time, 10) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  174. </if>
  175. <if test="busStatus != null and busStatus == 2">
  176. ORDER BY wos.load_time
  177. </if>
  178. <if test="busStatus != null and busStatus == 4">
  179. ORDER BY CASE WHEN wo.status = 503 THEN wo.status * -1 ELSE wo.status END ASC, wo.update_time desc
  180. </if>
  181. </select>
  182. <select id="findCountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  183. SELECT
  184. count(case when wo.status = 502 then 1 end) totalComplete,
  185. count(case when wo.status not in (101, 102, 103, 202) then 1 end) totalTake,
  186. count(case when wo.status in (203, 301, 302, 401, 402) then 1 end) totalExecute
  187. from kwt_waybill_order wo
  188. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  189. where wo.del_flag = 0 and wos.del_flag = 0
  190. <if test="driverId != null and driverId != ''">
  191. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  192. </if>
  193. <if test="truckId != null and truckId != ''">
  194. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  195. </if>
  196. </select>
  197. <select id="findAmountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  198. SELECT
  199. IFNULL(SUM(wos.load_amount), 0.0) loadAmount
  200. from kwt_waybill_order_subtask wos
  201. left join kwt_waybill_order wo on wos.w_order_id = wo.id
  202. where wo.del_flag = 0 and wos.del_flag = 0
  203. <if test="driverId != null and driverId != ''">
  204. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  205. </if>
  206. <if test="truckId != null and truckId != ''">
  207. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  208. </if>
  209. </select>
  210. <select id="findUnfinishedByTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  211. SELECT count(1) totalExecute from kwt_waybill_order wo
  212. where wo.del_flag = 0
  213. and wo.status in (101, 201, 203, 301, 302, 401, 402)
  214. <if test="type != null and type != ''">
  215. and wo.type = #{type, jdbcType=INTEGER}
  216. </if>
  217. <if test="truckId != null and truckId != ''">
  218. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  219. </if>
  220. </select>
  221. <select id="findTicketCountByAddress" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  222. SELECT
  223. sum(wot.amount) amount,
  224. MIN(wot.operate_time) loadTime,
  225. MAX(wot.operate_time) unloadTime
  226. from kwt_waybill_order_ticket wot
  227. left join kwt_waybill_order_address woa on woa.id = wot.w_address_id
  228. left join kwt_logistics_order_address loa on loa.id = woa.l_address_id
  229. left join kwt_logistics_order lo on lo.id = loa.l_order_id
  230. left join kwt_waybill_order wo on wo.id = wot.w_order_id
  231. where wot.del_flag = 0
  232. <if test="passStatus != null and passStatus != ''">
  233. and wo.status = 502
  234. </if>
  235. <if test="wOrderId != null and wOrderId != ''">
  236. and wot.w_order_id = #{wOrderId, jdbcType=BIGINT}
  237. </if>
  238. <if test="type != null and type != ''">
  239. and wot.type = #{type, jdbcType=VARCHAR}
  240. </if>
  241. <if test="unit != null and unit != ''">
  242. and wot.unit = #{unit, jdbcType=VARCHAR}
  243. </if>
  244. <if test="lAddressId != null and lAddressId != ''">
  245. and loa.id = #{lAddressId, jdbcType=BIGINT}
  246. </if>
  247. <if test="lOrderId != null and lOrderId != ''">
  248. and lo.id = #{lOrderId, jdbcType=BIGINT}
  249. </if>
  250. <if test="upperlOrderId != null and upperlOrderId != ''">
  251. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, lo.pids)
  252. </if>
  253. </select>
  254. </mapper>