Compare commits
3 Commits
134fac97e3
...
dc9e5a783d
| Author | SHA1 | Date |
|---|---|---|
|
|
dc9e5a783d | |
|
|
7ef608bcc4 | |
|
|
2a6ec19aa6 |
|
|
@ -0,0 +1,216 @@
|
|||
using OpenAuth.App.BaseApp.Base;
|
||||
using OpenAuth.Repository;
|
||||
using Models;
|
||||
using OpenAuth.App.Interface;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.BaseApp.DmModuleManager.Response;
|
||||
using OpenAuth.App.BaseApp.DmModuleManager.Request;
|
||||
|
||||
namespace OpenAuth.App.BaseApp.DmModuleManager
|
||||
{
|
||||
public class DmModuleApp : SqlSugarBaseApp<DmModule, SugarDbContext>
|
||||
{
|
||||
private ISqlSugarClient client;
|
||||
|
||||
#region 构造函数
|
||||
public DmModuleApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<DmModule> repository, IAuth auth, ISqlSugarClient sqlSugarClient) : base(unitWork, repository, auth)
|
||||
{
|
||||
this.client = sqlSugarClient;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 数据查询
|
||||
/// <summary>
|
||||
/// 分页查询模板信息
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<PageInfo<List<DmModule>>>> LoadModulePageInfo(PageReq request)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
|
||||
var table = await base.Repository.AsQueryable()
|
||||
.WhereIF(!string.IsNullOrEmpty(request.key), u => u.ModuleName.Contains(request.key) || u.Description.Contains(request.key))
|
||||
.OrderByDescending(u => u.CreateTime)
|
||||
.ToPageListAsync(request.page, request.limit, totalNumber);
|
||||
|
||||
return new Response<PageInfo<List<DmModule>>>()
|
||||
{
|
||||
Result = new PageInfo<List<DmModule>>
|
||||
{
|
||||
Items = table,
|
||||
Total = totalNumber
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有模板信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<List<DmModule>>> LoadAll()
|
||||
{
|
||||
var table = await base.Repository.AsQueryable()
|
||||
.OrderByDescending(u => u.CreateTime)
|
||||
.ToListAsync();
|
||||
|
||||
return new Response<List<DmModule>>()
|
||||
{
|
||||
Result = table
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模板id获取字段列表
|
||||
/// </summary>
|
||||
/// <param name="id">模板id</param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<List<DmModulecolumn>>> LoadCloumsById(string id)
|
||||
{
|
||||
var table = await base.Repository.AsSugarClient().Queryable<DmModulecolumn>()
|
||||
.Where(r => r.ModuleId == id)
|
||||
.OrderByDescending(r => r.Sort)
|
||||
.ToListAsync();
|
||||
|
||||
return new Response<List<DmModulecolumn>>()
|
||||
{
|
||||
Result = table
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模板详情信息查询
|
||||
/// </summary>
|
||||
/// <param name="id">模板id</param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<DmDetailRes>> LoadModuleDetailInfo(string id)
|
||||
{
|
||||
var table = await base.Repository.AsQueryable()
|
||||
.Where(r => r.Id == id)
|
||||
.Select(r => new DmDetailRes
|
||||
{
|
||||
Id = r.Id,
|
||||
ModuleName = r.ModuleName,
|
||||
Description = r.Description,
|
||||
CreateTime = r.CreateTime,
|
||||
CreateUserId = r.CreateUserId,
|
||||
CreateUserName = r.CreateUserName,
|
||||
Cloums = SqlFunc.Subqueryable<DmModulecolumn>().Where(a => a.ModuleId == r.Id).ToList()
|
||||
}).FirstAsync();
|
||||
|
||||
return new Response<DmDetailRes>()
|
||||
{
|
||||
Result = table
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 增删改
|
||||
/// <summary>
|
||||
/// 添加或者修改数据
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public Response<bool> AddOrUpdate(AddorUpdateModuleReq request)
|
||||
{
|
||||
//查询当前登录用户信息
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
using (var uow = base.UnitWork.CreateContext())
|
||||
{
|
||||
var module = request.Module;
|
||||
if (string.IsNullOrEmpty(module.Id))
|
||||
{
|
||||
if (uow.DmModule.IsAny(u => u.ModuleName == module.ModuleName))
|
||||
{
|
||||
throw new Exception("模板名称已存在");
|
||||
}
|
||||
module.Id = Guid.NewGuid().ToString();
|
||||
module.CreateTime = DateTime.Now;
|
||||
module.CreateUserId = user.Id.ToString();
|
||||
module.CreateUserName = user.Name;
|
||||
|
||||
List<DmModulecolumn> cloum = new List<DmModulecolumn>();
|
||||
foreach (var item in request.Cloums)
|
||||
{
|
||||
DmModulecolumn cl = new DmModulecolumn();
|
||||
cl.Id = Guid.NewGuid().ToString();
|
||||
cl.ModuleId = module.Id;
|
||||
cl.Description = item.Description;
|
||||
cl.Name = item.Name;
|
||||
cl.Description = item.Description;
|
||||
cl.Sort = item.Sort;
|
||||
cloum.Add(cl);
|
||||
}
|
||||
|
||||
uow.DmModule.Insert(module);
|
||||
uow.DmModulecolumn.InsertRange(cloum);
|
||||
}
|
||||
else
|
||||
{
|
||||
//判断模板名称是否重复
|
||||
if (uow.DmModule.IsAny(u => u.ModuleName == module.ModuleName && u.Id != module.Id))
|
||||
{
|
||||
throw new Exception("模板名称已存在");
|
||||
}
|
||||
//更新模板信息
|
||||
uow.DmModule.Update(u => new DmModule
|
||||
{
|
||||
ModuleName = module.ModuleName,
|
||||
Description = module.Description
|
||||
}, u => u.Id == module.Id);
|
||||
|
||||
//删除模板原有字段
|
||||
uow.DmModulecolumn.Delete(u=>u.ModuleId==module.Id);
|
||||
//添加模板新字段
|
||||
List<DmModulecolumn> cloum = new List<DmModulecolumn>();
|
||||
foreach (var item in request.Cloums)
|
||||
{
|
||||
DmModulecolumn cl = new DmModulecolumn();
|
||||
cl.Id = Guid.NewGuid().ToString();
|
||||
cl.ModuleId = module.Id;
|
||||
cl.Description = item.Description;
|
||||
cl.Name = item.Name;
|
||||
cl.Description = item.Description;
|
||||
cl.Sort = item.Sort;
|
||||
cloum.Add(cl);
|
||||
}
|
||||
uow.DmModulecolumn.InsertRange(cloum);
|
||||
}
|
||||
|
||||
var flag = uow.Commit();
|
||||
|
||||
return new Response<bool>
|
||||
{
|
||||
Result = flag,
|
||||
Message = flag == true ? "success" : "error"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据选中id删除模板
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public Response<bool> DeleteModule(string[] ids)
|
||||
{
|
||||
using (var uow = base.UnitWork.CreateContext())
|
||||
{
|
||||
uow.DmModulecolumn.Delete(u => ids.Contains(u.ModuleId));
|
||||
uow.DmModule.Delete(u => ids.Contains(u.Id));
|
||||
|
||||
var flag = uow.Commit();
|
||||
return new Response<bool>
|
||||
{
|
||||
Result = flag,
|
||||
Message = flag == true ? "success" : "error"
|
||||
};
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenAuth.App.BaseApp.DmModuleManager.Request
|
||||
{
|
||||
public class AddorUpdateModuleReq
|
||||
{
|
||||
public DmModule Module { get; set; }
|
||||
|
||||
public List<Modulecolumns> Cloums { get; set; }
|
||||
}
|
||||
|
||||
public class Modulecolumns
|
||||
{
|
||||
/// <summary>
|
||||
/// Desc:字段名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:字段描述
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:字段描述
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int? Sort { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenAuth.App.BaseApp.DmModuleManager.Response
|
||||
{
|
||||
public class DmDetailRes
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:模板名称
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建时间
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public DateTime? CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建人Id
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string CreateUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建人名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string CreateUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:模板描述说明
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<DmModulecolumn> Cloums { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
///<summary>
|
||||
///模板表
|
||||
///</summary>
|
||||
[SugarTable("dm_module")]
|
||||
public partial class DmModule
|
||||
{
|
||||
public DmModule(){
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:主键
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true)]
|
||||
public string Id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:模板名称
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string ModuleName {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建时间
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public DateTime? CreateTime {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建人Id
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string CreateUserId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:创建人名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string CreateUserName {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:模板描述说明
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Description {get;set;}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
///<summary>
|
||||
///模板字段关联表
|
||||
///</summary>
|
||||
[SugarTable("dm_modulecolumn")]
|
||||
public partial class DmModulecolumn
|
||||
{
|
||||
public DmModulecolumn(){
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:字段id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true)]
|
||||
public string Id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:模板id
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string ModuleId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:字段名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Name {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:字段描述
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Description {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:字段描述
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int? Sort { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using OpenAuth.Repository.Domain;
|
||||
using Models;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Domain.DataMaintenance;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
|
@ -68,5 +69,7 @@ namespace OpenAuth.Repository
|
|||
|
||||
#endregion
|
||||
|
||||
public SugarRepositiry<DmModule> DmModule { get; set; }
|
||||
public SugarRepositiry<DmModulecolumn> DmModulecolumn { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,161 @@
|
|||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Models;
|
||||
using NetTaste;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.BaseApp.DmModuleManager;
|
||||
using OpenAuth.App.BaseApp.DmModuleManager.Request;
|
||||
using OpenAuth.App.BaseApp.DmModuleManager.Response;
|
||||
using OpenAuth.App.Request;
|
||||
|
||||
namespace OpenAuth.WebApi.Controllers.BaseControllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户操作
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class DmModuleController : ControllerBase
|
||||
{
|
||||
private readonly DmModuleApp _app;
|
||||
public DmModuleController(DmModuleApp app)
|
||||
{
|
||||
_app = app;
|
||||
}
|
||||
|
||||
#region 数据查询
|
||||
/// <summary>
|
||||
/// 分页查询模板信息
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Response<PageInfo<List<DmModule>>>> LoadModulePageInfo([FromQuery] PageReq request)
|
||||
{
|
||||
var result = new Response<PageInfo<List<DmModule>>>();
|
||||
try
|
||||
{
|
||||
result =await _app.LoadModulePageInfo(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有模板信息(不分页)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Response<List<DmModule>>> LoadAll()
|
||||
{
|
||||
var result = new Response<List<DmModule>>();
|
||||
try
|
||||
{
|
||||
result = await _app.LoadAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模板id获取字段列表
|
||||
/// </summary>
|
||||
/// <param name="id">模板id</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Response<List<DmModulecolumn>>> LoadCloumsById(string id)
|
||||
{
|
||||
var result = new Response<List<DmModulecolumn>>();
|
||||
try
|
||||
{
|
||||
result = await _app.LoadCloumsById(id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模板详情信息查询
|
||||
/// </summary>
|
||||
/// <param name="id">模板id</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Response<DmDetailRes>> LoadModuleDetailInfo(string id)
|
||||
{
|
||||
var result = new Response<DmDetailRes>();
|
||||
try
|
||||
{
|
||||
result = await _app.LoadModuleDetailInfo(id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 增删改
|
||||
/// <summary>
|
||||
/// 添加或者修改数据
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public Response<bool> AddOrUpdate(AddorUpdateModuleReq obj)
|
||||
{
|
||||
var result = new Response<bool>();
|
||||
try
|
||||
{
|
||||
result = _app.AddOrUpdate(obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据选中id删除模板
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
[HttpPost]
|
||||
public Response<bool> DeleteModule(string[] ids)
|
||||
{
|
||||
var result = new Response<bool>();
|
||||
try
|
||||
{
|
||||
result = _app.DeleteModule(ids);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<key id="71a3c006-a825-4b90-aee2-be461dc1d8e3" version="1">
|
||||
<creationDate>2024-12-28T08:22:54.9876543Z</creationDate>
|
||||
<activationDate>2024-12-28T08:22:54.9645899Z</activationDate>
|
||||
<expirationDate>2025-03-28T08:22:54.9645899Z</expirationDate>
|
||||
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
|
||||
<descriptor>
|
||||
<encryption algorithm="AES_256_CBC" />
|
||||
<validation algorithm="HMACSHA256" />
|
||||
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
|
||||
<!-- Warning: the key below is in an unencrypted form. -->
|
||||
<value>z5oB24p5fz/B9/KgNqqS++cQFtFJzRwgKPLbVQzhozLtA8+bBAqWZcxOrWNIV5oS/lb64tlqVtLkWMuQvMlFqg==</value>
|
||||
</masterKey>
|
||||
</descriptor>
|
||||
</descriptor>
|
||||
</key>
|
||||
Loading…
Reference in New Issue