AccountItemMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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="selectByCond" resultMap="BaseResultMap">
  129. SELECT
  130. <include refid="Base_Column_List"/>
  131. FROM dkic_b.t_mac_account_item as t
  132. where 1 = 1
  133. <include refid="Condition"/>
  134. </select>
  135. <!-- 查询表t_mac_account_item,(条件查询)个数 -->
  136. <select id="countByCond" resultType="Long">
  137. SELECT
  138. count(1)
  139. FROM dkic_b.t_mac_account_item as t
  140. where 1 = 1
  141. <include refid="Condition"/>
  142. </select>
  143. <!-- 查询应收账款明细 -->
  144. <select id="getReceivableAccountItem" resultMap="BaseResultMapResponse">
  145. SELECT t.item_id,
  146. t.acc_item_type,
  147. t.object_id,
  148. tmc.cus_code as "cusCode",
  149. tmc.cus_name as "cusName",
  150. tmc.cus_phone as "cusPhone",
  151. tmc.address_full as "addressFull",
  152. t.org_id,
  153. tmo.org_name as "orgName",
  154. t.staff_id,
  155. tms.staff_name as "staffName",
  156. t.biznis_type,
  157. t.biznis_id,
  158. t.biznis_no,
  159. t.acc_date,
  160. t.rec_status,
  161. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
  162. t.amt_rec,
  163. t.amt_pay,
  164. t.amt_should,
  165. t.amt_handle,
  166. t.amt_waive,
  167. t.amt_residue,
  168. t.remarks,
  169. t.make_staff,
  170. t.make_time,
  171. t.flg_valid,
  172. t.cp_id
  173. FROM dkic_b.t_mac_account_item as t
  174. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
  175. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  176. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  177. left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
  178. where t.flg_valid
  179. and t.acc_item_type = '账款类型-应收'
  180. and t.amt_residue > 0
  181. <include refid="Condition"/>
  182. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  183. limit #{end} offset #{start}
  184. </if>
  185. </select>
  186. <!-- 查询应付账款明细 -->
  187. <select id="getPayableAccountItem" resultMap="BaseResultMapResponse">
  188. SELECT t.item_id,
  189. t.acc_item_type,
  190. t.object_id,
  191. tms.sup_code as "supCode",
  192. tms.sup_name as "supName",
  193. tms.contact_phone as "contactPhone",
  194. tms.return_address as "returnAddress",
  195. t.org_id,
  196. tmo.org_name as "orgName",
  197. t.staff_id,
  198. tms.staff_name as "staffName",
  199. t.biznis_type,
  200. t.biznis_id,
  201. t.biznis_no,
  202. t.acc_date,
  203. t.rec_status,
  204. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
  205. t.amt_rec,
  206. t.amt_pay,
  207. t.amt_should,
  208. t.amt_handle,
  209. t.amt_waive,
  210. t.amt_residue,
  211. t.remarks,
  212. t.make_staff,
  213. t.make_time,
  214. t.flg_valid,
  215. t.cp_id
  216. FROM dkic_b.t_mac_account_item as t
  217. left join dkic_b.t_mst_supplier tms on tms.sup_id = t.object_id
  218. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  219. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  220. left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
  221. where t.flg_valid
  222. and t.acc_item_type = '账款类型-应付'
  223. and t.amt_residue > 0
  224. <include refid="Condition"/>
  225. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  226. limit #{end} offset #{start}
  227. </if>
  228. </select>
  229. <!-- 根据主键查询表t_mac_account_item的一行数据 -->
  230. <select id="selectById" resultMap="BaseResultMap">
  231. SELECT
  232. <include refid="Base_Column_List"/>
  233. FROM dkic_b.t_mac_account_item
  234. WHERE item_id = #{itemId}::uuid
  235. </select>
  236. <!-- 根据主键锁定表t_mac_account_item的一行数据 -->
  237. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  238. SELECT
  239. <include refid="Base_Column_List"/>
  240. FROM dkic_b.t_mac_account_item
  241. WHERE item_id = #{id}::uuid
  242. for update
  243. </select>
  244. <!-- 根据主键锁定表t_mac_account_item的多行数据 -->
  245. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  246. SELECT
  247. <include refid="Base_Column_List"/>
  248. FROM dkic_b.t_mac_account_item
  249. <include refid="idsForeach"/>
  250. for update
  251. </select>
  252. <insert id="insertBatch">
  253. insert into dkic_b.t_mac_account_item
  254. (
  255. <trim suffixOverrides=",">
  256. acc_item_type,
  257. object_id,
  258. org_id,
  259. staff_id,
  260. biznis_type,
  261. biznis_id,
  262. biznis_no,
  263. acc_date,
  264. rec_status,
  265. amt_rec,
  266. amt_pay,
  267. amt_should,
  268. amt_handle,
  269. amt_waive,
  270. amt_residue,
  271. remarks,
  272. make_staff,
  273. make_time,
  274. cp_id,
  275. op_app_code,
  276. </trim>
  277. )
  278. values
  279. <foreach collection="list" index="index" item="item" separator=",">
  280. (
  281. <trim suffixOverrides=",">
  282. #{item.accItemType},
  283. #{item.objectId}::uuid,
  284. #{item.orgId}::uuid,
  285. #{item.staffId}::uuid,
  286. #{item.biznisType},
  287. #{item.biznisId}::uuid,
  288. #{item.biznisNo},
  289. #{item.accDate},
  290. #{item.recStatus},
  291. #{item.amtRec},
  292. #{item.amtPay},
  293. #{item.amtShould},
  294. #{item.amtHandle},
  295. #{item.amtWaive},
  296. #{item.amtResidue},
  297. #{item.remarks},
  298. #{item.makeStaff}::uuid,
  299. #{item.makeTime},
  300. #{item.cpId},
  301. #{item.opAppCode},
  302. </trim>
  303. )
  304. </foreach>
  305. </insert>
  306. <!-- 查询收款总额 -->
  307. <select id="getSumAmtRec" resultType="java.util.Map">
  308. SELECT sum(tmai.amt_rec) as "sumAmtRec"
  309. FROM dkic_b.t_mac_account_item as tmai
  310. where tmai.flg_valid
  311. and tmai.object_id = #{id}::uuid
  312. </select>
  313. <delete id="deleteById">
  314. DELETE
  315. FROM dkic_b.t_mac_account_item
  316. WHERE item_id = #{id}::uuid;
  317. </delete>
  318. </mapper>