Jelajahi Sumber

Merge branch 'master' into feature/v1.2.27

lianbingjie 1 tahun lalu
induk
melakukan
c37ae94f50
2 mengubah file dengan 79 tambahan dan 12 penghapusan
  1. 72 9
      identity/identity.go
  2. 7 3
      identity/identity_test.go

+ 72 - 9
identity/identity.go

@@ -5,6 +5,7 @@ import (
 	"strings"
 
 	. "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/mongodb"
 	. "app.yhyue.com/moapp/jybase/mysql"
 	. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
 )
@@ -85,8 +86,8 @@ func IdentityByUserId(msl *Mysql, userId int64) *Identity {
 //根据职位id获取身份信息
 func IdentityByPositionId(msl *Mysql, positionId int64) *Identity {
 	list := msl.SelectBySql(`SELECT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,a.ent_id,b.phone,b.id as user_id,d.id as ent_account_id from base_service.base_position a
-		inner join base_service.base_user b on (a.user_id=b.id)
-		inner join base_service.base_account c on (a.id=? and a.account_id=c.id)
+		inner join base_service.base_user b on (a.id=? and a.user_id=b.id)
+		inner join base_service.base_account c on (a.account_id=c.id)
 		left join base_service.base_account d on (d.type=1 and d.person_id=0 and d.ent_id<>0 and d.ent_id=a.ent_id) limit 1`, positionId)
 	if list != nil && len(*list) == 1 {
 		identity := &Identity{
@@ -95,6 +96,52 @@ func IdentityByPositionId(msl *Mysql, positionId int64) *Identity {
 			UserName:     ObjToString((*list)[0]["person_name"]),
 			AccountId:    Int64All((*list)[0]["account_id"]),
 			EntAccountId: Int64All((*list)[0]["ent_account_id"]),
+			PositionId:   positionId,
+			PositionType: Int64All((*list)[0]["position_type"]),
+			UserId:       Int64All((*list)[0]["user_id"]),
+		}
+		if identity.PositionType == 0 {
+			identity.Name = "个人版"
+		}
+		phone := ObjToString((*list)[0]["phone"])
+		if identity.EntId > 0 {
+			ents := msl.SelectBySql(`SELECT a.id,a.name,a.ent_id,a.niche_dis,b.name as ent_name,c.role_id,d.dept_id from jianyu.entniche_user a inner join jianyu.entniche_info b on (a.phone=? and b.id=? and a.ent_id=b.id) left join jianyu.entniche_user_role c on (a.id=c.user_id) LEFT JOIN jianyu.entniche_department_user d ON (d.user_id=a.id) limit 1`, phone, identity.EntId)
+			if ents != nil && len(*ents) > 0 {
+				identity.EntUserId = Int64All((*ents)[0]["id"])
+				identity.EntUserName = ObjToString((*ents)[0]["name"])
+				identity.Name = ObjToString((*ents)[0]["ent_name"])
+				identity.EntRole = Int64All((*ents)[0]["role_id"])
+				identity.EntNicheDis = Int64All((*ents)[0]["niche_dis"])
+				identity.EntDeptId = Int64All((*ents)[0]["dept_id"])
+			}
+		}
+		return identity
+	}
+	return nil
+}
+
+//根据账户id获取身份信息
+func IdentityByAccountId(msl *Mysql, accountId int64) *Identity {
+	array := msl.SelectBySql(`SELECT type,person_id,ent_id from base_service.base_account where id=?`, accountId)
+	if array == nil || len(*array) == 0 {
+		return nil
+	} else if Int64All((*array)[0]["type"]) == 1 && Int64All((*array)[0]["person_id"]) == 0 {
+		return &Identity{
+			EntId:        Int64All((*array)[0]["ent_id"]),
+			EntAccountId: Int64All((*array)[0]["id"]),
+		}
+	}
+	list := msl.SelectBySql(`SELECT a.id as position_id,c.person_id,a.person_name,a.type as position_type,a.ent_id,b.phone,b.id as user_id,d.id as ent_account_id from base_service.base_account c
+		inner join base_service.base_user b on (c.id=? AND c.person_id=b.person_id)
+		inner join base_service.base_position a on (a.account_id=c.id)
+		left join base_service.base_account d on (d.type=1 and d.person_id=0 and d.ent_id<>0 and d.ent_id=a.ent_id) limit 1`, accountId)
+	if list != nil && len(*list) == 1 {
+		identity := &Identity{
+			EntId:        Int64All((*list)[0]["ent_id"]),
+			PersonId:     Int64All((*list)[0]["person_id"]),
+			UserName:     ObjToString((*list)[0]["person_name"]),
+			AccountId:    accountId,
+			EntAccountId: Int64All((*list)[0]["ent_account_id"]),
 			PositionId:   Int64All((*list)[0]["position_id"]),
 			PositionType: Int64All((*list)[0]["position_type"]),
 			UserId:       Int64All((*list)[0]["user_id"]),
@@ -120,16 +167,31 @@ func IdentityByPositionId(msl *Mysql, positionId int64) *Identity {
 }
 
 //根据企业员工id获取身份信息
-func IdentityByEntUserId(msl *Mysql, entUserId int64) *Identity {
+func IdentityByEntUserId(msl *Mysql, mgo *MongodbSim, entUserId int64) *Identity {
 	ents := msl.SelectBySql(`SELECT a.id,a.name,a.phone,a.ent_id,a.niche_dis,b.name as ent_name,c.role_id,d.dept_id  from jianyu.entniche_user a inner join jianyu.entniche_info b on (a.id=? and a.ent_id=b.id) left join jianyu.entniche_user_role c on (a.id=c.user_id) LEFT JOIN jianyu.entniche_department_user d ON (d.user_id=a.id) limit 1`, entUserId)
 	if ents == nil || len(*ents) == 0 {
 		return nil
 	}
-	if entId := Int64All((*ents)[0]["ent_id"]); entId > 0 {
-		list := msl.SelectBySql(`SELECT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,d.id as user_id,b.id as ent_account_id from base_service.base_user d
-		inner join base_service.base_position a on (d.phone=? and a.ent_id=? and a.type=1 and d.id=a.user_id)
-		inner join base_service.base_account c on (c.ent_id=? and c.type=1 and a.account_id=c.id)
-		inner join base_service.base_account b on (b.type=1 and b.person_id=0 and b.ent_id=?) order by a.id desc limit 1`, ObjToString((*ents)[0]["phone"]), entId, entId, entId)
+	if entId, phone := Int64All((*ents)[0]["ent_id"]), ObjToString((*ents)[0]["phone"]); entId > 0 && phone != "" {
+		users, ok := mgo.Find("user", map[string]interface{}{
+			"$or": []map[string]interface{}{
+				map[string]interface{}{
+					"s_phone": phone,
+				},
+				map[string]interface{}{
+					"s_m_phone": phone,
+				},
+			},
+		}, `{"s_phone":-1}`, map[string]interface{}{
+			"base_user_id": 1,
+		}, false, 0, 1)
+		if !ok || users == nil {
+			return nil
+		}
+		userId := Int64All((*users)[0]["base_user_id"])
+		list := msl.SelectBySql(`SELECT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,b.id as ent_account_id from base_service.base_position a
+		inner join base_service.base_account c on (a.user_id=? and a.ent_id=? and a.type=1 and c.ent_id=? and c.type=1 and a.account_id=c.id)
+		inner join base_service.base_account b on (b.type=1 and b.person_id=0 and b.ent_id=?) order by a.id desc limit 1`, userId, entId, entId, entId)
 		if list != nil && len(*list) > 0 {
 			identity := &Identity{
 				PersonId:     Int64All((*list)[0]["person_id"]),
@@ -138,7 +200,7 @@ func IdentityByEntUserId(msl *Mysql, entUserId int64) *Identity {
 				EntAccountId: Int64All((*list)[0]["ent_account_id"]),
 				PositionId:   Int64All((*list)[0]["position_id"]),
 				PositionType: Int64All((*list)[0]["position_type"]),
-				UserId:       Int64All((*list)[0]["user_id"]),
+				UserId:       userId,
 				EntId:        entId,
 				EntUserId:    Int64All((*ents)[0]["id"]),
 				EntUserName:  ObjToString((*ents)[0]["name"]),
@@ -160,6 +222,7 @@ func IdentityByEntId(msl *Mysql, entId int64) *Identity {
 		return nil
 	}
 	return &Identity{
+		EntId:        entId,
 		EntAccountId: Int64All((*list)[0]["id"]),
 	}
 }

+ 7 - 3
identity/identity_test.go

@@ -10,7 +10,7 @@ import (
 var msl *Mysql
 
 func init() {
-	msl = &mysql.Mysql{
+	msl = &Mysql{
 		Address:      "192.168.3.217:4000",
 		UserName:     "root",
 		PassWord:     "=PDT49#80Z!RVv52_z",
@@ -18,7 +18,7 @@ func init() {
 		MaxOpenConns: 5,
 		MaxIdleConns: 5,
 	}
-	entity.BaseMysql.Init()
+	msl.Init()
 	log.Println("初始化 base mysql")
 }
 func Test_IdentityList(t *testing.T) {
@@ -35,6 +35,10 @@ func Test_IdentityByPositionId(t *testing.T) {
 	log.Println(IdentityByPositionId(msl, 945))
 }
 
+func Test_IdentityByAccountId(t *testing.T) {
+	log.Println(IdentityByAccountId(msl, 13496))
+}
+
 func Test_IdentityByEntUserId(t *testing.T) {
-	log.Println(IdentityByEntUserId(msl, 4271))
+	log.Println(IdentityByEntUserId(msl, nil, 4271))
 }