Skip to content

Latest commit

 

History

History
527 lines (492 loc) · 16.4 KB

配置XML.md

File metadata and controls

527 lines (492 loc) · 16.4 KB

application

<?xml version="1.0" encoding="utf-8" ?>
<application name="scene" desc="dolphin template" packagename="scene"/>

bean

<bean name="article_info" desc="文章信息" 
    extends="$article">
    <prop name="url" desc="地址" type="null.String" />
</bean>
// Code generated by dol build. DO NOT EDIT.
// source: auto.go

package types

import (
	"github.com/2637309949/dolphin/packages/null"
)

// ArticleInfo defined 文章信息
type ArticleInfo struct {
	*Article
	// 地址
	URL null.String `json:"url" xml:"url"`
}

controller

<controller name="article" desc="文章">
    <api name="add" func="add" table="article" method="post" desc="批量添加文章">
        <param name="article" type="$article" desc="文章信息"/>
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="batch_add" func="add" table="article" desc="批量添加文章" method="post">
        <param name="article" type="[]$article" desc="文章信息" />
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="del" func="delete" table="article" method="delete" desc="删除文章">
        <param name="article" type="$article" desc="文章"/>
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="batch_del" func="delete" table="article" desc="批量删除文章" method="put">
        <param name="article" type="[]$article" desc="文章信息" />
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="update" func="update" table="article" desc="更新文章" method="put">
        <param name="article" type="$article" desc="文章信息" />
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="batch_update" func="update" table="article" desc="批量更新文章" method="put">
        <param name="article" type="[]$article" desc="文章信息" />
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="page" func="page" table="article" method="get" desc="文章分页查询">
        <param name="page" type="int" value="1" desc="页码"/>
        <param name="size" type="int" value="15" desc="单页数"/>
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="get" func="one" table="article" method="get" desc="获取文章信息">
        <param name="id" type="string" desc="文章id" />
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
    <api name="payment" method="post" desc="文章付费">
        <param name="article" type="$article_info" desc="文章"/>
        <return>
            <success type="$success"/>
            <failure type="$fail"/>
        </return>
    </api>
</controller>
// Code generated by dol build. Only Generate by tools if not existed.
// source: article.go

package api

import (
	"errors"
	"scene/types"

	"time"

	"github.com/2637309949/dolphin/packages/null"
	"github.com/2637309949/dolphin/packages/logrus"
	"github.com/thoas/go-funk"
)

