package config

import (
	"log"
	mu "mfw/util"
	"qfw/util"
	"qfw/util/mongodb"
	"strings"
	"sync"
)

var Udpclient mu.UdpClient //udp对象
var Sysconfig map[string]interface{}
var MgoIP, MgoDB, MgoC, MgoFileFiled, SidField, EidField string
var Sys sync.RWMutex
var Isjjr bool //节假日
//var IsRun bool = true
var tomail, api string

func init() {
	util.ReadConfig(&Sysconfig)
	MgoIP = util.ObjToString(Sysconfig["mongodb_ip"])
	MgoDB = util.ObjToString(Sysconfig["mongodb_db"])
	MgoC = util.ObjToString(Sysconfig["mongodb_c"])
	tomail = util.ObjToString(Sysconfig["tomail"])
	api = util.ObjToString(Sysconfig["api"])
	SidField = util.ObjToString(Sysconfig["json_sidfiled"])
	EidField = util.ObjToString(Sysconfig["json_eidfiled"])
	MgoFileFiled = util.ObjToStringDef(Sysconfig["mongodb_filefiled"], "projectinfo")
	if strings.TrimSpace(MgoIP) == "" || strings.TrimSpace(MgoDB) == "" || strings.TrimSpace(MgoC) == "" {
		log.Println("获取配置文件参数失败", Sysconfig)
		return
	}
	mongodb.InitMongodbPool(util.IntAllDef(Sysconfig["dbsize"], 5), MgoIP, MgoDB)

	Udpclient = mu.UdpClient{Local: Sysconfig["udpip"].(string) + ":" + Sysconfig["udpport"].(string), BufSize: 1024}

	go func() {
		SendEmail()
	}()
}
