MoneyAccountMapper.xml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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" typeHandler="JsonTypeHandler"/>
  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" typeHandler="JsonTypeHandler"/>
  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(tmti.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(select tmti.trf_in_mac, tmti.amt_trf
  86. from dkic_b.t_mac_transfer as tmt
  87. inner join dkic_b.t_mac_transfer_item as tmti
  88. on tmti.trf_id = tmt.trf_id and tmt.flg_valid
  89. and tmti.flg_valid and tmt.trf_type = 0) tmti
  90. on tmti.trf_in_mac = t.mac_id
  91. <include refid="Condition"/>
  92. order by t.display_no
  93. </select>
  94. <!-- 查询表t_mst_money_account,(条件查询)个数 -->
  95. <select id="countByCond" resultType="Long">
  96. SELECT count(1)
  97. FROM dkic_b.t_mst_money_account as t
  98. <include refid="Condition"/>
  99. </select>
  100. <!-- 根据主键查询表t_mst_money_account的一行数据 -->
  101. <select id="selectById" resultMap="BaseResultMapResponse">
  102. SELECT t.mac_id,
  103. t.mac_code,
  104. t.mac_name,
  105. t.mac_Type,
  106. dd.data_value AS "macTypeName",
  107. t.balance,
  108. t.display_no,
  109. t.mac_receipt_code,
  110. t.acc_date,
  111. t.flg_negative,
  112. t.remarks,
  113. t.flg_valid,
  114. t.cp_id,
  115. coalesce(tmti.amt_trf, 0) as "initBalance"
  116. FROM dkic_b.t_mst_money_account as t
  117. left join dkic_b.t_mst_dictionary_data as dd on t.mac_type = dd.data_id
  118. left join(select tmti.trf_in_mac, tmti.amt_trf
  119. from dkic_b.t_mac_transfer as tmt
  120. inner join dkic_b.t_mac_transfer_item as tmti
  121. on tmti.trf_id = tmt.trf_id and tmt.flg_valid
  122. and tmti.flg_valid and tmt.trf_type = 0) tmti
  123. on tmti.trf_in_mac = t.mac_id
  124. WHERE t.mac_id = #{id}::uuid
  125. </select>
  126. <!-- 王英杰 2024年3月6日 微信小程序用 -->
  127. <select id="wxSelectByCond" resultType="java.util.Map">
  128. SELECT T
  129. .*
  130. FROM
  131. (
  132. SELECT
  133. tmdd.data_id AS "macId",
  134. null AS "macType",
  135. null AS "macCode",
  136. tmdd.data_value AS "macName",
  137. null AS "Remarks",
  138. 'true' AS "flgValid",
  139. null AS "macTypeName",
  140. null AS "macId",
  141. null AS "balance",
  142. null AS "displayNo"
  143. FROM
  144. dkic_b.t_mst_dictionary_data tmdd
  145. WHERE
  146. tmdd.dict_code = '基础资料-账户' UNION ALL
  147. SELECT
  148. t.mac_id AS "macId",
  149. t.mac_Type as "macType",
  150. t.mac_code AS "macCode",
  151. t.mac_name AS "macName",
  152. t.remarks AS "Remarks",
  153. t.flg_valid AS "flgValid",
  154. dd.data_value AS "macTypeName",
  155. t.mac_id AS "macId",
  156. t.balance AS "balance",
  157. t.display_no AS "displayNo"
  158. FROM
  159. dkic_b.t_mst_money_account as t
  160. LEFT JOIN dkic_b.t_mst_dictionary_data dd ON t.mac_type = dd.data_id
  161. <include refid="Condition"/>
  162. ) T
  163. <where>
  164. <if test="searchText !=null">
  165. AND T."macName" LIKE concat('%', #{searchText}, '%')
  166. </if>
  167. </where>
  168. </select>
  169. <!-- 王英杰 2024年3月6日 微信小程序用 -->
  170. <select id="wxCountByCond" resultType="Long">
  171. SELECT
  172. count(1)
  173. FROM
  174. (
  175. SELECT
  176. null AS "macType",
  177. tmdd.data_value AS "macCode",
  178. null AS "macName",
  179. null AS "Remarks",
  180. null AS "flgValid",
  181. null AS "macTypeName",
  182. null AS "macId",
  183. null AS "balance",
  184. null AS "displayNo"
  185. FROM
  186. dkic_b.t_mst_dictionary_data tmdd
  187. WHERE
  188. tmdd.dict_code = '账户类别' UNION ALL
  189. SELECT
  190. t.mac_Type as "macType",
  191. t.mac_code AS "macCode",
  192. t.mac_name AS "macName",
  193. t.remarks AS "Remarks",
  194. t.flg_valid AS "flgValid",
  195. dd.data_value AS "macTypeName",
  196. t.mac_id AS "macId",
  197. t.balance AS "balance",
  198. t.display_no AS "displayNo"
  199. FROM
  200. dkic_b.t_mst_money_account as t
  201. LEFT JOIN dkic_b.t_mst_dictionary_data dd ON t.mac_type = dd.data_id
  202. <include refid="Condition"/>
  203. ) T
  204. <where>
  205. <if test="searchText !=null">
  206. AND T."macName" LIKE concat('%', #{searchText}, '%')
  207. </if>
  208. </where>
  209. </select>
  210. <select id="selectDisplayNo" resultType="Integer">
  211. SELECT MAX(display_no) + 1 FROM dkic_b.t_mst_money_account t
  212. WHERE t.cp_id = #{cpId}
  213. </select>
  214. <!-- 根据主键锁定表t_mst_money_account的一行数据 -->
  215. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  216. SELECT
  217. <include refid="Base_Column_List"/>
  218. FROM dkic_b.t_mst_money_account
  219. WHERE mac_id = #{id}::uuid
  220. for update
  221. </select>
  222. </mapper>