package BasePurviewService import ( "dsBaseWeb/Business/BasePurview/BasePurviewProto" "encoding/json" "strings" ) func AddPurviewInfo(purviewName string, businessCode string, purviewType int32, menuUrl string, parentId string, sortId int32,actionPersonId string,actionIpAddress string) (*BasePurviewProto.Reply, error) { Reply, err := AddBasePurview(BasePurviewProto.ModelArg{PurviewName: purviewName, BusinessCode: businessCode, PurviewType: purviewType, MenuUrl: menuUrl, ParentId: parentId, SortId: sortId, BUse: 1, ActionPersonId: actionPersonId, ActionIpAddress: actionIpAddress}) return Reply, err } func DeletePurviewInfo(ids string,actionPersonId string,actionIpAddress string) (*BasePurviewProto.Reply, error) { idsArr := strings.Split(ids, ",") Reply, err := DeleteBasePurview(BasePurviewProto.DeleteIdsArg{Ids: idsArr, ActionPersonId: actionPersonId, ActionIpAddress: actionIpAddress}) return Reply, err } func UpdatePurviewInfo(purviewId string, purviewName string, businessCode string, purviewType int32, menuUrl string, sortId int32,actionPersonId string,actionIpAddress string) (*BasePurviewProto.Reply, error) { Reply, err := UpdateBasePurview(BasePurviewProto.ModelArg{PurviewId: purviewId, PurviewName: purviewName, BusinessCode: businessCode, PurviewType: purviewType, MenuUrl: menuUrl, SortId: sortId, ActionPersonId: actionPersonId, ActionIpAddress: actionIpAddress}) return Reply, err } func GetPurviewInfoById(purviewId string,actionPersonId string,actionIpAddress string) (*BasePurviewProto.Reply, error) { Reply, err := GetBasePurview(BasePurviewProto.ModelArg{PurviewId: purviewId, ActionPersonId: actionPersonId, ActionIpAddress: actionIpAddress}) return Reply, err } func PagePurviewInfoByBusinessCode(page int32, limit int32, businessCode string,actionPersonId string,actionIpAddress string) (*BasePurviewProto.Reply, error) { Reply, err := PageBasePurview(BasePurviewProto.QueryArg{Page: page, Limit: limit, BusinessCode: businessCode, ActionPersonId: actionPersonId, ActionIpAddress: actionIpAddress}) return Reply, err } func PagePurviewInfoByPersonIdBusinessCode(page int32, limit int32, personId string, businessCode string,actionPersonId string,actionIpAddress string) (*BasePurviewProto.Reply, error) { Reply, err := PageBasePurview(BasePurviewProto.QueryArg{Page: page, Limit: limit, PersonId: personId, BusinessCode: businessCode, ActionPersonId: actionPersonId, ActionIpAddress: actionIpAddress}) afterConversion := convertPurviewTree(Reply.List) Reply.List = afterConversion return Reply, err } func convertPurviewTree(strJson string) string { var originalArr []Original var oneLevelArr []OneLevel twoLevelMap := make(map[string][]Original) json.Unmarshal([]byte(strJson), &originalArr) for i := 0; i < len(originalArr); i++ { jsonObj := originalArr[i] if jsonObj.ParentId != "00000000-0000-0000-0000-000000000000" { res, exist := twoLevelMap[jsonObj.ParentId] if exist { res = append(res, jsonObj) twoLevelMap[jsonObj.ParentId] = res } else { var tempOriginalArr []Original tempOriginalArr = append(tempOriginalArr, jsonObj) twoLevelMap[jsonObj.ParentId] = tempOriginalArr } } else { var oneLevel OneLevel oneLevel.PurviewId = jsonObj.PurviewId oneLevel.ParentId = jsonObj.ParentId oneLevel.PurviewName = jsonObj.PurviewName oneLevel.MenuUrl = jsonObj.MenuUrl oneLevel.MenuIcon = jsonObj.MenuIcon oneLevel.SortId = jsonObj.SortId oneLevelArr = append(oneLevelArr, oneLevel) } } for i := 0; i < len(oneLevelArr); i++ { jsonObj := oneLevelArr[i] res, exist := twoLevelMap[jsonObj.PurviewId] if exist { oneLevelArr[i].Child = res } } oneLevelByte, _ := json.Marshal(oneLevelArr) return string(oneLevelByte) } type OneLevel struct { PurviewId string `json:"purview_id"` ParentId string `json:"parent_id"` PurviewName string `json:"purview_name"` MenuUrl string `json:"menu_url"` MenuIcon string `json:"menu_icon"` SortId string `json:"sort_id"` Child []Original `json:"child"` } type Original struct { PurviewId string `json:"purview_id"` ParentId string `json:"parent_id"` PurviewName string `json:"purview_name"` MenuUrl string `json:"menu_url"` MenuIcon string `json:"menu_icon"` SortId string `json:"sort_id"` }