zmq 1 rok pred
rodič
commit
5e16de8c8a

+ 30 - 5
src/platform/ZhonTai.Admin/Core/DiTuiHost.cs

@@ -61,7 +61,7 @@ using ZhonTai.DynamicApi;
 using ZhonTai.DynamicApi.Attributes;
 
 namespace ZhonTai.Admin.Core
-{    
+{
     /// <summary>
     /// 宿主应用
     /// </summary>
@@ -204,7 +204,10 @@ namespace ZhonTai.Admin.Core
             //雪花漂移算法
             var idGeneratorOptions = new IdGeneratorOptions(1) { WorkerIdBitLength = 6 };
             _hostAppOptions?.ConfigureIdGenerator?.Invoke(idGeneratorOptions);
-            YitIdHelper.SetIdGenerator(idGeneratorOptions);            
+            YitIdHelper.SetIdGenerator(idGeneratorOptions);
+
+            //权限处理
+            services.AddScoped<IPermissionHandler, PermissionHandler>();
 
             // ClaimType不被更改
             JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
@@ -215,7 +218,13 @@ namespace ZhonTai.Admin.Core
 
             //数据库配置
             var dbConfig = ConfigHelper.Get<DbConfig>("dbconfig", env.EnvironmentName);
-            services.AddSingleton(dbConfig);                        
+            services.AddSingleton(dbConfig);
+
+            //添加数据库
+            if (!_hostAppOptions.CustomInitDb)
+            {
+                services.AddDb(env, _hostAppOptions);
+            }
 
             //上传配置
             var uploadConfig = ConfigHelper.Load("uploadconfig", env.EnvironmentName, true);
@@ -716,7 +725,23 @@ namespace ZhonTai.Admin.Core
             app.UseAuthentication();
 
             //授权
-            app.UseAuthorization();            
+            app.UseAuthorization();
+
+            //登录用户初始化数据权限
+            if (appConfig.Validate.DataPermission)
+            {
+                app.Use(async (ctx, next) =>
+                {
+                    var user = ctx.RequestServices.GetRequiredService<IUser>();
+                    if (user?.Id > 0)
+                    {
+                        var userService = ctx.RequestServices.GetRequiredService<IUserService>();
+                        await userService.GetDataPermissionAsync();
+                    }
+
+                    await next();
+                });
+            }
 
             //配置端点
             app.MapControllers();
@@ -768,4 +793,4 @@ namespace ZhonTai.Admin.Core
             _hostAppOptions?.ConfigurePostMiddleware?.Invoke(hostAppMiddlewareContext);
         }
     }
-}
+}

+ 42 - 1
src/platform/ZhonTai.Admin/Services/Project/Dto/ProjectAddInput.cs

@@ -1,12 +1,53 @@
 using System;
 using System.Collections.Generic;
+using System.Data;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
 namespace ZhonTai.Admin.Services.Project.Dto
 {
-    internal class ProjectAddInput
+    public class ProjectAddInput
     {
+        /// <summary>
+        /// 项目Id
+        /// </summary>
+        public virtual long Id { get; set; }
+        /// <summary>
+        /// 项目名称
+        /// </summary>        
+        public string Name { get; set; }
+        /// <summary>
+        /// 项目图标
+        /// </summary>        
+        public string Logo { get; set; }
+        /// <summary>
+        /// 项目简介
+        /// </summary>        
+        public string Tips { get; set; }
+        /// <summary>
+        /// 最高佣金
+        /// </summary>        
+        public decimal MaxPrice { get; set; }
+        /// <summary>
+        /// 结算周期
+        /// </summary>
+        public int SettleDay { get; set; }
+        /// <summary>
+        /// 视频教程
+        /// </summary>
+        public string VideoUrl { get; set; }        
+        /// <summary>
+        /// 详情
+        /// </summary>
+        public string Detail { get; set; }
+        /// <summary>
+        /// 作业要求
+        /// </summary>
+        public string Works { get; set; }
+        /// <summary>
+        /// 项目价格
+        /// </summary>
+        public List<ProjectPriceAddInput> prices { get; set; }
     }
 }

+ 12 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/ProjectGetOutput.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class ProjectGetOutput:ProjectUpdateInput
+    {
+    }
+}

+ 4 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/ProjectGetPageOutput.cs

