人民医院API

HomeController.cs 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using RMYY_CallCenter_Api.DB;
  2. using RMYY_CallCenter_Api.Model;
  3. using RMYY_CallCenter_Api.Models;
  4. using RMYY_CallCenter_Api.Utility;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace RMYY_CallCenter_Api.Controllers
  12. {
  13. [AllowAnonymous]
  14. public class HomeController : BaseController
  15. {
  16. public ActionResult Index()
  17. {
  18. return Content("hello world!");
  19. }
  20. public ActionResult Daochu()
  21. {
  22. DataTable dt = new DataTable();
  23. dt.Columns.Add("code");
  24. dt.Columns.Add("name");
  25. DataRow dr = dt.NewRow();
  26. dr["code"] = "asd";
  27. dr["name"] = "咋说";
  28. dt.Rows.Add(dr);
  29. new NPOIHelper().ExportToExcel2("123", dt);
  30. return Content("hello world!");
  31. }
  32. /// <summary>
  33. /// 登录
  34. /// </summary>
  35. /// <param name="usercode"></param>
  36. /// <param name="password"></param>
  37. /// <returns></returns>
  38. [HttpPost]
  39. public ActionResult Login(string usercode, string password)
  40. {
  41. Dictionary<string, string> paras = new Dictionary<string, string>();
  42. string sql = " select * from T_Sys_UserAccount where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord";
  43. paras.Add("@F_UserCode", usercode);
  44. paras.Add("@F_PassWord", password);
  45. var dt = DbHelperSQL.Query(sql, paras).Tables[0];
  46. if (dt != null && dt.Rows.Count > 0)
  47. {
  48. var dr = dt.Rows[0];
  49. if (dr["F_EnableFlag"]?.ToString() == "0")
  50. {
  51. return Error("此账号已经被禁用");
  52. }
  53. Dictionary<string, string> Dic = new Dictionary<string, string>();
  54. Dic.Add("F_UserCode", dr["F_UserCode"].ToString());
  55. Dic.Add("F_RoleId", dr["F_RoleId"].ToString());
  56. Dic.Add("F_DeptId", dr["F_DeptId"].ToString());
  57. var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
  58. AddLogAsync(dr["F_UserName"].ToString(), dr["F_UserCode"].ToString(), "登录成功", "", 1);
  59. return Success("登录成功", token);
  60. }
  61. else
  62. {
  63. return Error("账号或密码错误");
  64. }
  65. }
  66. /// <summary>
  67. /// 钉钉获取UserId
  68. /// </summary>
  69. /// <param name="mobile"></param>
  70. /// <returns></returns>
  71. public ActionResult DingTalkGetUserIdByMobile(string mobile)
  72. {
  73. return Success(DingTalkHelper.GetUserIdByMobile(mobile));
  74. }
  75. /// <summary>
  76. /// 钉钉发送消息
  77. /// </summary>
  78. /// <param name="userid"></param>
  79. /// <param name="content"></param>
  80. /// <returns></returns>
  81. public ActionResult DingTalkSendMessageText(string userid,string content)
  82. {
  83. return Success(DingTalkHelper.SendMessageText(userid, "", content));
  84. }
  85. /// <summary>
  86. /// 钉钉发送模板消息
  87. /// </summary>
  88. /// <param name="userid"></param>
  89. /// <param name="msgjson"></param>
  90. /// <param name="templateid"></param>
  91. /// <returns></returns>
  92. public ActionResult DingTalkSendMessageTemplate(string userid, string msgjson, string templateid)
  93. {
  94. return Success(DingTalkHelper.SendMessageByTemplate(userid, "", msgjson, templateid));
  95. }
  96. /// <summary>
  97. /// 存储登录日志
  98. /// </summary>
  99. /// <param name="name"></param>
  100. /// <param name="code"></param>
  101. /// <param name="log"></param>
  102. /// <param name="ip"></param>
  103. /// <param name="channel"></param>
  104. /// <returns></returns>
  105. private int AddLogAsync(string name, string code, string log, string ip, int channel)
  106. {
  107. RMYY_CallCenter_Api.Bll.T_Sys_Login_Logs bll = new RMYY_CallCenter_Api.Bll.T_Sys_Login_Logs();
  108. var login_log = new T_Sys_Login_Logs()
  109. {
  110. T_username = name,
  111. T_usercode = code,
  112. T_result = log,
  113. T_login_ip = ip,
  114. T_channel = channel,
  115. T_time = DateTime.Now
  116. };
  117. return bll.Add(login_log);
  118. }
  119. public ActionResult GetLoginLogList(string username, string starttime = "", string endtime = "", int pageindex = 1, int pagesize = 10)
  120. {
  121. DataTable datatable= new DataTable();
  122. string sql = " 1=1";
  123. int recordCount = 0;
  124. if (!string.IsNullOrEmpty(username))
  125. {
  126. sql += " and T_username='" + username + "'";
  127. }
  128. if (starttime.Trim() != "" && starttime != "undefined")
  129. sql += " and datediff(day,T_time,'" + starttime + "')<=0";
  130. if (endtime.Trim() != "" && endtime != "undefined")
  131. sql += " and datediff(day,T_time,'" + endtime + "')>=0";
  132. datatable = Bll.PagerBll.GetListPager
  133. ("T_Sys_Login_Logs ",
  134. "T_id",
  135. "*",
  136. sql,
  137. "order by T_id desc",
  138. pagesize,
  139. pageindex,
  140. true,
  141. out recordCount
  142. );
  143. var obj = new
  144. {
  145. state = "success",
  146. message = "成功",
  147. rows = datatable,
  148. total = recordCount
  149. };
  150. return Content(obj.ToJson());
  151. }
  152. public ActionResult DingTalkGetDeUserInfoByUserid(string userid)
  153. {
  154. return Content(DingTalkHelper.GetUserInfoByUserId(userid));
  155. }
  156. public ActionResult DingTalkGetDeptlist()
  157. {
  158. return Content(DingTalkHelper.GetDeptlist());
  159. }
  160. public ActionResult DingTalkGetUserIdsByDeptId(double deptid)
  161. {
  162. return Content(DingTalkHelper.GetUserIdsByDeptId(deptid));
  163. }
  164. }
  165. }