| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 | 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")type WpvehicleController struct {    ctrl.ItemController}func (this *WpvehicleController) NestPrepare() {    this.CtxItemInfo, _ = ii.ItemInfoMap["wpvehicle"]}func (this *WpvehicleController) 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 *WpvehicleController) 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 *WpvehicleController) UiDetail() {    sid := this.Ctx.Input.Param(":hi")    if sid == ""{        this.Ctx.WriteString("No sid")    }    this.Data["DeviceId"] = sid    this.TplName = "wpvehicle/detail.tpl"}func (this *WpvehicleController) UiStatus() {	sn := this.getSn()	if sn == "" {		lg.Error("WpvehicleController.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 = "wpvehicle/main.tpl"}func (this *WpvehicleController) UiWpldStatus() {	sn := this.getSn()	if sn == "" {		lg.Error("WpvehicleController.UiWpldStatus ", st.ParamSnIsNone)		this.Ctx.WriteString("请提供正确的序列号!")		return	}	ssn := this.GetString("ssn")	this.Data["ssn"] = ssn	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 = "wpvehicle/wpldmain.tpl"}func (this *WpvehicleController) UiMotorStatus() {	sn := this.getSn()	//if sn == "" {	//	lg.Error("WpvehicleController.UiMotorStatus ", st.ParamSnIsNone)	//	this.Ctx.WriteString("请提供正确的序列号!")	//	return	//}	ssn := this.GetString("ssn")	this.Data["ssn"] = ssn	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 = "wpvehicle/motormain.tpl"}func (this *WpvehicleController) UiMotorList() {	sn := this.getSn()	//if sn == "" {	//	lg.Error("WpvehicleController.UiMotorStatus ", st.ParamSnIsNone)	//	this.Ctx.WriteString("请提供正确的序列号!")	//	return	//}	ssn := this.GetString("ssn")	this.Data["ssn"] = ssn	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 = "wpvehicle/motorlist.tpl"}func (this *WpvehicleController) UiMotoralignList() {	sn := this.getSn()	//if sn == "" {	//	lg.Error("WpvehicleController.UiMotorStatus ", st.ParamSnIsNone)	//	this.Ctx.WriteString("请提供正确的序列号!")	//	return	//}	ssn := this.GetString("ssn")	this.Data["ssn"] = ssn	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 = "wpvehicle/motoralignlist.tpl"}func (this *WpvehicleController) UiMotorHistory() {	this.TplName = "wpvehicle/motorhistory.tpl"}func (this *WpvehicleController) 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.Wpstatus).ListWithParamsWithDb(etc.DbNameWpStatus, 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 *WpvehicleController) UiHistory() {    sid := this.Ctx.Input.Param(":hi")    if sid == ""{        this.Ctx.WriteString("No sid")    }    this.Data["DeviceId"] = sid    this.Data["UrlItemList"] = "/wpvehicle/history/itemlist/" + sid    this.TplName = "wpvehicle/history.tpl"}func (this *WpvehicleController) UiWPHistory() {	sid := this.Ctx.Input.Param(":hi")	if sid == ""{		this.Ctx.WriteString("No sid")	}	this.Data["DeviceId"] = sid	this.Data["UrlItemList"] = "/wpvehicle/history/itemlist/" + sid	this.TplName = "wpvehicle/wphistory.tpl"}func (c *WpvehicleController) 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 *WpvehicleController) 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)}
 |