コード例 #1
0
        private CommonResult _ValidateAirBagCondition(AirBagFilePutCondition condition)
        {
            var result        = new CommonResult <AirBagFilePutCondition>();
            var airBagDetails = condition.AirBagDetails.ToList();
            var status        = _uow.RecallStatuses.GetAll().Select(x => x.RecallStatusName).ToList();

            _logger.LogInformation("#########################InPut And Duplication Checking#######################");
            foreach (var row in airBagDetails)
            {
                _InputCheck(row, status);
                _DuplicateCheckInFile(row, airBagDetails);


                //質問
            }

            var errorCount = airBagDetails.Where(x => !string.IsNullOrEmpty(x.ErrorMessages)).Count();

            if (errorCount == 0)
            {
                result.ResultType = ResultType.Success;
            }
            else
            {
                result.ResultType = ResultType.Error;
                result.ErrorMessages.Add(string.Format(Resources.E_RegisterErrorCount, errorCount));
            }
            return(result);
        }
コード例 #2
0
        private byte[] _CreateErrorExcelByte(AirBagFilePutCondition condition)
        {
            var workBook  = new XLWorkbook();
            var workSheet = workBook.Worksheets.Add("ErrorFeedBacks");
            var colIndex  = new AirBagDetailInputFileMap().MemberMaps.ToDictionary(x => x.Data.Member.Name, x => x.Data.Index + 1);
            var errorList = condition.AirBagDetails.Where(x => !string.IsNullOrEmpty(x.ErrorMessages)).ToList();

            workSheet.Range("A1:F1").Style.Fill.BackgroundColor = XLColor.PastelOrange;
            workSheet.Style.Font.FontName = "游ゴシック";

            workSheet.Cell(1, 1).Value = "Make of Vehicle";
            workSheet.Cell(1, 2).Value = "Model of Vehicle";
            workSheet.Cell(1, 3).Value = "Manifest VIN";
            workSheet.Cell(1, 4).Value = "Border Checked";
            workSheet.Cell(1, 5).Value = "Alpha";
            workSheet.Cell(1, 6).Value = "Non-Alpha";

            var rowIndex = 2;

            foreach (var row in condition.AirBagDetails)
            {
                if (string.IsNullOrEmpty(row.ErrorMessages))
                {
                    continue;
                }

                workSheet.Cell(rowIndex, colIndex[nameof(row.CarMakerNameEng)]).Value = row.CarMakerNameEng;
                workSheet.Cell(rowIndex, colIndex[nameof(row.CarModelName)]).Value    = row.CarModelName;
                workSheet.Cell(rowIndex, colIndex[nameof(row.ChassisNo)]).Value       = row.ChassisNo;
                //workSheet.Cell(rowIndex, colIndex[nameof(row.InspectionDateText)]).Value = row.InspectionDate?.ToString("dd/M/yyyy");
                workSheet.Cell(rowIndex, colIndex[nameof(row.InspectionDateText)]).Style.NumberFormat.SetFormat("dd/MM/yyyy");
                workSheet.Cell(rowIndex, colIndex[nameof(row.InspectionDateText)]).Value       = row.InspectionDateText;
                workSheet.Cell(rowIndex, colIndex[nameof(row.RecallStatusName)]).Value         = row.RecallStatusName;
                workSheet.Cell(rowIndex, colIndex[nameof(row.NonAlphaRecallStatusName)]).Value = row.NonAlphaRecallStatusName;
                workSheet.Cell(rowIndex, colIndex[nameof(row.ErrorMessages)]).Value            = row.ErrorMessages;

                rowIndex++;
            }

            workSheet.Columns("A:F").AdjustToContents();

            var bytes = new byte[0];

            using (var ms = new MemoryStream())
            {
                workBook.SaveAs(ms);
                bytes = ms.ToArray();
            }

            return(bytes);
        }
