示例#1
0
        public static void Set(AreaQuantity areaQuantity)
        {
            var key = new AreaQuantityKeys
            {
                AreaId = areaQuantity.AreaId,
                SexId  = areaQuantity.SexId,
                JobId  = areaQuantity.JobId,
                AgeId  = areaQuantity.AgeId
            };

            if (!Memory.DicAreaQuantity.ContainsKey(areaQuantity.Year))
            {
                Memory.DicAreaQuantity[areaQuantity.Year] = new Dictionary <AreaQuantityKeys, AreaQuantity>();
            }
            Memory.DicAreaQuantity[areaQuantity.Year][key] = areaQuantity;
        }
示例#2
0
        public BsonDocument GetBson(AreaQuantity areaQuantity)
        {
            return(new BsonDocument
            {
                { AreaQuantity.AreaQuantityFields.AreaId.ToString(), areaQuantity.AreaId },

                { AreaQuantity.AreaQuantityFields.AgeId.ToString(), areaQuantity.AgeId },

                { AreaQuantity.AreaQuantityFields.SexId.ToString(), areaQuantity.SexId },

                { AreaQuantity.AreaQuantityFields.JobId.ToString(), areaQuantity.JobId },

                { AreaQuantity.AreaQuantityFields.Year.ToString(), areaQuantity.Year },

                { AreaQuantity.AreaQuantityFields.Quantity.ToString(), areaQuantity.Quantity }
            });
        }
示例#3
0
        public static void Remove(AreaQuantity areaQuantity)
        {
            var key = new AreaQuantityKeys
            {
                AreaId = areaQuantity.AreaId,
                SexId  = areaQuantity.SexId,
                JobId  = areaQuantity.JobId,
                AgeId  = areaQuantity.AgeId
            };

            if (Memory.DicAreaQuantity.ContainsKey(areaQuantity.Year))
            {
                if (Memory.DicAreaQuantity[areaQuantity.Year].ContainsKey(key))
                {
                    Memory.DicAreaQuantity[areaQuantity.Year].Remove(key);
                }
            }
        }
示例#4
0
        public static AreaQuantity CheckExistAreaQuantity(AreaQuantity areaQuantity)
        {
            if (!EntityDic.AreaQuantityDic.ContainsKey(areaQuantity.Year))
            {
                return(null);
            }
            AreaQuantityKeys key = new AreaQuantityKeys
            {
                AreaId = areaQuantity.AreaId,
                AgeId  = areaQuantity.AgeId,
                SexId  = areaQuantity.SexId,
                JobId  = areaQuantity.JobId
            };

            if (EntityDic.AreaQuantityDic[areaQuantity.Year].ContainsKey(key))
            {
                return(EntityDic.AreaQuantityDic[areaQuantity.Year][key].Clone() as AreaQuantity);
            }
            return(null);
        }
