LocalGuideDataRepository.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Resource;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Resource;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OASystem.Infrastructure.Repositories.Resource
  13. {
  14. public class LocalGuideDataRepository : BaseRepository<Res_LocalGuideData, LocalGuideDataView>
  15. {
  16. private readonly IMapper _mapper;
  17. public LocalGuideDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  18. {
  19. _mapper=mapper;
  20. }
  21. public async Task<Result> LocalGuideOperation(LocalGuideOperationDto dto)
  22. {
  23. Result result = new Result() { Code = -2, Msg = "未知错误" };
  24. try
  25. {
  26. if (dto.Status == 1)//添加
  27. {
  28. string selectSql = string.Format(@"select * from Res_LocalGuideData where UnitArea='{0}' and UnitName='{1}' and Contact='{2}' and ContactTel='{3}'"
  29. , dto.UnitArea, dto.UnitName, dto.Contact, dto.ContactTel);
  30. var LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(selectSql).FirstAsync();//查询是否存在
  31. if (LocalGuideData != null)
  32. {
  33. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  34. }
  35. else//不存在,可添加
  36. {
  37. Res_LocalGuideData _LocalGuideDat = _mapper.Map<Res_LocalGuideData>(dto);
  38. int id = await AddAsyncReturnId(_LocalGuideDat);
  39. if (id == 0)
  40. {
  41. return result = new Result() { Code = -1, Msg = "添加失败!" };
  42. }
  43. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  44. }
  45. }
  46. else if(dto.Status == 2)//修改
  47. {
  48. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_LocalGuideData
  49. {
  50. UnitArea = dto.UnitArea,
  51. UnitName = dto.UnitName,
  52. Address = dto.Address,
  53. Contact = dto.Contact,
  54. ContactTel = dto.ContactTel,
  55. ContactEmail = dto.ContactEmail,
  56. ContactFax = dto.ContactFax,
  57. OtherInfo = dto.OtherInfo,
  58. Score = dto.Score,
  59. SuitScore = dto.SuitScore,
  60. ServeScore = dto.ServeScore,
  61. TalkProScore = dto.TalkProScore,
  62. TimeScore = dto.TimeScore,
  63. FitScore = dto.FitScore,
  64. StrainScore = dto.StrainScore,
  65. LocalAndChineseScore = dto.LocalAndChineseScore,
  66. StaffType=dto.StaffType,
  67. Remark = dto.Remark,
  68. });
  69. if (!res)
  70. {
  71. return result = new Result() { Code = -1, Msg = "修改失败!" };
  72. }
  73. result = new Result() { Code = 0, Msg = "修改成功!" };
  74. }
  75. else
  76. {
  77. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. return result = new Result() { Code = -2, Msg = "程序错误!" };
  83. }
  84. return result;
  85. }
  86. public async Task<Result> QueryLocalGuide(QueryLocalGuide dto)
  87. {
  88. Result result = new Result() { Code = -2, Msg = "未知错误" };
  89. try
  90. {
  91. string sqlWhere = string.Empty;
  92. if (!string.IsNullOrWhiteSpace(dto.UnitName))
  93. {
  94. sqlWhere += string.Format(@" And UnitName like '%{0}%'", dto.UnitName);
  95. }
  96. if (!string.IsNullOrWhiteSpace(dto.UnitArea) && dto.UnitArea != "全部")
  97. {
  98. sqlWhere += string.Format(@" And UnitArea like '%{0}%'", dto.UnitArea);
  99. }
  100. if (!string.IsNullOrWhiteSpace(dto.Contact))
  101. {
  102. sqlWhere += string.Format(@" And Contact like '%{0}%'", dto.Contact);
  103. }
  104. if (!string.IsNullOrWhiteSpace(dto.ContactTel))
  105. {
  106. sqlWhere += string.Format(@" And ContactTel like '%{0}%'", dto.ContactTel);
  107. }
  108. sqlWhere += string.Format(@" And IsDel={0}", 0);
  109. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  110. {
  111. Regex r = new Regex("And");
  112. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  113. }
  114. if (dto.PortType == 1)
  115. {
  116. string sql = string.Format(@"select * from Res_LocalGuideData {0}", sqlWhere);
  117. List<Res_LocalGuideData> LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  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. return result = new Result()
  126. {
  127. Code = 0,
  128. Msg = "查询成功",
  129. Data = LocalGuideData,
  130. };
  131. }
  132. else
  133. {
  134. int count = LocalGuideData.Count;
  135. float totalPage = (float)count / dto.PageSize;//总页数
  136. if (totalPage == 0) totalPage = 1;
  137. else totalPage = (int)Math.Ceiling((double)totalPage);
  138. List<Res_LocalGuideData> ListData = new List<Res_LocalGuideData>();
  139. for (int i = 0; i < dto.PageSize; i++)
  140. {
  141. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  142. if (RowIndex < LocalGuideData.Count)
  143. {
  144. ListData.Add(LocalGuideData[RowIndex]);
  145. }
  146. else
  147. {
  148. break;
  149. }
  150. }
  151. return result = new Result()
  152. {
  153. Code = 0,
  154. Msg = "查询成功",
  155. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  156. };
  157. }
  158. }
  159. else if (dto.PortType == 2)
  160. {
  161. string sql = string.Format(@"select * from Res_LocalGuideData {0}", sqlWhere);
  162. List<Res_LocalGuideData> LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  163. if (LocalGuideData.Count == 0)
  164. {
  165. return result = new Result() { Code = 0, Msg = "暂无数据" };
  166. }
  167. LocalGuideData = LocalGuideData.OrderByDescending(x => x.CreateTime).ToList();
  168. if (dto.PageSize == 0 && dto.PageIndex == 0)
  169. {
  170. return result = new Result()
  171. {
  172. Code = 0,
  173. Msg = "查询成功",
  174. Data = LocalGuideData,
  175. };
  176. }
  177. else
  178. {
  179. int count = LocalGuideData.Count;
  180. float totalPage = (float)count / dto.PageSize;//总页数
  181. if (totalPage == 0) totalPage = 1;
  182. else totalPage = (int)Math.Ceiling((double)totalPage);
  183. List<Res_LocalGuideData> ListData = new List<Res_LocalGuideData>();
  184. for (int i = 0; i < dto.PageSize; i++)
  185. {
  186. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  187. if (RowIndex < LocalGuideData.Count)
  188. {
  189. ListData.Add(LocalGuideData[RowIndex]);
  190. }
  191. else
  192. {
  193. break;
  194. }
  195. }
  196. return result = new Result()
  197. {
  198. Code = 0,
  199. Msg = "查询成功",
  200. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  201. };
  202. }
  203. }
  204. else
  205. {
  206. return result = new Result() { Code = -2, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS" };
  207. }
  208. }
  209. catch (Exception)
  210. {
  211. return result;
  212. throw;
  213. }
  214. }
  215. }
  216. }