VisitingClientsRepository.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using AutoMapper;
  2. using EyeSoft.Runtime.InteropServices;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Statistics;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OASystem.Infrastructure.Repositories.Groups
  13. {
  14. /// <summary>
  15. /// 客户拜访 仓储
  16. /// </summary>
  17. public class VisitingClientsRepository : BaseRepository<Grp_VisitingClients, VisitingClientsView>
  18. {
  19. private readonly IMapper _mapper;
  20. private readonly JsonView _view;
  21. public VisitingClientsRepository(SqlSugarClient sqlSugar, IMapper mapper)
  22. : base(sqlSugar)
  23. {
  24. _mapper = mapper;
  25. _view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = BusStatusCode.Failed.GetEnumDescription() };
  26. }
  27. /// <summary>
  28. /// 获取客户拜访列表
  29. /// </summary>
  30. /// <param name="portType"></param>
  31. /// <param name="pageIndex"></param>
  32. /// <param name="pageSize"></param>
  33. /// <param name="diId"></param>
  34. /// <param name="search"></param>
  35. /// <returns></returns>
  36. public async Task<JsonView> _List(int portType,int pageIndex, int pageSize,int diId,string search)
  37. {
  38. if (portType ==1 || portType == 2 || portType == 3)
  39. {
  40. string sql = string.Format(@$"Select
  41. ROW_NUMBER() Over(Order By BeginDt Asc) As RowNumber,
  42. vc.Id,
  43. vc.DiId,
  44. vc.BeginDt,
  45. vc.EndDt,
  46. vc.CustomerUnit,
  47. vc.CustomerJob,
  48. vc.CustomerName,
  49. vc.CustomerContact,
  50. u.CnName As Operator,
  51. vc.CreateTime As OperationDt,
  52. vc.Remark
  53. From Grp_VisitingClients vc
  54. Left Join Sys_Users u On vc.CreateUserId = u.Id
  55. Where vc.Isdel = 0 And vc.DiId = {diId}");
  56. RefAsync<int > total = 0;
  57. var data = await _sqlSugar.SqlQueryable<VisitingClientsListView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  58. _view.Code = StatusCodes.Status200OK;
  59. _view.Msg = MsgTips.Succeed;
  60. _view.Data = data;
  61. _view.Count = total;
  62. }
  63. return _view;
  64. }
  65. /// <summary>
  66. /// 团组客户拜访 Add Or Edit
  67. /// </summary>
  68. /// <param name="_dto"></param>
  69. /// <returns></returns>
  70. public async Task<JsonView> _AddOrEdit(MarketingSalesVCOperrateDto _dto)
  71. {
  72. var info = _mapper.Map<Grp_VisitingClients>(_dto);
  73. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3)
  74. {
  75. if (info.Id > 0) //编辑
  76. {
  77. var update = await _sqlSugar.Updateable(info).IgnoreColumns(it => new { it.CreateTime, it.CreateUserId, it.DeleteUserId, it.DeleteTime, it.IsDel }).ExecuteCommandAsync();
  78. if (update <= 0) return new JsonView() { Code = (int)BusStatusCode.UpdateFailed, Msg = BusStatusCode.UpdateFailed.GetEnumDescription() };
  79. }
  80. else //新增
  81. {
  82. info.CreateUserId = _dto.UserId;
  83. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  84. if (add <= 0) return new JsonView() { Code = (int)BusStatusCode.AddFailed, Msg = BusStatusCode.AddFailed.GetEnumDescription() };
  85. }
  86. return new JsonView() { Code = (int)BusStatusCode.Success, Msg = BusStatusCode.Success.GetEnumDescription() };
  87. }
  88. else return new JsonView() { Code = (int)BusStatusCode.PortTypeError, Msg = BusStatusCode.PortTypeError.GetEnumDescription() };
  89. }
  90. public async Task<JsonView> _Save(MarketingSalesVCSaveDto _dto)
  91. {
  92. var infos = _mapper.Map<List<Grp_VisitingClients>>(_dto.Items);
  93. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3)
  94. {
  95. if (_dto.DiId < 1)
  96. {
  97. return new JsonView() { Code = (int)BusStatusCode.DiIdValueError, Msg = BusStatusCode.DiIdValueError.GetEnumDescription() };
  98. }
  99. //int diid = infos[0].DiId;
  100. int userId = _dto.UserId;
  101. //if (diid < 1) return new JsonView() { Code = (int)BusStatusCode.DiIdValueError, Msg = BusStatusCode.DiIdValueError.GetEnumDescription() };
  102. if (userId < 1) return new JsonView() { Code = (int)BusStatusCode.UserIdValueError, Msg = BusStatusCode.UserIdValueError.GetEnumDescription() };
  103. //执行逻辑删除
  104. var update = await _sqlSugar.Updateable<Grp_VisitingClients>()
  105. .SetColumns(it => new Grp_VisitingClients() { IsDel = 1, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), DeleteUserId = _dto.UserId })
  106. .Where(it => it.DiId == _dto.DiId)
  107. .ExecuteCommandAsync();
  108. if (infos.Count > 0)
  109. {
  110. infos.ForEach(it =>
  111. {
  112. it.CreateUserId = _dto.UserId;
  113. });
  114. //执行添加
  115. var add = await _sqlSugar.Insertable(infos).ExecuteCommandAsync();
  116. if (add > 0) return new JsonView() { Code = (int)BusStatusCode.Success, Msg = BusStatusCode.Success.GetEnumDescription() };
  117. }
  118. else
  119. {
  120. return new JsonView() { Code = (int)BusStatusCode.Success, Msg = BusStatusCode.Success.GetEnumDescription() };
  121. }
  122. }
  123. else return new JsonView() { Code = (int)BusStatusCode.PortTypeError, Msg = BusStatusCode.PortTypeError.GetEnumDescription() };
  124. return new JsonView() { Code = (int)BusStatusCode.Failed, Msg = BusStatusCode.Failed.GetEnumDescription() };
  125. }
  126. /// <summary>
  127. /// 团组客户拜访 del
  128. /// </summary>
  129. /// <param name="id"></param>
  130. /// <param name="userId"></param>
  131. /// <returns></returns>
  132. public async Task<JsonView> _Del(int id, int userId)
  133. {
  134. var info = new Grp_VisitingClients() { Id = id, IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")};
  135. var update = await _sqlSugar.Updateable(info)
  136. .UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime })
  137. .WhereColumns(it => it.Id)
  138. .ExecuteCommandAsync();
  139. if (update <= 0) return new JsonView() { Code = (int)BusStatusCode.DeleteFailed, Msg = BusStatusCode.DeleteFailed.GetEnumDescription() };
  140. return new JsonView() { Code = (int)BusStatusCode.Success, Msg = BusStatusCode.Success.GetEnumDescription() };
  141. }
  142. }
  143. }