@@ -9,6 +9,10 @@ namespace ZhonTai.Admin.Services.Project.Dto
 {
     public class ProjectGetPageOutput
     {
+        /// <summary>
+        /// 项目Id
+        /// </summary>        
+        public long Id { get; set; }
         /// <summary>
         /// 项目名称
         /// </summary>        

+ 24 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/ProjectPriceAddInput.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class ProjectPriceAddInput
+    {
+        /// <summary>
+        /// 项目价格Id
+        /// </summary>
+        public long Id { get; set; }        
+        /// <summary>
+        /// 结算标准
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 价格
+        /// </summary>
+        public decimal Price { get; set; }
+    }
+}

+ 19 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/ProjectUpdateInput.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Validators;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class ProjectUpdateInput:ProjectAddInput
+    {
+        /// <summary>
+        /// 项目Id
+        /// </summary>
+        [Required]        
+        public override long Id { get; set; }
+    }
+}

+ 118 - 5
src/platform/ZhonTai.Admin/Services/Project/ProjectService.cs

@@ -15,6 +15,15 @@ using ZhonTai.Admin.Services.User.Dto;
 using ZhonTai.Admin.Domain.UserRole;
 using ZhonTai.Admin.Domain.Project;
 using ZhonTai.Admin.Services.Project.Dto;
+using ZhonTai.Admin.Core.Attributes;
+using ZhonTai.Admin.Domain.Tenant;
+using ZhonTai.Admin.Domain.TenantPkg;
+using ZhonTai.Admin.Domain.Pkg;
+using ZhonTai.Admin.Repositories;
+using ZhonTai.Admin.Services.Tenant.Dto;
+using System.Linq.Expressions;
+using ZhonTai.Admin.Domain.Org;
+using ZhonTai.Admin.Services.Pkg;
 
 namespace ZhonTai.Admin.Services.Project
 {
@@ -25,7 +34,7 @@ namespace ZhonTai.Admin.Services.Project
     [DynamicApi(Area = AdminConsts.AreaName)]
     public partial class ProjectService : BaseService, IProjectService, IDynamicApi
     {
-        private readonly IProjectRepository _projectRepository ;
+        private readonly IProjectRepository _projectRepository;
         private readonly IProjectPriceRepository _projectPriceRepository;
 
         public ProjectService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository)
@@ -33,6 +42,31 @@ namespace ZhonTai.Admin.Services.Project
             _projectRepository = projectRepository;
             _projectPriceRepository = projectPriceRepository;
         }
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<ProjectGetOutput> GetAsync(long id)
+        {
+            var project = await _projectRepository.Select
+            .WhereDynamic(id)
+            .FirstAsync(a => new ProjectGetOutput
+            {
+                Name = a.Name,
+                Logo = a.Logo,
+                Tips = a.Tips,
+                SettleDay = a.SettleDay,
+                MaxPrice = a.MaxPrice,
+                Works = a.Works,
+                VideoUrl = a.VideoUrl,
+                Detail = a.Detail,
+                Id = a.Id,                
+                prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<ProjectPriceAddInput>()
+            });
+            return project;
+        }
+
         /// <summary>
         /// 查询分页
         /// </summary>
@@ -60,19 +94,98 @@ namespace ZhonTai.Admin.Services.Project
             return data;
         }
         /// <summary>
-        /// 添加项目
+        /// 添加
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
         [HttpPost]
