package thyyxxk.webserver.dao.his.targetmanagement;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.highreport.ReportBaseInfo;

import java.util.List;
import java.util.Map;

/**
 * @description: 指标管理
 * @author: hsh
 * @date: 2023/5/30 16:58
 **/
@Mapper
public interface TargetManagementDao extends BaseMapper<ReportBaseInfo> {

    @Select("<script> ${sql} </script>")
    String targetSqlExecute(@Param("sql") String sql);

    @Update(" delete from report_base_info where report_id = #{reportId} ")
    void deleteReportBaseInfoById(@Param("reportId") String reportId);

    @Select("<script> " +
            " select * from report_base_info where flag = 'Y' and report_type = 'zb' " +
            " <if test=\"id != null and id != '' \"> " +
            " and report_id = #{id} " +
            " </if> " +
            " <if test=\"pid != null and pid != '' \"> " +
            " and level = #{pid} " +
            " </if> " +
            "</script> ")
    ReportBaseInfo selectReportBaseInfoById(@Param("id") String id, @Param("pid") String pid);

    /**
     * @description: 根据指标字典配置的指标报表id查询指标报表详情
     * @author: hsh
     * @date: 2023/7/5 10:38
     * @param: [calcId]
     * @return: ReportBaseInfo
     **/
    @Select("<script> " +
            " select * from report_base_info where flag = 'Y' and report_type = 'zb' and report_id = #{calcId} " +
            "</script> ")
    ReportBaseInfo selectReportBaseInfoByCalcId(@Param("calcId") String calcId);

    /**
     * @Description 查询指标报表的所有id以及名称（包括增加的手工数据指标）
     * @Author hsh
     * @param reportType 报表类型
     * @return list
     * @Date 2024/4/1 16:49
     */
    @Select(" select report_name as name, report_id as 'code' from report_base_info where flag = 'Y' and (report_type = 'sg' or report_type = #{reportType}) ")
    List<Map<String, Object>> selectTargetZbReportId(@Param("reportType") String reportType);

}
