| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- using CallCenter.Utility;
- using CallCenterApi.Common;
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers
- {
- public class MsgController : BaseController
- {
- /// <summary>
- /// 获取消息列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- string sql = " and isdel=0 ";
- DataTable dt = new DataTable();
-
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ua != null)
- {
- sql += " and CreateUser='" + ua.F_UserCode + "'";
- int state = RequestString.GetInt("state", -1);
- string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
- string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
- string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
- string strpageindex = RequestString.GetQueryString("page");
- int pageindex = 1;
- string strpagesize = RequestString.GetQueryString("pagesize");
- int pagesize = 10;
- if (state != -1)
- {
- sql += " and State='" + state + "'";
- }
- if (strkey.Trim() != "" && strkey != "undefined")
- {
- sql += " and Detail like '%" + strkey.Trim() + "%' ";
- }
- if (strstarttime.Trim() != "" && strstarttime != "undefined")
- {
- sql += " and datediff(day,CreateDate,'" + strstarttime + "')<=0 ";
- }
- if (strendtime.Trim() != "" && strendtime != "undefined")
- {
- sql += " and datediff(day,CreateDate,'" + strendtime + "')>=0 ";
- }
- if (strpageindex.Trim() != "")
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- if (strpagesize.Trim() != "")
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Msg_List",
- "ID",
- "*,dbo.GetUserName(CreateUser) as CreateUserName, dbo.GetUserName(ToUser) as ToUserName",
- sql,
- "ORDER BY ID desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- res = Content(obj.ToJson());
- }
- }
- }
- return res;
- }
- /// <summary>
- /// 添加/修改信息
- /// </summary>
- /// <returns></returns>
- public ActionResult AddMsg()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
-
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ua != null)
- {
- int id = RequestString.GetInt("id", 0);
- int type = RequestString.GetInt("type", 0);
- int toid = RequestString.GetInt("toid", 0);
- string usercode = RequestString.GetFormString("usercode");
- string cont = RequestString.GetFormString("cont");
- Model.T_Msg_List model = new Model.T_Msg_List();
- if (id == 0)
- {
- model.Detail = cont;
- model.Type = type;
- model.ToUser = usercode;
- model.ToID = toid;
- model.State = 0;
- model.IsDel = 0;
- model.CreateDate = DateTime.Now;
- model.CreateUser = ua.F_UserCode;
- if (new BLL.T_Msg_List().Add(model) > 0)
- {
- res = Success("新增成功!");
- }
- else
- {
- res = Error("新增失败!");
- }
- }
- else
- {
- model = new BLL.T_Msg_List().GetModel(id);
- if (model != null)
- {
- model.Detail = cont;
- model.Type = type;
- model.ToUser = usercode;
- model.ToID = toid;
- if (new BLL.T_Msg_List().Update(model))
- {
- res = Success("修改成功!");
- }
- else
- {
- res = Error("修改失败!");
- }
- }
- else
- {
- res = Error("修改失败!");
- }
- }
- }
- }
-
- }
- return res;
- }
- /// <summary>
- /// 删除消息
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelMsg(string[] ids)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
-
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ua != null)
- {
- if (ids != null && ids.Length > 0)
- {
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- string sql = "update T_Msg_List set IsDel=1,DelUser='" + ua.F_UserCode + "',DelTime=getdate() where ID in(" + idd.TrimEnd(',') + ")";
- if (!string.IsNullOrEmpty(idd.Trim()))
- {
- if (DbHelperSQL.ExecuteSql(sql) > 0)
- {
- res = Success("删除成功");
- }
- else
- {
- res = Error("删除失败");
- }
- }
- else
- {
- res = Error("请选择记录");
- }
- }
- else
- {
- res = Error("获取参数失败");
- }
- }
- }
-
- }
- return res;
- }
- /// <summary>
- /// 更新状态
- /// </summary>
- /// <param name="ids"></param>
- /// <param name="state"></param>
- /// <returns></returns>
- public ActionResult UpdateState(string[] ids,int state)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
-
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ua != null)
- {
- if (ids != null && ids.Length > 0)
- {
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- string sj = "null";
- if (state == 1)
- {
- sj = "getdate()";
- }
- string sql = "update T_Msg_List set State=" + state + ",ReadDate=" + sj + " where ID in(" + idd.TrimEnd(',') + ")";
- if (!string.IsNullOrEmpty(idd.Trim()))
- {
- if (DbHelperSQL.ExecuteSql(sql) > 0)
- {
- res = Success("更新成功");
- }
- else
- {
- res = Error("更新失败");
- }
- }
- else
- {
- res = Error("请选择记录");
- }
- }
- else
- {
- res = Error("获取参数失败");
- }
- }
- }
-
- }
- return res;
- }
- /// <summary>
- /// 阅读消息
- /// </summary>
- /// <returns></returns>
- public ActionResult ReadMsg()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
-
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ua != null)
- {
- int id = RequestString.GetInt("id", 0);
- Model.T_Msg_List model = new BLL.T_Msg_List().GetModel(id);
- if (model != null)
- {
- model.State = 0;
- model.ReadDate = DateTime.Now;
- if (new BLL.T_Msg_List().Update(model))
- {
- res = Success("成功!");
- }
- else
- {
- res = Error("失败!");
- }
- }
- else
- {
- res = Error("失败");
- }
- }
- }
-
- }
- return res;
- }
- }
- }
|