瀏覽代碼

feat:增加方法

wangchuanjin 1 年之前
父節點
當前提交
279dbf2a4c
共有 2 個文件被更改,包括 57 次插入6 次删除
  1. 50 3
      identity/identity.go
  2. 7 3
      identity/identity_test.go

+ 50 - 3
identity/identity.go

@@ -86,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{
@@ -96,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"]),
@@ -127,7 +173,7 @@ func IdentityByEntUserId(msl *Mysql, mgo *MongodbSim, entUserId int64) *Identity
 		return nil
 	}
 	if entId, phone := Int64All((*ents)[0]["ent_id"]), ObjToString((*ents)[0]["phone"]); entId > 0 && phone != "" {
-		users, ok := mgo.Find(Mgo_User, map[string]interface{}{
+		users, ok := mgo.Find("user", map[string]interface{}{
 			"$or": []map[string]interface{}{
 				map[string]interface{}{
 					"s_phone": phone,
@@ -176,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))
 }