// entname
package spider

import (
	"encoding/json"
	"fmt"
	"log"
	mu "mfw/util"
)

//从消息服务器获取企业名录
func GetEntName(code string) []interface{} {
	tmp := []interface{}{}
	msgid := mu.UUID(8)
	ret, err := Msclient.Call("", msgid, mu.SERVICE_GETNAME, mu.SENDTO_TYPE_RAND_RECIVER, map[string]interface{}{"code": code}, 60)
	if err != nil {
		log.Println("getEntName err:", err)
		return nil
	} else {
		json.Unmarshal(ret, &tmp)
		return resetMapList(tmp)
	}
}

//数据类型转换
func resetMapList(s []interface{}) (ret []interface{}) {
	for _, v := range s {
		if tmp, ok := v.(map[string]interface{}); ok {
			ent := map[string]string{}
			for k1, v1 := range tmp {
				ent[k1] = fmt.Sprint(v1)
			}
			ret = append(ret, ent)
		}
	}
	return ret
}
