説明なし

InternalMessagesController.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using CallCenterApi.Interface.Controllers.workorder;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. namespace CallCenterApi.Interface.Controllers.information
  13. {
  14. [Authority]
  15. public class InternalMessagesController : BaseController
  16. {
  17. BLL.T_SMS_InternalMessages bll = new BLL.T_SMS_InternalMessages();
  18. /// <summary>
  19. /// 获取所有列表 分页
  20. /// </summary>
  21. /// <returns></returns>
  22. public ActionResult GetAllList()
  23. {
  24. DataTable dt = new DataTable();
  25. string SMS_Title = HttpUtility.UrlDecode(RequestString.GetQueryString("title"));
  26. string SMS_ReceiveUserCode = HttpUtility.UrlDecode(RequestString.GetQueryString("receiveUserCode"));
  27. string SMS_SendUserCode = HttpUtility.UrlDecode(RequestString.GetQueryString("sendUserCode"));
  28. string SMS_Content = HttpUtility.UrlDecode(RequestString.GetQueryString("content"));
  29. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("strstarttime"));
  30. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("strendtime"));
  31. string strpageindex = RequestString.GetQueryString("page");
  32. int pageindex = 1;
  33. string strpagesize = RequestString.GetQueryString("pagesize");
  34. int pagesize = 10;
  35. string sql = string.Empty;
  36. if (SMS_Title.Trim() != "")
  37. {
  38. sql += " and SMS_Title like '%" + SMS_Title + "%'";
  39. }
  40. if (SMS_ReceiveUserCode.Trim() != "")
  41. {
  42. sql += " and SMS_ReceiveUserCode = '" + SMS_ReceiveUserCode + "'";
  43. }
  44. if (SMS_SendUserCode.Trim() != "")
  45. {
  46. sql += " and SMS_SendUserCode = '" + SMS_SendUserCode + "'";
  47. }
  48. if (SMS_Content.Trim() != "")
  49. {
  50. sql += " and SMS_Content like '%" + SMS_Content + "%'";
  51. }
  52. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  53. {
  54. sql += " and datediff(day,SMS_SendUserCode,'" + strstarttime + "')<=0 ";
  55. }
  56. if (strendtime.Trim() != "" && strendtime != "undefined")
  57. {
  58. sql += " and datediff(day,SMS_SendUserCode,'" + strendtime + "')>=0 ";
  59. }
  60. if (strpageindex.Trim() != "")
  61. {
  62. pageindex = Convert.ToInt32(strpageindex);
  63. }
  64. if (strpagesize.Trim() != "")
  65. {
  66. pagesize = Convert.ToInt32(strpagesize);
  67. }
  68. int recordCount = 0;
  69. dt = BLL.PagerBLL.GetListPager(
  70. "T_SMS_InternalMessages",
  71. "F_Id",
  72. "*",
  73. sql,
  74. "ORDER BY SMS_Id desc",
  75. pagesize,
  76. pageindex,
  77. true,
  78. out recordCount);
  79. var obj = new
  80. {
  81. rows = dt,
  82. total = recordCount
  83. };
  84. return Content(obj.ToJson());
  85. }
  86. /// <summary>
  87. /// 获取前几条列表
  88. /// </summary>
  89. /// <returns></returns>
  90. public ActionResult GetTopList()
  91. {
  92. DataTable dt = new DataTable();
  93. string strWhere = string.Empty;
  94. int Top = RequestString.GetInt("top", 5);
  95. string SMS_ReceiveUserCode = RequestString.GetQueryString("receiveUserCode");
  96. if (SMS_ReceiveUserCode.Trim() != "")
  97. {
  98. strWhere += " and SMS_ReceiveUserCode = '" + SMS_ReceiveUserCode + "'";
  99. }
  100. dt = bll.GetList(Top, strWhere, " SMS_Order,SMS_SendTime ").Tables[0];
  101. var obj = new
  102. {
  103. rows = dt,
  104. total = Top
  105. };
  106. return Content(obj.ToJson());
  107. }
  108. /// <summary>
  109. /// 获取一条详细信息
  110. /// </summary>
  111. /// <param name="infoid"></param>
  112. /// <returns></returns>
  113. public ActionResult GetInfo(string infoid)
  114. {
  115. if (infoid != null && infoid.Trim() != "")
  116. {
  117. Model.T_SMS_InternalMessages model = bll.GetModel(int.Parse(infoid.Trim()));
  118. if (model != null)
  119. {
  120. if (model.SMS_IsRead == 0)
  121. {
  122. model.SMS_IsRead = 1;
  123. model.SMS_ReadTime = DateTime.Now;
  124. bool b = bll.Update(model);
  125. if (b)
  126. {
  127. return Success("获取成功", model);
  128. }
  129. else
  130. {
  131. return Error("获取失败,无更新权限");
  132. }
  133. }
  134. else {
  135. return Success("获取成功", model);
  136. }
  137. }
  138. else
  139. {
  140. return Error("获取失败");
  141. };
  142. }
  143. else
  144. {
  145. return Error("获取参数失败");
  146. }
  147. }
  148. /// <summary>
  149. /// 保存信息
  150. /// </summary>
  151. /// <returns></returns>
  152. public ActionResult SaveInfo()
  153. {
  154. int id = RequestString.GetInt("id", 0);
  155. string SMS_Title = RequestString.GetFormString("title");
  156. string SMS_ReceiveUserCode = RequestString.GetFormString("receiveUserCode");
  157. string SMS_SendUserCode = RequestString.GetFormString("sendUserCode");
  158. string SMS_Content = RequestString.GetFormString("content");
  159. int SMS_IsDelete = RequestString.GetInt("isDelete", 0);
  160. int SMS_IsRead = RequestString.GetInt("isRead", 0);
  161. int SMS_Order = RequestString.GetInt("order", 0);
  162. int SMS_IsTop = RequestString.GetInt("isTop", 0);
  163. int SMS_Type = RequestString.GetInt("smstype", 0);
  164. if (!string.IsNullOrWhiteSpace(SMS_Title) || !string.IsNullOrWhiteSpace(SMS_ReceiveUserCode) || !string.IsNullOrWhiteSpace(SMS_ReceiveUserCode))
  165. {
  166. Model.T_SMS_InternalMessages model = new Model.T_SMS_InternalMessages();
  167. if (id == 0)
  168. {
  169. model.SMS_Title = SMS_Title;
  170. model.SMS_Content = SMS_Content;
  171. model.SMS_ReceiveUserCode = SMS_ReceiveUserCode;
  172. model.SMS_SendUserCode = SMS_SendUserCode;
  173. model.SMS_IsRead = SMS_IsRead;
  174. model.SMS_SendTime = DateTime.Now;
  175. //model.SMS_ReadTime = SMS_ReadTime;
  176. //model.SMS_DeleteTime = SMS_DeleteTime;
  177. model.SMS_IsDelete = 0;
  178. model.SMS_Order = SMS_Order;
  179. model.SMS_IsTop = SMS_IsTop;
  180. model.SMS_Type = SMS_Type;
  181. int n = bll.Add(model);
  182. if (n > 0)
  183. {
  184. return Success("添加成功", n);
  185. }
  186. else
  187. {
  188. return Error("添加失败");
  189. }
  190. }
  191. else
  192. {
  193. model = bll.GetModel(id);
  194. if (model != null)
  195. {
  196. model.SMS_Id = id;
  197. model.SMS_Title = SMS_Title;
  198. model.SMS_Content = SMS_Content;
  199. model.SMS_ReceiveUserCode = SMS_ReceiveUserCode;
  200. model.SMS_SendUserCode = SMS_SendUserCode;
  201. model.SMS_IsRead = SMS_IsRead;
  202. model.SMS_SendTime = model.SMS_SendTime;
  203. //model.SMS_ReadTime = DateTime.Now;
  204. //model.SMS_DeleteTime = SMS_DeleteTime;
  205. model.SMS_IsDelete = 0;
  206. model.SMS_Order = SMS_Order;
  207. model.SMS_IsTop = SMS_IsTop;
  208. model.SMS_Type = SMS_Type;
  209. if (bll.Update(model))
  210. {
  211. return Success("修改成功");
  212. }
  213. else
  214. {
  215. return Error("修改失败");
  216. }
  217. }
  218. return Error("信息不存在");
  219. }
  220. }
  221. else
  222. {
  223. return Error("获取参数失败");
  224. }
  225. }
  226. /// <summary>
  227. /// 获取一条详细信息
  228. /// </summary>
  229. /// <param name="infoid"></param>
  230. /// <returns></returns>
  231. public ActionResult UpdateInfo(string infoid)
  232. {
  233. if (infoid != null && infoid.Trim() != "")
  234. {
  235. Model.T_SMS_InternalMessages model = bll.GetModel(int.Parse(infoid.Trim()));
  236. if (model != null)
  237. {
  238. if (model.SMS_IsRead == 0)
  239. {
  240. model.SMS_Type = 1;
  241. model.SMS_IsRead = 1;
  242. model.SMS_ReadTime = DateTime.Now;
  243. bool b = bll.Update(model);
  244. if (b)
  245. {
  246. return Success("获取成功", model);
  247. }
  248. else
  249. {
  250. return Error("获取失败,无更新权限");
  251. }
  252. }
  253. else
  254. {
  255. return Success("获取成功", model);
  256. }
  257. }
  258. else
  259. {
  260. return Error("获取失败");
  261. };
  262. }
  263. else
  264. {
  265. return Error("获取参数失败");
  266. }
  267. }
  268. /// <summary>
  269. /// 删除信息
  270. /// </summary>
  271. /// <param name="ids"></param>
  272. /// <returns></returns>
  273. public ActionResult DelInfo(string[] ids)
  274. {
  275. if (ids != null && ids.Length > 0)
  276. {
  277. string idd = " ";
  278. foreach (string str in ids)
  279. {
  280. idd += str + ",";
  281. }
  282. if (bll.DeleteList(idd.TrimEnd(',')))
  283. {
  284. return Success("删除成功");
  285. }
  286. else
  287. return Error("删除失败");
  288. }
  289. else
  290. {
  291. return Error("获取参数失败");
  292. }
  293. }
  294. /// <summary>
  295. /// 添加信息
  296. /// </summary>
  297. /// <param name="title"></param>
  298. /// <param name="content"></param>
  299. /// <param name="receiveUserCode"></param>
  300. /// <param name="sendUserCode"></param>
  301. /// <returns></returns>
  302. public bool AddInternalMessagesInfo(string title,string content,string receiveUserCode,string sendUserCode, int smstype = 0, int smstop = 0)
  303. {
  304. if (!string.IsNullOrWhiteSpace(title) || !string.IsNullOrWhiteSpace(receiveUserCode) || !string.IsNullOrWhiteSpace(sendUserCode))
  305. {
  306. Model.T_SMS_InternalMessages model = new Model.T_SMS_InternalMessages();
  307. model.SMS_Title = title;
  308. model.SMS_Content = content;
  309. model.SMS_ReceiveUserCode = receiveUserCode;
  310. model.SMS_SendUserCode = sendUserCode;
  311. model.SMS_IsRead = 0;
  312. model.SMS_SendTime = DateTime.Now;
  313. //model.SMS_ReadTime = SMS_ReadTime;
  314. //model.SMS_DeleteTime = SMS_DeleteTime;
  315. model.SMS_IsDelete = 0;
  316. model.SMS_Order = 0;
  317. model.SMS_IsTop = 0;
  318. model.SMS_Type = smstype;
  319. int n = bll.Add(model);
  320. if (n > 0)
  321. {
  322. return true;
  323. }
  324. else
  325. {
  326. return false;
  327. }
  328. }
  329. else {
  330. return false;
  331. }
  332. }
  333. /// <summary>
  334. /// 更新状态
  335. /// </summary>
  336. /// <param name="ids"></param>
  337. /// <param name="state"></param>
  338. /// <returns></returns>
  339. public ActionResult UpdateState(string[] ids, int state = 0)
  340. {
  341. int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
  342. if (userId <= 0)
  343. return Error("权限不足");
  344. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  345. if (ua == null)
  346. return Error("权限不足!");
  347. if (ids != null && ids.Length > 0)
  348. {
  349. string idd = " ";
  350. foreach (string str in ids)
  351. {
  352. idd += str + ",";
  353. }
  354. string sj = "null";
  355. if (state == 1)
  356. {
  357. sj = "getdate()";
  358. }
  359. string sql = "update T_SMS_InternalMessages set SMS_IsRead=" + state + ",SMS_ReadTime=" + sj + " where SMS_Id in(" + idd.TrimEnd(',') + ")";
  360. if (!string.IsNullOrEmpty(idd.Trim()))
  361. {
  362. if (DbHelperSQL.ExecuteSql(sql) > 0)
  363. {
  364. return Success("更新成功");
  365. }
  366. else
  367. {
  368. return Error("更新失败");
  369. }
  370. }
  371. else
  372. {
  373. return Error("请选择记录");
  374. }
  375. }
  376. else
  377. {
  378. return Error("获取参数失败");
  379. }
  380. }
  381. /// <summary>
  382. /// 获取消息提醒
  383. /// </summary>
  384. /// <returns></returns>
  385. public ActionResult GetMsg(int smstype = 0)
  386. {
  387. int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
  388. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  389. if (userModel != null)
  390. {
  391. var sql = " SMS_IsDelete=0 and SMS_IsRead=0 ";
  392. sql += " and SMS_ReceiveUserCode='" + userModel.F_UserCode + "'";
  393. if (smstype > 0)
  394. sql += " and SMS_Type=" + smstype;
  395. var msglist = bll.GetModelList(sql + " order by SMS_IsTop desc,SMS_SendTime desc");
  396. return Success("获取消息成功", msglist);
  397. }
  398. return Error("权限不足");
  399. }
  400. }
  401. }