| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- using CallCenter.Utility;
- 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 AddressBookController : BaseController
- {
- private BLL.T_Cus_AddressBook bll = new BLL.T_Cus_AddressBook();
- public class AddressBook
- {
- public int id { get; set; }
- public string F_Name { get; set; }
- public string F_Sex { get; set; }
- public string F_Address { get; set; }
- public string F_Telephone { get; set; }
- public string F_Mobile { get; set; }
- public string F_ElseMobile { get; set; }
- public string F_Position { get; set; }
- public string F_Note { get; set; }
- public int F_Departmentid { get; set; }
- public string F_Area;
- public string F_Offce;
- public string F_Department;
- public string code;
- }
- public ActionResult Add(AddressBook address )
- {
- Model.T_Cus_AddressBook model = new Model.T_Cus_AddressBook();
- if (string.IsNullOrEmpty(address.F_Name))
- {
- return Error("姓名不能为空");
- }
- if (address.F_Departmentid <0)
- {
- return Error("部门不能为空");
- }
- if (string.IsNullOrEmpty(address.F_Mobile))
- {
- return Error("手机号不能为空");
- }
- if (address.id == 0)
- {
- model.F_Name = address.F_Name;
- model.F_Sex = address.F_Sex;
- model.F_Address = address.F_Address;
- model.F_Telephone = address.F_Telephone;
- model.F_Mobile = address.F_Mobile;
- model.F_ElseMobile = address.F_ElseMobile;
- var deptment = new BLL.T_Sys_Department().GetModel(address.F_Departmentid);
- if (deptment!=null )
- {
- model.F_Department = deptment.F_DeptName ;
- model.F_DepartmentId = deptment.F_DeptId ;
- }
- model.F_Position = address.F_Position;
- model.F_Note = address.F_Note;
- int n = bll.Add(model);
- if (n > 0)
- {
- return Success("添加成功", n);
- }
- else
- {
- return Error("添加失败");
- }
- }
- else
- {
- model = bll.GetModel(address.id);
- if (model != null)
- {
- model.F_UserId = address.id;
- model.F_Name = address.F_Name;
- model.F_Sex = address.F_Sex;
- model.F_Address = address.F_Address;
- model.F_Telephone = address.F_Telephone;
- model.F_Mobile = address.F_Mobile;
- model.F_ElseMobile = address.F_ElseMobile;
- var deptment = new BLL.T_Sys_Department().GetModel(address.F_Departmentid);
- if (deptment != null)
- {
- model.F_Department = deptment.F_DeptName;
- model.F_DepartmentId = deptment.F_DeptId;
- }
- model.F_Position = address.F_Position;
- model.F_Note = address.F_Note;
- if (bll.Update(model))
- {
- return Success("修改成功");
- }
- else
- {
- return Error("修改失败");
- }
- }
- return Error("信息不存在");
- }
- }
- public List<AddressBook> AddressBooks(List<Model.T_Cus_AddressBook> addressBooks)
- {
- List<AddressBook> Input = new List<AddressBook>();
- foreach (var it in addressBooks)
- {
- AddressBook model = new AddressBook();
- model.id = it.F_UserId;
- model.F_Name = it.F_Name;
- if (!string .IsNullOrEmpty (it.F_Name))
- {
- char[] strCharArr = it.F_Name.ToCharArray();
- model. code = GetSpellCode(strCharArr[0].ToString ());
- }
- model.F_Sex = it.F_Sex;
- model.F_Address = it.F_Address;
- model.F_Telephone = it.F_Telephone;
- model.F_Mobile = it.F_Mobile;
- model.F_ElseMobile = it.F_ElseMobile;
- model.F_Position = it.F_Position;
- model.F_Note = it.F_Note;
- if (it.F_DepartmentId >0 )
- {
- Model.T_Sys_Department t_Sys_Department = new BLL.T_Sys_Department().GetModel(it.F_DepartmentId);
- if (t_Sys_Department!=null )
- model.F_Department = t_Sys_Department.F_DeptName ;
- }
- else
- model.F_Department = it.F_Department;
- var deptment = new BLL.T_Sys_Department().GetModel(it.F_DepartmentId );
- if (deptment != null)
- {
- var deptment1 = new BLL.T_Sys_Department().GetModel(deptment.F_ParentId);
- if (deptment.F_Layer ==1)
- {
- model.F_Offce = deptment.F_DeptName;
- if (deptment1 != null)
- {
- model.F_Area = deptment1.F_DeptName;
- }
- }
- else if (deptment.F_Layer == 2)
- {
- model.F_Offce = deptment.F_DeptName;
- if (deptment1!=null )
- {
- model.F_Area = deptment1.F_DeptName;
- }
- }
- else if (deptment.F_Layer == 3)
- {
- if (deptment1 != null)
- {
- model.F_Offce = deptment1.F_DeptName;
- var deptment2 = new BLL.T_Sys_Department().GetModel(deptment.F_ParentId);
- if (deptment2!=null )
- {
- model.F_Area = deptment2.F_DeptName;
- }
- }
- }
- else
- {
- model.F_Offce = deptment.F_DeptName;
- if (deptment1 != null)
- {
- model.F_Area = deptment1.F_DeptName;
- }
- }
- }
- Input.Add(model);
- }
- return Input;
- }
- /// <summary>
- /// 得到一个汉字的拼音第一个字母,如果是一个英文字母则直接返回大写字母
- /// </summary>
- /// <param name="CnChar">单个汉字</param>
- /// <returns>单个大写字母</returns>
- private string GetSpellCode(string CnChar)
- {
- long iCnChar;
- byte[] arrCN = System.Text.Encoding.Default.GetBytes(CnChar);
- //如果是字母,则直接返回
- if (arrCN.Length == 1)
- {
- CnChar = CnChar.ToUpper();
- }
- else
- {
- int area = (short)arrCN[0];
- int pos = (short)arrCN[1];
- iCnChar = (area << 8) + pos;
- // iCnChar match the constant
- string letter = "ABCDEFGHJKLMNOPQRSTWXYZ";
- int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614,
- 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906,
- 51387, 51446, 52218, 52698, 52980, 53689, 54481, 55290 };
- for (int i = 0; i < 23; i++)
- {
- if (areacode[i] <= iCnChar && iCnChar < areacode[i + 1])
- {
- CnChar = letter.Substring(i, 1);
- break;
- }
- }
- }
- return CnChar;
- }
- /// <summary>
- /// 获取一条详细信息 Id
- /// </summary>
- /// <param name="infoid"></param>
- /// <returns></returns>
- public ActionResult GetAppInfo(string infoid)
- {
- if (infoid != null && infoid.Trim() != "")
- {
- Model.T_Cus_AddressBook model = bll.GetModel(int.Parse(infoid.Trim()));
- if (model != null)
- {
- var list = new List<Model.T_Cus_AddressBook>();
- if (model != null)
- list.Add(model);
- List<AddressBook> Input = AddressBooks(list);
- return Success("获取成功", Input);
- }
- else
- {
- return Error("获取失败");
- };
- }
- else
- {
- return Error("获取参数失败");
- }
- }
- public ActionResult GetAppList(string keywords)
- {
- if (Request.IsAuthenticated)
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- int dptid = 0;
- if (userModel != null)
- {
- dptid = userModel.F_DeptId;
- }
- if (userModel.F_RoleId == 49)
- {
- dptid = 1;
- }
- if (userModel.F_See == "5")
- return Success("暂无记录");
-
- DataTable dt = new DataTable();
- string sql = "F_IsDelete=0 ";
- if (!string.IsNullOrEmpty(keywords))
- {
- var dept = new BLL.T_Sys_Department().GetModelList("F_DeptName like '%" + keywords + "%'").FirstOrDefault();
- if (dept != null)
- {
- if (dptid == 1)
- dptid = dept.F_DeptId;
- else
- {
- sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
- }
- }
- else
- {
- sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
- }
-
- }
- Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
- if (dptid > 0)
- {
- sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
- }
- var modelList = bll.GetAPPList(sql+ " order by code asc").Tables[0];
- // List<AddressBook> Input = AddressBooks(modelList);
- // var modelListOrder = Input.OrderBy(x => x.F_Name);
- return Content(modelList.ToJson());
- }
- return NoToken("未知错误,请重新登录");
- }
- public ActionResult GetAppModelList(string keywords, int pageindex = 1, int pagesize = 10)
- {
- if (Request.IsAuthenticated)
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- List<AddressBook> Input = new List<AddressBook>();
- int dptid = 0;
- if (userModel != null)
- {
- dptid = userModel.F_DeptId;
- }
- if (userModel.F_RoleId == 49)
- {
- dptid = 1;
- }
- if (userModel.F_See == "5")
- return Success("暂无记录");
-
- DataTable dt = new DataTable();
- string sql = "F_IsDelete=0 ";
- if (!string.IsNullOrEmpty(keywords))
- {
- var dept = new BLL.T_Sys_Department().GetModelList("F_DeptName like '%" + keywords + "%'").FirstOrDefault();
- if (dept != null)
- {
- if (dptid == 1)
- dptid = dept.F_DeptId;
- else
- {
- sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
- }
- }
- else
- {
- sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
- }
-
- }
- Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
- if (dptid > 0)
- {
- sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
- }
-
- var modelList = bll.GetAPPList(sql + " order by code asc").Tables[0];
- if (pageindex* pagesize<modelList .Rows .Count )
- {
- for (int i=0;i< modelList.Rows .Count;i ++)
- {
- if (i>= pageindex * pagesize- pagesize&& i< pageindex * pagesize)
- {
- AddressBook model = new AddressBook();
- model = BookData(modelList.Rows[i]);
- Input.Add(model);
- }
- }
-
- }
- else
- {
- for (int i = 0; i < modelList.Rows.Count; i++)
- {
- AddressBook model = new AddressBook();
- model = BookData(modelList.Rows[i]);
- Input.Add(model);
- }
- }
- // List<AddressBook> Input = AddressBooks(modelList);
- // var modelListOrder = Input.OrderBy(x => x.F_Name);
- return Content(Input.ToJson());
- }
- return NoToken("未知错误,请重新登录");
- }
- public AddressBook BookData(DataRow dt)
- {
- AddressBook model = new AddressBook();
- if (dt["F_UserId"] != null && dt["F_UserId"].ToString() != "")
- model.id = int.Parse (dt["F_UserId"] .ToString());
- if (dt["F_Name"] != null && dt["F_Name"].ToString() != "")
- model.F_Name = dt["F_Name"].ToString();
- if (dt["code"] != null && dt["code"].ToString() != "")
- model.code = dt["code"].ToString();
- if (dt["F_Sex"] != null && dt["F_Sex"].ToString() != "")
- model.F_Sex = dt["F_Sex"].ToString();
- if (dt["F_Address"] != null && dt["F_Address"].ToString() != "")
- model.F_Address = dt["F_Address"].ToString();
- if (dt["F_Telephone"] != null && dt["F_Telephone"].ToString() != "")
- model.F_Telephone = dt["F_Telephone"].ToString();
- if (dt["F_Mobile"] != null && dt["F_Mobile"].ToString() != "")
- model.F_Mobile = dt["F_Mobile"].ToString();
- if (dt["F_ElseMobile"] != null && dt["F_ElseMobile"].ToString() != "")
- model.F_ElseMobile = dt["F_ElseMobile"].ToString();
- if (dt["F_Position"] != null && dt["F_Position"].ToString() != "")
- model.F_Position = dt["F_Position"].ToString();
- if (dt["F_Note"] != null && dt["F_Note"].ToString() != "")
- model.F_Note = dt["F_Note"].ToString();
- if (dt["F_Department"] != null && dt["F_Department"].ToString() != "")
- model.F_Department = dt["F_Department"].ToString();
- if (dt["F_Area"] != null && dt["F_Area"].ToString() != "")
- model.F_Area = dt["F_Area"].ToString();
- if (dt["F_Offce"] != null && dt["F_Offce"].ToString() != "")
- model.F_Offce = dt["F_Offce"].ToString();
- return model;
- }
- /// <summary>
- /// 获取一条详细信息 Id
- /// </summary>
- /// <param name="infoid"></param>
- /// <returns></returns>
- public ActionResult GetInfo(string infoid)
- {
- if (infoid != null && infoid.Trim() != "")
- {
- Model.T_Cus_AddressBook model = bll.GetModel(int.Parse(infoid.Trim()));
- if (model != null)
- {
- return Success("获取成功", model);
- }
- else
- {
- return Error("获取失败");
- };
- }
- else
- {
- return Error("获取参数失败");
- }
- }
- /// <summary>
- /// 删除通讯录信息
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelAddressBook(string[] ids)
- {
- if (ids != null && ids.Length > 0)
- {
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- string sql = "UPDATE dbo.T_Cus_AddressBook SET F_IsDelete = 1 WHERE F_UserId in(" + idd.TrimEnd(',') + ")";
- if (!string.IsNullOrEmpty(idd.Trim()))
- {
- if (DbHelperSQL.ExecuteSql(sql) > 0)
- {
- return Success("设置成功");
- }
- else
- {
- return Error("设置失败");
- }
- }
- else
- {
- return Error("请选择用户");
- }
- }
- else
- {
- return Error("获取参数失败");
- }
- }
- public ActionResult GetList(string keywords)
- {
- if (Request.IsAuthenticated)
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- Model.T_Sys_RoleInfo ro = new BLL.T_Sys_RoleInfo().GetModel(userModel.F_RoleId);
- int dptid = 0;
- if (userModel != null)
- {
- dptid = userModel.F_DeptId;
- }
- if (ro.F_RoleCode == "CLZY" || ro.F_RoleCode == "ZR" || ro.F_RoleCode == "XTGLY")
- {
- dptid = 1;
- }
- if (userModel.F_See == "5")
- return Success("暂无记录");
- Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
- DataTable dt = new DataTable();
- string sql = "F_IsDelete=0 ";
- if (!string.IsNullOrEmpty(keywords))
- {
- sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
- }
- if (dptid > 0)
- {
- sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
- }
- var modelList = bll .GetModelList(sql);
- List<AddressBook> Input = AddressBooks(modelList);
- var modelListOrder = Input.OrderBy(x => x.F_Name );
- return Content(modelListOrder.ToJson());
- }
- return NoToken("未知错误,请重新登录");
- }
-
- public ActionResult GetModelList(string keywords, int pageindex = 1, int pagesize = 10)
- {
- if (Request.IsAuthenticated)
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- Model.T_Sys_RoleInfo ro = new BLL.T_Sys_RoleInfo().GetModel(userModel.F_RoleId);
- int dptid = 0;
- if (userModel != null)
- {
- dptid = userModel.F_DeptId;
- }
- if (ro.F_RoleCode == "CLZY" || ro.F_RoleCode == "ZR" || ro.F_RoleCode == "XTGLY")
- {
- dptid = 1;
- }
- if (userModel.F_See == "5")
- return Success("暂无记录");
- Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
- DataTable dt = new DataTable();
- string sql = "and F_IsDelete=0 ";
-
- if (!string.IsNullOrEmpty(keywords))
- {
- sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
- }
- if (dptid > 0)
- {
- sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
- }
- int recordCount = 0;
- if (!string.IsNullOrWhiteSpace(sql))
- {
- dt = BLL.PagerBLL.GetListPager(
- "T_Cus_AddressBook",
- "F_UserId",
- "*",
- sql,
- "ORDER BY T_Cus_AddressBook.F_UserId desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- }
- List<Model.T_Cus_AddressBook> modlelist = new BLL.T_Cus_AddressBook().DataTableToList(dt);
- List<AddressBook> Input = AddressBooks(modlelist);
- var modelListOrder = Input.OrderBy(x => x.F_Name);
-
- if (modlelist.Count > 0)
- {
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = modelListOrder,
- total = recordCount
- };
- return Content(obj.ToJson()); ;
- }
- else
- {
- return Success("暂无记录"); ;
- }
- }
- return NoToken("未知错误,请重新登录");
- }
- }
- }
|