示例#5
0
        public static void Init()
        {
            #region Age

            var listAge = SelectDatabase.Select(new Age().EntityName());
            foreach (var item in listAge)
            {
                Age age = new Age
                {
                    AgeId    = item[0].AsObjectId,
                    AgeStart = item[1].AsInt32,
                    AgeEnd   = item[2].AsInt32
                };
                SetMemory.Set(age);
            }

            #endregion

            #region Sex

            var listSex = SelectDatabase.Select(new Sex().EntityName());
            foreach (var item in listSex)
            {
                Sex sex = new Sex
                {
                    SexId   = item[0].AsObjectId,
                    SexName = item[1].AsString
                };
                SetMemory.Set(sex);
            }

            #endregion

            #region Job

            var listJob = SelectDatabase.Select(new Job().EntityName());
            foreach (var item in listJob)
            {
                Job job = new Job
                {
                    JobId   = item[0].AsObjectId,
                    JobName = item[1].AsString
                };
                SetMemory.Set(job);
            }

            #endregion

            #region Area

            var listArea = SelectDatabase.Select(new Area().EntityName());
            foreach (var item in listArea)
            {
                Area area = new Area
                {
                    AreaId   = item[0].AsObjectId,
                    AreaName = item[1].AsString
                };
                SetMemory.Set(area);
            }

            #endregion

            #region AreaQuantity

            var listAreaQuantity = SelectDatabase.Select(new AreaQuantity().EntityName());
            foreach (var item in listAreaQuantity)
            {
                AreaQuantity areaQuantity = new AreaQuantity
                {
                    AreaId   = item[1].AsObjectId,
                    AgeId    = item[2].AsObjectId,
                    SexId    = item[3].AsObjectId,
                    JobId    = item[4].AsObjectId,
                    Year     = item[5].AsInt32,
                    Quantity = item[6].AsInt64
                };
                SetMemory.Set(areaQuantity);
            }

            #endregion

            #region Branch

            var listBranch = SelectDatabase.Select(new Branch().EntityName());
            foreach (var item in listBranch)
            {
                Branch branch = new Branch
                {
                    BranchId   = item[0].AsObjectId,
                    BranchName = item[1].AsString,
                    AreaId     = item[3].AsObjectId
                };
                SetMemory.Set(branch);
            }

            #endregion

            #region BranchQuantity

            var listBranchQuantity = SelectDatabase.Select(new BranchQuantity().EntityName());
            foreach (var item in listBranchQuantity)
            {
                BranchQuantity branchQuantity = new BranchQuantity
                {
                    BranchId = item[1].AsObjectId,
                    AgeId    = item[2].AsObjectId,
                    SexId    = item[3].AsObjectId,
                    JobId    = item[4].AsObjectId,
                    Year     = item[5].AsInt32,
                    Quantity = item[6].AsInt64
                };
                SetMemory.Set(branchQuantity);
            }

            #endregion

            #region Province

            var listProvince = SelectDatabase.Select(new Province().EntityName());
            foreach (var item in listProvince)
            {
                Province province = new Province
                {
                    ProvinceId   = item[0].AsObjectId,
                    ProvinceName = item[1].AsString,
                    BranchId     = item[3].AsObjectId
                };
                SetMemory.Set(province);
            }

            #endregion

            #region ProvinceQuantity

            var listProvinceQuantity = SelectDatabase.Select(new ProvinceQuantity().EntityName());
            foreach (var item in listProvinceQuantity)
            {
                ProvinceQuantity provinceQuantity = new ProvinceQuantity
                {
                    ProvinceId = item[1].AsObjectId,
                    AgeId      = item[2].AsObjectId,
                    SexId      = item[3].AsObjectId,
                    JobId      = item[4].AsObjectId,
                    Year       = item[5].AsInt32,
                    Quantity   = item[6].AsInt64
                };
                SetMemory.Set(provinceQuantity);
            }

            #endregion

            #region District

            var listDistrict = SelectDatabase.Select(new District().EntityName());
            foreach (var item in listDistrict)
            {
                District district = new District
                {
                    DistrictId   = item[0].AsObjectId,
                    DistrictName = item[1].AsString,
                    ProvinceId   = item[3].AsObjectId
                };
                SetMemory.Set(district);
            }

            #endregion

            #region DistrictQuantity

            var listDistrictQuantity = SelectDatabase.Select(new DistrictQuantity().EntityName());
            foreach (var item in listDistrictQuantity)
            {
                DistrictQuantity districtQuantity = new DistrictQuantity
                {
                    DistrictId = item[1].AsObjectId,
                    AgeId      = item[2].AsObjectId,
                    SexId      = item[3].AsObjectId,
                    JobId      = item[4].AsObjectId,
                    Year       = item[5].ToInt32(),
                    Quantity   = item[6].ToInt64()
                };
                SetMemory.Set(districtQuantity);
            }

            #endregion
        }
