LocalGuideDataRepository.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.AesEncryption;
  4. using OASystem.Domain.Dtos.Resource;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.Entities.Resource;
  7. using OASystem.Domain.ViewModels.Resource;
  8. using SqlSugar.Extensions;
  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 LocalGuideDataRepository : BaseRepository<Res_LocalGuideData, LocalGuideDataView>
  17. {
  18. private readonly IMapper _mapper;
  19. public LocalGuideDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  20. {
  21. _mapper = mapper;
  22. }
  23. public async Task<Result> LocalGuideOperation(LocalGuideOperationDto dto)
  24. {
  25. var localGuideDat = _mapper.Map<Res_LocalGuideData>(dto);
  26. localGuideDat.LastUpdate = DateTime.Now;
  27. EncryptionProcessor.EncryptProperties(localGuideDat);
  28. if (dto.Status == 1)//添加
  29. {
  30. string selectSql = string.Format(@"select * from Res_LocalGuideData where UnitArea='{0}' and UnitName='{1}' and Contact='{2}' and ContactTel='{3}'",
  31. AesEncryptionHelper.Encrypt(dto.UnitArea),
  32. AesEncryptionHelper.Encrypt(dto.UnitName),
  33. AesEncryptionHelper.Encrypt(dto.Contact),
  34. AesEncryptionHelper.Encrypt(dto.ContactTel));
  35. var LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(selectSql).FirstAsync();//查询是否存在
  36. if (LocalGuideData != null) return new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  37. else//不存在,可添加
  38. {
  39. int id = await AddAsyncReturnId(localGuideDat);
  40. if (id == 0) return new Result() { Code = -1, Msg = "添加失败!" };
  41. return new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  42. }
  43. }
  44. else if (dto.Status == 2)//修改
  45. {
  46. var res = await _sqlSugar.Updateable(localGuideDat).IgnoreColumns(x => new { x.IsDel, x.CreateUserId, x.CreateTime, x.DeleteUserId, x.DeleteTime }).ExecuteCommandAsync();
  47. if (res < 1)
  48. {
  49. return new Result() { Code = -1, Msg = "修改失败!" };
  50. }
  51. return new Result() { Code = 0, Msg = "修改成功!" };
  52. }
  53. return new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  54. }
  55. public async Task<Result> QueryLocalGuide(QueryLocalGuide dto)
  56. {
  57. Result result = new Result() { Code = -2, Msg = "未知错误" };
  58. string sqlWhere = string.Empty;
  59. if (!string.IsNullOrWhiteSpace(dto.UnitName)) sqlWhere += string.Format(@" And UnitName like '%{0}%'", AesEncryptionHelper.Encrypt(dto.UnitName));
  60. if (!string.IsNullOrWhiteSpace(dto.UnitArea) && dto.UnitArea != "全部") sqlWhere += string.Format(@" And UnitArea like '%{0}%'", AesEncryptionHelper.Encrypt(dto.UnitArea));
  61. if (!string.IsNullOrWhiteSpace(dto.Contact)) sqlWhere += string.Format(@" And Contact like '%{0}%'", AesEncryptionHelper.Encrypt(dto.Contact));
  62. if (!string.IsNullOrWhiteSpace(dto.ContactTel)) sqlWhere += string.Format(@" And ContactTel like '%{0}%'", AesEncryptionHelper.Encrypt(dto.ContactTel));
  63. sqlWhere += string.Format(@" And IsDel={0}", 0);
  64. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  65. {
  66. Regex r = new Regex("And");
  67. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  68. }
  69. if (dto.PortType == 1)
  70. {
  71. string sql = string.Format(@"select * from Res_LocalGuideData {0}", sqlWhere);
  72. var localGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  73. if (localGuideData.Count == 0)
  74. {
  75. return result = new Result() { Code = 0, Msg = "暂无数据" };
  76. }
  77. localGuideData = localGuideData.OrderByDescending(x => x.CreateTime).ToList();
  78. if (dto.PageSize == 0 || dto.PageIndex == 0)
  79. {
  80. foreach (var item in localGuideData) EncryptionProcessor.DecryptProperties(item);
  81. return result = new Result()
  82. {
  83. Code = 0,
  84. Msg = "查询成功",
  85. Data = localGuideData,
  86. };
  87. }
  88. else
  89. {
  90. int count = localGuideData.Count;
  91. float totalPage = (float)count / dto.PageSize;//总页数
  92. if (totalPage == 0) totalPage = 1;
  93. else totalPage = (int)Math.Ceiling((double)totalPage);
  94. List<Res_LocalGuideData> ListData = new List<Res_LocalGuideData>();
  95. for (int i = 0; i < dto.PageSize; i++)
  96. {
  97. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  98. if (RowIndex < localGuideData.Count)
  99. {
  100. EncryptionProcessor.DecryptProperties(localGuideData[RowIndex]);
  101. ListData.Add(localGuideData[RowIndex]);
  102. }
  103. else break;
  104. }
  105. return result = new Result()
  106. {
  107. Code = 0,
  108. Msg = "查询成功",
  109. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  110. };
  111. }
  112. }
  113. else if (dto.PortType == 2)
  114. {
  115. string sql = string.Format(@"select * from Res_LocalGuideData {0}", sqlWhere);
  116. var localGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  117. //2024-05-11 修改,取消该判断,避免前端报错
  118. //if (LocalGuideData.Count == 0)
  119. //{
  120. // return result = new Result() { Code = 0, Msg = "暂无数据" };
  121. //}
  122. localGuideData = localGuideData.OrderByDescending(x => x.CreateTime).ToList();
  123. if (dto.PageSize == 0 && dto.PageIndex == 0)
  124. {
  125. foreach (var item in localGuideData) EncryptionProcessor.DecryptProperties(item);
  126. return result = new Result()
  127. {
  128. Code = 0,
  129. Msg = "查询成功",
  130. Data = localGuideData,
  131. };
  132. }
  133. else
  134. {
  135. int count = localGuideData.Count;
  136. float totalPage = (float)count / dto.PageSize;//总页数
  137. if (totalPage == 0) totalPage = 1;
  138. else totalPage = (int)Math.Ceiling((double)totalPage);
  139. List<Res_LocalGuideData> ListData = new List<Res_LocalGuideData>();
  140. for (int i = 0; i < dto.PageSize; i++)
  141. {
  142. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  143. if (RowIndex < localGuideData.Count)
  144. {
  145. EncryptionProcessor.DecryptProperties(localGuideData[RowIndex]);
  146. ListData.Add(localGuideData[RowIndex]);
  147. }
  148. else
  149. {
  150. break;
  151. }
  152. }
  153. return result = new Result()
  154. {
  155. Code = 0,
  156. Msg = "查询成功",
  157. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  158. };
  159. }
  160. }
  161. else if (dto.PortType == 3)
  162. {
  163. string sql = string.Format(@"select Id,UnitArea,UnitName,Contact,ContactTel,Score,LastUpdate from Res_LocalGuideData {0}", sqlWhere);
  164. var localGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  165. if (localGuideData.Count == 0)
  166. {
  167. return result = new Result() { Code = 0, Msg = "暂无数据" };
  168. }
  169. localGuideData = localGuideData.OrderByDescending(x => x.CreateTime).ToList();
  170. if (dto.PageSize == 0 && dto.PageIndex == 0)
  171. {
  172. foreach (var item in localGuideData) EncryptionProcessor.DecryptProperties(item);
  173. return result = new Result()
  174. {
  175. Code = 0,
  176. Msg = "查询成功",
  177. Data = localGuideData,
  178. };
  179. }
  180. else
  181. {
  182. int count = localGuideData.Count;
  183. float totalPage = (float)count / dto.PageSize;//总页数
  184. if (totalPage == 0) totalPage = 1;
  185. else totalPage = (int)Math.Ceiling((double)totalPage);
  186. var ListData = new List<Res_LocalGuideData_ListItemView>();
  187. for (int i = 0; i < dto.PageSize; i++)
  188. {
  189. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  190. if (RowIndex < localGuideData.Count)
  191. {
  192. var temp = new Res_LocalGuideData_ListItemView()
  193. {
  194. Contact = localGuideData[RowIndex].Contact,
  195. ContactTel = localGuideData[RowIndex].ContactTel,
  196. Id = localGuideData[RowIndex].Id,
  197. Score = localGuideData[RowIndex].Score,
  198. UnitArea = localGuideData[RowIndex].UnitArea,
  199. UnitName = localGuideData[RowIndex].UnitName
  200. };
  201. temp.LastUpdateStr = localGuideData[RowIndex].CreateTime.ToString("yyyy-MM-dd");
  202. EncryptionProcessor.DecryptProperties(temp);
  203. ListData.Add(temp);
  204. }
  205. else break;
  206. }
  207. return result = new Result()
  208. {
  209. Code = 0,
  210. Msg = "查询成功",
  211. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  212. };
  213. }
  214. }
  215. return result = new Result() { Code = -2, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS" };
  216. }
  217. }
  218. }