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.

167 lines
4.6 KiB

1 year ago
<%@ CodeTemplate Language="C#" ClassName="GoModel" TargetLanguage="C#" Debug="False" Description="" encoding="GB2312" %>
<%@ Property Name="databaseProjectName" Type="System.String" Default="SpSampleDb" Optional="True" Category="Context" Description="" %>
<%@ Property Name="nameSpace" Type="System.String" Default="Model" Optional="True" Category="Context" Description="" %>
<%
DbEntity db = Template.GetDataBase(databaseProjectName);
foreach(Table tb in db.Tables)
{
OpenResponse(databaseProjectName+"\\GoModel\\"+tb.ModuleName+"\\"+tb.PropertyName.ToLower()+".go");
string pkParmList = "";
foreach(Field fd in tb.Fields)
{
if(fd.IsPK == true)
pkParmList += fd.DataType.DotNetType+" "+fd.MemberName+",";
}
pkParmList = pkParmList.Trim(',');
string noDefaultFields = "";
string noDefaultFieldFormats = "";
string noDefaultFieldValues = "";
int iField = 0;
foreach(Field fd in tb.Fields)
{
if( (fd.DefaultValue != "" || fd.DefaultValue != null) && fd.Identity.Enable == false)
{
noDefaultFields += ""+fd.PropertyName+",";
if( fd.DataType.GroupName.ToUpper() == "STRING")
noDefaultFieldValues += "\t\t\t\t\tFormatCom.String("+tb.MemberName+"."+fd.MemberName+"),\r\n";
else if( fd.DataType.GroupName.ToUpper() == "DATETIME")
noDefaultFieldValues += "\t\t\t\t\tDBAccess.DateStr("+tb.MemberName+"."+fd.MemberName+"),\r\n";
else
noDefaultFieldValues += "\t\t\t\t\t"+tb.MemberName+"."+fd.MemberName+",\r\n";
if( fd.DataType.GroupName.ToUpper() == "NUMBER")
noDefaultFieldFormats += "{"+iField.ToString()+"},";
//else if( fd.DataType.GroupName.ToUpper() == "DATETIME")
// noDefaultFieldFormats += "{"+iField.ToString()+"},";
else
noDefaultFieldFormats += "'{"+iField.ToString()+"}',";
iField++;
}
}
if( noDefaultFields.EndsWith(","))
noDefaultFields = noDefaultFields.Substring(0,noDefaultFields.Length-1);
if( noDefaultFieldValues.EndsWith(",\r\n"))
noDefaultFieldValues = noDefaultFieldValues.Substring(0,noDefaultFieldValues.Length-3);
noDefaultFieldFormats = noDefaultFieldFormats.Trim(',');
%>
/*******************************************************/
/*Project:
Module :
Description :
Date : <%=DateTime.Now.ToString()%>
Create : Lxc
Update :
TODO : */
/*******************************************************/
package models
import (
"errors"
"strconv"
"time"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
)
var (
<%=tb.PropertyName%>List map[string]*<%=tb.PropertyName%>
)
func init() {
<%=tb.PropertyName%>List = make(map[string]*<%=tb.PropertyName%>)
u := new (<%=tb.PropertyName%>)
<%=tb.PropertyName%>List["user_11111"] = u
}
type <%=tb.PropertyName%> struct {
<%
foreach(Field fd in tb.Fields)
{
if( fd.DataType.Convert == "ToDateTime")
{
Response.WriteLine("\t"+fd.PropertyName +" DateTime");
}
else if( fd.DataType.Convert == "ToInt32")
{
Response.WriteLine("\t"+fd.PropertyName +" int");
}
else if( fd.DataType.Convert == "ToString")
{
Response.WriteLine("\t"+fd.PropertyName +" string");
}
else
Response.WriteLine("\t"+fd.PropertyName +" string");
}
%>
}
func <%=tb.PropertyName%>Factory() (u * <%=tb.PropertyName%>) {
return new( <%=tb.PropertyName%>)
}
func (m <%=tb.PropertyName%>)Add(u <%=tb.PropertyName%>) string {
u.Id = "user_" + strconv.FormatInt(time.Now().UnixNano(), 10)
<%=tb.PropertyName%>List[u.Id] = &u
return u.Id
}
func (m <%=tb.PropertyName%>) GetOneById(uid string) (u *<%=tb.PropertyName%>, err error) {
if u, ok := <%=tb.PropertyName%>List[uid]; ok {
return u, nil
}
return nil, errors.New("<%=tb.PropertyName%> not exists")
}
func (m <%=tb.PropertyName%>) GetAll() ([]orm.Params, error) {
beego.Debug("GetAll<%=tb.PropertyName%>")
var maps []orm.Params
sql := "select <%=noDefaultFields%> from t_car_brand where 1=1"
var num, err = orm.NewOrm().Raw(sql).Values(&maps)
if err == nil && num > 0 {
beego.Debug("num=", num)
return maps, err
}
return nil, err
}
func (m <%=tb.PropertyName%>) GetById(id int) (*<%=tb.PropertyName%>, error) {
u := new(<%=tb.PropertyName%>)
err := orm.NewOrm().QueryTable(TableName("<%=tb.PropertyName%>")).Filter("id", id).One(u)
if err != nil {
return nil, err
}
return u, nil
}
func (m <%=tb.PropertyName%>) Update(uid string, uu *<%=tb.PropertyName%>) (a *<%=tb.PropertyName%>, err error) {
if u, ok := <%=tb.PropertyName%>List[uid]; ok {
/*
if uu.Username != "" {
u.Username = uu.Username
}
*/
return u, nil
}
return nil, errors.New("User Not Exist")
}
func (m <%=tb.PropertyName%>) Delete(uid string) {
delete(<%=tb.PropertyName%>List, uid)
}
<%
CloseResponse();
}
%>