作者 yangfu

重构 去掉repository

... ... @@ -4,20 +4,20 @@ import "sync"
//全局
var (
once sync.Once
User IUserRepository
UserAuth IUserAuthRepository
Commend ICommendRepository
Company ICompanyRepository
Department IDepartmentRepository
Position IPositionRepository
Chance IChanceRepository
ChanceFavorite IChanceFavoriteRepository
Comment ICommentRepository
Message IMessageRepository
UserCompany IUserCompanyRepository
UserPosition IUserPositionRepository
UserDepartment IUserDepartmentRepository
once sync.Once
//User IUserRepository
//UserAuth IUserAuthRepository
//Commend ICommendRepository
//Company ICompanyRepository
//Department IDepartmentRepository
//Position IPositionRepository
//Chance IChanceRepository
//ChanceFavorite IChanceFavoriteRepository
//Comment ICommentRepository
//Message IMessageRepository
//UserCompany IUserCompanyRepository
//UserPosition IUserPositionRepository
//UserDepartment IUserDepartmentRepository
)
func init() {
... ... @@ -25,24 +25,24 @@ func init() {
}
func InitRepository() {
User = &UserRepository{}
UserAuth = &UserAuthRepository{}
Commend = &CommendRepository{}
Company = &CompanyRepository{}
Department = &DepartmentRepository{}
Position = &PositionRepository{}
Chance = &ChanceRepository{}
Comment = &CommentRepository{}
Message = &MessageRepository{}
ChanceFavorite = &ChanceFavoriteRepository{}
UserCompany = &UserCompanyRepository{}
UserPosition = &UserPositionRepository{}
UserDepartment = &UserDepartmentRepository{}
//User = &UserRepository{}
//UserAuth = &UserAuthRepository{}
//Commend = &CommendRepository{}
//Company = &CompanyRepository{}
//Department = &DepartmentRepository{}
//Position = &PositionRepository{}
//Chance = &ChanceRepository{}
//Comment = &CommentRepository{}
//Message = &MessageRepository{}
//ChanceFavorite = &ChanceFavoriteRepository{}
//UserCompany = &UserCompanyRepository{}
//UserPosition = &UserPositionRepository{}
//UserDepartment = &UserDepartmentRepository{}
}
func InitRepositoryMock() {
once.Do(func() {
User = &UserMockRepository{}
UserAuth = &UserAuthMockRepository{}
//User = &UserMockRepository{}
//UserAuth = &UserAuthMockRepository{}
})
}
... ...
... ... @@ -2,36 +2,41 @@ package protocol
import "opp/models"
//机会审核
//审核对象
const (
MarkFlag_Zan = 1
MarkFlag_Collect = 2
AuditByDepartmentor = iota + 1 //部门长
AuditByUser //指定用户
AuditByRole //指定角色
AuditBySpecailUser //特殊人员
)
//审核类型
const (
UnMarkFlag = 0
MarkFlag = 1 //是否标记 /点赞 /收藏
FlowTypeNormal = iota + 1 //正常审核流程
FlowTypeSpecail //特殊审核流程
)
//审核人为空
const (
AuditFlowType_Departmentor = iota + 1 //部门长
AuditFlowType_User //指定用户
AuditFlowType_Role //指定角色
AuditFlowType_SpecailUser //特殊人员
NoApproverPass = 1 //自动通过
NoApproverToAdmin = 2 //转交给公司管理员
)
//机会
//审核状态
const (
FlowType_Normal = iota + 1
FlowType_Specail
ReviewStatusWait = 0 //待处理
ReviewStatusAuditging = 1 //待审核
ReviewStatusReturn = 2 //退回
ReviewStatusPass = 3 //通过
)
//公开状态
const (
NoApprover_Pass = 1
NoApprover_ToAdmin = 2
)
const (
StaticType_Question = 1 << iota
StaticType_Question2
NoPublic = 0 //未公开
PublicToDepartment = 1 //部门公开
PublicToCompany = 2 //公司公开
)
/*Favorite */
... ...
package protocol
/*
全局变量声明
*/
//机会点赞收藏
const (
MarkFlagZan = 1 //点赞标记
MarkFlagCollect = 2 //收藏标记
)
//标记状态
const (
UnMarkFlag = 0 //取消标记
MarkFlag = 1 //标记 /点赞 /收藏
)
//有效状态
const (
InValid = 0 //无效
Valid = 1 //有效
)
... ...
... ... @@ -29,7 +29,7 @@ func init() {
beego.AddNamespace(nsH5)
beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
beego.SetStaticPath("/log/opp", beego.AppConfig.String("aliyun_logs_access"))
beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access"))
beego.Handler("/metrics", promhttp.Handler())
beego.Handler("/upgrage", http.HandlerFunc(websocket.Upgrage))
}
... ...
... ... @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/internal/utils"
"opp/models"
"opp/protocol"
... ... @@ -139,7 +138,7 @@ func GetChance(chanceId int64, companyId int64) (v *protocol.ChanceDetail, err e
baseUserInfo *protocol.BaseUserInfo
)
if c, err = repository.Chance.GetChanceById(chanceId); err != nil {
if c, err = models.GetChanceById(chanceId); err != nil {
return
}
if baseUserInfo, err = GetUserBaseInfo(c.UserId, companyId); err != nil {
... ...
... ... @@ -13,7 +13,6 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
"opp/internal/repository"
"opp/models"
"opp/protocol"
s_sms "opp/services/sms"
... ... @@ -89,14 +88,14 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp
Success:
{
userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id, 1)
userAuth, err = models.GetUserAuthByUserId(user.Id, 1)
if err != nil {
if err == orm.ErrNoRows {
userAuth = &models.UserAuth{
UserId: user.Id,
DeviceType: 1, //int8(header.DeviceType),
}
repository.UserAuth.AddUserAuth(userAuth)
models.AddUserAuth(userAuth)
} else {
log.Error(err)
return
... ... @@ -111,12 +110,12 @@ Success:
user.NickName = getUserResponse.NickName
user.Accid = getUserResponse.Accid
user.UserCenterId = getUserResponse.Id
if err = repository.User.UpdateUserInfo(user); err != nil {
if err = models.UpdateUsersById(user); err != nil {
log.Error(err)
return
}
userAuth.AuthCodeExp = time.Now().Add(time.Second * protocol.TokenExpire)
if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil {
if err = models.UpdateUserAuthById(userAuth); err != nil {
return
}
rsp = &protocol.LoginResponse{AuthCode: userAuth.AuthCode}
... ... @@ -179,7 +178,7 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice
userAuth *models.UserAuth
updateMap = make(map[string]interface{})
)
if userAuth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
if userAuth, err = models.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
log.Error(err)
return
}
... ... @@ -204,7 +203,7 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke
// err = protocol.NewErrWithMessage(101, err)
// return
//}
userAuth, err = repository.UserAuth.GetUserAuthByAuthCode(request.AuthCode)
userAuth, err = models.GetUserByAuthCode(request.AuthCode)
if err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(4139, err)
... ... @@ -214,7 +213,7 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke
userAuth.RefreshToken = uid.NewV1().StringNoDash()
userAuth.AccessTokenExp = time.Now().Add(protocol.TokenExpire * time.Second)
userAuth.RefreshTokenExp = time.Now().Add(protocol.TokenExpire * time.Second)
if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil {
if err = models.UpdateUserAuthById(userAuth); err != nil {
log.Error(err)
return
}
... ... @@ -237,13 +236,13 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT
// protocol.NewErrWithMessage(101, err)
// return
//}
userAuth, err = repository.UserAuth.GetUserAuthByRefreshToken(request.RefreshToken)
userAuth, err = models.GetUserAuthByRefreshToken(request.RefreshToken)
if err != nil {
protocol.NewErrWithMessage(4139, err)
return
}
userAuth.AccessToken = uid.NewV1().StringNoDash()
if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil {
if err = models.UpdateUserAuthById(userAuth); err != nil {
return
}
rsp = &protocol.RefreshTokenResponse{
... ... @@ -263,7 +262,7 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
err = common.NewErrorWithMsg(4141, "token not empty")
return
}
userAuth, err = repository.UserAuth.GetUserAuthByToken(request.Token)
userAuth, err = models.GetUserAuthByToken(request.Token)
if err != nil {
log.Error("查询失败: token:", request.Token, err)
err = protocol.NewErrWithMessage(4141, err)
... ... @@ -433,7 +432,7 @@ func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rs
updateMap = make(map[string]interface{})
)
//rsp =&protocol.RevokeResponse{}
if userAuth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
if userAuth, err = models.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
log.Error(err)
return
}
... ...
package auth
import (
"opp/internal/repository"
"testing"
"opp/protocol"
... ... @@ -10,7 +9,7 @@ import (
func init() {
tests.Init()
repository.InitRepositoryMock()
//repository.InitRepositoryMock()
}
func Test_SmsCode(t *testing.T) {
... ...
... ... @@ -7,7 +7,6 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/internal/utils"
"opp/models"
"opp/protocol"
... ... @@ -22,7 +21,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest)
chance *protocol.ChanceDetail
)
rsp = &protocol.FavoriteResponse{}
favorites, rsp.Total, err = repository.ChanceFavorite.GetChanceFavorites(
favorites, rsp.Total, err = models.GetChanceFavorites(
header.Uid,
header.CompanyId,
request.ObjectType,
... ... @@ -46,8 +45,8 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest)
log.Error(err)
return
}
chance.IsZan = (f.MarkFlag & protocol.MarkFlag_Zan) == protocol.MarkFlag_Zan
chance.IsCollect = (f.MarkFlag & protocol.MarkFlag_Collect) == protocol.MarkFlag_Collect
chance.IsZan = (f.MarkFlag & protocol.MarkFlagZan) == protocol.MarkFlagZan
chance.IsCollect = (f.MarkFlag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect
item.Favorite = chance
case protocol.SourceTypeComment:
}
... ... @@ -67,12 +66,12 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
table string = "comment"
)
rsp = &protocol.SympathyActionResponse{}
if chanceFavoirte, err = repository.ChanceFavorite.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
if chanceFavoirte, err = models.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
log.Error(err)
return
}
if request.SourceType == protocol.SourceTypeChance {
if chance, err = repository.Chance.GetChanceById(request.Id); err != nil {
if chance, err = models.GetChanceById(request.Id); err != nil {
log.Error("机会不存在", err)
return
}
... ... @@ -81,28 +80,28 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
}
if chanceFavoirte != nil {
exists = true
if request.MarkType == protocol.MarkFlag_Zan {
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) == 0 {
if request.MarkType == protocol.MarkFlagZan {
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlagZan) == 0 {
err = protocol.NewSuccessWithMessage("已经取消赞,不能重复取消赞")
return
}
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) > 0 {
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlagZan) > 0 {
err = protocol.NewSuccessWithMessage("已经赞,不能重复点赞")
return
}
} else if request.MarkType == protocol.MarkFlag_Collect {
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) == 0 {
} else if request.MarkType == protocol.MarkFlagCollect {
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlagCollect) == 0 {
err = protocol.NewSuccessWithMessage("已经取消收藏,不能重复取消收藏")
return
}
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) > 0 {
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlagCollect) > 0 {
err = protocol.NewSuccessWithMessage("已经收藏,不能重复收藏")
return
}
}
}
if exists {
if err = repository.ChanceFavorite.UpdateChanceFavorite(header.Uid, header.CompanyId, request.Id, 1<<(uint(request.MarkType-1))); err != nil {
if err = models.UpdateChanceFavorite(header.Uid, header.CompanyId, request.Id, 1<<(uint(request.MarkType-1))); err != nil {
log.Error(request.MarkType, err)
return
}
... ... @@ -120,7 +119,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
CreateAt: time.Now(),
EnableStatus: 1,
}
if _, err = repository.ChanceFavorite.AddChanceFavorite(chanceFavoirte); err != nil {
if _, err = models.AddChanceFavorite(chanceFavoirte); err != nil {
log.Error(err)
return
} else {
... ... @@ -129,7 +128,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
}
END:
{
if request.MarkType != protocol.MarkFlag_Zan {
if request.MarkType != protocol.MarkFlagZan {
return
}
if request.SympathyType == protocol.UnMarkFlag {
... ... @@ -394,7 +393,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
//1.检查是否是特殊审核人
for i := range configs {
config := configs[i]
if groupId == 0 && config.FlowType == protocol.FlowType_Normal {
if groupId == 0 && config.FlowType == protocol.FlowTypeNormal {
groupId = config.AuditGroupId
continue
}
... ... @@ -428,7 +427,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
return
}
if company, err = repository.Company.GetCompanyById(header.CompanyId); err != nil {
if company, err = models.GetCompanyById(header.CompanyId); err != nil {
log.Error(err)
return
}
... ... @@ -443,17 +442,17 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
config := configs[i]
var userIds []int64
switch config.AuditFlowType {
case protocol.AuditFlowType_Departmentor:
case protocol.AuditByDepartmentor:
if userIds, err = getDepartmentors(header); err != nil {
log.Error(err)
return
}
case protocol.AuditFlowType_User:
case protocol.AuditByUser:
if err = json.Unmarshal([]byte(config.ToUser), &userIds); err != nil {
log.Error(err)
return
}
case protocol.AuditFlowType_Role:
case protocol.AuditByRole:
}
if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
... ... @@ -461,7 +460,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
}
for j := 0; j < len(userIds); j++ {
uid := userIds[j]
if uid == 0 && auditConfig.NoApprover == protocol.NoApprover_ToAdmin { //审批人为空 转交给管理员
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
uid = company.AdminId
}
if uid == header.Uid { //审核人自己 转交给管理员
... ... @@ -508,7 +507,7 @@ func getDepartmentors(header *protocol.RequestHeader) (ids []int64, err error) {
var (
departments []*protocol.Department
)
if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &departments); err != nil {
if err = models.GetUserDepartments(header.Uid, header.CompanyId, &departments); err != nil {
log.Error(err)
return
}
... ... @@ -543,7 +542,7 @@ func getParentDepartmentors(pid int) (ids []int64) {
if department.ParentId == 0 {
return
}
if department, err = repository.Department.GetDepartmentById(pid); err != nil {
if department, err = models.GetDepartmentById(pid); err != nil {
log.Error(err)
return
}
... ...
... ... @@ -4,7 +4,6 @@ import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/internal/utils"
"opp/models"
"opp/protocol"
... ... @@ -23,14 +22,14 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
)
switch request.SourceType {
case protocol.SourceTypeChance:
if chance, err = repository.Chance.GetChanceById(request.Id); err != nil {
if chance, err = models.GetChanceById(request.Id); err != nil {
log.Error(err)
return
}
updateTable = chance
updateMap["CommentTotal"] = chance.CommentTotal + 1
case protocol.SourceTypeComment:
if comment, err = repository.Comment.GetCommentById(request.Id); err != nil {
if comment, err = models.GetCommentById(request.Id); err != nil {
log.Error(err)
return
}
... ... @@ -47,7 +46,7 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
CreateAt: time.Now(),
SourceId: request.Id,
}
if _, err = repository.Comment.AddComment(newComment); err != nil {
if _, err = models.AddComment(newComment); err != nil {
log.Error(err)
return
}
... ... @@ -74,7 +73,7 @@ func IComments(header *protocol.RequestHeader, request *protocol.ICommentsReques
baseUserInfo *protocol.BaseUserInfo
total int
)
if comments, total, err = repository.Comment.GetComments(header.UserId, protocol.SourceTypeChance, 0, request.LastId, request.PageSize); err != nil {
if comments, total, err = models.GetComments(header.UserId, protocol.SourceTypeChance, 0, request.LastId, request.PageSize); err != nil {
log.Error(err)
return
}
... ... @@ -112,7 +111,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
total int
exists bool
)
if comments, total, err = repository.Comment.GetComments(header.UserId, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
if comments, total, err = models.GetComments(header.UserId, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
log.Error(err)
return
}
... ... @@ -134,7 +133,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
ZanTotal: comment.ZanTotal,
CommentTotal: comment.CommentTotal,
}
if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlag_Zan); exists {
if exists, _ = models.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlagZan); exists {
item.IsZan = 1
}
rsp.Comments = append(rsp.Comments, item)
... ... @@ -150,7 +149,7 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm
exists bool
)
rsp = &protocol.CommentDetailsSingleResponse{}
if comment, err = repository.Comment.GetCommentById(request.Id); err != nil {
if comment, err = models.GetCommentById(request.Id); err != nil {
log.Error(err)
return
}
... ... @@ -167,7 +166,7 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm
ZanTotal: comment.ZanTotal,
CommentTotal: comment.CommentTotal,
}
if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlag_Zan); exists {
if exists, _ = models.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlagZan); exists {
rsp.Comment.IsZan = 1
}
return
... ...
... ... @@ -2,7 +2,6 @@ package commend
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
"opp/internal/repository"
"opp/models"
"opp/protocol"
"opp/services/agg"
... ... @@ -15,11 +14,11 @@ func Commend(header *protocol.RequestHeader, request *protocol.CommendRequest) (
commends []*models.Commend
)
rsp = &protocol.CommendResponse{}
user, err = repository.User.GetUsersById(header.Uid)
user, err = models.GetUsersById(header.Uid)
if err != nil {
return
}
if commends, rsp.Total, err = repository.Commend.GetCommends(header.CompanyId, request.LastId, request.PageSize); err != nil {
if commends, rsp.Total, err = models.GetCommends(header.CompanyId, request.LastId, request.PageSize); err != nil {
return
}
for i := 0; i < len(commends); i++ {
... ...
... ... @@ -3,7 +3,6 @@ package department
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/models"
"opp/protocol"
)
... ... @@ -16,7 +15,7 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
rsp = &protocol.DepartmentsResponse{}
switch request.Type {
case protocol.DepartmentAll:
if departments, err = repository.Department.GetDepartmentByCompanyId(header.CompanyId); err != nil {
if departments, err = models.GetDepartmentByCompanyId(header.CompanyId); err != nil {
log.Error(err)
return
}
... ...
... ... @@ -7,7 +7,6 @@ import (
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/internal/utils"
"opp/models"
"opp/protocol"
... ... @@ -17,7 +16,7 @@ import (
func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) {
var ()
rsp = &protocol.MessageCenterResponse{}
err = repository.Message.GetUserMsgTotals(header.Uid, header.CompanyId, request.MsgType, &rsp.Totals)
err = models.GetUserMsgTotals(header.Uid, header.CompanyId, request.MsgType, &rsp.Totals)
return
}
... ... @@ -25,7 +24,7 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent
func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterReadRequest) (rsp *protocol.MsgCenterReadResponse, err error) {
var ()
//rsp =&protocol.MsgCenterReadResponse{}
err = repository.Message.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, request.MsgId)
err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, request.MsgId)
if err != nil {
log.Error(err)
}
... ... @@ -35,7 +34,7 @@ func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterRe
//标记全部已读
func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCenterAllReadRequest) (rsp *protocol.MsgCenterAllReadResponse, err error) {
var ()
err = repository.Message.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, 0)
err = models.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, 0)
if err != nil {
log.Error(err)
}
... ... @@ -48,7 +47,7 @@ func MsgInteractive(header *protocol.RequestHeader, request *protocol.MsgInterac
userMsgs []*models.UserMsg
)
rsp = &protocol.MsgInteractiveResponse{}
userMsgs, rsp.Total, err = repository.Message.GetUserMsgs(header.Uid, header.CompanyId, request.MsgType, request.SourceType, request.LastId, request.PageSize)
userMsgs, rsp.Total, err = models.GetUserMsgs(header.Uid, header.CompanyId, request.MsgType, request.SourceType, request.LastId, request.PageSize)
if err != nil {
log.Error(err)
return
... ...
... ... @@ -5,7 +5,6 @@ import (
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"net/http"
"opp/internal/repository"
"opp/internal/utils"
"opp/models"
"opp/protocol"
... ... @@ -22,7 +21,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode
)
//rsp =&protocol.CheckSmsCodeResponse{}
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
if user, err = models.GetUsersById(header.Uid); err != nil {
log.Error(err)
return
}
... ... @@ -42,7 +41,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
user *models.User
result bool
)
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
if user, err = models.GetUsersById(header.Uid); err != nil {
log.Error(err)
return
}
... ... @@ -93,7 +92,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
err = protocol.NewErrWithMessage(2027)
return
}
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
if user, err = models.GetUsersById(header.Uid); err != nil {
log.Error(err)
return
}
... ... @@ -144,7 +143,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
err = protocol.NewErrWithMessage(2027)
return
}
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
if user, err = models.GetUsersById(header.Uid); err != nil {
log.Error(err)
return
}
... ... @@ -203,12 +202,12 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
userCompany *models.UserCompany
auth *models.UserAuth
)
if userCompany, err = repository.UserCompany.GetUserCompanyByUserId(header.Uid, int64(request.CompanyId)); err != nil {
if userCompany, err = models.GetUserCompanyByUserId(header.Uid, int64(request.CompanyId)); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(4201) //找不到这家公司
return
}
if auth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, protocol.DeviceType); err != nil {
if auth, err = models.GetUserAuthByUserId(header.Uid, protocol.DeviceType); err != nil {
log.Error(err)
return
}
... ... @@ -233,17 +232,35 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
//用户信息
func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
var (
companyId = header.CompanyId
companyId int64
userCompany *models.UserCompany
userAuth *models.UserAuth
userBaseAgg *protocol.UserBaseInfoAggregation
companys []*models.Company
)
if userCompany, err = models.GetUserCompanys(header.Uid); err != nil {
if companys, err = models.GetCompanyByPermission(header.Uid); err != nil {
log.Error(err)
return
}
//保证用户登录期间公司有权限
if len(companys) == 0 {
//无权限
err = protocol.NewErrWithMessage(2002)
return
}
for i := range companys {
if companys[i].Id == header.CompanyId {
companyId = header.CompanyId
break
}
}
if companyId == 0 {
if userCompany, err = models.GetUserCompanys(header.Uid); err != nil {
log.Error(err)
return
}
if userAuth, err = models.GetUserAuthByUserId(header.Uid, protocol.DeviceType); err != nil {
log.Error(err)
return
... ... @@ -256,10 +273,6 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
companyId = int64(userCompany.CompanyId)
header.UserId = userCompany.Id
}
if companys, err = models.GetCompanyByPermission(header.Uid); err != nil {
log.Error(err)
return
}
if userBaseAgg, err = agg.GetUserBaseInfoAggregation(header.UserId, companyId); err != nil {
return
}
... ...