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

ExtensionBindController.cs 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.IRepositories.Call;
  5. using System.Linq;
  6. using System.Model;
  7. using System.Threading.Tasks;
  8. using Microsoft.AspNetCore.Mvc;
  9. using SqlSugar;
  10. namespace TVShoppingCallCenter_ZLJ.Controllers.CallCenter
  11. {
  12. [Produces("application/json")]
  13. [Route("api/[controller]")]
  14. public class ExtensionBindController : BaseController
  15. {
  16. private readonly ICall_ExtensionBindRepository call_ExtensionBindRepository;
  17. public ExtensionBindController(ICall_ExtensionBindRepository _call_ExtensionBindRepository)
  18. {
  19. call_ExtensionBindRepository = _call_ExtensionBindRepository;
  20. }
  21. /// <summary>
  22. /// 添加媒体
  23. /// </summary>
  24. /// <param name="input"></param>
  25. /// <returns></returns>
  26. [HttpPost("add")]
  27. public async Task<IActionResult> AddAsync(T_Call_ExtensionBind input)
  28. {
  29. if (string.IsNullOrEmpty(input.F_Extension))
  30. return Error("请输入分机号");
  31. if (string.IsNullOrEmpty(input.F_Telephone))
  32. return Error("请输入固话号");
  33. if (await call_ExtensionBindRepository.GetCount(x => x.F_Extension == input.F_Extension
  34. && x.F_IsDelete == 0) > 0)
  35. return Error("分机号已存在");
  36. input.F_AddTime = DateTime.Now;
  37. input.F_IsDelete = 0;
  38. input.F_AddUser = UserLogin.UserCode;
  39. var res = await call_ExtensionBindRepository.Add(input);
  40. if (res > 0)
  41. {
  42. return Success("添加成功");
  43. }
  44. else
  45. {
  46. return Error("添加失败");
  47. }
  48. }
  49. /// <summary>
  50. /// 修改媒体
  51. /// </summary>
  52. [HttpPost("update")]
  53. public async Task<IActionResult> UpdateAsync(T_Call_ExtensionBind input)
  54. {
  55. if (input.F_ID <= 0)
  56. return Error("参数错误");
  57. if (string.IsNullOrEmpty(input.F_Extension))
  58. return Error("请输入分机号");
  59. if (string.IsNullOrEmpty(input.F_Telephone))
  60. return Error("请输入固话号");
  61. var model = await call_ExtensionBindRepository.GetSingle(x => x.F_ID == input.F_ID);
  62. if (model == null)
  63. return Error("操作失败");
  64. if (await call_ExtensionBindRepository.GetCount(x => x.F_Extension == input.F_Extension
  65. && x.F_IsDelete == 0&&x .F_ID !=input .F_ID ) > 0)
  66. return Error("分机号已存在");
  67. input.F_IsDelete = 0;
  68. model.F_Extension = input.F_Extension;
  69. model.F_Telephone = input.F_Telephone;
  70. var b = await call_ExtensionBindRepository.Update(model);
  71. if (b)
  72. return Success("修改成功");
  73. return Error("修改失败");
  74. }
  75. /// <summary>
  76. /// 删除媒体
  77. /// </summary>
  78. /// <param name="ids"></param>
  79. /// <returns></returns>
  80. [HttpPost("delete")]
  81. public async Task<IActionResult> Remove(int[] ids)
  82. {
  83. var res = 0;
  84. if (ids != null && ids.Length > 0)
  85. {
  86. foreach (var item in ids)
  87. {
  88. var model = await call_ExtensionBindRepository.GetSingle(x => x.F_ID == item);
  89. model.F_IsDelete = (int)EnumUserCountState.Delete;
  90. if (call_ExtensionBindRepository.Update(model).Result)
  91. res += 1;
  92. }
  93. if (res == ids.Length)
  94. return Success("删除成功");
  95. else if (res > 0 && res < ids.Length)
  96. return Error("部分删除失败,请查看后重新操作");
  97. else
  98. return Error("删除失败,请查看后重新操作");
  99. }
  100. else
  101. return Error("请选择要删除的记录");
  102. }
  103. /// <summary>
  104. /// 获取媒体列表
  105. /// </summary>
  106. /// <param name="keyword"></param>
  107. /// <param name="pageindex"></param>
  108. /// <param name="pagesize"></param>
  109. /// <returns></returns>
  110. [HttpGet("getlist")]
  111. public async Task<IActionResult> GetLisAsync(string extension, string telephone, int pageindex = 1, int pagesize = 20)
  112. {
  113. List<IConditionalModel> conModels = new List<IConditionalModel>();
  114. #region 条件筛选
  115. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  116. if (!string.IsNullOrEmpty(extension))
  117. {
  118. conModels.Add(new ConditionalModel() { FieldName = "F_Extension", ConditionalType = ConditionalType.Like, FieldValue = extension });
  119. }
  120. if (!string.IsNullOrEmpty(telephone))
  121. {
  122. conModels.Add(new ConditionalModel() { FieldName = "F_Telephone", ConditionalType = ConditionalType.Like, FieldValue = telephone });
  123. }
  124. #endregion
  125. int recordCount = 0;
  126. var list = await call_ExtensionBindRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
  127. var obj = new
  128. {
  129. state = "success",
  130. message = "成功",
  131. rows = list,
  132. total = list.Totals,
  133. };
  134. return Content(obj.ToJson());
  135. }
  136. /// <summary>
  137. /// 获取详情
  138. /// </summary>
  139. /// <param name="id">id</param>
  140. /// <returns></returns>
  141. [HttpGet("getdetails")]
  142. public async Task<IActionResult> GetDetailsAsync(int id)
  143. {
  144. if (id <= 0)
  145. return Error("参数错误");
  146. var model = await call_ExtensionBindRepository.GetSingle(x => x.F_ID == id);
  147. if (model == null)
  148. {
  149. return Error("获取失败");
  150. }
  151. return Success("获取成功!", model);
  152. }
  153. }
  154. }