public async Task <ApiResult <ImportViolationOutputDto> > ImportViolations([FromForm] ImportViolationInputDto input) { try { var batchInfo = await _batchInfoRepository.FirstOrDefaultAsync(x => x.Id == input.BatchId); if (batchInfo == null) { return(new ApiResult <ImportViolationOutputDto>().Error("批次信息不存在")); } List <BatchTableModelDto> list; using (var fs = input.File.OpenReadStream()) { list = GetExcelData(fs, input.File.FileName); } var errors = await CheckError(list); await QueryViolationInfo(list, batchInfo); list.ForEach(x => { x.Uniquecode = CommonHelper.GenerateViolationCode(x.车牌号, x.违章时间, x.违章原因); x.BatchId = input.BatchId; x.CreateUserId = AbpSession.UserId; x.CreateUserName = AbpSession.UserName; x.WebSiteId = AbpSession.WebSiteId; }); var repeats = await CheckRepeat(list, input.BatchId); var fileName = $"{Guid.NewGuid().ToString("N")}{Path.GetExtension(input.File.FileName)}"; var fullFilePath = Path.Combine(_env.WebRootPath, "UploadFiles", fileName); await FileOperateHelper.SaveStreamToFileAsync(input.File.OpenReadStream(), fullFilePath); var result = new ImportViolationOutputDto { SuccessList = list, ErrorList = errors, FilePath = fileName }; return(new ApiResult <ImportViolationOutputDto>().Success(result)); } catch (Exception ex) { _logger.Error($"ImportViolations:{ex.Message}"); return(new ApiResult <ImportViolationOutputDto>().Error(MessageTipsConsts.SystemBusy)); } }