OpenBankTableController.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. string Areas = data["Areas"].ToString();
  35. string BankName = data["BankName"].ToString();
  36. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  37. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  38. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  39. IQueryable<OpenBankTable> query = maindb.OpenBankTable;
  40. if(!string.IsNullOrEmpty(SearchKey))
  41. {
  42. query = query.Where(m => m.BankName.Contains(Areas));
  43. }
  44. if(!string.IsNullOrEmpty(SearchKey))
  45. {
  46. query = query.Where(m => m.BankName.Contains(BankName));
  47. }
  48. if(!string.IsNullOrEmpty(SearchKey))
  49. {
  50. query = query.Where(m => m.BankName.Contains(SearchKey));
  51. }
  52. query = query.Take(PageSize);
  53. foreach (var subdata in query.ToList())
  54. {
  55. Dictionary<string, object> curData = new Dictionary<string, object>();
  56. curData.Add("BankName", subdata.BankName); //开户行名称
  57. curData.Add("BankCode", subdata.BankCode); //联行号
  58. dataList.Add(curData);
  59. }
  60. return dataList;
  61. }
  62. #endregion
  63. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  64. /// <summary>
  65. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  66. /// </summary>
  67. /// <param name="value">请求的参数(json字符串)</param>
  68. /// <param name="signField">要签名的字段</param>
  69. /// <returns></returns>
  70. private string CheckSign(string value, string[] signField)
  71. {
  72. JsonData json = JsonMapper.ToObject(value);
  73. Dictionary<string, string> dic = new Dictionary<string, string>();
  74. for (int i = 0; i < signField.Length; i++)
  75. {
  76. dic.Add(signField[i], json[signField[i]].ToString());
  77. }
  78. string sign = json["sign"].ToString(); //客户端签名字符串
  79. return new Sign().sign(dic, sign);
  80. }
  81. #endregion
  82. }
  83. }