using Adf.Core.Db;
using Adf.Core.Entity;
using Adf.Core.Util;
using Aspose.Cells;
using Aspose.Cells.Rendering;
using CYQ.Data;
using CYQ.Data.Table;
using CYQ.Data.Tool;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Windows.Forms;

namespace CompanyServer
{
    public partial class 上海直报 : Form
    {
        private int 执行间隔 = 0;
        private DateTime nextDatetime = new DateTime();
        private string con = ""; // 连接池
        public CYQ.Data.Cache.CacheManage cache = CYQ.Data.Cache.CacheManage.Instance;
        public 上海直报()
        {
            InitializeComponent();
            this.timer1.Enabled = false;
            DataRow dr = ServerClass.ReadDataTable("上海直报");
            if (dr != null)
            {
                con = dr["connectstring"].ToString();
                this.textBox2.Text = con;
            }
        }
        private void 测试连接_Click(object sender, EventArgs e)
        {

            if (string.IsNullOrWhiteSpace(con))
            {
                MessageBox.Show("请填写连接池信息", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.textBox2.Focus();
                return;
            }

            string retValue = ServerClass.ConnectTest(con);
            if (retValue != "")
            {
                MessageBox.Show(retValue, "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("连接成功!", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void 开启_Click(object sender, EventArgs e)
        {
            if (this.开启.Text == "停止")
            {
                this.开启.Text = "开启";
                this.timer1.Enabled = false;
                return;
            }

            if (string.IsNullOrWhiteSpace(this.执行时间.Text))
            {
                MessageBox.Show("请填写执行时间!", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.执行时间.Focus();
                return;
            }

            if (!int.TryParse(this.执行时间.Text, out 执行间隔))
            {
                MessageBox.Show("执行时间请填写正整数!", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.执行时间.Focus();
                return;
            }
            con = this.textBox2.Text;

            if (string.IsNullOrWhiteSpace(con))
            {
                MessageBox.Show("请填写连接池信息", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.textBox2.Focus();
                return;
            }
            this.开启.Text = "停止";


            nextDatetime = DateTime.Now;
            this.timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //在执行中或者未到下次执行时间则不执行
            if (this.backgroundWorker1.IsBusy || nextDatetime >= DateTime.Now)
            {
                return;
            }
            this.timer1.Enabled = false;
            this.backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            #region 获取access_token
            //string userName = "zuowuhao@qq.com";
            //string password = "Test.123";
            //string clientId = "ybqq_client";
            //string clientSecert = "bM*H,W6&8DqM76";
            //string Scope = "data_sync_api";
            //var client = new RestClient("https://account.shsunshine.org/connect/token");
            //client.Timeout = -1;
            //var request = new RestRequest(Method.POST);
            //request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            //request.AddParameter("grant_type", "password");
            //request.AddParameter("username", userName);
            //request.AddParameter("password", password);
            //request.AddParameter("scope", Scope);
            //request.AddParameter("client_id", clientId);
            //request.AddParameter("client_secret", clientSecert);
            //IRestResponse response = client.Execute(request);
            //RootModel rootmodel = JsonConvert.DeserializeObject<RootModel>(response.Content);
            //string access_token = rootmodel.access_token;
            #endregion

            #region 同步数据
            if ((DateTime.Now.Minute == 15 || DateTime.Now.Minute == 35 || DateTime.Now.Minute == 55) && (DateTime.Now.Hour > 9 || DateTime.Now.Hour < 6))
            {

                //获取最新的versioncode
                //string stucodeversion = string.Empty;
                //string delversion = string.Empty;
                //using (MAction action = new MAction("report_VersionTab", con))
                //{
                //    MDataTable curTab = action.Select("code='123456789'") ?? new MDataTable();
                //    if (curTab.Rows.Count > 0)
                //    {
                //        stucodeversion = curTab.Rows[0].Get("stucodeversion", "");
                //        delversion = curTab.Rows[0].Get("delversion", "");
                //    }
                //}
                ////数据同步
                //DataSync(access_token, stucodeversion);
                ////删除同步数据
                //DeleteData(access_token, delversion);
            }

            #endregion


            DoAtuoLoopTSent(con);
            if (DateTime.Now.Minute == 0 || DateTime.Now.Minute == 5 || DateTime.Now.Minute == 15 || DateTime.Now.Minute == 30 || DateTime.Now.Minute == 45)
            {
                //查询苗子（关联两个以上的疾病）
                //seleseedling();
                //同步到政务云

                string qftime = string.Empty;//发给填报人的信息时间
                string qflimttime = string.Empty;//发给领导的信息时间
                string cbmb = string.Empty;//发给填报人的信息内容
                string cbmbx = string.Empty;//发给领导的信息内容  
                string curphone = string.Empty;//获取当前手机号  
                string schooltypenamex = string.Empty;//学校类型
                string miaomessage = string.Empty;//苗子信息

                string jiumessage = string.Empty;//是否闭环提示信息(填报人)

                string checkmessage = string.Empty; //是否闭环提示信息(校领导)

                string kbtime = string.Empty;//发给填报人的信息时间（打卡）
                string kbtimex = string.Empty;//发给领导的信息时间 （打卡）
                string kbmb = string.Empty;//发给填报人的信息内容（打卡）
                string kbmbx = string.Empty;//发给领导的信息内容(打卡)  

                string cbtime10 = string.Empty;//发给填报人的信息时间10:30
                string cbtimex10 = string.Empty;//发给领导的信息时间  10:30
                string cbmb10 = string.Empty;//发给填报人的信息内容 10:30
                string cbmbx10 = string.Empty;//发给领导的信息内容 10:30

                string mrsprphone = string.Empty;//每日短信审批人手机号

                int ispressreport = 0;//非教学日是否催报（0：否；1:是）
                #region 非教学日是否催报
                using (MAction action = new MAction("report_configure", con))
                {
                    MDataTable jxr = action.Select() ?? new MDataTable();
                    if (jxr.Rows.Count > 0)
                    {
                        ispressreport = jxr.Rows[0].Get("ispressreport", 0);
                    }
                }
                #endregion
                #region 从数据字典找值赋值
                using (MAction action = new MAction("adf_datadic", con))
                {
                    //短信审批人手机号
                    MDataTable tempmrsprphone = action.Select("diccode = 'mrsprphone' ") ?? new MDataTable();
                    mrsprphone = tempmrsprphone.Rows[0].Get("dicvalue", "");

                    //第一个早上催报时间点
                    MDataTable tempqt = action.Select("diccode = 'cbtime' ") ?? new MDataTable();
                    qftime = tempqt.Rows[0].Get("dicvalue", "");
                    MDataTable tempqtx = action.Select("diccode = 'cbtimex' ") ?? new MDataTable();
                    qflimttime = tempqtx.Rows[0].Get("dicvalue", "");
                    MDataTable cbmbTab = action.Select("diccode = 'cbmb' ") ?? new MDataTable();
                    cbmb = cbmbTab.Rows[0].Get("dicvalue", "");
                    MDataTable cbmbxTab = action.Select("diccode = 'cbmbx' ") ?? new MDataTable();
                    cbmbx = cbmbxTab.Rows[0].Get("dicvalue", "");
                    #region 第二个早上催报时间点
                    //第二个早上催报时间点
                    MDataTable tempqt10 = action.Select("diccode = 'cbtime10' ") ?? new MDataTable();
                    cbtime10 = tempqt10.Rows[0].Get("dicvalue", "");
                    MDataTable tempqtx10 = action.Select("diccode = 'cbtimex10' ") ?? new MDataTable();
                    cbtimex10 = tempqtx10.Rows[0].Get("dicvalue", "");
                    MDataTable cbmbTab10 = action.Select("diccode = 'cbmb10' ") ?? new MDataTable();
                    cbmb10 = cbmbTab10.Rows[0].Get("dicvalue", "");
                    MDataTable cbmbxTab10 = action.Select("diccode = 'cbmbx10' ") ?? new MDataTable();
                    cbmbx10 = cbmbxTab10.Rows[0].Get("dicvalue", "");


                    string curdata = DateTime.Now.ToString("MM 月 dd 日");
                    cbmb10 = cbmb10.Replace("{date}", curdata);//替换时间字段
                    cbmbx10 = cbmbx10.Replace("{date}", curdata);//替换时间字段

                    cbtime10 = DateTime.Now.ToString("yyyy-MM-dd") + " " + cbtime10;//发给填报人的信息
                    cbtimex10 = DateTime.Now.ToString("yyyy-MM-dd") + " " + cbtimex10;//发给领导的信息
                    #endregion

                    cbmb = cbmb.Replace("{date}", curdata);//替换时间字段
                    cbmbx = cbmbx.Replace("{date}", curdata);//替换时间字段
                    MDataTable tempphone = action.Select("diccode = 'curphone' ") ?? new MDataTable();
                    curphone = tempphone.Rows[0].Get("dicvalue", "");
                    MDataTable temptypenamex = action.Select("diccode = 'schooltypenamex' ") ?? new MDataTable();
                    schooltypenamex = temptypenamex.Rows[0].Get("dicvalue", "");
                    MDataTable tempmiaomessage = action.Select("diccode = 'miaomessage' ") ?? new MDataTable();
                    miaomessage = tempmiaomessage.Rows[0].Get("dicvalue", "");

                    MDataTable tempjiumessage = action.Select("diccode = 'jiumessage' ") ?? new MDataTable();
                    jiumessage = tempjiumessage.Rows[0].Get("dicvalue", "");
                    MDataTable tempcheckmessage = action.Select("diccode = 'checkmessage' ") ?? new MDataTable();
                    checkmessage = tempcheckmessage.Rows[0].Get("dicvalue", "");

                    qftime = DateTime.Now.ToString("yyyy-MM-dd") + " " + qftime;//发给填报人的信息
                    qflimttime = DateTime.Now.ToString("yyyy-MM-dd") + " " + qflimttime;//发给领导的信息 

                    //打卡
                    MDataTable temkbtime = action.Select("diccode = 'kbtime' ") ?? new MDataTable();
                    kbtime = temkbtime.Rows[0].Get("dicvalue", "");
                    MDataTable tempkbtimex = action.Select("diccode = 'kbtimex' ") ?? new MDataTable();
                    kbtimex = tempkbtimex.Rows[0].Get("dicvalue", "");
                    MDataTable tempkbmb = action.Select("diccode = 'kbmb' ") ?? new MDataTable();
                    kbmb = tempkbmb.Rows[0].Get("dicvalue", "");
                    MDataTable tempkbmbx = action.Select("diccode = 'kbmbx' ") ?? new MDataTable();
                    kbmbx = tempkbmbx.Rows[0].Get("dicvalue", "");
                    kbmb = kbmb.Replace("{date}", curdata);//替换时间字段
                    kbmbx = kbmbx.Replace("{date}", curdata);//替换时间字段
                    kbtime = DateTime.Now.ToString("yyyy-MM-dd") + " " + kbtime;//发给填报人的信息
                    kbtimex = DateTime.Now.ToString("yyyy-MM-dd") + " " + kbtimex;//发给领导的信息
                }
                #endregion


                //查询教学日历
                /// 0-9:30/12:30 短信模板
                /// 1-上报情况统计表
                /// 2-修正上报情况统计表
                /// 3-午检打卡报表
                /// 4-修正午检打卡报表
                /// 5-16:00后 短信模板
                /// 6-16:00后苗子汇总
                /// 7-16:00后 短信模板(周末)
                #region 按教学日历催报
                using (MAction action = new MAction("report_teaching_calendar", con))
                {
                    MDataTable teachingdata = action.Select("IsClasses = '开课' and teachingdate='" + DateTime.Now.ToString("yyyy-MM-dd") + "' ") ?? new MDataTable();
                    if (teachingdata.Rows.Count > 0)
                    {
                        #region 教学日期间日报短信
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                        {
                            try
                            {
                                MDataTable dayReport1 = GetDayList(con, 0) ?? new MDataTable();
                                #region 数据
                                int erCount = 1;
                                string curAnswer = string.Empty;
                                int allcount = dayReport1.Rows.Count;
                                foreach (MDataRow er1 in dayReport1.Rows)
                                {
                                    if (allcount == erCount)
                                    {
                                        break;
                                    }
                                    curAnswer += er1.Get("message", "").ToString();
                                    erCount++;
                                }
                                string bottommes = string.Empty;
                                bottommes = dayReport1.Rows[allcount - 1].Get("message", "");
                                curAnswer = curAnswer + "\n" + bottommes;
                                #endregion

                                DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "10：00短信报错：" + ex.ToString());
                            }

                        }
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:01:00")))
                        {
                            try
                            {
                                MDataTable dayReport1 = GetDayList(con, 0) ?? new MDataTable();
                                #region 数据
                                int erCount = 1;
                                string curAnswer = string.Empty;
                                int allcount = dayReport1.Rows.Count;
                                foreach (MDataRow er1 in dayReport1.Rows)
                                {
                                    if (allcount == erCount)
                                    {
                                        break;
                                    }
                                    curAnswer += er1.Get("message", "").ToString();
                                    erCount++;
                                }
                                string bottommes = string.Empty;
                                bottommes = dayReport1.Rows[allcount - 1].Get("message", "");
                                curAnswer = curAnswer + "\n" + bottommes;
                                #endregion

                                DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "15：00短信报错：" + ex.ToString());
                            }
                        }
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                        {
                            try
                            {
                                MDataTable dayReport1 = GetDayList(con, 5) ?? new MDataTable();
                                #region 数据
                                int erCount = 1;
                                string curAnswer = string.Empty;
                                int allcount = dayReport1.Rows.Count;
                                foreach (MDataRow er1 in dayReport1.Rows)
                                {
                                    if (allcount - 1 == erCount)
                                    {
                                        break;
                                    }
                                    curAnswer += er1.Get("message", "").ToString();
                                    erCount++;
                                }
                                string bottommes = string.Empty;
                                bottommes = dayReport1.Rows[allcount - 2].Get("message", "") + dayReport1.Rows[allcount - 1].Get("message", "");
                                curAnswer = curAnswer + "\n" + bottommes;
                                #endregion
                                DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "16：30短信报错：" + ex.ToString());
                            }
                        }
                        #endregion

                        #region 教学日期间日报图片
                        //9：15  未上报
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:14:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:16:00")))
                        {
                            try
                            {
                                GetListData(9, "因病直报教育技术群,数据报送侦探队");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "09：15上报统计报错：" + ex.ToString());
                            }
                        }
                        //9：30  未上报 明细
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:31:00")))
                        {
                            try
                            {
                                GetListData(9, "因病直报教育技术群,数据报送侦探队");
                                GetListData(1, "因病直报教育技术群,数据报送侦探队");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "09：30未上报统计+明细报错：" + ex.ToString());
                            }
                        }
                        //10：00 未上报 明细
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                        {
                            try
                            {
                                GetListData(9, "因病数据报送群");
                                GetListData(1, "因病数据报送群");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "10：00上报统计+明细报错：" + ex.ToString());
                            }
                        }
                        //14：15 未午间 
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:14:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:16:00")))
                        {
                            try
                            {
                                GetListData(8, "因病直报教育技术群,数据报送侦探队");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "14：15打卡统计报错：" + ex.ToString());
                            }
                        }
                        //14：30 未午间 明细
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:31:00")))
                        {
                            try
                            {
                                GetListData(8, "因病直报教育技术群,数据报送侦探队");
                                GetListData(3, "因病直报教育技术群,数据报送侦探队");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "14：30打卡统计+明细报错：" + ex.ToString());
                            }
                        }
                        //15：00 未午间 明细 未上报明细
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:01:00")))
                        {
                            try
                            {
                                GetListData(8, "因病数据报送群");
                                GetListData(3, "因病数据报送群");
                                GetListData(1, "因病数据报送群");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "15：00打卡统计+明细+上报明细报错：" + ex.ToString());
                            }
                        }
                        //16：30  未午间明细
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                        {
                            try
                            {
                                GetListData(3, "因病直报教育技术群,数据报送侦探队");
                                GetListData(1, "因病直报教育技术群,数据报送侦探队");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "16：30打卡明细+上报明细报错：" + ex.ToString());
                            }
                        }
                        #endregion
                        //早上催报
                        #region 发送短信，发给填报人的（一天只发一次）
                        if (DateTime.Now > Convert.ToDateTime(qftime))
                        {
                            DoCLetterAllSent(con, cbmb, schooltypenamex);//一天只发一次
                        }
                        #endregion

                        #region 发送短信，发给领导人的（一天只发一次）
                        if (DateTime.Now > Convert.ToDateTime(qflimttime))
                        {
                            DoCLetterAllLeaderSent(con, cbmbx, schooltypenamex);//一天只发一次
                        }
                        #endregion


                        #region 发送短信10：30，发给填报人的（一天只发一次）
                        if (DateTime.Now > Convert.ToDateTime(cbtime10))
                        {
                            DoCLetterAllSent2(con, cbmb10, schooltypenamex);//一天只发一次
                        }
                        #endregion
                        #region 发送短信10：30，发给领导人的（一天只发一次）
                        if (DateTime.Now > Convert.ToDateTime(cbtimex10))
                        {
                            DoCLetterAllLeaderSent2(con, cbmbx10, schooltypenamex);//一天只发一次
                        }
                        #endregion

                        //下午打卡催报
                        #region 发送短信，发给填报人的（一天只发一次）
                        if (DateTime.Now > Convert.ToDateTime(kbtime))
                        {
                            DoCLetterAllSentK(con, kbmb, schooltypenamex);//一天只发一次
                        }
                        #endregion
                        #region 发送短信，发给领导人的（一天只发一次）
                        if (DateTime.Now > Convert.ToDateTime(kbtimex))
                        {
                            DoCLetterAllLeaderSentK(con, kbmbx, schooltypenamex);//一天只发一次
                        }
                        #endregion

                        #region 催报闭环催报短信
                        //填报人
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                        {
                            DoClosedLoopTSent(con, jiumessage);
                        }
                        //校领导
                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:01:00")))
                        {
                            DoClosedLoopLSent(con, checkmessage);
                        }
                        #endregion

                        #region 图片和文件上报

                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:31:00")))
                        {
                            try
                            {
                                GetListData(10, "因病直报教育技术群,数据报送侦探队");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "闭环统计报错：" + ex.ToString());
                            }
                        }