示例#6
0
        public static void AddAreaQuantity()
        {
            MongoRepository <Area>   areas    = new MongoRepository <Area>();
            MongoRepository <Branch> branches = new MongoRepository <Branch>();

            MongoRepository <Age> ages = new MongoRepository <Age>();
            MongoRepository <Sex> sexs = new MongoRepository <Sex>();
            MongoRepository <Job> jobs = new MongoRepository <Job>();

            List <BranchQuantity> branchQuantities = new MongoRepository <BranchQuantity>().ToList();

            Dictionary <BranchQuantityKeys, BranchQuantity> branchQuantitiesDic = new Dictionary <BranchQuantityKeys, BranchQuantity>();

            foreach (var branchQuantity in branchQuantities)
            {
                var keys = new BranchQuantityKeys
                {
                    BranchId = branchQuantity.BranchId,
                    AgeId    = branchQuantity.AgeId,
                    SexId    = branchQuantity.SexId,
                    JobId    = branchQuantity.JobId
                };
                branchQuantitiesDic[keys] = branchQuantity;
            }

            MongoRepository <AreaQuantity> areaQuantities = new MongoRepository <AreaQuantity>();
            var year = 2016;

            foreach (var area in areas)
            {
                var listBranch = branches.ToList().Where(p => p.AreaId.ToString() == area.Id).ToList();

                foreach (var age in ages)
                {
                    foreach (var sex in sexs)
                    {
                        foreach (var job in jobs)
                        {
                            long total = 0;

                            foreach (var branch in listBranch)
                            {
                                var key = new BranchQuantityKeys
                                {
                                    BranchId = branch.Id,
                                    AgeId    = age.Id,
                                    SexId    = sex.Id,
                                    JobId    = job.Id
                                };
                                if (branchQuantitiesDic.ContainsKey(key))
                                {
                                    total += branchQuantitiesDic[key].Quantity;
                                }
                            }
                            AreaQuantity areaQuantity = new AreaQuantity
                            {
                                AreaId   = area.Id,
                                AgeId    = age.Id,
                                SexId    = sex.Id,
                                JobId    = job.Id,
                                Year     = year,
                                Quantity = total
                            };
                            areaQuantities.Add(areaQuantity);
                        }
                    }
                }
            }
        }
示例#7
0
        public static void UpdateAreaQuantity(List <int> listYear)
        {
            var areas = GetAllArea();
            var ages  = GetAllAge();
            var sexs  = GetAllSex();
            var jobs  = GetAllJob();

            foreach (var year in listYear)
            {
                foreach (var area in areas)
                {
                    var branches = GetBranchesInArea(area.Id);

                    foreach (var age in ages)
                    {
                        foreach (var sex in sexs)
                        {
                            foreach (var job in jobs)
                            {
                                long total = 0;

                                foreach (var branch in branches)
                                {
                                    var key = new BranchQuantityKeys
                                    {
                                        BranchId = branch.Id,
                                        AgeId    = age.Id,
                                        SexId    = sex.Id,
                                        JobId    = job.Id
                                    };
                                    var branchQuantity = GetBranchQuantityByDoubleKey(year, key);
                                    if (branchQuantity != null)
                                    {
                                        total += branchQuantity.Quantity;
                                    }
                                }

                                AreaQuantity areaQuantity = new AreaQuantity
                                {
                                    AreaId   = area.Id,
                                    AgeId    = age.Id,
                                    SexId    = sex.Id,
                                    JobId    = job.Id,
                                    Year     = year,
                                    Quantity = total
                                };
                                var listInsert        = new List <AreaQuantity>();
                                var listUpdate        = new List <AreaQuantity>();
                                var checkAreaQuantity = CheckExistAreaQuantity(areaQuantity);
                                if (checkAreaQuantity == null)
                                {
                                    if (areaQuantity.Quantity > 0)
                                    {
                                        listInsert.Add(areaQuantity);
                                    }
                                }
                                else
                                {
                                    areaQuantity.Id = checkAreaQuantity.Id;
                                    listUpdate.Add(areaQuantity);
                                }

                                if (listInsert.Count > 0)
                                {
                                    InsertAreaQuantity(listInsert);
                                }
                                if (listUpdate.Count > 0)
                                {
                                    UpdateAreaQuantity(listUpdate);
                                }
                            }
                        }
                    }
                }
            }
        }