コード例 #1
0
ファイル: CalculationService.cs プロジェクト: mehabadi/HPMS
        public void DeleteCalculation(CalculationId calculationId)
        {
            try
            {
                using (var tr = new TransactionScope())
                {
                    var calculation = calculationRep.GetById(calculationId);
                    if (calculation.IsDeterministic)
                    {
                        throw new CalculationException((int)ApiExceptionCode.CouldNotDeleteDeterministicCalculation, ApiExceptionCode.CouldNotDeleteDeterministicCalculation.DisplayName);
                    }
                    if (calculation.State == CalculationState.Running)
                    {
                        throw new CalculationInvalidStateOperationException(typeof(Calculation).Name, CalculationState.Running.DisplayName, System.Reflection.MethodBase.GetCurrentMethod().Name);
                    }

                    calculationRep.Delete(calculation);
                    tr.Complete();
                }
            }
            catch (Exception exp)
            {
                var res = calculationRep.TryConvertException(exp);
                if (res == null)
                {
                    throw;
                }
                throw res;
            }
        }
コード例 #2
0
        public EmployeePointData GetPoints(Employee emp, CalculationId calcId)
        {
            var q  = session.Query <SummaryEmployeePoint>().Where(j => j.EmployeeId == emp.Id && j.CalculationId == calcId).ToFuture();
            var q3 = session.Query <SummaryJobPositionPoint>().Where(j => j.EmployeeId == emp.Id && j.CalculationId == calcId);
            var q4 = q3.ToFuture();
            var q2 = (from j in session.Query <JobPosition>()
                      join i in session.Query <SummaryJobPositionPoint>()
                      on j.Id equals i.JobPositionId
                      where i.EmployeeId == emp.Id && i.CalculationId == calcId
                      select j);
            var q5 = q2.Fetch(j => j.SharedJobPosition).ToFuture();

            var q7 = session.Query <JobIndexPoint>().Where(j => j.EmployeeId == emp.Id && j.CalculationId == calcId);
            var q8 = q7.ToFuture();
            var q9 = (from j in session.Query <JobIndex>()
                      join i in session.Query <JobIndexPoint>()
                      on j.Id equals i.JobIndexId
                      where i.EmployeeId == emp.Id && i.CalculationId == calcId
                      select j).Fetch(j => j.SharedJobIndex).ToFuture();

            var res = new Dictionary <JobPosition, JobPositionPointData>();

            return(new EmployeePointData
            {
                SummaryEmployeePoints = q.ToList(),
                SummaryJobPositionPoints = q5.ToDictionary(i => i, i =>
                                                           new JobPositionPointData
                {
                    SummaryJobPositionPoints = q4.ToList().Where(j => j.JobPositionId.Equals(i.Id)).ToList(),
                    JobIndexPoints = q9.ToDictionary(j => j, j => q8.Where(k => k.JobIndexId.Equals(j.Id)).ToList())
                })
            });
        }
コード例 #3
0
        public Calculation GetById(CalculationId id)
        {
            var calculation = Single(c => c.Id == id);

            calculationConfigurator.Config(calculation);
            return(calculation);
        }
コード例 #4
0
        public EmployeeCalculationException(EmployeeCalculationExceptionId employeeCalculationExceptionId, Calculation calculation, EmployeeId employeeId, int calculationPathNo, string message)
        {
            if (employeeCalculationExceptionId == null)
            {
                throw new ArgumentNullException("employeeCalculationExceptionId");
            }
            this.id = employeeCalculationExceptionId;
            if (calculation == null)
            {
                throw new ArgumentNullException("calculation");
            }
            if (employeeId == null)
            {
                throw new ArgumentNullException("employeeId");
            }

            this.employeeId        = employeeId;
            this.calculationId     = calculation.Id;
            this.calculationPathNo = calculationPathNo;
            if (message.Length > 1024)
            {
                this.message = message.Substring(0, 1023);
            }
            else
            {
                this.message = message;
            }
        }
コード例 #5
0
        public decimal GetEmployeeFinalPointBy(PeriodId periodId, string employeeNo, CalculationId calculationId)
        {
            var employeePoint =
                repEmp.Find(e => e.PeriodId == periodId && e.CalculationId == calculationId && e.IsFinal && e.EmployeeId.EmployeeNo == employeeNo)
                .SingleOrDefault();

            return(employeePoint == null ? 0 : employeePoint.Value);
        }
