作者 tangxuhui

更新

@@ -22,10 +22,10 @@ func CreateNoticeSettingRepository(options map[string]interface{}) (domain.Notic @@ -22,10 +22,10 @@ func CreateNoticeSettingRepository(options map[string]interface{}) (domain.Notic
22 return repository.NewNoticeSettingRepository(transactionContext) 22 return repository.NewNoticeSettingRepository(transactionContext)
23 } 23 }
24 24
25 -func CreateNoticeEmptyRepository(options map[string]interface{}) (domain.NoticeEmptyRepository, error) { 25 +func CreateNoticePersonalRepository(options map[string]interface{}) (domain.NoticePersonalRepository, error) {
26 var transactionContext *pg.TransactionContext 26 var transactionContext *pg.TransactionContext
27 if value, ok := options["transactionContext"]; ok { 27 if value, ok := options["transactionContext"]; ok {
28 transactionContext = value.(*pg.TransactionContext) 28 transactionContext = value.(*pg.TransactionContext)
29 } 29 }
30 - return repository.NewNoticeEmptyRepository(transactionContext) 30 + return repository.NewNoticePersonalRepository(transactionContext)
31 } 31 }
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type AgreeJoinCreationProjectCommand struct {
  10 + // 接收方用户id
  11 + UserId int64 `json:"userId" valid:"Required"`
  12 + // 共创项目id
  13 + CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
  14 + // 共创项目名称
  15 + CreationProjectName string `json:"creationProjectName" valid:"Required"`
  16 + // 共创项目编号
  17 + CreationProjectNumber string `json:"creationProjectNumber" valid:"Required"`
  18 +}
  19 +
  20 +func (agreeJoinCreationProjectCommand *AgreeJoinCreationProjectCommand) Valid(validation *validation.Validation) {
  21 +
  22 +}
  23 +
  24 +func (agreeJoinCreationProjectCommand *AgreeJoinCreationProjectCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(agreeJoinCreationProjectCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + for _, validErr := range valid.Errors {
  32 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  33 + }
  34 + }
  35 + return nil
  36 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type InformExpectedDividendsCommand struct {
  10 + // 用户id
  11 + UserId int64 `json:"userId" valid:"Required"`
  12 + // 共创项目id
  13 + CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
  14 + // 共创项目名称
  15 + CreationProjectName string `json:"creationProjectName" valid:"Required"`
  16 + // 共创合约id
  17 + CreationContractId int64 `json:"creationContractId" valid:"Required"`
  18 + // 共创合约名称
  19 + CreationContractName string `json:"creationContractName" valid:"Required"`
  20 + // 共创合约编号
  21 + CreationContractNumber string `json:"creationContractNumber" valid:"Required"`
  22 + // 产品名称
  23 + ProductName string `json:"productName" valid:"Required"`
  24 +}
  25 +
  26 +func (informExpectedDividendsCommand *InformExpectedDividendsCommand) Valid(validation *validation.Validation) {
  27 +
  28 +}
  29 +
  30 +func (informExpectedDividendsCommand *InformExpectedDividendsCommand) ValidateCommand() error {
  31 + valid := validation.Validation{}
  32 + b, err := valid.Valid(informExpectedDividendsCommand)
  33 + if err != nil {
  34 + return err
  35 + }
  36 + if !b {
  37 + for _, validErr := range valid.Errors {
  38 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type InformJoinCreationContractCommand struct {
  10 + // 接收方用户id
  11 + UserId int64 `json:"userId" valid:"Required"`
  12 + // 共创项目id
  13 + CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
  14 + // 共创项目名称
  15 + CreationProjectName string `json:"creationProjectName" valid:"Required"`
  16 + // 共创合约id
  17 + CreationContractId int64 `json:"creationContractId" valid:"Required"`
  18 + // 共创合约名称
  19 + CreationContractName string `json:"creationContractName" valid:"Required"`
  20 + // 共创合约编号
  21 + CreationContractNumber string `json:"creationContractNumber" valid:"Required"`
  22 +}
  23 +
  24 +func (informJoinCreationContractCommand *InformJoinCreationContractCommand) Valid(validation *validation.Validation) {
  25 +
  26 +}
  27 +
  28 +func (informJoinCreationContractCommand *InformJoinCreationContractCommand) ValidateCommand() error {
  29 + valid := validation.Validation{}
  30 + b, err := valid.Valid(informJoinCreationContractCommand)
  31 + if err != nil {
  32 + return err
  33 + }
  34 + if !b {
  35 + for _, validErr := range valid.Errors {
  36 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type RefuseJoinCreationProjectCommand struct {
  10 + // 接收方用户id
  11 + UserId int64 `json:"userId" valid:"Required"`
  12 + // 共创项目id
  13 + CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
  14 + // 共创项目名称
  15 + CreationProjectName string `json:"creationProjectName" valid:"Required"`
  16 + // 共创项目编号
  17 + CreationProjectNumber string `json:"creationProjectNumber" valid:"Required"`
  18 +}
  19 +
  20 +func (refuseJoinCreationProjectCommand *RefuseJoinCreationProjectCommand) Valid(validation *validation.Validation) {
  21 +
  22 +}
  23 +
  24 +func (refuseJoinCreationProjectCommand *RefuseJoinCreationProjectCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(refuseJoinCreationProjectCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + for _, validErr := range valid.Errors {
  32 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  33 + }
  34 + }
  35 + return nil
  36 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type GetNoticePersonalListQuery struct {
  10 + // 接收方用户的id
  11 + UserId int64 `json:"userId"`
  12 + // 分页偏移量
  13 + PageSize int64 `json:"pageSize"`
  14 + // 每页限制数量 默认20
  15 + PageIndex int64 `json:"pageIndex"`
  16 + // 是否是已读
  17 + IsRead int64 `json:"isRead"`
  18 +}
  19 +
  20 +func (getNoticePersonalListQuery *GetNoticePersonalListQuery) Valid(validation *validation.Validation) {
  21 + validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (getNoticePersonalListQuery *GetNoticePersonalListQuery) ValidateQuery() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(getNoticePersonalListQuery)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + for _, validErr := range valid.Errors {
  32 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  33 + }
  34 + }
  35 + return nil
  36 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/query"
  8 +)
  9 +
  10 +// 个人消息通知
  11 +type NoticePersonalService struct {
  12 +}
  13 +
  14 +// 设置消息:共创申请审核通过
  15 +func (noticePersonalService *NoticePersonalService) AgreeJoinCreationProject(agreeJoinCreationProjectCommand *command.AgreeJoinCreationProjectCommand) (interface{}, error) {
  16 + if err := agreeJoinCreationProjectCommand.ValidateCommand(); err != nil {
  17 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  18 + }
  19 + transactionContext, err := factory.CreateTransactionContext(nil)
  20 + if err != nil {
  21 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  22 + }
  23 + if err := transactionContext.StartTransaction(); err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + defer func() {
  27 + transactionContext.RollbackTransaction()
  28 + }()
  29 + if err := transactionContext.CommitTransaction(); err != nil {
  30 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  31 + }
  32 + return nil, nil
  33 +}
  34 +
  35 +// 获取消息列表
  36 +func (noticePersonalService *NoticePersonalService) GetNoticePersonalList(getNoticePersonalListQuery *query.GetNoticePersonalListQuery) (interface{}, error) {
  37 + if err := getNoticePersonalListQuery.ValidateQuery(); err != nil {
  38 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  39 + }
  40 + transactionContext, err := factory.CreateTransactionContext(nil)
  41 + if err != nil {
  42 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  43 + }
  44 + if err := transactionContext.StartTransaction(); err != nil {
  45 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  46 + }
  47 + defer func() {
  48 + transactionContext.RollbackTransaction()
  49 + }()
  50 + if err := transactionContext.CommitTransaction(); err != nil {
  51 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  52 + }
  53 + return nil, nil
  54 +}
  55 +
  56 +// 设置消息:分红预算消息
  57 +func (noticePersonalService *NoticePersonalService) InformExpectedDividends(informExpectedDividendsCommand *command.InformExpectedDividendsCommand) (interface{}, error) {
  58 + if err := informExpectedDividendsCommand.ValidateCommand(); err != nil {
  59 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  60 + }
  61 + transactionContext, err := factory.CreateTransactionContext(nil)
  62 + if err != nil {
  63 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  64 + }
  65 + if err := transactionContext.StartTransaction(); err != nil {
  66 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  67 + }
  68 + defer func() {
  69 + transactionContext.RollbackTransaction()
  70 + }()
  71 + if err := transactionContext.CommitTransaction(); err != nil {
  72 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  73 + }
  74 + return nil, nil
  75 +}
  76 +
  77 +// 设置消息:共创确认
  78 +func (noticePersonalService *NoticePersonalService) InformJoinCreationContract(informJoinCreationContractCommand *command.InformJoinCreationContractCommand) (interface{}, error) {
  79 + if err := informJoinCreationContractCommand.ValidateCommand(); err != nil {
  80 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  81 + }
  82 + transactionContext, err := factory.CreateTransactionContext(nil)
  83 + if err != nil {
  84 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  85 + }
  86 + if err := transactionContext.StartTransaction(); err != nil {
  87 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  88 + }
  89 + defer func() {
  90 + transactionContext.RollbackTransaction()
  91 + }()
  92 + if err := transactionContext.CommitTransaction(); err != nil {
  93 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  94 + }
  95 + return nil, nil
  96 +}
  97 +
  98 +// 设置消息:共创申请审核拒绝
  99 +func (noticePersonalService *NoticePersonalService) RefuseJoinCreationProject(refuseJoinCreationProjectCommand *command.RefuseJoinCreationProjectCommand) (interface{}, error) {
  100 + if err := refuseJoinCreationProjectCommand.ValidateCommand(); err != nil {
  101 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  102 + }
  103 + transactionContext, err := factory.CreateTransactionContext(nil)
  104 + if err != nil {
  105 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  106 + }
  107 + if err := transactionContext.StartTransaction(); err != nil {
  108 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  109 + }
  110 + defer func() {
  111 + transactionContext.RollbackTransaction()
  112 + }()
  113 + if err := transactionContext.CommitTransaction(); err != nil {
  114 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  115 + }
  116 + return nil, nil
  117 +}
  118 +
  119 +func NewNoticePersonalService(options map[string]interface{}) *NoticePersonalService {
  120 + newNoticePersonalService := &NoticePersonalService{}
  121 + return newNoticePersonalService
  122 +}
1 -package domain  
2 -  
3 -// 系统默认的空白消息配置样板  
4 -type NoticeEmpty struct {  
5 - // 消息id  
6 - NoticeEmptyId int64 `json:"noticeEmptyId"`  
7 - // 内容模板  
8 - Content string `json:"content"`  
9 - // 是否推送 【是:1】【否:2】  
10 - IsPush int `json:"isPush"`  
11 - // 消息对应的业务模块  
12 - Module string `json:"module"`  
13 - // 业务环节  
14 - ModuleAction string `json:"moduleAction"`  
15 - // 消息对应的编码  
16 - SysCode string `json:"sysCode"`  
17 -}  
18 -  
19 -type NoticeEmptyRepository interface {  
20 - Save(noticeEmpty *NoticeEmpty) (*NoticeEmpty, error) //用不到  
21 - // Remove(noticeEmpty *NoticeEmpty) (*NoticeEmpty, error)//用户不到  
22 - // FindOne(queryOptions map[string]interface{}) (*NoticeEmpty, error) //用不到  
23 - Find(queryOptions map[string]interface{}) (int64, []*NoticeEmpty, error)  
24 -}  
25 -  
26 -func (noticeEmpty *NoticeEmpty) Identify() interface{} {  
27 - if noticeEmpty.NoticeEmptyId == 0 {  
28 - return nil  
29 - }  
30 - return noticeEmpty.NoticeEmptyId  
31 -}  
32 -  
33 -func (noticeEmpty *NoticeEmpty) Update(data map[string]interface{}) error {  
34 - if noticeEmptyId, ok := data["noticeEmptyId"]; ok {  
35 - noticeEmpty.NoticeEmptyId = noticeEmptyId.(int64)  
36 - }  
37 - if content, ok := data["content"]; ok {  
38 - noticeEmpty.Content = content.(string)  
39 - }  
40 - if isPush, ok := data["isPush"]; ok {  
41 - noticeEmpty.IsPush = isPush.(int)  
42 - }  
43 - if module, ok := data["module"]; ok {  
44 - noticeEmpty.Module = module.(string)  
45 - }  
46 - if moduleAction, ok := data["moduleAction"]; ok {  
47 - noticeEmpty.ModuleAction = moduleAction.(string)  
48 - }  
49 - if sysCode, ok := data["sysCode"]; ok {  
50 - noticeEmpty.SysCode = sysCode.(string)  
51 - }  
52 - return nil  
53 -}  
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +const (
  6 + NoticePersonalIsNotRead = 1
  7 + NoticePersonalIsRead = 2
  8 +)
  9 +
  10 +// 个人消息通知内容
  11 +type NoticePersonal struct {
  12 + // 编号id
  13 + NoticePersonalId int64 `json:"noticePersonalId"`
  14 + // 创建时间
  15 + CreatedAt time.Time `json:"createdAt"`
  16 + // 删除时间
  17 + DeletedAt time.Time `json:"deletedAt"`
  18 + // 更新时间
  19 + UpdatedAt time.Time `json:"updatedAt"`
  20 + // 发送通知时的扩展参数
  21 + Extend string `json:"extend"`
  22 + // 公司id
  23 + CompanyId int64 `json:"companyId"`
  24 + // 内容模板
  25 + Content string `json:"content"`
  26 + // 是否已读【1:未读】【2:已读】
  27 + IsRead string `json:"isRead"`
  28 + // 消息对应的业务模块
  29 + Module string `json:"module"`
  30 + // 业务环节
  31 + ModuleAction string `json:"moduleAction"`
  32 + //账号id
  33 + UserBaseId int64 `json:"userBaseId"`
  34 + // 组织id
  35 + OrgId int64 `json:"orgId"`
  36 + // 消息对应的编码
  37 + SysCode string `json:"sysCode"`
  38 + // 接收方用户id
  39 + UserId int64 `json:"userId"`
  40 +}
  41 +
  42 +type NoticePersonalRepository interface {
  43 + Save(noticePersonal *NoticePersonal) (*NoticePersonal, error)
  44 + Remove(noticePersonal *NoticePersonal) (*NoticePersonal, error)
  45 + FindOne(queryOptions map[string]interface{}) (*NoticePersonal, error)
  46 + Find(queryOptions map[string]interface{}) (int64, []*NoticePersonal, error)
  47 +}
  48 +
  49 +func (noticePersonal *NoticePersonal) Identify() interface{} {
  50 + if noticePersonal.NoticePersonalId == 0 {
  51 + return nil
  52 + }
  53 + return noticePersonal.NoticePersonalId
  54 +}
  55 +
  56 +func (noticePersonal *NoticePersonal) Update(data map[string]interface{}) error {
  57 + if createdAt, ok := data["createdAt"]; ok {
  58 + noticePersonal.CreatedAt = createdAt.(time.Time)
  59 + }
  60 + if deletedAt, ok := data["deletedAt"]; ok {
  61 + noticePersonal.DeletedAt = deletedAt.(time.Time)
  62 + }
  63 + if updatedAt, ok := data["updatedAt"]; ok {
  64 + noticePersonal.UpdatedAt = updatedAt.(time.Time)
  65 + }
  66 + if extend, ok := data["extend"]; ok {
  67 + noticePersonal.Extend = extend.(string)
  68 + }
  69 + if companyId, ok := data["companyId"]; ok {
  70 + noticePersonal.CompanyId = companyId.(int64)
  71 + }
  72 + if content, ok := data["content"]; ok {
  73 + noticePersonal.Content = content.(string)
  74 + }
  75 + if isRead, ok := data["isRead"]; ok {
  76 + noticePersonal.IsRead = isRead.(string)
  77 + }
  78 + if module, ok := data["module"]; ok {
  79 + noticePersonal.Module = module.(string)
  80 + }
  81 + if moduleAction, ok := data["moduleAction"]; ok {
  82 + noticePersonal.ModuleAction = moduleAction.(string)
  83 + }
  84 + if noticePersonalId, ok := data["noticePersonalId"]; ok {
  85 + noticePersonal.NoticePersonalId = noticePersonalId.(int64)
  86 + }
  87 + if organizationId, ok := data["organizationId"]; ok {
  88 + noticePersonal.OrgId = organizationId.(int64)
  89 + }
  90 + if sysCode, ok := data["sysCode"]; ok {
  91 + noticePersonal.SysCode = sysCode.(string)
  92 + }
  93 + if userId, ok := data["userId"]; ok {
  94 + noticePersonal.UserId = userId.(int64)
  95 + }
  96 + if userId, ok := data["userBaseId"]; ok {
  97 + noticePersonal.UserBaseId = userId.(int64)
  98 + }
  99 + return nil
  100 +}
1 -package models  
2 -  
3 -type NoticeEmpty struct {  
4 - tableName string `pg:"notice_emptys,alias:notice_empty"`  
5 - // 消息id  
6 - NoticeEmptyId int64  
7 - // 内容模板  
8 - Content string  
9 - // 是否推送 【是:1】【否:2】  
10 - IsPush int  
11 - // 消息对应的业务模块  
12 - Module string  
13 - // 业务环节  
14 - ModuleAction string  
15 - // 消息对应的编码  
16 - SysCode string  
17 -}  
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type NoticePersonal struct {
  6 + tableName string `pg:"notice_personals"`
  7 + // 创建时间
  8 + CreatedAt time.Time
  9 + // 删除时间
  10 + DeletedAt time.Time
  11 + // 更新时间
  12 + UpdatedAt time.Time
  13 + // 发送通知时的扩展参数
  14 + Extend string
  15 + // 公司id
  16 + CompanyId int64
  17 + // 内容模板
  18 + Content string
  19 + // 是否已读【1:未读】【2:已读】
  20 + IsRead string
  21 + // 消息对应的业务模块
  22 + Module string
  23 + // 业务环节
  24 + ModuleAction string
  25 + // 编号id
  26 + NoticePersonalId int64
  27 + // 组织id
  28 + OrgId int64
  29 + // 消息对应的编码
  30 + SysCode string
  31 + // 接收方用户id
  32 + UserId int64
  33 +
  34 + UserBaseId int64
  35 +}
1 -package transform  
2 -  
3 -import (  
4 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"  
5 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"  
6 -)  
7 -  
8 -func TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel *models.NoticeEmpty) (*domain.NoticeEmpty, error) {  
9 - return &domain.NoticeEmpty{  
10 - NoticeEmptyId: noticeEmptyModel.NoticeEmptyId,  
11 - Content: noticeEmptyModel.Content,  
12 - IsPush: noticeEmptyModel.IsPush,  
13 - Module: noticeEmptyModel.Module,  
14 - ModuleAction: noticeEmptyModel.ModuleAction,  
15 - SysCode: noticeEmptyModel.SysCode,  
16 - }, nil  
17 -}  
  1 +package transform
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
  6 +)
  7 +
  8 +func TransformToNoticePersonalDomainModelFromPgModels(noticePersonalModel *models.NoticePersonal) (*domain.NoticePersonal, error) {
  9 + return &domain.NoticePersonal{
  10 + CreatedAt: noticePersonalModel.CreatedAt,
  11 + DeletedAt: noticePersonalModel.DeletedAt,
  12 + UpdatedAt: noticePersonalModel.UpdatedAt,
  13 + Extend: noticePersonalModel.Extend,
  14 + CompanyId: noticePersonalModel.CompanyId,
  15 + Content: noticePersonalModel.Content,
  16 + IsRead: noticePersonalModel.IsRead,
  17 + Module: noticePersonalModel.Module,
  18 + ModuleAction: noticePersonalModel.ModuleAction,
  19 + NoticePersonalId: noticePersonalModel.NoticePersonalId,
  20 + OrgId: noticePersonalModel.OrgId,
  21 + SysCode: noticePersonalModel.SysCode,
  22 + UserId: noticePersonalModel.UserId,
  23 + }, nil
  24 +}
1 -package repository  
2 -  
3 -import (  
4 - "fmt"  
5 -  
6 - "github.com/go-pg/pg/v10"  
7 - "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"  
8 - pgTransaction "github.com/linmadan/egglib-go/transaction/pg"  
9 - "github.com/linmadan/egglib-go/utils/snowflake"  
10 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"  
11 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"  
12 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform"  
13 -)  
14 -  
15 -type NoticeEmptyRepository struct {  
16 - transactionContext *pgTransaction.TransactionContext  
17 -}  
18 -  
19 -func (repository *NoticeEmptyRepository) nextIdentify() (int64, error) {  
20 - IdWorker, err := snowflake.NewIdWorker(1)  
21 - if err != nil {  
22 - return 0, err  
23 - }  
24 - id, err := IdWorker.NextId()  
25 - return id, err  
26 -}  
27 -  
28 -func (repository *NoticeEmptyRepository) Save(noticeEmpty *domain.NoticeEmpty) (*domain.NoticeEmpty, error) {  
29 - sqlBuildFields := []string{  
30 - "notice_empty_id",  
31 - "content",  
32 - "is_push",  
33 - "module",  
34 - "module_action",  
35 - "sys_code",  
36 - }  
37 - insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)  
38 - insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)  
39 - returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)  
40 - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "noticeEmpty_id")  
41 - updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)  
42 - tx := repository.transactionContext.PgTx  
43 - if noticeEmpty.Identify() == nil {  
44 - noticeEmptyId, err := repository.nextIdentify()  
45 - if err != nil {  
46 - return noticeEmpty, err  
47 - } else {  
48 - noticeEmpty.NoticeEmptyId = noticeEmptyId  
49 - }  
50 - if _, err := tx.QueryOne(  
51 - pg.Scan(  
52 - &noticeEmpty.NoticeEmptyId,  
53 - &noticeEmpty.Content,  
54 - &noticeEmpty.IsPush,  
55 - &noticeEmpty.Module,  
56 - &noticeEmpty.ModuleAction,  
57 - &noticeEmpty.SysCode,  
58 - ),  
59 - fmt.Sprintf("INSERT INTO notice_emptys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),  
60 - noticeEmpty.NoticeEmptyId,  
61 - noticeEmpty.Content,  
62 - noticeEmpty.IsPush,  
63 - noticeEmpty.Module,  
64 - noticeEmpty.ModuleAction,  
65 - noticeEmpty.SysCode,  
66 - ); err != nil {  
67 - return noticeEmpty, err  
68 - }  
69 - } else {  
70 - if _, err := tx.QueryOne(  
71 - pg.Scan(  
72 - &noticeEmpty.NoticeEmptyId,  
73 - &noticeEmpty.Content,  
74 - &noticeEmpty.IsPush,  
75 - &noticeEmpty.Module,  
76 - &noticeEmpty.ModuleAction,  
77 - &noticeEmpty.SysCode,  
78 - ),  
79 - fmt.Sprintf("UPDATE notice_emptys SET %s WHERE notice_empty_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),  
80 - noticeEmpty.NoticeEmptyId,  
81 - noticeEmpty.Content,  
82 - noticeEmpty.IsPush,  
83 - noticeEmpty.Module,  
84 - noticeEmpty.ModuleAction,  
85 - noticeEmpty.SysCode,  
86 - noticeEmpty.Identify(),  
87 - ); err != nil {  
88 - return noticeEmpty, err  
89 - }  
90 - }  
91 - return noticeEmpty, nil  
92 -}  
93 -  
94 -func (repository *NoticeEmptyRepository) Remove(noticeEmpty *domain.NoticeEmpty) (*domain.NoticeEmpty, error) {  
95 - tx := repository.transactionContext.PgTx  
96 - noticeEmptyModel := new(models.NoticeEmpty)  
97 - noticeEmptyModel.NoticeEmptyId = noticeEmpty.Identify().(int64)  
98 - if _, err := tx.Model(noticeEmptyModel).WherePK().Delete(); err != nil {  
99 - return noticeEmpty, err  
100 - }  
101 - return noticeEmpty, nil  
102 -}  
103 -func (repository *NoticeEmptyRepository) FindOne(queryOptions map[string]interface{}) (*domain.NoticeEmpty, error) {  
104 - tx := repository.transactionContext.PgTx  
105 - noticeEmptyModel := new(models.NoticeEmpty)  
106 - query := sqlbuilder.BuildQuery(tx.Model(noticeEmptyModel), queryOptions)  
107 - query.SetWhereByQueryOption("notice_empty.notice_empty_id = ?", "noticeEmptyId")  
108 - if err := query.First(); err != nil {  
109 - if err.Error() == "pg: no rows in result set" {  
110 - return nil, fmt.Errorf("没有此资源")  
111 - } else {  
112 - return nil, err  
113 - }  
114 - }  
115 - if noticeEmptyModel.NoticeEmptyId == 0 {  
116 - return nil, nil  
117 - } else {  
118 - return transform.TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel)  
119 - }  
120 -}  
121 -func (repository *NoticeEmptyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.NoticeEmpty, error) {  
122 - tx := repository.transactionContext.PgTx  
123 - var noticeEmptyModels []*models.NoticeEmpty  
124 - noticeEmptys := make([]*domain.NoticeEmpty, 0)  
125 - query := sqlbuilder.BuildQuery(tx.Model(&noticeEmptyModels), queryOptions)  
126 - query.SetOffsetAndLimit(20)  
127 - query.SetOrderDirect("notice_empty_id", "DESC")  
128 - if count, err := query.SelectAndCount(); err != nil {  
129 - return 0, noticeEmptys, err  
130 - } else {  
131 - for _, noticeEmptyModel := range noticeEmptyModels {  
132 - if noticeEmpty, err := transform.TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel); err != nil {  
133 - return 0, noticeEmptys, err  
134 - } else {  
135 - noticeEmptys = append(noticeEmptys, noticeEmpty)  
136 - }  
137 - }  
138 - return int64(count), noticeEmptys, nil  
139 - }  
140 -}  
141 -func NewNoticeEmptyRepository(transactionContext *pgTransaction.TransactionContext) (*NoticeEmptyRepository, error) {  
142 - if transactionContext == nil {  
143 - return nil, fmt.Errorf("transactionContext参数不能为nil")  
144 - } else {  
145 - return &NoticeEmptyRepository{  
146 - transactionContext: transactionContext,  
147 - }, nil  
148 - }  
149 -}  
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg/v10"
  7 + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
  8 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  9 + "github.com/linmadan/egglib-go/utils/snowflake"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform"
  13 +)
  14 +
  15 +type NoticePersonalRepository struct {
  16 + transactionContext *pgTransaction.TransactionContext
  17 +}
  18 +
  19 +func (repository *NoticePersonalRepository) nextIdentify() (int64, error) {
  20 + IdWorker, err := snowflake.NewIdWorker(1)
  21 + if err != nil {
  22 + return 0, err
  23 + }
  24 + id, err := IdWorker.NextId()
  25 + return id, err
  26 +}
  27 +func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePersonal) (*domain.NoticePersonal, error) {
  28 + sqlBuildFields := []string{
  29 + "created_at",
  30 + "deleted_at",
  31 + "updated_at",
  32 + "extend",
  33 + "company_id",
  34 + "content",
  35 + "is_read",
  36 + "module",
  37 + "module_action",
  38 + "notice_personal_id",
  39 + "org_id",
  40 + "sys_code",
  41 + "user_id",
  42 + "user_base_id",
  43 + }
  44 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  45 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
  46 + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  47 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "noticePersonal_id")
  48 + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
  49 + tx := repository.transactionContext.PgTx
  50 + if noticePersonal.Identify() == nil {
  51 + noticePersonalId, err := repository.nextIdentify()
  52 + if err != nil {
  53 + return noticePersonal, err
  54 + } else {
  55 + noticePersonal.NoticePersonalId = noticePersonalId
  56 + }
  57 + if _, err := tx.QueryOne(
  58 + pg.Scan(
  59 + &noticePersonal.CreatedAt,
  60 + &noticePersonal.DeletedAt,
  61 + &noticePersonal.UpdatedAt,
  62 + &noticePersonal.Extend,
  63 + &noticePersonal.CompanyId,
  64 + &noticePersonal.Content,
  65 + &noticePersonal.IsRead,
  66 + &noticePersonal.Module,
  67 + &noticePersonal.ModuleAction,
  68 + &noticePersonal.NoticePersonalId,
  69 + &noticePersonal.OrgId,
  70 + &noticePersonal.SysCode,
  71 + &noticePersonal.UserId,
  72 + &noticePersonal.UserBaseId,
  73 + ),
  74 + fmt.Sprintf("INSERT INTO notice_personals (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  75 + noticePersonal.CreatedAt,
  76 + noticePersonal.DeletedAt,
  77 + noticePersonal.UpdatedAt,
  78 + noticePersonal.Extend,
  79 + noticePersonal.CompanyId,
  80 + noticePersonal.Content,
  81 + noticePersonal.IsRead,
  82 + noticePersonal.Module,
  83 + noticePersonal.ModuleAction,
  84 + noticePersonal.NoticePersonalId,
  85 + noticePersonal.OrgId,
  86 + noticePersonal.SysCode,
  87 + noticePersonal.UserId,
  88 + noticePersonal.UserBaseId,
  89 + ); err != nil {
  90 + return noticePersonal, err
  91 + }
  92 + } else {
  93 + if _, err := tx.QueryOne(
  94 + pg.Scan(
  95 + &noticePersonal.CreatedAt,
  96 + &noticePersonal.DeletedAt,
  97 + &noticePersonal.UpdatedAt,
  98 + &noticePersonal.Extend,
  99 + &noticePersonal.CompanyId,
  100 + &noticePersonal.Content,
  101 + &noticePersonal.IsRead,
  102 + &noticePersonal.Module,
  103 + &noticePersonal.ModuleAction,
  104 + &noticePersonal.NoticePersonalId,
  105 + &noticePersonal.OrgId,
  106 + &noticePersonal.SysCode,
  107 + &noticePersonal.UserId,
  108 + &noticePersonal.UserBaseId,
  109 + ),
  110 + fmt.Sprintf("UPDATE notice_personals SET %s WHERE notice_personal_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  111 + noticePersonal.CreatedAt,
  112 + noticePersonal.DeletedAt,
  113 + noticePersonal.UpdatedAt,
  114 + noticePersonal.Extend,
  115 + noticePersonal.CompanyId,
  116 + noticePersonal.Content,
  117 + noticePersonal.IsRead,
  118 + noticePersonal.Module,
  119 + noticePersonal.ModuleAction,
  120 + noticePersonal.NoticePersonalId,
  121 + noticePersonal.OrgId,
  122 + noticePersonal.SysCode,
  123 + noticePersonal.UserId,
  124 + noticePersonal.Identify(),
  125 + ); err != nil {
  126 + return noticePersonal, err
  127 + }
  128 + }
  129 + return noticePersonal, nil
  130 +}
  131 +func (repository *NoticePersonalRepository) Remove(noticePersonal *domain.NoticePersonal) (*domain.NoticePersonal, error) {
  132 + tx := repository.transactionContext.PgTx
  133 + noticePersonalModel := new(models.NoticePersonal)
  134 + noticePersonalModel.NoticePersonalId = noticePersonal.Identify().(int64)
  135 + if _, err := tx.Model(noticePersonalModel).WherePK().Delete(); err != nil {
  136 + return noticePersonal, err
  137 + }
  138 + return noticePersonal, nil
  139 +}
  140 +func (repository *NoticePersonalRepository) FindOne(queryOptions map[string]interface{}) (*domain.NoticePersonal, error) {
  141 + tx := repository.transactionContext.PgTx
  142 + noticePersonalModel := new(models.NoticePersonal)
  143 + query := sqlbuilder.BuildQuery(tx.Model(noticePersonalModel), queryOptions)
  144 + query.SetWhereByQueryOption("notice_personal.notice_personal_id = ?", "noticePersonalId")
  145 + if err := query.First(); err != nil {
  146 + if err.Error() == "pg: no rows in result set" {
  147 + return nil, fmt.Errorf("没有此资源")
  148 + } else {
  149 + return nil, err
  150 + }
  151 + }
  152 + if noticePersonalModel.NoticePersonalId == 0 {
  153 + return nil, nil
  154 + } else {
  155 + return transform.TransformToNoticePersonalDomainModelFromPgModels(noticePersonalModel)
  156 + }
  157 +}
  158 +func (repository *NoticePersonalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.NoticePersonal, error) {
  159 + tx := repository.transactionContext.PgTx
  160 + var noticePersonalModels []*models.NoticePersonal
  161 + noticePersonals := make([]*domain.NoticePersonal, 0)
  162 + query := sqlbuilder.BuildQuery(tx.Model(&noticePersonalModels), queryOptions)
  163 + query.SetOffsetAndLimit(20)
  164 + query.SetOrderDirect("notice_personal_id", "DESC")
  165 + if count, err := query.SelectAndCount(); err != nil {
  166 + return 0, noticePersonals, err
  167 + } else {
  168 + for _, noticePersonalModel := range noticePersonalModels {
  169 + if noticePersonal, err := transform.TransformToNoticePersonalDomainModelFromPgModels(noticePersonalModel); err != nil {
  170 + return 0, noticePersonals, err
  171 + } else {
  172 + noticePersonals = append(noticePersonals, noticePersonal)
  173 + }
  174 + }
  175 + return int64(count), noticePersonals, nil
  176 + }
  177 +}
  178 +func NewNoticePersonalRepository(transactionContext *pgTransaction.TransactionContext) (*NoticePersonalRepository, error) {
  179 + if transactionContext == nil {
  180 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  181 + } else {
  182 + return &NoticePersonalRepository{
  183 + transactionContext: transactionContext,
  184 + }, nil
  185 + }
  186 +}