notice_personal_dao.go
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
type NoticePersonalDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewNoticePersonalDao(transactionContext *pgTransaction.TransactionContext) (*NoticePersonalDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &NoticePersonalDao{
transactionContext: transactionContext,
}, nil
}
}
//
func (dao *NoticePersonalDao) ReadNoticePersonal(userBaseId int64, noticeId int, readAll bool) (int, error) {
tx := dao.transactionContext.PgTx
updateData := map[string]interface{}{
"is_read": domain.NoticePersonalIsRead,
}
if readAll {
result, err := tx.Model(&updateData).
TableExpr("notice_personals").
Where("user_base_id=?", userBaseId).
Where("is_read=?", domain.NoticePersonalIsNotRead).
Update()
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
result, err := tx.Model(&updateData).
TableExpr("notice_personals").
Where("notice_personal_id=?", noticeId).
Update()
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}