Esempio n. 1
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
                    });
                }
            }
        }
Esempio n. 2
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();
        }