| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 | 
package controllersimport (    "eps/models/gensetMgr"    "wb/cs"    "wb/ctrl"    "wb/ctrl/uibuilder"    "wb/ii"    "wb/om"    "wb/ut"    "github.com/astaxie/beego"    "eps/models/statusMgr"    "strings"    "wb/lg"    "wb/cc"    "wb/st"    "eps/models/etc"    "wb/svc"    "wb/gis")type GensetController struct {    ctrl.ItemController}func (this *GensetController) NestPrepare() {    this.CtxItemInfo, _ = ii.ItemInfoMap[etc.Tbl.Genset]}func (this *GensetController) UiAdd() {    this.Data["Service"] = "/genset/item/add/"    sn := ut.TUId()    this.Data["Sn"] = sn    _, companys := om.Table(etc.Tbl.Company).GetAll()    this.Data["CompanyOptions"] = uibuilder.BuildSelectOptions(companys, "", cc.Col.Sn, cc.Col.Name)    this.FillFormElement(uibuilder.BuildFormElement(this.CtxItemInfo, map[string]interface{}{"sn":sn}, map[string]string{}))    this.TplName = "genset/edit.tpl"}func (this *GensetController) UiSyzAdd() {    this.Data["Service"] = "/genset/item/add/"    sn := ut.TUId()    this.Data["Sn"] = sn    _, companys := om.Table(etc.Tbl.Company).GetAll()    this.Data["CompanyOptions"] = uibuilder.BuildSelectOptions(companys, "", cc.Col.Sn, cc.Col.Name)    this.FillFormElement(uibuilder.BuildFormElement(this.CtxItemInfo, map[string]interface{}{"sn":sn}, map[string]string{}))    this.TplName = "genset/add.tpl"}func (this *GensetController) Update() {    this.ItemController.Update()    statusMgr.RefreshStatus(this.getSn())}func (this *GensetController) Add(){    this.ItemController.Add()    statusMgr.RefreshStatus(this.getSn())}func (this *GensetController) 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}    cd, oldValueMap := om.Table(itemName).Get(params)    if cd == "success" {        this.Data["Sn"] = sn        this.Data["Service"] = "/genset/item/update"        statusMap := make(map[string]string)        if this.CtxUser.GetRole() != cc.Role.SysAdmin {            for _, field := range this.CtxItemInfo.Fields {                statusMap[field.Name] = uibuilder.StatusStatic            }        }        if this.CtxUser.GetRole() == cc.Role.Admin{            statusMap["firm"] = ""        }        _, 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)        this.FillFormElement(uibuilder.BuildFormElement(this.CtxItemInfo, oldValueMap, statusMap))        this.TplName = "genset/edit.tpl"    } else {        this.Ctx.WriteString(st.ItemNotFound)    }}func (this *GensetController) UiDetals() {    sid := this.Ctx.Input.Param(":hi")    if sid == ""{        this.Ctx.WriteString("No sid")    }    this.Data["DeviceId"] = sid    this.TplName = "genset/detail.tpl"}func (this *GensetController) 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.Gsstatus).ListWithParamsWithDb(etc.DbNameGsStatus, 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 *GensetController) UiHistory() {    sid := this.Ctx.Input.Param(":hi")    if sid == ""{        this.Ctx.WriteString("No sid")    }    this.Data["DeviceId"] = sid    this.Data["UrlItemList"] = "/genset/history/itemlist/" + sid    this.TplName = "genset/history.tpl"}func (this *GensetController) UiStatus() {    sn := this.getSn()    if sn == "" {        lg.Error("GensetController.UiStatus ", st.ParamSnIsNone)        this.Ctx.WriteString("请提供正确的序列号!")        return    }    params := om.Params{etc.Sid: sn}    code, oldValueMap := om.Table(etc.Tbl.Genset).Get(params)    this.Data["DeviceName"] = "设备*"    this.Data["RatePower"] = 220    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 = "genset/main.tpl"}func (this * GensetController)UiDemo(){    if beego.BConfig.RunMode != "dev"{        this.Ctx.WriteString("没有权限")        return    }    sn := beego.AppConfig.String("demoGensetSn")    this.Data["redirectUrl"] = "/genset/status?sn=" + sn    this.TplName = "login/public.html"}func (c *GensetController) Status() {    sn := c.getSn()    if sn == "" {        lg.Error("GensetController.Status ", st.ParamSnIsNone)        c.Ctx.WriteString("{}")        return    }    c.Data["json"] = statusMgr.GetStatus(sn)    c.ServeJSON()}func (this *GensetController) Operate() {    sns := this.getSn()    if sns == "" {        lg.Error("Operate ", st.ParamSnIsNone)        this.Ctx.WriteString("{}")        return    }    snList := strings.Split(sns, ",")    operate := this.GetString(etc.Operate)    lg.Info("GensetController.Operate:Cmd ", operate, "to: ", sns)    for _, sn := range snList{        gensetMgr.SendCmd(sn, operate)    }    this.Ctx.WriteString(st.Success)}func (c *GensetController) getSn()string{    sn := c.GetString(cc.Col.Sn)    sn = strings.TrimSpace(sn)    return sn}func (this *GensetController) UiVideo() {    sid := this.GetString("sid")    if sid == ""{        this.Ctx.WriteString("No sid")    }    _,list := om.Table("genset").Get(om.Params{"sid":sid})    this.Data["rtmp"] = list.GetString("rtmp")    this.Data["hls"] = list.GetString("hls")    this.Data["DeviceId"] = sid    this.TplName = "genset/video.tpl"}var gRefreshMap = make(map[string]map[string]interface{})func (this *GensetController) ApiRefresh(){    tbRet := svc.Svc(this.CtxUser).GetTableList(etc.Tbl.Genset, svc.ListParams{})    lstGenset := tbRet.Rows    lstPoint := make([]map[string]interface{}, 0)    for _, gs := range lstGenset{        lng, lat := gis.Wgs2bdWithDefaultByPt(gs)        sid := gs.GetString("sid")        status := statusMgr.GetMgrBySid(sid).GetStatus(sid)        ele := 0        if status.GetString("status") == "running"{            ele = 1        }        newPoint := make(map[string]interface{})        newPoint["id"]=sid        newPoint["name"] = gs.GetString("name")        newPoint["lng"] = lng        newPoint["lat"] = lat        newPoint["electric"] = ele        newPoint["valid"] = 1        newPoint["upt"] = 1        if oldPoint, ok := gRefreshMap[sid];ok{            if isPointSame(oldPoint, newPoint) == false{                //gRefreshMap[sid] = newPoint                lstPoint = append(lstPoint, newPoint)            }        }else{            //gRefreshMap[sid] = newPoint            newPoint["upt"] = 0            lstPoint = append(lstPoint, newPoint)        }    }    retMap := make(map[string]interface{})    retMap["status"] = "success"    retMap["total"] = len(lstPoint)    retMap["rows"] = lstPoint    this.SendJson(retMap)}func isPointSame(old, new map[string]interface{}) bool{    if isPointAttrSame(old, new, "name") == false{        return false    }    if isPointAttrSame(old, new, "lng") == false{        return false    }    if isPointAttrSame(old, new, "lat") == false{        return false    }    if isPointAttrSame(old, new, "electric") == false{        return false    }    return true}func isPointAttrSame(old, new map[string]interface{}, key string)bool{    if o, ok := old[key]; ok{        if n, ok := new[key];ok{            if n == o{                return true            }        }    }    return false}
 |