VisaCommissionRepository.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using AutoMapper;
  2. using OASystem.Domain.AesEncryption;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.ViewModels.Groups;
  6. using OASystem.Infrastructure.Tools;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Runtime;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. /// <summary>
  16. /// 签证提成录入
  17. /// 仓储
  18. /// </summary>
  19. public class VisaCommissionRepository : BaseRepository<Grp_VisaCommission, VisaCommissionViewModel>
  20. {
  21. private readonly IMapper _mapper;
  22. private readonly DelegationInfoRepository _groupRep;
  23. public VisaCommissionRepository(SqlSugarClient sqlSugar, IMapper mapper, DelegationInfoRepository groupRep)
  24. : base(sqlSugar)
  25. {
  26. _mapper = mapper;
  27. _groupRep = groupRep;
  28. }
  29. /// <summary>
  30. /// Init
  31. /// </summary>
  32. /// <returns></returns>
  33. public async Task<JsonView> Init()
  34. {
  35. var groupInfo = await _groupRep.GetGroupNameList(new Domain.Dtos.Groups.GroupNameDto() { PortType = 1 });
  36. return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = new { GroupData = groupInfo.Data } };
  37. }
  38. /// <summary>
  39. /// Item
  40. /// </summary>
  41. /// <returns></returns>
  42. public async Task<JsonView> Item(VisaCommissionItemDto _dto)
  43. {
  44. var data = await _sqlSugar.Queryable<Grp_VisaCommission>()
  45. .Where(x => x.IsDel == 0 && x.DiId == _dto.DiId && x.UId == _dto.CurrUserId)
  46. .Select(x => new
  47. {
  48. x.Id,
  49. x.Country,
  50. x.Quantity,
  51. x.Remark
  52. })
  53. .ToListAsync();
  54. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == _dto.DiId).FirstAsync();
  55. if (groupInfo != null)
  56. {
  57. string[] countryArray = _groupRep.GroupSplitCountry(groupInfo.VisitCountry).ToArray();
  58. foreach (string country in countryArray)
  59. {
  60. if (data.Find(x => country.Equals(x.Country)) == null)
  61. {
  62. data.Add(new
  63. {
  64. Id = 0,
  65. Country = country,
  66. Quantity = 0,
  67. Remark = ""
  68. });
  69. }
  70. }
  71. }
  72. return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = data };
  73. }
  74. /// <summary>
  75. /// Save
  76. /// </summary>
  77. /// <returns></returns>
  78. public async Task<JsonView> Save(VisaCommissionSaveDto _dto)
  79. {
  80. var data = _mapper.Map<List<Grp_VisaCommission>>(_dto.Items);
  81. for (int i = 0; i < data.Count; i++)
  82. {
  83. data[i].CreateUserId = _dto.Items.FirstOrDefault()?.CurrUserId ?? 0;
  84. data[i].UId = _dto.Items.FirstOrDefault()?.CurrUserId ?? 0;
  85. }
  86. //添加数据
  87. var addData = data.Where(x => x.Id < 1).ToList();
  88. //修改数据
  89. var updData = data.Where(x => x.Id > 0).ToList();
  90. _sqlSugar.BeginTran();
  91. bool status = false;
  92. if (addData.Count > 0) {
  93. var addCount = await _sqlSugar.Insertable<Grp_VisaCommission>(addData).ExecuteCommandAsync();
  94. if (addCount > 0) status=true;
  95. }
  96. if (updData.Count > 0)
  97. {
  98. var updCount = await _sqlSugar.Updateable<Grp_VisaCommission>(updData)
  99. .UpdateColumns(x => new
  100. {
  101. x.Country,
  102. x.Quantity,
  103. x.Remark
  104. })
  105. .WhereColumns(x => x.Id)
  106. .ExecuteCommandAsync();
  107. if (updCount > 0) status = true;
  108. }
  109. var jv = new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
  110. if (status) _sqlSugar.CommitTran();
  111. else
  112. {
  113. _sqlSugar.RollbackTran();
  114. jv.Code = StatusCodes.Status400BadRequest;
  115. jv.Msg = "操作失败";
  116. }
  117. return jv;
  118. }
  119. /// <summary>
  120. /// Create
  121. /// </summary>
  122. /// <returns></returns>
  123. public async Task<JsonView> Create(VisaCommissionCreateDto _dto)
  124. {
  125. var _view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  126. //添加查重
  127. var info = await _sqlSugar.Queryable<Grp_VisaCommission>()
  128. .Where(x => x.IsDel == 0 && x.DiId == _dto.DiId && x.Country.Equals(_dto.Country))
  129. .FirstAsync();
  130. //if (info != null)
  131. //{
  132. // _view.Code = StatusCodes.Status400BadRequest;
  133. // _view.Msg = "该数据已存在请勿重新添加!";
  134. // return _view;
  135. //}
  136. var createInfo = _mapper.Map<Grp_VisaCommission>(_dto);
  137. createInfo.CreateUserId = _dto.CurrUserId;
  138. createInfo.UId = _dto.CurrUserId;
  139. var createStatus = await _sqlSugar.Insertable<Grp_VisaCommission>(createInfo)
  140. .ExecuteCommandAsync();
  141. if (createStatus > 0)
  142. {
  143. _view.Code = StatusCodes.Status200OK;
  144. _view.Msg = "操作成功!";
  145. return _view;
  146. }
  147. return _view;
  148. }
  149. /// <summary>
  150. /// Edit
  151. /// </summary>
  152. /// <param name="id"></param>
  153. /// <param name="_dto"></param>
  154. /// <returns></returns>
  155. public async Task<JsonView> Edit(int id,VisaCommissionCreateDto _dto)
  156. {
  157. var _view = new JsonView() { Code = StatusCodes.Status204NoContent, Msg = "操作失败!" };
  158. var editInfo = _mapper.Map<Grp_VisaCommission>(_dto);
  159. editInfo.CreateUserId = _dto.CurrUserId;
  160. editInfo.UId = _dto.CurrUserId;
  161. var editStatus = await _sqlSugar.Updateable<Grp_VisaCommission>(editInfo)
  162. .UpdateColumns(x => new
  163. {
  164. x.Country,
  165. x.Quantity,
  166. x.Remark
  167. })
  168. .Where(x => x.Id == id)
  169. .ExecuteCommandAsync();
  170. if (editStatus > 0)
  171. {
  172. _view.Code = StatusCodes.Status200OK;
  173. _view.Msg = "操作成功!";
  174. return _view;
  175. }
  176. return _view;
  177. }
  178. /// <summary>
  179. /// Del
  180. /// </summary>
  181. /// <param name="id"></param>
  182. /// <param name="currUserId"></param>
  183. /// <returns></returns>
  184. public async Task<JsonView> Del(int id,int currUserId)
  185. {
  186. var _view = new JsonView() { Code = StatusCodes.Status204NoContent, Msg = "操作失败!" };
  187. var editStatus = await _sqlSugar.Updateable<Grp_VisaCommission>()
  188. .SetColumns(x => new Grp_VisaCommission
  189. {
  190. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  191. DeleteUserId = currUserId,
  192. })
  193. .Where(x => x.Id == id)
  194. .ExecuteCommandAsync();
  195. if (editStatus > 0)
  196. {
  197. _view.Code = StatusCodes.Status200OK;
  198. _view.Msg = "操作成功!";
  199. return _view;
  200. }
  201. return _view;
  202. }
  203. }
  204. }