<?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.lymsh.mommybaby.maindata.dao.DepartmentsMapper">

    <resultMap id="DepartmentsResultMap" type="com.lyms.platform.permission.model.Departments">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="title" property="title" jdbcType="VARCHAR"/>
        <result column="type" property="type" jdbcType="INTEGER"/>
        <result column="hospital_id" property="hospitalId" jdbcType="INTEGER"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="publish_id" property="publishId" jdbcType="INTEGER"/>
        <result column="publish_name" property="publishName" jdbcType="VARCHAR"/>
        <result column="yn" property="yn" jdbcType="INTEGER"/>
        <result column="modified" property="modified" jdbcType="TIMESTAMP"/>
        <result column="created" property="created" jdbcType="TIMESTAMP"/>
    </resultMap>


    <insert id="addDepartments" parameterType="com.lyms.platform.permission.model.Departments">
insert into departments (type,title,hospital_id,description,publish_id,publish_name,yn,modified,created) values (#{type},#{title},#{hospitalId},#{description},#{publishId},#{publishName},#{yn},#{modified},#{created})
</insert>


    <update id="updateDepartments" parameterType="com.lyms.platform.permission.model.Departments">
        update departments
        <set>
            <if test="title != null and title != ''">
                title = #{title,jdbcType=VARCHAR},
            </if>
            <if test="hospitalId != null">
                hospital_id = #{hospitalId,jdbcType=INTEGER},
            </if>
            <if test="type != null">
                type = #{type,jdbcType=INTEGER},
            </if>
            <if test="description != null and description != ''">
                description = #{description,jdbcType=VARCHAR},
            </if>
            <if test="publishId != null">
                publish_id = #{publishId,jdbcType=INTEGER},
            </if>
            <if test="publishName != null and publishName != ''">
                publish_name = #{publishName,jdbcType=VARCHAR},
            </if>
            <if test="yn != null">
                yn = #{yn,jdbcType=INTEGER},
            </if>
            <if test="modified != null">
                modified = #{modified,jdbcType=TIMESTAMP},
            </if>
            <if test="created != null">
                created = #{created,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>


    <delete id="deleteDepartments" parameterType="java.lang.Integer">
delete from departments where id = #{id,jdbcType=INTEGER}
</delete>


    <select id="getDepartments" resultMap="DepartmentsResultMap" parameterType="java.lang.Integer">
select id,type,title,hospital_id,description,publish_id,publish_name,yn,modified,created
 from departments where id = #{id,jdbcType=INTEGER}
</select>


    <sql id="orderAndLimit">
        <if test="sort != null and sort != '' ">
            order by ${sort}
            <if test="need != null">
                limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
            </if>
        </if>
    </sql>


    <sql id="DepartmentsCondition">
        <where>
            1 = 1
            <if test="id != null">
                and id = #{id,jdbcType=INTEGER}
            </if>
            <if test="title != null and title != ''">
                and title = #{title,jdbcType=VARCHAR}
            </if>
            <if test="hospitalId != null">
                and hospital_id = #{hospitalId,jdbcType=INTEGER}
            </if>
            <if test="type != null">
                and type = #{type,jdbcType=INTEGER}
            </if>
            <if test="description != null and description != ''">
                and description = #{description,jdbcType=VARCHAR}
            </if>
            <if test="publishId != null">
                and publish_id = #{publishId,jdbcType=INTEGER}
            </if>
            <if test="publishName != null and publishName != ''">
                and publish_name = #{publishName,jdbcType=VARCHAR}
            </if>
            <if test="yn != null">
                and yn = #{yn,jdbcType=INTEGER}
            </if>
            <if test="modified != null">
                and modified = #{modified,jdbcType=TIMESTAMP}
            </if>
            <if test="created != null">
                and created = #{created,jdbcType=TIMESTAMP}
            </if>
        </where>
    </sql>


    <select id="queryDepartments" resultMap="DepartmentsResultMap" parameterType="com.lyms.platform.permission.model.DepartmentsQuery">
        select id,type,title,hospital_id,description,publish_id,publish_name,yn,modified,created
        from departments
        <include refid="DepartmentsCondition"/>
        <include refid="orderAndLimit"/>
    </select>


    <select id="queryDepartmentsCount" resultType="int" parameterType="com.lyms.platform.permission.model.DepartmentsQuery">
        select count(1) from departments
        <include refid="DepartmentsCondition"/>
    </select>


</mapper>