예제 #1
0
        //Изчисляване на коефициента за разпределение според коефициента
        public CaseSelectionProtokolVM CalculateAllKoef(CaseSelectionProtokolVM caseSelectionProtocol)

        {
            if (caseSelectionProtocol.SelectionModeId != NomenclatureConstants.SelectionMode.SelectByDuty)
            {
                caseSelectionProtocol.CourtDutyId = null;
            }

            CourtLoadPeriod courtLoadPeriod = GetLoadPeriod(caseSelectionProtocol.CourtGroupId, caseSelectionProtocol.CourtDutyId);
            int             totalPeriodDays = repo.AllReadonly <CourtLoadPeriodLawUnit>()
                                              .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id)
                                              .Where(x => (x.LawUnitId ?? 0) == 0)
                                              .Count();



            decimal totalKoef = 0;

            // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId)))
            foreach (var lawUnit in caseSelectionProtocol.LawUnits)
            {
                CalculateLawUnitDataInGroup(lawUnit, courtLoadPeriod.Id);
                totalKoef = totalKoef + lawUnit.Koef;
            }
            // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId)))
            foreach (var lawUnit in caseSelectionProtocol.LawUnits)
            {
                lawUnit.KoefNormalized = lawUnit.Koef / totalKoef * 100M;

                ////Когато нормализираният коефициент е прекалено малък го приравняваме на 1 за да има поне 1 участие  като вероятност
                //if ((lawUnit.KoefNormalized > 0) && (lawUnit.KoefNormalized < 1))
                //{ lawUnit.KoefNormalized = 1; }

                int lawUnitPeriodDays = repo.AllReadonly <CourtLoadPeriodLawUnit>()
                                        .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id)
                                        .Where(x => x.LawUnitId == lawUnit.LawUnitId)
                                        .Count();
                lawUnit.CasesCountIfWorkAllPeriodInGroup = (decimal)totalPeriodDays / (decimal)lawUnitPeriodDays * 100M / (decimal)lawUnit.LoadIndex * lawUnit.CaseCount;
                lawUnit.ExcludeByBigDeviation            = false;
            }

            return(caseSelectionProtocol);
        }
예제 #2
0
        //Преизчислява редовете с дневни брой дела за група /дежурство по избран съдия
        public void UpdateDailyLoadPeriod_RemoveByDismisal(int case_lawunit_id)

        {
            var case_law_unit = repo.GetById <CaseLawUnit>(case_lawunit_id);



            CourtLoadPeriod courtLoadPeriod = GetLoadPeriod(case_law_unit.CourtGroupId, case_law_unit.CourtDutyId);

            Expression <Func <CourtLoadPeriodLawUnit, bool> > courtLoadPeriodRowsLawunitsSelect = x => true;

            if ((courtLoadPeriod.CourtDutyId ?? 0) < 1)
            {
                //Ако е група
                courtLoadPeriodRowsLawunitsSelect = x => (x.CourtLoadPeriodId == courtLoadPeriod.Id) && (x.SelectionDate.Date == case_law_unit.DateFrom.Date);
            }
            else
            {
                //Ако е по дежурство
                courtLoadPeriodRowsLawunitsSelect = x => (x.CourtLoadPeriodId == courtLoadPeriod.Id);
            }


            var courtLoadPeriodLawUnits = repo.All <CourtLoadPeriodLawUnit>().Where(courtLoadPeriodRowsLawunitsSelect);

            decimal totalAverage = 0;

            //Изчислява сумарния дневен ред
            foreach (var courtLoadPeriodLawUnit in courtLoadPeriodLawUnits)
            {
                if (courtLoadPeriodLawUnit.LawUnitId == null)
                {
                    courtLoadPeriodLawUnit.DayCases      = courtLoadPeriodLawUnit.DayCases - 1;
                    courtLoadPeriodLawUnit.TotalDayCases = courtLoadPeriodLawUnit.TotalDayCases - 1;
                    courtLoadPeriodLawUnit.AverageCases  = courtLoadPeriodLawUnit.DayCases / (courtLoadPeriodLawUnits.Count() - 1);
                    totalAverage = courtLoadPeriodLawUnit.AverageCases;
                }
            }



            foreach (var lawUnit in courtLoadPeriodLawUnits)
            {
                if (lawUnit.LawUnitId != null)
                {
                    //Ако не е наличен променя само среднодневните бройки
                    if (lawUnit.IsAvailable == false)
                    {
                        lawUnit.AverageCases  = totalAverage;
                        lawUnit.TotalDayCases = totalAverage;
                    }

                    //Ако е избран намалява дневната му ставка
                    if (lawUnit.LawUnitId == case_law_unit.LawUnitId)
                    {
                        lawUnit.DayCases      = lawUnit.DayCases - 1;
                        lawUnit.TotalDayCases = lawUnit.TotalDayCases - 1;
                    }
                }
            }
            repo.SaveChanges();
        }
