🐛fix: #ICL05Q 代码生成命名空间设置无效

This commit is contained in:
yubaolee 2025-07-10 21:24:26 +08:00
parent d83a40e07e
commit f980fc5afc
8 changed files with 39 additions and 18 deletions

View File

@ -337,6 +337,7 @@ namespace OpenAuth.App
.Replace("{ModuleCode}", sysTableInfo.ModuleCode)
.Replace("{ModuleName}", sysTableInfo.ModuleName)
.Replace("{ClassName}", sysTableInfo.ClassName)
.Replace("{Namespace}", sysTableInfo.Namespace)
.Replace("{UpdateColumns}", updateColumns)
.Replace("{InsertColumns}", insertColumns)
.Replace("{StartName}", StratName);
@ -370,6 +371,7 @@ namespace OpenAuth.App
.Replace("{ModuleCode}", sysTableInfo.ModuleCode)
.Replace("{ModuleName}", sysTableInfo.ModuleName)
.Replace("{ClassName}", sysTableInfo.ClassName)
.Replace("{Namespace}", sysTableInfo.Namespace)
.Replace("{SubForeignKey}", subTable.ForeignKey)
.Replace("{SubClassName}", subTable.ClassName)
.Replace("{SubModuleCode}", subTable.ModuleCode)
@ -508,6 +510,7 @@ namespace OpenAuth.App
domainContent = FileHelper.ReadFile(@"Template\\BuildControllerApi.html")
.Replace("{TableName}", sysTableInfo.TableName)
.Replace("{ModuleCode}", sysTableInfo.ModuleCode)
.Replace("{Namespace}", sysTableInfo.Namespace)
.Replace("{ModuleName}", sysTableInfo.ModuleName)
.Replace("{ClassName}", sysTableInfo.ClassName)
.Replace("{StartName}", StratName);
@ -607,6 +610,7 @@ namespace OpenAuth.App
domainContent = domainContent.Replace("{ClassName}", tableInfo.ClassName)
.Replace("{AttributeList}", attributeBuilder.ToString())
.Replace("{Namespace}", tableInfo.Namespace)
.Replace("{Construction}", constructionBuilder.ToString());
@ -621,10 +625,29 @@ namespace OpenAuth.App
tableAttr.Append(" [Table(\"" + tableInfo.TableName + "\")]");
domainContent = domainContent.Replace("{AttributeManager}", tableAttr.ToString());
FileHelper.WriteFile(
mapPath +
$"\\OpenAuth.Repository\\Domain\\", tableInfo.ClassName + ".cs",
domainContent);
// 检查命名空间是否以OpenAuth.Repository开头
if (!tableInfo.Namespace.StartsWith("OpenAuth.Repository"))
{
throw new Exception("命名空间必须以OpenAuth.Repository开头");
}
// 获取OpenAuth.Repository后面的部分
var subNamespace = tableInfo.Namespace.Substring("OpenAuth.Repository".Length).TrimStart('.');
// 构建目录层级
var domainPath = Path.Combine(mapPath, "OpenAuth.Repository");
if (!string.IsNullOrEmpty(subNamespace))
{
foreach (var part in subNamespace.Split('.'))
{
domainPath = Path.Combine(domainPath, part);
}
}
// 确保目录存在
if (!Directory.Exists(domainPath))
{
Directory.CreateDirectory(domainPath);
}
FileHelper.WriteFile(domainPath, tableInfo.ClassName + ".cs", domainContent);
}
Dictionary<string, Type> PrimitiveTypes = new Dictionary<string, Type>()

View File

@ -38,7 +38,7 @@ namespace OpenAuth.App.Test
//模拟路径
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
.Replace("\\OpenAuth.App\\bin\\Debug\\netcoreapp3.1","");
.Replace("\\OpenAuth.App\\bin\\Debug\\net9.0","");
var mockPathProvider = new Mock<IPathProvider>();
mockPathProvider.Setup(x => x.MapPath("",false)).Returns(path);
services.AddScoped(x => mockHttpFac.Object);

View File

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using {Namespace};
namespace OpenAuth.WebApi.Controllers
{

View File

@ -1,16 +1,14 @@
//------------------------------------------------------------------------------
// 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
//------------------------------------------------------------------------------
/*
* @Author: yubaolee <yubaolee@163.com> | ahfu~ <954478625@qq.com>
* @Description: 实体类
* Copyright (c) 2025 by yubaolee | ahfu~ , All Rights Reserved.
*/
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using OpenAuth.Repository.Core;
namespace OpenAuth.Repository.Domain
namespace {Namespace}
{
{AttributeManager}
public class {ClassName} : {BaseEntityName}

View File

@ -5,7 +5,7 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using {Namespace};
using SqlSugar;
namespace OpenAuth.App
{

View File

@ -5,7 +5,7 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using {Namespace};
using SqlSugar;
namespace OpenAuth.App
{

View File

@ -6,7 +6,7 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using {Namespace};
using SqlSugar;

View File

@ -6,7 +6,7 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using {Namespace};
using SqlSugar;