DelegationVisaRepository.cs 8.2 KB

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