UserLevelSetController.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class UserLevelSetController : BaseController
  18. {
  19. public UserLevelSetController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 我的-职级列表
  23. [Authorize]
  24. public JsonResult List(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = ListDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> ListDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  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. List<Dictionary<string, object>> query = new UserLevelSetService().List(new List<FieldItem>(), "", PageNum, PageSize);
  38. foreach (var subdata in query)
  39. {
  40. Dictionary<string, object> curData = new Dictionary<string, object>();
  41. curData.Add("Name", subdata["Name"].ToString()); //等级名称
  42. curData.Add("Id", subdata["Id"].ToString()); //Id
  43. dataList.Add(curData);
  44. }
  45. return dataList;
  46. }
  47. #endregion
  48. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  49. /// <summary>
  50. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  51. /// </summary>
  52. /// <param name="value">请求的参数(json字符串)</param>
  53. /// <param name="signField">要签名的字段</param>
  54. /// <returns></returns>
  55. private string CheckSign(string value, string[] signField)
  56. {
  57. JsonData json = JsonMapper.ToObject(value);
  58. Dictionary<string, string> dic = new Dictionary<string, string>();
  59. for (int i = 0; i < signField.Length; i++)
  60. {
  61. dic.Add(signField[i], json[signField[i]].ToString());
  62. }
  63. string sign = json["sign"].ToString(); //客户端签名字符串
  64. return new Sign().sign(dic, sign);
  65. }
  66. #endregion
  67. }
  68. }