StockController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using JCSoft.WX.Framework.Api;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Caching.Memory;
  10. using Newtonsoft.Json;
  11. using ZcPeng.PublicLibrary;
  12. using Common.Wechat;
  13. using System.Data.SqlClient;
  14. using System.Linq.Dynamic.Core;
  15. using CoreEntity.Entity;
  16. using Common.Model;
  17. using Newtonsoft.Json.Converters;
  18. using PublicLibrary.Model;
  19. using SupplierWeb.Codes.EF;
  20. using SupplierWeb.Codes.mvc;
  21. namespace SupplierWeb.Controllers
  22. {
  23. [Route("web/stock")]
  24. [ApiController]
  25. public class StockController : BaseController
  26. {
  27. public StockController(IMemoryCache cache, IApiClient client) : base(cache, client)
  28. {
  29. }
  30. [AuthPermission]
  31. [HttpPost]
  32. [Route("getData")]
  33. public JsonResult GetData(string[] filters, Int32 pageIndex, Int32 pageSize,
  34. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  35. {
  36. var userid = getStaff("userid");
  37. //判断参数是否合法
  38. if (string.IsNullOrEmpty(userid))
  39. {
  40. return Json(new
  41. {
  42. success = 0,
  43. msg = "没有登陆",
  44. timeout = 1,
  45. });
  46. }
  47. //var db = new LJHYBZKContext();
  48. List<QueryFilter> filterList = new List<QueryFilter>();
  49. if (data != null)
  50. {
  51. if (data.filters.Count > 0)
  52. {
  53. var list = JsonConvert.SerializeObject(data.filters);
  54. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  55. }
  56. pageIndex = data.pageIndex;
  57. pageSize = data.pageSize;
  58. sortField = data.sortField;
  59. sortDirection = data.sortDirection;
  60. sumFields = data.sumFields.ToObject<string[]>();
  61. }
  62. var isAce = sortDirection == 0 ? "asc" : "desc";
  63. var queryCondition = "1=1 ";
  64. var param = new List<SqlParameter>();
  65. var start = (pageIndex - 1) * pageSize;
  66. var end = (start + 1 + pageSize);
  67. if (filterList != null)
  68. {
  69. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(),out param,new Egbalance());
  70. }
  71. //var result = db.Egbalance.Join(db.Goodsdoc, x => x.GoodsId, y => y.GoodsId, (x, y) => new
  72. //{
  73. // x.PlacePack,
  74. // x.PlaceNum,
  75. // x.StorPack,
  76. // x.StorNum,
  77. // x.StorMax,
  78. // x.StorMin,
  79. // x.GoodsId,
  80. // y.GoodsName
  81. //}).Where(queryCondition, param.ToArray()).OrderBy(sortField + (isAce ? " asc" : " desc")).Skip(pageSize * (pageIndex - 1)).Take(pageSize);
  82. var dt = new DataTable();
  83. var sql =
  84. $"select * from ";
  85. var sql1 = $"(select A.*," +
  86. $"B.GoodsName," +
  87. $"row_number() over (order by A.{sortField} {isAce}) as rowNum " +
  88. $"from OgBalance A " +
  89. $" left join OrgDoc A1 on A1.OrgId = A.OwnerId and A1.EntId = A.EntId " +
  90. $" left join GoodsDoc B on B.GoodsId = A.GoodsId and B.EntId = A.EntId " +
  91. $" where 1=1 " +
  92. $" and A.EntId = 'E1WB67UEYPG' " +
  93. $" and A1.K_UserId = {userid} " +
  94. $"{queryCondition} " +
  95. $") R";
  96. var sql2 = $" where rowNum > {start} and rowNum < {end}";
  97. DataAccess.GetValues(sql + sql1 + sql2, ref dt, param.ToArray(), out var msg);
  98. IList<Egbalance> result = new List<Egbalance>();
  99. if (dt != null && dt.Rows.Count > 0)
  100. {
  101. result = ModelConvertHelper<Egbalance>.ConvertToModel(dt);
  102. }
  103. var jsonData = JsonConvert.SerializeObject(result);
  104. var countSql = "select count(1) from " + sql1;
  105. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out var msg1);
  106. return Json(new
  107. {
  108. items = JsonConvert.DeserializeObject(jsonData),
  109. sum = new { },
  110. totalCount = count
  111. });
  112. }
  113. }
  114. }