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

OutboundTaskController.cs 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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;
  7. using System.IRepositories.Call;
  8. using System.IRepositories.Sys;
  9. using System.Linq;
  10. using System.Model;
  11. using System.Model.Call;
  12. using System.Model.Sys;
  13. using System.Security.Claims;
  14. using System.Threading.Tasks;
  15. using System.Utility;
  16. using Microsoft.AspNetCore.Mvc;
  17. using Microsoft.Extensions.Configuration;
  18. using SqlSugar;
  19. using TVShoppingCallCenter_ZLJ.Models.Inputs.System;
  20. namespace TVShoppingCallCenter_ZLJ.Controllers.AutoDial
  21. {
  22. [Produces("application/json")]
  23. [Route("api/[controller]")]
  24. public class OutboundTaskController : BaseController
  25. {
  26. private readonly IConfiguration config;
  27. private readonly ISys_MobileDataRepository busMobileDataRepository;
  28. private readonly ISys_OutboundTaskReposity _sys_outboundTaskrepository;
  29. private readonly ItaskRepository _taskrepository;
  30. private readonly ISys_AutoDialRepository _sys_autodialrepository;
  31. public OutboundTaskController(ISys_OutboundTaskReposity sys_outboundTaskrepository
  32. , ISys_AutoDialRepository sys_autodialrepository, ItaskRepository taskrepository
  33. , IConfiguration _configuration, ISys_MobileDataRepository _busMobileDataRepository)
  34. {
  35. _sys_outboundTaskrepository = sys_outboundTaskrepository;
  36. _sys_autodialrepository = sys_autodialrepository;
  37. _taskrepository = taskrepository;
  38. config = _configuration;
  39. busMobileDataRepository = _busMobileDataRepository;
  40. }
  41. /// <summary>
  42. /// 添加外呼任务
  43. /// </summary>
  44. /// <param name="input"></param>
  45. /// <returns></returns>
  46. [HttpPost("add")]
  47. public async Task<IActionResult> AddAsync(T_Sys_OutboundTask input)
  48. {
  49. if (string.IsNullOrEmpty (input.F_Name))
  50. return Error("请输入任务名称");
  51. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  52. input.F_AddTime = DateTime.Now;
  53. input.F_AddUser = user;
  54. input.F_TaskUser = input .F_TaskUser ;
  55. input.F_IsDelete = 0;
  56. var res = await _sys_outboundTaskrepository.Add(input);
  57. if (res > 0)
  58. {
  59. return Success("添加成功");
  60. }
  61. else
  62. {
  63. return Error("添加失败");
  64. }
  65. }
  66. /// <summary>
  67. /// 修改外呼任务
  68. /// </summary>
  69. /// <param name="input"></param>
  70. /// <returns></returns>
  71. [HttpPost("update")]
  72. public async Task<IActionResult> UpdateAsync(T_Sys_OutboundTask input)
  73. {
  74. if (input.F_ID <= 0)
  75. return Error("参数错误");
  76. if (string.IsNullOrEmpty(input.F_Name))
  77. return Error("请输入任务名称");
  78. var model = await _sys_outboundTaskrepository.GetSingle(x => x.F_ID == input.F_ID);
  79. if (model == null)
  80. return Error("操作失败");
  81. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  82. input.F_AddTime = model.F_AddTime ;
  83. model.F_AddUser = user;
  84. model.F_TaskUser = input.F_TaskUser;
  85. model.F_IsDelete = 0;
  86. model.F_Type = input.F_Type ;
  87. model.F_Content = input.F_Content; ;
  88. model.F_State = input.F_State;
  89. model.F_StartTime = input.F_StartTime;
  90. model.F_EndTime = input.F_EndTime;
  91. var res = await _sys_outboundTaskrepository.Update (model);
  92. if (res )
  93. {
  94. return Success("修改成功");
  95. }
  96. else
  97. {
  98. return Error("添加失败");
  99. }
  100. }
  101. /// <summary>
  102. /// 修改外呼号码
  103. /// </summary>
  104. /// <param name="input"></param>
  105. /// <returns></returns>
  106. [HttpPost("updatecall")]
  107. public async Task<IActionResult> Updatecall(T_Sys_AutoDial input)
  108. {
  109. if (input.F_ID <= 0)
  110. return Error("参数错误");
  111. if (input.F_Parentid <= 0)
  112. return Error("请选择外呼任务");
  113. var model = await _sys_autodialrepository.GetSingle(x => x.F_ID == input.F_ID);
  114. if (model == null)
  115. return Error("操作失败,此外呼不存在");
  116. var call = _sys_autodialrepository.GetListALL(x => x.F_Tel == input.F_Tel && x.F_ISOutbound == 0 &&
  117. x.F_IsDelete == 0&&x .F_Tel != model.F_Tel ).Result;
  118. if (call.Count > 0)
  119. {
  120. return Error("操作失败,该外呼号码已存在");
  121. }
  122. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  123. model.F_Parentid = input.F_Parentid;
  124. model.F_ISOutbound = model.F_ISOutbound;
  125. // model.F_CallUser = input.F_CallUser;
  126. model.F_LastCallid = input.F_LastCallid;
  127. model.F_Tel = input.F_Tel;
  128. model.F_IsDelete = 0;
  129. var res = await _sys_autodialrepository.Update(model);
  130. if (res)
  131. {
  132. var task = await _taskrepository.GetListALL(x => x.outbound_id == model.F_ID);
  133. if (task!=null&& task.Count >0)
  134. {
  135. foreach (var it in task)
  136. {
  137. if (input.F_Tel.Length >= 11)
  138. {
  139. it.number = await CallOutprefix(input.F_Tel);
  140. }
  141. else
  142. it.number = input.F_Tel;
  143. var taskres = await _taskrepository.Update(it);
  144. }
  145. }
  146. return Success("修改成功");
  147. }
  148. else
  149. {
  150. return Error("添加失败");
  151. }
  152. }
  153. /// <summary>
  154. /// 添加中间件外呼任务
  155. /// </summary>
  156. /// <returns></returns>
  157. [HttpPost("addmiddleware")]
  158. public async Task<IActionResult> Addmiddleware()
  159. {
  160. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  161. List<IConditionalModel> conModels = new List<IConditionalModel>();
  162. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  163. conModels.Add(new ConditionalCollections()
  164. {
  165. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  166. {
  167. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_TaskUser", ConditionalType = ConditionalType.Equal , FieldValue = user }),
  168. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal , FieldValue = "1" })
  169. }
  170. });
  171. conModels.Add(new ConditionalModel() { FieldName = "F_StartTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = DateTime .Now .ToString() });
  172. conModels.Add(new ConditionalModel() { FieldName = "F_EndTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = DateTime.Now.ToString() });
  173. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal , FieldValue = "1" });
  174. var list = await _sys_outboundTaskrepository.GetListALL (conModels, " F_AddTime desc");
  175. int n = 0;
  176. if (list != null)
  177. {
  178. if (list.Count > 0)
  179. {
  180. foreach (var it in list)
  181. {
  182. List<IConditionalModel> conModel = new List<IConditionalModel>();
  183. #region 条件筛选
  184. conModel.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  185. conModel.Add(new ConditionalModel() { FieldName = "F_Parentid", ConditionalType = ConditionalType.Equal, FieldValue = it.F_ID .ToString() });
  186. conModel.Add(new ConditionalModel() { FieldName = "F_ISOutbound", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
  187. #endregion
  188. var modellist = await _sys_autodialrepository.GetListALL (conModel, " F_ID asc");
  189. if (modellist!=null )
  190. {
  191. foreach (var iv in modellist)
  192. {
  193. var model = await _taskrepository.GetListALL(x => x.outbound_id == iv.F_ID);
  194. if (model==null || model.Count <=0)
  195. {
  196. task tasks = new task();
  197. tasks.agent = user;
  198. if (iv.F_Tel.Length >=11)
  199. {
  200. tasks.number = await CallOutprefix( iv.F_Tel);
  201. }
  202. else
  203. tasks.number = iv.F_Tel;
  204. tasks.state = 0;
  205. tasks.type = it.F_Type;
  206. tasks.content = it.F_Content;
  207. tasks.outbound_id = iv.F_ID;
  208. tasks.status = 0;
  209. var res = await _taskrepository.Add(tasks);
  210. }
  211. }
  212. n = modellist.Count ();
  213. }
  214. }
  215. if (n >0)
  216. return Success("任务启动", list.Count);
  217. else
  218. return Success("暂无任务", 0);
  219. }
  220. else
  221. return Success("暂无任务", 0);
  222. }
  223. else
  224. return Success("暂无任务",0);
  225. }
  226. /// <summary>
  227. /// 添加自动外呼
  228. /// </summary>
  229. /// <param name="input"></param>
  230. /// <returns></returns>
  231. [HttpPost("addcall")]
  232. public async Task<IActionResult> AddAsync([FromBody]OutboundTaskInputcs input)
  233. {
  234. if (string.IsNullOrEmpty(input.F_Name))
  235. return Error("请输入任务名称");
  236. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  237. var outboundTask = new T_Sys_OutboundTask();
  238. if (input .F_ID >0)
  239. {
  240. outboundTask = _sys_outboundTaskrepository.GetSingle(x => x.F_ID == input.F_ID).Result ;
  241. if (outboundTask == null)
  242. return Error("操作失败,此任务不存在");
  243. outboundTask.F_AddTime = DateTime.Now;
  244. outboundTask.F_AddUser = user;
  245. outboundTask.F_TaskUser = input.F_TaskUser;
  246. outboundTask.F_Remarks = input.F_Remarks;
  247. outboundTask.F_StartTime = input.F_StartTime;
  248. outboundTask.F_EndTime = input.F_EndTime;
  249. outboundTask.F_State = input.F_State;
  250. outboundTask.F_Name = input.F_Name;
  251. outboundTask.F_Type = input.F_Type;
  252. outboundTask.F_Content = input.F_Content;
  253. outboundTask.F_IsDelete = 0;
  254. var task = _sys_outboundTaskrepository.Update (outboundTask).Result;
  255. }
  256. else
  257. {
  258. outboundTask.F_AddTime = DateTime.Now;
  259. outboundTask.F_AddUser = user;
  260. outboundTask.F_TaskUser = input.F_TaskUser;
  261. outboundTask.F_Remarks = input.F_Remarks;
  262. outboundTask.F_StartTime = input.F_StartTime;
  263. outboundTask.F_EndTime = input.F_EndTime;
  264. outboundTask.F_State = input.F_State;
  265. outboundTask.F_Name = input.F_Name;
  266. outboundTask.F_Type = input.F_Type;
  267. outboundTask.F_Content = input.F_Content;
  268. outboundTask.F_IsDelete = 0;
  269. var task = _sys_outboundTaskrepository.Add(outboundTask).Result ;
  270. if (task <=0)
  271. {
  272. return Error("任务添加失败");
  273. }
  274. else
  275. {
  276. outboundTask.F_ID = task;
  277. }
  278. }
  279. string msg = "";
  280. if (input.AutoDials != null )
  281. {
  282. foreach (var it in input.AutoDials)
  283. {
  284. T_Sys_AutoDial model = new T_Sys_AutoDial ();
  285. var call = _sys_autodialrepository.GetListALL(x => x.F_Tel == it.F_Tel&&x .F_ISOutbound ==0&&
  286. x .F_IsDelete ==0).Result ;
  287. if (string.IsNullOrEmpty(it.F_Tel))
  288. {
  289. msg += "号码为空,添加失败";
  290. }
  291. else if (call.Count > 0)
  292. {
  293. msg += it.F_Tel + "已存在外呼任务中,该号码添加失败";
  294. }
  295. else
  296. {
  297. model.F_Parentid = outboundTask.F_ID;
  298. model.F_ISOutbound = it.F_ISOutbound;
  299. model.F_CallUser = input.F_TaskUser;
  300. model.F_LastCallid = it.F_LastCallid;
  301. model.F_Tel = it.F_Tel;
  302. model.F_IsDelete = 0;
  303. var res = await _sys_autodialrepository.Add(model);
  304. if (res <=0)
  305. {
  306. msg += it.F_Tel + "号码添加失败";
  307. }
  308. }
  309. }
  310. }
  311. if (msg == "")
  312. {
  313. return Success("添加成功");
  314. }
  315. else
  316. return Error(msg);
  317. }
  318. /// <summary>
  319. /// 删除外呼号码
  320. /// </summary>
  321. /// <param name="ids"></param>
  322. /// <returns></returns>
  323. [HttpPost("delete")]
  324. public async Task<IActionResult> Remove(int[] ids)
  325. {
  326. var res = 0;
  327. if (ids != null && ids.Length > 0)
  328. {
  329. foreach (var item in ids)
  330. {
  331. var model = await _sys_autodialrepository.GetSingle(x => x.F_ID == item);
  332. model.F_IsDelete = (int)EnumUserCountState.Delete;
  333. if (_sys_autodialrepository.Update(model).Result)
  334. res += 1;
  335. }
  336. if (res == ids.Length)
  337. return Success("删除成功");
  338. else if (res > 0 && res < ids.Length)
  339. return Error("部分删除失败,请查看后重新操作");
  340. else
  341. return Error("删除失败,请查看后重新操作");
  342. }
  343. else
  344. return Error("请选择要删除的记录");
  345. }
  346. /// <summary>
  347. /// 删除外呼任务
  348. /// </summary>
  349. /// <param name="ids"></param>
  350. /// <returns></returns>
  351. [HttpPost("deletetask")]
  352. public async Task<IActionResult> RemoveTask(int id)
  353. {
  354. var model = _sys_outboundTaskrepository.GetSingle(x => x.F_ID == id).Result;
  355. if (model == null)
  356. return Error("该任务不存在");
  357. var dt = _sys_autodialrepository.GetListALL(x => x.F_Parentid == id && x.F_IsDelete == 0).Result;
  358. if (dt != null)
  359. {
  360. if (dt.Count > 0)
  361. return Error("请先删除此任务下的外呼号码");
  362. }
  363. model.F_IsDelete = (int)EnumUserCountState.Delete;
  364. bool n = _sys_outboundTaskrepository.Update(model).Result;
  365. if (n)
  366. return Success("删除成功");
  367. else
  368. return Error("删除失败");
  369. }
  370. /// <summary>
  371. /// 获取任务
  372. /// </summary>
  373. /// <param name="keyword"></param>
  374. /// <param name="pageindex"></param>
  375. /// <param name="pagesize"></param>
  376. /// <returns></returns>
  377. [HttpGet("getlist")]
  378. public async Task<IActionResult> GetListMark(string keyword,int pageindex = 1, int pagesize = 20)
  379. {
  380. List<IConditionalModel> conModels = new List<IConditionalModel>();
  381. #region 条件筛选
  382. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  383. if (!string.IsNullOrEmpty(keyword))
  384. {
  385. conModels.Add(new ConditionalCollections()
  386. {
  387. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  388. {
  389. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  390. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_TaskUser", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  391. }
  392. });
  393. }
  394. #endregion
  395. int recordCount = 0;
  396. var list = await _sys_outboundTaskrepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, " F_AddTime desc");
  397. var obj = new
  398. {
  399. state = "success",
  400. message = "成功",
  401. rows = list,
  402. total = list.Totals,
  403. };
  404. return Content(obj.ToJson());
  405. }
  406. /// <summary>
  407. /// 获取外呼计划列表
  408. /// </summary>
  409. /// <param name="keyword"></param>
  410. /// <param name="pageindex"></param>
  411. /// <param name="pagesize"></param>
  412. /// <returns></returns>
  413. [HttpGet("getcalllist")]
  414. public async Task<IActionResult> GetList(int pid,string keyword,int pageindex = 1, int pagesize = 20)
  415. {
  416. List<IConditionalModel> conModels = new List<IConditionalModel>();
  417. #region 条件筛选
  418. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  419. conModels.Add(new ConditionalModel() { FieldName = "F_Parentid", ConditionalType = ConditionalType.Equal, FieldValue = pid.ToString() });
  420. if (!string.IsNullOrEmpty(keyword))
  421. {
  422. conModels.Add(new ConditionalCollections()
  423. {
  424. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  425. {
  426. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Tel", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  427. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_CallUser", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  428. }
  429. });
  430. }
  431. #endregion
  432. int recordCount = 0;
  433. var list = await _sys_autodialrepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, " F_ID asc");
  434. var obj = new
  435. {
  436. state = "success",
  437. message = "成功",
  438. rows = list,
  439. total = list.Totals,
  440. };
  441. return Content(obj.ToJson());
  442. }
  443. /// <summary>
  444. /// 获取任务详情
  445. /// </summary>
  446. /// <param name="id">id</param>
  447. /// <returns></returns>
  448. [HttpGet("getdetails")]
  449. public async Task<IActionResult> GetDetailsAsync(int id)
  450. {
  451. if (id <= 0)
  452. return Error("参数错误");
  453. var model = await _sys_outboundTaskrepository.GetSingle(x => x.F_ID == id);
  454. if (model == null)
  455. {
  456. return Error("获取失败");
  457. }
  458. return Success("获取成功!", model);
  459. }
  460. /// <summary>
  461. /// 获取外呼号码
  462. /// </summary>
  463. /// <param name="id">id</param>
  464. /// <returns></returns>
  465. [HttpGet("getdetailscall")]
  466. public async Task<IActionResult> GetDetails(int id)
  467. {
  468. if (id <= 0)
  469. return Error("参数错误");
  470. var model = await _sys_autodialrepository.GetSingle(x => x.F_ID == id);
  471. if (model == null)
  472. {
  473. return Error("获取失败");
  474. }
  475. return Success("获取成功!", model);
  476. }
  477. /// <summary>
  478. /// 上传文件并导入数据库
  479. /// </summary>
  480. /// <returns></returns>
  481. [HttpPost("importexcel")]
  482. public async Task<IActionResult> ImportExcel(int headrow = 0,int pid=0)
  483. {
  484. if (pid <= 0)
  485. return Error("请选择外呼任务");
  486. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  487. 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"))
  488. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  489. NPOIHelper npoi = new NPOIHelper();
  490. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  491. int num = dtExcel.Rows.Count;
  492. var cols = dtExcel.Columns;
  493. int colnum = cols.Count;
  494. string errmsg = string.Empty;
  495. if (num > 0)
  496. {
  497. int index = 1;
  498. foreach (DataRow dr in dtExcel.Rows)
  499. {
  500. var model = new T_Sys_AutoDial();
  501. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  502. model.F_Parentid = pid;
  503. if (dr["是否完成外呼"].ToString()=="是")
  504. {
  505. model.F_ISOutbound = 1;
  506. }
  507. else
  508. model.F_ISOutbound = 0;
  509. // model.F_LastCallid = it.F_LastCallid;
  510. model.F_Tel = dr["外呼号码"].ToString();
  511. var call = _sys_autodialrepository.GetListALL(x => x.F_Tel == dr["外呼号码"].ToString() && x.F_ISOutbound == 0 &&
  512. x.F_IsDelete == 0).Result;
  513. if (call!=null && call.Count ()>0)
  514. {
  515. errmsg = errmsg + "\r\n第" + index + "行导入失败!该已存在外呼任务中";
  516. }
  517. else
  518. {
  519. model.F_IsDelete = 0;
  520. int b = await _sys_autodialrepository.Add(model);
  521. if (b <= 0)
  522. {
  523. if (!string.IsNullOrEmpty(errmsg))
  524. {
  525. errmsg = errmsg + "\r\n第" + index + "行导入失败!";
  526. }
  527. else
  528. {
  529. errmsg = "第" + index + "行导入失败!";
  530. }
  531. }
  532. }
  533. index++;
  534. }
  535. }
  536. else
  537. {
  538. return Error("文件中无数据");
  539. }
  540. if (!string.IsNullOrEmpty(errmsg))
  541. {
  542. return Error(errmsg);
  543. }
  544. return Success("导入成功");
  545. }
  546. #region
  547. [NonAction]
  548. public async Task<string> CallOutprefix(string phone)
  549. {
  550. string phone1 = StringHelper.ToDBC(StringHelper.RemoveNotNumber(StringHelper.NoHtml(phone)));
  551. string tophone = phone1;
  552. string fix = ""; string bfix = ""; string wfix = "";
  553. string zipcode = config["appSettings:CallOutZipCode"];
  554. bfix = config["appSettings:CallOutBPre"];
  555. wfix = config["appSettings:CallOutWPre"];
  556. int zip = await GetZipCodeByPhone(phone1, zipcode);
  557. if (zip == 1)
  558. {
  559. fix = bfix;
  560. }
  561. else if (zip == 2)
  562. {
  563. fix = wfix;
  564. }
  565. else
  566. {
  567. tophone = phone1.TrimStart('0');
  568. if (zip == 3)
  569. {//本地固话去0加9 比如:988888517,937188888517
  570. fix = bfix;
  571. }
  572. else if (zip == 4)
  573. {//外地固话前加9 比如:9037188888517
  574. fix = wfix;
  575. }
  576. }
  577. phone = fix + tophone;
  578. return phone;
  579. }
  580. /// <summary>
  581. /// 根据号码和区号判断号码是否为归属地号码
  582. /// 返回0为分机号或特殊号码
  583. /// 返回1为本地号码
  584. /// 返回2为外地号码
  585. /// </summary>
  586. /// <param name="phone"></param>
  587. /// <param name="zipcode"></param>
  588. /// <returns></returns>
  589. [NonAction]
  590. public async Task<int> GetZipCodeByPhone(string phone, string zipcode)
  591. {
  592. int res = 0;
  593. if (phone.Trim().Length >= 7)
  594. {
  595. //7位及7位以上是固定电话或手机
  596. //判断是否手机
  597. if (phone.Trim().Length == 11 && phone[0] == '1')
  598. {//号码为11位,首位是1,为手机号
  599. string p7 = phone.Substring(0, 7);
  600. T_Sys_MobileData mobileModel = await busMobileDataRepository.GetFirst(q => q.F_MobileNum == p7);
  601. if (mobileModel != null)
  602. {
  603. if (mobileModel.F_ZipCode.Equals(zipcode))
  604. {
  605. res = 1;
  606. }
  607. else
  608. {
  609. res = 2;
  610. }
  611. }
  612. }
  613. else
  614. {
  615. if (phone.Trim().Length == 11 && phone.Substring(0, 3).Equals(zipcode))
  616. {//号码为11位
  617. //截取前三位区号判断是否本地
  618. bool resbd3 = phone.Substring(0, 3).Equals(zipcode);
  619. //截取前四位区号判断是否本地
  620. bool resbd4 = phone.Substring(0, 4).Equals(zipcode);
  621. if (resbd3 || resbd4)
  622. {
  623. res = 3;
  624. }
  625. else
  626. {
  627. res = 4;
  628. }
  629. }
  630. else if (phone.Trim().Length < 11)
  631. {//号码小于11位,为本地
  632. res = 1;
  633. }
  634. else if (phone.Trim().Length < 11)
  635. {//号码小于11位,为本地
  636. res = 3;
  637. }
  638. else if (phone.Trim().Length > 11 && phone.Substring(0, 4).Equals(zipcode))
  639. {//号码大于11位,截取前四位区号判断是否本地
  640. res = 3;
  641. }
  642. else
  643. {
  644. res = 4;
  645. }
  646. }
  647. }
  648. return res;
  649. }
  650. #endregion
  651. }
  652. }