public QCEvent ConvertToQCEvent(QCEventMessage model, QCDevice device)
        {
            var defectTypeService = provider.GetRequiredService <IDefectTypeService>();
            var proBatchService   = provider.GetRequiredService <IProductionBatchService>();

            var proBatch = proBatchService.ProductionBatchs.InLine(device.ProductionLineId.Value)
                           .RunningAtTime(model.CreatedTime).Select(o => new ProductionBatch
            {
                Id             = o.Id,
                ProductModelId = o.ProductModelId
            }).First();
            var defCodes       = model.Details.Select(o => o.QCDefectCode).ToList();
            var defectTypesMap = defectTypeService.DefectTypes.QCMappingCodes(defCodes)
                                 .Select(o => new
            {
                o.Id,
                o.QCMappingCode
            }).ToDictionary(o => o.QCMappingCode);
            var entity = new QCEvent
            {
                Id                = model.Id,
                CreatedTime       = model.CreatedTime,
                QCDeviceId        = device.Id,
                ProductionBatchId = proBatch.Id,
                Details           = model.Details.Select(o => new QCEventDetail
                {
                    DefectTypeId = defectTypesMap[o.QCDefectCode].Id,
                    Id           = o.Id,
                }).ToList()
            };

            return(entity);
        }
        public ValidationData ValidateQCMessage(
            QCEventMessage model)
        {
            var validationData = new ValidationData();
            var existed        = QCEvents.Exists(model.Id);

            if (existed)
            {
                return(validationData.Fail(mess: "Existed ID", AppResultCode.FailValidation));
            }
            if (string.IsNullOrWhiteSpace(model.Identifier))
            {
                return(validationData.Fail(mess: "Identifier must not be null", AppResultCode.FailValidation));
            }
            return(validationData);
        }
Example #3
0
        protected (QCEvent, List <(byte[], string)>) ProcessQCMessage(IServiceProvider sProvider,
                                                                      QCEventMessage model, string savePath)
        {
            var qcEventService  = sProvider.GetRequiredService <IQCEventService>();
            var qcDeviceService = sProvider.GetRequiredService <IQCDeviceService>();
            var fileService     = sProvider.GetRequiredService <IFileService>();
            var deviceCode      = model.Identifier;
            var device          = qcDeviceService.QCDevices.Code(deviceCode).Select(o => new QCDevice
            {
                Id               = o.Id,
                Code             = o.Code,
                ProductionLineId = o.ProductionLineId
            }).First();

            var entity    = qcEventService.ConvertToQCEvent(model, device);
            var imagesB64 = new List <(byte[], string)>();

            if (model.LeftB64Image != null && model.RightB64Image != null)
            {
                var leftImg  = Convert.FromBase64String(model.LeftB64Image);
                var rightImg = Convert.FromBase64String(model.RightB64Image);
                var(leftDir, leftFile)   = (Path.GetDirectoryName(model.LeftImage), Path.GetFileName(model.LeftImage));
                var(rightDir, rightFile) = (Path.GetDirectoryName(model.RightImage), Path.GetFileName(model.RightImage));
                var(leftRel, lFull)      = fileService.GetFilePath(Path.Combine(savePath, leftDir), savePath, leftFile, ext: ".jpg");
                var(rightRel, rFull)     = fileService.GetFilePath(Path.Combine(savePath, rightDir), savePath, rightFile, ext: ".jpg");
                entity.LeftImage         = model.LeftImage;
                entity.RightImage        = model.RightImage;
                imagesB64.Add((leftImg, lFull));
                imagesB64.Add((rightImg, rFull));
            }
            if (model.SideB64Images != null)
            {
                for (var i = 0; i < model.SideB64Images.Count; i++)
                {
                    var b64     = model.SideB64Images[i];
                    var imgPath = model.SideImages[i];
                    var img     = Convert.FromBase64String(b64);
                    var(dir, file) = (Path.GetDirectoryName(imgPath), Path.GetFileName(imgPath));
                    var(rel, full) = fileService.GetFilePath(Path.Combine(savePath, dir), savePath, file, ext: ".jpg");
                    imagesB64.Add((img, full));
                }
                entity.SideImages = JsonConvert.SerializeObject(model.SideImages);
            }
            return(entity, imagesB64);
        }