UserBll.cs 9.79 KB
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Quiz.DAL;
using Quiz.Models;

namespace Quiz.BLL
{
    public class UserBll
    {
        public static int IsAnswer(string iphone)
        {
            return DAL.User.IsAnswer(iphone);
        }

        public static List<Models.User> GetUsers()
        {
            return DAL.User.GetUsers();
        }

        public static bool AddUserAnswer(Models.UserAnswer model)
        {
            return DAL.User.AddUserAnswer(model);
        }

        public static List<Models.Topic> GetTopics()
        {
            return DAL.User.GetTopics();
        }

        public static List<Models.School> GetSchools()
        {
            return DAL.User.GetSchools();
        }

        public static UserAnswer GetUserAnswerOne(string phone)
        {
            return DAL.User.GetUserAnswerOne(phone);
        }
        public static bool ExamineSendMsg(string code, string mobile)
        {
            return DAL.User.ExamineSendMsg(code, mobile);
        }
        //数据解析
        public static List<UserAnswer> GetAnswers()
        {
            return DAL.User.GetAnswers();
        }

     
        public static List<UserAnswer> GetAnswerskq()
        {
            return DAL.User.GetAnswerskq();
        }
        public static List<Models.Topic> GetTopicskq()
        {
            return DAL.User.GetTopicskq();
        }
        public static List<Models.User> GetUserskq()
        {
            return DAL.User.GetUserskq();
        }
        public static List<UserAnswer> GetAnswersyc()
        {
            return DAL.User.GetAnswersyc();
        }
        public static List<UserAnswer> getschoolMB()
        {

            return DAL.User.getschoolMB();
        }
        public static List<Models.Topic> GetTopicsyc()
        {
            return DAL.User.GetTopicsyc();
        }
        public static List<Models.User> GetUsersyc()
        {
            return DAL.User.GetUsersyc();
        }
        public static List<Models.User> GetUsersycTwo() {
            return DAL.User.GetUsersycTwo();
        }
        public static DataKanbans getDataKanbanlist()
        {
            DataKanbans resetlist = new DataKanbans();
            var schooltypelist = DAL.User.GetSchoolList();
            var scholcount = DAL.User.getschoolcountT();
            var rtypelist = DAL.User.getschooltypeRecoveryList();
            var rlist = DAL.User.getschoolRecoveryList();
            var schoolList = DAL.User.GetSchoolNameList();
            ///总人数分步
            if (schooltypelist != null && schooltypelist.Count > 0)
            {
                resetlist.TotalSchoolCount = new List<schoolTypeM>();
                resetlist.TotalSchoolCount = scholcount;
            }
            //调查人数分部
            if (rtypelist != null && rtypelist.Count > 0)
            {
                resetlist.SchoolTypesList = new List<schoolTypeM>();
                resetlist.SchoolTypesList = rtypelist;
            }
            //今日
            if (schoolList != null && schoolList.Count > 0)
            {
                decimal dayCount = 0;
                decimal RdayCount = 0;
                int isok = 0;
                List<schoolRecovery> daySchoolR = new List<schoolRecovery>();
                if (rlist != null && rlist.Count > 0)
                {
                    daySchoolR = rlist.FindAll(o => o.Intime == DateTime.Now.ToString("yyyy-MM-dd"));

                    if (daySchoolR != null && daySchoolR.Count > 0) isok = 1;
                }
                resetlist.SchoolDayCount = new List<schoolRecovery>();
                foreach (var item in schoolList)
                {
                    schoolRecovery schoolday = new schoolRecovery();
                    schoolday.schoolName = item.schoolName;
                    dayCount = dayCount + item.schoolcount;
                    if (isok == 1)
                    {
                        var get = daySchoolR.Find(o => o.schoolName == item.schoolName);
                        if (get != null && !string.IsNullOrEmpty(get.schoolName))
                        {
                            schoolday.RecoveryCount = get.RecoveryCount;
                            decimal rcount = get.RecoveryCount / item.schoolcount;
                            schoolday.Recovery = decimal.Parse(rcount.ToString("#0.00")) * 100;
                            RdayCount = RdayCount + get.RecoveryCount;
                        }
                        else
                        {
                            schoolday.schoolcount = 0;
                            schoolday.Recovery = 0;
                        }
                    }
                    else
                    {
                        schoolday.schoolcount = 0;
                        schoolday.Recovery = 0;
                    }
                    resetlist.SchoolDayCount.Add(schoolday);

                }

                resetlist.dayRCount = RdayCount;
                decimal dayR = RdayCount / dayCount;
                resetlist.dayRecovery = decimal.Parse(dayR.ToString("#0.00")) * 100;

            }
            //累计
            if (schoolList != null && schoolList.Count > 0)
            {

                resetlist.SchoolCount = new List<schoolRecovery>();
                decimal TotalCount = 0;
                decimal RTotalcount = 0;
                int isok = 0;
                if (rlist != null && rlist.Count > 0) isok = 1;
                foreach (var item in schoolList)
                {
                    schoolRecovery schoolday = new schoolRecovery();
                    TotalCount = TotalCount + item.schoolcount;
                    schoolday.schoolName = item.schoolName;
                    if (isok == 1)
                    {
                        var get = rlist.Find(o => o.schoolName == item.schoolName);
                        if (get != null && !string.IsNullOrEmpty(get.schoolName))
                        {
                            schoolday.RecoveryCount = int.Parse(get.RecoveryCount.ToString());
                            decimal rcount = get.RecoveryCount / item.schoolcount;
                            schoolday.Recovery = decimal.Parse(rcount.ToString("#0.00")) * 100;
                            RTotalcount = RTotalcount + int.Parse(get.RecoveryCount.ToString());

                        }
                        else
                        {
                            schoolday.RecoveryCount = 0;
                            schoolday.Recovery = 0;
                        }

                    }
                    else
                    {
                        schoolday.RecoveryCount = 0;
                        schoolday.Recovery = 0;

                    }


                    resetlist.SchoolCount.Add(schoolday);
                }

                resetlist.TotalRCount = RTotalcount;
                decimal totalR = RTotalcount / TotalCount;
                resetlist.TotalRecovery = decimal.Parse(totalR.ToString("#0.00")) * 100;
                // resetlist.TotalRecovery = decimal.Parse(dayR.ToString("#0.00")) * 100;
                resetlist.TotalCount = TotalCount;
            }

            return resetlist;
        }

