wangchuanjin 1 рік тому
батько
коміт
3f53bd110d

+ 25 - 25
service/identity.go → identity/identity.go

@@ -5,17 +5,17 @@ import (
 	"strings"
 
 	. "app.yhyue.com/moapp/jybase/common"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "app.yhyue.com/moapp/jybase/mysql"
 	. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
 )
 
 //获取用户可切换的身份列表
-func IdentityList(userId int64) []*Identity {
+func IdentityList(msl *Mysql, 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)
-		inner join base_account c on (a.account_id=c.id)
-    	left join base_account b on (b.type=1 and b.person_id=0 and b.ent_id<>0 and c.ent_id=b.ent_id) order by a.id desc`, userId)
+	list := msl.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_service.base_user d
+		inner join base_service.base_position a on (d.id=? and d.id=a.user_id)
+		inner join base_service.base_account c on (a.account_id=c.id)
+    	left join base_service.base_account b on (b.type=1 and b.person_id=0 and b.ent_id<>0 and c.ent_id=b.ent_id) order by a.id desc`, userId)
 	if list != nil {
 		m := map[int64]*Identity{}
 		entIds := []string{}
@@ -43,7 +43,7 @@ func IdentityList(userId int64) []*Identity {
 			}
 		}
 		if len(entIds) > 0 {
-			ents := entity.Mysql.SelectBySql(`SELECT a.id,a.name,a.ent_id,a.niche_dis,b.name as ent_name,c.role_id,d.dept_id 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) left join entniche_user_role c on (a.id=c.user_id) LEFT JOIN entniche_department_user d ON(d.user_id =a.id ) order by b.createtime`, phone)
+			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 in (`+strings.Join(entIds, ",")+`) 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) order by b.createtime`, phone)
 			if ents != nil {
 				for _, v := range *ents {
 					i := m[Int64All(v["ent_id"])]
@@ -65,10 +65,10 @@ func IdentityList(userId int64) []*Identity {
 }
 
 //根据账号id获取个人身份信息
-func IdentityByUserId(userId int64) *Identity {
-	list := entity.BaseMysql.SelectBySql(`SELECT a.account_id,a.id as position_id,c.person_id,a.person_name,a.type as position_type from base_user d
-		inner join base_position a on (d.id=? and a.type=0 and d.id=a.user_id)
-		inner join base_account c on (c.type=0 and a.account_id=c.id) order by a.id desc limit 1`, userId)
+func IdentityByUserId(msl *Mysql, userId int64) *Identity {
+	list := msl.SelectBySql(`SELECT a.account_id,a.id as position_id,c.person_id,a.person_name,a.type as position_type from base_service.base_user d
+		inner join base_service.base_position a on (d.id=? and a.type=0 and d.id=a.user_id)
+		inner join base_service.base_account c on (c.type=0 and a.account_id=c.id) order by a.id desc limit 1`, userId)
 	if list != nil && len(*list) > 0 {
 		return &Identity{
 			PersonId:     Int64All((*list)[0]["person_id"]),
@@ -83,11 +83,11 @@ func IdentityByUserId(userId int64) *Identity {
 }
 
 //根据职位id获取身份信息
-func IdentityByPositionId(positionId int64) *Identity {
-	list := entity.BaseMysql.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_position a
-		inner join base_user b on (a.user_id=b.id)
-		inner join base_account c on (a.id=? and a.account_id=c.id)
-		left join 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)
+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)
+		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{
 			EntId:        Int64All((*list)[0]["ent_id"]),
@@ -104,7 +104,7 @@ func IdentityByPositionId(positionId int64) *Identity {
 		}
 		phone := ObjToString((*list)[0]["phone"])
 		if identity.EntId > 0 {
-			ents := entity.Mysql.SelectBySql(`SELECT a.id,a.name,a.ent_id,a.niche_dis,b.name as ent_name,c.role_id,d.dept_id from entniche_user a inner join entniche_info b on (a.phone=? and b.id=? and a.ent_id=b.id) left join entniche_user_role c on (a.id=c.user_id) LEFT JOIN entniche_department_user d ON(d.user_id =a.id ) limit 1`, phone, identity.EntId)
+			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"])
@@ -120,16 +120,16 @@ func IdentityByPositionId(positionId int64) *Identity {
 }
 
 //根据企业员工id获取身份信息
-func IdentityByEntUserId(entUserId int64) *Identity {
-	ents := entity.Mysql.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 entniche_user a inner join entniche_info b on (a.id=? and a.ent_id=b.id) left join entniche_user_role c on (a.id=c.user_id) LEFT JOIN entniche_department_user d ON(d.user_id =a.id ) limit 1`, entUserId)
+func IdentityByEntUserId(msl *Mysql, 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 := entity.BaseMysql.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_user d
-		inner join base_position a on (d.phone=? and a.ent_id=? and a.type=1 and d.id=a.user_id)
-		inner join base_account c on (c.ent_id=? and c.type=1 and a.account_id=c.id)
-		inner join 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)
+		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 list != nil && len(*list) > 0 {
 			identity := &Identity{
 				PersonId:     Int64All((*list)[0]["person_id"]),
@@ -154,8 +154,8 @@ func IdentityByEntUserId(entUserId int64) *Identity {
 }
 
 //根据企业id获取身份信息
-func IdentityByEntId(entId int64) *Identity {
-	list := entity.BaseMysql.SelectBySql(`select id from base_account where ent_id=? and type=1 and person_id=0 limit 1`, entId)
+func IdentityByEntId(msl *Mysql, entId int64) *Identity {
+	list := msl.SelectBySql(`select id from base_service.base_account where ent_id=? and type=1 and person_id=0 limit 1`, entId)
 	if list == nil || len(*list) == 0 {
 		return nil
 	}

+ 40 - 0
identity/identity_test.go

@@ -0,0 +1,40 @@
+package service
+
+import (
+	"log"
+	"testing"
+
+	. "app.yhyue.com/moapp/jybase/mysql"
+)
+
+var msl *Mysql
+
+func init() {
+	msl = &mysql.Mysql{
+		Address:      "192.168.3.217:4000",
+		UserName:     "root",
+		PassWord:     "=PDT49#80Z!RVv52_z",
+		DBName:       "base_service",
+		MaxOpenConns: 5,
+		MaxIdleConns: 5,
+	}
+	entity.BaseMysql.Init()
+	log.Println("初始化 base mysql")
+}
+func Test_IdentityList(t *testing.T) {
+	for _, v := range IdentityList(msl, 185509) {
+		log.Println(v)
+	}
+}
+
+func Test_IdentityByUserId(t *testing.T) {
+	log.Println(IdentityByUserId(msl, 68773))
+}
+
+func Test_IdentityByPositionId(t *testing.T) {
+	log.Println(IdentityByPositionId(msl, 945))
+}
+
+func Test_IdentityByEntUserId(t *testing.T) {
+	log.Println(IdentityByEntUserId(msl, 4271))
+}

+ 3 - 2
rpc/internal/logic/identitybyentidlogic.go

@@ -3,9 +3,10 @@ package logic
 import (
 	"context"
 
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/service"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -25,5 +26,5 @@ func NewIdentityByEntIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *I
 
 // 根据企业id获取身份信息
 func (l *IdentityByEntIdLogic) IdentityByEntId(in *pb.IdentityReq) (*pb.Identity, error) {
-	return service.IdentityByEntId(in.Id), nil
+	return IdentityByEntId(entity.BaseMysql, in.Id), nil
 }

+ 3 - 2
rpc/internal/logic/identitybyentuseridlogic.go

@@ -3,9 +3,10 @@ package logic
 import (
 	"context"
 
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/service"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -25,5 +26,5 @@ func NewIdentityByEntUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext
 
 // 根据企业员工id获取身份信息
 func (l *IdentityByEntUserIdLogic) IdentityByEntUserId(in *pb.IdentityReq) (*pb.Identity, error) {
-	return service.IdentityByEntUserId(in.Id), nil
+	return IdentityByEntUserId(entity.BaseMysql, in.Id), nil
 }

+ 3 - 2
rpc/internal/logic/identitybypositionidlogic.go

@@ -3,9 +3,10 @@ package logic
 import (
 	"context"
 
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/service"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -25,5 +26,5 @@ func NewIdentityByPositionIdLogic(ctx context.Context, svcCtx *svc.ServiceContex
 
 // 根据职位id获取身份信息
 func (l *IdentityByPositionIdLogic) IdentityByPositionId(in *pb.IdentityReq) (*pb.Identity, error) {
-	return service.IdentityByPositionId(in.Id), nil
+	return IdentityByPositionId(entity.BaseMysql, in.Id), nil
 }

+ 3 - 2
rpc/internal/logic/identitybyuseridlogic.go

@@ -3,9 +3,10 @@ package logic
 import (
 	"context"
 
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/service"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -25,5 +26,5 @@ func NewIdentityByUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 
 // 获取账号id获取个人身份信息
 func (l *IdentityByUserIdLogic) IdentityByUserId(in *pb.IdentityReq) (*pb.Identity, error) {
-	return service.IdentityByUserId(in.Id), nil
+	return IdentityByUserId(entity.BaseMysql, in.Id), nil
 }

+ 3 - 2
rpc/internal/logic/identitylistlogic.go

@@ -3,9 +3,10 @@ package logic
 import (
 	"context"
 
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/service"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -26,6 +27,6 @@ func NewIdentityListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Iden
 // 获取用户可切换的身份列表
 func (l *IdentityListLogic) IdentityList(in *pb.IdentityReq) (*pb.IdentityResp, error) {
 	resp := &pb.IdentityResp{}
-	resp.Identitys = service.IdentityList(in.Id)
+	resp.Identitys = IdentityList(entity.BaseMysql, in.Id)
 	return resp, nil
 }

+ 3 - 2
service/entService.go

@@ -7,6 +7,7 @@ import (
 
 	"app.yhyue.com/moapp/jybase/common"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
 	userCenter "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
 )
 
@@ -154,7 +155,7 @@ func (this *EntService) Examinet(data *userCenter.ExamineReq) (int64, string, in
 		Mysql:       entity.Mysql,
 		ResourceLib: entity.ResourceLib,
 	}
-	if identity := IdentityByEntId(data.EntId); identity != nil {
+	if identity := IdentityByEntId(entity.BaseMysql, data.EntId); identity != nil {
 		info.EntAccountId = identity.EntAccountId
 	}
 	if info.EntExamine() {
@@ -286,7 +287,7 @@ func (this *EntService) UpdateEnt(data *userCenter.EntUpdateReq) (int64, string,
 		Mysql:       entity.Mysql,
 		ResourceLib: entity.ResourceLib,
 	}
-	if identity := IdentityByEntId(data.EntId); identity != nil {
+	if identity := IdentityByEntId(entity.BaseMysql, data.EntId); identity != nil {
 		info.EntAccountId = identity.EntAccountId
 	}
 	status, msg := info.UpdateEnt()

+ 0 - 24
service/identity_test.go

@@ -1,24 +0,0 @@
-package service
-
-import (
-	"log"
-	"testing"
-)
-
-func Test_IdentityList(t *testing.T) {
-	for _, v := range IdentityList(185509) {
-		log.Println(v)
-	}
-}
-
-func Test_IdentityByUserId(t *testing.T) {
-	log.Println(IdentityByUserId(68773))
-}
-
-func Test_IdentityByPositionId(t *testing.T) {
-	log.Println(IdentityByPositionId(945))
-}
-
-func Test_IdentityByEntUserId(t *testing.T) {
-	log.Println(IdentityByEntUserId(4271))
-}