KwpSettlementLogisticsMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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.payment.dao.KwpSettlementLogisticsMapper">
  4. <resultMap id="BaseResultMap" type="com.sckw.payment.model.KwpSettlementLogistics">
  5. <!--@mbg.generated-->
  6. <!--@Table kwp_settlement_logistics-->
  7. <id column="id" jdbcType="BIGINT" property="id"/>
  8. <result column="ent_id" jdbcType="BIGINT" property="entId"/>
  9. <result column="l_ledger_id" jdbcType="BIGINT" property="lLedgerId"/>
  10. <result column="sl_order_no" jdbcType="VARCHAR" property="slOrderNo"/>
  11. <result column="name" jdbcType="VARCHAR" property="name"/>
  12. <result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
  13. <result column="actual_price" jdbcType="DECIMAL" property="actualPrice"/>
  14. <result column="receipt_time" jdbcType="TIMESTAMP" property="receiptTime"/>
  15. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  16. <result column="audit_user" jdbcType="VARCHAR" property="auditUser"/>
  17. <result column="audit_phone" jdbcType="VARCHAR" property="auditPhone"/>
  18. <result column="success_user" jdbcType="VARCHAR" property="successUser"/>
  19. <result column="success_phone" jdbcType="VARCHAR" property="successPhone"/>
  20. <result column="status" jdbcType="INTEGER" property="status"/>
  21. <result column="create_by" jdbcType="BIGINT" property="createBy"/>
  22. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  23. <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
  24. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  25. <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
  26. </resultMap>
  27. <sql id="Base_Column_List">
  28. id,
  29. ent_id,
  30. l_ledger_id,
  31. sl_order_no,
  32. name,
  33. total_price,
  34. actual_price,
  35. receipt_time,
  36. remark,
  37. audit_user,
  38. audit_phone,
  39. success_user,
  40. success_phone,
  41. status,
  42. create_by,
  43. create_time,
  44. update_by,
  45. update_time,
  46. del_flag
  47. </sql>
  48. <sql id="Join_Column_List">
  49. s.id,
  50. s.ent_id as entId,
  51. s.l_ledger_id as lLedgerId,
  52. s.sl_order_no as slOrderNo,
  53. s.name,
  54. s.total_price as totalPrice,
  55. s.actual_price as actualPrice,
  56. s.receipt_time as receiptTime,
  57. s.remark,
  58. s.audit_user as auditUser,
  59. s.audit_phone as auditPhone,
  60. s.success_user as successUser,
  61. s.success_phone as successPhone,
  62. s.status,
  63. s.create_by as createBy,
  64. s.create_time as createTime,
  65. s.update_by as updateBy,
  66. s.update_time as updateTime,
  67. s.del_flag as delFlag
  68. </sql>
  69. <!-- 连表筛选准备 -->
  70. <sql id="settlementLogisticsSelect">
  71. select l.name as ledgerName,
  72. l.l_ledger_no as lLedgerNo,
  73. l.trading as trading,
  74. l.settle_price as ledgerSettlePrice,
  75. l.url as attachmentUrl,
  76. lu2.unit_type as unitType,
  77. lu2.firm_name as firmName,
  78. <include refid="Join_Column_List"/>
  79. from kwp_settlement_logistics s
  80. inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
  81. inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
  82. inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
  83. </sql>
  84. <!-- 连表筛选准备 -->
  85. <sql id="settlementLogisticsSelectSum">
  86. select count(l.id) total,
  87. sum(l.settle_price) as actualReceivable,
  88. sum(s.actual_price) as currentReceipt
  89. from kwp_settlement_logistics s
  90. inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
  91. inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
  92. inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
  93. </sql>
  94. <!-- 根据连表,查询条件准备 -->
  95. <sql id="settlementLogisticsSelectWhere">
  96. <if test="settlementReq.status != null and settlementReq.status != 0">
  97. and s.status = #{settlementReq.status}
  98. </if>
  99. <if test="settlementReq.unitType != null">
  100. and lu.unit_type = #{settlementReq.unitType,jdbcType=INTEGER}
  101. </if>
  102. <if test="settlementReq.unitTypeTwo != null">
  103. and lu2.unit_type = #{settlementReq.unitTypeTwo,jdbcType=INTEGER}
  104. </if>
  105. <if test="settlementReq.entId != null">
  106. and lu2.top_ent_id = #{settlementReq.entId,jdbcType=INTEGER}
  107. </if>
  108. <if test="settlementReq.trading != null and settlementReq.trading != ''">
  109. and l.trading = #{settlementReq.trading,jdbcType=VARCHAR}
  110. </if>
  111. <if test="settlementReq.startCreateTime != null and settlementReq.endCreateTime != null">
  112. and s.create_time between #{settlementReq.startCreateTime,jdbcType=TIMESTAMP} and #{settlementReq.endCreateTime,jdbcType=TIMESTAMP}
  113. </if>
  114. <if test="settlementReq.startReceiptTime != null and settlementReq.endReceiptTime != null">
  115. and s.receipt_time between #{settlementReq.startReceiptTime,jdbcType=TIMESTAMP} and #{settlementReq.endReceiptTime,jdbcType=TIMESTAMP}
  116. </if>
  117. <if test="settlementReq.keywords != null and settlementReq.keywords != ''">
  118. and ( l.name like concat('%'
  119. , #{settlementReq.keywords,jdbcType=VARCHAR}
  120. , '%')
  121. or lu2.firm_name like concat('%'
  122. , #{settlementReq.keywords,jdbcType=VARCHAR}
  123. , '%')
  124. or s.sl_order_no like concat('%'
  125. , #{settlementReq.keywords,jdbcType=VARCHAR}
  126. , '%')
  127. )
  128. </if>
  129. </sql>
  130. <!-- 结算运费-物流订单列表 -->
  131. <select id="pageSelect" resultType="com.sckw.payment.model.dto.SettlementLogisticsDto">
  132. <include refid="settlementLogisticsSelect"/>
  133. <where>
  134. l.del_flag = 0
  135. and s.del_flag = 0
  136. and lu.del_flag = 0
  137. and lu2.del_flag = 0
  138. <include refid="settlementLogisticsSelectWhere"/>
  139. </where>
  140. order by s.update_time desc
  141. </select>
  142. <!-- 结算运费-物流订单列表合计 -->
  143. <select id="selectSum" resultType="com.sckw.payment.model.vo.res.SettlementLogisticsSumVo">
  144. select a.*, (a.actualReceivable - a.currentReceipt) AS remainingReceivables From (
  145. <include refid="settlementLogisticsSelectSum"/>
  146. <where>
  147. l.del_flag = 0
  148. and s.del_flag = 0
  149. and lu.del_flag = 0
  150. and lu2.del_flag = 0
  151. <include refid="settlementLogisticsSelectWhere"/>
  152. </where>
  153. ) a
  154. </select>
  155. <!-- 结算运费-物流订单列表头部汇总数 -->
  156. <select id="getCountList" resultType="java.lang.Long">
  157. select count(s.id) as num
  158. from kwp_settlement_logistics s
  159. inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
  160. inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
  161. inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
  162. <where>
  163. l.del_flag = 0
  164. and s.del_flag = 0
  165. and lu.del_flag = 0
  166. and lu2.del_flag = 0
  167. <include refid="settlementLogisticsSelectWhere"/>
  168. </where>
  169. </select>
  170. <!-- 根据结算物流订单id查详情 -->
  171. <select id="detail" parameterType="java.lang.Long"
  172. resultType="com.sckw.payment.model.dto.SettlementLogisticsDto">
  173. select l.name as ledgerName,
  174. l.l_ledger_no as lLedgerNo,
  175. l.trading as trading,
  176. l.settle_price as settlePrice,
  177. l.url as attachmentUrl,
  178. lu.unit_type as unitType,
  179. lu2.firm_name as firmName,
  180. <include refid="Join_Column_List"/>
  181. from kwp_settlement_logistics s
  182. inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
  183. inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
  184. inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
  185. where s.id = #{id,jdbcType=BIGINT}
  186. <if test="unitType != null">
  187. and lu.unit_type = #{unitType,jdbcType=INTEGER}
  188. </if>
  189. <if test="unitTypeTwo != null">
  190. and lu2.unit_type = #{unitTypeTwo,jdbcType=INTEGER}
  191. </if>
  192. </select>
  193. <!-- 根据多个结算运费物流订单id查订单,用于导出 -->
  194. <select id="selectLogisticsList" resultType="com.sckw.payment.model.dto.SettlementLogisticsDto">
  195. <include refid="settlementLogisticsSelect"/>
  196. <where>
  197. l.del_flag = 0
  198. and s.del_flag = 0
  199. and lu.del_flag = 0
  200. and lu2.del_flag = 0
  201. <include refid="settlementLogisticsSelectWhere"/>
  202. <if test="ids != null and ids.size() > 0">
  203. and s.id in
  204. <foreach collection="ids" item="id" close=")" open="(" separator=",">
  205. #{id,jdbcType=BIGINT}
  206. </foreach>
  207. </if>
  208. </where>
  209. order by s.update_time desc
  210. </select>
  211. <select id="getListById" resultType="com.sckw.payment.model.dto.LedgerUnitDto">
  212. select kltu.top_ent_id,
  213. kltu.ent_id,
  214. kltu.unit_type
  215. from kwp_settlement_logistics kst
  216. inner join kwp_ledger_logistics klt on kst.l_ledger_id = klt.id and klt.del_flag = 0
  217. inner join kwp_ledger_logistics_unit kltu on klt.id = kltu.l_ledger_id and kltu.del_flag = 0
  218. <where>
  219. kst.del_flag = 0
  220. and kst.id = #{id,jdbcType=BIGINT}
  221. </where>
  222. </select>
  223. <select id="selectJoin" resultType="java.lang.String">
  224. select s.sl_order_no
  225. from kwp_settlement_logistics s
  226. inner join kwp_ledger_logistics l on s.l_ledger_id = l.id and l.del_flag = 0
  227. inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
  228. and lu.del_flag = 0 and lu.unit_type = 1
  229. inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id and lu2.del_flag = 0
  230. and lu2.unit_type = 2
  231. <where>
  232. s.del_flag = 0
  233. and s.status != 3
  234. and lu.top_ent_id = #{entId,jdbcType=BIGINT}
  235. and lu2.top_ent_id = #{entTarget,jdbcType=BIGINT}
  236. </where>
  237. </select>
  238. <select id="sumMoneyType" resultType="com.sckw.payment.model.dto.MoneyType">
  239. select ifnull(sum(ksl.total_price - ksl.actual_price), '0') money,
  240. 1 type
  241. from kwp_settlement_logistics ksl
  242. inner join kwp_ledger_logistics kll on ksl.l_ledger_id = kll.id and kll.del_flag = 0
  243. inner join kwp_ledger_logistics_unit kllu on kll.id = kllu.l_ledger_id and kllu.del_flag = 0 and
  244. kllu.unit_type = #{unitType,jdbcType=INTEGER}
  245. <where>
  246. ksl.del_flag = 0
  247. and kllu.top_ent_id = #{entId,jdbcType=BIGINT}
  248. and ksl.create_time
  249. <foreach collection="cur" item="item" open="between" close="" separator="and">
  250. #{item,jdbcType=TIMESTAMP}
  251. </foreach>
  252. </where>
  253. union all
  254. select ifnull(sum(ksl.total_price - ksl.actual_price), '0') money,
  255. 2 type
  256. from kwp_settlement_logistics ksl
  257. inner join kwp_ledger_logistics kll on ksl.l_ledger_id = kll.id and kll.del_flag = 0
  258. inner join kwp_ledger_logistics_unit kllu on kll.id = kllu.l_ledger_id and kllu.del_flag = 0 and
  259. kllu.unit_type = #{unitType,jdbcType=INTEGER}
  260. <where>
  261. ksl.del_flag = 0
  262. and kllu.top_ent_id = #{entId,jdbcType=BIGINT}
  263. and ksl.create_time
  264. <foreach collection="pre" item="item" open="between" close="" separator="and">
  265. #{item,jdbcType=TIMESTAMP}
  266. </foreach>
  267. </where>
  268. </select>
  269. </mapper>