コード例 #6
0
        public EmployeePoint GetFinalUnitPoint(CalculationId calculationId, EmployeeId employeeId)
        {
            var res =
                repEmp.Find(e => e.CalculationId == calculationId && e.EmployeeId == employeeId && e.Name == "finalunitPoint")
                .SingleOrDefault();

            return(res);
        }
コード例 #7
0
ファイル: CalculatorEngine.cs プロジェクト: mehabadi/HPMS
 public void UpdateCompileResult(CalculationId id, string libraryText, Dictionary <string, Core.RuleEngine.Model.RuleBase> rules)
 {
     using (var transaction = new TransactionScope())
     {
         var calc = calcRep.GetById(id);
         calc.UpdateCompileResult(libraryText, rules);
         transaction.Complete();
     }
 }
コード例 #8
0
        public List <JobIndexPoint> GetBy(CalculationId calculationId, EmployeeId employeeId)
        {
            var res =
                repJobIndex.Find(
                    e => e.CalculationId == calculationId && e.EmployeeId == employeeId)
                .ToList();

            return(res);
        }
コード例 #9
0
ファイル: CalculationService.cs プロジェクト: mehabadi/HPMS
 public void ChangeDeterministicStatus(CalculationId calculationId, bool isDeterministic)
 {
     using (var scope = new TransactionScope())
     {
         var calculation = calculationRep.GetById(calculationId);
         var period      = periodRep.GetById(calculation.PeriodId);
         calculation.ChangeDeterministicStatus(isDeterministic, calculationRep, period);
         scope.Complete();
     }
 }
コード例 #10
0
ファイル: CalculationService.cs プロジェクト: mehabadi/HPMS
        public void RunCalculation(CalculationId calculationId)
        {
            var calculator = calculatorProvider.GetCalculator(calculationId);

            using (var tr = new TransactionScope())
            {
                var calculation = calculationRep.GetById(calculationId);
                calculation.Run(calculator);
                tr.Complete();
            }
        }
コード例 #11
0
ファイル: CalculationService.cs プロジェクト: mehabadi/HPMS
        public Calculation GetCalculation(CalculationId calculationId)
        {
            Calculation calculation;

            using (var tr = new TransactionScope())
            {
                calculation = calculationRep.GetById(calculationId);
                tr.Complete();
            }
            return(calculation);
        }
コード例 #12
0
ファイル: CalculatorEngine.cs プロジェクト: mehabadi/HPMS
 public void AddCalculationException(CalculationId calculationId, EmployeeId employeeId, int calculationPathNo, string messages)
 {
     using (var transaction = new TransactionScope())
     {
         var clac       = calcRep.GetById(calculationId);
         var empCalcExp = new EmployeeCalculationException(calcExpRep.GetNextId(), clac, employeeId,
                                                           calculationPathNo, messages);
         calcExpRep.Add(empCalcExp);
         transaction.Complete();
     }
 }
コード例 #13
0
ファイル: CalculationService.cs プロジェクト: mehabadi/HPMS
        public CalculationStateReport GetCalculationState(CalculationId calculationId)
        {
            var         calculator = calculatorProvider.GetCalculator(calculationId);
            Calculation calculation;

            using (var tr = new TransactionScope())
            {
                calculation = calculationRep.GetById(calculationId);
                tr.Complete();
            }
            if (calculation.State == CalculationState.Running)
            {
                return(new CalculationStateReport(calculation, calculator.Progress, calculator.Messages));
            }
            else
            {
                return(new CalculationStateReport(calculation, null, null));
            }
        }
