作者 tangxuhui

更新

... ... @@ -13,3 +13,19 @@ func CreateDictionaryRepository(options map[string]interface{}) (domain.Dictiona
}
return repository.NewDictionaryRepository(transactionContext)
}
func CreateNoticeSettingRepository(options map[string]interface{}) (domain.NoticeSettingRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewNoticeSettingRepository(transactionContext)
}
func CreateNoticeEmptyRepository(options map[string]interface{}) (domain.NoticeEmptyRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewNoticeEmptyRepository(transactionContext)
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type RemoveNoticeSettingCommand struct {
// 消息id
NoticeSettingId int64 `json:"noticeSettingId" valid:"Required"`
}
func (removeNoticeSettingCommand *RemoveNoticeSettingCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeNoticeSettingCommand *RemoveNoticeSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeNoticeSettingCommand)
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 UpdateNoticeSettingCommand struct {
NoticeSettingId int64 `json:"noticeSettingId"`
// 公司id
CompanyId int64 `json:"companyId"`
// 内容模板
Content string `json:"content"`
// 是否推送 【是:1】【否:2】
IsPush int `json:"isPush"`
// 消息对应的业务模块
Module string `json:"module"`
// 业务环节
ModuleAction string `json:"moduleAction"`
// 组织id
OrganizationId int64 `json:"organizationId"`
// 消息对应的编码
SysCode string `json:"sysCode"`
}
func (updateNoticeSettingCommand *UpdateNoticeSettingCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateNoticeSettingCommand *UpdateNoticeSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateNoticeSettingCommand)
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 GetNoticeSettingQuery struct {
// 消息id
NoticeSettingId int64 `json:"noticeSettingId" valid:"Required"`
}
func (getNoticeSettingQuery *GetNoticeSettingQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getNoticeSettingQuery *GetNoticeSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getNoticeSettingQuery)
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 ListNoticeSettingQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
func (listNoticeSettingQuery *ListNoticeSettingQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listNoticeSettingQuery *ListNoticeSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listNoticeSettingQuery)
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 (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticeSetting/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticeSetting/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
// 编排消息通知内容
type NoticeSettingService struct {
}
// 返回编排消息通知内容
func (noticeSettingService *NoticeSettingService) GetNoticeSetting(getNoticeSettingQuery *query.GetNoticeSettingQuery) (interface{}, error) {
if err := getNoticeSettingQuery.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()
}()
var noticeSettingRepository domain.NoticeSettingRepository
if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
noticeSetting, err := noticeSettingRepository.FindOne(map[string]interface{}{"noticeSettingId": getNoticeSettingQuery.NoticeSettingId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if noticeSetting == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getNoticeSettingQuery.NoticeSettingId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return noticeSetting, nil
}
}
// 返回编排消息通知内容列表
func (noticeSettingService *NoticeSettingService) ListNoticeSetting(listNoticeSettingQuery *query.ListNoticeSettingQuery) (interface{}, error) {
if err := listNoticeSettingQuery.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()
}()
var noticeSettingRepository domain.NoticeSettingRepository
if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
if count, noticeSettings, err := noticeSettingRepository.Find(tool_funs.SimpleStructToMap(listNoticeSettingQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"noticeSettings": noticeSettings,
}, nil
}
}
// 更新编排消息通知内容
func (noticeSettingService *NoticeSettingService) UpdateNoticeSetting(updateNoticeSettingCommand *command.UpdateNoticeSettingCommand) (interface{}, error) {
if err := updateNoticeSettingCommand.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()
}()
var noticeSettingRepository domain.NoticeSettingRepository
if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
noticeSetting, err := noticeSettingRepository.FindOne(map[string]interface{}{"noticeSettingId": updateNoticeSettingCommand.NoticeSettingId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if noticeSetting == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateNoticeSettingCommand.NoticeSettingId)))
}
if err := noticeSetting.Update(tool_funs.SimpleStructToMap(updateNoticeSettingCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if noticeSetting, err := noticeSettingRepository.Save(noticeSetting); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return noticeSetting, nil
}
}
func NewNoticeSettingService(options map[string]interface{}) *NoticeSettingService {
newNoticeSettingService := &NoticeSettingService{}
return newNoticeSettingService
}
... ...
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"
// 编排消息通知内容
type NoticeSetting struct {
// 消息id
NoticeSettingId int64 `json:"noticeSettingId"`
// 公司id
CompanyId int64 `json:"companyId"`
// 内容模板
Content string `json:"content"`
// 是否推送 【是:1】【否:2】
IsPush int `json:"isPush"`
// 消息对应的业务模块
Module string `json:"module"`
// 业务环节
ModuleAction string `json:"moduleAction"`
// 组织id
OrgId int64 `json:"orgId"`
// 消息对应的编码
SysCode string `json:"sysCode"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
}
type NoticeSettingRepository interface {
Save(noticeSetting *NoticeSetting) (*NoticeSetting, error)
Remove(noticeSetting *NoticeSetting) (*NoticeSetting, error)
FindOne(queryOptions map[string]interface{}) (*NoticeSetting, error)
Find(queryOptions map[string]interface{}) (int64, []*NoticeSetting, error)
}
func (noticeSetting *NoticeSetting) Identify() interface{} {
if noticeSetting.NoticeSettingId == 0 {
return nil
}
return noticeSetting.NoticeSettingId
}
func (noticeSetting *NoticeSetting) Update(data map[string]interface{}) error {
if companyId, ok := data["companyId"]; ok {
noticeSetting.CompanyId = companyId.(int64)
}
if content, ok := data["content"]; ok {
noticeSetting.Content = content.(string)
}
if isPush, ok := data["isPush"]; ok {
noticeSetting.IsPush = isPush.(int)
}
if module, ok := data["module"]; ok {
noticeSetting.Module = module.(string)
}
if moduleAction, ok := data["moduleAction"]; ok {
noticeSetting.ModuleAction = moduleAction.(string)
}
if noticeSettingId, ok := data["noticeSettingId"]; ok {
noticeSetting.NoticeSettingId = noticeSettingId.(int64)
}
if organizationId, ok := data["orgId"]; ok {
noticeSetting.OrgId = organizationId.(int64)
}
if sysCode, ok := data["sysCode"]; ok {
noticeSetting.SysCode = sysCode.(string)
}
if createdAt, ok := data["createdAt"]; ok {
noticeSetting.CreatedAt = createdAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
noticeSetting.DeletedAt = deletedAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
noticeSetting.UpdatedAt = updatedAt.(time.Time)
}
return nil
}
... ...
package domain
//NoticeModule 消息模块
type NoticeModule struct {
ModuleCode string `json:"Code"`
Name string `json:"name"`
}
//NoticeModuleAction 业务环节
type NoticeModuleAction struct {
ModuleCode string `json:"module_code"`
ActionCode string `json:"action_Code"`
Name string `json:"name"`
}
// 编排消息需要的变量
type NoticeSettingParam struct {
// 变量的代码标识
ParamCode string `json:"paramCode"`
// 变量名称描述
ParamName string `json:"paramName"`
// 业务环节
ModuleAction string `json:"moduleAction"`
// 消息对应的业务模块
Module string `json:"module"`
}
//GetNoticeModuleList 获取消息模块列表
func GetNoticeModuleList() []NoticeModule {
return noticeModuleList
}
//GetNoticeModuleActionList 获取业务环节列表
func GetNoticeModuleActionList() []NoticeModuleAction {
return noticeModuleActionList
}
//GetNoticeSettingParamList 获取变量列表
func GetNoticeSettingParamList(actionCode string) []NoticeSettingParam {
if len(actionCode) == 0 {
return noticeSettingParamList
}
var list []NoticeSettingParam
for i := range noticeSettingParamList {
if noticeSettingParamList[i].ModuleAction == actionCode {
list = append(list, noticeSettingParamList[i])
}
}
return list
}
//ValidNoticeModule 校验NoticeModule编码
func ValidNoticeModule(code string) bool {
for i := range noticeModuleList {
if noticeModuleList[i].ModuleCode == code {
return true
}
}
return false
}
//ValidNoticeModuleAction 校验NoticeModuleAction编码
func ValidNoticeModuleAction(moduleCode string, actioncode string) bool {
for i := range noticeModuleActionList {
if (noticeModuleActionList[i].ActionCode == actioncode) &&
(noticeModuleActionList[i].ModuleCode == moduleCode) {
return true
}
}
return false
}
//业务模块
const (
Module01 = "module01" // 天联共创
)
//业务环节
const (
Action01_01 = "action01_01" //天联共创-共创申请通过
Action01_02 = "action01_02" //天联共创-共创申请拒绝
Action01_03 = "action01_03" //天联共创-共创确认
Action01_04 = "action01_04" //天联共创-分红预算消息
Action01_05 = "action01_05" //天联共创-账期结算消息
Action01_06 = "action01_06" //天联共创-支付消息
)
//业务环节变量
const (
Param01_01_01 = "param01_01_01" //共创申请通过-共创项目编号
Param01_01_02 = "param01_01_02" //共创申请通过-共创项目名称
Param01_02_01 = "param01_02_01" //共创申请拒绝-共创项目编号
Param01_02_02 = "param01_02_02" //共创申请拒绝-共创项目名称
Param01_03_01 = "param01_03_01" //共创确认-共创项目编号
Param01_03_02 = "param01_03_02" //共创确认-共创项目名称
Param01_03_03 = "param01_03_03" //共创确认-项目合约编号
Param01_03_04 = "param01_03_04" //共创确认-项目合约名称
Param01_04_01 = "param01_04_01" //分红预算消息-共创项目编号
Param01_04_02 = "param01_04_02" //分红预算消息-共创项目名称
Param01_04_03 = "param01_04_03" //分红预算消息-项目合约编号
Param01_04_04 = "param01_04_04" //分红预算消息-项目合约名称
Param01_04_05 = "param01_04_05" //分红预算消息-订单产品信息
Param01_04_06 = "param01_04_06" //分红预算消息-分红金额
Param01_05_01 = "param01_05_01" //账期结算消息-账期结算单号
Param01_05_02 = "param01_05_02" //账期结算消息-结算金额
Param01_05_03 = "param01_05_03" //账期结算消息-分红预算单号
Param01_06_01 = "param01_06_01" //支付消息-账期结算单号
Param01_06_02 = "param01_06_02" //支付消息-结算金额
Param01_06_03 = "param01_06_03" //支付消息-实付金额
)
//noticeModuleList 模块列表
var noticeModuleList = []NoticeModule{
{ModuleCode: Module01, Name: "天联共创"},
}
//noticeModuleActionList 业务环节列表
var noticeModuleActionList = []NoticeModuleAction{
{ModuleCode: Module01, ActionCode: Action01_01, Name: "共创申请通过"},
{ModuleCode: Module01, ActionCode: Action01_02, Name: "共创申请拒绝"},
{ModuleCode: Module01, ActionCode: Action01_03, Name: "共创确认"},
{ModuleCode: Module01, ActionCode: Action01_04, Name: "分红预算消息"},
{ModuleCode: Module01, ActionCode: Action01_05, Name: "账期结算消息"},
{ModuleCode: Module01, ActionCode: Action01_06, Name: "支付消息"},
}
//noticeSettingParamList 业务变量列表
var noticeSettingParamList = []NoticeSettingParam{
{ModuleAction: Module01, Module: Action01_01, ParamCode: Param01_01_01, ParamName: "共创项目编号"},
{ModuleAction: Module01, Module: Action01_01, ParamCode: Param01_01_02, ParamName: "共创项目名称"},
{ModuleAction: Module01, Module: Action01_02, ParamCode: Param01_02_01, ParamName: "共创项目编号"},
{ModuleAction: Module01, Module: Action01_02, ParamCode: Param01_02_02, ParamName: "共创项目名称"},
{ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_01, ParamName: "共创项目编号"},
{ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_02, ParamName: "共创项目名称"},
{ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_03, ParamName: "项目合约编号"},
{ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_04, ParamName: "项目合约名称"},
{ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_01, ParamName: "共创项目编号"},
{ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_02, ParamName: "共创项目名称"},
{ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_03, ParamName: "项目合约编号"},
{ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_04, ParamName: "项目合约名称"},
{ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_05, ParamName: "订单产品信息"},
{ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_06, ParamName: "分红金额"},
{ModuleAction: Module01, Module: Action01_05, ParamCode: Param01_05_01, ParamName: "账期结算单号"},
{ModuleAction: Module01, Module: Action01_05, ParamCode: Param01_05_02, ParamName: "结算金额"},
{ModuleAction: Module01, Module: Action01_05, ParamCode: Param01_05_03, ParamName: "分红预算单号"},
{ModuleAction: Module01, Module: Action01_06, ParamCode: Param01_06_01, ParamName: "账期结算单号"},
{ModuleAction: Module01, Module: Action01_06, ParamCode: Param01_06_02, ParamName: "结算金额"},
{ModuleAction: Module01, Module: Action01_06, ParamCode: Param01_06_03, ParamName: "实付金额"},
}
... ...
... ... @@ -5,7 +5,7 @@ import (
)
type Dictionary struct {
tableName string `pg:"dictionary"`
tableName string `pg:"dictionarys"`
// 字典编号 主键
DictionaryId int64 `pg:",pk"`
// 字典编码
... ...
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 NoticeSetting struct {
tableName string `pg:"notice_settings"`
// 公司id
CompanyId int64
// 内容模板
Content string
// 是否推送 【是:1】【否:2】
IsPush int
// 消息对应的业务模块
Module string
// 业务环节
ModuleAction string
// 消息id
NoticeSettingId int64
// 组织id
OrgId int64
// 消息对应的编码
SysCode string
// 创建时间
CreatedAt time.Time
// 删除时间
DeletedAt time.Time
// 更新时间
UpdatedAt time.Time
}
... ...
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 TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel *models.NoticeSetting) (*domain.NoticeSetting, error) {
return &domain.NoticeSetting{
CompanyId: noticeSettingModel.CompanyId,
Content: noticeSettingModel.Content,
IsPush: noticeSettingModel.IsPush,
Module: noticeSettingModel.Module,
ModuleAction: noticeSettingModel.ModuleAction,
NoticeSettingId: noticeSettingModel.NoticeSettingId,
OrganizationId: noticeSettingModel.OrganizationId,
SysCode: noticeSettingModel.SysCode,
CreatedAt: noticeSettingModel.CreatedAt,
DeletedAt: noticeSettingModel.DeletedAt,
UpdatedAt: noticeSettingModel.UpdatedAt,
}, 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"
"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 NoticeSettingRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *NoticeSettingRepository) nextIdentify() (int64, error) {
id, err := idWorker.NextId()
return id, err
}
func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSetting) (*domain.NoticeSetting, error) {
sqlBuildFields := []string{
"company_id",
"content",
"is_push",
"module",
"module_action",
"notice_setting_id",
"organization_id",
"sys_code",
"created_at",
"deleted_at",
"updated_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "noticeSetting_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if noticeSetting.Identify() == nil {
noticeSettingId, err := repository.nextIdentify()
if err != nil {
return noticeSetting, err
} else {
noticeSetting.NoticeSettingId = noticeSettingId
}
if _, err := tx.QueryOne(
pg.Scan(
&noticeSetting.CompanyId,
&noticeSetting.Content,
&noticeSetting.IsPush,
&noticeSetting.Module,
&noticeSetting.ModuleAction,
&noticeSetting.NoticeSettingId,
&noticeSetting.OrgId,
&noticeSetting.SysCode,
&noticeSetting.CreatedAt,
&noticeSetting.DeletedAt,
&noticeSetting.UpdatedAt,
),
fmt.Sprintf("INSERT INTO notice_settings (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
noticeSetting.CompanyId,
noticeSetting.Content,
noticeSetting.IsPush,
noticeSetting.Module,
noticeSetting.ModuleAction,
noticeSetting.NoticeSettingId,
noticeSetting.OrgId,
noticeSetting.SysCode,
noticeSetting.CreatedAt,
noticeSetting.DeletedAt,
noticeSetting.UpdatedAt,
); err != nil {
return noticeSetting, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&noticeSetting.CompanyId,
&noticeSetting.Content,
&noticeSetting.IsPush,
&noticeSetting.Module,
&noticeSetting.ModuleAction,
&noticeSetting.NoticeSettingId,
&noticeSetting.OrgId,
&noticeSetting.SysCode,
&noticeSetting.CreatedAt,
&noticeSetting.DeletedAt,
&noticeSetting.UpdatedAt,
),
fmt.Sprintf("UPDATE notice_settings SET %s WHERE notice_setting_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
noticeSetting.CompanyId,
noticeSetting.Content,
noticeSetting.IsPush,
noticeSetting.Module,
noticeSetting.ModuleAction,
noticeSetting.NoticeSettingId,
noticeSetting.OrgId,
noticeSetting.SysCode,
noticeSetting.CreatedAt,
noticeSetting.DeletedAt,
noticeSetting.UpdatedAt,
noticeSetting.Identify(),
); err != nil {
return noticeSetting, err
}
}
return noticeSetting, nil
}
func (repository *NoticeSettingRepository) Remove(noticeSetting *domain.NoticeSetting) (*domain.NoticeSetting, error) {
tx := repository.transactionContext.PgTx
noticeSettingModel := new(models.NoticeSetting)
noticeSettingModel.NoticeSettingId = noticeSetting.Identify().(int64)
if _, err := tx.Model(noticeSettingModel).WherePK().Delete(); err != nil {
return noticeSetting, err
}
return noticeSetting, nil
}
func (repository *NoticeSettingRepository) FindOne(queryOptions map[string]interface{}) (*domain.NoticeSetting, error) {
tx := repository.transactionContext.PgTx
noticeSettingModel := new(models.NoticeSetting)
query := sqlbuilder.BuildQuery(tx.Model(noticeSettingModel), queryOptions)
query.SetWhereByQueryOption("notice_setting.notice_setting_id = ?", "noticeSettingId")
query.SetWhereByQueryOption("notice_setting.module_action=?", "moduleAction")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if noticeSettingModel.NoticeSettingId == 0 {
return nil, nil
} else {
return transform.TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel)
}
}
func (repository *NoticeSettingRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.NoticeSetting, error) {
tx := repository.transactionContext.PgTx
var noticeSettingModels []*models.NoticeSetting
noticeSettings := make([]*domain.NoticeSetting, 0)
query := sqlbuilder.BuildQuery(tx.Model(&noticeSettingModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("notice_setting_id", "DESC")
query.SetWhereByQueryOption("notice_setting.module_action=?", "moduleAction")
query.SetWhereByQueryOption("notice_setting.org_id=?", "orgId")
if count, err := query.SelectAndCount(); err != nil {
return 0, noticeSettings, err
} else {
for _, noticeSettingModel := range noticeSettingModels {
if noticeSetting, err := transform.TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel); err != nil {
return 0, noticeSettings, err
} else {
noticeSettings = append(noticeSettings, noticeSetting)
}
}
return int64(count), noticeSettings, nil
}
}
func NewNoticeSettingRepository(transactionContext *pgTransaction.TransactionContext) (*NoticeSettingRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &NoticeSettingRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...