地铁二期项目正式开始

BaseController.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. 
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. using YTSoft.BaseCallCenter.Model;
  10. using YTSoft.BaseCallCenter.MVCWeb.Models;
  11. using YTSoft.Common;
  12. namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
  13. {
  14. public class BaseController : Controller
  15. {
  16. //字典表
  17. BLL.T_Sys_DictionaryValue dicValueBll = new BLL.T_Sys_DictionaryValue();
  18. BLL.T_Sys_SystemConfig bll_T_Sys_SystemConfig = new BLL.T_Sys_SystemConfig();
  19. BLL.T_Com_LogAction busLog = new BLL.T_Com_LogAction();
  20. #region 登录用户信息
  21. private int _f_UserID;
  22. private string _userName;
  23. private string _f_UserCode;
  24. private int _roleId;
  25. private int _f_DeptId;
  26. private string _f_Telephone;
  27. private bool _f_SeatFlag;
  28. /// <summary>
  29. /// 用户id
  30. /// </summary>
  31. public int F_UserID
  32. {
  33. get
  34. {
  35. //从cookie集合中读取用户信息
  36. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  37. if (loginInfoCookies != null)
  38. {
  39. _f_UserID = int.Parse(loginInfoCookies.Values["F_UserID"]);
  40. }
  41. return _f_UserID;
  42. }
  43. set { _f_UserID = value; }
  44. }
  45. /// <summary>
  46. /// 用户账号
  47. /// </summary>
  48. public string F_UserCode
  49. {
  50. get
  51. {
  52. //从cookie集合中读取用户信息
  53. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  54. if (loginInfoCookies != null)
  55. {
  56. _f_UserCode = loginInfoCookies.Values["F_UserCode"];
  57. }
  58. return _f_UserCode;
  59. }
  60. set { _f_UserCode = value; }
  61. }
  62. /// <summary>
  63. /// 部门Id
  64. /// </summary>
  65. public int F_DeptId
  66. {
  67. get
  68. {
  69. //从cookie集合中读取用户信息
  70. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  71. if (loginInfoCookies != null)
  72. {
  73. _f_DeptId = int.Parse(loginInfoCookies.Values["F_DeptId"]);
  74. }
  75. return _f_DeptId;
  76. }
  77. set { _f_DeptId = value; }
  78. }
  79. /// <summary>
  80. /// 用户名
  81. /// </summary>
  82. public string F_UserName
  83. {
  84. get
  85. {
  86. //从cookie集合中读取用户信息
  87. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  88. if (loginInfoCookies != null)
  89. {
  90. _userName = HttpUtility.UrlDecode(HttpUtility.UrlDecode(loginInfoCookies.Values["F_UserName"], Encoding.UTF8));
  91. }
  92. return _userName;
  93. }
  94. set { _userName = value; }
  95. }
  96. /// <summary>
  97. /// 电话
  98. /// </summary>
  99. public string F_Telephone
  100. {
  101. get
  102. {
  103. //从cookie集合中读取用户信息
  104. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  105. if (loginInfoCookies != null)
  106. {
  107. _f_Telephone = loginInfoCookies.Values["F_Telephone"];
  108. }
  109. return _f_Telephone;
  110. }
  111. set { _f_Telephone = value; }
  112. }
  113. /// <summary>
  114. /// 角色Id
  115. /// </summary>
  116. public int F_RoleID
  117. {
  118. get
  119. {
  120. //从cookie集合中读取用户信息
  121. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  122. if (loginInfoCookies != null)
  123. {
  124. _roleId = int.Parse(loginInfoCookies.Values["F_RoleID"]);
  125. }
  126. return _roleId;
  127. }
  128. set { _roleId = value; }
  129. }
  130. private int _f_Id;
  131. /// <summary>
  132. ///微信微博映射id
  133. /// </summary>
  134. public int F_PId
  135. {
  136. get
  137. {
  138. //从cookie集合中读取用户信息
  139. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  140. if (loginInfoCookies != null)
  141. {
  142. _f_Id = loginInfoCookies.Values["F_PId"].ToInt32();
  143. }
  144. return _f_Id;
  145. }
  146. set { _f_Id = value; }
  147. }
  148. /// <summary>
  149. /// 坐席标志
  150. /// </summary>
  151. public bool F_SeatFlag
  152. {
  153. get
  154. {
  155. //从cookie集合中读取用户信息
  156. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];
  157. if (loginInfoCookies != null)
  158. {
  159. _f_SeatFlag = bool.Parse(loginInfoCookies.Values["F_SeatFlag"]);
  160. }
  161. return _f_SeatFlag;
  162. }
  163. set { _f_SeatFlag = value; }
  164. }
  165. #endregion
  166. #region 验证用户是否已经登录
  167. /// <summary>
  168. /// Action执行前判断
  169. /// </summary>
  170. /// <param name="filterContext"></param>
  171. protected override void OnActionExecuting(ActionExecutingContext filterContext)
  172. {
  173. if (!this.checkLogin())// 判断是否登录
  174. {
  175. filterContext.Result = RedirectToRoute("Default", new { Controller = "Default", Action = "SSO" });
  176. }
  177. base.OnActionExecuting(filterContext);
  178. }
  179. /// <summary>
  180. /// 判断是否登录
  181. /// </summary>
  182. protected bool checkLogin()
  183. {
  184. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];//用户信息
  185. if (loginInfoCookies != null)
  186. {
  187. return true;
  188. }
  189. else
  190. {
  191. return false;
  192. }
  193. }
  194. /// <summary>
  195. /// 退出登录
  196. /// </summary>
  197. /// <returns></returns>
  198. public void Exit()
  199. {
  200. HttpCookie loginInfoCookies = Request.Cookies["BaseCallCenter_T_User"];//用户信息
  201. if (loginInfoCookies != null)
  202. {
  203. loginInfoCookies.Expires = DateTime.Now.AddDays(-1);
  204. Response.Cookies.Add(loginInfoCookies);
  205. }
  206. }
  207. #endregion
  208. #region 公共方法
  209. #region 获取业务类型
  210. /// <summary>
  211. /// 获取业务类型
  212. /// </summary>
  213. public List<Model.T_Wo_WorkOrderType> GetWorkTypeModelList()
  214. {
  215. //最终需要返回的菜单
  216. List<Model.T_Wo_WorkOrderType> newModelList = new List<T_Wo_WorkOrderType>();
  217. Model.PageData<Model.T_Wo_WorkOrderType> pageModel = new Model.PageData<Model.T_Wo_WorkOrderType>();
  218. BLL.T_Wo_WorkOrderType bll = new BLL.T_Wo_WorkOrderType();
  219. //获取业务类型列表
  220. List<Model.T_Wo_WorkOrderType> WorkTypeModelList = bll.GetModelList("");
  221. if (WorkTypeModelList != null && WorkTypeModelList.Count > 0)
  222. {
  223. //获取默认根节点
  224. Model.T_Wo_WorkOrderType rootNode = WorkTypeModelList.FirstOrDefault(m => m.F_ParentId == 0);
  225. //获取一级节点
  226. List<Model.T_Wo_WorkOrderType> rootModelList = WorkTypeModelList.Where(t => t.F_ParentId == rootNode.F_WorkOrderTypeId).ToList();
  227. if (rootModelList != null && rootModelList.Count > 0)
  228. {
  229. foreach (T_Wo_WorkOrderType WorkOrderTypeModel in rootModelList)
  230. {
  231. List<Model.T_Wo_WorkOrderType> nullModelList = new List<T_Wo_WorkOrderType>();
  232. WorkOrderTypeModel.WorkTypeModelList = nullModelList;
  233. newModelList.Add(GetWorkTypeModelChild(WorkOrderTypeModel, WorkOrderTypeModel, WorkTypeModelList));
  234. }
  235. }
  236. }
  237. return newModelList;
  238. }
  239. //获取所有子集
  240. public Model.T_Wo_WorkOrderType GetWorkTypeModelChild(T_Wo_WorkOrderType rootNode, T_Wo_WorkOrderType WorkOrderTypeModel, List<Model.T_Wo_WorkOrderType> WorkTypeModelList)
  241. {
  242. //获取子集节点
  243. List<Model.T_Wo_WorkOrderType> sonModelList = WorkTypeModelList.Where(t => t.F_ParentId == WorkOrderTypeModel.F_WorkOrderTypeId).ToList();
  244. if (sonModelList != null && sonModelList.Count > 0)
  245. {
  246. foreach (T_Wo_WorkOrderType workOrderTypeModel in sonModelList)
  247. {
  248. //获取子子集
  249. List<Model.T_Wo_WorkOrderType> childModelList = WorkTypeModelList.Where(t => t.F_ParentId == workOrderTypeModel.F_WorkOrderTypeId).ToList();
  250. if (childModelList != null && childModelList.Count > 0)
  251. {
  252. GetWorkTypeModelChild(rootNode, workOrderTypeModel, WorkTypeModelList);
  253. }
  254. else
  255. {
  256. rootNode.WorkTypeModelList.Add(workOrderTypeModel);
  257. }
  258. }
  259. }
  260. return rootNode;
  261. }
  262. #endregion
  263. #region 获取处理类型字典
  264. /// <summary>
  265. /// 获取处理类型字典
  266. /// </summary>
  267. /// <returns></returns>
  268. public List<T_Sys_DictionaryValue> GetCodeType(string dicCodeType)
  269. {
  270. return dicValueBll.GetModelList("F_DictionaryFlag='" + dicCodeType + "'");
  271. }
  272. #endregion
  273. /// <summary>
  274. /// 根据key获取网站基础配置值
  275. /// </summary>
  276. /// <param name="key"></param>
  277. /// <returns></returns>
  278. public string GetSysconfig(string key)
  279. {
  280. return bll_T_Sys_SystemConfig.GetParamValueByParamCode(key);
  281. }
  282. /// <summary>
  283. /// 数据库日志
  284. /// </summary>
  285. /// <param name="TableName"></param>
  286. /// <param name="id"></param>
  287. /// <param name="ActionName"></param>
  288. /// <param name="oldobj"></param>
  289. /// <param name="newobj"></param>
  290. /// <returns></returns>
  291. public bool AddLog(string TableName, string id,string ActionName,string oldobj,object newobj)
  292. {
  293. Model.T_Com_LogAction modellog = new T_Com_LogAction();
  294. modellog.ActionName = ActionName;
  295. modellog.AddUser = HttpUtility.UrlDecode(F_UserName);
  296. modellog.AddUserId = F_UserID;
  297. modellog.Atime = DateTime.Now;
  298. modellog.ActionUrl = string.Format("/{0}/{1}", RouteData.Values["controller"], RouteData.Values["action"]);
  299. modellog.ContentNew = newobj == null ? "":JsonConvert.SerializeObject(newobj);
  300. modellog.ContentOld = oldobj == null ? "": oldobj;
  301. modellog.TableId = id;
  302. modellog.TableName = TableName.ToLower();
  303. return busLog.Add(modellog);
  304. }
  305. /// <summary>
  306. ///
  307. /// </summary>
  308. /// <param name="TableName"></param>
  309. /// <param name="id"></param>
  310. /// <param name="ActionName"></param>
  311. /// <param name="oldobj"></param>
  312. /// <param name="ContentNew">操作记录 敏感信息 主要设置</param>
  313. /// <returns></returns>
  314. public bool AddAction(string TableName, string id, string ActionName, string oldobj="",string ContentNew= "操作记录")
  315. {
  316. Model.T_Com_LogAction modellog = new T_Com_LogAction();
  317. modellog.ActionName = ActionName;
  318. modellog.AddUser = HttpUtility.UrlDecode(F_UserName);
  319. modellog.AddUserId = F_UserID;
  320. modellog.Atime = DateTime.Now;
  321. modellog.ActionUrl = string.Format("/{0}/{1}", RouteData.Values["controller"], RouteData.Values["action"]);
  322. modellog.ContentNew = ContentNew;
  323. modellog.ContentOld = oldobj.ToMyString();
  324. modellog.TableId = id.ToMyString();
  325. modellog.TableName = TableName.ToLower();
  326. return busLog.Add(modellog);
  327. }
  328. #endregion
  329. #region 公共返回参数
  330. /// <summary>
  331. /// 成功的消息格式化
  332. /// </summary>
  333. /// <param name="message"></param>
  334. /// <param name="data"></param>
  335. /// <returns></returns>
  336. protected virtual string Success(string message, object data=null,int count=0)
  337. {
  338. var jsonMsg = new ReturnData { code =0, msg = message, data = data ,count= count };
  339. // LogDefault.Info(jsonMsg);
  340. return JsonConvert.SerializeObject(jsonMsg);
  341. }
  342. /// <summary>
  343. /// 成功的消息格式化
  344. /// </summary>
  345. /// <param name="message"></param>
  346. /// <param name="data"></param>
  347. /// <returns></returns>
  348. protected virtual string Success(string message)
  349. {
  350. var jsonMsg = new ReturnData { code = 0, msg = message };
  351. // LogDefault.Info(jsonMsg);
  352. return JsonConvert.SerializeObject(jsonMsg);
  353. }
  354. /// <summary>
  355. /// 错误的消息格式化
  356. /// </summary>
  357. /// <param name="message"></param>
  358. /// <returns></returns>
  359. protected virtual string Error(string message)
  360. {
  361. var jsonMsg = new ReturnData { code = -1, msg = message };
  362. return JsonConvert.SerializeObject(jsonMsg);
  363. }
  364. #endregion
  365. }
  366. }