<?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.toesbieya.my.mapper.SysDepartmentMapper">
    <select id="get" resultType="com.toesbieya.my.model.entity.SysDepartment">
        select *
        from sys_department
        where status = 1
    </select>
    <select id="getAll" resultType="com.toesbieya.my.model.entity.SysDepartment">
        select *
        from sys_department
    </select>
    <insert id="add" parameterType="com.toesbieya.my.model.entity.SysDepartment">
        insert into sys_department (pid, name, status)
        VALUES (#{pid}, #{name}, #{status});
    </insert>
    <update id="update" parameterType="com.toesbieya.my.model.entity.SysDepartment">
        update sys_department
        set pid=#{pid},
        name=#{name},
        status=#{status}
        where id = #{id}
    </update>
    <delete id="del">
        delete
        from sys_department
        where id = #{id}
    </delete>
    <select id="nameExist" resultType="java.lang.Boolean">
        select if(count(0) > 0, 1, 0)
        from sys_department
        where name = #{name}
        and pid = #{pid}
        <if test="id!=null">
            and id!=#{id}
        </if>
    </select>
</mapper>