PingAnYeXianSZCG_API 接口代码

MsgController.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  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 CallCenterApi.Interface.Controllers
  12. {
  13. public class MsgController : BaseController
  14. {
  15. /// <summary>
  16. /// 获取消息列表
  17. /// </summary>
  18. /// <returns></returns>
  19. public ActionResult GetList()
  20. {
  21. ActionResult res = NoToken("未知错误,请重新登录");
  22. if (Request.IsAuthenticated)
  23. {
  24. string sql = " and isdel=0 ";
  25. DataTable dt = new DataTable();
  26. int userId = CurrentUser.UserData.F_UserId;
  27. if (userId != 0)
  28. {
  29. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  30. if (ua != null)
  31. {
  32. sql += " and CreateUser='" + ua.F_UserCode + "'";
  33. int state = RequestString.GetInt("state", -1);
  34. string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
  35. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  36. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  37. string strpageindex = RequestString.GetQueryString("page");
  38. int pageindex = 1;
  39. string strpagesize = RequestString.GetQueryString("pagesize");
  40. int pagesize = 10;
  41. if (state != -1)
  42. {
  43. sql += " and State='" + state + "'";
  44. }
  45. if (strkey.Trim() != "" && strkey != "undefined")
  46. {
  47. sql += " and Detail like '%" + strkey.Trim() + "%' ";
  48. }
  49. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  50. {
  51. sql += " and datediff(day,CreateDate,'" + strstarttime + "')<=0 ";
  52. }
  53. if (strendtime.Trim() != "" && strendtime != "undefined")
  54. {
  55. sql += " and datediff(day,CreateDate,'" + strendtime + "')>=0 ";
  56. }
  57. if (strpageindex.Trim() != "")
  58. {
  59. pageindex = Convert.ToInt32(strpageindex);
  60. }
  61. if (strpagesize.Trim() != "")
  62. {
  63. pagesize = Convert.ToInt32(strpagesize);
  64. }
  65. int recordCount = 0;
  66. dt = BLL.PagerBLL.GetListPager(
  67. "T_Msg_List",
  68. "ID",
  69. "*,dbo.GetUserName(CreateUser) as CreateUserName, dbo.GetUserName(ToUser) as ToUserName",
  70. sql,
  71. "ORDER BY ID desc",
  72. pagesize,
  73. pageindex,
  74. true,
  75. out recordCount);
  76. var obj = new
  77. {
  78. state = "success",
  79. message = "成功",
  80. rows = dt,
  81. total = recordCount
  82. };
  83. res = Content(obj.ToJson());
  84. }
  85. }
  86. }
  87. return res;
  88. }
  89. /// <summary>
  90. /// 添加/修改信息
  91. /// </summary>
  92. /// <returns></returns>
  93. public ActionResult AddMsg()
  94. {
  95. ActionResult res = NoToken("未知错误,请重新登录");
  96. if (Request.IsAuthenticated)
  97. {
  98. int userId = CurrentUser.UserData.F_UserId;
  99. if (userId != 0)
  100. {
  101. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  102. if (ua != null)
  103. {
  104. int id = RequestString.GetInt("id", 0);
  105. int type = RequestString.GetInt("type", 0);
  106. int toid = RequestString.GetInt("toid", 0);
  107. string usercode = RequestString.GetFormString("usercode");
  108. string cont = RequestString.GetFormString("cont");
  109. Model.T_Msg_List model = new Model.T_Msg_List();
  110. if (id == 0)
  111. {
  112. model.Detail = cont;
  113. model.Type = type;
  114. model.ToUser = usercode;
  115. model.ToID = toid;
  116. model.State = 0;
  117. model.IsDel = 0;
  118. model.CreateDate = DateTime.Now;
  119. model.CreateUser = ua.F_UserCode;
  120. if (new BLL.T_Msg_List().Add(model) > 0)
  121. {
  122. res = Success("新增成功!");
  123. }
  124. else
  125. {
  126. res = Error("新增失败!");
  127. }
  128. }
  129. else
  130. {
  131. model = new BLL.T_Msg_List().GetModel(id);
  132. if (model != null)
  133. {
  134. model.Detail = cont;
  135. model.Type = type;
  136. model.ToUser = usercode;
  137. model.ToID = toid;
  138. if (new BLL.T_Msg_List().Update(model))
  139. {
  140. res = Success("修改成功!");
  141. }
  142. else
  143. {
  144. res = Error("修改失败!");
  145. }
  146. }
  147. else
  148. {
  149. res = Error("修改失败!");
  150. }
  151. }
  152. }
  153. }
  154. }
  155. return res;
  156. }
  157. /// <summary>
  158. /// 删除消息
  159. /// </summary>
  160. /// <param name="ids"></param>
  161. /// <returns></returns>
  162. public ActionResult DelMsg(string[] ids)
  163. {
  164. ActionResult res = NoToken("未知错误,请重新登录");
  165. if (Request.IsAuthenticated)
  166. {
  167. int userId = CurrentUser.UserData.F_UserId;
  168. if (userId != 0)
  169. {
  170. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  171. if (ua != null)
  172. {
  173. if (ids != null && ids.Length > 0)
  174. {
  175. string idd = " ";
  176. foreach (string str in ids)
  177. {
  178. idd += str + ",";
  179. }
  180. string sql = "update T_Msg_List set IsDel=1,DelUser='" + ua.F_UserCode + "',DelTime=getdate() where ID in(" + idd.TrimEnd(',') + ")";
  181. if (!string.IsNullOrEmpty(idd.Trim()))
  182. {
  183. if (DbHelperSQL.ExecuteSql(sql) > 0)
  184. {
  185. res = Success("删除成功");
  186. }
  187. else
  188. {
  189. res = Error("删除失败");
  190. }
  191. }
  192. else
  193. {
  194. res = Error("请选择记录");
  195. }
  196. }
  197. else
  198. {
  199. res = Error("获取参数失败");
  200. }
  201. }
  202. }
  203. }
  204. return res;
  205. }
  206. /// <summary>
  207. /// 更新状态
  208. /// </summary>
  209. /// <param name="ids"></param>
  210. /// <param name="state"></param>
  211. /// <returns></returns>
  212. public ActionResult UpdateState(string[] ids,int state)
  213. {
  214. ActionResult res = NoToken("未知错误,请重新登录");
  215. if (Request.IsAuthenticated)
  216. {
  217. int userId = CurrentUser.UserData.F_UserId;
  218. if (userId != 0)
  219. {
  220. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  221. if (ua != null)
  222. {
  223. if (ids != null && ids.Length > 0)
  224. {
  225. string idd = " ";
  226. foreach (string str in ids)
  227. {
  228. idd += str + ",";
  229. }
  230. string sj = "null";
  231. if (state == 1)
  232. {
  233. sj = "getdate()";
  234. }
  235. string sql = "update T_Msg_List set State=" + state + ",ReadDate=" + sj + " where ID in(" + idd.TrimEnd(',') + ")";
  236. if (!string.IsNullOrEmpty(idd.Trim()))
  237. {
  238. if (DbHelperSQL.ExecuteSql(sql) > 0)
  239. {
  240. res = Success("更新成功");
  241. }
  242. else
  243. {
  244. res = Error("更新失败");
  245. }
  246. }
  247. else
  248. {
  249. res = Error("请选择记录");
  250. }
  251. }
  252. else
  253. {
  254. res = Error("获取参数失败");
  255. }
  256. }
  257. }
  258. }
  259. return res;
  260. }
  261. /// <summary>
  262. /// 阅读消息
  263. /// </summary>
  264. /// <returns></returns>
  265. public ActionResult ReadMsg()
  266. {
  267. ActionResult res = NoToken("未知错误,请重新登录");
  268. if (Request.IsAuthenticated)
  269. {
  270. int userId = CurrentUser.UserData.F_UserId;
  271. if (userId != 0)
  272. {
  273. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  274. if (ua != null)
  275. {
  276. int id = RequestString.GetInt("id", 0);
  277. Model.T_Msg_List model = new BLL.T_Msg_List().GetModel(id);
  278. if (model != null)
  279. {
  280. model.State = 0;
  281. model.ReadDate = DateTime.Now;
  282. if (new BLL.T_Msg_List().Update(model))
  283. {
  284. res = Success("成功!");
  285. }
  286. else
  287. {
  288. res = Error("失败!");
  289. }
  290. }
  291. else
  292. {
  293. res = Error("失败");
  294. }
  295. }
  296. }
  297. }
  298. return res;
  299. }
  300. }
  301. }