| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using Admin.NET.Core;
- using Admin.NET.Plugin.AiDOP.Entity.S8;
- using Admin.NET.Plugin.AiDOP.Infrastructure.S8;
- namespace Admin.NET.Plugin.AiDOP.Service.S8;
- public class S8NotificationLayerService : ITransient
- {
- private readonly SqlSugarRepository<AdoS8NotificationLayer> _rep;
- private readonly SqlSugarRepository<SysRole> _roleRep;
- public S8NotificationLayerService(
- SqlSugarRepository<AdoS8NotificationLayer> rep,
- SqlSugarRepository<SysRole> roleRep)
- {
- _rep = rep;
- _roleRep = roleRep;
- }
- public async Task<List<AdoS8NotificationLayer>> ListAsync(long tenantId, long factoryId) =>
- await _rep.AsQueryable()
- .Where(x => x.TenantId == tenantId && x.FactoryId == factoryId)
- .ToListAsync();
- public async Task<List<object>> GetRoleOptionsAsync()
- {
- var roles = await _roleRep.AsQueryable()
- .Where(x => (x.Id >= 1329908000101L && x.Id <= 1329908000107L) || x.Id == 1300000000101L)
- .OrderBy(x => x.Id)
- .Select(x => new { value = x.Code, label = x.Name })
- .ToListAsync();
- return roles.Cast<object>().ToList();
- }
- public async Task<AdoS8NotificationLayer> CreateAsync(AdoS8NotificationLayer body)
- {
- if (string.IsNullOrWhiteSpace(body.SceneCode) || string.IsNullOrWhiteSpace(body.Severity) || string.IsNullOrWhiteSpace(body.LevelCode))
- throw new S8BizException("场景、严重度、层级必填");
- if (string.IsNullOrWhiteSpace(body.TargetRoleIds))
- throw new S8BizException("目标角色必填");
- if (string.IsNullOrWhiteSpace(body.NotifyChannel))
- throw new S8BizException("通知渠道至少选一个");
- // S8-SEVERITY-FOLLOW-SERIOUS-STANDARDIZE-EXEC-1:归一为 FOLLOW/SERIOUS 后再校验/写入。
- body.Severity = S8SeverityCode.Normalize(body.Severity);
- var exists = await _rep.AsQueryable()
- .AnyAsync(x => x.TenantId == body.TenantId && x.FactoryId == body.FactoryId &&
- x.SceneCode == body.SceneCode && x.Severity == body.Severity && x.LevelCode == body.LevelCode);
- if (exists) throw new S8BizException("同场景+严重度+层级已存在");
- body.Id = 0;
- body.CreatedAt = DateTime.Now;
- return await _rep.InsertReturnEntityAsync(body);
- }
- public async Task<AdoS8NotificationLayer> UpdateAsync(long id, AdoS8NotificationLayer body)
- {
- var e = await _rep.GetByIdAsync(id) ?? throw new S8BizException("记录不存在");
- if (string.IsNullOrWhiteSpace(body.SceneCode) || string.IsNullOrWhiteSpace(body.Severity) || string.IsNullOrWhiteSpace(body.LevelCode))
- throw new S8BizException("场景、严重度、层级必填");
- if (string.IsNullOrWhiteSpace(body.TargetRoleIds))
- throw new S8BizException("目标角色必填");
- if (string.IsNullOrWhiteSpace(body.NotifyChannel))
- throw new S8BizException("通知渠道至少选一个");
- // S8-SEVERITY-FOLLOW-SERIOUS-STANDARDIZE-EXEC-1:归一为 FOLLOW/SERIOUS 后再校验/写入。
- body.Severity = S8SeverityCode.Normalize(body.Severity);
- var exists = await _rep.AsQueryable()
- .AnyAsync(x => x.Id != id && x.TenantId == body.TenantId && x.FactoryId == body.FactoryId &&
- x.SceneCode == body.SceneCode && x.Severity == body.Severity && x.LevelCode == body.LevelCode);
- if (exists) throw new S8BizException("同场景+严重度+层级已存在");
- body.Id = id;
- body.CreatedAt = e.CreatedAt;
- body.UpdatedAt = DateTime.Now;
- await _rep.UpdateAsync(body);
- return body;
- }
- public async Task DeleteAsync(long id) => await _rep.DeleteByIdAsync(id);
- }
|