DT 的数据字典
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

228 lines
6.6 KiB

<%@ CodeTemplate Language="C#" ClassName="Go_FastApiCtrl" TargetLanguage="C#" Debug="False" Description="" %>
<%@ Property Name="databaseName" Type="System.String" Default="TqAd" Optional="True" Category="Context" Description="" %>
<%@ Property Name="databaseProjectName" Type="System.String" Default="SpSampleDb" Optional="True" Category="Context" Description="" %>
<%@ Property Name="nameSpace" Type="System.String" Default="Ctrl" Optional="True" Category="Context" Description="" %>
<%
DbEntity db = Template.GetDataBase(databaseProjectName);
foreach(Table tb in db.Tables)
{
OpenResponse(databaseProjectName+"\\GoFastApiCtrl\\"+tb.ModuleName+"\\"+tb.PropertyName.ToLower()+"ctrl.go");
string pkParmList = "";
foreach(Field fd in tb.Fields)
{
if(fd.IsPK == true)
pkParmList += fd.DataType.DotNetType+" "+fd.MemberName+",";
}
pkParmList = pkParmList.Trim(',');
%>
/*******************************************************/
/*Project:
Module :
Description :
Date : <%=DateTime.Now.ToString()%>
Create : Lxc
Update :
TODO : */
/*******************************************************/
package controllers
import (
// "hm/eclibs/formatcom"
"hm/eclibs/logger"
"github.com/labstack/echo"
"hm/apiserver/models/<%=tb.ModuleName.ToLower()%>"
)
/*
<%=tb.PropertyName.ToLower()%>Ctrl = new(controllers.<%=tb.PropertyName%>Ctrl)
e.GET("/<%=tb.PropertyName.ToLower()%>/:uid", <%=tb.PropertyName.ToLower()%>Ctrl .Get)
e.GET("/<%=tb.PropertyName.ToLower()%>/q/:method", <%=tb.PropertyName.ToLower()%>Ctrl .Query)
e.POST("/<%=tb.PropertyName.ToLower()%>", <%=tb.PropertyName.ToLower()%>Ctrl .Post)
e.PUT("/<%=tb.PropertyName.ToLower()%>/:uid", <%=tb.PropertyName.ToLower()%>Ctrl .Put)
e.POST("/<%=tb.PropertyName.ToLower()%>/:method", <%=tb.PropertyName.ToLower()%>Ctrl .Patch)
e.DELETE("/<%=tb.PropertyName.ToLower()%>/:uid", <%=tb.PropertyName.ToLower()%>Ctrl .Delete)
*/
// Operations about <%=tb.PropertyName%>
type <%=tb.PropertyName%>Ctrl struct {
BaseController
}
// @Title Get
// @Description get <%=tb.PropertyName%> by uid
// @Param uid path string true "The key for staticblock"
// @Success 200 {object} models.<%=tb.MemberName%>
// @Failure 403 :uid is empty
// @router /:uid [get]
func (this *<%=tb.PropertyName%>Ctrl) Get(c echo.Context) error {
resultDto := NewResultDto()
uid :=c.Param("uid")
logger.Debug(uid)
if uid != "" {
<%=tb.MemberName.ToLower()%>Dal:= new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
<%=tb.MemberName.ToLower()%> := <%=tb.MemberName.ToLower()%>Dal.GetModel(uid)
if <%=tb.MemberName.ToLower()%> != nil {
resultDto.ResultData = <%=tb.MemberName.ToLower()%>
} else {
logger.Error("<%=tb.MemberName.ToLower()%>")
}
}
return this.JSON(c, resultDto)
}
// @Title Query
// @Description get all <%=tb.MemberName%>
// @Success 200 {object} models.<%=tb.MemberName%>
// @router / [get]
func (this *<%=tb.PropertyName%>Ctrl) Query(c echo.Context) error {
resultDto := NewResultDto()
method := c.Param("method")
logger.Debug("method=" + method)
<%=tb.MemberName.ToLower()%>Dal:= new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
where := ""
if method == "all" {
<%=tb.MemberName%>List, _ := <%=tb.MemberName.ToLower()%>Dal.<%=tb.PropertyName%>List(where)
resultDto.ResultData = <%=tb.MemberName%>List
} else if method == "<%=tb.MemberName%>" {
//washid := c.QueryParam("washid")
where = ""
<%=tb.MemberName%>List, _ := <%=tb.MemberName.ToLower()%>Dal.<%=tb.PropertyName%>List(where)
resultDto.ResultData = <%=tb.MemberName%>List
} else {
resultDto.Result = R_ERROR
resultDto.Message = "err:Query not finded method="+method
}
return this.JSON(c, resultDto)
}
// @Title create<%=tb.PropertyName%>
// @Description create <%=tb.PropertyName%>
// @Param body body models.<%=tb.PropertyName%> true "body for <%=tb.PropertyName%> content"
// @Success 200 {int} models.<%=tb.PropertyName%>.Id
// @Failure 403 body is empty
// @router / [post]
func (this *<%=tb.PropertyName%>Ctrl) Post(c echo.Context) error {
resultDto := NewResultDto()
model := new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
err := this.PostBind(c, model)
if err != nil {
logger.Error(err)
resultDto.Result = R_ERROR
resultDto.Message = err.Error()
}
id,err :=model.Add()
if id>0 {
resultDto.Result = R_SUCCESS
} else {
resultDto.Result = R_ERROR
resultDto.Message = err.Error()
}
return this.JSON(c, resultDto)
}
// @Title update
// @Description update the user
// @Param uid path string true "The uid you want to update"
// @Param body body models.User true "body for user content"
// @Success 200 {object} models.User
// @Failure 403 :uid is not int
// @router /:uid [put]
func (this *<%=tb.PropertyName%>Ctrl) Put(c echo.Context) error {
resultDto := NewResultDto()
uid := c.Param("uid")
if uid != "" {
<%=tb.MemberName.ToLower()%>Dal := new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
model := <%=tb.MemberName.ToLower()%>Dal.GetModel(uid)
if model == nil {
resultDto.Result = R_ERROR
resultDto.Message = "not exists��"
return this.JSON(c, resultDto)
}
err := this.PostBind(c, model)
if err != nil {
logger.Error(err)
resultDto.Result = R_ERROR
resultDto.Message = err.Error()
}
rows, err :=model.Update()
if rows>0 {
resultDto.Result = R_SUCCESS
} else {
resultDto.Result = R_ERROR
resultDto.Message = err.Error()
}
}
return this.JSON(c, resultDto)
}
func (this *<%=tb.PropertyName%>Ctrl) Patch(c echo.Context) error {
resultDto := NewResultDto()
method := c.Param("method")
logger.Debug("Patch method=" + method)
model := new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
err := this.PostBind(c, model)
if err != nil {
logger.Error(err)
resultDto.Result = R_ERROR
resultDto.Message = err.Error()
}
if method == "method1" {
//model.Brand = c.FormValue("brand")
} else {
resultDto.Result = R_ERROR
resultDto.Message = "err:Path not finded method="+method
}
return this.JSON(c, resultDto)
}
// @Title delete
// @Description delete the <%=tb.MemberName%>
// @Param uid path string true "The uid you want to delete"
// @Success 200 {string} delete success!
// @Failure 403 uid is empty
// @router /:uid [delete]
func (this *<%=tb.PropertyName%>Ctrl) Delete(c echo.Context) error {
resultDto := NewResultDto()
uid := c.Param("uid")
logger.Debug(uid)
<%=tb.PropertyName.ToLower()%>Model := new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
rows,err:=<%=tb.PropertyName.ToLower()%>Model.Delete(uid)
if rows > 0 {
resultDto.Result = R_SUCCESS
} else {
resultDto.Result = R_ERROR
resultDto.Message = err.Error()
}
return this.JSON(c, resultDto)
}
<%
CloseResponse();
}
%>