Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/feature/v1.2.12' into feature/v1.2.12

# Conflicts:
#	rpc/pb/userCenter.pb.go
#	rpc/pb/userCenter_grpc.pb.go
#	rpc/userCenter.proto
WH01243 2 anni fa
parent
commit
d4e8d2c1d1

+ 5 - 0
api/internal/handler/routes.go

@@ -102,6 +102,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/userCenter/user/deleteById",
 				Handler: UserDelHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/userCenter/user/identity",
+				Handler: UserIdentityHandler(serverCtx),
+			},
 		},
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
 	)

+ 28 - 0
api/internal/handler/useridentityhandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func UserIdentityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.UserIdentityReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewUserIdentityLogic(r.Context(), svcCtx)
+		resp, err := l.UserIdentity(&req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 3 - 0
api/internal/logic/useraddlogic.go

@@ -37,6 +37,9 @@ func (l *UserAddLogic) UserAdd(req types.UserAddReq) (*types.Resp, error) {
 		AOpenid:  req.AOpenid,
 		SOpenid:  req.SOpenid,
 		Unionid:  req.Unionid,
+		IdCard:   req.IdCard,
+		Sex:      req.Sex,
+		Address:  req.Address,
 	})
 	return &types.Resp{
 		Error_code: res.ErrorCode,

+ 51 - 0
api/internal/logic/useridentitylogic.go

@@ -0,0 +1,51 @@
+package logic
+
+import (
+	"context"
+
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/types"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type UserIdentityLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUserIdentityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserIdentityLogic {
+	return &UserIdentityLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *UserIdentityLogic) UserIdentity(req *types.UserIdentityReq) (resp *types.Resp, err error) {
+	res, err := entity.UserCenterRpc.UserIdentity(l.ctx, &UserIdentityReq{
+		AppId:      req.AppId,
+		EntId:      req.EntId,
+		BaseUserId: req.NewUserId,
+	})
+	status := 0
+	if res != nil && res.ErrorMsg == "" {
+		status = 1
+	}
+	return &types.Resp{
+		Error_code: res.ErrorCode,
+		Error_msg:  res.ErrorMsg,
+		Data: map[string]interface{}{
+			"personId":          res.PersonId,
+			"userName":          res.UserName,
+			"userAccountId":     res.UserAccountId,
+			"entAccountId":      res.EntAccountId,
+			"entUserAccountId":  res.EntUserAccountId,
+			"userPositionId":    res.UserPositionId,
+			"entUserPositionId": res.EntUserPositionId,
+			"status":            status,
+		},
+	}, err
+}

+ 9 - 0
api/internal/types/types.go

@@ -210,6 +210,9 @@ type UserAddReq struct {
 	SOpenid       string `json:"s_openid,optional"`
 	AOpenid       string `json:"a_openid,optional"`
 	Unionid       string `json:"unionid,optional"`
+	IdCard        string `json:"idCard,optional"`
+	Address       string `json:"address,optional"`
+	Sex           int64  `json:"sex,optional"`
 }
 
 type UserUpdateReq struct {
@@ -268,3 +271,9 @@ type WorkDesktopClearUserInfo struct {
 	UserIds   string `json:"userIds,optional"`
 	NewUserId string `header:"newUserId"`
 }
+
+type UserIdentityReq struct {
+	AppId     string `json:"appId"`
+	NewUserId int64  `json:"newUserId"`
+	EntId     int64  `json:"entId,optional"`
+}

+ 11 - 0
api/userCenter.api

@@ -223,6 +223,9 @@ type (
 		SOpenid       string `json:"s_openid,optional"`
 		AOpenid       string `json:"a_openid,optional"`
 		Unionid       string `json:"unionid,optional"`
+		IdCard        string `json:"idCard,optional"`
+		Address       string `json:"address,optional"`
+		Sex           int64  `json:"sex,optional"`
 	}
 
 	UserUpdateReq {
@@ -283,6 +286,12 @@ type (
 		UserIds   string `json:"userIds,optional"`
 		NewUserId string `header:"newUserId"`
 	}
+
+	UserIdentityReq {
+		AppId     string `json:"appId"`
+		NewUserId int64  `json:"newUserId"`
+		EntId     int64  `json:"entId,optional"`
+	}
 )
 
 service userCenter-api {
@@ -328,4 +337,6 @@ service userCenter-api {
 	post /userCenter/user/updateById (UserUpdateReq) returns (resp)
 	@handler UserDel
 	post /userCenter/user/deleteById (UserDelReq) returns (resp)
+	@handler UserIdentity
+	post /userCenter/user/identity (UserIdentityReq) returns (resp)
 }

+ 4 - 1
entity/db.go

@@ -9,6 +9,9 @@ var (
 	Mgo               mongodb.MongodbSim
 	Mysql             *mysql.Mysql
 	BaseMysql         *mysql.Mysql
-	UserTable         = "base_user"
+	UserTable         = "base_user" //用户表
 	UserSnapshotTable = "base_user_snapshot"
+	BasePerson        = "base_person"   //自然人表
+	BaseAccount       = "base_account"  //账户表
+	BasePosition      = "base_position" //职位表
 )

+ 32 - 0
rpc/internal/logic/useridentitylogic.go

@@ -0,0 +1,32 @@
+package logic
+
+import (
+	"context"
+
+	"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"
+)
+
+type UserIdentityLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewUserIdentityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserIdentityLogic {
+	return &UserIdentityLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// 获取用户身份相关参数
+func (l *UserIdentityLogic) UserIdentity(in *pb.UserIdentityReq) (*pb.UserIdentityResp, error) {
+	// todo: add your logic here and delete this line
+
+	return service.UserIdentity(in), nil
+}

+ 6 - 0
rpc/internal/server/usercenterserver.go

@@ -135,3 +135,9 @@ func (s *UserCenterServer) CheckIsEntAdmin(ctx context.Context, in *pb.EntUserRe
 	l := logic.NewCheckIsEntAdminLogic(ctx, s.svcCtx)
 	return l.CheckIsEntAdmin(in)
 }
+
+// 获取用户身份相关参数
+func (s *UserCenterServer) UserIdentity(ctx context.Context, in *pb.UserIdentityReq) (*pb.UserIdentityResp, error) {
+	l := logic.NewUserIdentityLogic(ctx, s.svcCtx)
+	return l.UserIdentity(in)
+}

+ 1 - 1
rpc/pb/userCenter.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
 // 	protoc-gen-go v1.28.0
-// 	protoc        v3.15.1
+// 	protoc        v3.15.5
 // source: userCenter.proto
 
 package pb

+ 1 - 1
rpc/pb/userCenter_grpc.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
 // versions:
 // - protoc-gen-go-grpc v1.2.0
-// - protoc             v3.15.1
+// - protoc             v3.15.5
 // source: userCenter.proto
 
 package pb

+ 1 - 0
rpc/userCenter.proto

@@ -438,6 +438,7 @@ message  WorkDesktopClearUserInfoReq{
   string userIds = 4;
   string newUserId = 5;
 }
+
 service UserCenter {
   //企业认证
   rpc EntAuth (EntAuthReq) returns (EntAuthResp);

+ 10 - 0
rpc/usercenter/usercenter.go

@@ -57,6 +57,8 @@ type (
 	UserAddResp                  = pb.UserAddResp
 	UserAdds                     = pb.UserAdds
 	UserIdReq                    = pb.UserIdReq
+	UserIdentityReq              = pb.UserIdentityReq
+	UserIdentityResp             = pb.UserIdentityResp
 	UserInfo                     = pb.UserInfo
 	UserReq                      = pb.UserReq
 	WorkDesktopClearUserInfoReq  = pb.WorkDesktopClearUserInfoReq
@@ -104,6 +106,8 @@ type (
 		GetEntUserList(ctx context.Context, in *EntUserListReq, opts ...grpc.CallOption) (*EntUserListResp, error)
 		// 查看员工是否是企业管理员
 		CheckIsEntAdmin(ctx context.Context, in *EntUserReq, opts ...grpc.CallOption) (*CheckIsEntAdminResp, error)
+		// 获取用户身份相关参数
+		UserIdentity(ctx context.Context, in *UserIdentityReq, opts ...grpc.CallOption) (*UserIdentityResp, error)
 	}
 
 	defaultUserCenter struct {
@@ -230,3 +234,9 @@ func (m *defaultUserCenter) CheckIsEntAdmin(ctx context.Context, in *EntUserReq,
 	client := pb.NewUserCenterClient(m.cli.Conn())
 	return client.CheckIsEntAdmin(ctx, in, opts...)
 }
+
+// 获取用户身份相关参数
+func (m *defaultUserCenter) UserIdentity(ctx context.Context, in *UserIdentityReq, opts ...grpc.CallOption) (*UserIdentityResp, error) {
+	client := pb.NewUserCenterClient(m.cli.Conn())
+	return client.UserIdentity(ctx, in, opts...)
+}

+ 118 - 28
service/user.go

@@ -4,26 +4,56 @@ import (
 	"database/sql"
 	"time"
 
+	"app.yhyue.com/moapp/jybase/common"
+
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
 	. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
 )
 
 func UserAdd(this *UserAddReq) *UserAddResp {
-	userId := entity.BaseMysql.Insert(entity.UserTable, map[string]interface{}{
-		"appid":       this.Appid,
-		"phone":       this.Phone,
-		"nickname":    this.Nickname,
-		"headimg":     this.Headimg,
-		"company":     this.Company,
-		"position":    this.Position,
-		"password":    this.Password,
-		"s_openid":    this.SOpenid,
-		"a_openid":    this.AOpenid,
-		"unionid":     this.Unionid,
-		"create_time": time.Now().Format("2006-01-02 15:04:05"),
+	userId := int64(0)
+	ok := entity.BaseMysql.ExecTx("新增用户相关表字段", func(tx *sql.Tx) bool {
+		//自然人
+		personId := entity.BaseMysql.InsertByTx(tx, entity.BasePerson, map[string]interface{}{
+			"name":        this.Nickname,
+			"headimg":     this.Headimg,
+			"idcard":      this.IdCard,
+			"address":     this.Address,
+			"sex":         this.Sex,
+			"contact":     this.Phone,
+			"create_time": time.Now().Format("2006-01-02 15:04:05"),
+			"update_time": time.Now().Format("2006-01-02 15:04:05"),
+		})
+		//账户表
+		accountId := entity.BaseMysql.InsertByTx(tx, entity.BaseAccount, map[string]interface{}{
+			"person_id": personId,
+			"type":      0,
+		})
+		//用户表
+		baseUserId := entity.BaseMysql.InsertByTx(tx, entity.UserTable, map[string]interface{}{
+			"appid":       this.Appid,
+			"person_id":   personId,
+			"phone":       this.Phone,
+			"password":    this.Password,
+			"s_openid":    this.SOpenid,
+			"a_openid":    this.AOpenid,
+			"unionid":     this.Unionid,
+			"create_time": time.Now().Format("2006-01-02 15:04:05"),
+			"update_time": time.Now().Format("2006-01-02 15:04:05"),
+		})
+		//职位表
+		positionId := entity.BaseMysql.InsertByTx(tx, entity.BasePosition, map[string]interface{}{
+			"type":        0,
+			"account_id":  accountId,
+			"user_id":     baseUserId,
+			"person_name": this.Nickname,
+		})
+		userId = baseUserId
+		return personId > 0 && accountId > 0 && baseUserId > 0 && positionId > 0
 	})
+
 	status, msg := 0, ""
-	if userId > 0 {
+	if userId > 0 && ok {
 		status = 1
 	} else {
 		msg = "新增用户失败"
@@ -114,22 +144,34 @@ func UserUpdates(this *UserIdReq) bool {
 		} else {
 			set["unionid"] = ""
 		}
+		//base_user
 		ok1 := entity.BaseMysql.UpdateByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id}, set)
-		snapshot := entity.BaseMysql.InsertByTx(tx, entity.UserSnapshotTable, map[string]interface{}{
-			"appid":       this.Appid,
-			"user_id":     this.Id,
-			"phone":       this.Phone,
-			"nickname":    this.Nickname,
-			"headimg":     this.Headimg,
-			"company":     this.Company,
-			"position":    this.Position,
-			"password":    this.Password,
-			"s_openid":    this.SOpenid,
-			"a_openid":    this.AOpenid,
-			"unionid":     this.Unionid,
-			"create_time": time.Now().Format("2006-01-02 15:04:05"),
-		})
-		return ok1 && snapshot > 0
+		//查询出personid
+		ok2 := true
+		ok3 := true
+		rdata := entity.BaseMysql.SelectBySqlByTx(tx, `select person_id from base_user where id =?`, this.Id)
+		if rdata != nil && len(*rdata) > 0 {
+			person_id := common.Int64All((*rdata)[0]["person_id"])
+			ok2 = entity.BaseMysql.UpdateByTx(tx, entity.BasePerson, map[string]interface{}{
+				"id": person_id,
+			}, map[string]interface{}{
+				"contact": this.Phone,
+				"name":    this.Nickname,
+				"headimg": this.Headimg,
+			})
+			//获取accountid
+			mdata := entity.BaseMysql.SelectBySqlByTx(tx, `select id from base_account where person_id =?`, person_id)
+			if mdata != nil && len(*mdata) > 0 {
+				accountId := common.Int64All((*mdata)[0]["id"])
+				ok3 = entity.BaseMysql.UpdateByTx(tx, entity.BasePosition, map[string]interface{}{
+					"user_id":    this.Id,
+					"account_id": accountId,
+				}, map[string]interface{}{
+					"person_name": this.Nickname,
+				})
+			}
+		}
+		return ok1 && ok2 && ok3
 	})
 	if flag {
 		ok = true
@@ -166,3 +208,51 @@ func UserDels(this *UserIdReq) bool {
 	}
 	return ok
 }
+
+//
+
+/*
+	int64   error_code = 1;
+	string  error_msg = 2;
+	int64 personId=3;//自然人id
+	int64 userAccountId=4;//个人账户id
+	int64 entAccountId =5; //企业账户id
+	int64 entUserAccountId =6;//企业雇员账户id
+	int64 userPositionId =7; // 个人职位id
+	int64 entUserPositionId =8;// 企业雇员职位id
+	string userName=9; //昵称
+
+*/
+func UserIdentity(this *UserIdentityReq) *UserIdentityResp {
+	resp := &UserIdentityResp{}
+	//个人账户
+	data := entity.BaseMysql.SelectBySql(`SELECT a.person_id personId,c.id userAccountId ,d.id userPositionId,b.name userName FROM base_user a 
+								INNER JOIN base_person b ON a.person_id =b.id 
+								INNER JOIN base_account c ON c.person_id = b.id  AND c.type=0
+								INNER JOIN base_position d ON d.account_id = c.id AND d.user_id = a.id AND d.type=0
+								WHERE a.id =? AND a.appid =?`, this.BaseUserId, this.AppId)
+	if data != nil && len(*data) > 0 {
+		r := (*data)[0]
+		resp.PersonId = common.Int64All(r["personId"])
+		resp.UserAccountId = common.Int64All(r["userAccountId"])
+		resp.UserPositionId = common.Int64All(r["userPositionId"])
+		resp.UserName = common.ObjToString(r["userName"])
+	} else {
+		resp.ErrorCode = -1
+		resp.ErrorMsg = "暂无数据"
+	}
+	//企业账户
+	data2 := entity.BaseMysql.SelectBySql(`select c.id entUserAccountId ,d.id entUserPositionId, e.id entAccountId from base_user a 
+											inner join base_person b on a.person_id =b.id 
+											inner join base_account c on c.person_id = b.id  and c.type=1
+											inner join base_position d on d.account_id = c.id and d.user_id = a.id and d.type=1
+											inner join base_account e on e.type=1 and (e.person_id is null or e.person_id =0)
+											where a.id =? and a.appid =? and c.ent_id =?`, this.BaseUserId, this.AppId, this.EntId)
+	if data2 != nil && len(*data2) > 0 {
+		r := (*data2)[0]
+		resp.EntAccountId = common.Int64All(r["entAccountId"])
+		resp.EntUserAccountId = common.Int64All(r["entUserAccountId"])
+		resp.EntUserPositionId = common.Int64All(r["entUserPositionId"])
+	}
+	return resp
+}