|
|
@@ -1,4 +1,5 @@
|
|
1
|
1
|
using RMYY_CallCenter_Api.DB;
|
|
|
2
|
+using RMYY_CallCenter_Api.Models.Input;
|
|
2
|
3
|
using RMYY_CallCenter_Api.Utility;
|
|
3
|
4
|
using System;
|
|
4
|
5
|
using System.Collections.Generic;
|
|
|
@@ -12,6 +13,10 @@ namespace RMYY_CallCenter_Api.Controllers
|
|
12
|
13
|
public class IndexController : BaseController
|
|
13
|
14
|
{
|
|
14
|
15
|
private Bll.T_Sys_Menu menbll = new Bll.T_Sys_Menu();
|
|
|
16
|
+ private Bll.T_Sys_Role rolebll = new Bll.T_Sys_Role();
|
|
|
17
|
+ private Bll.T_Msg_Chat bllchat = new Bll.T_Msg_Chat();
|
|
|
18
|
+ private Bll.T_Msg_Chat_Map bllmap = new Bll.T_Msg_Chat_Map();
|
|
|
19
|
+ private readonly Bll.T_Sys_UserAccount userAccount = new Bll.T_Sys_UserAccount();
|
|
15
|
20
|
// GET: Index
|
|
16
|
21
|
/// <summary>
|
|
17
|
22
|
/// 获取当前用户
|
|
|
@@ -216,6 +221,482 @@ namespace RMYY_CallCenter_Api.Controllers
|
|
216
|
221
|
return Content(obj.ToJson());
|
|
217
|
222
|
}
|
|
218
|
223
|
|
|
|
224
|
+ #region 及时通讯
|
|
|
225
|
+
|
|
|
226
|
+ #region 模仿微信聊天(暂时不用)
|
|
|
227
|
+ /// <summary>
|
|
|
228
|
+ /// 即时聊天 - 角色信息
|
|
|
229
|
+ /// </summary>
|
|
|
230
|
+ /// <param name="pageIndex"></param>
|
|
|
231
|
+ /// <param name="pageSize"></param>
|
|
|
232
|
+ /// <param name="code"></param>
|
|
|
233
|
+ /// <param name="name"></param>
|
|
|
234
|
+ /// <returns></returns>
|
|
|
235
|
+ public ActionResult GetRoleList()
|
|
|
236
|
+ {
|
|
|
237
|
+ //var dtCache = CacheHelper.Get<DataTable>($"RoleList");
|
|
|
238
|
+ var dtCache = RedisHelper.StringGet("RoleList");
|
|
|
239
|
+ if (dtCache != null)
|
|
|
240
|
+ {
|
|
|
241
|
+ return Success("获取成功", dtCache.ToString().ToObject<DataTable>());
|
|
|
242
|
+ }
|
|
|
243
|
+ DataTable dt = new DataTable();
|
|
|
244
|
+ dt = rolebll.GetAllList().Tables[0];
|
|
|
245
|
+ //CacheHelper.Insert($"RoleList", dt, 10);
|
|
|
246
|
+ RedisHelper.StringSet("RoleList", dt.ToJson(), new TimeSpan(0, 10, 0));
|
|
|
247
|
+ return Success("获取成功", dt);
|
|
|
248
|
+ }
|
|
|
249
|
+
|
|
|
250
|
+ /// <summary>
|
|
|
251
|
+ /// 即时聊天 - 坐席人员
|
|
|
252
|
+ /// </summary>
|
|
|
253
|
+ /// <param name="pageIndex"></param>
|
|
|
254
|
+ /// <param name="pageSize"></param>
|
|
|
255
|
+ /// <param name="code"></param>
|
|
|
256
|
+ /// <param name="name"></param>
|
|
|
257
|
+ /// <returns></returns>
|
|
|
258
|
+ public ActionResult GetUserListByRoleId(int roleid, string keyword)
|
|
|
259
|
+ {
|
|
|
260
|
+ DataTable dt = new DataTable();
|
|
|
261
|
+ //取得前天日期
|
|
|
262
|
+ DateTime start = DateTime.Parse(DateTime.Now.AddDays(-2).ToShortDateString() + " 00:00:00");
|
|
|
263
|
+
|
|
|
264
|
+ string sql1 = "SELECT FromUserId,COUNT(1)AS counts FROM T_Msg_Chat_Map WHERE ToUserId = " + User.F_UserId + " AND ISNULL(IsRead,0) = 0 AND CreateDate > '" + start + "' group by FromUserId order by FromUserId";
|
|
|
265
|
+ var dt1 = DbHelperSQL.Query(sql1).Tables[0];
|
|
|
266
|
+ //缓存
|
|
|
267
|
+ //var dtCache = CacheHelper.Get<DataTable>($"UserList{roleid}");
|
|
|
268
|
+ var objCache = RedisHelper.StringGet($"UserList{roleid}");
|
|
|
269
|
+ if (objCache != null)
|
|
|
270
|
+ {
|
|
|
271
|
+ var dtCache = objCache.ToString().ToObject<DataTable>();
|
|
|
272
|
+ #region 提示统计
|
|
|
273
|
+ if (!string.IsNullOrEmpty(keyword))
|
|
|
274
|
+ {
|
|
|
275
|
+ dtCache = ToDataTable1(dtCache.Select("F_UserName LIKE '%" + keyword + "%' OR F_UserCode LIKE '%" + keyword + "%'"));
|
|
|
276
|
+ }
|
|
|
277
|
+ foreach (DataRow dr in dtCache.Rows)
|
|
|
278
|
+ {
|
|
|
279
|
+ var list = dt1.Select(" FromUserId=" + dr["F_UserId"]);
|
|
|
280
|
+ dr["counts"] = list.Count() > 0 ? list[0]["counts"].ToString() : "0";
|
|
|
281
|
+ }
|
|
|
282
|
+ #endregion
|
|
|
283
|
+ return Success("获取成功", dtCache);
|
|
|
284
|
+ }
|
|
|
285
|
+ //实时查询
|
|
|
286
|
+ var sql = " F_DeleteFlag=0 ";
|
|
|
287
|
+ if (roleid != 0)
|
|
|
288
|
+ {
|
|
|
289
|
+ sql += " and F_RoleId = " + roleid + "";
|
|
|
290
|
+ }
|
|
|
291
|
+ string sqldt = "SELECT F_UserId,F_UserCode,F_UserName,F_RoleId,F_SexFlag,F_See FROM T_Sys_UserAccount WHERE " + sql + " ";
|
|
|
292
|
+ dt = DbHelperSQL.Query(sqldt).Tables[0];
|
|
|
293
|
+
|
|
|
294
|
+ #region 提示统计
|
|
|
295
|
+ dt.Columns.Add("counts", typeof(string)); //统计
|
|
|
296
|
+ //string sql1 = "SELECT FromUserId,COUNT(1)AS counts FROM T_Msg_Chat_Map WHERE ToUserId = " + User.F_UserId + " AND ISNULL(IsRead,0) = 0 AND CreateDate > '" + start + "' group by FromUserId order by FromUserId";
|
|
|
297
|
+ //var dt1 = DbHelperSQL.Query(sql1).Tables[0];
|
|
|
298
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
299
|
+ {
|
|
|
300
|
+ var list = dt1.Select(" FromUserId=" + dr["F_UserId"]);
|
|
|
301
|
+ dr["counts"] = list.Count() > 0 ? list[0]["counts"].ToString() : "0";
|
|
|
302
|
+ }
|
|
|
303
|
+ //缓存保存
|
|
|
304
|
+ //CacheHelper.Insert($"UserList{roleid}", dt, 10);
|
|
|
305
|
+ RedisHelper.StringSet($"UserList{roleid}", dt.ToJson(), new TimeSpan(0, 10, 0));
|
|
|
306
|
+ if (!string.IsNullOrEmpty(keyword))
|
|
|
307
|
+ {
|
|
|
308
|
+ dt = ToDataTable1(dt.Select("F_UserName LIKE '%" + keyword + "%' OR F_UserCode LIKE '%" + keyword + "%'"));
|
|
|
309
|
+ }
|
|
|
310
|
+ #endregion
|
|
|
311
|
+ return Success("获取成功", dt);
|
|
|
312
|
+ }
|
|
|
313
|
+
|
|
|
314
|
+ /// <summary>
|
|
|
315
|
+ /// 即时聊天 - 获取最新通讯(获取双方记录【聊天】)
|
|
|
316
|
+ /// </summary>
|
|
|
317
|
+ /// <returns></returns>
|
|
|
318
|
+ public ActionResult GetChatList(int fromuserId)
|
|
|
319
|
+ {
|
|
|
320
|
+ DataTable dt = null;
|
|
|
321
|
+ int recordCount = 0;
|
|
|
322
|
+ //取得前天日期
|
|
|
323
|
+ DateTime start = DateTime.Parse(DateTime.Now.AddDays(-2).ToShortDateString() + " 00:00:00");
|
|
|
324
|
+ //接收坐席Id
|
|
|
325
|
+
|
|
|
326
|
+ if (fromuserId > 0)
|
|
|
327
|
+ {
|
|
|
328
|
+ //条件(最近3天的记录)
|
|
|
329
|
+ string sql = " ISNULL(a.IsDelete,0) = 0 AND ISNULL(c.F_DeleteFlag,0) = 0 "; // AND ISNULL(b.IsRead,0) = 0
|
|
|
330
|
+ if (fromuserId > 0)
|
|
|
331
|
+ {
|
|
|
332
|
+ sql += " and (b.FromUserId = " + fromuserId + " or b.ToUserId = " + fromuserId + ") ";
|
|
|
333
|
+ }
|
|
|
334
|
+ if (User.F_UserId > 0)
|
|
|
335
|
+ {
|
|
|
336
|
+ sql += " and (b.ToUserId = " + User.F_UserId + " or b.FromUserId = " + User.F_UserId + ") ";
|
|
|
337
|
+ }
|
|
|
338
|
+ if (start != null)
|
|
|
339
|
+ {
|
|
|
340
|
+ sql += " and b.CreateDate > '" + start + "' ";
|
|
|
341
|
+ }
|
|
|
342
|
+ //查询(聊天记录)
|
|
|
343
|
+ string sql1 = "SELECT a.Id,a.FromUserId,a.Content,a.IsToAll,a.CreateDate,c.F_UserName FROM dbo.T_Msg_Chat a RIGHT JOIN dbo.T_Msg_Chat_Map b ON b.ChatId = a.Id LEFT JOIN dbo.T_Sys_UserAccount c ON c.F_UserId = a.FromUserId WHERE " + sql + " ORDER BY a.CreateDate ASC";
|
|
|
344
|
+ dt = DbHelperSQL.Query(sql1).Tables[0];
|
|
|
345
|
+ recordCount = dt.Rows.Count;
|
|
|
346
|
+
|
|
|
347
|
+ //修改(设置已读)
|
|
|
348
|
+ string sqlwhere = " ISNULL(IsRead,0) = 0 ";
|
|
|
349
|
+ if (fromuserId > 0)
|
|
|
350
|
+ {
|
|
|
351
|
+ sqlwhere += " and FromUserId = " + fromuserId + " ";
|
|
|
352
|
+ }
|
|
|
353
|
+ if (User.F_UserId > 0)
|
|
|
354
|
+ {
|
|
|
355
|
+ sqlwhere += " and ToUserId = " + User.F_UserId + " ";
|
|
|
356
|
+ }
|
|
|
357
|
+ string sqlwhere1 = "UPDATE dbo.T_Msg_Chat_Map SET IsRead = 1 WHERE " + sqlwhere + " ";
|
|
|
358
|
+ DbHelperSQL.ExecuteSql(sqlwhere1);
|
|
|
359
|
+
|
|
|
360
|
+ }
|
|
|
361
|
+ var obj = new
|
|
|
362
|
+ {
|
|
|
363
|
+ rows = dt,
|
|
|
364
|
+ total = recordCount
|
|
|
365
|
+ };
|
|
|
366
|
+ return Content(obj.ToJson());
|
|
|
367
|
+ }
|
|
|
368
|
+ #endregion
|
|
|
369
|
+
|
|
|
370
|
+ #region 及时通讯 - 通讯列表
|
|
|
371
|
+ /// <summary>
|
|
|
372
|
+ /// 即时通讯 - 获取通讯列表
|
|
|
373
|
+ /// </summary>
|
|
|
374
|
+ /// <returns></returns>
|
|
|
375
|
+ public ActionResult GetChatListSearch()
|
|
|
376
|
+ {
|
|
|
377
|
+ DataTable dt = new DataTable();
|
|
|
378
|
+ int fromid = RequestString.GetInt("fromid", 0);
|
|
|
379
|
+ int isread = RequestString.GetInt("isread", -1);
|
|
|
380
|
+ string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("strstarttime"));
|
|
|
381
|
+ string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("strendtime"));
|
|
|
382
|
+ string strpageindex = RequestString.GetQueryString("page");
|
|
|
383
|
+ int pageindex = 1;
|
|
|
384
|
+ string strpagesize = RequestString.GetQueryString("pagesize");
|
|
|
385
|
+ int pagesize = 10;
|
|
|
386
|
+
|
|
|
387
|
+ //接收坐席Id
|
|
|
388
|
+
|
|
|
389
|
+ string sql = " and ISNULL(a.IsDelete,0) = 0 AND ISNULL(c.F_DeleteFlag,0) = 0 ";
|
|
|
390
|
+
|
|
|
391
|
+
|
|
|
392
|
+
|
|
|
393
|
+ #region 权限设置
|
|
|
394
|
+ //管理员,坐席班长
|
|
|
395
|
+ if (User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "ZXBZ")
|
|
|
396
|
+ {
|
|
|
397
|
+ //
|
|
|
398
|
+ }
|
|
|
399
|
+ else
|
|
|
400
|
+ {
|
|
|
401
|
+ sql += " and (b.ToUserId = " + User.F_UserId + " OR b.FromUserId = " + User.F_UserId + ") ";
|
|
|
402
|
+ }
|
|
|
403
|
+ #endregion
|
|
|
404
|
+
|
|
|
405
|
+ if (fromid > 0)
|
|
|
406
|
+ {
|
|
|
407
|
+ sql += " and (b.FromUserId = " + fromid + " or b.ToUserId = " + fromid + ") ";
|
|
|
408
|
+ }
|
|
|
409
|
+ if (isread != -1)
|
|
|
410
|
+ {
|
|
|
411
|
+ sql += " and ISNULL(b.IsRead,0) = " + isread + " ";
|
|
|
412
|
+ }
|
|
|
413
|
+ if (!string.IsNullOrEmpty(strstarttime))
|
|
|
414
|
+ {
|
|
|
415
|
+ sql += " and datediff(day,b.CreateDate,'" + strstarttime + "')<=0 ";
|
|
|
416
|
+ }
|
|
|
417
|
+ if (!string.IsNullOrEmpty(strendtime))
|
|
|
418
|
+ {
|
|
|
419
|
+ sql += " and datediff(day,b.CreateDate,'" + strendtime + "')>=0 ";
|
|
|
420
|
+ }
|
|
|
421
|
+ if (strpageindex.Trim() != "")
|
|
|
422
|
+ {
|
|
|
423
|
+ pageindex = Convert.ToInt32(strpageindex);
|
|
|
424
|
+ }
|
|
|
425
|
+ if (strpagesize.Trim() != "")
|
|
|
426
|
+ {
|
|
|
427
|
+ pagesize = Convert.ToInt32(strpagesize);
|
|
|
428
|
+ }
|
|
|
429
|
+ int recordCount = 0;
|
|
|
430
|
+ var col = "a.Id,b.FromUserId,b.ToUserId,a.Content,a.IsToAll,a.CreateDate,b.IsRead,c.F_UserName,c.F_UserCode,c.F_RoleId,d.F_UserName AS ToUserName,d.F_UserCode AS ToUserCode,d.F_RoleId AS ToRoleId";
|
|
|
431
|
+ dt = Bll.PagerBll.GetListPager(
|
|
|
432
|
+ " dbo.T_Msg_Chat a RIGHT JOIN dbo.T_Msg_Chat_Map b ON b.ChatId = a.Id LEFT JOIN dbo.T_Sys_UserAccount c ON c.F_UserId = b.FromUserId LEFT JOIN dbo.T_Sys_UserAccount d ON d.F_UserId = b.ToUserId ",
|
|
|
433
|
+ "b.Id",
|
|
|
434
|
+ col,
|
|
|
435
|
+ sql,
|
|
|
436
|
+ " ORDER BY a.CreateDate ASC",
|
|
|
437
|
+ pagesize,
|
|
|
438
|
+ pageindex,
|
|
|
439
|
+ true,
|
|
|
440
|
+ out recordCount);
|
|
|
441
|
+
|
|
|
442
|
+ var obj = new
|
|
|
443
|
+ {
|
|
|
444
|
+ rows = dt,
|
|
|
445
|
+ total = recordCount
|
|
|
446
|
+ };
|
|
|
447
|
+ return Content(obj.ToJson());
|
|
|
448
|
+ }
|
|
|
449
|
+ #endregion
|
|
|
450
|
+
|
|
|
451
|
+ /// <summary>
|
|
|
452
|
+ /// 即时聊天 - 保存最新通讯
|
|
|
453
|
+ /// </summary>
|
|
|
454
|
+ /// <returns></returns>
|
|
|
455
|
+ public ActionResult SaveChatInfo(ChatInput input)
|
|
|
456
|
+ {
|
|
|
457
|
+ //发送坐席Id
|
|
|
458
|
+
|
|
|
459
|
+ var model = new Model.T_Msg_Chat();
|
|
|
460
|
+ var modelmap = new Model.T_Msg_Chat_Map();
|
|
|
461
|
+ model.Content = input.Content; //必填
|
|
|
462
|
+ model.VoiceUrl = input.VoiceUrl;
|
|
|
463
|
+ model.FromUserId = User.F_UserId;
|
|
|
464
|
+ model.ToUserId = input.ToUserId;
|
|
|
465
|
+ model.ToRoleId = input.ToRoleId;
|
|
|
466
|
+ //如果用户和角色都为0,则发送所有人
|
|
|
467
|
+ if (input.ToUserId == 0 && input.ToRoleId == 0)
|
|
|
468
|
+ {
|
|
|
469
|
+ input.IsToAll = 1;
|
|
|
470
|
+ }
|
|
|
471
|
+ model.IsToAll = input.IsToAll;
|
|
|
472
|
+ int chatId = bllchat.Add(model);
|
|
|
473
|
+ if (chatId > 0)
|
|
|
474
|
+ {
|
|
|
475
|
+ modelmap.ChatId = chatId;
|
|
|
476
|
+ modelmap.FromUserId = User.F_UserId;
|
|
|
477
|
+ //群发聊天
|
|
|
478
|
+ if (input.IsToAll > 0)
|
|
|
479
|
+ {
|
|
|
480
|
+ var userList = userAccount.DataTableToList(userAccount.GetList(" F_DeleteFlag=0 ").Tables[0]);
|
|
|
481
|
+ foreach (var u in userList)
|
|
|
482
|
+ {
|
|
|
483
|
+ modelmap.ToUserId = u.F_UserId;
|
|
|
484
|
+ bllmap.Add(modelmap);
|
|
|
485
|
+ }
|
|
|
486
|
+ return Success("发送成功");
|
|
|
487
|
+ }
|
|
|
488
|
+ //角色聊天
|
|
|
489
|
+ if (input.ToRoleId > 0 && input.ToUserId == 0)
|
|
|
490
|
+ {
|
|
|
491
|
+ var userList = userAccount.DataTableToList(userAccount.GetList(" F_DeleteFlag=0 AND F_RoleId=" + input.ToRoleId + " ").Tables[0]);
|
|
|
492
|
+ foreach (var u in userList)
|
|
|
493
|
+ {
|
|
|
494
|
+ modelmap.ToUserId = u.F_UserId;
|
|
|
495
|
+ bllmap.Add(modelmap);
|
|
|
496
|
+ }
|
|
|
497
|
+ return Success("发送成功");
|
|
|
498
|
+ }
|
|
|
499
|
+ //私人聊天
|
|
|
500
|
+ modelmap.ToUserId = input.ToUserId;
|
|
|
501
|
+ //关闭之前所有的信息
|
|
|
502
|
+ string sqlwhere1 = "UPDATE dbo.T_Msg_Chat_Map SET IsRead = 1 WHERE FromUserId = " + input.ToUserId + " or ToUserId = " + User.F_UserId + " ";
|
|
|
503
|
+ DbHelperSQL.ExecuteSql(sqlwhere1);
|
|
|
504
|
+ //后添加新的信息
|
|
|
505
|
+ bllmap.Add(modelmap);
|
|
|
506
|
+ return Success("发送成功");
|
|
|
507
|
+ }
|
|
|
508
|
+ return Error("发送失败");
|
|
|
509
|
+ }
|
|
|
510
|
+
|
|
|
511
|
+ /// <summary>
|
|
|
512
|
+ /// 即时通讯 - 获取最新通讯(单方查看)
|
|
|
513
|
+ /// </summary>
|
|
|
514
|
+ /// <param name="isread">0未读1已读2全部</param>
|
|
|
515
|
+ /// <returns></returns>
|
|
|
516
|
+ public ActionResult GetChatLists(int top, int fromid, int isread = 0)
|
|
|
517
|
+ {
|
|
|
518
|
+ DataTable dt = null;
|
|
|
519
|
+ int recordCount = 0;
|
|
|
520
|
+ //接收坐席Id
|
|
|
521
|
+
|
|
|
522
|
+ string sql = " ISNULL(a.IsDelete,0) = 0 AND ISNULL(c.F_DeleteFlag,0) = 0 "; // AND ISNULL(b.IsRead,0) = 0
|
|
|
523
|
+ if (top <= 0)
|
|
|
524
|
+ {
|
|
|
525
|
+ top = 50;
|
|
|
526
|
+ }
|
|
|
527
|
+ if (fromid > 0)
|
|
|
528
|
+ {
|
|
|
529
|
+ //sql += " and ISNULL(b.FromUserId,0) = " + fromid + " ";
|
|
|
530
|
+ sql += " and (b.FromUserId = " + fromid + " or b.ToUserId = " + fromid + ") ";
|
|
|
531
|
+ sql += " and (b.ToUserId = " + User.F_UserId + " or b.FromUserId = " + User.F_UserId + ") ";
|
|
|
532
|
+ }
|
|
|
533
|
+ else
|
|
|
534
|
+ {
|
|
|
535
|
+ sql += " and b.ToUserId = " + User.F_UserId + " ";
|
|
|
536
|
+ }
|
|
|
537
|
+ if (isread != 2)
|
|
|
538
|
+ {
|
|
|
539
|
+ sql += " and ISNULL(b.IsRead,0) = " + isread + " ";
|
|
|
540
|
+ }
|
|
|
541
|
+ //查询(聊天记录)
|
|
|
542
|
+ string sql1 = "SELECT TOP " + top + " a.Id,b.FromUserId,b.ToUserId,a.Content,a.IsToAll,a.CreateDate,b.IsRead,c.F_UserName,c.F_RoleId,c.F_SexFlag,c.F_See FROM dbo.T_Msg_Chat a RIGHT JOIN dbo.T_Msg_Chat_Map b ON b.ChatId = a.Id LEFT JOIN dbo.T_Sys_UserAccount c ON c.F_UserId = a.FromUserId WHERE " + sql + " ORDER BY a.CreateDate ASC";
|
|
|
543
|
+ dt = DbHelperSQL.Query(sql1).Tables[0];
|
|
|
544
|
+ recordCount = dt.Rows.Count;
|
|
|
545
|
+
|
|
|
546
|
+ var obj = new
|
|
|
547
|
+ {
|
|
|
548
|
+ rows = dt,
|
|
|
549
|
+ total = recordCount
|
|
|
550
|
+ };
|
|
|
551
|
+ return Content(obj.ToJson());
|
|
|
552
|
+ }
|
|
|
553
|
+
|
|
|
554
|
+ /// <summary>
|
|
|
555
|
+ /// 即时通讯 - 获取最新通讯数量(单方查看)
|
|
|
556
|
+ /// </summary>
|
|
|
557
|
+ /// <param name="isread">0未读1已读2全部</param>
|
|
|
558
|
+ /// <returns></returns>
|
|
|
559
|
+ public ActionResult GetChatCount(int top)
|
|
|
560
|
+ {
|
|
|
561
|
+ DataTable dt = null;
|
|
|
562
|
+ int recordCount = 0;
|
|
|
563
|
+ //接收坐席Id
|
|
|
564
|
+
|
|
|
565
|
+ if (top <= 0)
|
|
|
566
|
+ {
|
|
|
567
|
+ top = 50;
|
|
|
568
|
+ }
|
|
|
569
|
+ string sql = " ISNULL(a.IsDelete,0) = 0 AND ISNULL(c.F_DeleteFlag,0) = 0 "; // AND ISNULL(b.IsRead,0) = 0
|
|
|
570
|
+ sql += " and b.ToUserId = " + User.F_UserId + " and ISNULL(b.IsRead,0) = 0 ";
|
|
|
571
|
+ //查询(聊天记录)
|
|
|
572
|
+ string sql1 = "SELECT TOP " + top + " a.Id FROM dbo.T_Msg_Chat a WITH (NOLOCK) RIGHT JOIN dbo.T_Msg_Chat_Map b WITH (NOLOCK) ON b.ChatId = a.Id LEFT JOIN dbo.T_Sys_UserAccount c WITH (NOLOCK) ON c.F_UserId = a.FromUserId WHERE " + sql + " ORDER BY a.CreateDate ASC";
|
|
|
573
|
+ dt = DbHelperSQL.Query(sql1).Tables[0];
|
|
|
574
|
+ recordCount = dt.Rows.Count;
|
|
|
575
|
+
|
|
|
576
|
+ var obj = new
|
|
|
577
|
+ {
|
|
|
578
|
+ rows = "",
|
|
|
579
|
+ total = recordCount
|
|
|
580
|
+ };
|
|
|
581
|
+ return Content(obj.ToJson());
|
|
|
582
|
+ }
|
|
|
583
|
+
|
|
|
584
|
+ /// <summary>
|
|
|
585
|
+ /// 即时通讯 - 获取最新通讯信息(单方查看)
|
|
|
586
|
+ /// </summary>
|
|
|
587
|
+ /// <param name="id"></param>
|
|
|
588
|
+ /// <param name="User.F_UserId"></param>
|
|
|
589
|
+ /// <returns></returns>
|
|
|
590
|
+ public ActionResult GetChatInfoById(int id)
|
|
|
591
|
+ {
|
|
|
592
|
+ if (id <= 0)
|
|
|
593
|
+ {
|
|
|
594
|
+ return Error("参数出错");
|
|
|
595
|
+ }
|
|
|
596
|
+ DataTable dt = null;
|
|
|
597
|
+ string cid = string.Empty, content = string.Empty, createDate = string.Empty, userName = string.Empty, isread = string.Empty, roleId = string.Empty;
|
|
|
598
|
+ //接收坐席Id
|
|
|
599
|
+
|
|
|
600
|
+ string sql = " ISNULL(a.IsDelete,0) = 0 AND ISNULL(c.F_DeleteFlag,0) = 0 "; // AND ISNULL(b.IsRead,0) = 0
|
|
|
601
|
+ if (User.F_UserId > 0)
|
|
|
602
|
+ {
|
|
|
603
|
+ sql += " and b.ToUserId = " + User.F_UserId + " ";
|
|
|
604
|
+ }
|
|
|
605
|
+ if (id > 0)
|
|
|
606
|
+ {
|
|
|
607
|
+ sql += " and a.Id = " + id + " ";
|
|
|
608
|
+ }
|
|
|
609
|
+ //查询(聊天记录)
|
|
|
610
|
+ string sql1 = "SELECT a.Id,a.FromUserId,a.Content,a.IsToAll,a.CreateDate,b.IsRead,c.F_UserName,c.F_RoleId FROM dbo.T_Msg_Chat a RIGHT JOIN dbo.T_Msg_Chat_Map b ON b.ChatId = a.Id LEFT JOIN dbo.T_Sys_UserAccount c ON c.F_UserId = a.FromUserId WHERE " + sql + " ORDER BY a.CreateDate ASC";
|
|
|
611
|
+ dt = DbHelperSQL.Query(sql1).Tables[0];
|
|
|
612
|
+ if (dt.Rows.Count > 0)
|
|
|
613
|
+ {
|
|
|
614
|
+ cid = dt.Rows[0]["Id"].ToString();
|
|
|
615
|
+ content = dt.Rows[0]["Content"].ToString();
|
|
|
616
|
+ createDate = dt.Rows[0]["CreateDate"].ToString();
|
|
|
617
|
+ userName = dt.Rows[0]["F_UserName"].ToString();
|
|
|
618
|
+ roleId = dt.Rows[0]["F_RoleId"].ToString();
|
|
|
619
|
+ isread = dt.Rows[0]["IsRead"].ToString();
|
|
|
620
|
+ }
|
|
|
621
|
+
|
|
|
622
|
+ //修改(设置已读)
|
|
|
623
|
+ string sqlwhere = " ISNULL(IsRead,0) = 0 ";
|
|
|
624
|
+ if (User.F_UserId > 0)
|
|
|
625
|
+ {
|
|
|
626
|
+ sqlwhere += " and ToUserId = " + User.F_UserId + " ";
|
|
|
627
|
+ }
|
|
|
628
|
+ if (id > 0)
|
|
|
629
|
+ {
|
|
|
630
|
+ sqlwhere += " and ChatId = " + id + " ";
|
|
|
631
|
+ }
|
|
|
632
|
+ string sqlwhere1 = "UPDATE dbo.T_Msg_Chat_Map SET IsRead = 1 WHERE " + sqlwhere + " ";
|
|
|
633
|
+ DbHelperSQL.ExecuteSql(sqlwhere1);
|
|
|
634
|
+
|
|
|
635
|
+ var obj = new
|
|
|
636
|
+ {
|
|
|
637
|
+ id = cid,
|
|
|
638
|
+ username = userName,
|
|
|
639
|
+ content = content,
|
|
|
640
|
+ createdate = createDate,
|
|
|
641
|
+ roleId = roleId,
|
|
|
642
|
+ isread = isread
|
|
|
643
|
+ };
|
|
|
644
|
+ return Content(obj.ToJson());
|
|
|
645
|
+ }
|
|
|
646
|
+
|
|
|
647
|
+ /// <summary>
|
|
|
648
|
+ /// 即时通讯 - 关闭通讯信息(单方查看)
|
|
|
649
|
+ /// </summary>
|
|
|
650
|
+ /// <param name="id"></param>
|
|
|
651
|
+ /// <param name="User.F_UserId"></param>
|
|
|
652
|
+ /// <returns></returns>
|
|
|
653
|
+ public ActionResult CloseChat(int id)
|
|
|
654
|
+ {
|
|
|
655
|
+ //接收坐席Id
|
|
|
656
|
+
|
|
|
657
|
+ int recordCount = 0;
|
|
|
658
|
+ //修改(设置已读)
|
|
|
659
|
+ string sqlwhere = " ISNULL(IsRead,0) = 0 ";
|
|
|
660
|
+ if (User.F_UserId > 0)
|
|
|
661
|
+ {
|
|
|
662
|
+ sqlwhere += " and ToUserId = " + User.F_UserId + " ";
|
|
|
663
|
+ }
|
|
|
664
|
+ if (id > 0)
|
|
|
665
|
+ {
|
|
|
666
|
+ sqlwhere += " and ChatId = " + id + " ";
|
|
|
667
|
+ }
|
|
|
668
|
+ string sqlwhere1 = "UPDATE dbo.T_Msg_Chat_Map SET IsRead = 1 WHERE " + sqlwhere + " ";
|
|
|
669
|
+ int n = DbHelperSQL.ExecuteSql(sqlwhere1);
|
|
|
670
|
+ if (n > 0)
|
|
|
671
|
+ {
|
|
|
672
|
+ recordCount = n;
|
|
|
673
|
+ }
|
|
|
674
|
+
|
|
|
675
|
+ var obj = new
|
|
|
676
|
+ {
|
|
|
677
|
+ rows = "",
|
|
|
678
|
+ total = recordCount
|
|
|
679
|
+ };
|
|
|
680
|
+ return Content(obj.ToJson());
|
|
|
681
|
+ }
|
|
|
682
|
+
|
|
|
683
|
+ /// <summary>
|
|
|
684
|
+ /// DataRow转成DataTable
|
|
|
685
|
+ /// </summary>
|
|
|
686
|
+ /// <param name="rows"></param>
|
|
|
687
|
+ /// <returns></returns>
|
|
|
688
|
+ public DataTable ToDataTable1(DataRow[] rows)
|
|
|
689
|
+ {
|
|
|
690
|
+ if (rows == null || rows.Length == 0) return null;
|
|
|
691
|
+ DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构
|
|
|
692
|
+ foreach (DataRow row in rows)
|
|
|
693
|
+ {
|
|
|
694
|
+ tmp.ImportRow(row); // 将DataRow添加到DataTable中
|
|
|
695
|
+ }
|
|
|
696
|
+ return tmp;
|
|
|
697
|
+ }
|
|
|
698
|
+
|
|
|
699
|
+ #endregion
|
|
219
|
700
|
|
|
220
|
701
|
}
|
|
221
|
702
|
}
|