| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 | package controllersimport (	"strings"	"testbench/models/etc"	"testbench/models/statusMgr"	"wb/cc"	"wb/cfg"	"wb/ctrl"	"wb/ctrl/uibuilder"	"wb/gis"	"wb/ii"	"wb/lg"	"wb/om"	"wb/st"	"wb/ut")type ElectricController struct {    ctrl.ItemController}func (this *ElectricController) NestPrepare() {    this.CtxItemInfo, _ = ii.ItemInfoMap["electric"]}func (this *ElectricController) 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 *ElectricController) 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 = om.TransDateTime(oItemInfo, 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 *ElectricController) UiStatus() {	sn := this.getSn()	if sn == "" {		lg.Error("ElectricController.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 = "electric/main.tpl"}func (this *ElectricController) UiBEStatus() {	sn := this.getSn()	if sn == "" {		lg.Error("ElectricController.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 = "electric/bemain.tpl"}func (this *ElectricController) UiHYDStatus() {	sn := this.getSn()	if sn == "" {		lg.Error("ElectricController.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 = "electric/hydmain.tpl"}func (c *ElectricController) 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 *ElectricController) ApiOnlinePosition(){    lstPos := statusMgr.WPStatusMgr.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)}
 |