KwpSettlementLogisticsMapper.xml 14 KB

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