package service import ( "fmt" "strings" . "app.yhyue.com/moapp/jybase/common" "bp.jydev.jianyu360.cn/BaseService/userCenter/entity" . "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter" ) func IdentityList(userId int64) []*Identity { result := []*Identity{} list := entity.BaseMysql.SelectBySql(`SELECT DISTINCT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,a.ent_id,b.id as ent_account_id,d.phone from base_user d inner join base_position a on (d.id=? and d.id=a.user_id) left JOIN base_account b on (b.type=1 and b.person_id=0 and a.ent_id=b.ent_id) left JOIN base_account c on (a.account_id=c.id)`, userId) if list != nil { m := map[int64]*Identity{} entIds := []string{} phone := "" for _, v := range *list { i := &Identity{ EntId: Int64All(v["ent_id"]), PersonId: Int64All(v["person_id"]), UserName: ObjToString(v["person_name"]), AccountId: Int64All(v["account_id"]), EntAccountId: Int64All(v["ent_account_id"]), PositionId: Int64All(v["position_id"]), PositionType: Int64All(v["position_type"]), } if i.PositionType == 0 { i.Name = "个人版" m[0] = i } else if i.EntId > 0 { m[i.EntId] = i entIds = append(entIds, fmt.Sprint(i.EntId)) } if phone == "" { phone = ObjToString(v["phone"]) } } if len(entIds) > 0 { ents := entity.Mysql.SelectBySql(`SELECT a.id,a.name,a.ent_id,b.name as ent_name from entniche_user a inner join entniche_info b on (a.phone=? and b.id in (`+strings.Join(entIds, ",")+`) and a.ent_id=b.id) order by b.createtime`, phone) if ents != nil { for _, v := range *ents { i := m[Int64All(v["ent_id"])] i.EntUserId = Int64All(v["id"]) i.EntUserName = ObjToString(v["name"]) i.Name = ObjToString(v["ent_name"]) result = append(result, i) } } } if m[0] != nil { result = append(result, m[0]) } } return result }