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

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.kcim.dao.model.ComputeStandShareParam" id="ComputeStandShareParamMap">
        <result property="id" column="id"/>
        <result property="hospId" column="hosp_id"/>
        <result property="computeDate" column="compute_date"/>
        <result property="visitNo" column="visit_no"/>
        <result property="code" column="code"/>
        <result property="name" column="name"/>
        <result property="itemType" column="item_type"/>
        <result property="orderCode" column="order_code"/>
        <result property="orderName" column="order_name"/>
        <result property="responsibilityCode" column="responsibility_code"/>
        <result property="responsibilityName" column="responsibility_name"/>
        <result property="num" column="num"/>
        <result property="createUser" column="create_user"/>
        <result property="createTime" column="create_time"/>
        <result property="updateUser" column="update_user"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteUser" column="delete_user"/>
        <result property="deleteTime" column="delete_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>
    <select id="getComputeShareParamSum" resultType="com.kcim.vo.ComputeShareParamSumVo">
        SELECT
            a.item_type,
            a.responsibility_code,
            a.num,
            b.share_param_code,
            sum(b.compute_result ) as sum,
            sum(b.compute_single_result) as singleSum
        FROM
            compute_stand_share_param a
                LEFT JOIN compute_stand_share_param_detail b ON a.id = b.share_param_id
                AND b.del_flag = 0
        WHERE
            a.compute_date = #{computeDate,jdbcType=VARCHAR}
          AND b.compute_date = #{computeDate,jdbcType=VARCHAR}
          AND a.del_flag = 0
          AND b.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
        GROUP BY
            a.responsibility_code,
            b.share_param_code,
            a.item_type
    </select>
    <select id="getComputeShareParamDetail" resultType="com.kcim.vo.ComputeShareParamDetailVo">
        SELECT a.item_type,
               a.responsibility_code,
               sum(a.num)                   as num,
               a.`code`,
               b.share_param_code,
               sum(b.compute_result)        as compute_result,
               sum(b.compute_single_result) as compute_single_result
        FROM compute_stand_share_param a
                 LEFT JOIN compute_stand_share_param_detail b ON a.id = b.share_param_id
            AND b.del_flag = 0
        WHERE a.compute_date = #{computeDate,jdbcType=VARCHAR}
          AND b.compute_date = #{computeDate,jdbcType=VARCHAR}
          AND a.del_flag = 0
          AND b.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
        GROUP BY a.responsibility_code,
                 b.share_param_code,
                 a.`code`, a.item_type
    </select>
</mapper>