| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- 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 GroupController : BaseController
- {
- // GET: Group
- /// <summary>
- /// 获取班组列表
- /// </summary>
- /// <returns></returns>
- [Authority]
- public ActionResult GetList(int isdc = 0)
- {
- DataTable dt = new DataTable();
- string sql = " and F_IsDelete=0 ";
- string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
- string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
- string strpageindex = RequestString.GetQueryString("page");
- int pageindex = 1;
- string strpagesize = RequestString.GetQueryString("pagesize");
- int pagesize = 10;
- if (strcode.Trim() != "" && strcode != "undefined")
- {
- sql += " and F_GroupCode = '" + strcode.Trim() + "' ";
- }
- if (strname.Trim() != "" && strname != "undefined")
- {
- sql += " and F_GroupName like '%" + strname + "%' ";
- }
- if (strpageindex.Trim() != "")
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- if (strpagesize.Trim() != "")
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- string cols = "*,dbo.GetUserName(F_CreateUser) as UserName";
- if (isdc > 0)
- {
- var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Sys_Group where 1=1 " + sql).Tables[0];
- var msg = new NPOIHelper().ExportToExcel("班组列表", dtdc);
- if (msg == "")
- {
- return Success("导出成功");
- }
- else
- {
- return Error("导出失败");
- }
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Sys_Group",
- "F_Id",
- cols,
- sql,
- "ORDER BY F_CreateTime DESC",
- pagesize,
- pageindex,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取班组列表
- /// </summary>
- /// <returns></returns>
- [Authority]
- public ActionResult GetGroupList()
- {
- DataTable dt = new BLL.T_Sys_Group().GetList(" F_State=0 and F_IsDelete=0 ").Tables[0];
- dt.Columns.Add("Users", typeof(object));
- foreach (DataRow dr in dt.Rows)
- {
- dr["Users"] = new BLL.T_Sys_UserAccount().GetList(" F_GroupCode='"+dr["F_GroupCode"].ToString()+"' ").Tables[0];
- }
- return Success("加载成功", dt);
- }
- /// <summary>
- /// 获取班组
- /// </summary>
- /// <param name="GroupId"></param>
- /// <returns></returns>
- [Authority]
- public ActionResult GetGroup(int id = 0)
- {
- if (id != 0)
- {
- return Success("成功", new BLL.T_Sys_Group().GetModel(id));
- }
- else
- {
- return Error("参数错误");
- }
- }
- /// <summary>
- /// 获取班组
- /// </summary>
- /// <param name="GroupId"></param>
- /// <returns></returns>
- [Authority]
- public ActionResult GetGroupByCode(string code)
- {
- if (!string.IsNullOrEmpty(code))
- {
- return Success("成功", new BLL.T_Sys_Group().GetModelList(" F_GroupCode='" + code + "' ").FirstOrDefault());
- }
- else
- {
- return Error("参数错误");
- }
- }
- /// <summary>
- /// 添加班组
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- [Authority]
- public ActionResult AddGroup()
- {
- int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- int id = RequestString.GetInt("id", 0);
- string name = RequestString.GetFormString("name");
- string code = RequestString.GetFormString("code");
- string remark = RequestString.GetFormString("remark");
- Model.T_Sys_Group dModel = new Model.T_Sys_Group();
- if (id == 0)
- {
- var list = new BLL.T_Sys_Group().GetModelList(" F_GroupCode='" + code + "' and F_IsDelete=0 ");
- if (list.Count > 0)
- {
- return Error("已经存在此班组");
- }
- else
- {
- dModel.F_GroupCode = code;
- dModel.F_GroupName = name;
- dModel.F_Remark = remark;
- dModel.F_State = 0;
- dModel.F_IsDelete = 0;
- dModel.F_CreateUser = userModel.F_UserCode;
- dModel.F_CreateTime = DateTime.Now;
- int n = new BLL.T_Sys_Group().Add(dModel);
- if (n > 0)
- return Success("添加成功", n);
- else
- return Error("添加失败");
- }
- }
- else
- {
- dModel = new BLL.T_Sys_Group().GetModel(id);
- if (dModel != null)
- {
- var list = new BLL.T_Sys_Group().GetModelList(" F_GroupCode='" + code + "' and F_IsDelete=0 and F_Id!='" + id + "' ");
- if (list.Count > 0)
- {
- return Error("已经存在此班组");
- }
- else
- {
- dModel.F_GroupCode = code;
- dModel.F_GroupName = name;
- dModel.F_Remark = remark;
- if (new BLL.T_Sys_Group().Update(dModel))
- return Success("修改成功");
- else
- return Error("修改失败");
- }
- }
- else
- {
- return Error("修改失败");
- }
- }
- }
- /// <summary>
- /// 删除班组
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [Authority]
- public ActionResult DelGroup(string[] ids)
- {
- int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ids == null || ids.Length <= 0)
- {
- return Error("请选择要删除的班组");
- }
- var idStr = string.Join(",", ids);
- if (string.IsNullOrEmpty(idStr.Trim()))
- {
- return Error("请选择要删除的班组");
- }
- int n = DbHelperSQL.ExecuteSql(" update T_Sys_Group set F_IsDelete=1,F_DeleteUser='" + userModel.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
- if (n > 0)
- {
- return Success("删除成功");
- }
- return Error("删除失败");
- }
- }
- }
|