BackgroundProcess.aspx.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. namespace LYFZ.WanYuKeFu
  9. {
  10. public partial class BackgroundProcess : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. if (!IsPostBack)
  15. {
  16. string type = "";
  17. if (Request.QueryString["type"] != null)
  18. {
  19. type=Request.QueryString["type"].ToLower().Trim();
  20. }
  21. switch(type)
  22. {
  23. case "getusername":
  24. #region 获取登录用名
  25. if (LYFZ.Command.Command_Session.GetObject("User") != null)
  26. {
  27. LYFZ.WanYuKeFuData.Model.User retUser = (LYFZ.WanYuKeFuData.Model.User)LYFZ.Command.Command_Session.GetObject("User");
  28. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, retUser.UserName)));
  29. }
  30. else {
  31. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败,"未登录")));
  32. }
  33. #endregion
  34. break;
  35. case "getuserinfo":
  36. #region 获取登录用户信息
  37. if (LYFZ.Command.Command_Session.GetObject("User") != null)
  38. {
  39. LYFZ.WanYuKeFuData.Model.User retUser = (LYFZ.WanYuKeFuData.Model.User)LYFZ.Command.Command_Session.GetObject("User");
  40. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, JsonConvert.SerializeObject(retUser))));
  41. }
  42. else
  43. {
  44. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "未登录")));
  45. }
  46. #endregion
  47. break;
  48. case "updatepwd":
  49. #region 修改当前登录用户密码
  50. if (Request.QueryString["newpwd"] != null)
  51. {
  52. string newpwd = Request.QueryString["newpwd"];
  53. if (LYFZ.Command.Command_Session.GetObject("User") != null)
  54. {
  55. LYFZ.WanYuKeFuData.Model.User retUser = (LYFZ.WanYuKeFuData.Model.User)LYFZ.Command.Command_Session.GetObject("User");
  56. retUser.Password = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(newpwd);
  57. LYFZ.WanYuKeFuData.DAL.User userDal = new LYFZ.WanYuKeFuData.DAL.User(Global.DbConn);
  58. if (userDal.Update(retUser))
  59. {
  60. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, "修改成功")));
  61. }
  62. else {
  63. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "更新数据库时失败")));
  64. }
  65. }
  66. else
  67. {
  68. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "未登录")));
  69. }
  70. }
  71. else {
  72. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.参数错误, "新密码不能为空")));
  73. }
  74. #endregion
  75. break;
  76. case "pushuserlist":
  77. PushUserList();
  78. break;
  79. case "pushmsglist":
  80. PushMsgList();
  81. break;
  82. case "delpushuser":
  83. DelPushUser();
  84. break;
  85. case "delpusmsg":
  86. DelPusMsg();
  87. break;
  88. case "getpushuser":
  89. GetPushUserList();
  90. break;
  91. case "getpushqiyue":
  92. GetPushQiYueList();
  93. break;
  94. case "sendpushmsg":
  95. SendPushMsg();
  96. break;
  97. case "retransmission":
  98. Retransmission();
  99. break;
  100. case "registerpushuser":
  101. RegisterPushUser();
  102. break;
  103. case "badgeclear":
  104. BadgeClear();
  105. break;
  106. case "read":
  107. SetMsgRead();
  108. break;
  109. case "usermsglist":
  110. GetSpecifiedUserMsgList();
  111. break;
  112. case "unreadcount":
  113. GetUnreadCount();
  114. break;
  115. case "wanyukfurl":
  116. WanYuKFUrl();
  117. break;
  118. default:
  119. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.参数错误, "参数错误")));
  120. break;
  121. }
  122. }
  123. }
  124. LYFZ.WanYuKeFuData.DAL.MsgReadStatus msgReadDal = new LYFZ.WanYuKeFuData.DAL.MsgReadStatus(Global.DbConn);
  125. /// <summary>
  126. /// 获取网鱼客服系统url
  127. /// </summary>
  128. void WanYuKFUrl()
  129. {
  130. try
  131. {
  132. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, LYFZ.WanYuKeFu.ErpGetuiApiSDK.WanYuKFUrl)));
  133. }
  134. catch (Exception ex)
  135. {
  136. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, String.Format("错误:{0}", ex.Message))));
  137. }
  138. }
  139. /// <summary>
  140. /// 设置消息的已读状态
  141. /// </summary>
  142. void SetMsgRead()
  143. {
  144. try
  145. {
  146. long msgID = Convert.ToInt64(GetParameterValue("msgid"));
  147. string userID = GetParameterValue("userid").Trim();
  148. if (!msgReadDal.CheckMsgReadExists(msgID, userID))
  149. {
  150. LYFZ.WanYuKeFuData.Model.MsgReadStatus msgReadModel = new WanYuKeFuData.Model.MsgReadStatus();
  151. msgReadModel.MsgID = msgID;
  152. msgReadModel.UserID = userID.Trim();
  153. msgReadModel.ReadStatus = 1;
  154. msgReadModel.ReadTime = DateTime.Now.ToJavaScriptTimeStamp();
  155. if (msgReadDal.Add(msgReadModel))
  156. {
  157. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, "OK")));
  158. }
  159. }
  160. else {
  161. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, "OK")));
  162. }
  163. }
  164. catch (Exception ex)
  165. {
  166. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, String.Format("错误:{0}", ex.Message))));
  167. }
  168. }
  169. /// <summary>
  170. /// 清除badge
  171. /// </summary>
  172. void BadgeClear()
  173. {
  174. try
  175. {
  176. string cid = GetParameterValue("cid");
  177. int badge = GetParameterIntValue("badge");
  178. msgPushUserDal.BadgeClear(cid, badge);
  179. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, String.Format("已成功设置为 {0}", badge))));
  180. }
  181. catch (Exception ex){
  182. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.参数错误,String.Format("错误:{0}",ex.Message))));
  183. }
  184. }
  185. string GetParameterValue(string key)
  186. {
  187. if (Request[key] != null)
  188. {
  189. return Request[key];
  190. }
  191. else {
  192. return "";
  193. }
  194. }
  195. int GetParameterIntValue(string key)
  196. {
  197. string intValue = GetParameterValue(key);
  198. try
  199. {
  200. if (!String.IsNullOrEmpty(intValue))
  201. {
  202. return Convert.ToInt32(intValue);
  203. }
  204. else
  205. {
  206. return 0;
  207. }
  208. }
  209. catch {
  210. return 0;
  211. }
  212. }
  213. LYFZ.WanYuKeFuData.DAL.GTMessagePushUser msgPushUserDal = new LYFZ.WanYuKeFuData.DAL.GTMessagePushUser(Global.DbConn);
  214. /// <summary>
  215. /// 注册推送用户设备
  216. /// </summary>
  217. void RegisterPushUser()
  218. {
  219. try
  220. {
  221. int userType = GetParameterIntValue("uType");
  222. string userID = "0";
  223. string userName = "0";
  224. int appState = 1;
  225. string tempAppSatae = GetParameterValue("appState");
  226. if (!String.IsNullOrEmpty(tempAppSatae))
  227. {
  228. if (tempAppSatae.Trim() == "0")
  229. {
  230. appState = 0;
  231. }
  232. else
  233. {
  234. appState = 1;
  235. }
  236. }
  237. string GTClientID = GetParameterValue("CID");
  238. string LYFZAPPID = GetParameterValue("LYFZAPPID");
  239. if (String.IsNullOrWhiteSpace(LYFZAPPID))
  240. {
  241. LYFZAPPID = "wangyuapp";
  242. }
  243. string AppVersion = GetParameterValue("AppVersion");
  244. if (String.IsNullOrWhiteSpace(AppVersion))
  245. {
  246. AppVersion = "1.0";
  247. }
  248. if (!String.IsNullOrEmpty(GTClientID))
  249. {
  250. LYFZ.WanYuKeFuData.Model.GTMessagePushUser pushUser = msgPushUserDal.GetModel("GTClientID", GTClientID);
  251. pushUser.GTType = userType;
  252. pushUser.GTState = 1;
  253. pushUser.Badge = 0;
  254. pushUser.APPState = appState;
  255. pushUser.UserID = userID;
  256. pushUser.UserName = userName;
  257. pushUser.GTClientID = GTClientID;
  258. pushUser.UpdateTime = DateTime.Now.ToJavaScriptTimeStamp();
  259. pushUser.AppVersion = AppVersion;
  260. pushUser.LYFZAPPID = LYFZAPPID;
  261. bool registerState = false;
  262. if (pushUser.ID > 0)
  263. {
  264. registerState = msgPushUserDal.Update(pushUser);
  265. }
  266. else
  267. {
  268. pushUser.CreationTime = DateTime.Now.ToJavaScriptTimeStamp();
  269. registerState = msgPushUserDal.Add(pushUser);
  270. }
  271. if (registerState)
  272. {
  273. msgPushDal.DelMsgHistoryRecord(DateTime.Now.AddDays(-90).ToJavaScriptTimeStamp());
  274. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, "设备注册成功")));
  275. }
  276. else
  277. {
  278. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "设备注册失败,更新数据库时失败")));
  279. }
  280. }
  281. else
  282. {
  283. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.参数错误, "设备注册失败,参数错误")));
  284. }
  285. }
  286. catch (Exception ex)
  287. {
  288. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "设备注册时出错:" + ex.Message)));
  289. }
  290. }
  291. /// <summary>
  292. /// 重发
  293. /// </summary>
  294. void Retransmission()
  295. {
  296. try
  297. {
  298. string msgid = GetParameterValue("msgid");
  299. LYFZ.WanYuKeFuData.Model.GTMsgRecord msgRecord = msgPushDal.GetModel(Convert.ToInt64(msgid));
  300. if (msgRecord != null && msgRecord.ID > 0)
  301. {
  302. msgRecord.SendTime = DateTime.Now.ToJavaScriptTimeStamp();
  303. string retString = ErpGetuiApiSDK.pushMessageToSingleBatchApp(msgRecord, msgPushUserDal);
  304. if (retString.ToLower().Contains("result\":\"ok\","))
  305. {
  306. msgRecord.State = 1;
  307. }
  308. else
  309. {
  310. msgRecord.State = 0;
  311. }
  312. if (msgRecord.State == 1)
  313. {
  314. if (msgPushDal.Update(msgRecord))
  315. {
  316. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, "重发成功", new { msgid = msgRecord.ID.ToString() })));
  317. }
  318. else
  319. {
  320. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "更新数据库时失败")));
  321. }
  322. }
  323. else {
  324. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "向客户端推送时失败")));
  325. }
  326. }
  327. else
  328. {
  329. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "没有找到指定ID 的数据")));
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "重推时出错:"+ex.Message)));
  335. }
  336. }
  337. LYFZ.WanYuKeFuData.DAL.GTMsgRecord msgPushDal = new LYFZ.WanYuKeFuData.DAL.GTMsgRecord(Global.DbConn);
  338. /// <summary>
  339. /// 推送消息
  340. /// </summary>
  341. void SendPushMsg()
  342. {
  343. try
  344. {
  345. string title = GetParameterValue("title");
  346. string description = GetParameterValue("description");
  347. string msgData = GetParameterValue("msgData");//.Replace("$_$", "&");
  348. //目标用户 0 为全部用户 1 为特定用户
  349. int TargetUser = GetParameterIntValue("TargetUser");
  350. string targetCidList = GetParameterValue("targetList").Trim(',');
  351. string targetList = String.Format(",{0},", targetCidList);
  352. string Platform = GetParameterValue("Platform").Trim(',');
  353. if (String.IsNullOrEmpty(Platform))
  354. {
  355. Platform = "IOS,Android";
  356. }
  357. if (String.IsNullOrEmpty(title))
  358. {
  359. title = "APP消息提醒";
  360. }
  361. if (targetList.Split(',').Length <= 100)
  362. {
  363. if (!String.IsNullOrEmpty(description) && !String.IsNullOrEmpty(msgData) && (TargetUser == 0 || (TargetUser > 0 && !String.IsNullOrEmpty(targetList))))
  364. {
  365. LYFZ.WanYuKeFuData.Model.GTMsgRecord msgRecord = new WanYuKeFuData.Model.GTMsgRecord();
  366. msgRecord.ID = LYFZ.WinAPI.CustomPublicMethod.GenerateId();
  367. msgRecord.Title = title;
  368. msgRecord.Description = description;
  369. msgRecord.MsgData = msgData;
  370. msgRecord.Platform = Platform;
  371. msgRecord.TargetUser = TargetUser;
  372. msgRecord.TargetList = targetList;
  373. msgRecord.SendTime = DateTime.Now.ToJavaScriptTimeStamp();
  374. string retString = ErpGetuiApiSDK.pushMessageToSingleBatchApp(msgRecord, msgPushUserDal);
  375. if (retString.ToLower().Contains("result\":\"ok\","))
  376. {
  377. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, "消息推送成功")));
  378. }
  379. else if (retString.ToLower().Contains("result\":\"-900000\","))
  380. {
  381. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.没有找到目标用户注册的APP设备, "消息推送失败,指定的用户还有没使用过APP")));
  382. }
  383. else {
  384. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.推送失败, retString)));
  385. }
  386. }
  387. else
  388. {
  389. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.参数错误, "消息推送失败,参数错误")));
  390. }
  391. }
  392. else {
  393. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.推送失败, "每次推送用户数不能超过 100 个用户")));
  394. }
  395. }
  396. catch (Exception ex)
  397. {
  398. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "消息推送时出错:" + ex.Message)));
  399. }
  400. }
  401. void GetPushUserList()
  402. {
  403. string filedOrder = "CreationTime desc";
  404. if (String.IsNullOrEmpty(filedOrder))
  405. {
  406. filedOrder = "id desc";
  407. }
  408. string whereString = "1=1";
  409. int currentPage = 1;
  410. int pageSize = 50;
  411. int _TotalCount = 0;//总记录数
  412. if (Request.QueryString["page"] != null)
  413. {
  414. currentPage = Convert.ToInt32(Request.QueryString["page"]);
  415. }
  416. if (Request.QueryString["pageSize"] != null)
  417. {
  418. pageSize = Convert.ToInt32(Request.QueryString["pageSize"]);
  419. }
  420. if (Request.QueryString["keywords"] != null && Request.QueryString["keywords"].ToString().Trim().Length > 0)
  421. {
  422. whereString = String.Format("GTClientID like '%{0}%'", Request.QueryString["keywords"].ToString().Trim());
  423. }
  424. //if (Request.QueryString["gttype"] != null && Request.QueryString["gttype"].ToString().Trim().Length>0)
  425. //{
  426. // whereString += " and [GTType]=" + Request.QueryString["gttype"].ToString();
  427. //}
  428. System.Data.DataTable tb = msgPushUserDal.PagingQueryDataTable("tb_GTMessagePushUser", "[GTType],[GTClientID],[GTState],[CreationTime] ,[UpdateTime]", filedOrder, whereString, pageSize, currentPage, out _TotalCount).Tables[0];
  429. dynamic data = new
  430. {
  431. TotalCount = _TotalCount,
  432. ListData = tb//JsonConvert.SerializeObject(tb)
  433. };
  434. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, data)));
  435. //返回参数
  436. }
  437. void GetPushQiYueList()
  438. {
  439. string filedOrder = "EnterpriseID desc";
  440. string whereString = "1=1";
  441. int currentPage = 1;
  442. int pageSize = 50;
  443. int _TotalCount = 0;//总记录数
  444. if (Request.QueryString["page"] != null)
  445. {
  446. currentPage = Convert.ToInt32(Request.QueryString["page"]);
  447. }
  448. if (Request.QueryString["pageSize"] != null)
  449. {
  450. pageSize = Convert.ToInt32(Request.QueryString["pageSize"]);
  451. }
  452. if (Request.QueryString["keywords"] != null && Request.QueryString["keywords"].ToString().Trim().Length > 0)
  453. {
  454. whereString = String.Format("EnterpriseID like '%{0}%' or EnterpriseName like '%{0}%'", Request.QueryString["keywords"].ToString().Trim());
  455. }
  456. System.Data.DataTable tb = msgPushUserDal.PagingQueryDataTable("view_GTEnterpriseIDList", "[EnterpriseID],[EnterpriseName]", filedOrder, whereString, pageSize, currentPage, out _TotalCount).Tables[0];
  457. dynamic data = new
  458. {
  459. TotalCount = _TotalCount,
  460. ListData = tb//JsonConvert.SerializeObject(tb)
  461. };
  462. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, data)));
  463. //返回参数
  464. }
  465. void DelPushUser()
  466. {
  467. try
  468. {
  469. string delIDList = "";
  470. if (Request.QueryString["delID"] != null)
  471. {
  472. delIDList = Request.QueryString["delID"].Trim(',');
  473. }
  474. if (msgPushUserDal.Delete(String.Format("id in(" + delIDList + ")")))
  475. {
  476. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功,"删除成功")));
  477. }
  478. else {
  479. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "删除失败")));
  480. }
  481. }
  482. catch (Exception ex)
  483. {
  484. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "删除时出错:" + ex.Message)));
  485. }
  486. }
  487. void DelPusMsg() {
  488. try
  489. {
  490. string delIDList = "";
  491. if (Request["delID"] != null)
  492. {
  493. delIDList = Request["delID"].Trim(',');
  494. }
  495. if (msgPushDal.Delete(String.Format("id in(" + delIDList + ")")))
  496. {
  497. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, "删除成功")));
  498. }
  499. else
  500. {
  501. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "删除失败")));
  502. }
  503. }
  504. catch (Exception ex)
  505. {
  506. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "删除时出错:" + ex.Message)));
  507. }
  508. }
  509. /// <summary>
  510. /// 获取推送用户集合 分页
  511. /// </summary>
  512. void PushUserList()
  513. {
  514. try
  515. {
  516. string filedOrder = "CreationTime desc";
  517. if (String.IsNullOrEmpty(filedOrder))
  518. {
  519. filedOrder = "id desc";
  520. }
  521. string whereString = "1=1";
  522. int currentPage = 1;
  523. int pageSize = 50;
  524. int _TotalCount = 0;//总记录数
  525. if (Request.QueryString["page"] != null)
  526. {
  527. currentPage = Convert.ToInt32(Request.QueryString["page"]);
  528. }
  529. if (Request.QueryString["pageSize"] != null)
  530. {
  531. pageSize = Convert.ToInt32(Request.QueryString["pageSize"]);
  532. }
  533. string keywords = Request.QueryString["keywords"];
  534. if (!String.IsNullOrWhiteSpace(keywords))
  535. {
  536. whereString = String.Format("(GTClientID like '%{0}%' or LYFZAPPID='{0}' or AppVersion='{0}')", keywords);
  537. }
  538. System.Data.DataTable tb = msgPushUserDal.PagingQueryDataTable(msgPushUserDal.TableName, msgPushUserDal.TableFieldNameStr + ", CONVERT(nvarchar(20),[ID]) as sid", filedOrder, whereString, pageSize, currentPage, out _TotalCount).Tables[0];
  539. dynamic data = new {
  540. TotalCount = _TotalCount,
  541. ListData = tb//JsonConvert.SerializeObject(tb)
  542. };
  543. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, data)));
  544. //返回参数
  545. }
  546. catch (Exception ex)
  547. {
  548. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "查询数据时出错:"+ex.Message)));
  549. }
  550. }
  551. /// <summary>
  552. /// 获取推送消息记录 分页
  553. /// </summary>
  554. void PushMsgList()
  555. {
  556. try
  557. {
  558. string filedOrder = "sendTime desc";
  559. if (String.IsNullOrEmpty(filedOrder))
  560. {
  561. filedOrder = "id desc";
  562. }
  563. string whereString = "1=1";
  564. int currentPage = 1;
  565. int pageSize = 50;
  566. int _TotalCount = 0;//总记录数
  567. if (Request.QueryString["page"] != null)
  568. {
  569. currentPage = Convert.ToInt32(Request.QueryString["page"]);
  570. }
  571. if (Request.QueryString["pageSize"] != null)
  572. {
  573. pageSize = Convert.ToInt32(Request.QueryString["pageSize"]);
  574. }
  575. if (Request.QueryString["keywords"] != null && Request.QueryString["keywords"].ToString().Trim().Length > 0)
  576. {
  577. whereString = String.Format("title like '%{0}%' or EnterpriseName like '%{0}%' or EnterpriseID like '%{0}%' or Platform like '%{0}%' ", Request.QueryString["keywords"].ToString().Trim());
  578. }
  579. System.Data.DataTable tb = msgPushDal.PagingQueryDataTable("view_GTMsgRecord", "CONVERT(nvarchar(20),[ID]) as ID,title,[description],msgData,TargetUser,targetList,[state],EnterpriseID,[Platform],sendTime,EnterpriseName ", filedOrder, whereString, pageSize, currentPage, out _TotalCount).Tables[0];
  580. dynamic data = new
  581. {
  582. TotalCount = _TotalCount,
  583. ListData = tb//JsonConvert.SerializeObject(tb)
  584. };
  585. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, data)));
  586. //返回参数
  587. }
  588. catch (Exception ex)
  589. {
  590. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "查询数据时出错:" + ex.Message)));
  591. }
  592. }
  593. /// <summary>
  594. /// 获取指定用户收到的推送消息列表 最新的前 100 条
  595. /// </summary>
  596. void GetSpecifiedUserMsgList()
  597. {
  598. try
  599. {
  600. string filedOrder = "sendTime desc";
  601. if (String.IsNullOrEmpty(filedOrder))
  602. {
  603. filedOrder = "id desc";
  604. }
  605. string EnterpriseID = "";
  606. string whereString = "1=1";
  607. string userID = "";
  608. int currentPage = 1;
  609. int pageSize = 100;
  610. int _TotalCount = 0;//总记录数
  611. string Platform="IOS";
  612. if (Request["page"] != null)
  613. {
  614. currentPage = Convert.ToInt32(Request["page"]);
  615. }
  616. if (Request["EnterpriseID"] != null)
  617. {
  618. EnterpriseID = Request["EnterpriseID"];
  619. }
  620. if (Request["UID"] != null && Request["UID"].ToString().Trim().Length > 0)
  621. {
  622. userID = Request["UID"].ToString().Trim();
  623. }
  624. if(Request["Platform"] != null)
  625. {
  626. Platform=Request["Platform"].ToString().Trim();
  627. }
  628. if (Platform != "IOS")
  629. {
  630. Platform = "Android";
  631. }
  632. if (!String.IsNullOrEmpty(EnterpriseID) && !String.IsNullOrEmpty(userID))
  633. {
  634. string eidAndUid = String.Format("{0}:{1}", EnterpriseID, userID);
  635. whereString = String.Format("(EnterpriseID='{0}' or EnterpriseID='E1000') and (TargetUser <=1 or [targetList] like '%,{1},%' or [targetList] like '%,{3},%') and [Platform] like '%{2}%'", EnterpriseID.Trim(), userID, Platform, eidAndUid);
  636. System.Data.DataTable tb = msgPushDal.PagingQueryDataTable("tb_GTMsgRecord", "CONVERT(nvarchar(20),[ID]) as ID,[title],[description],[msgData],[TargetUser],[targetList],[state],[EnterpriseID],[Platform],[sendTime] ", filedOrder, whereString, pageSize, currentPage, out _TotalCount).Tables[0];
  637. //{"title":"摄控本-安排数量设置 申请授权","content":"{\"JumpURL\":\"http:\/\/webapi.lyfz.net\/#\/RemoteAuthorization?msgid=4629368513340450532&name=Demo&uid=20170623094515297&account=demo&apieid=E6051806481742&apiuid=demo&apimsgid=5438917636193927209\"}","description":"2017年10月30日 16时44分34秒【管理员】向你发起远程授权请求“摄控本-安排数量设置”申请授权","badge":33}
  638. List<string> ReadMsIDList = msgPushDal.GetReadMsIDList(EnterpriseID, userID, Platform);
  639. List<object> objList = new List<object>();
  640. foreach (System.Data.DataRow row in tb.Rows)
  641. {
  642. objList.Add(new {
  643. ID = row["ID"].ToString(),
  644. title = row["title"],
  645. description = row["description"],
  646. msgData = row["msgData"].ToString().Replace("$webapi$", "http://webapi.lyfz.net").Replace("$apiuserid$", userID).Replace("$apimsgid$", row["ID"].ToString()).Replace("$_$", "&"),
  647. TargetUser = row["TargetUser"],
  648. ReadState = ReadMsIDList.Contains(row["ID"].ToString())?1:0,
  649. sendTime = Convert.ToInt64(row["sendTime"]).JavaScriptTimeStampToDateTime().ToYYYY_MM_dd_HH_mm_ss()
  650. });
  651. }
  652. dynamic data = new
  653. {
  654. TotalCount = _TotalCount,
  655. ListData = objList.ToArray()//tb//JsonConvert.SerializeObject(tb)
  656. };
  657. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, data)));
  658. }
  659. else {
  660. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.参数错误)));
  661. }
  662. //返回参数
  663. }
  664. catch (Exception ex)
  665. {
  666. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "查询数据时出错:" + ex.Message)));
  667. }
  668. }
  669. /// <summary>
  670. /// 获取用户消息未读记录条数
  671. /// </summary>
  672. void GetUnreadCount()
  673. {
  674. try
  675. {
  676. string EnterpriseID = "";
  677. string userID = "";
  678. string Platform = "IOS";
  679. if (Request.QueryString["EnterpriseID"] != null)
  680. {
  681. EnterpriseID = Request.QueryString["EnterpriseID"];
  682. }
  683. if (Request.QueryString["UID"] != null && Request.QueryString["UID"].ToString().Trim().Length > 0)
  684. {
  685. userID = Request.QueryString["UID"].ToString().Trim();
  686. }
  687. if (Request.QueryString["Platform"] != null)
  688. {
  689. Platform = Request.QueryString["Platform"].ToString().Trim();
  690. }
  691. if (Platform != "IOS")
  692. {
  693. Platform = "Android";
  694. }
  695. if (!String.IsNullOrEmpty(EnterpriseID) && !String.IsNullOrEmpty(userID))
  696. {
  697. int uReadCount = msgPushDal.GetUnreadCount(EnterpriseID,userID,Platform);
  698. dynamic data = new
  699. {
  700. UnreadCount = uReadCount,
  701. };
  702. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求成功, data)));
  703. }
  704. else
  705. {
  706. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.参数错误)));
  707. }
  708. //返回参数
  709. }
  710. catch (Exception ex)
  711. {
  712. Response.Write(JsonConvert.SerializeObject(new AjaxResult(EnumCode.AjaxResultCode.请求失败, "查询数据时出错:" + ex.Message)));
  713. }
  714. }
  715. }
  716. }