<?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.ruoyi.depart.mapper.SysDepartMapper">
    
    <resultMap type="SysDepart" id="SysDepartResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="departName"    column="depart_name"    />
        <result property="departNameEn"    column="depart_name_en"    />
        <result property="departNameAbbr"    column="depart_name_abbr"    />
        <result property="departOrder"    column="depart_order"    />
        <result property="description"    column="description"    />
        <result property="orgCategory"    column="org_category"    />
        <result property="orgType"    column="org_type"    />
        <result property="orgCode"    column="org_code"    />
        <result property="mobile"    column="mobile"    />
        <result property="fax"    column="fax"    />
        <result property="address"    column="address"    />
        <result property="memo"    column="memo"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="qywxIdentifier"    column="qywx_identifier"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deptType"    column="dept_type"    />
    </resultMap>

    <sql id="selectSysDepartVo">
        select id, parent_id, depart_name, depart_name_en, depart_name_abbr, depart_order, description, org_category, org_type, org_code, mobile, fax, address, memo, status, del_flag, qywx_identifier, create_by, create_time, update_by, update_time, dept_type from sys_depart
    </sql>

    <select id="selectSysDepartList" parameterType="SysDepart" resultMap="SysDepartResult">
        <include refid="selectSysDepartVo"/>
        <where>  
            <if test="parentId != null  and parentId != ''"> and parent_id = #{parentId}</if>
            <if test="departName != null  and departName != ''"> and depart_name like concat('%', #{departName}, '%')</if>
            <if test="departNameEn != null  and departNameEn != ''"> and depart_name_en = #{departNameEn}</if>
            <if test="departNameAbbr != null  and departNameAbbr != ''"> and depart_name_abbr = #{departNameAbbr}</if>
            <if test="departOrder != null "> and depart_order = #{departOrder}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="orgCategory != null  and orgCategory != ''"> and org_category = #{orgCategory}</if>
            <if test="orgType != null  and orgType != ''"> and org_type = #{orgType}</if>
            <if test="orgCode != null  and orgCode != ''"> and org_code = #{orgCode}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="fax != null  and fax != ''"> and fax = #{fax}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="memo != null  and memo != ''"> and memo = #{memo}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="qywxIdentifier != null  and qywxIdentifier != ''"> and qywx_identifier = #{qywxIdentifier}</if>
            <if test="deptType != null "> and dept_type = #{deptType}</if>
        </where>
    </select>
    
    <select id="selectSysDepartById" parameterType="String" resultMap="SysDepartResult">
        <include refid="selectSysDepartVo"/>
        where id = #{id}
    </select>
    <select id="selectDeptTypeByDeptName" resultType="com.ruoyi.depart.domain.SysDepart">
        select depart_name,id,parent_id,dept_type from sys_depart where depart_name = #{userdept}
    </select>

    <insert id="insertSysDepart" parameterType="SysDepart">
        insert into sys_depart
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="departName != null and departName != ''">depart_name,</if>
            <if test="departNameEn != null">depart_name_en,</if>
            <if test="departNameAbbr != null">depart_name_abbr,</if>
            <if test="departOrder != null">depart_order,</if>
            <if test="description != null">description,</if>
            <if test="orgCategory != null and orgCategory != ''">org_category,</if>
            <if test="orgType != null">org_type,</if>
            <if test="orgCode != null and orgCode != ''">org_code,</if>
            <if test="mobile != null">mobile,</if>
            <if test="fax != null">fax,</if>
            <if test="address != null">address,</if>
            <if test="memo != null">memo,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="qywxIdentifier != null">qywx_identifier,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deptType != null">dept_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="departName != null and departName != ''">#{departName},</if>
            <if test="departNameEn != null">#{departNameEn},</if>
            <if test="departNameAbbr != null">#{departNameAbbr},</if>
            <if test="departOrder != null">#{departOrder},</if>
            <if test="description != null">#{description},</if>
            <if test="orgCategory != null and orgCategory != ''">#{orgCategory},</if>
            <if test="orgType != null">#{orgType},</if>
            <if test="orgCode != null and orgCode != ''">#{orgCode},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="fax != null">#{fax},</if>
            <if test="address != null">#{address},</if>
            <if test="memo != null">#{memo},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="qywxIdentifier != null">#{qywxIdentifier},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deptType != null">#{deptType},</if>
         </trim>
    </insert>

    <update id="updateSysDepart" parameterType="SysDepart">
        update sys_depart
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="departName != null and departName != ''">depart_name = #{departName},</if>
            <if test="departNameEn != null">depart_name_en = #{departNameEn},</if>
            <if test="departNameAbbr != null">depart_name_abbr = #{departNameAbbr},</if>
            <if test="departOrder != null">depart_order = #{departOrder},</if>
            <if test="description != null">description = #{description},</if>
            <if test="orgCategory != null and orgCategory != ''">org_category = #{orgCategory},</if>
            <if test="orgType != null">org_type = #{orgType},</if>
            <if test="orgCode != null and orgCode != ''">org_code = #{orgCode},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="fax != null">fax = #{fax},</if>
            <if test="address != null">address = #{address},</if>
            <if test="memo != null">memo = #{memo},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="qywxIdentifier != null">qywx_identifier = #{qywxIdentifier},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deptType != null">dept_type = #{deptType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysDepartById" parameterType="String">
        delete from sys_depart where id = #{id}
    </delete>

    <delete id="deleteSysDepartByIds" parameterType="String">
        delete from sys_depart where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>