<?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.ym.mec.biz.dal.dao.OrganizationCloudTeacherFeeDao">

    <resultMap type="com.ym.mec.biz.dal.entity.OrganizationCloudTeacherFee" id="OrganizationCloudTeacherFee">
        <id column="id_" property="id"/>
        <result column="organ_id_" property="organId"/>
        <result column="price_" property="price"/>
        <result column="plus_price_" property="plusPrice"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
        <result column="organName" property="organName"/>
    </resultMap>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="OrganizationCloudTeacherFee">
        SELECT *
        FROM organization_cloud_teacher_fee
        WHERE id_ = #{id}
    </select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="OrganizationCloudTeacherFee">
        SELECT *
        FROM organization_cloud_teacher_fee
        ORDER BY id_
    </select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.OrganizationCloudTeacherFee"
            useGeneratedKeys="true" keyColumn="id_" keyProperty="id">
        INSERT INTO organization_cloud_teacher_fee
            (organ_id_, price_,plus_price_, create_time_, update_time_)
        VALUES (#{organId}, #{price},#{plusPrice}, NOW(), NOW())
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.OrganizationCloudTeacherFee">
        UPDATE organization_cloud_teacher_fee
        <set>
            <if test="price != null">
                price_ = #{price},
            </if>
            <if test="plusPrice != null">
                plus_price_ = #{plusPrice},
            </if>
            update_time_=NOW()
        </set>
        WHERE id_ = #{id}
    </update>

    <!-- 根据主键删除一条记录 -->
    <delete id="delete">
        DELETE
        FROM organization_cloud_teacher_fee
        WHERE id_ = #{id}
    </delete>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="OrganizationCloudTeacherFee" parameterType="map">
        SELECT octf.*,o.name_ organName FROM organization_cloud_teacher_fee octf
        LEFT JOIN organization o ON octf.organ_id_ = o.id_
        <include refid="queryPageSql"/>
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
        SELECT COUNT(*) FROM organization_cloud_teacher_fee octf
        LEFT JOIN organization o on octf.organ_id_ = o.id_
        <include refid="queryPageSql"/>
    </select>

    <sql id="queryPageSql">
        <where>
            <if test="organId != null">
                AND FIND_IN_SET(octf.organ_id_,#{organId})
            </if>
            <if test="search != null">
                AND (octf.organ_id_ =#{search} OR o.name_ LIKE CONCAT('%',#{search},'%'))
            </if>
        </where>
    </sql>

    <select id="getByOrganId" resultMap="OrganizationCloudTeacherFee">
        SELECT *
        FROM organization_cloud_teacher_fee
        WHERE organ_id_ = #{organId}
    </select>
</mapper>
