using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Domain.Share; using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Core.Application { [ApiExplorerSettings(GroupName = "Trial")] public class PersonalWorkstation : BaseService { private readonly IRepository _trialRepository; private readonly IRepository _trialUserRepository; private readonly IRepository _trialDocumentRepository; private readonly IRepository _systemDocumentRepository; private readonly IRepository _systemNoticeRepository; public PersonalWorkstation(IRepository trialRepository, IRepository trialUserRepository, IRepository trialDocumentRepository, IRepository systemDocumentRepository,IRepository systemNoticeRepository) { _trialRepository = trialRepository; _trialUserRepository = trialUserRepository; _trialDocumentRepository = trialDocumentRepository; _systemDocumentRepository = systemDocumentRepository; _systemNoticeRepository = systemNoticeRepository; } /// /// 个人面板 统计值 /// /// public async Task GetBasicStat() { return new PersonalStataDTO() { //正参与的数量 TrialCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? await _trialRepository.CountAsync() : await _trialUserRepository.Where(t => t.UserId == _userInfo.Id).CountAsync(), DeletedCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? await _trialRepository.AsQueryable(true).CountAsync(t => t.IsDeleted) : await _trialUserRepository.AsQueryable(true).Where(t => t.UserId == _userInfo.Id && t.IsDeleted) .CountAsync(), TotalNeedSignTrialDocCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0 : await _trialDocumentRepository.AsQueryable(true) .Where(t => t.Trial.TrialUserList.Any(t => t.UserId == _userInfo.Id)) .Where(t => t.IsDeleted == false || (t.IsDeleted == true && t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) .SelectMany(t => t.NeedConfirmedUserTypeList) .CountAsync(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId), HaveSignedTrialDocCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0 : await _trialDocumentRepository .Where( t => t.Trial.TrialUserList.Any(t => t.UserId == _userInfo.Id)) .Where(t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId)) .SelectMany(t => t.TrialDocConfirmedUserList) .CountAsync(t => t.ConfirmUserId == _userInfo.Id), TotalNeedSignSystemDocCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0 : await _systemDocumentRepository .Where(t => t.IsDeleted == false || (t.IsDeleted == true && t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) .SelectMany(t => t.NeedConfirmedUserTypeList) .CountAsync(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId), HaveSignedSystemDocCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0 : await _systemDocumentRepository .Where(t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId)) .SelectMany(t => t.SystemDocConfirmedUserList) .CountAsync(t => t.ConfirmUserId == _userInfo.Id), TotalApprovalRequiredCount= _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM ? _trialRepository.Where(t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id)).SelectMany(t=>t.TrialSiteSurveyList).Where(t => t.State == TrialSiteSurveyEnum.SPMApproved).Count() : _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM|| _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM ? _trialRepository.Where(t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id)).SelectMany(t => t.TrialSiteSurveyList).Where(t => t.State == TrialSiteSurveyEnum.CRCSubmitted).Count() :0, TotalSystemNoticeCount= _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0:await _systemNoticeRepository.Where(t => t.NoticeUserTypeList.Any(t => t.UserTypeId == _userInfo.UserTypeId) && t.NoticeStateEnum== Domain.Share.Management.SystemNotice_NoticeStateEnum.HavePublished) .CountAsync(), NeedReadSystemNoticeCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin ? 0 : await _systemNoticeRepository.Where(t => t.NoticeUserTypeList.Any(t => t.UserTypeId == _userInfo.UserTypeId) && t.NoticeStateEnum == Domain.Share.Management.SystemNotice_NoticeStateEnum.HavePublished && !t.NoticeUserReadList.Any(t=>t.CreateUserId==_userInfo.Id)) .Where(t => t.EndDate == null || t.EndDate != null && t.EndDate > DateTime.Now) .CountAsync(), }; } /// /// Site 调研 每个项目 需要处理的审批统计 /// /// /// [HttpPost] public async Task> GetSiteSurveyApprovalList(TrialSiteSurveyStatQuery query) { if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM) { return await _trialRepository .Where(t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id)) .WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM, c => c.TrialSiteSurveyList.Where(t => t.State == TrialSiteSurveyEnum.SPMApproved).Count() > 0) .WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM, c => c.TrialSiteSurveyList.Where(t => t.State == TrialSiteSurveyEnum.CRCSubmitted).Count() > 0) .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id }) .OrderByDescending(t => t.ApprovalRequiredCount).ToPagedListAsync(query.PageIndex, query.PageSize, query.SortField, query.Asc); } else { return new PageOutput(query.PageIndex, query.PageSize, 0, new List()); } } /// /// 需要签署文件数量 系统级别的在第一行 /// /// /// [HttpPost] public async Task> GetTrialDocStatList(TrialSiteSurveyStatQuery query) { if (_userInfo.IsAdmin) { return new PageOutput(query.PageIndex, query.PageSize, 0, new List()); } else { var trialDocStat = await _trialRepository .Where(t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id)) .WhereIf(!_userInfo.IsAdmin, c => c.TrialDocumentList.Where(t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) && !t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id)).Count() > 0) .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id, userTypeId = _userInfo.UserTypeId }) .OrderByDescending(t => t.WaitSignCount) .ToPagedListAsync(query.PageIndex, query.PageSize , query.SortField, query.Asc); //var sysDocStat = new DocSignStat() //{ // IsSystemDoc = true, // WaitSignCount = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin // ? 0 // : await _systemDocumentRepository // .Where(t => // t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) && // !t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id)) // .CountAsync() //}; //var list = trialDocStat.CurrentPageData.ToList(); //list.Insert(0, sysDocStat); //trialDocStat.CurrentPageData = list; //trialDocStat.TotalCount++; return trialDocStat; } } } }