KwtWaybillOrderV1Mapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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="userIds != null and userIds.size() > 0">
  15. and wo.create_by IN
  16. <foreach collection="userIds" open="(" close=")" item="item" separator=",">
  17. #{item}
  18. </foreach>
  19. </if>
  20. <if test="(loadCityCode != null and loadCityCode != '') or (unloadCityCode != null and unloadCityCode != '')">
  21. and wo.id in (
  22. SELECT DISTINCT w_order_id from kwt_waybill_order_address where del_flag = 0
  23. <if test="loadCityCode != null and loadCityCode != ''">
  24. and address_type = 1
  25. and left(city_code, #{loadCityCodeLevel, jdbcType=INTEGER}) = left( #{loadCityCode, jdbcType=INTEGER}, #{loadCityCodeLevel, jdbcType=INTEGER} )
  26. </if>
  27. <if test="unloadCityCode != null and unloadCityCode != ''">
  28. and address_type = 2
  29. and left(city_code, #{loadCityCodeLevel, jdbcType=INTEGER}) = left( #{unloadCityCode, jdbcType=INTEGER}, #{loadCityCodeLevel, jdbcType=INTEGER} )
  30. </if>
  31. )
  32. </if>
  33. <if test="(startLoadTime != null and startLoadTime != '') or (endLoadTime != null and endLoadTime != '')
  34. or (startUnloadTime != null and startUnloadTime != '') or (endUnloadTime != null and endUnloadTime != '')">
  35. and wo.id in (
  36. SELECT DISTINCT w_order_id from kwt_waybill_order_subtask where del_flag = 0
  37. <if test="startLoadTime != null and startLoadTime != ''">
  38. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  39. </if>
  40. <if test="endLoadTime != null and endLoadTime != ''">
  41. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  42. </if>
  43. <if test="startUnloadTime != null and startUnloadTime != ''">
  44. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  45. </if>
  46. <if test="endUnloadTime != null and endUnloadTime != ''">
  47. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  48. </if>
  49. )
  50. </if>
  51. <if test="startSendCarTime != null and startSendCarTime != '' " >
  52. and DATE( wo.create_time) <![CDATA[ >= ]]> #{startSendCarTime,jdbcType=TIMESTAMP}
  53. </if>
  54. <if test="startSendCarTime != null and startSendCarTime != '' " >
  55. and DATE( wo.create_time ) <![CDATA[ <= ]]> #{endSendCarTime,jdbcType=TIMESTAMP}
  56. </if>
  57. <if test="keywords != null and keywords != ''">
  58. and (
  59. wo.w_order_no like concat('%',#{keywords},'%')
  60. or wo.truck_no like concat('%',#{keywords},'%')
  61. or wo.driver_name like concat('%',#{keywords},'%')
  62. )
  63. </if>
  64. GROUP BY wo.status
  65. </select>
  66. <select id="findListPage" resultType="com.sckw.transport.model.vo.WaybillOrderSelectVo"
  67. parameterType="com.sckw.transport.model.dto.WaybillOrderQueryDto">
  68. SELECT
  69. wo.id wOrderId, wo.ent_id entId, wo.w_order_no wOrderNo, wo.type, wo.truck_no truckNo, wo.driver_name driverName,
  70. wo.driver_phone driverPhone, wo.type, wo.create_time sendCarTime, wo.create_by createBy, wo.create_time createTime,
  71. wo.update_time updateTime, wo.status
  72. from kwt_waybill_order wo
  73. where wo.del_flag = 0
  74. <if test="entId != null and entId != ''">
  75. and wo.ent_id = #{entId, jdbcType=VARCHAR}
  76. </if>
  77. <if test="userIds != null and userIds.size() > 0">
  78. and wo.create_by IN
  79. <foreach collection="userIds" open="(" close=")" item="item" separator=",">
  80. #{item}
  81. </foreach>
  82. </if>
  83. <if test="queryWstatus != null and queryWstatus != ''">
  84. AND wo.status in
  85. <foreach collection="queryWstatus.split(',')" item="item" open="(" close=")" separator=",">
  86. #{item}
  87. </foreach>
  88. </if>
  89. <if test="(loadCityCode != null and loadCityCode != '') or (unloadCityCode != null and unloadCityCode != '')">
  90. and wo.id in (
  91. SELECT DISTINCT w_order_id from kwt_waybill_order_address where del_flag = 0
  92. <if test="loadCityCode != null and loadCityCode != ''">
  93. and address_type = 1
  94. and left(city_code, #{loadCityCodeLevel, jdbcType=INTEGER}) = left( #{loadCityCode, jdbcType=INTEGER}, #{loadCityCodeLevel, jdbcType=INTEGER} )
  95. </if>
  96. <if test="unloadCityCode != null and unloadCityCode != ''">
  97. and address_type = 2
  98. and left(city_code, #{unloadCityCodeLevel, jdbcType=INTEGER}) = left( #{unloadCityCode, jdbcType=INTEGER}, #{unloadCityCodeLevel, jdbcType=INTEGER} )
  99. </if>
  100. )
  101. </if>
  102. <if test="(startLoadTime != null and startLoadTime != '') or (endLoadTime != null and endLoadTime != '')
  103. or (startUnloadTime != null and startUnloadTime != '') or (endUnloadTime != null and endUnloadTime != '')">
  104. and wo.id in (
  105. SELECT DISTINCT w_order_id from kwt_waybill_order_subtask where del_flag = 0
  106. <if test="startLoadTime != null and startLoadTime != ''">
  107. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  108. </if>
  109. <if test="endLoadTime != null and endLoadTime != ''">
  110. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  111. </if>
  112. <if test="startUnloadTime != null and startUnloadTime != ''">
  113. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  114. </if>
  115. <if test="endUnloadTime != null and endUnloadTime != ''">
  116. and DATE(load_time) <![CDATA[ >= ]]> #{startLoadTime,jdbcType=TIMESTAMP}
  117. </if>
  118. )
  119. </if>
  120. <if test="startSendCarTime != null and startSendCarTime != '' " >
  121. and DATE( wo.create_time) <![CDATA[ >= ]]> #{startSendCarTime,jdbcType=TIMESTAMP}
  122. </if>
  123. <if test="endSendCarTime != null and endSendCarTime != '' " >
  124. and DATE( wo.create_time ) <![CDATA[ <= ]]> #{endSendCarTime,jdbcType=TIMESTAMP}
  125. </if>
  126. <if test="keywords != null and keywords != ''">
  127. and (
  128. wo.w_order_no like concat('%',#{keywords},'%')
  129. or wo.truck_no like concat('%',#{keywords},'%')
  130. or wo.driver_name like concat('%',#{keywords},'%')
  131. )
  132. </if>
  133. order by wo.update_time desc
  134. </select>
  135. <select id="findCapacityListPage" resultType="com.sckw.transport.model.vo.WaybillOrderSelectVo"
  136. parameterType="com.sckw.transport.model.dto.WaybillSubtaskOrderQueryDto">
  137. SELECT
  138. wo.driver_id driverId, wo.driver_name driverName, wo.driver_phone driverPhone, wo.driver_idcard driverIdcard,
  139. wo.truck_id truckId, wo.truck_no truckNo, count(1) count
  140. from kwt_waybill_order wo
  141. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  142. WHERE wo.del_flag = 0 and wos.del_flag = 0
  143. <if test="ids != null and ids != ''">
  144. AND wos.l_order_id IN
  145. <foreach collection="ids.split(',')" item="item" open="(" close=")" separator=",">
  146. #{item}
  147. </foreach>
  148. </if>
  149. </select>
  150. <select id="findStatisticsCountByDriver" resultType="java.util.Map">
  151. SELECT
  152. count(case when wo.status = 101 then 1 end) waitTotal,
  153. count(case when wo.status = 201 then 1 end) departureTotal,
  154. count(case when wo.status in (203, 301, 302, 401, 402) then 1 end) executeTotal,
  155. count(case when wo.status in (501, 502, 503, 504, 103, 202) then 1 end) endTotal
  156. from kwt_waybill_order wo
  157. where wo.del_flag = 0
  158. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  159. <if test="specialEntIds != null and specialEntIds.size() > 0">
  160. and wo.ent_id in
  161. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  162. #{item,jdbcType=BIGINT}
  163. </foreach>
  164. </if>
  165. </select>
  166. <select id="findWaybillOrderSubtask" resultType="com.sckw.transport.model.vo.WaybillOrderSubtaskVo" parameterType="java.util.Map">
  167. SELECT
  168. 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,
  169. wo.driver_idcard driverIdcard, wo.type, wo.create_time sendCarTime, wo.create_time createTime, wo.update_time updateTime, wo.status, wos.unit,
  170. wos.load_amount loadAmount, wos.unload_amount unloadAmount, wos.load_time loadTime, wos.unload_time unloadTime, wos.entrust_amount entrustAmount,
  171. wos.deficit_amount deficitAmount, wos.deficit_price deficitPrice, wos.id wSubtaskId
  172. from kwt_waybill_order wo
  173. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  174. where wo.del_flag = 0 and wos.del_flag = 0
  175. <if test="entId != null and entId != ''">
  176. and wo.ent_id = #{entId, jdbcType=BIGINT}
  177. </if>
  178. <if test="lOrderId != null and lOrderId != ''">
  179. and wos.l_order_id = #{lOrderId, jdbcType=BIGINT}
  180. </if>
  181. <if test="specialEntIds != null and specialEntIds.size() > 0">
  182. and wo.ent_id in
  183. <foreach collection="specialEntIds" item="item" open="(" close=")" separator=",">
  184. #{item,jdbcType=BIGINT}
  185. </foreach>
  186. </if>
  187. <if test="driverId != null and driverId != ''">
  188. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  189. </if>
  190. <if test="busAppStatus != null and busAppStatus != ''">
  191. and wos.status = #{busAppStatus}
  192. </if>
  193. <if test="busStatus != null and busStatus == 1">
  194. and wo.status = 101
  195. </if>
  196. <if test="busStatus != null and busStatus == 2">
  197. and wo.status = 201
  198. </if>
  199. <if test="busStatus != null and busStatus == 3">
  200. and wo.status in (203, 301, 302, 401, 402)
  201. </if>
  202. <if test="busStatus != null and busStatus == 4">
  203. and wo.status in (103, 202, 501, 502, 503, 504)
  204. </if>
  205. <if test="month != null and month != ''">
  206. and LEFT(wo.create_time, 7) = #{month, jdbcType=TIMESTAMP}
  207. </if>
  208. <if test="startTime != null and startTime != ''">
  209. and LEFT(wo.create_time, 10) <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
  210. </if>
  211. <if test="endTime != null and endTime != ''">
  212. and LEFT(wo.create_time, 10) <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
  213. </if>
  214. <if test="busStatus != null and busStatus == 2">
  215. ORDER BY wos.load_time
  216. </if>
  217. <if test="busStatus != null and busStatus == 4">
  218. ORDER BY CASE WHEN wo.status = 503 THEN wo.status * -1 ELSE wo.status END ASC, wo.update_time desc
  219. </if>
  220. </select>
  221. <select id="findCountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  222. SELECT
  223. count(case when wo.status = 502 then 1 end) totalComplete,
  224. count(case when wo.status not in (101, 102, 103, 202) then 1 end) totalTake,
  225. count(case when wo.status in (203, 301, 302, 401, 402) then 1 end) totalExecute
  226. from kwt_waybill_order wo
  227. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  228. where wo.del_flag = 0 and wos.del_flag = 0
  229. <if test="driverId != null and driverId != ''">
  230. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  231. </if>
  232. <if test="truckId != null and truckId != ''">
  233. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  234. </if>
  235. </select>
  236. <select id="findCountByLOrderId" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  237. SELECT
  238. count(case when wo.status = 502 then 1 end) totalComplete
  239. from kwt_waybill_order wo
  240. left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
  241. where wo.del_flag = 0 and wos.del_flag = 0
  242. <if test="lOrderId != null and lOrderId != ''">
  243. and wos.l_order_id = #{lOrderId, jdbcType=BIGINT}
  244. </if>
  245. </select>
  246. <select id="findAmountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  247. SELECT
  248. IFNULL(SUM(wos.load_amount), 0.0) loadAmount
  249. from kwt_waybill_order_subtask wos
  250. left join kwt_waybill_order wo on wos.w_order_id = wo.id
  251. where wo.del_flag = 0 and wos.del_flag = 0
  252. <if test="driverId != null and driverId != ''">
  253. and wo.driver_id = #{driverId, jdbcType=BIGINT}
  254. </if>
  255. <if test="truckId != null and truckId != ''">
  256. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  257. </if>
  258. </select>
  259. <select id="findUnfinishedByTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  260. SELECT count(1) totalExecute from kwt_waybill_order wo
  261. where wo.del_flag = 0
  262. and wo.status in (101, 201, 203, 301, 302, 401, 402)
  263. <if test="type != null and type != ''">
  264. and wo.type = #{type, jdbcType=INTEGER}
  265. </if>
  266. <if test="truckId != null and truckId != ''">
  267. and wo.truck_id = #{truckId, jdbcType=BIGINT}
  268. </if>
  269. </select>
  270. <select id="findTicketCountByAddress" resultType="com.sckw.transport.model.vo.WaybillCountVo">
  271. SELECT
  272. sum(wot.amount) amount,
  273. MIN(wot.operate_time) loadTime,
  274. MAX(wot.operate_time) unloadTime
  275. from kwt_waybill_order_ticket wot
  276. left join kwt_waybill_order_address woa on woa.id = wot.w_address_id
  277. left join kwt_logistics_order_address loa on loa.id = woa.l_address_id
  278. left join kwt_logistics_order lo on lo.id = loa.l_order_id
  279. left join kwt_waybill_order wo on wo.id = wot.w_order_id
  280. where wot.del_flag = 0
  281. <if test="passStatus != null and passStatus != ''">
  282. and wo.status = 502
  283. </if>
  284. <if test="wOrderId != null and wOrderId != ''">
  285. and wot.w_order_id = #{wOrderId, jdbcType=BIGINT}
  286. </if>
  287. <if test="type != null and type != ''">
  288. and wot.type = #{type, jdbcType=VARCHAR}
  289. </if>
  290. <if test="unit != null and unit != ''">
  291. and wot.unit = #{unit, jdbcType=VARCHAR}
  292. </if>
  293. <if test="lAddressId != null and lAddressId != ''">
  294. and loa.id = #{lAddressId, jdbcType=BIGINT}
  295. </if>
  296. <if test="lOrderId != null and lOrderId != ''">
  297. and lo.id = #{lOrderId, jdbcType=BIGINT}
  298. </if>
  299. <if test="upperlOrderId != null and upperlOrderId != ''">
  300. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, lo.pids)
  301. </if>
  302. </select>
  303. <select id="selectWaybillOrderCarPage" parameterType="java.util.Map" resultType="com.sckw.transport.model.dto.OrderCarDTO">
  304. SELECT
  305. kwo.id as wOrderId,
  306. kwo.w_order_no as wOrderNo,
  307. kwo.driver_id as driverId,
  308. kwo.driver_name as driverName,
  309. kwo.driver_phone as driverPhone,
  310. kwo.driver_idcard as driverCard,
  311. kwo.truck_no as truckNo,
  312. kwo.status as status,
  313. kwos.l_order_id as lOrderId,
  314. klo.l_order_no as lOrderNo,
  315. klo.t_order_id as tOrderId,
  316. klo.t_order_no as tOrderNo
  317. FROM kwt_waybill_order kwo
  318. left join kwt_waybill_order_subtask kwos on kwos.w_order_id = kwo.id
  319. LEFT JOIN kwt_logistics_order klo ON kwos.l_order_id = klo.id
  320. WHERE kwo.del_flag = 0 and kwos.del_flag = 0 and klo.del_flag = 0
  321. <if test="tOrderIds != null and tOrderIds.size() > 0">
  322. and klo.t_order_id in
  323. <foreach collection="tOrderIds" item="item" close=")" open="(" separator=",">
  324. #{item,jdbcType=BIGINT}
  325. </foreach>
  326. </if>
  327. </select>
  328. </mapper>