879 lines
43 KiB
C#
879 lines
43 KiB
C#
using DG.Core;
|
||
using Exceptionless.Models;
|
||
using Hg.Core.Entity.Dncmsbase;
|
||
using Hg.Core.Entity.Hgaction;
|
||
using Hg.Core.Entity.Views.DNG8;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using Serilog;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading.Tasks;
|
||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
||
|
||
namespace Hg.Complaint.Domain
|
||
{
|
||
internal class LiveAuditDomain : ILiveAuditDomain
|
||
{
|
||
private readonly IServiceProvider _serviceProvider;
|
||
private readonly IRedisManager _redisManager;
|
||
private readonly IConfiguration _configuration;
|
||
private readonly IHttpClient _httpClient;
|
||
private readonly IMapper _mapper;
|
||
private readonly ICacheDomain _cacheDomain;
|
||
private readonly int _retryCount = 3;
|
||
private readonly SystemConfig _systemConfig;
|
||
|
||
public LiveAuditDomain(
|
||
IRedisManager redisManager,
|
||
IConfiguration configuration,
|
||
IMapper mapper,
|
||
IHttpClient httpClient,
|
||
ICacheDomain cacheDomain,
|
||
IServiceProvider serviceProvider)
|
||
{
|
||
_systemConfig = configuration.GetSection("SystemConfig").Get<SystemConfig>();
|
||
_redisManager = redisManager;
|
||
_mapper = mapper;
|
||
_httpClient = httpClient;
|
||
_configuration = configuration;
|
||
_cacheDomain = cacheDomain;
|
||
_serviceProvider = serviceProvider;
|
||
}
|
||
|
||
public async Task<PageResult<LiveInfoDto>> GetLivePage(SearchLiveDto dto)
|
||
{
|
||
var deptments = await _cacheDomain.GetDeptments();
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var logQuery = hgActionRepository.GetRepository<LiveAuditLog>().Query();
|
||
var auditQuery = hgActionRepository.GetRepository<LiveAudit>().Query();
|
||
|
||
#region 查询拼接
|
||
|
||
var query = from a in hgActionRepository.GetRepository<LiveInfo>().Query()
|
||
select new LiveInfoDto
|
||
{
|
||
Id = a.Id,
|
||
Deptid = a.Deptid,
|
||
PlatformId = a.PlatformId,
|
||
Platform = a.Platform,
|
||
LiveUrl = a.LiveUrl,
|
||
LiveId = a.LiveId,
|
||
Liver = a.Liver,
|
||
Schedule = a.Schedule,
|
||
ScheduleId = a.ScheduleId,
|
||
LiveTitle = a.LiveTitle,
|
||
Ctime = a.Ctime,
|
||
PassCount = (
|
||
from c in auditQuery
|
||
where c.LiveId == a.LiveId && c.AuditStatus == LiveAuditStatus.审核通过
|
||
select c.Id).Count(),
|
||
RectifyCount = (
|
||
from c in auditQuery
|
||
where c.LiveId == a.LiveId && c.AuditStatus == LiveAuditStatus.已整改
|
||
select c.Id).Count(),
|
||
RejectCount = (
|
||
from c in auditQuery
|
||
where c.LiveId == a.LiveId && c.AuditStatus == LiveAuditStatus.违规
|
||
select c.Id).Count(),
|
||
ToBeReviewedCount = (
|
||
from c in auditQuery
|
||
where c.LiveId == a.LiveId && c.AuditStatus == LiveAuditStatus.待审核
|
||
select c.Id).Count()
|
||
};
|
||
|
||
query = query.GroupBy(x => new
|
||
{
|
||
x.Id,
|
||
x.Deptid,
|
||
x.PlatformId,
|
||
x.Platform,
|
||
x.LiveUrl,
|
||
x.LiveId,
|
||
x.Liver,
|
||
x.Schedule,
|
||
x.ScheduleId,
|
||
x.LiveTitle,
|
||
x.Ctime,
|
||
}).Select(x => new LiveInfoDto
|
||
{
|
||
Id = x.Key.Id,
|
||
Deptid = x.Key.Deptid,
|
||
PlatformId = x.Key.PlatformId,
|
||
Platform = x.Key.Platform,
|
||
LiveUrl = x.Key.LiveUrl,
|
||
LiveId = x.Key.LiveId,
|
||
Liver = x.Key.Liver,
|
||
Schedule = x.Key.Schedule,
|
||
ScheduleId = x.Key.ScheduleId,
|
||
LiveTitle = x.Key.LiveTitle,
|
||
Ctime = x.Key.Ctime,
|
||
PassCount = x.Sum(x => x.PassCount),
|
||
RectifyCount = x.Sum(x => x.RectifyCount),
|
||
RejectCount = x.Sum(x => x.RejectCount),
|
||
ToBeReviewedCount = x.Sum(x => x.ToBeReviewedCount),
|
||
});
|
||
|
||
#endregion 查询拼接
|
||
|
||
query = query.If(!string.IsNullOrEmpty(dto.Liver), x => x.Where(x => x.Liver.Contains(dto.Liver)))
|
||
.If(!string.IsNullOrEmpty(dto.Schedule), x => x.Where(x => x.Schedule.Contains(dto.Schedule)))
|
||
.If(dto.Deptid.HasValue, x => x.Where(x => x.Deptid == dto.Deptid.Value))
|
||
.If(dto.LiveId.HasValue, x => x.Where(x => x.LiveId == dto.LiveId.Value))
|
||
.If(dto.PlatformId.HasValue, x => x.Where(x => x.PlatformId == dto.PlatformId.Value))
|
||
.If(dto.TimeFrom.HasValue, x => x.Where(x => x.Ctime >= dto.TimeFrom.Value))
|
||
.If(dto.TimeTo.HasValue, x => x.Where(x => x.Ctime < dto.TimeTo.Value));
|
||
|
||
var total = await query.CountAsync();
|
||
var data = await query.OrderByDescending(x => x.Id)
|
||
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToListAsync();
|
||
var lecturerids = string.Join(",", data.Select(x => x.Liver)).Split(',').Select(x => int.Parse(x)).ToList();
|
||
var lecturers = await dncmsbaseRepository.GetRepository<Lecturer>().Query()
|
||
.Where(x => lecturerids.Contains(x.Id))
|
||
.Select(x => new
|
||
{
|
||
x.Id,
|
||
x.Title
|
||
}).ToListAsync();
|
||
foreach (var item in data)
|
||
{
|
||
item.Deptname = deptments.Where(y => y.Id == item.Deptid).Select(x => x.Title).FirstOrDefault();
|
||
var liver = item.Liver?.Split(',').Select(x => int.Parse(x)).ToList();
|
||
var lecturer = lecturers.Where(x => liver.Contains(x.Id)).ToList();
|
||
item.Liver = string.Join(",", lecturer.Select(x => x.Title).ToList());
|
||
var audit = await auditQuery.Where(y => y.LiveId == item.LiveId).OrderByDescending(y => y.Id).FirstOrDefaultAsync();
|
||
if (audit == null)
|
||
{
|
||
item.AuditStatus = LiveAuditStatus.待审核;
|
||
}
|
||
else
|
||
{
|
||
var log = await logQuery.Where(y => y.LiveId == item.LiveId).OrderByDescending(y => y.Id).FirstOrDefaultAsync();
|
||
item.AuditStatus = log != null && audit.AuditStatus == LiveAuditStatus.待审核 && log.AuditStatus != LiveAuditStatus.审核通过 ? log.AuditStatus
|
||
: audit.AuditStatus;
|
||
}
|
||
}
|
||
|
||
return new PageResult<LiveInfoDto>(dto.PageIndex, dto.PageSize, total, data);
|
||
}
|
||
|
||
public async Task<PageResult<LiveAuditDto>> GetLiveAuditPage(SearchLiveAuditDto dto)
|
||
{
|
||
var deptments = await _cacheDomain.GetDeptments();
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var query = hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.If(dto.LiveId.HasValue, x => x.Where(x => x.LiveId == dto.LiveId))
|
||
.If(dto.Deptid.HasValue, x => x.Where(x => x.Deptid == dto.Deptid))
|
||
.If(!string.IsNullOrEmpty(dto.Schedule), x => x.Where(x => x.Schedule.Contains(dto.Schedule)))
|
||
.If(!string.IsNullOrEmpty(dto.Auditer), x => x.Where(x => x.Auditer.Contains(dto.Auditer)))
|
||
.If(!string.IsNullOrEmpty(dto.Liver), x => x.Where(x => x.Liver.Contains(dto.Liver)))
|
||
.If(!string.IsNullOrEmpty(dto.Remark), x => x.Where(x => x.Remark.Contains(dto.Remark)))
|
||
.If(dto.TimeFrom.HasValue, x => x.Where(x => x.Ctime >= dto.TimeFrom.Value))
|
||
.If(dto.TimeTo.HasValue, x => x.Where(x => x.Ctime < dto.TimeTo.Value))
|
||
.If(dto.AuditTimeFrom.HasValue, x => x.Where(x => x.AuditTime >= dto.AuditTimeFrom.Value))
|
||
.If(dto.AuditTimeTo.HasValue, x => x.Where(x => x.AuditTime < dto.AuditTimeTo.Value))
|
||
.If(dto.AuditStatus.HasValue, x => x.Where(x => x.AuditStatus == dto.AuditStatus));
|
||
|
||
var total = await query.CountAsync();
|
||
var list = await query.OrderByDescending(x => x.Id)
|
||
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToListAsync();
|
||
|
||
var data = _mapper.Map<LiveAudit, LiveAuditDto>(list);
|
||
|
||
var ids = data.Select(x => x.Id).ToList();
|
||
|
||
data.ForEach(x =>
|
||
{
|
||
x.Deptname = deptments.Where(y => y.Id == x.Deptid).Select(x => x.Title).FirstOrDefault();
|
||
});
|
||
|
||
return new PageResult<LiveAuditDto>(dto.PageIndex, dto.PageSize, total, data);
|
||
}
|
||
|
||
public async Task<List<LiveAuditLogDto>> GetLiveAuditLogs(int auditId, string? date)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
|
||
var liveAudit = await hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.FirstOrDefaultAsync(x => x.Id == auditId) ?? throw new ApiException("审核记录不存在或已删除!");
|
||
|
||
var auditIds = await hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.Where(x => x.LiveId == liveAudit.LiveId && x.LiveDate == date)
|
||
.Select(x => x.Id)
|
||
.ToListAsync();
|
||
|
||
var list = await hgActionRepository.GetRepository<LiveAuditLog>().Query()
|
||
.Where(x => auditIds.Contains(x.AuditId)).ToListAsync();
|
||
|
||
var data = _mapper.Map<LiveAuditLog, LiveAuditLogDto>(list);
|
||
|
||
return data;
|
||
}
|
||
|
||
public async Task CreateLiveAudit(CreateLiveAuditDto dto)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var data = await hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.FirstOrDefaultAsync(x => x.Id == dto.AuditId) ?? throw new ApiException("审核记录不存在或已删除!");
|
||
|
||
data.AuditStatus = dto.AuditStatus;
|
||
data.Auditer = dto.Operator;
|
||
data.AuditTime = DateTime.Now;
|
||
|
||
var log = _mapper.Map<CreateLiveAuditDto, LiveAuditLog>(dto);
|
||
|
||
log.Ctime = DateTime.Now;
|
||
log.Schedule = data.Schedule;
|
||
log.LiveId = data.LiveId;
|
||
|
||
using var transaction = await hgActionRepository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
await hgActionRepository.GetRepository<LiveAudit>().UpdateAsync(data, x => new
|
||
{
|
||
x.AuditStatus,
|
||
x.AuditTime,
|
||
x.Auditer
|
||
});
|
||
await hgActionRepository.GetRepository<LiveAuditLog>().InsertAsync(log);
|
||
await transaction.CommitAsync();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
throw;
|
||
}
|
||
}
|
||
|
||
#region 直播审核2
|
||
|
||
private DateTime limitDate = DateTime.Parse("2023-11-07");
|
||
//private DateTime limitDate = DateTime.Parse("1993-11-07");
|
||
|
||
/// <summary>
|
||
/// 课程表列表
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
public async Task<PageResult<LiveAuditSchedules>> GetLiveSchedulePage(SearchLiveScheduleDto dto)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var deptments = await dncmsbaseRepository.GetRepository<Deptment>().Query().ToListAsync();
|
||
var zxdRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<ZxdDbContext>>();
|
||
var setting = await zxdRepository.GetRepository<BasParameter>().Query().FirstOrDefaultAsync(n => n.PARAKEY == "LiveAudtiDeptIgnoreSetting");
|
||
List<string> notCaontainDeptids = new List<string>();
|
||
if (setting != null)
|
||
{
|
||
var deptids = setting.PARAVALUE.Split(',').ToList();
|
||
notCaontainDeptids.AddRange(deptids);
|
||
}
|
||
|
||
#region 查询拼接
|
||
|
||
var query = from a in dncmsbaseRepository.GetRepository<ZhiboSystemSchedules>().Query().Where(m => m.Status == 1 && !notCaontainDeptids.Contains(m.Dept))
|
||
select new LiveAuditSchedules
|
||
{
|
||
schedulesId = a.Id,
|
||
title = a.Title,
|
||
cmsmome = a.Cmsmemo,
|
||
mome = a.Memo,
|
||
deptid = a.Dept,
|
||
starttime = a.Starttime,
|
||
endtime = a.Endtime,
|
||
Liver = a.Lecturer,
|
||
pretime = a.Pretime,
|
||
weeks = a.Weeks,
|
||
marketingtype = a.Marketingtype,
|
||
livestreamid = a.Livestreamid,
|
||
roomtype = a.Roomtype
|
||
};
|
||
query = query.If(!string.IsNullOrEmpty(dto.Liver), x => x.Where(x => x.Liver.Contains(dto.Liver)))
|
||
.If(!string.IsNullOrEmpty(dto.Schedule), x => x.Where(x => x.title.Contains(dto.Schedule)))
|
||
.If(dto.Deptid.HasValue, x => x.Where(x => x.deptid.Contains(dto.Deptid.Value.ToString())));
|
||
// .If(dto.PlatformId.HasValue, x => x.Where(x => x. == dto.PlatformId.Value))
|
||
// .If(dto.TimeFrom.HasValue, x => x.Where(x => x.Ctime >= dto.TimeFrom.Value))
|
||
// .If(dto.TimeTo.HasValue, x => x.Where(x => x.Ctime < dto.TimeTo.Value));
|
||
|
||
#endregion 查询拼接
|
||
|
||
var total = await query.CountAsync();
|
||
var data = await query.OrderByDescending(x => x.schedulesId)
|
||
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToListAsync();
|
||
var lecturerids = string.Join(",", data.Select(x => x.Liver)).Split(',').Select(x => int.Parse(x)).ToList();
|
||
var lecturers = await dncmsbaseRepository.GetRepository<Lecturer>().Query()
|
||
.Where(x => lecturerids.Contains(x.Id))
|
||
.Select(x => new
|
||
{
|
||
x.Id,
|
||
x.Title
|
||
}).ToListAsync();
|
||
|
||
var schedulesIds = data.Select(m => m.schedulesId).ToList();
|
||
//var log = dncmsbaseRepository.GetRepository<CMS_LiveAuditLog>().Query().Where(m => schedulesIds.Contains(m.schedulesId)).ToList();
|
||
var pb = dncmsbaseRepository.GetRepository<ZhiboSystemSchedulesPlayback>().Query()
|
||
.Include(x => x.LiveAuditLogPlayBack)
|
||
.ThenInclude(x => x.CMS_LiveAuditLog)
|
||
.Where(m => schedulesIds.Contains(m.scheduleid) && m.zbdate > limitDate && m.status == 1).ToList();
|
||
foreach (var item in data)
|
||
{
|
||
var liver = item.Liver?.Split(',').Select(x => int.Parse(x)).ToList();
|
||
var lecturer = lecturers.Where(x => liver.Contains(x.Id)).ToList();
|
||
var mypb = pb.Where(m => m.scheduleid == item.schedulesId).ToList();
|
||
|
||
var mylog = mypb.SelectMany(n => n.LiveAuditLogPlayBack).Where(n => n.CMS_LiveAuditLog != null).Select(x => x.CMS_LiveAuditLog).ToList();
|
||
//var wlog = mylog.Where(i => i.auditStatus == LiveAuditStatus.待审核);
|
||
|
||
item.deptname = deptments.Where(y => item.deptid.Split(',').Contains(y.Id.ToString())).Select(x => x.Title).FirstOrDefault();//汉化事业部
|
||
item.Liver = string.Join(",", lecturer.Select(x => x.Title).ToList());//汉化老师
|
||
item.weeks = GetWeeksName(item.weeks);//汉化周
|
||
|
||
item.violation = mylog.Where(m => m.auditStatus == LiveAuditStatus.已整改 || m.auditStatus == LiveAuditStatus.违规).Count();//提交违规次数
|
||
//无提交审核记录的 和未审核 都算未审核
|
||
item.waitAudit = mypb.Count(n => !n.LiveAuditLogPlayBack.Any() || n.LiveAuditLogPlayBack.Exists(x => x.CMS_LiveAuditLog.auditStatus == LiveAuditStatus.待审核));
|
||
//item.waitAudit = mypb.Count(m => !mylog.Select(n => n.schedulesId).Contains(m.scheduleid) || wlog.Select(n => n.schedulesId).Contains(m.scheduleid));
|
||
}
|
||
|
||
return new PageResult<LiveAuditSchedules>(dto.PageIndex, dto.PageSize, total, data);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 直播回放列表
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
public async Task<PageResult<LiveAuditPlayBack>> GetLivePlayBackPage(SearchLivePlayBackDto dto)
|
||
{
|
||
var deptments = await _cacheDomain.GetDeptments();
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var query = from a in dncmsbaseRepository.GetRepository<ZhiboSystemSchedulesPlayback>().Query()
|
||
.Include(x => x.LiveAuditLogPlayBack)
|
||
.ThenInclude(x => x.CMS_LiveAuditLog)
|
||
.Where(m => m.scheduleid == dto.schedulesId && m.zbdate > limitDate && m.status == 1)
|
||
.If(dto.stime.HasValue, x => x.Where(x => x.ctime >= dto.stime))
|
||
.If(dto.etime.HasValue, x => x.Where(x => x.ctime <= dto.etime))
|
||
.If(dto.LiveAuditStatus.HasValue && dto.LiveAuditStatus == (int)LiveAuditStatus.违规, x => x.Where(n => n.LiveAuditLogPlayBack.Any(x => x.CMS_LiveAuditLog.auditStatus == LiveAuditStatus.违规)))
|
||
.If(dto.LiveAuditStatus.HasValue && dto.LiveAuditStatus == (int)LiveAuditStatus.审核通过, x => x.Where(n => !n.LiveAuditLogPlayBack.Any(x => x.CMS_LiveAuditLog.auditStatus == LiveAuditStatus.违规) && n.LiveAuditLogPlayBack.Any(x => x.CMS_LiveAuditLog.auditStatus == LiveAuditStatus.审核通过)))
|
||
.If(dto.LiveAuditStatus.HasValue && dto.LiveAuditStatus == (int)LiveAuditStatus.已整改, x => x.Where(n => n.LiveAuditLogPlayBack.All(x => x.CMS_LiveAuditLog.auditStatus == LiveAuditStatus.已整改)))
|
||
.If(dto.LiveAuditStatus.HasValue && dto.LiveAuditStatus == (int)LiveAuditStatus.待审核, x => x.Where(n => !n.LiveAuditLogPlayBack.Any()))
|
||
|
||
select new LiveAuditPlayBack
|
||
{
|
||
pbid = a.id,
|
||
scheduleid = a.scheduleid,
|
||
title = a.title,
|
||
thumb = a.thumb,
|
||
intro = a.intro,
|
||
ctime = a.ctime,
|
||
url = a.url,
|
||
recordid = a.recordid,
|
||
status = a.status,
|
||
istop = a.istop,
|
||
zbdate = a.zbdate
|
||
};
|
||
var total = await query.CountAsync();
|
||
var data = await query.OrderByDescending(x => x.ctime)
|
||
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToListAsync();
|
||
//判断回放记录当前状态
|
||
var lpbids = data.Select(m => m.pbid).ToList();
|
||
var mylpb = dncmsbaseRepository.GetRepository<LiveAuditLogPlayBack>().Query().Where(m => lpbids.Contains(m.playBackId)).ToList();//关系数据
|
||
var lpbGupLogid = mylpb.GroupBy(m => m.logId).ToDictionary(m => m.Key, n => n);
|
||
var myLog = dncmsbaseRepository.GetRepository<CMS_LiveAuditLog>().Query().Where(m => lpbGupLogid.Select(i => i.Key).Contains(m.id)).ToList();
|
||
//处理 回放记录状态
|
||
foreach (var item in data)
|
||
{
|
||
var lpb = mylpb.Where(m => m.playBackId == item.pbid);//
|
||
//没有审核记录
|
||
if (!lpb.Any()) item.auditStatus = LiveAuditStatus.待审核;
|
||
else
|
||
{
|
||
var log = myLog.Where(m => lpb.Select(n => n.logId).Contains(m.id));//我的审核日志
|
||
if (log.Any(m => m.auditStatus == LiveAuditStatus.违规))
|
||
{
|
||
item.auditStatus = LiveAuditStatus.违规;
|
||
}
|
||
else if (log.Any(m => m.auditStatus == LiveAuditStatus.审核通过))
|
||
{
|
||
item.auditStatus = LiveAuditStatus.审核通过;
|
||
}
|
||
else
|
||
{
|
||
item.auditStatus = LiveAuditStatus.已整改;
|
||
}
|
||
}
|
||
}
|
||
|
||
return new PageResult<LiveAuditPlayBack>(dto.PageIndex, dto.PageSize, total, data);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 回放审核记录
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
public async Task<PageResult<PlayBackAuditLog>> GetPlayBackAuditLogPage(SearchPlayBackAuditLogDto dto)
|
||
{
|
||
var deptments = await _cacheDomain.GetDeptments();
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var query = from a in dncmsbaseRepository.GetRepository<LiveAuditLogPlayBack>().Query().Where(m => m.playBackId == dto.playBackId)
|
||
join b in dncmsbaseRepository.GetRepository<CMS_LiveAuditLog>().Query() on a.logId equals b.id into lapb
|
||
from pb in lapb.DefaultIfEmpty()
|
||
select new PlayBackAuditLog
|
||
{
|
||
playBackId = a.playBackId,
|
||
schedulesId = pb.schedulesId,
|
||
auditStatus = pb.auditStatus,
|
||
rejectReason = pb.rejectReason,
|
||
auditRemark = pb.auditRemark,
|
||
auditAccessory = pb.auditAccessory,
|
||
creater = pb.creater,
|
||
ctime = pb.ctime,
|
||
solver = pb.solver,
|
||
solveTime = pb.solveTime,
|
||
solveRemark = pb.solveRemark,
|
||
solveAccessory = pb.solveAccessory
|
||
};
|
||
|
||
var total = await query.CountAsync();
|
||
var data = await query.OrderByDescending(x => x.ctime)
|
||
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToListAsync();
|
||
|
||
return new PageResult<PlayBackAuditLog>(dto.PageIndex, dto.PageSize, total, data);
|
||
}
|
||
|
||
public async Task AddLiveAuditLog(AddLiveAuditDto dto)
|
||
{
|
||
if (dto.AuditStatus != LiveAuditStatus.违规 && dto.AuditStatus != LiveAuditStatus.审核通过)
|
||
{
|
||
throw new ApiException("只接受:违规和合规!");
|
||
}
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var pbids = dto.playBackIds.Split(',').Select(x => int.Parse(x.Trim())).ToList();
|
||
if (!pbids.Any())
|
||
{
|
||
throw new ApiException("请选择审核录像!");
|
||
}
|
||
CMS_LiveAuditLog log = new CMS_LiveAuditLog();
|
||
log.auditRemark = dto.AuditRemark;
|
||
log.auditAccessory = dto.AuditAccessory;
|
||
log.auditStatus = LiveAuditStatus.违规;
|
||
log.rejectReason = dto.RejectReason;
|
||
log.schedulesId = dto.SchedulesId;
|
||
log.creater = dto.Operator;
|
||
log.ctime = DateTime.Now;
|
||
log.auditStatus = dto.AuditStatus;
|
||
|
||
using var transaction = await dncmsbaseRepository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
await dncmsbaseRepository.GetRepository<CMS_LiveAuditLog>().InsertAsync(log);
|
||
List<LiveAuditLogPlayBack> pblist = pbids.Select(m => new LiveAuditLogPlayBack() { logId = log.id, playBackId = m }).ToList();
|
||
await dncmsbaseRepository.GetRepository<LiveAuditLogPlayBack>().BatchInsertAsync(pblist);
|
||
|
||
await transaction.CommitAsync();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
throw;
|
||
}
|
||
}
|
||
|
||
public async Task SolveLiveAudit(SolveLiveAuditDto dto)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
|
||
var data = await dncmsbaseRepository.GetRepository<CMS_LiveAuditLog>().Query()
|
||
.FirstOrDefaultAsync(x => x.id == dto.logId) ?? throw new ApiException("审核记录不存在或已删除!");
|
||
|
||
data.solveAccessory = dto.SolveAccessory;
|
||
data.solver = dto.Operator;
|
||
data.solveRemark = dto.SolveRemark;
|
||
data.solveTime = DateTime.Now;
|
||
data.auditStatus = LiveAuditStatus.已整改;
|
||
|
||
using var transaction = await dncmsbaseRepository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
await dncmsbaseRepository.GetRepository<CMS_LiveAuditLog>().UpdateAsync(data);
|
||
|
||
await transaction.CommitAsync();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
throw;
|
||
}
|
||
}
|
||
|
||
private static string GetWeeksName(string weeks)
|
||
{
|
||
if (string.IsNullOrEmpty(weeks)) return "";
|
||
|
||
string str = "";
|
||
string[] s = Regex.Split(weeks, @",", RegexOptions.IgnoreCase);
|
||
for (int i = 0; i < s.Length; i++)
|
||
{
|
||
if (string.IsNullOrEmpty(s[i])) continue;
|
||
str += Enum.GetName(typeof(WeeksEnum), Convert.ToInt32(s[i])) + ",";
|
||
}
|
||
return str;
|
||
}
|
||
|
||
#endregion 直播审核2
|
||
|
||
public async Task CreateLiveAuditRectification(CreateLiveAuditRectificationDto dto)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var data = await hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.FirstOrDefaultAsync(x => x.Id == dto.AuditId) ?? throw new ApiException("审核记录不存在或已删除!");
|
||
|
||
data.AuditStatus = LiveAuditStatus.已整改;
|
||
|
||
var log = _mapper.Map<CreateLiveAuditRectificationDto, LiveAuditLog>(dto);
|
||
|
||
log.Ctime = DateTime.Now;
|
||
log.Schedule = data.Schedule;
|
||
log.StarTime = data.StarTime;
|
||
log.AuditStatus = data.AuditStatus;
|
||
log.LiveId = data.LiveId;
|
||
|
||
using var transaction = await hgActionRepository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
await hgActionRepository.GetRepository<LiveAudit>().UpdateAsync(data, x => new
|
||
{
|
||
x.AuditStatus,
|
||
x.AuditTime,
|
||
x.Auditer
|
||
});
|
||
await hgActionRepository.GetRepository<LiveAuditLog>().InsertAsync(log);
|
||
await transaction.CommitAsync();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
throw;
|
||
}
|
||
}
|
||
|
||
public List<SelectItem> GetRejectReasonSelect()
|
||
{
|
||
var result = new List<SelectItem>();
|
||
foreach (LiveAuditRejectReason item in Enum.GetValues(typeof(LiveAuditRejectReason)))
|
||
{
|
||
result.Add(new SelectItem(item, item.GetDescription()));
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public List<SelectItem> GetAuditStatusSelect()
|
||
{
|
||
var result = new List<SelectItem>();
|
||
foreach (LiveAuditStatus item in Enum.GetValues(typeof(LiveAuditStatus)))
|
||
{
|
||
result.Add(new SelectItem(item, item.GetDescription()));
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public async Task<List<SelectItem>> GetPlatformSelect()
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var result = await dncmsbaseRepository.GetRepository<LivePlatform>().Query()
|
||
.Select(x => new SelectItem(x.Id, x.Platform))
|
||
.ToListAsync();
|
||
return result;
|
||
}
|
||
|
||
public async Task<LiveAuditDetailDto> GetLiveAuditDetail(int auditId)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var data = await hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.FirstOrDefaultAsync(x => x.Id == auditId) ?? throw new ApiException("审核记录不存在或已删除!");
|
||
|
||
var log = await hgActionRepository.GetRepository<LiveAuditLog>().Query()
|
||
.OrderByDescending(x => x.Ctime)
|
||
.FirstOrDefaultAsync(x => x.AuditId == auditId && x.AuditStatus == LiveAuditStatus.已整改);
|
||
|
||
var result = new LiveAuditDetailDto()
|
||
{
|
||
AuditStatus = data.AuditStatus,
|
||
Id = auditId,
|
||
LiveRoomInfo = data.LiveRoomInfo,
|
||
LiveUrl = data.LiveUrl,
|
||
RectificationAccessory = log?.RectificationAccessory,
|
||
RectificationRemark = log?.RectificationRemark,
|
||
LiveDate = data.LiveDate,
|
||
ScheduleId = data.ScheduleId,
|
||
};
|
||
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 同步直播数据到审核数据
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task SyncLiveData()
|
||
{
|
||
await CreateOrUpdateLiveInfo();
|
||
var now = DateTime.Now;
|
||
var date = now.ToString("yyyy-MM-dd");
|
||
var week = now.DayOfWeek.ToString("d");
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var data = new List<LiveAudit>();
|
||
// 固化数据
|
||
if (!await hgActionRepository.GetRepository<LiveAudit>().Query().AnyAsync(x => x.LiveDate == date))
|
||
{
|
||
data = await (from a in dncmsbaseRepository.GetRepository<ZhiboSystemSchedules>().Query()
|
||
join b in dncmsbaseRepository.GetRepository<ZhiboSystemSchedulesToRoom>().Query() on a.Id equals b.Scheduleid into temAB
|
||
from b in temAB.DefaultIfEmpty()
|
||
join c in dncmsbaseRepository.GetRepository<ZhiboSystemRoom>().Query() on b.Roomid equals c.Id into temBC
|
||
from c in temBC.DefaultIfEmpty()
|
||
where a.Status == 1 && a.Weeks.Contains(week) && c.Status == 1
|
||
select new LiveAudit
|
||
{
|
||
Deptid = int.Parse(a.Dept),
|
||
LiveDate = date,
|
||
Ctime = now,
|
||
ScheduleId = a.Id,
|
||
Schedule = a.Title,
|
||
LiveId = c.Id,
|
||
Liver = a.Lecturer,
|
||
LiveRoomInfo = JsonHelper.ToJson(new { name = c.Title }),
|
||
StarTime = DateTime.Parse($"{date} {a.Starttime}"),
|
||
EndTime = DateTime.Parse($"{date} {a.Endtime}"),
|
||
LiveUrl = $"https://app.hc.dn8188.com/zhibo.html?roomid={c.Id}&agenttype=2"
|
||
}).ToListAsync();
|
||
|
||
await CreateLiveAudits(data, now);
|
||
return;
|
||
}
|
||
|
||
var source = await hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.Where(x => x.LiveDate == date)
|
||
.ToListAsync();
|
||
var liveids = source.Select(x => x.LiveId).ToList();
|
||
|
||
data = await (from a in dncmsbaseRepository.GetRepository<ZhiboSystemSchedules>().Query()
|
||
join b in dncmsbaseRepository.GetRepository<ZhiboSystemSchedulesToRoom>().Query() on a.Id equals b.Scheduleid into temAB
|
||
from b in temAB.DefaultIfEmpty()
|
||
join c in dncmsbaseRepository.GetRepository<ZhiboSystemRoom>().Query() on b.Roomid equals c.Id into temBC
|
||
from c in temBC.DefaultIfEmpty()
|
||
where a.Status == 1 && a.Weeks.Contains(week) && c.Status == 1
|
||
select new LiveAudit
|
||
{
|
||
Deptid = int.Parse(a.Dept),
|
||
LiveDate = date,
|
||
Ctime = now,
|
||
ScheduleId = a.Id,
|
||
Schedule = a.Title,
|
||
LiveId = c.Id,
|
||
Liver = a.Lecturer,
|
||
LiveRoomInfo = JsonHelper.ToJson(new { name = c.Title }),
|
||
StarTime = DateTime.Parse($"{date} {a.Starttime}"),
|
||
EndTime = DateTime.Parse($"{date} {a.Endtime}"),
|
||
LiveUrl = $"https://app.hc.dn8188.com/zhibo.html?roomid={c.Id}&agenttype=2"
|
||
}).ToListAsync();
|
||
|
||
// 差异新增
|
||
if (data.Any(x => !liveids.Contains(x.LiveId)))
|
||
{
|
||
await CreateLiveAudits(data.Where(x => !liveids.Contains(x.LiveId)).ToList(), now);
|
||
}
|
||
|
||
// 差异修改
|
||
if (data.Any(x => liveids.Contains(x.LiveId)))
|
||
{
|
||
await UpdateLiveAudits(data, source);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建直播审核数据
|
||
/// </summary>
|
||
/// <param name="data"></param>
|
||
/// <param name="now"></param>
|
||
/// <returns></returns>
|
||
private async Task CreateLiveAudits(List<LiveAudit> data, DateTime now)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var lecturerids = GetLecturerids(data);
|
||
var lecturers = await dncmsbaseRepository.GetRepository<Lecturer>().Query()
|
||
.Where(x => lecturerids.Contains(x.Id))
|
||
.Select(x => new
|
||
{
|
||
x.Id,
|
||
x.Title
|
||
}).ToListAsync();
|
||
var liveids = data.Select(x => x.LiveId).Distinct().ToList();
|
||
var sourceData = await hgActionRepository.GetRepository<LiveAudit>().Query()
|
||
.Where(x => x.LiveDate == now.AddDays(-1).ToString("yyyy-MM-dd") && liveids.Contains(x.LiveId))
|
||
.Select(x => new
|
||
{
|
||
x.LiveId,
|
||
x.AuditStatus,
|
||
x.AuditTime,
|
||
x.Auditer
|
||
}).ToListAsync();
|
||
var platform = await dncmsbaseRepository.GetRepository<LivePlatform>().Query().FirstAsync();
|
||
foreach (var item in data)
|
||
{
|
||
var livers = item.Liver.Split(',').Select(x => int.Parse(x)).ToList();
|
||
item.Liver = string.Join(",", lecturers.Where(x => livers.Contains(x.Id)).Select(x => x.Title).ToList());
|
||
var source = sourceData.FirstOrDefault(x => x.LiveId == item.LiveId);
|
||
item.PlatformId = platform.Id;
|
||
item.Platform = platform.Platform;
|
||
item.AuditStatus = LiveAuditStatus.待审核;
|
||
}
|
||
|
||
await hgActionRepository.GetRepository<LiveAudit>().BatchInsertAsync(data);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新直播审核数据
|
||
/// </summary>
|
||
/// <param name="data"></param>
|
||
/// <param name="source"></param>
|
||
/// <returns></returns>
|
||
private async Task UpdateLiveAudits(List<LiveAudit> data, List<LiveAudit> source)
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var lecturerids = GetLecturerids(data);
|
||
var lecturers = await dncmsbaseRepository.GetRepository<Lecturer>().Query()
|
||
.Where(x => lecturerids.Contains(x.Id))
|
||
.Select(x => new
|
||
{
|
||
x.Id,
|
||
x.Title
|
||
}).ToListAsync();
|
||
foreach (var item in data)
|
||
{
|
||
var livers = item.Liver.Split(',').Select(x => int.Parse(x)).ToList();
|
||
item.Liver = string.Join(",", lecturers.Where(x => livers.Contains(x.Id)).Select(x => x.Title).ToList());
|
||
}
|
||
var editData = new List<LiveAudit>();
|
||
foreach (var sourceItem in source)
|
||
{
|
||
var item = data.FirstOrDefault(x => x.LiveId == sourceItem.LiveId);
|
||
if (item != null && (sourceItem.EndTime != item.EndTime
|
||
|| sourceItem.StarTime != item.StarTime
|
||
|| sourceItem.Liver != item.Liver
|
||
|| sourceItem.LiveRoomInfo != item.LiveRoomInfo))
|
||
{
|
||
item.StarTime = sourceItem.StarTime;
|
||
item.EndTime = sourceItem.EndTime;
|
||
item.Liver = sourceItem.Liver;
|
||
item.LiveRoomInfo = sourceItem.LiveRoomInfo;
|
||
editData.Add(item);
|
||
}
|
||
}
|
||
// 差异修改
|
||
if (editData.Any())
|
||
{
|
||
await hgActionRepository.GetRepository<LiveAudit>().BatchUpdateAsync(editData, x => new
|
||
{
|
||
x.StarTime,
|
||
x.EndTime,
|
||
x.Liver,
|
||
x.LiveRoomInfo
|
||
});
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取老师id
|
||
/// </summary>
|
||
/// <param name="data"></param>
|
||
/// <returns></returns>
|
||
private static List<int> GetLecturerids(List<LiveAudit> data)
|
||
{
|
||
var lecturerids = new List<int>();
|
||
var lectureridList = data.Select(y => y.Liver.Split(',').Select(x => int.Parse(x)).ToList()).ToList();
|
||
foreach (var lecturerid in lectureridList)
|
||
{
|
||
lecturerids.AddRange(lecturerid);
|
||
}
|
||
lecturerids = lecturerids.Distinct().ToList();
|
||
return lecturerids;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 同步直播数据
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private async Task CreateOrUpdateLiveInfo()
|
||
{
|
||
using var scope = _serviceProvider.CreateAsyncScope();
|
||
var hgActionRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<HgAtionDbContext>>();
|
||
var dncmsbaseRepository = scope.ServiceProvider.GetRequiredService<IBaseRepository<DncmsbaseDbContext>>();
|
||
var platform = await dncmsbaseRepository.GetRepository<LivePlatform>().Query().FirstAsync();
|
||
|
||
var lives = await hgActionRepository.GetRepository<LiveInfo>().Query().ToListAsync();
|
||
|
||
var query = from a in dncmsbaseRepository.GetRepository<ZhiboSystemSchedules>().Query()
|
||
join b in dncmsbaseRepository.GetRepository<ZhiboSystemSchedulesToRoom>().Query() on a.Id equals b.Scheduleid into temAB
|
||
from b in temAB.DefaultIfEmpty()
|
||
join c in dncmsbaseRepository.GetRepository<ZhiboSystemRoom>().Query() on b.Roomid equals c.Id into temBC
|
||
from c in temBC.DefaultIfEmpty()
|
||
where a.Status == 1 && c.Status == 1
|
||
select new LiveInfo
|
||
{
|
||
LiveId = c.Id,
|
||
Deptid = int.Parse(a.Dept),
|
||
ScheduleId = a.Id,
|
||
Schedule = a.Title,
|
||
Liver = a.Lecturer,
|
||
LiveUrl = $"https://app.hc.dn8188.com/zhibo.html?roomid={c.Id}&agenttype=2",
|
||
PlatformId = platform.Id,
|
||
Platform = platform.Platform,
|
||
LiveTitle = c.Title,
|
||
Ctime = DateTime.Now,
|
||
};
|
||
|
||
var data = await query.If(lives.Any(), x => x.Where(x => !lives.Select(y => y.LiveId).Contains(x.LiveId)))
|
||
.ToListAsync();
|
||
|
||
if (data.Any())
|
||
{
|
||
await hgActionRepository.GetRepository<LiveInfo>().BatchInsertAsync(data);
|
||
}
|
||
}
|
||
}
|
||
} |