                        if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                        {
                            try
                            {
                                GetListData(10, "因病直报教育技术群,数据报送侦探队");
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog(DateTime.Now.ToString() + "闭环统计报错：" + ex.ToString());
                            }
                        }
                        #endregion

                    }
                    MDataTable noteachingdata = action.Select("IsClasses = '休假' and teachingdate='" + DateTime.Now.ToString("yyyy-MM-dd") + "' ") ?? new MDataTable();
                    if (noteachingdata.Rows.Count > 0)
                    {
                        if (ispressreport == 1)
                        {
                            #region 教学日期间日报短信
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                            {
                                try
                                {
                                    MDataTable dayReport1 = GetDayList(con, 0) ?? new MDataTable();
                                    #region 数据
                                    int erCount = 1;
                                    string curAnswer = string.Empty;
                                    int allcount = dayReport1.Rows.Count;
                                    foreach (MDataRow er1 in dayReport1.Rows)
                                    {
                                        if (allcount == erCount)
                                        {
                                            break;
                                        }
                                        curAnswer += er1.Get("message", "").ToString();
                                        erCount++;
                                    }
                                    string bottommes = string.Empty;
                                    bottommes = dayReport1.Rows[allcount - 1].Get("message", "");
                                    curAnswer = curAnswer + "\n" + bottommes;
                                    #endregion

                                    DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "10：00短信报错：" + ex.ToString());
                                }

                            }
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:01:00")))
                            {
                                try
                                {
                                    MDataTable dayReport1 = GetDayList(con, 0) ?? new MDataTable();
                                    #region 数据
                                    int erCount = 1;
                                    string curAnswer = string.Empty;
                                    int allcount = dayReport1.Rows.Count;
                                    foreach (MDataRow er1 in dayReport1.Rows)
                                    {
                                        if (allcount == erCount)
                                        {
                                            break;
                                        }
                                        curAnswer += er1.Get("message", "").ToString();
                                        erCount++;
                                    }
                                    string bottommes = string.Empty;
                                    bottommes = dayReport1.Rows[allcount - 1].Get("message", "");
                                    curAnswer = curAnswer + "\n" + bottommes;
                                    #endregion

                                    DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "15：00短信报错：" + ex.ToString());
                                }
                            }
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                            {
                                try
                                {
                                    MDataTable dayReport1 = GetDayList(con, 5) ?? new MDataTable();
                                    #region 数据
                                    int erCount = 1;
                                    string curAnswer = string.Empty;
                                    int allcount = dayReport1.Rows.Count;
                                    foreach (MDataRow er1 in dayReport1.Rows)
                                    {
                                        if (allcount - 1 == erCount)
                                        {
                                            break;
                                        }
                                        curAnswer += er1.Get("message", "").ToString();
                                        erCount++;
                                    }
                                    string bottommes = string.Empty;
                                    bottommes = dayReport1.Rows[allcount - 2].Get("message", "") + dayReport1.Rows[allcount - 1].Get("message", "");
                                    curAnswer = curAnswer + "\n" + bottommes;
                                    #endregion
                                    DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "16：30短信报错：" + ex.ToString());
                                }
                            }
                            #endregion

                            #region 教学日期间日报图片
                            //9：15  未上报
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:14:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:16:00")))
                            {
                                try
                                {
                                    GetListData(9, "因病直报教育技术群,数据报送侦探队");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "09：15上报统计报错：" + ex.ToString());
                                }
                            }
                            //9：30  未上报 明细
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:31:00")))
                            {
                                try
                                {
                                    GetListData(9, "因病直报教育技术群,数据报送侦探队");
                                    GetListData(1, "因病直报教育技术群,数据报送侦探队");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "09：30未上报统计+明细报错：" + ex.ToString());
                                }
                            }
                            //10：00 未上报 明细
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                            {
                                try
                                {
                                    GetListData(9, "因病数据报送群");
                                    GetListData(1, "因病数据报送群");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "10：00上报统计+明细报错：" + ex.ToString());
                                }
                            }
                            //14：15 未午间 
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:14:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:16:00")))
                            {
                                try
                                {
                                    GetListData(8, "因病直报教育技术群,数据报送侦探队");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "14：15打卡统计报错：" + ex.ToString());
                                }
                            }
                            //14：30 未午间 明细
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:31:00")))
                            {
                                try
                                {
                                    GetListData(8, "因病直报教育技术群,数据报送侦探队");
                                    GetListData(3, "因病直报教育技术群,数据报送侦探队");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "14：30打卡统计+明细报错：" + ex.ToString());
                                }
                            }
                            //15：00 未午间 明细 未上报明细
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 14:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:01:00")))
                            {
                                try
                                {
                                    GetListData(8, "因病数据报送群");
                                    GetListData(3, "因病数据报送群");
                                    GetListData(1, "因病数据报送群");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "15：00打卡统计+明细+上报明细报错：" + ex.ToString());
                                }
                            }
                            //16：30  未午间明细
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                            {
                                try
                                {
                                    GetListData(3, "因病直报教育技术群,数据报送侦探队");
                                    GetListData(1, "因病直报教育技术群,数据报送侦探队");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "16：30打卡明细+上报明细报错：" + ex.ToString());
                                }
                            }
                            #endregion
                            //早上催报
                            #region 发送短信，发给填报人的（一天只发一次）
                            if (DateTime.Now > Convert.ToDateTime(qftime))
                            {
                                DoCLetterAllSent(con, cbmb, schooltypenamex);//一天只发一次
                            }
                            #endregion

                            #region 发送短信，发给领导人的（一天只发一次）
                            if (DateTime.Now > Convert.ToDateTime(qflimttime))
                            {
                                DoCLetterAllLeaderSent(con, cbmbx, schooltypenamex);//一天只发一次
                            }
                            #endregion

                            #region 发送短信10：30，发给填报人的（一天只发一次）
                            if (DateTime.Now > Convert.ToDateTime(cbtime10))
                            {
                                DoCLetterAllSent2(con, cbmb10, schooltypenamex);//一天只发一次
                            }
                            #endregion
                            #region 发送短信10：30，发给领导人的（一天只发一次）
                            if (DateTime.Now > Convert.ToDateTime(cbtimex10))
                            {
                                DoCLetterAllLeaderSent2(con, cbmbx10, schooltypenamex);//一天只发一次
                            }
                            #endregion

                            //下午打卡催报
                            #region 发送短信，发给填报人的（一天只发一次）
                            if (DateTime.Now > Convert.ToDateTime(kbtime))
                            {
                                DoCLetterAllSentK(con, kbmb, schooltypenamex);//一天只发一次
                            }
                            #endregion
                            #region 发送短信，发给领导人的（一天只发一次）
                            if (DateTime.Now > Convert.ToDateTime(kbtimex))
                            {
                                DoCLetterAllLeaderSentK(con, kbmbx, schooltypenamex);//一天只发一次
                            }
                            #endregion

                            #region 催报闭环催报短信
                            //填报人
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                            {
                                DoClosedLoopTSent(con, jiumessage);
                            }
                            //校领导
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:01:00")))
                            {
                                DoClosedLoopLSent(con, checkmessage);
                            }
                            #endregion

                            #region 图片和文件上报

                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:31:00")))
                            {
                                try
                                {
                                    GetListData(10, "因病直报教育技术群,数据报送侦探队");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "闭环统计报错：" + ex.ToString());
                                }
                            }

                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                            {
                                try
                                {
                                    GetListData(10, "因病直报教育技术群,数据报送侦探队");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "闭环统计报错：" + ex.ToString());
                                }
                            }
                            #endregion
                        }
                        //寒假
                        else if (ispressreport == 2)
                        {
                            if ((int)DateTime.Now.DayOfWeek >= 1 && (int)DateTime.Now.DayOfWeek <= 5)
                            {
                                //周一到周五
                                #region 寒假日报短信1~5
                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                                {
                                    try
                                    {
                                        MDataTable dayReport1 = GetDayList(con, 7) ?? new MDataTable();
                                        #region 数据
                                        int erCount = 1;
                                        string curAnswer = string.Empty;
                                        int allcount = dayReport1.Rows.Count;
                                        foreach (MDataRow er1 in dayReport1.Rows)
                                        {
                                            if (allcount - 1 == erCount)
                                            {
                                                break;
                                            }
                                            curAnswer += er1.Get("message", "").ToString();
                                            erCount++;
                                        }
                                        string bottommes = string.Empty;
                                        bottommes = dayReport1.Rows[allcount - 2].Get("message", "") + dayReport1.Rows[allcount - 1].Get("message", "");
                                        curAnswer = curAnswer + "\n" + bottommes;
                                        #endregion
                                        DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.WriteLog(DateTime.Now.ToString() + "16：30短信报错：" + ex.ToString());
                                    }
                                }
                                #endregion

                                #region 发送短信，发给填报人的（一天只发一次）
                                if (DateTime.Now > Convert.ToDateTime(qftime))
                                {
                                    DoCLetterAllSent(con, cbmb, schooltypenamex);//一天只发一次
                                }
                                #endregion

                                #region 催报闭环催报短信
                                //填报人
                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                                {
                                    DoClosedLoopTSent(con, jiumessage);
                                }
                                //校领导
                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:01:00")))
                                {
                                    DoClosedLoopLSent(con, checkmessage);
                                }
                                #endregion

                                #region 图片和文件上报
                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:31:00")))
                                {
                                    try
                                    {
                                        GetListData(9, "因病直报教育技术群,数据报送侦探队");
                                        GetListData(10, "因病直报教育技术群,数据报送侦探队");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.WriteLog(DateTime.Now.ToString() + "12：30上报统计报错：" + ex.ToString());
                                    }
                                }

                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                                {
                                    try
                                    {
                                        GetListData(10, "因病直报教育技术群,数据报送侦探队");
                                        GetListData(1, "因病直报教育技术群,数据报送侦探队");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.WriteLog(DateTime.Now.ToString() + "16：30打卡明细+上报明细报错：" + ex.ToString());
                                    }
                                }
                                #endregion
                            }
                            else
                            {
                                //周六周日
                                #region 寒假日报短信6~7
                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:29") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                                {
                                    try
                                    {
                                        MDataTable dayReport1 = GetDayList(con, 7) ?? new MDataTable();
                                        #region 数据
                                        int erCount = 1;
                                        string curAnswer = string.Empty;
                                        int allcount = dayReport1.Rows.Count;
                                        foreach (MDataRow er1 in dayReport1.Rows)
                                        {
                                            if (allcount - 1 == erCount)
                                            {
                                                break;
                                            }
                                            curAnswer += er1.Get("message", "").ToString();
                                            erCount++;
                                        }
                                        string bottommes = string.Empty;
                                        bottommes = dayReport1.Rows[allcount - 2].Get("message", "") + dayReport1.Rows[allcount - 1].Get("message", "");
                                        curAnswer = curAnswer + "\n" + bottommes;
                                        #endregion
                                        DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.WriteLog(DateTime.Now.ToString() + "16：30短信报错：" + ex.ToString());
                                    }
                                }
                                #endregion

                                #region 催报闭环催报短信
                                //填报人
                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:01:00")))
                                {
                                    DoClosedLoopTSent(con, jiumessage);
                                }
                                //校领导
                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:59:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:01:00")))
                                {
                                    DoClosedLoopLSent(con, checkmessage);
                                }
                                #endregion

                                #region 图片和文件上报

                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:31:00")))
                                {
                                    try
                                    {
                                        GetListData(10, "因病直报教育技术群,数据报送侦探队");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.WriteLog(DateTime.Now.ToString() + "闭环统计报错：" + ex.ToString());
                                    }
                                }

                                if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                                {
                                    try
                                    {
                                        GetListData(10, "因病直报教育技术群,数据报送侦探队");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.WriteLog(DateTime.Now.ToString() + "闭环统计报错：" + ex.ToString());
                                    }
                                }
                                #endregion
                            }
                        }
                        //暑假
                        else if (ispressreport == 3)
                        {
                            #region 非教学日日报短信 短信审核人

                            //if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:49:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 09:51:00")))
                            //{
                            //    try
                            //    {
                            //        MDataTable dayReport1 = GetDayListNew(con, 7) ?? new MDataTable();
                            //        #region 数据
                            //        int erCount = 1;
                            //        string curAnswer = string.Empty;
                            //        int allcount = dayReport1.Rows.Count;
                            //        foreach (MDataRow er1 in dayReport1.Rows)
                            //        {
                            //            if (allcount == erCount)
                            //            {
                            //                break;
                            //            }
                            //            curAnswer += er1.Get("message", "").ToString();
                            //            erCount++;
                            //        }
                            //        string bottommes = string.Empty;
                            //        bottommes = dayReport1.Rows[allcount - 1].Get("message", "");
                            //        curAnswer = curAnswer + "\n" + bottommes;
                            //        #endregion

                            //        DoSentAllDayReport(con, mrsprphone, curAnswer);
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        LogHelper.WriteLog(DateTime.Now.ToString() + "09:50短信报错：" + ex.ToString());
                            //    }

                            //}
                            //if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:49:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:51:00")))
                            //{
                            //    try
                            //    {
                            //        MDataTable dayReport1 = GetDayListNew(con, 7) ?? new MDataTable();
                            //        #region 数据
                            //        int erCount = 1;
                            //        string curAnswer = string.Empty;
                            //        int allcount = dayReport1.Rows.Count;
                            //        foreach (MDataRow er1 in dayReport1.Rows)
                            //        {
                            //            if (allcount == erCount)
                            //            {
                            //                break;
                            //            }
                            //            curAnswer += er1.Get("message", "").ToString();
                            //            erCount++;
                            //        }
                            //        string bottommes = string.Empty;
                            //        bottommes = dayReport1.Rows[allcount - 1].Get("message", "");
                            //        curAnswer = curAnswer + "\n" + bottommes;
                            //        #endregion

                            //        DoSentAllDayReport(con, mrsprphone, curAnswer);
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        LogHelper.WriteLog(DateTime.Now.ToString() + "12:50短信报错：" + ex.ToString());
                            //    }
                            //}
                            //if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 13:49:59") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 13:51:00")))
                            //{
                            //    try
                            //    {
                            //        MDataTable dayReport1 = GetDayListNew(con, 7) ?? new MDataTable();
                            //        #region 数据
                            //        int erCount = 1;
                            //        string curAnswer = string.Empty;
                            //        int allcount = dayReport1.Rows.Count;
                            //        foreach (MDataRow er1 in dayReport1.Rows)
                            //        {
                            //            if (allcount - 1 == erCount)
                            //            {
                            //                break;
                            //            }
                            //            curAnswer += er1.Get("message", "").ToString();
                            //            erCount++;
                            //        }
                            //        string bottommes = string.Empty;
                            //        bottommes = dayReport1.Rows[allcount - 2].Get("message", "") + dayReport1.Rows[allcount - 1].Get("message", "");
                            //        curAnswer = curAnswer + "\n" + bottommes;
                            //        #endregion
                            //        DoSentAllDayReport(con, mrsprphone, curAnswer);
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        LogHelper.WriteLog(DateTime.Now.ToString() + "13:50短信报错：" + ex.ToString());
                            //    }
                            //}

                            //if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:29") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                            //{
                            //    try
                            //    {
                            //        MDataTable dayReport1 = GetDayList(con, 7) ?? new MDataTable();
                            //        #region 数据
                            //        int erCount = 1;
                            //        string curAnswer = string.Empty;
                            //        int allcount = dayReport1.Rows.Count;
                            //        foreach (MDataRow er1 in dayReport1.Rows)
                            //        {
                            //            if (allcount - 1 == erCount)
                            //            {
                            //                break;
                            //            }
                            //            curAnswer += er1.Get("message", "").ToString();
                            //            erCount++;
                            //        }
                            //        string bottommes = string.Empty;
                            //        bottommes = dayReport1.Rows[allcount - 2].Get("message", "") + dayReport1.Rows[allcount - 1].Get("message", "");
                            //        curAnswer = curAnswer + "\n" + bottommes;
                            //        #endregion
                            //        DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        LogHelper.WriteLog(DateTime.Now.ToString() + "16：30短信报错：" + ex.ToString());
                            //    }
                            //}
                            #endregion


                            #region 上午催报短信

                            if (DateTime.Now > Convert.ToDateTime(qftime))
                            {
                                DoCLetterAllSent(con, cbmb, schooltypenamex);//一天只发一次
                            }
                            #endregion

                            #region 下午催报短信
                            if (DateTime.Now > Convert.ToDateTime(cbtime10))
                            {
                                DoCLetterAllSent2(con, cbmb10, schooltypenamex);//一天只发一次
                            }
                            #endregion
                        }
                        else
                        {
                            #region 非教学日日报短信
                            if ((DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:29:29") && DateTime.Now < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 16:31:00")))
                            {
                                try
                                {
                                    MDataTable dayReport1 = GetDayList(con, 7) ?? new MDataTable();
                                    #region 数据
                                    int erCount = 1;
                                    string curAnswer = string.Empty;
                                    int allcount = dayReport1.Rows.Count;
                                    foreach (MDataRow er1 in dayReport1.Rows)
                                    {
                                        if (allcount - 1 == erCount)
                                        {
                                            break;
                                        }
                                        curAnswer += er1.Get("message", "").ToString();
                                        erCount++;
                                    }
                                    string bottommes = string.Empty;
                                    bottommes = dayReport1.Rows[allcount - 2].Get("message", "") + dayReport1.Rows[allcount - 1].Get("message", "");
                                    curAnswer = curAnswer + "\n" + bottommes;
                                    #endregion
                                    DoSentAllDayReport(con, "13918342407", curAnswer, "因病数据报送群");
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.WriteLog(DateTime.Now.ToString() + "16：30短信报错：" + ex.ToString());
                                }
                            }
                            #endregion
                        }
                    }
                }
                #endregion

                #region 苗子可配置通知

                DoQLetterAllSent(con, curphone, miaomessage);

                #endregion

            }

        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.timer1.Enabled = true;
            nextDatetime = nextDatetime.AddSeconds(执行间隔);
        }

        #region 早间催报
        /// <summary>
        /// 催报短信群发（填报人）
        /// </summary>
        public void DoCLetterAllSent(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发(填报人员)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = " where a000.SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"   select   a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
             dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
             a000.SchoolNumber,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
              CASE   WHEN datediff(SECOND,a003.CreateDate,'" + curdateAll +
                                     @"')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
             from  report_school  a000   inner join report_community 
            on report_community.CommunityCode=a000.CommunityName
            left join  (
            select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
            select  OkCode,SchoolCode,CreateDate from (select   
            COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate='" +
                                     curdate + @"'   
            and WuRenLeiXing='无人缺课'  group by SchoolCode
            union all 
            select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
             where AbsenceDate='" + curdate + @"'    group by SchoolCode
            union all 
            select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
             where SuspnDate='" + curdate + @"'  and IsClasses='停课'  group by SchoolCode
             union all 
            select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
            where  CONVERT(varchar(10), report_emergency.CreateDate, 20)='" + curdate +
                                     @"'  group by SchoolCode) a002
            )s001 group by SchoolCode 
                          ) a003  on  a003.SchoolCode=a000.SchoolCode " + gradesWhere1;

                        #endregion

                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }

                        string messagemb = message;
                        action.ResetTable(sql);
                        MDataTable alldata = action.Select("reportstatus='未报'" + schooltypename);
                        string MessageCode = Guid.NewGuid().ToString();
                        string SchoolCodeArr = string.Empty;
                        string phonestr = string.Empty;
                        foreach (var item in alldata.Rows)
                        {
                            SchoolCodeArr += item.Get("SchoolCode", "") + ",";
                        }
                        if (!string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            SchoolCodeArr = SchoolCodeArr.TrimEnd(',');
                        }
                        action.ResetTable("report_school");

                        #region 小方法：获取学校

                        string schoolcodeArrtemp = string.Empty;
                        if (string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            schoolcodeArrtemp = "''";
                        }
                        foreach (string item in SchoolCodeArr.Split(','))
                        {
                            schoolcodeArrtemp += "'" + item + "',";
                        }
                        if (!string.IsNullOrEmpty(schoolcodeArrtemp))
                        {
                            schoolcodeArrtemp = schoolcodeArrtemp.TrimEnd(',');
                        }

                        String sWhere = " schoolcode in (" + schoolcodeArrtemp + ")";
                        //return DbService.GetTable("report_school", 0, sWhere);
                        MDataTable mTable = action.Select(sWhere) ?? new MDataTable();
                        //MDataTable mTable = GetBySchoolCode(SchoolCodeArr) ?? new MDataTable();

                        #endregion


                        //给重表进行赋值
                        //List<MDataRow> lstDetail = new List<MDataRow>();
                        //MDataRow dRow = new MDataRow();
                        string phonestrF = string.Empty;
                        int i = 0;
                        foreach (var item in mTable.Rows)
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            i++;
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            string phone = item.Get("ContactsPhone", "");
                            action.Set("PhoneNumber", phone);
                            if (CheckPhoneIsAble(phone))
                            {
                                phonestr += phone + ",";
                                if (i % 100 == 0)
                                {
                                    phonestrF += phone + "|";
                                }
                                else
                                {
                                    phonestrF += phone + ",";
                                }
                            }
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                        //主表新增
                        action.ResetTable("Report_PhoneMessage");
                        action.Set("MessageCode", MessageCode);
                        action.Set("CreateDate", DateTime.Now);
                        action.Set("CreateUserCode", "admin");
                        action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发(填报人员)");
                        action.Set("message", messagemb);
                        action.Set("SchoolCodeArr", SchoolCodeArr);
                        action.Set("lettertype", 0);
                        if (!string.IsNullOrEmpty(phonestr))
                        {
                            phonestr = phonestr.TrimEnd(',');
                            phonestrF = phonestrF.TrimEnd(',');

                            string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                            for (int j = 0; j < phonestrF.Split('|').Length; j++)
                            {
                                String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestrF.Split('|')[j].ToString() +
                                                 "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }


                        }
                        //返回值
                        if (!action.Insert())
                        {
                            action.RollBack();
                        }
                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }

                }
                #endregion
            }
        }
        /// <summary>
        /// 催报短信群发（领导人）
        /// </summary>
        public void DoCLetterAllLeaderSent(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发(分管校级领导)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = " where a000.SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"   select   a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
             dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
             a000.SchoolNumber,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
              CASE   WHEN datediff(SECOND,a003.CreateDate,'" + curdateAll +
                                     @"')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
             from  report_school  a000   inner join report_community 
            on report_community.CommunityCode=a000.CommunityName
            left join  (
            select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
            select  OkCode,SchoolCode,CreateDate from (select   
            COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate='" +
                                     curdate + @"'   
            and WuRenLeiXing='无人缺课'  group by SchoolCode
            union all 
            select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
             where AbsenceDate='" + curdate + @"'    group by SchoolCode
            union all 
            select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
             where SuspnDate='" + curdate + @"'  and IsClasses='停课'  group by SchoolCode
             union all 
            select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
            where  CONVERT(varchar(10), report_emergency.CreateDate, 20)='" + curdate +
                                     @"'  group by SchoolCode) a002  
            )s001 group by SchoolCode 
            ) a003  on  a003.SchoolCode=a000.SchoolCode " + gradesWhere1;

                        #endregion


                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }
                        //action.ResetTable("adf_datadic");
                        //action.Select("diccode = 'cbmb'").Rows[0].Get("dicvalue", "");
                        string messagemb = message;
                        action.ResetTable(sql);
                        MDataTable alldata = action.Select("reportstatus='未报'" + schooltypename);
                        string MessageCode = Guid.NewGuid().ToString();
                        string SchoolCodeArr = string.Empty;
                        string phonestr = string.Empty;
                        foreach (var item in alldata.Rows)
                        {
                            SchoolCodeArr += item.Get("SchoolCode", "") + ",";
                        }
                        if (!string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            SchoolCodeArr = SchoolCodeArr.TrimEnd(',');
                        }
                        action.ResetTable("report_school");

                        #region 小方法：获取学校

                        string schoolcodeArrtemp = string.Empty;
                        if (string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            schoolcodeArrtemp = "''";
                        }
                        foreach (string item in SchoolCodeArr.Split(','))
                        {
                            schoolcodeArrtemp += "'" + item + "',";
                        }
                        if (!string.IsNullOrEmpty(schoolcodeArrtemp))
                        {
                            schoolcodeArrtemp = schoolcodeArrtemp.TrimEnd(',');
                        }

                        String sWhere = " schoolcode in (" + schoolcodeArrtemp + ")";
                        //return DbService.GetTable("report_school", 0, sWhere);
                        MDataTable mTable = action.Select(sWhere) ?? new MDataTable();
                        //MDataTable mTable = GetBySchoolCode(SchoolCodeArr) ?? new MDataTable();

                        #endregion


                        //给重表进行赋值
                        //List<MDataRow> lstDetail = new List<MDataRow>();
                        //MDataRow dRow = new MDataRow();
                        string phonestrF = string.Empty;
                        int i = 0;
                        foreach (var item in mTable.Rows)
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            i++;
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            string phone = item.Get("LContactsPhone", "");
                            action.Set("PhoneNumber", phone);
                            if (CheckPhoneIsAble(phone))
                            {
                                phonestr += phone + ",";
                                if (i % 100 == 0)
                                {
                                    phonestrF += phone + "|";
                                }
                                else
                                {
                                    phonestrF += phone + ",";
                                }
                            }
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                        //主表新增
                        action.ResetTable("Report_PhoneMessage");
                        action.Set("MessageCode", MessageCode);
                        action.Set("CreateDate", DateTime.Now);
                        action.Set("CreateUserCode", "admin");
                        action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发(分管校级领导)");
                        action.Set("message", messagemb);
                        action.Set("SchoolCodeArr", SchoolCodeArr);
                        if (!string.IsNullOrEmpty(phonestr))
                        {
                            phonestr = phonestr.TrimEnd(',');
                            phonestrF = phonestrF.TrimEnd(',');

                            string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                            for (int j = 0; j < phonestrF.Split('|').Length; j++)
                            {
                                string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestrF.Split('|') +
                                                 "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }


                        }
                        //返回值
                        if (!action.Insert())
                        {
                            action.RollBack();
                        }
                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }

                }
                #endregion
            }
        }

        /// <summary>
        /// 催报短信群发（填报人）
        /// </summary>
        public void DoCLetterAllSent2(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发2(填报人员)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = " where a000.SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"   select   a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
             dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
             a000.SchoolNumber,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
              CASE   WHEN datediff(SECOND,a003.CreateDate,'" + curdateAll +
                                     @"')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
             from  report_school  a000   inner join report_community 
            on report_community.CommunityCode=a000.CommunityName
            left join  (
            select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
            select  OkCode,SchoolCode,CreateDate from (select   
            COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate='" +
                                     curdate + @"'   
            and WuRenLeiXing='无人缺课'  group by SchoolCode
            union all 
            select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
             where AbsenceDate='" + curdate + @"'    group by SchoolCode
            union all 
            select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
             where SuspnDate='" + curdate + @"'  and IsClasses='停课'  group by SchoolCode
             union all 
            select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
            where  CONVERT(varchar(10), report_emergency.CreateDate, 20)='" + curdate +
                                     @"'  group by SchoolCode) a002
            )s001 group by SchoolCode 
                          ) a003  on  a003.SchoolCode=a000.SchoolCode " + gradesWhere1;

                        #endregion

                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }

                        string messagemb = message;
                        action.ResetTable(sql);
                        MDataTable alldata = action.Select("reportstatus='未报'" + schooltypename);
                        string MessageCode = Guid.NewGuid().ToString();
                        string SchoolCodeArr = string.Empty;
                        string phonestr = string.Empty;
                        foreach (var item in alldata.Rows)
                        {
                            SchoolCodeArr += item.Get("SchoolCode", "") + ",";
                        }
                        if (!string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            SchoolCodeArr = SchoolCodeArr.TrimEnd(',');
                        }
                        action.ResetTable("report_school");

                        #region 小方法：获取学校

                        string schoolcodeArrtemp = string.Empty;
                        if (string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            schoolcodeArrtemp = "''";
                        }
                        foreach (string item in SchoolCodeArr.Split(','))
                        {
                            schoolcodeArrtemp += "'" + item + "',";
                        }
                        if (!string.IsNullOrEmpty(schoolcodeArrtemp))
                        {
                            schoolcodeArrtemp = schoolcodeArrtemp.TrimEnd(',');
                        }

                        String sWhere = " schoolcode in (" + schoolcodeArrtemp + ")";
                        //return DbService.GetTable("report_school", 0, sWhere);
                        MDataTable mTable = action.Select(sWhere) ?? new MDataTable();
                        //MDataTable mTable = GetBySchoolCode(SchoolCodeArr) ?? new MDataTable();

                        #endregion


                        //给重表进行赋值
                        //List<MDataRow> lstDetail = new List<MDataRow>();
                        //MDataRow dRow = new MDataRow();
                        string phonestrF = string.Empty;
                        int i = 0;
                        foreach (var item in mTable.Rows)
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            i++;
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            string phone = item.Get("ContactsPhone", "");
                            action.Set("PhoneNumber", phone);
                            if (CheckPhoneIsAble(phone))
                            {
                                phonestr += phone + ",";
                                if (i % 100 == 0)
                                {
                                    phonestrF += phone + "|";
                                }
                                else
                                {
                                    phonestrF += phone + ",";
                                }
                            }
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                        //主表新增
                        action.ResetTable("Report_PhoneMessage");
                        action.Set("MessageCode", MessageCode);
                        action.Set("CreateDate", DateTime.Now);
                        action.Set("CreateUserCode", "admin");
                        action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发2(填报人员)");
                        action.Set("message", messagemb);
                        action.Set("SchoolCodeArr", SchoolCodeArr);
                        action.Set("lettertype", 0);
                        if (!string.IsNullOrEmpty(phonestr))
                        {
                            phonestr = phonestr.TrimEnd(',');
                            phonestrF = phonestrF.TrimEnd(',');

                            string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                            for (int j = 0; j < phonestrF.Split('|').Length; j++)
                            {
                                String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestrF.Split('|')[j].ToString() +
                                                 "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }


                        }
                        //返回值
                        if (!action.Insert())
                        {
                            action.RollBack();
                        }
                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }

                }
                #endregion
            }
        }
        /// <summary>
        /// 催报短信群发（领导人）
        /// </summary>
        public void DoCLetterAllLeaderSent2(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发2(分管校级领导)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = " where a000.SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"   select   a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
             dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
             a000.SchoolNumber,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
              CASE   WHEN datediff(SECOND,a003.CreateDate,'" + curdateAll +
                                     @"')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
             from  report_school  a000   inner join report_community 
            on report_community.CommunityCode=a000.CommunityName
            left join  (
            select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
            select  OkCode,SchoolCode,CreateDate from (select   
            COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate='" +
                                     curdate + @"'   
            and WuRenLeiXing='无人缺课'  group by SchoolCode
            union all 
            select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
             where AbsenceDate='" + curdate + @"'    group by SchoolCode
            union all 
            select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
             where SuspnDate='" + curdate + @"'  and IsClasses='停课'  group by SchoolCode
             union all 
            select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
            where  CONVERT(varchar(10), report_emergency.CreateDate, 20)='" + curdate +
                                     @"'  group by SchoolCode) a002  
            )s001 group by SchoolCode 
            ) a003  on  a003.SchoolCode=a000.SchoolCode " + gradesWhere1;

                        #endregion


                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }
                        //action.ResetTable("adf_datadic");
                        //action.Select("diccode = 'cbmb'").Rows[0].Get("dicvalue", "");
                        string messagemb = message;
                        action.ResetTable(sql);
                        MDataTable alldata = action.Select("reportstatus='未报'" + schooltypename);
                        string MessageCode = Guid.NewGuid().ToString();
                        string SchoolCodeArr = string.Empty;
                        string phonestr = string.Empty;
                        foreach (var item in alldata.Rows)
                        {
                            SchoolCodeArr += item.Get("SchoolCode", "") + ",";
                        }
                        if (!string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            SchoolCodeArr = SchoolCodeArr.TrimEnd(',');
                        }
                        action.ResetTable("report_school");

                        #region 小方法：获取学校

                        string schoolcodeArrtemp = string.Empty;
                        if (string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            schoolcodeArrtemp = "''";
                        }
                        foreach (string item in SchoolCodeArr.Split(','))
                        {
                            schoolcodeArrtemp += "'" + item + "',";
                        }
                        if (!string.IsNullOrEmpty(schoolcodeArrtemp))
                        {
                            schoolcodeArrtemp = schoolcodeArrtemp.TrimEnd(',');
                        }

                        String sWhere = " schoolcode in (" + schoolcodeArrtemp + ")";
                        //return DbService.GetTable("report_school", 0, sWhere);
                        MDataTable mTable = action.Select(sWhere) ?? new MDataTable();
                        //MDataTable mTable = GetBySchoolCode(SchoolCodeArr) ?? new MDataTable();

                        #endregion


                        //给重表进行赋值
                        //List<MDataRow> lstDetail = new List<MDataRow>();
                        //MDataRow dRow = new MDataRow();
                        string phonestrF = string.Empty;
                        int i = 0;
                        foreach (var item in mTable.Rows)
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            i++;
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            string phone = item.Get("LContactsPhone", "");
                            action.Set("PhoneNumber", phone);
                            if (CheckPhoneIsAble(phone))
                            {
                                phonestr += phone + ",";
                                if (i % 100 == 0)
                                {
                                    phonestrF += phone + "|";
                                }
                                else
                                {
                                    phonestrF += phone + ",";
                                }
                            }
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                        //主表新增
                        action.ResetTable("Report_PhoneMessage");
                        action.Set("MessageCode", MessageCode);
                        action.Set("CreateDate", DateTime.Now);
                        action.Set("CreateUserCode", "admin");
                        action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发2(分管校级领导)");
                        action.Set("message", messagemb);
                        action.Set("SchoolCodeArr", SchoolCodeArr);
                        if (!string.IsNullOrEmpty(phonestr))
                        {
                            phonestr = phonestr.TrimEnd(',');
                            phonestrF = phonestrF.TrimEnd(',');

                            string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                            for (int j = 0; j < phonestrF.Split('|').Length; j++)
                            {
                                string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestrF.Split('|') +
                                                 "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }


                        }
                        //返回值
                        if (!action.Insert())
                        {
                            action.RollBack();
                        }
                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }

                }
                #endregion
            }
        }
        /// <summary>
        /// 催报短信群发（区领导人）
        /// </summary>
        public void DoCLetterAreaLeaderSent(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发(区领导人)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = " where a000.SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion


                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"  select CountyName,count(1)num
from(
select * from (
select   a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
a000.SchoolNumber,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
CASE   WHEN datediff(SECOND,a003.CreateDate,'" + curdateAll +
                                     @"')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
from  report_school  a000   inner join report_community 
on report_community.CommunityCode=a000.CommunityName
left join  (
select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate='" + curdate + @"'   
and WuRenLeiXing='无人缺课'  group by SchoolCode
union all 
select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
where AbsenceDate='" + curdate + @"'    group by SchoolCode
union all 
select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
where SuspnDate='" + curdate + @"'  and IsClasses='停课'  group by SchoolCode
union all 
select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
where  CONVERT(varchar(10), report_emergency.CreateDate, 20)='" + curdate + @"'  group by SchoolCode) a002  
)s001 group by SchoolCode 
) a003  on  a003.SchoolCode=a000.SchoolCode " + gradesWhere1 + @"
)s where reportstatus='未报' " + schooltypename + @" @swhere
)m group by CountyName ";
                        #endregion

                        string messagemb = message;

                        //托幼
                        #region 托幼
                        string tysql = sql.Replace("@swhere", " and SchoolTypeName in ('幼儿园','托育点') ");
                        action.ResetTable(tysql);
                        MDataTable alldataty = action.Select();
                        if (alldataty.Rows.Count > 0)
                        {
                            string leaderphone = string.Empty;
                            foreach (var item in alldataty.Rows)
                            {
                                if (item.Get("num", 0) > 0)
                                {
                                    string CountyName = item.Get("CountyName", "");
                                    string sql1 = "select * from (select a.* from adf_user a inner join adf_userrole b on a.usercode=b.UserCode where b.RoleCode ='qujk' or b.RoleCode='xianqu')v where CountyName='" + CountyName + "' and usercode like'%ty'";
                                    action.ResetTable(sql1);
                                    //托幼
                                    MDataTable Leaderusergroup = action.Select();
                                    //获取区负责人号码
                                    foreach (var itemq in Leaderusergroup.Rows)
                                    {
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone1", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone1", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone2", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone2", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone3", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone3", "") + ",";
                                        }
                                    }
                                    string MessageCode = Guid.NewGuid().ToString();
                                    string phonestr = leaderphone;
                                    action.ResetTable("Report_PhoneMessage_detail");
                                    action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("SendCommunityCode", CountyName);
                                    action.Set("SendCityName", "上海市");
                                    action.Set("SendCountyName", "");
                                    action.Set("SchoolCode", "");
                                    action.Set("PhoneNumber", phonestr);
                                    if (!action.Insert())
                                    {
                                        action.RollBack();
                                    }

                                    //主表新增
                                    action.ResetTable("Report_PhoneMessage");
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("CreateDate", DateTime.Now);
                                    action.Set("CreateUserCode", "admin");
                                    action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发(区领导人)");
                                    action.Set("message", messagemb);
                                    action.Set("SchoolCodeArr", "");
                                    #region 发送短信
                                    if (!string.IsNullOrEmpty(phonestr))
                                    {
                                        phonestr = phonestr.TrimEnd(',');

                                        string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);
                                        string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestr +
                                                         "&content=" + messagecontent + "&reqReport=true";
                                        //调用短信接口
                                        Root ot = new Root();
                                        string reurl = string.Empty;
                                        try
                                        {
                                            reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            action.Set("batchId", ot.batchId);
                                            action.Set("code", ot.code);
                                        }
                                        catch (Exception ex)
                                        {
                                            //action.RollBack();
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            if (ot == null)
                                            {
                                                action.Set("batchId", "");
                                                action.Set("code", 400);
                                            }
                                            else
                                            {
                                                action.Set("batchId", ot.batchId);
                                                action.Set("code", ot.code);
                                            }

                                        }


                                    }

                                    #endregion
                                    //返回值
                                    if (!action.Insert())
                                    {
                                        action.RollBack();

                                    }

                                }
                            }

                        }

                        #endregion

                        //中小学
                        #region 中小学
                        string zxxsql = sql.Replace("@swhere", " and SchoolTypeName not in ('幼儿园','托育点') ");
                        action.ResetTable(zxxsql);
                        MDataTable alldatazxx = action.Select();
                        if (alldatazxx.Rows.Count > 0)
                        {
                            string leaderphone = string.Empty;
                            foreach (var item in alldatazxx.Rows)
                            {
                                if (item.Get("num", 0) > 0)
                                {
                                    string CountyName = item.Get("CountyName", "");
                                    string sql1 = "select * from (select a.* from adf_user a inner join adf_userrole b on a.usercode=b.UserCode where b.RoleCode ='qujk' or b.RoleCode='xianqu')v where CountyName='" + CountyName + "' and usercode like'%ty'";
                                    action.ResetTable(sql1);
                                    //托幼
                                    MDataTable Leaderusergroup = action.Select();
                                    //获取区负责人号码
                                    foreach (var itemq in Leaderusergroup.Rows)
                                    {
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone1", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone1", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone2", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone2", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone3", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone3", "") + ",";
                                        }
                                    }
                                    string MessageCode = Guid.NewGuid().ToString();
                                    string phonestr = leaderphone;
                                    action.ResetTable("Report_PhoneMessage_detail");
                                    action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("SendCommunityCode", CountyName);
                                    action.Set("SendCityName", "上海市");
                                    action.Set("SendCountyName", "");
                                    action.Set("SchoolCode", "");
                                    action.Set("PhoneNumber", phonestr);
                                    if (!action.Insert())
                                    {
                                        action.RollBack();
                                    }

                                    //主表新增
                                    action.ResetTable("Report_PhoneMessage");
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("CreateDate", DateTime.Now);
                                    action.Set("CreateUserCode", "admin");
                                    action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发(区领导人)");
                                    action.Set("message", messagemb);
                                    action.Set("SchoolCodeArr", "");
                                    #region 发送短信
                                    if (!string.IsNullOrEmpty(phonestr))
                                    {
                                        phonestr = phonestr.TrimEnd(',');

                                        string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);
                                        string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestr +
                                                         "&content=" + messagecontent + "&reqReport=true";
                                        //调用短信接口
                                        Root ot = new Root();
                                        string reurl = string.Empty;
                                        try
                                        {
                                            reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            action.Set("batchId", ot.batchId);
                                            action.Set("code", ot.code);
                                        }
                                        catch (Exception ex)
                                        {
                                            //action.RollBack();
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            if (ot == null)
                                            {
                                                action.Set("batchId", "");
                                                action.Set("code", 400);
                                            }
                                            else
                                            {
                                                action.Set("batchId", ot.batchId);
                                                action.Set("code", ot.code);
                                            }

                                        }


                                    }

                                    #endregion
                                    //返回值
                                    if (!action.Insert())
                                    {
                                        action.RollBack();

                                    }

                                }
                            }

                        }

                        #endregion

                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }


                }
                #endregion
            }
        }
        #endregion

        #region 午检催报
        /// <summary>
        /// 催报短信群发<打卡>（填报人）
        /// </summary>
        public void DoCLetterAllSentK(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发<打卡>(填报人员)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = " where SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"  select Contacts,ContactsPhone,SchoolLeaders,LContactsPhone,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)='" + curdate + @"') c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate='" + curdate + @"' and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001 " + gradesWhere1;

                        #endregion

                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }

                        string messagemb = message;
                        action.ResetTable(sql);
                        MDataTable alldata = action.Select("isSiginStr='未午检打卡'" + schooltypename);
                        string MessageCode = Guid.NewGuid().ToString();
                        string SchoolCodeArr = string.Empty;
                        string phonestr = string.Empty;
                        foreach (var item in alldata.Rows)
                        {
                            SchoolCodeArr += item.Get("SchoolCode", "") + ",";
                        }
                        if (!string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            SchoolCodeArr = SchoolCodeArr.TrimEnd(',');
                        }
                        action.ResetTable("report_school");

                        #region 小方法：获取学校

                        string schoolcodeArrtemp = string.Empty;
                        if (string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            schoolcodeArrtemp = "''";
                        }
                        foreach (string item in SchoolCodeArr.Split(','))
                        {
                            schoolcodeArrtemp += "'" + item + "',";
                        }
                        if (!string.IsNullOrEmpty(schoolcodeArrtemp))
                        {
                            schoolcodeArrtemp = schoolcodeArrtemp.TrimEnd(',');
                        }

                        String sWhere = " schoolcode in (" + schoolcodeArrtemp + ")";
                        //return DbService.GetTable("report_school", 0, sWhere);
                        MDataTable mTable = action.Select(sWhere) ?? new MDataTable();
                        //MDataTable mTable = GetBySchoolCode(SchoolCodeArr) ?? new MDataTable();

                        #endregion


                        //给重表进行赋值
                        //List<MDataRow> lstDetail = new List<MDataRow>();
                        //MDataRow dRow = new MDataRow();
                        string phonestrF = string.Empty;
                        int i = 0;
                        foreach (var item in mTable.Rows)
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            i++;
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            string phone = item.Get("ContactsPhone", "");
                            action.Set("PhoneNumber", phone);
                            if (CheckPhoneIsAble(phone))
                            {
                                phonestr += phone + ",";
                                if (i % 100 == 0)
                                {
                                    phonestrF += phone + "|";
                                }
                                else
                                {
                                    phonestrF += phone + ",";
                                }
                            }
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                        //主表新增
                        action.ResetTable("Report_PhoneMessage");
                        action.Set("MessageCode", MessageCode);
                        action.Set("CreateDate", DateTime.Now);
                        action.Set("CreateUserCode", "admin");
                        action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发<打卡>(填报人员)");
                        action.Set("message", messagemb);
                        action.Set("SchoolCodeArr", SchoolCodeArr);
                        action.Set("lettertype", 0);
                        if (!string.IsNullOrEmpty(phonestr))
                        {
                            phonestr = phonestr.TrimEnd(',');
                            phonestrF = phonestrF.TrimEnd(',');

                            string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                            for (int j = 0; j < phonestrF.Split('|').Length; j++)
                            {
                                String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestrF.Split('|')[j].ToString() +
                                                 "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }


                        }
                        //返回值
                        if (!action.Insert())
                        {
                            action.RollBack();
                        }
                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }

                }
                #endregion
            }
        }
        /// <summary>
        /// 催报短信群发<打卡>（领导人）
        /// </summary>
        public void DoCLetterAllLeaderSentK(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发<打卡>(分管校级领导)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = " where SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"  select Contacts,ContactsPhone,SchoolLeaders,LContactsPhone,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)='" + curdate + @"') c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate='" + curdate + @"' and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001 " + gradesWhere1;

                        #endregion


                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }
                        //action.ResetTable("adf_datadic");
                        //action.Select("diccode = 'cbmb'").Rows[0].Get("dicvalue", "");
                        string messagemb = message;
                        action.ResetTable(sql);
                        MDataTable alldata = action.Select("isSiginStr='未午检打卡'" + schooltypename);
                        string MessageCode = Guid.NewGuid().ToString();
                        string SchoolCodeArr = string.Empty;
                        string phonestr = string.Empty;
                        foreach (var item in alldata.Rows)
                        {
                            SchoolCodeArr += item.Get("SchoolCode", "") + ",";
                        }
                        if (!string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            SchoolCodeArr = SchoolCodeArr.TrimEnd(',');
                        }
                        action.ResetTable("report_school");

                        #region 小方法：获取学校

                        string schoolcodeArrtemp = string.Empty;
                        if (string.IsNullOrEmpty(SchoolCodeArr))
                        {
                            schoolcodeArrtemp = "''";
                        }
                        foreach (string item in SchoolCodeArr.Split(','))
                        {
                            schoolcodeArrtemp += "'" + item + "',";
                        }
                        if (!string.IsNullOrEmpty(schoolcodeArrtemp))
                        {
                            schoolcodeArrtemp = schoolcodeArrtemp.TrimEnd(',');
                        }

                        String sWhere = " schoolcode in (" + schoolcodeArrtemp + ")";
                        //return DbService.GetTable("report_school", 0, sWhere);
                        MDataTable mTable = action.Select(sWhere) ?? new MDataTable();
                        //MDataTable mTable = GetBySchoolCode(SchoolCodeArr) ?? new MDataTable();

                        #endregion


                        //给重表进行赋值
                        //List<MDataRow> lstDetail = new List<MDataRow>();
                        //MDataRow dRow = new MDataRow();
                        string phonestrF = string.Empty;
                        int i = 0;
                        foreach (var item in mTable.Rows)
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            i++;
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            string phone = item.Get("LContactsPhone", "");
                            action.Set("PhoneNumber", phone);
                            if (CheckPhoneIsAble(phone))
                            {
                                phonestr += phone + ",";
                                if (i % 100 == 0)
                                {
                                    phonestrF += phone + "|";
                                }
                                else
                                {
                                    phonestrF += phone + ",";
                                }
                            }
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                        //主表新增
                        action.ResetTable("Report_PhoneMessage");
                        action.Set("MessageCode", MessageCode);
                        action.Set("CreateDate", DateTime.Now);
                        action.Set("CreateUserCode", "admin");
                        action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发<打卡>(分管校级领导)");
                        action.Set("message", messagemb);
                        action.Set("SchoolCodeArr", SchoolCodeArr);
                        if (!string.IsNullOrEmpty(phonestr))
                        {
                            phonestr = phonestr.TrimEnd(',');
                            phonestrF = phonestrF.TrimEnd(',');

                            string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                            for (int j = 0; j < phonestrF.Split('|').Length; j++)
                            {
                                string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestrF.Split('|') +
                                                 "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }


                        }
                        //返回值
                        if (!action.Insert())
                        {
                            action.RollBack();
                        }
                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }

                }
                #endregion
            }
        }

        /// <summary>
        /// 催报短信群发<打卡>（区领导人）
        /// </summary>
        public void DoCLetterAreaLeaderSentK(string conn, string message, string schooltypenamex)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string curdateAll = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string curdate = DateTime.Now.ToString("yyyy-MM-dd");
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                if (!action.Exists("title like '%催报自动群发<打卡>(区领导人)' and CONVERT(varchar(100),CreateDate,23)='" + curdate + "'"))
                {
                    action.BeginTransation();
                    try
                    {
                        action.ResetTable("adf_datadic");
                        string gradesStr = action.Select("diccode = 'curgrade'").Rows[0].Get("dicvalue", "");

                        #region 年级条件
                        string gradesWhere1 = string.Empty;
                        if (!string.IsNullOrEmpty(gradesStr))
                        {
                            var gradesArr = gradesStr.Split(',');
                            string minGrade = string.Empty;
                            int x = 0;
                            foreach (var item in gradesArr)
                            {
                                if (x == 0)
                                {
                                    minGrade += "grade like '%" + item + "%'";
                                }
                                else
                                {
                                    minGrade += " or grade like '%" + item + "%'";
                                }
                                x++;
                            }
                            gradesWhere1 = "  and a000.SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
                        }
                        #endregion


                        string schooltypename = string.Empty;
                        if (!string.IsNullOrEmpty(schooltypenamex))
                        {
                            // and SchoolTypeName in('')
                            schooltypename = " and SchoolTypeName in('" + schooltypenamex.Replace(",", "','") + "')";
                        }
                        #region sql

                        //把输入的数据拼接成sql语句，并交给cmd对象
                        string sql = @"  select CountyName,count(1)num from ( 
select Contacts,ContactsPhone,SchoolLeaders,LContactsPhone,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)='" + curdate + @"') c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate='" + curdate + @"' and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001 where 1=1 " + gradesWhere1 + schooltypename + @" @swhere)m group by CountyName";

                        #endregion

                        string messagemb = message;

                        //托幼
                        #region 托幼
                        string tysql = sql.Replace("@swhere", " and SchoolTypeName in ('幼儿园','托育点') ");
                        action.ResetTable(tysql);
                        MDataTable alldataty = action.Select();
                        if (alldataty.Rows.Count > 0)
                        {
                            string leaderphone = string.Empty;
                            foreach (var item in alldataty.Rows)
                            {
                                if (item.Get("num", 0) > 0)
                                {
                                    string CountyName = item.Get("CountyName", "");
                                    string sql1 = "select * from (select a.* from adf_user a inner join adf_userrole b on a.usercode=b.UserCode where b.RoleCode ='qujk' or b.RoleCode='xianqu')v where CountyName='" + CountyName + "' and usercode like'%ty'";
                                    action.ResetTable(sql1);
                                    //托幼
                                    MDataTable Leaderusergroup = action.Select();
                                    //获取区负责人号码
                                    foreach (var itemq in Leaderusergroup.Rows)
                                    {
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone1", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone1", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone2", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone2", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone3", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone3", "") + ",";
                                        }
                                    }
                                    string MessageCode = Guid.NewGuid().ToString();
                                    string phonestr = leaderphone;
                                    action.ResetTable("Report_PhoneMessage_detail");
                                    action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("SendCommunityCode", CountyName);
                                    action.Set("SendCityName", "上海市");
                                    action.Set("SendCountyName", "");
                                    action.Set("SchoolCode", "");
                                    action.Set("PhoneNumber", phonestr);
                                    if (!action.Insert())
                                    {
                                        action.RollBack();
                                    }

                                    //主表新增
                                    action.ResetTable("Report_PhoneMessage");
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("CreateDate", DateTime.Now);
                                    action.Set("CreateUserCode", "admin");
                                    action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发<打卡>(区领导人)");
                                    action.Set("message", messagemb);
                                    action.Set("SchoolCodeArr", "");
                                    #region 发送短信
                                    if (!string.IsNullOrEmpty(phonestr))
                                    {
                                        phonestr = phonestr.TrimEnd(',');

                                        string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);
                                        string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestr +
                                                         "&content=" + messagecontent + "&reqReport=true";
                                        //调用短信接口
                                        Root ot = new Root();
                                        string reurl = string.Empty;
                                        try
                                        {
                                            reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            action.Set("batchId", ot.batchId);
                                            action.Set("code", ot.code);
                                        }
                                        catch (Exception ex)
                                        {
                                            //action.RollBack();
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            if (ot == null)
                                            {
                                                action.Set("batchId", "");
                                                action.Set("code", 400);
                                            }
                                            else
                                            {
                                                action.Set("batchId", ot.batchId);
                                                action.Set("code", ot.code);
                                            }

                                        }


                                    }

                                    #endregion
                                    //返回值
                                    if (!action.Insert())
                                    {
                                        action.RollBack();

                                    }

                                }
                            }

                        }

                        #endregion

                        //中小学
                        #region 中小学
                        string zxxsql = sql.Replace("@swhere", " and SchoolTypeName not in ('幼儿园','托育点') ");
                        action.ResetTable(zxxsql);
                        MDataTable alldatazxx = action.Select();
                        if (alldatazxx.Rows.Count > 0)
                        {
                            string leaderphone = string.Empty;
                            foreach (var item in alldatazxx.Rows)
                            {
                                if (item.Get("num", 0) > 0)
                                {
                                    string CountyName = item.Get("CountyName", "");
                                    string sql1 = "select * from (select a.* from adf_user a inner join adf_userrole b on a.usercode=b.UserCode where b.RoleCode ='qujk' or b.RoleCode='xianqu')v where CountyName='" + CountyName + "' and usercode like'%ty'";
                                    action.ResetTable(sql1);
                                    //托幼
                                    MDataTable Leaderusergroup = action.Select();
                                    //获取区负责人号码
                                    foreach (var itemq in Leaderusergroup.Rows)
                                    {
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone1", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone1", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone2", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone2", "") + ",";
                                        }
                                        if (CheckPhoneIsAble(itemq.Get("fzcellphone3", "")))
                                        {
                                            leaderphone += itemq.Get("fzcellphone3", "") + ",";
                                        }
                                    }
                                    string MessageCode = Guid.NewGuid().ToString();
                                    string phonestr = leaderphone;
                                    action.ResetTable("Report_PhoneMessage_detail");
                                    action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("SendCommunityCode", CountyName);
                                    action.Set("SendCityName", "上海市");
                                    action.Set("SendCountyName", "");
                                    action.Set("SchoolCode", "");
                                    action.Set("PhoneNumber", phonestr);
                                    if (!action.Insert())
                                    {
                                        action.RollBack();
                                    }

                                    //主表新增
                                    action.ResetTable("Report_PhoneMessage");
                                    action.Set("MessageCode", MessageCode);
                                    action.Set("CreateDate", DateTime.Now);
                                    action.Set("CreateUserCode", "admin");
                                    action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "催报自动群发<打卡>(区领导人)");
                                    action.Set("message", messagemb);
                                    action.Set("SchoolCodeArr", "");
                                    #region 发送短信
                                    if (!string.IsNullOrEmpty(phonestr))
                                    {
                                        phonestr = phonestr.TrimEnd(',');

                                        string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);
                                        string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonestr +
                                                         "&content=" + messagecontent + "&reqReport=true";
                                        //调用短信接口
                                        Root ot = new Root();
                                        string reurl = string.Empty;
                                        try
                                        {
                                            reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            action.Set("batchId", ot.batchId);
                                            action.Set("code", ot.code);
                                        }
                                        catch (Exception ex)
                                        {
                                            //action.RollBack();
                                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                                            if (ot == null)
                                            {
                                                action.Set("batchId", "");
                                                action.Set("code", 400);
                                            }
                                            else
                                            {
                                                action.Set("batchId", ot.batchId);
                                                action.Set("code", ot.code);
                                            }

                                        }


                                    }

                                    #endregion
                                    //返回值
                                    if (!action.Insert())
                                    {
                                        action.RollBack();

                                    }

                                }
                            }

                        }

                        #endregion

                    }
                    catch (Exception ex)
                    {
                        action.RollBack();
                        exeMsgInfo.RetValue = ex.ToString();
                        exeMsgInfo.RetStatus = 400;
                    }
                    finally
                    {
                        action.EndTransation();
                    }


                }
                #endregion
            }
        }
        #endregion

        #region 条子 发送给固定人员 (发给各区业务负责人)

        /// <summary>
        /// 苗子短信群发
        /// </summary>
        public void DoQLetterAllSent(string conn, string curphone, string miaomessage)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            string tempphone = curphone;
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑

                try
                {
                    action.BeginTransation();
                    #region sql
                    //string sql = @"  select * from report_vseedlingdetail where CONVERT(datetime,CreateDate)>=dateadd(day, -3, getdate()) and  SeedlingCode not in (select SeedlingCode from Report_QPhoneMessage_detail)";
                    string sql = @"  SELECT a.*,
--STUFF(
--(SELECT ',' + convert(varchar(10),Grade)+'('+convert(varchar(10),Class)+')'
--FROM (select SeedlingCode,Grade,Class from  report_seedlingcases group by SeedlingCode,Grade,Class)s001
--WHERE SeedlingCode=a.SeedlingCode
--FOR xml path('')
--),1,1,''
--)gradeclass
''gradeclass
from report_vseedlingdetail a
where CONVERT(datetime,CreateDate)>=dateadd(day, -30, getdate()) and  SeedlingCode not in (select SeedlingCode from Report_QPhoneMessage_detail)";
                    #endregion
                    action.ResetTable(sql);
                    MDataTable alldata = action.Select();
                    int i = 0;
                    if (alldata.Rows.Count > 0)
                    {
                        foreach (var item in alldata.Rows)
                        {
                            string SeedlingClaim = item.Get("SeedlingClaim", "");//市级、区级、校级
                            string gradeclass = item.Get("gradeclass", ""); //触发年级
                            curphone = tempphone;
                            if (SeedlingClaim.Contains("校级") || SeedlingClaim.Contains("区级"))
                            {
                                curphone = "";
                            }
                            i++;
                            string MessageCode = Guid.NewGuid().ToString();

                            action.ResetTable("report_school");

                            #region 小方法：获取学校

                            String sWhere = " schoolcode ='" + item.Get("SchoolCode", "") + "'";
                            MDataTable mTable = action.Select(sWhere) ?? new MDataTable();
                            #endregion

                            string SchoolTypeName = mTable.Rows[0].Get("SchoolTypeName", "");
                            string CountyName = mTable.Rows[0].Get("CountyName", "");
                            string leaderphone = string.Empty;
                            MDataTable Leaderusergroup = new MDataTable();
                            if (SeedlingClaim.Contains("市级") || SeedlingClaim.Contains("区级") || SeedlingClaim.Contains("发热"))
                            {
                                if (SchoolTypeName == "幼儿园" || SchoolTypeName == "托育点")
                                {
                                    string sql1 = "select * from (select a.* from adf_user a inner join adf_userrole b on a.usercode=b.UserCode where b.RoleCode ='qujk' or b.RoleCode='xianqu')v where CountyName='" + CountyName + "' and usercode like'%ty'";
                                    action.ResetTable(sql1);
                                    //托幼
                                    Leaderusergroup = action.Select();

                                }
                                else
                                {
                                    string sql2 = "select * from (select a.* from adf_user a inner join adf_userrole b on a.usercode=b.UserCode where b.RoleCode ='qujk' or b.RoleCode='xianqu')v where CountyName='" + CountyName + "' and usercode like'%zxx'";
                                    action.ResetTable(sql2);
                                    //中小学
                                    Leaderusergroup = action.Select();
                                }
                                foreach (var itemq in Leaderusergroup.Rows)
                                {
                                    //业务负责人号码
                                    if (CheckPhoneIsAble(itemq.Get("fzcellphone1", "")))
                                    {
                                        leaderphone += itemq.Get("fzcellphone1", "") + ",";
                                    }
                                    if (CheckPhoneIsAble(itemq.Get("fzcellphone2", "")))
                                    {
                                        leaderphone += itemq.Get("fzcellphone2", "") + ",";
                                    }
                                    if (CheckPhoneIsAble(itemq.Get("fzcellphone3", "")))
                                    {
                                        leaderphone += itemq.Get("fzcellphone3", "") + ",";
                                    }
                                    //科室负责人号码
                                    if (CheckPhoneIsAble(itemq.Get("departmentcellphone", "")))
                                    {
                                        leaderphone += itemq.Get("departmentcellphone", "") + ",";
                                    }
                                }
                            }
                            //foreach (var phoneItem in curphone.Split(','))
                            //{                     
                            curphone = leaderphone + curphone;
                            //if (!string.IsNullOrEmpty(curphone))
                            //{
                            if (!string.IsNullOrEmpty(curphone))
                            {
                                curphone = curphone.TrimEnd(',');
                                curphone += ",";
                            }
                            action.ResetTable("Report_QPhoneMessage_detail");
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", mTable.Rows[0].Get("CommunityName", ""));
                            action.Set("SendCityName", mTable.Rows[0].Get("CityName", ""));
                            action.Set("SendCountyName", mTable.Rows[0].Get("CountyName", ""));
                            action.Set("SchoolCode", mTable.Rows[0].Get("SchoolCode", ""));
                            action.Set("SeedlingCode", item.Get("SeedlingCode", ""));
                            action.Set("PhoneNumber", mTable.Rows[0].Get("LContactsPhone", ""));//校领导
                            if (CheckPhoneIsAble(mTable.Rows[0].Get("LContactsPhone", "")))
                            {
                                curphone += mTable.Rows[0].Get("LContactsPhone", "") + ",";
                            }
                            if (CheckPhoneIsAble(mTable.Rows[0].Get("ContactsPhone", "")))
                            {
                                curphone += mTable.Rows[0].Get("ContactsPhone", "") + ",";
                            }
                            if (!string.IsNullOrEmpty(curphone))
                            {
                                curphone = curphone.TrimEnd(',');
                            }
                            action.Set("QPhoneNumber", curphone);
                            //从表新增
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                            //}
                            //}学校：{学校名称}在{时间}触发{苗子名称}
                            string lettermessage = miaomessage.Replace("{学校名称}", item.Get("SchoolName", "")).Replace("{时间}", item.Get("CreateDate", DateTime.Now).ToString("yyyy-MM-dd")).Replace("{苗子名称}", item.Get("SeedlingClaim", ""));//"学校：" + item.Get("SchoolName", "") + " 在 " + item.Get("CreateDate", DateTime.Now).ToString("yyyy-MM-dd") + " 触发了苗子<" + item.Get("SeedlingClaim", "") + ">";
                                                                                                                                                                                                                                           //if (!string.IsNullOrEmpty(lettermessage))
                                                                                                                                                                                                                                           //{
                                                                                                                                                                                                                                           //    lettermessage = lettermessage + ",触发的年级和班级<" + gradeclass + ">";
                                                                                                                                                                                                                                           //}
                            action.ResetTable("Report_PhoneMessage");
                            string messagecontent = HttpUtility.UrlEncode(lettermessage, Encoding.Default);

                            string messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + curphone + "&content=" + messagecontent + "&reqReport=true";
                            //调用短信接口
                            Root ot = new Root();
                            string reurl = string.Empty;
                            try
                            {
                                reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                ot = JsonConvert.DeserializeObject<Root>(reurl);
                                action.Set("batchId", ot.batchId);
                                action.Set("code", ot.code);
                            }
                            catch (Exception ex)
                            {
                                //action.RollBack();
                                ot = JsonConvert.DeserializeObject<Root>(reurl);
                                if (ot == null)
                                {
                                    action.Set("batchId", "");
                                    action.Set("code", 400);
                                }
                                else
                                {
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }

                            }
                            //返回值
                            action.Set("MessageCode", MessageCode);
                            action.Set("CreateDate", DateTime.Now);
                            action.Set("CreateUserCode", "admin");
                            action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "预警自动群发<" + item.Get("SchoolName", "") + ":" + item.Get("SeedlingClaim", "") + ">");
                            action.Set("message", lettermessage);
                            action.Set("SchoolCodeArr", item.Get("SchoolCode", ""));
                            action.Set("lettertype", 1);
                            //主表增加
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    action.RollBack();
                    exeMsgInfo.RetValue = ex.ToString();
                    exeMsgInfo.RetStatus = 400;
                }
                finally
                {
                    action.EndTransation();
                }
                #endregion
            }
        }

        #endregion

        #region 是否闭环催报
        /// <summary>
        /// 是否闭环（填报人）
        /// </summary>
        public void DoClosedLoopTSent(string conn, string message)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                action.BeginTransation();
                try
                {
                    #region sql

                    //把输入的数据拼接成sql语句，并交给cmd对象
                    string sql = @" select c.CountyName,c.CityName,c.CommunityName,c.SchoolCode,SchoolName,Contacts,ContactsPhone,SchoolLeaders,LContactsPhone,count(1)as'allcount'
,(stuff((
select ';'+s02.StudentName from Report_Student_Absence_Management s01 
inner join report_student_absence s02 on s01.AbsenceCode=s02.AbsenceCode 
inner join report_school s03 on s01.SchoolCode=s03.SchoolCode 
 where s02.SchoolCode=c.SchoolCode and isnull(s01.isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,s02.AbsenceDate),getdate())>=3  FOR xml PATH('')), 1, 1, '')
)studentname 
from Report_Student_Absence_Management a 
inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
inner join report_school c on a.SchoolCode=c.SchoolCode 
inner join report_county d on c.CountyName=d.countyname
where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=3
group by c.CountyName,c.CityName,c.CommunityName,c.SchoolCode,SchoolName,Contacts,ContactsPhone,SchoolLeaders,LContactsPhone
 ";

                    #endregion

                    string messagemb = message;
                    action.ResetTable(sql);
                    MDataTable alldata = action.Select();  //所有学校信息
                    string tempmessage = messagemb;
                    foreach (var item in alldata.Rows)
                    {
                        messagemb = tempmessage;
                        string MessageCode = Guid.NewGuid().ToString();
                        string allcount = item.Get("allcount", "");//数量
                        string studentname = item.Get("studentname", "");//名单
                        string phone = item.Get("ContactsPhone", "");
                        messagemb = messagemb.Replace("{学校}", item.Get("SchoolName", "")).Replace("{数量}", allcount).Replace("{名单}", studentname);
                        if (CheckPhoneIsAble(phone))
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            action.Set("PhoneNumber", phone);
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }

                            //主表新增
                            action.ResetTable("Report_PhoneMessage");
                            action.Set("MessageCode", MessageCode);
                            action.Set("CreateDate", DateTime.Now);
                            action.Set("CreateUserCode", "admin");
                            action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "提醒闭环(填报人员)");
                            action.Set("message", messagemb);
                            action.Set("SchoolCodeArr", item.Get("SchoolCode", ""));
                            action.Set("lettertype", 0);
                            if (!string.IsNullOrEmpty(phone))
                            {
                                string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                                String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phone +
                                                     "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }
                            //返回值
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }

                    }

                }
                catch (Exception ex)
                {
                    action.RollBack();
                    exeMsgInfo.RetValue = ex.ToString();
                    exeMsgInfo.RetStatus = 400;
                }
                finally
                {
                    action.EndTransation();
                }

                #endregion
            }
        }

        /// <summary>
        /// 是否闭环（校领导）
        /// </summary>
        public void DoClosedLoopLSent(string conn, string message)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                #region 现有逻辑
                action.BeginTransation();
                try
                {
                    #region sql

                    //把输入的数据拼接成sql语句，并交给cmd对象
                    string sql = @" select c.CountyName,c.CityName,c.CommunityName,c.SchoolCode,SchoolName,Contacts,ContactsPhone,SchoolLeaders,LContactsPhone,count(1)as'allcount'
,(stuff((
select ';'+s02.StudentName from Report_Student_Absence_Management s01 
inner join report_student_absence s02 on s01.AbsenceCode=s02.AbsenceCode 
inner join report_school s03 on s01.SchoolCode=s03.SchoolCode 
 where s02.SchoolCode=c.SchoolCode and isnull(s01.isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,s02.AbsenceDate),getdate())>=14  FOR xml PATH('')), 1, 1, '')
)studentname 
from Report_Student_Absence_Management a 
inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
inner join report_school c on a.SchoolCode=c.SchoolCode 
inner join report_county d on c.CountyName=d.countyname
where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=14
group by c.CountyName,c.CityName,c.CommunityName,c.SchoolCode,SchoolName,Contacts,ContactsPhone,SchoolLeaders,LContactsPhone
 ";

                    #endregion

                    string messagemb = message;
                    action.ResetTable(sql);
                    MDataTable alldata = action.Select();  //所有学校信息
                    string tempmessage = messagemb;
                    foreach (var item in alldata.Rows)
                    {
                        messagemb = tempmessage;
                        string MessageCode = Guid.NewGuid().ToString();
                        string allcount = item.Get("allcount", "");//数量
                        string studentname = item.Get("studentname", "");//名单
                        string phone = item.Get("LContactsPhone", "");
                        messagemb = messagemb.Replace("{学校}", item.Get("SchoolName", "")).Replace("{数量}", allcount).Replace("{名单}", studentname);
                        if (CheckPhoneIsAble(phone))
                        {
                            action.ResetTable("Report_PhoneMessage_detail");
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", item.Get("CommunityName", ""));
                            action.Set("SendCityName", item.Get("CityName", ""));
                            action.Set("SendCountyName", item.Get("CountyName", ""));
                            action.Set("SchoolCode", item.Get("SchoolCode", ""));
                            action.Set("PhoneNumber", phone);
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }

                            //主表新增
                            action.ResetTable("Report_PhoneMessage");
                            action.Set("MessageCode", MessageCode);
                            action.Set("CreateDate", DateTime.Now);
                            action.Set("CreateUserCode", "admin");
                            action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "提醒闭环(校领导)");
                            action.Set("message", messagemb);
                            action.Set("SchoolCodeArr", item.Get("SchoolCode", ""));
                            action.Set("lettertype", 0);
                            if (!string.IsNullOrEmpty(phone))
                            {
                                string messagecontent = HttpUtility.UrlEncode(messagemb, Encoding.Default);

                                String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phone +
                                                     "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }
                            }
                            //返回值
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }

                    }

                }
                catch (Exception ex)
                {
                    action.RollBack();
                    exeMsgInfo.RetValue = ex.ToString();
                    exeMsgInfo.RetStatus = 400;
                }
                finally
                {
                    action.EndTransation();
                }

                #endregion
            }
        }
        #endregion

        #region 发送预备短信

        public void DoAtuoLoopTSent(string conn)
        {
            using (MAction action = new MAction("report_timingsend", conn))
            {
                cache.Clear();//清除所有缓存项
                MDataTable Taball = action.Select(" sendstatus=0 ") ?? new MDataTable();
                string mrsprphone = string.Empty;
                using (MAction dataDic = new MAction("adf_datadic", conn))
                {
                    mrsprphone = (dataDic.Select(" diccode='mrsprphone' ").Rows[0] ?? new MDataRow()).Get("dicvalue", "");
                }
                           
                foreach (MDataRow item in Taball.Rows)
                {
                    string sendappointmenttime = item.Get("sendappointmenttime", DateTime.Now).ToString("yyyy-MM-dd HH:mm");   //发送时间
                    string remindertime = item.Get("remindertime", DateTime.Now).ToString("yyyy-MM-dd HH:mm");    //预约时间
                    string sendmessage = item.Get("sendmessage", "");//短息内容
                    string sendphone = item.Get("sendphone", "");//发送号码
                    string wxteamname = item.Get("wxteamname", "");//发送群名
                    string timingsendcode = item.Get("timingsendcode", "");//主键
                    if (DateTime.Now.ToString("yyyy-MM-dd HH:mm") == remindertime)
                    {
                        //string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/text?room=" + wxteamname, "", "短信即将在5分钟后发送");
                        string messagecontent = HttpUtility.UrlEncode("短信即将在2分钟后发送", Encoding.Default);
                        String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + mrsprphone +
                                                    "&content=" + messagecontent + "&reqReport=true";
                        HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                    }
                    if (DateTime.Now.ToString("yyyy-MM-dd HH:mm") == sendappointmenttime)
                    {
                        #region 发送短信

                        action.ResetTable("Report_PhoneMessage");
                        if (!string.IsNullOrEmpty(sendphone))
                        {
                            string MessageCode = Guid.NewGuid().ToString();
                            action.ResetTable("Report_PhoneMessage_detail");
                            action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                            action.Set("MessageCode", MessageCode);
                            action.Set("SendCommunityCode", "2df768c3-0620-4cfa-b854-7c722858df5f");
                            action.Set("SendCityName", "上海市");
                            action.Set("SendCountyName", "市级日报领导短信");
                            action.Set("SchoolCode", "");
                            action.Set("PhoneNumber", sendphone);
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }

                            //主表新增
                            action.ResetTable("Report_PhoneMessage");
                            action.Set("MessageCode", MessageCode);
                            action.Set("CreateDate", DateTime.Now);
                            action.Set("CreateUserCode", "admin");
                            action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "市级日报领导短信");
                            action.Set("message", sendmessage);
                            action.Set("SchoolCodeArr", "");
                            action.Set("lettertype", 0);
                            if (!string.IsNullOrEmpty(sendphone))
                            {
                                string messagecontent = HttpUtility.UrlEncode("\n" + sendmessage, Encoding.Default);

                                String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + sendphone +
                                                     "&content=" + messagecontent + "&reqReport=true";
                                //调用短信接口
                                Root ot = new Root();
                                string reurl = string.Empty;
                                try
                                {
                                    reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    action.Set("batchId", ot.batchId);
                                    action.Set("code", ot.code);
                                }
                                catch (Exception ex)
                                {
                                    //action.RollBack();
                                    ot = JsonConvert.DeserializeObject<Root>(reurl);
                                    if (ot == null)
                                    {
                                        action.Set("batchId", "");
                                        action.Set("code", 400);
                                    }
                                    else
                                    {
                                        action.Set("batchId", ot.batchId);
                                        action.Set("code", ot.code);
                                    }

                                }


                            }
                            //返回值
                            if (!action.Insert())
                            {
                                action.RollBack();
                            }
                        }
                        #endregion
                        //string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/text?room=" + wxteamname, "", "短信发送成功");

                        HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + mrsprphone +
                                                    "&content=" + HttpUtility.UrlEncode("短信发送成功", Encoding.Default) + "&reqReport=true");

                        action.ResetTable("report_timingsend");
                        action.Set("sendstatus", 1);
                        action.Update("timingsendcode='" + timingsendcode + "'");
                    }
                }
            }
        }
        #endregion

        /// <summary>
        /// 手机号输入验证
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool CheckPhoneIsAble(string input)
        {
            if (input.Length < 11)
            {
                return false;
            }
            //电信手机号码正则
            string dianxin = @"^1[35789][01379]\d{8}$";
            Regex regexDX = new Regex(dianxin);
            //联通手机号码正则
            string liantong = @"^1[34578][01256]\d{8}";
            Regex regexLT = new Regex(liantong);
            //移动手机号码正则
            string yidong = @"^(1[0123456789]\d{8}|1[345678][012356789]\d{8})$";
            Regex regexYD = new Regex(yidong);
            string suiji = @"^1[0123456789][0123456789]\d{8}$";
            Regex regexSJ = new Regex(suiji);
            if (regexDX.IsMatch(input) || regexLT.IsMatch(input) || regexYD.IsMatch(input) || regexSJ.IsMatch(input))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public class Root
        {
            /// <summary>
            /// 批号
            /// </summary>
            public string batchId { get; set; }
            /// <summary>
            /// 状态码
            /// </summary>
            public int code { get; set; }
        }

        /// <summary>
        /// get 请求
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="postDataStr"></param>
        /// <returns></returns>
        public static string HttpGet2(string Url, string postDataStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

        //苗子两个以上关联
        public void seleseedling()
        {
            using (MAction action = new MAction("report_standard", con))
            {
                //获取两个疾病以上苗子
                MDataTable standard = action.Select(" isnull(DiseaseCode2,'') !='' or isnull(DiseaseCode3,'') !='' ") ?? new MDataTable();
                foreach (MDataRow onestandard in standard.Rows)
                {
                    string StandardCode = onestandard.Get("StandardCode", "");//标准编号
                    string StandardName = onestandard.Get("StandardName", "");//标准名称
                    string DiseaseCode = onestandard.Get("DiseaseCode", "");//第一疾病编号
                    string StandardType = onestandard.Get("StandardType", "");//标准类型
                    string StandardDay = onestandard.Get("StandardDay", "");//天数
                    string StandardPeoples = onestandard.Get("StandardPeoples", "");//人数
                    string StandardTypeName = onestandard.Get("StandardTypeName", "");//类型
                    string ThresholdCondition = onestandard.Get("ThresholdCondition", "");//阀值条件
                    string ThresholdCriteria = onestandard.Get("ThresholdCriteria", "");//阀值标准  
                    string sType = onestandard.Get("sType", "");//类型
                    string DiseaseCode2 = onestandard.Get("DiseaseCode2", "");//第二疾病编号
                    string DiseaseCode3 = onestandard.Get("DiseaseCode3", "");//第三疾病编号 
                    string StandardOrder = onestandard.Get("StandardOrder", "");//标准序号
                    if (StandardType == "校级")
                    {
                        if (!string.IsNullOrEmpty(DiseaseCode2) && !string.IsNullOrEmpty(DiseaseCode3))
                        {
                            #region 关联三个疾病
                            //某个学校多少人发病
                            string sql = @"  select SchoolCode,COUNT(1) as 'allcount' from (
select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @"-1 --在这区间内最近的几天
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=3
)x001 group by SchoolCode
";
                            action.ResetTable(sql);
                            MDataTable schooldiseaseCount = action.Select(" allcount >=" + StandardPeoples) ?? new MDataTable();//人数标准达标学校code
                                                                                                                                //存在的话开始循环
                            foreach (var xzitem in schooldiseaseCount.Rows)
                            {
                                int DiseaseNumber = xzitem.Get("allcount", 0);
                                string schoolcode = xzitem.Get("SchoolCode", "");
                                //获取学校明细
                                action.ResetTable("Report_School");
                                MDataRow SchoolInfo = action.Select("SchoolCode='" + schoolcode + "'").Rows[0];
                                //查询是否存在
                                string sExistTab = "select * from dbo.Report_Seedling where  DATEDIFF(DAY,CreateDate,GETDATE())=0 and StandardCode= '" + StandardCode + "' and SchoolCode='" + schoolcode + "'";
                                action.ResetTable(sExistTab);
                                if (action.Select().Rows.Count <= 0)//不存的话进行插入
                                {
                                    //今天有没有新增
                                    string todaysql = @"select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and AbsenceDate= CONVERT(varchar(10),GETDATE(),120)  and SchoolCode='" + schoolcode + @"'
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=3";
                                    action.ResetTable(todaysql);
                                    if (action.Select().Rows.Count > 0)
                                    {
                                        string SeedlingCode = Guid.NewGuid().ToString();
                                        #region 插入主表
                                        //插入主表
                                        action.ResetTable("Report_Seedling");
                                        action.Set("SeedlingCode", SeedlingCode);
                                        action.Set("DiseaseCode", DiseaseCode);
                                        action.Set("SeedlingClaim", StandardName);
                                        action.Set("SeedlingName", DiseaseCode);
                                        action.Set("StandardTypeName", StandardTypeName);
                                        action.Set("SchoolCode", schoolcode);
                                        action.Set("SchoolNumber", SchoolInfo.Get("SchoolNumber", ""));
                                        action.Set("SchoolName", SchoolInfo.Get("SchoolName", ""));
                                        action.Set("CityName", SchoolInfo.Get("CityName", ""));
                                        action.Set("CountyName", SchoolInfo.Get("CountyName", ""));
                                        action.Set("CommunityName", SchoolInfo.Get("CommunityName", ""));
                                        action.Set("StandardType", StandardType);
                                        action.Set("StandardDay", StandardDay);
                                        action.Set("StandardPeoples", StandardPeoples);
                                        action.Set("StandardOrder", StandardOrder);
                                        action.Set("ThresholdCondition", ThresholdCondition);
                                        action.Set("ThresholdCriteria", ThresholdCriteria);
                                        action.Set("Contacts", SchoolInfo.Get("Contacts", ""));
                                        action.Set("ContactsPhone", SchoolInfo.Get("ContactsPhone", ""));
                                        action.Set("DiseaseNumber", DiseaseNumber);
                                        action.Set("CreateDate", DateTime.Now);
                                        action.Set("ResultStatues", "0");
                                        action.Set("IsAccord", "是");
                                        action.Set("StandardCode", StandardCode);
                                        action.Set("sType", sType);
                                        action.Set("DiseaseCode2", DiseaseCode2);
                                        action.Set("DiseaseCode3", DiseaseCode3);
                                        action.Insert();
                                        #endregion

                                        string SeedDetailSql = @"select b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode,COUNT(1)alcount 
from report_absencedetail a inner join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @" and SchoolCode='" + schoolcode + @"' and Casenature='新发' --在这区间内最近的几天
group by b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode
having COUNT(1)=3";
                                        action.ResetTable(SeedDetailSql);
                                        MDataTable SeedDetailTab = action.Select() ?? new MDataTable();
                                        //插入从表
                                        #region 插入从表
                                        foreach (var Detail in SeedDetailTab.Rows)
                                        {
                                            action.ResetTable("report_seedlingcases");
                                            action.Set("SeedlingCasesCode", Guid.NewGuid().ToString());
                                            action.Set("SeedlingCode", SeedlingCode);
                                            action.Set("AbsenceCode", Detail.Get("AbsenceCode", ""));
                                            action.Set("SchoolCode", Detail.Get("SchoolCode", ""));
                                            action.Set("AbsenceDate", Detail.Get("AbsenceDate", ""));
                                            action.Set("Grade", Detail.Get("Grade", ""));
                                            action.Set("Class", Detail.Get("Class", ""));
                                            action.Set("OtherGrade", Detail.Get("OtherGrade", ""));
                                            action.Set("Gender", Detail.Get("Gender", ""));
                                            action.Set("StudentName", Detail.Get("StudentName", ""));
                                            action.Set("Age", Detail.Get("Age", ""));
                                            action.Set("Casenature", Detail.Get("Casenature", ""));
                                            action.Set("CaseStatus", Detail.Get("CaseStatus", ""));
                                            action.Set("Remark", Detail.Get("Remark", ""));
                                            action.Set("AbsenceNumber", Detail.Get("AbsenceNumber", ""));
                                            action.Set("Disease", Detail.Get("Disease", ""));
                                            action.Set("OrthrDisease", Detail.Get("OrthrDisease", ""));
                                            action.Set("Symptom", Detail.Get("Symptom", ""));
                                            action.Set("OrtherSymptom", Detail.Get("OrtherSymptom", ""));
                                            action.Set("Hurt", Detail.Get("Hurt", ""));
                                            action.Set("OrtherHurt", Detail.Get("OrtherHurt", ""));
                                            action.Set("Degree", Detail.Get("Degree", ""));
                                            action.Set("ReprotCode", Detail.Get("ReprotCode", ""));
                                            action.Set("CreateDate", Detail.Get("CreateDate", ""));
                                            action.Set("CreateUserCode", Detail.Get("CreateUserCode", ""));
                                            action.Set("ModifyDate", Detail.Get("ModifyDate", ""));
                                            action.Set("ModifyUserCode", Detail.Get("ModifyUserCode", ""));
                                            action.Insert();
                                        }
                                        #endregion

                                    }

                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region 关联两个疾病
                            //某个学校多少人发病
                            string sql = @"  select SchoolCode,COUNT(1) as 'allcount' from (
select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @"-1 --在这区间内最近的几天
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=2
)x001 group by SchoolCode
";
                            action.ResetTable(sql);
                            MDataTable schooldiseaseCount = action.Select(" allcount >=" + StandardPeoples) ?? new MDataTable();//人数标准达标学校code
                                                                                                                                //存在的话开始循环
                            foreach (var xzitem in schooldiseaseCount.Rows)
                            {
                                int DiseaseNumber = xzitem.Get("allcount", 0);
                                string schoolcode = xzitem.Get("SchoolCode", "");
                                //获取学校明细
                                action.ResetTable("Report_School");
                                MDataRow SchoolInfo = action.Select("SchoolCode='" + schoolcode + "'").Rows[0];
                                //查询是否存在
                                string sExistTab = "select * from dbo.Report_Seedling where  DATEDIFF(DAY,CreateDate,GETDATE())=0 and StandardCode= '" + StandardCode + "' and SchoolCode='" + schoolcode + "'";
                                action.ResetTable(sExistTab);
                                if (action.Select().Rows.Count <= 0)//不存的话进行插入
                                {
                                    //今天有没有新增
                                    string todaysql = @"select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and AbsenceDate= CONVERT(varchar(10),GETDATE(),120)  and SchoolCode='" + schoolcode + @"'
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=2";
                                    action.ResetTable(todaysql);
                                    if (action.Select().Rows.Count > 0)
                                    {
                                        string SeedlingCode = Guid.NewGuid().ToString();
                                        #region 插入主表
                                        //插入主表
                                        action.ResetTable("Report_Seedling");
                                        action.Set("SeedlingCode", SeedlingCode);
                                        action.Set("DiseaseCode", DiseaseCode);
                                        action.Set("SeedlingClaim", StandardName);
                                        action.Set("SeedlingName", DiseaseCode);
                                        action.Set("StandardTypeName", StandardTypeName);
                                        action.Set("SchoolCode", schoolcode);
                                        action.Set("SchoolNumber", SchoolInfo.Get("SchoolNumber", ""));
                                        action.Set("SchoolName", SchoolInfo.Get("SchoolName", ""));
                                        action.Set("CityName", SchoolInfo.Get("CityName", ""));
                                        action.Set("CountyName", SchoolInfo.Get("CountyName", ""));
                                        action.Set("CommunityName", SchoolInfo.Get("CommunityName", ""));
                                        action.Set("StandardType", StandardType);
                                        action.Set("StandardDay", StandardDay);
                                        action.Set("StandardPeoples", StandardPeoples);
                                        action.Set("StandardOrder", StandardOrder);
                                        action.Set("ThresholdCondition", ThresholdCondition);
                                        action.Set("ThresholdCriteria", ThresholdCriteria);
                                        action.Set("Contacts", SchoolInfo.Get("Contacts", ""));
                                        action.Set("ContactsPhone", SchoolInfo.Get("ContactsPhone", ""));
                                        action.Set("DiseaseNumber", DiseaseNumber);
                                        action.Set("CreateDate", DateTime.Now);
                                        action.Set("ResultStatues", "0");
                                        action.Set("IsAccord", "是");
                                        action.Set("StandardCode", StandardCode);
                                        action.Set("sType", sType);
                                        action.Set("DiseaseCode2", DiseaseCode2);
                                        action.Set("DiseaseCode3", DiseaseCode3);
                                        action.Insert();
                                        #endregion

                                        string SeedDetailSql = @"select b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode,COUNT(1)alcount 
from report_absencedetail a inner join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @" and SchoolCode='" + schoolcode + @"' and Casenature='新发' --在这区间内最近的几天
group by b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode
having COUNT(1)=2";
                                        action.ResetTable(SeedDetailSql);
                                        MDataTable SeedDetailTab = action.Select() ?? new MDataTable();
                                        //插入从表
                                        #region 插入从表
                                        foreach (var Detail in SeedDetailTab.Rows)
                                        {
                                            action.ResetTable("report_seedlingcases");
                                            action.Set("SeedlingCasesCode", Guid.NewGuid().ToString());
                                            action.Set("SeedlingCode", SeedlingCode);
                                            action.Set("AbsenceCode", Detail.Get("AbsenceCode", ""));
                                            action.Set("SchoolCode", Detail.Get("SchoolCode", ""));
                                            action.Set("AbsenceDate", Detail.Get("AbsenceDate", ""));
                                            action.Set("Grade", Detail.Get("Grade", ""));
                                            action.Set("Class", Detail.Get("Class", ""));
                                            action.Set("OtherGrade", Detail.Get("OtherGrade", ""));
                                            action.Set("Gender", Detail.Get("Gender", ""));
                                            action.Set("StudentName", Detail.Get("StudentName", ""));
                                            action.Set("Age", Detail.Get("Age", ""));
                                            action.Set("Casenature", Detail.Get("Casenature", ""));
                                            action.Set("CaseStatus", Detail.Get("CaseStatus", ""));
                                            action.Set("Remark", Detail.Get("Remark", ""));
                                            action.Set("AbsenceNumber", Detail.Get("AbsenceNumber", ""));
                                            action.Set("Disease", Detail.Get("Disease", ""));
                                            action.Set("OrthrDisease", Detail.Get("OrthrDisease", ""));
                                            action.Set("Symptom", Detail.Get("Symptom", ""));
                                            action.Set("OrtherSymptom", Detail.Get("OrtherSymptom", ""));
                                            action.Set("Hurt", Detail.Get("Hurt", ""));
                                            action.Set("OrtherHurt", Detail.Get("OrtherHurt", ""));
                                            action.Set("Degree", Detail.Get("Degree", ""));
                                            action.Set("ReprotCode", Detail.Get("ReprotCode", ""));
                                            action.Set("CreateDate", Detail.Get("CreateDate", ""));
                                            action.Set("CreateUserCode", Detail.Get("CreateUserCode", ""));
                                            action.Set("ModifyDate", Detail.Get("ModifyDate", ""));
                                            action.Set("ModifyUserCode", Detail.Get("ModifyUserCode", ""));
                                            action.Insert();
                                        }
                                        #endregion

                                    }

                                }
                            }
                            #endregion
                        }
                    }
                    else if (StandardType == "班级")
                    {
                        if (!string.IsNullOrEmpty(DiseaseCode2) && !string.IsNullOrEmpty(DiseaseCode3))
                        {
                            #region 关联三个疾病
                            //某个学校多少人发病
                            string sql = @"  select SchoolCode,Grade,Class,COUNT(1) as 'allcount' from (
select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @"-1 --在这区间内最近的几天
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=3
)x001 group by SchoolCode,Grade,Class
";
                            action.ResetTable(sql);
                            MDataTable schooldiseaseCount = action.Select(" allcount >=" + StandardPeoples) ?? new MDataTable();//人数标准达标学校code
                                                                                                                                //存在的话开始循环
                            foreach (var xzitem in schooldiseaseCount.Rows)
                            {
                                int DiseaseNumber = xzitem.Get("allcount", 0);
                                string schoolcode = xzitem.Get("SchoolCode", "");
                                string Grade = xzitem.Get("Grade", "");
                                string Class = xzitem.Get("Class", "");
                                //获取学校明细
                                action.ResetTable("Report_School");
                                MDataRow SchoolInfo = action.Select("SchoolCode='" + schoolcode + "'").Rows[0];
                                //查询是否存在
                                string sExistTab = "select * from dbo.Report_Seedling where  DATEDIFF(DAY,CreateDate,GETDATE())=0 and StandardCode= '" + StandardCode + "' and SchoolCode='" + schoolcode + "' and Grade='" + Grade + "' and Class='" + Class + "'";
                                action.ResetTable(sExistTab);
                                if (action.Select().Rows.Count <= 0)//不存的话进行插入
                                {
                                    //今天有没有新增
                                    string todaysql = @"select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and AbsenceDate= CONVERT(varchar(10),GETDATE(),120)  and SchoolCode='" + schoolcode + @"' and Grade='" + Grade + @"' and Class='" + Class + @"'
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=3";
                                    action.ResetTable(todaysql);
                                    if (action.Select().Rows.Count > 0)
                                    {
                                        string SeedlingCode = Guid.NewGuid().ToString();
                                        #region 插入主表
                                        //插入主表
                                        action.ResetTable("Report_Seedling");
                                        action.Set("SeedlingCode", SeedlingCode);
                                        action.Set("DiseaseCode", DiseaseCode);
                                        action.Set("SeedlingClaim", StandardName);
                                        action.Set("SeedlingName", DiseaseCode);
                                        action.Set("StandardTypeName", StandardTypeName);
                                        action.Set("SchoolCode", schoolcode);
                                        action.Set("SchoolNumber", SchoolInfo.Get("SchoolNumber", ""));
                                        action.Set("SchoolName", SchoolInfo.Get("SchoolName", ""));
                                        action.Set("CityName", SchoolInfo.Get("CityName", ""));
                                        action.Set("CountyName", SchoolInfo.Get("CountyName", ""));
                                        action.Set("CommunityName", SchoolInfo.Get("CommunityName", ""));
                                        action.Set("StandardType", StandardType);
                                        action.Set("StandardDay", StandardDay);
                                        action.Set("StandardPeoples", StandardPeoples);
                                        action.Set("StandardOrder", StandardOrder);
                                        action.Set("ThresholdCondition", ThresholdCondition);
                                        action.Set("ThresholdCriteria", ThresholdCriteria);
                                        action.Set("Contacts", SchoolInfo.Get("Contacts", ""));
                                        action.Set("ContactsPhone", SchoolInfo.Get("ContactsPhone", ""));
                                        action.Set("DiseaseNumber", DiseaseNumber);
                                        action.Set("CreateDate", DateTime.Now);
                                        action.Set("ResultStatues", "0");
                                        action.Set("IsAccord", "是");
                                        action.Set("StandardCode", StandardCode);
                                        action.Set("sType", sType);
                                        action.Set("DiseaseCode2", DiseaseCode2);
                                        action.Set("DiseaseCode3", DiseaseCode3);
                                        action.Insert();
                                        #endregion

                                        string SeedDetailSql = @"select b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode,COUNT(1)alcount 
from report_absencedetail a inner join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @" and Casenature='新发' and SchoolCode='" + schoolcode + @"'and Grade='" + Grade + @"' and Class='" + Class + @"' --在这区间内最近的几天
group by b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode
having COUNT(1)=3";
                                        action.ResetTable(SeedDetailSql);
                                        MDataTable SeedDetailTab = action.Select() ?? new MDataTable();
                                        //插入从表
                                        #region 插入从表
                                        foreach (var Detail in SeedDetailTab.Rows)
                                        {
                                            action.ResetTable("report_seedlingcases");
                                            action.Set("SeedlingCasesCode", Guid.NewGuid().ToString());
                                            action.Set("SeedlingCode", SeedlingCode);
                                            action.Set("AbsenceCode", Detail.Get("AbsenceCode", ""));
                                            action.Set("SchoolCode", Detail.Get("SchoolCode", ""));
                                            action.Set("AbsenceDate", Detail.Get("AbsenceDate", ""));
                                            action.Set("Grade", Detail.Get("Grade", ""));
                                            action.Set("Class", Detail.Get("Class", ""));
                                            action.Set("OtherGrade", Detail.Get("OtherGrade", ""));
                                            action.Set("Gender", Detail.Get("Gender", ""));
                                            action.Set("StudentName", Detail.Get("StudentName", ""));
                                            action.Set("Age", Detail.Get("Age", ""));
                                            action.Set("Casenature", Detail.Get("Casenature", ""));
                                            action.Set("CaseStatus", Detail.Get("CaseStatus", ""));
                                            action.Set("Remark", Detail.Get("Remark", ""));
                                            action.Set("AbsenceNumber", Detail.Get("AbsenceNumber", ""));
                                            action.Set("Disease", Detail.Get("Disease", ""));
                                            action.Set("OrthrDisease", Detail.Get("OrthrDisease", ""));
                                            action.Set("Symptom", Detail.Get("Symptom", ""));
                                            action.Set("OrtherSymptom", Detail.Get("OrtherSymptom", ""));
                                            action.Set("Hurt", Detail.Get("Hurt", ""));
                                            action.Set("OrtherHurt", Detail.Get("OrtherHurt", ""));
                                            action.Set("Degree", Detail.Get("Degree", ""));
                                            action.Set("ReprotCode", Detail.Get("ReprotCode", ""));
                                            action.Set("CreateDate", Detail.Get("CreateDate", ""));
                                            action.Set("CreateUserCode", Detail.Get("CreateUserCode", ""));
                                            action.Set("ModifyDate", Detail.Get("ModifyDate", ""));
                                            action.Set("ModifyUserCode", Detail.Get("ModifyUserCode", ""));
                                            action.Insert();
                                        }
                                        #endregion

                                    }

                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region 关联两个疾病
                            //某个学校多少人发病
                            string sql = @"  select SchoolCode,Grade,Class,COUNT(1) as 'allcount' from (
select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @"-1 --在这区间内最近的几天
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=2
)x001 group by SchoolCode,Grade,Class
";
                            action.ResetTable(sql);
                            MDataTable schooldiseaseCount = action.Select(" allcount >=" + StandardPeoples) ?? new MDataTable();//人数标准达标学校code
                                                                                                                                //存在的话开始循环
                            foreach (var xzitem in schooldiseaseCount.Rows)
                            {
                                int DiseaseNumber = xzitem.Get("allcount", 0);
                                string schoolcode = xzitem.Get("SchoolCode", "");
                                string Grade = xzitem.Get("Grade", "");
                                string Class = xzitem.Get("Class", "");
                                //获取学校明细
                                action.ResetTable("Report_School");
                                MDataRow SchoolInfo = action.Select("SchoolCode='" + schoolcode + "'").Rows[0];
                                //查询是否存在
                                string sExistTab = "select * from dbo.Report_Seedling where  DATEDIFF(DAY,CreateDate,GETDATE())=0 and StandardCode= '" + StandardCode + "' and SchoolCode='" + schoolcode + "' and Grade='" + Grade + "' and Class='" + Class + "'";
                                action.ResetTable(sExistTab);
                                if (action.Select().Rows.Count <= 0)//不存的话进行插入
                                {
                                    //今天有没有新增
                                    string todaysql = @"select b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName,COUNT(1)alcount from report_absencedetail a 
left join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  Casenature='新发' and (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and AbsenceDate= CONVERT(varchar(10),GETDATE(),120)  and SchoolCode='" + schoolcode + @"' and Grade='" + Grade + @"' and Class='" + Class + @"'
group by b.AbsenceCode,b.SchoolCode,b.Grade,b.Class,b.StudentName
having COUNT(1)=2";
                                    action.ResetTable(todaysql);
                                    if (action.Select().Rows.Count > 0)
                                    {
                                        string SeedlingCode = Guid.NewGuid().ToString();
                                        #region 插入主表
                                        //插入主表
                                        action.ResetTable("Report_Seedling");
                                        action.Set("SeedlingCode", SeedlingCode);
                                        action.Set("DiseaseCode", DiseaseCode);
                                        action.Set("SeedlingClaim", StandardName);
                                        action.Set("SeedlingName", DiseaseCode);
                                        action.Set("StandardTypeName", StandardTypeName);
                                        action.Set("SchoolCode", schoolcode);
                                        action.Set("SchoolNumber", SchoolInfo.Get("SchoolNumber", ""));
                                        action.Set("SchoolName", SchoolInfo.Get("SchoolName", ""));
                                        action.Set("CityName", SchoolInfo.Get("CityName", ""));
                                        action.Set("CountyName", SchoolInfo.Get("CountyName", ""));
                                        action.Set("CommunityName", SchoolInfo.Get("CommunityName", ""));
                                        action.Set("StandardType", StandardType);
                                        action.Set("StandardDay", StandardDay);
                                        action.Set("StandardPeoples", StandardPeoples);
                                        action.Set("StandardOrder", StandardOrder);
                                        action.Set("ThresholdCondition", ThresholdCondition);
                                        action.Set("ThresholdCriteria", ThresholdCriteria);
                                        action.Set("Contacts", SchoolInfo.Get("Contacts", ""));
                                        action.Set("ContactsPhone", SchoolInfo.Get("ContactsPhone", ""));
                                        action.Set("DiseaseNumber", DiseaseNumber);
                                        action.Set("CreateDate", DateTime.Now);
                                        action.Set("ResultStatues", "0");
                                        action.Set("IsAccord", "是");
                                        action.Set("StandardCode", StandardCode);
                                        action.Set("sType", sType);
                                        action.Set("DiseaseCode2", DiseaseCode2);
                                        action.Set("DiseaseCode3", DiseaseCode3);
                                        action.Insert();
                                        #endregion

                                        string SeedDetailSql = @"select b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode,COUNT(1)alcount 
from report_absencedetail a inner join Report_Student_Absence b on a.AbsenceCode=b.AbsenceCode
where  (a.DiseaseCode='" + DiseaseCode + @"' or a.DiseaseCode='" + DiseaseCode2 + @"' or a.DiseaseCode='" + DiseaseCode3 + @"') 
and DATEDIFF(DAY,AbsenceDate,GETDATE())<=" + StandardDay + @" and Casenature='新发' and SchoolCode='" + schoolcode + @"'and Grade='" + Grade + @"' and Class='" + Class + @"' --在这区间内最近的几天
group by b.AbsenceCode,SchoolCode,AbsenceDate,Grade,Class,OtherGrade,Gender,StudentName,Age,Casenature,CaseStatus,Remark,AbsenceNumber,Disease,OtherDisease,Symptom,OtherSymptom,Hurt,OtherHurt,Degree,ReprotCode,CreateDate,CreateUserCode,ModifyDate,ModifyUserCode
having COUNT(1)=2";
                                        action.ResetTable(SeedDetailSql);
                                        MDataTable SeedDetailTab = action.Select() ?? new MDataTable();
                                        //插入从表
                                        #region 插入从表
                                        foreach (var Detail in SeedDetailTab.Rows)
                                        {
                                            action.ResetTable("report_seedlingcases");
                                            action.Set("SeedlingCasesCode", Guid.NewGuid().ToString());
                                            action.Set("SeedlingCode", SeedlingCode);
                                            action.Set("AbsenceCode", Detail.Get("AbsenceCode", ""));
                                            action.Set("SchoolCode", Detail.Get("SchoolCode", ""));
                                            action.Set("AbsenceDate", Detail.Get("AbsenceDate", ""));
                                            action.Set("Grade", Detail.Get("Grade", ""));
                                            action.Set("Class", Detail.Get("Class", ""));
                                            action.Set("OtherGrade", Detail.Get("OtherGrade", ""));
                                            action.Set("Gender", Detail.Get("Gender", ""));
                                            action.Set("StudentName", Detail.Get("StudentName", ""));
                                            action.Set("Age", Detail.Get("Age", ""));
                                            action.Set("Casenature", Detail.Get("Casenature", ""));
                                            action.Set("CaseStatus", Detail.Get("CaseStatus", ""));
                                            action.Set("Remark", Detail.Get("Remark", ""));
                                            action.Set("AbsenceNumber", Detail.Get("AbsenceNumber", ""));
                                            action.Set("Disease", Detail.Get("Disease", ""));
                                            action.Set("OrthrDisease", Detail.Get("OrthrDisease", ""));
                                            action.Set("Symptom", Detail.Get("Symptom", ""));
                                            action.Set("OrtherSymptom", Detail.Get("OrtherSymptom", ""));
                                            action.Set("Hurt", Detail.Get("Hurt", ""));
                                            action.Set("OrtherHurt", Detail.Get("OrtherHurt", ""));
                                            action.Set("Degree", Detail.Get("Degree", ""));
                                            action.Set("ReprotCode", Detail.Get("ReprotCode", ""));
                                            action.Set("CreateDate", Detail.Get("CreateDate", ""));
                                            action.Set("CreateUserCode", Detail.Get("CreateUserCode", ""));
                                            action.Set("ModifyDate", Detail.Get("ModifyDate", ""));
                                            action.Set("ModifyUserCode", Detail.Get("ModifyUserCode", ""));
                                            action.Insert();
                                        }
                                        #endregion

                                    }

                                }
                            }
                            #endregion
                        }
                    }
                }

            }
        }



        /// <summary>
        /// 创建人:gxg
        /// 创建时间:2020-09-10
        /// 日报
        /// </summary>      
        /// <param name="typeindex">
        /// 0-9:30/12:30 短信模板
        /// 1-上报情况统计表
        /// 2-修正上报情况统计表
        /// 3-午检打卡报表
        /// 4-修正午检打卡报表
        /// 5-16:00后 短信模板
        /// 6-16:00后苗子汇总
        /// 7-16:00后 短信模板(周末)
        /// </param>
        /// <returns></returns>
        public MDataTable GetDayListNew(string conn, int typeindex = 0)
        {

            String sWhere = " 1=1 ";


            string sql = string.Empty;
            #region 语句

            if (typeindex == 0)
            {
                #region 9:30 短信模板
                sql = @"select 
message=RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，'+
(CASE WHEN SUM(新增发热学生)<=0 THEN'各校直报今日无新增发热等症状学生' ELSE '各校直报今日新增发热等症状学生'+CONVERT(varchar(100),SUM(新增发热学生))+'人' END)+
(CASE WHEN SUM(新增发热学生)<=0 and SUM(在校发热学生)<=0 THEN'' WHEN SUM(新增发热学生)>0 and SUM(在校发热学生)<=0 THEN'，在校期间未筛查出发热学生'  ELSE '，在校期间筛查出发热学生'+CONVERT(varchar(100),SUM(在校发热学生))+'人' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'，' ELSE '' END)+
(CASE WHEN SUM(中小学在校发热学生)>0 THEN '中小学'+CONVERT(varchar(100),SUM(中小学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '，中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '，国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'）' ELSE '' END)+
+'，'
 from (
select count(1)'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
UNION ALL
select 
message=
(CASE WHEN SUM(新增发热教职工)<=0 THEN+'无新增发热等症状教职员工' ELSE '新增发热等症状教职员工'+CONVERT(varchar(100),SUM(新增发热教职工))+'人' END)+
(CASE WHEN SUM(新增发热教职工)<=0 and SUM(在校发热教职工)<=0 THEN+'' WHEN SUM(新增发热教职工)>0 and SUM(在校发热教职工)<=0 THEN '，在校期间未筛查出发热教职员工'  ELSE '，在校期间筛查出发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'，' ELSE '' END)+
(CASE WHEN SUM(中小学在校发热教职工)>0 THEN+'中小学'+CONVERT(varchar(100),SUM(中小学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热教职工)>0 THEN+'，中职校'+CONVERT(varchar(100),SUM(中职校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热教职工)>0 THEN+'，国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'）' ELSE '' END)+
'。'
 from (
select count(1)'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message='未发现核酸检测阳性病例。'
";
                #endregion
            }
            else if (typeindex == 1 || typeindex == 2 || typeindex == 9)
            {
                #region 上报情况统计表
                sql = @"select *,[上报率(%)]as'sbl' from (
select x001.CountyName'区',sum(ybzxx)'已报中小学',sum(ybty)'已报幼儿园',sum(wbzxx)'未报中小学',sum(wbty)'未报幼儿园',ROUND((CAST((sum(ybzxx)+sum(ybty)) AS FLOAT)/(sum(wbzxx)+sum(wbty)+sum(ybzxx)+sum(ybty)) * 100),2)as'上报率(%)',z.num from (
  select CountyName,yb as ybty,wb as wbty,0ybzxx,0wbzxx from (
  select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)  group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报' and isnull(isInternational,'0')='0'  and schooltypename in('幼儿园','托育点')
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报' and isnull(isInternational,'0')='0' and schooltypename in('幼儿园','托育点')
group by CountyName 
)s001 group by CountyName  
)m001

union all
select CountyName,0 as ybty,0 as wbty,yb as ybzxx,wb as wbzxx from(
   select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'   and isnull(isInternational,'0') ='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报'  and isnull(isInternational,'0')='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
group by CountyName 
)s001 group by CountyName  )m002
)x001 inner join report_county z on x001.CountyName=z.countyname group by x001.CountyName,z.num 

union all

 select '中职校'as CountyName, SUM(yb)ybty,0ybzxx,SUM(wb)wbty,0wbzxx,ROUND((CAST(sum(yb) AS FLOAT)/(sum(yb)+sum(wb)) * 100),2)as'上报率(%)',17 as num from (
  select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'   and isnull(isInternational,'0')='0' and schooltypename in('中等职业学校','职业高中学校')
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报'  and isnull(isInternational,'0')='0' and schooltypename in('中等职业学校','职业高中学校')
group by CountyName 
)s001 group by CountyName  
) x002
union all 
 select '国际子女学校'as CountyName, SUM(yb)ybty,0ybzxx,SUM(wb)wbty,0wbzxx, ROUND((CAST(sum(yb) AS FLOAT)/(sum(yb)+sum(wb)) * 100),2)as'上报率(%)',18 as num  from (
  select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'   and isnull(isInternational,0) ='1'
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报'  and isnull(isInternational,0) ='1'
group by CountyName 
)s001 group by CountyName  
) x003 

union all 

 select '总计'as '区',SUM(yb)as'已报中小学',0as'已报幼儿园',SUM(wb)as'未报中小学',0as'未报幼儿园',Cast(CONVERT(decimal(18,2),SUM(yb)) /CONVERT(decimal(18,2),(SUM(yb)+SUM(wb)))*100 AS NUMERIC(18,2))'上报率(%)',19 as num from (
   select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 09:30:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23)   
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)    group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)  and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)  group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'  
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 09:30:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23)   
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)    group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)  and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)  group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报' 
group by CountyName 
)s001 group by CountyName  
)x021
) m012 ";

                #endregion
                sWhere = " order by  num asc";
            }
            else if (typeindex == 3 || typeindex == 4 || typeindex == 8)
            {
                #region 午检打卡报表
                sql = @" select *,[打卡率(%)]as'dkl' from (
select x001.CountyName'区',sum(ydkzxx)'已打卡中小学',sum(ydkty)'已打卡幼儿园',sum(wdkzxx)'未打卡中小学',sum(wdkty)'未打卡幼儿园',ROUND(CAST((sum(ydkzxx)+sum(ydkty)) AS FLOAT)/(sum(ydkzxx)+sum(ydkty)+sum(wdkzxx)+sum(wdkty)) * 100,2)'打卡率(%)',z.num from (
select CountyName ,sum(未午检打卡)wdkty,sum(已午检打卡)ydkty,0wdkzxx,0ydkzxx from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'   and isnull(isInternational,'0') ='0' and schooltypename in('幼儿园','托育点')
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'   and isnull(isInternational,'0') ='0' and schooltypename in('幼儿园','托育点')
 group by CountyName
)v group by CountyName 
union all

select CountyName ,0wdkty,0ydkty,sum(未午检打卡)wdkzxx,sum(已午检打卡)ydkzxx from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'  and isnull(isInternational,'0') ='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'  and isnull(isInternational,'0') ='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
 group by CountyName
)v  group by CountyName 
)x001 inner join report_county z on x001.CountyName=z.countyname group by x001.CountyName,z.num

