AccountItemMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. <!-- 如果是退货,只差剩余应收小于0的 -->
  123. <if test="formType == 'refund'">
  124. AND t.amt_residue <![CDATA[ < ]]> 0
  125. </if>
  126. </sql>
  127. <sql id="idsForeach">
  128. <!-- 根据主键itemId批量操作 -->
  129. WHERE item_id in
  130. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  131. #{item}
  132. </foreach>
  133. </sql>
  134. <!-- 根据主键查询表t_mac_account_item的一行数据 -->
  135. <select id="selectByCond" resultMap="BaseResultMap">
  136. SELECT
  137. <include refid="Base_Column_List"/>
  138. FROM dkic_b.t_mac_account_item as t
  139. where 1 = 1
  140. <include refid="Condition"/>
  141. </select>
  142. <!-- 查询表t_mac_account_item,(条件查询)个数 -->
  143. <select id="countByCond" resultType="Long">
  144. SELECT
  145. count(1)
  146. FROM dkic_b.t_mac_account_item as t
  147. where 1 = 1
  148. <include refid="Condition"/>
  149. </select>
  150. <!--查询应收和收款汇总(根据制单员权限)-->
  151. <select id="getReceivableAccountSum" resultType="Map">
  152. SELECT SUM
  153. ( CASE WHEN tmai.acc_item_type = '账款类型-应收' THEN tmai.amt_should ELSE 0 END ) AS receivable,
  154. SUM ( CASE WHEN tmai.acc_item_type = '账款类型-收款' THEN tmai.amt_should ELSE 0 END ) AS receipt
  155. FROM
  156. dkic_b.t_mac_account_item tmai
  157. WHERE
  158. tmai.flg_valid
  159. AND tmai.cp_id = #{cpId}
  160. AND (
  161. tmai.make_staff = #{staffId}::uuid
  162. OR EXISTS ( SELECT 1 FROM dkic_b.t_mst_staff_purview tmsp WHERE tmsp.staff_id = tmai.make_staff AND tmsp.purview_code = 'PU10000003' )
  163. )
  164. <!--开始日期-->
  165. <if test="accDateStart != null">
  166. AND tmai.acc_date &gt;= #{accDateStart,typeHandler=TimestampTypeHandler}
  167. </if>
  168. <!--截止日期-->
  169. <if test="accDateEnd != null">
  170. AND tmai.acc_date &lt;= #{accDateEnd,typeHandler=TimestampTypeHandler}
  171. </if>
  172. </select>
  173. <!-- 查询应收账款明细 -->
  174. <select id="getReceivableAccountItem" resultMap="BaseResultMapResponse">
  175. SELECT t.item_id,
  176. t.item_id as "accItemId",
  177. t.acc_item_type,
  178. t.object_id,
  179. tmc.cus_code as "cusCode",
  180. tmc.cus_name as "cusName",
  181. tmc.cus_phone as "cusPhone",
  182. tmc.address_full as "addressFull",
  183. t.org_id,
  184. tmo.org_name as "orgName",
  185. t.staff_id,
  186. tms.staff_name as "staffName",
  187. t.biznis_type,
  188. t.biznis_id,
  189. t.biznis_no,
  190. t.acc_date,
  191. t.rec_status,
  192. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
  193. coalesce(sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}), '其他收入') as "biznisTypeName",
  194. t.amt_rec,
  195. t.amt_pay,
  196. t.amt_should,
  197. t.amt_handle,
  198. t.amt_waive,
  199. t.amt_residue as "amtNotHandle",
  200. t.amt_residue as "amtReceivableHandle",
  201. t.amt_residue,
  202. t.remarks,
  203. t.make_staff,
  204. t.make_time,
  205. t.flg_valid,
  206. t.cp_id
  207. FROM dkic_b.t_mac_account_item as t
  208. left join dkic_b.t_psi_outbound as tpo on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
  209. LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpo.out_type
  210. left join dkic_b.t_mac_other_receivable as tmor
  211. on tmor.receivable_id = t.biznis_id and t.biznis_type = 't_mac_other_receivable'
  212. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
  213. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  214. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  215. left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
  216. where t.flg_valid
  217. and t.acc_item_type = '账款类型-应收'
  218. and t.amt_residue <![CDATA[ <> ]]> 0
  219. <include refid="Condition"/>
  220. order by t.acc_date
  221. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  222. limit #{end} offset #{start}
  223. </if>
  224. </select>
  225. <!-- 查询应付账款明细 -->
  226. <select id="getPayableAccountItem" resultMap="BaseResultMapResponse">
  227. SELECT t.item_id,
  228. t.item_id as "accItemId",
  229. t.acc_item_type,
  230. t.object_id,
  231. supplier.sup_code as "supCode",
  232. supplier.sup_name as "supName",
  233. t.org_id,
  234. tmo.org_name as "orgName",
  235. t.staff_id,
  236. tms.staff_name as "staffName",
  237. t.biznis_type,
  238. t.biznis_id,
  239. t.biznis_no,
  240. t.acc_date,
  241. t.rec_status,
  242. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
  243. sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "biznisTypeName",
  244. t.amt_rec,
  245. t.amt_pay,
  246. t.amt_should,
  247. t.amt_handle,
  248. t.amt_waive,
  249. t.amt_residue,
  250. t.amt_residue as "amtNotHandle",
  251. t.amt_residue as "amtPayableHandle",
  252. t.remarks,
  253. t.make_staff,
  254. t.make_time,
  255. t.flg_valid,
  256. t.cp_id
  257. FROM dkic_b.t_mac_account_item as t
  258. left join dkic_b.t_psi_inbound as tpi on tpi.into_id = t.biznis_id and t.biznis_type = 't_psi_inbound'
  259. LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpi.into_type
  260. left join dkic_b.t_mst_supplier supplier on supplier.sup_id = t.object_id
  261. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  262. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  263. left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
  264. where t.flg_valid
  265. and t.acc_item_type = '账款类型-应付'
  266. and t.amt_residue <![CDATA[ <> ]]> 0
  267. <include refid="Condition"/>
  268. order by t.acc_date
  269. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  270. limit #{end} offset #{start}
  271. </if>
  272. </select>
  273. <!-- 根据主键查询表t_mac_account_item的一行数据 -->
  274. <select id="selectById" resultMap="BaseResultMap">
  275. SELECT
  276. <include refid="Base_Column_List"/>
  277. FROM dkic_b.t_mac_account_item
  278. WHERE item_id = #{itemId}::uuid
  279. </select>
  280. <!-- 根据主键锁定表t_mac_account_item的一行数据 -->
  281. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  282. SELECT
  283. <include refid="Base_Column_List"/>
  284. FROM dkic_b.t_mac_account_item
  285. WHERE item_id = #{id}::uuid
  286. for update
  287. </select>
  288. <!-- 根据主键锁定表t_mac_account_item的多行数据 -->
  289. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  290. SELECT
  291. <include refid="Base_Column_List"/>
  292. FROM dkic_b.t_mac_account_item
  293. <include refid="idsForeach"/>
  294. for update
  295. </select>
  296. <insert id="insertBatch">
  297. insert into dkic_b.t_mac_account_item
  298. (
  299. <trim suffixOverrides=",">
  300. acc_item_type,
  301. object_id,
  302. org_id,
  303. staff_id,
  304. biznis_type,
  305. biznis_id,
  306. biznis_no,
  307. acc_date,
  308. rec_status,
  309. amt_rec,
  310. amt_pay,
  311. amt_should,
  312. amt_handle,
  313. amt_waive,
  314. amt_residue,
  315. remarks,
  316. make_staff,
  317. make_time,
  318. cp_id,
  319. op_app_code,
  320. </trim>
  321. )
  322. values
  323. <foreach collection="list" index="index" item="item" separator=",">
  324. (
  325. <trim suffixOverrides=",">
  326. #{item.accItemType},
  327. #{item.objectId}::uuid,
  328. #{item.orgId}::uuid,
  329. #{item.staffId}::uuid,
  330. #{item.biznisType},
  331. #{item.biznisId}::uuid,
  332. #{item.biznisNo},
  333. #{item.accDate},
  334. #{item.recStatus},
  335. #{item.amtRec},
  336. #{item.amtPay},
  337. #{item.amtShould},
  338. #{item.amtHandle},
  339. #{item.amtWaive},
  340. #{item.amtResidue},
  341. #{item.remarks},
  342. #{item.makeStaff}::uuid,
  343. #{item.makeTime},
  344. #{item.cpId},
  345. #{item.opAppCode},
  346. </trim>
  347. )
  348. </foreach>
  349. </insert>
  350. <!-- 查询收款总额 -->
  351. <select id="getSumAmtRecPay" resultType="java.util.Map">
  352. SELECT COALESCE(sum(tmai.amt_rec), 0) as "sumAmtRec",
  353. COALESCE(sum(tmai.amt_pay), 0) as "sumAmtPay"
  354. FROM dkic_b.t_mac_account_item as tmai
  355. where tmai.flg_valid
  356. and tmai.object_id = #{id}::uuid
  357. </select>
  358. <delete id="deleteById">
  359. DELETE
  360. FROM dkic_b.t_mac_account_item
  361. WHERE item_id = #{id}::uuid;
  362. </delete>
  363. </mapper>