<?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.SubjectEnterpriseMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.SubjectEnterprise">
        <id column="id" property="id"/>
        <id column="tenant_id" property="tenantId"/>
        <result column="subject_id" property="subjectId"/>
        <result column="subject_name" property="subjectName"/>
        <result column="code" property="code"/>
        <result column="name" property="name"/>
        <result column="rd_subject_enable" property="rdSubjectEnable"/>
        <result column="ad_subject_enable" property="adSubjectEnable"/>
    </resultMap>

    <insert id="insertBatch">
        insert into kd_subject_enterprise(tenant_id, subject_id, subject_name, code, name)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.tenantId},#{item.subjectId},#{item.subjectName},#{item.code},#{item.name})
        </foreach>
    </insert>

    <delete id="deleteById">
        delete from kd_subject_enterprise
        where id = #{id}
    </delete>

    <select id="selectSubjectEnterpriseList" resultMap="ResultMap">
        select e.id, e.subject_id, e.code, e.name, s.rd_subject_enable, s.ad_subject_enable, e.subject_name
        from kd_subject_enterprise e
        left join kd_subject s on e.subject_id = s.id
        where e.tenant_id = #{ew.tenantId}
        <if test="ew.code != null and ew.code != ''">and e.code = #{ew.code} </if>
        <if test="ew.name != null and ew.name != ''">and e.name like concat('%',#{ew.name},'%')</if>
        <if test="ew.subjectName != null and ew.subjectName != ''">and e.subject_name like concat('%',#{ew.subjectName},'%')</if>
    </select>
</mapper>