コード例 #14
0
        public Dictionary <int, IList <Employee> > FindRemainingEmployeesOfCalculation(List <string> enList, PeriodId periodId, CalculationId calculationId, int pathNo)
        {
            int firstLevel = 1;
            var res        = new Dictionary <int, IList <EmployeeId> >();


            var employeeJobs = (from jo in session.Query <Job>()
                                join i in session.Query <JobPositionEmployee>()
                                on jo.Id equals i.JobPosition.JobId
                                where enList.Contains(i.EmployeeId.EmployeeNo) && i.EmployeeId.PeriodId == periodId
                                select new { jo, i.EmployeeId }); //.Distinct();


            IEnumerable <EmployeeId> empCompletedInFirstLevel = new List <EmployeeId>();

            //if (firstLevel > 0)
            if (calculationId != null)
            {
                var calculation = session.Query <Calculation>().Where(c => c.Id == calculationId).SingleOrDefault();
                if (calculation.CalculationResult.LastCalculatedPath.HasValue)
                {
                    firstLevel = calculation.CalculationResult.LastCalculatedPath.Value;
                }
                //Get Completed Employee in this calc path , and finaly Remove from firstLevel
                empCompletedInFirstLevel =
                    session.Query <EmployeePoint>().Where(ep => ep.CalculationId == calculationId
                                                          //&& ep.CalculatePathNo == firstLevel
                                                          ).Select(ep => ep.EmployeeId).ToFuture();
            }
            //todo :(LOW) query for data
            var dummy = employeeJobs.Select(empJob => empJob.jo).Fetch(j => j.JobIndexList).ToFuture();
            var employeeJobindexes = session.Query <Domain.Model.JobIndices.JobIndex>()
                                     .Where(j => employeeJobs.Select(empJob => empJob.jo)
                                            .SelectMany(jo => jo.JobIndexList)
                                            .Select(ji => ji.JobIndexId.Id)
                                            .Contains(j.Id.Id)).ToFuture();

            var jobIndexLevels = employeeJobindexes.Where(ji => ji.CalculationLevel >= firstLevel)
                                 .Select(ji => ji.CalculationLevel).Distinct().ToList();

            //var empJobInexIdsLevel1 = employeeJobindexes.Where(ji=>jei.CalculationLevel ==1).Select(ji => ji.Id).ToList();
            //var empLevel1 = employeeJobs.Where(empj => empj.jo.JobIndexList.Any(i => empJobInexIdsLevel1.Contains(i))).Select(empj => empj.EmployeeId).ToList();

            for (int level = firstLevel; level <= jobIndexLevels.Max(); level++)
            {
                //uncomment this if you want to get employee with its job index level
                //var empJobInexIdsLevel = employeeJobindexes.Where(ji => ji.CalculationLevel == level).Select(ji => ji.Id).ToList();
                var empJobInexIdsLevel = employeeJobindexes.Select(ji => ji.Id).ToList();
                var empLevel           = employeeJobs.Where(empj => empj.jo.JobIndexList.Select(j => j.JobIndexId).Any(i => empJobInexIdsLevel.Contains(i)))
                                         .Select(empj => empj.EmployeeId).ToList();
                if (level == 1)
                {
                    empLevel.AddRange(employeeJobs.Where(empj => !empj.jo.JobIndexList.Any())
                                      .Select(empj => empj.EmployeeId).ToList());
                }



                //if (level == firstLevel)
                //    empLevel = empLevel.Where(emp => !empCompletedInFirstLevel.Contains(emp)).ToList();

                res.Add(level, empLevel);
            }

            return(res.ToDictionary(i => i.Key, i => FindInList(i.Value.Select(x => x.EmployeeNo).ToList(), periodId)));
        }
コード例 #15
0
 public List <SummaryCalculationPoint> GetCalculationPointBy(CalculationId calcId)
 {
     return(rep.Find <SummaryCalculationPoint>(s => s.CalculationId == calcId).ToList());
 }
コード例 #16
0
        public List <JobIndexPoint> GetJobIndexPointByLimitPoint(CalculationId calculationId, decimal limitPoint)
        {
            var res = repJobIndex.Find(j => j.CalculationId == calculationId && j.Value <= limitPoint).ToList();

            return(res);
        }
