123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- using OASystem.API.OAMethodLib;
- using OASystem.Domain.AesEncryption;
- using OASystem.Domain.Dtos.CRM;
- using OASystem.Domain.Entities.Customer;
- using OASystem.Infrastructure.Repositories.CRM;
- using System.Collections;
- using System.Diagnostics;
- namespace OASystem.API.Controllers
- {
- /// <summary>
- /// 市场客户资料
- /// </summary>
- [Route("api/[controller]/[action]")]
- public class MarketCustomerResourcesController : ControllerBase
- {
- private readonly NewClientDataRepository _clientDataRepository;
- private readonly SqlSugarClient _sqlSugar;
- /// <summary>
- /// 初始化
- /// </summary>
- public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository, SqlSugarClient sqlSugar)
- {
- this._clientDataRepository = clientDataRepository;
- _sqlSugar = sqlSugar;
- }
- /// <summary>
- /// 客户资料数据
- /// 基础数据
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
- {
- JsonView jw = new JsonView();
- try
- {
- Result resultData = await _clientDataRepository._Init(dto);
- if (resultData.Code == 0)
- {
- jw = JsonView(true, "查询成功!", resultData.Data);
- }
- else
- {
- jw = JsonView(false, resultData.Msg);
- }
- }
- catch (Exception)
- {
- jw = JsonView(false, "程序错误!");
- }
- return Ok(jw);
- }
- /// <summary>
- /// 查询客户资料数据
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
- {
- #region 参数验证
- if (dto.OperationUserId < 0)
- return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
- if (dto.PortType < 0)
- return Ok(JsonView(false, "请传入有效的PortType参数!"));
- #endregion
- JsonView jw = new JsonView();
- try
- {
- Result resultData = await _clientDataRepository.QueryNewClientData(dto);
- if (resultData.Code == 0)
- {
- #region 客户资料表操作记录
- await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
- #endregion
- jw = JsonView(true, resultData.Msg, resultData.Data);
- }
- else
- {
- jw = JsonView(false, resultData.Msg);
- }
- }
- catch (Exception)
- {
- jw = JsonView(false, "程序错误!");
- }
- return Ok(jw);
- }
- /// <summary>
- /// 客户资料数据
- /// Details
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
- {
- #region 参数验证
- if (dto.Id < 0)
- return Ok(JsonView(false, "请传入有效的Id参数!"));
- if (dto.UserId < 0)
- return Ok(JsonView(false, "请传入有效的UserId参数!"));
- if (dto.PortType < 0)
- return Ok(JsonView(false, "请传入有效的PortType参数!"));
- #endregion
- JsonView jw = new JsonView();
- try
- {
- Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
- if (resultData.Code == 0)
- {
- #region 客户资料表操作记录
- await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
- #endregion
- jw = JsonView(true, "查询成功!", resultData.Data);
- }
- else
- {
- jw = JsonView(false, resultData.Msg);
- }
- }
- catch (Exception)
- {
- jw = JsonView(false, "程序错误!");
- }
- return Ok(jw);
- }
- /// <summary>
- /// 客户资料操作(Status:1.新增,2.修改)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
- {
- #region 参数验证
- if (dto.CreateUserId < 0)
- {
- return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
- }
- if (dto.PortType < 0)
- {
- return Ok(JsonView(false, "请传入有效的PortType参数!"));
- }
- #endregion
- try
- {
- Domain.Result result = await _clientDataRepository.NewClientOp(dto);
- if (result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- #region 客户资料操作记录
- OperationEnum operationEnum = OperationEnum.NoOperation;
- if (dto.Status == 1)
- {
- operationEnum = OperationEnum.Add;
- dto.Id = Convert.ToInt32(result.Data);
- }
- else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
- await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
- #endregion
- return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
- }
- }
- /// <summary>
- /// 新客户资料操作(删除)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> NewClientDel(DelBaseDto dto)
- {
- #region 参数验证
- if (dto.Id < 0)
- {
- return Ok(JsonView(false, "请传入有效的Id参数!"));
- }
- if (dto.DeleteUserId < 0)
- {
- return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
- }
- if (dto.PortType < 0)
- {
- return Ok(JsonView(false, "请传入有效的PortType参数!"));
- }
- #endregion
- var res = await _clientDataRepository.DelNewClientData(dto);
- if (res.Code != 0)
- {
- return Ok(JsonView(false, "删除失败"));
- }
- #region 客户资料表操作记录
- await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
- #endregion
- return Ok(JsonView(true, "删除成功!"));
- }
- /// <summary>
- /// 获取下拉列表数据和单条数据信息
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
- {
- JsonView jw = new JsonView();
- var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
- if (result.Code == 0)
- {
- #region 客户资料表操作记录
- await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
- #endregion
- jw = JsonView(true, result.Msg, result.Data);
- }
- else
- {
- jw = JsonView(false, result.Msg);
- }
- return Ok(jw);
- }
- /// <summary>
- /// 获取现有负责人
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryUserSelect()
- {
- try
- {
- Result resTable = _clientDataRepository.QueryUserSelect();
- return Ok(JsonView(true, resTable.Msg, resTable.Data));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- }
- }
- /// <summary>
- /// 获取出团数据
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryNumberGroups()
- {
- var result = await _clientDataRepository.QueryNumberGroups();
- if (result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true, result.Msg, result.Data));
- }
- /// <summary>
- /// 新客户资料操作
- /// 批量分配
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
- {
- #region 参数验证
- if (dto.UserId < 0)
- {
- return Ok(JsonView(false, "请传入有效的UserId参数!"));
- }
- if (dto.PortType < 0)
- {
- return Ok(JsonView(false, "请传入有效的PortType参数!"));
- }
- #endregion
- var res = await _clientDataRepository._BatchAssignment(dto);
- if (res.Code != 0)
- {
- return Ok(JsonView(false, res.Msg));
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- [HttpPost]
-
- public IActionResult QueryClientType(QueryClientTypeDto Dto)
- {
- var jw = JsonView(true,"获取成功!");
- Dictionary<int,List<int>> keyValuePairs = new Dictionary<int,List<int>>();
- keyValuePairs.Add(419, new List<int>() //四川
- {
- 376,377,378,381,382,387,388,389,390,753,754
- });
- keyValuePairs.Add(420, new List<int>() //云南
- {
- 407,408,409,410,449,451,452,453,567,754
- });
- keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754 }); // 贵州
- keyValuePairs.Add(422, new List<int>() { 415, 416, 754 }); // 西藏
- keyValuePairs.Add(423, new List<int>() { 417, 418, 454, 456, 754 }); // 重庆
- keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754 }); // 青海
- keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754 }); // 陕西
- keyValuePairs.Add(606, new List<int>() { 597, 598, 599, 600, 601, 602, 603, 604, 754 }); // 宁夏
- keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754 }); // 甘肃
- keyValuePairs.Add(634, new List<int>() { 455, 630, 631, 632, 633, 754 }); // 新疆
- ArrayList arr = new ArrayList();
- var ids = new List<int>();
- foreach (var item in Dto.SetDataIdArr)
- {
- if (keyValuePairs.Keys.Contains(item))
- {
- ids.AddRange(keyValuePairs[item]);
- }
- }
- arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
- .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
- .Select(x => new { x.Id, x.Name })
- .ToList());
- if (arr.Count == 0)
- {
- arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
- .Where(u => u.STid == 37 && u.IsDel == 0)
- .Select(x => new { x.Id, x.Name }).ToList());
- }
- jw.Data = arr;
-
- return Ok(jw);
- }
- }
- }
|