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

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.kcim.dao.model.ShareParamValue" id="shareParamValueMap">
        <result property="id" column="id"/>
        <result property="dateYear" column="date_year"/>
        <result property="dateMonth" column="date_month"/>
        <result property="shareParamCode" column="share_param_code"/>
        <result property="responsibilityCode" column="responsibility_code"/>
        <result property="valueNum" column="value_num"/>
        <result property="hospId" column="hosp_id"/>
        <result property="fileId" column="fileId"/>
        <result property="dataSourceType" column="data_source_type"/>
        <result property="createTime" column="create_time"/>
        <result property="deleteTime" column="delete_time"/>
    </resultMap>
    <update id="reducingHistory">
        update cost_share_param_value set delete_time = 0
        where file_id = #{id}
        and hosp_id = #{hospId}
        and id in
        <foreach close=")" collection="list" item="item" open="(" separator=",">
            #{item}
        </foreach>
    </update>
    <select id="getValues" resultType="com.kcim.dao.model.dto.ShareParamValueVO">
        select cspv.*, csp.share_param_name, cr.responsibility_name
        from cost_share_param_value cspv
        left join cost_share_param csp
        on csp.share_param_code = cspv.share_param_code and csp.hosp_id = cspv.hosp_id
        left join cost_responsibility cr
        on cspv.responsibility_code = cr.responsibility_code and cspv.hosp_id = cr.hosp_id
        where cspv.hosp_id = #{hospId}
        and cspv.delete_time = 0
        and csp.delete_time = 0
        and cr.delete_time = 0
        and cspv.date_month = month(#{date})
        and cspv.date_year = year(#{date})
        <if test="shareParamCode != null and shareParamCode != ''">
            and (cspv.share_param_code like concat('%',#{shareParamCode,jdbcType=VARCHAR},'%') or csp.share_param_name like concat('%',#{shareParamCode,jdbcType=VARCHAR},'%') )

        </if>
        <if test="responsibilityCode != null and responsibilityCode != ''">
            and cspv.responsibility_code = #{responsibilityCode}
        </if>
        limit #{current},#{pageSize}

    </select>
    <select id="getValuesCount" resultType="java.lang.Integer">
        select count(*)
        from cost_share_param_value cspv
        left join cost_share_param csp
        on csp.share_param_code = cspv.share_param_code and csp.hosp_id = cspv.hosp_id
        left join cost_responsibility cr
        on cspv.responsibility_code = cr.responsibility_code and cspv.hosp_id = cr.hosp_id
        where cspv.hosp_id = #{hospId}
        and cspv.delete_time = 0
        and csp.delete_time = 0
        and cr.delete_time = 0
        and cspv.date_month = month(#{date})
        and cspv.date_year = year(#{date})
        <if test="shareParamCode != null and shareParamCode != ''">
            and (cspv.share_param_code like concat('%',#{shareParamCode,jdbcType=VARCHAR},'%') or csp.share_param_name like concat('%',#{shareParamCode,jdbcType=VARCHAR},'%') )
        </if>
        <if test="responsibilityCode != null and responsibilityCode != ''">
            and cspv.responsibility_code = #{responsibilityCode}
        </if>
    </select>

    <select id="getListByYearAndMonth" resultType="com.kcim.dao.model.ShareParamValue">
        select cspv.*
        from cost_share_param_value cspv
                 left join cost_share_param csp
                           on csp.share_param_code = cspv.share_param_code and csp.hosp_id = cspv.hosp_id
                 left join cost_responsibility cr
                           on cspv.responsibility_code = cr.responsibility_code and cspv.hosp_id = cr.hosp_id
        where cspv.hosp_id = #{hospId}
          and cspv.delete_time = 0
          and csp.delete_time = 0
          and cr.delete_time = 0
          and cspv.date_month = #{month}
          and cspv.date_year = #{year}
    </select>
    <select id="selectHistoryList" resultType="com.kcim.dao.model.ShareParamValue">
        select  *
        from cost_share_param_value
        where  hosp_id = #{hospId}
          and delete_time != 0
          and file_id = #{id}
    </select>


</mapper>