TruckMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.aoyang.tms.mapper.TruckMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.aoyang.tms.entity.Truck">
  6. <id column="truck_id" property="truckId" />
  7. <result column="trade_type" property="tradeType" />
  8. <result column="org_id" property="orgId" />
  9. <result column="org_name" property="orgName" />
  10. <result column="org_short_name" property="orgShortName" />
  11. <result column="truck_name" property="truckName" />
  12. <result column="car_number" property="carNumber" />
  13. <result column="engine_number" property="engineNumber" />
  14. <result column="purchase_date" property="purchaseDate" />
  15. <result column="color" property="color" />
  16. <result column="dead_weight" property="deadWeight" />
  17. <result column="capacity" property="capacity" />
  18. <result column="manufacturer" property="manufacturer" />
  19. <result column="status" property="status" />
  20. <result column="bind_status" property="bindStatus" />
  21. <result column="tms_status" property="tmsStatus" />
  22. <result column="dept_name" property="deptName" />
  23. <result column="dept_id" property="deptId" />
  24. <result column="creater" property="creater" />
  25. <result column="create_date" property="createDate" />
  26. <result column="updater" property="updater" />
  27. <result column="update_date" property="updateDate" />
  28. <result column="frame_number" property="frameNumber" />
  29. <result column="trailer_number" property="trailerNumber" />
  30. <result column="creater_name" property="createrName" />
  31. <result column="updater_name" property="updaterName" />
  32. <result column="linked" property="linked" />
  33. <result column="auto_account" property="autoAccount" />
  34. <result column="type_name" property="typeName" />
  35. <result column="owner" property="owner" />
  36. <result column="address" property="address" />
  37. <result column="use_nature" property="useNature" />
  38. <result column="vehicle_id_code" property="vehicleIdCode" />
  39. <result column="register_date" property="registerDate" />
  40. <result column="issue_date" property="issueDate" />
  41. <result column="file_no" property="fileNo" />
  42. <result column="energy_type" property="energyType" />
  43. <result column="face_url" property="faceUrl" />
  44. <result column="back_url" property="backUrl" />
  45. <result column="auth_status" property="authStatus" />
  46. <result column="auth_date" property="authDate" />
  47. <result column="level" property="level" />
  48. <result column="com_status" property="comStatus" />
  49. <result column="com_contract_status" property="comContractStatus" />
  50. </resultMap>
  51. <!-- 通用查询结果列 -->
  52. <sql id="Base_Column_List">
  53. truck_id, trade_type, org_id, org_name, org_short_name, truck_name, car_number, engine_number, purchase_date, color, dead_weight, capacity, manufacturer, status, bind_status, tms_status, dept_name, dept_id, creater, create_date, updater, update_date, frame_number, trailer_number, creater_name, updater_name, linked, auto_account, type_name, owner, address, use_nature, vehicle_id_code, register_date, issue_date, file_no, energy_type, face_url, back_url, auth_status, auth_date, level, com_status, com_contract_status
  54. </sql>
  55. <!-- 查询实时调度车辆列表 -->
  56. <select id="listTmsManageTruck" resultType="com.aoyang.tms.controller.vo.TruckOrderManageVO">
  57. SELECT * FROM (
  58. SELECT
  59. truck.truck_id as truckId, truck.tms_status as tmsStatus, truck.org_id as orgId, truck.org_name as orgName, truck.org_short_name as orgShortName,
  60. truck.car_number as carNumber, truck.trailer_number as trailerNumber, truck.dept_id as deptId, truck.dept_name as deptName,
  61. two.id as orderId, two.order_status as orderStatus, two.order_no as orderNo, two.type, two.spot_id as spotId, two.spot_name as spotName,
  62. two.shipper_id as shipperId, two.shipper_name as shipperName, two.update_date as updateDate, two.create_date as createDate, two.queue_no as queueNo, wc.id as cycleId,
  63. case when wc.jing_weight > 0 then 1 else 0 end as weightFlag, two.spot_id
  64. FROM
  65. truck
  66. left join (
  67. select * from tms_work_order wo where 40 > wo.order_status
  68. <if test="param!=null and param.loadCount == 1">
  69. and wo.type = 1 and wo.order_status in (10, 20, 30)
  70. </if>
  71. <if test="param!=null and param.loadGotoSpot == 1">
  72. and wo.type = 1 and wo.order_status = 10
  73. </if>
  74. <if test="param!=null and param.loadWait == 1">
  75. and wo.type = 1 and wo.order_status = 20
  76. </if>
  77. <if test="param!=null and param.loadSubmit == 1">
  78. and wo.type = 1 and wo.order_status = 30
  79. </if>
  80. <if test="param!=null and param.unloadCount == 1">
  81. and wo.type = 2 and wo.order_status in (10, 20, 30)
  82. </if>
  83. <if test="param!=null and param.unloadGotoSpot == 1">
  84. and wo.type = 2 and wo.order_status = 10
  85. </if>
  86. <if test="param!=null and param.unloadWait == 1">
  87. and wo.type = 2 and wo.order_status = 20
  88. </if>
  89. <if test="param!=null and param.unloadSubmit == 1">
  90. and wo.type = 2 and wo.order_status = 30
  91. </if>
  92. <if test="param!=null and param.emptyUnAllocated == 1">
  93. and wo.type = 1
  94. </if>
  95. <if test="param!=null and param.heavyUnAllocated == 1">
  96. and wo.type = 2
  97. </if>
  98. order by order_status desc, plan_reach_time asc
  99. ) two on truck.truck_id = two.truck_id
  100. left join tms_work_cycle wc on truck.truck_id = wc.truck_id and wc.status = 1
  101. where truck.org_id = #{param.orgId}
  102. <if test="param!=null and param.deptId!=null">
  103. and truck.dept_id = #{param.deptId}
  104. </if>
  105. <if test="param!=null and param.carNumber!=null and param.carNumber!=''">
  106. and (truck.car_number like concat('%',#{param.carNumber},'%') or
  107. truck.trailer_number like concat('%',#{param.carNumber},'%'))
  108. </if>
  109. <if test="param!=null and param.shipperId!=null">
  110. and two.shipper_id = #{param.shipperId}
  111. </if>
  112. <if test="param!=null and param.surplusCount == 1">
  113. and (two.id is null or two.order_status = 0)
  114. </if>
  115. <if test="param!=null and param.unExecuted == 1">
  116. and two.order_status = 0
  117. </if>
  118. <if test="param!=null and param.unAllocated == 1">
  119. and two.id is null
  120. </if>
  121. <if test="param.loadCount == 1 or param.loadWait == 1 or param.loadGotoSpot == 1 or param.loadSubmit == 1 or
  122. param.unloadCount == 1 or param.unloadGotoSpot == 1 or param.unloadWait == 1 or param.unloadSubmit == 1">
  123. and two.id is not null
  124. </if>
  125. <if test="param!=null and param.emptyUnAllocated == 1">
  126. and (wc.jing_weight = 0 or wc.jing_weight is null) and two.id is null
  127. </if>
  128. <if test="param!=null and param.heavyUnAllocated == 1">
  129. and wc.jing_weight > 0 and two.id is null
  130. </if>
  131. group by truck.truck_id
  132. ) tbl
  133. <where>
  134. <if test="param != null and param.spotId != null">
  135. and tbl.spot_id = #{param.spotId}
  136. </if>
  137. </where>
  138. ORDER BY
  139. <choose>
  140. <when test="param != null and param.spotId != null">
  141. tbl.queueNo is null, tbl.queueNo asc
  142. </when>
  143. <when test="param != null and param.sortBy != null">
  144. ${param.sortBy} ${param.sortType}
  145. </when>
  146. <otherwise>
  147. tbl.createDate desc
  148. </otherwise>
  149. </choose>
  150. </select>
  151. <!-- 查询未派单车辆 -->
  152. <select id="listUnAllocatedTruck" resultType="com.aoyang.tms.entity.Truck">
  153. SELECT
  154. <include refid="Base_Column_List"/>
  155. FROM
  156. truck left join tms_work_order wo on truck.truck_id = wo.truck_id and 40 > wo.order_status
  157. WHERE truck.org_id = #{orgId} and wo.id is null
  158. </select>
  159. <!-- 条件查询车辆数量 -->
  160. <select id="getOrgOrderCount" parameterType="com.aoyang.tms.controller.param.WorkManagePageParam" resultType="java.lang.Integer">
  161. SELECT count(1)
  162. FROM (
  163. select truck.truck_id from
  164. truck
  165. left join (
  166. select * from tms_work_order wo where 40 > wo.order_status
  167. order by order_status desc, plan_reach_time asc
  168. ) two on truck.truck_id = two.truck_id
  169. WHERE truck.org_id = #{param.orgId} and two.id is null
  170. <if test="param!=null and param.deptId!=null">
  171. and truck.dept_id = #{param.deptId}
  172. </if>
  173. <if test="param!=null and param.carNumber!=null and param.carNumber!='' ">
  174. and truck.car_number = #{param.carNumber}
  175. </if>
  176. <if test="param!=null and param.shipperId!=null">
  177. and two.shipper_id = #{param.shipperId}
  178. </if>
  179. <if test="param!=null and param.orderStatus!=null">
  180. and two.order_status = #{param.orderStatus}
  181. </if>
  182. <if test="param!=null and param.type!=null">
  183. and two.type = #{param.type}
  184. </if>
  185. group by truck.truck_id
  186. ) tbl
  187. </select>
  188. <!-- 查询总运力 -->
  189. <select id="getTotalCount" parameterType="com.aoyang.tms.controller.param.WorkManagePageParam" resultType="java.lang.Integer">
  190. SELECT count(1)
  191. FROM (
  192. select truck.truck_id FROM truck
  193. left join (
  194. select * from tms_work_order wo where 40 > wo.order_status
  195. order by order_status desc, plan_reach_time asc
  196. ) two on truck.truck_id = two.truck_id
  197. WHERE truck.org_id = #{param.orgId}
  198. <if test="param!=null and param.deptId!=null">
  199. and truck.dept_id = #{param.deptId}
  200. </if>
  201. <if test="param!=null and param.carNumber!=null and param.carNumber!='' ">
  202. and truck.car_number = #{param.carNumber}
  203. </if>
  204. <if test="param!=null and param.shipperId!=null">
  205. and two.shipper_id = #{param.shipperId}
  206. </if>
  207. group by truck.truck_id
  208. ) tbl
  209. </select>
  210. <!-- 查询未执行派单车辆 -->
  211. <select id="getUnExecutedOrderTruckCount" parameterType="com.aoyang.tms.controller.param.WorkManagePageParam" resultType="java.lang.Integer">
  212. SELECT count(1)
  213. FROM ( select truck.truck_id from truck left join tms_work_order wo on truck.truck_id = wo.truck_id and wo.order_status = 0
  214. WHERE truck.org_id = #{param.orgId} and wo.id is not null
  215. <if test="param!=null and param.deptId!=null">
  216. and truck.dept_id = #{param.deptId}
  217. </if>
  218. <if test="param!=null and param.carNumber!=null and param.carNumber!='' ">
  219. and truck.car_number = #{param.carNumber}
  220. </if>
  221. <if test="param!=null and param.shipperId!=null">
  222. and wo.shipper_id = #{param.shipperId}
  223. </if>
  224. group by truck.truck_id ) tbl
  225. </select>
  226. <!-- 查询未派单车辆 -->
  227. <select id="getUnAllocatedTruckCount" parameterType="com.aoyang.tms.controller.param.WorkManagePageParam" resultType="java.lang.Integer">
  228. SELECT count(1)
  229. FROM
  230. truck left join tms_work_order wo on truck.truck_id = wo.truck_id and 40 > wo.order_status
  231. WHERE truck.org_id = #{param.orgId} and wo.id is null
  232. <if test="param!=null and param.deptId!=null">
  233. and truck.dept_id = #{param.deptId}
  234. </if>
  235. <if test="param!=null and param.carNumber!=null and param.carNumber!='' ">
  236. and truck.car_number = #{param.carNumber}
  237. </if>
  238. <if test="param!=null and param.shipperId!=null">
  239. and wo.shipper_id = #{param.shipperId}
  240. </if>
  241. </select>
  242. <!-- 查询未派指定类型运单车车辆 -->
  243. <select id="getUnAllocatedOrderCount" parameterType="com.aoyang.tms.controller.param.WorkManagePageParam" resultType="java.lang.Integer">
  244. SELECT count(1) FROM (
  245. SELECT truck.truck_id
  246. FROM
  247. truck
  248. left join tms_work_order wo on truck.truck_id = wo.truck_id and 40 > wo.order_status
  249. <if test="param.orderType == 1">
  250. and wo.type = #{param.orderType}
  251. </if>
  252. <if test="param.orderType == 2">
  253. and wo.type = #{param.orderType}
  254. </if>
  255. left join tms_work_cycle wc on truck.truck_id = wc.truck_id and wc.status = 1
  256. WHERE truck.org_id = #{param.orgId} and wo.id is null
  257. <if test="param.orderType == 1">
  258. and ( wc.jing_weight = 0 or wc.jing_weight is null )
  259. </if>
  260. <if test="param.orderType == 2">
  261. and wc.jing_weight > 0
  262. </if>
  263. <if test="param!=null and param.deptId!=null">
  264. and truck.dept_id = #{param.deptId}
  265. </if>
  266. <if test="param!=null and param.shipperId!=null">
  267. and wo.shipper_id = #{param.shipperId}
  268. </if>
  269. <if test="param!=null and param.carNumber!=null and param.carNumber!='' ">
  270. and truck.car_number = #{param.carNumber}
  271. </if>
  272. ) tbl
  273. </select>
  274. </mapper>