ForeignReceivablesRepository.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. #region 关联已收款项
  36. /// <summary>
  37. /// 收款账单 数据源
  38. /// </summary>
  39. /// <returns></returns>
  40. public async Task<Result> GetDataSource()
  41. {
  42. Result result = new() { Code = -2 };
  43. var groupNameData = await _delegationRep.GetGroupNameList(new GroupNameDto());
  44. var currencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种
  45. var remittanceMethodData = await _setDataRep.GetSetDataBySTId(_setDataRep, 14); //汇款方式
  46. result.Code = 0;
  47. result.Msg = "成功!";
  48. result.Data = new
  49. {
  50. GroupNameData = groupNameData.Data,
  51. CurrencyData = currencyData.Data,
  52. RemittanceMethodData = remittanceMethodData.Data
  53. };
  54. return result;
  55. }
  56. /// <summary>
  57. /// 根据diid查询团组应收款项
  58. /// </summary>
  59. /// <param name="diid"></param>
  60. /// <returns></returns>
  61. public async Task<Result> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  62. {
  63. Result result = new() { Code = -2 };
  64. var groupInfoData = await _delegationRep.GetGroupInfo(new GroupInfoDto() { Id = dto.DiId });
  65. //应收款项
  66. string groupReceivedSql = string.Format(@"Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0}", dto.DiId);
  67. var groupReceivedList = await _sqlSugar.SqlQueryable<ForeignReceivablesView>(groupReceivedSql).ToListAsync();
  68. //已收款项
  69. string groupProceedsReceivedSql = string.Format(@"Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0}", dto.DiId);
  70. var groupProceedsReceivedList = await _sqlSugar.SqlQueryable<ProceedsReceivedView>(groupProceedsReceivedSql).ToListAsync();
  71. List<ProceedsReceivedView> NotFIDData = new List<ProceedsReceivedView>();
  72. if (dto.PortType == 1)
  73. {
  74. foreach (var item in groupReceivedList)
  75. {
  76. item._ProceedsReceivedDatas = groupProceedsReceivedList.Where(s => s.FID == item.Id).ToList();
  77. }
  78. NotFIDData = groupProceedsReceivedList.Where(s => !groupReceivedList.Any(e => s.FID == e.Id)).ToList();
  79. }
  80. result.Code = 0;
  81. result.Msg = "查询成功!";
  82. result.Data = new
  83. {
  84. GroupInfo = groupInfoData.Data,
  85. GroupCollectionStatementData = new
  86. {
  87. ReceivedData = groupReceivedList,
  88. UnallocatedData = NotFIDData
  89. }
  90. };
  91. return result;
  92. }
  93. /// <summary>
  94. /// 应收款项 删除
  95. /// </summary>
  96. /// <param name="dto"></param>
  97. /// <returns></returns>
  98. public async Task<Result> _Del(DelForForeignReceivablesInfoDto dto)
  99. {
  100. Result result = new Result() { Code = -1, Msg = "程序错误!" };
  101. _sqlSugar.BeginTran();
  102. try
  103. {
  104. var res = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  105. .Where(it => it.Id == dto.Id)
  106. .SetColumns(it => new Fin_ForeignReceivables()
  107. {
  108. IsDel = 1,
  109. DeleteUserId = dto.UserId,
  110. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  111. }
  112. ).ExecuteCommandAsync();
  113. if (res > 0)
  114. {
  115. await _sqlSugar.Updateable<Fin_ProceedsReceived>()
  116. .Where(a => a.FID == dto.Id)
  117. .SetColumns(a => new Fin_ProceedsReceived
  118. {
  119. IsDel = 1,
  120. DeleteUserId = dto.UserId,
  121. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  122. }).ExecuteCommandAsync();
  123. _sqlSugar.CommitTran();
  124. result.Msg = "删除成功!";
  125. result.Code = 0;
  126. }
  127. else
  128. {
  129. _sqlSugar.RollbackTran();
  130. result.Msg = "删除失败!";
  131. return result;
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. _sqlSugar.RollbackTran();
  137. result.Msg = ex.Message;
  138. return result;
  139. }
  140. return result;
  141. }
  142. /// <summary>
  143. /// 财务模块
  144. /// 收款账单 Add And Update
  145. /// </summary>
  146. /// <param name="diid"></param>
  147. /// <returns></returns>
  148. public async Task<Result> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  149. {
  150. Result result = new() { Code = -2 };
  151. if (dto.foreignReceivablesInfos.Count <= 0)
  152. {
  153. result.Msg = "收款账单没有信息,不能进行,添加或修改操作!!!";
  154. return result;
  155. }
  156. int addCount = 0, updateCount = 0;
  157. if (dto.PortType == 1)
  158. {
  159. List<Fin_ForeignReceivables> _ForeignReceivables = new List<Fin_ForeignReceivables>();
  160. foreach (var item in dto.foreignReceivablesInfos)
  161. {
  162. _ForeignReceivables.Add(new Fin_ForeignReceivables()
  163. {
  164. Diid = dto.DiId,
  165. Id = item.Id,
  166. PriceName = item.PriceName,
  167. Price = item.Price,
  168. Count = item.Count,
  169. Unit = item.Unit,
  170. ItemSumPrice = item.ItemSumPrice,
  171. Rate = item.Rate,
  172. Currency = item.Currency,
  173. AddingWay = item.AddingWay,
  174. CreateUserId = dto.UserId,
  175. CreateTime = DateTime.Now,
  176. Remark = item.Remark
  177. });
  178. }
  179. if (_ForeignReceivables.Count > 0)
  180. {
  181. var x = _sqlSugar.Storageable(_ForeignReceivables).ToStorage();
  182. addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
  183. updateCount = x.AsUpdateable.ExecuteCommand(); //存在更新
  184. }
  185. result.Code = 0;
  186. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  187. }
  188. return result;
  189. }
  190. /// <summary>
  191. /// 根据diid查询团组应收款项
  192. /// </summary>
  193. /// <param name="diid"></param>
  194. /// <returns></returns>
  195. public async Task<Result> GetGroupReceivablesByDiid(int diid)
  196. {
  197. Result result = new() { Code = -2 };
  198. string sql = string.Format(@"Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0}", diid);
  199. var groupReceivedList = await _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql).ToListAsync();
  200. result.Code = 0;
  201. result.Msg = "查询成功!";
  202. result.Data = groupReceivedList;
  203. return result;
  204. }
  205. /// <summary>
  206. /// 根据diid 数组 查询团组应收款项
  207. /// </summary>
  208. /// <param name="diid"></param>
  209. /// <returns></returns>
  210. public async Task<Result> GetGroupReceivablesByDiids(int[] diids)
  211. {
  212. Result result = new() { Code = -2 };
  213. //string sql = string.Format(@"Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0}", diids);
  214. var groupReceivedList = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  215. .Where(pr => pr.IsDel == 0 && diids.Contains(pr.Diid)).ToListAsync();
  216. result.Code = 0;
  217. result.Msg = "查询成功!";
  218. result.Data = groupReceivedList;
  219. return result;
  220. }
  221. #endregion
  222. #region 未关联已收款项
  223. /// <summary>
  224. /// 收款账单 数据源
  225. /// </summary>
  226. /// <returns></returns>
  227. public async Task<Result> PostDataSource()
  228. {
  229. Result result = new() { Code = -2 };
  230. var groupNameData = await _delegationRep.GetGroupNameList(new GroupNameDto());
  231. var currencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种
  232. var remittanceMethodData = await _setDataRep.GetSetDataBySTId(_setDataRep, 14); //汇款方式
  233. result.Code = 0;
  234. result.Msg = "成功!";
  235. result.Data = new
  236. {
  237. GroupNameData = groupNameData.Data,
  238. CurrencyData = currencyData.Data,
  239. RemittanceMethodData = remittanceMethodData.Data
  240. };
  241. return result;
  242. }
  243. /// <summary>
  244. /// 根据diid查询团组应收款项
  245. /// </summary>
  246. /// <param name="diid"></param>
  247. /// <returns></returns>
  248. public async Task<Result> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  249. {
  250. Result result = new() { Code = -2 };
  251. var groupInfoData = await _delegationRep.GetGroupInfo(new GroupInfoDto() { Id = dto.DiId });
  252. //应收款项
  253. string groupReceivedSql = string.Format(@"Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0}", dto.DiId);
  254. var groupReceivedList = await _sqlSugar.SqlQueryable<ProceedsReceivedNewView>(groupReceivedSql).ToListAsync();
  255. result.Code = 0;
  256. result.Msg = "查询成功!";
  257. result.Data = new
  258. {
  259. GroupInfo = groupInfoData.Data,
  260. GroupCollectionStatementData = groupReceivedList
  261. };
  262. return result;
  263. }
  264. /// <summary>
  265. /// 财务模块
  266. /// 收款账单 Add And Update
  267. /// </summary>
  268. /// <param name="diid"></param>
  269. /// <returns></returns>
  270. public async Task<Result> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  271. {
  272. Result result = new() { Code = -2 };
  273. if (dto.foreignReceivablesInfos.Count <= 0)
  274. {
  275. result.Msg = "收款账单没有信息,不能进行,添加或修改操作!!!";
  276. return result;
  277. }
  278. int addCount = 0, updateCount = 0;
  279. if (dto.PortType == 1)
  280. {
  281. List<Fin_ForeignReceivables> _ForeignReceivables = new List<Fin_ForeignReceivables>();
  282. foreach (var item in dto.foreignReceivablesInfos)
  283. {
  284. _ForeignReceivables.Add(new Fin_ForeignReceivables()
  285. {
  286. Diid = dto.DiId,
  287. Id = item.Id,
  288. PriceName = item.PriceName,
  289. Price = item.Price,
  290. Count = item.Count,
  291. Unit = item.Unit,
  292. ItemSumPrice = item.ItemSumPrice,
  293. Rate = item.Rate,
  294. Currency = item.Currency,
  295. AddingWay = item.AddingWay,
  296. CreateUserId = dto.UserId,
  297. CreateTime = DateTime.Now,
  298. Remark = item.Remark
  299. });
  300. }
  301. if (_ForeignReceivables.Count > 0)
  302. {
  303. var x = _sqlSugar.Storageable(_ForeignReceivables).ToStorage();
  304. addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
  305. updateCount = x.AsUpdateable.ExecuteCommand(); //存在更新
  306. }
  307. result.Code = 0;
  308. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  309. }
  310. return result;
  311. }
  312. /// <summary>
  313. /// 财务模块
  314. /// 收款账单
  315. /// Del
  316. /// </summary>
  317. /// <param name="diid"></param>
  318. /// <returns></returns>
  319. public async Task<Result> PostReceivablesDel(ForeignReceivablesDelDto dto)
  320. {
  321. Result result = new() { Code = -2 };
  322. var delStatus = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  323. .SetColumns(a => new Fin_ForeignReceivables
  324. {
  325. IsDel = 1,
  326. DeleteUserId = dto.UserId,
  327. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  328. })
  329. .Where(a => a.Id == dto.Id)
  330. .ExecuteCommandAsync();
  331. if (delStatus > 0)
  332. {
  333. result.Msg = "操作成功!";
  334. result.Code = 0;
  335. }
  336. else
  337. {
  338. result.Msg = "操作成功!";
  339. }
  340. return result;
  341. }
  342. #endregion
  343. }
  344. }