105 lines
3.0 KiB
Go
105 lines
3.0 KiB
Go
|
package logic
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"github.com/fonchain_enterprise/micro-account/api/accountFiee"
|
||
|
"github.com/fonchain_enterprise/micro-account/pkg/common/utils"
|
||
|
"github.com/fonchain_enterprise/micro-account/pkg/dao"
|
||
|
"github.com/fonchain_enterprise/micro-account/pkg/model"
|
||
|
"github.com/jinzhu/copier"
|
||
|
)
|
||
|
|
||
|
type ChatUserLogic struct{}
|
||
|
|
||
|
// 创建聊天用户
|
||
|
func (ChatUserLogic) CreateChatUser(data *accountFiee.ChatUserData) (resp *accountFiee.CreateChatUserResp, err error) {
|
||
|
resp = &accountFiee.CreateChatUserResp{
|
||
|
Data: &accountFiee.ChatUserData{},
|
||
|
Msg: "创建成功",
|
||
|
}
|
||
|
var modelData = model.ChatUser{}
|
||
|
if err = copier.CopyWithOption(&modelData, data, utils.CopierProtoOptions); err != nil {
|
||
|
resp.Msg = "数据转换失败"
|
||
|
return
|
||
|
}
|
||
|
err = dao.ChatUserDao.CreateChatUser(&modelData)
|
||
|
if err != nil {
|
||
|
resp.Msg = "创建失败"
|
||
|
return
|
||
|
}
|
||
|
if err = copier.CopyWithOption(resp.Data, &modelData, utils.CopierProtoOptions); err != nil {
|
||
|
resp.Msg = "创建失败."
|
||
|
return
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 删除聊天用户
|
||
|
func (ChatUserLogic) DeleteChatUsers(req *accountFiee.DeleteChatUserRequest) (resp *accountFiee.CommonMsg, err error) {
|
||
|
err = dao.ChatUserDao.DeleteChatUsers(req.Id, req.Ids)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 更新聊天用户
|
||
|
func (ChatUserLogic) UpdateChatUser(data *accountFiee.ChatUserData) (resp *accountFiee.CommonMsg, err error) {
|
||
|
resp = new(accountFiee.CommonMsg)
|
||
|
if data.ID == 0 {
|
||
|
resp.Msg = "ID不能为空"
|
||
|
err = errors.New(resp.Msg)
|
||
|
return
|
||
|
}
|
||
|
var modelData = model.ChatUser{}
|
||
|
if err = copier.CopyWithOption(&modelData, data, utils.CopierProtoOptions); err != nil {
|
||
|
return
|
||
|
}
|
||
|
err = dao.ChatUserDao.UpdateChatUser(&modelData)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 覆盖聊天用户
|
||
|
func (ChatUserLogic) SaveChatUser(data *accountFiee.ChatUserData) (resp *accountFiee.CommonMsg, err error) {
|
||
|
resp = new(accountFiee.CommonMsg)
|
||
|
if data.ID == 0 {
|
||
|
resp.Msg = "ID不能为空"
|
||
|
err = errors.New(resp.Msg)
|
||
|
return
|
||
|
}
|
||
|
var modelData = model.ChatUser{}
|
||
|
if err = copier.CopyWithOption(&modelData, data, utils.CopierProtoOptions); err != nil {
|
||
|
return
|
||
|
}
|
||
|
err = dao.ChatUserDao.SaveChatUser(&modelData)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 使用id查询聊天用户
|
||
|
func (ChatUserLogic) GetChatUserById(req *accountFiee.GetChatUserByIdRequest) (data *accountFiee.ChatUserData, err error) {
|
||
|
data = &accountFiee.ChatUserData{}
|
||
|
modelData, err := dao.ChatUserDao.GetChatUserById(int(req.Id))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err = copier.CopyWithOption(&data, &modelData, utils.CopierProtoOptions); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 批量查询聊天用户
|
||
|
func (ChatUserLogic) GetChatUserList(req *accountFiee.GetChatUserListRequest) (resp *accountFiee.GetChatUserListResp, err error) {
|
||
|
resp = &accountFiee.GetChatUserListResp{
|
||
|
List: []*accountFiee.ChatUserData{},
|
||
|
Page: req.Page,
|
||
|
PageSize: req.PageSize,
|
||
|
}
|
||
|
var data = []model.ChatUser{}
|
||
|
data, resp.Total, err = dao.ChatUserDao.GetChatUserList(req)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
if err = copier.CopyWithOption(&resp.List, &data, utils.CopierProtoOptions); err != nil {
|
||
|
return
|
||
|
}
|
||
|
return
|
||
|
}
|