| | |
| | | "basic.com/valib/bhomeclient.git" |
| | | "basic.com/valib/bhomedbapi.git" |
| | | "basic.com/valib/logger.git" |
| | | "github.com/satori/go.uuid" |
| | | uuid "github.com/satori/go.uuid" |
| | | ) |
| | | |
| | | type DictionaryController struct { |
| | | } |
| | | |
| | | type DicTypeVo struct { |
| | | Type string `json:"type"` |
| | | Dics []DicWithChildren `json:"dics"` |
| | | Type string `json:"type"` |
| | | Dics []DicWithChildren `json:"dics"` |
| | | } |
| | | |
| | | type DicWithChildren struct { |
| | | models.Dictionary |
| | | Children []DicWithChildren `json:"children"` |
| | | Children []DicWithChildren `json:"children"` |
| | | } |
| | | |
| | | type DicList []DicWithChildren |
| | | func (dl DicList) Len()int { |
| | | |
| | | func (dl DicList) Len() int { |
| | | return len(dl) |
| | | } |
| | | func (dl DicList) Swap(i,j int) { |
| | | dl[i],dl[j] = dl[j],dl[i] |
| | | func (dl DicList) Swap(i, j int) { |
| | | dl[i], dl[j] = dl[j], dl[i] |
| | | } |
| | | func (dl DicList) Less(i,j int) bool { |
| | | func (dl DicList) Less(i, j int) bool { |
| | | return dl[i].Sort < dl[j].Sort |
| | | } |
| | | |
| | | func recursiveChildren(parentId string, allList *[]models.Dictionary) []DicWithChildren { |
| | | var children = make([]DicWithChildren, 0) |
| | | for _,d := range *allList { |
| | | for _, d := range *allList { |
| | | if d.ParentId == parentId { |
| | | dwc := DicWithChildren{} |
| | | dwc.Dictionary = d |
| | |
| | | resMap := make(map[string]DicList, 0) |
| | | |
| | | wg := &sync.WaitGroup{} |
| | | wg.Add(4) |
| | | wg.Add(2) |
| | | go func() { |
| | | defer wg.Done() |
| | | for _, dic := range allDics { |
| | |
| | | } |
| | | } |
| | | }() |
| | | //人员底库 |
| | | personTableList := make(DicList, 0) |
| | | var tableApi bhomedbapi.DbTableApi |
| | | go func() { |
| | | defer wg.Done() |
| | | personTables, dtErr := tableApi.FindAllDbTablesByType("0", "person") |
| | | if dtErr == nil && personTables != nil { |
| | | for idx, t := range personTables { |
| | | dwc := DicWithChildren{} |
| | | dwc.Dictionary = models.Dictionary{ |
| | | Value: t.Id, |
| | | Name: t.TableName, |
| | | Sort: idx + 1, |
| | | } |
| | | personTableList = append(personTableList, dwc) |
| | | } |
| | | } |
| | | }() |
| | | // 车辆底库 |
| | | carTableList := make(DicList, 0) |
| | | go func() { |
| | | defer wg.Done() |
| | | carTables, _ := tableApi.FindAllDbTablesByType("0", "car") |
| | | if carTables != nil { |
| | | for idx, t := range carTables { |
| | | dwc := DicWithChildren{} |
| | | dwc.Dictionary = models.Dictionary{ |
| | | Value: t.Id, |
| | | Name: t.TableName, |
| | | Sort: idx + 1, |
| | | } |
| | | carTableList = append(carTableList, dwc) |
| | | } |
| | | } |
| | | }() |
| | | // //人员底库 |
| | | // personTableList := make(DicList, 0) |
| | | // var tableApi bhomedbapi.DbTableApi |
| | | // go func() { |
| | | // defer wg.Done() |
| | | // personTables, dtErr := tableApi.FindAllDbTablesByType("0", "person") |
| | | // if dtErr == nil && personTables != nil { |
| | | // for idx, t := range personTables { |
| | | // dwc := DicWithChildren{} |
| | | // dwc.Dictionary = models.Dictionary{ |
| | | // Value: t.Id, |
| | | // Name: t.TableName, |
| | | // Sort: idx + 1, |
| | | // } |
| | | // personTableList = append(personTableList, dwc) |
| | | // } |
| | | // } |
| | | // }() |
| | | // // 车辆底库 |
| | | // carTableList := make(DicList, 0) |
| | | // go func() { |
| | | // defer wg.Done() |
| | | // carTables, _ := tableApi.FindAllDbTablesByType("0", "car") |
| | | // if carTables != nil { |
| | | // for idx, t := range carTables { |
| | | // dwc := DicWithChildren{} |
| | | // dwc.Dictionary = models.Dictionary{ |
| | | // Value: t.Id, |
| | | // Name: t.TableName, |
| | | // Sort: idx + 1, |
| | | // } |
| | | // carTableList = append(carTableList, dwc) |
| | | // } |
| | | // } |
| | | // }() |
| | | |
| | | wg.Wait() |
| | | |
| | | resMap["time_rule"] = timeList |
| | | resMap["compareBase"] = personTableList |
| | | resMap["compareCarBase"] = carTableList |
| | | // resMap["compareBase"] = personTableList |
| | | // resMap["compareCarBase"] = carTableList |
| | | |
| | | for k, dList := range resMap { |
| | | v := dList |
| | |
| | | func (controller DictionaryController) FindByParentId(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply { |
| | | parentId := c.Query("parentId") |
| | | if parentId == "" { |
| | | return &bhomeclient.Reply{ Msg: "参数有误"} |
| | | return &bhomeclient.Reply{Msg: "参数有误"} |
| | | } |
| | | var model models.Dictionary |
| | | if flag, err := model.SelectById(parentId); !flag && err == nil { |
| | |
| | | Value: "", |
| | | Name: "空", |
| | | } |
| | | return &bhomeclient.Reply{ Success: true, Data: []models.Dictionary{empty} } |
| | | return &bhomeclient.Reply{Success: true, Data: []models.Dictionary{empty}} |
| | | } else { |
| | | dics, err := model.FindByParentId(parentId) |
| | | if err != nil { |
| | | return &bhomeclient.Reply{ Msg: "查询失败"} |
| | | return &bhomeclient.Reply{Msg: "查询失败"} |
| | | } else { |
| | | return &bhomeclient.Reply{ Success:true, Data: dics } |
| | | return &bhomeclient.Reply{Success: true, Data: dics} |
| | | } |
| | | } |
| | | } else { |
| | | return &bhomeclient.Reply{ Msg: "查询失败"} |
| | | return &bhomeclient.Reply{Msg: "查询失败"} |
| | | } |
| | | } |
| | | |
| | | |
| | | // @Summary 根据type查找字典列表 |
| | | // @Description 根据type查找字典列表 |
| | |
| | | func (controller DictionaryController) ListByType(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply { |
| | | typ := c.Query("type") |
| | | if typ == "" { |
| | | return &bhomeclient.Reply{ Msg: "参数有误"} |
| | | return &bhomeclient.Reply{Msg: "参数有误"} |
| | | } |
| | | var model models.Dictionary |
| | | dics, err := model.FindByType(typ) |
| | | if err == nil { |
| | | return &bhomeclient.Reply{ Success:true, Data: dics } |
| | | return &bhomeclient.Reply{Success: true, Data: dics} |
| | | } else { |
| | | return &bhomeclient.Reply{ Msg: "查询失败"} |
| | | return &bhomeclient.Reply{Msg: "查询失败"} |
| | | } |
| | | } |
| | | |
| | |
| | | func (controller DictionaryController) Save(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply { |
| | | var model models.Dictionary |
| | | if err := c.BindJSON(&model); err != nil { |
| | | return &bhomeclient.Reply{ Msg: "参数有误"} |
| | | return &bhomeclient.Reply{Msg: "参数有误"} |
| | | } |
| | | var flag bool |
| | | if model.Id == "" { |
| | |
| | | } |
| | | |
| | | if !flag { |
| | | return &bhomeclient.Reply{ Msg: "保存失败"} |
| | | return &bhomeclient.Reply{Msg: "保存失败"} |
| | | } else { |
| | | return &bhomeclient.Reply{ Success:true, Msg: "保存成功"} |
| | | return &bhomeclient.Reply{Success: true, Msg: "保存成功"} |
| | | } |
| | | } |