OtherReceivableMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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.OtherReceivableMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. receivable_id, receivable_no, object_type, business_type, object_id, org_id, staff_id, sum_amt_receivable, acc_item_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.OtherReceivable">
  11. <id column="receivable_id" property="receivableId"/>
  12. <result column="receivable_no" property="receivableNo"/>
  13. <result column="object_type" property="objectType"/>
  14. <result column="business_type" property="businessType"/>
  15. <result column="object_id" property="objectId" typeHandler="UuidTypeHandler"/>
  16. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  17. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  18. <result column="sum_amt_receivable" property="sumAmtReceivable"/>
  19. <result column="acc_item_id" property="accItemId" typeHandler="UuidTypeHandler"/>
  20. <result column="acc_date" property="accDate" typeHandler="TimestampTypeHandler"/>
  21. <result column="remarks" property="remarks"/>
  22. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  23. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  24. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  25. <result column="flg_valid" property="flgValid"/>
  26. <result column="cp_id" property="cpId"/>
  27. </resultMap>
  28. <!-- 通用查询映射结果 -->
  29. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mac.OtherReceivableResponse">
  30. <id column="receivable_id" property="receivableId"/>
  31. <result column="receivable_no" property="receivableNo"/>
  32. <result column="object_type" property="objectType"/>
  33. <result column="business_type" property="businessType"/>
  34. <result column="object_id" property="objectId" typeHandler="UuidTypeHandler"/>
  35. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  36. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  37. <result column="sum_amt_receivable" property="sumAmtReceivable"/>
  38. <result column="acc_item_id" property="accItemId" typeHandler="UuidTypeHandler"/>
  39. <result column="acc_date" property="accDate" typeHandler="TimestampTypeHandler"/>
  40. <result column="remarks" property="remarks"/>
  41. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  42. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  43. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  44. <result column="flg_valid" property="flgValid"/>
  45. <result column="cp_id" property="cpId"/>
  46. <result column="receivable_residue" property="receivableResidue"/>
  47. <result column="receipt_residue" property="receiptResidue"/>
  48. </resultMap>
  49. <!-- 通用条件列 -->
  50. <sql id="Condition">
  51. <where>
  52. <if test="flgValid != null">
  53. AND t.flg_valid = #{flgValid}
  54. </if>
  55. <if test="receivableNo != null and receivableNo != ''">
  56. AND t.receivable_no LIKE concat('%',my_ex.likequery(#{receivableNo}),'%')
  57. </if>
  58. <if test="objectType != null and objectType != ''">
  59. AND t.object_type = #{objectType}
  60. </if>
  61. <if test="businessType != null and businessType != ''">
  62. AND t.business_type = #{businessType}
  63. </if>
  64. <if test="objectId != null and objectId != ''">
  65. AND t.object_id = #{objectId}
  66. </if>
  67. <if test="orgId != null and orgId != ''">
  68. AND t.org_id = #{orgId}
  69. </if>
  70. <if test="staffId != null and staffId != ''">
  71. AND t.staff_id = #{staffId}
  72. </if>
  73. <if test="sumAmtReceivable != null">
  74. AND t.sum_amt_receivable = #{sumAmtReceivable}
  75. </if>
  76. <if test="accItemId != null and accItemId != ''">
  77. AND t.acc_item_id = #{accItemId}
  78. </if>
  79. <if test="accDate != null">
  80. AND t.acc_date = #{accDate}
  81. </if>
  82. <if test="remarks != null and remarks != ''">
  83. AND t.remarks = #{remarks}
  84. </if>
  85. <if test="annexPaths != null and annexPaths != ''">
  86. AND t.annex_paths = #{annexPaths}
  87. </if>
  88. <if test="makeStaff != null and makeStaff != ''">
  89. AND t.make_staff = #{makeStaff}
  90. </if>
  91. <if test="cpId != null">
  92. AND t.cp_id = #{cpId}
  93. </if>
  94. <if test="cusPhone != null and cusPhone != ''">
  95. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  96. </if>
  97. <if test="cusName != null and cusName != ''">
  98. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  99. </if>
  100. <if test="orgIds != null and orgIds.size() > 0">
  101. AND t.org_id =any(#{orgIds, typeHandler=UuidListTypeHandler})
  102. </if>
  103. <if test="staffIds != null and staffIds.size() > 0">
  104. AND t.staff_id =any(#{staffIds, typeHandler=UuidListTypeHandler})
  105. </if>
  106. <if test="makeTimeStart != null and makeTimeEnd != null">
  107. AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  108. AND t.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  109. </if>
  110. <if test="flgValidList != null and flgValidList.size()>0">
  111. AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  112. </if>
  113. <if test="searchText !=null">
  114. AND ( t.receivable_no LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  115. or tmc.cus_name LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  116. </if>
  117. </where>
  118. </sql>
  119. <sql id="idsForeach">
  120. <!-- 根据主键receivableId批量操作 -->
  121. WHERE receivable_id in
  122. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  123. #{item}
  124. </foreach>
  125. </sql>
  126. <!-- 查询表t_mac_other_receivable,(条件查询+分页)列表 -->
  127. <select id="selectByCond" resultMap="BaseResultMapResponse">
  128. SELECT t.receivable_id,
  129. t.receivable_no,
  130. t.object_type,
  131. t.business_type,
  132. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "objectTypeName",
  133. t.object_id,
  134. tmc.cus_code as "cusCode",
  135. tmc.cus_name as "cusName",
  136. tmc.cus_phone as "cusPhone",
  137. t.org_id,
  138. tmo.org_name as "orgName",
  139. t.staff_id,
  140. tms.staff_name as "staffName",
  141. t.sum_amt_receivable,
  142. t.acc_item_id,
  143. t.acc_date,
  144. t.remarks,
  145. t.annex_paths,
  146. t.make_staff,
  147. makestaff.staff_name as "makeStaffName",
  148. t.make_time,
  149. t.flg_valid,
  150. t.cp_id,
  151. coalesce(tmrp.sum_amt_rec, 0) as "sumAmtRec"
  152. FROM dkic_b.t_mac_other_receivable as t
  153. left join dkic_b.t_mst_customer tmc
  154. on tmc.cus_id = t.object_id and t.object_type in ('对象类型-客户')
  155. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  156. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  157. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  158. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.object_type
  159. left join dkic_b.t_mac_rec_pay as tmrp on tmrp.flg_valid and tmrp.biznis_id = t.receivable_id
  160. <include refid="Condition"/>
  161. order by t.op_create_time desc
  162. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  163. limit #{end} offset #{start}
  164. </if>
  165. </select>
  166. <!-- 查询表t_mac_other_receivable,(条件查询)个数 -->
  167. <select id="countByCond" resultType="Long">
  168. SELECT
  169. count(1)
  170. FROM dkic_b.t_mac_other_receivable as t
  171. left join dkic_b.t_mst_customer tmc
  172. on tmc.cus_id = t.object_id and t.object_type in ('对象类型-客户')
  173. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  174. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  175. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  176. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.object_type
  177. left join dkic_b.t_mac_rec_pay as tmrp on tmrp.flg_valid and tmrp.biznis_id = t.receivable_id
  178. <include refid="Condition"/>
  179. </select>
  180. <!-- 根据主键查询表t_mac_other_receivable的一行数据 -->
  181. <select id="selectById" resultMap="BaseResultMapResponse">
  182. SELECT t.receivable_id,
  183. t.receivable_no,
  184. t.object_type,
  185. t.business_type,
  186. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "objectTypeName",
  187. t.object_id,
  188. tmc.cus_id as "cusId",
  189. tmc.cus_code as "cusCode",
  190. tmc.cus_name as "cusName",
  191. tmc.cus_phone as "cusPhone",
  192. t.org_id,
  193. tmo.org_name as "orgName",
  194. t.staff_id,
  195. tms.staff_name as "staffName",
  196. t.sum_amt_receivable,
  197. t.acc_item_id,
  198. t.acc_date,
  199. t.remarks,
  200. t.annex_paths,
  201. t.make_staff,
  202. makestaff.staff_name as "makeStaffName",
  203. t.make_time,
  204. t.flg_valid,
  205. t.cp_id,
  206. coalesce(tmrp.sum_amt_rec, 0) as "sumAmtRec"
  207. ,tma.receivable_residue
  208. ,tma.receipt_residue
  209. FROM dkic_b.t_mac_other_receivable as t
  210. left join dkic_b.t_mst_customer tmc
  211. on tmc.cus_id = t.object_id and t.object_type in ('对象类型-客户')
  212. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  213. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  214. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  215. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.object_type
  216. left join dkic_b.t_mac_rec_pay as tmrp on tmrp.flg_valid and tmrp.biznis_id = t.receivable_id
  217. LEFT JOIN dkic_b.t_mac_account tma on tma.object_id = tmc.cus_id
  218. WHERE receivable_id = #{id}::uuid
  219. </select>
  220. <!-- 根据主键锁定表t_mac_other_receivable的一行数据 -->
  221. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  222. SELECT
  223. <include refid="Base_Column_List"/>
  224. FROM dkic_b.t_mac_other_receivable
  225. WHERE receivable_id = #{id}::uuid
  226. for update
  227. </select>
  228. <!-- 根据主键锁定表t_mac_other_receivable的多行数据 -->
  229. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  230. SELECT
  231. <include refid="Base_Column_List"/>
  232. FROM dkic_b.t_mac_other_receivable
  233. <include refid="idsForeach"/>
  234. for update
  235. </select>
  236. <insert id="insertBatch">
  237. insert into dkic_b.t_mac_other_receivable
  238. (
  239. <trim suffixOverrides=",">
  240. receivable_no,
  241. object_type,
  242. business_type,
  243. object_id,
  244. org_id,
  245. staff_id,
  246. sum_amt_receivable,
  247. acc_item_id,
  248. acc_date,
  249. remarks,
  250. annex_paths,
  251. make_staff,
  252. make_time,
  253. cp_id,
  254. </trim>
  255. )
  256. values
  257. <foreach collection="list" index="index" item="item" separator=",">
  258. (
  259. <trim suffixOverrides=",">
  260. #{item.receivableNo},
  261. #{item.objectType},
  262. #{item.businessType},
  263. #{item.objectId}::uuid,
  264. #{item.orgId}::uuid,
  265. #{item.staffId}::uuid,
  266. #{item.sumAmtReceivable},
  267. #{item.accItemId}::uuid,
  268. #{item.accDate},
  269. #{item.remarks},
  270. #{item.annexPaths},
  271. #{item.makeStaff}::uuid,
  272. #{item.makeTime},
  273. #{item.cpId},
  274. </trim>
  275. )
  276. </foreach>
  277. </insert>
  278. </mapper>