足力健后端,使用.netcore版本,合并1个项目使用

SeatGroupController.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.IRepositories;
  5. using System.Linq;
  6. using System.Linq.Expressions;
  7. using System.Model;
  8. using System.Security.Claims;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using SqlSugar;
  13. using TVShoppingCallCenter_ZLJ.Models.Inputs;
  14. namespace TVShoppingCallCenter_ZLJ.Controllers.System
  15. {
  16. [Authorize]
  17. [Produces("application/json")]
  18. [Route("api/[controller]")]
  19. public class SeatGroupController : BaseController
  20. {
  21. private readonly ISys_SeatGroupRepository _sys_seatgroupRepository;
  22. public SeatGroupController(ISys_SeatGroupRepository sys_seatgroupRepository)
  23. {
  24. _sys_seatgroupRepository = sys_seatgroupRepository;
  25. }
  26. /// <summary>
  27. /// 获取坐席组列表
  28. /// </summary>
  29. /// <param name="filter"></param>
  30. /// <returns></returns>
  31. [Authorize]
  32. [HttpGet("getlistbypage")]
  33. public async Task<IActionResult> GetListsByPage(string key, int pageindex = 1, int pagesize = 20)
  34. {
  35. List<IConditionalModel> conModels = new List<IConditionalModel>();
  36. #region 条件筛选
  37. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  38. if (!string.IsNullOrEmpty(key))
  39. {
  40. conModels.Add(new ConditionalCollections()
  41. {
  42. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  43. {
  44. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_ZXZName", ConditionalType = ConditionalType.Like, FieldValue = key }),
  45. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_ZXZCode", ConditionalType = ConditionalType.Like, FieldValue = key }),
  46. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_ZXAtt", ConditionalType = ConditionalType.Like, FieldValue = key })
  47. }
  48. });
  49. }
  50. #endregion
  51. int recordCount = 0;
  52. var list = await _sys_seatgroupRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, "F_CreateOn desc");
  53. return Success("成功", list);
  54. }
  55. [Authorize]
  56. [HttpGet("getlistdrop")]
  57. public async Task<IActionResult> GetListDrop(string key)
  58. {
  59. List<IConditionalModel> conModels = new List<IConditionalModel>();
  60. #region 条件筛选
  61. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  62. if (!string.IsNullOrEmpty(key))
  63. {
  64. conModels.Add(new ConditionalCollections()
  65. {
  66. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  67. {
  68. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_ZXZCode", ConditionalType = ConditionalType.Like, FieldValue = key }),
  69. new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_ZXZName", ConditionalType = ConditionalType.Like, FieldValue = key }),
  70. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_ZXAtt", ConditionalType = ConditionalType.Like, FieldValue = key })
  71. }
  72. });
  73. }
  74. #endregion
  75. var list = await _sys_seatgroupRepository.GetListALL(conModels, "F_CreateOn desc");
  76. var result = list.Select(x => new {
  77. x.F_ZXZID,
  78. x.F_ZXZCode,
  79. x.F_ZXZName,
  80. x.F_ZXAtt
  81. });
  82. return Success("获取全部数据成功", result);
  83. }
  84. /// <summary>
  85. /// 获取实体
  86. /// </summary>
  87. [Authorize]
  88. [HttpGet("getdetails")]
  89. public async Task<IActionResult> GetDetails(int id)
  90. {
  91. if (id > 0)
  92. {
  93. var dModel = await _sys_seatgroupRepository.GetSingle(x => x.F_ZXZID == id && x.F_State == (int)EnumDelState.Enabled);
  94. if (dModel != null)
  95. {
  96. return Success("获取坐席组成功", dModel);
  97. }
  98. else
  99. {
  100. return Error("获取坐席组失败");
  101. }
  102. }
  103. else
  104. {
  105. return Error("获取参数失败");
  106. }
  107. }
  108. /// <summary>
  109. /// 添加坐席组
  110. /// </summary>
  111. [Authorize]
  112. [HttpPost("add")]
  113. public async Task<IActionResult> Add(SeatGroupInput input)
  114. {
  115. #region 验证
  116. if (string.IsNullOrWhiteSpace(input.zxzcode))
  117. {
  118. return Error("编号不能为空");
  119. }
  120. if (string.IsNullOrWhiteSpace(input.zxzname))
  121. {
  122. return Error("名称不能为空");
  123. }
  124. if (string.IsNullOrWhiteSpace(input.zxatt))
  125. {
  126. return Error("坐席地区号不能为空");
  127. }
  128. if (string.IsNullOrWhiteSpace(input.whwdkey))
  129. {
  130. return Error("外呼外地前缀不能为空");
  131. }
  132. if (string.IsNullOrWhiteSpace(input.whbdkey))
  133. {
  134. return Error("外呼本地前缀不能为空");
  135. }
  136. if (!ValidateString.IsNumberStr(input.whwdkey.Trim().ToString()))
  137. {
  138. return Error("外呼外地前缀必须为数字");
  139. }
  140. if (!ValidateString.IsNumberStr(input.whbdkey.Trim().ToString()))
  141. {
  142. return Error("外呼本地前缀必须为数字");
  143. }
  144. if (await GetExistByCodeAsync(input.zxzcode, 0) || await GetExistByNameAsync(input.zxzname, 0))
  145. {
  146. return Error("坐席组编号和名称必须唯一,请重新输入!");
  147. }
  148. #endregion
  149. T_Sys_SeatGroup clmodel = new T_Sys_SeatGroup();
  150. clmodel.F_ZXZCode = input.zxzcode.Trim();
  151. clmodel.F_IVRKey = input.ivrkey;
  152. clmodel.F_ZXZName = input.zxzname.Trim();
  153. clmodel.F_ZXAtt = input.zxatt.Trim();
  154. clmodel.F_WHWDKey = input.whwdkey.Trim();
  155. clmodel.F_WHBDKey = input.whbdkey.Trim();
  156. clmodel.F_Des = input.des;
  157. clmodel.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";
  158. clmodel.F_CreateOn = DateTime.Now;
  159. clmodel.F_State = (int)EnumDelState.Enabled;
  160. var res = await _sys_seatgroupRepository.Add(clmodel);
  161. if (res > 0)
  162. return Success("坐席组保存成功");
  163. else
  164. {
  165. return Error("坐席组保存失败");
  166. }
  167. }
  168. /// <summary>
  169. /// 修改坐席组
  170. /// </summary>
  171. [Authorize]
  172. [HttpPost("update")]
  173. public async Task<IActionResult> Edit(SeatGroupInput input)
  174. {
  175. #region
  176. if (input.id <= 0)
  177. return Error("请选择要编辑的坐席组");
  178. if (string.IsNullOrWhiteSpace(input.whwdkey))
  179. return Error("外呼外地前缀不能为空");
  180. if (string.IsNullOrWhiteSpace(input.whbdkey))
  181. return Error("外呼本地前缀不能为空");
  182. if (!ValidateString.IsNumberStr(input.whwdkey.Trim().ToString()))
  183. {
  184. return Error("外呼外地前缀必须为数字");
  185. }
  186. if (!ValidateString.IsNumberStr(input.whbdkey.Trim().ToString()))
  187. {
  188. return Error("外呼本地前缀必须为数字");
  189. }
  190. if (await GetExistByCodeAsync(input.zxzcode, input.id) || await GetExistByNameAsync(input.zxzname, input.id))
  191. return Error("坐席组编号和名称必须唯一,请重新输入!");
  192. #endregion
  193. var clmodel = await _sys_seatgroupRepository.GetSingle(x => x.F_ZXZID == input.id && x.F_State == (int)EnumDelState.Enabled);
  194. if (clmodel == null)
  195. return Error("信息获取失败");
  196. clmodel.F_ZXZCode = input.zxzcode.Trim();
  197. clmodel.F_ZXZName = input.zxzname.Trim();
  198. clmodel.F_ZXAtt = input.zxatt.Trim();
  199. clmodel.F_WHWDKey = input.whwdkey.Trim();
  200. clmodel.F_WHBDKey = input.whbdkey.Trim();
  201. clmodel.F_IVRKey = input.ivrkey;
  202. clmodel.F_Des = input.des;
  203. clmodel.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  204. clmodel.F_LastModifyOn = DateTime.Now;
  205. var res = await _sys_seatgroupRepository.Update(clmodel);
  206. if (res)
  207. return Success("坐席组保存成功");
  208. else
  209. {
  210. return Error("坐席组保存失败");
  211. }
  212. }
  213. [Authorize]
  214. [HttpPost("delete")]
  215. public async Task<IActionResult> Remove(int[] ids)
  216. {
  217. //使用逻辑删除
  218. //物理删除的数据无法恢复
  219. var res = 0;
  220. if (ids != null && ids.Length > 0)
  221. {
  222. foreach (var item in ids)
  223. {
  224. var ml = await _sys_seatgroupRepository.GetSingle(x => x.F_ZXZID == item);
  225. ml.F_State = (int)EnumDelState.Delete;
  226. if (await _sys_seatgroupRepository.Update(ml))
  227. res += 1;
  228. }
  229. if (res == ids.Length)
  230. return Success("删除成功");
  231. else if (res > 0 && res < ids.Length)
  232. return Error("部分删除失败,请查看后重新操作");
  233. else
  234. return Error("删除失败,请查看后重新操作");
  235. }
  236. else
  237. return Error("请选择要删除的记录");
  238. }
  239. #region 私有方法
  240. /// <summary>
  241. /// 根据坐席组编号查询是否存在此坐席组编号
  242. /// </summary>
  243. /// <param name="code"></param>
  244. /// <returns></returns>
  245. private async Task<bool> GetExistByCodeAsync(string code, int id)
  246. {
  247. long c = 0;
  248. if (id > 0)
  249. c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZCode.Equals(code) && x.F_ZXZID != id && x.F_State == (int)EnumDelState.Enabled);
  250. else
  251. c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZCode.Equals(code) && x.F_State == (int)EnumDelState.Enabled);
  252. return c > 0;
  253. }
  254. /// <summary>
  255. /// 根据坐席组名称查询是否存在此坐席组编号
  256. /// </summary>
  257. /// <param name="code"></param>
  258. /// <returns></returns>
  259. private async Task<bool> GetExistByNameAsync(string name, int id)
  260. {
  261. long c = 0;
  262. if (id > 0)
  263. c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZName.Equals(name) && x.F_ZXZID != id && x.F_State == (int)EnumDelState.Enabled);
  264. else
  265. c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZName.Equals(name) && x.F_State == (int)EnumDelState.Enabled);
  266. return c > 0;
  267. }
  268. #endregion
  269. }
  270. }