作者 tangxuhui

更新

... ... @@ -22,10 +22,10 @@ func CreateNoticeSettingRepository(options map[string]interface{}) (domain.Notic
return repository.NewNoticeSettingRepository(transactionContext)
}
func CreateNoticeEmptyRepository(options map[string]interface{}) (domain.NoticeEmptyRepository, error) {
func CreateNoticePersonalRepository(options map[string]interface{}) (domain.NoticePersonalRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewNoticeEmptyRepository(transactionContext)
return repository.NewNoticePersonalRepository(transactionContext)
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type AgreeJoinCreationProjectCommand struct {
// 接收方用户id
UserId int64 `json:"userId" valid:"Required"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
// 共创项目名称
CreationProjectName string `json:"creationProjectName" valid:"Required"`
// 共创项目编号
CreationProjectNumber string `json:"creationProjectNumber" valid:"Required"`
}
func (agreeJoinCreationProjectCommand *AgreeJoinCreationProjectCommand) Valid(validation *validation.Validation) {
}
func (agreeJoinCreationProjectCommand *AgreeJoinCreationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(agreeJoinCreationProjectCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type InformExpectedDividendsCommand struct {
// 用户id
UserId int64 `json:"userId" valid:"Required"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
// 共创项目名称
CreationProjectName string `json:"creationProjectName" valid:"Required"`
// 共创合约id
CreationContractId int64 `json:"creationContractId" valid:"Required"`
// 共创合约名称
CreationContractName string `json:"creationContractName" valid:"Required"`
// 共创合约编号
CreationContractNumber string `json:"creationContractNumber" valid:"Required"`
// 产品名称
ProductName string `json:"productName" valid:"Required"`
}
func (informExpectedDividendsCommand *InformExpectedDividendsCommand) Valid(validation *validation.Validation) {
}
func (informExpectedDividendsCommand *InformExpectedDividendsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(informExpectedDividendsCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type InformJoinCreationContractCommand struct {
// 接收方用户id
UserId int64 `json:"userId" valid:"Required"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
// 共创项目名称
CreationProjectName string `json:"creationProjectName" valid:"Required"`
// 共创合约id
CreationContractId int64 `json:"creationContractId" valid:"Required"`
// 共创合约名称
CreationContractName string `json:"creationContractName" valid:"Required"`
// 共创合约编号
CreationContractNumber string `json:"creationContractNumber" valid:"Required"`
}
func (informJoinCreationContractCommand *InformJoinCreationContractCommand) Valid(validation *validation.Validation) {
}
func (informJoinCreationContractCommand *InformJoinCreationContractCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(informJoinCreationContractCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type RefuseJoinCreationProjectCommand struct {
// 接收方用户id
UserId int64 `json:"userId" valid:"Required"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
// 共创项目名称
CreationProjectName string `json:"creationProjectName" valid:"Required"`
// 共创项目编号
CreationProjectNumber string `json:"creationProjectNumber" valid:"Required"`
}
func (refuseJoinCreationProjectCommand *RefuseJoinCreationProjectCommand) Valid(validation *validation.Validation) {
}
func (refuseJoinCreationProjectCommand *RefuseJoinCreationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(refuseJoinCreationProjectCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type GetNoticePersonalListQuery struct {
// 接收方用户的id
UserId int64 `json:"userId"`
// 分页偏移量
PageSize int64 `json:"pageSize"`
// 每页限制数量 默认20
PageIndex int64 `json:"pageIndex"`
// 是否是已读
IsRead int64 `json:"isRead"`
}
func (getNoticePersonalListQuery *GetNoticePersonalListQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getNoticePersonalListQuery *GetNoticePersonalListQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getNoticePersonalListQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/query"
)
// 个人消息通知
type NoticePersonalService struct {
}
// 设置消息:共创申请审核通过
func (noticePersonalService *NoticePersonalService) AgreeJoinCreationProject(agreeJoinCreationProjectCommand *command.AgreeJoinCreationProjectCommand) (interface{}, error) {
if err := agreeJoinCreationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 获取消息列表
func (noticePersonalService *NoticePersonalService) GetNoticePersonalList(getNoticePersonalListQuery *query.GetNoticePersonalListQuery) (interface{}, error) {
if err := getNoticePersonalListQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 设置消息:分红预算消息
func (noticePersonalService *NoticePersonalService) InformExpectedDividends(informExpectedDividendsCommand *command.InformExpectedDividendsCommand) (interface{}, error) {
if err := informExpectedDividendsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 设置消息:共创确认
func (noticePersonalService *NoticePersonalService) InformJoinCreationContract(informJoinCreationContractCommand *command.InformJoinCreationContractCommand) (interface{}, error) {
if err := informJoinCreationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 设置消息:共创申请审核拒绝
func (noticePersonalService *NoticePersonalService) RefuseJoinCreationProject(refuseJoinCreationProjectCommand *command.RefuseJoinCreationProjectCommand) (interface{}, error) {
if err := refuseJoinCreationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
func NewNoticePersonalService(options map[string]interface{}) *NoticePersonalService {
newNoticePersonalService := &NoticePersonalService{}
return newNoticePersonalService
}
... ...
package domain
// 系统默认的空白消息配置样板
type NoticeEmpty struct {
// 消息id
NoticeEmptyId int64 `json:"noticeEmptyId"`
// 内容模板
Content string `json:"content"`
// 是否推送 【是:1】【否:2】
IsPush int `json:"isPush"`
// 消息对应的业务模块
Module string `json:"module"`
// 业务环节
ModuleAction string `json:"moduleAction"`
// 消息对应的编码
SysCode string `json:"sysCode"`
}
type NoticeEmptyRepository interface {
Save(noticeEmpty *NoticeEmpty) (*NoticeEmpty, error) //用不到
// Remove(noticeEmpty *NoticeEmpty) (*NoticeEmpty, error)//用户不到
// FindOne(queryOptions map[string]interface{}) (*NoticeEmpty, error) //用不到
Find(queryOptions map[string]interface{}) (int64, []*NoticeEmpty, error)
}
func (noticeEmpty *NoticeEmpty) Identify() interface{} {
if noticeEmpty.NoticeEmptyId == 0 {
return nil
}
return noticeEmpty.NoticeEmptyId
}
func (noticeEmpty *NoticeEmpty) Update(data map[string]interface{}) error {
if noticeEmptyId, ok := data["noticeEmptyId"]; ok {
noticeEmpty.NoticeEmptyId = noticeEmptyId.(int64)
}
if content, ok := data["content"]; ok {
noticeEmpty.Content = content.(string)
}
if isPush, ok := data["isPush"]; ok {
noticeEmpty.IsPush = isPush.(int)
}
if module, ok := data["module"]; ok {
noticeEmpty.Module = module.(string)
}
if moduleAction, ok := data["moduleAction"]; ok {
noticeEmpty.ModuleAction = moduleAction.(string)
}
if sysCode, ok := data["sysCode"]; ok {
noticeEmpty.SysCode = sysCode.(string)
}
return nil
}
package domain
import "time"
const (
NoticePersonalIsNotRead = 1
NoticePersonalIsRead = 2
)
// 个人消息通知内容
type NoticePersonal struct {
// 编号id
NoticePersonalId int64 `json:"noticePersonalId"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 发送通知时的扩展参数
Extend string `json:"extend"`
// 公司id
CompanyId int64 `json:"companyId"`
// 内容模板
Content string `json:"content"`
// 是否已读【1:未读】【2:已读】
IsRead string `json:"isRead"`
// 消息对应的业务模块
Module string `json:"module"`
// 业务环节
ModuleAction string `json:"moduleAction"`
//账号id
UserBaseId int64 `json:"userBaseId"`
// 组织id
OrgId int64 `json:"orgId"`
// 消息对应的编码
SysCode string `json:"sysCode"`
// 接收方用户id
UserId int64 `json:"userId"`
}
type NoticePersonalRepository interface {
Save(noticePersonal *NoticePersonal) (*NoticePersonal, error)
Remove(noticePersonal *NoticePersonal) (*NoticePersonal, error)
FindOne(queryOptions map[string]interface{}) (*NoticePersonal, error)
Find(queryOptions map[string]interface{}) (int64, []*NoticePersonal, error)
}
func (noticePersonal *NoticePersonal) Identify() interface{} {
if noticePersonal.NoticePersonalId == 0 {
return nil
}
return noticePersonal.NoticePersonalId
}
func (noticePersonal *NoticePersonal) Update(data map[string]interface{}) error {
if createdAt, ok := data["createdAt"]; ok {
noticePersonal.CreatedAt = createdAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
noticePersonal.DeletedAt = deletedAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
noticePersonal.UpdatedAt = updatedAt.(time.Time)
}
if extend, ok := data["extend"]; ok {
noticePersonal.Extend = extend.(string)
}
if companyId, ok := data["companyId"]; ok {
noticePersonal.CompanyId = companyId.(int64)
}
if content, ok := data["content"]; ok {
noticePersonal.Content = content.(string)
}
if isRead, ok := data["isRead"]; ok {
noticePersonal.IsRead = isRead.(string)
}
if module, ok := data["module"]; ok {
noticePersonal.Module = module.(string)
}
if moduleAction, ok := data["moduleAction"]; ok {
noticePersonal.ModuleAction = moduleAction.(string)
}
if noticePersonalId, ok := data["noticePersonalId"]; ok {
noticePersonal.NoticePersonalId = noticePersonalId.(int64)
}
if organizationId, ok := data["organizationId"]; ok {
noticePersonal.OrgId = organizationId.(int64)
}
if sysCode, ok := data["sysCode"]; ok {
noticePersonal.SysCode = sysCode.(string)
}
if userId, ok := data["userId"]; ok {
noticePersonal.UserId = userId.(int64)
}
if userId, ok := data["userBaseId"]; ok {
noticePersonal.UserBaseId = userId.(int64)
}
return nil
}
... ...
package models
type NoticeEmpty struct {
tableName string `pg:"notice_emptys,alias:notice_empty"`
// 消息id
NoticeEmptyId int64
// 内容模板
Content string
// 是否推送 【是:1】【否:2】
IsPush int
// 消息对应的业务模块
Module string
// 业务环节
ModuleAction string
// 消息对应的编码
SysCode string
}
package models
import "time"
type NoticePersonal struct {
tableName string `pg:"notice_personals"`
// 创建时间
CreatedAt time.Time
// 删除时间
DeletedAt time.Time
// 更新时间
UpdatedAt time.Time
// 发送通知时的扩展参数
Extend string
// 公司id
CompanyId int64
// 内容模板
Content string
// 是否已读【1:未读】【2:已读】
IsRead string
// 消息对应的业务模块
Module string
// 业务环节
ModuleAction string
// 编号id
NoticePersonalId int64
// 组织id
OrgId int64
// 消息对应的编码
SysCode string
// 接收方用户id
UserId int64
UserBaseId int64
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
)
func TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel *models.NoticeEmpty) (*domain.NoticeEmpty, error) {
return &domain.NoticeEmpty{
NoticeEmptyId: noticeEmptyModel.NoticeEmptyId,
Content: noticeEmptyModel.Content,
IsPush: noticeEmptyModel.IsPush,
Module: noticeEmptyModel.Module,
ModuleAction: noticeEmptyModel.ModuleAction,
SysCode: noticeEmptyModel.SysCode,
}, nil
}
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
)
func TransformToNoticePersonalDomainModelFromPgModels(noticePersonalModel *models.NoticePersonal) (*domain.NoticePersonal, error) {
return &domain.NoticePersonal{
CreatedAt: noticePersonalModel.CreatedAt,
DeletedAt: noticePersonalModel.DeletedAt,
UpdatedAt: noticePersonalModel.UpdatedAt,
Extend: noticePersonalModel.Extend,
CompanyId: noticePersonalModel.CompanyId,
Content: noticePersonalModel.Content,
IsRead: noticePersonalModel.IsRead,
Module: noticePersonalModel.Module,
ModuleAction: noticePersonalModel.ModuleAction,
NoticePersonalId: noticePersonalModel.NoticePersonalId,
OrgId: noticePersonalModel.OrgId,
SysCode: noticePersonalModel.SysCode,
UserId: noticePersonalModel.UserId,
}, nil
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform"
)
type NoticeEmptyRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *NoticeEmptyRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *NoticeEmptyRepository) Save(noticeEmpty *domain.NoticeEmpty) (*domain.NoticeEmpty, error) {
sqlBuildFields := []string{
"notice_empty_id",
"content",
"is_push",
"module",
"module_action",
"sys_code",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "noticeEmpty_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if noticeEmpty.Identify() == nil {
noticeEmptyId, err := repository.nextIdentify()
if err != nil {
return noticeEmpty, err
} else {
noticeEmpty.NoticeEmptyId = noticeEmptyId
}
if _, err := tx.QueryOne(
pg.Scan(
&noticeEmpty.NoticeEmptyId,
&noticeEmpty.Content,
&noticeEmpty.IsPush,
&noticeEmpty.Module,
&noticeEmpty.ModuleAction,
&noticeEmpty.SysCode,
),
fmt.Sprintf("INSERT INTO notice_emptys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
noticeEmpty.NoticeEmptyId,
noticeEmpty.Content,
noticeEmpty.IsPush,
noticeEmpty.Module,
noticeEmpty.ModuleAction,
noticeEmpty.SysCode,
); err != nil {
return noticeEmpty, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&noticeEmpty.NoticeEmptyId,
&noticeEmpty.Content,
&noticeEmpty.IsPush,
&noticeEmpty.Module,
&noticeEmpty.ModuleAction,
&noticeEmpty.SysCode,
),
fmt.Sprintf("UPDATE notice_emptys SET %s WHERE notice_empty_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
noticeEmpty.NoticeEmptyId,
noticeEmpty.Content,
noticeEmpty.IsPush,
noticeEmpty.Module,
noticeEmpty.ModuleAction,
noticeEmpty.SysCode,
noticeEmpty.Identify(),
); err != nil {
return noticeEmpty, err
}
}
return noticeEmpty, nil
}
func (repository *NoticeEmptyRepository) Remove(noticeEmpty *domain.NoticeEmpty) (*domain.NoticeEmpty, error) {
tx := repository.transactionContext.PgTx
noticeEmptyModel := new(models.NoticeEmpty)
noticeEmptyModel.NoticeEmptyId = noticeEmpty.Identify().(int64)
if _, err := tx.Model(noticeEmptyModel).WherePK().Delete(); err != nil {
return noticeEmpty, err
}
return noticeEmpty, nil
}
func (repository *NoticeEmptyRepository) FindOne(queryOptions map[string]interface{}) (*domain.NoticeEmpty, error) {
tx := repository.transactionContext.PgTx
noticeEmptyModel := new(models.NoticeEmpty)
query := sqlbuilder.BuildQuery(tx.Model(noticeEmptyModel), queryOptions)
query.SetWhereByQueryOption("notice_empty.notice_empty_id = ?", "noticeEmptyId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if noticeEmptyModel.NoticeEmptyId == 0 {
return nil, nil
} else {
return transform.TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel)
}
}
func (repository *NoticeEmptyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.NoticeEmpty, error) {
tx := repository.transactionContext.PgTx
var noticeEmptyModels []*models.NoticeEmpty
noticeEmptys := make([]*domain.NoticeEmpty, 0)
query := sqlbuilder.BuildQuery(tx.Model(&noticeEmptyModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("notice_empty_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, noticeEmptys, err
} else {
for _, noticeEmptyModel := range noticeEmptyModels {
if noticeEmpty, err := transform.TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel); err != nil {
return 0, noticeEmptys, err
} else {
noticeEmptys = append(noticeEmptys, noticeEmpty)
}
}
return int64(count), noticeEmptys, nil
}
}
func NewNoticeEmptyRepository(transactionContext *pgTransaction.TransactionContext) (*NoticeEmptyRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &NoticeEmptyRepository{
transactionContext: transactionContext,
}, nil
}
}
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform"
)
type NoticePersonalRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *NoticePersonalRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePersonal) (*domain.NoticePersonal, error) {
sqlBuildFields := []string{
"created_at",
"deleted_at",
"updated_at",
"extend",
"company_id",
"content",
"is_read",
"module",
"module_action",
"notice_personal_id",
"org_id",
"sys_code",
"user_id",
"user_base_id",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "noticePersonal_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if noticePersonal.Identify() == nil {
noticePersonalId, err := repository.nextIdentify()
if err != nil {
return noticePersonal, err
} else {
noticePersonal.NoticePersonalId = noticePersonalId
}
if _, err := tx.QueryOne(
pg.Scan(
&noticePersonal.CreatedAt,
&noticePersonal.DeletedAt,
&noticePersonal.UpdatedAt,
&noticePersonal.Extend,
&noticePersonal.CompanyId,
&noticePersonal.Content,
&noticePersonal.IsRead,
&noticePersonal.Module,
&noticePersonal.ModuleAction,
&noticePersonal.NoticePersonalId,
&noticePersonal.OrgId,
&noticePersonal.SysCode,
&noticePersonal.UserId,
&noticePersonal.UserBaseId,
),
fmt.Sprintf("INSERT INTO notice_personals (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
noticePersonal.CreatedAt,
noticePersonal.DeletedAt,
noticePersonal.UpdatedAt,
noticePersonal.Extend,
noticePersonal.CompanyId,
noticePersonal.Content,
noticePersonal.IsRead,
noticePersonal.Module,
noticePersonal.ModuleAction,
noticePersonal.NoticePersonalId,
noticePersonal.OrgId,
noticePersonal.SysCode,
noticePersonal.UserId,
noticePersonal.UserBaseId,
); err != nil {
return noticePersonal, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&noticePersonal.CreatedAt,
&noticePersonal.DeletedAt,
&noticePersonal.UpdatedAt,
&noticePersonal.Extend,
&noticePersonal.CompanyId,
&noticePersonal.Content,
&noticePersonal.IsRead,
&noticePersonal.Module,
&noticePersonal.ModuleAction,
&noticePersonal.NoticePersonalId,
&noticePersonal.OrgId,
&noticePersonal.SysCode,
&noticePersonal.UserId,
&noticePersonal.UserBaseId,
),
fmt.Sprintf("UPDATE notice_personals SET %s WHERE notice_personal_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
noticePersonal.CreatedAt,
noticePersonal.DeletedAt,
noticePersonal.UpdatedAt,
noticePersonal.Extend,
noticePersonal.CompanyId,
noticePersonal.Content,
noticePersonal.IsRead,
noticePersonal.Module,
noticePersonal.ModuleAction,
noticePersonal.NoticePersonalId,
noticePersonal.OrgId,
noticePersonal.SysCode,
noticePersonal.UserId,
noticePersonal.Identify(),
); err != nil {
return noticePersonal, err
}
}
return noticePersonal, nil
}
func (repository *NoticePersonalRepository) Remove(noticePersonal *domain.NoticePersonal) (*domain.NoticePersonal, error) {
tx := repository.transactionContext.PgTx
noticePersonalModel := new(models.NoticePersonal)
noticePersonalModel.NoticePersonalId = noticePersonal.Identify().(int64)
if _, err := tx.Model(noticePersonalModel).WherePK().Delete(); err != nil {
return noticePersonal, err
}
return noticePersonal, nil
}
func (repository *NoticePersonalRepository) FindOne(queryOptions map[string]interface{}) (*domain.NoticePersonal, error) {
tx := repository.transactionContext.PgTx
noticePersonalModel := new(models.NoticePersonal)
query := sqlbuilder.BuildQuery(tx.Model(noticePersonalModel), queryOptions)
query.SetWhereByQueryOption("notice_personal.notice_personal_id = ?", "noticePersonalId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if noticePersonalModel.NoticePersonalId == 0 {
return nil, nil
} else {
return transform.TransformToNoticePersonalDomainModelFromPgModels(noticePersonalModel)
}
}
func (repository *NoticePersonalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.NoticePersonal, error) {
tx := repository.transactionContext.PgTx
var noticePersonalModels []*models.NoticePersonal
noticePersonals := make([]*domain.NoticePersonal, 0)
query := sqlbuilder.BuildQuery(tx.Model(&noticePersonalModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("notice_personal_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, noticePersonals, err
} else {
for _, noticePersonalModel := range noticePersonalModels {
if noticePersonal, err := transform.TransformToNoticePersonalDomainModelFromPgModels(noticePersonalModel); err != nil {
return 0, noticePersonals, err
} else {
noticePersonals = append(noticePersonals, noticePersonal)
}
}
return int64(count), noticePersonals, nil
}
}
func NewNoticePersonalRepository(transactionContext *pgTransaction.TransactionContext) (*NoticePersonalRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &NoticePersonalRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...