DelegationVisaRepository.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. ChangeDataBase(DBEnum.OA2023DB);
  38. string sql2 = string.Format(@" Select WorkStatus as code,COUNT(1) as nums From Grp_VisaProgressCustomer With(Nolock) Where DiId={0} And IsDel=0 Group by WorkStatus ", item.DiId);
  39. List<dynamic> listComplete = _sqlSugar.SqlQueryable<dynamic>(sql2).ToList();
  40. int totalCount = 0;
  41. //未作详细描述文本
  42. int count_0 = 0;
  43. int count_1 = 0;
  44. int count_2 = 0;
  45. int count_3 = 0;
  46. foreach (var comCount in listComplete)
  47. {
  48. switch (comCount.code)
  49. {
  50. case 0: count_0 = comCount.nums; break;
  51. case 1: count_1 = comCount.nums; break;
  52. case 2: count_2 = comCount.nums; break;
  53. case 3: count_3 = comCount.nums; break;
  54. default:
  55. break;
  56. }
  57. totalCount += comCount.nums;
  58. }
  59. int comNums = totalCount - count_0;
  60. if (comNums > 0)
  61. {
  62. item.CompletePNumber = string.Format(@"{0} / {1}", comNums, totalCount);
  63. }
  64. else {
  65. item.CompletePNumber = "跳转配置";
  66. }
  67. }
  68. rst.DataList = new List<Grp_DelegationVisaView>(dataSource);
  69. if (rst.DataList.Count > 0)
  70. {
  71. ChangeDataBase(DBEnum.OA2014DB);
  72. string sqlCount = string.Format(@" Select Id as DiId From DelegationInfo With(Nolock) {0} ", sqlWhere);
  73. int dataCount = _sqlSugar.SqlQueryable<Grp_DelegationVisaView>(sqlCount).Count();
  74. rst.DataCount = dataCount;
  75. }
  76. return rst;
  77. }
  78. public Grp_DelegationVisaView GetDelegationInfo(int diId)
  79. {
  80. ChangeDataBase(DBEnum.OA2014DB);
  81. string sql = string.Format(@" Select * From(Select ROW_NUMBER() Over(order By Id desc) as RowNumber, Id as DiId,
  82. TeamName,ClientUnit,ClientName,TeamLev,VisitDate,VisitDays,VisitPNumber
  83. From DelegationInfo With(Nolock) Where Id = {0}
  84. ) as tb ", diId);
  85. Grp_DelegationVisaView rst = _sqlSugar.SqlQueryable<Grp_DelegationVisaView>(sql).First();
  86. string sql2 = string.Format(@" Select * From Grp_VisaProgressCustomer With(Nolock) Where DiId={0} And IsDel=0 ", diId);
  87. List<Grp_VisaProgressCustomer> listComplete = _sqlSugar.SqlQueryable<Grp_VisaProgressCustomer>(sql2).ToList();
  88. rst.CompletePNumber = string.Format(@"已完成{0}人", listComplete.Count);
  89. return rst;
  90. }
  91. public List<DelegationVisaProgressView> GetDelegationProgressList(int diid)
  92. {
  93. ChangeDataBase(DBEnum.OA2014DB);
  94. string sqlDeleClient = string.Format(@" Select
  95. Id as 'PersonViewId',
  96. Diid,
  97. LastName,
  98. [Name] as 'FirstName'
  99. From DeleClient With(Nolock) Where Diid = {0} And IsDel = 0 ", diid);
  100. List<DelegationVisaProgressView> clientList = _sqlSugar.SqlQueryable<DelegationVisaProgressView>(sqlDeleClient).ToList();
  101. string sqlDelegation = string.Format(@" Select * From DelegationInfo With(Nolock) Where Id = {0} ", diid);
  102. OA2021_DelegationInfo delegationInfo = _sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sqlDelegation).First();
  103. //string countryName = delegationInfo.VisitCountry;
  104. #region 检查与配置
  105. ChangeDataBase(DBEnum.OA2023DB);
  106. string sqlCheck = string.Format(@" Select * From Grp_VisaProgressCustomer With(Nolock) Where DiId = {0} ", diid);
  107. List<Grp_VisaProgressCustomer> listVisaPro = _sqlSugar.SqlQueryable<Grp_VisaProgressCustomer>(sqlCheck).ToList();
  108. if (listVisaPro.Count < 1)
  109. {
  110. //listVisaPro = new List<Grp_VisaProgressCustomer>(initVisitCountry(diid, delegationInfo));
  111. initVisitCountry(diid, delegationInfo);
  112. }
  113. #endregion
  114. string sqlView1 = string.Format(@" Select
  115. Id as 'ProgressViewId',
  116. DiId,
  117. CustomerId,
  118. LastName,
  119. FirstName,
  120. Country,
  121. WorkStatus as 'StatusSign'
  122. From Grp_VisaProgressCustomer With(Nolock) Where DiId = {0} And IsDel = 0 ", diid);
  123. List<DelegationVisaProgressView> result = _sqlSugar.SqlQueryable<DelegationVisaProgressView>(sqlView1).ToList();
  124. //查询各子项行数
  125. foreach (var pro in result)
  126. {
  127. string sqlCheckCount = string.Format(@" Select PicType,Count(PicType) PicTypeCount
  128. From Grp_VisaProgressCustomerPicture Where VisaProgressCustomerId = {0}
  129. Group by PicType Order By PicType ", pro.ProgressViewId);
  130. List<dynamic> tempList = _sqlSugar.SqlQueryable<dynamic>(sqlCheckCount).ToList();
  131. DelegationVisaPicCountList countList = new DelegationVisaPicCountList();
  132. foreach (var item in tempList)
  133. {
  134. int tempCount = item.PicTypeCount;
  135. switch (item.PicType)
  136. {
  137. case 0: countList.FirstPageCount = tempCount; break;
  138. case 1: countList.DocumentsCount = tempCount; break;
  139. case 2: countList.ExemptionCount = tempCount; break;
  140. case 3: countList.DispatchCount = tempCount; break;
  141. case 4: countList.VisaCount = tempCount; break;
  142. case 5: countList.InvoiceCount = tempCount; break;
  143. default: break;
  144. }
  145. }
  146. countList.totalCount();
  147. pro.PicCountList = countList;
  148. }
  149. return result;
  150. }
  151. public void initVisitCountry(int diid, OA2021_DelegationInfo delegationInfo)
  152. {
  153. ChangeDataBase(DBEnum.OA2014DB);
  154. string sqlDeleClient = String.Format(@" Select * From DeleClient With(Nolock) Where diid = {0} ", diid);
  155. List<OA2021_DeleClient1> listDeleClient = _sqlSugar.SqlQueryable<OA2021_DeleClient1>(sqlDeleClient).ToList();
  156. ChangeDataBase(DBEnum.OA2023DB);
  157. List<Grp_VisaProgressCustomer> listVisaCustomer = new List<Grp_VisaProgressCustomer>();
  158. string countryName = delegationInfo.VisitCountry;
  159. string[] countrys = Regex.Replace(countryName, @"[,,|-、\s丶]", ",", RegexOptions.IgnoreCase).Split(',');
  160. foreach (var client in listDeleClient)
  161. {
  162. foreach (string cname in countrys)
  163. {
  164. Grp_VisaProgressCustomer item = new Grp_VisaProgressCustomer();
  165. item.Country = cname;
  166. item.CreateUserId = -3;
  167. item.CustomerId = 0;
  168. item.DiId = diid;
  169. item.FirstName = client.Name;
  170. item.LastName = client.LastName;
  171. item.WorkStatus = 0;
  172. listVisaCustomer.Add(item);
  173. }
  174. }
  175. _sqlSugar.Insertable(listVisaCustomer).UseParameter().ExecuteCommand();
  176. //return listVisaCustomer;
  177. }
  178. public List<VisaProgressImageView> GetVisaProgressImageList(int visaProgressCustomerId, int picType)
  179. {
  180. string sql1 = string.Format(@" Select
  181. Id as imageId,
  182. PicPath as 'path',
  183. PicName as picName
  184. From Grp_VisaProgressCustomerPicture
  185. Where VisaProgressCustomerId = {0} And PicType = {1} ", visaProgressCustomerId, picType);
  186. List<VisaProgressImageView> imageList = _sqlSugar.SqlQueryable<VisaProgressImageView>(sql1).ToList();
  187. return imageList;
  188. }
  189. }
  190. }