转移.net core 3.1,为.NET 5做准备

This commit is contained in:
ÂëÉñ
2020-10-22 14:59:36 +08:00
parent fd9bca23a7
commit a35d596237
1080 changed files with 175912 additions and 185681 deletions

View File

@@ -0,0 +1,185 @@
<%--
Name: Database Table Properties
Author: yubaolee
Description: Create a list of properties from a database table
--%>
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="应用层" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="Table"
Type="SchemaExplorer.TableSchema" %>
<%@ Property Name="HeaderModel"
Type="System.Boolean"
Category="1.Database"
Default="true"
Description="是否为启用头表模式,即类似‘入库订单’界面" %>
using System;
using System.Linq;
using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class <%=Table.Name%>App : BaseApp<<%=Table.Name%>>
{
private RevelanceManagerApp _revelanceApp;
/// <summary>
/// 加载列表
/// </summary>
public TableData Load(Query<%=Table.Name%>ListReq request)
{
var loginContext = _auth.GetCurrentUser();
if (loginContext == null)
{
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
}
var properties = loginContext.GetProperties("<%=Table.Name%>");
if (properties == null || properties.Count == 0)
{
throw new Exception("当前登录用户没有访问该模块字段的权限,请联系管理员配置");
}
var result = new TableData();
var objs = UnitWork.Find<<%=Table.Name%>>(null);
if (!string.IsNullOrEmpty(request.key))
{
objs = objs.Where(u => u.Id.Contains(request.key));
}
var propertyStr = string.Join(',', properties.Select(u => u.Key));
result.columnHeaders = properties;
result.data = objs.OrderBy(u => u.Id)
.Skip((request.page - 1) * request.limit)
.Take(request.limit).Select($"new ({propertyStr})");
result.count = objs.Count();
return result;
}
<%
if(Table.Name.Contains("Tbl") && (!Table.Name.Contains("Dtbl")) && this.HeaderModel){
var dtblName = Table.Name.Replace("Tbl","Dtbl"); //明细表的表名
%>
public void Add(AddOrUpdate<%=Table.Name%>Req req)
{
var obj = req.MapTo<<%=Table.Name%>>();
//todo:补充或调整自己需要的字段
obj.CreateTime = DateTime.Now;
var user = _auth.GetCurrentUser().User;
obj.CreateUserId = user.Id;
obj.CreateUserName = user.Name;
UnitWork.Add(obj);
if (req.<%=dtblName%>Reqs != null && req.<%=dtblName%>Reqs.Any())
{
foreach (var detail in req.<%=dtblName%>Reqs)
{
detail.ForeignKeyId = obj.Id; //todo:调整自己的明细表外键
_<%=dtblName%>App.AddNoSave(detail);
}
}
UnitWork.Save();
}
public void Update(AddOrUpdate<%=Table.Name%>Req obj)
{
var user = _auth.GetCurrentUser().User;
if (obj.<%=dtblName%>Reqs != null && obj.<%=dtblName%>Reqs.Any())
{
//id为空的添加
foreach (var detail in obj.<%=dtblName%>Reqs.Where(u =>string.IsNullOrEmpty(u.Id)))
{
detail.ForeignKeyId = obj.Id; //todo:调整自己的明细表外键
_<%=dtblName%>App.AddNoSave(detail);
}
//id比数据库少的删除
var containids = obj.<%=dtblName%>Reqs.Select(u => u.Id)
.Where(u =>!string.IsNullOrEmpty(u)).ToList();
if (containids.Any())
{
UnitWork.Delete<<%=dtblName%>>(u =>(!containids.Contains(u.Id)) && u.ForeignKeyId == obj.Id); //todo:调整自己的明细表外键
}
//更新id相同的
foreach (var detail in obj.<%=dtblName%>Reqs.Where(u =>!string.IsNullOrEmpty(u.Id)))
{
_<%=dtblName%>App.Update(detail);
}
}
UnitWork.Update<<%=Table.Name%>>(u => u.Id == obj.Id, u => new <%=Table.Name%>
{
<% foreach(ColumnSchema p in Table.Columns) {
if(p.IsPrimaryKeyMember) continue;
%>
<%= p.Name%> = obj.<%= p.Name%>,
<% } %>
UpdateTime = DateTime.Now,
UpdateUserId = user.Id,
UpdateUserName = user.Name
//todo:补充或调整自己需要的字段
});
UnitWork.Save();
}
<%
}else{ %>
public void Add(AddOrUpdate<%=Table.Name%>Req req)
{
var obj = req.MapTo<<%=Table.Name%>>();
//todo:补充或调整自己需要的字段
obj.CreateTime = DateTime.Now;
var user = _auth.GetCurrentUser().User;
obj.CreateUserId = user.Id;
obj.CreateUserName = user.Name;
Repository.Add(obj);
}
public void Update(AddOrUpdate<%=Table.Name%>Req obj)
{
var user = _auth.GetCurrentUser().User;
UnitWork.Update<<%=Table.Name%>>(u => u.Id == obj.Id, u => new <%=Table.Name%>
{
<% foreach(ColumnSchema p in Table.Columns) {
if(p.IsPrimaryKeyMember) continue;
%>
<%= p.Name%> = obj.<%= p.Name%>,
<% } %>
UpdateTime = DateTime.Now,
UpdateUserId = user.Id,
UpdateUserName = user.Name
//todo:补充或调整自己需要的字段
});
}
<%
}
%>
public <%=Table.Name%>App(IUnitWork unitWork, IRepository<<%=Table.Name%>> repository,
RevelanceManagerApp app, IAuth auth) : base(unitWork, repository,auth)
{
_revelanceApp = app;
}
}
}

