DelegationVisaRepository.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using Aspose.Words.Lists;
  2. using OASystem.Domain.Dtos.Groups;
  3. using OASystem.Domain.Entities.Groups;
  4. using OASystem.Domain.ViewModels.Groups;
  5. using OASystem.Domain.ViewModels.Resource;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace OASystem.Infrastructure.Repositories.Groups
  12. {
  13. public class DelegationVisaRepository : BaseRepository<Grp_VisaProgress, Grp_DelegationVisaView>
  14. {
  15. public DelegationVisaRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  16. {
  17. }
  18. public DelegationVisaViewList GetDelegationList(IOS_VisaDto _dto)
  19. {
  20. string sqlWhere = string.Format(" Where IsDel=0 ");
  21. int currPIndex = (((_dto.PageIndex > 0) ? (_dto.PageIndex - 1) : 0) * _dto.PageSize) + 1;
  22. int currPSize = (((_dto.PageIndex > 0) ? (_dto.PageIndex - 1) : 0) + 1) * _dto.PageSize;
  23. ChangeDataBase(DBEnum.OA2014DB);
  24. string sql = string.Format(@" Select * From(Select ROW_NUMBER() Over(order By Id desc) as RowNumber, Id as DiId,
  25. TeamName,ClientUnit,ClientName,TeamLev,VisitDate,VisitDays,VisitPNumber
  26. From DelegationInfo With(Nolock) {2}
  27. ) as tb Where tb.RowNumber Between {0} And {1} ", currPIndex, currPSize, sqlWhere);
  28. DelegationVisaViewList rst = new DelegationVisaViewList();
  29. rst.CurrPageIndex = currPIndex;
  30. rst.CurrPageSize = currPSize;
  31. List<Grp_DelegationVisaView> dataSource = _sqlSugar.SqlQueryable<Grp_DelegationVisaView>(sql).ToList();
  32. foreach (var item in dataSource)
  33. {
  34. string sql2 = string.Format(@" Select * From Grp_VisaProgressCustomer With(Nolock) Where DiId={0} And IsDel=0 ", item.DiId);
  35. List<Grp_VisaProgressCustomer> listComplete = _sqlSugar.SqlQueryable<Grp_VisaProgressCustomer>(sql2).ToList();
  36. item.CompletePNumber = string.Format(@"已完成{0}人", listComplete.Count);
  37. }
  38. rst.DataList = new List<Grp_DelegationVisaView>(dataSource);
  39. if (rst.DataList.Count > 0)
  40. {
  41. string sqlCount = string.Format(@" Select Id as DiId From DelegationInfo With(Nolock) {0} ", sqlWhere);
  42. int dataCount = _sqlSugar.SqlQueryable<Grp_DelegationVisaView>(sqlCount).Count();
  43. rst.DataCount = dataCount;
  44. }
  45. return rst;
  46. }
  47. public List<DelegationVisaProgressView> GetDelegationProgressList(int diid)
  48. {
  49. ChangeDataBase(DBEnum.OA2014DB);
  50. string sqlDeleClient = string.Format(@" Select
  51. Id as 'PersonViewId',
  52. Diid,
  53. LastName,
  54. [Name] as 'FirstName'
  55. From DeleClient With(Nolock) Where Diid = {0} And IsDel = 0 ", diid);
  56. List<DelegationVisaProgressView> clientList = _sqlSugar.SqlQueryable<DelegationVisaProgressView>(sqlDeleClient).ToList();
  57. string sqlDelegation = string.Format(@" Select * From DelegationInfo With(Nolock) Where Id = {0} ", diid);
  58. OA2021_DelegationInfo delegationInfo = _sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sqlDelegation).First();
  59. //string countryName = delegationInfo.VisitCountry;
  60. #region 检查与配置
  61. ChangeDataBase(DBEnum.OA2023DB);
  62. string sqlCheck = string.Format(@" Select * From Grp_VisaProgressCustomer With(Nolock) Where DiId = {0} ", diid);
  63. List<Grp_VisaProgressCustomer> listVisaPro = _sqlSugar.SqlQueryable<Grp_VisaProgressCustomer>(sqlCheck).ToList();
  64. if (listVisaPro.Count < 1)
  65. {
  66. //listVisaPro = new List<Grp_VisaProgressCustomer>(initVisitCountry(diid, delegationInfo));
  67. initVisitCountry(diid, delegationInfo);
  68. }
  69. #endregion
  70. string sqlView1 = string.Format(@" Select
  71. Id as 'ProgressViewId',
  72. DiId,
  73. CustomerId,
  74. LastName,
  75. FirstName,
  76. Country,
  77. WorkStatus as 'StatusSign'
  78. From Grp_VisaProgressCustomer With(Nolock) Where DiId = {0} And IsDel = 0 ", diid);
  79. List<DelegationVisaProgressView> result = _sqlSugar.SqlQueryable<DelegationVisaProgressView>(sqlView1).ToList();
  80. //查询各子项行数
  81. foreach (var pro in result)
  82. {
  83. string sqlCheckCount = string.Format(@" Select PicType,Count(PicType) PicTypeCount
  84. From Grp_VisaProgressCustomerPicture Where VisaProgressCustomerId = {0}
  85. Group by PicType Order By PicType ", pro.ProgressViewId);
  86. List<dynamic> tempList = _sqlSugar.SqlQueryable<dynamic>(sqlCheckCount).ToList();
  87. DelegationVisaPicCountList countList = new DelegationVisaPicCountList();
  88. foreach (var item in tempList)
  89. {
  90. int tempCount = item.PicTypeCount;
  91. switch (item.PicType)
  92. {
  93. case 0: countList.FirstPageCount = tempCount; break;
  94. case 1: countList.DocumentsCount = tempCount; break;
  95. case 2: countList.ExemptionCount = tempCount; break;
  96. case 3: countList.DispatchCount = tempCount; break;
  97. case 4: countList.VisaCount = tempCount; break;
  98. case 5: countList.InvoiceCount = tempCount; break;
  99. default: break;
  100. }
  101. }
  102. countList.totalCount();
  103. pro.PicCountList = countList;
  104. }
  105. return result;
  106. }
  107. public void initVisitCountry(int diid, OA2021_DelegationInfo delegationInfo)
  108. {
  109. ChangeDataBase(DBEnum.OA2014DB);
  110. string sqlDeleClient = String.Format(@" Select * From DeleClient With(Nolock) Where diid = {0} ", diid);
  111. List<OA2021_DeleClient> listDeleClient = _sqlSugar.SqlQueryable<OA2021_DeleClient>(sqlDeleClient).ToList();
  112. ChangeDataBase(DBEnum.OA2023DB);
  113. List<Grp_VisaProgressCustomer> listVisaCustomer = new List<Grp_VisaProgressCustomer>();
  114. string countryName = delegationInfo.VisitCountry;
  115. string[] countrys = Regex.Replace(countryName, @"[,,|-、\s丶]", ",", RegexOptions.IgnoreCase).Split(',');
  116. foreach (var client in listDeleClient)
  117. {
  118. foreach (string cname in countrys)
  119. {
  120. Grp_VisaProgressCustomer item = new Grp_VisaProgressCustomer();
  121. item.Country = cname;
  122. item.CreateUserId = -3;
  123. item.CustomerId = 0;
  124. item.DiId = diid;
  125. item.FirstName = client.Name;
  126. item.LastName = client.LastName;
  127. item.WorkStatus = 0;
  128. listVisaCustomer.Add(item);
  129. }
  130. }
  131. _sqlSugar.Insertable(listVisaCustomer).UseParameter().ExecuteCommand();
  132. //return listVisaCustomer;
  133. }
  134. public List<VisaProgressImageView> GetVisaProgressImageList(int visaProgressCustomerId, int picType)
  135. {
  136. string sql1 = string.Format(@" Select
  137. Id as imageId,
  138. PicPath as 'path',
  139. PicName as picName
  140. From Grp_VisaProgressCustomerPicture
  141. Where VisaProgressCustomerId = {0} And PicType = {1} ", visaProgressCustomerId, picType);
  142. List<VisaProgressImageView> imageList = _sqlSugar.SqlQueryable<VisaProgressImageView>(sql1).ToList();
  143. return imageList;
  144. }
  145. }
  146. }