MoneyAccountMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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
  8. , mac_code, mac_name, mac_type, balance, display_no, flg_default, mac_receipt_code, acc_date, flg_negative, remarks, flg_valid, cp_id
  9. </sql>
  10. <!-- 通用查询映射结果 -->
  11. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.MoneyAccount">
  12. <id column="mac_id" property="macId"/>
  13. <result column="mac_code" property="macCode"/>
  14. <result column="mac_name" property="macName"/>
  15. <result column="mac_type" property="macType" typeHandler="UuidTypeHandler"/>
  16. <result column="balance" property="balance"/>
  17. <result column="display_no" property="displayNo"/>
  18. <result column="flg_default" property="flgDefault"/>
  19. <result column="mac_receipt_code" property="macReceiptCode" typeHandler="JsonTypeHandler"/>
  20. <result column="acc_date" property="accDate"/>
  21. <result column="flg_negative" property="flgNegative"/>
  22. <result column="remarks" property="remarks"/>
  23. <result column="flg_valid" property="flgValid"/>
  24. <result column="cp_id" property="cpId"/>
  25. </resultMap>
  26. <!-- 通用查询映射结果 -->
  27. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mst.MoneyAccountResponse">
  28. <id column="mac_id" property="macId"/>
  29. <result column="mac_code" property="macCode"/>
  30. <result column="mac_name" property="macName"/>
  31. <result column="mac_type" property="macType" typeHandler="UuidTypeHandler"/>
  32. <result column="balance" property="balance"/>
  33. <result column="display_no" property="displayNo"/>
  34. <result column="flg_default" property="flgDefault"/>
  35. <result column="mac_receipt_code" property="macReceiptCode" typeHandler="JsonTypeHandler"/>
  36. <result column="acc_date" property="accDate"/>
  37. <result column="flg_negative" property="flgNegative"/>
  38. <result column="remarks" property="remarks"/>
  39. <result column="flg_valid" property="flgValid"/>
  40. <result column="cp_id" property="cpId"/>
  41. <result column="macTypeName" property="macTypeName"/>
  42. </resultMap>
  43. <!-- 通用条件列 -->
  44. <sql id="Condition">
  45. <where>
  46. <if test="macCode != null and macCode != ''">
  47. AND t.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  48. </if>
  49. <if test="macName != null and macName != ''">
  50. AND t.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  51. </if>
  52. <if test="remarks != null and remarks != ''">
  53. AND t.remarks LIKE concat('%',my_ex.likequery(#{remarks}),'%')
  54. </if>
  55. <if test="cpId != null">
  56. AND t.cp_id = #{cpId}
  57. </if>
  58. <if test="flgValidList != null and flgValidList.size>0">
  59. AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  60. </if>
  61. <if test="flgValid != null ">
  62. AND t.flg_valid = #{flgValid}
  63. </if>
  64. <if test="flgDefault != null ">
  65. AND t.flg_default = #{flgDefault}
  66. </if>
  67. <if test="macType != null">
  68. AND t.mac_Type = #{macType} ::uuid
  69. </if>
  70. <if test="macTypeList != null and macTypeList.size() > 0">
  71. AND t.mac_Type =any(#{macTypeList, typeHandler=UuidListTypeHandler})
  72. </if>
  73. </where>
  74. </sql>
  75. <!-- 查询表t_mst_money_account,(条件查询+分页)列表 -->
  76. <select id="selectByCond" resultMap="BaseResultMapResponse">
  77. SELECT t.mac_id,
  78. <<<<<<< HEAD
  79. t.mac_code,
  80. t.mac_name,
  81. t.mac_Type,
  82. dd.data_value AS "macTypeName",
  83. t.balance,
  84. t.display_no,
  85. t.mac_receipt_code,
  86. t.acc_date,
  87. t.flg_negative,
  88. t.remarks,
  89. t.flg_valid,
  90. t.cp_id,
  91. coalesce(tmti.amt_trf, 0) as "initBalance"
  92. =======
  93. t.mac_code,
  94. t.mac_name,
  95. t.mac_Type,
  96. dd.data_value AS "macTypeName",
  97. t.balance,
  98. t.display_no,
  99. t.mac_receipt_code,
  100. t.acc_date,
  101. t.flg_negative,
  102. t.remarks,
  103. t.flg_valid,
  104. t.flg_default,
  105. t.cp_id,
  106. coalesce(tmti.amt_trf, 0) as "initBalance"
  107. >>>>>>> 83f9d270283aa09f581977351123c663d2d1f6a5
  108. FROM dkic_b.t_mst_money_account as t
  109. left join dkic_b.t_mst_dictionary_data as dd on t.mac_type = dd.data_id
  110. left join(select tmti.trf_in_mac, tmti.amt_trf
  111. from dkic_b.t_mac_transfer as tmt
  112. inner join dkic_b.t_mac_transfer_item as tmti
  113. on tmti.trf_id = tmt.trf_id and tmt.flg_valid
  114. and tmti.flg_valid and tmt.trf_type = 0) tmti
  115. on tmti.trf_in_mac = t.mac_id
  116. <include refid="Condition"/>
  117. order by t.display_no
  118. </select>
  119. <!-- 查询表t_mst_money_account,(条件查询)个数 -->
  120. <select id="countByCond" resultType="Long">
  121. SELECT count(1)
  122. FROM dkic_b.t_mst_money_account as t
  123. <include refid="Condition"/>
  124. </select>
  125. <!-- 根据主键查询表t_mst_money_account的一行数据 -->
  126. <select id="selectById" resultMap="BaseResultMapResponse">
  127. SELECT t.mac_id,
  128. t.mac_code,
  129. t.mac_name,
  130. t.mac_Type,
  131. dd.data_value AS "macTypeName",
  132. t.balance,
  133. t.display_no,
  134. t.mac_receipt_code,
  135. t.acc_date,
  136. t.flg_negative,
  137. t.remarks,
  138. t.flg_valid,
  139. t.cp_id,
  140. coalesce(tmti.amt_trf, 0) as "initBalance",
  141. t.flg_default
  142. FROM dkic_b.t_mst_money_account as t
  143. left join dkic_b.t_mst_dictionary_data as dd on t.mac_type = dd.data_id
  144. left join(select tmti.trf_in_mac, tmti.amt_trf
  145. from dkic_b.t_mac_transfer as tmt
  146. inner join dkic_b.t_mac_transfer_item as tmti
  147. on tmti.trf_id = tmt.trf_id and tmt.flg_valid
  148. and tmti.flg_valid and tmt.trf_type = 0) tmti
  149. on tmti.trf_in_mac = t.mac_id
  150. WHERE t.mac_id = #{id}::uuid
  151. </select>
  152. <!-- 王英杰 2024年3月6日 微信小程序用 -->
  153. <select id="wxSelectByCond" resultType="java.util.Map">
  154. SELECT T
  155. .*
  156. FROM
  157. (
  158. SELECT
  159. tmdd.data_id AS "macId",
  160. null AS "macType",
  161. null AS "macCode",
  162. tmdd.data_value AS "macName",
  163. null AS "Remarks",
  164. 'true' AS "flgValid",
  165. null AS "macTypeName",
  166. null AS "macId",
  167. null AS "balance",
  168. null AS "displayNo",
  169. 'true' AS "flgNegative",
  170. tmdd.cp_id
  171. FROM
  172. dkic_b.t_mst_dictionary_data tmdd
  173. WHERE
  174. tmdd.cp_id = #{cpId} and
  175. tmdd.dict_code = '基础资料-账户' UNION ALL
  176. SELECT
  177. t.mac_id AS "macId",
  178. t.mac_Type as "macType",
  179. t.mac_code AS "macCode",
  180. t.mac_name AS "macName",
  181. t.remarks AS "Remarks",
  182. t.flg_valid AS "flgValid",
  183. dd.data_value AS "macTypeName",
  184. t.mac_id AS "macId",
  185. t.balance AS "balance",
  186. t.display_no AS "displayNo",
  187. t.flg_negative as "flgNegative",
  188. t.cp_id
  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('%', my_ex.likequery(#{searchText}), '%')
  197. </if>
  198. </where>
  199. </select>
  200. <!-- 王英杰 2024年3月6日 微信小程序用 -->
  201. <select id="wxCountByCond" resultType="Long">
  202. SELECT
  203. count(1)
  204. FROM
  205. (
  206. SELECT
  207. null AS "macType",
  208. tmdd.data_value AS "macCode",
  209. null AS "macName",
  210. null AS "Remarks",
  211. null AS "flgValid",
  212. null AS "macTypeName",
  213. null AS "macId",
  214. null AS "balance",
  215. null AS "displayNo"
  216. FROM
  217. dkic_b.t_mst_dictionary_data tmdd
  218. WHERE
  219. tmdd.dict_code = '账户类别' UNION ALL
  220. SELECT
  221. t.mac_Type as "macType",
  222. t.mac_code AS "macCode",
  223. t.mac_name AS "macName",
  224. t.remarks AS "Remarks",
  225. t.flg_valid AS "flgValid",
  226. dd.data_value AS "macTypeName",
  227. t.mac_id AS "macId",
  228. t.balance AS "balance",
  229. t.display_no AS "displayNo"
  230. FROM
  231. dkic_b.t_mst_money_account as t
  232. LEFT JOIN dkic_b.t_mst_dictionary_data dd ON t.mac_type = dd.data_id
  233. <include refid="Condition"/>
  234. ) T
  235. <where>
  236. <if test="searchText !=null">
  237. AND T."macName" LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  238. </if>
  239. </where>
  240. </select>
  241. <select id="selectDisplayNo" resultType="Integer">
  242. SELECT MAX(display_no) + 1
  243. FROM dkic_b.t_mst_money_account t
  244. WHERE t.cp_id = #{cpId}
  245. </select>
  246. <!-- 根据主键锁定表t_mst_money_account的一行数据 -->
  247. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  248. SELECT
  249. <include refid="Base_Column_List"/>
  250. FROM dkic_b.t_mst_money_account
  251. WHERE mac_id = #{id}::uuid
  252. for update
  253. </select>
  254. <insert id="insertBatch">
  255. insert into dkic_b.t_mst_money_account
  256. (
  257. <trim suffixOverrides=",">
  258. mac_code,
  259. mac_name,
  260. mac_type,
  261. balance,
  262. display_no,
  263. flg_default,
  264. acc_date,
  265. flg_negative,
  266. remarks,
  267. cp_id,
  268. </trim>
  269. )
  270. values
  271. <foreach collection="list" index="index" item="item" separator=",">
  272. (
  273. <trim suffixOverrides=",">
  274. #{item.macCode},
  275. #{item.macName},
  276. #{item.macType} ::uuid,
  277. #{item.balance},
  278. #{item.displayNo},
  279. #{item.flgDefault},
  280. #{item.accDate},
  281. #{item.flgNegative},
  282. #{item.remarks},
  283. #{item.cpId},
  284. </trim>
  285. )
  286. </foreach>
  287. </insert>
  288. </mapper>