Ejemplo n.º 1
0
        public virtual async Task <List <EquipmentInfoDto> > GetEquipmentInfos(int?processTypeId, int?unitId)
        {
            var manager      = Manager as EquipmentManager;
            var processTypes = await ProcessTypeManager.GetAllList();

            var query = Manager.GetAll().Where(o => o.UnitId == unitId);

            if (processTypeId.HasValue)
            {
                query = from equipment in query
                        join equipmentProcessType in EquipmentProcessTypeRepository.GetAll() on equipment.Id equals equipmentProcessType.EquipmentId
                        where equipmentProcessType.ProcessTypeId == processTypeId
                        select equipment;
            }

            var equipments = await query.Include(o => o.EquipmentProcessTypes).ToListAsync();

            var result = new List <EquipmentInfoDto>();

            foreach (var equipment in equipments)
            {
                var dto = equipment.MapTo <EquipmentInfoDto>();
                dto.ProcessTypeName = string.Join(',', equipment.EquipmentProcessTypes.Select(o => processTypes.FirstOrDefault(p => p.Id == o.ProcessTypeId)?.ProcessTypeName));
                result.Add(dto);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 从云平台同步设备信息
        /// </summary>
        /// <returns></returns>
        public virtual async Task SyncEquipmentFromMES()
        {
            var companySN = await SettingManager.GetSettingValueAsync(MESSettingNames.MESCompanySN);

            var companyToken = await SettingManager.GetSettingValueAsync(MESSettingNames.MESCompanyToken);

            if (string.IsNullOrEmpty(companySN) || string.IsNullOrEmpty(companyToken))
            {
                throw new UserFriendlyException(L("请绑定企业编号与企业令牌"));
            }

            string apiUrl = $"http://mes.imould.me/Ajax/ajaxapi.ashx?action=GetYunEquipmentList&page=1&pagesize=1000&companysn={companySN}&companytoken={companyToken}";

            var pageResult = await Senparc.CO2NET.HttpUtility.Get.GetJsonAsync <CloudPageResultDto <CloudEquipmentDto> >(apiUrl);

            foreach (var cloudEquipment in pageResult.Data.ObjList)
            {
                if (await Manager.GetAll().CountAsync(o => o.EquipmentSN == cloudEquipment.ResSN) == 0)
                {
                    var processType = await ProcessTypeManager.GetByNameOrInsert(cloudEquipment.EquipmentType);

                    var equipment = new Equipment()
                    {
                        EquipmentSN = cloudEquipment.ResSN,
                        Brand       = cloudEquipment.Brand,
                        Price       = cloudEquipment.ProcessPrice,
                        Range       = cloudEquipment.Range,
                        BuyCost     = cloudEquipment.Cost,
                    };
                    int buyYear;
                    int.TryParse(cloudEquipment.BuyYear, out buyYear);
                    if (buyYear > 0)
                    {
                        equipment.BuyYear = buyYear;
                    }
                    //下载设备图片
                    var imgPath = $"http://mes.imould.me/thumb.ashx?fileid={cloudEquipment.EquipmentPic}";
                    var file    = await FileManager.DownLoadFile(imgPath);

                    equipment.EquipmentPic = file.Id;
                    var equipmentId = await Manager.InsertAndGetIdAsync(equipment);

                    await EquipmentProcessTypeRepository.InsertAsync(new EquipmentProcessType()
                    {
                        EquipmentId   = equipmentId,
                        ProcessTypeId = processType.Id
                    });
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 设备现场信息
        /// </summary>
        /// <param name="equipmentProcessInfoSearchDto"></param>
        /// <returns></returns>
        public virtual async Task <List <EquipmentProcessInfoDto> > GetEquipmentProcessInfos(EquipmentProcessInfoSearchDto equipmentProcessInfoSearchDto)
        {
            var manager      = Manager as EquipmentManager;
            var processTypes = await ProcessTypeManager.GetAllList();

            var query = Manager.GetAll()
                        .Include(o => o.Operator)
                        .Where(o => o.UnitId == equipmentProcessInfoSearchDto.UnitId)
                        .WhereIf(!equipmentProcessInfoSearchDto.Keyword.IsNullOrEmpty(), o => o.EquipmentSN.Contains(equipmentProcessInfoSearchDto.Keyword));

            if (equipmentProcessInfoSearchDto.ProcessTypeId.HasValue)
            {
                query = from equipment in query
                        join equipmentProcessType in EquipmentProcessTypeRepository.GetAll() on equipment.Id equals equipmentProcessType.EquipmentId
                        where equipmentProcessType.ProcessTypeId == equipmentProcessInfoSearchDto.ProcessTypeId
                        select equipment;
            }

            var equipments = await query.Include(o => o.EquipmentProcessTypes).ToListAsync();

            var result = new List <EquipmentProcessInfoDto>();

            var startDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));

            foreach (var equipment in equipments)
            {
                var dto = equipment.MapTo <EquipmentProcessInfoDto>();
                dto.Operator        = equipment.Operator?.Name;
                dto.ProcessTypeName = string.Join(',', equipment.EquipmentProcessTypes.Select(o => processTypes.FirstOrDefault(p => p.Id == o.ProcessTypeId)?.ProcessTypeName));
                //获取设备正在加工中的任务
                var task = await manager.GetProcessingTask(equipment.Id);

                //设备上安排的未完成任务
                //var unFinishedTasks =await  GetUnFinishedTasks(equipment.Id);
                dto.TaskId    = task?.Id;
                dto.PartSN    = task?.Part?.PartSN;
                dto.PartName  = task?.Part?.PartName;
                dto.ProjectSN = task?.Part?.Project?.ProjectSN;
                dto.ProcessTaskProgressInfo = task?.ProcessTaskProgressInfo;
                //dto.Tasks = unFinishedTasks;
                dto.TaskNumber = await manager.GetUnFinishedTasks(equipment.Id).CountAsync();

                dto.EquipmentLoadInfo = await manager.GetLoadInfo(equipment.Id, startDate, startDate.AddDays(7));

                result.Add(dto);
            }

            return(result);
        }
Ejemplo n.º 5
0
        public virtual async Task <EquipmentInfoDto> GetEquipmentInfo(int equipmentId)
        {
            var processTypes = await ProcessTypeManager.GetAllList();

            using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MustHaveTenant))
            {
                //不直接调用Manager.GetAll,以避免使用底层权限过滤
                var equipment = await Manager.Repository.GetAll().Include(o => o.EquipmentProcessTypes).Where(o => o.Id == equipmentId)
                                .SingleOrDefaultAsync();

                var dto = equipment.MapTo <EquipmentInfoDto>();
                dto.ProcessTypeName = string.Join(',', equipment.EquipmentProcessTypes.Select(o => processTypes.FirstOrDefault(p => p.Id == o.ProcessTypeId)?.ProcessTypeName));
                return(dto);
            }
        }
Ejemplo n.º 6
0
        public virtual void HandleEvent(EntityCreatedEventData <MouldTry.Domains.MouldTry> eventData)
        {
            var entity = eventData.Entity;

            if (entity.ProjectId != null)
            {
            }
            var ProjectId   = Convert.ToInt32(entity.ProjectId);
            var processType = ProcessTypeManager.GetByNameOrInsert("试模").Result;
            var project     = projectManager.GetByIdAsync(ProjectId).Result;
            var part        = PartManager.GetAll().Where(o => o.ProjectId == ProjectId && o.PartName == "整副").FirstOrDefault();

            if (part == null)
            {
                part = PartManager.GenerateNewPart(project, "整副", "", 1).Result;
                part.EnableProcess = true;
            }
            //var part = PartManager.GetByNameOrInsert("整副", Convert.ToInt32(entity.ProjectId));
            var processTask = new ProcessTask();

            //var project =  projectManager.GetByProjectSNOrInsert(entity.Project.ProjectSN);
            processTask.ProcessSN     = entity.MouldTrySN;
            processTask.PartId        = part.Id;
            processTask.SupplierId    = entity.UnitId;
            processTask.ProcessTypeId = processType.Id;
            var maxSort = 0;

            try
            {
                maxSort = ProcessTaskManager.GetAll().Where(o => o.PartId == part.Id).Max(o => o.Sort);
            }
            catch
            {
            }
            processTask.Sort              = maxSort++;
            processTask.ArrangeDate       = entity.ArrangeDate;
            processTask.ArrangeEndDate    = entity.ArrangeDate;
            processTask.ProjectCharger    = entity.TryPerson;
            processTask.AppointDate       = entity.PlanDate;
            processTask.RequireDate       = entity.PlanDate;
            processTask.ProcessTaskStatus = ProcessTaskStatus.WaitForProcess;
            //throw new NotImplementedException();
            ProcessTaskManager.SaveAsync(processTask).GetAwaiter().GetResult();

            //CurrentUnitOfWork.SaveChangesAsync();
        }
Ejemplo n.º 7
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>());
            }
        }