AccountItemMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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.AccountItemMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. item_id, acc_item_type, object_id, org_id, staff_id, biznis_type, biznis_id, biznis_no, acc_date, rec_status, amt_rec, amt_pay, amt_should, amt_handle, amt_waive, amt_residue, remarks, make_staff, make_time, flg_valid
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mac.AccountItem">
  11. <id column="item_id" property="itemId"/>
  12. <result column="acc_item_type" property="accItemType"/>
  13. <result column="object_id" property="objectId" typeHandler="UuidTypeHandler"/>
  14. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  15. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  16. <result column="biznis_type" property="biznisType"/>
  17. <result column="biznis_id" property="biznisId" typeHandler="UuidTypeHandler"/>
  18. <result column="biznis_no" property="biznisNo"/>
  19. <result column="acc_date" property="accDate" typeHandler="TimestampTypeHandler"/>
  20. <result column="rec_status" property="recStatus"/>
  21. <result column="amt_rec" property="amtRec"/>
  22. <result column="amt_pay" property="amtPay"/>
  23. <result column="amt_should" property="amtShould"/>
  24. <result column="amt_handle" property="amtHandle"/>
  25. <result column="amt_waive" property="amtWaive"/>
  26. <result column="amt_residue" property="amtResidue"/>
  27. <result column="remarks" property="remarks"/>
  28. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  29. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  30. <result column="flg_valid" property="flgValid"/>
  31. <result column="cp_id" property="cpId"/>
  32. </resultMap>
  33. <!-- 通用查询映射结果 -->
  34. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mac.AccountItemResponse">
  35. <id column="item_id" property="itemId"/>
  36. <result column="acc_item_type" property="accItemType"/>
  37. <result column="object_id" property="objectId" typeHandler="UuidTypeHandler"/>
  38. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  39. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  40. <result column="biznis_type" property="biznisType"/>
  41. <result column="biznis_id" property="biznisId" typeHandler="UuidTypeHandler"/>
  42. <result column="biznis_no" property="biznisNo"/>
  43. <result column="acc_date" property="accDate" typeHandler="TimestampTypeHandler"/>
  44. <result column="rec_status" property="recStatus"/>
  45. <result column="amt_rec" property="amtRec"/>
  46. <result column="amt_pay" property="amtPay"/>
  47. <result column="amt_should" property="amtShould"/>
  48. <result column="amt_handle" property="amtHandle"/>
  49. <result column="amt_waive" property="amtWaive"/>
  50. <result column="amt_residue" property="amtResidue"/>
  51. <result column="remarks" property="remarks"/>
  52. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  53. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  54. <result column="flg_valid" property="flgValid"/>
  55. <result column="cp_id" property="cpId"/>
  56. </resultMap>
  57. <!-- 通用条件列 -->
  58. <sql id="Condition">
  59. <if test="accItemType != null and accItemType != ''">
  60. AND t.acc_item_type = #{accItemType}
  61. </if>
  62. <if test="objectId != null and objectId != ''">
  63. AND t.object_id = #{objectId}::uuid
  64. </if>
  65. <if test="orgId != null and orgId != ''">
  66. AND t.org_id = #{orgId}::uuid
  67. </if>
  68. <if test="staffId != null and staffId != ''">
  69. AND t.staff_id = #{staffId}::uuid
  70. </if>
  71. <if test="biznisType != null and biznisType != ''">
  72. AND t.biznis_type = #{biznisType}
  73. </if>
  74. <if test="biznisId != null and biznisId != ''">
  75. AND t.biznis_id = #{biznisId}
  76. </if>
  77. <if test="biznisNo != null and biznisNo != ''">
  78. AND t.biznis_no = #{biznisNo}
  79. </if>
  80. <if test="accDate != null">
  81. AND t.acc_date = #{accDate}
  82. </if>
  83. <if test="recStatus != null and recStatus != ''">
  84. AND t.rec_status = #{recStatus}
  85. </if>
  86. <if test="amtRec != null">
  87. AND t.amt_rec = #{amtRec}
  88. </if>
  89. <if test="amtPay != null">
  90. AND t.amt_pay = #{amtPay}
  91. </if>
  92. <if test="amtShould != null">
  93. AND t.amt_should = #{amtShould}
  94. </if>
  95. <if test="amtHandle != null">
  96. AND t.amt_handle = #{amtHandle}
  97. </if>
  98. <if test="amtWaive != null">
  99. AND t.amt_waive = #{amtWaive}
  100. </if>
  101. <if test="amtResidue != null">
  102. AND t.amt_residue = #{amtResidue}
  103. </if>
  104. <if test="remarks != null and remarks != ''">
  105. AND t.remarks = #{remarks}
  106. </if>
  107. <if test="makeStaff != null and makeStaff != ''">
  108. AND t.make_staff = #{makeStaff}
  109. </if>
  110. <if test="makeTime != null">
  111. AND t.make_time = #{makeTime}
  112. </if>
  113. <if test="flgValid != null">
  114. AND t.flg_valid = #{flgValid}
  115. </if>
  116. <if test="cpId != null">
  117. AND t.cp_id = #{cpId}
  118. </if>
  119. </sql>
  120. <sql id="idsForeach">
  121. <!-- 根据主键itemId批量操作 -->
  122. WHERE item_id in
  123. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  124. #{item}
  125. </foreach>
  126. </sql>
  127. <!-- 查询表t_mac_account_item,(条件查询+分页)列表 -->
  128. <select id="getPayableAccountItem" resultMap="BaseResultMapResponse">
  129. SELECT t.item_id,
  130. t.acc_item_type,
  131. t.object_id,
  132. tms.sup_code as "supCode",
  133. tms.sup_name as "supName",
  134. tms.contact_phone as "contactPhone",
  135. tms.return_address as "returnAddress",
  136. t.org_id,
  137. tmo.org_name as "orgName",
  138. t.staff_id,
  139. tms.staff_name as "staffName",
  140. t.biznis_type,
  141. t.biznis_id,
  142. t.biznis_no,
  143. t.acc_date,
  144. t.rec_status,
  145. t.amt_rec,
  146. t.amt_pay,
  147. t.amt_should,
  148. t.amt_handle,
  149. t.amt_waive,
  150. t.amt_residue,
  151. t.remarks,
  152. t.make_staff,
  153. t.make_time,
  154. t.flg_valid,
  155. t.cp_id
  156. FROM dkic_b.t_mac_account_item as t
  157. left join dkic_b.t_mst_supplier tms on tms.sup_id = t.object_id
  158. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  159. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  160. where t.flg_valid
  161. and t.acc_item_type = '账款类型-应付'
  162. <include refid="Condition"/>
  163. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  164. limit #{end} offset #{start}
  165. </if>
  166. </select>
  167. <!-- 查询表t_mac_account_item,(条件查询+分页)列表 -->
  168. <select id="selectByCond" resultMap="BaseResultMapResponse">
  169. SELECT t.item_id,
  170. t.acc_item_type,
  171. t.object_id,
  172. tmc.cus_code as "cusCode",
  173. tmc.cus_name as "cusName",
  174. tmc.cus_phone as "cusPhone",
  175. tmc.address_full as "addressFull",
  176. t.org_id,
  177. tmo.org_name as "orgName",
  178. t.staff_id,
  179. tms.staff_name as "staffName",
  180. t.biznis_type,
  181. t.biznis_id,
  182. t.biznis_no,
  183. t.acc_date,
  184. t.rec_status,
  185. t.amt_rec,
  186. t.amt_pay,
  187. t.amt_should,
  188. t.amt_handle,
  189. t.amt_waive,
  190. t.amt_residue,
  191. t.remarks,
  192. t.make_staff,
  193. t.make_time,
  194. t.flg_valid,
  195. t.cp_id
  196. FROM dkic_b.t_mac_account_item as t
  197. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
  198. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  199. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  200. where t.flg_valid
  201. and t.acc_item_type = '账款类型-应收'
  202. <include refid="Condition"/>
  203. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  204. limit #{end} offset #{start}
  205. </if>
  206. </select>
  207. <!-- 查询表t_mac_account_item,(条件查询)个数 -->
  208. <select id="countByCond" resultType="Long">
  209. SELECT
  210. count(1)
  211. FROM dkic_b.t_mac_account_item
  212. where 1=1
  213. <include refid="Condition"/>
  214. </select>
  215. <!-- 根据主键查询表t_mac_account_item的一行数据 -->
  216. <select id="selectById" resultMap="BaseResultMap">
  217. SELECT
  218. <include refid="Base_Column_List"/>
  219. FROM dkic_b.t_mac_account_item
  220. WHERE item_id = #{itemId}::uuid
  221. </select>
  222. <!-- 根据主键锁定表t_mac_account_item的一行数据 -->
  223. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  224. SELECT
  225. <include refid="Base_Column_List"/>
  226. FROM dkic_b.t_mac_account_item
  227. WHERE item_id = #{id}::uuid
  228. for update
  229. </select>
  230. <!-- 根据主键锁定表t_mac_account_item的多行数据 -->
  231. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  232. SELECT
  233. <include refid="Base_Column_List"/>
  234. FROM dkic_b.t_mac_account_item
  235. <include refid="idsForeach"/>
  236. for update
  237. </select>
  238. <insert id="insertBatch">
  239. insert into dkic_b.t_mac_account_item
  240. (
  241. <trim suffixOverrides=",">
  242. acc_item_type,
  243. object_id,
  244. org_id,
  245. staff_id,
  246. biznis_type,
  247. biznis_id,
  248. biznis_no,
  249. acc_date,
  250. rec_status,
  251. amt_rec,
  252. amt_pay,
  253. amt_should,
  254. amt_handle,
  255. amt_waive,
  256. amt_residue,
  257. remarks,
  258. make_staff,
  259. make_time,
  260. cp_id,
  261. op_app_code,
  262. </trim>
  263. )
  264. values
  265. <foreach collection="list" index="index" item="item" separator=",">
  266. (
  267. <trim suffixOverrides=",">
  268. #{item.accItemType},
  269. #{item.objectId}::uuid,
  270. #{item.orgId}::uuid,
  271. #{item.staffId}::uuid,
  272. #{item.biznisType},
  273. #{item.biznisId}::uuid,
  274. #{item.biznisNo},
  275. #{item.accDate},
  276. #{item.recStatus},
  277. #{item.amtRec},
  278. #{item.amtPay},
  279. #{item.amtShould},
  280. #{item.amtHandle},
  281. #{item.amtWaive},
  282. #{item.amtResidue},
  283. #{item.remarks},
  284. #{item.makeStaff}::uuid,
  285. #{item.makeTime},
  286. #{item.cpId},
  287. #{item.opAppCode},
  288. </trim>
  289. )
  290. </foreach>
  291. </insert>
  292. <!-- 查询收款总额 -->
  293. <select id="getSumAmtRec" resultType="java.util.Map">
  294. SELECT sum(tmai.amt_rec) as "sumAmtRec"
  295. FROM dkic_b.t_mac_account_item as tmai
  296. where tmai.flg_valid
  297. and tmai.object_id = #{id}::uuid
  298. </select>
  299. <delete id="deleteById">
  300. DELETE
  301. FROM dkic_b.t_mac_account_item
  302. WHERE item_id = #{id}::uuid;
  303. </delete>
  304. </mapper>