Skip to content

Commit

Permalink
完善可以根据主键类型调整父类
Browse files Browse the repository at this point in the history
  • Loading branch information
yubaolee committed Apr 1, 2021
1 parent 36c3d67 commit e6b812d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
25 changes: 23 additions & 2 deletions OpenAuth.App/BuilderTableApp.cs
Expand Up @@ -242,7 +242,7 @@ public void CreateBusiness(CreateBusiReq req)
GenerateAppReq(sysTableInfo, tableColumns);

//生成WebApI接口
GenerateWebApi(sysTableInfo);
GenerateWebApi(sysTableInfo, tableColumns);
}

/// <summary>
Expand Down Expand Up @@ -361,7 +361,7 @@ private void GenerateAppReq(BuilderTable sysTableInfo, List<BuilderTableColumn>
/// </summary>
/// <param name="sysTableInfo"></param>
/// <exception cref="Exception"></exception>
private void GenerateWebApi(BuilderTable sysTableInfo)
private void GenerateWebApi(BuilderTable sysTableInfo, List<BuilderTableColumn> sysColumns)
{
string domainContent;
string apiPath = ProjectPath.GetProjectDirectoryInfo()
Expand All @@ -380,6 +380,27 @@ private void GenerateWebApi(BuilderTable sysTableInfo)
.Replace("{ModuleName}", sysTableInfo.ModuleName)
.Replace("{ClassName}", sysTableInfo.ClassName)
.Replace("{StartName}", StratName);

var primarykey = sysColumns.FirstOrDefault(u => u.IsKey);
if (primarykey == null)
{
throw new Exception($"未能找到表{sysTableInfo.TableName}的主键字段");
}
if (primarykey.ColumnType == "decimal" || primarykey.ColumnType == "numberic") //是否为数字
{
if(primarykey.IsIncrement) //是否自增
{
domainContent = domainContent.Replace("{KeyTypeName}", "int");
}
else //普通的雪花算法生成id
{
domainContent = domainContent.Replace("{KeyTypeName}", "long");
}
}
else
{
domainContent = domainContent.Replace("{KeyTypeName}", "string");
}
FileHelper.WriteFile(controllerPath, controllerName + ".cs", domainContent);
}

Expand Down
7 changes: 4 additions & 3 deletions OpenAuth.WebApi/Template/BuildApp.html
Expand Up @@ -23,21 +23,22 @@
var loginContext = _auth.GetCurrentUser();
if (loginContext == null)
{
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
}

var properties = loginContext.GetProperties("{ClassName}");

if (properties == null || properties.Count == 0)
{
throw new Exception("当前登录用户没有访问该模块字段的权限,请联系管理员配置");
throw new Exception("当前登录用户没有访问该模块字段的权限,请联系管理员配置");
}

var result = new TableData();
var objs = GetDataPrivilege("u");
if (!string.IsNullOrEmpty(request.key))
{
objs = objs.Where(u => u.Id.Contains(request.key));
//增加筛选条件,如:
//objs = objs.Where(u => u.Name.Contains(request.key));
}

var propertyStr = string.Join(',', properties.Select(u => u.Key));
Expand Down
4 changes: 2 additions & 2 deletions OpenAuth.WebApi/Template/BuildControllerApi.html
Expand Up @@ -20,7 +20,7 @@

//获取详情
[HttpGet]
public Response<{ClassName}> Get(string id)
public Response<{ClassName}> Get({KeyTypeName} id)
{
var result = new Response<{ClassName}>();
try
Expand Down Expand Up @@ -87,7 +87,7 @@
/// 批量删除
/// </summary>
[HttpPost]
public Response Delete([FromBody]string[] ids)
public Response Delete([FromBody]{KeyTypeName}[] ids)
{
var result = new Response();
try
Expand Down

0 comments on commit e6b812d

Please sign in to comment.