union all 

select '中职校'CountyName,sum(ydk)ydkty,0ydkzxx,sum(wdk)wdkty,0wdkzxx,ROUND(CAST((sum(ydk)) AS FLOAT)/(sum(ydk)+sum(wdk)) * 100,2)'打卡率(%)',17 as num from (
select CountyName ,sum(未午检打卡)wdk,sum(已午检打卡)ydk from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'  and isnull(isInternational,'') ='0' and schooltypename in('中等职业学校','职业高中学校')
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'  and isnull(isInternational,'') ='0' and schooltypename in('中等职业学校','职业高中学校')
 group by CountyName
)v group by CountyName 
)x002
union all

  
select '国际子女学校'CountyName,sum(ydk)ydkty,0ydkzxx,sum(wdk)wdkty,0wdkzxx,ROUND(CAST((sum(ydk)) AS FLOAT)/(sum(ydk)+sum(wdk)) * 100,2)'打卡率(%)',18 as num from (
select CountyName ,sum(未午检打卡)wdk,sum(已午检打卡)ydk from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'  and isnull(isInternational,'') ='1' 
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'  and isnull(isInternational,'') ='1' 
 group by CountyName
)v group by CountyName 
)x003 

union all

select '总计'as'区',sum(ydk)'已打卡中小学',0'已打卡幼儿园',sum(wdk)'未打卡中小学',0'未打卡幼儿园',ROUND(CAST((sum(ydk)) AS FLOAT)/(sum(ydk)+sum(wdk)) * 100,2)'打卡率(%)',19 as'num' from (
select CountyName ,sum(未午检打卡)wdk,sum(已午检打卡)ydk from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡' 
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡' 
 group by CountyName
)v group by CountyName 
)x021)s87";
                #endregion
                sWhere = " order by  num asc";
            }
            else if (typeindex == 5)
            {
                int reporttype = 0;
                #region 非教学日是否催报
                using (MAction action = new MAction("report_configure", con))
                {
                    MDataTable jxr = action.Select() ?? new MDataTable();
                    if (jxr.Rows.Count > 0)
                    {
                        reporttype = jxr.Rows[0].Get("ispressreport", 0);
                    }
                }
                #endregion
                if (reporttype == 1 || reporttype == 2)
                {
                    #region 16：00短信
                    sql = @"select message='【返校发热情况】'+
RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，全市中小学校、幼儿园实报'+CONVERT(varchar(100),(select count(1) from report_school))  +'所，各校因病直报数据汇总：'+
CASE WHEN (select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23))<=0 THEN '未筛查出因病缺课学生。' else '因病缺课学生'+CONVERT(varchar(100),(select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23) and a.isIntoSchool in('入校后','校门口')))+'人。'end
union all 
select 
message=
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))>0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '新发发热学生'+CONVERT(varchar(100),SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))+'人' WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '未筛查出新发发热学生' ELSE '' END +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '（' end +
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '）' end +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))>0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '，均为在校期间筛查出' WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '' ELSE '' END
+'；'
 from (
select count(1)'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',count(1)'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and a.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',count(1)'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')  and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',count(1)'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',count(1)'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('一年级','二年级','三年级','四年级','五年级')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',count(1)'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select 
message=
CASE WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)>0 THEN '新发发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)<=0 THEN '无新增发热等症状教职员工'  ELSE '' END +
CASE WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)>0 THEN '，均为在校期间筛查出' ELSE '' END+
'。'
 from (
select count(1)'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',count(1)'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName ='小学' and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',count(1)'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',count(1)'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',count(1)'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all


select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName='小学'
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',count(1)'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message=
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN (
'今日新增'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起'+
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '（' end +
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN '幼儿园'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '小学'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '初中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '高中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '中职校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '国际子女学校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)
+CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '）' end +
+'在校期间聚集性发热病例，') ELSE '今日未发现在校期间聚集性发热病例，' END
union all
 select message='未发现核酸检测阳性病例。'";
                    #endregion
                }
                else
                {
                    #region 16:00后 短信模板
                    sql = @"select message='【返校发热情况】'+
RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，全市中小学校、幼儿园实报'+CONVERT(varchar(100),(select count(1) from report_school))  +'所，各校因病直报数据汇总：'+
CASE WHEN (select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23))<=0 THEN '未筛查出因病缺课学生。' else '因病缺课学生'+CONVERT(varchar(100),(select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23)))+'人。'end
union all 
select 
message=
(CASE WHEN (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN
'新发发热学生'+CONVERT(varchar(100),SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))+'人' ELSE '未筛查出新发发热学生' end) +
CASE WHEN (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))<=0
THEN '' else '（' end +
(CASE WHEN SUM(全部幼儿园在校发热学生)>0 THEN '幼儿园'+CONVERT(varchar(100),SUM(全部幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(全部幼儿园在校发热学生)>0 THEN '、' ELSE '' END)+
(CASE WHEN SUM(全部小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(全部小学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(全部中学在校发热学生)>0 THEN '中学'+CONVERT(varchar(100),SUM(全部中学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(全部中职校在校发热学生)>0 THEN '中职校'+CONVERT(varchar(100),SUM(全部中职校在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(全部国际子女学校在校发热学生)>0 THEN '国际子女学校'+CONVERT(varchar(100),SUM(全部国际子女学校在校发热学生))+'人' ELSE '' END)+
CASE WHEN (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))<=0
THEN '' else '）' end +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))>0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '，在校期间筛查出发热学生'+CONVERT(varchar(100),SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))+'人' WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '，在校期间未筛查出发热学生' ELSE '' END +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '（' end +
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '）' end +'；'
 from (
select count(1)'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',count(1)'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and a.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',count(1)'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')  and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',count(1)'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',count(1)'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('一年级','二年级','三年级','四年级','五年级')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',count(1)'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select 
message=
CASE WHEN SUM(新增发热教职工)>0 THEN '新发发热教职员工'+CONVERT(varchar(100),SUM(新增发热教职工))+'人' ELSE '未筛查出新发发热教职员工' END +
CASE WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)>0 THEN '，在校期间筛查出发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)<=0 THEN '，在校期间未筛查出发热教职员工'  ELSE '' END +'。'
 from (
select count(1)'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',count(1)'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName ='小学' and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',count(1)'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',count(1)'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',count(1)'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all


select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName='小学'
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',count(1)'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message=
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN (
'今日新增'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起'+
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '（' end +
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN '幼儿园'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '小学'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '初中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '高中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '中职校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '国际子女学校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)
+CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '）' end +
+'在校期间聚集性发热病例，') ELSE '今日未发现在校期间聚集性发热病例，' END
union all
 select message='未发现核酸检测阳性病例。' ";
                    #endregion
                }

            }
            else if (typeindex == 6)
            {
                #region 16:00后苗子汇总
                sql = @"select ROW_NUMBER() over( order by CreateDate asc) number,* from (
select * from (
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,sum(alcount)alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,(case when sum(tk)>0 then '已停课' else '' end)tk from (
--总数
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--类型--------------------------------------------------------------------类型--------------------------------------------------------------------类型------------------------------------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwd,0 as alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='未到校'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,count(AbsenceCode) alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='校门口'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,0 as alcountxm,count(AbsenceCode) alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='入校后'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)x002 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
---未检测，检测中，阴性，阳性--------------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk--------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcount,0alcountwd,0alcountxm,0alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwjc,0 alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=0  and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all 
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,count(AbsenceCode) alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,count(AbsenceCode) as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阴性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,0 as alcountyix,count(AbsenceCode) as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阳性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
) x003 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--停课----------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk-
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,1as tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
left join report_suspension f on a.SchoolCode=f.SchoolCode where f.SuspnDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59' and f.IsClasses='停课' and (SuspensionType='全校' or (SuspensionType='年级' and SuspensionGrade=b.Grade) or (SuspensionType='班级' and SuspensionGrade=b.Grade and SuspensionClass=b.Class))--b.Grade,b.Class
)s004 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s009 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s912 where  SeedlingClaim = '校级苗子-发热聚集(一天一班3例)' and (alcountrx + alcountxm )>=3 and
SchoolCode NOT IN
(SELECT   SchoolCode
FROM      report_vseedlingdetail
WHERE   CONVERT(varchar(100), CreateDate, 23) = CONVERT(varchar(100), getdate(), 23) AND 
SeedlingClaim = '校级苗子-发热聚集(三天一班6例)')
union all
select * from (
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,sum(alcount)alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,(case when sum(tk)>0 then '已停课' else '' end)tk from (
--总数
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--类型--------------------------------------------------------------------类型--------------------------------------------------------------------类型------------------------------------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwd,0 as alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='未到校'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,count(AbsenceCode) alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='校门口'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,0 as alcountxm,count(AbsenceCode) alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='入校后'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)x002 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
---未检测，检测中，阴性，阳性--------------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk--------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcount,0alcountwd,0alcountxm,0alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwjc,0 alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=0  and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all 
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,count(AbsenceCode) alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,count(AbsenceCode) as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阴性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,0 as alcountyix,count(AbsenceCode) as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阳性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
) x003 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--停课----------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk-
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,1as tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
left join report_suspension f on a.SchoolCode=f.SchoolCode where f.SuspnDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59' and f.IsClasses='停课' and (SuspensionType='全校' or (SuspensionType='年级' and SuspensionGrade=b.Grade) or (SuspensionType='班级' and SuspensionGrade=b.Grade and SuspensionClass=b.Class))--b.Grade,b.Class
)s004 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s009 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s912 where  SeedlingClaim = '校级苗子-发热聚集(三天一班6例)' and (alcountrx + alcountxm )>=6
)x091";//视图
                #endregion
            }
            else if (typeindex == 7)
            {
                int reporttype = 0;
                #region 非教学日是否催报
                using (MAction action = new MAction("report_configure", con))
                {
                    MDataTable jxr = action.Select() ?? new MDataTable();
                    if (jxr.Rows.Count > 0)
                    {
                        reporttype = jxr.Rows[0].Get("ispressreport", 0);
                    }
                }
                //int newstucount = Convert.ToInt32("studentData");//新增发热等症状(高校学生)" + newstuincount + @"
                //int newstuincount = Convert.ToInt32("inSchoolStudentData");//在校新增发热等症状(高校学生)
                //int newteacount = Convert.ToInt32("teacherData");//新增发热等症状(高校教职工)
                //int newteaincount = Convert.ToInt32("inSchoolTeacherData");//在校新增发热等症状(高校教职工)
                //int aggregationcount = Convert.ToInt32("multipleData");//在高校聚集性病例数

                int newstucount = Convert.ToInt32("66");//新增发热等症状(高校学生)" + newstuincount + @"
                int newstuincount = Convert.ToInt32("0");//在校新增发热等症状(高校学生)
                int newteacount = Convert.ToInt32("0");//新增发热等症状(高校教职工)
                int newteaincount = Convert.ToInt32("3");//在校新增发热等症状(高校教职工)
                int aggregationcount = Convert.ToInt32("0");//在高校聚集性病例数

                string stunumstr = string.Empty;//高校在校学生
                if (newstuincount > 0)
                {
                    stunumstr += "、高校" + newstuincount + "人、";
                }
                string stunuminstr = string.Empty;//高校在校教职工
                if (newteaincount > 0)
                {
                    stunuminstr += "、高校" + newteaincount + "人、";
                }

                #endregion
                if (reporttype == 1 || reporttype == 2 || reporttype == 3)
                {

                    #region  每日合并短信
                    sql = @"select 
message=RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，'+";
                    if (newstuincount == newstucount)
                    {
                        sql += @"(CASE WHEN SUM(在校发热学生)+" + newstucount + @"<=0 THEN'各校直报今日无新增发热等症状学生' ELSE '各校直报今日新增发热等症状学生'+CONVERT(varchar(100),SUM(在校发热学生)+" + newstucount + @")+'人' END)+
(CASE WHEN SUM(在校发热学生)+" + newstuincount + @">0 THEN'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '、中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '、中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
'" + stunumstr + @"'+
(CASE WHEN SUM(在校发热学生)+" + newstuincount + @">0 THEN'）' ELSE '' END)+
(CASE WHEN SUM(新增发热学生)+" + newstuincount + @"<=0 and SUM(在校发热学生)+" + newstuincount + @"<=0 THEN'' WHEN SUM(新增发热学生)+" + newstuincount + @">0 and SUM(在校发热学生)+" + newstuincount + @"<=0 THEN'，在校期间未筛查出发热学生'  ELSE '，均为在校期间筛查出' END)+";
                    }
                    else
                    {
                        sql += @"(CASE WHEN SUM(在校发热学生)+" + newstucount + @"<=0 THEN'各校直报今日无新增发热等症状学生' ELSE '各校直报今日新增发热等症状学生'+CONVERT(varchar(100),SUM(在校发热学生)+" + newstucount + @")+'人' END)+
(CASE WHEN SUM(在校发热学生)+" + newstucount + @">0 THEN'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '、中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '、中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
'、高校" + newstucount + @"人'+
(CASE WHEN SUM(在校发热学生)+" + newstucount + @">0 THEN'）' ELSE '' END)+
                        (CASE WHEN SUM(在校发热学生)+" + newstucount + @"<=0 and SUM(在校发热学生)+" + newstuincount + @"<=0 THEN'' WHEN SUM(在校发热学生)+" + newstucount + @">0 and SUM(在校发热学生)+" + newstuincount + @"<=0 THEN'，在校期间未筛查出发热学生'  ELSE '，在校期间筛查出发热学生'+CONVERT(varchar(100),SUM(在校发热学生)+" + newstuincount + @")+'人' END)+
(CASE WHEN SUM(在校发热学生)+" + newstuincount + @">0 THEN'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '、中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '、中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
'" + stunumstr + @"'+
(CASE WHEN SUM(在校发热学生)+" + newstuincount + @">0 THEN'）' ELSE '' END)+";
                    }
                    sql += @"
'；'
 from (
select count(1)'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName in('小学')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',count(1)'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校','小学')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
UNION ALL
select 
message=";
                    if (newteacount == newteaincount)
                    {
                        sql += @"(CASE WHEN SUM(在校发热教职工)+" + newteacount + @"<=0 THEN+'无新增发热等症状教职员工' ELSE '新增发热等症状教职员工'+CONVERT(varchar(100),SUM(在校发热教职工)+" + newteacount + @")+'人' END)+
(CASE WHEN SUM(在校发热教职工)+" + newteaincount + @">0 THEN+'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热教职工)>0 THEN+'小学'+CONVERT(varchar(100),SUM(小学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热教职工)>0 THEN+'、中学'+CONVERT(varchar(100),SUM(中学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热教职工)>0 THEN+'、中职校'+CONVERT(varchar(100),SUM(中职校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热教职工)>0 THEN+'、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热教职工))+'人' ELSE '' END)+
'" + stunuminstr + @"'+
(CASE WHEN SUM(在校发热教职工)+" + newteaincount + @">0 THEN+'）' ELSE '' END)+
(CASE WHEN SUM(在校发热教职工)+" + newteaincount + @"<=0 and SUM(在校发热教职工)+" + newteaincount + @"<=0 THEN+''  ELSE '，均为在校期间筛查出' END)+";
                    }
                    else
                    {
                        sql += @"(CASE WHEN SUM(在校发热教职工)+" + newteacount + @"<=0 THEN+'无新增发热等症状教职员工' ELSE '新增发热等症状教职员工'+CONVERT(varchar(100),SUM(在校发热教职工)+" + newteacount + @")+'人' END)+
(CASE WHEN SUM(在校发热教职工)+" + newteacount + @">0 THEN+'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热教职工)>0 THEN+'小学'+CONVERT(varchar(100),SUM(小学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热教职工)>0 THEN+'、中学'+CONVERT(varchar(100),SUM(中学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热教职工)>0 THEN+'、中职校'+CONVERT(varchar(100),SUM(中职校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热教职工)>0 THEN+'、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热教职工))+'人' ELSE '' END)+
'、高校" + newteacount + @"人'+
(CASE WHEN SUM(在校发热教职工)+" + newteacount + @">0 THEN+'）' ELSE '' END)+
(CASE WHEN SUM(在校发热教职工)+" + newteacount + @"<=0 and SUM(在校发热教职工)+" + newteaincount + @"<=0 THEN+'' WHEN SUM(在校发热教职工)+" + newteacount + @">0 and SUM(在校发热教职工)+" + newteaincount + @"<=0 THEN '，在校期间未筛查出发热教职员工'  ELSE '，在校期间筛查出发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工)+" + newteaincount + @")+'人' END)+
(CASE WHEN SUM(在校发热教职工)+" + newteaincount + @">0 THEN+'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热教职工)>0 THEN+'小学'+CONVERT(varchar(100),SUM(小学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热教职工)>0 THEN+'、中学'+CONVERT(varchar(100),SUM(中学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热教职工)>0 THEN+'、中职校'+CONVERT(varchar(100),SUM(中职校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热教职工)>0 THEN+'、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热教职工))+'人' ELSE '' END)+
'" + stunuminstr + @"'+
(CASE WHEN SUM(在校发热教职工)+" + newteaincount + @">0 THEN+'）' ELSE '' END)+";
                    }
                    sql += @"
