正在显示
6 个修改的文件
包含
143 行增加
和
0 行删除
pkg/application/factory/dao.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/dao" | ||
6 | +) | ||
7 | + | ||
8 | +func CreateNoticePersonalDao(options map[string]interface{}) (*dao.NoticePersonalDao, error) { | ||
9 | + var transactionContext *pg.TransactionContext | ||
10 | + if value, ok := options["transactionContext"]; ok { | ||
11 | + transactionContext = value.(*pg.TransactionContext) | ||
12 | + } | ||
13 | + return dao.NewNoticePersonalDao(transactionContext) | ||
14 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ReadNoticeCommand struct { | ||
10 | + UserId int `json:"userId" valid:"Required"` //读取谁的消息读 | ||
11 | + NoticeId int `json:"noticeId"` //消息id | ||
12 | + ReadAll bool `json:"readAll"` //是否全部标记为已读 | ||
13 | +} | ||
14 | + | ||
15 | +func (readNoticeCommand *ReadNoticeCommand) Valid(validation *validation.Validation) { | ||
16 | + if !readNoticeCommand.ReadAll { | ||
17 | + if readNoticeCommand.NoticeId <= 0 { | ||
18 | + validation.AddError("消息id", "未填写") | ||
19 | + } | ||
20 | + } | ||
21 | +} | ||
22 | + | ||
23 | +func (readNoticeCommand *ReadNoticeCommand) ValidateCommand() error { | ||
24 | + valid := validation.Validation{} | ||
25 | + b, err := valid.Valid(readNoticeCommand) | ||
26 | + if err != nil { | ||
27 | + return err | ||
28 | + } | ||
29 | + if !b { | ||
30 | + for _, validErr := range valid.Errors { | ||
31 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
32 | + } | ||
33 | + } | ||
34 | + return nil | ||
35 | +} |
@@ -12,6 +12,7 @@ import ( | @@ -12,6 +12,7 @@ import ( | ||
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/command" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/command" |
13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/query" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/query" |
14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" | 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" |
15 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/dao" | ||
15 | ) | 16 | ) |
16 | 17 | ||
17 | // 个人消息通知 | 18 | // 个人消息通知 |
@@ -627,6 +628,40 @@ func (noticePersonalService *NoticePersonalService) CreditAccountPayment(creditA | @@ -627,6 +628,40 @@ func (noticePersonalService *NoticePersonalService) CreditAccountPayment(creditA | ||
627 | return noticePersonal, nil | 628 | return noticePersonal, nil |
628 | } | 629 | } |
629 | 630 | ||
631 | +// 设置消息:账期结算消息-分红预算 | ||
632 | +func (noticePersonalService *NoticePersonalService) ReadNotice(readNoticeCommand *command.ReadNoticeCommand) (interface{}, error) { | ||
633 | + if err := readNoticeCommand.ValidateCommand(); err != nil { | ||
634 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
635 | + } | ||
636 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
637 | + if err != nil { | ||
638 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
639 | + } | ||
640 | + if err := transactionContext.StartTransaction(); err != nil { | ||
641 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
642 | + } | ||
643 | + defer func() { | ||
644 | + _ = transactionContext.RollbackTransaction() | ||
645 | + }() | ||
646 | + // 共创合约DAO初始化 | ||
647 | + var noticePersonalDao *dao.NoticePersonalDao | ||
648 | + if value, err := factory.CreateNoticePersonalDao(map[string]interface{}{ | ||
649 | + "transactionContext": transactionContext, | ||
650 | + }); err != nil { | ||
651 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
652 | + } else { | ||
653 | + noticePersonalDao = value | ||
654 | + } | ||
655 | + _, err = noticePersonalDao.ReadNoticePersonal(int64(readNoticeCommand.UserId), | ||
656 | + readNoticeCommand.NoticeId, readNoticeCommand.ReadAll) | ||
657 | + if err != nil { | ||
658 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
659 | + } | ||
660 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
661 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
662 | + } | ||
663 | + return readNoticeCommand, nil | ||
664 | +} | ||
630 | func NewNoticePersonalService(options map[string]interface{}) *NoticePersonalService { | 665 | func NewNoticePersonalService(options map[string]interface{}) *NoticePersonalService { |
631 | newNoticePersonalService := &NoticePersonalService{} | 666 | newNoticePersonalService := &NoticePersonalService{} |
632 | return newNoticePersonalService | 667 | return newNoticePersonalService |
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" | ||
8 | +) | ||
9 | + | ||
10 | +type NoticePersonalDao struct { | ||
11 | + transactionContext *pgTransaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +func NewNoticePersonalDao(transactionContext *pgTransaction.TransactionContext) (*NoticePersonalDao, error) { | ||
15 | + if transactionContext == nil { | ||
16 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
17 | + } else { | ||
18 | + return &NoticePersonalDao{ | ||
19 | + transactionContext: transactionContext, | ||
20 | + }, nil | ||
21 | + } | ||
22 | +} | ||
23 | + | ||
24 | +// | ||
25 | +func (dao *NoticePersonalDao) ReadNoticePersonal(userId int64, noticeId int, readAll bool) (int, error) { | ||
26 | + tx := dao.transactionContext.PgTx | ||
27 | + updateData := map[string]interface{}{ | ||
28 | + "is_read": domain.NoticePersonalIsRead, | ||
29 | + } | ||
30 | + if readAll { | ||
31 | + result, err := tx.Model(&updateData). | ||
32 | + TableExpr("notice_personals"). | ||
33 | + Where("user_id=?", userId). | ||
34 | + Where("is_read=?", domain.NoticePersonalIsNotRead). | ||
35 | + Update() | ||
36 | + if err != nil { | ||
37 | + return 0, err | ||
38 | + } | ||
39 | + return result.RowsAffected(), nil | ||
40 | + } | ||
41 | + result, err := tx.Model(&updateData). | ||
42 | + TableExpr("notice_personals"). | ||
43 | + Where("notice_personal_id=?", noticeId). | ||
44 | + Where("user_id=?", userId). | ||
45 | + Update() | ||
46 | + if err != nil { | ||
47 | + return 0, err | ||
48 | + } | ||
49 | + return result.RowsAffected(), nil | ||
50 | +} |
@@ -68,3 +68,11 @@ func (controller *NoticePersonalController) CreditAccountPayment() { | @@ -68,3 +68,11 @@ func (controller *NoticePersonalController) CreditAccountPayment() { | ||
68 | data, err := noticePersonalService.CreditAccountPayment(creditAccountPaymentCommand) | 68 | data, err := noticePersonalService.CreditAccountPayment(creditAccountPaymentCommand) |
69 | controller.Response(data, err) | 69 | controller.Response(data, err) |
70 | } | 70 | } |
71 | + | ||
72 | +func (controller *NoticePersonalController) ReadNotice() { | ||
73 | + noticePersonalService := service.NewNoticePersonalService(nil) | ||
74 | + readNoticeCommand := &command.ReadNoticeCommand{} | ||
75 | + controller.Unmarshal(readNoticeCommand) | ||
76 | + data, err := noticePersonalService.ReadNotice(readNoticeCommand) | ||
77 | + controller.Response(data, err) | ||
78 | +} |
@@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
7 | 7 | ||
8 | func init() { | 8 | func init() { |
9 | web.Router("/notice-personal/", &controllers.NoticePersonalController{}, "Post:GetNoticePersonalList") | 9 | web.Router("/notice-personal/", &controllers.NoticePersonalController{}, "Post:GetNoticePersonalList") |
10 | + web.Router("/notice-personal/read", &controllers.NoticePersonalController{}, "Post:ReadNotice") | ||
10 | web.Router("/notice-personal/agree-join-creation-project", &controllers.NoticePersonalController{}, "Post:AgreeJoinCreationProject") | 11 | web.Router("/notice-personal/agree-join-creation-project", &controllers.NoticePersonalController{}, "Post:AgreeJoinCreationProject") |
11 | web.Router("/notice-personal/inform-expected-dividends", &controllers.NoticePersonalController{}, "Post:InformExpectedDividends") | 12 | web.Router("/notice-personal/inform-expected-dividends", &controllers.NoticePersonalController{}, "Post:InformExpectedDividends") |
12 | web.Router("/notice-personal/refuse-join-creation-project", &controllers.NoticePersonalController{}, "Post:RefuseJoinCreationProject") | 13 | web.Router("/notice-personal/refuse-join-creation-project", &controllers.NoticePersonalController{}, "Post:RefuseJoinCreationProject") |
-
请 注册 或 登录 后发表评论