zhou.xiaoning 4 년 전
부모
커밋
6e24443c25
2개의 변경된 파일61개의 추가작업 그리고 49개의 파일을 삭제
  1. 2 1
      .gitignore
  2. 59 48
      permission_generator/main.go

+ 2 - 1
.gitignore

@@ -24,4 +24,5 @@ _testmain.go
 *.test
 *.prof
 
-permission_generator/out
+permission_generator/out
+permission_generator/buildsql

+ 59 - 48
permission_generator/main.go

@@ -116,28 +116,33 @@ func buildSQL(datas []interface{}, parentCode string, level int) string {
 	for i, v := range datas {
 		data := v.(map[string]interface{})
 		var (
-			remark string
+			remark  string
+			rulekey string
 		)
 
-		if data["remark"] != nil {
-			remark = data["remark"].(string)
-		}
-
-		sql += "INSERT INTO FUNCMENULIST (RESOURCECODE, RESOURCENAME, RESOURCELEVEL, MENUTYPE, PARENTCODE, URL, SORT, ICONAME, REMARK)\n"
-		if parentCode == "" {
-			sql += fmt.Sprintf("VALUES('%s', '%s', %d, 3, NULL, '', %d, '', '%s');\n", data["code"].(string), data["title"].(string), level, i+1, remark)
-		} else {
-			sql += fmt.Sprintf("VALUES('%s', '%s', %d, 3, '%s', '', %d, '', '%s');\n", data["code"].(string), data["title"].(string), level, parentCode, i+1, remark)
-		}
-
-		// 递归
-		sub := data["children"].([]interface{})
-		if len(sub) > 0 {
-			sql += buildSQL(data["children"].([]interface{}), data["code"].(string), level+1)
-		}
-
-		if level == 1 {
-			sql += "\n"
+		if data["rulekey"] != nil {
+			rulekey = data["rulekey"].(string)
+
+			if data["remark"] != nil {
+				remark = data["remark"].(string)
+			}
+
+			sql += "INSERT INTO FUNCMENULIST (RESOURCECODE, RESOURCENAME, RESOURCELEVEL, MENUTYPE, PARENTCODE, URL, SORT, ICONAME, REMARK)\n"
+			if parentCode == "" {
+				sql += fmt.Sprintf("VALUES('%s', '%s', %d, 3, NULL, '', %d, '', '%s');\n", rulekey, data["title"].(string), level, i+1, remark)
+			} else {
+				sql += fmt.Sprintf("VALUES('%s', '%s', %d, 3, '%s', '', %d, '', '%s');\n", rulekey, data["title"].(string), level, parentCode, i+1, remark)
+			}
+
+			// 递归
+			sub := data["children"].([]interface{})
+			if len(sub) > 0 {
+				sql += buildSQL(data["children"].([]interface{}), data["code"].(string), level+1)
+			}
+
+			if level == 1 {
+				sql += "\n"
+			}
 		}
 	}
 
@@ -151,38 +156,44 @@ func buildPCWEBSQL(datas []interface{}, parentCode string, level int) string {
 	for i, v := range datas {
 		data := v.(map[string]interface{})
 		var (
-			remark string
+			remark  string
+			rulekey string
 		)
 
-		if data["remark"] != nil {
-			remark = data["remark"].(string)
-		}
-
-		title := ""
-		if data["title"] != nil {
-			title = data["title"].(string)
-		} else {
-			title = data["label"].(string)
-		}
-
-		sql += "INSERT INTO FUNCMENULIST (RESOURCECODE, RESOURCENAME, RESOURCELEVEL, MENUTYPE, PARENTCODE, URL, SORT, ICONAME, REMARK)\n"
-		if parentCode == "" {
-			sql += fmt.Sprintf("VALUES('%s', '%s', %d, 5, NULL, '', %d, '', '%s');\n", data["code"].(string), title, level, i+1, remark)
-		} else {
-			sql += fmt.Sprintf("VALUES('%s', '%s', %d, 5, '%s', '', %d, '', '%s');\n", data["code"].(string), title, level, parentCode, i+1, remark)
+		if data["rulekey"] != nil {
+			rulekey = data["rulekey"].(string)
+
+			if data["remark"] != nil {
+				remark = data["remark"].(string)
+			}
+
+			title := ""
+			if data["title"] != nil {
+				title = data["title"].(string)
+			} else {
+				title = data["label"].(string)
+			}
+
+			sql += "INSERT INTO FUNCMENULIST (RESOURCECODE, RESOURCENAME, RESOURCELEVEL, MENUTYPE, PARENTCODE, URL, SORT, ICONAME, REMARK)\n"
+			if parentCode == "" {
+				sql += fmt.Sprintf("VALUES('%s', '%s', %d, 5, NULL, '', %d, '', '%s');\n", rulekey, title, level, i+1, remark)
+			} else {
+				sql += fmt.Sprintf("VALUES('%s', '%s', %d, 5, '%s', '', %d, '', '%s');\n", rulekey, title, level, parentCode, i+1, remark)
+			}
+
+			// 递归
+			if data["auth"] != nil {
+				sql += buildPCWEBSQL(data["auth"].([]interface{}), data["code"].(string), level+1)
+			}
+			if data["children"] != nil {
+				sql += buildPCWEBSQL(data["children"].([]interface{}), data["code"].(string), level+1)
+			}
+
+			if level == 1 {
+				sql += "\n"
+			}
 		}
 
-		// 递归
-		if data["auth"] != nil {
-			sql += buildPCWEBSQL(data["auth"].([]interface{}), data["code"].(string), level+1)
-		}
-		if data["children"] != nil {
-			sql += buildPCWEBSQL(data["children"].([]interface{}), data["code"].(string), level+1)
-		}
-
-		if level == 1 {
-			sql += "\n"
-		}
 	}
 
 	return sql