MoneyAccountMapper.xml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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.mdm.mapper.mst.MoneyAccountMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. mac_id, mac_code, mac_name, mac_type, balance, display_no, flg_default, mac_receipt_code, acc_date, flg_negative, remarks, flg_valid, cp_id
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.MoneyAccount">
  11. <id column="mac_id" property="macId"/>
  12. <result column="mac_code" property="macCode"/>
  13. <result column="mac_name" property="macName"/>
  14. <result column="mac_type" property="macType" typeHandler="UuidTypeHandler"/>
  15. <result column="balance" property="balance"/>
  16. <result column="display_no" property="displayNo"/>
  17. <result column="flg_default" property="flgDefault"/>
  18. <result column="mac_receipt_code" property="macReceiptCode"/>
  19. <result column="acc_date" property="accDate"/>
  20. <result column="flg_negative" property="flgNegative"/>
  21. <result column="remarks" property="remarks"/>
  22. <result column="flg_valid" property="flgValid"/>
  23. <result column="cp_id" property="cpId"/>
  24. </resultMap>
  25. <!-- 通用查询映射结果 -->
  26. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mst.MoneyAccountResponse">
  27. <id column="mac_id" property="macId"/>
  28. <result column="mac_code" property="macCode"/>
  29. <result column="mac_name" property="macName"/>
  30. <result column="mac_type" property="macType" typeHandler="UuidTypeHandler"/>
  31. <result column="balance" property="balance"/>
  32. <result column="display_no" property="displayNo"/>
  33. <result column="flg_default" property="flgDefault"/>
  34. <result column="mac_receipt_code" property="macReceiptCode"/>
  35. <result column="acc_date" property="accDate"/>
  36. <result column="flg_negative" property="flgNegative"/>
  37. <result column="remarks" property="remarks"/>
  38. <result column="flg_valid" property="flgValid"/>
  39. <result column="cp_id" property="cpId"/>
  40. </resultMap>
  41. <!-- 通用条件列 -->
  42. <sql id="Condition">
  43. <where>
  44. <if test="macCode != null and macCode != ''">
  45. AND t.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  46. </if>
  47. <if test="macName != null and macName != ''">
  48. AND t.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  49. </if>
  50. <if test="remarks != null and remarks != ''">
  51. AND t.remarks = LIKE concat('%',my_ex.likequery(#{remarks}),'%')
  52. </if>
  53. <if test="cpId != null">
  54. AND t.cp_id = #{cpId}
  55. </if>
  56. <if test="flgValidList != null and flgValidList.size>0">
  57. AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  58. </if>
  59. <if test="flgValid != null ">
  60. AND t.flg_valid = #{flgValid}
  61. </if>
  62. <if test="macTypeList != null and macTypeList.size() > 0">
  63. AND t.mac_Type =any(#{macTypeList, typeHandler=UuidListTypeHandler})
  64. </if>
  65. </where>
  66. </sql>
  67. <!-- 查询表t_mst_money_account,(条件查询+分页)列表 -->
  68. <select id="selectByCond" resultMap="BaseResultMapResponse">
  69. SELECT t.mac_id,
  70. t.mac_code,
  71. t.mac_name,
  72. t.mac_Type,
  73. dd.data_value AS "macTypeName",
  74. t.balance,
  75. t.display_no,
  76. t.mac_receipt_code,
  77. t.acc_date,
  78. t.flg_negative,
  79. t.remarks,
  80. t.flg_valid,
  81. t.cp_id,
  82. coalesce(tmt.amt_trf, 0) as "initBalance"
  83. FROM dkic_b.t_mst_money_account as t
  84. left join dkic_b.t_mst_dictionary_data as dd on t.mac_type = dd.data_id
  85. left join dkic_b.t_mac_transfer as tmt
  86. on tmt.trf_in_mac = t.mac_id and tmt.trf_type = 0 and tmt.flg_valid
  87. <include refid="Condition"/>
  88. </select>
  89. <!-- 查询表t_mst_money_account,(条件查询)个数 -->
  90. <select id="countByCond" resultType="Long">
  91. SELECT count(1)
  92. FROM dkic_b.t_mst_money_account as t
  93. <include refid="Condition"/>
  94. </select>
  95. <!-- 根据主键查询表t_mst_money_account的一行数据 -->
  96. <select id="selectById" resultMap="BaseResultMapResponse">
  97. SELECT t.mac_id,
  98. t.mac_code,
  99. t.mac_name,
  100. t.mac_Type,
  101. dd.data_value AS "macTypeName",
  102. t.balance,
  103. t.display_no,
  104. t.mac_receipt_code,
  105. t.acc_date,
  106. t.flg_negative,
  107. t.remarks,
  108. t.flg_valid,
  109. t.cp_id,
  110. coalesce(tmt.amt_trf, 0) as "initBalance"
  111. FROM dkic_b.t_mst_money_account as t
  112. left join dkic_b.t_mst_dictionary_data as dd on t.mac_type = dd.data_id
  113. left join dkic_b.t_mac_transfer as tmt on tmt.trf_in_mac = t.mac_id and tmt.trf_type = 0
  114. WHERE t.mac_id = #{macId}::uuid
  115. </select>
  116. <!-- 王英杰 2024年3月6日 微信小程序用 -->
  117. <select id="wxSelectByCond" resultType="java.util.Map">
  118. SELECT T
  119. .*
  120. FROM
  121. (
  122. SELECT
  123. tmdd.data_id AS "macId",
  124. null AS "macType",
  125. null AS "macCode",
  126. tmdd.data_value AS "macName",
  127. null AS "Remarks",
  128. 'true' AS "flgValid",
  129. null AS "macTypeName",
  130. null AS "macId",
  131. null AS "balance",
  132. null AS "displayNo"
  133. FROM
  134. dkic_b.t_mst_dictionary_data tmdd
  135. WHERE
  136. tmdd.dict_code = '基础资料-账户' UNION ALL
  137. SELECT
  138. t.mac_id AS "macId",
  139. t.mac_Type as "macType",
  140. t.mac_code AS "macCode",
  141. t.mac_name AS "macName",
  142. t.remarks AS "Remarks",
  143. t.flg_valid AS "flgValid",
  144. dd.data_value AS "macTypeName",
  145. t.mac_id AS "macId",
  146. t.balance AS "balance",
  147. t.display_no AS "displayNo"
  148. FROM
  149. dkic_b.t_mst_money_account as t
  150. LEFT JOIN dkic_b.t_mst_dictionary_data dd ON t.mac_type = dd.data_id
  151. <include refid="Condition"/>
  152. ) T
  153. <where>
  154. <if test="searchText !=null">
  155. AND T."macName" LIKE concat('%', #{searchText}, '%')
  156. </if>
  157. </where>
  158. </select>
  159. <!-- 王英杰 2024年3月6日 微信小程序用 -->
  160. <select id="wxCountByCond" resultType="Long">
  161. SELECT
  162. count(1)
  163. FROM
  164. (
  165. SELECT
  166. null AS "macType",
  167. tmdd.data_value AS "macCode",
  168. null AS "macName",
  169. null AS "Remarks",
  170. null AS "flgValid",
  171. null AS "macTypeName",
  172. null AS "macId",
  173. null AS "balance",
  174. null AS "displayNo"
  175. FROM
  176. dkic_b.t_mst_dictionary_data tmdd
  177. WHERE
  178. tmdd.dict_code = '账户类别' UNION ALL
  179. SELECT
  180. t.mac_Type as "macType",
  181. t.mac_code AS "macCode",
  182. t.mac_name AS "macName",
  183. t.remarks AS "Remarks",
  184. t.flg_valid AS "flgValid",
  185. dd.data_value AS "macTypeName",
  186. t.mac_id AS "macId",
  187. t.balance AS "balance",
  188. t.display_no AS "displayNo"
  189. FROM
  190. dkic_b.t_mst_money_account as t
  191. LEFT JOIN dkic_b.t_mst_dictionary_data dd ON t.mac_type = dd.data_id
  192. <include refid="Condition"/>
  193. ) T
  194. <where>
  195. <if test="searchText !=null">
  196. AND T."macName" LIKE concat('%', #{searchText}, '%')
  197. </if>
  198. </where>
  199. </select>
  200. <select id="selectDisplayNo" resultType="Integer">
  201. SELECT MAX(display_no) + 1 FROM dkic_b.t_mst_money_account t
  202. WHERE t.cp_id = #{cpId}
  203. </select>
  204. <!-- 根据主键锁定表t_mst_money_account的一行数据 -->
  205. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  206. SELECT
  207. <include refid="Base_Column_List"/>
  208. FROM t_mst_money_account
  209. WHERE mac_id = #{id}::uuid
  210. for update
  211. </select>
  212. </mapper>