'。'
 from (
select count(1)'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName in('小学')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',count(1)'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校','小学')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message=
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )+" + aggregationcount + @">0 THEN (
'今日新增'+CONVERT(varchar(100),(select COUNT(1)+" + aggregationcount + @" from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起'+
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)+" + aggregationcount + @"<=0
THEN '' else '（' end +
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN '幼儿园'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '小学'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '初中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '高中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '中职校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+
------------------------------------------------------------
(CASE WHEN " + aggregationcount + @">0 then '、' else '' end)+ 
(CASE WHEN " + aggregationcount + @">0 then '高校'+CONVERT(VARCHAR(100)," + aggregationcount + @")+'起' else '' end)+ 
--------------------------------------------------------------
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '国际子女学校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)
+CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:30:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)+" + aggregationcount + @"<=0
THEN '' else '）' end +
+'在校期间聚集性发热病例，') ELSE '今日未发现在校期间聚集性发热病例，' END
union all
select message='未发现核酸检测阳性病例。' ";
                    #endregion
                }
            }
            else if (typeindex == 10)
            {
                #region 发热闭环情况统计表
                sql = @"select ROW_NUMBER() over(order by x002.num)numbers ,x002.CountyName as'辖区',isnull(sum(隔离已满14天未闭环学校数),0)as'满14天未闭环学校数',isnull(sum(隔离已满14天未闭环病例数),0)as'满14天未闭环病例数' from (
select c.CountyName,c.SchoolName,1as'隔离已满14天未闭环学校数',count(1)as'隔离已满14天未闭环病例数' from Report_Student_Absence_Management a 
 inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
 inner join report_school c on a.SchoolCode=c.SchoolCode 
 where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=14
 group by c.CountyName,c.SchoolName 
)x001 right join report_county x002 on x001.CountyName=x002.countyname group by x002.CountyName,x002.num
union all
select '17'as numbers,'合计' as'辖区',isnull(sum(隔离已满14天未闭环学校数),0)as'满14天未闭环学校数',isnull(sum(隔离已满14天未闭环病例数),0)as'满14天未闭环病例数' from (
select c.CountyName,c.SchoolName,1as'隔离已满14天未闭环学校数',count(1)as'隔离已满14天未闭环病例数' from Report_Student_Absence_Management a 
 inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
 inner join report_school c on a.SchoolCode=c.SchoolCode 
 where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=14
 group by c.CountyName,c.SchoolName 
)x001  ";

                #endregion
                sWhere = " ";
            }
            else if (typeindex == 11)
            {
                #region 发热闭环学校明细
                sql = @"select d.num,c.CountyName '辖区',c.SchoolName as '学校名称',c.SchoolTypeName as'学校类型',c.Contacts as'填报人',c.ContactsPhone as'填报人号码',count(1)as'隔离已满14天未闭环病例数' from Report_Student_Absence_Management a 
inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
inner join report_school c on a.SchoolCode=c.SchoolCode 
inner join report_county d on c.CountyName=d.countyname
where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=14
group by c.CountyName,c.SchoolName,c.SchoolTypeName,c.Contacts,c.ContactsPhone,d.num  ";
                #endregion
                sWhere = " order by num asc ";
            }
            #endregion


            MDataTable reTba = new MDataTable();
            using (MAction action = new MAction(sql, conn))
            {
                cache.Clear();//清除所有缓存项
                reTba = action.Select(sWhere);
            }

            if (typeindex == 0 || typeindex == 5 || typeindex == 7)
            {
                foreach (var item in reTba.Rows)
                {
                    string message = item.Get("message", "");
                    message = message.Replace("，）", "）");
                    message = message.Replace("（，", "（");
                    message = message.Replace("、）", "）");
                    message = message.Replace("（、", "（");
                    message = message.Replace("。。", "。");
                    message = message.Replace("，，", "，");
                    message = message.Replace("、、", "、");
                    item.Set("message", message);
                }
            }
            if (typeindex == 2)
            {
                #region 修正上报情况统计表

                int x = reTba.Rows.Count;
                int xt = 0;//第几行
                int zxx = 0;//中小学
                int yey = 0;//幼儿园
                foreach (var item in reTba.Rows)
                {
                    xt++;

                    if (x != xt)
                    {
                        bool jsl = false;
                        if (item.Get("未报中小学", 0) == 1)
                        {
                            item.Set("已报中小学", item.Get("已报中小学", 0) + 1);
                            item.Set("未报中小学", 0);
                            jsl = true;
                            zxx++;
                        }
                        if (item.Get("未报幼儿园", 0) == 1)
                        {
                            item.Set("已报幼儿园", item.Get("已报幼儿园", 0) + 1);
                            item.Set("未报幼儿园", 0);
                            jsl = true;
                            yey++;
                        }

                        if (jsl)
                        {
                            item.Set("上报率(%)", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                            item.Set("sbl", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                        }
                    }
                    else
                    {
                        bool hzl = false;
                        if (zxx > 0)
                        {
                            item.Set("已报中小学", item.Get("已报中小学", 0) + zxx);
                            item.Set("未报中小学", item.Get("未报中小学", 0) - zxx);
                            hzl = true;
                        }
                        if (yey > 0)
                        {
                            item.Set("已报幼儿园", item.Get("已报幼儿园", 0) + yey);
                            item.Set("未报幼儿园", item.Get("未报幼儿园", 0) - yey);
                            hzl = true;
                        }

                        if (hzl)
                        {
                            item.Set("上报率(%)", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                            item.Set("sbl", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                        }
                    }
                }


                #endregion
            }
            else if (typeindex == 4)
            {
                #region 修正午检打卡报表

                int x = reTba.Rows.Count;
                int xt = 0;//第几行
                int zxx = 0;//中小学
                int yey = 0;//幼儿园
                foreach (var item in reTba.Rows)
                {
                    xt++;

                    if (x != xt)
                    {
                        bool jsl = false;
                        if (item.Get("未打卡中小学", 0) == 1)
                        {
                            item.Set("已打卡中小学", item.Get("已打卡中小学", 0) + 1);
                            item.Set("未打卡中小学", 0);
                            jsl = true;
                            zxx++;
                        }
                        if (item.Get("未打卡幼儿园", 0) == 1)
                        {
                            item.Set("已打卡幼儿园", item.Get("已打卡幼儿园", 0) + 1);
                            item.Set("未打卡幼儿园", 0);
                            jsl = true;
                            yey++;
                        }

                        if (jsl)
                        {
                            item.Set("打卡率(%)", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                            item.Set("dkl", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                        }
                    }
                    else
                    {
                        bool hzl = false;
                        if (zxx > 0)
                        {
                            item.Set("已打卡中小学", item.Get("已打卡中小学", 0) + zxx);
                            item.Set("未打卡中小学", item.Get("未打卡中小学", 0) - zxx);
                            hzl = true;
                        }
                        if (yey > 0)
                        {
                            item.Set("已打卡幼儿园", item.Get("已打卡幼儿园", 0) + yey);
                            item.Set("未打卡幼儿园", item.Get("未打卡幼儿园", 0) - yey);
                            hzl = true;
                        }

                        if (hzl)
                        {
                            item.Set("打卡率(%)", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                            item.Set("dkl", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                        }
                    }
                }


                #endregion
            }
            if (typeindex == 1 || typeindex == 2 || typeindex == 3 || typeindex == 4)
            {
                foreach (var item in reTba.Rows)
                {
                    string sbl = item.Get("sbl", 0.00m).ToString();
                    string ts = item.Get("上报率(%)", 0.00m).ToString();
                    item.Set("sbl", sbl);
                    item.Set("上报率(%)", ts);
                }
            }
            return reTba;
        }
        /// <summary>
        /// 创建人:zuowh
        /// 创建时间:2020-09-10
        /// 日报
        /// </summary>      
        /// <param name="typeindex">
        /// 0-9:30/12:30 短信模板
        /// 1-上报情况统计表
        /// 2-修正上报情况统计表
        /// 3-午检打卡报表
        /// 4-修正午检打卡报表
        /// 5-16:00后 短信模板
        /// 6-16:00后苗子汇总
        /// 7-16:00后 短信模板(周末)
        /// </param>
        /// <returns></returns>
        public MDataTable GetDayList(string conn, int typeindex = 0)
        {
            String sWhere = " 1=1 ";


            string sql = string.Empty;
            #region 语句

            if (typeindex == 0)
            {
                #region 9:30 短信模板
                sql = @"select 
message=RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，'+
(CASE WHEN SUM(新增发热学生)<=0 THEN'各校直报今日无新增发热等症状学生' ELSE '各校直报今日新增发热等症状学生'+CONVERT(varchar(100),SUM(新增发热学生))+'人' END)+
(CASE WHEN SUM(新增发热学生)<=0 and SUM(在校发热学生)<=0 THEN'' WHEN SUM(新增发热学生)>0 and SUM(在校发热学生)<=0 THEN'，在校期间未筛查出发热学生'  ELSE '，在校期间筛查出发热学生'+CONVERT(varchar(100),SUM(在校发热学生))+'人' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'，' ELSE '' END)+
(CASE WHEN SUM(中小学在校发热学生)>0 THEN '中小学'+CONVERT(varchar(100),SUM(中小学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '，中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '，国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'）' ELSE '' END)+
+'，'
 from (
select count(1)'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'中小学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'中小学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
UNION ALL
select 
message=
(CASE WHEN SUM(新增发热教职工)<=0 THEN+'无新增发热等症状教职员工' ELSE '新增发热等症状教职员工'+CONVERT(varchar(100),SUM(新增发热教职工))+'人' END)+
(CASE WHEN SUM(新增发热教职工)<=0 and SUM(在校发热教职工)<=0 THEN+'' WHEN SUM(新增发热教职工)>0 and SUM(在校发热教职工)<=0 THEN '，在校期间未筛查出发热教职员工'  ELSE '，在校期间筛查出发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'，' ELSE '' END)+
(CASE WHEN SUM(中小学在校发热教职工)>0 THEN+'中小学'+CONVERT(varchar(100),SUM(中小学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热教职工)>0 THEN+'，中职校'+CONVERT(varchar(100),SUM(中职校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热教职工)>0 THEN+'，国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'）' ELSE '' END)+
'。'
 from (
select count(1)'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'中小学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'中小学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message='未发现核酸检测阳性病例。'
";
                #endregion
            }
            else if (typeindex == 1 || typeindex == 2 || typeindex == 9)
            {
                #region 上报情况统计表
                sql = @"select *,[上报率(%)]as'sbl' from (
select x001.CountyName'区',sum(ybzxx)'已报中小学',sum(ybty)'已报幼儿园',sum(wbzxx)'未报中小学',sum(wbty)'未报幼儿园',ROUND((CAST((sum(ybzxx)+sum(ybty)) AS FLOAT)/(sum(wbzxx)+sum(wbty)+sum(ybzxx)+sum(ybty)) * 100),2)as'上报率(%)',z.num from (
  select CountyName,yb as ybty,wb as wbty,0ybzxx,0wbzxx from (
  select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)  group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报' and isnull(isInternational,'0')='0'  and schooltypename in('幼儿园','托育点')
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报' and isnull(isInternational,'0')='0' and schooltypename in('幼儿园','托育点')
group by CountyName 
)s001 group by CountyName  
)m001

union all
select CountyName,0 as ybty,0 as wbty,yb as ybzxx,wb as wbzxx from(
   select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'   and isnull(isInternational,'0') ='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报'  and isnull(isInternational,'0')='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
group by CountyName 
)s001 group by CountyName  )m002
)x001 inner join report_county z on x001.CountyName=z.countyname group by x001.CountyName,z.num 

union all

 select '中职校'as CountyName, SUM(yb)ybty,0ybzxx,SUM(wb)wbty,0wbzxx,ROUND((CAST(sum(yb) AS FLOAT)/(sum(yb)+sum(wb)) * 100),2)as'上报率(%)',17 as num from (
  select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'   and isnull(isInternational,'0')='0' and schooltypename in('中等职业学校','职业高中学校')
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报'  and isnull(isInternational,'0')='0' and schooltypename in('中等职业学校','职业高中学校')
group by CountyName 
)s001 group by CountyName  
) x002
union all 
 select '国际子女学校'as CountyName, SUM(yb)ybty,0ybzxx,SUM(wb)wbty,0wbzxx, ROUND((CAST(sum(yb) AS FLOAT)/(sum(yb)+sum(wb)) * 100),2)as'上报率(%)',18 as num  from (
  select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'   and isnull(isInternational,0) ='1'
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 12:00:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23) 
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)  group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报'  and isnull(isInternational,0) ='1'
group by CountyName 
)s001 group by CountyName  
) x003 

union all 

 select '总计'as '区',SUM(yb)as'已报中小学',0as'已报幼儿园',SUM(wb)as'未报中小学',0as'未报幼儿园',Cast(CONVERT(decimal(18,2),SUM(yb)) /CONVERT(decimal(18,2),(SUM(yb)+SUM(wb)))*100 AS NUMERIC(18,2))'上报率(%)',19 as num from (
   select CountyName,SUM(已报)yb,SUM(未报)wb from (
select CountyName ,0 as'已报',COUNT(1)as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 09:30:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23)   
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)    group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)  and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)  group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode   
)v  where 1=1 and ReportStatus ='未报'  
group by CountyName 

union all

select CountyName as'辖区',COUNT(1) as'已报',0as'未报' from (
   select   isnull(a000.isInternational,'0')isInternational,a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,CONVERT(varchar(100),getdate(),23)+' 09:30:00')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate=CONVERT(varchar(100),getdate(),23)   
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate=CONVERT(varchar(100),getdate(),23)    group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate=CONVERT(varchar(100),getdate(),23)  and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)=CONVERT(varchar(100),getdate(),23)  group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode  
)v  where 1=1 and ReportStatus !='未报' 
group by CountyName 
)s001 group by CountyName  
)x021
) m012 ";

                #endregion
                sWhere = " order by  num asc";
            }
            else if (typeindex == 3 || typeindex == 4 || typeindex == 8)
            {
                #region 午检打卡报表
                sql = @" select *,[打卡率(%)]as'dkl' from (
select x001.CountyName'区',sum(ydkzxx)'已打卡中小学',sum(ydkty)'已打卡幼儿园',sum(wdkzxx)'未打卡中小学',sum(wdkty)'未打卡幼儿园',ROUND(CAST((sum(ydkzxx)+sum(ydkty)) AS FLOAT)/(sum(ydkzxx)+sum(ydkty)+sum(wdkzxx)+sum(wdkty)) * 100,2)'打卡率(%)',z.num from (
select CountyName ,sum(未午检打卡)wdkty,sum(已午检打卡)ydkty,0wdkzxx,0ydkzxx from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'   and isnull(isInternational,'0') ='0' and schooltypename in('幼儿园','托育点')
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'   and isnull(isInternational,'0') ='0' and schooltypename in('幼儿园','托育点')
 group by CountyName
)v group by CountyName 
union all

select CountyName ,0wdkty,0ydkty,sum(未午检打卡)wdkzxx,sum(已午检打卡)ydkzxx from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'  and isnull(isInternational,'0') ='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'  and isnull(isInternational,'0') ='0' and schooltypename  not in('幼儿园','托育点','中等职业学校','职业高中学校')
 group by CountyName
)v  group by CountyName 
)x001 inner join report_county z on x001.CountyName=z.countyname group by x001.CountyName,z.num