コード例 #17
0
ファイル: EmployeeTest.cs プロジェクト: mehabadi/HPMS
        public void EmployeesInJobIndexLevelTest()
        {
            int firstLevel    = 1;
            var periodId      = new PeriodId(10);
            var enList        = new string[] { "2000", "4000", "8000", "12000", "16000" };
            var res           = new Dictionary <int, IList <EmployeeId> >();
            var calculationId = new CalculationId(10);

            using (var session = PMSSession.GetSession())
                using (session.BeginTransaction())
                {
                    var calculationExpRep = new CalculationExceptionRepository(new NHUnitOfWork(session));

                    var employeeJobs = (from jo in session.Query <Job>()
                                        join i in session.Query <JobPositionEmployee>()
                                        on jo.Id equals i.JobPosition.JobId
                                        where enList.Contains(i.EmployeeId.EmployeeNo) && i.EmployeeId.PeriodId == periodId
                                        select new { jo, i.EmployeeId });//.Distinct();


                    IEnumerable <EmployeeId> empCompletedInFirstLevel = new List <EmployeeId>();
                    Calculation calculation = null;
                    if (calculationId != null)
                    {
                        calculation = session.Query <Calculation>().Where(c => c.Id == calculationId).SingleOrDefault();
                        if (calculation.CalculationResult != null && calculation.CalculationResult.LastCalculatedPath.HasValue)
                        {
                            firstLevel = calculation.CalculationResult.LastCalculatedPath.Value;
                        }
                    }

                    var dummy = employeeJobs.Select(empJob => empJob.jo).Fetch(j => j.JobIndexList).ToFuture();
                    var employeeJobindexes = session.Query <Domain.Model.JobIndices.JobIndex>()
                                             .Where(j => employeeJobs.Select(empJob => empJob.jo).SelectMany(jo => jo.JobIndexList).Select(ji => ji.JobIndexId.Id).Contains(j.Id.Id))
                                             .ToFuture();

                    var jobIndexLevels = employeeJobindexes.Where(ji => ji.CalculationLevel >= firstLevel).Select(ji => ji.CalculationLevel).Distinct().ToList();

                    //var empJobInexIdsLevel1 = employeeJobindexes.Where(ji=>jei.CalculationLevel ==1).Select(ji => ji.Id).ToList();
                    //var empLevel1 = employeeJobs.Where(empj => empj.jo.JobIndexList.Any(i => empJobInexIdsLevel1.Contains(i))).Select(empj => empj.EmployeeId).ToList();


                    for (int level = firstLevel; level <= jobIndexLevels.Max(); level++)
                    {
                        var empJobInexIdsLevel = employeeJobindexes.Where(ji => ji.CalculationLevel == level).Select(ji => ji.Id).ToList();
                        var empLevel           = employeeJobs.Where(empj => empj.jo.JobIndexList.Select(j => j.JobIndexId).Any(i => empJobInexIdsLevel.Contains(i)))
                                                 .Select(empj => empj.EmployeeId).OrderBy(emp => emp.EmployeeNo).ToList();

                        if (level == firstLevel)
                        {
                            if (calculation.CalculationResult != null && calculation.CalculationResult.LastCalculatedEmployeeId != null)
                            {
                                var enNotCompletedInFirstLevel = enList.Skip(
                                    enList.ToList().FindLastIndex(s => s == calculation.CalculationResult.LastCalculatedEmployeeId.EmployeeNo) + 1);


                                //var expEmployeeIds = calculation.EmployeeCalculationExceptions.Select(exp => exp.EmployeeId).ToList();
                                var expEmployeeIds = calculationExpRep.GetAllBy(calculationId).Select(exp => exp.EmployeeId).ToList();
                                enNotCompletedInFirstLevel = enNotCompletedInFirstLevel.Union(expEmployeeIds.Select(exp => exp.EmployeeNo));
                                empLevel = empLevel.Where(emp => enNotCompletedInFirstLevel.Contains(emp.EmployeeNo)).ToList();
                            }
                        }
                        res.Add(level, empLevel);
                    }
                }
        }
コード例 #18
0
 public Calculation GetById(CalculationId calculationId)
 {
     return(rep.FindByKey(calculationId));
 }
コード例 #19
0
 public IList <EmployeeCalculationException> FindBy(CalculationId calculationId, ListFetchStrategy <EmployeeCalculationException> fs)
 {
     return(rep.Find(c => c.CalculationId == calculationId, fs));
 }
コード例 #20
0
 public void DeleteAll(CalculationId calculationId)
 {
     session.CreateSQLQuery("DELETE FROM Calculations_Exceptions WHERE CalculationId = :id")
     .SetParameter("id", calculationId.Id)
     .ExecuteUpdate();
 }
コード例 #21
0
 public IList <EmployeeCalculationException> GetAllBy(CalculationId calculationId)
 {
     return(rep.Find(c => c.CalculationId == calculationId));
 }
コード例 #22
0
ファイル: CalculatorEngine.cs プロジェクト: mehabadi/HPMS
 public List <SummaryCalculationPoint> GetCalculationPiontBy(CalculationId calcId)
 {
     return(jipRep.GetCalculationPointBy(calcId));
 }
