| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System;
- using System.Collections.Generic;
- using System.Common;
- using System.IRepositories.Call;
- using System.Linq;
- using System.Model;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using SqlSugar;
- namespace TVShoppingCallCenter_ZLJ.Controllers.CallCenter
- {
- [Produces("application/json")]
- [Route("api/[controller]")]
- public class ExtensionBindController : BaseController
- {
- private readonly ICall_ExtensionBindRepository call_ExtensionBindRepository;
-
- public ExtensionBindController(ICall_ExtensionBindRepository _call_ExtensionBindRepository)
- {
- call_ExtensionBindRepository = _call_ExtensionBindRepository;
- }
- /// <summary>
- /// 添加媒体
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("add")]
- public async Task<IActionResult> AddAsync(T_Call_ExtensionBind input)
- {
- if (string.IsNullOrEmpty(input.F_Extension))
- return Error("请输入分机号");
- if (string.IsNullOrEmpty(input.F_Telephone))
- return Error("请输入固话号");
- if (await call_ExtensionBindRepository.GetCount(x => x.F_Extension == input.F_Extension
- && x.F_IsDelete == 0) > 0)
- return Error("分机号已存在");
- input.F_AddTime = DateTime.Now;
- input.F_IsDelete = 0;
- input.F_AddUser = UserLogin.UserCode;
- var res = await call_ExtensionBindRepository.Add(input);
- if (res > 0)
- {
- return Success("添加成功");
- }
- else
- {
- return Error("添加失败");
- }
- }
- /// <summary>
- /// 修改媒体
- /// </summary>
- [HttpPost("update")]
- public async Task<IActionResult> UpdateAsync(T_Call_ExtensionBind input)
- {
- if (input.F_ID <= 0)
- return Error("参数错误");
- if (string.IsNullOrEmpty(input.F_Extension))
- return Error("请输入分机号");
- if (string.IsNullOrEmpty(input.F_Telephone))
- return Error("请输入固话号");
- var model = await call_ExtensionBindRepository.GetSingle(x => x.F_ID == input.F_ID);
- if (model == null)
- return Error("操作失败");
- if (await call_ExtensionBindRepository.GetCount(x => x.F_Extension == input.F_Extension
- && x.F_IsDelete == 0&&x .F_ID !=input .F_ID ) > 0)
- return Error("分机号已存在");
- input.F_IsDelete = 0;
- model.F_Extension = input.F_Extension;
- model.F_Telephone = input.F_Telephone;
- var b = await call_ExtensionBindRepository.Update(model);
- if (b)
- return Success("修改成功");
- return Error("修改失败");
- }
- /// <summary>
- /// 删除媒体
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost("delete")]
- public async Task<IActionResult> Remove(int[] ids)
- {
- var res = 0;
- if (ids != null && ids.Length > 0)
- {
- foreach (var item in ids)
- {
- var model = await call_ExtensionBindRepository.GetSingle(x => x.F_ID == item);
- model.F_IsDelete = (int)EnumUserCountState.Delete;
- if (call_ExtensionBindRepository.Update(model).Result)
- res += 1;
- }
- if (res == ids.Length)
- return Success("删除成功");
- else if (res > 0 && res < ids.Length)
- return Error("部分删除失败,请查看后重新操作");
- else
- return Error("删除失败,请查看后重新操作");
- }
- else
- return Error("请选择要删除的记录");
- }
- /// <summary>
- /// 获取媒体列表
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="pageindex"></param>
- /// <param name="pagesize"></param>
- /// <returns></returns>
- [HttpGet("getlist")]
- public async Task<IActionResult> GetLisAsync(string extension, string telephone, int pageindex = 1, int pagesize = 20)
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- #region 条件筛选
- conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
-
- if (!string.IsNullOrEmpty(extension))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Extension", ConditionalType = ConditionalType.Like, FieldValue = extension });
- }
- if (!string.IsNullOrEmpty(telephone))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Telephone", ConditionalType = ConditionalType.Like, FieldValue = telephone });
- }
-
- #endregion
- int recordCount = 0;
- var list = await call_ExtensionBindRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = list,
- total = list.Totals,
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取详情
- /// </summary>
- /// <param name="id">id</param>
- /// <returns></returns>
- [HttpGet("getdetails")]
- public async Task<IActionResult> GetDetailsAsync(int id)
- {
- if (id <= 0)
- return Error("参数错误");
- var model = await call_ExtensionBindRepository.GetSingle(x => x.F_ID == id);
- if (model == null)
- {
- return Error("获取失败");
- }
- return Success("获取成功!", model);
- }
- }
- }
|