Browse Source

style: 调整svc

2637309949 4 years ago
parent
commit
576dc90e0f
2 changed files with 33 additions and 26 deletions
  1. 33 0
      internal/svc/erp.go
  2. 0 26
      internal/svc/servicecontext.go

+ 33 - 0
internal/svc/erp.go

@@ -0,0 +1,33 @@
+package svc
+
+import (
+	"fmt"
+	"strings"
+
+	"git.i2edu.net/i2/go-zero/core/stores/sqlc"
+	"git.i2edu.net/i2/go-zero/core/stores/sqlx"
+	"git.i2edu.net/i2/i2-bill-erp/internal/config"
+	"git.i2edu.net/i2/i2-bill-erp/model"
+	"github.com/thoas/go-funk"
+)
+
+type ErpUtil struct {
+	Config  config.Config
+	SqlConn sqlx.SqlConn
+}
+
+func (rp *ErpUtil) InRoles(userId string, roles ...string) (bool, error) {
+	user := model.SysUser{}
+	role := strings.Join(funk.Map(roles, func(r string) string { return fmt.Sprintf("'%v'", r) }).([]string), ",")
+	err := rp.SqlConn.QueryRowPartial(&user, fmt.Sprintf(`SELECT sys_user_role.user_id id FROM sys_user_role
+	left join sys_role on sys_role.id=sys_user_role.role_id 
+	where sys_role.code in (%v) and sys_role.del_flag=0 and sys_user_role.del_flag=0 and sys_user_role.user_id=?`, role), userId)
+	switch err {
+	case nil:
+		return true, nil
+	case sqlc.ErrNotFound:
+		return false, nil
+	default:
+		return true, nil
+	}
+}

+ 0 - 26
internal/svc/servicecontext.go

@@ -1,14 +1,9 @@
 package svc
 
 import (
-	"fmt"
-	"strings"
-
 	"git.i2edu.net/i2/i2-bill-erp/internal/config"
 	"git.i2edu.net/i2/i2-bill-erp/model"
-	"github.com/thoas/go-funk"
 
-	"git.i2edu.net/i2/go-zero/core/stores/sqlc"
 	"git.i2edu.net/i2/go-zero/core/stores/sqlx"
 )
 
@@ -21,27 +16,6 @@ type ServiceContext struct {
 	MktPartTimeUser model.MktPartTimeUserModel
 }
 
-type ErpUtil struct {
-	Config  config.Config
-	SqlConn sqlx.SqlConn
-}
-
-func (rp *ErpUtil) InRoles(userId string, roles ...string) (bool, error) {
-	user := model.SysUser{}
-	role := strings.Join(funk.Map(roles, func(r string) string { return fmt.Sprintf("'%v'", r) }).([]string), ",")
-	err := rp.SqlConn.QueryRowPartial(&user, fmt.Sprintf(`SELECT sys_user_role.user_id id FROM sys_user_role
-	left join sys_role on sys_role.id=sys_user_role.role_id 
-	where sys_role.code in (%v) and sys_role.del_flag=0 and sys_user_role.del_flag=0 and sys_user_role.user_id=?`, role), userId)
-	switch err {
-	case nil:
-		return true, nil
-	case sqlc.ErrNotFound:
-		return false, nil
-	default:
-		return true, nil
-	}
-}
-
 func NewServiceContext(c config.Config) *ServiceContext {
 	sc := ServiceContext{
 		Config:  c,