527 lines
22 KiB
C#
527 lines
22 KiB
C#
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using System.Text.Encodings.Web;
|
||
using Hg.Core.Domain.Dto.Meeting;
|
||
using Hg.Core.Entity;
|
||
|
||
namespace Hg.Core.Domain
|
||
{
|
||
public class MeetingDomain : IMeetingDomain
|
||
{
|
||
private readonly IBaseRepository<ZxdDbContext> _zxdRepository;
|
||
private readonly IRedisManager _redisManager;
|
||
private readonly IConfiguration _configuration;
|
||
private readonly IHttpClient _httpClient;
|
||
private readonly IMapper _mapper;
|
||
private readonly SystemConfig _systemConfig;
|
||
private readonly IInneruserDomain _inneruserDomain;
|
||
private readonly ICacheDomain _cacheDomain;
|
||
|
||
public MeetingDomain(IBaseRepository<ZxdDbContext> zxdRepository,
|
||
IRedisManager redisManager,
|
||
IConfiguration configuration,
|
||
IMapper mapper,
|
||
IHttpClient httpClient,
|
||
IInneruserDomain inneruserDomain,
|
||
ICacheDomain cacheDomain)
|
||
{
|
||
_zxdRepository = zxdRepository;
|
||
_redisManager = redisManager;
|
||
_mapper = mapper;
|
||
_httpClient = httpClient;
|
||
_configuration = configuration;
|
||
_inneruserDomain = inneruserDomain;
|
||
_cacheDomain = cacheDomain;
|
||
_systemConfig = _configuration.GetSection("SystemConfig").Get<SystemConfig>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 会议地点下拉
|
||
/// </summary>
|
||
/// <param name="site"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<SelectItem>> GetMeetingSiteSelect(string? site)
|
||
{
|
||
var select = await _zxdRepository.GetRepository<Meeting>().Query()
|
||
.If(!string.IsNullOrEmpty(site), x => x.Where(x => x.Site.Contains(site)))
|
||
.Where(x => !string.IsNullOrEmpty(x.Site))
|
||
.Select(x => new SelectItem(x.Site, x.Site)).Distinct()
|
||
.ToListAsync();
|
||
|
||
return select;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 分页
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
public async Task<PageResult<MeetingDto>> GetPage(SearchMeetingDto dto)
|
||
{
|
||
|
||
var predicate = PredicateExtensionses.False<Meeting>();
|
||
if (dto.ChannelList != null && dto.ChannelList.Any())
|
||
{
|
||
foreach (var channel in dto.ChannelList)
|
||
{
|
||
predicate = predicate.Or(x => x.Channels.Contains(channel));
|
||
}
|
||
}
|
||
|
||
var query = _zxdRepository.GetRepository<Meeting>().Query()
|
||
.If(!string.IsNullOrEmpty(dto.MeetingName), x => x.Where(x => x.MeetingName.Contains(dto.MeetingName)))
|
||
.If(dto.MeetingType != null, x => x.Where(x => x.MeetingType == (MeetingType)dto.MeetingType))
|
||
.If(!string.IsNullOrEmpty(dto.Compere), x => x.Where(x => x.Compere.Contains(dto.Compere)))
|
||
.If(!string.IsNullOrEmpty(dto.CreateUser), x => x.Where(x => x.CreateUser == dto.CreateUser))
|
||
.If(!string.IsNullOrEmpty(dto.Paricipant), x => x.Where(x => x.MeetingParticipants.Any(y => y.Paricipant == dto.Paricipant)))
|
||
.If(dto.CreateTimeForm != null, x => x.Where(x => x.CreateTime >= dto.CreateTimeForm))
|
||
.If(dto.CreateTimeTo != null, x => x.Where(x => x.CreateTime < dto.CreateTimeTo.Value.AddDays(1)))
|
||
.If(dto.MeetingDateForm != null, x => x.Where(x => x.BeginTime >= dto.MeetingDateForm))
|
||
.If(dto.MeetingDateTo != null, x => x.Where(x => x.BeginTime < dto.MeetingDateTo.Value.AddDays(1)))
|
||
.If(!string.IsNullOrEmpty(dto.Channels), x => x.Where(predicate))
|
||
.Where(x => !x.IsDelete)
|
||
.Include(x => x.MeetingParticipants)
|
||
.Include(x => x.MeetingAccessories);
|
||
|
||
var companyVirtualList = await _cacheDomain.GetCompanyVirtualList();
|
||
companyVirtualList.Add( new Bas_CompanyVirtual
|
||
{
|
||
Channel = "-1",
|
||
CompanyName = "合规风控中心"
|
||
});
|
||
companyVirtualList.Add(new Bas_CompanyVirtual
|
||
{
|
||
Channel = "-2",
|
||
CompanyName = "其他部门"
|
||
});
|
||
var total = await query.CountAsync();
|
||
var data = await query
|
||
.Select(x => new MeetingDto
|
||
{
|
||
Id = x.Id,
|
||
Compere = x.Compere,
|
||
CreateTime = x.CreateTime,
|
||
CreateUser = x.CreateUser,
|
||
Channels = x.Channels,
|
||
MeetingName = x.MeetingName,
|
||
MeetingSite = x.Site,
|
||
AccessoryCount = x.MeetingAccessories.Count,
|
||
ParticipantCount = x.MeetingParticipants.Count,
|
||
MeetingTime = x.BeginTime.AddHours(x.ContinueHour).AddMinutes(x.ContinueMinute) >= DateTime.Parse(x.BeginTime.ToString("yyyy-MM-dd")).AddDays(1) ?
|
||
$"{x.BeginTime:yyyy/MM/dd HH:mm}-{x.BeginTime.AddHours(x.ContinueHour).AddMinutes(x.ContinueMinute):yyyy/MM/dd HH:mm}"
|
||
: $"{x.BeginTime:yyyy/MM/dd} {x.BeginTime:HH:mm}-{x.BeginTime.AddHours(x.ContinueHour).AddMinutes(x.ContinueMinute):HH:mm}",
|
||
MeetingType = x.MeetingType.GetDescription(),
|
||
Remark = x.Remark,
|
||
UpdateTime = x.UpdateTime,
|
||
UpdateUser = x.UpdateUser,
|
||
Time = x.UpdateTime != null ? x.UpdateTime : x.CreateTime
|
||
})
|
||
.OrderByDescending(x => x.Time)
|
||
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToListAsync();
|
||
|
||
foreach(var item in data)
|
||
{
|
||
if (string.IsNullOrEmpty(item.Channels)) continue;
|
||
var channels = item.Channels.Split(',').Select(x => x.Replace(";", ",")).ToList();
|
||
var companyVirtuals = companyVirtualList.Where(x => channels.Contains(x.Channel));
|
||
item.ChannelList = companyVirtuals.Select(x => x.CompanyName).ToList();
|
||
}
|
||
|
||
return new PageResult<MeetingDto>(dto.PageIndex, dto.PageSize, total, data);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取会议参与人
|
||
/// </summary>
|
||
/// <param name="meetingId"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task<List<MeetingParticipantDto>> GetMeetingParticipants(int? meetingId)
|
||
{
|
||
if (meetingId == null)
|
||
{
|
||
throw new ApiException("会议ID不能为空!");
|
||
}
|
||
var data = await _zxdRepository.GetRepository<MeetingParticipant>().Query()
|
||
.Where(x => x.MeetingId == meetingId)
|
||
.Select(x => new MeetingParticipantDto
|
||
{
|
||
Id = x.Id,
|
||
Participant = x.Paricipant ?? ""
|
||
})
|
||
.ToListAsync();
|
||
return data;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取会议附件
|
||
/// </summary>
|
||
/// <param name="meetingId"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task<MeetingAccessoryDto> GetMeetingAccessory(int? meetingId)
|
||
{
|
||
if (meetingId == null)
|
||
{
|
||
throw new ApiException("会议ID不能为空!");
|
||
}
|
||
var meeting = await _zxdRepository.GetRepository<Meeting>().Query()
|
||
.Where(x => x.Id == meetingId)
|
||
.Where(x => !x.IsDelete)
|
||
.Include(x => x.MeetingAccessories)
|
||
.FirstOrDefaultAsync();
|
||
|
||
if (meeting == null)
|
||
{
|
||
throw new ApiException("会议不存或已删除!");
|
||
}
|
||
|
||
var data = new MeetingAccessoryDto
|
||
{
|
||
Id = meeting.Id,
|
||
Compere = meeting.Compere,
|
||
MeetingName = meeting.MeetingName,
|
||
MeetingType = meeting.MeetingType.GetDescription()
|
||
};
|
||
foreach (var meetingAccessory in meeting.MeetingAccessories)
|
||
{
|
||
data.Accessories.Add(new AccessoryDto
|
||
{
|
||
FileName = meetingAccessory.FileName,
|
||
FileSize = meetingAccessory.FileSize,
|
||
FileUrl = meetingAccessory.FileUrl,
|
||
Uploader = meetingAccessory.Uploader,
|
||
UploadTime = meetingAccessory.UploadTime,
|
||
Id = meetingAccessory.Id
|
||
});
|
||
}
|
||
|
||
return data;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取会议详情
|
||
/// </summary>
|
||
/// <param name="meetingId"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task<MeetingDetailDto> GetMeetingMeetingDetail(int? meetingId)
|
||
{
|
||
if (meetingId == null)
|
||
{
|
||
throw new ApiException("会议ID不能为空!");
|
||
}
|
||
var meeting = await _zxdRepository.GetRepository<Meeting>().Query()
|
||
.Where(x => x.Id == meetingId)
|
||
.Where(x => !x.IsDelete)
|
||
.Include(x => x.MeetingAccessories)
|
||
.Include(x => x.MeetingParticipants)
|
||
.FirstOrDefaultAsync();
|
||
|
||
if (meeting == null)
|
||
{
|
||
throw new ApiException("会议不存或已删除!");
|
||
}
|
||
|
||
var data = new MeetingDetailDto
|
||
{
|
||
Id = meeting.Id,
|
||
Channels = meeting.Channels,
|
||
Compere = meeting.Compere,
|
||
MeetingName = meeting.MeetingName,
|
||
MeetingType = ((int)meeting.MeetingType).ToString(),
|
||
MeetingSite = meeting.Site,
|
||
BeginTime = meeting.BeginTime,
|
||
ContinueHour = meeting.ContinueHour,
|
||
ContinueMinute = meeting.ContinueMinute,
|
||
Remark = meeting.Remark,
|
||
};
|
||
if (meeting.MeetingParticipants != null && meeting.MeetingParticipants.Any())
|
||
{
|
||
var meetingParticipants = meeting.MeetingParticipants.Select(x => new InneruserDto(x.Eid, x.Paricipant ?? "", -1));
|
||
data.Participant = JsonSerializer.Serialize(meetingParticipants);
|
||
}
|
||
var accessoryList = new List<AccessoryDto>();
|
||
foreach (var meetingAccessory in meeting.MeetingAccessories)
|
||
{
|
||
accessoryList.Add(new AccessoryDto
|
||
{
|
||
FileName = meetingAccessory.FileName,
|
||
FileSize = meetingAccessory.FileSize,
|
||
FileUrl = meetingAccessory.FileUrl,
|
||
Uploader = meetingAccessory.Uploader,
|
||
UploadTime = meetingAccessory.UploadTime,
|
||
Id = meetingAccessory.Id
|
||
});
|
||
}
|
||
data.Accessories = JsonSerializer.Serialize(accessoryList);
|
||
|
||
return data;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建或修改会议
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <param name="user"></param>
|
||
/// <returns></returns>
|
||
public async Task CreateOrEditMeeting(CreateOrEditMeetingDto dto, int eid)
|
||
{
|
||
var user = await _inneruserDomain.GetInneruser(eid);
|
||
if (user == null)
|
||
{
|
||
throw new ApiException($"Eid:{eid}, 用户不存在!");
|
||
}
|
||
var userName = user.Name;
|
||
var meetingType = int.Parse(dto.MeetingType ?? "0");
|
||
var beginTime = DateTime.Parse(dto.BeginTime ?? DateTime.Now.ToString());
|
||
var continueHour = int.Parse(dto.ContinueHour ?? "0");
|
||
var continueMinute = int.Parse(dto.ContinueMinute ?? "0");
|
||
var comperes = await _inneruserDomain.GetInnerusersByName(dto.Compere);
|
||
var participants = string.IsNullOrEmpty(dto.Participant) ? null :
|
||
await _inneruserDomain.GetInnerusers(dto.Participant);
|
||
Log.Information($"参数:{dto.ToJson()}");
|
||
var option = new JsonSerializerOptions()
|
||
{
|
||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||
};
|
||
if (dto.Id != null && int.TryParse(dto.Id, out int id) && id > 0)
|
||
{
|
||
var meeting = await _zxdRepository.GetRepository<Meeting>().Query()
|
||
.Include(x => x.MeetingParticipants)
|
||
.Include(x => x.MeetingAccessories)
|
||
.FirstOrDefaultAsync(x => x.Id == id);
|
||
if (meeting == null)
|
||
{
|
||
throw new ApiException("会议不存或已删除!");
|
||
}
|
||
|
||
meeting.BeginTime = beginTime;
|
||
meeting.Channels = dto.Channels;
|
||
meeting.Compere = JsonSerializer.Serialize(comperes, option);
|
||
meeting.ContinueHour = continueHour;
|
||
meeting.ContinueMinute = continueMinute;
|
||
meeting.MeetingName = dto.MeetingName;
|
||
meeting.MeetingType = (MeetingType)meetingType;
|
||
meeting.Remark = dto.Remark;
|
||
meeting.Site = dto.MeetingSite;
|
||
meeting.UpdateTime = DateTime.Now;
|
||
meeting.UpdateUser = userName;
|
||
var transaction = await _zxdRepository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
if (participants != null)
|
||
{
|
||
foreach (var participant in participants)
|
||
{
|
||
if (!meeting.MeetingParticipants.Any(x => x.Eid == participant.EId))
|
||
{
|
||
meeting.MeetingParticipants.Add(new MeetingParticipant
|
||
{
|
||
Eid = participant.EId,
|
||
Paricipant = participant.Name
|
||
});
|
||
}
|
||
}
|
||
var eids = participants.Select(x => x.EId).ToList();
|
||
var deleteParticipants = meeting.MeetingParticipants.Where(x => !eids.Contains(x.Eid)).ToList();
|
||
foreach (var deleteParticipant in deleteParticipants)
|
||
{
|
||
await _zxdRepository.GetRepository<MeetingParticipant>().DeleteAsync(deleteParticipant);
|
||
}
|
||
}
|
||
if (dto.AccessoryList != null && dto.AccessoryList.Any())
|
||
{
|
||
foreach (var accessory in dto.AccessoryList)
|
||
{
|
||
if (!meeting.MeetingAccessories.Any(x => x.FileUrl == accessory.FileUrl))
|
||
{
|
||
meeting.MeetingAccessories.Add(new MeetingAccessory
|
||
{
|
||
FileName = accessory.FileName,
|
||
FileSize = accessory.FileSize,
|
||
FileUrl = accessory.FileUrl,
|
||
UploadEid = user.EId,
|
||
Uploader = user.Name,
|
||
UploadTime = DateTime.Now
|
||
});
|
||
}
|
||
|
||
}
|
||
var fileUrls = dto.AccessoryList.Select(x => x.FileUrl).ToList();
|
||
var deleteAccessories = meeting.MeetingAccessories.Where(x => !fileUrls.Contains(x.FileUrl)).ToList();
|
||
foreach (var deleteAccessory in deleteAccessories)
|
||
{
|
||
await _zxdRepository.GetRepository<MeetingAccessory>().DeleteAsync(deleteAccessory);
|
||
}
|
||
}
|
||
|
||
await _zxdRepository.GetRepository<Meeting>().UpdateAsync(meeting);
|
||
await transaction.CommitAsync();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
Log.Error(ex, "修改会议资料报错!");
|
||
throw;
|
||
}
|
||
return;
|
||
}
|
||
|
||
var meetingInfo = new Meeting
|
||
{
|
||
BeginTime = beginTime,
|
||
Compere = JsonSerializer.Serialize(comperes, option),
|
||
ContinueHour = continueHour,
|
||
ContinueMinute = continueMinute,
|
||
MeetingName = dto.MeetingName,
|
||
MeetingType = (MeetingType)meetingType,
|
||
Remark = dto.Remark,
|
||
Site = dto.MeetingSite,
|
||
CreateTime = DateTime.Now,
|
||
Channels = dto.Channels,
|
||
CreateUser = userName
|
||
};
|
||
if (participants != null)
|
||
{
|
||
foreach (var participant in participants)
|
||
{
|
||
meetingInfo.MeetingParticipants.Add(new MeetingParticipant
|
||
{
|
||
Eid = participant.EId,
|
||
Paricipant = participant.Name
|
||
});
|
||
|
||
}
|
||
}
|
||
if (dto.AccessoryList != null && dto.AccessoryList.Any())
|
||
{
|
||
foreach (var accessory in dto.AccessoryList)
|
||
{
|
||
meetingInfo.MeetingAccessories.Add(new MeetingAccessory
|
||
{
|
||
FileName = accessory.FileName,
|
||
FileSize = accessory.FileSize,
|
||
FileUrl = accessory.FileUrl,
|
||
UploadEid = user.EId,
|
||
Uploader = user.Name,
|
||
UploadTime = DateTime.Now
|
||
});
|
||
}
|
||
}
|
||
await _zxdRepository.GetRepository<Meeting>().InsertAsync(meetingInfo);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除会议
|
||
/// </summary>
|
||
/// <param name="meetingId"></param>
|
||
/// <param name="eid"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task DeleteMeeting(int? meetingId, int eid)
|
||
{
|
||
var user = await _inneruserDomain.GetInneruser(eid);
|
||
var meeting = await _zxdRepository.GetRepository<Meeting>().Query()
|
||
.Where(x => x.Id == meetingId)
|
||
.Where(x => !x.IsDelete)
|
||
.FirstOrDefaultAsync();
|
||
|
||
if (meeting == null)
|
||
{
|
||
throw new ApiException("会议不存或已删除!");
|
||
}
|
||
|
||
meeting.IsDelete = true;
|
||
meeting.UpdateTime = DateTime.Now;
|
||
meeting.UpdateUser = user.Name;
|
||
await _zxdRepository.GetRepository<Meeting>().UpdateAsync(meeting);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除会议附件
|
||
/// </summary>
|
||
/// <param name="accessoryd"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task DeleteMeetingAccessory(int? accessoryId)
|
||
{
|
||
var meetingAccessory = await _zxdRepository.GetRepository<MeetingAccessory>().Query()
|
||
.Where(x => x.Id == accessoryId)
|
||
.FirstOrDefaultAsync();
|
||
|
||
if (meetingAccessory == null)
|
||
{
|
||
throw new ApiException("会议附件不存或已删除!");
|
||
}
|
||
await _zxdRepository.GetRepository<MeetingAccessory>().DeleteAsync(meetingAccessory);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改会议附件
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <param name="eid"></param>
|
||
/// <returns></returns>
|
||
public async Task EditMeetingAccessory(EditMeetingAccessoryDto dto, int eid)
|
||
{
|
||
var user = await _inneruserDomain.GetInneruser(eid);
|
||
var transaction = await _zxdRepository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
if (dto.Id != null && int.TryParse(dto.Id, out int id) && id > 0)
|
||
{
|
||
var meeting = await _zxdRepository.GetRepository<Meeting>().Query()
|
||
.Include(x => x.MeetingParticipants)
|
||
.Include(x => x.MeetingAccessories)
|
||
.FirstOrDefaultAsync(x => x.Id == id && !x.IsDelete);
|
||
if (meeting == null)
|
||
{
|
||
throw new ApiException("会议不存或已删除!");
|
||
}
|
||
if (dto.AccessoryList != null && dto.AccessoryList.Any())
|
||
{
|
||
foreach (var accessory in dto.AccessoryList)
|
||
{
|
||
if (!meeting.MeetingAccessories.Any(x => x.FileUrl == accessory.FileUrl))
|
||
{
|
||
meeting.MeetingAccessories.Add(new MeetingAccessory
|
||
{
|
||
FileName = accessory.FileName,
|
||
FileSize = accessory.FileSize,
|
||
FileUrl = accessory.FileUrl,
|
||
UploadEid = user.EId,
|
||
Uploader = user.Name,
|
||
UploadTime = DateTime.Now
|
||
});
|
||
}
|
||
|
||
}
|
||
var fileUrls = dto.AccessoryList.Select(x => x.FileUrl).ToList();
|
||
var deleteAccessories = meeting.MeetingAccessories.Where(x => !fileUrls.Contains(x.FileUrl)).ToList();
|
||
foreach (var deleteAccessory in deleteAccessories)
|
||
{
|
||
await _zxdRepository.GetRepository<MeetingAccessory>().DeleteAsync(deleteAccessory);
|
||
}
|
||
}
|
||
meeting.UpdateUser = user.Name;
|
||
meeting.UpdateTime = DateTime.Now;
|
||
await _zxdRepository.GetRepository<Meeting>().UpdateAsync(meeting);
|
||
await transaction.CommitAsync();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
Log.Error(ex, "修改会议附件报错!");
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|