mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
feat: 代码生成默认生成基于SqlSugar的代码
This commit is contained in:
parent
bb87b4fed7
commit
1290ed068e
@ -1,19 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using OpenAuth.App.Interface;
|
using OpenAuth.App.Interface;
|
||||||
using OpenAuth.App.Request;
|
using OpenAuth.App.Request;
|
||||||
using OpenAuth.App.Response;
|
using OpenAuth.App.Response;
|
||||||
using OpenAuth.Repository;
|
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using SqlSugar;
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
public class {ModuleCode} : {BaseAppName}<{ClassName},OpenAuthDBContext>
|
public class {ModuleCode} : SqlSugarBaseApp<{ClassName}>
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -24,45 +23,52 @@ namespace OpenAuth.App
|
|||||||
var loginContext = _auth.GetCurrentUser();
|
var loginContext = _auth.GetCurrentUser();
|
||||||
if (loginContext == null)
|
if (loginContext == null)
|
||||||
{
|
{
|
||||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var result = new TableData();
|
var result = new TableData();
|
||||||
var objs = GetDataPrivilege("u");
|
var objs = GetDataPrivilege("u");
|
||||||
if (!string.IsNullOrEmpty(request.key))
|
if (!string.IsNullOrEmpty(request.key))
|
||||||
{
|
{
|
||||||
//增加筛选条件,如:
|
objs = objs.Where(u => u.Name.Contains(request.key));
|
||||||
//objs = objs.Where(u => u.Name.Contains(request.key));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ForeignKeyTemplate}
|
{ForeignKeyTemplate}
|
||||||
|
|
||||||
result.data = objs.OrderBy(u => u.Id)
|
result.data = objs.OrderBy(u => u.Id)
|
||||||
.Skip((request.page - 1) * request.limit)
|
.Skip((request.page - 1) * request.limit)
|
||||||
.Take(request.limit);
|
.Take(request.limit).ToList();
|
||||||
result.count =await objs.CountAsync();
|
result.count = await objs.CountAsync();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(AddOrUpdate{ClassName}Req obj)
|
public void Add(AddOrUpdate{ClassName}Req req)
|
||||||
{
|
{
|
||||||
//程序类型取入口应用的名称,可以根据自己需要调整
|
var obj = req.MapTo<{ClassName}>();
|
||||||
var addObj = obj.MapTo<{ClassName}>();
|
obj.Id = Guid.NewGuid().ToString();
|
||||||
//addObj.Time = DateTime.Now;
|
//todo: 根据业务需要调整字段
|
||||||
Repository.Add(addObj);
|
obj.Createtime = DateTime.Now;
|
||||||
|
var user = _auth.GetCurrentUser().User;
|
||||||
|
obj.Createuserid = user.Id;
|
||||||
|
obj.Createusername = user.Name;
|
||||||
|
Repository.Insert(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(AddOrUpdate{ClassName}Req obj)
|
public void Update(AddOrUpdate{ClassName}Req obj)
|
||||||
{
|
{
|
||||||
UnitWork.Update<{ClassName}>(u => u.Id == obj.Id, u => new {ClassName}
|
var user = _auth.GetCurrentUser().User;
|
||||||
|
Repository.Update(u => new {ClassName}
|
||||||
{
|
{
|
||||||
//todo:要修改的字段赋值
|
//todo: 根据业务需要调整字段
|
||||||
});
|
{ClassName} = obj.{ClassName},
|
||||||
|
Updatetime = DateTime.Now,
|
||||||
|
Updateuserid = user.Id,
|
||||||
|
Updateusername = user.Name
|
||||||
|
},u => u.Id == obj.Id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public {ModuleCode}(IUnitWork<OpenAuthDBContext> unitWork, IRepository<{ClassName},OpenAuthDBContext> repository, IAuth auth) : base(unitWork, repository, auth)
|
public {ModuleCode}(ISqlSugarClient client, IAuth auth) : base(client, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using OpenAuth.App.Interface;
|
using OpenAuth.App.Interface;
|
||||||
using OpenAuth.App.Request;
|
using OpenAuth.App.Request;
|
||||||
using OpenAuth.App.Response;
|
using OpenAuth.App.Response;
|
||||||
using OpenAuth.Repository;
|
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using SqlSugar;
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
public class {ModuleCode} : {BaseAppName}<{ClassName},OpenAuthDBContext>
|
public class {ModuleCode} : SqlSugarBaseApp<{ClassName}>
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -24,52 +23,62 @@ namespace OpenAuth.App
|
|||||||
var loginContext = _auth.GetCurrentUser();
|
var loginContext = _auth.GetCurrentUser();
|
||||||
if (loginContext == null)
|
if (loginContext == null)
|
||||||
{
|
{
|
||||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
var columnFields = loginContext.GetTableColumns("{ClassName}");
|
var columnFields = loginContext.GetTableColumns("{ClassName}");
|
||||||
if (columnFields == null || columnFields.Count == 0)
|
if (columnFields == null || columnFields.Count == 0)
|
||||||
{
|
{
|
||||||
throw new Exception("请在代码生成界面配置{ClassName}表的字段属性");
|
throw new Exception("请在代码生成界面配置{ClassName}表的字段属性");
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = new TableData();
|
var result = new TableData();
|
||||||
var objs = GetDataPrivilege("u");
|
var objs = GetDataPrivilege("u");
|
||||||
if (!string.IsNullOrEmpty(request.key))
|
if (!string.IsNullOrEmpty(request.key))
|
||||||
{
|
{
|
||||||
//增加筛选条件,如:
|
//增加筛选条件,如:
|
||||||
//objs = objs.Where(u => u.Name.Contains(request.key));
|
objs = objs.Where(u => u.Name.Contains(request.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
{ForeignKeyTemplate}
|
{ForeignKeyTemplate}
|
||||||
|
|
||||||
var propertyStr = string.Join(',', columnFields.Select(u => u.ColumnName));
|
var columnnames = columnFields.Select(u => u.ColumnName);
|
||||||
|
var propertyStr = string.Join(',', columnnames);
|
||||||
result.columnFields = columnFields;
|
result.columnFields = columnFields;
|
||||||
result.data = objs.OrderBy(u => u.Id)
|
result.data = objs.OrderByDescending(u => u.Id)
|
||||||
.Skip((request.page - 1) * request.limit)
|
.Skip((request.page - 1) * request.limit)
|
||||||
.Take(request.limit).Select($"new ({propertyStr})");
|
.Take(request.limit).Select($"{propertyStr}").ToList();
|
||||||
result.count =await objs.CountAsync();
|
result.count = await objs.CountAsync();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(AddOrUpdate{ClassName}Req obj)
|
public void Add(AddOrUpdate{ClassName}Req req)
|
||||||
{
|
{
|
||||||
//程序类型取入口应用的名称,可以根据自己需要调整
|
var obj = req.MapTo<{ClassName}>();
|
||||||
var addObj = obj.MapTo<{ClassName}>();
|
obj.Id = Guid.NewGuid().ToString();
|
||||||
//addObj.Time = DateTime.Now;
|
//todo: 根据业务需要调整字段
|
||||||
Repository.Add(addObj);
|
obj.Createtime = DateTime.Now;
|
||||||
|
var user = _auth.GetCurrentUser().User;
|
||||||
|
obj.Createuserid = user.Id;
|
||||||
|
obj.Createusername = user.Name;
|
||||||
|
Repository.Insert(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(AddOrUpdate{ClassName}Req obj)
|
public void Update(AddOrUpdate{ClassName}Req obj)
|
||||||
{
|
{
|
||||||
UnitWork.Update<{ClassName}>(u => u.Id == obj.Id, u => new {ClassName}
|
var user = _auth.GetCurrentUser().User;
|
||||||
|
Repository.Update(u => new {ClassName}
|
||||||
{
|
{
|
||||||
//todo:要修改的字段赋值
|
//todo: 根据业务需要调整字段
|
||||||
});
|
Name = obj.Name,
|
||||||
|
Updatetime = DateTime.Now,
|
||||||
|
Updateuserid = user.Id,
|
||||||
|
Updateusername = user.Name
|
||||||
|
},u => u.Id == obj.Id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public {ModuleCode}(IUnitWork<OpenAuthDBContext> unitWork, IRepository<{ClassName},OpenAuthDBContext> repository, IAuth auth) : base(unitWork, repository, auth)
|
public {ModuleCode}(ISqlSugarClient client, IAuth auth) : base(client, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user