-        public async Task<long> AddAsync(ProjectGetPageInput input)
+        [AdminTransaction]
+        public async Task<long> AddAsync(ProjectAddInput input)
         {
 
             //添加项目
+            ProjectEntity entity = Mapper.Map<ProjectEntity>(input);
+            ProjectEntity project = await _projectRepository.InsertAsync(entity);
+            long projectId = project.Id;
+
+            //添加项目价格            
+            var prices = input.prices.Select(m => new ProjectPriceEntity
+            {
+                ProjectId = projectId,
+                Name=m.Name,
+                Price=m.Price
+            }).ToList();
+
+            await _projectPriceRepository.InsertAsync(prices);
+
+            return 1;
+        }
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task UpdateAsync(ProjectUpdateInput input)
+        {
+
+            var project = await _projectRepository.GetAsync(input.Id);
+            if (!(project?.Id > 0))
+            {
+                throw ResultOutput.Exception("项目不存在");
+            }
+
+            //更新项目
+            await _projectRepository.UpdateDiy.SetSource(
+            new ProjectEntity()
+            {
+                Id = project.Id,
+                Name = input.Name,
+                Logo = input.Logo,
+                Tips = input.Tips,
+                SettleDay = input.SettleDay,
+                MaxPrice = input.MaxPrice,
+                Works = input.Works,
+                VideoUrl = input.VideoUrl,
+                Detail = input.Detail,
+            })
+            .UpdateColumns(a => new { a.Name, a.Logo, a.Tips, a.SettleDay, a.MaxPrice, a.VideoUrl, a.Detail, a.ModifiedTime }).ExecuteAffrowsAsync();
+
+            //删除项目价格
+            var PriceIds = _projectPriceRepository.Select.Where(m => m.ProjectId == project.Id).ToList(m => m.Id);
+            var inputPrice = input.prices.Where(m => m.Id > 0).ToList();
+            var inputPriceIds = inputPrice.Select(m => m.Id).ToList();
+            var deletePriceIds = PriceIds.Except(inputPriceIds).ToList();
+            if (deletePriceIds.Count() > 0)
+            {
+                await _projectPriceRepository.SoftDeleteAsync(a => deletePriceIds.Contains(a.Id));
+            }
+            //新增项目价格
+            var addPriceIds = input.prices.Where(m => m.Id <= 0).ToList();
+            if (addPriceIds.Count() > 0)
+            {
+                var list = addPriceIds.Select(m => new ProjectPriceEntity
+                {
+                    ProjectId = project.Id,
+                    Name = m.Name,
+                    Price = m.Price
+                }).ToList();
+                await _projectPriceRepository.InsertAsync(list);
+            }
+            //更新项目价格
+            foreach (var item in inputPrice)
+            {
+                await _projectPriceRepository.UpdateDiy.SetSource(
+                    new ProjectPriceEntity()
+                    {
+                        Id = item.Id,
+                        Name = item.Name,
+                        Price = item.Price
+                    })
+                .UpdateColumns(a => new { a.Name, a.Price, a.ModifiedTime }).ExecuteAffrowsAsync();
+            }
+
 
-            //添加项目价格
 
-            return 0;
         }
     }
 }

+ 91 - 2
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -6657,6 +6657,56 @@
             映射配置
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.Id">
+            <summary>
+            项目Id
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.Name">
+            <summary>
+            项目名称
+            </summary>        
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.Logo">
+            <summary>
+            项目图标
+            </summary>        
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.Tips">
+            <summary>
+            项目简介
+            </summary>        
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.MaxPrice">
+            <summary>
+            最高佣金
+            </summary>        
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.SettleDay">
+            <summary>
+            结算周期
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.VideoUrl">
+            <summary>
+            视频教程
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.Detail">
+            <summary>
+            详情
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.Works">
+            <summary>
+            作业要求
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.prices">
+            <summary>
+            项目价格
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectGetPageInput.Status">
             <summary>
             项目状态   1待上架 2上架 3下架 4暂停
@@ -6667,6 +6717,11 @@
             关键字 项目标题
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectGetPageOutput.Id">
+            <summary>
+            项目Id
+            </summary>        
+        </member>
         <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectGetPageOutput.Name">
             <summary>
             项目名称
@@ -6687,11 +6742,38 @@
             状态 0待上架 1上架 2下架 3暂停
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectPriceAddInput.Id">
+            <summary>
+            项目价格Id
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectPriceAddInput.Name">
+            <summary>
+            结算标准
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectPriceAddInput.Price">
+            <summary>
+            价格
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectUpdateInput.Id">
+            <summary>
+            项目Id
+            </summary>
+        </member>
         <member name="T:ZhonTai.Admin.Services.Project.ProjectService">
             <summary>
             项目服务
             </summary>
         </member>
+        <member name="M:ZhonTai.Admin.Services.Project.ProjectService.GetAsync(System.Int64)">
+            <summary>
+            查询
+            </summary>
+            <param name="id"></param>
+            <returns></returns>
+        </member>
         <member name="M:ZhonTai.Admin.Services.Project.ProjectService.GetPageAsync(ZhonTai.Admin.Core.Dto.PageInput{ZhonTai.Admin.Services.Project.Dto.ProjectGetPageInput})">
             <summary>
             查询分页
@@ -6699,9 +6781,16 @@
             <param name="input"></param>
             <returns></returns>
         </member>
-        <member name="M:ZhonTai.Admin.Services.Project.ProjectService.AddAsync(ZhonTai.Admin.Services.Project.Dto.ProjectGetPageInput)">
+        <member name="M:ZhonTai.Admin.Services.Project.ProjectService.AddAsync(ZhonTai.Admin.Services.Project.Dto.ProjectAddInput)">
+            <summary>
+            添加
+            </summary>
+            <param name="input"></param>
+            <returns></returns>
+        </member>
+        <member name="M:ZhonTai.Admin.Services.Project.ProjectService.UpdateAsync(ZhonTai.Admin.Services.Project.Dto.ProjectUpdateInput)">
             <summary>
-            添加项目
+            修改
             </summary>
             <param name="input"></param>
             <returns></returns>