李昊 4 years ago
parent
commit
d3fd7e9b25

+ 49 - 1
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminOrganizationController.cs

@@ -2,7 +2,9 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using GxPress.Common.Page;
 using GxPress.Repository.Interface.Organization;
+using GxPress.Request.OrganizationUser;
 using GxPress.Result.Organization;
+using GxPress.Service.Interface.OrganizationUser;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 
@@ -14,10 +16,56 @@ namespace GxPress.Api.AdminControllers
     public class AdminOrganizationController : Controller
     {
         private readonly IOrganizationRepository repository;
-        public AdminOrganizationController(IOrganizationRepository repository)
+        private readonly IOrganizationUserService service;
+
+        private readonly IOrganizationUserRepository organizationUserRepository;
+        public AdminOrganizationController(IOrganizationRepository repository, IOrganizationUserService service, IOrganizationUserRepository organizationUserRepository)
         {
             this.repository = repository;
+            this.service = service;
+            this.organizationUserRepository = organizationUserRepository;
+        }
+        /// <summary>
+        /// 添加机构用户
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        [HttpPost("add-user")]
+        public async Task<bool> InsertOrganizationUserAsync(Entity.tede2.Organization.OrganizationUser model)
+        {
+            if (model.OrganizationId == 0)
+                throw new Common.Exceptions.BusinessException("机构ID必填");
+            if (string.IsNullOrEmpty(model.LoginAccountNumber))
+                throw new Common.Exceptions.BusinessException("登陆账号必填");
+            if (string.IsNullOrEmpty(model.UserName))
+                throw new Common.Exceptions.BusinessException("用户名必填");
+            if (string.IsNullOrEmpty(model.Phone))
+                throw new Common.Exceptions.BusinessException("手机号码必填");
+            if (model.Phone.Length != 11)
+                throw new Common.Exceptions.BusinessException("手机号码有误");
+            return await service.InsertAsync(model);
+        }
+        /// <summary>
+        /// 机构用户列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("user-list")]
+        public async Task<PagedList<Entity.tede2.Organization.OrganizationUser>> GetSearchAllAsync(OrganizationUserSearchRequest request)
+        {
+            return await organizationUserRepository.GetSearchAllAsync(request);
+        }
+        /// <summary>
+        ///  机构用户修改
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPut("user-updat")]
+        public async Task<bool> UpdateAsync(OrganizationUserUpdateRequest request)
+        {
+            return await organizationUserRepository.UpdateAsync(request);
         }
+
         /// <summary>
         ///  机构列表
         /// </summary>

File diff suppressed because it is too large
+ 5 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminUtilsController.cs


+ 12 - 0
gx_api/GxPress/Model/GxPress.Entity/User.cs

@@ -24,8 +24,20 @@ namespace GxPress.Entity
         /// </summary>
         [DataColumn]
         public string Name { get; set; }
+        /// <summary>
+        /// 登陆名
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string LoginAccountNumber { get; set; }
 
         /// <summary>
+        /// 机构id
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int OrganizationId { get; set; }
+        /// <summary>
         /// 头像地址
         /// </summary>
         [DataColumn]

+ 97 - 0
gx_api/GxPress/Model/GxPress.Entity/tede2/Organization/OrganizationUser.cs

@@ -0,0 +1,97 @@
+using System;
+using Datory.Annotations;
+
+namespace GxPress.Entity.tede2.Organization
+{
+    /// <summary>
+    /// 机构
+    /// </summary>
+    [DataTable("tede_organization_user")]
+    public class OrganizationUser : Datory.Entity
+    {
+        /// <summary>
+        /// 登陆账号
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string LoginAccountNumber { get; set; }
+        /// <summary>
+        /// 用户名
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string UserName { get; set; }
+        /// <summary>
+        /// 手机
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string Phone { get; set; }
+        /// <summary>
+        /// 登陆时间
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public DateTime LoginTime { get; set; }
+        /// <summary>
+        ///设备 1pc电脑 2 安卓手机 3 IOS手机 4其他
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int FacilityType { get; set; }
+        /// <summary>
+        /// mac地址
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string MacAddress { get; set; }
+        /// <summary>
+        /// 开通状态 1 立即 2定时开通
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int OpenStatus { get; set; }
+        /// <summary>
+        /// 启用时间
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public DateTime OpenTime { get; set; }
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public DateTime BeginTime { get; set; }
+        /// <summary>
+        /// 结束时间
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public DateTime EndTime { get; set; }
+        /// <summary>
+        /// 是否禁用
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public bool IsDisable { get; set; }
+        /// <summary>
+        /// 是否到期关闭
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public bool IsClose { get; set; }
+        /// <summary>
+        /// 机构id
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int OrganizationId { get; set; }
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int UserId { get; set; }
+    }
+}

+ 6 - 1
gx_api/GxPress/Model/GxPress.EnumConst/VipTypeConst.cs

