| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.dk.mdm.mapper.mst.StaffMapper">
- <!-- 通用设置 -->
- <!-- 通用查询列 -->
- <sql id="Base_Column_List">
- t.staff_id
- , t.staff_code, t.staff_name,t.staff_phone, t.org_id, t.role_ids, t.wx_user_id, t.remarks,
- t.flg_valid,t.flg_can_login,t.hr_status,
- t.cp_id, t.op_create_time, t.op_create_user_id, t.op_update_time, t.op_update_user_id
- </sql>
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dk.mdm.model.response.mst.StaffResponse">
- <id column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
- <result column="staff_code" property="staffCode"/>
- <result column="staff_name" property="staffName"/>
- <result column="staff_phone" property="staffPhone"/>
- <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
- <result column="org_name" property="orgName"/>
- <result column="hr_status_name" property="hrStatusName"/>
- <result column="role_names" property="roleNames"/>
- <result column="role_ids" property="roleIds" typeHandler="UuidListTypeHandler"/>
- <result column="wx_user_id" property="wxUserId" typeHandler="UuidTypeHandler"/>
- <result column="remarks" property="remarks"/>
- <result column="flg_valid" property="flgValid"/>
- <result column="cp_id" property="cpId"/>
- <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
- <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
- <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
- <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
- <result column="op_app_code" property="opAppCode"/>
- <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
- <result column="op_db_user" property="opDbUser"/>
- <result column="flg_can_login" property="flgCanLogin"/>
- <result column="hr_status" property="hrStatus"/>
- </resultMap>
- <!-- 通用条件列 -->
- <sql id="Condition">
- <where>
- <if test="staffId != null">
- AND t.staff_id = #{staffId}
- </if>
- <if test="staffCode != null and staffCode != ''">
- AND position (#{staffCode} in t.staff_code ) >0
- </if>
- <if test="staffName != null and staffName != ''">
- AND position (#{staffName} in t.staff_name ) >0
- </if>
- <if test="staffPhone != null and staffPhone != ''">
- AND position (#{staffPhone} in t.staff_phone ) >0
- </if>
- <if test="orgId != null">
- AND t.org_id = #{orgId}
- </if>
- <if test="remarks != null and remarks != ''">
- AND t.remarks = #{remarks}
- </if>
- <if test="flgValid != null">
- AND t.flg_valid = #{flgValid}
- </if>
- <if test="cpId != null">
- AND t.cp_id = #{cpId}
- </if>
- <if test="hrStatus != null">
- AND t.hr_status = #{hrStatus}
- </if>
- <if test="roleIds != null and roleIds.size()>0">
- AND t.role_ids &&
- #{roleIds, typeHandler=UuidListTypeHandler}
- </if>
- <if test="orgIds != null and orgIds.size()>0">
- AND t.org_id =
- any(#{orgIds, typeHandler=UuidListTypeHandler})
- </if>
- <if test="searchText !=null">
- AND ( t.staff_name LIKE concat('%', #{searchText}, '%')
- or t.staff_phone LIKE concat('%', #{searchText}, '%'))
- </if>
- </where>
- </sql>
- <!-- 查询表t_mst_staff,(条件查询+分页)列表 -->
- <select id="selectByCond" resultMap="BaseResultMap">
- SELECT
- <include refid="Base_Column_List"/>
- , org.org_name,
- case when t.hr_status = 1 then '在职' else '离职' end as hr_status_name,
- (SELECT COALESCE(array_to_string(array_agg(role_name), ','),'')
- FROM dkic_b.t_mst_role
- WHERE role_id = ANY (t.role_ids)) AS role_names
- FROM dkic_b.t_mst_staff t
- LEFT JOIN dkic_b.t_mst_org org
- ON t.org_Id = org.org_Id
- <include refid="Condition"/>
- ORDER BY t.op_create_time desc
- <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
- limit #{end} offset #{start}
- </if>
- </select>
- <!-- 查询表t_mst_staff,(条件查询)个数 -->
- <select id="countByCond" resultType="Long">
- SELECT
- count(1)
- FROM dkic_b.t_mst_staff t
- <include refid="Condition"/>
- </select>
- <!-- 根据主键查询表t_mst_staff的一行数据 -->
- <select id="selectById" resultMap="BaseResultMap">
- SELECT
- <include refid="Base_Column_List"/>
- , org.org_name,
- case when t.hr_status = 1 then '在职' else '离职' end as hr_status_name,
- (SELECT COALESCE(array_to_string(array_agg(role_name), ','),'')
- FROM dkic_b.t_mst_role
- WHERE role_id = ANY (t.role_ids)) AS role_names
- FROM dkic_b.t_mst_staff t
- LEFT JOIN dkic_b.t_mst_org org ON t.org_Id = org.org_Id
- WHERE t.staff_id = #{staffId}::uuid
- </select>
- <insert id="insertBatch">
- insert into dkic_b.t_mst_staff
- (
- <trim suffixOverrides=",">
- staff_code,
- staff_name,
- staff_phone,
- org_id,
- role_ids,
- wx_user_id,
- remarks,
- cp_id,
- op_app_code,
- flg_can_login,
- </trim>
- )
- values
- <foreach collection="list" index="index" item="item" separator=",">
- (
- <trim suffixOverrides=",">
- #{item.staffCode},
- #{item.staffName},
- #{item.staffPhone},
- #{item.orgId}::uuid,
- #{item.roleIds},
- #{item.wxUserId}::uuid,
- #{item.remarks},
- #{item.cpId},
- #{item.opAppCode},
- #{item.flgCanLogin},
- </trim>
- )
- </foreach>
- </insert>
- </mapper>
|