OrderMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.usual.mapper.OrderGeneralTransportMapper">
  4. <sql id="orderListWhere">
  5. ko.del_flag = 0
  6. <if test="orderListParam.startTime != null">
  7. and ko.create_time &gt;= #{orderListParam.startTime,jdbcType=TIMESTAMP}
  8. </if>
  9. <if test="orderListParam.endTime != null">
  10. and ko.create_time &lt;= #{orderListParam.endTime,jdbcType=TIMESTAMP}
  11. </if>
  12. <if test="orderListParam.orderNo != null and orderListParam.orderNo != ''">
  13. and (ko.`order_no` like concat('%', #{orderListParam.orderNo,jdbcType=VARCHAR}, '%'))
  14. </if>
  15. <if test="orderListParam.status != null">
  16. and ko.status = #{orderListParam.status}
  17. </if>
  18. <if test="orderListParam.owCompany != null and orderListParam.owCompany != ''">
  19. and ko.cy_company_id = #{owCompany}
  20. </if>
  21. <if test="orderListParam.orderSource != null">
  22. and ko.order_source = #{orderListParam.orderSource}
  23. </if>
  24. <if test="orderListParam.typeHandling != null">
  25. and ko.type_handling = #{orderListParam.typeHandling}
  26. </if>
  27. <if test="orderListParam.tenantId != null and orderListParam.tenantId != ''">
  28. and ko.tenant_id = #{orderListParam.tenantId}
  29. </if>
  30. </sql>
  31. <select id="orderList" parameterType="com.sckw.usual.entity.req.OrderListParam" resultType="com.sckw.usual.entity.res.KwOrderRes">
  32. select *
  33. from kw_order ko
  34. <where>
  35. <include refid="orderListWhere" />
  36. </where>
  37. order by ko.create_time desc
  38. </select>
  39. <select id="orderDetailbyId" resultType="com.sckw.usual.entity.res.KwOrderDetailRes">
  40. select
  41. <!-- header-->
  42. o.id,
  43. o.order_source orderSource,
  44. o.order_no orderNo,
  45. o.create_time createTime,
  46. o.create_by createBy,
  47. o.status,
  48. o.pid,
  49. o.type_handling typeHandling,
  50. <!-- 企业信息-->
  51. o.ty_company_id tyCompanId,
  52. o.ty_company tyCompany,
  53. o.ty_phone tyPhone,
  54. o.cy_company_id cyCompanyId,
  55. o.cy_company cyCompany,
  56. o.cy_phone cyPhone,
  57. o.fh_company_id fhCompanyId,
  58. o.fh_company fhCompany,
  59. o.fh_phone fhPhone,
  60. o.sh_company_id shCompanyId,
  61. o.sh_company shCompany,
  62. o.sh_phone shPhone,
  63. o.remain_num remainNum, #剩余代运量
  64. o.remain_allocation remainAllocation, #剩余代分配量
  65. o.total_load_amount totalLoadAmount,
  66. o.total_unload_amount totalUnLoadAmount,
  67. o.tenant_id tenantId,
  68. <!-- 货物信息-->
  69. tg.goods_id goodsId,
  70. tg.goods_name goodsName,
  71. tg.goods_type goodsType,
  72. tg.goods_unit goodsUnit,
  73. tg.goods_num goodsNum,
  74. tg.goods_volume goodsVolume,
  75. tg.goods_weight goodsWeight,
  76. <!-- 履约信息-->
  77. tpr.per_start_time perStartTime,
  78. tpr.per_end_time perEndTime,
  79. tpr.billing_cycle settlementCycle,
  80. tpr.pay_method payment,
  81. tpr.pay_company payCompany,
  82. tpr.billing_mode billingMode,
  83. tpr.gathering_company gatheringCompany,
  84. tpr.price,
  85. <!-- 扣亏货-->
  86. tdg.rational_loss rationalLoss,
  87. tdg.ded_price dedPrice,
  88. <!-- 更多信息-->
  89. tm.truck_type truckType,
  90. tm.truck_type_str truckTypeStr,
  91. tm.estimate_freight estimateFreight,
  92. tm.remark
  93. from kw_order o
  94. left join kw_order_usual_land_transport_more tm on o.id = tm.order_id
  95. left join kw_order_usual_land_transport_goods tg on o.id = tg.order_id
  96. left join kw_order_usual_land_transport_def_goods tdg on o.id = tdg.order_id
  97. left join kw_order_usual_transport_per tpr on o.id = tpr.order_id
  98. <where>
  99. o.del_flag = 0
  100. <if test="orderId != null">
  101. and o.id = #{orderId}
  102. </if>
  103. </where>
  104. </select>
  105. <select id="findLogisticsOrder" resultType="com.sckw.usual.entity.KwOrder"
  106. parameterType="java.util.Map">
  107. select *
  108. from kw_order
  109. where del_flag = 0
  110. <if test="id != null and id != ''">
  111. and id = #{id, jdbcType=BIGINT}
  112. </if>
  113. <if test="pid != null and pid != ''">
  114. and pid in (#{pid, jdbcType=VARCHAR})
  115. </if>
  116. <if test="status != null and status != ''">
  117. and status = #{status, jdbcType=INTEGER}
  118. </if>
  119. <if test="upperlOrderId != null and upperlOrderId != ''">
  120. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, pids)
  121. </if>
  122. <if test="belowlOrderId != null and belowlOrderId != ''">
  123. and FIND_IN_SET(id, #{belowlOrderId, jdbcType=VARCHAR})
  124. </if>
  125. <if test="ownOrderId != null and ownOrderId != ''">
  126. and id != #{ownOrderId, jdbcType=BIGINT}
  127. </if>
  128. <if test="allOrderId != null and allOrderId != ''">
  129. and (
  130. FIND_IN_SET(#{plOrderIds, jdbcType=BIGINT}
  131. , pids)
  132. or FIND_IN_SET(id
  133. , #{currentlOrderId, jdbcType=VARCHAR})
  134. )
  135. </if>
  136. <if test="checkEntId != null and checkEntId != ''">
  137. and id in (select l_order_id from kw_order_usual_land_transport_unit where unit_type = 1
  138. and top_ent_id = #{checkEntId, jdbcType=BIGINT})
  139. </if>
  140. </select>
  141. <select id="findLogisticsOrderCount" resultType="com.sckw.usual.entity.LogisticsCountVo" parameterType="java.util.Map">
  142. SELECT
  143. IFNULL(sum(load_amount), 0.0) loadAmount, IFNULL(sum(unload_amount), 0.0) unloadAmount,
  144. IFNULL(sum(total_load_amount), 0.0) totalLoadAmount, IFNULL(sum(total_unload_amount), 0.0) totalUnloadAmount
  145. from kw_order where del_flag = 0
  146. <if test="tOrderId != null and tOrderId != ''">
  147. and t_order_id = #{tOrderId, jdbcType=BIGINT}
  148. </if>
  149. <if test="lOrderId != null and lOrderId != ''">
  150. and id = #{lOrderId, jdbcType=BIGINT}
  151. </if>
  152. <if test="level != null and level != ''">
  153. and pid is null
  154. </if>
  155. <if test="finishedStatus != null and finishedStatus != ''">
  156. and status in (4, 5, 6)
  157. </if>
  158. <if test="status != null and status != ''">
  159. and status = #{lOrderId, jdbcType=INTEGER}
  160. </if>
  161. <if test="upperlOrderId != null and upperlOrderId != ''">
  162. and FIND_IN_SET(#{upperlOrderId, jdbcType=BIGINT}, pids)
  163. </if>
  164. <if test="belowlOrderId != null and belowlOrderId != ''">
  165. and FIND_IN_SET(id, #{belowlOrderId, jdbcType=VARCHAR})
  166. </if>
  167. </select>
  168. <select id="countByStatus" resultType="java.util.Map">
  169. SELECT `status`, COUNT(*) AS count FROM kw_order where del_flag = 0 GROUP BY `status`
  170. </select>
  171. <select id="finishWaybillCount" resultType="Integer">
  172. select COALESCE(count(id), 0) from kw_waybill_order where order_id = #{#orderId} and status = 5 and del_flag = 0
  173. </select>
  174. <select id="finishOrderSum" resultType="BigDecimal">
  175. select COALESCE(SUM(total_load_amount), 0) from kw_order where id = #{#orderId} and status = 9 and del_flag = 0
  176. </select>
  177. </mapper>