GrpScheduleRepository.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using OASystem.Domain.Dtos.Groups;
  2. using OASystem.Domain.Entities.Groups;
  3. using OASystem.Domain.ViewModels.Groups;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace OASystem.Infrastructure.Repositories.Groups
  10. {
  11. public class GrpScheduleRepository : BaseRepository<Grp_ScheduleInfo, Grp_ScheduleInfo>
  12. {
  13. public GrpScheduleRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  14. {
  15. }
  16. public string SetSql_GrpScheduleDto(Grp_ScheduleDto _dto)
  17. {
  18. string sqlWhere = string.Empty;
  19. if (_dto.SysUserId > 0)
  20. {
  21. sqlWhere += string.Format(@" And s.Id in ( Select Id From Grp_SchedulePerson With(Nolock) Where SysUserId = '{0}' ) ", _dto.SysUserId);
  22. }
  23. if (_dto.DiId > 0)
  24. {
  25. sqlWhere = string.Format(@" And s.DiId = '{0}' ", _dto.DiId);
  26. }
  27. //请放在最后
  28. if (_dto.ScheduleId > 0)
  29. {
  30. sqlWhere = string.Format(@" And s.Id = '{0}' ", _dto.ScheduleId);
  31. }
  32. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  33. {
  34. Regex r = new Regex("And");
  35. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  36. }
  37. string sql = string.Format(@" Select s.Id,s.DiId,di.TeamName as DeleName,s.PrimaryStep,s.ExpectBeginDt,s.ExpectEndDt,s.Leader,s.Exception,u.CnName as LeaderName
  38. From Grp_Schedule as s With(Nolock) Inner Join Grp_DelegationInfo as di With(Nolock) On s.DiId=di.Id
  39. Inner Join Sys_Users as u With(Nolock) On s.Leader=u.Id
  40. {0} ", sqlWhere);
  41. return sql;
  42. }
  43. #region 获取添加后的新数据
  44. public async Task<Grp_ScheduleDetailView> GetInsertBackData(int detailId)
  45. {
  46. Grp_ScheduleDetailInfo item = await _sqlSugar.Queryable<Grp_ScheduleDetailInfo>().FirstAsync(s => s.Id == detailId);
  47. if (item != null)
  48. {
  49. Grp_ScheduleDetailView temp = new Grp_ScheduleDetailView();
  50. temp.Duty = item.Duty;
  51. temp.Exception = item.Exception;
  52. temp.ExpectBeginDt = item.ExpectBeginDt;
  53. temp.ExpectEndDt = item.ExpectEndDt;
  54. temp.DetailId = item.Id;
  55. temp.JobContent = item.JobContent;
  56. temp.Level = item.SLevel;
  57. temp.RealEndDt = item.RealEndDt;
  58. temp.Remark = item.Remark;
  59. temp.Root = item.ParentStep;
  60. temp.Step = item.Step;
  61. temp.StepStatus = item.StepStatus;
  62. return temp;
  63. }
  64. return null;
  65. }
  66. #endregion
  67. /// <summary>
  68. /// 获取团组流程数据单个对象
  69. /// </summary>
  70. /// <typeparam name="T"></typeparam>
  71. /// <param name="_dto"></param>
  72. /// <returns></returns>
  73. public async Task<Grp_ScheduleCombinView> GetView_GrpSchedule(Grp_ScheduleDto _dto)
  74. {
  75. Grp_ScheduleCombinView _view = new Grp_ScheduleCombinView();
  76. #region 主流程
  77. string sql = this.SetSql_GrpScheduleDto(_dto);
  78. Grp_ScheduleView primary = await _sqlSugar.SqlQueryable<Grp_ScheduleView>(sql).FirstAsync();
  79. #endregion
  80. _view.Primary = primary;
  81. #region 主流程节点
  82. List<Grp_ScheduleRootView> rootList = new List<Grp_ScheduleRootView>()
  83. {
  84. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Wait },
  85. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Confirm},
  86. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Budget},
  87. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Feedback},
  88. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Puote},
  89. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Visa},
  90. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Business},
  91. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.CostAudit},
  92. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Pay},
  93. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Training},
  94. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.DropOff},
  95. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.PickUp},
  96. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Collect},
  97. new Grp_ScheduleRootView() { Root = (int)GrpSchedulePrimaryStepEnum.Finish}
  98. };
  99. #endregion
  100. #region 子节点
  101. //子节点
  102. List<Grp_ScheduleDetailInfo> detailEntityList = _sqlSugar.Queryable<Grp_ScheduleDetailInfo>().Where(s => s.IsDel != 1 && s.ScheduleId == _dto.ScheduleId).ToList();
  103. List<Grp_ScheduleDetailView> childList = new List<Grp_ScheduleDetailView>();
  104. //区分2级节点 3级节点
  105. List<Grp_ScheduleDetailInfo> LV2List = detailEntityList.Where(s => s.SLevel == 2).ToList();
  106. List<Grp_ScheduleDetailInfo> LV3List = detailEntityList.Where(s => s.SLevel == 3).ToList();
  107. foreach (var item in LV2List)
  108. {
  109. Grp_ScheduleDetailView temp = new Grp_ScheduleDetailView();
  110. temp.Duty = item.Duty;
  111. temp.Exception = item.Exception;
  112. temp.ExpectBeginDt = item.ExpectBeginDt;
  113. temp.ExpectEndDt = item.ExpectEndDt;
  114. temp.DetailId = item.Id;
  115. temp.JobContent = item.JobContent;
  116. temp.Level = item.SLevel;
  117. temp.RealEndDt = item.RealEndDt;
  118. temp.Remark = item.Remark;
  119. temp.Root = item.ParentStep;
  120. temp.Step = item.Step;
  121. temp.StepStatus = item.StepStatus;
  122. List<Grp_ScheduleDetailInfo> tempLv3List = LV3List.Where(s => s.ParentStep == item.Step).ToList();
  123. List<Grp_ScheduleDetailView> tempChildList = new List<Grp_ScheduleDetailView>();
  124. if (tempLv3List.Count > 0)
  125. {
  126. foreach (var item2 in tempLv3List)
  127. {
  128. Grp_ScheduleDetailView temp2 = new Grp_ScheduleDetailView();
  129. temp2.Duty = item2.Duty;
  130. temp2.Exception = item2.Exception;
  131. temp2.ExpectBeginDt = item2.ExpectBeginDt;
  132. temp2.ExpectEndDt = item2.ExpectEndDt;
  133. temp2.DetailId = item2.Id;
  134. temp2.JobContent = item2.JobContent;
  135. temp2.Level = item2.SLevel;
  136. temp2.RealEndDt = item2.RealEndDt;
  137. temp2.Remark = item2.Remark;
  138. temp2.Root = item2.ParentStep;
  139. temp2.Step = item2.Step;
  140. temp2.StepStatus = item2.StepStatus;
  141. tempChildList.Add(temp2);
  142. }
  143. }
  144. temp.ChildList = new List<Grp_ScheduleDetailView>(tempChildList);
  145. childList.Add(temp);
  146. }
  147. #endregion
  148. foreach (var item in rootList)
  149. {
  150. item.ChildList = new List<Grp_ScheduleDetailView>(childList.Where(s => s.Root == item.Root).ToList());
  151. }
  152. _view.RootList = new List<Grp_ScheduleRootView>(rootList);
  153. #region 流程人员
  154. List<Grp_SchedulePersonInfo> personEntityList = _sqlSugar.Queryable<Grp_SchedulePersonInfo>().Where(s => s.IsDel != 1 && s.ScheduleId == _dto.ScheduleId).ToList();
  155. List<Grp_SchedulePersonView> personList = new List<Grp_SchedulePersonView>();
  156. foreach (var item in personEntityList)
  157. {
  158. Grp_SchedulePersonView temp = new Grp_SchedulePersonView();
  159. temp.JobStr = item.JobStr;
  160. temp.PersonId = item.Id;
  161. temp.PersonRemark = item.Remark;
  162. temp.SysUserId = item.SysUserId;
  163. temp.SysUserName = item.SysUserName;
  164. personList.Add(temp);
  165. }
  166. #endregion
  167. _view.PersonList = new List<Grp_SchedulePersonView>(personList);
  168. return _view;
  169. }
  170. /// <summary>
  171. /// 获取团组流程(列表分页)
  172. /// </summary>
  173. /// <param name="_dto"></param>
  174. /// <returns></returns>
  175. public async Task<List<Grp_ScheduleView>> GetViewList_GrpSchedule(Grp_ScheduleDto _dto)
  176. {
  177. List<Grp_ScheduleView> _viewList = new List<Grp_ScheduleView>();
  178. string sqlInner = this.SetSql_GrpScheduleDto(_dto);
  179. string sql = string.Format(@" Select * From(
  180. Select * From ( Select ROW_NUMBER() Over(order By Id desc) as RowNumber,* From ( {2} )
  181. as a ) as tb Where tb.RowNumber Between {0} And {1} ",
  182. (((_dto.PageIndex > 0) ? (_dto.PageIndex - 1) : 0) * _dto.PageSize) + 1,
  183. (((_dto.PageIndex > 0) ? (_dto.PageIndex - 1) : 0) + 1) * _dto.PageSize,
  184. sqlInner);
  185. _viewList = await _sqlSugar.SqlQueryable<Grp_ScheduleView>(sql).ToListAsync();
  186. return _viewList;
  187. }
  188. public void bulkInsert<T>(List<T> list) where T : class, new()
  189. {
  190. _sqlSugar.Insertable(list).UseParameter().ExecuteCommand();
  191. }
  192. public async Task<List<Grp_SchedulePersonInfo>> GetEntityList_SchedulePersonBySql(string sql)
  193. {
  194. List<Grp_SchedulePersonInfo> _list = new List<Grp_SchedulePersonInfo>();
  195. _list = await _sqlSugar.SqlQueryable<Grp_SchedulePersonInfo>(sql).ToListAsync();
  196. return _list;
  197. }
  198. }
  199. }