<?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.kcim.dao.mapper.ReportRelationMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.kcim.dao.model.ReportRelation" id="reportRelationMap">
        <result property="id" column="id"/>
        <result property="reportId" column="report_id"/>
        <result property="relationCode" column="relation_code"/>
        <result property="hospId" column="hosp_id"/>
        <result property="relation" column="relation"/>
        <result property="createTime" column="create_time"/>
        <result property="deleteTime" column="delete_time"/>
    </resultMap>
    <select id="getAccountRelation" resultType="com.kcim.vo.RelationVO">
        select ca.accounting_code as code, ca.accounting_name as name, 1 as relation
        from cost_report_relation crr
                 left join cost_accounting ca on crr.relation_code = ca.accounting_code
        where crr.delete_time = 0
          and ca.delete_time = 0
          and crr.hosp_id = #{hospId}
          and ca.hosp_id = #{hospId}
          and crr.report_id = #{reportId}
    </select>

    <select id="getShareParam" resultType="com.kcim.vo.RelationVO">
        select csl.id as code, csl.share_name as name, 2 as relation
        from cost_report_relation crr
                 left join cost_share_level csl on crr.relation_code = csl.id
        where crr.delete_time = 0
          and csl.delete_time = 0
          and crr.hosp_id = #{hospId}
          and csl.hosp_id = #{hospId}
          and crr.report_id = #{reportId}
          and crr.relation = 2

    </select>
    <select id="getResponsibilities" resultType="com.kcim.vo.RelationVO">
        select cr.responsibility_code as code, cr.responsibility_name as name, 3 as relation
        from cost_report_relation crr
                 left join cost_responsibility cr
                           on crr.relation_code = cr.responsibility_code and crr.hosp_id = cr.hosp_id
        where crr.delete_time = 0
          and crr.hosp_id = #{hospId}
          and cr.delete_time = 0
          and crr.report_id = #{reportId}
          and crr.relation = 3
    </select>


</mapper>