AccountItemMapper.xml 14 KB

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