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

SeatGroupController.cs 12KB

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