OpenBankTableController.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using MySystem.MainModels;
  10. using LitJson;
  11. using Library;
  12. namespace MySystem.Areas.Api.Controllers.v1
  13. {
  14. [Area("Api")]
  15. [Route("Api/v1/[controller]/[action]")]
  16. public class OpenBankTableController : BaseController
  17. {
  18. public OpenBankTableController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  19. {
  20. }
  21. #region 创客-首页-开户行查询
  22. [Authorize]
  23. public JsonResult List(string value)
  24. {
  25. value = DesDecrypt(value);
  26. JsonData data = JsonMapper.ToObject(value);
  27. List<Dictionary<string, object>> dataList = ListDo(value);
  28. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  29. }
  30. public List<Dictionary<string, object>> ListDo(string value)
  31. {
  32. JsonData data = JsonMapper.ToObject(value);
  33. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  34. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  35. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  36. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  37. IQueryable<OpenBankTable> query = maindb.OpenBankTable;
  38. if(value.Contains("\"Areas\""))
  39. {
  40. if(!string.IsNullOrEmpty(data["Areas"].ToString()))
  41. {
  42. string Areas = data["Areas"].ToString();
  43. if(Areas.Contains(","))
  44. {
  45. string[] AreasList = Areas.Split(',');
  46. if(AreasList.Length == 3)
  47. {
  48. string p = AreasList[0];
  49. string c = AreasList[1];
  50. string a = AreasList[2];
  51. query = query.Where(m => (m.BankName.Contains(p) || m.BankName.Contains(c) || m.BankName.Contains(a)));
  52. }
  53. else if(AreasList.Length == 2)
  54. {
  55. string p = AreasList[0];
  56. string c = AreasList[1];
  57. query = query.Where(m => (m.BankName.Contains(p) || m.BankName.Contains(c)));
  58. }
  59. else
  60. {
  61. query = query.Where(m => m.BankName.Contains(Areas));
  62. }
  63. }
  64. else
  65. {
  66. query = query.Where(m => m.BankName.Contains(Areas));
  67. }
  68. }
  69. }
  70. if(value.Contains("\"BankName\""))
  71. {
  72. if(!string.IsNullOrEmpty(data["BankName"].ToString()))
  73. {
  74. string BankName = data["BankName"].ToString();
  75. query = query.Where(m => m.BankName.Contains(BankName));
  76. }
  77. }
  78. if(!string.IsNullOrEmpty(SearchKey))
  79. {
  80. query = query.Where(m => m.BankName.Contains(SearchKey));
  81. }
  82. query = query.Take(PageSize);
  83. foreach (var subdata in query.ToList())
  84. {
  85. Dictionary<string, object> curData = new Dictionary<string, object>();
  86. curData.Add("BankName", subdata.BankName); //开户行名称
  87. curData.Add("BankCode", subdata.BankCode); //联行号
  88. dataList.Add(curData);
  89. }
  90. return dataList;
  91. }
  92. #endregion
  93. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  94. /// <summary>
  95. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  96. /// </summary>
  97. /// <param name="value">请求的参数(json字符串)</param>
  98. /// <param name="signField">要签名的字段</param>
  99. /// <returns></returns>
  100. private string CheckSign(string value, string[] signField)
  101. {
  102. JsonData json = JsonMapper.ToObject(value);
  103. Dictionary<string, string> dic = new Dictionary<string, string>();
  104. for (int i = 0; i < signField.Length; i++)
  105. {
  106. dic.Add(signField[i], json[signField[i]].ToString());
  107. }
  108. string sign = json["sign"].ToString(); //客户端签名字符串
  109. return new Sign().sign(dic, sign);
  110. }
  111. #endregion
  112. }
  113. }