Finance_ServiceSurchargeController.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Microsoft.AspNetCore.Mvc;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Threading.Tasks;
  8. using XYY.Common.Standard;
  9. using XYY.Core.Standard.Mvc;
  10. using XYY.Model.Standard.Finance;
  11. using XYY.Service.Standard.Finance;
  12. namespace XYY.Api.Finance.Controllers
  13. {
  14. [Route("api/[controller]/[action]")]
  15. [ApiController]
  16. public class Finance_ServiceSurchargeController : ApiControllerBase
  17. {
  18. IFinance_ServiceSurchargeService serviceSurchargeService;
  19. XYY.Core.Standard.AliYun.IAliYunPostFileSerivce aliOSS;
  20. public Finance_ServiceSurchargeController(IFinance_ServiceSurchargeService serviceSurchargeService, Core.Standard.AliYun.IAliYunPostFileSerivce aliOSS)
  21. {
  22. this.serviceSurchargeService = serviceSurchargeService;
  23. this.aliOSS = aliOSS;
  24. }
  25. #region wms调用
  26. public async Task<IActionResult> AddServiceSurchargeService([FromForm] Finance_ServiceSurcharge surcharge)
  27. {
  28. var data = new byte[surcharge.Stream.Length];
  29. surcharge.FileUrl = aliOSS.PostHttpFile(surcharge.Stream.OpenReadStream(), surcharge.Stream.FileName);
  30. await this.serviceSurchargeService.AddServiceSurchargeService(surcharge);
  31. return Ok();
  32. }
  33. public async Task<IActionResult> UpdateServiceSurchargeService([FromForm] Finance_ServiceSurcharge surcharge)
  34. {
  35. if (surcharge.Stream != null)
  36. {
  37. var data = new byte[surcharge.Stream.Length];
  38. surcharge.FileUrl = aliOSS.PostHttpFile(surcharge.Stream.OpenReadStream(), Guid.NewGuid().ToString());
  39. }
  40. await this.serviceSurchargeService.UpdateServiceSurchargeService(surcharge);
  41. return Ok();
  42. }
  43. public async Task<IActionResult> GetLogs([FromQuery] int id)
  44. {
  45. var data = await serviceSurchargeService.GetLogs(id);
  46. return new JsonResult(new
  47. {
  48. total = data.Count,
  49. rows = data
  50. });
  51. }
  52. public async Task<IActionResult> QueryServiceSurchargeService([FromQuery] int expressId)
  53. {
  54. var list = await serviceSurchargeService.QueryServiceSurchargeService(expressId);
  55. PageResult<Finance_ServiceSurcharge> pr
  56. = new PageResult<Finance_ServiceSurcharge>() { Result = list, PageIndex = 1, PageSize = 1000, TotalCount = list.Count };
  57. return new JsonResult(new
  58. {
  59. total = pr.TotalCount,
  60. rows = pr.Result
  61. });
  62. }
  63. public async Task<IActionResult> DownloadServiceSurchargeService(int expresssId)
  64. {
  65. var data = serviceSurchargeService.DownloadServiceSurchargeService(expresssId);
  66. return File(DateTime.Now.ToString_yyyyMMdd() + ".xlsx", data);
  67. }
  68. #endregion
  69. #region 附加费调价处理
  70. public async Task<IActionResult> AddServiceSurcharge(int ExpressId)
  71. {
  72. var filelist = (await Request.ReadFormAsync()).Files;
  73. if (filelist != null && filelist.Count > 0)
  74. {
  75. var file = filelist[0];
  76. using (var ms = new System.IO.MemoryStream())
  77. {
  78. file.CopyTo(ms);
  79. var byteData=ms.ToArray();
  80. string url = aliOSS.PostHttpFile(new MemoryStream(byteData), Guid.NewGuid().ToString() + ".xlsx");
  81. var result =await serviceSurchargeService.ConcertToQuotation(ExpressId, byteData);
  82. return Ok(new { url = url, detail = result });
  83. }
  84. }
  85. else
  86. {
  87. return Error("请上传一个文件");
  88. }
  89. }
  90. #endregion
  91. }
  92. }