diff --git a/src/dao/public_platoon_user_relation_dao.go b/src/dao/public_platoon_user_relation_dao.go index 0b3b732..c1eb8f1 100644 --- a/src/dao/public_platoon_user_relation_dao.go +++ b/src/dao/public_platoon_user_relation_dao.go @@ -13,5 +13,7 @@ type PublicPlatoonUserRelationDao interface { PublicPlatoonUserRelationFindByPid(fatherUid int64, fatherName, positionName string) ([]model.PublicPlatoonUserRelation, error) PublicPlatoonUserRelationFindCountByPosition(fatherUid int64, fatherName, positionName string, startPosition, endPosition int64) ([]model.PublicPlatoonUserRelation, int64, error) PublicPlatoonUserRelationFindByParamsByPage(params map[string]interface{}, page, pageSize int) (*[]model.PublicPlatoonUserRelation, error) - PublicPlatoonUserRelationGet(phone int, uid int64, inviteCode string) (mm *[]model.PublicPlatoonUserRelation, err error) + PublicPlatoonUserRelationFind(uid int64) ([]*model.PublicPlatoonUserRelation, error) + PublicPlatoonUserRelationFindByUid(uid int64) ([]*model.PublicPlatoonUserRelation, error) + PublicPlatoonUserRelationGetOneByUid(uid int64) (*model.PublicPlatoonUserRelation, error) } diff --git a/src/dao/user_dao.go b/src/dao/user_dao.go index 96d76af..848b2a5 100644 --- a/src/dao/user_dao.go +++ b/src/dao/user_dao.go @@ -1,5 +1,9 @@ package dao +import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + type UserDao interface { //TODO:: You can add specific method definitions here + UserGetOneByPhone(phone int) (*model.User, error) + UserGetOneById(id int64) (*model.User, error) } diff --git a/src/implement/public_platoon_user_relation_implement.go b/src/implement/public_platoon_user_relation_implement.go index 6e2af74..5e34316 100644 --- a/src/implement/public_platoon_user_relation_implement.go +++ b/src/implement/public_platoon_user_relation_implement.go @@ -120,6 +120,80 @@ func (p PublicPlatoonUserRelationDb) PublicPlatoonUserRelationFindByParamsByPage } } -func (p PublicPlatoonUserRelationDb) agPublicPlatoonUserRelationGet(phone int, uid int64, inviteCode string) (mm *[]model.PublicPlatoonUserRelation, err error) { - return +func (p PublicPlatoonUserRelationDb) PublicPlatoonUserRelationFind(uid int64) ([]*model.PublicPlatoonUserRelation, error) { + var head model.PublicPlatoonUserRelation + if uid != 0 { + has, err1 := p.Db.Where("uid = ?", uid).Get(&head) + if err1 != nil { + return nil, zhios_order_relate_logx.Error(err1) + } + if has == false { + return nil, zhios_order_relate_logx.Error("未查询到数据") + } + } else { + has, err2 := p.Db.Where("level1 = ?", 1).Get(&head) + if err2 != nil { + return nil, err2 + } + if has == false { + return nil, zhios_order_relate_logx.Error("未查询到数据") + } + } + relations, err3 := p.GetTreeBySmall(&head, 3) + if err3 != nil { + return nil, err3 + } + return relations, nil +} + +func (p PublicPlatoonUserRelationDb) PublicPlatoonUserRelationFindByUid(uid int64) ([]*model.PublicPlatoonUserRelation, error) { + var head model.PublicPlatoonUserRelation + has, err1 := p.Db.Where("uid = ?", uid).Get(&head) + if err1 != nil { + return nil, zhios_order_relate_logx.Error(err1) + } + if has == false { + return nil, zhios_order_relate_logx.Error("未查询到数据") + } + relations, err3 := p.GetTreeBySmall(&head, 0) + if err3 != nil { + return nil, err3 + } + return relations, nil +} + +func (p PublicPlatoonUserRelationDb) PublicPlatoonUserRelationGetOneByUid(uid int64) (*model.PublicPlatoonUserRelation, error) { + var parent model.PublicPlatoonUserRelation + has, err := p.Db.Where("uid = ?", uid).Get(&parent) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, zhios_order_relate_logx.Error("未查询到上级用户公排记录") + } + return &parent, nil +} + +func (p PublicPlatoonUserRelationDb) GetTreeBySmall(head *model.PublicPlatoonUserRelation, leveLimit int) ([]*model.PublicPlatoonUserRelation, error) { + if leveLimit == 0 { + leveLimit = 1 + } + var res []*model.PublicPlatoonUserRelation + var queue []*model.PublicPlatoonUserRelation + queue = append(queue, head) + for len(queue) > 0 { + node := queue[0] + queue = queue[1:] + if node.Level1 > head.Level1+leveLimit { + break + } + res = append(res, node) + var son []*model.PublicPlatoonUserRelation + err1 := p.Db.Where("father_uid1 = ?", node.Uid).Find(son) + if err1 != nil { + return nil, zhios_order_relate_logx.Error(err1) + } + res = append(res, son...) + } + return res, nil } diff --git a/src/implement/user_implement.go b/src/implement/user_implement.go index 26de634..be675de 100644 --- a/src/implement/user_implement.go +++ b/src/implement/user_implement.go @@ -2,6 +2,8 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" "xorm.io/xorm" ) @@ -12,3 +14,24 @@ func NewUserDb(engine *xorm.Engine) dao.UserDao { type UserDb struct { Db *xorm.Engine } + +func (p UserDb) UserGetOneByPhone(phone int) (*model.User, error) { + var user *model.User + has, err := p.Db.Where("phone = ?", phone).Get(user) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, zhios_order_relate_logx.Error("未查询到相关用户记录") + } + return user, nil +} + +func (p UserDb) UserGetOneById(id int64) (*model.User, error) { + var user *model.User + _, err := p.Db.Where("phones = ?", id).Get(&user) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + return user, nil +}