| | |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 上传图片 |
| | | /// 上传图片(Drop) |
| | | /// </summary> |
| | | /// <param name="fileNames"></param> |
| | | /// <param name="note"></param> |
| | | /// <param name="sid"></param> |
| | | /// <param name="UserId"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<ActionResult> AddImg2(string UserId) |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传图片 |
| | | /// </summary> |
| | | /// <param name="UserId"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<ActionResult> AddImg(string UserId) |
| | | public async Task<ActionResult> AddImg(int UserId) |
| | | { |
| | | //初始化FRMReportInfo类 |
| | | FRMReportInfo fRMReportInfo = new FRMReportInfo();//创建记录 |
| | | fRMReportInfo.UserId = UserId; |
| | | |
| | | if (HttpContext.Request.Files.Count == 0) |
| | | return Error("上传请求文件为0!"); |
| | | if (HttpContext.Request.Files.Count != 1) |
| | | return Error("只能上次一张图片!"); |
| | | var uploadFile = HttpContext.Request.Files[0]; //上传文件 |
| | | if (uploadFile == null) |
| | | return Error("图片为空!请重新上传!"); |
| | | FileInfo file = new FileInfo(uploadFile.FileName); |
| | | if (file.Extension != ".jpg" && file.Extension != ".jpeg" && file.Extension != ".png") |
| | | return Error("只能上传图片!请重新上传!"); |
| | | if (uploadFile.InputStream.Length > 4 * 1024 * 1024) //1024*1024*100=100M--前端验证 |
| | | return Error("文件大小已经超过4M!请重新上传!"); |
| | | |
| | | var createTime = DateTime.Now.ToString("yyyyMMddHHmm");//创建时间 |
| | | var filepath = string.Format("{0}【{1}】{2}", _virtualPath, createTime, |
| | | uploadFile.FileName); |
| | | var filename = |
| | | Server.MapPath(string.Format("{0}【{1}】{2}", _virtualPath, createTime, uploadFile.FileName)); |
| | | Directory.CreateDirectory(Server.MapPath(_virtualPath)); |
| | | uploadFile.SaveAs(filename); |
| | | fRMReportInfo.ImgPath = filepath; |
| | | |
| | | byte[] bytes; |
| | | using (var memoryStream = new MemoryStream()) |
| | | //判断当前的金额是否能支付本次消耗 |
| | | UseOrderService _useOrderService = new UseOrderService(); |
| | | PayOrderService _payOrderService = new PayOrderService(); |
| | | AccountBLL _accountBll = new AccountBLL(); |
| | | SysBusinessPlanBLL _sysBusinessPlanBll = new SysBusinessPlanBLL(); |
| | | var paySum = await _payOrderService.SumAsync(a => a.CreateUserId == UserId && a.PaymentStatus == EnumPaymentStatus.Success, "OrderAmount"); |
| | | var useSum = await _useOrderService.SumAsync(a => a.CreateUserId == UserId, "OrderAmount"); |
| | | var userGrade = _accountBll.GetUserGradeById(UserId); |
| | | var freeDescNo = _sysBusinessPlanBll.GetFreeDescbyName("公司财报OCR"); |
| | | var vipDescNo = _sysBusinessPlanBll.GetVipDescbyName("公司财报OCR"); |
| | | UseOrder param = new UseOrder(); |
| | | param.CreateUserId = UserId;//int.Parse(UserId); |
| | | param.OrderType = "公司财报OCR"; |
| | | param.OrderNo = Guid.NewGuid().ToString("N"); |
| | | if (userGrade == UserGradeType.Free.GetDisplayName()) //普通版 |
| | | { |
| | | uploadFile.InputStream.CopyTo(memoryStream); |
| | | bytes = memoryStream.ToArray(); |
| | | } |
| | | var base64Str = Convert.ToBase64String(bytes); |
| | | var table = await ResultsIdentifyBLL.AliOcrTable(base64Str); |
| | | if (table != null) |
| | | { |
| | | string fileName = uploadFile.FileName.Replace(file.Extension, ""); |
| | | fRMReportInfo.ImgName = fileName; |
| | | var title = "OCR_" + DateTime.Now.ToString("yyyyMMddhhmmssfff"); |
| | | var ExcelPath = string.Format("{0}【{1}】{2}", _savePath, createTime, |
| | | title.ToString() + ".xlsx"); |
| | | var ExcelPathShow = string.Format("{0}【{1}】{2}", _savePath, createTime, |
| | | title.ToString() + "_Show" + ".xlsx"); |
| | | var RealPath = Server.MapPath(string.Format("{0}【{1}】{2}", _excelPath, createTime, |
| | | title.ToString() + ".xlsx")); |
| | | Directory.CreateDirectory(Server.MapPath(_excelPath)); |
| | | NPOIHelper.FRMExportExcel(table, RealPath, title, true); |
| | | fRMReportInfo.ReportName = title + ".xlsx"; |
| | | fRMReportInfo.ReportPath = ExcelPath; |
| | | fRMReportInfo.ReportPath_Show = ExcelPathShow; |
| | | param.OrderAmount = freeDescNo; |
| | | param.PayAmount = freeDescNo; |
| | | } |
| | | else |
| | | { |
| | | return Error("识别失败!图片智能识别结果为空!"); |
| | | param.OrderAmount = vipDescNo; |
| | | param.PayAmount = vipDescNo; |
| | | } |
| | | |
| | | bool result = _acc.AddFRMReport(fRMReportInfo); |
| | | // 保存失败修改文件名 |
| | | if (!result) |
| | | if (paySum < useSum+param.PayAmount) |
| | | { |
| | | if (System.IO.File.Exists(filename)) |
| | | return Error("识别失败!当前金币额度不足!请及时充值!"); |
| | | } |
| | | else |
| | | { |
| | | //初始化FRMReportInfo类并推荐业务 |
| | | FRMReportInfo fRMReportInfo = new FRMReportInfo();//创建记录 |
| | | fRMReportInfo.UserId = UserId.ToString(); |
| | | |
| | | if (HttpContext.Request.Files.Count == 0) |
| | | return Error("上传请求文件为0!"); |
| | | if (HttpContext.Request.Files.Count != 1) |
| | | return Error("只能上次一张图片!"); |
| | | var uploadFile = HttpContext.Request.Files[0]; //上传文件 |
| | | if (uploadFile == null) |
| | | return Error("图片为空!请重新上传!"); |
| | | FileInfo file = new FileInfo(uploadFile.FileName); |
| | | if (file.Extension != ".jpg" && file.Extension != ".jpeg" && file.Extension != ".png") |
| | | return Error("只能上传图片!请重新上传!"); |
| | | if (uploadFile.InputStream.Length > 4 * 1024 * 1024) //1024*1024*100=100M--前端验证 |
| | | return Error("文件大小已经超过4M!请重新上传!"); |
| | | |
| | | var createTime = DateTime.Now.ToString("yyyyMMddHHmm");//创建时间 |
| | | var filepath = string.Format("{0}【{1}】{2}", _virtualPath, createTime, |
| | | uploadFile.FileName); |
| | | var filename = |
| | | Server.MapPath(string.Format("{0}【{1}】{2}", _virtualPath, createTime, uploadFile.FileName)); |
| | | Directory.CreateDirectory(Server.MapPath(_virtualPath)); |
| | | uploadFile.SaveAs(filename); |
| | | fRMReportInfo.ImgPath = filepath; |
| | | |
| | | byte[] bytes; |
| | | using (var memoryStream = new MemoryStream()) |
| | | { |
| | | var newName = Regex.Replace(filename, @"【\d*】", $"【保存失败{DateTime.Now:yyyyMMdd}】"); |
| | | //文件名重复,删除之前的 |
| | | if (System.IO.File.Exists(newName)) |
| | | { |
| | | System.IO.File.Delete(newName); |
| | | } |
| | | System.IO.File.Move(filename, newName); |
| | | uploadFile.InputStream.CopyTo(memoryStream); |
| | | bytes = memoryStream.ToArray(); |
| | | } |
| | | return Error("保存文件失败!"); |
| | | } |
| | | else |
| | | { |
| | | //消耗积分存入系统20230525FX |
| | | UseOrderService _orderService = new UseOrderService(); |
| | | AccountBLL _accountBll = new AccountBLL(); |
| | | SysBusinessPlanBLL _sysBusinessPlanBll = new SysBusinessPlanBLL(); |
| | | var userGrade = _accountBll.GetUserGradeById(int.Parse(UserId)); |
| | | var freeDescNo = _sysBusinessPlanBll.GetFreeDescbyName("公司财报OCR"); |
| | | var vipDescNo = _sysBusinessPlanBll.GetVipDescbyName("公司财报OCR"); |
| | | UseOrder param = new UseOrder(); |
| | | param.CreateUserId = int.Parse(UserId); |
| | | param.OrderType = "公司财报OCR"; |
| | | param.OrderNo = Guid.NewGuid().ToString("N"); |
| | | if (userGrade == UserGradeType.Free.GetDisplayName()) //普通版 |
| | | var base64Str = Convert.ToBase64String(bytes); |
| | | var table = await ResultsIdentifyBLL.AliOcrTable(base64Str); |
| | | if (table != null) |
| | | { |
| | | param.OrderAmount = freeDescNo; |
| | | param.PayAmount = freeDescNo; |
| | | string fileName = uploadFile.FileName.Replace(file.Extension, ""); |
| | | fRMReportInfo.ImgName = fileName; |
| | | var title = "OCR_" + DateTime.Now.ToString("yyyyMMddhhmmssfff"); |
| | | var ExcelPath = string.Format("{0}【{1}】{2}", _savePath, createTime, |
| | | title.ToString() + ".xlsx"); |
| | | var ExcelPathShow = string.Format("{0}【{1}】{2}", _savePath, createTime, |
| | | title.ToString() + "_Show" + ".xlsx"); |
| | | var RealPath = Server.MapPath(string.Format("{0}【{1}】{2}", _excelPath, createTime, |
| | | title.ToString() + ".xlsx")); |
| | | Directory.CreateDirectory(Server.MapPath(_excelPath)); |
| | | NPOIHelper.FRMExportExcel(table, RealPath, title, true); |
| | | fRMReportInfo.ReportName = title + ".xlsx"; |
| | | fRMReportInfo.ReportPath = ExcelPath; |
| | | fRMReportInfo.ReportPath_Show = ExcelPathShow; |
| | | } |
| | | else |
| | | { |
| | | param.OrderAmount = vipDescNo; |
| | | param.PayAmount = vipDescNo; |
| | | return Error("识别失败!图片智能识别结果为空!"); |
| | | } |
| | | await _orderService.AddAsync(param); |
| | | return Success(data: fRMReportInfo.ReportPath); |
| | | } |
| | | |
| | | bool result = _acc.AddFRMReport(fRMReportInfo); |
| | | // 保存失败修改文件名 |
| | | if (!result) |
| | | { |
| | | if (System.IO.File.Exists(filename)) |
| | | { |
| | | var newName = Regex.Replace(filename, @"【\d*】", $"【保存失败{DateTime.Now:yyyyMMdd}】"); |
| | | //文件名重复,删除之前的 |
| | | if (System.IO.File.Exists(newName)) |
| | | { |
| | | System.IO.File.Delete(newName); |
| | | } |
| | | System.IO.File.Move(filename, newName); |
| | | } |
| | | return Error("保存文件失败!"); |
| | | } |
| | | else |
| | | { |
| | | //消耗积分存入系统20230525FX |
| | | |
| | | await _useOrderService.AddAsync(param); |
| | | return Success(data: fRMReportInfo.ReportPath); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |