This commit is contained in:
mmrbnjd
2025-07-07 22:04:07 +03:30
parent 2432ab293f
commit 1924c88e7a
8 changed files with 94 additions and 10 deletions

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hushian.Application.Contracts
{
interface IconversationAssistant
{
}
}

View File

@@ -27,7 +27,11 @@ namespace Hushian.Application.Services
private readonly IGenericRepository<User> _UserRepository;
private readonly IGenericRepository<Exper> _ExperRepository;
private readonly VerificationService _verificationService;
public AuthService(IOptions<JwtSettings> jwtSettings, IGenericRepository<Company> companyRepository, IGenericRepository<User> userRepository, IGenericRepository<Exper> experRepository, VerificationService verificationService)
public AuthService(IOptions<JwtSettings> jwtSettings
, IGenericRepository<Company> companyRepository
, IGenericRepository<User> userRepository
, IGenericRepository<Exper> experRepository
, VerificationService verificationService)
{
_jwtSettings = jwtSettings.Value;
_CompanyRepository = companyRepository;
@@ -119,8 +123,6 @@ namespace Hushian.Application.Services
public async Task<JwtSecurityToken> GenerateToken(string UserName, int userId)
{
var claims = new[]
{
new Claim(JwtRegisteredClaimNames.Sub,UserName),

View File

@@ -22,6 +22,13 @@ namespace Hushian.Application.Services
private readonly VerificationService _VerificationService;
private readonly IMapper _mapper;
public CompanyService(IGenericRepository<Company> companyRepository, VerificationService verificationService, IMapper mapper)
{
_CompanyRepository = companyRepository;
_VerificationService = verificationService;
_mapper = mapper;
}
public async Task<ResponseBase<int>> RegisterCompany(RegisterCompanyDto dto)
{
ResponseBase<int> Response = new();
@@ -197,6 +204,8 @@ namespace Hushian.Application.Services
}
public async Task<bool> AnyCompany(int CompanyID)
=>await _CompanyRepository.Get().AnyAsync(a=>a.ID==CompanyID);
public async Task<bool> AllowBot(int CompanyID)
=> await _CompanyRepository.Get().AnyAsync(a => a.ID == CompanyID && a.allowBot);
private async Task<int> Verifi(string Mobile) => await _VerificationService.GenerateCodeByPhoneNumberConfirmed(Mobile);
}

View File

@@ -18,11 +18,25 @@ namespace Hushian.Application.Services
{
private readonly IGenericRepository<Conversation> _ConversationRepository;
private readonly IGenericRepository<ConversationResponse> _ConversationResponseRepository;
private readonly IMapper _mapper;
private readonly CompanyService _companyService;
private readonly UserService _userService;
private readonly GroupService _groupService;
private readonly ExperService _experService;
public ConversationService(
IGenericRepository<Conversation> conversationRepository
, IGenericRepository<ConversationResponse> conversationResponseRepository
, CompanyService companyService, UserService userService, GroupService groupService
, ExperService experService)
{
_ConversationRepository = conversationRepository;
_ConversationResponseRepository = conversationResponseRepository;
_companyService = companyService;
_userService = userService;
_groupService = groupService;
_experService = experService;
}
public async Task<ResponseBase<int>> NewConversation(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
{
var Response = new ResponseBase<int>();
@@ -30,9 +44,18 @@ namespace Hushian.Application.Services
{
if (await _userService.AnyUser(dto.UserID))
{
if (type == ConversationType.Bot)
{
if (!await _companyService.AllowBot(dto.CompanyID))
{
Response.Errors.Add("دستیار گفتگو هوشمند برای این شرکت در دسترس نمی باشد");
return Response;
}
}
if (!dto.GroupID.HasValue || (dto.GroupID.HasValue
&& await _groupService.AnyGroup(dto.GroupID.Value)
&& await _groupService.CHeckGroupMemberCompany(dto.GroupID.Value, dto.CompanyID)))
&& await _groupService.AnyGroup(dto.GroupID.Value)
&& await _groupService.CHeckGroupMemberCompany(dto.GroupID.Value, dto.CompanyID)))
{
Conversation conversation = new Conversation()
{
@@ -46,6 +69,8 @@ namespace Hushian.Application.Services
}
else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
}
else Response.Errors.Add("شناسه کاربر یافت نشد");
@@ -118,7 +143,7 @@ namespace Hushian.Application.Services
=> await _ConversationRepository.Get()
.Include(inc => inc.Group)
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
.Where(w => w.ConversationResponses.Any(a=>a.ExperID==ExperID) && w.Status==ConversationStatus.Finished)
.Where(w => w.ConversationResponses.Any(a => a.ExperID == ExperID) && w.Status == ConversationStatus.Finished)
.Select(s => new Read_ConversationDto()
{
ExperID = s.ConversationResponses.Last().ExperID,
@@ -177,5 +202,19 @@ namespace Hushian.Application.Services
UserFullName = s.User.FullName
}).ToListAsync();
public async Task<bool> FinishConversation(int ConversationID)
{
var convModel = await _ConversationRepository.Get()
.Include(inc => inc.ConversationResponses)
.FirstOrDefaultAsync(w => w.ID == ConversationID);
if (convModel != null && convModel.Status != ConversationStatus.Finished)
{
convModel.Status = ConversationStatus.Finished;
return await _ConversationRepository.UPDATEBool(convModel);
}
return true;
}
}
}

View File

@@ -16,10 +16,17 @@ namespace Hushian.Application.Services
{
public class ExperService
{
private readonly IGenericRepository<Company> _CompanyRepository;
private readonly IGenericRepository<Exper> _ExperRepository;
private readonly VerificationService _VerificationService;
private readonly IMapper _mapper;
public ExperService(IGenericRepository<Exper> experRepository, VerificationService verificationService, IMapper mapper)
{
_ExperRepository = experRepository;
_VerificationService = verificationService;
_mapper = mapper;
}
public async Task<ResponseBase<bool>> ADDExper(ADD_ExperDto dto, int CompanyID)
{
var Response = new ResponseBase<bool>();

View File

@@ -20,6 +20,17 @@ namespace Hushian.Application.Services
private readonly IGenericRepository<ExperGroup> _EGRepository;
private readonly IMapper _mapper;
private readonly ExperService _experService;
public GroupService(IGenericRepository<Group> groupRepository
, IGenericRepository<ExperGroup> eGRepository
, IMapper mapper, ExperService experService)
{
_GroupRepository = groupRepository;
_EGRepository = eGRepository;
_mapper = mapper;
_experService = experService;
}
public async Task<ResponseBase<bool>> NewGroup(ADD_GroupDto model, int CompanyID)
{
ResponseBase<bool> Response = new();

View File

@@ -27,7 +27,12 @@ namespace Hushian.Application.Services
private readonly IGenericRepository<User> _UserRepository;
private readonly AuthService _authService;
public VerificationService(IGenericRepository<VerificationCode> verificationCodeRepository, IMessageSender messageSender, IGenericRepository<User> userRepository, AuthService authService, IGenericRepository<Company> companyRepository, IGenericRepository<Exper> experRepository)
public VerificationService(IGenericRepository<VerificationCode> verificationCodeRepository
, IMessageSender messageSender
, IGenericRepository<User> userRepository
, AuthService authService
, IGenericRepository<Company> companyRepository
, IGenericRepository<Exper> experRepository)
{
_VerificationCodeRepository = verificationCodeRepository;
_messageSender = messageSender;