public async Task TestGetAll()
        {
            var query = new AllQuery();

            var queryHandler = new AllQueryHandler(_repository);

            var result = await queryHandler.HandleAsync(query).ConfigureAwait(false);

            Assert.Equal(8, result.Count());
            Assert.IsAssignableFrom <IEnumerable <CategoryModel> >(result);
        }
Beispiel #2
0
 public IEnumerable <int> Search(params string[] terms) =>
 Search(AllQuery.From(terms));
        public async Task <IEnumerable <CategoryModel> > HandleAsync(AllQuery query)
        {
            var categories = await _repository.GetAllAsync().ConfigureAwait(false);

            return(Mapper.Map <IEnumerable <CategoryModel> >(categories));
        }
        private ConstructionPlanMonthDetail GetCommonProperty(ConstructionPlanMonth item, int month,
                                                              ConstructionPlanImportCommon cpic, AllQuery all, DateTime dtNow, string planDate, ref DataTable dt, ref DataTable dtChart)
        {
            ConstructionPlanMonthDetail c = new ConstructionPlanMonthDetail();

            #region 通用属性
            c.Line         = cpic.Line;
            c.Month        = month;
            c.WorkType     = 112;//默认委外维护
            c.WorkTypeName = all.workType.Where(a => a.ID == c.WorkType).FirstOrDefault().Name;
            c.EqpType      = item.Code;
            c.EqpTypeName  = item.EqpTypeName;
            c.Location     = item.Location;
            c.LocationBy   = item.LocationBy;
            c.LocationName = all.locations.Where(a => a.LocationBy == c.LocationBy && a.ID == c.Location).FirstOrDefault().Name;
            c.Department   = cpic.Department;
            c.Team         = item.Team;
            c.TeamName     = all.team.Where(a => a.ID == c.Team).FirstOrDefault().Name;
            c.PMType       = (int)GetPMTypeByFrequency(item.Frequency, true);
            c.PMTypeName   = all.pmType.Where(a => a.ID == c.PMType).FirstOrDefault().Name;
            c.PMCycle      = item.Cycle;
            c.PMFrequency  = item.Frequency * 12;
            c.Unit         = item.Unit;
            c.PlanQuantity = item.Quantity;
            c.RealQuantity = item.Quantity;
            c.Query        = cpic.ID;
            c.PlanDate     = planDate;
            c.UpdateTime   = dtNow;
            c.UpdateBy     = _userID;

            InsertRow(ref dt, c);
            InsertRow(ref dtChart, c, cpic.Year);
            #endregion
            return(c);
        }
        public async Task <ApiResult> Create(int query)
        {
            ApiResult ret = new ApiResult();
            List <ConstructionPlanMonthDetail> month = new List <ConstructionPlanMonthDetail>();
            DataTable dt      = GetColumnName(false);
            DataTable dtChart = GetColumnName(true);
            DateTime  dtNow   = DateTime.Now;
            // 每天工作时间统计,年表中的任务分配给时间做少的一天
            List <List <int> > dayMinInMonth = new List <List <int> >();

            for (int i = 0; i < 12; i++)
            {
                List <int> tmp = new List <int>();
                for (int j = 0; j < 31; j++)
                {
                    tmp.Add(0);
                }
                dayMinInMonth.Add(tmp);
            }
            try
            {
                List <ConstructionPlanMonth> cpms = await _importRepo.ListMonthByQuery(query);

                List <ConstructionPlanYear> cpys = await _importRepo.ListYearByQuery(query);

                ConstructionPlanImportCommon cpic = await _importRepo.GetByID(query);

                AllQuery all = new AllQuery();
                //all.eqpTypes = await _importRepo.ListAllEqpTypes();
                all.locations = await _importRepo.ListAllLocations();

                all.team = await _importRepo.ListAllOrgByType(OrgType.Team);

                all.workType = await _importRepo.ListDictionarysByParent(MSS.Platform.Workflow.WebApi.Model.Common.WORK_TYPE);

                all.pmType = await _importRepo.ListDictionarysByParent(MSS.Platform.Workflow.WebApi.Model.Common.PM_TYPE);

                int year  = cpic.Year;
                int index = 0;
                // 12月份循环
                for (int i = 1; i < 13; i++)
                {
                    int j = 0;
                    // 处理月表
                    foreach (var item in cpms)
                    {
                        string m = "." + i.ToString("D2");
                        if (item.Frequency % 31 == 0)
                        {
                            string d        = "." + MSS.Platform.Workflow.WebApi.Model.Common.GetLastDay(i, year);
                            string planDate = year + m + ".01-" + year + m + d;
                            ConstructionPlanMonthDetail c = GetCommonProperty(item, i, cpic, all, dtNow, planDate, ref dt, ref dtChart);
                            //dt.Rows[j+index][14] = c.PlanDate;
                            month.Add(c);
                        }
                        else
                        {
                            List <int> day     = dayMinInMonth[i - 1];
                            List <int> allDate = GetDay(item, ref day);
                            foreach (var date in allDate)
                            {
                                string planDate = year + m + "." + date.ToString("D2");
                                ConstructionPlanMonthDetail c = GetCommonProperty(item, i, cpic, all, dtNow, planDate, ref dt, ref dtChart);
                                //dt.Rows[j+index][14] = c.PlanDate;
                                month.Add(c);
                            }
                        }
                        j++;
                    }
                    index += j;
                }
                // 处理年表
                foreach (var item in cpys)
                {
                    int        j        = 0;
                    List <int> allMonth = GetMonth(item);
                    foreach (var m in allMonth)
                    {
                        int min = dayMinInMonth[m - 1].Min();
                        int day = dayMinInMonth[m - 1].IndexOf(min);
                        dayMinInMonth[m - 1][day] += item.Once;
                        string planDate = year + "." + m.ToString("D2") + "." + (day + 1).ToString("D2");
                        ConstructionPlanMonthDetail c = GetCommonProperty(item, m, cpic, all, dtNow, planDate, ref dt, ref dtChart);
                        //dt.Rows[index+j][14] = c.PlanDate;
                        month.Add(c);
                        j++;
                    }
                    index += j;
                }
                //自动创建检修表单
                //List<MaintenanceList> mls = GetMLists(month, cpic.Year, dtNow);
                // 创建的数据存入数据,按时间排序?
                using (TransactionScope scope = new TransactionScope())
                {
                    _importRepo.BulkLoad(dt);
                    _importRepo.BulkLoad(dtChart);
                    await _importRepo.UpdateCommonStatus(query, _userID);

                    scope.Complete();
                }
                // 创建的数据按照月份拆分后,按照时间排序后,分页
                List <List <ConstructionPlanMonthDetail> > months = new List <List <ConstructionPlanMonthDetail> >();
                List <object> retList = new List <object>();
                for (int i = 0; i < 12; i++)
                {
                    months.Add(new List <ConstructionPlanMonthDetail>());
                }
                foreach (var item in month)
                {
                    months[item.Month - 1].Add(item);
                }
                foreach (var item in months)
                {
                    retList.Add(new { rows = item.OrderBy(a => a.PlanDate).Take(10), total = item.Count });
                }
                ret.data = retList;
            }
            catch (Exception ex)
            {
                ret.code = Code.Failure;
                ret.msg  = ex.Message;
            }
            return(ret);
        }
        public async Task <IEnumerable <CategoryModel> > Get()
        {
            var query = new AllQuery();

            return(await _queryProcessor.ProcessAsync(query).ConfigureAwait(true));
        }