ReceiptMapper.xml 14 KB

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