union all 

select '中职校'CountyName,sum(ydk)ydkty,0ydkzxx,sum(wdk)wdkty,0wdkzxx,ROUND(CAST((sum(ydk)) AS FLOAT)/(sum(ydk)+sum(wdk)) * 100,2)'打卡率(%)',17 as num from (
select CountyName ,sum(未午检打卡)wdk,sum(已午检打卡)ydk from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'  and isnull(isInternational,'') ='0' and schooltypename in('中等职业学校','职业高中学校')
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'  and isnull(isInternational,'') ='0' and schooltypename in('中等职业学校','职业高中学校')
 group by CountyName
)v group by CountyName 
)x002
union all

  
select '国际子女学校'CountyName,sum(ydk)ydkty,0ydkzxx,sum(wdk)wdkty,0wdkzxx,ROUND(CAST((sum(ydk)) AS FLOAT)/(sum(ydk)+sum(wdk)) * 100,2)'打卡率(%)',18 as num from (
select CountyName ,sum(未午检打卡)wdk,sum(已午检打卡)ydk from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡'  and isnull(isInternational,'') ='1' 
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡'  and isnull(isInternational,'') ='1' 
 group by CountyName
)v group by CountyName 
)x003 

union all

select '总计'as'区',sum(ydk)'已打卡中小学',0'已打卡幼儿园',sum(wdk)'未打卡中小学',0'未打卡幼儿园',ROUND(CAST((sum(ydk)) AS FLOAT)/(sum(ydk)+sum(wdk)) * 100,2)'打卡率(%)',19 as'num' from (
select CountyName ,sum(未午检打卡)wdk,sum(已午检打卡)ydk from(
select  CountyName ,count(SchoolCode) as '未午检打卡',0as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='未午检打卡' 
 group by CountyName
 
union all

select  CountyName ,0 as '未午检打卡',count(SchoolCode) as'已午检打卡' from (
select isnull(isInternational,'0')isInternational,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when isSigin>0 then '已午检打卡' else '未午检打卡' end)isSiginStr from (
select a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+COUNT(d.SchoolCode))as'isSigin' 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CONVERT(varchar(100),CreateDate,23)=CONVERT(varchar(100),getdate(),23)) c on a.SchoolCode=c.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate=CONVERT(varchar(100),getdate(),23) and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.isInternational,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName
)s001)v where isSiginStr='已午检打卡' 
 group by CountyName
)v group by CountyName 
)x021)s87";
                #endregion
                sWhere = " order by  num asc";
            }
            else if (typeindex == 5)
            {
                int reporttype = 0;
                #region 非教学日是否催报
                using (MAction action = new MAction("report_configure", con))
                {
                    MDataTable jxr = action.Select() ?? new MDataTable();
                    if (jxr.Rows.Count > 0)
                    {
                        reporttype = jxr.Rows[0].Get("ispressreport", 0);
                    }
                }
                #endregion
                if (reporttype == 1 || reporttype == 2)
                {
                    #region 16：00短信
                    sql = @"select message='【返校发热情况】'+
RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，全市中小学校、幼儿园实报'+CONVERT(varchar(100),(select count(1) from report_school))  +'所，各校因病直报数据汇总：'+
CASE WHEN (select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23))<=0 THEN '未筛查出因病缺课学生。' else '因病缺课学生'+CONVERT(varchar(100),(select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23) and a.isIntoSchool in('入校后','校门口')))+'人。'end
union all 
select 
message=
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))>0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '新发发热学生'+CONVERT(varchar(100),SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))+'人' WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '未筛查出新发发热学生' ELSE '' END +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '（' end +
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '）' end +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))>0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '，均为在校期间筛查出' WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '' ELSE '' END
+'；'
 from (
select count(1)'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',count(1)'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and a.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',count(1)'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')  and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',count(1)'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',count(1)'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('一年级','二年级','三年级','四年级','五年级')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',count(1)'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select 
message=
CASE WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)>0 THEN '新发发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)<=0 THEN '无新增发热等症状教职员工'  ELSE '' END +
CASE WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)>0 THEN '，均为在校期间筛查出' ELSE '' END+
'。'
 from (
select count(1)'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',count(1)'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName ='小学' and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',count(1)'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',count(1)'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',count(1)'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all


select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName='小学'
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',count(1)'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message=
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN (
'今日新增'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起'+
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '（' end +
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN '幼儿园'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '小学'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '初中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '高中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '中职校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '国际子女学校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)
+CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '）' end +
+'在校期间聚集性发热病例，') ELSE '今日未发现在校期间聚集性发热病例，' END
union all
 select message='未发现核酸检测阳性病例。'";
                    #endregion
                }
                else
                {
                    #region 16:00后 短信模板
                    sql = @"select message='【返校发热情况】'+
RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，全市中小学校、幼儿园实报'+CONVERT(varchar(100),(select count(1) from report_school))  +'所，各校因病直报数据汇总：'+
CASE WHEN (select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23))<=0 THEN '未筛查出因病缺课学生。' else '因病缺课学生'+CONVERT(varchar(100),(select count(1) from dbo.report_student_absence a inner join report_school b on a.schoolcode=b.SchoolCode where a.AbsenceDate=CONVERT(varchar(100),getdate(),23)))+'人。'end
union all 
select 
message=
(CASE WHEN (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN
'新发发热学生'+CONVERT(varchar(100),SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))+'人' ELSE '未筛查出新发发热学生' end) +
CASE WHEN (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))<=0
THEN '' else '（' end +
(CASE WHEN SUM(全部幼儿园在校发热学生)>0 THEN '幼儿园'+CONVERT(varchar(100),SUM(全部幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(全部幼儿园在校发热学生)>0 THEN '、' ELSE '' END)+
(CASE WHEN SUM(全部小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(全部小学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(全部中学在校发热学生)>0 THEN '中学'+CONVERT(varchar(100),SUM(全部中学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(全部中职校在校发热学生)>0 THEN '中职校'+CONVERT(varchar(100),SUM(全部中职校在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(全部国际子女学校在校发热学生)>0 THEN '国际子女学校'+CONVERT(varchar(100),SUM(全部国际子女学校在校发热学生))+'人' ELSE '' END)+
CASE WHEN (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))<=0
THEN '' else '）' end +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))>0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '，在校期间筛查出发热学生'+CONVERT(varchar(100),SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))+'人' WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0 AND (SUM(全部幼儿园在校发热学生)+SUM(全部小学在校发热学生)+SUM(全部中学在校发热学生)+SUM(全部中职校在校发热学生)+SUM(全部国际子女学校在校发热学生))>0 THEN '，在校期间未筛查出发热学生' ELSE '' END +
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '（' end +
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN '、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人、' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
CASE WHEN (SUM(幼儿园在校发热学生)+SUM(小学在校发热学生)+SUM(中学在校发热学生)+SUM(中职校在校发热学生)+SUM(国际子女学校在校发热学生))<=0
THEN '' else '）' end +'；'
 from (
select count(1)'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',count(1)'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and a.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',count(1)'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')  and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',count(1)'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',count(1)'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('一年级','二年级','三年级','四年级','五年级')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',count(1)'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and a.Grade in('六年级','七年级','八年级','九年级','高一','高二','高三')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'全部幼儿园在校发热学生',0'全部小学在校发热学生',0'全部中学在校发热学生',0'全部中职校在校发热学生',0'全部国际子女学校在校发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select 
message=
CASE WHEN SUM(新增发热教职工)>0 THEN '新发发热教职员工'+CONVERT(varchar(100),SUM(新增发热教职工))+'人' ELSE '未筛查出新发发热教职员工' END +
CASE WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)>0 THEN '，在校期间筛查出发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' WHEN SUM(新增发热教职工)>0 AND SUM(在校发热教职工)<=0 THEN '，在校期间未筛查出发热教职员工'  ELSE '' END +'。'
 from (
select count(1)'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',count(1)'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName ='小学' and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',count(1)'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',count(1)'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校') and isnull(b.isInternational,0)=0
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',count(1)'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and isnull(b.isInternational,0)=1
union all


select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName='小学'
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',count(1)'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('小学','幼儿园','托育点','中等职业学校','职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'全部幼儿园在校发热教职工',0'全部小学在校发热教职工',0'全部中学在校发热教职工',0'全部中职校在校发热教职工',0'全部国际子女学校在校发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message=
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN (
'今日新增'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起'+
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '（' end +
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN '幼儿园'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '小学'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '初中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '高中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '中职校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '国际子女学校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)
+CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '）' end +
+'在校期间聚集性发热病例，') ELSE '今日未发现在校期间聚集性发热病例，' END
union all
 select message='未发现核酸检测阳性病例。' ";
                    #endregion
                }

            }
            else if (typeindex == 6)
            {
                #region 16:00后苗子汇总
                sql = @"select ROW_NUMBER() over( order by CreateDate asc) number,* from (
select * from (
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,sum(alcount)alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,(case when sum(tk)>0 then '已停课' else '' end)tk from (
--总数
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--类型--------------------------------------------------------------------类型--------------------------------------------------------------------类型------------------------------------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwd,0 as alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='未到校'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,count(AbsenceCode) alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='校门口'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,0 as alcountxm,count(AbsenceCode) alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='入校后'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)x002 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
---未检测，检测中，阴性，阳性--------------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk--------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcount,0alcountwd,0alcountxm,0alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwjc,0 alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=0  and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all 
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,count(AbsenceCode) alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,count(AbsenceCode) as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阴性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,0 as alcountyix,count(AbsenceCode) as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阳性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
) x003 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--停课----------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk-
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,1as tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
left join report_suspension f on a.SchoolCode=f.SchoolCode where f.SuspnDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59' and f.IsClasses='停课' and (SuspensionType='全校' or (SuspensionType='年级' and SuspensionGrade=b.Grade) or (SuspensionType='班级' and SuspensionGrade=b.Grade and SuspensionClass=b.Class))--b.Grade,b.Class
)s004 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s009 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s912 where  SeedlingClaim = '校级苗子-发热聚集(一天一班3例)' and (alcountrx + alcountxm )>=3 and
SchoolCode NOT IN
(SELECT   SchoolCode
FROM      report_vseedlingdetail
WHERE   CONVERT(varchar(100), CreateDate, 23) = CONVERT(varchar(100), getdate(), 23) AND 
SeedlingClaim = '校级苗子-发热聚集(三天一班6例)')
union all
select * from (
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,sum(alcount)alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,(case when sum(tk)>0 then '已停课' else '' end)tk from (
--总数
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--类型--------------------------------------------------------------------类型--------------------------------------------------------------------类型------------------------------------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,sum(alcountwd)alcountwd,sum(alcountxm)alcountxm,sum(alcountrx)alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwd,0 as alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='未到校'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,count(AbsenceCode) alcountxm,0 as alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='校门口'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 as alcountwd,0 as alcountxm,count(AbsenceCode) alcountrx from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where c.isIntoSchool='入校后'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)x002 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
---未检测，检测中，阴性，阳性--------------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk--------------------------------------
select SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcount,0alcountwd,0alcountxm,0alcountrx,sum(alcountwjc)alcountwjc,sum(alcountjcz)alcountjcz,sum(alcountyix)alcountyix,sum(alcountyax)alcountyax,0 tk from (
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,count(AbsenceCode) alcountwjc,0 alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=0  and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all 
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,count(AbsenceCode) alcountjcz,0 as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,count(AbsenceCode) as alcountyix,0 as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阴性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0 alcountwjc,0 as alcountjcz,0 as alcountyix,count(AbsenceCode) as alcountyax from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode where ISNULL(isReceiveCheck,0)=1 and isnull(d.CheckResult,'')='阳性' and DiseaseName='发热'
)s001 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
) x003 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
union all
--停课----------------------------------------------------------------------------------------------alcount,0alcountwd,0alcountxm,0alcountrx,0alcountjcz,0alcountyix,0alcountyax,0 tk-
select  SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone,0alcount,0alcountwd,0alcountxm,0alcountrx,0alcountwjc,0alcountjcz,0alcountyix,0alcountyax,1as tk from(
select a.SeedlingCode,a.CreateDate,a.CountyName,a.CommunityName,a.SchoolCode,a.SchoolName,a.SchoolTypeName,a.DiseaseName,a.SeedlingClaim,b.Grade,b.Class,c.isIntoSchool,isnull(d.CheckResult,'')CheckResult,c.AbsenceCode,a.Contacts,a.ContactsPhone 
from  (select * from report_vseedlingdetail 
where CreateDate BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59') a 
inner join [dbo].[report_seedlingcases] b  on a.SeedlingCode=b.SeedlingCode
inner join [dbo].[report_student_absence] c on b.AbsenceCode=c.AbsenceCode
left join [dbo].[Report_Student_Absence_Management] d on b.AbsenceCode=d.AbsenceCode
left join report_suspension f on a.SchoolCode=f.SchoolCode where f.SuspnDate  BETWEEN CONVERT(varchar(100), DATEADD(DAY, - 1, getdate()),23) + ' 16:00:00' AND CONVERT(varchar(100), getdate(), 23) + ' 15:59:59' and f.IsClasses='停课' and (SuspensionType='全校' or (SuspensionType='年级' and SuspensionGrade=b.Grade) or (SuspensionType='班级' and SuspensionGrade=b.Grade and SuspensionClass=b.Class))--b.Grade,b.Class
)s004 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s009 group by SeedlingCode,CreateDate,CountyName,CommunityName,SchoolCode,SchoolName,SchoolTypeName,DiseaseName,SeedlingClaim,Grade,Class,Contacts,ContactsPhone
)s912 where  SeedlingClaim = '校级苗子-发热聚集(三天一班6例)' and (alcountrx + alcountxm )>=6
)x091";//视图
                #endregion
            }
            else if (typeindex == 7)
            {
                int reporttype = 0;
                #region 非教学日是否催报
                using (MAction action = new MAction("report_configure", con))
                {
                    MDataTable jxr = action.Select() ?? new MDataTable();
                    if (jxr.Rows.Count > 0)
                    {
                        reporttype = jxr.Rows[0].Get("ispressreport", 0);
                    }
                }
                #endregion
                if (reporttype == 1 || reporttype == 2)
                {
                    #region 周末16:00 短信模板
                    sql = @"select 
message=RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，'+
(CASE WHEN SUM(在校发热学生)<=0 THEN'各校直报今日无新增发热等症状学生' ELSE '各校直报今日新增发热等症状学生'+CONVERT(varchar(100),SUM(在校发热学生))+'人' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '、中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '、中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'）' ELSE '' END)+
(CASE WHEN SUM(新增发热学生)<=0 and SUM(在校发热学生)<=0 THEN'' WHEN SUM(新增发热学生)>0 and SUM(在校发热学生)<=0 THEN'，在校期间未筛查出发热学生'  ELSE '，均为在校期间筛查出' END)+
+'；'
 from (
select count(1)'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName in('小学')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',count(1)'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校','小学')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
UNION ALL
select 
message=
(CASE WHEN SUM(在校发热教职工)<=0 THEN+'无新增发热等症状教职员工' ELSE '新增发热等症状教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热教职工)>0 THEN+'小学'+CONVERT(varchar(100),SUM(小学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热教职工)>0 THEN+'、中学'+CONVERT(varchar(100),SUM(中学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热教职工)>0 THEN+'、中职校'+CONVERT(varchar(100),SUM(中职校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热教职工)>0 THEN+'、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'）' ELSE '' END)+
(CASE WHEN SUM(在校发热教职工)<=0 and SUM(在校发热教职工)<=0 THEN+''  ELSE '，均为在校期间筛查出' END)+
'。'
 from (
select count(1)'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName in('小学')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',count(1)'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校','小学')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message=
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN (
'今日新增'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起'+
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '（' end +
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN '幼儿园'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '小学'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '初中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '高中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '中职校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '国际子女学校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)
+CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '）' end +
+'在校期间聚集性发热病例，') ELSE '今日未发现在校期间聚集性发热病例，' END
union all
select message='未发现核酸检测阳性病例。' ";
                    #endregion
                }
                else
                {
                    #region 周末16:00 短信模板
                    sql = @"select 
message=RIGHT('00'+CAST(DATEPART(MM,getdate()) AS VARCHAR(2)),2)+'月'+RIGHT('00'+CAST(DATEPART(DD,getdate()) AS VARCHAR(2)),2)+'日截止'+RIGHT('00'+CAST(DATEPART(HH,getdate()) AS VARCHAR(2)),2)+':'+RIGHT('00'+CAST(DATEPART(MI,getdate()) AS VARCHAR(2)),2)+'，'+
(CASE WHEN SUM(新增发热学生)<=0 THEN'各校直报今日无新增发热等症状学生' ELSE '各校直报今日新增发热等症状学生'+CONVERT(varchar(100),SUM(新增发热学生))+'人' END)+
(CASE WHEN SUM(新增发热学生)<=0 and SUM(在校发热学生)<=0 THEN'' WHEN SUM(新增发热学生)>0 and SUM(在校发热学生)<=0 THEN'，在校期间未筛查出发热学生'  ELSE '，在校期间筛查出发热学生'+CONVERT(varchar(100),SUM(在校发热学生))+'人' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热学生)>0 THEN'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热学生)>0 THEN '小学'+CONVERT(varchar(100),SUM(小学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热学生)>0 THEN '、中学'+CONVERT(varchar(100),SUM(中学在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热学生)>0 THEN '、中职校'+CONVERT(varchar(100),SUM(中职校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热学生)>0 THEN '、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热学生))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热学生)>0 THEN'）' ELSE '' END)+
+'；'
 from (
select count(1)'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热学生',count(1)'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生'  from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热学生',0'在校发热学生',count(1)'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',count(1)'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName in('小学')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',count(1)'中学在校发热学生',0'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校','小学')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',count(1)'中职校在校发热学生',0'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热学生',0'在校发热学生',0'幼儿园在校发热学生',0'小学在校发热学生',0'中学在校发热学生',0'中职校在校发热学生',count(1)'国际子女学校在校发热学生' from report_student_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
UNION ALL
select 
message=
(CASE WHEN SUM(新增发热教职工)<=0 THEN+'无新增发热等症状教职员工' ELSE '新增发热等症状教职员工'+CONVERT(varchar(100),SUM(新增发热教职工))+'人' END)+
(CASE WHEN SUM(新增发热教职工)<=0 and SUM(在校发热教职工)<=0 THEN+'' WHEN SUM(新增发热教职工)>0 and SUM(在校发热教职工)<=0 THEN '，在校期间未筛查出发热教职员工'  ELSE '，在校期间筛查出发热教职员工'+CONVERT(varchar(100),SUM(在校发热教职工))+'人' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'（' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'幼儿园'+CONVERT(varchar(100),SUM(幼儿园在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(幼儿园在校发热教职工)>0 THEN+'、' ELSE '' END)+
(CASE WHEN SUM(小学在校发热教职工)>0 THEN+'小学'+CONVERT(varchar(100),SUM(小学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中学在校发热教职工)>0 THEN+'、中学'+CONVERT(varchar(100),SUM(中学在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(中职校在校发热教职工)>0 THEN+'、中职校'+CONVERT(varchar(100),SUM(中职校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(国际子女学校在校发热教职工)>0 THEN+'、国际子女学校'+CONVERT(varchar(100),SUM(国际子女学校在校发热教职工))+'人' ELSE '' END)+
(CASE WHEN SUM(在校发热教职工)>0 THEN+'）' ELSE '' END)+
'。'
 from (
select count(1)'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23)
union all
select 0'新增发热教职工',count(1)'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工'  from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
union all
select 0'新增发热教职工',0'在校发热教职工',count(1)'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='幼儿园' or b.SchoolTypeName='托育点')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',count(1)'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName in('小学')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',count(1)'中学在校发热教职工',0'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and b.SchoolTypeName not in('幼儿园','托育点','中等职业学校','职业高中学校','小学')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',count(1)'中职校在校发热教职工',0'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=0 and (b.SchoolTypeName='中等职业学校' or b.SchoolTypeName='职业高中学校')
union all
select 0'新增发热教职工',0'在校发热教职工',0'幼儿园在校发热教职工',0'小学在校发热教职工',0'中学在校发热教职工',0'中职校在校发热教职工',count(1)'国际子女学校在校发热教职工' from report_teacher_absence a inner join report_school b on a.SchoolCode=b.SchoolCode 
where Casenature='新发' and Symptom like '%发热%' and AbsenceDate= CONVERT(varchar(100),GETDATE(),23) and (a.isIntoSchool='校门口' or a.isIntoSchool='入校后')
and isnull(b.isInternational,0)=1
)v
union all
select message=
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN (
'今日新增'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起'+
CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '（' end +
(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x )>0 THEN '幼儿园'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName ='幼儿园' or SchoolTypeName ='托育点') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '小学'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('一年级','二年级','三年级','四年级','五年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '初中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('六年级','七年级','八年级','九年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '高中'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and c.Grade in('高一','高二','高三','高预年级') and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '中职校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')  and (SchoolTypeName in('中等职业学校','职业高中学校') or c.Grade in('职一','职二','职三','职四','高预年级')) and isnull(isInternational,0)=0
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起、' ELSE '' END)+

(CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)>0 THEN '国际子女学校'+CONVERT(varchar(100),(select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后') and isnull(isInternational,0)=1
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x))+'起' ELSE '' END)
+CASE WHEN (select COUNT(1) from (select * from (
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and  c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
and SeedlingClaim='校级苗子-发热聚集(一天一班3例)'and b.SchoolCode not in(select SchoolCode from report_seedling where CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)' )
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples
union all 
select b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples,count(1)'alcount' from  report_seedlingcases a 
inner join report_seedling b on a.SeedlingCode=b.SeedlingCode 
inner join report_student_absence c on a.AbsenceCode=c.AbsenceCode
inner join report_standard d on b.StandardCode=d.StandardCode
inner join report_school f on b.SchoolCode=f.SchoolCode
where b.CreateDate between CONVERT(varchar(100),dateadd(day,-1,getdate()),23)+' 16:00:00' and CONVERT(varchar(100),GETDATE(),23)+' 15:59:59' and b.DiseaseCode='8ef59696-6735-4f54-bdd6-3f3ef31f5d81' and SeedlingClaim='校级苗子-发热聚集(三天一班6例)'   and c.Casenature='新发' and c.isIntoSchool in('校门口','入校后')
group by b.SeedlingCode,b.SeedlingClaim,d.StandardPeoples)x012 group by SeedlingCode,SeedlingClaim,alcount,StandardPeoples having alcount>=StandardPeoples)x)<=0
THEN '' else '）' end +
+'在校期间聚集性发热病例，') ELSE '今日未发现在校期间聚集性发热病例，' END
union all
select message='未发现核酸检测阳性病例。' ";
                    #endregion
                }

            }
            else if (typeindex == 10)
            {
                #region 发热闭环情况统计表
                sql = @"select ROW_NUMBER() over(order by x002.num)numbers ,x002.CountyName as'辖区',isnull(sum(隔离已满14天未闭环学校数),0)as'满14天未闭环学校数',isnull(sum(隔离已满14天未闭环病例数),0)as'满14天未闭环病例数' from (
select c.CountyName,c.SchoolName,1as'隔离已满14天未闭环学校数',count(1)as'隔离已满14天未闭环病例数' from Report_Student_Absence_Management a 
 inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
 inner join report_school c on a.SchoolCode=c.SchoolCode 
 where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=14
 group by c.CountyName,c.SchoolName 
)x001 right join report_county x002 on x001.CountyName=x002.countyname group by x002.CountyName,x002.num
union all
select '17'as numbers,'合计' as'辖区',isnull(sum(隔离已满14天未闭环学校数),0)as'满14天未闭环学校数',isnull(sum(隔离已满14天未闭环病例数),0)as'满14天未闭环病例数' from (
select c.CountyName,c.SchoolName,1as'隔离已满14天未闭环学校数',count(1)as'隔离已满14天未闭环病例数' from Report_Student_Absence_Management a 
 inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
 inner join report_school c on a.SchoolCode=c.SchoolCode 
 where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=14
 group by c.CountyName,c.SchoolName 
)x001  ";

                #endregion
                sWhere = " ";
            }
            else if (typeindex == 11)
            {
                #region 发热闭环学校明细
                sql = @"select d.num,c.CountyName '辖区',c.SchoolName as '学校名称',c.SchoolTypeName as'学校类型',c.Contacts as'填报人',c.ContactsPhone as'填报人号码',count(1)as'隔离已满14天未闭环病例数' from Report_Student_Absence_Management a 
inner join report_student_absence b on a.AbsenceCode=b.AbsenceCode
inner join report_school c on a.SchoolCode=c.SchoolCode 
inner join report_county d on c.CountyName=d.countyname
where isnull(isBlackSchool,0)=0 and  DateDiff(dd,CONVERT(datetime,b.AbsenceDate),getdate())>=14
group by c.CountyName,c.SchoolName,c.SchoolTypeName,c.Contacts,c.ContactsPhone,d.num  ";
                #endregion
                sWhere = " order by num asc ";
            }
            #endregion


            MDataTable reTba = new MDataTable();
            using (MAction action = new MAction(sql, conn))
            {
                cache.Clear();//清除所有缓存项
                reTba = action.Select(sWhere);
            }

            if (typeindex == 0 || typeindex == 5 || typeindex == 7)
            {
                foreach (var item in reTba.Rows)
                {
                    string message = item.Get("message", "");
                    message = message.Replace("，）", "）");
                    message = message.Replace("（，", "（");
                    message = message.Replace("、）", "）");
                    message = message.Replace("（、", "（");
                    message = message.Replace("。。", "。");
                    message = message.Replace("，，", "，");
                    message = message.Replace("、、", "、");
                    item.Set("message", message);
                }
            }
            if (typeindex == 2)
            {
                #region 修正上报情况统计表

                int x = reTba.Rows.Count;
                int xt = 0;//第几行
                int zxx = 0;//中小学
                int yey = 0;//幼儿园
                foreach (var item in reTba.Rows)
                {
                    xt++;

                    if (x != xt)
                    {
                        bool jsl = false;
                        if (item.Get("未报中小学", 0) == 1)
                        {
                            item.Set("已报中小学", item.Get("已报中小学", 0) + 1);
                            item.Set("未报中小学", 0);
                            jsl = true;
                            zxx++;
                        }
                        if (item.Get("未报幼儿园", 0) == 1)
                        {
                            item.Set("已报幼儿园", item.Get("已报幼儿园", 0) + 1);
                            item.Set("未报幼儿园", 0);
                            jsl = true;
                            yey++;
                        }

                        if (jsl)
                        {
                            item.Set("上报率(%)", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                            item.Set("sbl", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                        }
                    }
                    else
                    {
                        bool hzl = false;
                        if (zxx > 0)
                        {
                            item.Set("已报中小学", item.Get("已报中小学", 0) + zxx);
                            item.Set("未报中小学", item.Get("未报中小学", 0) - zxx);
                            hzl = true;
                        }
                        if (yey > 0)
                        {
                            item.Set("已报幼儿园", item.Get("已报幼儿园", 0) + yey);
                            item.Set("未报幼儿园", item.Get("未报幼儿园", 0) - yey);
                            hzl = true;
                        }

                        if (hzl)
                        {
                            item.Set("上报率(%)", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                            item.Set("sbl", (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0)) / (item.Get("未报中小学", 0) + item.Get("未报幼儿园", 0) + item.Get("已报中小学", 0) + item.Get("已报幼儿园", 0)) * 100);
                        }
                    }
                }


                #endregion
            }
            else if (typeindex == 4)
            {
                #region 修正午检打卡报表

                int x = reTba.Rows.Count;
                int xt = 0;//第几行
                int zxx = 0;//中小学
                int yey = 0;//幼儿园
                foreach (var item in reTba.Rows)
                {
                    xt++;

                    if (x != xt)
                    {
                        bool jsl = false;
                        if (item.Get("未打卡中小学", 0) == 1)
                        {
                            item.Set("已打卡中小学", item.Get("已打卡中小学", 0) + 1);
                            item.Set("未打卡中小学", 0);
                            jsl = true;
                            zxx++;
                        }
                        if (item.Get("未打卡幼儿园", 0) == 1)
                        {
                            item.Set("已打卡幼儿园", item.Get("已打卡幼儿园", 0) + 1);
                            item.Set("未打卡幼儿园", 0);
                            jsl = true;
                            yey++;
                        }

                        if (jsl)
                        {
                            item.Set("打卡率(%)", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                            item.Set("dkl", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                        }
                    }
                    else
                    {
                        bool hzl = false;
                        if (zxx > 0)
                        {
                            item.Set("已打卡中小学", item.Get("已打卡中小学", 0) + zxx);
                            item.Set("未打卡中小学", item.Get("未打卡中小学", 0) - zxx);
                            hzl = true;
                        }
                        if (yey > 0)
                        {
                            item.Set("已打卡幼儿园", item.Get("已打卡幼儿园", 0) + yey);
                            item.Set("未打卡幼儿园", item.Get("未打卡幼儿园", 0) - yey);
                            hzl = true;
                        }

                        if (hzl)
                        {
                            item.Set("打卡率(%)", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                            item.Set("dkl", (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0)) / (item.Get("未打卡中小学", 0) + item.Get("未打卡幼儿园", 0) + item.Get("已打卡中小学", 0) + item.Get("已打卡幼儿园", 0)) * 100);
                        }
                    }
                }


                #endregion
            }
            if (typeindex == 1 || typeindex == 2 || typeindex == 3 || typeindex == 4)
            {
                foreach (var item in reTba.Rows)
                {
                    string sbl = item.Get("sbl", 0.00m).ToString();
                    string ts = item.Get("上报率(%)", 0.00m).ToString();
                    item.Set("sbl", sbl);
                    item.Set("上报率(%)", ts);
                }
            }
            return reTba;
        }

        public void DoSentAllDayReport(string conn, string phonestr, string mess, string groupstr = "")
        {
            string phonelst = string.Empty;
            var phonearr = phonestr.Split(',');
            foreach (var item in phonearr)
            {
                if (CheckPhoneIsAble(item))
                {
                    phonelst += item + ",";
                }
            }
            if (!string.IsNullOrEmpty(phonelst))
            {
                phonelst = phonelst.TrimEnd(',');
            }
            using (MAction action = new MAction("Report_PhoneMessage", conn))
            {
                cache.Clear();//清除所有缓存项
                if (!string.IsNullOrEmpty(phonelst))
                {
                    string MessageCode = Guid.NewGuid().ToString();
                    action.ResetTable("Report_PhoneMessage_detail");
                    action.Set("MessageDetailCode", Guid.NewGuid().ToString());
                    action.Set("MessageCode", MessageCode);
                    action.Set("SendCommunityCode", "2df768c3-0620-4cfa-b854-7c722858df5f");
                    action.Set("SendCityName", "上海市");
                    action.Set("SendCountyName", "市级日报短信");
                    action.Set("SchoolCode", "");
                    action.Set("PhoneNumber", phonelst);
                    if (!action.Insert())
                    {
                        action.RollBack();
                    }

                    //主表新增
                    action.ResetTable("Report_PhoneMessage");
                    action.Set("MessageCode", MessageCode);
                    action.Set("CreateDate", DateTime.Now);
                    action.Set("CreateUserCode", "admin");
                    action.Set("title", DateTime.Now.ToString("yyyyMMddHHmmss") + "短信日报");
                    action.Set("message", mess);
                    action.Set("SchoolCodeArr", "");
                    action.Set("lettertype", 0);
                    if (!string.IsNullOrEmpty(phonelst))
                    {
                        string messagecontent = HttpUtility.UrlEncode(mess, Encoding.Default);

                        String messstr = "username=ybqkzb&password=CnaJ9_ETDphF&destAddr=" + phonelst +
                                             "&content=" + messagecontent + "&reqReport=true";
                        //调用短信接口
                        Root ot = new Root();
                        string reurl = string.Empty;
                        try
                        {
                            reurl = HttpGet2("http://202.120.199.225:8082/api/http/SendSmsMessage", messstr);
                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                            action.Set("batchId", ot.batchId);
                            action.Set("code", ot.code);


                        }
                        catch (Exception ex)
                        {
                            //action.RollBack();
                            ot = JsonConvert.DeserializeObject<Root>(reurl);
                            if (ot == null)
                            {
                                action.Set("batchId", "");
                                action.Set("code", 400);
                            }
                            else
                            {
                                action.Set("batchId", ot.batchId);
                                action.Set("code", ot.code);
                            }

                        }
                        SendMsgAuto(mess);
                    }
                    //返回值
                    if (!action.Insert())
                    {
                        action.RollBack();
                    }
                }

                //if (!string.IsNullOrEmpty(groupstr))
                //{
                //    var groupArr = groupstr.Split(',');
                //    foreach (string item in groupArr)
                //    {
                //        string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/text?room=" + item, "", mess);
                //        LogHelper.WriteLog(DateTime.Now.ToString() + "短信信息：" + message, Application.StartupPath + "/log");
                //    }
                //}
            }
        }


        /// <summary>
        /// 得到列表Json值
        /// </summary>
        /// <param name="typeindex">1/2：上报明细、3/4：打卡明细、6：聚集苗子汇总、8：打卡统计、9：上报统计</param>
        /// <returns></returns>
        public void GetListData(int typeindex = 0, string groupstr = "")
        {

            //获取数据
            MDataTable dtInfo = GetDayList(con, typeindex);


            #region 导出Excel
            ReportInAll(dtInfo, typeindex, groupstr);
            #endregion

        }

        public ExeMsgInfo ReportInAll(MDataTable dtInfo, int typeindex = 0, string groupstr = "")
        {
            string daydate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            ExeMsgInfo res = null;
            string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            string retResponse = string.Empty;
            int pageCount = 1;
            int recordCount = 0;
            if (typeindex == 1 || typeindex == 2)
            {
                string fileToSave = "";
                //上报明细
                MDataTable dtInfoDetail = GetNotTimelyList(con, Convert.ToDateTime(daydate).ToString("yyyy-MM-dd"), "", "", 1, 99999, "", ref recordCount, ref pageCount, "1", "", "", "未报", "", "") ?? new MDataTable();
                if (dtInfoDetail.Rows.Count <= 0)
                {
                    return null;
                }
                //导出保存excel
                ExcelHelper.ToSaveExcel2(dtInfoDetail, "全市每日未及时上报因病缺课缺勤报告学校表导出.xlsx", "晨报表", "", ref fileToSave);

                #region aspose.cells
                Workbook book = new Workbook(Application.StartupPath + "/upload/" + fileToSave);
                Worksheet sheet = book.Worksheets[0];
                sheet.PageSetup.LeftMargin = 0;
                sheet.PageSetup.RightMargin = 0;
                sheet.PageSetup.BottomMargin = 0;
                sheet.PageSetup.TopMargin = 0;
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.ImageFormat = ImageFormat.Emf;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

                SheetRender sr = new SheetRender(sheet, imgOptions);
                string outimg = Application.StartupPath + "/upload/" + "晨报表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                sr.ToImage(0, outimg);
                #endregion

                if (!string.IsNullOrEmpty(groupstr))
                {
                    var groupArr = groupstr.Split(',');
                    foreach (string item in groupArr)
                    {
                        string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=jpg", outimg, "");
                        LogHelper.WriteLog(DateTime.Now.ToString() + "上报明细图片返回值：" + message, Application.StartupPath + "/log");
                    }
                }

                return null;
            }
            else if (typeindex == 3 || typeindex == 4)
            {
                string fileToSave = "";
                string[] datastr = { Convert.ToDateTime(daydate).ToString("yyyy-MM-dd") };
                MDataTable dtInfoDetail = GetCensusList(con, "未午检打卡", "", "", "", "", datastr, "", 1, 9999, "", ref recordCount, ref pageCount, "", "");
                //打卡明细
                if (dtInfoDetail.Rows.Count <= 0)
                {
                    return null;
                }
                ExcelHelper.ToSaveExcel2(dtInfoDetail, "午检打卡报表导出.xlsx", "午检表", "", ref fileToSave);
                #region aspose.cells
                Workbook book = new Workbook(Application.StartupPath + "/upload/" + fileToSave);
                Worksheet sheet = book.Worksheets[0];
                sheet.PageSetup.LeftMargin = 0;
                sheet.PageSetup.RightMargin = 0;
                sheet.PageSetup.BottomMargin = 0;
                sheet.PageSetup.TopMargin = 0;
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.ImageFormat = ImageFormat.Emf;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

                SheetRender sr = new SheetRender(sheet, imgOptions);
                string outimg = Application.StartupPath + "/upload/" + "午检表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                sr.ToImage(0, outimg);
                #endregion

                if (!string.IsNullOrEmpty(groupstr))
                {
                    var groupArr = groupstr.Split(',');
                    foreach (string item in groupArr)
                    {
                        string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=jpg", outimg, "");
                        LogHelper.WriteLog(DateTime.Now.ToString() + "午检明细图片返回值：" + message, Application.StartupPath + "/log");
                    }
                }

                return null;
            }
            else if (typeindex == 6)
            {
                string fileToSave = "";
                //16:00后苗子汇总
                ExcelHelper.ToSaveExcel2(dtInfo, "聚集发热苗子汇总表格导出.xlsx", "聚集发热苗子汇总表格", "聚集性发热病例汇总" + DateTime.Now.ToString("MMddHHmmss"), ref fileToSave);
                if (dtInfo.Rows.Count <= 0)
                {
                    return null;
                }
                #region aspose.cells
                Workbook book = new Workbook(Application.StartupPath + "/upload/" + fileToSave);
                Worksheet sheet = book.Worksheets[0];
                sheet.PageSetup.LeftMargin = 0;
                sheet.PageSetup.RightMargin = 0;
                sheet.PageSetup.BottomMargin = 0;
                sheet.PageSetup.TopMargin = 0;
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.ImageFormat = ImageFormat.Emf;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

                SheetRender sr = new SheetRender(sheet, imgOptions);
                string outimg = Application.StartupPath + "/upload/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                sr.ToImage(0, outimg);
                #endregion

                if (!string.IsNullOrEmpty(groupstr))
                {
                    var groupArr = groupstr.Split(',');
                    foreach (string item in groupArr)
                    {
                        string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=jpg", outimg, "");
                        LogHelper.WriteLog(DateTime.Now.ToString() + "聚集发热返回值：" + message, Application.StartupPath + "/log");
                    }
                }

                return null;
            }
            else if (typeindex == 8)//打卡统计转成图片
            {
                string fileToSave = "";
                string title = Convert.ToDateTime(daydate).Month + " 月" + Convert.ToDateTime(daydate).Day + " 日截止 " +
                               Convert.ToDateTime(daydate).ToString("HH:mm") + "全市因病缺课缺勤直报系统午检打卡情况";
                ExcelHelper.ToSaveExcel(dtInfo, "午检打卡报表导出(日报).xlsx", "午检表", title, ref fileToSave);

                #region aspose.cells
                Workbook book = new Workbook(Application.StartupPath + "/upload/" + fileToSave);
                Worksheet sheet = book.Worksheets[0];
                sheet.PageSetup.LeftMargin = 0;
                sheet.PageSetup.RightMargin = 0;
                sheet.PageSetup.BottomMargin = 0;
                sheet.PageSetup.TopMargin = 0;
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.ImageFormat = ImageFormat.Emf;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

                SheetRender sr = new SheetRender(sheet, imgOptions);
                string outimg = Application.StartupPath + "/upload/" + "午检表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                sr.ToImage(0, outimg);
                #endregion

                if (!string.IsNullOrEmpty(groupstr))
                {
                    var groupArr = groupstr.Split(',');
                    foreach (string item in groupArr)
                    {
                        string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=jpg", outimg, "");
                        LogHelper.WriteLog(DateTime.Now.ToString() + "午检打卡报表返回值：" + message, Application.StartupPath + "/log");
                    }
                }

            }
            else if (typeindex == 9)//上报统计转成图片
            {
                string fileToSave = "";
                string title = Convert.ToDateTime(daydate).Month + " 月" + Convert.ToDateTime(daydate).Day + " 日截止 " +
                               Convert.ToDateTime(daydate).ToString("HH:mm") + "全市因病缺课缺勤直报系统上报情况";
                ExcelHelper.ToSaveExcel(dtInfo, "上报统计表导出(日报).xlsx", "上报表", title, ref fileToSave);

                #region aspose.cells
                Workbook book = new Workbook(Application.StartupPath + "/upload/" + fileToSave);
                Worksheet sheet = book.Worksheets[0];
                sheet.PageSetup.LeftMargin = 0;
                sheet.PageSetup.RightMargin = 0;
                sheet.PageSetup.BottomMargin = 0;
                sheet.PageSetup.TopMargin = 0;
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.ImageFormat = ImageFormat.Emf;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

                SheetRender sr = new SheetRender(sheet, imgOptions);
                string outimg = Application.StartupPath + "/upload/" + "上报表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                sr.ToImage(0, outimg);
                #endregion


                if (!string.IsNullOrEmpty(groupstr))
                {
                    var groupArr = groupstr.Split(',');
                    foreach (string item in groupArr)
                    {
                        string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=jpg", outimg, "");
                        LogHelper.WriteLog(DateTime.Now.ToString() + "上报统计表返回值：" + message, Application.StartupPath + "/log");
                    }
                }
            }
            else if (typeindex == 10)//上报统计转成图片
            {
                string fileToSave = "";
                MDataTable dtInfoDetail = GetDayList(con, 11);
                if (dtInfoDetail.Rows.Count > 0)
                {
                    //午检打卡报表\修正午检打卡报表
                    string title = Convert.ToDateTime(daydate).Month + " 月" + Convert.ToDateTime(daydate).Day + " 日截止 " +
                                   Convert.ToDateTime(daydate).ToString("HH:mm") + "全市因病缺课缺勤直报系统发热处置闭环情况";
                    //Adf.ShReport.Services.ExcelHelper.ToExcelmian(dtInfo, dtInfoDetail, "发热处置闭环情况导出(日报).xlsx", "发热处置闭环情况(日报)" + date, title);
                    //ExcelHelper.ToExcelmian()
                    ExcelHelper.ToExcelmian(dtInfo, dtInfoDetail, "发热处置闭环情况导出(日报).xlsx", "闭环表", ref fileToSave, title);

                    #region 发第一张图片+aspose.cells
                    Workbook book = new Workbook(Application.StartupPath + "/upload/" + fileToSave);
                    //发第一张图片
                    Worksheet sheet = book.Worksheets[0];
                    sheet.PageSetup.LeftMargin = 0;
                    sheet.PageSetup.RightMargin = 0;
                    sheet.PageSetup.BottomMargin = 0;
                    sheet.PageSetup.TopMargin = 0;
                    ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                    imgOptions.ImageFormat = ImageFormat.Emf;
                    imgOptions.OnePagePerSheet = true;
                    imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

                    SheetRender sr = new SheetRender(sheet, imgOptions);
                    string outimg = Application.StartupPath + "/upload/" + "闭环表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                    sr.ToImage(0, outimg);

                    if (!string.IsNullOrEmpty(groupstr))
                    {
                        var groupArr = groupstr.Split(',');
                        foreach (string item in groupArr)
                        {
                            string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=jpg", outimg, "");
                            LogHelper.WriteLog(DateTime.Now.ToString() + "闭环表返回值：" + message, Application.StartupPath + "/log");
                        }
                    }
                    #endregion


                    #region 发第二张图片+aspose.cells
                    Worksheet sheet2 = book.Worksheets[1];
                    sheet2.PageSetup.LeftMargin = 0;
                    sheet2.PageSetup.RightMargin = 0;
                    sheet2.PageSetup.BottomMargin = 0;
                    sheet2.PageSetup.TopMargin = 0;
                    ImageOrPrintOptions imgOptions2 = new ImageOrPrintOptions();
                    imgOptions2.ImageFormat = ImageFormat.Emf;
                    imgOptions2.OnePagePerSheet = true;
                    imgOptions2.PrintingPage = PrintingPageType.IgnoreBlank;

                    SheetRender sr2 = new SheetRender(sheet2, imgOptions2);
                    string outimg2 = Application.StartupPath + "/upload/" + "闭环明细" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                    sr2.ToImage(0, outimg2);

                    if (!string.IsNullOrEmpty(groupstr))
                    {
                        var groupArr = groupstr.Split(',');
                        foreach (string item in groupArr)
                        {
                            string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=jpg", outimg2, "");
                            LogHelper.WriteLog(DateTime.Now.ToString() + "闭环表返回值：" + message, Application.StartupPath + "/log");
                        }
                    }
                    #endregion

                    //发第三个文件
                    if (!string.IsNullOrEmpty(groupstr))
                    {
                        var groupArr = groupstr.Split(',');
                        foreach (string item in groupArr)
                        {
                            string message = ServerClass.HttpPostByFile("http://222.73.241.5:31999/room/send/file?room=" + item + "&type=xls&fileName=发热处置闭环情况(日报)" + DateTime.Now.ToString("yyyy-MM-dd:hh:mm"), Application.StartupPath + "/upload/" + fileToSave, "");
                            LogHelper.WriteLog(DateTime.Now.ToString() + "闭环表返回值：" + message, Application.StartupPath + "/log");
                        }
                    }
                }

            }

            return null;
        }

        public void SendMsgAuto(string curAnswer)
        {
            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();
            try
            {
                if (!String.IsNullOrEmpty(curAnswer))
                {
                    //新增到预约表
                    string leaderphone = string.Empty;
                    leaderphone = (DbService.GetOne("adf_datadic", "diccode='rbldcellphone'") ?? new MDataRow()).Get("dicvalue", "");
                    MDataRow mDataRow = new MDataRow(DBTool.GetColumns("report_timingsend"));
                    string timingsendcode = Guid.NewGuid().ToString();
                    mDataRow.Set("timingsendcode", timingsendcode);
                    mDataRow.Set("sendmessage", curAnswer);
                    mDataRow.Set("sendphone", leaderphone);
                    mDataRow.Set("wxteamname", "");
                    mDataRow.Set("sendappointmenttime", DateTime.Now.AddMinutes(10));
                    mDataRow.Set("remindertime", DateTime.Now.AddMinutes(5));
                    mDataRow.Set("sendstatus", "0");
                    exeMsgInfo = AddByTimingsend(mDataRow);

                }
                else
                {
                    exeMsgInfo.RetStatus = 400;
                    exeMsgInfo.RetValue = "发送内容为空";
                }
            }
            catch (Exception ex)
            {

                exeMsgInfo.RetStatus = 400;
                exeMsgInfo.RetValue = ex.Message;
            }

        }
        public ExeMsgInfo AddByTimingsend(MDataRow dataRow)
        {

            ExeMsgInfo exeMsgInfo = new ExeMsgInfo();

            String sendmessage = dataRow.Get("sendmessage", "");
            if (String.IsNullOrEmpty(sendmessage))
            {
                exeMsgInfo.RetStatus = 400;
                exeMsgInfo.RetValue = "发送内容不能为空";
                return exeMsgInfo;
            }

            String sendphone = dataRow.Get("sendphone", "");
            if (String.IsNullOrEmpty(sendphone))
            {
                exeMsgInfo.RetStatus = 400;
                exeMsgInfo.RetValue = "发送号码不能为空";
                return exeMsgInfo;
            }

            dataRow.Set("clicknum", 0);
            dataRow.Set("sendstatus", 0);
            dataRow.Set("CreateDate", DateTime.Now);

            using (MAction action = new MAction("report_timingsend"))
            {
                try
                {
                    action.BeginTransation();
                    action.Data.LoadFrom(dataRow);
                    if (!action.Insert())
                    {
                        action.RollBack();
                        exeMsgInfo.RetStatus = 400;
                        exeMsgInfo.RetValue = "发送失败";
                        action.EndTransation();
                        return exeMsgInfo;
                    }

                    exeMsgInfo.RetStatus = 100;
                    exeMsgInfo.RetValue = "发送成功";
                }
                catch (Exception ex)
                {
                    action.RollBack();
                    exeMsgInfo.RetStatus = 400;
                    exeMsgInfo.RetValue = ex.Message;
                }
                finally
                {
                    action.EndTransation();
                }
            }

            return exeMsgInfo;
        }


        /// <summary>
        /// 创建人：zuowh
        /// 创建时间：2018-07-02
        /// 得到全市每日未及时上报因病缺课缺勤报告学校表
        /// </summary>   
        /// <param name="wurenleixing">类型，0缺勤，1缺课</param>
        /// <param name="startdate">开始日期</param>  
        /// <param name="countyname">区</param>
        /// <param name="communityname">社区</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="recordCount"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public MDataTable GetNotTimelyList(string conn, string startdate, string countyname, string communityname, int pageIndex, int pageSize, string orderBy, ref int recordCount,
            ref int pageCount, string wurenleixing = "1", string expWhere = "", string schooltypename = "", string istype = "", string gradesStr = "", string isinternational = "")
        {
            String sWhere = " 1=1 ";
            String sWhere2 = " 1=1 ";
            string shsbtime = string.Empty;
            using (MAction action = new MAction("adf_datadic", conn))
            {
                shsbtime = (action.Select("diccode='daytimeOne1'") ?? new MDataTable()).Rows[0].Get("dicvalue", "");
            }
            if (!String.IsNullOrEmpty(countyname))//区
            {
                sWhere += " and countyname like '%" + countyname + "%'";
            }
            if (!String.IsNullOrEmpty(communityname))//社区
            {
                sWhere += " and CommunityName =" + DbService.SetQuotesValue(communityname);
            }
            if (!string.IsNullOrEmpty(expWhere))
            {
                sWhere += expWhere;
            }
            if (!string.IsNullOrEmpty(schooltypename))
            {
                schooltypename = schooltypename.TrimEnd(',');
                sWhere += " and schooltypename in(" + schooltypename + ")";
            }
            if (!string.IsNullOrEmpty(istype))
            {
                sWhere += " and ReportStatus =" + DbService.SetQuotesValue(istype);
            }
            if (!string.IsNullOrEmpty(isinternational))
            {
                sWhere += " and isinternational =" + DbService.SetQuotesValue(isinternational);
            }
            string gradesWhere1 = string.Empty;
            if (!string.IsNullOrEmpty(gradesStr))
            {
                var gradesArr = gradesStr.Split(',');
                string minGrade = string.Empty;
                int i = 0;
                foreach (var item in gradesArr)
                {
                    if (i == 0)
                    {
                        minGrade += "grade like '%" + item + "%'";
                    }
                    else
                    {
                        minGrade += " or grade like '%" + item + "%'";
                    }
                    i++;
                }
                gradesWhere1 = " where a000.SchoolCode in(select schoolcode from report_student where (" + minGrade + ")  group by schoolcode)";
            }
            String sOrderBy = " order by CountyName asc,CommunityName asc";
            sWhere += sOrderBy;
            string sql = @"   select   '" + startdate + @"' as 'daytime',a000.SchoolCode,a000.CountyName,a000.CommunityName, a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate,isnull(a000.isInternational,'0')isInternational,CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,'@datetime " + shsbtime + @"')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (
 select max(OkCode)OkCode,SchoolCode,Min(CreateDate)CreateDate from(
select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate='@datetime'   
 and WuRenLeiXing='无人缺课'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_student_absence 
  where AbsenceDate='@datetime'    group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate='@datetime'  and IsClasses='停课'  group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)='@datetime'  group by SchoolCode) a002  
)s001 group by SchoolCode
) a003  on  a003.SchoolCode=a000.SchoolCode " + gradesWhere1;

            if (wurenleixing == "0")//缺勤数据
            {
                sql = @"   '" + startdate + @"' as 'daytime',select   a000.SchoolCode,a000.CountyName,a000.CommunityName,a000.isDirectly, 
  dbo.report_community.CommunityName as CommunityNames,a000.SchoolName,a000.SchoolTypeName,a000.Contacts,a000.ContactsPhone,
  a000.organizationcode,a003.OkCode,a003.CreateDate,isnull(a000.isInternational,'0')isInternational, CASE ISNULL(a003.OkCode,0) when 0 THEN '未报'  ELSE  
   CASE   WHEN datediff(SECOND,a003.CreateDate,'@datetime " + shsbtime + @"')>=0 THEN '已报' ELSE '未及时报告' END  END   as  ReportStatus 
  from  report_school  a000   inner join report_community 
 on report_community.CommunityCode=a000.CommunityName
 left join  (select  OkCode,SchoolCode,CreateDate from (select   
 COUNT(NoAbsenceId) as OkCode,SchoolCode,min(CreateDate) as CreateDate from  report_noabsence a001   where TianBiaoDate='@datetime'   
 and WuRenLeiXing='无人缺勤'  group by SchoolCode
 union all 
 select   COUNT(AbsenceCode) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_teacher_absence 
  where AbsenceDate='@datetime'    group by SchoolCode
 union all 
 select    COUNT(SuspensionId) as OkCode,SchoolCode,min(CreateDate) as CreateDate  from  report_suspension 
  where SuspnDate='@datetime'   group by SchoolCode
  union all 
 select    COUNT(EmergencyId)  as OkCode ,SchoolCode,min(CreateDate) as CreateDate  from  report_emergency  
 where  CONVERT(varchar(10), report_emergency.CreateDate, 20)='@datetime'  group by SchoolCode) a002  ) a003  on  a003.SchoolCode=a000.SchoolCode " + gradesWhere1;
            }

            if (!string.IsNullOrEmpty(startdate))
            {
                sql = StringHelper.ReplaceAll(sql, "@datetime", startdate);
            }

            //return DbService.GetPageTable(sql, pageIndex, pageSize, sWhere, ref recordCount, ref pageCount);
            MDataTable reTba = new MDataTable();

            using (MAction action = new MAction(sql, conn))
            {
                cache.Clear();//清除所有缓存项
                reTba = action.Select(pageIndex, pageSize, sWhere, out recordCount);
                if (pageSize > 0)
                {
                    pageCount = MathHelper.DivisionForMinInt(recordCount, pageSize);
                }
            }

            return reTba;
        }


        /// <summary>
        /// 打卡列表(报表)
        /// </summary>
        /// <param name="schoolcode"></param>
        /// <param name="senddate"></param>
        /// <param name="communityname"></param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="recordCount"></param>
        /// <param name="pageCount"></param>
        /// <param name="wurenleixing"></param>
        /// <param name="startdate"></param>
        /// <param name="countyname"></param>
        /// <returns></returns>
        public MDataTable GetCensusList(string conn, string isSiginStr, string schoolcode, string CountyName, string CommunityName, string SchoolTypeName, string[] datearr, string SchoolName, int pageIndex, int pageSize, string orderBy, ref int recordCount,
            ref int pageCount, string expWhere = "", string isinternational = "")
        {
            String sWhere = " 1=1 ";
            string shsbtime = string.Empty;
            using (MAction action = new MAction("adf_datadic", conn))
            {
                shsbtime = (action.Select("diccode='daytimeOne2'") ?? new MDataTable()).Rows[0].Get("dicvalue", "");
            }
            if (!String.IsNullOrEmpty(SchoolName))
            {
                sWhere += " and SchoolName like '%" + SchoolName + "%'";
            }
            if (!String.IsNullOrEmpty(isSiginStr))
            {
                sWhere += " and isSiginStr = '" + isSiginStr + "'";
            }
            if (!String.IsNullOrEmpty(isinternational))
            {
                sWhere += " and isinternational = '" + isinternational + "'";
            }
            if (!string.IsNullOrEmpty(expWhere))
            {
                sWhere += expWhere;
            }
            if (!String.IsNullOrEmpty(schoolcode))
            {
                sWhere += " and  schoolcode=" + DbService.SetQuotesValue(schoolcode);
            }
            if (!string.IsNullOrEmpty(SchoolTypeName))
            {
                SchoolTypeName = SchoolTypeName.TrimEnd(',');
                sWhere += " and schooltypename in(" + SchoolTypeName + ")";
            }
            if (!String.IsNullOrEmpty(CountyName))
            {
                sWhere += " and countyname like '%" + CountyName + "%'";
            }
            if (!String.IsNullOrEmpty(CommunityName))
            {
                sWhere += " and communityname like '%" + CommunityName + "%'";
            }
            String sOrderBy = " order by daytime desc,CountyName asc,CommunityName2 asc";
            sWhere += sOrderBy;
            string sql = string.Empty;
            int x = 0;
            foreach (string startdate in datearr)
            {
                x++;
                if (x > 1)
                {
                    sql += " union all ";
                }
                sql += @"select '" + startdate + @"' as 'daytime',Contacts,ContactsPhone,SchoolLeaders,LContactsPhone,CityName,SchoolTypeName,CommunityName,CountyName,CommunityName2,SchoolCode,SchoolName,(case when (isSigin=1 or sclnum>0) then '已午检打卡' when isSigin=2 then '未及时午检打卡' else '未午检打卡' end)isSiginStr,isInternational from (
select a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName as CommunityName2,a.SchoolCode,a.SchoolName,(COUNT(c.SignInCode)+ (case when COUNT(h.SignInCode)=0 then 0 else COUNT(h.SignInCode)+1 end))as'isSigin',+COUNT(d.SchoolCode) sclnum,isnull(a.isInternational,'0')isInternational 
from report_school a 
inner join report_community b on a.CommunityName=b.CommunityCode
left join (select * from Report_NoonSignIn where CreateDate <='" + startdate + @" " + shsbtime + @"' and CONVERT(varchar(100),CreateDate,23)='" + startdate + @"') c on a.SchoolCode=c.SchoolCode
left join (select * from Report_NoonSignIn where CreateDate >'" + startdate + @" " + shsbtime + @"' and CONVERT(varchar(100),CreateDate,23)='" + startdate + @"') h on a.SchoolCode=h.SchoolCode
left join (select SchoolCode  from Report_Suspension where SuspnDate='" + startdate + @"' and IsClasses='停课' and SuspensionType='全校')d on a.SchoolCode=d.SchoolCode
group by a.Contacts,a.ContactsPhone,a.SchoolLeaders,a.LContactsPhone,a.CityName,a.SchoolTypeName,a.CommunityName,a.CountyName,b.CommunityName,a.SchoolCode,a.SchoolName,a.isInternational
)s001
";
            }

            MDataTable reTba = new MDataTable();

            using (MAction action = new MAction(sql, conn))
            {
                cache.Clear();//清除所有缓存项
                reTba = action.Select(pageIndex, pageSize, sWhere, out recordCount);
                if (pageSize > 0)
                {
                    pageCount = MathHelper.DivisionForMinInt(recordCount, pageSize);
                }
            }

            return reTba;
            //return DbService.GetPageTable(sql, pageIndex, pageSize, sWhere, ref recordCount, ref pageCount);
        }


        /// <summary>
        /// 数据同步
        /// </summary>
        /// <param name="access_token">获取的token值</param>
        /// <param name="stucodeversion">上一次更新的疾病信息版本</param>
        public void DataSync(string access_token, string stucodeversion)
        {

            //sql语句
            string sqlstr = @"select  ROW_NUMBER()over( order by a.rv asc)num,a.AbsenceCode,b.OrganizationCode,b.RegisterDate,a.AbsenceDate,b.CountyName,b.schoolTypeName,b.SchoolName,a.StudentName,a.ParentName,
a.ParentPhoneNumber,a.Gender,a.Age,a.Class,a.grade,a.Casenature,a.isIntoSchool,a.AbsenceNumber,a.Symptom,a.OtherSymptom,
a.Disease,a.OtherDisease,a.Hurt,a.OtherHurt,a.Degree,a.Remark,b.Contacts,b.ContactsPhone,(case when isnull(c.DealStatus,'')='其他' then c.OtherDealStatus else isnull(c.DealStatus,'') end)dealStatusName,substring(a.rv, 1, 8)rv,a.CreateDate
 from report_student_absence a 
inner join report_school b on a.SchoolCode=b.SchoolCode
left join Report_Student_Absence_Management c on a.AbsenceCode=c.AbsenceCode";
            //sqlstr += " where CONVERT(varchar(100),a.CreateDate,23)= CONVERT(varchar(100),'2020-09-03',23)";
            sqlstr += " where 1=1 ";
            if (!string.IsNullOrEmpty(stucodeversion))
            {
                sqlstr += "and rv>" + stucodeversion;
            }
            using (MAction action = new MAction(sqlstr, con))
            {
                MDataTable datalist = action.Select() ?? new MDataTable();


                string strrv = string.Empty;
                if (datalist.Rows.Count > 0)
                {
                    foreach (var item in datalist.Rows)
                    {
                        strrv = ByteToHexString(item.Get<byte[]>("rv"), item.Get<byte[]>("rv").Length);
                        Dictionary<string, object> dicmodel = new Dictionary<string, object>();
                        dicmodel.Add("absenceCode", item.Get("AbsenceCode", ""));
                        dicmodel.Add("organizationCode", item.Get("organizationCode", ""));
                        dicmodel.Add("registerDate", item.Get("registerDate", DateTime.Now));
                        dicmodel.Add("absenceDate", DateTime.Now);
                        dicmodel.Add("countyName", item.Get("CountyName", ""));
                        dicmodel.Add("schoolTypeName", item.Get("schoolTypeName", ""));
                        dicmodel.Add("schoolName", item.Get("SchoolName", ""));
                        dicmodel.Add("studentName", item.Get("StudentName", ""));
                        dicmodel.Add("parentName", item.Get("ParentName", ""));
                        dicmodel.Add("parentPhoneNumber", item.Get("ParentPhoneNumber", ""));
                        dicmodel.Add("gender", item.Get("Gender", ""));
                        dicmodel.Add("age", item.Get("Age", 0));
                        dicmodel.Add("grade", item.Get("grade", ""));
                        dicmodel.Add("class", item.Get("Class", ""));
                        dicmodel.Add("casenature", item.Get("Casenature", ""));
                        dicmodel.Add("isIntoSchool", item.Get("isIntoSchool", ""));
                        dicmodel.Add("absenceNumber", item.Get("AbsenceNumber", ""));
                        dicmodel.Add("symptom", item.Get("Symptom", ""));
                        dicmodel.Add("otherSymptom", item.Get("OtherSymptom", ""));
                        dicmodel.Add("disease", item.Get("Disease", ""));
                        dicmodel.Add("otherDisease", item.Get("OtherDisease", ""));
                        dicmodel.Add("hurt", item.Get("Hurt", ""));
                        dicmodel.Add("degree", item.Get("Degree", ""));
                        dicmodel.Add("remark", item.Get("Remark", ""));
                        dicmodel.Add("contacts", item.Get("Contacts", ""));
                        dicmodel.Add("contactsPhone", item.Get("ContactsPhone", ""));
                        dicmodel.Add("dealStatusName", item.Get("dealStatusName", ""));
                        dicmodel.Add("status", 0);
                        dicmodel.Add("updateTime", DateTime.Now);
                        string poststr = PostByCode("https://datasyncapi.shsunshine.org/api/YbqqDetails", access_token, dicmodel);
                        RootSuccess SuccessByPost = JsonConvert.DeserializeObject<RootSuccess>(poststr);
                    }
                }

                //给更新表更新值
                if (!string.IsNullOrEmpty(strrv))
                {
                    //切表
                    action.ResetTable("report_VersionTab");
                    action.Set("stucodeversion", strrv);
                    action.Update("code='123456789'");
                }
            }
        }


        /// <summary>
        /// 删除同步数据
        /// </summary>
        /// <param name="access_token">获取的token值</param>
        /// <param name="delversion">上一次删除的疾病信息版本</param>
        public void DeleteData(string access_token, string delversion)
        {
            //sql语句
            string sqlstr = @"select ROW_NUMBER() over(order by delversion asc)num,*,substring(delversion, 1, 8)delversions from report_delstuTab";
            sqlstr += " where 1=1 ";
            if (!string.IsNullOrEmpty(delversion))
            {
                sqlstr += "and delversion >" + delversion;
            }
            using (MAction action = new MAction(sqlstr, con))
            {
                MDataTable datalist = action.Select() ?? new MDataTable();
                string delversionrv = string.Empty;
                if (datalist.Rows.Count > 0)
                {
                    foreach (var item in datalist.Rows)
                    {
                        delversionrv = ByteToHexString(item.Get<byte[]>("delversions"), item.Get<byte[]>("delversions").Length);
                        string poststr = DeleteByCode("https://datasyncapi.shsunshine.org/api/YbqqDetails/Deleted/" + item.Get("AbsenceCode", ""), access_token);
                        RootSuccess SuccessByPost = JsonConvert.DeserializeObject<RootSuccess>(poststr);
                    }
                }

                //给更新表更新值
                if (!string.IsNullOrEmpty(delversionrv))
                {
                    //切表
                    action.ResetTable("report_VersionTab");
                    action.Set("delversion", delversionrv);
                    action.Update("code='123456789'");
                }
            }
        }
        /// <summary>
        /// 指定Post地址使用Get 方式获取全部字符串
        /// </summary>
        /// <param name="url">请求后台地址</param>
        /// <returns></returns>
        public string PostByCode(string url, string access_token, Dictionary<string, object> dic)
        {
            string result = "";
            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "POST";
                //req.ContentType = "application/x-www-form-urlencoded";
                req.ContentType = "application/json";
                //req.Accept = "application/json";
                req.Headers.Add("Authorization", "Bearer " + access_token);
                req.Headers.Add("Cache-Control", "no-cache");
                #region 添加Post 参数
                //StringBuilder builder = new StringBuilder();
                //int i = 0;
                //foreach (var item in dic)
                //{
                //    if (i > 0)
                //        builder.Append("&");
                //    builder.AppendFormat("{0}={1}", item.Key, item.Value);
                //    i++;
                //}
                string Contentjson = JsonConvert.SerializeObject(dic);
                byte[] data = Encoding.UTF8.GetBytes(Contentjson);
                req.ContentLength = data.Length;
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(data, 0, data.Length);
                    reqStream.Close();
                }
                #endregion
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                Stream stream = resp.GetResponseStream();
                //获取响应内容
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    result = reader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                result = "{\"code\":400,\"id\":\"\"}";
            }
            return result;
        }

        /// <summary>
        /// 指定Post地址使用Get 方式获取全部字符串
        /// </summary>
        /// <param name="url">请求后台地址</param>
        /// <returns></returns>
        public string DeleteByCode(string url, string access_token, string postDataStr = "")
        {
            string result = "";
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + (postDataStr == "" ? "" : "?") + postDataStr);
                request.Method = "GET";
                //request.ContentType = "text/html;charset=UTF-8";
                request.ContentType = "application/json";
                //req.Accept = "application/json";
                request.Headers.Add("Authorization", "Bearer " + access_token);
                request.Headers.Add("Cache-Control", "no-cache");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream myResponseStream = response.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                string retString = myStreamReader.ReadToEnd();
                myStreamReader.Close();
                myResponseStream.Close();

                return retString;
            }
            catch (Exception ex)
            {
                result = "{\"code\":400,\"id\":\"\"}";
            }
            return result;
        }
        /// <summary>
        /// 16进制转字符串
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public string ByteToHexString(byte[] bytes, int length)
        {
            string str = string.Empty;
            if (bytes != null)
            {
                for (int i = 0; i < length; i++)
                {
                    str += bytes[i].ToString("X2");
                }
                str = "0x" + str;
            }
            return str;
        }
    }

    public class RootModel
    {
        /// <summary>
        /// 
        /// </summary>
        public string access_token { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int expires_in { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string token_type { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string scope { get; set; }
    }

    public class RootSuccess
    {
        /// <summary>
        /// 
        /// </summary>
        public int code { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string id { get; set; }
    }

}
