SchoolSignInRecordController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 SchoolSignInRecordController : BaseController
  18. {
  19. public SchoolSignInRecordController(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 UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  35. string Month = data["Month"].ToString(); //月份
  36. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  37. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  38. var a = Month.Substring(0, 3);
  39. var b = Month.Substring(Month.Length - 2);
  40. var time = a + "-" + b;
  41. DateTime start = DateTime.Parse(time + "-01 00:00:00");
  42. DateTime end = start.AddMonths(1);
  43. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  44. IQueryable<SchoolSignInRecord> query = maindb.SchoolSignInRecord.Where(m => m.Status > -1 && m.CreateDate >= start && m.CreateDate < end);
  45. if (!string.IsNullOrEmpty(data["UserId"].ToString()))
  46. {
  47. query = query.Where(m => m.UserId == UserId);
  48. }
  49. int TotalCount = query.Count();
  50. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  51. if (PageNum == 1)
  52. {
  53. query = query.Take(PageSize);
  54. }
  55. else
  56. {
  57. int skipNum = PageSize * (PageNum - 1);
  58. query = query.Skip(skipNum).Take(PageSize);
  59. }
  60. var mydata = query.ToList();
  61. foreach (var subdata in mydata)
  62. {
  63. Dictionary<string, object> curData = new Dictionary<string, object>();
  64. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  65. dataList.Add(curData);
  66. }
  67. return dataList;
  68. }
  69. #endregion
  70. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  71. /// <summary>
  72. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  73. /// </summary>
  74. /// <param name="value">请求的参数(json字符串)</param>
  75. /// <param name="signField">要签名的字段</param>
  76. /// <returns></returns>
  77. private string CheckSign(string value, string[] signField)
  78. {
  79. JsonData json = JsonMapper.ToObject(value);
  80. Dictionary<string, string> dic = new Dictionary<string, string>();
  81. for (int i = 0; i < signField.Length; i++)
  82. {
  83. dic.Add(signField[i], json[signField[i]].ToString());
  84. }
  85. string sign = json["sign"].ToString(); //客户端签名字符串
  86. return new Sign().sign(dic, sign);
  87. }
  88. #endregion
  89. }
  90. }