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)); } }
///// <summary> ///// 通过指定id获取BatchInfoListDto信息 ///// </summary> //public async Task<BatchInfoListDto> GetById(EntityDto<string> input) //{ // var entity = await _entityRepository.GetAsync(input.Id); // return entity.MapTo<BatchInfoListDto>(); //} /// <summary> /// 删除批次 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ApiResult> Delete(string id) { var entity = await _entityRepository.FirstOrDefaultAsync(id); if (entity == null) { return(ApiResult.DataNotFound()); } if (entity.Status == 2) { return(new ApiResult().Error("当前状态不允许删除")); } entity.IsDeleted = true; await _entityRepository.UpdateAsync(entity); return(new ApiResult().Success()); }