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.
 
 
 
 
 

208 lines
5.6 KiB

<%@ CodeTemplate Language="C#" ClassName="Go_ModelOrm" 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+"\\GoModelOrm\\"+tb.ModuleName.ToLower()+"\\"+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.ToLower()+",";
if( fd.DataType.Convert == "ToString")
noDefaultFieldValues += "'\"+formatcom.String(m."+fd.PropertyName+")+\"',";
else if( fd.DataType.Convert == "ToDateTime")
noDefaultFieldValues += "'\"+formatcom.ToString(m."+fd.PropertyName+")+\"',";
else if( fd.DataType.Convert == "ToDecimal")
noDefaultFieldValues += "'\"+formatcom.FloatToStr(m."+fd.PropertyName+")+\"',";
else if( fd.DataType.Convert == "ToInt32")
noDefaultFieldValues += "'\"+formatcom.IntToStr(m."+fd.PropertyName+")+\"',";
else
noDefaultFieldValues += "\"+formatcom.String(m."+fd.PropertyName+")+\",";
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(","))
noDefaultFieldValues = noDefaultFieldValues.Substring(0,noDefaultFieldValues.Length-1);
noDefaultFieldFormats = noDefaultFieldFormats.Trim(',');
noDefaultFieldFormats = noDefaultFieldFormats.Trim('+');
%>
/*******************************************************/
/*Project:
Module :
Description :
Date : <%=DateTime.Now.ToString()%>
Create : Lxc
Update :
TODO : */
/*******************************************************/
package <%=tb.ModuleName.ToLower()%>
import (
"hm/eclibs/formatcom"
"hm/eclibs/logger"
"hm/eclibs/db"
)
type <%=tb.PropertyName%> struct {
<%
foreach(Field fd in tb.Fields)
{
if( fd.DataType.Convert == "ToDateTime")
{
Response.Write("\t"+fd.PropertyName +" string ");
}
else if( fd.DataType.Convert == "ToInt32")
{
Response.Write("\t"+fd.PropertyName +" int64 ");
}
else if( fd.DataType.Convert == "ToString")
{
Response.Write("\t"+fd.PropertyName +" string");
}
else if( fd.DataType.Convert == "ToDecimal")
{
Response.Write("\t"+fd.PropertyName +" float64");
}
else
Response.Write("\t"+fd.PropertyName +" string");
Response.WriteLine("\t`json:\""+fd.PropertyName.ToLower()+"\"`");
}
%>
}
func (m *<%=tb.PropertyName%>) TableName() string {
return "<%=tb.TableSpace.ToLower()+tb.PropertyName.ToLower()%>"
}
func (m *<%=tb.PropertyName%>) ViewName() string {
return "v_<%=tb.PropertyName.ToLower()%>"
}
func (m *<%=tb.PropertyName%>)Add() int64 {
return db.Insert(m)
}
func (m *<%=tb.PropertyName%>) Update( ) int64 {
return db.Update(m)
}
func (m *<%=tb.PropertyName%>) Delete( ) int64 {
id:=m.Id
sql:="delete from " + m.TableName() + " where id="+ formatcom.IntToStr(id)
rows, err := db.Delete(sql)
if err != nil {
logger.Error(err.Error())
}
return rows
}
func (m *<%=tb.PropertyName%>) GetModel(uid int64) *<%=tb.PropertyName%> {
where := "id=" + formatcom.IntToStr(uid)
return m.GetModelByWhere(where )
}
func (m *<%=tb.PropertyName%>) GetModelByWhere(where string) *<%=tb.PropertyName%> {
<%=tb.PropertyName.ToLower()%>Arr, err := m.<%=tb.PropertyName%>Arr(where)
if err != nil {
logger.Error("GetModel where=", where)
return nil
}
for _, value := range <%=tb.PropertyName.ToLower()%>Arr {
model := new(<%=tb.PropertyName%>)
err :=db.BindData(model, value)
if err !=nil{
logger.Error(err)
continue
}
return model
}
return nil
}
func (m *<%=tb.PropertyName%>)<%=tb.PropertyName%>Arr(where string) ([]db.Params, error) {
var sqlstr = "select a.* from " + m.TableName() + " a "
if where != "" {
sqlstr += " where " + where
}
<%=tb.PropertyName.ToLower()%>list, err := db.Query(sqlstr)
return <%=tb.PropertyName.ToLower()%>list, err
}
func (m *<%=tb.PropertyName%>)<%=tb.PropertyName%>List(where string) ([]*<%=tb.PropertyName%>, error) {
<%=tb.PropertyName.ToLower()%>List := make([]*<%=tb.PropertyName%>, 0, 1)
<%=tb.PropertyName.ToLower()%>Arr, err := m.<%=tb.PropertyName%>Arr(where)
if err != nil {
return <%=tb.PropertyName.ToLower()%>List, err
}
if <%=tb.PropertyName.ToLower()%>Arr == nil {
return <%=tb.PropertyName.ToLower()%>List, nil
}
for _, value := range <%=tb.PropertyName.ToLower()%>Arr {
model := new(<%=tb.PropertyName%>)
err :=db.BindData(model, value)
if err !=nil{
logger.Error(err)
continue
}
<%=tb.PropertyName.ToLower()%>List = append(<%=tb.PropertyName.ToLower()%>List, model)
}
return <%=tb.PropertyName.ToLower()%>List, nil
}
<%
CloseResponse();
}
%>