AnalyseFileController.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Microsoft.AspNetCore.Hosting;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace TEAMModelBI.Controllers.BIHome
  10. {
  11. [Route("analyse")]
  12. [ApiController]
  13. public class AnalyseFileController : ControllerBase
  14. {
  15. private readonly IWebHostEnvironment _environment; //读取文件流
  16. public AnalyseFileController(IWebHostEnvironment environment)
  17. {
  18. _environment = environment;
  19. }
  20. [HttpPost("get-visitjson")]
  21. public async Task<IActionResult> GetVisitJson()
  22. {
  23. var path = $"{_environment.ContentRootPath}/JsonFile/TempFile/PT1H.json";
  24. StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  25. List<object> objs = new();
  26. StringBuilder visits = new("[");
  27. string text;
  28. while ((text = streamReader.ReadLine()) != null)
  29. {
  30. objs.Add(text.ToString());
  31. visits.Append($"{text},");
  32. }
  33. visits.Append("]");
  34. streamReader.Close();
  35. //var temp = visits.Split("||");
  36. //var temp1 = string.Join("||");
  37. return Ok(new { state = 200, objs, visits });
  38. }
  39. public record AGInfo
  40. {
  41. }
  42. }
  43. }