<?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.sky.scientific.mapper.DepartmentMapper">

    <!-- 通用查询映射结果 -->
<!--    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.DepartmentEntity">-->
<!--        <id column="id" property="id"/>-->
<!--        <result column="tenantId" property="tenantId"/>-->
<!--         <result column="year_and_month" property="yearAndMonth"/>-->
<!--        <result column="parent_id" property="parentId"/>-->
<!--        <result column="parent_name" property="parentName"/>-->
<!--        <result column="name" property="name"/>-->
<!--    </resultMap>-->

    <delete id="deleteByIds">
        DELETE FROM kd_department
        WHERE id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
    <delete id="deleteByYearAndTenantId">
        DELETE FROM kd_department
        WHERE year_and_month = #{year}
        AND tenant_id = #{tenantId}
    </delete>

    <select id="getNameById" parameterType="java.lang.Long" resultType="java.lang.String">
        select name from kd_department where id = #{id}
    </select>

    <select id="getFullNameById" resultType="java.lang.String">
        SELECT CONCAT_WS('/',(SELECT name FROM kd_department d2 WHERE d2.id = d1.parent_id), d1.`name`) as departmentName
        FROM kd_department d1
        WHERE d1.id = #{id}
    </select>
</mapper>
