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.

188 lines
5.6 KiB

1 year ago
<%@ CodeTemplate Language="C#" ClassName="Go_Ctrl" 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="Ctrl" Optional="True" Category="Context" Description="" %>
<%
DbEntity db = Template.GetDataBase(databaseProjectName);
foreach(Table tb in db.Tables)
{
OpenResponse(databaseProjectName+"\\GoCtrl\\"+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 (
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/easycode/carapi/models"
)
// Operations about <%=tb.PropertyName%>
type <%=tb.PropertyName%>Ctrl struct {
beego.Controller
}
// @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 (c *<%=tb.PropertyName%>Ctrl) Post() {
var serial models.<%=tb.PropertyName%>
json.Unmarshal(c.Ctx.Input.RequestBody, &serial)
//<%=tb.MemberName%> := models.<%=tb.PropertyName%>Factory() // new(models.<%=tb.PropertyName%>)
uid := serial.Add(serial)
c.Data["json"] = map[string]string{"uid": uid}
c.ServeJSON()
}
// @Title Query
// @Description get all <%=tb.MemberName%>
// @Success 200 {object} models.<%=tb.MemberName%>
// @router / [get]
func (c *<%=tb.PropertyName%>Ctrl) Query() {
method := c.GetString("method")
beego.Debug("method=" + method)
resultModel := new(models.ResultModel) // =new ResultRowModel()
var <%=tb.MemberName%>map []orm.Params
var err error = nil
<%=tb.MemberName%> := models.<%=tb.PropertyName%>Factory() // new(models.<%=tb.PropertyName%>)
if method == "all<%=tb.MemberName%>" {
All<%=tb.MemberName%>(c)
} else if method == "<%=tb.MemberName%>" {
//<%=tb.MemberName%>map, err = <%=tb.MemberName%>.GetAllImportBrand()
} else {
resultModel.Result = "error"
resultModel.Message = "��ѯû������"
resultModel.Resutcode = "err:<%=tb.MemberName%>_Q_002"
c.Data["jsonp"] = resultModel
c.ServeJSONP()
}
beego.Debug("method success=" + method)
if err == nil {
resultModel.Result = "success"
resultModel.Rows = <%=tb.MemberName%>map
//resultModel.Rows1 = <%=tb.MemberName%>.GetBrandGroup(<%=tb.MemberName%>map)
c.Data["jsonp"] = resultModel
} else {
resultModel.Result = "error"
resultModel.Message = "��ѯû������"
resultModel.Resutcode = "err:<%=tb.MemberName%>_Q_001"
c.Data["jsonp"] = resultModel
}
c.ServeJSONP()
}
/*���ҳ���ͨ��pid*/
func All<%=tb.MemberName%>(c *SerialCtrl) {
resultModel := new(models.ResultModel)
pid := c.GetString("pid")
serialModel := models.SerialFactory()
serialmap, err := serialModel.GetByPid(pid)
if err == nil {
resultModel.Result = "success"
resultModel.Rows = serialmap
c.Data["jsonp"] = resultModel
} else {
resultModel.Result = "error"
resultModel.Message = "�������ݴ���"
resultModel.Resutcode = "err:t_Car_Serial_Q_002"
beego.Error(err)
c.Data["jsonp"] = resultModel
}
c.ServeJSONP()
}
// @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 (c *<%=tb.PropertyName%>Ctrl) Get() {
uid := c.GetString(":uid")
beego.Error(uid)
callback1 := c.GetString("callback")
beego.Error(callback1)
if uid != "" {
<%=tb.PropertyName.ToLower()%>Model := models.<%=tb.PropertyName%>Factory() // new(models.<%=tb.PropertyName%>)
<%=tb.PropertyName.ToLower()%> , err := <%=tb.PropertyName.ToLower()%>Model.GetOneById(uid)
if err != nil {
c.Data["jsonp"] = err.Error()
} else {
c.Data["jsonp"] = <%=tb.PropertyName.ToLower()%>
beego.Error("<%=tb.PropertyName.ToLower()%>")
}
}
c.ServeJSONP()
}
// @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 (c *<%=tb.PropertyName%>Ctrl) Put() {
uid := c.GetString(":uid")
if uid != "" {
var <%=tb.PropertyName.ToLower()%> models.<%=tb.PropertyName%>
json.Unmarshal(c.Ctx.Input.RequestBody, &<%=tb.PropertyName.ToLower()%> )
uu, err := <%=tb.PropertyName.ToLower()%> .Update(uid, &<%=tb.PropertyName.ToLower()%> )
if err ==nil{
c.Data["jsonp"] = uu
}else {//dosoming
}
}
beego.Error(uid)
c.ServeJSONP()
}
// @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 (c *<%=tb.PropertyName%>Ctrl) Delete() {
uid := c.GetString(":uid")
beego.Error(uid)
<%=tb.PropertyName.ToLower()%>Model := models.<%=tb.PropertyName%>Factory() // new(models.<%=tb.PropertyName%>)
<%=tb.PropertyName.ToLower()%>Model.Delete(uid)
c.Data["json"] = "delete success!"
c.ServeJSONP()
}
<%
CloseResponse();
}
%>