InvitationOfficialActivityDataRepository.cs 11 KB

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