Exemplo n.º 1
0
        /// <summary>
        /// 获取所有机构下的男女比例
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public BaseResponse <ChartPieModel> GetOrgAgeList(int?groupId)
        {
            BaseResponse <ChartPieModel> response = new BaseResponse <ChartPieModel>();
            List <List <ArrayList> >     baseList = new List <List <ArrayList> >()
            {
            };

            //先找出有数据存在的机构
            var taskOrgquery = from p in unitOfWork.GetRepository <DC_Person>().dbSet
                               join org in unitOfWork.GetRepository <ORG_Organization>().dbSet
                               on p.OrganizationID equals org.OrganizationID
                               where org.GroupID == groupId && (DateTime.Now.Year - p.Birthdate.Value.Year) >= 51 && (DateTime.Now.Year - p.Birthdate.Value.Year) <= 200
                               group org by new { org.OrganizationID, org.OrgName } into g
                select new
            {
                g.Key.OrganizationID,
                g.Key.OrgName
            };
            var allorg = taskOrgquery.ToList();

            //年龄阶段
            //51--60
            //61--70
            //71--80
            //81--90
            //91--100
            //100+

            int[] ageLevel = { 1, 2, 3, 4, 5, 6 };
            int[] Start    = { 51, 61, 71, 81, 91, 100 };
            int[] End      = { 60, 70, 80, 90, 100, 200 };

            Dictionary <string, string> dataName  = new Dictionary <string, string>();
            Dictionary <string, int>    dataValue = new Dictionary <string, int>();
            List <SelectModel>          namelist  = new List <SelectModel>();


            for (int i = 0; i < 5; i++)
            {
                int selectStart = Start[i];
                int selectEnd   = End[i];
                var query11     = from p in unitOfWork.GetRepository <DC_Person>().dbSet
                                  join org in unitOfWork.GetRepository <ORG_Organization>().dbSet
                                  on p.OrganizationID equals org.OrganizationID
                                  where org.GroupID == groupId && (DateTime.Now.Year - p.Birthdate.Value.Year) >= selectStart && (DateTime.Now.Year - p.Birthdate.Value.Year) <= selectEnd
                                  group org by new { org.OrganizationID, org.OrgName } into g
                    select new
                {
                    g.Key.OrganizationID,
                    g.Key.OrgName,
                    count = g.Count()
                };
                var list = query11.ToList();
                foreach (var item in list)
                {
                    dataName.Add(item.OrganizationID + (i + 1).ToString(), Start[i] + "-" + End[i]);
                    dataValue.Add(item.OrganizationID + (i + 1).ToString(), item.count);
                }
            }
            int index = 0;

            int[] data = new int[Start.Length];
            foreach (var item in allorg)
            {
                List <ArrayList> al = new List <ArrayList>();
                index++;
                for (int i = 1; i <= 6; i++)
                {
                    if (dataValue.ContainsKey(item.OrganizationID + i.ToString()))
                    {
                        data[i - 1] += dataValue[item.OrganizationID + i.ToString()];
                        ArrayList lld = new ArrayList();
                        lld.Add(dataName[item.OrganizationID + i.ToString()]);
                        lld.Add(dataValue[item.OrganizationID + i.ToString()]);
                        al.Add(lld);
                    }
                }
                namelist.Add(new SelectModel()
                {
                    Name = item.OrgName, Value = index
                });
                baseList.Add(al);
            }
            //所有机构的值
            List <ArrayList> alllist = new List <ArrayList>();

            for (int i = 0; i < Start.Length; i++)
            {
                if (data[i] != 0)
                {
                    ArrayList all1 = new ArrayList();
                    all1.Add(Start[i] + "-" + End[i]);
                    all1.Add(data[i]);
                    alllist.Add(all1);
                }
            }
            namelist.Add(new SelectModel()
            {
                Name = "所有机构", Value = namelist.Count() + 1
            });
            namelist = namelist.OrderByDescending(a => a.Value).ToList();
            baseList.Add(alllist);

            ChartPieModel cm = new ChartPieModel();

            cm.SelectNames = namelist;
            cm.MyData      = baseList;
            response.Data  = cm;
            return(response);
        }
