OfficialActivitiesRepository.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using AutoMapper;
  2. using MathNet.Numerics.Distributions;
  3. using MathNet.Numerics.Statistics.Mcmc;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos.Resource;
  6. using OASystem.Domain.Entities.Groups;
  7. using OASystem.Domain.Entities.Resource;
  8. using OASystem.Domain.ViewModels.Resource;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace OASystem.Infrastructure.Repositories.Resource
  15. {
  16. public class OfficialActivitiesRepository : BaseRepository<Res_OfficialActivities, OfficialActivitiesView>
  17. {
  18. private readonly IMapper _mapper;
  19. public OfficialActivitiesRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  20. {
  21. _mapper = mapper;
  22. }
  23. /// <summary>
  24. /// 根据Diid查询公务出访数据List
  25. /// </summary>
  26. /// <param name="dto"></param>
  27. /// <returns></returns>
  28. public async Task<Result> QueryOfficialActivitiesByDiId(OfficialActivitiesByDiIdDto dto)
  29. {
  30. Result result = new Result() { Code = -2, Msg = "未知错误" };
  31. try
  32. {
  33. string sqlWhere = string.Empty;
  34. sqlWhere += string.Format(@"And o.Isdel={0} And o.DiId={1} ", 0, dto.DiId);
  35. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  36. {
  37. Regex r = new Regex("And");
  38. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  39. }
  40. string sql = string.Format(@"select *,(select CnName from Sys_Users where o.CreateUserId=Id) as CreateUserName,(select Name from Sys_SetData
  41. where Id=o.OfficialForm) as OfficialFormName from Res_OfficialActivities o {0} order by o.CreateTime desc", sqlWhere);
  42. List<OfficialActivitiesView> OfficialActivities = await _sqlSugar.SqlQueryable<OfficialActivitiesView>(sql).ToListAsync();
  43. List<Sys_SetData> data = await _sqlSugar.Queryable<Sys_SetData>().Where(a => a.IsDel == 0 && a.STid == 38).ToListAsync();
  44. if (OfficialActivities.Count != 0)
  45. {
  46. if (dto.PageSize == 0 && dto.PageIndex == 0)
  47. {
  48. result = new Result() { Code = 0, Msg = "查询成功!", Data = OfficialActivities };
  49. }
  50. else
  51. {
  52. int count = OfficialActivities.Count;
  53. float totalPage = (float)count / dto.PageSize;//总页数
  54. if (totalPage == 0) totalPage = 1;
  55. else totalPage = (int)Math.Ceiling((double)totalPage);
  56. List<OfficialActivitiesView> _OfficialActivities = new List<OfficialActivitiesView>();
  57. for (int i = 0; i < dto.PageSize; i++)
  58. {
  59. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  60. if (RowIndex < OfficialActivities.Count)
  61. {
  62. //2024年4月1日 11:55:44 -蒋金辰 -日期处理
  63. DateTime dt;
  64. bool b_dt = DateTime.TryParse(OfficialActivities[RowIndex].Date, out dt);
  65. if (b_dt)
  66. {
  67. OfficialActivities[RowIndex].Date = dt.ToString("yyyy-MM-dd HH:mm");
  68. }
  69. _OfficialActivities.Add(OfficialActivities[RowIndex]);
  70. }
  71. else
  72. {
  73. break;
  74. }
  75. }
  76. ListViewBase<OfficialActivitiesView> rst = new ListViewBase<OfficialActivitiesView>();
  77. rst.DataList = _OfficialActivities;
  78. rst.DataCount = count;
  79. rst.CurrPageIndex = dto.PageIndex;
  80. rst.CurrPageSize = dto.PageSize;
  81. result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  82. }
  83. }
  84. else
  85. {
  86. result = new Result() { Code = 0, Msg = "暂无数据!", Data = OfficialActivities };
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. result = new Result() { Code = -2, Msg = "未知错误" };
  92. }
  93. return result;
  94. }
  95. /// <summary>
  96. /// 根据公务出访Id查询单个数据
  97. /// </summary>
  98. /// <param name="dto"></param>
  99. /// <returns></returns>
  100. /// <exception cref="NotImplementedException"></exception>
  101. public async Task<Result> QueryOfficialActivitiesById(OfficialActivitiesDiIdDto dto)
  102. {
  103. Result result = new Result() { Code = -2, Msg = "未知错误" };
  104. try
  105. {
  106. string sqlWhere = string.Empty;
  107. sqlWhere += string.Format(@"And o.Isdel={0} And o.DiId={1} And o.Id={2}", 0, dto.DiId, dto.Id);
  108. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  109. {
  110. Regex r = new Regex("And");
  111. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  112. }
  113. string sql = string.Format(@"select *,(select CnName from Sys_Users where o.CreateUserId=Id) as CreateUserName,(select Name from Sys_SetData
  114. where Id=o.OfficialForm) as OfficialFormName from Res_OfficialActivities o {0}", sqlWhere);
  115. OfficialActivitiesView OfficialActivities = await _sqlSugar.SqlQueryable<OfficialActivitiesView>(sql).FirstAsync();
  116. result = new Result() { Code = 0, Msg = "查询成功!", Data = OfficialActivities };
  117. }
  118. catch (Exception ex)
  119. {
  120. result = new Result() { Code = -2, Msg = "未知错误" };
  121. }
  122. return result;
  123. }
  124. public async Task<Result> OpOfficialActivities(OpOfficialActivitiesDto dto)
  125. {
  126. Result result = new Result() { Code = -2, Msg = "未知错误" };
  127. try
  128. {
  129. if (dto.Status == 1)//添加
  130. {
  131. string selectSql = string.Format(@"select * from Res_OfficialActivities where Client='{0}' and Address='{1}' and IsDel='{2}'", dto.Client, dto.Address, 0);
  132. var res_InvitationOfficial = await _sqlSugar.SqlQueryable<Res_OfficialActivities>(selectSql).FirstAsync();//查询是否存在
  133. if (res_InvitationOfficial != null)
  134. {
  135. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  136. }
  137. else//不存在,可添加
  138. {
  139. Res_OfficialActivities _InvitationOfficialActivityData = _mapper.Map<Res_OfficialActivities>(dto);
  140. int id = await _sqlSugar.Insertable(_InvitationOfficialActivityData).ExecuteReturnIdentityAsync();
  141. if (id == 0)
  142. {
  143. return result = new Result() { Code = -1, Msg = "添加失败!" };
  144. }
  145. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  146. }
  147. }
  148. else if (dto.Status == 2)//修改
  149. {
  150. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_OfficialActivities
  151. {
  152. Type = dto.Type,
  153. Client = dto.Client,
  154. Date = dto.Date,
  155. Time = dto.Time,
  156. Address = dto.Address,
  157. Contact = dto.Contact,
  158. Job = dto.Job,
  159. Tel = dto.Tel,
  160. OfficialForm = dto.OfficialForm,
  161. Setting = dto.Setting,
  162. Dresscode = dto.Dresscode,
  163. Attendees = dto.Attendees,
  164. IsNeedTrans = dto.IsNeedTrans,
  165. Translators = dto.Translators,
  166. language = dto.language,
  167. Trip = dto.Trip,
  168. CreateUserId = dto.CreateUserId,
  169. Remark = dto.Remark,
  170. });
  171. if (!res)
  172. {
  173. return result = new Result() { Code = -1, Msg = "修改失败!" };
  174. }
  175. return result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } };
  176. }
  177. else
  178. {
  179. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. return result = new Result() { Code = -2, Msg = "程序错误!" };
  185. }
  186. }
  187. }
  188. }