コード例 #23
0
        public CalculationData ProvideDataForRule(Employee employee, CalculationId calculationId, bool withCalculationPoints = false)
        {
            #region Query
            // employee job customFieldValue
            var employeeJobpositionCustomFieldsWithValue = session.Query <EmployeeJobPosition>().Where(j => j.Employee == employee)
                                                           .FetchMany(j => j.EmployeeJobCustomFieldValues).ToFuture();

            var employeeWithCustomFieldsWithValue = session.Query <Employee>().Where(e => e == employee).FetchMany(e => e.CustomFieldValues).ToFuture();

            var employeeJobPositionsWithUnitAndSharedData = (from jobPositionEmployee in session.Query <JobPositionEmployee>().Where(j => j.EmployeeId == employee.Id)
                                                             join unit in session.Query <Unit>() on jobPositionEmployee.JobPosition.UnitId equals unit.Id
                                                             select new { JobPositionEmployee = jobPositionEmployee, Unit = unit })
                                                            .ToFuture();

            // employee Job and JobPosition
            var employeeJobs = (from job in session.Query <Job>()
                                join jobPositionEmployee in session.Query <JobPositionEmployee>()
                                on job.Id equals jobPositionEmployee.JobPosition.JobId
                                where jobPositionEmployee.EmployeeId == employee.Id
                                select job);
            var dummy1 = employeeJobs.Fetch(j => j.JobIndexList).ToFuture();
            var employeeJobsWithSharedJob = employeeJobs.Fetch(j => j.SharedJob).ToFuture();

            var employeeJobIndexesWithSharedData = session.Query <JobIndex>()
                                                   .Where(j => employeeJobs.SelectMany(jo => jo.JobIndexList).Select(ji => ji.JobIndexId.Id).Contains(j.Id.Id)).OrderBy(i => i.CalculationOrder)
                                                   .Fetch(j => j.SharedJobIndex).ToFuture();

            var jobIndexInquiryPoints = (from inquiryJobIndexPoint in session.Query <InquiryJobIndexPoint>().Where(i => i.ConfigurationItemId.InquirySubjectId == employee.Id)
                                         join emp in session.Query <Employee>() on inquiryJobIndexPoint.ConfigurationItemId.InquirerId equals emp.Id
                                         join jobPositionEmployee in session.Query <JobPositionEmployee>() on inquiryJobIndexPoint.ConfigurationItemId.InquirerJobPositionId equals jobPositionEmployee.JobPosition.Id
                                         select new { inquiryJobIndexPoint = inquiryJobIndexPoint, emp = emp, jobPositionEmployee.JobPosition.SharedJobPosition, inquiryJobIndexPoint.ConfigurationItemId.InquirySubjectJobPositionId.SharedJobPositionId, }
                                         ).ToFuture();

            // employee Unit and JobPosition
            var employeeUnits = (from unit in session.Query <Unit>()
                                 join jobPositionEmployee in session.Query <JobPositionEmployee>()
                                 on unit.Id equals jobPositionEmployee.JobPosition.UnitId
                                 where jobPositionEmployee.EmployeeId == employee.Id
                                 select unit);
            var dummy2 = employeeUnits.Fetch(j => j.UnitIndexList).ToFuture();
            //var employeeUnitsWithSharedUnit = employeeUnits.Fetch(j => j.SharedUnit).ToFuture();

            var employeeUnitIndexesWithSharedData = session.Query <UnitIndex>()
                                                    .Where(j => employeeUnits.SelectMany(jo => jo.UnitIndexList).Select(ji => ji.UnitIndexId.Id).Contains(j.Id.Id)).OrderBy(i => i.CalculationOrder)
                                                    .Fetch(j => j.SharedUnitIndex).ToFuture();

            var unitIdList             = employeeUnits.Select(eu => eu.Id.SharedUnitId.Id);
            var unitIndexInquiryPoints = (from inquiryUnitIndexPoint in session.Query <InquiryUnitIndexPoint>().Where(i => unitIdList.Contains(i.ConfigurationItemId.InquirySubjectUnitId.SharedUnitId.Id))
                                          join emp in session.Query <Employee>() on inquiryUnitIndexPoint.ConfigurationItemId.InquirerId equals emp.Id
                                          select new { inquiryUnitIndexPoint = inquiryUnitIndexPoint, emp = emp }
                                          ).ToFuture();


            var allPoints = new List <CalculationPoint>();

            if (withCalculationPoints)
            {
                var empJobIndexPoints = session.Query <EmployeePoint>().Where(ep => ep.EmployeeId == employee.Id && ep.CalculationId == calculationId).ToList();//.ToFuture();
                allPoints.AddRange(empJobIndexPoints);
            }

            employeeWithCustomFieldsWithValue.ToList();

            #endregion

            var employeeData = from job in employeeJobsWithSharedJob.ToList()
                               join employeeJobPositionWithUnit in employeeJobPositionsWithUnitAndSharedData.ToList()
                               on job.Id equals employeeJobPositionWithUnit.JobPositionEmployee.JobPosition.JobId
                               join c in employeeJobpositionCustomFieldsWithValue.ToList()
                               on employeeJobPositionWithUnit.JobPositionEmployee.JobPosition.Id equals c.JobPositionId
                               select new
            {
                JobPosition   = employeeJobPositionWithUnit.JobPositionEmployee.JobPosition,
                Unit          = employeeJobPositionWithUnit.Unit,
                UnitIndexList =
                    employeeUnitIndexesWithSharedData.ToList()
                    .Where(
                        ji =>
                        employeeJobPositionWithUnit.Unit.UnitIndexList.Select(x => x.UnitIndexId)
                        .Contains(ji.Id))
                    .ToList(),
                Job          = job,
                jobIndexList =
                    employeeJobIndexesWithSharedData.ToList()
                    .Where(ji => job.JobIndexList.Select(x => x.JobIndexId).Contains(ji.Id))
                    .ToList(),
                c.EmployeeJobCustomFieldValues
            };


            var calculationData = new CalculationData();

            calculationData.employee = employee;

            calculationData.JobPositions = employeeData.ToDictionary(
                empData => empData.JobPosition,
                empData => new JobPositionData
            {
                Job     = empData.Job,
                Indices = (from jobIndex in empData.jobIndexList
                           join jobIndexWithInquiryValues in
                           jobIndexInquiryPoints.Where(
                               g => g.SharedJobPositionId.Id == empData.JobPosition.SharedJobPosition.Id.Id)
                           .GroupBy(g => g.inquiryJobIndexPoint.JobIndexId)
                           .ToList()
                           on jobIndex.Id equals jobIndexWithInquiryValues.Key into gjii
                           from k in gjii.DefaultIfEmpty()
                           select new { ji = jobIndex, k })
                          .ToDictionary(j => j.ji,
                                        j => (j.k != null
                                ? j.k.GroupBy(jk => jk.emp)
                                              .ToDictionary(g => g.Key,
                                                            g =>
                                                            g.Select(
                                                                f =>
                                                                new InquiryData
                {
                    JobPosition = f.SharedJobPosition,
                    Point = f.inquiryJobIndexPoint
                }).ToList())
                                : null)),
                Unit = empData.Unit,
                //UnitIndices = (from unitIndex in empData.UnitIndexList
                //    join unitIndexWithInquiryValues in
                //        unitIndexInquiryPoints
                //        .GroupBy(
                //            g => g.inquiryUnitIndexPoint.ConfigurationItemId.UnitIndexIdUintPeriod).ToList()
                //        on unitIndex.Id equals unitIndexWithInquiryValues.Key into gjii
                //    from k in gjii.DefaultIfEmpty()
                //    select new {UnitIndex = unitIndex, k})
                //    .ToDictionary(j => j.UnitIndex,
                //        j => j.k.Select(
                //            ss =>
                //                new System.Tuple<Employee, string>(ss.emp,
                //                    ss.inquiryUnitIndexPoint.UnitIndexValue)).First()),

                CustomFields    = empData.EmployeeJobCustomFieldValues,
                WorkTimePercent =
                    employee.JobPositions.Single(j => j.JobPositionId == empData.JobPosition.Id).WorkTimePercent,
                Weight =
                    employee.JobPositions.Single(j => j.JobPositionId == empData.JobPosition.Id).JobPositionWeight
            });
            foreach (var jobPositionData in calculationData.JobPositions)
            {
                jobPositionData.Value.UnitIndices = new Dictionary <UnitIndex, System.Tuple <Employee, string> >();
                foreach (var unitIndex in employeeData.Single(e => e.JobPosition.DictionaryName == jobPositionData.Key.DictionaryName).UnitIndexList)
                {
                    var inquiryunitIndexPoint = unitIndexInquiryPoints.Single(
                        ui =>
                        ui.inquiryUnitIndexPoint.ConfigurationItemId.UnitIndexIdUintPeriod == unitIndex.Id &&
                        ui.inquiryUnitIndexPoint.ConfigurationItemId.InquirySubjectUnitId.SharedUnitId ==
                        jobPositionData.Value.Unit.SharedUnit.Id);
                    jobPositionData.Value.UnitIndices.Add(unitIndex,
                                                          new System.Tuple <Employee, string>(inquiryunitIndexPoint.emp,
                                                                                              inquiryunitIndexPoint.inquiryUnitIndexPoint.UnitIndexValue));
                }
            }
            if (withCalculationPoints)
            {
                calculationData.CalculationPoints = allPoints.ToList();
            }
            return(calculationData);
        }
