<?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="org.example.mapper.HospitalDeptMapper">

    <resultMap id="DeptResultMap" type="org.example.entity.HospitalDept">
        <id property="code" column="code"/>
        <result property="outCode" column="out_code"/>
        <result property="name" column="name"/>
        <result property="address" column="address"/>
        <result property="telephone" column="telephone"/>
        <result property="introduction" column="introduction"/>
        <result property="enabled" column="enabled"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <!-- 查询所有科室 -->
    <select id="findAll" resultMap="DeptResultMap">
        SELECT code, out_code, name, address, telephone, introduction, enabled, remark
        FROM tb_hospital_dept
    </select>

    <!-- 根据科室代码查询科室 -->
    <select id="findByCode" parameterType="string" resultMap="DeptResultMap">
        SELECT code, out_code, name, address, telephone, introduction, enabled, remark
        FROM tb_hospital_dept
        WHERE code = #{code}
    </select>

    <!-- 插入新科室 -->
    <insert id="insert" parameterType="org.example.entity.HospitalDept">
        INSERT INTO tb_hospital_dept(code, out_code, name, address, telephone, introduction, enabled, remark)
        VALUES(#{code}, #{outCode}, #{name}, #{address}, #{telephone}, #{introduction}, #{enabled}, #{remark})
    </insert>

    <!-- 更新科室信息 -->
    <update id="update" parameterType="org.example.entity.HospitalDept">
        UPDATE tb_hospital_dept
        SET out_code=#{outCode}, name=#{name}, address=#{address}, telephone=#{telephone},
            introduction=#{introduction}, enabled=#{enabled}, remark=#{remark}
        WHERE code=#{code}
    </update>

    <!-- 根据科室代码删除科室 -->
    <delete id="deleteByCode" parameterType="string">
        DELETE FROM tb_hospital_dept WHERE code = #{code}
    </delete>

</mapper>
