57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package dao
|
|
|
|
import (
|
|
"git.rosy.net.cn/jx-print/globals"
|
|
editionModel "git.rosy.net.cn/jx-print/model/app_model"
|
|
"time"
|
|
)
|
|
|
|
type PrintNotice struct {
|
|
}
|
|
|
|
var PrintNoticeDao = new(PrintNotice)
|
|
|
|
// AddNotice 添加版本控制
|
|
func (p PrintNotice) AddNotice(param *editionModel.AddOrUpdatePrintNotice) error {
|
|
if err := Insert(globals.GetDB(), editionModel.PrintNotice{
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
NoticeType: param.NoticeType,
|
|
Msg: param.Msg,
|
|
Link: param.Link,
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateNotice 修改版本控制
|
|
func (p PrintNotice) UpdateNotice(param *editionModel.AddOrUpdatePrintNotice) error {
|
|
if err := Update(globals.GetDB(), editionModel.PrintNotice{
|
|
ID: param.Id,
|
|
UpdatedAt: time.Now(),
|
|
NoticeType: param.NoticeType,
|
|
Msg: param.Msg,
|
|
Link: param.Link,
|
|
}, []string{"updated_at", "notice_type", "msg", "link"}...); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DeletePrintNotice 删除
|
|
func (p PrintNotice) DeletePrintNotice(id int) error {
|
|
sql := `DELETE FROM print_notice WHERE id = ?`
|
|
_, err := globals.GetDB().Exec(sql, []interface{}{id}...)
|
|
return err
|
|
}
|
|
|
|
func (p PrintNotice) SelectPrintNotice(param *editionModel.QueryPrintNotice) ([]*editionModel.PrintNotice, error) {
|
|
var result []*editionModel.PrintNotice
|
|
sql := `SELECT * FROM print_edition WHERE notice_type = ? ORDER BY created_at DESC LIMIT ? OFFSET ? `
|
|
if err := globals.GetDB().Select(&result, sql, []interface{}{param.NoticeType, param.PageSize, (param.PageNumber - 1) * param.PageSize}); err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|