コード例 #24
0
        public Dictionary <int, IList <Employee> > FindRemainingEmployeesOfCalculation(List <string> enList, PeriodId periodId, CalculationId calculationId)
        {
            int firstLevel = 1;
            var res        = new Dictionary <int, IList <EmployeeId> >();


            var employeeJobs = (from jo in session.Query <Job>()
                                join i in session.Query <JobPositionEmployee>()
                                on jo.Id equals i.JobPosition.JobId
                                where enList.Contains(i.EmployeeId.EmployeeNo) && i.EmployeeId.PeriodId == periodId
                                select new { jo, i.EmployeeId }); //.Distinct();


            IEnumerable <EmployeeId> empCompletedInFirstLevel = new List <EmployeeId>();
            Calculation calculation = null;

            if (calculationId != null)
            {
                calculation = session.Query <Calculation>().Where(c => c.Id == calculationId).SingleOrDefault();
                if (calculation.CalculationResult != null && calculation.CalculationResult.LastCalculatedPath.HasValue)
                {
                    firstLevel = calculation.CalculationResult.LastCalculatedPath.Value;
                }
            }
            // todo :(LOW) query for caculation data
            var dummy = employeeJobs.Select(empJob => empJob.jo).Fetch(j => j.JobIndexList).ToFuture();
            var employeeJobindexes = session.Query <Domain.Model.JobIndices.JobIndex>()
                                     .Where(j => employeeJobs.Select(empJob => empJob.jo)
                                            .SelectMany(jo => jo.JobIndexList)
                                            .Select(ji => ji.JobIndexId.Id)
                                            .Contains(j.Id.Id)).ToFuture();

            var jobIndexLevels = employeeJobindexes.Where(ji => ji.CalculationLevel >= firstLevel)
                                 .Select(ji => ji.CalculationLevel).Distinct().ToList();

            //var empJobInexIdsLevel1 = employeeJobindexes.Where(ji=>jei.CalculationLevel ==1).Select(ji => ji.Id).ToList();
            //var empLevel1 = employeeJobs.Where(empj => empj.jo.JobIndexList.Any(i => empJobInexIdsLevel1.Contains(i))).Select(empj => empj.EmployeeId).ToList();

            for (int level = firstLevel; level <= jobIndexLevels.Max(); level++)
            {
                var empJobInexIdsLevel = employeeJobindexes.Where(ji => ji.CalculationLevel == level).Select(ji => ji.Id).ToList();
                var empLevel           = employeeJobs.Where(empj => empj.jo.JobIndexList.Select(j => j.JobIndexId).Any(i => empJobInexIdsLevel.Contains(i)))
                                         .Select(empj => empj.EmployeeId).OrderBy(emp => emp.EmployeeNo).ToList();

                if (level == firstLevel)
                {
                    if (calculation.CalculationResult != null && calculation.CalculationResult.LastCalculatedEmployeeId != null)
                    {
                        var enNotCompletedInFirstLevel = enList.Skip(
                            enList.FindLastIndex(s => s == calculation.CalculationResult.LastCalculatedEmployeeId.EmployeeNo) + 1);

                        //var expEmployeeIds = calculation.EmployeeCalculationExceptions.Select(exp => exp.EmployeeId).ToList();
                        var expEmployeeIds = session.Query <EmployeeCalculationException>().Where(c => c.CalculationId.Id == calculationId.Id).Select(exp => exp.EmployeeId).ToList();
                        enNotCompletedInFirstLevel = enNotCompletedInFirstLevel.Union(expEmployeeIds.Select(exp => exp.EmployeeNo));
                        empLevel = empLevel.Where(emp => enNotCompletedInFirstLevel.Contains(emp.EmployeeNo)).ToList();
                    }
                }

                res.Add(level, empLevel);
            }

            return(res.ToDictionary(i => i.Key, i => FindInList(i.Value.Select(x => x.EmployeeNo).ToList(), periodId)));
        }