263 lines
12 KiB
Plaintext
263 lines
12 KiB
Plaintext
@{
|
||
ModelData modelData = Model;
|
||
NamespaceObject namespaceObject = modelData.NamespaceObject;
|
||
SysTableSchemaViewEntity[] sysTableSchemas = modelData.sysTableSchemas;
|
||
ClassInfo classInfo= modelData.ClassInfos.FirstOrDefault();
|
||
//ClassInfo classInfo= modelData.ClassInfos.Where(x=>x.ClassName=="SecurityUserService").FirstOrDefault();
|
||
}
|
||
using CloudBuilder.Core.DatabaseAccessor;
|
||
using CloudBuilder.Core.Policy;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using System.Transactions;
|
||
using CloudBuilder.Core.Service;
|
||
@{
|
||
if(classInfo.Usings!=null && classInfo.Usings.Length>0)
|
||
{
|
||
for (var i = 0; i < classInfo.Usings.Length; i++)
|
||
{
|
||
if(classInfo.Usings[i]=="CloudBuilder.Core.Service") continue;
|
||
<text>using @classInfo.Usings[i];
|
||
</text>
|
||
}
|
||
}
|
||
}
|
||
|
||
namespace @namespaceObject.Namespace
|
||
{
|
||
[Authorize(AuthorizePolicy.PERMISSION)]
|
||
[ApiController]
|
||
[Route("[controller]/[action]")]
|
||
public class @{@classInfo.ClassName.Replace("Service", "")}Controller : ControllerBase
|
||
{
|
||
private readonly IApplicationService service;
|
||
private readonly @{@classInfo.InterfaceName} @classInfo.ClassName.StringToProtectedProerty();
|
||
|
||
public @{@classInfo.ClassName.Replace("Service", "")}Controller(IApplicationService service, @{@classInfo.InterfaceName} @classInfo.ClassName.StringToProtectedProerty())
|
||
{
|
||
this.service = service;
|
||
this.@classInfo.ClassName.StringToProtectedProerty()= @classInfo.ClassName.StringToProtectedProerty();
|
||
}
|
||
|
||
@{
|
||
if(classInfo.ClassMethodInfos!=null && classInfo.ClassMethodInfos.Length>0 && classInfo.ClassMethodInfos[0].Parameters!=null)
|
||
{
|
||
for (var j= 0; j< classInfo.ClassMethodInfos.Length; j++)
|
||
{
|
||
//没有参数的情况=======================================
|
||
if(classInfo.ClassMethodInfos[j].Parameters.Length==0)
|
||
{
|
||
if(classInfo.ClassMethodInfos[j].AuthorizeName!=null)
|
||
{
|
||
<text> @classInfo.ClassMethodInfos[j].AuthorizeName
|
||
</text>
|
||
}
|
||
if(classInfo.ClassMethodInfos[j].PermissionOperate!=null)
|
||
{
|
||
@{<text> @string.Format(classInfo.ClassMethodInfos[j].PermissionOperate,"\""+@classInfo.ClassMethodInfos[j].PermissionOperateAttribute.Name+"\"", "\""+@classInfo.ClassMethodInfos[j].PermissionOperateAttribute.Operate.ToString()+"\"")
|
||
</text>}
|
||
}
|
||
if(classInfo.ClassMethodInfos[j].HttpName!=null)
|
||
{
|
||
<text> @classInfo.ClassMethodInfos[j].HttpName
|
||
</text>
|
||
}
|
||
if(classInfo.ClassMethodInfos[j].UnitOfWorkName!=null)
|
||
{
|
||
<text> @classInfo.ClassMethodInfos[j].UnitOfWorkName
|
||
</text>
|
||
}
|
||
if(@classInfo.ClassMethodInfos[j].MethodReturnName=="Void")
|
||
{
|
||
//文本开始=================================================================================================================
|
||
<text> public dynamic @{@classInfo.ClassMethodInfos[j].MethodName}()
|
||
{
|
||
try
|
||
{
|
||
|
||
@{<text> </text>@classInfo.ClassName.StringToProtectedProerty()}.@{@classInfo.ClassMethodInfos[j].MethodName}();
|
||
|
||
return string.Empty;
|
||
}
|
||
catch (ValidatedException vex)
|
||
{
|
||
return vex;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new ServiceErrorException(ex);
|
||
}
|
||
}
|
||
|
||
</text>
|
||
//文本结束=================================================================================================================
|
||
}
|
||
else
|
||
{
|
||
//文本开始=================================================================================================================
|
||
<text> public dynamic @{@classInfo.ClassMethodInfos[j].MethodName}()
|
||
{
|
||
try
|
||
{
|
||
|
||
var result = @{@classInfo.ClassName.StringToProtectedProerty()}.@{@classInfo.ClassMethodInfos[j].MethodName}();
|
||
return result;
|
||
}
|
||
catch (ValidatedException vex)
|
||
{
|
||
return vex;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new ServiceErrorException(ex);
|
||
}
|
||
}
|
||
|
||
</text>
|
||
//文本结束=================================================================================================================
|
||
}
|
||
}
|
||
|
||
|
||
//只有1个参数的情况============================================
|
||
if(classInfo.ClassMethodInfos[j].Parameters.Length>0)
|
||
{
|
||
//超过1个参数的情况,如果是get,不能用组合对象,如果是post,要重新组合一个类========================================
|
||
if(classInfo.ClassMethodInfos[j].Parameters.Length>1 && classInfo.ClassMethodInfos[j].HttpName!="[HttpGet]")
|
||
{
|
||
<text>
|
||
public class @{@classInfo.ClassMethodInfos[j].MethodName}CompositionData
|
||
{
|
||
</text>
|
||
|
||
for (var ik = 0; ik < classInfo.ClassMethodInfos[j].Parameters.Length; ik++){
|
||
string parameterTypeName=classInfo.ClassMethodInfos[j].Parameters[ik].ParameterTypeName;
|
||
if(classInfo.ClassMethodInfos[j].Parameters[ik].IsValueType)
|
||
{
|
||
if(classInfo.ClassMethodInfos[j].Parameters[ik].ParameterTypeName=="String")
|
||
parameterTypeName="string";
|
||
if(classInfo.ClassMethodInfos[j].Parameters[ik].ParameterTypeName=="Boolean")
|
||
parameterTypeName="bool";
|
||
}
|
||
<text> public @parameterTypeName @classInfo.ClassMethodInfos[j].Parameters[ik].ParameterName { get; set; }
|
||
</text>
|
||
|
||
}
|
||
|
||
<text>
|
||
}
|
||
</text>
|
||
}
|
||
|
||
if(classInfo.ClassMethodInfos[j].AuthorizeName!=null)
|
||
{
|
||
<text> @classInfo.ClassMethodInfos[j].AuthorizeName
|
||
</text>
|
||
}
|
||
if(classInfo.ClassMethodInfos[j].PermissionOperate!=null)
|
||
{
|
||
@{<text> @string.Format(classInfo.ClassMethodInfos[j].PermissionOperate,"\""+@classInfo.ClassMethodInfos[j].PermissionOperateAttribute.Name+"\"","\""+@classInfo.ClassMethodInfos[j].PermissionOperateAttribute.Operate.ToString()+"\"")
|
||
</text>}
|
||
}
|
||
if(classInfo.ClassMethodInfos[j].HttpName!=null)
|
||
{
|
||
<text> @classInfo.ClassMethodInfos[j].HttpName
|
||
</text>
|
||
}
|
||
if(classInfo.ClassMethodInfos[j].UnitOfWorkName!=null)
|
||
{
|
||
<text> @classInfo.ClassMethodInfos[j].UnitOfWorkName
|
||
</text>
|
||
}
|
||
|
||
if(@classInfo.ClassMethodInfos[j].MethodReturnName=="Void")
|
||
{
|
||
string parametersName=@classInfo.ClassMethodInfos[j].Parameters[0].ParameterTypeName.Replace("String", "string").Replace("Boolean", "bool")+" "+@classInfo.ClassMethodInfos[j].Parameters[0].ParameterName;
|
||
if(classInfo.ClassMethodInfos[j].Parameters.Length>1 && classInfo.ClassMethodInfos[j].HttpName!="[HttpGet]")
|
||
{
|
||
parametersName=@classInfo.ClassMethodInfos[j].MethodName+"CompositionData compositionData";
|
||
}
|
||
else if(classInfo.ClassMethodInfos[j].Parameters.Length>1){
|
||
parametersName=string.Empty;
|
||
|
||
}
|
||
//文本开始================================================
|
||
<text> public dynamic @{@classInfo.ClassMethodInfos[j].MethodName}(@{@parametersName})</text><text>{
|
||
try
|
||
{
|
||
@{<text> </text>@classInfo.ClassName.StringToProtectedProerty()}.@{@classInfo.ClassMethodInfos[j].MethodName}(@{for (var i = 0; i < classInfo.ClassMethodInfos[j].Parameters.Length; i++){
|
||
if(classInfo.ClassMethodInfos[j].Parameters.Length>1){
|
||
if(i>0){<text>,</text>}<text>compositionData.@classInfo.ClassMethodInfos[j].Parameters[i].ParameterName</text>
|
||
}
|
||
else{
|
||
<text>@classInfo.ClassMethodInfos[j].Parameters[i].ParameterName</text>
|
||
}
|
||
}});
|
||
|
||
return string.Empty;
|
||
}
|
||
catch (ValidatedException vex)
|
||
{
|
||
return vex;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new ServiceErrorException(ex);
|
||
}
|
||
}
|
||
|
||
</text>
|
||
//文本结束===================================================
|
||
}
|
||
else
|
||
{
|
||
string parametersName=@classInfo.ClassMethodInfos[j].Parameters[0].ParameterTypeName.Replace("String", "string").Replace("Boolean", "bool")+" "+@classInfo.ClassMethodInfos[j].Parameters[0].ParameterName;
|
||
if(classInfo.ClassMethodInfos[j].Parameters.Length>1 && classInfo.ClassMethodInfos[j].HttpName!="[HttpGet]")
|
||
{
|
||
parametersName=@classInfo.ClassMethodInfos[j].MethodName+"CompositionData compositionData";
|
||
}
|
||
else if(classInfo.ClassMethodInfos[j].Parameters.Length>1)
|
||
{
|
||
parametersName=string.Empty;
|
||
for (var ikb = 0; ikb < classInfo.ClassMethodInfos[j].Parameters.Length; ikb++){
|
||
if(ikb>0)parametersName+=", ";
|
||
parametersName+=@classInfo.ClassMethodInfos[j].Parameters[ikb].ParameterTypeName.Replace("String", "string").Replace("Boolean", "bool")+" "+@classInfo.ClassMethodInfos[j].Parameters[ikb].ParameterName;
|
||
}
|
||
}
|
||
//文本开始================================================
|
||
<text> public dynamic @{@classInfo.ClassMethodInfos[j].MethodName}(@{@parametersName})</text><text>
|
||
{
|
||
try
|
||
{
|
||
|
||
var result = @{@classInfo.ClassName.StringToProtectedProerty()}.@{@classInfo.ClassMethodInfos[j].MethodName}(@{for (var i = 0; i < classInfo.ClassMethodInfos[j].Parameters.Length; i++){
|
||
if(classInfo.ClassMethodInfos[j].Parameters.Length>1){
|
||
if(i>0){<text>,</text>}if(classInfo.ClassMethodInfos[j].HttpName!="[HttpGet]"){<text>compositionData.</text>}<text>@classInfo.ClassMethodInfos[j].Parameters[i].ParameterName</text>
|
||
}
|
||
else{
|
||
<text>@classInfo.ClassMethodInfos[j].Parameters[i].ParameterName</text>
|
||
}
|
||
}});
|
||
return result;
|
||
}
|
||
catch (ValidatedException vex)
|
||
{
|
||
return vex;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new ServiceErrorException(ex);
|
||
}
|
||
}
|
||
|
||
</text>
|
||
//文本结束===================================================
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//下面}为代码段结束=================================================================================================================
|
||
}
|
||
|
||
}
|
||
} |