平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WarnInfoService.cs 5.7 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using Mapster;
  2. using MoYu.DependencyInjection;
  3. using MoYu.FriendlyException;
  4. using SafeCampus.Application.Services.Business;
  5. using SafeCampus.Application.Services.Business.Warn.Dto;
  6. using SafeCampus.Application.Services.Business.Warn.Service;
  7. namespace SafeCampus.Web.Core.Controllers.Application.Business.Warn.Service;
  8. public class WarnInfoService:DbRepository<WarnInfo>, IWarnInfoService,ITransient
  9. {
  10. private readonly ISimpleCacheService _simpleCacheService;
  11. public WarnInfoService(ISimpleCacheService simpleCacheService)
  12. {
  13. _simpleCacheService = simpleCacheService;
  14. }
  15. public async Task<bool> Add(WarnInfoDto vm)
  16. {
  17. var model = vm.Adapt<WarnInfo>();
  18. await InsertAsync(model);
  19. return true;
  20. }
  21. public async Task<bool> Delete(long Id)
  22. {
  23. var model = await GetFirstAsync(x=>x.Id==Id);
  24. if (model == null)
  25. {
  26. throw Oops.Oh("信息不存在");
  27. }
  28. await DeleteAsync(model);
  29. return true;
  30. }
  31. public async Task<bool> Update(WarnInfoDto vm)
  32. {
  33. if (!vm.ID.HasValue)
  34. {
  35. throw Oops.Oh("请填写ID");
  36. }
  37. var model = await GetFirstAsync(p => p.Id == vm.ID);
  38. if (model == null)
  39. {
  40. throw Oops.Oh("信息不存在");
  41. }
  42. var res = vm.Adapt(model);
  43. await UpdateAsync(res);
  44. return true;
  45. }
  46. public async Task<WarnInfoDto> GetInfo(long Id)
  47. {
  48. var model = await Context.Queryable<WarnInfo>()
  49. .Includes(x=>x.CameraInfoItem)
  50. .Includes(x => x.PersonInfoItem)
  51. .Includes(x => x.PersonSetInfoItem)
  52. .FirstAsync(x => x.Id == Id);
  53. if (model == null)
  54. {
  55. throw Oops.Oh("信息不存在!");
  56. }
  57. return model.Adapt<WarnInfoDto>();
  58. }
  59. public async Task<SqlSugarPagedList<WarnInfoList>> GetList(WarnInfoSearch search)
  60. {
  61. var config = _simpleCacheService.Get<List<WarnGroupInfo>>(SafeCampusConst.WarnGroup);
  62. var guolvIds = new List<long>();
  63. if (config!=null)
  64. {
  65. var guolv = Context.Queryable<WarnInfo>();
  66. foreach (var warnGroupInfo in config)
  67. {
  68. if (warnGroupInfo.State)
  69. {
  70. foreach (var warnGroupSubset in warnGroupInfo.Subset)
  71. {
  72. if (!warnGroupSubset.State)
  73. {
  74. guolvIds.AddRange(await guolv
  75. .Where(x => warnGroupInfo.CameraId.Contains(x.CameraId) &&
  76. x.AlarmType == warnGroupSubset.Code).Select(x => x.Id).ToListAsync());
  77. }
  78. }
  79. }
  80. else
  81. {
  82. guolvIds.AddRange(await guolv
  83. .Where(x => warnGroupInfo.CameraId.Contains(x.CameraId)).Select(x => x.Id).ToListAsync());
  84. }
  85. }
  86. }
  87. var query = Context.Queryable<WarnInfo>()
  88. .Includes(x=>x.CameraInfoItem)
  89. .Includes(x=>x.PersonInfoItem)
  90. .Includes(x=>x.PersonSetInfoItem)
  91. .WhereIF(search.WarnHand.HasValue, x => x.WarnHand == search.WarnHand)
  92. .WhereIF(!string.IsNullOrEmpty(search.AlarmType),x => x.AlarmType == search.AlarmType)
  93. .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId)
  94. .WhereIF(search.StartTick.HasValue,x => x.Tick >= search.StartTick)
  95. .WhereIF(search.EndTick.HasValue, x => x.Tick <= search.EndTick)
  96. .WhereIF(guolvIds.Any(),x=>!guolvIds.Contains(x.Id));
  97. var list=await query.OrderByDescending(x=>x.Tick)
  98. .ToPagedListAsyncMapster<WarnInfo,WarnInfoList>(search.PageNum, search.PageSize);
  99. return list;
  100. }
  101. public async Task<bool> HandWarn(HandWarnInput input)
  102. {
  103. var model = await GetFirstAsync(p => p.Id == input.Id);
  104. if (model == null)
  105. {
  106. throw Oops.Oh("信息不存在!");
  107. }
  108. model.Remark = input.Remark;
  109. model.WarnHand = 1;
  110. model.HandTime = DateTime.Now;
  111. await UpdateAsync(model);
  112. return true;
  113. }
  114. public async Task<List<WarnInfoList>> GetListNoPage(WarnInfoSearch search)
  115. {
  116. var query = Context.Queryable<WarnInfo>()
  117. .Includes(x => x.CameraInfoItem,x=>x.CameraGroupItem)
  118. .Includes(x => x.PersonInfoItem)
  119. .Includes(x => x.PersonSetInfoItem)
  120. .WhereIF(search.WarnHand.HasValue, x => x.WarnHand == search.WarnHand)
  121. .WhereIF(!string.IsNullOrEmpty(search.AlarmType), x => x.AlarmType == search.AlarmType)
  122. .WhereIF(search.AlarmTypes!=null&&search.AlarmTypes.Any(),x=>search.AlarmTypes.Contains(x.AlarmType))
  123. .WhereIF(search.PersonSetIds != null&&search.PersonSetIds.Any(),x=>search.PersonSetIds.Contains(x.PersonSetId))
  124. .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId)
  125. .WhereIF(search.StartTick.HasValue, x => x.Tick >= search.StartTick)
  126. .WhereIF(search.EndTick.HasValue, x => x.Tick <= search.EndTick);
  127. var list = await query.OrderByDescending(x => x.Tick)
  128. .ToListAsync();
  129. return list.Adapt<List<WarnInfoList>>();
  130. }
  131. public async Task<List<WarnType>>GetWarnType()
  132. {
  133. var query = Context.Queryable<WarnInfo>()
  134. .GroupBy(x => new { x.AlarmType, x.AlarmTypeDesc })
  135. .Select(xx => new WarnType
  136. {
  137. Name = xx.AlarmTypeDesc,
  138. Code = xx.AlarmType
  139. });
  140. return await query.ToListAsync();
  141. }
  142. }