コード例 #3
0
        public CommonResult <FileResultBase> ValidateCondition(AirBagFilePutCondition condition)
        {
            var result         = new CommonResult <FileResultBase>();
            var validateResult = _ValidateAirBagCondition(condition);

            if (validateResult.ResultType == ResultType.Success)
            {
                result.ResultType = ResultType.Success;
            }
            else
            {
                result.ErrorMessages = validateResult.ErrorMessages;
                result.ResultType    = ResultType.Error;
                result.Result        = new FileResultBase
                {
                    Bytes       = _CreateErrorExcelByte(condition),
                    ContentType = ContentType.Xlsx,
                    ResultType  = ResultType.Error
                };
            }

            return(result);
        }
コード例 #4
0
        public CommonResult CheckAndSaveAirBagFile()
        {
            _logger.LogInformation("********** CheckAndSaveAirBagFile is Started!! **********");
            var result = new CommonResult <FileResultBase>();


            var blobIdQueries = _uow.AirBagFiles.GetAll().Where(x => x.UploadStatus == (int)UploadStatusCode.Before).ToList();

            //before statusがnull場合
            if (blobIdQueries.Count == 0)
            {
                _logger.LogInformation("********** Can't find anyting **********");
                return(new CommonResult {
                    ResultType = ResultType.Error, ErrorMessages = { Resources.E_NoQueryError }
                });
            }


            foreach (var blobIdQuery in blobIdQueries)
            {
                blobIdQuery.UploadStatus = (int)UploadStatusCode.InProcess;
                blobIdQuery.UpdatedAt    = DateTime.Now.AddHours(9);
                _uow.SaveChanges();

                if (blobIdQuery.BlobId != 0)
                {
                    var blobInfo       = _fileService.GetBlobName("airbag", blobIdQuery.BlobId);
                    var resultBlobFile = _fileService.DownloadFileFromBlob("airbag", blobInfo.BlobName);
                    var memoryStream   = new MemoryStream(resultBlobFile.Result);
                    var dataReader     = new AirBagDetailDataReader();

                    try
                    {
                        dataReader.LoadFile(memoryStream);
                        //var validateResult = dataReader.ValidateFormat();

                        //if (validateResult.ResultType != ResultType.Success)
                        //{
                        //    return Json(validateResult);
                        //}
                    }
                    catch
                    {
                        blobIdQuery.UploadStatus = (int)UploadStatusCode.Error;
                        blobIdQuery.ErrorMessage = Resources.E_FailedLoadingFile;
                        blobIdQuery.UpdatedAt    = DateTime.Now.AddHours(9);
                        //_uow.SaveChanges();

                        var errorResult = new CommonResult <FileResultBase>
                        {
                            ResultType    = ResultType.Error,
                            ErrorMessages = new List <string> {
                                Resources.E_FailedLoadingFile
                            }
                        };
                        return(errorResult);
                    }

                    var condition = new AirBagFilePutCondition();

                    //SetPutConditionBase(condition);

                    condition.AirBagDetails = dataReader.GetContent();

                    var validationResult = ValidateCondition(condition);


                    //if (!validationResult.Succeeded && validationResult.Result != null)
                    //{
                    //    validationResult.Result.FileName = dataReader.GetFileName();

                    //    TempData.Put(TEMP_ERROR_EXCEL_KEY, validationResult.Result);
                    //}

                    var registerResult = RegisterAirBag(condition, blobIdQuery.CreatedBy, blobIdQuery.CreatedAt);

                    //処理結果生成
                    //result = new CommonResult<FileResultBase>();
                    result.ErrorMessages = new List <string>();
                    //validationチェックでエラー
                    if (validationResult.ResultType != ResultType.Success)
                    {
                        var uploadErrorFileResult = _fileService.UploadStreamExcel(validationResult.Result.Bytes, "ErrorExcel.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "airbag", blobIdQuery.UpdatedBy, blobIdQuery.UpdatedAt ?? DateTime.Now);
                        var uploadPropertyresult  = _fileService.RegisterFilesWithBlobFileProperties(uploadErrorFileResult.Result.BlobName, uploadErrorFileResult.Result.FileName, "airbag", DateTime.Now, "system");
                        blobIdQuery.UploadStatus = (int)UploadStatusCode.Error;
                        blobIdQuery.ErrorBlobId  = uploadPropertyresult.BlobId;
                        blobIdQuery.ErrorMessage = Resources.E_FileValidationError;
                        //一部格納成功
                        if (registerResult.ResultType == ResultType.Success)
                        {
                            result.SuccessMessage = registerResult.SuccessMessage;
                        }

                        result.Result = validationResult.Result;
                        result.ErrorMessages.AddRange(validationResult.ErrorMessages);
                        blobIdQuery.UpdatedAt = DateTime.Now.AddHours(9);
                    }

                    //全件格納成功
                    else if (registerResult.ResultType == ResultType.Success && validationResult.ResultType == ResultType.Success)
                    {
                        blobIdQuery.UploadStatus = (int)UploadStatusCode.Done;
                        result.SuccessMessage    = registerResult.SuccessMessage;
                        blobIdQuery.UpdatedAt    = DateTime.Now.AddHours(9);
                    }

                    //全件失敗
                    else
                    {
                        blobIdQuery.UploadStatus = (int)UploadStatusCode.Error;
                        result.ErrorMessages.AddRange(registerResult.ErrorMessages);
                        blobIdQuery.ErrorMessage = registerResult.ErrorMessages[0];
                        blobIdQuery.UpdatedAt    = DateTime.Now.AddHours(9);
                    }
                    _uow.SaveChanges();
                    LogComplete();
                    //return result;
                }
            }//foreach


            return(result);
        }
コード例 #5
0
        public CommonResult RegisterAirBag(AirBagFilePutCondition condition, string UpdatedBy, DateTime?UserNow)
        {
            _logger.LogInformation("#########################RegisterAirBag Checking#######################");
            //登録できるデータがなければ結果なしでリターンん
            var registableData = condition.AirBagDetails.Where(x => string.IsNullOrEmpty(x.ErrorMessages)).ToList();

            if (!registableData.Any())
            {
                return(new CommonResult()
                {
                    ResultType = ResultType.Error,
                    ErrorMessages = { Resources.E_RegisterDataError }
                });
            }
            ;
            //using (var tran = _uow.BeginTran())
            //{
            //HashSet<string> chassissNoList = new HashSet<string>(_uow.AirBags.GetAll().Select(x => x.ChassisNo));
            List <AirBag> mappedRegistableData = new List <AirBag>();
            List <AirBag> mappedUpdatableData  = new List <AirBag>();
            var           mappedData           = Mapper.Map <List <AirBag> >(registableData);

            mappedData.ForEach(airBagDetail =>
            {
                airBagDetail.CreatedAt = UserNow;
                airBagDetail.UpdatedAt = UserNow;
                airBagDetail.CreatedBy = UpdatedBy;
                airBagDetail.UpdatedBy = UpdatedBy;
            });
            var chassisNoList = mappedData.Select(x => x.ChassisNo);

            //var findAirBagID = _uow.AirBags.Find(x => chassisNoList.Contains(x.ChassisNo)).Select(x=>x.AirBagId);
            //_uow.AirBags.Remove(x => findAirBagID.Contains(x.AirBagId));


            //var IsChassisMappedData = mappedData.Where(x => chassisNoList.Contains(x.ChassisNo)).ToList();

            _uow.AirBags.Remove(x => chassisNoList.Contains(x.ChassisNo));
            _logger.LogInformation("#########################RegisterAirBag2 Checking#######################");
            _uow.AirBags.AddRange(mappedData);


            //mappedRegistableData = mappedData.Where(x => !chassissNoList.Contains(x.ChassisNo)).ToList();

            ////foreach (var row in registableData)
            ////{
            //    row.ChassisNo = row.ChassisNo.Trim();

            //    if (!chassissNoList.Contains(row.ChassisNo))
            //    {
            //        mappedRegistableData.Add(mappedData);
            //    }
            //    else
            //    {
            //        mappedUpdatableData.Add(mappedData);
            //    }

            ////}


            //foreach (var row in registableData)
            //{   //chassisNo空白削除

            //var searchResult = await _uow.AirBags.GetByParamAsync(row.ChassisNo);

            //if (!chassissNoList.Contains(row.ChassisNo))
            //{
            //upsertResult = _RegisterAirBagDetail(condition, mappedRegistableData);
            //}
            //else
            //{
            //upsertResult = await _UpdateAirBagDetail(condition, mappedUpdatableData);
            //}
            //}
            _uow.SaveChanges();
            //tran.Commit();
            //}

            return(new CommonResult
            {
                LastUpdatedAt = UserNow,
                ResultType = ResultType.Success,
                SuccessMessage = Resources.S_Registerd
            });
        }
コード例 #6
0
        public async Task <IActionResult> RegisterAirBagEx()
        {
            //Excel習得
            //var dataReader = new AirBagDetailDataReader(Request.Form.Files[0]);
            //try
            //{
            //    dataReader.LoadFile();
            //    //var validateResult = dataReader.ValidateFormat();

            //    //if (validateResult.ResultType != ResultType.Success)
            //    //{
            //    //    return Json(validateResult);
            //    //}
            //}
            //catch
            //{
            //    var errorResult = new CommonResult<FileResultBase>
            //    {
            //        ResultType = ResultType.Error,
            //        ErrorMessages = new List<string> { Resources.E_FailedLoadingFile }
            //    };
            //    return Json(errorResult);
            //}

            var condition = new AirBagFilePutCondition();

            SetPutConditionBase(condition);

            //condition.AirBagDetails = dataReader.GetContent();



            //Excel Upload blob
            if (string.IsNullOrEmpty(Request.ContentType) || Request.ContentType.IndexOf("multipart/", StringComparison.OrdinalIgnoreCase) < 0)
            {
                return(BadRequest($"Expected a multipart request, but got {Request.ContentType}"));
            }

            var resultList = new List <BlobUploadResult>();
            var files      = Request.Form.Files;

            if (files != null && files.Count != 0)
            {
                var user       = "******" ?? IDENTITY_DEFAULT_NAME;
                var blobResult = _fileService.UploadExcelFilesWithBlobFileProperties(files, "airbag", user, UserNow);
                blobResult.Wait();
                //result.Result[0].FileName;
                resultList = blobResult.Result;
            }
            DateTime now = condition.UserNow;

            var result = new CommonResult <FileResultBase>();

            //register  Excel File in DB
            if (resultList.Count > 0)
            {
                foreach (var uploadResult in resultList)
                {
                    var Registeredresult = _service.RegisterFilesWithBlobFileProperties(uploadResult.BlobName, uploadResult.FileName, "airbag", now, "system");
                    uploadResult.BlobId = Registeredresult.BlobId;
                }
                var saveExcelInfo = _service.RegisterFileInfo(resultList, now, condition.UpdatedBy);
                result.ResultType     = ResultType.Success;
                result.SuccessMessage = saveExcelInfo.SuccessMessage;
            }



            //var registerResult1 = _service.RegisterAirBag();
            else
            {
                result.ResultType = ResultType.Error;
                result.ErrorMessages.Add(Resources.E_FailSaveAirBagFileInStorage);
            }


            //Excelポマトチャック
            //var checkResult = dataReader.FormatCheck();
            //if (checkResult.ResultType == ResultType.Error)
            //{
            //    var errorResult = new CommonResult<FileResultBase>
            //    {
            //        ResultType = ResultType.Error,
            //        ErrorMessages = new List<string> { Resources.E_ExcelFormatError }
            //    };
            //    return Json(errorResult);
            //}

            //var validationResult = _service.ValidateCondition(condition);

            //if (!validationResult.Succeeded && validationResult.Result != null)
            //{
            //    validationResult.Result.FileName = dataReader.GetFileName();

            //    TempData.Put(TEMP_ERROR_EXCEL_KEY, validationResult.Result);
            //}

            //var registerResult = await _service.RegisterAirBag(condition);

            ////処理結果生成

            //result.ErrorMessages = new List<string>();

            //if (validationResult.ResultType != ResultType.Success)
            //{
            //    result.Result = validationResult.Result;
            //    result.ErrorMessages.AddRange(validationResult.ErrorMessages);
            //}

            //if (registerResult.ResultType == ResultType.Success)
            //{
            //    result.SuccessMessage = registerResult.SuccessMessage;
            //}
            //else
            //{
            //    result.ErrorMessages.AddRange(registerResult.ErrorMessages);
            //}
            return(Json(result));
        }