|
@@ -13,6 +13,7 @@ import (
|
|
|
"github.com/gin-contrib/sessions"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
+ "fmt"
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
@@ -25,6 +26,9 @@ func init() {
|
|
|
Admin.GET("/menu", func(c *gin.Context) {
|
|
|
c.HTML(http.StatusOK, "menu.html", gin.H{})
|
|
|
})
|
|
|
+ Admin.GET("/infotype", func(c *gin.Context) {
|
|
|
+ c.HTML(http.StatusOK, "class.html", gin.H{})
|
|
|
+ })
|
|
|
Admin.GET("/role", func(c *gin.Context) {
|
|
|
c.HTML(http.StatusOK, "role.html", gin.H{})
|
|
|
})
|
|
@@ -46,6 +50,13 @@ func init() {
|
|
|
Admin.POST("/menu/data", MenuData)
|
|
|
Admin.POST("/menu/searchbyid", MenuSearchById)
|
|
|
Admin.POST("/menu/del", MenuDel)
|
|
|
+ Admin.POST("/infotype/data", InfotypeData)
|
|
|
+ Admin.POST("/fields/data", FieldsData)
|
|
|
+ Admin.POST("/topclass/data", TopclassData)
|
|
|
+ Admin.POST("/subclass/data", SubclassData)
|
|
|
+ Admin.POST("/infotype/save", InfotypeSave)
|
|
|
+ Admin.POST("/infotype/select", InfotypeSelect)
|
|
|
+ Admin.POST("/infotype/del", InfotypeDel)
|
|
|
Admin.POST("/role/menu/data", RoleMenuData)
|
|
|
Admin.POST("/role/menu/save", RoleMenuSave)
|
|
|
Admin.POST("/role/select", RoleSelect)
|
|
@@ -84,6 +95,203 @@ func SecondMenuData(c *gin.Context) {
|
|
|
data, _ := Mgo.Find("menusecond", maps, nil, nil, false, -1, -1)
|
|
|
c.JSON(200, gin.H{"data": data})
|
|
|
}
|
|
|
+func InfotypeData(c *gin.Context) {
|
|
|
+ datas, _ := Mgo.Find("infotype", `{}`, nil, nil, false, -1, -1)
|
|
|
+ list:=[]map[string]interface{}{}
|
|
|
+ for _,data:=range *datas{
|
|
|
+ if data["subclass"]==nil{
|
|
|
+ data["subclass"]=""
|
|
|
+ list=append(list,data)
|
|
|
+ }else{
|
|
|
+ for k,_:=range data["subclass"].(map[string]interface{}){
|
|
|
+ value:=map[string]interface{}{
|
|
|
+ "_id":data["_id"],
|
|
|
+ "topclass":data["topclass"],
|
|
|
+ "subclass":k,
|
|
|
+ }
|
|
|
+ list=append(list,value)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.JSON(200, gin.H{"data": list})
|
|
|
+}
|
|
|
+func FieldsData(c *gin.Context){
|
|
|
+ datas, _ := Mgo.Find("fields", `{}`, nil, nil, false, -1, -1)
|
|
|
+ c.JSON(200, gin.H{"data": datas})
|
|
|
+}
|
|
|
+func TopclassData(c *gin.Context){
|
|
|
+ datas, _ := Mgo.Find("infoclass", `{}`, nil, nil, false, -1, -1)
|
|
|
+ c.JSON(200, gin.H{"data": datas})
|
|
|
+}
|
|
|
+func SubclassData(c *gin.Context){
|
|
|
+ topclass, _ := c.GetPostForm("top")
|
|
|
+ datas, _ := Mgo.FindOneByField("infoclass",`{"topclass":"`+topclass+`"}`,`{"subclass":"1"}`)
|
|
|
+ data:=*datas
|
|
|
+ if data["subclass"]!=nil{
|
|
|
+ c.JSON(200, gin.H{"data": datas})
|
|
|
+ }
|
|
|
+}
|
|
|
+func InfotypeSave(c *gin.Context){
|
|
|
+ topclass, _ := c.GetPostForm("topclass")
|
|
|
+ subclass, _ := c.GetPostForm("subclass")
|
|
|
+ fieldsStr, _ := c.GetPostForm("fields")
|
|
|
+ fieldsStr2, _ := c.GetPostForm("fields2")
|
|
|
+ _id,_:=c.GetPostForm("_id")
|
|
|
+ fields := make([]string, 0)
|
|
|
+ err := json.Unmarshal([]byte(fieldsStr), &fields)
|
|
|
+ fields2 := make([]string, 0)
|
|
|
+ err2 := json.Unmarshal([]byte(fieldsStr2), &fields2)
|
|
|
+ if _id=="" {
|
|
|
+ b := Mgo.Count("infotype", map[string]interface{}{
|
|
|
+ "topclass": topclass,
|
|
|
+ })
|
|
|
+ b2 := 0
|
|
|
+ if subclass != "" {
|
|
|
+ b2 = Mgo.Count("infotype", map[string]interface{}{
|
|
|
+ "subclass." + subclass: map[string]interface{}{
|
|
|
+ "$exists": true,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (b == 0)||(b!=0&&b2==0&&subclass!=""){
|
|
|
+ if err == nil {
|
|
|
+ if subclass == "" {
|
|
|
+ maps := map[string]interface{}{
|
|
|
+ "topclass": topclass,
|
|
|
+ "fields": map[string]interface{}{},
|
|
|
+ }
|
|
|
+ for _, field := range fields {
|
|
|
+ maps["fields"].(map[string]interface{})[field] = true
|
|
|
+ }
|
|
|
+ Mgo.Save("infotype", maps)
|
|
|
+ } else {
|
|
|
+ maps := map[string]interface{}{
|
|
|
+ }
|
|
|
+ for _, field := range fields {
|
|
|
+ maps = map[string]interface{}{
|
|
|
+ "subclass." + subclass + "." + field: true,
|
|
|
+ }
|
|
|
+ maps2 := map[string]interface{}{
|
|
|
+ "$set": maps,
|
|
|
+ }
|
|
|
+ set := map[string]interface{}{
|
|
|
+ "topclass": topclass,
|
|
|
+ }
|
|
|
+ Mgo.Update("infotype", set, maps2, true, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.JSON(200, gin.H{"rep": true})
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if err == nil && err2==nil{
|
|
|
+ set:=map[string]interface{}{
|
|
|
+ "_id":bson.ObjectIdHex(_id),
|
|
|
+ }
|
|
|
+ if subclass == "" {
|
|
|
+ maps := map[string]interface{}{
|
|
|
+ "fields": map[string]interface{}{},
|
|
|
+ }
|
|
|
+ for _, field := range fields {
|
|
|
+ maps["fields"].(map[string]interface{})[field] = true
|
|
|
+ }
|
|
|
+ maps2:=map[string]interface{}{
|
|
|
+ "$set":maps,
|
|
|
+ }
|
|
|
+ Mgo.Update("infotype", set, maps2, false, false)
|
|
|
+ } else {
|
|
|
+ maps := map[string]interface{}{
|
|
|
+ "subclass."+subclass:map[string]interface{}{},
|
|
|
+ }
|
|
|
+ for _, field := range fields {
|
|
|
+ maps["subclass."+subclass].(map[string]interface{})[field] = true
|
|
|
+ maps2 := map[string]interface{}{
|
|
|
+ "$set": maps,
|
|
|
+ }
|
|
|
+ Mgo.Update("infotype", set, maps2, false, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.JSON(200, gin.H{"rep": true})
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+func InfotypeSelect(c *gin.Context) {
|
|
|
+ _id, _ := c.GetPostForm("_id")
|
|
|
+ subclass, _ := c.GetPostForm("subclass")
|
|
|
+ fmt.Println(_id)
|
|
|
+ fmt.Println(subclass)
|
|
|
+ one1,_:=Mgo.FindById("infotype",_id,`{}`)
|
|
|
+ one:=*one1
|
|
|
+ datas, _ := Mgo.Find("fields", `{}`, nil, nil, false, -1, -1)
|
|
|
+ datas2:=*datas
|
|
|
+ //list2:=[]map[string]interface{}{}
|
|
|
+ if one["subclass"]==nil{
|
|
|
+ list:=[]interface{}{}
|
|
|
+ for k,v:=range one["fields"].(map[string]interface{}){
|
|
|
+ if v==true{
|
|
|
+ s_name1,_:=Mgo.FindOneByField("fields",map[string]interface{}{"s_field":k},`{}`)
|
|
|
+ s_name:=*s_name1
|
|
|
+ //已存在属性
|
|
|
+ list=append(list,s_name)
|
|
|
+ for key,value:=range datas2{
|
|
|
+ if value["s_field"]==k{
|
|
|
+ datas2 = append(datas2[:key], datas2[key+1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println(one["topclass"].(string),list)
|
|
|
+ c.JSON(200, gin.H{"topclass": one["topclass"].(string), "subclass": "","fields2":datas2, "fields": list})
|
|
|
+ }else{
|
|
|
+ maps:=one["subclass"].(map[string]interface{})[subclass]
|
|
|
+ list:=[]interface{}{}
|
|
|
+ for k,v:=range maps.(map[string]interface{}){
|
|
|
+ if v==true{
|
|
|
+ s_name1,_:=Mgo.FindOneByField("fields",map[string]interface{}{"s_field":k},`{}`)
|
|
|
+ s_name:=*s_name1
|
|
|
+ list=append(list,s_name)
|
|
|
+ for key,value:=range datas2{
|
|
|
+ if value["s_field"]==k{
|
|
|
+ datas2 = append(datas2[:key], datas2[key+1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println(one["topclass"].(string),subclass,list)
|
|
|
+ c.JSON(200, gin.H{"topclass": one["topclass"].(string), "subclass":subclass,"fields2":datas2, "fields": list})
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+func InfotypeDel(c *gin.Context) {
|
|
|
+ _id, _ := c.GetPostForm("_id")
|
|
|
+ subclass, _ := c.GetPostForm("subclass")
|
|
|
+ set:=map[string]interface{}{
|
|
|
+ "_id":bson.ObjectIdHex(_id),
|
|
|
+ }
|
|
|
+ if subclass==""{
|
|
|
+ b:=Mgo.Del("infotype",set)
|
|
|
+ c.JSON(200, gin.H{"rep": b})
|
|
|
+ }else{
|
|
|
+ info1,_:=Mgo.FindById("infotype",_id,`{}`)
|
|
|
+ info:=*info1
|
|
|
+ maps:=info["subclass"].(map[string]interface{})
|
|
|
+ delete(maps,subclass)
|
|
|
+ if len(maps)==0{
|
|
|
+ b:=Mgo.Del("infotype",set)
|
|
|
+ c.JSON(200, gin.H{"rep": b})
|
|
|
+ }else{
|
|
|
+ maps2:=map[string]interface{}{
|
|
|
+ "subclass":maps,
|
|
|
+ }
|
|
|
+ maps3:=map[string]interface{}{
|
|
|
+ "$set":maps2,
|
|
|
+ }
|
|
|
+ b:=Mgo.Update("infotype",set,maps3,false,false)
|
|
|
+ c.JSON(200, gin.H{"rep": b})
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
func RoleMenuData(c *gin.Context) {
|
|
|
role, _ := c.GetPostForm("role")
|
|
|
maps := map[string]interface{}{
|