InvitationOfficialActivityDataRepository.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Dtos.Resource;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.Entities.Resource;
  7. using OASystem.Domain.ViewModels;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using OASystem.Domain.ViewModels.Resource;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Security.Cryptography;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace OASystem.Infrastructure.Repositories.Resource
  17. {
  18. public class InvitationOfficialActivityDataRepository : BaseRepository<Res_InvitationOfficialActivityData, InvitationOfficialActivitiesByIdDto>
  19. {
  20. private readonly IMapper _mapper;
  21. public InvitationOfficialActivityDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  22. {
  23. _mapper = mapper;
  24. }
  25. /// <summary>
  26. /// 查询商邀资料列表
  27. /// </summary>
  28. /// <param name="dto"></param>
  29. /// <returns></returns>
  30. public async Task<Result> QueryInvitationOfficialActivityData(QueryInvitationOfficialActivityDataDto dto)
  31. {
  32. Result result = new Result() { Code = -2, Msg = "未知错误" };
  33. try
  34. {
  35. string sqlWhere = string.Empty;
  36. if (!string.IsNullOrWhiteSpace(dto.Country)) { sqlWhere += string.Format(@" And i.Country like '%{0}%'", dto.Country); }
  37. if (!string.IsNullOrWhiteSpace(dto.UnitName)) { sqlWhere += string.Format(@" And i.UnitName like '%{0}%'", dto.UnitName); }
  38. if (!string.IsNullOrWhiteSpace(dto.Contact)) { sqlWhere += string.Format(@" And i.Contact like '%{0}%'", dto.Contact); }
  39. if (!string.IsNullOrWhiteSpace(dto.Delegation)) { sqlWhere += string.Format(@" And ','+i.Delegation+',' like '%,{0},%'", dto.Delegation); }
  40. if (!string.IsNullOrWhiteSpace(dto.Field)) { sqlWhere += string.Format(@" And i.Field like '%{0}%'", dto.Field); }
  41. if (dto.CreateUserId != 0 && !string.IsNullOrWhiteSpace(dto.CreateUserId.ToString())) { sqlWhere += string.Format(@" And i.CreateUserId={0}", dto.CreateUserId); }
  42. if (!string.IsNullOrWhiteSpace(dto.StartCreateTime) && !string.IsNullOrWhiteSpace(dto.EndCreateTime))
  43. {
  44. sqlWhere += string.Format(@" And i.CreateTime between '{0}' and '{1}'", dto.StartCreateTime, dto.EndCreateTime);
  45. }
  46. sqlWhere += string.Format(@"And Isdel={0}", 0);
  47. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  48. {
  49. Regex r = new Regex("And");
  50. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  51. }
  52. string sql = string.Format(@"select i.*,(select CnName from Sys_Users where Id=i.CreateUserId ) as CreateUserName from
  53. Res_InvitationOfficialActivityData i {0} order by CreateTime desc", sqlWhere);
  54. List<InvitationOfficialActivityDataView> _ivitiesViews = await _sqlSugar.SqlQueryable<InvitationOfficialActivityDataView>(sql).ToListAsync();
  55. if (_ivitiesViews.Count != 0)
  56. {
  57. foreach (var item in _ivitiesViews)
  58. {
  59. string delegationNameList = "";
  60. string[] DelegationName = item.Delegation.Split(',');
  61. for (int i = 0; i < DelegationName.Length; i++)
  62. {
  63. Grp_DelegationInfo _DelegationInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(a => a.Id ==int.Parse(DelegationName[i]));
  64. if (_DelegationInfo != null) { delegationNameList += _DelegationInfo.TeamName + ","; }
  65. }
  66. if (!string.IsNullOrWhiteSpace(delegationNameList))
  67. {
  68. item.DelegationStr = delegationNameList.Substring(0, delegationNameList.Length - 1);
  69. }
  70. }
  71. if (dto.PageSize == 0 && dto.PageIndex == 0)
  72. {
  73. result = new Result() { Code = 0, Msg = "查询成功!", Data = _ivitiesViews };
  74. }
  75. else
  76. {
  77. int count = _ivitiesViews.Count;
  78. float totalPage = (float)count / dto.PageSize;//总页数
  79. if (totalPage == 0) totalPage = 1;
  80. else totalPage = (int)Math.Ceiling((double)totalPage);
  81. List<InvitationOfficialActivityDataView> invitations = new List<InvitationOfficialActivityDataView>();
  82. for (int i = 0; i < dto.PageSize; i++)
  83. {
  84. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  85. if (RowIndex < _ivitiesViews.Count)
  86. {
  87. invitations.Add(_ivitiesViews[RowIndex]);
  88. }
  89. else
  90. {
  91. break;
  92. }
  93. }
  94. ListViewBase<InvitationOfficialActivityDataView> rst = new ListViewBase<InvitationOfficialActivityDataView>();
  95. rst.DataList = invitations;
  96. rst.DataCount = count;
  97. rst.CurrPageIndex = dto.PageIndex;
  98. rst.CurrPageSize = dto.PageSize;
  99. result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  100. }
  101. }
  102. else
  103. {
  104. result = new Result() { Code = 0, Msg = "暂无数据!", Data = _ivitiesViews };
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. result = new Result() { Code = -2, Msg = "未知错误" };
  110. }
  111. return result;
  112. }
  113. /// <summary>
  114. /// 根据Id查询商邀资料信息
  115. /// </summary>
  116. /// <param name="dto"></param>
  117. /// <returns></returns>
  118. /// <exception cref="NotImplementedException"></exception>
  119. public async Task<Result> QueryInvitationOfficialActivityById(QueryInvitationOfficialActivityByIdDto dto)
  120. {
  121. Result result = new Result() { Code = -2, Msg = "未知错误" };
  122. try
  123. {
  124. Res_InvitationOfficialActivityData res_Invitation = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>().FirstAsync(a => a.Id == dto.Id && a.IsDel == 0);
  125. if (res_Invitation!=null) {
  126. result = new Result() { Code = 0, Msg = "查询成功!", Data = res_Invitation };
  127. }
  128. else
  129. {
  130. result = new Result() { Code = 0, Msg = "暂无数据!", Data = res_Invitation };
  131. }
  132. }
  133. catch (Exception ex)
  134. {
  135. result = new Result() { Code = -2, Msg = "未知错误" };
  136. }
  137. return result;
  138. }
  139. public async Task<Result> OpInvitationOfficialActivity(OpInvitationOfficialActivityDto dto)
  140. {
  141. Result result = new Result() { Code = -2, Msg = "未知错误" };
  142. try
  143. {
  144. if (dto.Status == 1)//添加
  145. {
  146. string selectSql = string.Format(@"select * from Res_InvitationOfficialActivityData where UnitName='{0}' and IsDel='{1}'", dto.UnitName, 0);
  147. var res_InvitationOfficial = await _sqlSugar.SqlQueryable<Res_InvitationOfficialActivityData>(selectSql).FirstAsync();//查询是否存在
  148. if (res_InvitationOfficial != null)
  149. {
  150. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  151. }
  152. else//不存在,可添加
  153. {
  154. Res_InvitationOfficialActivityData _InvitationOfficialActivityData = _mapper.Map<Res_InvitationOfficialActivityData>(dto);
  155. int id = await _sqlSugar.Insertable(_InvitationOfficialActivityData).ExecuteReturnIdentityAsync();
  156. if (id == 0)
  157. {
  158. return result = new Result() { Code = -1, Msg = "添加失败!" };
  159. }
  160. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  161. }
  162. }
  163. else if (dto.Status == 2)//修改
  164. {
  165. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_InvitationOfficialActivityData
  166. {
  167. Country = dto.Country,
  168. City = dto.City,
  169. UnitName = dto.UnitName,
  170. UnitWeb = dto.UnitWeb,
  171. Field = dto.Field,
  172. Address = dto.Address,
  173. UnitInfo = dto.UnitInfo,
  174. Contact = dto.Contact,
  175. Job = dto.Job,
  176. Tel = dto.Tel,
  177. Email = dto.Email,
  178. WeChat = dto.WeChat,
  179. FaceBook = dto.FaceBook,
  180. Ins = dto.Ins,
  181. Delegation = dto.Delegation,
  182. FilePath = dto.FilePath,
  183. SndFilePath = dto.SndFilePath,
  184. Fax = dto.Fax,
  185. CreateUserId = dto.CreateUserId,
  186. Remark = dto.Remark
  187. });
  188. if (!res)
  189. {
  190. return result = new Result() { Code = -1, Msg = "修改失败!" };
  191. }
  192. return result = new Result() { Code = 0, Msg = "修改成功!" };
  193. }
  194. else
  195. {
  196. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  197. }
  198. }
  199. catch (Exception ex)
  200. {
  201. return result = new Result() { Code = -2, Msg = "程序错误!" };
  202. }
  203. }
  204. }
  205. }