monthreports.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "dashoo.cn/base_common/labsop"
  8. "dashoo.cn/base_common/utils"
  9. "dashoo.cn/mcs_api/business/company"
  10. "dashoo.cn/mcs_api/business/device"
  11. "dashoo.cn/mcs_common/business/equipment"
  12. "github.com/signintech/gopdf"
  13. "github.com/tealeg/xlsx"
  14. )
  15. type MonthReportsController struct {
  16. BaseController
  17. }
  18. type MonthModel struct {
  19. ChannelName string `json:"cname"`
  20. Data []Reportinfo `json:"data"`
  21. }
  22. // @Title 周报月报列表
  23. // @Description 周报月报列表
  24. // @Success 200 {object} business.device.DeviceChannels
  25. // @router /list [get]
  26. func (this *MonthReportsController) List() {
  27. var showcols []string
  28. var timearea string
  29. var code string
  30. svc := device.GetDeviceService(utils.DBE)
  31. client := labsop.GetLabSopClient(this.GetupdbAndHost())
  32. start, _ := this.GetInt64("start")
  33. end, _ := this.GetInt64("end")
  34. cols := this.GetString("cols")
  35. code = "c" + this.GetString("serial")
  36. startstr := time.Unix(start/1000, 0).Format("2006-01-02")
  37. endstr := time.Unix(end/1000, 0).Format("2006-01-02")
  38. t1, _ := utils.TimeParse(startstr+" 00:00:00", "2006-1-2 15:4:5")
  39. t2, _ := utils.TimeParse(endstr+" 23:59:59", "2006-1-2 15:4:5")
  40. day := (t2.Unix()-t1.Unix())/(60*60*24) + 1
  41. var reports = make([]Reportinfo, 0)
  42. if cols == "" {
  43. timearea = ReportDefaultTimearea
  44. showcols = strings.Split(ReportDefaultTimearr, ",")
  45. } else {
  46. timearea = "1h"
  47. showcolsstr := cols
  48. showcols = strings.Split(showcolsstr, ",")
  49. }
  50. channelmodel := svc.GetEntitieByCode(code)
  51. for i := 0; int64(i) < day; i++ {
  52. var begin int64 = t1.AddDate(0, 0, i).Unix()
  53. var end int64 = t1.AddDate(0, 0, i+1).Unix() - 1
  54. data := new(labsop.DatapointLabSop)
  55. queryCommand := fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2 ,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3,MEDIAN(tvoc) as tvoc from %v where time > %vs and time < %vs group by time(%v) fill(none)", code, begin, end, timearea)
  56. fmt.Println("--------queryCommand-1111--------", queryCommand)
  57. if DeviceItemContainint(ChannelItem_Power, channelmodel.DataItem) {
  58. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3 ,MEDIAN(tvoc) as tvoc ,MEDIAN(electricalsupply) as electricalsupply,MEDIAN(electricalpower) as electricalpower from %v where time > %vs and time < %vs group by time(%v) fill(none)", code, begin, end, timearea)
  59. fmt.Println("--------queryCommand---------", queryCommand)
  60. } else if DeviceItemContainint(ChannelItem_HaveLiquidLevel, channelmodel.DataItem) {
  61. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2 ,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3,MEDIAN(tvoc) as tvoc,MEDIAN(liquidlevel) as liquidlevel from %v where time > %vs and time < %vs group by time(%v) fill(none)", code, begin, end, timearea)
  62. }
  63. result := client.QueryLabSop(queryCommand, data)
  64. reportdata := GetReportData(utils.TimeFormat(t1.AddDate(0, 0, i), "2006-1-2"), channelmodel.DataItem, showcols, result, []TriggerHourData{})
  65. reports = append(reports, reportdata)
  66. }
  67. this.Data["reports"] = reports
  68. var datainfo MonthModel
  69. datainfo.Data = reports
  70. datainfo.ChannelName = channelmodel.Title
  71. this.Data["json"] = &datainfo
  72. this.ServeJSON()
  73. }
  74. // @Title 周报月报导出EXCEL
  75. // @Description 周报月报导出EXCEL
  76. // @Success 200 {object} business.device.DeviceChannels
  77. // @router /excel [get]
  78. func (this *MonthReportsController) GetExcel() {
  79. var showcols []string
  80. var showxlscols []string
  81. var timearea string
  82. svc := device.GetDeviceService(utils.DBE)
  83. client := labsop.GetLabSopClient(this.GetupdbAndHost())
  84. start, _ := this.GetInt64("start")
  85. end, _ := this.GetInt64("end")
  86. cols := this.GetString("cols")
  87. serials := strings.Split(this.GetString("serials"), ",")
  88. startstr := time.Unix(start/1000, 0).Format("2006-01-02")
  89. endstr := time.Unix(end/1000, 0).Format("2006-01-02")
  90. t1, _ := utils.TimeParse(startstr+" 00:00:00", "2006-1-2 15:4:5")
  91. t2, _ := utils.TimeParse(endstr+" 23:59:59", "2006-1-2 15:4:5")
  92. day := (t2.Unix()-t1.Unix())/(60*60*24) + 1
  93. if cols == "" {
  94. timearea = ReportDefaultTimearea
  95. showcols = strings.Split(ReportDefaultTimearr, ",")
  96. showxlscols = strings.Split(strings.Replace(ReportDefaultTimearr, ",", ":00,", -1)+":00", ",")
  97. } else {
  98. timearea = "1h"
  99. showcolsstr := cols
  100. showcols = strings.Split(showcolsstr, ",")
  101. showxlscols = strings.Split(strings.Replace(showcolsstr, ",", ":00,", -1)+":00", ",")
  102. }
  103. svccompany := company.GetCompanyService(utils.DBE)
  104. companyname := svccompany.GetFullnameByAccode(this.GetAccode())
  105. xlsx.PagePrintfooterContant = "第 &P 页 "
  106. xlsx.PagePrintheadContant = companyname
  107. f := xlsx.NewFile()
  108. if this.GetString("type") == "1" {
  109. var codestring []string
  110. for i := 0; i < len(serials); i++ {
  111. codestring = append(codestring, "'c"+serials[i]+"'")
  112. }
  113. svceq := equipment.GetEquipmentService(utils.DBE)
  114. eids := svceq.GetEquipmentidsByUid(this.User.Id)
  115. where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.EquipMentId in (" + eids + ")) and a.DataItem in (" + ChannelItem_Report + ") and a.Code in(" + strings.Join(codestring, ",") + ")"
  116. _, channel1 := svc.GetChannelsList(-1, 8, where, this.User.Id)
  117. for _, v := range channel1 {
  118. if v.Code != "" {
  119. var reportsall = make([]Reportinfo, 0)
  120. for i := 0; int64(i) < day; i++ {
  121. var begin int64 = t1.AddDate(0, 0, i).Unix()
  122. var end int64 = t1.AddDate(0, 0, i+1).Unix() - 1
  123. data := new(labsop.DatapointLabSop)
  124. queryCommand := fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2 ,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3,MEDIAN(tvoc) as tvoc from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  125. if DeviceItemContainint(ChannelItem_Power, v.DataItem) {
  126. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3 ,MEDIAN(tvoc) as tvoc ,MEDIAN(electricalsupply) as electricalsupply,MEDIAN(electricalpower) as electricalpower from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  127. } else if DeviceItemContainint(ChannelItem_HaveLiquidLevel, v.DataItem) {
  128. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2 ,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3,MEDIAN(tvoc) as tvoc,MEDIAN(liquidlevel) as liquidlevel from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  129. }
  130. result := client.QueryLabSop(queryCommand, data)
  131. reportdata := GetReportData(utils.TimeFormat(t1.AddDate(0, 0, i), "2006-1-2"), v.DataItem, showcols, result, []TriggerHourData{})
  132. reportsall = append(reportsall, reportdata)
  133. }
  134. DaySaveXlsx("日期", v.Title, this.User.Realname, v.Title, showxlscols, reportsall, f)
  135. }
  136. }
  137. SaveDirectory("static/file/excel/report/" + this.GetAccode())
  138. f.Save("static/file/excel/report/" + this.GetAccode() + "/monthdevicedata.xlsx")
  139. var errinfo ErrorInfo
  140. errinfo.Message = this.Ctx.Request.Host + "/static/file/excel/report/" + this.GetAccode() + "/monthdevicedata.xlsx"
  141. errinfo.Code = 0
  142. this.Data["json"] = &errinfo
  143. this.ServeJSON()
  144. } else if this.GetString("type") == "2" {
  145. svceq := equipment.GetEquipmentService(utils.DBE)
  146. eids := svceq.GetEquipmentidsByUid(this.User.Id)
  147. Uid := this.User.Id
  148. where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.EquipMentId in (" + eids + ")) and a.DataItem in (" + ChannelItem_Report + ") "
  149. _, channel := svc.GetChannelsList(-1, 8, where, Uid)
  150. for _, v := range channel {
  151. if v.Code != "" {
  152. var reportsall = make([]Reportinfo, 0)
  153. var i int
  154. for i = 0; int64(i) < day; i++ {
  155. var begin int64 = t1.AddDate(0, 0, i).Unix()
  156. var end int64 = t1.AddDate(0, 0, i+1).Unix() - 1
  157. data := new(labsop.DatapointLabSop)
  158. queryCommand := fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement ,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3,MEDIAN(tvoc) as tvoc from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  159. if DeviceItemContainint(ChannelItem_Power, v.DataItem) {
  160. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3 ,MEDIAN(tvoc) as tvoc ,MEDIAN(electricalsupply) as electricalsupply,MEDIAN(electricalpower) as electricalpower from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  161. } else if DeviceItemContainint(ChannelItem_HaveLiquidLevel, v.DataItem) {
  162. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3 ,MEDIAN(tvoc) as tvoc ,MEDIAN(liquidlevel) as liquidlevel from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  163. }
  164. result := client.QueryLabSop(queryCommand, data)
  165. reportdata := GetReportData(utils.TimeFormat(t1.AddDate(0, 0, i), "2006-1-2"), v.DataItem, showcols, result, []TriggerHourData{})
  166. reportsall = append(reportsall, reportdata)
  167. }
  168. DaySaveXlsx("日期", v.Title, this.User.Realname, v.Title, showxlscols, reportsall, f)
  169. }
  170. }
  171. SaveDirectory("static/file/excel/report/" + this.GetAccode())
  172. f.Save("static/file/excel/report/" + this.GetAccode() + "/monthdevicedata.xlsx")
  173. var errinfo ErrorInfo
  174. errinfo.Message = this.Ctx.Request.Host + "/static/file/excel/report/" + this.GetAccode() + "/monthdevicedata.xlsx"
  175. errinfo.Code = 0
  176. this.Data["json"] = &errinfo
  177. this.ServeJSON()
  178. }
  179. }
  180. // @Title 周报月报导出PDF
  181. // @Description 周报月报导出PDF
  182. // @Success 200 {object} business.device.DeviceChannels
  183. // @router /pdf [get]
  184. func (this *MonthReportsController) GetPDF() {
  185. var showcols []string
  186. var timearea string
  187. svc := device.GetDeviceService(utils.DBE)
  188. client := labsop.GetLabSopClient(this.GetupdbAndHost())
  189. start, _ := this.GetInt64("start")
  190. end, _ := this.GetInt64("end")
  191. cols := this.GetString("cols")
  192. startstr := time.Unix(start/1000, 0).Format("2006-01-02")
  193. endstr := time.Unix(end/1000, 0).Format("2006-01-02")
  194. t1, _ := utils.TimeParse(startstr+" 00:00:00", "2006-1-2 15:4:5")
  195. t2, _ := utils.TimeParse(endstr+" 23:59:59", "2006-1-2 15:4:5")
  196. day := (t2.Unix()-t1.Unix())/(60*60*24) + 1
  197. svceq := equipment.GetEquipmentService(utils.DBE)
  198. eids := svceq.GetEquipmentidsByUid(this.User.Id)
  199. Uid := this.User.Id
  200. channel := make([]device.DeviceChannels, 0)
  201. if this.GetString("type") == "1" {
  202. serials := strings.Split(this.GetString("serials"), ",")
  203. var codestring []string
  204. for i := 0; i < len(serials); i++ {
  205. codestring = append(codestring, "'c"+serials[i]+"'")
  206. }
  207. where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.EquipMentId in (" + eids + ")) and a.DataItem in (" + ChannelItem_Report + ") and a.Code in(" + strings.Join(codestring, ",") + ")"
  208. _, channel = svc.GetChannelsList(-1, 8, where, Uid)
  209. } else {
  210. where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.EquipMentId in (" + eids + ")) and a.DataItem in (" + ChannelItem_Report + ") "
  211. _, channel = svc.GetChannelsList(-1, 8, where, Uid)
  212. }
  213. if cols == "" {
  214. timearea = ReportDefaultTimearea
  215. showcols = strings.Split(ReportDefaultTimearr, ",")
  216. } else {
  217. timearea = "1h"
  218. showcolsstr := cols
  219. showcols = strings.Split(showcolsstr, ",")
  220. }
  221. var times float64
  222. // var report float64
  223. // report = float64(len(reports))
  224. times = float64(len(showcols))
  225. y := 0
  226. pdf := gopdf.GoPdf{}
  227. pdf.Start(gopdf.Config{Unit: "pt", PageSize: gopdf.Rect{W: (200*times + 600), H: 2550}}) //595.28, 841.89 = A4
  228. pdf.AddTTFFont("HDZB_5", "static/fonts/msyh.ttf")
  229. for k, v := range channel {
  230. if v.Code != "" {
  231. var reports = make([]Reportinfo, 0)
  232. var j int
  233. for j = 0; int64(j) < day; j++ {
  234. var begin int64 = t1.AddDate(0, 0, j).Unix()
  235. var end int64 = t1.AddDate(0, 0, j+1).Unix() - 1
  236. data := new(labsop.DatapointLabSop)
  237. queryCommand := fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2 ,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3,MEDIAN(tvoc) as tvoc from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  238. if DeviceItemContainint(ChannelItem_Power, v.DataItem) {
  239. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3 ,MEDIAN(tvoc) as tvoc ,MEDIAN(electricalsupply) as electricalsupply,MEDIAN(electricalpower) as electricalpower from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  240. } else if DeviceItemContainint(ChannelItem_HaveLiquidLevel, v.DataItem) {
  241. queryCommand = fmt.Sprintf("select MEDIAN(temperature) as temperature,MEDIAN(humidity) as humidity,MEDIAN(voltage) as voltage,MEDIAN(rssi) as rssi,MEDIAN(o2) as o2,MEDIAN(co2) as co2 ,MEDIAN(ots) as ots,MEDIAN(displacement) as displacement,MEDIAN(h2o) as h2o ,MEDIAN(so2) as so2,MEDIAN(windspeed) as windspeed ,MEDIAN(pressure) as pressure,MEDIAN(clo2) as clo2,MEDIAN(c2h4) as c2h4,MEDIAN(c2h2) as c2h2,MEDIAN(cl2) as cl2,MEDIAN(o3) as o3,MEDIAN(tvoc) as tvoc,MEDIAN(liquidlevel) as liquidlevel from %v where time > %vs and time < %vs group by time(%v) fill(none)", v.Code, begin, end, timearea)
  242. }
  243. result := client.QueryLabSop(queryCommand, data)
  244. reportdata := GetReportData(utils.TimeFormat(t1.AddDate(0, 0, j), "2006-1-2"), v.DataItem, showcols, result, []TriggerHourData{})
  245. reports = append(reports, reportdata)
  246. this.Data["reports"] = reports
  247. }
  248. this.Data["showcols"] = showcols
  249. var times float64
  250. var report float64
  251. var i float64
  252. report = float64(len(reports))
  253. times = float64(len(showcols))
  254. //pdf.Start(gopdf.Config{Unit: "pt", PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
  255. pdf.AddPage()
  256. pdf.Line(100, 100, 200*times+500, 100) //横线
  257. pdf.Line(100, 150, 200*times+500, 150) //横线
  258. pdf.Line(100, 100, 100, 150) //竖线
  259. for i = 0; i <= times; i++ {
  260. pdf.Line(200*i+500, 100, 200*i+500, 150) //竖线
  261. }
  262. pdf.SetFont("HDZB_5", "B", 24) //字体
  263. pdf.Curr.X = 105
  264. pdf.Curr.Y = 120
  265. pdf.Cell(nil, channel[k].Title)
  266. pdf.Curr.X = (200*times+600)/2 - 100
  267. pdf.Curr.Y = 70
  268. pdf.Cell(nil, "名称:"+this.User.Realname)
  269. var yyy float64
  270. var r float64
  271. var t float64
  272. yyy = 120
  273. for i = 0; i < report; i++ {
  274. pdf.Curr.Y = yyy + 20
  275. pdf.Br(26)
  276. pdf.Curr.X = 105
  277. pdf.Cell(nil, reports[int(i)].Name)
  278. if yyy == 120 {
  279. for r = 0; r < times; r++ {
  280. pdf.Curr.X = 200*r + 510
  281. pdf.Curr.Y = 120
  282. pdf.Cell(nil, (showcols[int(r)] + ":00"))
  283. }
  284. }
  285. if len(reports[int(i)].DataT) != 0 {
  286. for k, temp := range reports[int(i)].DataT {
  287. pdf.Curr.X = 310 + float64(k*200)
  288. pdf.Curr.Y = 50 + yyy
  289. pdf.Cell(nil, temp)
  290. }
  291. yyy = yyy + 50
  292. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  293. }
  294. if len(reports[int(i)].DataH) != 0 {
  295. for k, temp := range reports[int(i)].DataH {
  296. pdf.Curr.X = 310 + float64(k*200)
  297. pdf.Curr.Y = 50 + yyy
  298. pdf.Cell(nil, temp)
  299. }
  300. yyy = yyy + 50
  301. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  302. }
  303. if len(reports[int(i)].DataO2) != 0 {
  304. for k, temp := range reports[int(i)].DataO2 {
  305. pdf.Curr.X = 310 + float64(k*200)
  306. pdf.Curr.Y = 50 + yyy
  307. pdf.Cell(nil, temp)
  308. }
  309. yyy = yyy + 50
  310. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  311. }
  312. if len(reports[int(i)].DataCO2) != 0 {
  313. for k, temp := range reports[int(i)].DataCO2 {
  314. pdf.Curr.X = 310 + float64(k*200)
  315. pdf.Curr.Y = 50 + yyy
  316. pdf.Cell(nil, temp)
  317. }
  318. yyy = yyy + 50
  319. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  320. }
  321. if len(reports[int(i)].DataDoorlock) != 0 {
  322. for k, temp := range reports[int(i)].DataDoorlock {
  323. pdf.Curr.X = 310 + float64(k*200)
  324. pdf.Curr.Y = 50 + yyy
  325. pdf.Cell(nil, temp)
  326. }
  327. yyy = yyy + 50
  328. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  329. }
  330. if len(reports[int(i)].DataDisplacement) != 0 {
  331. for k, temp := range reports[int(i)].DataDisplacement {
  332. pdf.Curr.X = 310 + float64(k*200)
  333. pdf.Curr.Y = 50 + yyy
  334. pdf.Cell(nil, temp)
  335. }
  336. yyy = yyy + 50
  337. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  338. }
  339. if len(reports[int(i)].DataH2O) != 0 {
  340. for k, temp := range reports[int(i)].DataH2O {
  341. pdf.Curr.X = 310 + float64(k*200)
  342. pdf.Curr.Y = 50 + yyy
  343. pdf.Cell(nil, temp)
  344. }
  345. yyy = yyy + 50
  346. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  347. }
  348. if len(reports[int(i)].DataSO2) != 0 {
  349. for k, temp := range reports[int(i)].DataSO2 {
  350. pdf.Curr.X = 310 + float64(k*200)
  351. pdf.Curr.Y = 50 + yyy
  352. pdf.Cell(nil, temp)
  353. }
  354. yyy = yyy + 50
  355. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  356. }
  357. if len(reports[int(i)].Datapower) != 0 {
  358. for k, temp := range reports[int(i)].Datapower {
  359. pdf.Curr.X = 310 + float64(k*200)
  360. pdf.Curr.Y = 50 + yyy
  361. pdf.Cell(nil, temp)
  362. }
  363. yyy = yyy + 50
  364. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  365. }
  366. if len(reports[int(i)].Datasupply) != 0 {
  367. for k, temp := range reports[int(i)].Datasupply {
  368. pdf.Curr.X = 310 + float64(k*200)
  369. pdf.Curr.Y = 50 + yyy
  370. pdf.Cell(nil, temp)
  371. }
  372. yyy = yyy + 50
  373. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  374. }
  375. if len(reports[int(i)].DataLiquidLevel) != 0 {
  376. for k, temp := range reports[int(i)].DataLiquidLevel {
  377. pdf.Curr.X = 310 + float64(k*200)
  378. pdf.Curr.Y = 50 + yyy
  379. pdf.Cell(nil, temp)
  380. }
  381. yyy = yyy + 50
  382. pdf.Line(300, yyy+30, 200*times+500, yyy+30) //横线
  383. }
  384. if yyy > 2350 || i == report-1 {
  385. for r = 0; r <= (times + 2); r++ {
  386. pdf.Line(200*r+100, 150, 200*r+100, yyy+30) //竖线
  387. }
  388. y = y + 1
  389. yy := utils.ToStr(y)
  390. pdf.Curr.X = (200*times+600)/2 - 100
  391. pdf.Curr.Y = 2500
  392. pdf.Cell(nil, "第 "+yy+" 页")
  393. }
  394. pdf.Line(100, yyy+30, 300, yyy+30) //横线
  395. if yyy > 2350 && i != report-1 {
  396. pdf.AddPage()
  397. yyy = 120
  398. pdf.Line(100, 100, 200*times+500, 100) //横线
  399. pdf.Line(100, 150, 200*times+500, 150) //横线
  400. pdf.Line(100, 100, 100, 150) //竖线
  401. for t = 0; t <= times; t++ {
  402. pdf.Line(200*t+500, 100, 200*t+500, 150) //竖线
  403. }
  404. pdf.SetFont("HDZB_5", "B", 24) //字体
  405. pdf.Curr.X = 105
  406. pdf.Curr.Y = 120
  407. pdf.Cell(nil, channel[k].Title)
  408. pdf.Curr.X = (200*times+600)/2 - 100
  409. pdf.Curr.Y = 70
  410. pdf.Cell(nil, "名称:"+this.User.Realname)
  411. for t = 0; t < times; t++ {
  412. pdf.Curr.X = 200*t + 510
  413. pdf.Curr.Y = 120
  414. pdf.Cell(nil, (showcols[int(t)] + ":00"))
  415. }
  416. }
  417. }
  418. }
  419. }
  420. SaveDirectory("static/file/pdf/report/" + this.GetAccode())
  421. pdf.WritePdf("static/file/pdf/report/" + this.GetAccode() + "/devicedata.pdf")
  422. var errinfo ErrorInfo
  423. errinfo.Message = this.Ctx.Request.Host + "/static/file/pdf/report/" + this.GetAccode() + "/devicedata.pdf"
  424. errinfo.Code = 0
  425. this.Data["json"] = &errinfo
  426. this.ServeJSON()
  427. }
  428. // @Title 周报月报导出最值报表
  429. // @Description 周报月报导出最值报表
  430. // @Success 200 {object} business.device.DeviceChannels
  431. // @router /maxreport [get]
  432. func (this *MonthReportsController) MaxReport() {
  433. this.Data["PageTitle"] = "title.data_query"
  434. svc := device.GetDeviceService(utils.DBE)
  435. client := labsop.GetLabSopClient(this.GetupdbAndHost())
  436. rtype := this.GetString("type")
  437. start, _ := this.GetInt64("start")
  438. end, _ := this.GetInt64("end")
  439. startstr := time.Unix(start/1000, 0).Format("2006-01-02")
  440. endstr := time.Unix(end/1000, 0).Format("2006-01-02")
  441. t1, _ := utils.TimeParse(startstr+" 00:00:00", "2006-1-2 15:4:5")
  442. t2, _ := utils.TimeParse(endstr+" 23:59:59", "2006-1-2 15:4:5")
  443. svccompany := company.GetCompanyService(utils.DBE)
  444. companyname := svccompany.GetFullnameByAccode(this.GetAccode())
  445. xlsx.PagePrintfooterContant = "第 &P 页 "
  446. xlsx.PagePrintheadContant = companyname
  447. f := xlsx.NewFile()
  448. if rtype == "3" {
  449. svceq := equipment.GetEquipmentService(utils.DBE)
  450. eids := svceq.GetEquipmentidsByUid(this.User.Id)
  451. uidstr := this.User.Id
  452. var codestring []string
  453. serials := strings.Split(this.GetString("serials"), ",")
  454. for i := 0; i < len(serials); i++ {
  455. codestring = append(codestring, "'c"+serials[i]+"'")
  456. }
  457. where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.EquipMentId in (" + eids + ")) and a.DataItem in (" + ChannelItem_Report + ") and a.Code in(" + strings.Join(codestring, ",") + ")"
  458. _, channel1 := svc.GetChannelsList(-1, 8, where, uidstr)
  459. for k, v := range channel1 {
  460. if v.Code != "" {
  461. queryGroupCommand := fmt.Sprintf("select max(temperature),min(temperature),max(humidity),min(humidity),max(o2),min(o2),max(co2),min(co2),max(ots),min(ots),max(displacement),min(displacement),max(h2o),min(h2o),max(so2),min(so2),max(electricalpower),min(electricalpower),max(electricalsupply),min(electricalsupply),max(liquidlevel),min(liquidlevel) from %v where time > %vs and time < %vs group by time(1d,16h) fill(none) ", v.Code, t1.Unix()-1, t2.Unix()+1)
  462. datagroup, _ := client.QueryOneResultByCommand(queryGroupCommand)
  463. var datas [][]interface{}
  464. if datagroup != nil && len(datagroup) > 0 {
  465. datas = datagroup[0].Values
  466. }
  467. this.GroupSaveXlsx(utils.ToStr(k+1)+"."+v.Title, v.Serial, startstr+" ~ "+endstr, v.DataItem, datas, f)
  468. }
  469. }
  470. SaveDirectory("static/file/excel/report/" + this.GetAccode())
  471. f.Save("static/file/excel/report/" + this.GetAccode() + "/reportdata.xlsx")
  472. var errinfo ErrorInfo
  473. errinfo.Message = this.Ctx.Request.Host + "/static/file/excel/report/" + this.GetAccode() + "/reportdata.xlsx"
  474. errinfo.Code = 0
  475. this.Data["json"] = &errinfo
  476. this.ServeJSON()
  477. } else if rtype == "4" {
  478. svceq := equipment.GetEquipmentService(utils.DBE)
  479. eids := svceq.GetEquipmentidsByUid(this.User.Id)
  480. uidstr := this.User.Id
  481. where := " (a.CreateUserId=" + uidstr + " or a.EquipMentId in (" + eids + ")) and a.DataItem in (" + ChannelItem_Report + ") "
  482. _, channel := svc.GetChannelsList(-1, 8, where, uidstr)
  483. for k, v := range channel {
  484. if v.Code != "" {
  485. queryGroupCommand := fmt.Sprintf("select max(temperature),min(temperature),max(humidity),min(humidity),max(o2),min(o2),max(co2),min(co2),max(ots),min(ots),max(displacement),min(displacement),max(h2o),min(h2o),max(so2),min(so2),max(electricalpower),min(electricalpower),max(electricalsupply),min(electricalsupply),max(liquidlevel),min(liquidlevel) from %v where time > %vs and time < %vs group by time(1d,16h) fill(none) ", v.Code, t1.Unix()-1, t2.Unix()+1)
  486. datagroup, _ := client.QueryOneResultByCommand(queryGroupCommand)
  487. var datas [][]interface{}
  488. if datagroup != nil && len(datagroup) > 0 {
  489. datas = datagroup[0].Values
  490. }
  491. this.GroupSaveXlsx(utils.ToStr(k+1)+"."+v.Title, v.Serial, startstr+" ~ "+endstr, v.DataItem, datas, f)
  492. }
  493. }
  494. SaveDirectory("static/file/excel/report/" + this.GetAccode())
  495. f.Save("static/file/excel/report/" + this.GetAccode() + "/reportdata.xlsx")
  496. var errinfo ErrorInfo
  497. errinfo.Message = this.Ctx.Request.Host + "/static/file/excel/report/" + this.GetAccode() + "/reportdata.xlsx"
  498. errinfo.Code = 0
  499. this.Data["json"] = &errinfo
  500. this.ServeJSON()
  501. }
  502. }
  503. func (this *MonthReportsController) GroupSaveXlsx(name, code, timestr string, dataitem int, report [][]interface{}, f *xlsx.File) {
  504. sheet, _ := f.AddSheet(name + "(" + code + ")")
  505. rowname := sheet.AddRow()
  506. celln := rowname.AddCell()
  507. celln.Value = "设备名称:" + name
  508. rowname = sheet.AddRow()
  509. celln = rowname.AddCell()
  510. celln.Value = "设备编号:" + code
  511. rowname = sheet.AddRow()
  512. celln = rowname.AddCell()
  513. celln.Value = "项目:"
  514. rowname = sheet.AddRow()
  515. celln = rowname.AddCell()
  516. celln.Value = "日期:" + timestr
  517. rowhead := sheet.AddRow()
  518. cell := rowhead.AddCell()
  519. cell.Value = ""
  520. cell = rowhead.AddCell()
  521. cell.Value = ""
  522. if DeviceItemContainint(ChannelItem_HaveT, dataitem) {
  523. cell = rowhead.AddCell()
  524. cell.Value = "温度°C"
  525. }
  526. if DeviceItemContainint(ChannelItem_HaveH, dataitem) {
  527. cell = rowhead.AddCell()
  528. cell.Value = "湿度%"
  529. }
  530. if DeviceItemContainint(ChannelItem_HaveO2, dataitem) {
  531. cell = rowhead.AddCell()
  532. cell.Value = "氧气%"
  533. }
  534. if DeviceItemContainint(ChannelItem_HaveCO2, dataitem) { //Ots Displacement
  535. cell = rowhead.AddCell()
  536. cell.Value = "二氧化碳%"
  537. }
  538. if DeviceItemContainint(ChannelItem_Doorlock, dataitem) {
  539. cell = rowhead.AddCell()
  540. cell.Value = "二氧化碳%"
  541. }
  542. if DeviceItemContainint(ChannelItem_Displacement, dataitem) {
  543. cell = rowhead.AddCell()
  544. cell.Value = "二氧化碳%"
  545. }
  546. if DeviceItemContainint(ChannelItem_H2O, dataitem) {
  547. cell = rowhead.AddCell()
  548. cell.Value = "电导率us/cm"
  549. }
  550. if DeviceItemContainint(ChannelItem_SO2, dataitem) {
  551. cell = rowhead.AddCell()
  552. cell.Value = "二氧化硫ppm"
  553. }
  554. if DeviceItemContainint(ChannelItem_WindSpeed, dataitem) {
  555. cell = rowhead.AddCell()
  556. cell.Value = "风速m/s"
  557. }
  558. if DeviceItemContainint(ChannelItem_Pressure, dataitem) {
  559. cell = rowhead.AddCell()
  560. cell.Value = "气压hpa"
  561. }
  562. if DeviceItemContainint(ChannelItem_ClO2, dataitem) {
  563. cell = rowhead.AddCell()
  564. cell.Value = "二氧化氯PPM"
  565. }
  566. if DeviceItemContainint(ChannelItem_C2H4, dataitem) {
  567. cell = rowhead.AddCell()
  568. cell.Value = "乙烯PPM"
  569. }
  570. if DeviceItemContainint(ChannelItem_C2H2, dataitem) {
  571. cell = rowhead.AddCell()
  572. cell.Value = "乙炔PPM"
  573. }
  574. if DeviceItemContainint(ChannelItem_Cl2, dataitem) {
  575. cell = rowhead.AddCell()
  576. cell.Value = "氯气PPM"
  577. }
  578. if DeviceItemContainint(ChannelItem_O3, dataitem) {
  579. cell = rowhead.AddCell()
  580. cell.Value = "臭氧PPM"
  581. }
  582. if DeviceItemContainint(ChannelItem_TVOC, dataitem) {
  583. cell = rowhead.AddCell()
  584. cell.Value = "TVOC"
  585. }
  586. if DeviceItemContainint(ChannelItem_Power, dataitem) {
  587. cell = rowhead.AddCell()
  588. cell.Value = "功率W"
  589. cell = rowhead.AddCell()
  590. cell.Value = "电量V"
  591. }
  592. if DeviceItemContainint(ChannelItem_HaveLiquidLevel, dataitem) {
  593. cell = rowhead.AddCell()
  594. cell.Value = "液位mm"
  595. }
  596. if report != nil && len(report) > 0 && report[0] != nil && len(report[0]) > 0 {
  597. for _, v := range report {
  598. var valuef0, valuef1, valuef2, valuef3, valuef4, valuef5,
  599. valuef6, valuef7, valuef8, valuef9, valuef10 float64
  600. var valuei0, valuei1, valuei2, valuei3 int64
  601. valuef0, _ = v[0].(json.Number).Float64()
  602. vint := int64(valuef0)
  603. if DeviceItemContainint(ChannelItem_HaveT, dataitem) {
  604. valuef1, _ = v[1].(json.Number).Float64()
  605. valuef2, _ = v[2].(json.Number).Float64()
  606. }
  607. if DeviceItemContainint(ChannelItem_HaveH, dataitem) {
  608. valuef3, _ = v[3].(json.Number).Float64()
  609. valuef4, _ = v[4].(json.Number).Float64()
  610. }
  611. if DeviceItemContainint(ChannelItem_HaveO2, dataitem) {
  612. valuef5, _ = v[5].(json.Number).Float64()
  613. valuef6, _ = v[6].(json.Number).Float64()
  614. }
  615. if DeviceItemContainint(ChannelItem_HaveCO2, dataitem) { //Ots Displacement
  616. valuef7, _ = v[7].(json.Number).Float64()
  617. valuef8, _ = v[8].(json.Number).Float64()
  618. }
  619. if DeviceItemContainint(ChannelItem_Doorlock, dataitem) { //Ots Displacement
  620. valuef7, _ = v[7].(json.Number).Float64()
  621. valuef8, _ = v[8].(json.Number).Float64()
  622. }
  623. if DeviceItemContainint(ChannelItem_Displacement, dataitem) { //Ots Displacement
  624. valuef7, _ = v[7].(json.Number).Float64()
  625. valuef8, _ = v[8].(json.Number).Float64()
  626. }
  627. if DeviceItemContainint(ChannelItem_H2O, dataitem) {
  628. valuef7, _ = v[7].(json.Number).Float64()
  629. valuef8, _ = v[8].(json.Number).Float64()
  630. }
  631. if DeviceItemContainint(ChannelItem_SO2, dataitem) {
  632. valuef7, _ = v[7].(json.Number).Float64()
  633. valuef8, _ = v[8].(json.Number).Float64()
  634. }
  635. if DeviceItemContainint(ChannelItem_Power, dataitem) {
  636. valuei0, _ = v[9].(json.Number).Int64()
  637. valuei1, _ = v[10].(json.Number).Int64()
  638. valuei2, _ = v[11].(json.Number).Int64()
  639. valuei3, _ = v[12].(json.Number).Int64()
  640. }
  641. if DeviceItemContainint(ChannelItem_HaveLiquidLevel, dataitem) {
  642. valuef9, _ = v[20].(json.Number).Float64()
  643. valuef10, _ = v[21].(json.Number).Float64()
  644. }
  645. row := sheet.AddRow()
  646. cell = row.AddCell()
  647. cell.Value = time.Unix(vint, 0).Format("2006-01-02")
  648. cell = row.AddCell()
  649. cell.Value = "最高值"
  650. if DeviceItemContainint(ChannelItem_HaveT, dataitem) {
  651. cell = row.AddCell()
  652. cell.Value = utils.ToStr(valuef1)
  653. }
  654. if DeviceItemContainint(ChannelItem_HaveH, dataitem) {
  655. cell = row.AddCell()
  656. cell.Value = utils.ToStr(valuef3)
  657. }
  658. if DeviceItemContainint(ChannelItem_HaveO2, dataitem) {
  659. cell = row.AddCell()
  660. cell.Value = utils.ToStr(valuef5)
  661. }
  662. if DeviceItemContainint(ChannelItem_HaveCO2, dataitem) { //Ots Displacement
  663. cell = row.AddCell()
  664. cell.Value = utils.ToStr(valuef7)
  665. }
  666. if DeviceItemContainint(ChannelItem_Doorlock, dataitem) { //Ots Displacement
  667. cell = row.AddCell()
  668. cell.Value = utils.ToStr(valuef7)
  669. }
  670. if DeviceItemContainint(ChannelItem_Displacement, dataitem) { //Ots Displacement
  671. cell = row.AddCell()
  672. cell.Value = utils.ToStr(valuef7)
  673. }
  674. if DeviceItemContainint(ChannelItem_H2O, dataitem) {
  675. cell = row.AddCell()
  676. cell.Value = utils.ToStr(valuef7)
  677. }
  678. if DeviceItemContainint(ChannelItem_SO2, dataitem) {
  679. cell = row.AddCell()
  680. cell.Value = utils.ToStr(valuef7)
  681. }
  682. if DeviceItemContainint(ChannelItem_Power, dataitem) {
  683. cell = row.AddCell()
  684. cell.Value = utils.ToStr(valuei0)
  685. cell = row.AddCell()
  686. cell.Value = utils.ToStr(valuei2)
  687. }
  688. if DeviceItemContainint(ChannelItem_HaveLiquidLevel, dataitem) {
  689. cell = row.AddCell()
  690. cell.Value = utils.ToStr(valuef9)
  691. }
  692. row = sheet.AddRow()
  693. cell = row.AddCell()
  694. cell.Value = ""
  695. cell = row.AddCell()
  696. cell.Value = "最低值"
  697. if DeviceItemContainint(ChannelItem_HaveT, dataitem) {
  698. cell = row.AddCell()
  699. cell.Value = utils.ToStr(valuef2)
  700. }
  701. if DeviceItemContainint(ChannelItem_HaveH, dataitem) {
  702. cell = row.AddCell()
  703. cell.Value = utils.ToStr(valuef4)
  704. }
  705. if DeviceItemContainint(ChannelItem_HaveO2, dataitem) {
  706. cell = row.AddCell()
  707. cell.Value = utils.ToStr(valuef6)
  708. }
  709. if DeviceItemContainint(ChannelItem_HaveCO2, dataitem) { //Ots Displacement
  710. cell = row.AddCell()
  711. cell.Value = utils.ToStr(valuef8)
  712. }
  713. if DeviceItemContainint(ChannelItem_Doorlock, dataitem) { //Ots Displacement
  714. cell = row.AddCell()
  715. cell.Value = utils.ToStr(valuef8)
  716. }
  717. if DeviceItemContainint(ChannelItem_Displacement, dataitem) { //Ots Displacement
  718. cell = row.AddCell()
  719. cell.Value = utils.ToStr(valuef8)
  720. }
  721. if DeviceItemContainint(ChannelItem_H2O, dataitem) {
  722. cell = row.AddCell()
  723. cell.Value = utils.ToStr(valuef8)
  724. }
  725. if DeviceItemContainint(ChannelItem_SO2, dataitem) {
  726. cell = row.AddCell()
  727. cell.Value = utils.ToStr(valuef8)
  728. }
  729. if DeviceItemContainint(ChannelItem_Power, dataitem) {
  730. cell = row.AddCell()
  731. cell.Value = utils.ToStr(valuei1)
  732. cell = row.AddCell()
  733. cell.Value = utils.ToStr(valuei3)
  734. }
  735. if DeviceItemContainint(ChannelItem_HaveLiquidLevel, dataitem) {
  736. cell = row.AddCell()
  737. cell.Value = utils.ToStr(valuef10)
  738. }
  739. }
  740. }
  741. // for i, j := 0, len(showcols); i < j; i++ {
  742. // sheet.Cols[i+2].Width = 10
  743. // }
  744. sheet.Cols[0].Width = 17 //设置时间单元格的宽度
  745. sheet.Cols[1].Width = 11 //设置时间单元格的宽度
  746. }