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.
 
 
 
 
 

241 lines
6.8 KiB

<%@ CodeTemplate Language="C#" ClassName="Go_ModelSvr" 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+"\\GoModelSvr\\"+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.ToLower()+",";
if( fd.DataType.Convert == "ToString")
noDefaultFieldValues += "'\"+format.String(u."+fd.PropertyName+")+\"',";
else if( fd.DataType.Convert == "ToDateTime")
noDefaultFieldValues += "'\"+format.ToString(u."+fd.PropertyName+")+\"',";
else if( fd.DataType.Convert == "ToDecimal")
noDefaultFieldValues += "'\"+format.FloatToStr(u."+fd.PropertyName+")+\"',";
else if( fd.DataType.Convert == "ToInt32")
noDefaultFieldValues += "'\"+format.IntToStr(u."+fd.PropertyName+")+\"',";
else
noDefaultFieldValues += "\"+format.String(u."+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 models
import (
"github.com/easycode/eclibs/format"
"github.com/easycode/eclibs/logger"
"github.com/easycode/eclibs/orm"
)
type <%=tb.PropertyName%> struct {
<%
foreach(Field fd in tb.Fields)
{
if( fd.DataType.Convert == "ToDateTime")
{
Response.WriteLine("\t"+fd.PropertyName +" string ");
}
else if( fd.DataType.Convert == "ToInt32")
{
Response.WriteLine("\t"+fd.PropertyName +" int64 ");
}
else if( fd.DataType.Convert == "ToString")
{
Response.WriteLine("\t"+fd.PropertyName +" string");
}
else if( fd.DataType.Convert == "ToDecimal")
{
Response.WriteLine("\t"+fd.PropertyName +" float64");
}
else
Response.WriteLine("\t"+fd.PropertyName +" string");
}
%>
}
func (m <%=tb.PropertyName%>)Add(u <%=tb.PropertyName%>) bool {
sql := "insert into " + orm.TableName("<%=tb.PropertyName%>") + " (<%=noDefaultFields%>) values(<%=noDefaultFieldValues%>) "
ok, err := orm.Insert(sql)
if err != nil {
logger.Error(err.Error())
}
return ok
}
func (m <%=tb.PropertyName%>)<%=tb.PropertyName%>Arr(where string) ([]orm.Params, error) {
var sqlstr = "select a.* from " + orm.TableName("<%=tb.PropertyName%>") + " a "
if where != "" {
sqlstr += " where " + where
}
<%=tb.PropertyName.ToLower()%>list, err := orm.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 {
<%=tb.PropertyName.ToLower()%> := m.MapToClass(value)
<%=tb.PropertyName.ToLower()%>List = append(<%=tb.PropertyName.ToLower()%>List, <%=tb.PropertyName.ToLower()%>)
}
return <%=tb.PropertyName.ToLower()%>List, nil
}
func (m <%=tb.PropertyName%>)MapToClass(value orm.Params) *<%=tb.PropertyName%> {
//teststr, _ := json.Marshal(value)
//logger.Debug("arr =" + string(teststr))
<%=tb.PropertyName.ToLower()%> := new(<%=tb.PropertyName%> )
<%
foreach(Field fd in tb.Fields)
{
if( fd.DataType.Convert == "ToInt32")
{
Response.WriteLine("\t"+tb.PropertyName.ToLower()+"."+fd.PropertyName+" = format.StrToInt(value[\""+fd.PropertyName.ToLower()+"\"])");
}
else if( fd.DataType.Convert == "ToDecimal")
{
Response.WriteLine("\t"+tb.PropertyName.ToLower()+"."+fd.PropertyName+" = format.StrToFloat(value[\""+fd.PropertyName.ToLower()+"\"])");
}
else
Response.WriteLine("\t"+tb.PropertyName.ToLower()+"."+fd.PropertyName+" = format.ToString(value[\""+fd.PropertyName.ToLower()+"\"])");
}
%>
//teststr1, _ := json.Marshal(order)
//logger.Debug("order=" + string(teststr1))
return <%=tb.PropertyName.ToLower()%>
}
func (m <%=tb.PropertyName%>) Update( u *<%=tb.PropertyName%>) bool {
sql := "Update <%=tb.PropertyName%> set <%
iField = 0;
string updstr = "";
string upvalue = "";
iField = 0;
bool bHasPrevPk = false;
foreach(Field fd in tb.Fields)
{
if( fd.Identity.Enable == false && (fd.IsPK == false || bHasPrevPk== true))
{
updstr += ""+fd.PropertyName+"= ";
if( fd.DataType.Convert == "ToInt32")
{
updstr += "\"+format.IntToStr(u."+fd.PropertyName +")+\",";
}
else if( fd.DataType.Convert == "ToDecimal")
{
updstr += "\"+format.FloatToStr(u."+fd.PropertyName +")+\",";
}
else
updstr += "'\""+"+format.ToString(u."+fd.PropertyName+")+\"',";
//updstr += ",";
iField++;
}
if( fd.IsPK == true)
bHasPrevPk = true;
}
if( updstr.EndsWith(",\r\n"))
updstr = updstr.Substring(0,updstr.Length-3);
if( updstr.EndsWith(","))
updstr = updstr.Substring(0,updstr.Length-1);
%><%=updstr%>where id="+format.IntToStr(u.Id)
ok, err := orm.Update(sql)
if err != nil {
logger.Error(err.Error())
}
return ok
}
func (m <%=tb.PropertyName%>) Delete(id int64 ) bool {
sql:="delete from <%=tb.PropertyName%> where id="+ format.IntToStr(id)
ok, err := orm.Delete(sql)
if err != nil {
logger.Error(err.Error())
}
return ok
}
<%
CloseResponse();
}
%>