Browse Source

feat:更新目录结构

Cheng Jian 3 years ago
parent
commit
83c5eb7bff

+ 1 - 1
opms_admin/app/model/sys_user.go

@@ -36,7 +36,7 @@ type LoginUserRes struct {
 
 // SysUserSearchReq 用户搜索请求参数
 type SysUserSearchReq struct {
-	DeptId   string `json:"deptId"` //部门id
+	DeptId   int    `json:"deptId"` //部门id
 	DeptIds  []int  //所属部门id数据
 	Phone    string `json:"phone"`
 	Status   string `json:"status"`

+ 3 - 0
opms_admin/app/service/sys_user.go

@@ -71,6 +71,9 @@ func (s *userService) GetUserList(req *model.SysUserSearchReq) (total int, userL
 		keyWords := "%" + req.KeyWords + "%"
 		userModel = userModel.Where("user_name like ? or  nick_name like ?", keyWords, keyWords)
 	}
+	if req.DeptId != 0 {
+		userModel = userModel.Where("dept_id", req.DeptId)
+	}
 	if len(req.DeptIds) != 0 {
 		userModel = userModel.Where("dept_id in (?)", req.DeptIds)
 	}

+ 9 - 3
opms_admin/config/config.toml

@@ -16,7 +16,13 @@
 [database]
     [[database.default]]
         Debug = true
-        link = "mysql:root:Dashoo#190801@tcp(127.0.0.1:3306)/dashoo_crm"
+        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/dashoo_crm"
 
-[micro_srv]
-    auth = "dashoo.labsop.auth-2.1"
+# token认证设置
+[gtoken]
+    # 缓存模式 1 gcache 2 gredis
+    cache-mode = 1
+    # 是否支持多端登录
+    multi-login = true
+    # 必须16,24或32个字母
+    encrypt-key = "jwtdashoo-191225"

+ 2 - 1
opms_admin/main.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"dashoo.cn/micro/app/handler"
 	"dashoo.cn/opms_libary/micro_srv"
-
 	"github.com/gogf/gf/frame/g"
 	"github.com/smallnest/rpcx/protocol"
 )
@@ -35,6 +34,7 @@ func main() {
 // AuthExcludePaths 设定不需要认证的路径
 var AuthExcludePaths = []string{
 	"/Auth/Login",
+	"/Auth/ValidToken",
 	"/Role/GetRoleList",
 	"/Common/GetCaptchaImg",
 	"/Model/*",
@@ -45,6 +45,7 @@ var AuthExcludePaths = []string{
 
 // 处理Auth
 func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
+	ctx = context.WithValue(ctx, "NotAuthSrv", true)
 	// token拦截器
 	err := micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
 	return err

+ 19 - 12
opms_libary/micro_srv/micro_srv.go

@@ -199,13 +199,16 @@ func HandleAuth(ctx context.Context, req *protocol.Message, token string, authEx
 	path := "/" + req.ServicePath + "/" + req.ServiceMethod
 	//g.Log().Info("reqPath: ", path)
 	//g.Log().Info("token: ", token)
-	req.Metadata["authExclude"] = "true"
 
 	if authPath(path, authExcludePaths) {
 		req.Metadata["authExclude"] = "false"
-
-		//rsp := validToken(token)
-		rsp := gtoken.GFToken.ValidToken(token)
+		var rsp gtoken.Resp
+		notAuthSrv := ctx.Value("NotAuthSrv")
+		if notAuthSrv != nil && notAuthSrv.(bool) {
+			rsp = gtoken.GFToken.ValidToken(token)
+		} else {
+			rsp = validToken(token)
+		}
 
 		//return errors.New("InvalidToken")
 		if rsp.Code != 0 {
@@ -259,23 +262,27 @@ func authPath(urlPath string, authExcludePaths []string) bool {
 }
 
 // 验证token
-func validToken(token string) auth.Response {
-	rsp := &auth.Response{}
+func validToken(token string) gtoken.Resp {
+	grsp := gtoken.Resp{}
 	if token == "" {
-		rsp.Code = 401
-		rsp.Msg = "valid token empty"
-		return *rsp
+		grsp.Code = 401
+		grsp.Msg = "valid token empty"
+		return grsp
 	}
 
 	authService := InitMicroSrvClient("Auth", "micro_srv.auth")
 	defer authService.Close()
+	rsp := &auth.Response{}
 	err := authService.Call(context.TODO(), "ValidToken", token, rsp)
 	if err != nil {
 		g.Log().Error(err)
-		rsp.Code = 401
-		return *rsp
+		grsp.Code = 401
+		return grsp
 	}
-	return *rsp
+	grsp.Code = int(rsp.Code)
+	grsp.Msg = rsp.Msg
+	grsp.Data = rsp.Data
+	return grsp
 }
 
 // IsAuthExclude 是否进行auth验证

+ 0 - 0
opms_parent/app/dao/.gitkeep → opms_parent/app/dao/base/.gitkeep


+ 0 - 0
opms_parent/app/handler/.gitkeep → opms_parent/app/dao/cust/.gitkeep


+ 0 - 0
opms_parent/app/model/.gitkeep → opms_parent/app/handler/base/.gitkeep


+ 0 - 0
opms_parent/app/service/.gitkeep → opms_parent/app/handler/cust/.gitkeep


+ 0 - 0
opms_parent/app/model/base/.gitkeep


+ 0 - 0
opms_parent/app/model/cust/.gitkeep


+ 3 - 2
opms_parent/app/service/base.go

@@ -7,8 +7,9 @@ import (
 )
 
 var (
-	// UpdateFieldEx 更新过滤字段
-	UpdateFieldEx = []string{"CreatedBy", "CreatedName", "CreatedTime"}
+	// CommonUpdateFieldEx, UpdateFieldEx 更新过滤字段
+	CommonUpdateFieldEx = []interface{}{"created_by", "created_name", "created_time"}
+	UpdateFieldEx       = []interface{}{"id", "created_by", "created_name", "created_time"}
 )
 
 // SetCreatedInfo 插入数据库时设置创建信息

+ 0 - 0
opms_parent/app/service/base/.gitkeep


+ 64 - 0
opms_parent/app/service/context.go

@@ -0,0 +1,64 @@
+package service
+
+import (
+	"context"
+	"dashoo.cn/opms_libary/micro_srv"
+	"dashoo.cn/opms_libary/request"
+	"github.com/gogf/gf/os/glog"
+)
+
+// Context 上下文管理服务
+type contextService struct {
+	Tenant  string            `json:"tenant"`
+	CxtUser *request.UserInfo `json:"cxtUser"`
+}
+
+// Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
+func (c *contextService) Init(ctx context.Context) (*contextService, error) {
+	c = new(contextService)
+	// 获取租户码
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return nil, err
+	}
+	reqMethod, _ := micro_srv.GetReqMethod(ctx)
+	glog.Info("Received " + reqMethod + " request @ " + tenant)
+	c.Tenant = tenant
+	c.CxtUser = nil
+	if !micro_srv.IsAuthExclude(ctx) {
+		userInfo, err := micro_srv.GetUserInfo(ctx)
+		if err != nil {
+			return nil, err
+		}
+		c.CxtUser = &userInfo
+	}
+	return c, nil
+}
+
+func (c *contextService) GetCxtUserId() int {
+	if c.CxtUser == nil {
+		return -1
+	}
+	return c.CxtUser.Id
+}
+
+func (c *contextService) GetCxtUserUuid() string {
+	if c.CxtUser == nil {
+		return "-1"
+	}
+	return c.CxtUser.Uuid
+}
+
+func (c *contextService) GetCxtUserName() string {
+	if c.CxtUser == nil {
+		return "-1"
+	}
+	return c.CxtUser.UserName
+}
+
+func (c *contextService) GetCxtUserDeptId() int {
+	if c.CxtUser == nil {
+		return -1
+	}
+	return c.CxtUser.DeptId
+}

+ 0 - 0
opms_parent/app/service/cust/.gitkeep


+ 1 - 1
opms_parent/config/config.toml

@@ -19,4 +19,4 @@
         link = "mysql:root:Dashoo#190801@tcp(127.0.0.1:3306)/dashoo_crm"
 
 [micro_srv]
-    auth = "dashoo.labsop.auth-2.1"
+    auth = "dashoo.opms.admin-0.0.1,127.0.0.1:8887"