TradeMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.dk.oauth.mapper.TradeMapper">
  4. <!-- 通用查询列 -->
  5. <sql id="Base_Column_List">
  6. t
  7. .
  8. trade_id
  9. ,t.trade_no
  10. ,t.cp_id
  11. ,t.wx_user_id
  12. ,t.trade_amount
  13. ,t.trade_time
  14. ,t.trade_type
  15. ,t.buy_long
  16. ,t.buy_begin_date
  17. ,t.buy_end_date
  18. ,t.buy_fun_id
  19. ,t.buy_grade_code
  20. ,t.wx_trade_no
  21. ,t.extend_days
  22. ,t.dk_user_id
  23. </sql>
  24. <resultMap type="com.dk.oauth.entity.Trade" id="ResultMap">
  25. <id column="trade_id" property="tradeId"/>
  26. <result column="cp_id" property="cpId"/>
  27. <result column="trade_no" property="tradeNo"/>
  28. <result column="wx_user_id" property="wxUserId" typeHandler="UuidTypeHandler"/>
  29. <result column="trade_amount" property="tradeAmount"/>
  30. <result column="trade_time" property="tradeTime" typeHandler="TimestampTypeHandler"/>
  31. <result column="trade_type" property="tradeType"/>
  32. <result column="buy_long" property="buyLong"/>
  33. <result column="buy_begin_date" property="buyBeginDate" typeHandler="TimestampTypeHandler"/>
  34. <result column="buy_end_date" property="buyEndDate" typeHandler="TimestampTypeHandler"/>
  35. <result column="buy_fun_id" property="buyFunId" typeHandler="UuidListTypeHandler"/>
  36. <result column="buy_grade_code" property="buyGradeCode"/>
  37. <result column="wx_trade_no" property="wxTradeNo"/>
  38. <result column="extend_days" property="extendDays"/>
  39. <result column="dk_user_id" property="dkUserId" typeHandler="UuidTypeHandler"/>
  40. </resultMap>
  41. <!-- 通用查询映射结果 -->
  42. <resultMap id="BaseResultMap" type="com.dk.oauth.entity.TradeResponse">
  43. <id column="trade_id" property="tradeId"/>
  44. <result column="cp_id" property="cpId"/>
  45. <result column="trade_no" property="tradeNo"/>
  46. <result column="wx_user_id" property="wxUserId" typeHandler="UuidTypeHandler"/>
  47. <result column="trade_amount" property="tradeAmount"/>
  48. <result column="trade_time" property="tradeTime" typeHandler="TimestampTypeHandler"/>
  49. <result column="trade_type" property="tradeType"/>
  50. <result column="buy_long" property="buyLong"/>
  51. <result column="buy_begin_date" property="buyBeginDate" typeHandler="TimestampTypeHandler"/>
  52. <result column="buy_end_date" property="buyEndDate" typeHandler="TimestampTypeHandler"/>
  53. <result column="buy_fun_id" property="buyFunId" typeHandler="UuidListTypeHandler"/>
  54. <result column="buy_grade_code" property="buyGradeCode"/>
  55. <result column="wx_trade_no" property="wxtradeNo"/>
  56. <result column="extend_days" property="extendDays"/>
  57. <result column="dk_user_id" property="dkUserId" typeHandler="UuidTypeHandler"/>
  58. </resultMap>
  59. <!-- 通用条件列 -->
  60. <sql id="Condition">
  61. <where>
  62. <if test="tradeId != null and tradeId != ''">
  63. AND t.trade_id = #{tradeId}
  64. </if>
  65. <if test="tradeNo != null and tradeNo != ''">
  66. AND t.trade_no = #{tradeNo}
  67. </if>
  68. <if test="cpId != null and cpId != ''">
  69. AND t.cp_id = #{cpId}
  70. </if>
  71. <if test="wxUserId != null and wxUserId != ''">
  72. AND t.wx_user_id = #{wxUserId}::uuid
  73. </if>
  74. <if test="tradeType != null and tradeType != ''">
  75. AND t.trade_type = #{tradeType}
  76. </if>
  77. <if test="dkUserId != null and dkUserId != ''">
  78. AND t.dk_user_id = #{dkUserId}::uuid
  79. </if>
  80. </where>
  81. </sql>
  82. <!-- 根据主键查询表t_mst_staff的一行数据 -->
  83. <select id="selectById" resultMap="BaseResultMap">
  84. SELECT
  85. <include refid="Base_Column_List"/>
  86. ,g.grade_name gradeName
  87. FROM dkic_a.t_cp_trade t
  88. left join sys.t_grade g on t.buy_grade_code = g.grade_code
  89. WHERE t.trade_id = #{id}
  90. </select>
  91. <!-- 查询表t_cp_trade,(条件查询+分页)列表 -->
  92. <select id="selectTrade" resultMap="BaseResultMap">
  93. SELECT
  94. <include refid="Base_Column_List"/>
  95. ,g.grade_name gradeName
  96. FROM dkic_a.t_cp_trade t
  97. left join sys.t_grade g on t.buy_grade_code = g.grade_code
  98. <include refid="Condition"/>
  99. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  100. limit #{end} offset #{start}
  101. </if>
  102. </select>
  103. <!-- 查询表t_cp_trade,(条件查询)个数 -->
  104. <select id="countByCond" resultType="Long">
  105. SELECT
  106. count(1)
  107. FROM dkic_a.t_cp_trade t
  108. <include refid="Condition"/>
  109. </select>
  110. <!-- 更新数据-->
  111. <update id="updateById">
  112. update dkic_a.t_cp_trade set
  113. wx_trade_no = #{wxTradeNo},
  114. trade_status = #{tradeStatus}
  115. where trade_id = #{tradeId}
  116. </update>
  117. <!-- 查询表t_cp_trade,根据交易单号查数据 -->
  118. <select id="selectTradeByNo" resultMap="BaseResultMap">
  119. SELECT
  120. <include refid="Base_Column_List"/>
  121. FROM dkic_a.t_cp_trade t
  122. WHERE t.trade_no = #{tradeNo}
  123. </select>
  124. <insert id="insertBatch">
  125. insert into dkic_a.t_cp_trade
  126. (
  127. <trim suffixOverrides=",">
  128. trade_id
  129. ,trade_no
  130. ,cp_id
  131. ,wx_user_id
  132. ,trade_amount
  133. ,trade_time
  134. ,trade_type
  135. ,buy_long
  136. ,buy_begin_date
  137. ,buy_end_date
  138. ,buy_fun_id
  139. ,buy_grade_code
  140. ,wx_trade_no
  141. ,extend_days
  142. ,dk_user_id
  143. </trim>
  144. )
  145. values
  146. <foreach collection="list" index="index" item="item" separator=",">
  147. (
  148. <trim suffixOverrides=",">
  149. #{item.tradeId},
  150. #{item.tradeNo},
  151. #{item.cpId},
  152. #{item.wxUserId}::uuid,
  153. #{item.tradeAmount},
  154. #{item.tradeTime},
  155. #{item.tradeType},
  156. #{item.buyLong},
  157. #{item.buyBeginDate},
  158. #{item.buyEndDate},
  159. #{item.buyFunId}::uuid[],
  160. #{item.buyGradeCode},
  161. #{item.wxTradeNo},
  162. #{item.extendDays},
  163. #{item.dkUserId}::uuid,
  164. </trim>
  165. )
  166. </foreach>
  167. </insert>
  168. </mapper>