@@ -20,11 +20,16 @@ namespace GxPress.EnumConst
     public enum VipPortTypeConst
     {
         //客户端
+        [Description("PC电脑")]
         Pc = 1,
         //Android手机
+        [Description("安卓手机")]
         Android = 2,
         //苹果手机
-        Ios = 3
+        [Description("ios手机")]
+        Ios = 3,
+        [Description("其他")]
+        Other = 4
     }
     /// <summary>
     /// 支付方式

+ 115 - 0
gx_api/GxPress/Model/GxPress.Request/OrganizationUser/OrganizationUserRequest.cs

@@ -0,0 +1,115 @@
+using System;
+
+namespace GxPress.Request.OrganizationUser
+{
+    public class OrganizationUserRequest
+    {
+
+    }
+    /// <summary>
+    /// 搜索
+    /// </summary>
+    public class OrganizationUserSearchRequest : Common.Page.PageParameter
+    {
+        /// <summary>
+        /// 机构id
+        /// </summary>
+        /// <value></value>
+
+        public int OrganizationId { get; set; }
+        /// <summary>
+        /// 搜索字段
+        /// </summary>
+        /// <value></value>
+        public string KeyWord { get; set; }
+    }
+    /// <summary>
+    /// 修改
+    /// </summary>
+    public class OrganizationUserUpdateRequest
+    {
+        /// <summary>
+        /// ID
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 登陆账号
+        /// </summary>
+        /// <value></value>
+
+        public string LoginAccountNumber { get; set; }
+        /// <summary>
+        /// 用户名
+        /// </summary>
+        /// <value></value>
+
+        public string UserName { get; set; }
+        /// <summary>
+        /// 手机
+        /// </summary>
+        /// <value></value>
+
+        public string Phone { get; set; }
+        /// <summary>
+        /// 登陆时间
+        /// </summary>
+        /// <value></value>
+
+        public DateTime LoginTime { get; set; }
+        /// <summary>
+        ///设备 1pc电脑 2 安卓手机 3 IOS手机 4其他
+        /// </summary>
+        /// <value></value>
+
+        public int FacilityType { get; set; }
+        /// <summary>
+        /// mac地址
+        /// </summary>
+        /// <value></value>
+
+        public string MacAddress { get; set; }
+        /// <summary>
+        /// 开通状态 1 立即 2定时开通
+        /// </summary>
+        /// <value></value>
+
+        public int OpenStatus { get; set; }
+        /// <summary>
+        /// 启用时间
+        /// </summary>
+        /// <value></value>
+
+        public string OpenTime { get; set; }
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        /// <value></value>
+
+        public string BeginTime { get; set; }
+        /// <summary>
+        /// 结束时间
+        /// </summary>
+        /// <value></value>
+
+        public string EndTime { get; set; }
+        /// <summary>
+        /// 是否禁用 1设置 2取消
+        /// </summary>
+        /// <value></value>
+
+        public int IsDisable { get; set; }
+        /// <summary>
+        /// 是否到期关闭 1设置 2取消
+        /// </summary>
+        /// <value></value>
+
+        public int IsClose { get; set; }
+        /// <summary>
+        /// 机构id
+        /// </summary>
+        /// <value></value>
+
+        public int OrganizationId { get; set; }
+    }
+}

+ 5 - 0
gx_api/GxPress/Model/GxPress.Request/User/UserRequest.cs

@@ -233,5 +233,10 @@ namespace GxPress.Request.User
         /// </summary>
         /// <value></value>
         public int IsFreeze { get; set; }
+        /// <summary>
+        /// 是否 VIP 1是 2否 0 全部
+        /// </summary>
+        /// <value></value>
+        public int IsVip { get; set; }
     }
 }

+ 89 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Organization/OrganizationUserRepository.cs

