zhengyuxuan
2025-03-19 82831a86d529817e51f5b6e3cec636d21cef3c9b
LifePayment/LifePayment.Application/User/UserRoleService.cs
@@ -1,4 +1,5 @@
using LifePayment.Application.Contracts;
using LifePayment.Domain;
using LifePayment.Domain.Models;
using Microsoft.EntityFrameworkCore;
using System;
@@ -8,6 +9,7 @@
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Z.EntityFramework.Plus;
using ZeroD.Util;
namespace HumanResourcesServices.Application
@@ -16,21 +18,27 @@
    {
        private readonly IRepository<User, Guid> _userRepository;
        private readonly IRepository<Role, Guid> _roleRepository;
        private readonly IRepository<LifePayChannles, Guid> _channleRepository;
        private readonly IRepository<UserRole, Guid> _userRoleRep;
        private readonly IRepository<UserChannle, Guid> _userChannleRep;
        public UserRoleService(
               IRepository<User, Guid> userRepository,
               IRepository<Role, Guid> roleRepository,
               IRepository<UserRole, Guid> userRoleRep)
               IRepository<LifePayChannles, Guid> channleRepository,
               IRepository<UserRole, Guid> userRoleRep,
               IRepository<UserChannle, Guid> userChannleRep)
        {
            _userRepository = userRepository;
            _roleRepository = roleRepository;
            _channleRepository = channleRepository;
            _userRoleRep = userRoleRep;
            _userChannleRep = userChannleRep;
        }
        public async Task<PageOutput<UserDto>> GetBackClientUsers(GetBackClientUsersInput input)
        {
            var query = _userRepository.Where(s => s.ClientId == Constant.ClientType.Back).Include(i => i.UserRoles).Select(u => new UserDto
            var query = _userRepository.Where(s => s.ClientId == Constant.ClientType.Back).Include(i => i.UserRoles).Include(i => i.UserChannle).Select(u => new UserDto
            {
                Id = u.Id,
                UserName = u.UserName,
@@ -43,6 +51,13 @@
                        {
                            Id = r.Id,
                            Name = r.Name,
                        },
                Channles = from uc in u.UserChannle
                           from c in _channleRepository.Where(s => s.ChannlesNum == uc.ChannleId)
                        select new UserChannleDto
                        {
                            Id = c.ChannlesNum,
                            Name = c.ChannlesName,
                        },
                Remark = u.Remark,
                CompanyOrgId = u.CompanyOrgId,
@@ -77,6 +92,21 @@
            entity.Remark = input.Remark;
            entity.DepartmentOrgId = input.DepartmentOrgId;
            entity.CompanyOrgId = input.CompanyOrgId;
            var userchannle = await _userChannleRep.Where(s => s.UserId == input.Id).DeleteAsync();
            List<UserChannle> userChannles = new List<UserChannle>();
            foreach (var item in input.ChannlesId)
            {
                userChannles.Add(new UserChannle()
                {
                    Id = Guid.NewGuid(),
                    ChannleId = item,
                    UserId = entity.Id
                });
            }
            await _userChannleRep.InsertManyAsync(userChannles);
            return Constant.SUCCESS;
        }