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

OutboundTaskController.cs 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.Common.Helpers;
  5. using System.Data;
  6. using System.IRepositories.Call;
  7. using System.IRepositories.Sys;
  8. using System.Linq;
  9. using System.Model.Call;
  10. using System.Model.Sys;
  11. using System.Security.Claims;
  12. using System.Threading.Tasks;
  13. using Microsoft.AspNetCore.Mvc;
  14. using SqlSugar;
  15. using TVShoppingCallCenter_ZLJ.Models.Inputs.System;
  16. namespace TVShoppingCallCenter_ZLJ.Controllers.AutoDial
  17. {
  18. [Produces("application/json")]
  19. [Route("api/[controller]")]
  20. public class OutboundTaskController : BaseController
  21. {
  22. private readonly ISys_OutboundTaskReposity _sys_outboundTaskrepository;
  23. private readonly ItaskRepository _taskrepository;
  24. private readonly ISys_AutoDialRepository _sys_autodialrepository;
  25. public OutboundTaskController(ISys_OutboundTaskReposity sys_outboundTaskrepository
  26. , ISys_AutoDialRepository sys_autodialrepository, ItaskRepository taskrepository)
  27. {
  28. _sys_outboundTaskrepository = sys_outboundTaskrepository;
  29. _sys_autodialrepository = sys_autodialrepository;
  30. _taskrepository = taskrepository;
  31. }
  32. /// <summary>
  33. /// 添加外呼任务
  34. /// </summary>
  35. /// <param name="input"></param>
  36. /// <returns></returns>
  37. [HttpPost("add")]
  38. public async Task<IActionResult> AddAsync(T_Sys_OutboundTask input)
  39. {
  40. if (string.IsNullOrEmpty (input.F_Name))
  41. return Error("请输入任务名称");
  42. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  43. input.F_AddTime = DateTime.Now;
  44. input.F_AddUser = user;
  45. input.F_TaskUser = input .F_TaskUser ;
  46. input.F_IsDelete = 0;
  47. var res = await _sys_outboundTaskrepository.Add(input);
  48. if (res > 0)
  49. {
  50. return Success("添加成功");
  51. }
  52. else
  53. {
  54. return Error("添加失败");
  55. }
  56. }
  57. /// <summary>
  58. /// 修改外呼任务
  59. /// </summary>
  60. /// <param name="input"></param>
  61. /// <returns></returns>
  62. [HttpPost("update")]
  63. public async Task<IActionResult> UpdateAsync(T_Sys_OutboundTask input)
  64. {
  65. if (input.F_ID <= 0)
  66. return Error("参数错误");
  67. if (string.IsNullOrEmpty(input.F_Name))
  68. return Error("请输入任务名称");
  69. var model = await _sys_outboundTaskrepository.GetSingle(x => x.F_ID == input.F_ID);
  70. if (model == null)
  71. return Error("操作失败");
  72. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  73. input.F_AddTime = model.F_AddTime ;
  74. model.F_AddUser = user;
  75. model.F_TaskUser = input.F_TaskUser;
  76. model.F_IsDelete = 0;
  77. model.F_Type = input.F_Type ;
  78. model.F_Content = input.F_Content; ;
  79. model.F_State = input.F_State;
  80. model.F_StartTime = input.F_StartTime;
  81. model.F_EndTime = input.F_EndTime;
  82. var res = await _sys_outboundTaskrepository.Update (model);
  83. if (res )
  84. {
  85. return Success("修改成功");
  86. }
  87. else
  88. {
  89. return Error("添加失败");
  90. }
  91. }
  92. /// <summary>
  93. /// 修改外呼号码
  94. /// </summary>
  95. /// <param name="input"></param>
  96. /// <returns></returns>
  97. [HttpPost("updatecall")]
  98. public async Task<IActionResult> Updatecall(T_Sys_AutoDial input)
  99. {
  100. if (input.F_ID <= 0)
  101. return Error("参数错误");
  102. if (input.F_Parentid <= 0)
  103. return Error("请选择外呼任务");
  104. if (string.IsNullOrEmpty(input.F_CallUser))
  105. return Error("请选择外呼人");
  106. var model = await _sys_autodialrepository.GetSingle(x => x.F_ID == input.F_ID);
  107. if (model == null)
  108. return Error("操作失败,此外呼不存在");
  109. var call = _sys_autodialrepository.GetListALL(x => x.F_Tel == input.F_Tel && x.F_ISOutbound == 0 &&
  110. x.F_IsDelete == 0&&x .F_Tel != model.F_Tel ).Result;
  111. if (call.Count > 0)
  112. {
  113. return Error("操作失败,该外呼号码已存在");
  114. }
  115. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  116. model.F_Parentid = input.F_Parentid;
  117. model.F_ISOutbound = model.F_ISOutbound;
  118. model.F_CallUser = input.F_CallUser;
  119. model.F_LastCallid = input.F_LastCallid;
  120. model.F_Tel = input.F_Tel;
  121. model.F_IsDelete = 0;
  122. var res = await _sys_autodialrepository.Update(model);
  123. if (res)
  124. {
  125. return Success("修改成功");
  126. }
  127. else
  128. {
  129. return Error("添加失败");
  130. }
  131. }
  132. /// <summary>
  133. /// 添加中间件外呼任务
  134. /// </summary>
  135. /// <returns></returns>
  136. [HttpPost("addmiddleware")]
  137. public async Task<IActionResult> Addmiddleware()
  138. {
  139. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  140. List<IConditionalModel> conModels = new List<IConditionalModel>();
  141. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  142. conModels.Add(new ConditionalCollections()
  143. {
  144. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  145. {
  146. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_TaskUser", ConditionalType = ConditionalType.Equal , FieldValue = user }),
  147. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal , FieldValue = "0" })
  148. }
  149. });
  150. conModels.Add(new ConditionalModel() { FieldName = "F_StartTime", ConditionalType = ConditionalType.GreaterThan , FieldValue = DateTime .Now .ToString() });
  151. conModels.Add(new ConditionalModel() { FieldName = "F_EndTime", ConditionalType = ConditionalType.LessThanOrEqual , FieldValue = DateTime.Now.ToString() });
  152. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal , FieldValue = "1" });
  153. var list = await _sys_outboundTaskrepository.GetListALL (conModels, " F_AddTime desc");
  154. int n = 0;
  155. if (list != null)
  156. {
  157. if (list.Count > 0)
  158. {
  159. foreach (var it in list)
  160. {
  161. List<IConditionalModel> conModel = new List<IConditionalModel>();
  162. #region 条件筛选
  163. conModel.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  164. conModel.Add(new ConditionalModel() { FieldName = "F_Parentid", ConditionalType = ConditionalType.Equal, FieldValue = it.F_ID .ToString() });
  165. conModel.Add(new ConditionalModel() { FieldName = "F_ISOutbound", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
  166. #endregion
  167. var modellist = await _sys_autodialrepository.GetListALL (conModels, " F_ID asc");
  168. if (modellist!=null )
  169. {
  170. foreach (var iv in modellist)
  171. {
  172. task tasks = new task();
  173. tasks.agent = user;
  174. tasks.number = iv .F_Tel ;
  175. tasks.state =0;
  176. tasks.type = it .F_Type ;
  177. tasks.content = it.F_Content ;
  178. tasks.outbound_id = iv .F_ID ;
  179. tasks.status = 0;
  180. var res = await _taskrepository.Add (tasks);
  181. if (res>0)
  182. {
  183. n= n + 1;
  184. }
  185. }
  186. }
  187. }
  188. if (n >0)
  189. return Success("任务启动", list.Count);
  190. else
  191. return Success("暂无任务", 0);
  192. }
  193. else
  194. return Success("暂无任务", 0);
  195. }
  196. else
  197. return Success("暂无任务",0);
  198. }
  199. /// <summary>
  200. /// 添加自动外呼
  201. /// </summary>
  202. /// <param name="input"></param>
  203. /// <returns></returns>
  204. [HttpPost("addcall")]
  205. public async Task<IActionResult> AddAsync([FromBody]OutboundTaskInputcs input)
  206. {
  207. if (string.IsNullOrEmpty(input.F_Name))
  208. return Error("请输入任务名称");
  209. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  210. var outboundTask = new T_Sys_OutboundTask();
  211. if (input .F_ID >0)
  212. {
  213. outboundTask = _sys_outboundTaskrepository.GetSingle(x => x.F_ID == input.F_ID).Result ;
  214. if (outboundTask == null)
  215. return Error("操作失败,此任务不存在");
  216. }
  217. else
  218. {
  219. outboundTask.F_AddTime = DateTime.Now;
  220. outboundTask.F_AddUser = user;
  221. outboundTask.F_TaskUser = input.F_TaskUser;
  222. outboundTask.F_Remarks = input.F_Remarks;
  223. outboundTask.F_StartTime = input.F_StartTime;
  224. outboundTask.F_EndTime = input.F_EndTime;
  225. outboundTask.F_State = input.F_State;
  226. var task = _sys_outboundTaskrepository.Add(outboundTask).Result ;
  227. if (task <=0)
  228. {
  229. return Error("任务添加失败");
  230. }
  231. else
  232. {
  233. outboundTask.F_ID = task;
  234. }
  235. }
  236. string msg = "";
  237. if (input.AutoDials != null )
  238. {
  239. foreach (var it in input.AutoDials)
  240. {
  241. T_Sys_AutoDial model = new T_Sys_AutoDial ();
  242. var call = _sys_autodialrepository.GetListALL(x => x.F_Tel == it.F_Tel&&x .F_ISOutbound ==0&&
  243. x .F_IsDelete ==0).Result ;
  244. if (string.IsNullOrEmpty(it.F_Tel))
  245. {
  246. msg += "号码为空,添加失败";
  247. }
  248. else if (call.Count > 0)
  249. {
  250. msg += it.F_Tel + "已存在外呼任务中,该号码添加失败";
  251. }
  252. else
  253. {
  254. model.F_Parentid = outboundTask.F_ID;
  255. model.F_ISOutbound = it.F_ISOutbound;
  256. model.F_CallUser = input.F_TaskUser;
  257. model.F_LastCallid = it.F_LastCallid;
  258. model.F_Tel = it.F_Tel;
  259. model.F_IsDelete = 0;
  260. var res = await _sys_autodialrepository.Add(model);
  261. if (res <=0)
  262. {
  263. msg += it.F_Tel + "号码添加失败";
  264. }
  265. }
  266. }
  267. }
  268. if (msg == "")
  269. {
  270. return Success("添加成功");
  271. }
  272. else
  273. return Error(msg);
  274. }
  275. /// <summary>
  276. /// 删除外呼号码
  277. /// </summary>
  278. /// <param name="ids"></param>
  279. /// <returns></returns>
  280. [HttpPost("delete")]
  281. public async Task<IActionResult> Remove(int[] ids)
  282. {
  283. var res = 0;
  284. if (ids != null && ids.Length > 0)
  285. {
  286. foreach (var item in ids)
  287. {
  288. var model = await _sys_autodialrepository.GetSingle(x => x.F_ID == item);
  289. model.F_IsDelete = (int)EnumUserCountState.Delete;
  290. if (_sys_autodialrepository.Update(model).Result)
  291. res += 1;
  292. }
  293. if (res == ids.Length)
  294. return Success("删除成功");
  295. else if (res > 0 && res < ids.Length)
  296. return Error("部分删除失败,请查看后重新操作");
  297. else
  298. return Error("删除失败,请查看后重新操作");
  299. }
  300. else
  301. return Error("请选择要删除的记录");
  302. }
  303. /// <summary>
  304. /// 删除外呼任务
  305. /// </summary>
  306. /// <param name="ids"></param>
  307. /// <returns></returns>
  308. [HttpPost("deletetask")]
  309. public async Task<IActionResult> RemoveTask(int id)
  310. {
  311. var model = _sys_outboundTaskrepository.GetSingle(x => x.F_ID == id).Result;
  312. if (model == null)
  313. return Error("该任务不存在");
  314. var dt = _sys_autodialrepository.GetListALL(x => x.F_Parentid == id && x.F_IsDelete == 0).Result;
  315. if (dt != null)
  316. {
  317. if (dt.Count > 0)
  318. return Error("请先删除此任务下的外呼号码");
  319. }
  320. model.F_IsDelete = (int)EnumUserCountState.Delete;
  321. bool n = _sys_outboundTaskrepository.Update(model).Result;
  322. if (n)
  323. return Success("删除成功");
  324. else
  325. return Error("删除失败");
  326. }
  327. /// <summary>
  328. /// 获取任务
  329. /// </summary>
  330. /// <param name="keyword"></param>
  331. /// <param name="pageindex"></param>
  332. /// <param name="pagesize"></param>
  333. /// <returns></returns>
  334. [HttpGet("getlist")]
  335. public async Task<IActionResult> GetListMark(string keyword,int pageindex = 1, int pagesize = 20)
  336. {
  337. List<IConditionalModel> conModels = new List<IConditionalModel>();
  338. #region 条件筛选
  339. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  340. if (!string.IsNullOrEmpty(keyword))
  341. {
  342. conModels.Add(new ConditionalCollections()
  343. {
  344. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  345. {
  346. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  347. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_TaskUser", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  348. }
  349. });
  350. }
  351. #endregion
  352. int recordCount = 0;
  353. var list = await _sys_outboundTaskrepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, " F_AddTime desc");
  354. var obj = new
  355. {
  356. state = "success",
  357. message = "成功",
  358. rows = list,
  359. total = list.Totals,
  360. };
  361. return Content(obj.ToJson());
  362. }
  363. /// <summary>
  364. /// 获取外呼计划列表
  365. /// </summary>
  366. /// <param name="keyword"></param>
  367. /// <param name="pageindex"></param>
  368. /// <param name="pagesize"></param>
  369. /// <returns></returns>
  370. [HttpGet("getcalllist")]
  371. public async Task<IActionResult> GetList(int pid,string keyword,int pageindex = 1, int pagesize = 20)
  372. {
  373. List<IConditionalModel> conModels = new List<IConditionalModel>();
  374. #region 条件筛选
  375. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  376. conModels.Add(new ConditionalModel() { FieldName = "F_Parentid", ConditionalType = ConditionalType.Equal, FieldValue = pid.ToString() });
  377. if (!string.IsNullOrEmpty(keyword))
  378. {
  379. conModels.Add(new ConditionalCollections()
  380. {
  381. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  382. {
  383. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Tel", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  384. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_CallUser", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  385. }
  386. });
  387. }
  388. #endregion
  389. int recordCount = 0;
  390. var list = await _sys_autodialrepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, " F_ID asc");
  391. var obj = new
  392. {
  393. state = "success",
  394. message = "成功",
  395. rows = list,
  396. total = list.Totals,
  397. };
  398. return Content(obj.ToJson());
  399. }
  400. /// <summary>
  401. /// 获取任务详情
  402. /// </summary>
  403. /// <param name="id">id</param>
  404. /// <returns></returns>
  405. [HttpGet("getdetails")]
  406. public async Task<IActionResult> GetDetailsAsync(int id)
  407. {
  408. if (id <= 0)
  409. return Error("参数错误");
  410. var model = await _sys_outboundTaskrepository.GetSingle(x => x.F_ID == id);
  411. if (model == null)
  412. {
  413. return Error("获取失败");
  414. }
  415. return Success("获取成功!", model);
  416. }
  417. /// <summary>
  418. /// 获取外呼号码
  419. /// </summary>
  420. /// <param name="id">id</param>
  421. /// <returns></returns>
  422. [HttpGet("getdetailscall")]
  423. public async Task<IActionResult> GetDetails(int id)
  424. {
  425. if (id <= 0)
  426. return Error("参数错误");
  427. var model = await _sys_autodialrepository.GetSingle(x => x.F_ID == id);
  428. if (model == null)
  429. {
  430. return Error("获取失败");
  431. }
  432. return Success("获取成功!", model);
  433. }
  434. /// <summary>
  435. /// 上传文件并导入数据库
  436. /// </summary>
  437. /// <returns></returns>
  438. [HttpPost("importexcel")]
  439. public async Task<IActionResult> ImportExcel(int headrow = 0,int pid=0)
  440. {
  441. if (pid <= 0)
  442. return Error("请选择外呼任务");
  443. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  444. if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
  445. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  446. NPOIHelper npoi = new NPOIHelper();
  447. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  448. int num = dtExcel.Rows.Count;
  449. var cols = dtExcel.Columns;
  450. int colnum = cols.Count;
  451. string errmsg = string.Empty;
  452. if (num > 0)
  453. {
  454. int index = 1;
  455. foreach (DataRow dr in dtExcel.Rows)
  456. {
  457. var model = new T_Sys_AutoDial();
  458. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  459. model.F_Parentid = pid;
  460. if (dr["是否完成外呼"].ToString()=="是")
  461. {
  462. model.F_ISOutbound = 1;
  463. }
  464. else
  465. model.F_ISOutbound = 0;
  466. // model.F_LastCallid = it.F_LastCallid;
  467. model.F_Tel = dr["外呼号码"].ToString();
  468. model.F_IsDelete = 0;
  469. int b = await _sys_autodialrepository.Add(model);
  470. if (b <= 0)
  471. {
  472. if (!string.IsNullOrEmpty(errmsg))
  473. {
  474. errmsg = errmsg + "\r\n第" + index + "行导入失败!";
  475. }
  476. else
  477. {
  478. errmsg = "第" + index + "行导入失败!";
  479. }
  480. }
  481. index++;
  482. }
  483. }
  484. else
  485. {
  486. return Error("文件中无数据");
  487. }
  488. if (!string.IsNullOrEmpty(errmsg))
  489. {
  490. return Error(errmsg);
  491. }
  492. return Success("导入成功");
  493. }
  494. }
  495. }