<?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.OrganCourseTypeOriginalCostDao">
    <resultMap id="OperatingReport" type="com.ym.mec.biz.dal.entity.OrganCourseTypeOriginalCost">
        <id column="id_" property="id"/>
        <result column="organ_id_" property="organId"/>
        <result column="course_type_" property="courseType"/>
        <result column="price_" property="price"/>
        <result column="tenant_id_" property="tenantId"/>
    </resultMap>
    <sql id="Base_Column_List">
        id_, organ_id_, course_type_, price_
    </sql>
    <select id="findByOrganIdAndCourseType" resultType="java.math.BigDecimal">
        select price_ from organ_course_type_original_cost
        where (organ_id_ = #{organId} OR organ_id_ = 0) AND course_type_ = #{courseType} limit 1
    </select>
    <select id="getCourseCostPrice" resultType="java.math.BigDecimal">
        SELECT SUM(CASE WHEN oct.id_ IS NULL THEN oct1.price_ ELSE oct.price_ END) cost_ FROM course_schedule cs
        left join organ_course_type_original_cost oct ON oct.course_type_ = cs.type_ AND oct.organ_id_ = cs.organ_id_
        left join organ_course_type_original_cost oct1 ON oct1.course_type_ = cs.type_ AND oct1.organ_id_ = 0
        where FIND_IN_SET(cs.id_,#{courseIds})
    </select>
</mapper>