| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- using CallCenter.Utility;
- using CallCenterApi.Interface.Controllers.Base;
- using CallCenterApi.Interface.Models.Filter;
- using CallCenterApi.Interface.Models.Input;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers
- {
-
- public class DictionaryController : BaseController
- {
- private BLL.T_Sys_DictionaryBase dictionaryBaseBLL = new BLL.T_Sys_DictionaryBase();
- private BLL.T_Sys_DictionaryValue dictionaryValueBLL = new BLL.T_Sys_DictionaryValue();
- #region 字典操作
- /// <summary>
- /// 获取字典列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetList(FilterDictionary filter)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- var sql = " and F_State=1 ";
- var recordCount = 0;
- var dt = BLL.PagerBLL.GetListPager(
- "T_Sys_DictionaryBase",
- "F_DictionaryFlag",
- "*",
- sql,
- "ORDER BY F_Sort ",
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- List<Model.T_Sys_DictionaryBase> modelList = new BLL.T_Sys_DictionaryBase().DataTableToList(dt);
- var obj = new
- {
- rows = modelList.Select(x => new
- {
- name = x.F_DictionaryName,
- flag = x.F_DictionaryFlag,
- sort = x.F_Sort
- }),
- total = recordCount
- };
- res = Content(obj.ToJson());
- }
- return res;
- }
- /// <summary>
- /// 获取字典
- /// </summary>
- /// <param name="dicFlag"></param>
- /// <returns></returns>
- public ActionResult GetDic(string dicFlag)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- Model.T_Sys_DictionaryBase baseModel = dictionaryBaseBLL.GetModel(dicFlag);
- if (baseModel != null)
- res = Success("加载字典成功", new
- {
- name = baseModel.F_DictionaryName,
- flag = baseModel.F_DictionaryFlag,
- sort = baseModel.F_Sort
- });
- else
- res = Error("加载字典失败");
- }
- return res;
- }
- //[Authority]
- /// <summary>
- /// 添加字典
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public ActionResult AddDic(DictionaryBaseInput input)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- Model.T_Sys_DictionaryBase orderModel = new Model.T_Sys_DictionaryBase();
- BLL.T_Sys_DictionaryBase orderBll = new BLL.T_Sys_DictionaryBase();
- orderModel.F_DictionaryFlag = input.DicFlag;
- orderModel.F_DictionaryName = input.Name;
- orderModel.F_Describe = input.Remark;
- orderModel.F_State = true;
- orderModel.F_Sort = input.Sort;
- if (orderBll.Add(orderModel))
- res = Success("字典添加成功");
- else
- res = Error("字典添加失败");
- }
- return res;
- }
- //[Authority]
- /// <summary>
- /// 编辑字典
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public ActionResult EditDic(DictionaryBaseInput input)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- BLL.T_Sys_DictionaryBase orderBll = new BLL.T_Sys_DictionaryBase();
- Model.T_Sys_DictionaryBase orderModel = orderBll.GetModel(input.DicFlag);
- if (orderModel == null)
- return Error("字典对象不存在");
- orderModel.F_DictionaryFlag = input.DicFlag;
- orderModel.F_DictionaryName = input.Name;
- orderModel.F_Describe = input.Remark;
- orderModel.F_Sort = input.Sort;
- if (orderBll.Update(orderModel))
- res = Success("字典添加成功");
- else
- res = Error("字典添加失败");
- }
- return res;
- }
- //[Authority]
- /// <summary>
- /// 删除字典
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelDic(string[] ids)
- {
- if (Request.IsAuthenticated)
- {
- if (ids == null || ids.Length <= 0)
- return Error("获取参数失败");
- StringBuilder sb = new StringBuilder();
- foreach (var item in ids)
- {
- sb.Append("'" + item + "',");
- }
- if (new BLL.T_Sys_DictionaryBase().DeleteList(sb.ToString().Trim(',')))
- return Success("删除成功");
- else
- return Error("删除失败");
- }
- return Error("删除失败");
- }
- #endregion
- #region 字典值操作
- //获取字典值列表
- public ActionResult GetDicValueList(FilterDictionary filter)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- string sql = "";
- DataTable dt = new DataTable();
- if (!string.IsNullOrWhiteSpace(filter.Id))
- {
- sql += " and F_DictionaryFlag= '" + filter.Id + "' ";
- }
- if (!string.IsNullOrWhiteSpace(filter.Flag))
- {
- sql += " and F_DictionaryFlag like '%" + filter.Flag + "%' ";
- }
- if (!string.IsNullOrWhiteSpace(filter.Name))
- {
- sql += " and F_Name like '%" + filter.Name + "%' ";
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Sys_DictionaryValue",
- "F_DictionaryValueId",
- "*",
- sql,
- "ORDER BY F_Sort ",
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- List<Model.T_Sys_DictionaryValue> modelList = new BLL.T_Sys_DictionaryValue().DataTableToList(dt);
- var obj = new
- {
- rows = dt,
- total = recordCount
- };
- res = Content(obj.ToJson());
- }
- return res;
- }
- //获取字典值列表
- public ActionResult GetDicValueListByFlag(string flag,string key)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- DataTable dt = new DataTable();
- var sql = "";
- if (!string.IsNullOrWhiteSpace(key))
- sql += " and F_Name like '%" + key + "%' ";
- dt = new BLL.T_Sys_DictionaryValue().GetList(" F_DictionaryFlag='" + flag + "' and F_State=1 "+ sql).Tables[0];
- res = Success("列表加载成功", dt);
- }
- return res;
- }
- //加载字典值
- public ActionResult GetDicValue(int dicValueId = 0)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- if (dicValueId <= 0)
- return Error("字典值标识传输失败");
- Model.T_Sys_DictionaryValue valueModel = dictionaryValueBLL.GetModel(dicValueId);
- if (valueModel != null)
- res = Success("加载字典值成功", new
- {
- id = valueModel.F_DictionaryValueId,
- dicflag = valueModel.F_DictionaryFlag,
- name = valueModel.F_Name,
- remark = valueModel.F_Describe,
- sort = valueModel.F_Sort,
- });
- else
- res = Error("加载字典值失败");
- }
- return res;
- }
- //[Authority]
- //添加字典值
- public ActionResult AddDicValue(DictionaryValueInput input)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- Model.T_Sys_DictionaryValue orderModel = new Model.T_Sys_DictionaryValue();
- BLL.T_Sys_DictionaryValue orderBll = new BLL.T_Sys_DictionaryValue();
- orderModel.F_Name = input.DicvName;
- orderModel.F_Describe = input.DicDes;
- orderModel.F_State = true;
- orderModel.F_ValueCode = "";
- orderModel.F_DictionaryFlag = input.DicFlag;
- orderModel.F_Sort = input.Sort;
- if (orderBll.Add(orderModel) > 0)
- res = Success("字典值添加成功");
- else
- res = Error("字典值添加失败");
- }
- return res;
- }
- ////[Authority]
- //编辑字典值
- public ActionResult EditDicValue(DictionaryValueInput input)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- if (input.DicVid <= 0)
- return Error("字典值id获取失败");
- BLL.T_Sys_DictionaryValue orderBll = new BLL.T_Sys_DictionaryValue();
- Model.T_Sys_DictionaryValue orderModel = orderBll.GetModel(input.DicVid);
- if (orderModel == null)
- return Error("字典值对象获取失败");
- orderModel.F_Name = input.DicvName;
- orderModel.F_Describe = input.DicDes;
- orderModel.F_ValueCode = "";
- orderModel.F_DictionaryFlag = input.DicFlag;
- orderModel.F_Sort = input.Sort;
- if (orderBll.Update(orderModel))
- res = Success("字典值编辑成功");
- else
- res = Error("字典值编辑失败");
- }
- return res;
- }
- //[Authority]
- //删除字典值
- public ActionResult DelDicValue(string[] ids)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- if (ids == null || ids.Length <= 0)
- return Error("获取参数失败");
- var idStr = string.Join(",", ids);
- if (new BLL.T_Sys_DictionaryValue().DeleteList(idStr))
- res = Success("删除成功");
- else
- res = Error("删除失败");
- }
- return res;
- }
- #endregion
- #region 乡镇村管理
- BLL.T_Sys_DicCountry cBll = new BLL.T_Sys_DicCountry();
- //获取行政村列表
- public ActionResult GetDicCountryList(string name,int dicvalueid,int PageSize=10,int PageIndex=1)
- {
- string sql = "";
- DataTable dt = new DataTable();
- if (dicvalueid>0)
- {
- sql += " and isnull(F_DicValueId,'')= '" + dicvalueid + "' ";
- }
- if (!string.IsNullOrWhiteSpace(name))
- {
- sql += " and F_Country like '%" + name + "%' ";
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Sys_DicCountry",
- "F_DicCountryId",
- "*",
- sql,
- "ORDER BY CreateTime desc ",
- PageSize,
- PageIndex,
- true,
- out recordCount);
- var obj = new
- {
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- //获取行政村列表
- public ActionResult GetDicCountryListByDic(int dicvalueid)
- {
- DataTable dt = new DataTable();
- dt = cBll.GetList(" isnull(F_DicValueId,'')= '" + dicvalueid + "' ").Tables[0];
- return Success("列表加载成功", dt);
- }
- //加载行政村
- public ActionResult GetDicCountry(int diccId = 0)
- {
- if (diccId <= 0)
- return Error("标识传输失败");
- Model.T_Sys_DicCountry valueModel = cBll.GetModel(diccId);
- if (valueModel != null)
- return Success("加载字典值成功", valueModel);
- else
- return Error("加载字典值失败");
- }
- //添加行政村
- public ActionResult AddDicCountry(string name,int dicvalueid)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ua != null)
- {
- Model.T_Sys_DicCountry orderModel = new Model.T_Sys_DicCountry();
- orderModel.F_Country = name;
- orderModel.F_DicValueId = dicvalueid;
- orderModel.CreateUser = ua.F_UserCode;
- orderModel.CreateTime = DateTime.Now;
- if (cBll.Add(orderModel) > 0)
- return Success("行政村添加成功");
- else
- return Error("行政村添加失败");
- }
- return Error("不存在此用户");
- }
- return NoToken("未知错误,请重新登录");
- }
- //编辑行政村
- public ActionResult EditDicCountry(int dicid, string name, int dicvalueid)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- if (dicid <= 0)
- return Error("id获取失败");
- Model.T_Sys_DicCountry orderModel = cBll.GetModel(dicid);
- if (orderModel == null)
- return Error("对象获取失败");
- orderModel.F_Country = name;
- orderModel.F_DicValueId = dicvalueid;
- if (cBll.Update(orderModel))
- return Success("行政村编辑成功");
- else
- return Error("行政村编辑失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- //删除行政村
- public ActionResult DelDicCountry(string[] ids)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- if (ids == null || ids.Length <= 0)
- return Error("获取参数失败");
- var idStr = string.Join(",", ids);
- if (cBll.DeleteList(idStr))
- return Success("删除成功");
- else
- return Error("删除失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- #endregion
- }
- }
|