public List <ParameterInfoEntity> GetParameterList()
        {
            string homeindex_redisKey = SystemManageConst.HomeIndex_KEY;
            var    dataResult         = new List <ParameterInfoEntity>();

            using (var redisdb = _redisDbContext.GetRedisIntance())
            {
                dataResult = redisdb.Get <List <ParameterInfoEntity> >(homeindex_redisKey);//从缓存里取
                if (dataResult == null)
                {
                    using (var db = _dbContext.GetIntance()) //从数据库中
                    {
                        ParameterInfoEntity parameterInfoEntity = new ParameterInfoEntity();
                        parameterInfoEntity.HosInfoCount           = db.Ado.GetInt("SELECT COUNT(1) FROM YB_HosInfo");
                        parameterInfoEntity.HosInfoCheckCount      = db.Ado.GetInt("SELECT COUNT(1) FROM YB_HosInfo WHERE States != '1'");
                        parameterInfoEntity.HosInfoCheckErrorCount = db.Ado.GetInt("SELECT COUNT(1) FROM Check_ResultInfo WHERE DataType = '2'");
                        //审核列表
                        List <CheckResultInfoDto> checklist = db.Ado.SqlQuery <CheckResultInfoDto>(@"SELECT a1.CheckResultInfoCode,a1.RegisterCode,a1.PersonalCode,a1.InstitutionCode,a1.InstitutionName,a2.YLJGDJBM,a2.YLJGDJMC 
                                                             FROM dbo.Check_ResultInfo a1 LEFT JOIN dbo.HIS_YYXX a2 ON a1.InstitutionCode = a2.YYDMYYDM");
                        int checkcount = checklist.Count();
                        int onecount   = 0;
                        int twocount   = 0;
                        int threecount = 0;
                        if (checklist != null)
                        {
                            onecount   = checklist.Where(it => it.YLJGDJBM == SystemManageConst.AONE).Count();   //一级
                            twocount   = checklist.Where(it => it.YLJGDJBM == SystemManageConst.ATWO).Count();   //二级
                            threecount = checklist.Where(it => it.YLJGDJBM == SystemManageConst.ATHREE).Count(); //三级
                        }
                        parameterInfoEntity.OneProportion   = Math.Floor(Math.Round(decimal.Parse(((decimal)onecount / checkcount).ToString("0.000")), 2) * 100).ToString() + '%';
                        parameterInfoEntity.TwoProportion   = Math.Floor(Math.Round(decimal.Parse(((decimal)twocount / checkcount).ToString("0.000")), 2) * 100).ToString() + '%';
                        parameterInfoEntity.ThreeProportion = Math.Floor(Math.Round(decimal.Parse(((decimal)threecount / checkcount).ToString("0.000")), 2) * 100).ToString() + '%';
                        dataResult = new List <ParameterInfoEntity>();
                        dataResult.Add(parameterInfoEntity);
                    }
                    if (dataResult != null)//加入缓存
                    {
                        redisdb.Set(homeindex_redisKey, dataResult);
                        redisdb.Expire(homeindex_redisKey, 86400);//设置缓存时间
                    }
                }
            }
            return(dataResult);
        }
        public IActionResult UpdateFK(IFormCollection Files, string registerCode, string describe, bool repeat)
        {
            List <CheckComplaintDetailEntity> checkComplaintDetails = new List <CheckComplaintDetailEntity>();

            try
            {
                //var form = Request.Form;//直接从表单里面获取文件名不需要参数
                string    dd       = Files["File"];
                var       form     = Files; //定义接收类型的参数
                Hashtable hash     = new Hashtable();
                string    fileCode = "";    //申诉主表编码
                UserInfo  userInfo = new UserInfo
                {
                    UserId          = User.GetCurrentUserId(),
                    UserName        = User.GetCurrentUserName(),
                    InstitutionCode = User.GetCurrentUserOrganizeId(),
                    InstitutionName = User.GetCurrentUserOrganizeName()
                };
                if (repeat)
                {
                    string CheckComplainId = _afterCheckService.UpdateFeedbackCount(registerCode, describe, userInfo);
                    if (!string.IsNullOrEmpty(CheckComplainId))
                    {
                        fileCode = CheckComplainId;
                    }
                    else
                    {
                        return(Ok(new { code = -5, msg = "反馈失败,请联系管理员" }));
                    }
                }
                else
                {
                    string CheckComplainId = _afterCheckService.UpdateFK(registerCode, describe, userInfo);
                    if (!string.IsNullOrEmpty(CheckComplainId))
                    {
                        fileCode = CheckComplainId;
                    }
                }

                IFormFileCollection cols = Request.Form.Files;
                if (cols == null || cols.Count == 0)
                {
                    return(Ok(new { code = -1, msg = "没有上传文件", data = hash }));
                }
                if (string.IsNullOrEmpty(fileCode))
                {
                    return(Ok(new { code = -4, msg = "请选择档案目录" }));
                }
                int i = 0;
                foreach (IFormFile file in cols)
                {
                    i++;
                    //定义文件数组后缀格式
                    string[] LimitFileType  = { ".JPG", ".JPEG", ".PNG", ".GIF", ".PNG", ".BMP", ".DOC", ".DOCX", ".XLS", ".XLSX", ".TXT", ".PDF" };
                    string[] LimitFileType1 = { ".JPG", ".JPEG", ".PNG", ".GIF", ".PNG", ".BMP" };
                    string[] LimitFileType2 = { ".DOC", ".DOCX", ".XLS", ".XLSX", ".TXT", ".PDF" };
                    //获取文件后缀是否存在数组中
                    string currentPictureExtension = Path.GetExtension(file.FileName).ToUpper();
                    if (LimitFileType.Contains(currentPictureExtension))
                    {
                        string filetype = string.Empty;    //1图片、2文本
                        if (LimitFileType1.Contains(currentPictureExtension))
                        {
                            filetype = "1";
                        }
                        if (LimitFileType2.Contains(currentPictureExtension))
                        {
                            filetype = "2";
                        }
                        //  var uppath = "E:/znsh/Platform_ZNSH/uploads/" + fileCode + "/" ;
                        var uppath   = XYDbContext.UPLOADPATH + "医院反馈上传/" + fileCode + "/";
                        var lookpath = "/" + fileCode + "/";
                        var new_path = Path.Combine(uppath, file.FileName);
                        var path     = Path.Combine(Directory.GetCurrentDirectory(), new_path);
                        if (!Directory.Exists(uppath))
                        {
                            Directory.CreateDirectory(uppath);
                        }
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            byte[] fileByte    = new byte[file.Length]; //用文件的长度来初始化一个字节数组存储临时的文件
                            Stream fileStream  = file.OpenReadStream(); //建立文件流对象
                            string fileNameNew = Path.GetFileNameWithoutExtension(file.FileName);
                            //int a = int.Parse(fileNameNew.Substring(fileNameNew.Length - 4, 4));
                            CheckComplaintDetailEntity checkComplaintDetailEntity = new CheckComplaintDetailEntity()
                            {
                                ComplaintDetailCode = ConstDefine.CreateGuid(),
                                CheckComplainId     = fileCode,
                                ImageName           = file.FileName,
                                ImageSize           = (int)(file.Length) / 1024,
                                ImageUrl            = "/医院反馈上传" + lookpath + file.FileName,//上线时需更改
                                CreateUserId        = User.GetCurrentUserId(),
                                CreateUserName      = User.GetCurrentUserName(),
                                CreateTime          = DateTime.Now,
                                Datatype            = "1", //医院反馈上传标识
                                FilesType           = filetype
                            };
                            checkComplaintDetails.Add(checkComplaintDetailEntity);
                            //文件保存到数据库里面去
                            bool flage = _afterCheckService.Add(checkComplaintDetailEntity);
                            if (flage)
                            {
                                //再把文件保存的文件夹中
                                file.CopyTo(stream);
                                hash.Add("file", "/" + new_path);
                            }
                        }
                    }
                    else
                    {
                        return(Ok(new { status = -2, message = "请上传指定格式的图片", data = hash }));
                    }
                }
                using (var redisdb = _redisDbContext.GetRedisIntance())
                {
                    redisdb.SAdd(fileCode, checkComplaintDetails);
                    redisdb.Expire(fileCode, 86400);//设置缓存时间
                }
                return(Ok(new { status = 0, message = "上传成功", data = hash }));
            }
            catch (Exception ex)
            {
                return(Ok(new { status = -3, message = "上传失败", data = ex.Message }));
            }
        }
        /// <summary>
        /// 获取住院或门诊的统计
        /// </summary>
        /// <param name="flag">1住院2门诊</param>
        /// <returns></returns>
        public List <StaticsViewModel> GetStaticsViews(string flag, string drugname)
        {
            var dataResult = new List <StaticsViewModel>();
            //判断缓存
            string rediskey = "";

            if (flag == "1")//住院
            {
                rediskey = SystemManageConst.DRUGHOSKEY;
            }
            else
            {
                rediskey = SystemManageConst.DRUGCLINICKEY;
            }


            using (var redisdb = _redisDbContext.GetRedisIntance())
            {
                //删除缓存测试用
                //redisdb.Del(rediskey);
                dataResult = redisdb.Get <List <StaticsViewModel> >(rediskey);//从缓存里取
                if (dataResult == null)
                {
                    using (var db = _dbContext.GetIntance())
                    {
                        CheckDrugStatusEntity checkResultStatus = new CheckDrugStatusEntity()
                        {
                            CRowId = (flag == "1"?1:2), CheckResultStatus = "N", Flag = (flag == "1"?"HOS":"CLINIC"), FunctionDesc = (flag == "1" ? "'万能神药'住院信息获取" : "'万能神药'门诊信息获取")
                        };
                        bool checkStatusResultStart = UpdateResultStatusNew(checkResultStatus);
                        if (!checkStatusResultStart)
                        {
                            return(null);
                        }
                        if (flag == "1")//住院
                        {
                            dataResult = db.Queryable <AllPowerfulDrugEntity, YBHosPreInfoEntity>((a, c) => new object[] {
                                JoinType.Left, a.DrugCode == c.ItemCode
                            }).GroupBy(a => a.CommonName)
                                         .Where(a => drugname.Contains(a.CommonName))
                                         .OrderBy((a, c) => SqlFunc.AggregateSum(c.COUNT), OrderByType.Desc)
                                         .Select((a, c) => new StaticsViewModel()
                            {
                                commonname = a.CommonName, count = SqlFunc.AggregateSum(c.COUNT).ToString(), price = SqlFunc.AggregateSum(c.COUNT * c.PRICE)
                            }).ToList();
                        }
                        else
                        {
                            dataResult = db.Queryable <AllPowerfulDrugEntity, YBClinicPreInfoEntity>((a, c) => new object[] {
                                JoinType.Left, a.DrugCode == c.ItemCode
                            }).GroupBy(a => a.CommonName)
                                         .Where(a => drugname.Contains(a.CommonName))
                                         .OrderBy((a, c) => SqlFunc.AggregateSum(c.COUNT), OrderByType.Desc)
                                         .Select((a, c) => new StaticsViewModel()
                            {
                                commonname = a.CommonName, count = SqlFunc.AggregateSum(c.COUNT).ToString(), price = SqlFunc.AggregateSum(c.COUNT * c.PRICE)
                            }).ToList();
                        }
                        checkResultStatus = new CheckDrugStatusEntity()
                        {
                            CRowId = (flag == "1" ? 1 : 2), CheckResultStatus = "Y", Flag = (flag == "1" ? "HOS" : "CLINIC"), FunctionDesc = (flag == "1" ? "'万能神药'住院信息获取" : "'万能神药'门诊信息获取")
                        };
                        bool checkStatusResultEnd = UpdateResultStatusNew(checkResultStatus);
                        if (!checkStatusResultEnd)
                        {
                            return(null);
                        }
                    }
                    if (dataResult != null)//加入缓存
                    {
                        redisdb.Set(rediskey, dataResult);
                        redisdb.Expire(rediskey, 86400);//设置缓存时间1天
                    }
                }
                else
                {
                    var    dataResultNew = new List <StaticsViewModel>();
                    string drugnamenew   = drugname;
                    //遍历缓存
                    foreach (StaticsViewModel item in dataResult)
                    {
                        if (item != null && drugname.Contains(item.commonname))
                        {
                            dataResultNew.Add(item);
                            drugnamenew = drugnamenew.Replace(item.commonname + ',', "");
                        }
                    }
                    if (drugnamenew.Length > 0)//从数据库中取
                    {
                        using (var db = _dbContext.GetIntance())
                        {
                            CheckDrugStatusEntity checkResultStatus = new CheckDrugStatusEntity()
                            {
                                CRowId = (flag == "1" ? 1 : 2), CheckResultStatus = "N", Flag = (flag == "1" ? "HOS" : "CLINIC"), FunctionDesc = (flag == "1" ? "'万能神药'住院信息获取" : "'万能神药'门诊信息获取")
                            };
                            bool checkStatusResultStart = UpdateResultStatusNew(checkResultStatus);
                            if (!checkStatusResultStart)
                            {
                                return(null);
                            }
                            if (flag == "1")//住院
                            {
                                dataResult = db.Queryable <AllPowerfulDrugEntity, YBHosPreInfoEntity>((a, c) => new object[] {
                                    JoinType.Left, a.DrugCode == c.ItemCode
                                }).GroupBy(a => a.CommonName)
                                             .Where(a => drugnamenew.Contains(a.CommonName))
                                             .OrderBy((a, c) => SqlFunc.AggregateSum(c.COUNT), OrderByType.Desc)
                                             .Select((a, c) => new StaticsViewModel()
                                {
                                    commonname = a.CommonName, count = SqlFunc.AggregateSum(c.COUNT).ToString(), price = SqlFunc.AggregateSum(c.COUNT * c.PRICE)
                                }).ToList();
                            }
                            else
                            {
                                dataResult = db.Queryable <AllPowerfulDrugEntity, YBClinicPreInfoEntity>((a, c) => new object[] {
                                    JoinType.Left, a.DrugCode == c.ItemCode
                                }).GroupBy(a => a.CommonName)
                                             .Where(a => drugnamenew.Contains(a.CommonName))
                                             .OrderBy((a, c) => SqlFunc.AggregateSum(c.COUNT), OrderByType.Desc)
                                             .Select((a, c) => new StaticsViewModel()
                                {
                                    commonname = a.CommonName, count = SqlFunc.AggregateSum(c.COUNT).ToString(), price = SqlFunc.AggregateSum(c.COUNT * c.PRICE)
                                }).ToList();
                            }
                            checkResultStatus = new CheckDrugStatusEntity()
                            {
                                CRowId = (flag == "1" ? 1 : 2), CheckResultStatus = "Y", Flag = (flag == "1" ? "HOS" : "CLINIC"), FunctionDesc = (flag == "1" ? "'万能神药'住院信息获取" : "'万能神药'门诊信息获取")
                            };
                            bool checkStatusResultEnd = UpdateResultStatusNew(checkResultStatus);
                            if (!checkStatusResultEnd)
                            {
                                return(null);
                            }
                        }
                        dataResult.AddRange(dataResultNew);
                        if (dataResult != null)              //加入缓存
                        {
                            redisdb.Del(rediskey);           //先删除缓存
                            redisdb.Set(rediskey, dataResult);
                            redisdb.Expire(rediskey, 86400); //设置缓存时间1天
                        }
                    }
                    else
                    {
                        dataResult = dataResultNew;
                    }
                }
            }
            return(dataResult);
        }