LocalGuideDataRepository.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 SqlSugar.Extensions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace OASystem.Infrastructure.Repositories.Resource
  14. {
  15. public class LocalGuideDataRepository : BaseRepository<Res_LocalGuideData, LocalGuideDataView>
  16. {
  17. private readonly IMapper _mapper;
  18. public LocalGuideDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  19. {
  20. _mapper = mapper;
  21. }
  22. public async Task<Result> LocalGuideOperation(LocalGuideOperationDto dto)
  23. {
  24. Result result = new Result() { Code = -2, Msg = "未知错误" };
  25. try
  26. {
  27. if (dto.Status == 1)//添加
  28. {
  29. string selectSql = string.Format(@"select * from Res_LocalGuideData where UnitArea='{0}' and UnitName='{1}' and Contact='{2}' and ContactTel='{3}'"
  30. , dto.UnitArea, dto.UnitName, dto.Contact, dto.ContactTel);
  31. var LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(selectSql).FirstAsync();//查询是否存在
  32. if (LocalGuideData != null)
  33. {
  34. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  35. }
  36. else//不存在,可添加
  37. {
  38. Res_LocalGuideData _LocalGuideDat = _mapper.Map<Res_LocalGuideData>(dto);
  39. _LocalGuideDat.LastUpdate = DateTime.Now;
  40. int id = await AddAsyncReturnId(_LocalGuideDat);
  41. if (id == 0)
  42. {
  43. return result = new Result() { Code = -1, Msg = "添加失败!" };
  44. }
  45. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  46. }
  47. }
  48. else if (dto.Status == 2)//修改
  49. {
  50. DateTime dtLastUpdate = DateTime.Now;
  51. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_LocalGuideData
  52. {
  53. UnitArea = dto.UnitArea,
  54. UnitName = dto.UnitName,
  55. Address = dto.Address,
  56. Contact = dto.Contact,
  57. ContactTel = dto.ContactTel,
  58. ContactEmail = dto.ContactEmail,
  59. ContactFax = dto.ContactFax,
  60. OtherInfo = dto.OtherInfo,
  61. Score = dto.Score,
  62. SuitScore = dto.SuitScore,
  63. ServeScore = dto.ServeScore,
  64. TalkProScore = dto.TalkProScore,
  65. TimeScore = dto.TimeScore,
  66. FitScore = dto.FitScore,
  67. StrainScore = dto.StrainScore,
  68. LocalAndChineseScore = dto.LocalAndChineseScore,
  69. StaffType = dto.StaffType,
  70. Remark = dto.Remark,
  71. LastUpdate = dtLastUpdate
  72. });
  73. if (!res)
  74. {
  75. return result = new Result() { Code = -1, Msg = "修改失败!" };
  76. }
  77. result = new Result() { Code = 0, Msg = "修改成功!" };
  78. }
  79. else
  80. {
  81. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. return result = new Result() { Code = -2, Msg = "程序错误!" };
  87. }
  88. return result;
  89. }
  90. public async Task<Result> QueryLocalGuide(QueryLocalGuide dto)
  91. {
  92. Result result = new Result() { Code = -2, Msg = "未知错误" };
  93. try
  94. {
  95. string sqlWhere = string.Empty;
  96. if (!string.IsNullOrWhiteSpace(dto.UnitName))
  97. {
  98. sqlWhere += string.Format(@" And UnitName like '%{0}%'", dto.UnitName);
  99. }
  100. if (!string.IsNullOrWhiteSpace(dto.UnitArea) && dto.UnitArea != "全部")
  101. {
  102. sqlWhere += string.Format(@" And UnitArea like '%{0}%'", dto.UnitArea);
  103. }
  104. if (!string.IsNullOrWhiteSpace(dto.Contact))
  105. {
  106. sqlWhere += string.Format(@" And Contact like '%{0}%'", dto.Contact);
  107. }
  108. if (!string.IsNullOrWhiteSpace(dto.ContactTel))
  109. {
  110. sqlWhere += string.Format(@" And ContactTel like '%{0}%'", dto.ContactTel);
  111. }
  112. sqlWhere += string.Format(@" And IsDel={0}", 0);
  113. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  114. {
  115. Regex r = new Regex("And");
  116. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  117. }
  118. if (dto.PortType == 1)
  119. {
  120. string sql = string.Format(@"select * from Res_LocalGuideData {0}", sqlWhere);
  121. List<Res_LocalGuideData> LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  122. if (LocalGuideData.Count == 0)
  123. {
  124. return result = new Result() { Code = 0, Msg = "暂无数据" };
  125. }
  126. LocalGuideData = LocalGuideData.OrderByDescending(x => x.CreateTime).ToList();
  127. if (dto.PageSize == 0 || dto.PageIndex == 0)
  128. {
  129. return result = new Result()
  130. {
  131. Code = 0,
  132. Msg = "查询成功",
  133. Data = LocalGuideData,
  134. };
  135. }
  136. else
  137. {
  138. int count = LocalGuideData.Count;
  139. float totalPage = (float)count / dto.PageSize;//总页数
  140. if (totalPage == 0) totalPage = 1;
  141. else totalPage = (int)Math.Ceiling((double)totalPage);
  142. List<Res_LocalGuideData> ListData = new List<Res_LocalGuideData>();
  143. for (int i = 0; i < dto.PageSize; i++)
  144. {
  145. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  146. if (RowIndex < LocalGuideData.Count)
  147. {
  148. ListData.Add(LocalGuideData[RowIndex]);
  149. }
  150. else
  151. {
  152. break;
  153. }
  154. }
  155. return result = new Result()
  156. {
  157. Code = 0,
  158. Msg = "查询成功",
  159. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  160. };
  161. }
  162. }
  163. else if (dto.PortType == 2)
  164. {
  165. string sql = string.Format(@"select * from Res_LocalGuideData {0}", sqlWhere);
  166. List<Res_LocalGuideData> LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  167. //2024-05-11 修改,取消该判断,避免前端报错
  168. //if (LocalGuideData.Count == 0)
  169. //{
  170. // return result = new Result() { Code = 0, Msg = "暂无数据" };
  171. //}
  172. LocalGuideData = LocalGuideData.OrderByDescending(x => x.CreateTime).ToList();
  173. if (dto.PageSize == 0 && dto.PageIndex == 0)
  174. {
  175. return result = new Result()
  176. {
  177. Code = 0,
  178. Msg = "查询成功",
  179. Data = LocalGuideData,
  180. };
  181. }
  182. else
  183. {
  184. int count = LocalGuideData.Count;
  185. float totalPage = (float)count / dto.PageSize;//总页数
  186. if (totalPage == 0) totalPage = 1;
  187. else totalPage = (int)Math.Ceiling((double)totalPage);
  188. List<Res_LocalGuideData> ListData = new List<Res_LocalGuideData>();
  189. for (int i = 0; i < dto.PageSize; i++)
  190. {
  191. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  192. if (RowIndex < LocalGuideData.Count)
  193. {
  194. ListData.Add(LocalGuideData[RowIndex]);
  195. }
  196. else
  197. {
  198. break;
  199. }
  200. }
  201. return result = new Result()
  202. {
  203. Code = 0,
  204. Msg = "查询成功",
  205. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  206. };
  207. }
  208. }
  209. else if (dto.PortType == 3)
  210. {
  211. string sql = string.Format(@"select Id,UnitArea,UnitName,Contact,ContactTel,Score,LastUpdate from Res_LocalGuideData {0}", sqlWhere);
  212. List<Res_LocalGuideData> LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(sql).ToListAsync();
  213. if (LocalGuideData.Count == 0)
  214. {
  215. return result = new Result() { Code = 0, Msg = "暂无数据" };
  216. }
  217. LocalGuideData = LocalGuideData.OrderByDescending(x => x.CreateTime).ToList();
  218. if (dto.PageSize == 0 && dto.PageIndex == 0)
  219. {
  220. return result = new Result()
  221. {
  222. Code = 0,
  223. Msg = "查询成功",
  224. Data = LocalGuideData,
  225. };
  226. }
  227. else
  228. {
  229. int count = LocalGuideData.Count;
  230. float totalPage = (float)count / dto.PageSize;//总页数
  231. if (totalPage == 0) totalPage = 1;
  232. else totalPage = (int)Math.Ceiling((double)totalPage);
  233. List<Res_LocalGuideData_ListItemView> ListData = new List<Res_LocalGuideData_ListItemView>();
  234. for (int i = 0; i < dto.PageSize; i++)
  235. {
  236. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  237. if (RowIndex < LocalGuideData.Count)
  238. {
  239. Res_LocalGuideData_ListItemView temp = new Res_LocalGuideData_ListItemView()
  240. {
  241. Contact = LocalGuideData[RowIndex].Contact,
  242. ContactTel = LocalGuideData[RowIndex].ContactTel,
  243. Id = LocalGuideData[RowIndex].Id,
  244. Score = LocalGuideData[RowIndex].Score,
  245. UnitArea = LocalGuideData[RowIndex].UnitArea,
  246. UnitName = LocalGuideData[RowIndex].UnitName
  247. };
  248. temp.LastUpdateStr = LocalGuideData[RowIndex].CreateTime.ToString("yyyy-MM-dd");
  249. ListData.Add(temp);
  250. }
  251. else
  252. {
  253. break;
  254. }
  255. }
  256. return result = new Result()
  257. {
  258. Code = 0,
  259. Msg = "查询成功",
  260. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
  261. };
  262. }
  263. }
  264. else
  265. {
  266. return result = new Result() { Code = -2, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS" };
  267. }
  268. }
  269. catch (Exception)
  270. {
  271. return result;
  272. throw;
  273. }
  274. }
  275. }
  276. }