StaffMapper.xml 6.5 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.mst.StaffMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. t.staff_id
  8. , t.staff_code, t.staff_name,t.staff_phone, t.org_id, t.role_ids, t.wx_user_id, t.remarks,
  9. t.flg_valid,t.flg_can_login,t.hr_status,
  10. t.cp_id, t.op_create_time, t.op_create_user_id, t.op_update_time, t.op_update_user_id
  11. </sql>
  12. <!-- 通用查询映射结果 -->
  13. <resultMap id="BaseResultMap" type="com.dk.mdm.model.response.mst.StaffResponse">
  14. <id column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  15. <result column="staff_code" property="staffCode"/>
  16. <result column="staff_name" property="staffName"/>
  17. <result column="staff_phone" property="staffPhone"/>
  18. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  19. <result column="org_name" property="orgName"/>
  20. <result column="hr_status_name" property="hrStatusName"/>
  21. <result column="role_names" property="roleNames"/>
  22. <result column="role_ids" property="roleIds" typeHandler="UuidListTypeHandler"/>
  23. <result column="wx_user_id" property="wxUserId" typeHandler="UuidTypeHandler"/>
  24. <result column="remarks" property="remarks"/>
  25. <result column="flg_valid" property="flgValid"/>
  26. <result column="cp_id" property="cpId"/>
  27. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  28. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  29. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  30. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  31. <result column="op_app_code" property="opAppCode"/>
  32. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  33. <result column="op_db_user" property="opDbUser"/>
  34. <result column="flg_can_login" property="flgCanLogin"/>
  35. <result column="hr_status" property="hrStatus"/>
  36. </resultMap>
  37. <!-- 通用条件列 -->
  38. <sql id="Condition">
  39. <where>
  40. <if test="staffId != null">
  41. AND t.staff_id = #{staffId}
  42. </if>
  43. <if test="staffCode != null and staffCode != ''">
  44. AND position (#{staffCode} in t.staff_code ) >0
  45. </if>
  46. <if test="staffName != null and staffName != ''">
  47. AND position (#{staffName} in t.staff_name ) >0
  48. </if>
  49. <if test="staffPhone != null and staffPhone != ''">
  50. AND position (#{staffPhone} in t.staff_phone ) >0
  51. </if>
  52. <if test="orgId != null">
  53. AND t.org_id = #{orgId}
  54. </if>
  55. <if test="remarks != null and remarks != ''">
  56. AND t.remarks = #{remarks}
  57. </if>
  58. <if test="flgValid != null">
  59. AND t.flg_valid = #{flgValid}
  60. </if>
  61. <if test="cpId != null">
  62. AND t.cp_id = #{cpId}
  63. </if>
  64. <if test="hrStatus != null">
  65. AND t.hr_status = #{hrStatus}
  66. </if>
  67. <if test="roleIds != null and roleIds.size()>0">
  68. AND t.role_ids &amp;&amp;
  69. #{roleIds, typeHandler=UuidListTypeHandler}
  70. </if>
  71. <if test="orgIds != null and orgIds.size()>0">
  72. AND t.org_id =
  73. any(#{orgIds, typeHandler=UuidListTypeHandler})
  74. </if>
  75. <if test="searchText !=null">
  76. AND ( t.staff_name LIKE concat('%', #{searchText}, '%')
  77. or t.staff_phone LIKE concat('%', #{searchText}, '%'))
  78. </if>
  79. </where>
  80. </sql>
  81. <!-- 查询表t_mst_staff,(条件查询+分页)列表 -->
  82. <select id="selectByCond" resultMap="BaseResultMap">
  83. SELECT
  84. <include refid="Base_Column_List"/>
  85. , org.org_name,
  86. case when t.hr_status = 1 then '在职' else '离职' end as hr_status_name,
  87. (SELECT COALESCE(array_to_string(array_agg(role_name), ','),'')
  88. FROM dkic_b.t_mst_role
  89. WHERE role_id = ANY (t.role_ids)) AS role_names
  90. FROM dkic_b.t_mst_staff t
  91. LEFT JOIN dkic_b.t_mst_org org
  92. ON t.org_Id = org.org_Id
  93. <include refid="Condition"/>
  94. ORDER BY t.op_create_time desc
  95. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  96. limit #{end} offset #{start}
  97. </if>
  98. </select>
  99. <!-- 查询表t_mst_staff,(条件查询)个数 -->
  100. <select id="countByCond" resultType="Long">
  101. SELECT
  102. count(1)
  103. FROM dkic_b.t_mst_staff t
  104. <include refid="Condition"/>
  105. </select>
  106. <!-- 根据主键查询表t_mst_staff的一行数据 -->
  107. <select id="selectById" resultMap="BaseResultMap">
  108. SELECT
  109. <include refid="Base_Column_List"/>
  110. , org.org_name,
  111. case when t.hr_status = 1 then '在职' else '离职' end as hr_status_name,
  112. (SELECT COALESCE(array_to_string(array_agg(role_name), ','),'')
  113. FROM dkic_b.t_mst_role
  114. WHERE role_id = ANY (t.role_ids)) AS role_names
  115. FROM dkic_b.t_mst_staff t
  116. LEFT JOIN dkic_b.t_mst_org org ON t.org_Id = org.org_Id
  117. WHERE t.staff_id = #{staffId}::uuid
  118. </select>
  119. <insert id="insertBatch">
  120. insert into dkic_b.t_mst_staff
  121. (
  122. <trim suffixOverrides=",">
  123. staff_code,
  124. staff_name,
  125. staff_phone,
  126. org_id,
  127. role_ids,
  128. wx_user_id,
  129. remarks,
  130. cp_id,
  131. op_app_code,
  132. flg_can_login,
  133. </trim>
  134. )
  135. values
  136. <foreach collection="list" index="index" item="item" separator=",">
  137. (
  138. <trim suffixOverrides=",">
  139. #{item.staffCode},
  140. #{item.staffName},
  141. #{item.staffPhone},
  142. #{item.orgId}::uuid,
  143. #{item.roleIds},
  144. #{item.wxUserId}::uuid,
  145. #{item.remarks},
  146. #{item.cpId},
  147. #{item.opAppCode},
  148. #{item.flgCanLogin},
  149. </trim>
  150. )
  151. </foreach>
  152. </insert>
  153. </mapper>