View File

@@ -0,0 +1,122 @@
<%--
Name: Database Table Properties
Author: yubaolee
Description: Create a list of properties from a database table
--%>
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="控制器" %>
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
using System;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
namespace OpenAuth.WebApi.Controllers
{
/// <summary>
/// <%=ModuleName%>操作
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class <%=ModuleName%>sController : ControllerBase
{
private readonly <%=ModuleName%>App _app;
//获取详情
[HttpGet]
public Response<<%=ModuleName%>> Get(string id)
{
var result = new Response<<%=ModuleName%>>();
try
{
result.Result = _app.Get(id);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
//添加
[HttpPost]
public Response Add(AddOrUpdate<%=ModuleName%>Req obj)
{
var result = new Response();
try
{
_app.Add(obj);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
//修改
[HttpPost]
public Response Update(AddOrUpdate<%=ModuleName%>Req obj)
{
var result = new Response();
try
{
_app.Update(obj);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
/// <summary>
/// 加载列表
/// </summary>
[HttpGet]
public TableData Load([FromQuery]Query<%=ModuleName%>ListReq request)
{
return _app.Load(request);
}
/// <summary>
/// 批量删除
/// </summary>
[HttpPost]
public Response Delete([FromBody]string[] ids)
{
var result = new Response();
try
{
_app.Delete(ids);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.InnerException?.Message ?? ex.Message;
}
return result;
}
public <%=ModuleName%>sController(<%=ModuleName%>App app)
{
_app = app;
}
}
}

View File

@@ -0,0 +1,66 @@
<%@ Template Language="C#" TargetLanguage="C#" Debug="True" Encoding="UTF-8" %>
<%@ Assembly Src="../Internal/Model.cs" %>
<%@ Assembly Src="../Internal/Extensions.cs" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="SchemaMapper" %>
<%@ Property Name="Table"
Type="SchemaExplorer.TableSchema" %>
<%@ Property Name="HeaderModel"
Type="System.Boolean"
Category="1.Database"
Default="true"
Description="是否为启用头表模式,即类似‘入库订单’界面" %>
<%@ Property Name="EntityNamespace"
Type="System.String" %>
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a CodeSmith Template.
//
// DO NOT MODIFY contents of this file. Changes to this
// file will be lost if the code is regenerated.
// Author:Yubao Li
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
using OpenAuth.Repository.Core;
namespace OpenAuth.App.Request
{
/// <summary>
/// <%= Table.Description %>
/// </summary>
[Table("<%= Table.Name%>")]
public partial class AddOrUpdate<%= Table.Name %>Req
{
<% foreach(ColumnSchema p in Table.Columns) {
%>
/// <summary>
/// <%=p.Description %>
/// </summary>
public <%= p.SystemType.ToNullableType(p.AllowDBNull == true) %> <%= p.Name%> { get; set; }
<% } %>
//todo:添加自己的请求字段
<%
if(Table.Name.Contains("Tbl") && (!Table.Name.Contains("Dtbl")) && this.HeaderModel){
var dtblName = Table.Name.Replace("Tbl","Dtbl"); //明细表的表名
%>
public List<AddOrUpdate<%=dtblName%>Req> <%=dtblName%>Reqs { get; set; }
<% } %>
}
}

View File

@@ -0,0 +1,17 @@
<%--
Name: Database Table Properties
Author: yubaolee
Description: Create a list of properties from a database table
--%>
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %>
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
namespace OpenAuth.App.Request
{
public class Query<%=ModuleName%>ListReq : PageReq
{
//todo:添加自己的请求字段
}
}