        public static resetModel yanzheng(string mobile)
        {
            resetModel m = new resetModel();
            var get = DAL.User.getIsKanuser(mobile);
            if (get != null && !string.IsNullOrEmpty(get.PhoneName))
            {

                //生成4位随机码
                Random rad = new Random();//实例化随机数产生器rad;
                int code = rad.Next(1000, 10000);//用rad生成大于等于1000,小于等于9999的随机数;
                List<string> Mymobile = new List<string>();
                Mymobile.Add(mobile);
                string cons = string.Format("【满意度调查】您正在参与的教育调查4位验证码为:{0}", code);
                var ss = new sendDC()
                {
                    Content = cons,
                    Mobile = Mymobile
                };
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(ss);
                string result = PostUrl("http://campus.myjxt.com/api/Common/ExamineSendMsg", postData);

                resetModel reset = Newtonsoft.Json.JsonConvert.DeserializeObject<resetModel>(result);
                Utility.Helper.SaveLog(string.Format("status={0}&code={1}&mobile={2}", reset.status, code, mobile), "mobilecode");
                if (reset.status == 1)
                {
                    m.status = 1;
                    m.data = code;
                }
                else
                {
                    m.message = reset.message;
                }


            }
            else {
                m.status = 0;
                m.message = "您暂无权限观看看板数据!";

            }
            return m;

        }
        public static string PostUrl(string url, string postData)
        {
            string result = "";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            //req.TimeOut = "800";//设置请求超时时间,单位为毫秒
            req.ContentType = "application/json";
            byte[] data = Encoding.UTF8.GetBytes(postData);
            req.ContentLength = data.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);

                reqStream.Close();
            }
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            Stream stream = resp.GetResponseStream();
            //获取响应内容
            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
            return result;
        }
    }
}