@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using AutoMapper;
+using Datory;
+using GxPress.Common.AppOptions;
+using GxPress.Common.Page;
+using GxPress.Common.Tools;
+using GxPress.Repository.Interface.Organization;
+using GxPress.Request.OrganizationUser;
+using Microsoft.Extensions.Options;
+
+namespace GxPress.Repository.Implement.Organization
+{
+    public class OrganizationUserRepository : IOrganizationUserRepository
+    {
+        private readonly Repository<Entity.tede2.Organization.OrganizationUser> _repository;
+        private readonly IMapper _mapper;
+        private readonly string _connectionString;
+        private readonly string _databaseTypestr;
+        public OrganizationUserRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
+        {
+            _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
+            _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
+            var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
+            var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
+            _repository = new Repository<Entity.tede2.Organization.OrganizationUser>(database);
+            _mapper = mapper;
+        }
+        public IDatabase Database => _repository.Database;
+        public string TableName => _repository.TableName;
+        public List<TableColumn> TableColumns => _repository.TableColumns;
+
+        public async Task<PagedList<Entity.tede2.Organization.OrganizationUser>> GetSearchAllAsync(OrganizationUserSearchRequest request)
+        {
+            var query = Q.NewQuery();
+            if (!string.IsNullOrEmpty(request.KeyWord))
+            {
+                query.OrWhereLike(nameof(Entity.tede2.Organization.OrganizationUser.UserName), $"%request.KeyWord%");
+                query.OrWhereLike(nameof(Entity.tede2.Organization.OrganizationUser.LoginAccountNumber), $"%request.KeyWord%");
+            }
+            if (request.OrganizationId > 0)
+                query.Where(nameof(Entity.tede2.Organization.OrganizationUser.OrganizationId), request.OrganizationId);
+            var result = new PagedList<Entity.tede2.Organization.OrganizationUser>();
+            result.Total = await _repository.CountAsync(query);
+            result.Items = await _repository.GetAllAsync(query);
+            return result;
+        }
+        public async Task<bool> UpdateAsync(OrganizationUserUpdateRequest request)
+        {
+            var model = await _repository.GetAsync(request.Id);
+            if (!string.IsNullOrEmpty(request.LoginAccountNumber))
+                model.LoginAccountNumber = request.LoginAccountNumber;
+            if (!string.IsNullOrEmpty(request.UserName))
+                model.UserName = request.UserName;
+            if (!string.IsNullOrEmpty(request.Phone))
+                model.Phone = request.Phone;
+            if (!string.IsNullOrEmpty(request.MacAddress))
+                model.MacAddress = request.MacAddress;
+            if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
+            {
+                if (DateTime.TryParse(request.BeginTime, out var beginTme) && DateTime.TryParse(request.EndTime, out var endTime))
+                {
+                    model.BeginTime = beginTme;
+                    model.EndTime = endTime;
+                }
+            }
+            if (!string.IsNullOrEmpty(request.OpenTime))
+            {
+                if (DateTime.TryParse(request.BeginTime, out var OpenTime))
+                    model.OpenTime = OpenTime;
+            }
+            if (request.OpenStatus > 0)
+                model.OpenStatus = request.OpenStatus;
+            if (request.IsClose > 0)
+                model.IsClose = request.IsClose == 1;
+            if (request.IsDisable > 0)
+                model.IsDisable = request.IsDisable == 1;
+            if (request.OrganizationId > 0)
+                model.OrganizationId = request.OrganizationId;
+            return await _repository.UpdateAsync(model);
+        }
+
+        public async Task<bool> InsertAsync(Entity.tede2.Organization.OrganizationUser model)
+        {
+            return await _repository.InsertAsync(model) > 0;
+        }
+    }
+}

+ 2 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/UserRepository.cs

@@ -903,6 +903,8 @@ namespace GxPress.Repository.Implement
                 query.Where(nameof(User.IsDisable), request.IsDisable == 1);
             if (request.IsFreeze > 0)
                 query.Where(nameof(User.IsFreeze), request.IsFreeze == 1);
+            if (request.IsVip > 0)
+                query.Where(nameof(User.IsVip), request.IsVip == 1);
             result.Total = await _repository.CountAsync(query);
             var items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
             result.Items = items.Select(n => _mapper.Map<UserDetail>(n));

+ 15 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Organization/IOrganizationUserRepository.cs

@@ -0,0 +1,15 @@
+using System.Threading.Tasks;
+using Datory;
+using GxPress.Common.Page;
+using GxPress.Request.OrganizationUser;
+
+namespace GxPress.Repository.Interface.Organization
+{
+    public interface IOrganizationUserRepository : IRepository
+    {
+        Task<PagedList<Entity.tede2.Organization.OrganizationUser>> GetSearchAllAsync(OrganizationUserSearchRequest request);
+        Task<bool> UpdateAsync(OrganizationUserUpdateRequest request);
+
+        Task<bool> InsertAsync(Entity.tede2.Organization.OrganizationUser model);
+    }
+}

+ 34 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/OrganizationUser/OrganizationUserService.cs

@@ -0,0 +1,34 @@
+using System.Threading.Tasks;
+using GxPress.Repository.Interface;
+using GxPress.Repository.Interface.Organization;
+using GxPress.Service.Interface.OrganizationUser;
+
+namespace GxPress.Service.Implement.OrganizationUser
+{
+    public class OrganizationUserService : IOrganizationUserService
+    {
+        private readonly IOrganizationUserRepository organizationUserRepository;
+        private readonly IUserRepository userRepository;
+        public OrganizationUserService(IOrganizationUserRepository organizationUserRepository, IUserRepository userRepository)
+        {
+            this.organizationUserRepository = organizationUserRepository;
+            this.userRepository = userRepository;
+        }
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        public async Task<bool> InsertAsync(Entity.tede2.Organization.OrganizationUser model)
+        {
+            var user = new Entity.User();
+            user.LoginAccountNumber = model.LoginAccountNumber;
+            user.Name = model.UserName;
+            user.Phone = model.Phone;
+            user.OrganizationId = model.OrganizationId;
+            var userId = await userRepository.InsertAsync(user);
+            model.UserId = userId;
+            return await organizationUserRepository.InsertAsync(model);
+        }
+    }
+}

+ 14 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/OrganizationUser/IOrganizationUserService.cs

@@ -0,0 +1,14 @@
+using System.Threading.Tasks;
+
+namespace GxPress.Service.Interface.OrganizationUser
+{
+    public interface IOrganizationUserService : IService
+    {
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        Task<bool> InsertAsync(Entity.tede2.Organization.OrganizationUser model);
+    }
+}