InvitationOfficialActivityDataRepository.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. item.DelegationStr = delegationNameList.Substring(0,delegationNameList.Length-1);
  67. }
  68. if (dto.PageSize == 0 && dto.PageIndex == 0)
  69. {
  70. result = new Result() { Code = 0, Msg = "查询成功!", Data = _ivitiesViews };
  71. }
  72. else
  73. {
  74. int count = _ivitiesViews.Count;
  75. float totalPage = (float)count / dto.PageSize;//总页数
  76. if (totalPage == 0) totalPage = 1;
  77. else totalPage = (int)Math.Ceiling((double)totalPage);
  78. List<InvitationOfficialActivityDataView> invitations = new List<InvitationOfficialActivityDataView>();
  79. for (int i = 0; i < dto.PageSize; i++)
  80. {
  81. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  82. if (RowIndex < _ivitiesViews.Count)
  83. {
  84. invitations.Add(_ivitiesViews[RowIndex]);
  85. }
  86. else
  87. {
  88. break;
  89. }
  90. }
  91. ListViewBase<InvitationOfficialActivityDataView> rst = new ListViewBase<InvitationOfficialActivityDataView>();
  92. rst.DataList = invitations;
  93. rst.DataCount = count;
  94. rst.CurrPageIndex = dto.PageIndex;
  95. rst.CurrPageSize = dto.PageSize;
  96. result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  97. }
  98. }
  99. else
  100. {
  101. result = new Result() { Code = 0, Msg = "暂无数据!", Data = _ivitiesViews };
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. result = new Result() { Code = -2, Msg = "未知错误" };
  107. }
  108. return result;
  109. }
  110. /// <summary>
  111. /// 根据Id查询商邀资料信息
  112. /// </summary>
  113. /// <param name="dto"></param>
  114. /// <returns></returns>
  115. /// <exception cref="NotImplementedException"></exception>
  116. public async Task<Result> QueryInvitationOfficialActivityById(QueryInvitationOfficialActivityByIdDto dto)
  117. {
  118. Result result = new Result() { Code = -2, Msg = "未知错误" };
  119. try
  120. {
  121. Res_InvitationOfficialActivityData res_Invitation = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>().FirstAsync(a => a.Id == dto.Id && a.IsDel == 0);
  122. if (res_Invitation!=null) {
  123. result = new Result() { Code = 0, Msg = "查询成功!", Data = res_Invitation };
  124. }
  125. else
  126. {
  127. result = new Result() { Code = 0, Msg = "暂无数据!", Data = res_Invitation };
  128. }
  129. }
  130. catch (Exception ex)
  131. {
  132. result = new Result() { Code = -2, Msg = "未知错误" };
  133. }
  134. return result;
  135. }
  136. public async Task<Result> OpInvitationOfficialActivity(OpInvitationOfficialActivityDto dto)
  137. {
  138. Result result = new Result() { Code = -2, Msg = "未知错误" };
  139. try
  140. {
  141. if (dto.Status == 1)//添加
  142. {
  143. string selectSql = string.Format(@"select * from Res_InvitationOfficialActivityData where UnitName='{0}' and IsDel='{1}'", dto.UnitName, 0);
  144. var res_InvitationOfficial = await _sqlSugar.SqlQueryable<Res_InvitationOfficialActivityData>(selectSql).FirstAsync();//查询是否存在
  145. if (res_InvitationOfficial != null)
  146. {
  147. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  148. }
  149. else//不存在,可添加
  150. {
  151. Res_InvitationOfficialActivityData _InvitationOfficialActivityData = _mapper.Map<Res_InvitationOfficialActivityData>(dto);
  152. int id = await _sqlSugar.Insertable(_InvitationOfficialActivityData).ExecuteReturnIdentityAsync();
  153. if (id == 0)
  154. {
  155. return result = new Result() { Code = -1, Msg = "添加失败!" };
  156. }
  157. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  158. }
  159. }
  160. else if (dto.Status == 2)//修改
  161. {
  162. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_InvitationOfficialActivityData
  163. {
  164. Country = dto.Country,
  165. City = dto.City,
  166. UnitName = dto.UnitName,
  167. UnitWeb = dto.UnitWeb,
  168. Field = dto.Field,
  169. Address = dto.Address,
  170. UnitInfo = dto.UnitInfo,
  171. Contact = dto.Contact,
  172. Job = dto.Job,
  173. Tel = dto.Tel,
  174. Email = dto.Email,
  175. WeChat = dto.WeChat,
  176. FaceBook = dto.FaceBook,
  177. Ins = dto.Ins,
  178. Delegation = dto.Delegation,
  179. FilePath = dto.FilePath,
  180. SndFilePath = dto.SndFilePath,
  181. Fax = dto.Fax,
  182. CreateUserId = dto.CreateUserId,
  183. Remark = dto.Remark
  184. });
  185. if (!res)
  186. {
  187. return result = new Result() { Code = -1, Msg = "修改失败!" };
  188. }
  189. return result = new Result() { Code = 0, Msg = "修改成功!" };
  190. }
  191. else
  192. {
  193. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  194. }
  195. }
  196. catch (Exception ex)
  197. {
  198. return result = new Result() { Code = -2, Msg = "程序错误!" };
  199. }
  200. }
  201. }
  202. }