Нет описания

HomeController.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. 
  2. using CallCenter.Utility;
  3. using CallCenterApi.Common;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using CallCenterApi.Interface.Models.Common;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Data.SqlTypes;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Web;
  15. using System.Web.Caching;
  16. using System.Web.Mvc;
  17. namespace CallCenterApi.Interface.Controllers
  18. {
  19. public class HomeController : BaseController
  20. {
  21. [AllowAnonymous]
  22. public ActionResult TestSms() {
  23. //bool v = new SMSNewController().AddSmS( 1963441, userId, count, mag, u.F_Mobile);
  24. string workorderid = "2025-06-16-1";
  25. string mag = "[\"" + workorderid + "\"]";
  26. string v= SMSNewController .AddSmS(1, "测试发送", "15639002755", "1132299838815801344", mag , workorderid);
  27. return Success("成功",v);
  28. }
  29. // GET: Home
  30. public ActionResult Index()
  31. {
  32. return Success("成功");
  33. }
  34. [Authorize]
  35. public JsonResult json1()
  36. {
  37. var person = new
  38. {
  39. Name = "张三",
  40. Age = 22,
  41. Sex = "男"
  42. };
  43. return Json(person, JsonRequestBehavior.AllowGet);
  44. }
  45. public string json2()
  46. {
  47. var person = new
  48. {
  49. Name = "张三",
  50. Age = 22,
  51. Sex = "男",
  52. Date = DateTime.Now
  53. };
  54. return person.ToJson();
  55. }
  56. public string json2_()
  57. {
  58. var tt = new
  59. {
  60. exp = 20,
  61. money = 12
  62. };
  63. var person = new
  64. {
  65. Name = "张三",
  66. Age = 22,
  67. Sex = "男",
  68. other = tt,
  69. Date = DateTime.Now
  70. };
  71. return person.ToJson();
  72. }
  73. /// <summary>
  74. /// 演示 查询出来datatable的数据进行展示
  75. /// </summary>
  76. /// <returns></returns>
  77. public string json3()
  78. {
  79. DataTable tblDatas = new DataTable("Datas");
  80. DataColumn dc = null;
  81. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  82. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  83. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  84. DataRow newRow;
  85. newRow = tblDatas.NewRow();
  86. newRow["Product"] = "大话西游";
  87. newRow["Version"] = "2.0";
  88. newRow["Description"] = "我很喜欢";
  89. tblDatas.Rows.Add(newRow);
  90. newRow = tblDatas.NewRow();
  91. newRow["Product"] = "梦幻西游";
  92. newRow["Version"] = "3.0";
  93. newRow["Description"] = "比大话更幼稚";
  94. tblDatas.Rows.Add(newRow);
  95. return tblDatas.ToJson();
  96. }
  97. public ActionResult json3_()
  98. {
  99. DataTable tblDatas = new DataTable("Datas");
  100. DataColumn dc = null;
  101. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  102. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  103. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  104. DataRow newRow;
  105. newRow = tblDatas.NewRow();
  106. newRow["Product"] = "大话西游";
  107. newRow["Version"] = "2.0";
  108. newRow["Description"] = "我很喜欢";
  109. tblDatas.Rows.Add(newRow);
  110. newRow = tblDatas.NewRow();
  111. newRow["Product"] = "梦幻西游";
  112. newRow["Version"] = "3.0";
  113. newRow["Description"] = "比大话更幼稚";
  114. tblDatas.Rows.Add(newRow);
  115. return Success("成功", tblDatas);
  116. }
  117. public ActionResult excel()
  118. {
  119. DataTable tblDatas = new DataTable("Datas");
  120. DataColumn dc = null;
  121. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  122. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  123. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  124. DataRow newRow;
  125. newRow = tblDatas.NewRow();
  126. newRow["Product"] = "大话西游";
  127. newRow["Version"] = "2.0";
  128. newRow["Description"] = "我很喜欢";
  129. tblDatas.Rows.Add(newRow);
  130. newRow = tblDatas.NewRow();
  131. newRow["Product"] = "梦幻西游";
  132. newRow["Version"] = "3.0";
  133. newRow["Description"] = "比大话更幼稚";
  134. tblDatas.Rows.Add(newRow);
  135. NPOIHelper npoi = new NPOIHelper();
  136. string[] s = { "列1", "列2", "列3" };
  137. if (npoi.ToExcel(tblDatas, "test", null, "D:/2.xlsx", s))
  138. {
  139. return Success("成功", tblDatas);
  140. }
  141. else
  142. {
  143. return Error("导出失败");
  144. }
  145. }
  146. public ActionResult excel1()
  147. {
  148. DataTable tblDatas = new DataTable("Datas");
  149. DataColumn dc = null;
  150. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  151. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  152. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
  153. DataRow newRow;
  154. newRow = tblDatas.NewRow();
  155. newRow["Product"] = "大话西游";
  156. newRow["Version"] = "2.0";
  157. newRow["Description"] = "我很喜欢";
  158. tblDatas.Rows.Add(newRow);
  159. newRow = tblDatas.NewRow();
  160. newRow["Product"] = "梦幻西游";
  161. newRow["Version"] = "3.0";
  162. newRow["Description"] = "比大话更幼稚";
  163. tblDatas.Rows.Add(newRow);
  164. NPOIHelper npoi = new NPOIHelper();
  165. if (npoi.ExportToExcel("test", tblDatas) == "")
  166. {
  167. return Success("成功", tblDatas);
  168. }
  169. else
  170. {
  171. return Error("导出失败");
  172. }
  173. }
  174. public ActionResult error()
  175. {
  176. return Error("不具备权限");
  177. }
  178. public string ss()
  179. {
  180. return "ss";
  181. }
  182. public string tt(string name, string pass)
  183. {
  184. return "sss " + name + pass;
  185. }
  186. /// <summary>
  187. /// 抛出HTTP 500
  188. /// </summary>
  189. /// <returns></returns>
  190. public ActionResult ThrowHttp500()
  191. {
  192. throw new HttpException(500, "服务器错误");
  193. }
  194. /// <summary>
  195. /// 抛出HTTP 404
  196. /// </summary>
  197. /// <returns></returns>
  198. public ActionResult ThrowHttp404()
  199. {
  200. throw new HttpException(404, "页面未找到");
  201. }
  202. /// <summary>
  203. /// 抛出未引用对象异常
  204. /// ,此处单独使用HandleError特性
  205. /// ,并指定异常类型及响应视图
  206. /// </summary>
  207. /// <returns></returns>
  208. [HandleError(ExceptionType = typeof(NullReferenceException), View = "CustomError")]
  209. public ActionResult ThrowNullReferenceException()
  210. {
  211. throw new NullReferenceException();
  212. }
  213. /// <summary>
  214. /// 引发输入字符串的格式不正确异常
  215. /// ,此处指定了响应的错误页面
  216. /// ,由于是不同的控制器所以要完整的相对路径
  217. /// </summary>
  218. /// <returns></returns>
  219. [HandleError(View = "~/Views/Error/CustomHttpError.cshtml")]
  220. public ActionResult ThrowFormatException()
  221. {
  222. string str = "";
  223. int count = Convert.ToInt32(str);
  224. return View("Index");
  225. }
  226. public ActionResult GetRedis(string key)
  227. {
  228. List<object> caches = new List<object>();
  229. var keys = RedisHelper.GetKeyList(string.IsNullOrEmpty(key) ? "" : key);
  230. foreach (var k in keys)
  231. {
  232. caches.Add(new
  233. {
  234. key = k,
  235. value = RedisHelper.StringGet(k),
  236. outtime=RedisHelper.GetKeyOutTime(k)
  237. });
  238. }
  239. return Success("成功", caches);
  240. }
  241. public ActionResult UpdateRedis(string key, string value, int second = 10)
  242. {
  243. List<object> caches = new List<object>();
  244. var keys = RedisHelper.GetKeyList(string.IsNullOrEmpty(key) ? "" : key);
  245. foreach (var k in keys)
  246. {
  247. RedisHelper.StringSet(k, value, new TimeSpan(0, 0, second));
  248. }
  249. return Success("成功");
  250. }
  251. public ActionResult DeleteRedis(string key)
  252. {
  253. List<object> caches = new List<object>();
  254. var keys = RedisHelper.GetKeyList(string.IsNullOrEmpty(key) ? "" : key);
  255. long n = RedisHelper.KeysDelete(keys);
  256. return Success("成功", n);
  257. }
  258. public ActionResult GetAllCache()
  259. {
  260. System.Web.Caching.Cache cache = HttpRuntime.Cache;
  261. IDictionaryEnumerator cacheEnum = cache.GetEnumerator();
  262. List<cacheobj> caches = new List<cacheobj>();
  263. StringBuilder sb = new StringBuilder();
  264. while (cacheEnum.MoveNext())
  265. {
  266. Dictionary<string, string> dic = null;
  267. try
  268. {
  269. dic = (Dictionary<string, string>)cacheEnum.Value;
  270. }
  271. catch
  272. {
  273. continue;
  274. }
  275. sb.Append($"F_UserID={dic["F_UserID"]}, ");
  276. sb.Append($"F_UserCode={dic["F_UserCode"]}, ");
  277. sb.Append($"F_UserName={dic["F_UserName"]} ");
  278. caches.Add(new cacheobj
  279. {
  280. key = cacheEnum.Key.ToString().Substring(0, 20),
  281. value = sb.ToString()
  282. });
  283. sb.Clear();
  284. }
  285. return Success("", new
  286. {
  287. count = caches.Count(),
  288. });
  289. }
  290. //public ActionResult MakeCache()
  291. //{
  292. // while (true)
  293. // {
  294. // Dictionary<string, string> Dic = new Dictionary<string, string>();
  295. // Dic.Add("F_UserID", "1411");
  296. // Dic.Add("F_UserCode", "8000");
  297. // Dic.Add("F_DeptId", "1");
  298. // Dic.Add("F_UserName", "系统管理员");
  299. // Dic.Add("F_Telephone", "15537150907");
  300. // Dic.Add("F_RoleID", "1");
  301. // Dic.Add("F_SeatFlag", "1");
  302. // new CallCenterApi.BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  303. // {
  304. // F_LoginName = "8000",
  305. // F_LoginId = 1411,
  306. // F_Result = "登录成功",
  307. // F_LoginIP = Common.DTRequest.GetIP(),
  308. // F_Hostname = Common.DTRequest.GetIP(),
  309. // F_LoginDate = DateTime.Now,
  310. // F_Remark = "",
  311. // F_State = 0
  312. // });
  313. // var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
  314. // //放入缓存
  315. // CacheHelper.Insert(token, Dic, 2880, System.Web.Caching.CacheItemPriority.NotRemovable);
  316. // Response.Write(token.Substring(0, 20) + "</n>");
  317. // }
  318. //}
  319. public ActionResult TestCache()
  320. {
  321. int n = 0;
  322. while (n<100)
  323. {
  324. Dictionary<string, string> Dic = new Dictionary<string, string>();
  325. Dic.Add("F_UserID", (1000 + n).ToString());
  326. Dic.Add("F_UserCode", (8000+n).ToString());
  327. Dic.Add("F_DeptId", "1");
  328. Dic.Add("F_UserName", "系统管理员" + n);
  329. Dic.Add("F_Telephone", "15537150907");
  330. Dic.Add("F_RoleID", "1");
  331. Dic.Add("F_SeatFlag", "1");
  332. var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
  333. CacheItemRemovedCallback cacheItemRemovedCallback = new CacheItemRemovedCallback(onRemove);
  334. //放入缓存
  335. CacheHelper.Insert(token, Dic, 1, System.Web.Caching.CacheItemPriority.NotRemovable, cacheItemRemovedCallback);
  336. n++;
  337. }
  338. return Success(n.ToString());
  339. }
  340. /// <summary>
  341. /// 移除缓存后调用
  342. /// </summary>
  343. /// <param name="key"></param>
  344. /// <param name="val"></param>
  345. /// <param name="reason"></param>
  346. public void onRemove(string key, object val, CacheItemRemovedReason reason)
  347. {
  348. var obj = new
  349. {
  350. key = key,
  351. val = val,
  352. reason = reason
  353. };
  354. Error(obj.ToJson());
  355. }
  356. }
  357. public class cacheobj
  358. {
  359. public string key { get; set; }
  360. public string value { get; set; }
  361. }
  362. }