/// <summary>
        /// 通过工序获取加工点信息,开单数量多的排序在前
        /// </summary>
        /// <param name="processTypeName"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public virtual async Task <List <UnitDto> > GetAllUnitByProcessTypeName(string processTypeName, string key)
        {
            var units = await(Manager as UnitManager).GetAll().Include(o => o.UnitType).Where(o => o.UnitNature == UnitNature.供应商 || o.UnitNature == UnitNature.客户及供应商).Where(o => o.SupplierType != null && o.SupplierType.Contains("加工")).WhereIf(!string.IsNullOrEmpty(key), o => o.UnitName.Contains(key)).ToListAsync();

            if (string.IsNullOrEmpty(processTypeName))
            {
                //Logger.Error(Newtonsoft.Json.JsonConvert.SerializeObject(units));
                return(units.MapTo <List <UnitDto> >());
            }
            var processType = await ProcessTypeManager.GetAll().Where(o => o.ProcessTypeName == processTypeName).FirstOrDefaultAsync();

            if (processType == null)
            {
                return(units.MapTo <List <UnitDto> >());
            }
            var taskedSupplierDtos = await ProcessTaskManager.GetAll().Where(o => o.ProcessTypeId == processType.Id && o.SupplierId != null).GroupBy(o => o.SupplierId)
                                     .Select(o => new { Id = o.Key, Count = o.Count() }).OrderByDescending(o => o.Count).ToListAsync();

            var result = new List <UnitDto>();

            foreach (var supplier in taskedSupplierDtos)
            {
                var unitDto = units.FirstOrDefault(o => o.Id == supplier.Id);
                if (unitDto != null)
                {
                    result.Add(unitDto.MapTo <UnitDto>());
                }
            }
            result.AddRange(units.Where(o => !taskedSupplierDtos.Exists(t => t.Id == o.Id)).MapTo <List <UnitDto> >());

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 设备信息
        /// </summary>
        /// <param name="processTypeName"></param>
        /// <param name="unitId"></param>
        /// <returns></returns>
        public virtual async Task <List <EquipmentInfoDto> > GetEquipmentInfosByProcessTypeName(string processTypeName, int?unitId)
        {
            //返回所有设备
            if (string.IsNullOrEmpty(processTypeName))
            {
                return(await GetEquipmentInfos(null, unitId));
            }

            var processType = await ProcessTypeManager.GetAll().Where(o => o.ProcessTypeName == processTypeName).FirstOrDefaultAsync();

            if (processType != null)
            {
                return(await GetEquipmentInfos(processType.Id, unitId));
            }
            else
            {
                return(new List <EquipmentInfoDto>());
            }
        }