vengine初步实现增删改查
This commit is contained in:
29
visualdev/Tnb.Vengine/CodeGenerator/AcmenVmodelContext.cs
Normal file
29
visualdev/Tnb.Vengine/CodeGenerator/AcmenVmodelContext.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Tnb.Vengine.DataAccess;
|
||||
using Tnb.Vengine.Domain;
|
||||
|
||||
namespace Tnb.Vengine;
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成AppService的数据上下文
|
||||
/// </summary>
|
||||
public class AcmenVmodelContext : TemplateContext
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public AcmenVmodelContext(IDataAccess da, Vmodel vm) : base(vm.areaCode)
|
||||
{
|
||||
_da = da;
|
||||
Vm = vm;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public IDataAccess _da { get; set; }
|
||||
public Vmodel Vm { get; }
|
||||
|
||||
public string NsPrefix { get { return "Tnb"; } }
|
||||
|
||||
}
|
||||
|
||||
|
||||
123
visualdev/Tnb.Vengine/CodeGenerator/CodeHelper.cs
Normal file
123
visualdev/Tnb.Vengine/CodeGenerator/CodeHelper.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Tnb.Vengine;
|
||||
|
||||
public class CodeHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 从当前目录往上查找解决方案sln文件所在的目录
|
||||
/// </summary>
|
||||
public static string? GetSolutionDirectoryPath(bool includeParent = false)
|
||||
{
|
||||
var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
|
||||
while (Directory.GetParent(currentDirectory.FullName) != null)
|
||||
{
|
||||
currentDirectory = Directory.GetParent(currentDirectory.FullName);
|
||||
if (currentDirectory == null) return null;
|
||||
|
||||
if (Directory.GetFiles(currentDirectory!.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null)
|
||||
{
|
||||
if (includeParent && currentDirectory.Parent != null) return currentDirectory.Parent.FullName;
|
||||
else return currentDirectory.FullName;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存代码到文件
|
||||
/// </summary>
|
||||
public static void SaveCodeToFile(string code, string saveTo)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(saveTo);
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir!);
|
||||
}
|
||||
code = System.Web.HttpUtility.HtmlDecode(code);
|
||||
File.WriteAllText(saveTo, code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MD5加密
|
||||
/// </summary>
|
||||
/// <param name="szValue"></param>
|
||||
/// <returns></returns>
|
||||
public static string String2MD5(string szValue)
|
||||
{
|
||||
string pwd = string.Empty;
|
||||
MD5 md5 = MD5.Create();
|
||||
byte[] byt = md5.ComputeHash(Encoding.Unicode.GetBytes(szValue));
|
||||
for (int i = 0; i < byt.Length; i++)
|
||||
{
|
||||
pwd += byt[i].ToString("x"); //16进制
|
||||
}
|
||||
char[] arr = pwd.ToCharArray();
|
||||
Array.Reverse(arr);
|
||||
return new string(arr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// newtonsoft json 转小驼峰
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToCamelCase(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s) || !char.IsUpper(s[0]))
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
char[] array = s.ToCharArray();
|
||||
for (int i = 0; i < array.Length && (i != 1 || char.IsUpper(array[i])); i++)
|
||||
{
|
||||
bool flag = i + 1 < array.Length;
|
||||
if (i > 0 && flag && !char.IsUpper(array[i + 1]))
|
||||
{
|
||||
if (char.IsSeparator(array[i + 1]))
|
||||
{
|
||||
array[i] = char.ToLower(array[i], CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
array[i] = char.ToLower(array[i], CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
return new string(array);
|
||||
}
|
||||
|
||||
public static string LengthToString(int strLength)
|
||||
{
|
||||
var l = "DbConsts.";
|
||||
if (strLength <= 0) { l += nameof(DbConsts.LengthText); }
|
||||
else if (strLength <= DbConsts.LengthXXS) { l += nameof(DbConsts.LengthXXS); }
|
||||
else if (strLength <= DbConsts.LengthXS) { l += nameof(DbConsts.LengthXS); }
|
||||
else if (strLength <= DbConsts.LengthS) { l += nameof(DbConsts.LengthS); }
|
||||
else if (strLength <= DbConsts.LengthM) { l += nameof(DbConsts.LengthM); }
|
||||
else if (strLength <= DbConsts.LengthL) { l += nameof(DbConsts.LengthL); }
|
||||
else if (strLength <= DbConsts.LengthXL) { l += nameof(DbConsts.LengthXL); }
|
||||
else if (strLength <= DbConsts.LengthXXL) { l += nameof(DbConsts.LengthXXL); }
|
||||
else if (strLength <= DbConsts.LengthXXXL) { l += nameof(DbConsts.LengthXXXL); }
|
||||
else { l += nameof(DbConsts.LengthXXXXL); }
|
||||
return l;
|
||||
}
|
||||
|
||||
public static int PropDefineToLength(string? propDefine)
|
||||
{
|
||||
float.TryParse(propDefine, out float f);
|
||||
return (int)f;
|
||||
}
|
||||
public static int PropDefineToScale(string? propDefine)
|
||||
{
|
||||
float.TryParse(propDefine, out float f);
|
||||
return (int)(f * 10) % 10;
|
||||
}
|
||||
}
|
||||
77
visualdev/Tnb.Vengine/CodeGenerator/TemplateContext.cs
Normal file
77
visualdev/Tnb.Vengine/CodeGenerator/TemplateContext.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Tnb.Core;
|
||||
|
||||
namespace Tnb.Vengine;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class TemplateContext
|
||||
{
|
||||
#region 模板文件名,同时作为模板Key
|
||||
public const string KeyAppService = "AppService";
|
||||
public const string KeyDto = "AppServiceDto";
|
||||
public const string KeyEntity = "EntityInfo";
|
||||
public const string KeyEntityDto = "EntityDto";
|
||||
public const string KeyEntityAppService = "EntityController";
|
||||
public const string KeyEntityPageVue = "EntityPageVue";
|
||||
public const string KeyTableForeigns = "TableForeigns";
|
||||
public const string KeyVmodel = "Vmodel";
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public TemplateContext(string moduleCode)
|
||||
{
|
||||
#if DEBUG
|
||||
BasePath = CodeHelper.GetSolutionDirectoryPath(false)!;
|
||||
#else
|
||||
BasePath = EApp.Options.App.AcmenBasePath;
|
||||
#endif
|
||||
ModuleCode = moduleCode;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string BasePath { get; set; }
|
||||
private string ModuleCode { get; }
|
||||
|
||||
private string ModulePath => Path.Combine(BasePath, $"{ModuleCode}.Acmen");
|
||||
private string UiProjPath => Path.Combine(BasePath, "ItMgrWeb");
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string AppServicePath => Path.Combine(ModulePath, "AppServices");
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string PagePath => Path.Combine(UiProjPath, "src", "views");
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public string GetCsName(string name)
|
||||
{
|
||||
name = Regex.Replace(name.TrimStart('@', '.'), @"[^\w]", "_");
|
||||
name = char.IsLetter(name, 0) ? name : string.Concat("_", name);
|
||||
IEnumerable<string> arrs = name.Split('_');
|
||||
//if (arrs.Count() > 1 && Config.IsRemovePrefix) { arrs = arrs.Skip(1); }
|
||||
//if (Config.IsSnakeCaseToPascalCase) { arrs = arrs.Select(a => a.ToPascalCase()); }
|
||||
if (arrs.Count() > 0) { arrs = arrs.Select(a => a.ToPascal()); }
|
||||
|
||||
return string.Join("", arrs);
|
||||
}
|
||||
}
|
||||
|
||||
public enum eLambdaType
|
||||
{
|
||||
Join,
|
||||
ManyToMany,
|
||||
Where,
|
||||
MemberBinding,
|
||||
OneToMany
|
||||
}
|
||||
Reference in New Issue
Block a user