예제 #3
0
        //Преизчислява редовете с дневни брой дела за група /дежурство по избран съдия
        public void UpdateDailyLoadPeriod(int?CourtGroupId, int?CourtDutyId, int selectedLawUnit)

        {
            CourtLoadPeriod courtLoadPeriod = GetLoadPeriod(CourtGroupId, CourtDutyId);

            Expression <Func <CourtLoadPeriodLawUnit, bool> > courtLoadPeriodRowsLawunitsSelect = x => true;

            if (CourtDutyId == null)
            {
                //Ако е група
                courtLoadPeriodRowsLawunitsSelect = x => (x.CourtLoadPeriodId == courtLoadPeriod.Id) && (x.SelectionDate.Date == DateTime.Now.Date);
            }
            else
            {
                //Ако е по дежурство
                courtLoadPeriodRowsLawunitsSelect = x => (x.CourtLoadPeriodId == courtLoadPeriod.Id);
            }


            var courtLoadPeriodLawUnits = repo.All <CourtLoadPeriodLawUnit>().Where(courtLoadPeriodRowsLawunitsSelect);

            decimal totalAverage = 0;

            //Изчислява сумарния дневен ред
            foreach (var courtLoadPeriodLawUnit in courtLoadPeriodLawUnits)
            {
                if (courtLoadPeriodLawUnit.LawUnitId == null)
                {
                    courtLoadPeriodLawUnit.TotalDayCases = courtLoadPeriodLawUnit.TotalDayCases + 1;
                    courtLoadPeriodLawUnit.DayCases      = courtLoadPeriodLawUnit.DayCases + 1;
                    courtLoadPeriodLawUnit.AverageCases  = courtLoadPeriodLawUnit.TotalDayCases / (courtLoadPeriodLawUnits.Count() - 1);
                    totalAverage = courtLoadPeriodLawUnit.AverageCases;
                }
            }



            foreach (var lawUnit in courtLoadPeriodLawUnits)
            {
                if (lawUnit.LawUnitId != null)
                {
                    //Ако не е наличен променя само среднодневните бройки
                    if (lawUnit.IsAvailable == false)
                    {
                        lawUnit.AverageCases  = totalAverage;
                        lawUnit.TotalDayCases = totalAverage;
                    }

                    //Ако е избран увеличава  дневната му ставка
                    if (lawUnit.LawUnitId == selectedLawUnit)
                    {
                        lawUnit.DayCases      = lawUnit.DayCases + 1;
                        lawUnit.TotalDayCases = lawUnit.TotalDayCases + 1;
                    }

                    //foreach (var item in caseSelectionProtocol.LawUnits)
                    //{
                    //  if (item.LawUnitId==lawUnit.LawUnitId)
                    //  {
                    //    item.TotalCaseCount = lawUnit.TotalDayCases;

                    //  }
                    //}
                }
            }
            repo.SaveChanges();
        }
