StaffMapper.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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.common.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. <result column="default_wh_id" property="defaultWhId" typeHandler="UuidTypeHandler" />
  37. <result column="default_wh_name" property="defaultWhName"/>
  38. </resultMap>
  39. <!-- 通用条件列 -->
  40. <sql id="Condition">
  41. <where>
  42. <if test="staffId != null">
  43. AND t.staff_id = #{staffId}
  44. </if>
  45. <if test="staffCode != null and staffCode != ''">
  46. AND t.staff_code LIKE concat('%', my_ex.likequery(#{staffCode}), '%')
  47. </if>
  48. <if test="staffName != null and staffName != ''">
  49. AND t.staff_name LIKE concat('%', my_ex.likequery(#{staffName}), '%')
  50. </if>
  51. <if test="staffPhone != null and staffPhone != ''">
  52. AND t.staff_phone LIKE concat('%', my_ex.likequery(#{staffPhone}), '%')
  53. </if>
  54. <if test="orgId != null">
  55. AND t.org_id = #{orgId}
  56. </if>
  57. <if test="remarks != null and remarks != ''">
  58. AND t.remarks = #{remarks}
  59. </if>
  60. <if test="flgValid != null">
  61. AND t.flg_valid = #{flgValid}
  62. </if>
  63. <if test="cpId != null">
  64. AND t.cp_id = #{cpId}
  65. </if>
  66. <if test="hrStatus != null">
  67. AND t.hr_status = #{hrStatus}
  68. </if>
  69. <if test="roleIds != null and roleIds.size()>0">
  70. AND t.role_ids &amp;&amp;
  71. #{roleIds, typeHandler=UuidListTypeHandler}
  72. </if>
  73. <if test="orgIds != null and orgIds.size()>0">
  74. AND t.org_id =
  75. any(#{orgIds, typeHandler=UuidListTypeHandler})
  76. </if>
  77. <if test="searchText !=null">
  78. AND ( t.staff_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  79. or t.staff_phone LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  80. </if>
  81. </where>
  82. </sql>
  83. <!-- 查询表t_mst_staff,(条件查询+分页)列表 -->
  84. <select id="selectByCond" resultMap="BaseResultMap">
  85. SELECT
  86. <include refid="Base_Column_List"/>
  87. , org.org_name,
  88. case when t.hr_status = 1 then '在职' else '离职' end as hr_status_name,
  89. (SELECT COALESCE(array_to_string(array_agg(role_name), ','),'')
  90. FROM dkic_b.t_mst_role
  91. WHERE role_id = ANY (t.role_ids)) AS role_names
  92. FROM dkic_b.t_mst_staff t
  93. LEFT JOIN dkic_b.t_mst_org org
  94. ON t.org_Id = org.org_Id
  95. <include refid="Condition"/>
  96. ORDER BY t.op_create_time desc
  97. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  98. limit #{end} offset #{start}
  99. </if>
  100. </select>
  101. <!-- 查询表t_mst_staff,(条件查询+分页)列表 -->
  102. <select id="selectByCondByCode" resultMap="BaseResultMap">
  103. SELECT t.* FROM dkic_b.t_mst_staff t
  104. <where>
  105. <if test="staffCode != null and staffCode != ''">
  106. AND t.staff_code = #{staffCode}
  107. </if>
  108. <if test="cpId != null">
  109. AND t.cp_id = #{cpId}
  110. </if>
  111. </where>
  112. </select>
  113. <!-- 查询表t_mst_staff,(条件查询)个数 -->
  114. <select id="countByCond" resultType="Long">
  115. SELECT
  116. count(1)
  117. FROM dkic_b.t_mst_staff t
  118. <include refid="Condition"/>
  119. </select>
  120. <!-- 根据主键查询表t_mst_staff的一行数据 -->
  121. <select id="selectById" resultMap="BaseResultMap">
  122. SELECT
  123. <include refid="Base_Column_List"/>
  124. , org.org_name,
  125. case when t.hr_status = 1 then '在职' else '离职' end as hr_status_name,
  126. (SELECT COALESCE(array_to_string(array_agg(role_name), ','),'')
  127. FROM dkic_b.t_mst_role
  128. WHERE role_id = ANY (t.role_ids)) AS role_names
  129. FROM dkic_b.t_mst_staff t
  130. LEFT JOIN dkic_b.t_mst_org org ON t.org_Id = org.org_Id
  131. WHERE t.staff_id = #{id}::uuid
  132. </select>
  133. <!-- 根据用户Id查询表t_mst_staff的一行数据 -->
  134. <select id="selectByUserId" resultMap="BaseResultMap">
  135. SELECT
  136. <include refid="Base_Column_List"/>
  137. , org.org_name,
  138. CASE
  139. WHEN tmow.wh_id IS NULL THEN
  140. (SELECT wh_id FROM dkic_b.t_mst_warehouse where cp_id = T.cp_id and flg_default)
  141. ELSE tmow.wh_id
  142. END AS default_wh_id,
  143. CASE
  144. WHEN tmw.wh_name IS NULL THEN
  145. (SELECT wh_name FROM dkic_b.t_mst_warehouse where cp_id = T.cp_id and flg_default)
  146. ELSE tmw.wh_name
  147. END AS default_wh_name,
  148. case when t.hr_status = 1 then '在职' else '离职' end as hr_status_name,
  149. (SELECT COALESCE(array_to_string(array_agg(role_name), ','),'')
  150. FROM dkic_b.t_mst_role
  151. WHERE role_id = ANY (t.role_ids)) AS role_names
  152. FROM dkic_b.t_mst_staff t
  153. LEFT JOIN dkic_b.t_mst_org org ON t.org_Id = org.org_Id
  154. LEFT JOIN dkic_b.t_mst_org_wh tmow ON tmow.cp_id = T.cp_id
  155. AND tmow.org_id = T.org_id
  156. AND tmow.flg_default
  157. LEFT JOIN dkic_b.t_mst_warehouse tmw ON tmw.wh_id = tmow.wh_id
  158. WHERE t.wx_user_id = #{id}::uuid
  159. AND t.cp_id = #{cpId}
  160. </select>
  161. <!-- 根据用户Id更新dkic_a.t_wx_user的cpid-->
  162. <!-- <update id="updateWxInfoByUserId">-->
  163. <!-- update dkic_a.t_wx_user -->
  164. <!-- set current_cp = #{currentCp},joined_cps = #{currentCp}-->
  165. <!-- where user_id = #{userId}::uuid-->
  166. <!-- </update>-->
  167. <!-- 批量插入数 -->
  168. <insert id="insertBatch">
  169. insert into dkic_b.t_mst_staff
  170. (
  171. <trim suffixOverrides=",">
  172. staff_code,
  173. staff_name,
  174. staff_phone,
  175. org_id,
  176. role_ids,
  177. wx_user_id,
  178. remarks,
  179. cp_id,
  180. op_app_code,
  181. flg_can_login,
  182. </trim>
  183. )
  184. values
  185. <foreach collection="list" index="index" item="item" separator=",">
  186. (
  187. <trim suffixOverrides=",">
  188. #{item.staffCode},
  189. #{item.staffName},
  190. #{item.staffPhone},
  191. #{item.orgId}::uuid,
  192. #{item.roleIds},
  193. #{item.wxUserId}::uuid,
  194. #{item.remarks},
  195. #{item.cpId},
  196. #{item.opAppCode},
  197. #{item.flgCanLogin},
  198. </trim>
  199. )
  200. </foreach>
  201. </insert>
  202. </mapper>