| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 | package controllersimport (	"wb/cs"	"wb/ctrl"	"wb/ctrl/uibuilder"	"wb/ii"	"wb/om"	"wb/lg"	"wb/cc"	"wb/st"	"eps/models/etc"	"strings"    "wb/ut"    "wb/cfg"    "eps/models/statusMgr"    "wb/gis"    "fmt")type EpsController struct {    ctrl.ItemController}func (this *EpsController) NestPrepare() {    this.CtxItemInfo, _ = ii.ItemInfoMap["eps"]}func (this *EpsController) UiAdd() {    _, companys := om.Table(etc.Tbl.Company).GetAll()    this.Data["CompanyOptions"] = uibuilder.BuildSelectOptions(companys, "", cc.Col.Sn, cc.Col.Name)    this.UiAddItem(this.CtxItemInfo)}func (this *EpsController) UiUpdate() {    oItemInfo := this.CtxItemInfo    itemName := oItemInfo.Name    sn := this.GetString(cc.Col.Sn)    if sn == "" {        lg.Error("ui.Update", st.ParamSnIsNone)        this.Ctx.WriteString(st.ParamSnIsNone)        return    }    params := om.Params{cc.Col.Sn: sn}    c, oldValueMap := om.Table(itemName).Get(params)    oldValueMap = oItemInfo.FormatDateTimeInMObject(oldValueMap)    if c == st.Success {        this.SetDataWithoutDefaultStr(cc.UrlService, this.UrlItemUpdate, "/item/update/" + itemName)        this.Data["Sn"] = sn        this.Data["Form"] = uibuilder.BuildUpdatedForm(oItemInfo, oldValueMap)        this.Data["Onload"] = uibuilder.BuildUpdateOnLoadJs(oItemInfo)        customTpl := cfg.WebConfig.ViewsPath + "/" + oItemInfo.Name + "/" + "update.tpl"        if ut.IsPathExist(customTpl){            this.FillValue(oldValueMap)            this.FillFormElement(uibuilder.BuildFormElement(oItemInfo, oldValueMap, map[string]string{}))            this.TplName = oItemInfo.Name + "/" + "update.tpl"        }else{            this.TplName = this.TplUpdate        }        _, companys := om.Table(etc.Tbl.Company).GetAll()        selectdCompany := oldValueMap.GetString(etc.Col.Company)        this.Data["CompanyOptions"] = uibuilder.BuildSelectOptions(companys, selectdCompany, cc.Col.Sn, cc.Col.Name)        lg.Debug("UiUpdateItem tpl", this.TplName)    } else {        lg.Error("UiUpdateItem error", st.ItemNotFound)        this.Ctx.WriteString(st.ItemNotFound)    }}func (this *EpsController) UiDetail() {    sid := this.Ctx.Input.Param(":hi")    if sid == ""{        this.Ctx.WriteString("No sid")    }    this.Data["DeviceId"] = sid    this.TplName = "eps/detail.tpl"}func (this *EpsController) UiStatus() {	sn := this.getSn()	if sn == "" {		lg.Error("EpsController.UiStatus ", st.ParamSnIsNone)		this.Ctx.WriteString("请提供正确的序列号!")		return	}	params := om.Params{etc.Sid: sn}	code, oldValueMap := om.Table(etc.Tbl.Wp).Get(params)	this.Data["DeviceName"] = "设备*"	if code == "success"{        this.Data["DeviceName"] = ut.Maps.GetString(oldValueMap, cc.Col.Name)        this.Data["RatePower"], _ = ut.Maps.GetFloat64(oldValueMap, "gsratedpower")	}	this.Data["DeviceId"] = sn	this.TplName = "eps/main.tpl"}func (c *EpsController) Status() {	sn := c.getSn()	if sn == "" {		lg.Error("EpsController.Status ", st.ParamSnIsNone)		c.Ctx.WriteString("{}")		return	}	c.Data["json"] = statusMgr.GetStatus(sn)	c.ServeJSON()}func (this *EpsController) HistoryList() {    sid := this.Ctx.Input.Param(":hi")    if sid == ""{        this.Ctx.WriteString("{}")    }    queryParams, limitParams, orderByParams, searchText:= this.GetListPostParams()    queryParams[etc.Sid] = sid    searchParams := om.Params{}    if searchText != ""{        searchParams[cc.Col.CreateTime] = searchText    }    result, total, resultMaps := om.Table(etc.Tbl.Epsstatus).ListWithParamsWithDb(etc.DbNameEpsStatus, queryParams, searchParams, limitParams, orderByParams)    for _, vMap := range resultMaps{        vMap["createtime"] = ut.GetTimeStrFromDb(vMap.GetString("createtime"))        if flevel, ok := vMap.GetInt64("flevel");!ok || flevel < 0{            vMap["flevel"] = "#"        }        if opress, ok := vMap.GetInt64("opress");!ok || opress < 0{            vMap["opress"] = "#"        }        if etemp, ok := vMap.GetInt64("etemp");!ok || etemp < 0{            vMap["etemp"] = "#"        }    }    this.SendJson(&cs.TableResult{result, int64(total), resultMaps})}func (this *EpsController) UiHistory() {    sid := this.Ctx.Input.Param(":hi")    if sid == ""{        this.Ctx.WriteString("No sid")    }    this.Data["DeviceId"] = sid    this.Data["UrlItemList"] = "/eps/history/itemlist/" + sid    this.TplName = "eps/history.tpl"}func (c *EpsController) getSn()string{	sn := c.GetString(cc.Col.Sn)	sn = strings.TrimSpace(sn)	if sn == "" {	   lg.Error("GetStatus ", st.ParamSnIsNone)	   return ""	}	if len(sn) >= 16{	   return sn	}	iSn, err := c.GetInt64(cc.Col.Sn)	if err != nil{	   lg.Error("GetStatus ", st.ParamSnFormatError)	   return ""	}	sn = fmt.Sprintf("%016d", iSn)	return sn}func (c *EpsController) ApiOnlinePosition(){    lstPos := statusMgr.EPSStatusMgr.GetPositions()    lstPoint := make([]map[string]interface{}, len(lstPos))    for i, pos := range lstPos{        point := make(map[string]interface{})        lng, lat := gis.Wgs2bdWithDefaultByPt(pos)        point["id"]=ut.Maps.GetString(pos, "sid")        point["lng"] = lng        point["lat"] = lat        point["t"] = ut.Maps.GetString(pos, "t")        lstPoint[i] = point    }    retMap := make(map[string]interface{})    retMap["status"] = "success"    retMap["total"] = len(lstPoint)    retMap["rows"] = lstPoint    c.SendJson(retMap)}
 |