// ArticleAdd api implementation
// @Summary 添加文章
// @Tags 文章
// @Accept application/json
// @Param Authorization header string false "认证令牌"
// @Param article body types.Article false "文章信息"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/add [post]
func (ctr *Article) ArticleAdd(ctx *Context) {
	var payload types.Article
	if err := ctx.ShouldBindWith(&payload); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	payload.CreateTime = null.TimeFromNow()
	payload.Creater = null.IntFromStr(ctx.MustToken().GetUserID())
	payload.UpdateTime = null.TimeFromNow()
	payload.Updater = null.IntFromStr(ctx.MustToken().GetUserID())
	payload.IsDelete = null.IntFrom(0)
	ret, err := ctx.MustDB().Insert(&payload)
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

// ArticleBatchAdd api implementation
// @Summary 批量添加文章
// @Tags 文章
// @Accept application/json
// @Param Authorization header string false "认证令牌"
// @Param article body []types.Article false "文章信息"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/batch_add [post]
func (ctr *Article) ArticleBatchAdd(ctx *Context) {
	var payload []types.Article
	if err := ctx.ShouldBindWith(&payload); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	for i := range payload {
		payload[i].CreateTime = null.TimeFromNow()
		payload[i].Creater = null.IntFromStr(ctx.MustToken().GetUserID())
		payload[i].UpdateTime = null.TimeFromNow()
		payload[i].Updater = null.IntFromStr(ctx.MustToken().GetUserID())
		payload[i].IsDelete = null.IntFrom(0)
	}
	ret, err := ctx.MustDB().Insert(&payload)
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

// ArticleDel api implementation
// @Summary 删除文章
// @Tags 文章
// @Accept application/json
// @Param Authorization header string false "认证令牌"
// @Param article body types.Article false "文章"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/del [delete]
func (ctr *Article) ArticleDel(ctx *Context) {
	var payload types.Article
	if err := ctx.ShouldBindWith(&payload); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ret, err := ctx.MustDB().In("id", payload.ID.Int64).Update(&types.Article{
		UpdateTime: null.TimeFromNow(),
		Updater:    null.IntFromStr(ctx.MustToken().GetUserID()),
		IsDelete:   null.IntFrom(1),
	})
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

// ArticleBatchDel api implementation
// @Summary 批量删除文章
// @Tags 文章
// @Accept application/json
// @Param Authorization header string false "认证令牌"
// @Param article body []types.Article false "文章信息"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/batch_del [put]
func (ctr *Article) ArticleBatchDel(ctx *Context) {
	var payload []types.Article
	if err := ctx.ShouldBindWith(&payload); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	var ids = funk.Map(payload, func(form types.Article) int64 { return form.ID.Int64 }).([]int64)
	ret, err := ctx.MustDB().In("id", ids).Update(&types.Article{
		UpdateTime: null.TimeFromNow(),
		Updater:    null.IntFromStr(ctx.MustToken().GetUserID()),
		IsDelete:   null.IntFrom(1),
	})
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

// ArticleUpdate api implementation
// @Summary 更新文章
// @Tags 文章
// @Accept application/json
// @Param Authorization header string false "认证令牌"
// @Param article body types.Article false "文章信息"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/update [put]
func (ctr *Article) ArticleUpdate(ctx *Context) {
	var payload types.Article
	if err := ctx.ShouldBindWith(&payload); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	payload.Updater = null.IntFromStr(ctx.MustToken().GetUserID())
	payload.UpdateTime = null.TimeFromNow()
	ret, err := ctx.MustDB().ID(payload.ID.Int64).Update(&payload)
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

// ArticleBatchUpdate api implementation
// @Summary 批量更新文章
// @Tags 文章
// @Accept application/json
// @Param Authorization header string false "认证令牌"
// @Param article body []types.Article false "文章信息"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/batch_update [put]
func (ctr *Article) ArticleBatchUpdate(ctx *Context) {
	var payload []types.Article
	var err error
	var ret []int64
	var r int64
	if err := ctx.ShouldBindWith(&payload); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	s := ctx.MustDB().NewSession()
	s.Begin()
	defer s.Close()
	s.Begin()
	defer s.Close()
	for i := range payload {
		payload[i].UpdateTime = null.TimeFromNow()
		payload[i].Updater = null.IntFromStr(ctx.MustToken().GetUserID())
		r, err = s.ID(payload[i].ID.Int64).Update(&payload[i])
		if err != nil {
			logrus.Error(err)
			s.Rollback()
			ctx.Fail(err)
			return
		}
		ret = append(ret, r)
	}
	if err != nil {
		logrus.Error(err)
		s.Rollback()
		ctx.Fail(err)
		return
	}
	err = s.Commit()
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

// ArticlePage api implementation
// @Summary 文章分页查询
// @Tags 文章
// @Param Authorization header string false "认证令牌"
// @Param page  query  int false "页码"
// @Param size  query  int false "单页数"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/page [get]
func (ctr *Article) ArticlePage(ctx *Context) {
	q := ctx.TypeQuery()
	q.SetInt("page", 1)
	q.SetInt("size", 15)
	q.SetRule("article_page")
	q.SetString("creater")
	q.SetString("updater")
	q.SetRange("create_time")
	q.SetRange("update_time")
	q.SetInt("is_delete", 0)()
	q.SetString("sort", "update_time desc")
	q.SetTags()
	ret, err := ctr.Srv.DB.PageSearch(ctx.MustDB(), "article", "page", "article", q.Value())
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

// ArticleGet api implementation
// @Summary 获取文章信息
// @Tags 文章
// @Param Authorization header string false "认证令牌"
// @Param id  query  string false "文章id"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/get [get]
func (ctr *Article) ArticleGet(ctx *Context) {
	var entity types.Article
	err := ctx.ShouldBindWith(&entity)
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	if ext, err := ctx.MustDB().Get(&entity); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	} else if !ext {
		ctx.Fail(types.ErrNotFound)
		return
	}
	ctx.Success(entity)
}

// ArticlePayment api implementation
// @Summary 文章付费
// @Tags 文章
// @Accept application/json
// @Param Authorization header string false "认证令牌"
// @Param article body types.ArticleInfo false "文章"
// @Produce application/json
// @Failure 403 {object} types.Fail
// @Success 200 {object} types.Success
// @Failure 500 {object} types.Fail
// @Router /api/article/payment [post]
func (ctr *Article) ArticlePayment(ctx *Context) {
	var payload types.ArticleInfo
	if err := ctx.ShouldBindWith(&payload); err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ret, err := ctr.Srv.TODO(ctx, ctx.MustDB(), struct{}{})
	if err != nil {
		logrus.Error(ctx, err)
		ctx.Fail(err)
		return
	}
	ctx.Success(ret)
}

rpc

<service name="message_srv" desc="消息服务">
    <rpc name="send_mail" desc="发送邮件">
        <request type="$message_mail" desc="邮件"/>
        <reply type="$message_reply" desc="反馈"/>
    </rpc>
</service>
// Code generated by dol build. Only Generate by tools if not existed, your can rewrite platform.App default action
// source: MessageSrv.proto

syntax = "proto3";

package proto;

// MessageSrv defined
service MessageSrv {
  rpc SendMail (MessageMail) returns (MessageReply) {}
}


// MessageMail defined
message MessageMail {}

// MessageReply defined
message MessageReply {}

table

<table name="article" desc="文章" 
   >
    <column name="id" desc="主键" type="null.Int" xorm="bigint(20) notnull autoincr unique pk" />

    <column name="creater" desc="创建人" type="null.Int" xorm="bigint(20) notnull" />
    <column name="create_time" desc="创建时间" type="null.Time" xorm="datetime" />
    <column name="updater" desc="最后更新人" type="null.Int" xorm="bigint(20) notnull" />
    <column name="update_time" desc="最后更新时间" type="null.Time" xorm="datetime" />
    <column name="is_delete" desc="删除标记" type="null.Int" xorm="notnull" />
    <column name="remark" desc="备注" type="null.String" xorm="varchar(200)" />
</table>
// Code generated by dol build. DO NOT EDIT.
// source: auto.go

package types

import (
	"github.com/2637309949/dolphin/packages/null"
	"github.com/shopspring/decimal"
)

// Article defined 文章
type Article struct {
	// ID defined 主键
	ID null.Int `xorm:"bigint(20) notnull autoincr unique pk comment('主键') 'id'" json:"id" form:"id" xml:"id"`
	// UnansweredCount defined 未答复数目
	UnansweredCount null.Int `xorm:"comment('未答复数目') 'unanswered_count'" json:"unanswered_count" form:"unanswered_count" xml:"unanswered_count"`
	// BestAnswerersCount defined 最佳答复数目
	BestAnswerersCount null.Int `xorm:"comment('最佳答复数目') 'best_answerers_count'" json:"best_answerers_count" form:"best_answerers_count" xml:"best_answerers_count"`
	// IsSuperTopicVote defined 是否超级话题投票
	IsSuperTopicVote null.Int `xorm:"comment('是否超级话题投票') 'is_super_topic_vote'" json:"is_super_topic_vote" form:"is_super_topic_vote" xml:"is_super_topic_vote"`
	// Excerpt defined 摘录
	Excerpt null.String `xorm:"varchar(512) comment('摘录') 'excerpt'" json:"excerpt" form:"excerpt" xml:"excerpt"`
	// IsVote defined 是否投票
	IsVote null.Int `xorm:"comment('是否投票') 'is_vote'" json:"is_vote" form:"is_vote" xml:"is_vote"`
	// IsBlack defined
	IsBlack null.Int `xorm:"'is_black'" json:"is_black" form:"is_black" xml:"is_black"`
	// QuestionsCount defined 提问数目
	QuestionsCount null.Int `xorm:"comment('提问数目') 'questions_count'" json:"questions_count" form:"questions_count" xml:"questions_count"`
	// Category defined 分类
	Category null.String `xorm:"varchar(36) comment('分类') 'category'" json:"category" form:"category" xml:"category"`
	// Name defined 标题
	Name null.String `xorm:"varchar(108) comment('标题') 'name'" json:"name" form:"name" xml:"name"`
	// Introduction defined 简介
	Introduction null.String `xorm:"varchar(512) comment('简介') 'introduction'" json:"introduction" form:"introduction" xml:"introduction"`
	// URL defined 地址
	URL null.String `xorm:"varchar(512) comment('地址') 'url'" json:"url" form:"url" xml:"url"`
	// FollowersCount defined 粉丝数
	FollowersCount null.Int `xorm:"comment('粉丝数') 'followers_count'" json:"followers_count" form:"followers_count" xml:"followers_count"`
	// Type defined 类别
	Type null.String `xorm:"varchar(36) comment('类别') 'type'" json:"type" form:"type" xml:"type"`
	// Reward defined 打赏
	Reward decimal.Decimal `xorm:"decimal(6,2) comment('打赏') 'reward'" json:"reward" form:"reward" xml:"reward"`
	// Creater defined 创建人
	Creater null.Int `xorm:"bigint(20) notnull comment('创建人') 'creater'" json:"creater" form:"creater" xml:"creater"`
	// CreateTime defined 创建时间
	CreateTime null.Time `xorm:"datetime comment('创建时间') 'create_time'" json:"create_time" form:"create_time" xml:"create_time"`
	// Updater defined 最后更新人
	Updater null.Int `xorm:"bigint(20) notnull comment('最后更新人') 'updater'" json:"updater" form:"updater" xml:"updater"`
	// UpdateTime defined 最后更新时间
	UpdateTime null.Time `xorm:"datetime comment('最后更新时间') 'update_time'" json:"update_time" form:"update_time" xml:"update_time"`
	// IsDelete defined 删除标记
	IsDelete null.Int `xorm:"notnull comment('删除标记') 'is_delete'" json:"is_delete" form:"is_delete" xml:"is_delete"`
	// Remark defined 备注
	Remark null.String `xorm:"varchar(200) comment('备注') 'remark'" json:"remark" form:"remark" xml:"remark"`
}

// TableName table name of defined Article
func (m *Article) TableName() string {
	return "article"
}