ForeignReceivablesRepository.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using AutoMapper;
  2. using MathNet.Numerics.Statistics.Mcmc;
  3. using NPOI.SS.Formula.Functions;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos.Financial;
  6. using OASystem.Domain.Dtos.Groups;
  7. using OASystem.Domain.Entities.Financial;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Infrastructure.Repositories.Groups;
  10. using OASystem.Infrastructure.Repositories.System;
  11. using SqlSugar;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace OASystem.Infrastructure.Repositories.Financial
  18. {
  19. /// <summary>
  20. /// 财务 - 团组应收款项 仓库
  21. /// 雷怡 2023.08.16 15:03
  22. /// </summary>
  23. public class ForeignReceivablesRepository : BaseRepository<Fin_ForeignReceivables, Fin_ForeignReceivablesView>
  24. {
  25. private readonly IMapper _mapper;
  26. private readonly DelegationInfoRepository _delegationRep;
  27. private readonly SetDataRepository _setDataRep;
  28. public ForeignReceivablesRepository(SqlSugarClient sqlSugar, IMapper mapper, DelegationInfoRepository delegationRep, SetDataRepository setDataRep)
  29. : base(sqlSugar)
  30. {
  31. _mapper = mapper;
  32. _delegationRep = delegationRep;
  33. _setDataRep = setDataRep;
  34. }
  35. /// <summary>
  36. /// 收款账单 数据源
  37. /// </summary>
  38. /// <returns></returns>
  39. public async Task<Result> GetDataSource()
  40. {
  41. Result result = new() { Code = -2 };
  42. var groupNameData = await _delegationRep.GetGroupNameList(new GroupNameDto());
  43. var currencyData = await _setDataRep.GetSetDataBySTId(_setDataRep,66); //币种
  44. var remittanceMethodData = await _setDataRep.GetSetDataBySTId(_setDataRep, 14); //汇款方式
  45. result.Code = 0;
  46. result.Msg = "成功!";
  47. result.Data = new {
  48. GroupNameData= groupNameData.Data,
  49. CurrencyData = currencyData.Data,
  50. RemittanceMethodData = remittanceMethodData.Data
  51. };
  52. return result;
  53. }
  54. /// <summary>
  55. /// 根据diid查询团组应收款项
  56. /// </summary>
  57. /// <param name="diid"></param>
  58. /// <returns></returns>
  59. public async Task<Result> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  60. {
  61. Result result = new() { Code = -2 };
  62. var groupInfoData = await _delegationRep.GetGroupInfo(new GroupInfoDto() { Id = dto.DiId });
  63. //应收款项
  64. string groupReceivedSql = string.Format(@"Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0}", dto.DiId);
  65. var groupReceivedList = await _sqlSugar.SqlQueryable<ForeignReceivablesView>(groupReceivedSql).ToListAsync();
  66. //已收款项
  67. string groupProceedsReceivedSql = string.Format(@"Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0}", dto.DiId);
  68. var groupProceedsReceivedList = await _sqlSugar.SqlQueryable<ProceedsReceivedView>(groupProceedsReceivedSql).ToListAsync();
  69. List<ProceedsReceivedView> NotFIDData = new List<ProceedsReceivedView>();
  70. if (dto.PortType == 1 )
  71. {
  72. foreach (var item in groupReceivedList)
  73. {
  74. item._ProceedsReceivedDatas = groupProceedsReceivedList.Where(s => s.FID == item.Id).ToList();
  75. }
  76. NotFIDData = groupProceedsReceivedList.Where(s =>! groupReceivedList.Any(e => s.FID == e.Id)).ToList();
  77. }
  78. result.Code = 0;
  79. result.Msg = "查询成功!";
  80. result.Data = new
  81. {
  82. GroupInfo = groupInfoData.Data,
  83. GroupCollectionStatementData = new
  84. {
  85. ReceivedData = groupReceivedList,
  86. UnallocatedData = NotFIDData
  87. }
  88. };
  89. return result;
  90. }
  91. /// <summary>
  92. /// 应收款项 删除
  93. /// </summary>
  94. /// <param name="dto"></param>
  95. /// <returns></returns>
  96. public async Task<Result> _Del(DelForForeignReceivablesInfoDto dto)
  97. {
  98. Result result = new Result() { Code = -1, Msg = "程序错误!" };
  99. _sqlSugar.BeginTran();
  100. try
  101. {
  102. var res = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  103. .Where(it => it.Id == dto.Id)
  104. .SetColumns(it => new Fin_ForeignReceivables()
  105. {
  106. IsDel = 1,
  107. DeleteUserId = dto.UserId,
  108. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  109. }
  110. ).ExecuteCommandAsync();
  111. if (res > 0)
  112. {
  113. await _sqlSugar.Updateable<Fin_ProceedsReceived>()
  114. .Where(a => a.FID == dto.Id)
  115. .SetColumns(a => new Fin_ProceedsReceived
  116. {
  117. IsDel = 1,
  118. DeleteUserId = dto.UserId,
  119. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  120. }).ExecuteCommandAsync();
  121. _sqlSugar.CommitTran();
  122. result.Msg = "删除成功!";
  123. result.Code = 0;
  124. }
  125. else
  126. {
  127. _sqlSugar.RollbackTran();
  128. result.Msg = "删除失败!";
  129. return result;
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. _sqlSugar.RollbackTran();
  135. result.Msg= ex.Message;
  136. return result;
  137. }
  138. return result;
  139. }
  140. /// <summary>
  141. /// 财务模块
  142. /// 收款账单 Add And Update
  143. /// </summary>
  144. /// <param name="diid"></param>
  145. /// <returns></returns>
  146. public async Task<Result> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  147. {
  148. Result result = new() { Code = -2 };
  149. if (dto.foreignReceivablesInfos.Count <= 0)
  150. {
  151. result.Msg = "收款账单没有信息,不能进行,添加或修改操作!!!";
  152. return result;
  153. }
  154. int addCount = 0, updateCount = 0;
  155. if (dto.PortType == 1)
  156. {
  157. List<Fin_ForeignReceivables> _ForeignReceivables = new List<Fin_ForeignReceivables>();
  158. foreach (var item in dto.foreignReceivablesInfos)
  159. {
  160. _ForeignReceivables.Add(new Fin_ForeignReceivables()
  161. {
  162. Diid = dto.DiId,
  163. Id = item.Id,
  164. PriceName = item.PriceName,
  165. Price = item.Price,
  166. Count = item.Count,
  167. Unit = item.Unit,
  168. ItemSumPrice = item.ItemSumPrice,
  169. Rate = item.Rate,
  170. Currency = item.Currency,
  171. AddingWay = item.AddingWay,
  172. CreateUserId = dto.UserId,
  173. CreateTime = DateTime.Now,
  174. Remark = item.Remark
  175. });
  176. }
  177. if (_ForeignReceivables.Count > 0)
  178. {
  179. var x = _sqlSugar.Storageable(_ForeignReceivables).ToStorage();
  180. addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
  181. updateCount = x.AsUpdateable.ExecuteCommand(); //存在更新
  182. }
  183. result.Code = 0;
  184. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  185. }
  186. return result;
  187. }
  188. /// <summary>
  189. /// 根据diid查询团组应收款项
  190. /// </summary>
  191. /// <param name="diid"></param>
  192. /// <returns></returns>
  193. public async Task<Result> GetGroupReceivablesByDiid(int diid)
  194. {
  195. Result result = new() { Code = -2 };
  196. string sql = string.Format(@"Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0}", diid);
  197. var groupReceivedList = await _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql).ToListAsync();
  198. result.Code = 0;
  199. result.Msg = "查询成功!";
  200. result.Data = groupReceivedList;
  201. return result;
  202. }
  203. /// <summary>
  204. /// 根据diid 数组 查询团组应收款项
  205. /// </summary>
  206. /// <param name="diid"></param>
  207. /// <returns></returns>
  208. public async Task<Result> GetGroupReceivablesByDiids(int[] diids)
  209. {
  210. Result result = new() { Code = -2 };
  211. //string sql = string.Format(@"Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0}", diids);
  212. var groupReceivedList = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  213. .Where(pr => pr.IsDel == 0 && diids.Contains(pr.Diid)).ToListAsync();
  214. result.Code = 0;
  215. result.Msg = "查询成功!";
  216. result.Data = groupReceivedList;
  217. return result;
  218. }
  219. }
  220. }