切换导航条
此项目
正在载入...
登录
allied-creation
/
performance
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
tangxvhui
2 years ago
提交
59171f1bb4dbd8e99d1534c3ee0116dd8bdc7443
1 个父辈
4ecfc896
master
...
dev-pushdata
dev-tangxvhui
dev-zhengzhou
dev_zhuangmx
test
v1.3.2-fix
v1.4.0
v2.2.0-fix
20230410
20230403
20230331
20230324
20230315
20230203
20230112
20221208
20221205
v2.2.0
v2.0.0
v1.3.2
v1.3.2-fix
v1.3.1
v1.3.0
v1.2.4
更新
隐藏空白字符变更
内嵌
并排对比
正在显示
7 个修改的文件
包含
281 行增加
和
33 行删除
pkg/application/company/service.go
pkg/application/department/sync_data_service.go
pkg/application/user/sync_data_service.go
pkg/domain/received_message.go
pkg/infrastructure/pg/init.go
pkg/infrastructure/pg/models/message_record.go
pkg/infrastructure/repository/pg_received_message_repository.go
pkg/application/company/service.go
查看文件 @
59171f1
package
company
import
(
"encoding/json"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/company/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
type
CompanyServices
struct
{
type
SyncDataCompanyService
struct
{
}
type
BusinessAdminCommand
struct
{
//company:公司
Module
string
`json:"module"`
// add:添加,edit:编辑,setCompanyCharge:更改公司主管,changeAdmin换管理员
Action
string
`json:"action"`
// 具体的对象JSON数据
Datas
json
.
RawMessage
`json:"data"`
}
//从BusinessAdmins 接收消息,变更公司数据
//
func
(
c
CompanyServices
)
BusinessAdminCompany
()
error
{
return
nil
func
(
c
SyncDataCompanyService
)
FromBusinessAdminCompany
(
param
*
BusinessAdminCommand
)
error
{
action
:=
param
.
Module
+
"/"
+
param
.
Action
var
err
error
switch
action
{
case
"company/add"
:
var
param1
command
.
SaveCompanyCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param1
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
c
.
addCompany
(
&
param1
)
case
"company/edit"
:
var
param2
command
.
SaveCompanyCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param2
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
c
.
editCompany
(
&
param2
)
case
"company/setCompanyCharge"
:
var
param3
command
.
SetCompanyCharge
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param3
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
c
.
setCompanyCharge
(
&
param3
)
case
"company/changeAdmin"
:
var
param3
command
.
ChangeAdminCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param3
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
c
.
changeAdmin
(
&
param3
)
default
:
log
.
Logger
.
Error
(
"action err:"
+
action
)
}
return
err
}
//addCompany
//从BusinessAdmins 接收消息 添加公司
func
(
c
CompanyServices
)
addCompany
(
param
*
command
.
SaveCompanyCommand
)
error
{
//module="company" action="add"
func
(
c
SyncDataCompanyService
)
addCompany
(
param
*
command
.
SaveCompanyCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -63,11 +109,11 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error {
})
_
,
err
=
companyRepo
.
Insert
(
&
newCompany
)
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
_
,
err
=
userRepo
.
Insert
(
&
newUser
)
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -77,7 +123,8 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error {
//editCompany
//从BusinessAdmins 接收消息 更新公司
func
(
c
CompanyServices
)
editCompany
(
param
*
command
.
SaveCompanyCommand
)
error
{
//module="company" action="edit"
func
(
c
SyncDataCompanyService
)
editCompany
(
param
*
command
.
SaveCompanyCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -100,14 +147,14 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error {
"id"
:
param
.
Comapany
.
Id
,
})
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
_
,
userList
,
err
:=
userRepo
.
Find
(
map
[
string
]
interface
{}{
"limit"
:
1
,
"id"
:
param
.
User
.
Id
,
})
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
var
(
newCompany
*
domain
.
Company
...
...
@@ -146,32 +193,33 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error {
if
len
(
companyList
)
>
0
{
_
,
err
=
companyRepo
.
Update
(
newCompany
)
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
else
{
_
,
err
=
companyRepo
.
Insert
(
newCompany
)
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
if
len
(
userList
)
>
0
{
_
,
err
=
userRepo
.
Update
(
newUser
)
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
else
{
_
,
err
=
userRepo
.
Insert
(
newUser
)
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
return
nil
}
func
(
srv
CompanyServices
)
setCompanyCharge
(
param
*
command
.
SetCompanyCharge
)
error
{
//module="company" action="setCompanyCharge"
func
(
srv
SyncDataCompanyService
)
setCompanyCharge
(
param
*
command
.
SetCompanyCharge
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -193,14 +241,14 @@ func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) err
})
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
for
i
:=
range
companyList
{
companyList
[
i
]
.
ChargeUserIds
=
param
.
ChargeUserIds
companyList
[
i
]
.
UpdateAt
=
time
.
Now
()
_
,
err
=
companyRepo
.
Update
(
companyList
[
i
])
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
...
...
@@ -211,7 +259,8 @@ func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) err
//changeAdmin
//从BusinessAdmins 接收消息 变更主管
func
(
srv
CompanyServices
)
changeAdmin
(
param
*
command
.
ChangeAdminCommand
)
error
{
//module="company" action="changeAdmin"
func
(
srv
SyncDataCompanyService
)
changeAdmin
(
param
*
command
.
ChangeAdminCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -233,7 +282,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
"adminType"
:
domain
.
UserTypeManager
,
})
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
//修改旧管理员 为普通用户
for
i
:=
range
userList
{
...
...
@@ -241,7 +290,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
userList
[
i
]
.
UpdateAt
=
time
.
Now
()
_
,
err
:=
userRepo
.
Update
(
userList
[
i
])
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
//获取新管理员
...
...
@@ -251,7 +300,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
"account"
:
param
.
UserAccount
,
})
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
//修改为管理员用户
for
i
:=
range
userList2
{
...
...
@@ -259,7 +308,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
userList
[
i
]
.
UpdateAt
=
time
.
Now
()
_
,
err
:=
userRepo
.
Update
(
userList
[
i
])
if
err
!=
nil
{
return
err
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
...
...
pkg/application/department/sync_data_service.go
查看文件 @
59171f1
package
department
import
(
"encoding/json"
"time"
"github.com/linmadan/egglib-go/core/application"
...
...
@@ -11,10 +12,55 @@ import (
type
SyncDataDepartmentService
struct
{}
type
BusinessAdminCommand
struct
{
// department:部门
Module
string
`json:"module"`
// add:添加,edit:编辑,batchDelete:批量删除,import:导入部门
Action
string
`json:"action"`
// 具体的对象JSON数据
Datas
json
.
RawMessage
`json:"data"`
}
func
(
srv
SyncDataDepartmentService
)
FromBusinessAdminCompany
(
param
BusinessAdminCommand
)
error
{
action
:=
param
.
Module
+
"/"
+
param
.
Action
var
err
error
switch
action
{
case
"department/add"
:
var
param1
command
.
AddDepartmentCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param1
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
addDepartment
(
&
param1
)
case
"department/edit"
:
var
param1
command
.
EditDepartmentCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param1
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
editDepartment
(
&
param1
)
case
"department/batchDelete"
:
var
param1
command
.
BatchDeleteCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param1
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
batchDeleteDepartment
(
&
param1
)
case
"department/import"
:
var
param1
[]
command
.
ImportDepartmentCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param1
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
importDepartment
(
param1
)
}
return
err
}
//AddDepartment
//从BusinessAdmins 接收消息 添加部门
//module="department" action="add"
func
(
srv
SyncDataDepartmentService
)
addDepartment
(
param
command
.
AddDepartmentCommand
)
error
{
func
(
srv
SyncDataDepartmentService
)
addDepartment
(
param
*
command
.
AddDepartmentCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -56,7 +102,7 @@ func (srv SyncDataDepartmentService) addDepartment(param command.AddDepartmentCo
//EditDepartment
//从BusinessAdmins 接收消息 编辑部门
//module="department" action="edit"
func
(
srv
SyncDataDepartmentService
)
editDepartment
(
param
command
.
EditDepartmentCommand
)
error
{
func
(
srv
SyncDataDepartmentService
)
editDepartment
(
param
*
command
.
EditDepartmentCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -115,7 +161,7 @@ func (srv SyncDataDepartmentService) editDepartment(param command.EditDepartment
//batchDelete
//从BusinessAdmins 接收消息 删除部门
//module="department" action="batchDelete"
func
(
srv
SyncDataDepartmentService
)
batchDeleteDepartment
(
param
command
.
BatchDeleteCommand
)
error
{
func
(
srv
SyncDataDepartmentService
)
batchDeleteDepartment
(
param
*
command
.
BatchDeleteCommand
)
error
{
if
len
(
param
.
Ids
)
==
0
{
return
nil
}
...
...
pkg/application/user/sync_data_service.go
查看文件 @
59171f1
package
user
import
(
"encoding/json"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/command"
...
...
@@ -11,10 +14,65 @@ import (
type
SyncDataUserService
struct
{}
type
BusinessAdminCommand
struct
{
// employee:员工
Module
string
`json:"module"`
// add:添加,edit:编辑,batchDelete:批量删除,batchForbid:批量禁用用户,batchRemove:批量更改用户部门,import:导入用户
Action
string
`json:"action"`
// 具体的对象JSON数据
Datas
json
.
RawMessage
`json:"data"`
}
func
(
srv
SyncDataUserService
)
FromBusinessAdminCompany
(
param
*
BusinessAdminCommand
)
error
{
action
:=
param
.
Module
+
"/"
+
param
.
Action
var
err
error
switch
action
{
case
"employee/add"
:
var
param1
command
.
SaveUserCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param1
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
AddUser
(
&
param1
)
case
"employee/edit"
:
var
param2
command
.
SaveUserCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param2
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
UpdateUser
(
&
param2
)
case
"employee/batchDelete"
:
var
param3
command
.
BatchDeleteCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param3
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
batchDelete
(
&
param3
)
case
"company/batchForbid"
:
var
param4
command
.
BatchForbidCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param4
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
batchForbid
(
&
param4
)
case
"company/import"
:
var
param4
command
.
ImportUserCommand
err
=
json
.
Unmarshal
(
param
.
Datas
,
&
param4
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
srv
.
importUser
(
&
param4
)
default
:
log
.
Logger
.
Error
(
"action err:"
+
action
)
}
return
err
}
//AddUser
//从BusinessAdmins 接收消息 添加用户
//module="employee" action="add"
func
(
srv
SyncDataUserService
)
AddUser
(
param
command
.
SaveUserCommand
)
error
{
func
(
srv
SyncDataUserService
)
AddUser
(
param
*
command
.
SaveUserCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -59,7 +117,7 @@ func (srv SyncDataUserService) AddUser(param command.SaveUserCommand) error {
//UpdateUser
//从BusinessAdmins 接收消息 更新用户
//module="employee" action="edit"
func
(
srv
SyncDataUserService
)
UpdateUser
(
param
command
.
SaveUserCommand
)
error
{
func
(
srv
SyncDataUserService
)
UpdateUser
(
param
*
command
.
SaveUserCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
@@ -119,7 +177,7 @@ func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error {
//batchDelete
//从BusinessAdmins 接收消息 删除用户
//module="employee" action="batchDelete"
func
(
srv
SyncDataUserService
)
batchDelete
(
param
command
.
BatchDeleteCommand
)
error
{
func
(
srv
SyncDataUserService
)
batchDelete
(
param
*
command
.
BatchDeleteCommand
)
error
{
if
len
(
param
.
Uids
)
==
0
{
return
nil
}
...
...
@@ -150,7 +208,7 @@ func (srv SyncDataUserService) batchDelete(param command.BatchDeleteCommand) err
//batchForbid
//从BusinessAdmins 接收消息 禁用,启用用户
//module="employee" action="batchForbid"
func
(
srv
SyncDataUserService
)
batchForbid
(
param
command
.
BatchForbidCommand
)
error
{
func
(
srv
SyncDataUserService
)
batchForbid
(
param
*
command
.
BatchForbidCommand
)
error
{
if
len
(
param
.
Uids
)
==
0
{
return
nil
}
...
...
@@ -190,7 +248,7 @@ func (srv SyncDataUserService) batchForbid(param command.BatchForbidCommand) err
//importUser
//从BusinessAdmins 接收消息 导入用户数据
//module="employee" action="import"
func
(
srv
SyncDataUserService
)
importUser
(
param
command
.
ImportUserCommand
)
error
{
func
(
srv
SyncDataUserService
)
importUser
(
param
*
command
.
ImportUserCommand
)
error
{
transactionContext
,
err
:=
factory
.
CreateTransactionContext
(
nil
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
...
...
pkg/domain/received_message.go
0 → 100644
查看文件 @
59171f1
package
domain
import
"time"
type
ReceivedMessage
struct
{
MessageId
int64
MessageType
string
MessageBody
string
OccurredOn
time
.
Time
CreateAt
time
.
Time
}
type
ReceivedMessageRepository
interface
{
SaveMessage
(
param
*
ReceivedMessage
)
error
FindMessage
(
id
int64
)
(
*
ReceivedMessage
,
error
)
}
...
...
pkg/infrastructure/pg/init.go
查看文件 @
59171f1
...
...
@@ -3,11 +3,12 @@ package pg
import
(
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/linmadan/egglib-go/persistent/pg/hooks"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
var
DB
*
pg
.
DB
...
...
@@ -24,5 +25,22 @@ func init() {
Logger
:
log
.
Logger
,
})
}
if
!
constant
.
DISABLE_CREATE_TABLE
{
tables
:=
[]
interface
{}{
&
models
.
Company
{},
&
models
.
Department
{},
&
models
.
User
{},
}
for
_
,
model
:=
range
tables
{
err
:=
DB
.
Model
(
model
)
.
CreateTable
(
&
orm
.
CreateTableOptions
{
Temp
:
false
,
IfNotExists
:
true
,
FKConstraints
:
true
,
})
if
err
!=
nil
{
panic
(
err
)
}
}
}
}
...
...
pkg/infrastructure/pg/models/message_record.go
0 → 100644
查看文件 @
59171f1
package
models
import
"time"
type
ReceivedMessage
struct
{
tableName
struct
{}
`pg:"received_message"`
MessageId
int64
`pg:"pk:message_id"`
MessageType
string
MessageBody
string
OccurredOn
time
.
Time
CreateAt
time
.
Time
}
...
...
pkg/infrastructure/repository/pg_received_message_repository.go
0 → 100644
查看文件 @
59171f1
package
repository
import
(
"time"
pgTransaction
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type
ReceivedMessageRepository
struct
{
transactionContext
*
pgTransaction
.
TransactionContext
}
var
_
domain
.
ReceivedMessageRepository
=
(
*
ReceivedMessageRepository
)(
nil
)
func
(
repo
*
ReceivedMessageRepository
)
SaveMessage
(
param
*
domain
.
ReceivedMessage
)
error
{
message
:=
&
models
.
ReceivedMessage
{
MessageId
:
param
.
MessageId
,
MessageType
:
param
.
MessageType
,
MessageBody
:
param
.
MessageBody
,
OccurredOn
:
param
.
OccurredOn
,
CreateAt
:
time
.
Now
(),
}
tx
:=
repo
.
transactionContext
.
PgTx
_
,
err
:=
tx
.
Model
(
message
)
.
Insert
()
return
err
}
func
(
repo
*
ReceivedMessageRepository
)
FindMessage
(
messageId
int64
)
(
*
domain
.
ReceivedMessage
,
error
)
{
tx
:=
repo
.
transactionContext
.
PgTx
receivedMessageModel
:=
new
(
models
.
ReceivedMessage
)
query
:=
tx
.
Model
(
receivedMessageModel
)
.
Where
(
"message.id = ?"
,
messageId
)
if
err
:=
query
.
First
();
err
!=
nil
{
if
err
.
Error
()
!=
"pg: no rows in result set"
{
return
nil
,
err
}
}
message
:=
&
domain
.
ReceivedMessage
{
MessageId
:
receivedMessageModel
.
MessageId
,
MessageType
:
receivedMessageModel
.
MessageType
,
MessageBody
:
receivedMessageModel
.
MessageBody
,
OccurredOn
:
receivedMessageModel
.
OccurredOn
,
CreateAt
:
receivedMessageModel
.
CreateAt
,
}
return
message
,
nil
}
...
...
请
注册
或
登录
后发表评论