KwtWaybillOrderV1Mapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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="findCapacityListPage" resultType="com.sckw.transport.model.vo.WaybillOrderSelectVo"
  120. parameterType="com.sckw.transport.model.dto.WaybillSubtaskOrderQueryDto">
  121. SELECT
  122. wo.driver_id driverId, wo.driver_name driverName, wo.driver_phone driverPhone, wo.driver_idcard driverIdcard,
  123. wo.truck_id truckId, wo.truck_no truckNo, count(1) count
  124. from kwt_waybill_order wo
  125. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  126. WHERE wo.del_flag = 0 and wos.del_flag = 0
  127. <if test="ids != null and ids != ''">
  128. AND wos.l_order_id IN
  129. <foreach collection="ids.split(',')" item="item" open="(" close=")" separator=",">
  130. #{item}
  131. </foreach>
  132. </if>
  133. </select>
  134. <select id="findStatisticsCountByDriver" resultType="java.util.Map">
  135. SELECT
  136. count(case when wo.status = 101 then 1 end) waitTotal,
  137. count(case when wo.status = 201 then 1 end) departureTotal,
  138. count(case when wo.status in (203, 301, 302, 401, 402) then 1 end) executeTotal,
  139. count(case when wo.status in (501, 502, 503, 504, 103, 202) then 1 end) endTotal
  140. from kwt_waybill_order wo
  141. where wo.del_flag = 0
  142. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  143. <if test="specialEntIds != null and specialEntIds.size() > 0">
  144. and wo.ent_id in
  145. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  146. #{item,jdbcType=BIGINT}
  147. </foreach>
  148. </if>
  149. </select>
  150. <select id="findWaybillOrderByDriver" resultType="com.sckw.transport.model.KwtWaybillOrderV1" parameterType="java.util.Map">
  151. SELECT
  152. 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,
  153. wo.type, wo.create_time sendCarTime, wo.create_time createTime, wo.update_time updateTime, wo.status
  154. from kwt_waybill_order wo
  155. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  156. where wo.del_flag = 0 and wos.del_flag = 0
  157. <if test="entId != null and entId != ''">
  158. and wo.ent_id = #{entId, jdbcType=VARCHAR}
  159. </if>
  160. <if test="specialEntIds != null and specialEntIds.size() > 0">
  161. and wo.ent_id in
  162. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  163. #{item,jdbcType=BIGINT}
  164. </foreach>
  165. </if>
  166. <if test="driverId != null and driverId != ''">
  167. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  168. </if>
  169. <if test="busStatus != null and busStatus == 1">
  170. and wo.status = 101
  171. </if>
  172. <if test="busStatus != null and busStatus == 2">
  173. and wo.status = 201
  174. </if>
  175. <if test="busStatus != null and busStatus == 3">
  176. and wo.status in (203, 301, 302, 401, 402)
  177. </if>
  178. <if test="busStatus != null and busStatus == 4">
  179. and wo.status in (103, 202, 501, 502, 503, 504)
  180. </if>
  181. <if test="month != null and month != ''">
  182. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  183. </if>
  184. <if test="startTime != null and startTime != ''">
  185. and LEFT(wo.create_time, 10) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  186. </if>
  187. <if test="endTime != null and endTime != ''">
  188. and LEFT(wo.create_time, 10) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  189. </if>
  190. <if test="busStatus != null and busStatus == 2">
  191. ORDER BY wos.load_time
  192. </if>
  193. <if test="busStatus != null and busStatus == 4">
  194. ORDER BY CASE WHEN wo.status = 503 THEN wo.status * -1 ELSE wo.status END ASC, wo.update_time desc
  195. </if>
  196. </select>
  197. <select id="findCountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  198. SELECT
  199. count(case when wo.status = 502 then 1 end) totalComplete,
  200. count(case when wo.status not in (101, 102, 103, 202) then 1 end) totalTake,
  201. count(case when wo.status in (203, 301, 302, 401, 402) then 1 end) totalExecute
  202. from kwt_waybill_order wo
  203. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  204. where wo.del_flag = 0 and wos.del_flag = 0
  205. <if test="driverId != null and driverId != ''">
  206. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  207. </if>
  208. <if test="truckId != null and truckId != ''">
  209. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  210. </if>
  211. </select>
  212. <select id="findAmountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  213. SELECT
  214. IFNULL(SUM(wos.load_amount), 0.0) loadAmount
  215. from kwt_waybill_order_subtask wos
  216. left join kwt_waybill_order wo on wos.w_order_id = wo.id
  217. where wo.del_flag = 0 and wos.del_flag = 0
  218. <if test="driverId != null and driverId != ''">
  219. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  220. </if>
  221. <if test="truckId != null and truckId != ''">
  222. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  223. </if>
  224. </select>
  225. <select id="findUnfinishedByTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  226. SELECT count(1) totalExecute from kwt_waybill_order wo
  227. where wo.del_flag = 0
  228. and wo.status in (101, 201, 203, 301, 302, 401, 402)
  229. <if test="type != null and type != ''">
  230. and wo.type = #{type, jdbcType=INTEGER}
  231. </if>
  232. <if test="truckId != null and truckId != ''">
  233. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  234. </if>
  235. </select>
  236. <select id="findTicketCountByAddress" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  237. SELECT
  238. sum(wot.amount) amount,
  239. MIN(wot.operate_time) loadTime,
  240. MAX(wot.operate_time) unloadTime
  241. from kwt_waybill_order_ticket wot
  242. left join kwt_waybill_order_address woa on woa.id = wot.w_address_id
  243. left join kwt_logistics_order_address loa on loa.id = woa.l_address_id
  244. left join kwt_logistics_order lo on lo.id = loa.l_order_id
  245. left join kwt_waybill_order wo on wo.id = wot.w_order_id
  246. where wot.del_flag = 0
  247. <if test="passStatus != null and passStatus != ''">
  248. and wo.status = 502
  249. </if>
  250. <if test="wOrderId != null and wOrderId != ''">
  251. and wot.w_order_id = #{wOrderId, jdbcType=BIGINT}
  252. </if>
  253. <if test="type != null and type != ''">
  254. and wot.type = #{type, jdbcType=VARCHAR}
  255. </if>
  256. <if test="unit != null and unit != ''">
  257. and wot.unit = #{unit, jdbcType=VARCHAR}
  258. </if>
  259. <if test="lAddressId != null and lAddressId != ''">
  260. and loa.id = #{lAddressId, jdbcType=BIGINT}
  261. </if>
  262. <if test="lOrderId != null and lOrderId != ''">
  263. and lo.id = #{lOrderId, jdbcType=BIGINT}
  264. </if>
  265. <if test="upperlOrderId != null and upperlOrderId != ''">
  266. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, lo.pids)
  267. </if>
  268. </select>
  269. </mapper>