MacTransferMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.mac.MacTransferMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. trf_id, trf_no, trf_type, org_id, staff_id, acc_date, remarks, annex_paths, make_staff, make_time, flg_valid, cp_id
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mac.MacTransfer">
  11. <id column="trf_id" property="trfId"/>
  12. <result column="trf_no" property="trfNo"/>
  13. <result column="trf_type" property="trfType"/>
  14. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  15. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  16. <result column="acc_date" property="accDate" typeHandler="TimestampTypeHandler"/>
  17. <result column="remarks" property="remarks"/>
  18. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  19. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  20. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  21. <result column="flg_valid" property="flgValid"/>
  22. <result column="cp_id" property="cpId"/>
  23. </resultMap>
  24. <!-- 通用查询映射结果 -->
  25. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mac.MacTransferResponse">
  26. <id column="trf_id" property="trfId"/>
  27. <result column="trf_no" property="trfNo"/>
  28. <result column="trf_type" property="trfType"/>
  29. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  30. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  31. <result column="acc_date" property="accDate" typeHandler="TimestampTypeHandler"/>
  32. <result column="remarks" property="remarks"/>
  33. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  34. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  35. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  36. <result column="flg_valid" property="flgValid"/>
  37. <result column="cp_id" property="cpId"/>
  38. </resultMap>
  39. <!-- 通用条件列 -->
  40. <sql id="Condition">
  41. <where>
  42. <if test="trfNo != null and trfNo != ''">
  43. AND t.trf_no LIKE concat('%',my_ex.likequery(#{trfNo}),'%')
  44. </if>
  45. <if test="trfType != null">
  46. AND t.trf_type = #{trfType}
  47. </if>
  48. <if test="orgId != null and orgId != ''">
  49. AND org_id = #{orgId}
  50. </if>
  51. <if test="staffId != null and staffId != ''">
  52. AND staff_id = #{staffId}
  53. </if>
  54. <if test="accDate != null">
  55. AND t.acc_date = #{accDate}
  56. </if>
  57. <if test="remarks != null and remarks != ''">
  58. AND t.remarks LIKE concat('%',my_ex.likequery(#{remarks}),'%')
  59. </if>
  60. <if test="annexPaths != null and annexPaths != ''">
  61. AND t.annex_paths = #{annexPaths}
  62. </if>
  63. <if test="makeStaff != null and makeStaff != ''">
  64. AND t.make_staff = #{makeStaff}
  65. </if>
  66. <if test="cpId != null">
  67. AND t.cp_id = #{cpId}
  68. </if>
  69. <if test="orgIdList != null and orgIdList.size() > 0">
  70. AND t.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  71. </if>
  72. <if test="staffIdList != null and staffIdList.size() > 0">
  73. AND t.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  74. </if>
  75. <if test="makeTimeStart != null and makeTimeEnd != null">
  76. AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  77. AND t.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  78. </if>
  79. <if test="flgValidList != null and flgValidList.size()>0">
  80. AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  81. </if>
  82. <if test="searchText !=null">
  83. AND t.trf_no LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  84. </if>
  85. <if test="orgName !=null">
  86. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}), '%')
  87. </if>
  88. <if test="staffName !=null">
  89. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}), '%')
  90. </if>
  91. <if test="trfOutMacName !=null">
  92. AND tmmaout.mac_name LIKE concat('%',my_ex.likequery(#{trfOutMacName}), '%')
  93. </if>
  94. <if test="trfInMacName !=null">
  95. AND tmmain.mac_name LIKE concat('%',my_ex.likequery(#{trfInMacName}), '%')
  96. </if>
  97. <if test="accDateStart != null and accDateEnd != null">
  98. AND t.acc_date &gt;= #{accDateStart}::timestamp with time zone
  99. AND t.acc_date &lt; #{accDateEnd}::timestamp with time zone + interval '1 day'
  100. </if>
  101. </where>
  102. </sql>
  103. <sql id="idsForeach">
  104. <!-- 根据主键trfId批量操作 -->
  105. WHERE trf_id in
  106. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  107. #{item}
  108. </foreach>
  109. </sql>
  110. <!-- 查询表t_mac_transfer,(条件查询+分页)列表 -->
  111. <select id="selectByCond" resultMap="BaseResultMapResponse">
  112. SELECT t.trf_id,
  113. t.trf_no,
  114. t.trf_type,
  115. case when t.trf_type = 0 then '期初' else '转账' end as "trfTypeName",
  116. t.org_id,
  117. t.staff_id,
  118. t.acc_date,
  119. t.remarks,
  120. t.annex_paths,
  121. t.make_staff,
  122. t.make_time,
  123. t.flg_valid,
  124. t.cp_id,
  125. tmo.org_name as "orgName",
  126. tms.staff_name as "staffName",
  127. makestaff.staff_name as "makeStaffName"
  128. FROM dkic_b.t_mac_transfer as t
  129. left join dkic_b.t_mac_transfer_item tmti ON t.trf_id = tmti.trf_id
  130. left join dkic_b.t_mst_money_account tmmain ON tmti.trf_in_mac = tmmain.mac_id
  131. left join dkic_b.t_mst_money_account tmmaout ON tmti.trf_out_mac = tmmaout.mac_id
  132. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  133. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  134. left join dkic_b.t_mst_staff as makestaff on t.make_staff = makestaff.staff_id
  135. <include refid="Condition"/>
  136. GROUP BY T .trf_id ,
  137. tmo.org_name ,
  138. tms.staff_name ,
  139. makestaff.staff_name
  140. order by t.make_time desc
  141. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  142. limit #{end} offset #{start}
  143. </if>
  144. </select>
  145. <!-- 查询表t_mac_transfer,(条件查询)个数 -->
  146. <select id="countByCond" resultType="Long">
  147. SELECT count(1)
  148. FROM dkic_b.t_mac_transfer as t
  149. left join dkic_b.t_mac_transfer_item tmti ON t.trf_id = tmti.trf_id
  150. left join dkic_b.t_mst_money_account tmmain ON tmti.trf_in_mac = tmmain.mac_id
  151. left join dkic_b.t_mst_money_account tmmaout ON tmti.trf_out_mac = tmmaout.mac_id
  152. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  153. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  154. left join dkic_b.t_mst_staff as makestaff on t.make_staff = makestaff.staff_id
  155. <include refid="Condition"/>
  156. </select>
  157. <!-- 根据主键查询表t_mac_transfer的一行数据 -->
  158. <select id="selectById" resultMap="BaseResultMapResponse">
  159. SELECT t.trf_id,
  160. t.trf_no,
  161. t.trf_type,
  162. case when t.trf_type = 0 then '期初' else '转账' end as "trfTypeName",
  163. t.org_id,
  164. t.staff_id,
  165. t.acc_date,
  166. t.remarks,
  167. t.annex_paths,
  168. t.make_staff,
  169. t.make_time,
  170. t.flg_valid,
  171. t.cp_id,
  172. tmo.org_name as "orgName",
  173. tms.staff_name as "staffName",
  174. makestaff.staff_name as "makeStaffName"
  175. FROM dkic_b.t_mac_transfer as t
  176. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  177. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  178. left join dkic_b.t_mst_staff as makestaff on t.make_staff = makestaff.staff_id
  179. WHERE trf_id = #{id}::uuid
  180. </select>
  181. <!-- 根据主键锁定表t_mac_transfer的一行数据 -->
  182. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  183. SELECT
  184. <include refid="Base_Column_List"/>
  185. FROM dkic_b.t_mac_transfer
  186. WHERE trf_id = #{id}::uuid
  187. for update
  188. </select>
  189. <!-- 根据主键锁定表t_mac_transfer的多行数据 -->
  190. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  191. SELECT
  192. <include refid="Base_Column_List"/>
  193. FROM dkic_b.t_mac_transfer
  194. <include refid="idsForeach"/>
  195. for update
  196. </select>
  197. <insert id="insertBatch">
  198. insert into dkic_b.t_mac_transfer
  199. (
  200. <trim suffixOverrides=",">
  201. trf_no,
  202. trf_type,
  203. org_id,
  204. staff_id,
  205. acc_date,
  206. remarks,
  207. annex_paths,
  208. make_staff,
  209. make_time,
  210. cp_id,
  211. op_app_code,
  212. </trim>
  213. )
  214. values
  215. <foreach collection="list" index="index" item="item" separator=",">
  216. (
  217. <trim suffixOverrides=",">
  218. #{item.trfNo},
  219. #{item.trfType},
  220. #{item.orgId}::uuid,
  221. #{item.staffId}::uuid,
  222. #{item.accDate},
  223. #{item.remarks},
  224. #{item.annexPaths},
  225. #{item.makeStaff}::uuid,
  226. #{item.makeTime},
  227. #{item.cpId},
  228. #{item.opAppCode},
  229. </trim>
  230. )
  231. </foreach>
  232. </insert>
  233. </mapper>