package init

import (
	MC "app.yhyue.com/moapp/jybase/common"
	"fmt"
	"strings"
)

type labelStruct struct {
	Code        string `json:"code"`
	Title       string `json:"title"`
	Keywords    string `json:"keywords"`
	Description string `json:"description"`
	Url         string `json:"url"`
}

var LabelMap = map[string]labelStruct{}

/*
*包含地区标签、信息类型标签、行业标签；
*1、SEO信息展示
*2、地区标签访问地址
 */

func LabelInit() {
	labelList := MainMysql.SelectBySql(`select * from jy_label where status = ?`, 0)
	if labelList != nil && len(*labelList) > 0 {
		for _, v := range *labelList {
			names := MC.ObjToString(v["name"])
			url := ""
			switch MC.IntAll(v["mold"]) {
			case 1:
				url = fmt.Sprintf(C.LabelUrl.Area, MC.ObjToString(v["code"]))
			case 2:
				url = fmt.Sprintf(C.LabelUrl.Industry, MC.ObjToString(v["code"]))
			case 3:
				url = fmt.Sprintf(C.LabelUrl.SType, MC.ObjToString(v["code"]))
			}
			for _, nv := range strings.Split(names, ",") {
				LabelMap[nv] = labelStruct{
					Code:        MC.ObjToString(v["code"]),
					Title:       MC.ObjToString(v["title"]),
					Keywords:    MC.ObjToString(v["keywords"]),
					Description: MC.ObjToString(v["description"]),
					Url:         url,
				}
			}
		}
	}
}
