2637309949@qq.com %!s(int64=5) %!d(string=hai) anos
pai
achega
fac34cd96d

+ 8 - 7
client/gen/pipes/sql.go

@@ -7,6 +7,7 @@ package pipes
 import (
 	"fmt"
 	"path"
+	"path/filepath"
 	"strings"
 
 	"github.com/2637309949/dolphin/client/gen"
@@ -30,7 +31,7 @@ func (app *SQL) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, err
 	tplCache := map[string]bool{}
 	for _, c := range node.Controllers {
 		for _, api := range c.APIS {
-			if strings.TrimSpace(api.Table) != "" {
+			if strings.TrimSpace(api.Table) != "" && api.Function == "page" {
 				data := map[string]interface{}{
 					"PackageName": node.PackageName,
 					"Name":        node.Name,
@@ -38,8 +39,8 @@ func (app *SQL) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, err
 					"Application": node,
 					"Api":         api,
 				}
-				cpath := path.Join(dir, viper.GetString("dir.sql"), c.Name, fmt.Sprintf("%v_%v_%v", c.Name, "page", "count"))
-				if _, ok := tplCache[cpath]; !ok {
+				cpath := path.Join(dir, viper.GetString("dir.sql"), c.Name, fmt.Sprintf("%v_%v_%v", c.Name, api.Name, "count"))
+				if _, ok := tplCache[filepath.Base(cpath)]; !ok {
 					tmplCfg := &gen.TmplCfg{
 						Text:     template.TmplSQLCount,
 						FilePath: cpath,
@@ -48,10 +49,10 @@ func (app *SQL) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, err
 						Suffix:   ".tpl",
 					}
 					tmplCfgs = append(tmplCfgs, tmplCfg)
-					tplCache[cpath] = true
+					tplCache[filepath.Base(cpath)] = true
 				}
-				spath := path.Join(dir, viper.GetString("dir.sql"), c.Name, fmt.Sprintf("%v_%v_%v", c.Name, "page", "select"))
-				if _, ok := tplCache[spath]; !ok {
+				spath := path.Join(dir, viper.GetString("dir.sql"), c.Name, fmt.Sprintf("%v_%v_%v", c.Name, api.Name, "select"))
+				if _, ok := tplCache[filepath.Base(spath)]; !ok {
 					tmplCfg := &gen.TmplCfg{
 						Text:     template.TmplSQLSel,
 						FilePath: spath,
@@ -60,7 +61,7 @@ func (app *SQL) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, err
 						Suffix:   ".tpl",
 					}
 					tmplCfgs = append(tmplCfgs, tmplCfg)
-					tplCache[spath] = true
+					tplCache[filepath.Base(spath)] = true
 				}
 			}
 		}

+ 4 - 0
client/gen/template/sql.go

@@ -7,6 +7,8 @@ from
 	{{.Api.Table}}
 where
 	{{.Api.Table}}.id {{.Application.Unescaped "{{.ne}}"}} ""
+	and
+	{{.Api.Table}}.del_flag {{.Application.Unescaped "{{.ne}}"}} 0
 LIMIT {{.Application.Unescaped "{{.size}}"}} OFFSET {{.Application.Unescaped "{{.offset}}"}}
 `
 
@@ -17,4 +19,6 @@ from
 	{{.Api.Table}}
 where
 	{{.Api.Table}}.id {{.Application.Unescaped "{{.ne}}"}} ""
+	and
+	{{.Api.Table}}.del_flag {{.Application.Unescaped "{{.ne}}"}} 0
 `

+ 56 - 7
platform/app/app.ctx.go

@@ -222,7 +222,7 @@ func (q *Query) GetInt(key string, init ...interface{}) int64 {
 }
 
 // SetInt defined
-func (q *Query) SetInt(key string, init ...interface{}) {
+func (q *Query) SetInt(key string, init ...interface{}) func() {
 	v := q.ctx.Query(key)
 	if strings.TrimSpace(v) == "" {
 		if len(init) > 0 {
@@ -237,6 +237,13 @@ func (q *Query) SetInt(key string, init ...interface{}) {
 		}
 		q.m[key] = i
 	}
+	return func() {
+		if len(init) > 0 {
+			q.m[key] = init[0]
+		} else {
+			q.m[key] = 0
+		}
+	}
 }
 
 // GetBool defined
@@ -246,7 +253,7 @@ func (q *Query) GetBool(key string, init ...interface{}) bool {
 }
 
 // SetBool defined
-func (q *Query) SetBool(key string, init ...interface{}) {
+func (q *Query) SetBool(key string, init ...interface{}) func() {
 	v := q.ctx.Query(key)
 	if strings.TrimSpace(v) == "" {
 		if len(init) > 0 {
@@ -261,6 +268,13 @@ func (q *Query) SetBool(key string, init ...interface{}) {
 		}
 		q.m[key] = i
 	}
+	return func() {
+		if len(init) > 0 {
+			q.m[key] = init[0]
+		} else {
+			q.m[key] = false
+		}
+	}
 }
 
 // GetString defined
@@ -270,7 +284,7 @@ func (q *Query) GetString(key string, init ...interface{}) string {
 }
 
 // SetString defined
-func (q *Query) SetString(key string, init ...interface{}) {
+func (q *Query) SetString(key string, init ...interface{}) func() {
 	v := q.ctx.Query(key)
 	if strings.TrimSpace(v) == "" {
 		if len(init) > 0 {
@@ -281,10 +295,17 @@ func (q *Query) SetString(key string, init ...interface{}) {
 	} else {
 		q.m[key] = v
 	}
+	return func() {
+		if len(init) > 0 {
+			q.m[key] = init[0]
+		} else {
+			q.m[key] = ""
+		}
+	}
 }
 
 // SetArrayString defined
-func (q *Query) SetArrayString(key string, init ...[]string) {
+func (q *Query) SetArrayString(key string, init ...[]string) func() {
 	v := q.ctx.Query(key)
 	if strings.TrimSpace(v) == "" {
 		if len(init) > 0 {
@@ -295,6 +316,13 @@ func (q *Query) SetArrayString(key string, init ...[]string) {
 	} else {
 		q.m[key] = strings.Split(v, ",")
 	}
+	return func() {
+		if len(init) > 0 {
+			q.m[key] = init[0]
+		} else {
+			q.m[key] = []string{}
+		}
+	}
 }
 
 // GetArrayString defined
@@ -304,7 +332,7 @@ func (q *Query) GetArrayString(key string, init ...[]string) []string {
 }
 
 // SetArrayInt defined
-func (q *Query) SetArrayInt(key string, init ...[]int64) {
+func (q *Query) SetArrayInt(key string, init ...[]int64) func() {
 	v := q.ctx.Query(key)
 	if strings.TrimSpace(v) == "" {
 		if len(init) > 0 {
@@ -321,6 +349,13 @@ func (q *Query) SetArrayInt(key string, init ...[]int64) {
 			return it
 		}).([]int64)
 	}
+	return func() {
+		if len(init) > 0 {
+			q.m[key] = init[0]
+		} else {
+			q.m[key] = []int64{}
+		}
+	}
 }
 
 // GetArrayInt defined
@@ -330,7 +365,7 @@ func (q *Query) GetArrayInt(key string, init ...[]int) []int64 {
 }
 
 // SetArrayFloat64 defined
-func (q *Query) SetArrayFloat64(key string, init ...[]float64) {
+func (q *Query) SetArrayFloat64(key string, init ...[]float64) func() {
 	v := q.ctx.Query(key)
 	if strings.TrimSpace(v) == "" {
 		if len(init) > 0 {
@@ -347,6 +382,13 @@ func (q *Query) SetArrayFloat64(key string, init ...[]float64) {
 			return it
 		}).([]float64)
 	}
+	return func() {
+		if len(init) > 0 {
+			q.m[key] = init[0]
+		} else {
+			q.m[key] = []float64{}
+		}
+	}
 }
 
 // GetArrayFloat64 defined
@@ -356,7 +398,7 @@ func (q *Query) GetArrayFloat64(key string, init ...[]float64) []float64 {
 }
 
 // SetArrayBool defined
-func (q *Query) SetArrayBool(key string, init ...[]bool) {
+func (q *Query) SetArrayBool(key string, init ...[]bool) func() {
 	v := q.ctx.Query(key)
 	if strings.TrimSpace(v) == "" {
 		if len(init) > 0 {
@@ -373,6 +415,13 @@ func (q *Query) SetArrayBool(key string, init ...[]bool) {
 			return it
 		}).([]bool)
 	}
+	return func() {
+		if len(init) > 0 {
+			q.m[key] = init[0]
+		} else {
+			q.m[key] = []bool{}
+		}
+	}
 }
 
 // GetArrayBool defined

+ 15 - 4
platform/app/sys_cas.go

@@ -14,6 +14,8 @@ import (
 	"strings"
 	"time"
 
+	"github.com/2637309949/dolphin/packages/go-funk"
+
 	"github.com/2637309949/dolphin/packages/go-session/cookie"
 	"github.com/2637309949/dolphin/packages/go-session/session"
 	"github.com/2637309949/dolphin/packages/logrus"
@@ -291,11 +293,20 @@ func SysCasCheck(ctx *Context) {
 // @Failure 500 {object} model.Response
 // @Router /api/sys/cas/profile [get]
 func SysCasProfile(ctx *Context) {
+	user := ctx.LoginInInfo()
+	roles := []model.SysRole{}
+	err := ctx.DB.Sql("select name from sys_role left join sys_role_user on sys_role.id = sys_role_user.role_id and sys_role_user.user_id = ?", user.ID.String).Find(&roles)
+	if err != nil {
+		ctx.Fail(err)
+		return
+	}
+	rolesArr := funk.Map(roles, func(role model.SysRole) string {
+		return role.Name.String
+	}).([]string)
 	ctx.Success(map[string]interface{}{
-		"roles":        []string{"admin"},
-		"introduction": "I am a super administrator",
-		"avatar":       "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
-		"name":         "Super Admin",
+		"roles":  rolesArr,
+		"avatar": user.Avatar.String,
+		"name":   user.Name.String,
 	})
 }
 

+ 2 - 1
platform/app/sys_menu.go

@@ -143,8 +143,9 @@ func SysMenuList(ctx *Context) {
 	q := ctx.TypeQuery()
 	q.SetInt("page", 1)
 	q.SetInt("size", 15)
+	q.SetBool("isAdmin", ctx.InAdmin())()
 	q.SetTags()
-	ret, err := ctx.PageSearch(ctx.DB, "sys_menu", "page", "sys_menu", q.Value())
+	ret, err := ctx.PageSearch(ctx.DB, "sys_menu", "list", "sys_menu", q.Value())
 	if err != nil {
 		ctx.Fail(err)
 		return

+ 3 - 0
platform/doc/swagger.yaml

@@ -561,6 +561,9 @@ definitions:
       id:
         description: 主键
         type: string
+      intro:
+        description: 简介
+        type: string
       mobile:
         description: 电话
         type: string

+ 1 - 0
platform/model/sys_user.helper.go

@@ -17,6 +17,7 @@ var DefaultAdmin = SysUser{
 	Password:   null.StringFrom("admin"),
 	Name:       null.StringFrom("admin"),
 	FullName:   null.StringFrom("admin"),
+	Avatar:     null.StringFrom("http://pic.616pic.com/ys_bnew_img/00/06/27/TWk2P5YJ5k.jpg"),
 	Status:     null.IntFrom(1),
 	Domain:     null.StringFrom("127.0.0.1"),
 	CreateBy:   null.StringFrom("6ba7b810-9dad-11d1-80b4-00c04fd430c8"),

+ 5 - 5
platform/sql/sqlmap/sys_user.xml

@@ -1,12 +1,12 @@
 <sqlMap>
     <sql id="insert_sys_user">
         insert into sys_user
-		(`id`,`password`,`salt`,`name`,`full_name`,`mobile`,`email`,`org_id`,`gender`,`type`,`status`,`avatar`,`domain`,`create_by`,`create_time`,`update_by`,`update_time`,`del_flag`)
+		(`id`,`password`,`salt`,`name`,`full_name`,`intro`,`mobile`,`email`,`org_id`,`gender`,`type`,`status`,`avatar`,`domain`,`create_by`,`create_time`,`update_by`,`update_time`,`del_flag`)
 		values
-		(?id,?password,?salt,?name,?full_name,?mobile,?email,?org_id,?gender,?type,?status,?avatar,?domain,?create_by,?create_time,?update_by,?update_time,?del_flag)
+		(?id,?password,?salt,?name,?full_name,?intro,?mobile,?email,?org_id,?gender,?type,?status,?avatar,?domain,?create_by,?create_time,?update_by,?update_time,?del_flag)
     </sql>
     <sql id="update_sys_user">
-        update sys_user set `id`=?id,`password`=?password,`salt`=?salt,`name`=?name,`full_name`=?full_name,`mobile`=?mobile,`email`=?email,`org_id`=?org_id,`gender`=?gender,`type`=?type,`status`=?status,`avatar`=?avatar,`domain`=?domain,`create_by`=?create_by,`create_time`=?create_time,`update_by`=?update_by,`update_time`=?update_time,`del_flag`=?del_flag
+        update sys_user set `id`=?id,`password`=?password,`salt`=?salt,`name`=?name,`full_name`=?full_name,`intro`=?intro,`mobile`=?mobile,`email`=?email,`org_id`=?org_id,`gender`=?gender,`type`=?type,`status`=?status,`avatar`=?avatar,`domain`=?domain,`create_by`=?create_by,`create_time`=?create_time,`update_by`=?update_by,`update_time`=?update_time,`del_flag`=?del_flag
 		where  id =?id
     </sql>
     <sql id="delete_sys_user">
@@ -14,10 +14,10 @@
 		where id =?id
     </sql>
     <sql id="selectone_sys_user">
-        select `id`,`password`,`salt`,`name`,`full_name`,`mobile`,`email`,`org_id`,`gender`,`type`,`status`,`avatar`,`domain`,`create_by`,`create_time`,`update_by`,`update_time`,`del_flag` from sys_user
+        select `id`,`password`,`salt`,`name`,`full_name`,`intro`,`mobile`,`email`,`org_id`,`gender`,`type`,`status`,`avatar`,`domain`,`create_by`,`create_time`,`update_by`,`update_time`,`del_flag` from sys_user
 		where  id =?id
     </sql>
     <sql id="selectall_sys_user">
-        select `id`,`password`,`salt`,`name`,`full_name`,`mobile`,`email`,`org_id`,`gender`,`type`,`status`,`avatar`,`domain`,`create_by`,`create_time`,`update_by`,`update_time`,`del_flag` from sys_user
+        select `id`,`password`,`salt`,`name`,`full_name`,`intro`,`mobile`,`email`,`org_id`,`gender`,`type`,`status`,`avatar`,`domain`,`create_by`,`create_time`,`update_by`,`update_time`,`del_flag` from sys_user
     </sql>
 </sqlMap>

+ 19 - 0
platform/sql/sys_menu/sys_menu_list_count.tpl

@@ -0,0 +1,19 @@
+select
+    count(*) records
+from
+	sys_menu
+{{if ne .isAdmin true}}
+left join sys_role_menu
+on
+    sys_menu.id = sys_role_menu.menu_id
+left join sys_user_role
+on 
+    sys_role_menu.role_id = sys_user_role.role_id
+left join sys_user
+on
+    sys_user_role.user_id = sys_user.id
+{{end}}
+where
+	sys_menu.id {{.ne}} ""
+	and
+    sys_menu.del_flag = 0

+ 20 - 0
platform/sql/sys_menu/sys_menu_list_select.tpl

@@ -0,0 +1,20 @@
+select
+    distinct sys_menu.id, sys_menu.parent, sys_menu.name, sys_menu.code, sys_menu.icon, sys_menu.order_num, sys_menu.url
+from
+	sys_menu
+{{if ne .isAdmin true}}
+left join sys_role_menu
+on
+    sys_menu.id = sys_role_menu.menu_id
+left join sys_user_role
+on 
+    sys_role_menu.role_id = sys_user_role.role_id
+left join sys_user
+on
+    sys_user_role.user_id = sys_user.id
+{{end}}
+where
+	sys_menu.id {{.ne}} ""
+	and
+    sys_menu.del_flag = 0
+	order by order_num

+ 0 - 6
platform/sql/sys_menu/sys_menu_page_count.tpl

@@ -1,6 +0,0 @@
-select
-    count(*) records
-from
-	sys_menu
-where
-	sys_menu.id {{.ne}} ""

+ 0 - 7
platform/sql/sys_menu/sys_menu_page_select.tpl

@@ -1,7 +0,0 @@
-select
-    sys_menu.id
-from
-	sys_menu
-where
-	sys_menu.id {{.ne}} ""
-LIMIT {{.size}} OFFSET {{.offset}}

+ 1 - 0
platform/xml/tables/sys_user.xml

@@ -4,6 +4,7 @@
 	<column name="salt" desc="盐噪点" type="null.String" xorm="varchar(36) notnull" />
 	<column name="name" desc="名字" type="null.String" xorm="varchar(36) notnull" />
 	<column name="full_name" desc="全名" type="null.String" xorm="varchar(36)" />
+	<column name="intro" desc="简介" type="null.String" xorm="text" />
 	<column name="mobile" desc="电话" type="null.String" xorm="varchar(50)" />
 	<column name="email" desc="邮箱" type="null.String" xorm="varchar(50)" />
 	<column name="org_id" desc="组织ID" type="null.String" xorm="varchar(36)" />

+ 1 - 1
test/app.properties

@@ -1,5 +1,5 @@
 app.name = dolphin
 http.port = 8082
-app.mode = release
+app.mode = debug
 wc.appid = wx756d2f0339adf67c
 wc.appecret = 9cc4b7928467151acea7ab1bfa0a70a7