MultiOwnerMapper.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.sale.MultiOwnerMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. multi_id, order_id, owner_type, owner_id, allocation_ratio, flg_valid, cp_id
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.sale.MultiOwner">
  11. <id column="multi_id" property="multiId"/>
  12. <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
  13. <result column="owner_type" property="ownerType"/>
  14. <result column="owner_id" property="ownerId" typeHandler="UuidTypeHandler"/>
  15. <result column="allocation_ratio" property="allocationRatio"/>
  16. <result column="flg_valid" property="flgValid"/>
  17. <result column="cp_id" property="cpId"/>
  18. </resultMap>
  19. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.sale.MultiOwnerResponse">
  20. <id column="multi_id" property="multiId"/>
  21. <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
  22. <result column="owner_type" property="ownerType"/>
  23. <result column="owner_id" property="ownerId" typeHandler="UuidTypeHandler"/>
  24. <result column="allocation_ratio" property="allocationRatio"/>
  25. <result column="flg_valid" property="flgValid"/>
  26. <result column="cp_id" property="cpId"/>
  27. <result column="staff_id" property="staffId"/>
  28. <result column="staff_name" property="staffName"/>
  29. <result column="org_id" property="orgId"/>
  30. <result column="org_name" property="orgName"/>
  31. </resultMap>
  32. <!-- 通用条件列 -->
  33. <sql id="Condition">
  34. <where>
  35. <if test="orderId != null and orderId != ''">
  36. AND order_id = #{orderId}
  37. </if>
  38. <if test="ownerType != null and ownerType != ''">
  39. AND owner_type = #{ownerType}
  40. </if>
  41. <if test="ownerId != null and ownerId != ''">
  42. AND owner_id = #{ownerId}
  43. </if>
  44. <if test="allocationRatio != null">
  45. AND allocation_ratio = #{allocationRatio}
  46. </if>
  47. <if test="flgValid != null">
  48. AND flg_valid = #{flgValid}
  49. </if>
  50. <if test="cpId != null">
  51. AND cp_id = #{cpId}
  52. </if>
  53. </where>
  54. </sql>
  55. <sql id="idsForeach">
  56. <!-- 根据主键multiId批量操作 -->
  57. WHERE multi_id in
  58. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  59. #{item}
  60. </foreach>
  61. </sql>
  62. <!-- 查询表t_psi_multi_owner,(条件查询+分页)列表 -->
  63. <select id="selectByCond" resultMap="BaseResultMap">
  64. SELECT
  65. <include refid="Base_Column_List"/>
  66. FROM dkic_b.t_psi_multi_owner
  67. <include refid="Condition"/>
  68. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  69. limit #{end} offset #{start}
  70. </if>
  71. </select>
  72. <!-- 查询表t_psi_multi_owner,(条件查询)个数 -->
  73. <select id="countByCond" resultType="Long">
  74. SELECT
  75. count(1)
  76. FROM dkic_b.t_psi_multi_owner
  77. <include refid="Condition"/>
  78. </select>
  79. <!-- 根据主键查询表t_psi_multi_owner的一行数据 -->
  80. <select id="selectById" resultMap="BaseResultMap">
  81. SELECT
  82. <include refid="Base_Column_List"/>
  83. FROM dkic_b.t_psi_multi_owner
  84. WHERE multi_id = #{id}::uuid
  85. </select>
  86. <!-- 根据主键锁定表t_psi_multi_owner的一行数据 -->
  87. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  88. SELECT
  89. <include refid="Base_Column_List"/>
  90. FROM dkic_b.t_psi_multi_owner
  91. WHERE multi_id = #{id}::uuid
  92. for update
  93. </select>
  94. <!-- 根据主键锁定表t_psi_multi_owner的多行数据 -->
  95. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  96. SELECT
  97. <include refid="Base_Column_List"/>
  98. FROM dkic_b.t_psi_multi_owner
  99. <include refid="idsForeach"/>
  100. for update
  101. </select>
  102. <insert id="insertBatch">
  103. insert into dkic_b.t_psi_multi_owner
  104. (
  105. <trim suffixOverrides=",">
  106. order_id,
  107. owner_type,
  108. owner_id,
  109. allocation_ratio,
  110. cp_id,
  111. op_app_code,
  112. </trim>
  113. )
  114. values
  115. <foreach collection="list" index="index" item="item" separator=",">
  116. (
  117. <trim suffixOverrides=",">
  118. #{item.orderId}::uuid,
  119. #{item.ownerType},
  120. #{item.ownerId}::uuid,
  121. #{item.allocationRatio},
  122. #{item.cpId},
  123. #{item.opAppCode},
  124. </trim>
  125. )
  126. </foreach>
  127. </insert>
  128. <delete id="deleteByOrderId">
  129. DELETE FROM dkic_b.t_psi_multi_owner WHERE order_id = #{orderId}::uuid
  130. </delete>
  131. <!-- 查询表t_psi_multi_owner,(条件查询+分页)列表 -->
  132. <select id="selectByType" resultMap="BaseResultMapResponse">
  133. SELECT tpmo.multi_id,
  134. tpmo.order_id,
  135. tpmo.owner_type,
  136. tpmo.owner_id,
  137. tpmo.allocation_ratio,
  138. tpmo.flg_valid,
  139. tpmo.cp_id,
  140. tms.staff_id,
  141. tms.staff_name,
  142. tmo.org_id,
  143. tmo.org_name
  144. FROM dkic_b.t_psi_multi_owner tpmo
  145. left join dkic_b.t_mst_staff tms on tms.staff_id = tpmo.owner_id
  146. left join dkic_b.t_mst_org tmo on tmo.org_id = tpmo.owner_id
  147. where tpmo.order_id = #{orderId}::uuid AND tpmo.owner_type = ANY ( #{ownerTypes, typeHandler=StringListTypeHandler} )
  148. </select>
  149. </mapper>