| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- using RMYY_CallCenter_Api.DB;
- using RMYY_CallCenter_Api.Model;
- using RMYY_CallCenter_Api.Models;
- using RMYY_CallCenter_Api.Utility;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace RMYY_CallCenter_Api.Controllers
- {
- [AllowAnonymous]
- public class HomeController : BaseController
- {
- public ActionResult Index()
- {
- return Content("hello world!");
- }
- public ActionResult Daochu()
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("code");
- dt.Columns.Add("name");
- DataRow dr = dt.NewRow();
- dr["code"] = "asd";
- dr["name"] = "咋说";
- dt.Rows.Add(dr);
- new NPOIHelper().ExportToExcel2("123", dt);
- return Content("hello world!");
- }
- /// <summary>
- /// 登录
- /// </summary>
- /// <param name="usercode"></param>
- /// <param name="password"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Login(string usercode, string password)
- {
- Dictionary<string, string> paras = new Dictionary<string, string>();
- string sql = " select * from T_Sys_UserAccount where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord";
- paras.Add("@F_UserCode", usercode);
- paras.Add("@F_PassWord", password);
- var dt = DbHelperSQL.Query(sql, paras).Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- var dr = dt.Rows[0];
- if (dr["F_EnableFlag"]?.ToString() == "0")
- {
- return Error("此账号已经被禁用");
- }
-
- Dictionary<string, string> Dic = new Dictionary<string, string>();
- Dic.Add("F_UserCode", dr["F_UserCode"].ToString());
- Dic.Add("F_RoleId", dr["F_RoleId"].ToString());
- Dic.Add("F_DeptId", dr["F_DeptId"].ToString());
- var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
- AddLogAsync(dr["F_UserName"].ToString(), dr["F_UserCode"].ToString(), "登录成功", "", 1);
- return Success("登录成功", token);
- }
- else
- {
- return Error("账号或密码错误");
- }
- }
- /// <summary>
- /// 钉钉获取UserId
- /// </summary>
- /// <param name="mobile"></param>
- /// <returns></returns>
- public ActionResult DingTalkGetUserIdByMobile(string mobile)
- {
- return Success(DingTalkHelper.GetUserIdByMobile(mobile));
- }
- /// <summary>
- /// 钉钉发送消息
- /// </summary>
- /// <param name="userid"></param>
- /// <param name="content"></param>
- /// <returns></returns>
- public ActionResult DingTalkSendMessageText(string userid,string content)
- {
- return Success(DingTalkHelper.SendMessageText(userid, "", content));
- }
- /// <summary>
- /// 钉钉发送模板消息
- /// </summary>
- /// <param name="userid"></param>
- /// <param name="msgjson"></param>
- /// <param name="templateid"></param>
- /// <returns></returns>
- public ActionResult DingTalkSendMessageTemplate(string userid, string msgjson, string templateid)
- {
- return Success(DingTalkHelper.SendMessageByTemplate(userid, "", msgjson, templateid));
- }
- /// <summary>
- /// 存储登录日志
- /// </summary>
- /// <param name="name"></param>
- /// <param name="code"></param>
- /// <param name="log"></param>
- /// <param name="ip"></param>
- /// <param name="channel"></param>
- /// <returns></returns>
- private int AddLogAsync(string name, string code, string log, string ip, int channel)
- {
- RMYY_CallCenter_Api.Bll.T_Sys_Login_Logs bll = new RMYY_CallCenter_Api.Bll.T_Sys_Login_Logs();
- var login_log = new T_Sys_Login_Logs()
- {
- T_username = name,
- T_usercode = code,
- T_result = log,
- T_login_ip = ip,
- T_channel = channel,
- T_time = DateTime.Now
- };
- return bll.Add(login_log);
- }
- public ActionResult GetLoginLogList(string username, string starttime = "", string endtime = "", int pageindex = 1, int pagesize = 10)
- {
- DataTable datatable= new DataTable();
-
- string sql = " 1=1";
- int recordCount = 0;
- if (!string.IsNullOrEmpty(username))
- {
- sql += " and T_username='" + username + "'";
-
- }
- if (starttime.Trim() != "" && starttime != "undefined")
- sql += " and datediff(day,T_time,'" + starttime + "')<=0";
- if (endtime.Trim() != "" && endtime != "undefined")
- sql += " and datediff(day,T_time,'" + endtime + "')>=0";
- datatable = Bll.PagerBll.GetListPager
- ("T_Sys_Login_Logs ",
- "T_id",
- "*",
- sql,
- "order by T_id desc",
- pagesize,
- pageindex,
- true,
- out recordCount
- );
-
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = datatable,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- public ActionResult DingTalkGetDeUserInfoByUserid(string userid)
- {
- return Content(DingTalkHelper.GetUserInfoByUserId(userid));
- }
- public ActionResult DingTalkGetDeptlist()
- {
- return Content(DingTalkHelper.GetDeptlist());
- }
-
- public ActionResult DingTalkGetUserIdsByDeptId(double deptid)
- {
- return Content(DingTalkHelper.GetUserIdsByDeptId(deptid));
- }
- }
- }
|