예제 #4
0
        ////Създаване на период за група или дежурство
        //public bool MakeLoadPeriod(int? courtGroupid, int? courtDutyId)
        //{
        //    bool res = true;

        //    Expression<Func<CourtLoadPeriod, bool>> courtGroupDutySearch = x => true;
        //    if (courtGroupid != null)
        //    {

        //        courtGroupDutySearch = x => x.CourtGroupId == courtGroupid;
        //    }
        //    if (courtDutyId != null)
        //    {

        //        courtGroupDutySearch = x => x.CourtDutyId == courtDutyId;
        //    }



        //    CourtLoadPeriod courtLoadPeriod = repo.AllReadonly<CourtLoadPeriod>()
        //                                          .Where(courtGroupDutySearch)
        //                                          .FirstOrDefault();
        //    if (courtLoadPeriod == null)
        //    {

        //        try
        //        {
        //            courtLoadPeriod = new CourtLoadPeriod();
        //            if (courtGroupid != null)
        //            { courtLoadPeriod.CourtGroupId = courtGroupid; }
        //            if (courtDutyId != null)
        //            { courtLoadPeriod.CourtDutyId = courtDutyId; }
        //            courtLoadPeriod.DateFrom = DateTime.Now;
        //            repo.Add<CourtLoadPeriod>(courtLoadPeriod);
        //            repo.SaveChanges();


        //        }
        //        catch (Exception ex)
        //        {
        //            res = false;
        //            if (courtGroupid != null)
        //            {
        //                logger.LogError(ex, $"Грешка при запис на период за група  courtGroupId ={ courtGroupid}");
        //            }
        //            else
        //            { logger.LogError(ex, $"Грешка при запис на период за група  courtDutyId ={ courtDutyId}"); }
        //        }
        //    }

        //    return res;
        //}


        //Вземане  на период за група или дежурство
        public CourtLoadPeriod GetLoadPeriod(int?courtGroupid, int?courtDutyId)
        {
            Expression <Func <CourtLoadPeriod, bool> > courtGroupDutySearch = x => true;

            if (courtGroupid != null)
            {
                courtGroupDutySearch = x => x.CourtGroupId == courtGroupid && ((x.CourtDutyId ?? 0) < 1);
            }
            if (courtDutyId != null)
            {
                courtGroupDutySearch = x => x.CourtDutyId == courtDutyId;
            }



            CourtLoadPeriod courtLoadPeriod = repo.AllReadonly <CourtLoadPeriod>()
                                              .Include(x => x.CourtLoadResetPeriod)
                                              .Where(x => x.CourtLoadResetPeriod.DateFrom <= DateTime.Now)
                                              .Where(x => (x.CourtLoadResetPeriod.DateTo ?? DateTime.Now) >= DateTime.Now)
                                              .Where(courtGroupDutySearch).FirstOrDefault();


            if (courtLoadPeriod == null)
            {
                try
                {
                    var resetPeriodId = repo.AllReadonly <CourtLoadResetPeriod>()
                                        .Where(x => x.CourtId == userContext.CourtId)
                                        .Where(x => x.DateFrom <= DateTime.Now)
                                        .Where(x => (x.DateTo ?? DateTime.Now) >= DateTime.Now)
                                        .Select(x => x.Id)
                                        .FirstOrDefault();

                    if (resetPeriodId == 0)
                    {
                        throw new Exception($"Няма зададен период за разпределение за съд {userContext.CourtName}");
                    }

                    courtLoadPeriod = new CourtLoadPeriod();
                    if (courtGroupid != null)
                    {
                        courtLoadPeriod.CourtGroupId = courtGroupid;
                    }
                    if (courtDutyId != null)
                    {
                        courtLoadPeriod.CourtDutyId = courtDutyId;
                    }
                    courtLoadPeriod.CourtLoadResetPeriodId = resetPeriodId;
                    courtLoadPeriod.DateFrom = DateTime.Now;
                    repo.Add <CourtLoadPeriod>(courtLoadPeriod);
                    repo.SaveChanges();
                }
                catch (Exception ex)
                {
                    if (courtGroupid != null)
                    {
                        logger.LogError(ex, $"Грешка при запис на период за група  courtGroupId ={ courtGroupid}");
                    }
                    else
                    {
                        logger.LogError(ex, $"Грешка при запис на период за група  courtDutyId ={ courtDutyId}");
                    }
                }
            }

            return(courtLoadPeriod);
        }
        //Изчисляване на коефициента за разпределение според коефициента
        public CaseSelectionProtokolVM CalculateAllKoef(CaseSelectionProtokolVM caseSelectionProtocol)

        {
            if (caseSelectionProtocol.SelectionModeId != NomenclatureConstants.SelectionMode.SelectByDuty)
            {
                caseSelectionProtocol.CourtDutyId = null;
            }

            CourtLoadPeriod courtLoadPeriod = GetLoadPeriod(caseSelectionProtocol.CourtGroupId, caseSelectionProtocol.CourtDutyId);

            //Optimisacia2020.01.09 s
            //int totalPeriodDays = repo.AllReadonly<CourtLoadPeriodLawUnit>()
            //                        .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id)
            //                        .Where(x => (x.LawUnitId ?? 0) == 0)
            //                        .Count();
            //Optimisacia2020.01.09 e


            decimal totalKoef = 0;
            //2020.01.08 Optimisation
            List <int> LawUnitsArray = caseSelectionProtocol.LawUnits.Select(x => x.LawUnitId).ToList();

            LawUnitsArray.Add(0);

            // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId)))
            var courtLoadPeriodLawunitsList = repo.AllReadonly <CourtLoadPeriodLawUnit>().Where(x => LawUnitsArray.Contains(x.LawUnitId ?? 0))
                                              .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id).ToList();
            //Optimisacia2020.01.09 s
            int totalPeriodDays = courtLoadPeriodLawunitsList
                                  .Where(x => (x.LawUnitId ?? 0) == 0)
                                  .Count();

            //Optimisacia2020.01.09 e

            foreach (var lawUnit in caseSelectionProtocol.LawUnits)
            {
                // CalculateLawUnitDataInGroup(lawUnit, courtLoadPeriod.Id);
                CalculateLawUnitDataInGroup(lawUnit, courtLoadPeriod.Id, courtLoadPeriodLawunitsList);
                //2020.01.08 Optimisation
                totalKoef = totalKoef + lawUnit.Koef;
            }
            // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId)))
            foreach (var lawUnit in caseSelectionProtocol.LawUnits)
            {
                lawUnit.KoefNormalized = lawUnit.Koef / totalKoef * 100M;

                ////Когато нормализираният коефициент е прекалено малък го приравняваме на 1 за да има поне 1 участие  като вероятност
                //if ((lawUnit.KoefNormalized > 0) && (lawUnit.KoefNormalized < 1))
                //{ lawUnit.KoefNormalized = 1; }
                //2020.01.08 Optimisation 1
                //int lawUnitPeriodDays = repo.AllReadonly<CourtLoadPeriodLawUnit>()
                //                      .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id)
                //                      .Where(x => x.LawUnitId == lawUnit.LawUnitId)
                //                      .Where(x => x.AverageCases == 0)
                //                      .Count();
                int lawUnitPeriodDays = courtLoadPeriodLawunitsList
                                        .Where(x => x.LawUnitId == lawUnit.LawUnitId)
                                        .Where(x => x.AverageCases == 0)
                                        .Count();
                //2020.01.08 Optimisation 1
                if (lawUnitPeriodDays == 0)
                {
                    lawUnitPeriodDays = 1;
                }
                if (lawUnit.LoadIndex == 0)
                {
                    lawUnit.LoadIndex = 100;
                }
                lawUnit.CasesCountIfWorkAllPeriodInGroup = (decimal)totalPeriodDays / (decimal)lawUnitPeriodDays * 100M / (decimal)lawUnit.LoadIndex * lawUnit.CaseCount;
                lawUnit.ExcludeByBigDeviation            = false;
            }

            return(caseSelectionProtocol);
        }