Exemplo n.º 1
0
        public async Task <OutFormula> GetFormulaList(InFormula model)
        {
            OutFormula outFormula = new OutFormula
            {
                Info = new List <OutFormula_Info>()
            };
            var data = await iOHZBRepository.QueryFirstOrDefaultAsync <OhZb>("select * from OH_ZB where IsEnable=1 and CID=0 and ID=@Id", new { Id = model.ID });

            string starttime = model.StartTime;
            string endtime   = model.EndTime;

            outFormula.QueryTime = $"{starttime}至 {endtime}";
            outFormula.StartTime = starttime;
            outFormula.EndTime   = endtime;
            outFormula.Formula_c = data.FormulaC;
            var    array = Method.GetInteger(data.Formula).Split(",").GroupBy(p => p).Select(p => p.Key).ToArray();
            string re, zbmc, id;

            for (int i = 0; i < array.Length; i++)
            {
                id = array[i].ToString();
                re = await iOHZBRepository.GetZBList(starttime, endtime, id);

                data.Formula = data.Formula.Replace("'" + id + "'", re);
                zbmc         = await iOHZBRepository.GetZBMC(id);

                outFormula.Info.Add(new OutFormula_Info
                {
                    Col = zbmc,
                    Num = re,
                    ID  = id
                });
            }
            DataTable dt  = new DataTable();
            string    Ret = double.Parse(dt.Compute(data.Formula, "false").ToString()).ToString("0.##");

            outFormula.Info.Add(new OutFormula_Info
            {
                Col = data.Zbmc,
                Num = Ret,
                ID  = string.Empty
            });
            return(outFormula);
        }
Exemplo n.º 2
0
        public async Task <OutMQuery> GetComZbList(InMQuery model)
        {
            var outMQuery = new OutMQuery
            {
                Body = new List <OutMQuery_Body>(),
                Head = new List <OutMQuery_Head>()
            };

            var head = new List <OutMQuery_Head>();
            var data = await ohSetRepository.QueryFirstOrDefaultAsync <OhSet>("select * from OH_Set");

            outMQuery.UpdateTime = data.UpdateTime.ToString("yyyy-MM-dd HH:mm");
            head.Add(new OutMQuery_Head
            {
                Name = "指标名称"
            });
            var zb = await ohSetRepository.QueryAsync <OhZb>("select * from OH_ZB where IsEnable=1 and CID=0");

            if (model == null)
            {
                var timeN = DateTime.Now.ToString("yyyy-MM");
                head.Add(new OutMQuery_Head
                {
                    Name = $"全院{timeN}至{timeN}"
                });

                foreach (var item in zb)
                {
                    var Body = new OutMQuery_Body
                    {
                        Row = new List <OutMQuery_Row>()
                    };
                    var type    = item.Type;
                    var formula = item.Formula;
                    var array   = Method.GetInteger(item.Formula).Split(",").GroupBy(p => p).Select(p => p.Key).ToArray();
                    var dt      = new DataTable();
                    Body.Row.Add(new OutMQuery_Row
                    {
                        val = item.Zbmc
                    });
                    Body.Type = item.Type.ToString();
                    foreach (var t in array)
                    {
                        var re = await ohSetRepository.GetZBList(timeN, timeN, t.ToString());

                        formula = formula.Replace("'" + t.ToString() + "'", re);
                    }
                    var ret = double.Parse(dt.Compute(formula, "false").ToString() ?? string.Empty).ToString("0.##");

                    Body.Row.Add(new OutMQuery_Row
                    {
                        val = ret
                    });
                    outMQuery.Body.Add(Body);
                }
            }
            else
            {
                var table  = string.Empty;
                var type_c = string.Empty;
                foreach (var item in model.Info)
                {
                    table = item.Type switch
                    {
                        "bm" => "OH_CBXX",
                        "lx" => "OH_AJLX",
                        "xz" => "OH_AJXZ",
                        "ay" => "OH_AY",
                        "cbr" => "OH_CBXX",
                        "qt" => "",
                        _ => table
                    };

                    if (string.IsNullOrEmpty(table))
                    {
                        head.Add(new OutMQuery_Head
                        {
                            Name = $"全院{item.StartTime}至{item.EndTime}"
                        });
                    }
                    else
                    {
                        var name = await ohSetRepository.QueryFirstOrDefaultAsync <dynamic>($"select name from {table} where Id=@Id", new
                        {
                            Id = item.Data.ToString()
                        });

                        _logger.LogWarning($"sql 语句返回 dynamic   {JsonConvert.SerializeObject(data)}");
                        head.Add(new OutMQuery_Head
                        {
                            Name = $"{name}  {item.StartTime}至{item.EndTime}"
                        });
                    }
                }

                foreach (var item in zb)
                {
                    var body = new OutMQuery_Body
                    {
                        Row = new List <OutMQuery_Row>()
                    };
                    var formula = item.Formula;
                    var array   = Method.GetInteger(item.Formula).Split(",").GroupBy(p => p).Select(p => p.Key).ToArray();
                    var dt      = new DataTable();
                    body.Row.Add(new OutMQuery_Row
                    {
                        val = item.Zbmc
                    });
                    body.Type = item.Type.ToString();
                    foreach (var t in model.Info)
                    {
                        type_c = t.Type switch
                        {
                            "bm" => "1",
                            "lx" => "2",
                            "xz" => "3",
                            "ay" => "4",
                            "cbr" => "5",
                            "qt" => "0",
                            _ => type_c
                        };
                        foreach (var t1 in array)
                        {
                            var re = await ohSetRepository.GetComList(t.StartTime, t.EndTime, t1, type_c, t.Data);

                            formula = formula.Replace("'" + t1 + "'", re);
                        }
                        var ret = double.Parse(dt.Compute(formula, "false").ToString() ?? string.Empty).ToString("0.##");
                        body.Row.Add(new OutMQuery_Row
                        {
                            val = ret
                        });
                        outMQuery.Body.Add(body);
                    }
                }
            }

            outMQuery.Head = head;
            return(outMQuery);
        }