新增自定义通知模板

This commit is contained in:
linxiaozhi
2019-02-16 20:43:33 +08:00
parent 374b305d96
commit 7bd18fdb64
16 changed files with 830 additions and 112 deletions

View File

@@ -1,8 +1,8 @@
/*
* @Author: haodaquan
* @Date: 2017-06-20 09:44:44
* @Last Modified by: haodaquan
* @Last Modified time: 2017-06-21 12:21:37
* @Last Modified by: Bee
* @Last Modified time: 2019-02-15 22:12
*/
package models
@@ -47,6 +47,7 @@ func Init(startTime int64) {
new(Group),
new(Task),
new(TaskLog),
new(NotifyTpl),
)
if beego.AppConfig.String("runmode") == "dev" {

102
models/notify_tpl.go Normal file
View File

@@ -0,0 +1,102 @@
/************************************************************
** @Description: models
** @Author: Bee
** @Date: 2019-02-15 20:21
** @Last Modified by: Bee
** @Last Modified time: 2019-02-15 20:21
*************************************************************/
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
"time"
)
type NotifyTpl struct {
Id int
Type string
TplName string
TplType int
Title string
Content string
Status int
CreateId int
UpdateId int
CreateTime int64
UpdateTime int64
}
func (t *NotifyTpl) TableName() string {
return TableName("notify_tpl")
}
func (t *NotifyTpl) Update(fields ...string) error {
if t.TplName == "" {
return fmt.Errorf("模板名称不能为空")
}
if t.Content == "" {
return fmt.Errorf("模板内容不能为空")
}
if t.CreateTime == 0 {
t.CreateTime = time.Now().Unix()
}
if _, err := orm.NewOrm().Update(t, fields...); err != nil {
return err
}
return nil
}
func NotifyTplAdd(obj *NotifyTpl) (int64, error) {
if obj.TplName == "" {
return 0, fmt.Errorf("模板名称不能为空")
}
if obj.Content == "" {
return 0, fmt.Errorf("模板内容不能为空")
}
if obj.CreateTime == 0 {
obj.CreateTime = time.Now().Unix()
}
return orm.NewOrm().Insert(obj)
}
func NotifyTplGetById(id int) (*NotifyTpl, error) {
obj := &NotifyTpl{
Id: id,
}
err := orm.NewOrm().Read(obj)
if err != nil {
return nil, err
}
return obj, nil
}
func NotifyTplGetByTplTypeList(tpl_type int) ([]*NotifyTpl, int64, error) {
list := make([]*NotifyTpl, 0)
total, err := orm.NewOrm().QueryTable(TableName("notify_tpl")).Filter("tpl_type", tpl_type).Filter("status", 1).All(&list)
return list, total, err
}
func NotifyTplDelById(id int) error {
_, err := orm.NewOrm().QueryTable(TableName("notify_tpl")).Filter("id", id).Delete()
return err
}
func NotifyTplGetList(page, pageSize int, filters ...interface{}) ([]*NotifyTpl, int64) {
offset := (page - 1) * pageSize
list := make([]*NotifyTpl, 0)
query := orm.NewOrm().QueryTable(TableName("notify_tpl"))
if len(filters) > 0 {
l := len(filters)
for k := 0; k < l; k += 2 {
query = query.Filter(filters[k].(string), filters[k+1])
}
}
total, _ := query.Count()
query.OrderBy("-id").Limit(pageSize, offset).All(&list)
return list, total
}

View File

@@ -2,8 +2,8 @@
** @Description: models
** @Author: haodaquan
** @Date: 2018-06-11 21:26
** @Last Modified by: haodaquan
** @Last Modified time: 2018-06-11 21:26
** @Last Modified by: Bee
** @Last Modified time: 2019-02-15 21:32
*************************************************************/
package models
@@ -35,6 +35,7 @@ type Task struct {
Status int
IsNotify int
NotifyType int
NotifyTplId int
NotifyUserIds string
CreateId int
UpdateId int