eps.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package controllers
  2. import (
  3. "wb/cs"
  4. "wb/ctrl"
  5. "wb/ctrl/uibuilder"
  6. "wb/ii"
  7. "wb/om"
  8. "wb/lg"
  9. "wb/cc"
  10. "wb/st"
  11. "eps/models/etc"
  12. "strings"
  13. "wb/ut"
  14. "wb/cfg"
  15. "eps/models/statusMgr"
  16. "wb/gis"
  17. "fmt"
  18. )
  19. type EpsController struct {
  20. ctrl.ItemController
  21. }
  22. func (this *EpsController) NestPrepare() {
  23. this.CtxItemInfo, _ = ii.ItemInfoMap["eps"]
  24. }
  25. func (this *EpsController) UiAdd() {
  26. _, companys := om.Table(etc.Tbl.Company).GetAll()
  27. this.Data["CompanyOptions"] = uibuilder.BuildSelectOptions(companys, "", cc.Col.Sn, cc.Col.Name)
  28. this.UiAddItem(this.CtxItemInfo)
  29. }
  30. func (this *EpsController) UiUpdate() {
  31. oItemInfo := this.CtxItemInfo
  32. itemName := oItemInfo.Name
  33. sn := this.GetString(cc.Col.Sn)
  34. if sn == "" {
  35. lg.Error("ui.Update", st.ParamSnIsNone)
  36. this.Ctx.WriteString(st.ParamSnIsNone)
  37. return
  38. }
  39. params := om.Params{cc.Col.Sn: sn}
  40. c, oldValueMap := om.Table(itemName).Get(params)
  41. oldValueMap = oItemInfo.FormatDateTimeInMObject(oldValueMap)
  42. if c == st.Success {
  43. this.SetDataWithoutDefaultStr(cc.UrlService, this.UrlItemUpdate, "/item/update/" + itemName)
  44. this.Data["Sn"] = sn
  45. this.Data["Form"] = uibuilder.BuildUpdatedForm(oItemInfo, oldValueMap)
  46. this.Data["Onload"] = uibuilder.BuildUpdateOnLoadJs(oItemInfo)
  47. customTpl := cfg.WebConfig.ViewsPath + "/" + oItemInfo.Name + "/" + "update.tpl"
  48. if ut.IsPathExist(customTpl){
  49. this.FillValue(oldValueMap)
  50. this.FillFormElement(uibuilder.BuildFormElement(oItemInfo, oldValueMap, map[string]string{}))
  51. this.TplName = oItemInfo.Name + "/" + "update.tpl"
  52. }else{
  53. this.TplName = this.TplUpdate
  54. }
  55. _, companys := om.Table(etc.Tbl.Company).GetAll()
  56. selectdCompany := oldValueMap.GetString(etc.Col.Company)
  57. this.Data["CompanyOptions"] = uibuilder.BuildSelectOptions(companys, selectdCompany, cc.Col.Sn, cc.Col.Name)
  58. lg.Debug("UiUpdateItem tpl", this.TplName)
  59. } else {
  60. lg.Error("UiUpdateItem error", st.ItemNotFound)
  61. this.Ctx.WriteString(st.ItemNotFound)
  62. }
  63. }
  64. func (this *EpsController) UiDetail() {
  65. sid := this.Ctx.Input.Param(":hi")
  66. if sid == ""{
  67. this.Ctx.WriteString("No sid")
  68. }
  69. this.Data["DeviceId"] = sid
  70. this.TplName = "eps/detail.tpl"
  71. }
  72. func (this *EpsController) UiStatus() {
  73. sn := this.getSn()
  74. if sn == "" {
  75. lg.Error("EpsController.UiStatus ", st.ParamSnIsNone)
  76. this.Ctx.WriteString("请提供正确的序列号!")
  77. return
  78. }
  79. params := om.Params{etc.Sid: sn}
  80. code, oldValueMap := om.Table(etc.Tbl.Wp).Get(params)
  81. this.Data["DeviceName"] = "设备*"
  82. if code == "success"{
  83. this.Data["DeviceName"] = ut.Maps.GetString(oldValueMap, cc.Col.Name)
  84. this.Data["RatePower"], _ = ut.Maps.GetFloat64(oldValueMap, "gsratedpower")
  85. }
  86. this.Data["DeviceId"] = sn
  87. this.TplName = "eps/main.tpl"
  88. }
  89. func (c *EpsController) Status() {
  90. sn := c.getSn()
  91. if sn == "" {
  92. lg.Error("EpsController.Status ", st.ParamSnIsNone)
  93. c.Ctx.WriteString("{}")
  94. return
  95. }
  96. c.Data["json"] = statusMgr.GetStatus(sn)
  97. c.ServeJSON()
  98. }
  99. func (this *EpsController) HistoryList() {
  100. sid := this.Ctx.Input.Param(":hi")
  101. if sid == ""{
  102. this.Ctx.WriteString("{}")
  103. }
  104. queryParams, limitParams, orderByParams, searchText:= this.GetListPostParams()
  105. queryParams[etc.Sid] = sid
  106. searchParams := om.Params{}
  107. if searchText != ""{
  108. searchParams[cc.Col.CreateTime] = searchText
  109. }
  110. result, total, resultMaps := om.Table(etc.Tbl.Epsstatus).ListWithParamsWithDb(etc.DbNameEpsStatus, queryParams, searchParams, limitParams, orderByParams)
  111. for _, vMap := range resultMaps{
  112. vMap["createtime"] = ut.GetTimeStrFromDb(vMap.GetString("createtime"))
  113. if flevel, ok := vMap.GetInt64("flevel");!ok || flevel < 0{
  114. vMap["flevel"] = "#"
  115. }
  116. if opress, ok := vMap.GetInt64("opress");!ok || opress < 0{
  117. vMap["opress"] = "#"
  118. }
  119. if etemp, ok := vMap.GetInt64("etemp");!ok || etemp < 0{
  120. vMap["etemp"] = "#"
  121. }
  122. }
  123. this.SendJson(&cs.TableResult{result, int64(total), resultMaps})
  124. }
  125. func (this *EpsController) UiHistory() {
  126. sid := this.Ctx.Input.Param(":hi")
  127. if sid == ""{
  128. this.Ctx.WriteString("No sid")
  129. }
  130. this.Data["DeviceId"] = sid
  131. this.Data["UrlItemList"] = "/eps/history/itemlist/" + sid
  132. this.TplName = "eps/history.tpl"
  133. }
  134. func (c *EpsController) getSn()string{
  135. sn := c.GetString(cc.Col.Sn)
  136. sn = strings.TrimSpace(sn)
  137. if sn == "" {
  138. lg.Error("GetStatus ", st.ParamSnIsNone)
  139. return ""
  140. }
  141. if len(sn) >= 16{
  142. return sn
  143. }
  144. iSn, err := c.GetInt64(cc.Col.Sn)
  145. if err != nil{
  146. lg.Error("GetStatus ", st.ParamSnFormatError)
  147. return ""
  148. }
  149. sn = fmt.Sprintf("%016d", iSn)
  150. return sn
  151. }
  152. func (c *EpsController) ApiOnlinePosition(){
  153. lstPos := statusMgr.EPSStatusMgr.GetPositions()
  154. lstPoint := make([]map[string]interface{}, len(lstPos))
  155. for i, pos := range lstPos{
  156. point := make(map[string]interface{})
  157. lng, lat := gis.Wgs2bdWithDefaultByPt(pos)
  158. point["id"]=ut.Maps.GetString(pos, "sid")
  159. point["lng"] = lng
  160. point["lat"] = lat
  161. point["t"] = ut.Maps.GetString(pos, "t")
  162. lstPoint[i] = point
  163. }
  164. retMap := make(map[string]interface{})
  165. retMap["status"] = "success"
  166. retMap["total"] = len(lstPoint)
  167. retMap["rows"] = lstPoint
  168. c.SendJson(retMap)
  169. }