Exemplo n.º 2
0
 public ActionResult <ReturnModel> Post([FromBody] ChartPieModel model)
 {
     return(this.GetSuccessReturn(this.chartService.GetPieData().ToArray <PieData>()));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取所有机构下的男女比例
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public BaseResponse <ChartPieModel> GetOrgSexList(int?groupId)
        {
            BaseResponse <ChartPieModel> response = new BaseResponse <ChartPieModel>();


            //先找出有性别存在的机构
            var taskOrgquery = from t in unitOfWork.GetRepository <DC_Person>().dbSet
                               join org in unitOfWork.GetRepository <ORG_Organization>().dbSet
                               on t.OrganizationID equals org.OrganizationID
                               where org.GroupID == groupId
                               group org by new { org.OrganizationID, org.OrgName } into g
                select new
            {
                g.Key.OrganizationID,
                g.Key.OrgName
            };
            var allorg = taskOrgquery.ToList();


            var query = from p in unitOfWork.GetRepository <DC_Person>().dbSet
                        join org in unitOfWork.GetRepository <ORG_Organization>().dbSet
                        on p.OrganizationID equals org.OrganizationID
                        where org.GroupID == groupId
                        group org by new { org.OrganizationID, org.OrgName, p.Sex } into g
                select new
            {
                g.Key.OrganizationID,
                g.Key.OrgName,
                g.Key.Sex,
                Count = g.Count()
            };
            var list = query.ToList();

            Dictionary <string, string> dataName  = new Dictionary <string, string>();
            Dictionary <string, int>    dataValue = new Dictionary <string, int>();

            foreach (var item in query)
            {
                if (item.Sex == "1")
                {
                    dataName.Add(item.OrganizationID + "1", "男");
                    dataValue.Add(item.OrganizationID + "1", item.Count);
                }
                if (item.Sex == "2")
                {
                    dataName.Add(item.OrganizationID + "2", "女");
                    dataValue.Add(item.OrganizationID + "2", item.Count);
                }
                if (item.Sex != "1" && item.Sex != "2")
                {
                    dataName.Add(item.OrganizationID + "0", "其他");
                    dataValue.Add(item.OrganizationID + "0", item.Count);
                }
            }
            List <List <ArrayList> > baseList = new List <List <ArrayList> >()
            {
            };
            List <SelectModel> namelist = new List <SelectModel>();

            int index  = 0;
            int nansum = 0;
            int nsum   = 0;
            int qtsum  = 0;

            foreach (var item in allorg)
            {
                index++;
                List <ArrayList> al = new List <ArrayList>();

                if (dataName.ContainsKey(item.OrganizationID + "1"))
                {
                    ArrayList lld = new ArrayList();
                    lld.Add(dataName[item.OrganizationID + "1"]);
                    lld.Add(dataValue[item.OrganizationID + "1"]);
                    al.Add(lld);
                    nansum += dataValue[item.OrganizationID + "1"];
                }
                if (dataName.ContainsKey(item.OrganizationID + "2"))
                {
                    ArrayList lld = new ArrayList();
                    lld.Add(dataName[item.OrganizationID + "2"]);
                    lld.Add(dataValue[item.OrganizationID + "2"]);
                    al.Add(lld);
                    nsum += dataValue[item.OrganizationID + "2"];
                }
                if (dataName.ContainsKey(item.OrganizationID + "0"))
                {
                    ArrayList lld = new ArrayList();
                    lld.Add(dataName[item.OrganizationID + "0"]);
                    lld.Add(dataValue[item.OrganizationID + "0"]);
                    al.Add(lld);
                    qtsum += dataValue[item.OrganizationID + "0"];
                }
                namelist.Add(new SelectModel()
                {
                    Name = item.OrgName, Value = index
                });

                baseList.Add(al);
            }
            //所有机构的值
            List <ArrayList> alllist = new List <ArrayList>();

            if (nansum != 0)
            {
                ArrayList all1 = new ArrayList();
                all1.Add("男");
                all1.Add(nansum);
                alllist.Add(all1);
            }
            if (nsum != 0)
            {
                ArrayList all1 = new ArrayList();
                all1.Add("女");
                all1.Add(nsum);
                alllist.Add(all1);
            }
            if (qtsum != 0)
            {
                ArrayList all1 = new ArrayList();
                all1.Add("其他");
                all1.Add(qtsum);
                alllist.Add(all1);
            }
            namelist.Add(new SelectModel()
            {
                Name = "所有机构", Value = namelist.Count() + 1
            });
            namelist = namelist.OrderByDescending(a => a.Value).ToList();
            baseList.Add(alllist);

            ChartPieModel m = new ChartPieModel();

            m.MyData      = baseList;
            m.SelectNames = namelist;
            response.Data = m;
            return(response);
        }