| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956 |
- package system
- import (
- "encoding/json"
- "strings"
- "time"
- "dashoo.cn/backend/api/business/device"
- "dashoo.cn/backend/api/business/userchannels"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/utils"
- "github.com/signintech/gopdf"
- "github.com/tealeg/xlsx"
- )
- type DataExportsController struct {
- BaseController
- }
- type dataso2 struct {
- Timedata string
- Temperaturedata string
- Humiditydata string
- Voltagedata string
- O2data string
- }
- type datasco2 struct {
- Timedata string
- Temperaturedata string
- Humiditydata string
- Voltagedata string
- CO2data string
- }
- type dataspower struct {
- Timedata string
- Power string
- Supply string
- }
- type headnameo2 struct {
- Time string
- Temperature string
- Humidity string
- O2 string
- Voltage string
- Emptystr string
- TimeRange string
- }
- type datas struct {
- Timedata string
- Temperaturedata string
- Humiditydata string
- Voltagedata string
- }
- type headname struct {
- Time string
- Temperature string
- Humidity string
- Voltage string
- Emptystr string
- TimeRange string
- }
- type headnamepower struct {
- Time string
- Power string
- Supply string
- Emptystr string
- TimeRange string
- }
- type headnameliquidlevel struct {
- Time string
- Temperature string
- LiquidLevel string
- Emptystr string
- TimeRange string
- }
- // @Title 报表导出excel
- // @Description 报表导出excel
- // @Success 200 {object} business.device.DeviceChannels
- // @router /excel [get]
- func (this *DataExportsController) GetExcel() {
- timerange := ""
- svc := device.GetDeviceService(utils.DBE)
- svcuc := userchannels.GetUserChannelService(utils.DBE)
- channelid := svcuc.GetChannelids(utils.ToStr(this.User.Id))
- Uid := utils.ToStr(this.User.Id)
- start64, _ := this.GetInt64("start")
- end64, _ := this.GetInt64("end")
- begin_time := time.Unix(start64/1000, 0).Format("2006-01-02")
- end_time := time.Unix(end64/1000, 0).Format("2006-01-02")
- if begin_time == "" {
- timerange = utils.TimeFormat(time.Now().AddDate(0, 0, -7), "2006-01-02")
- } else {
- timerange = begin_time
- }
- if end_time == "" {
- timerange += " 至 " + utils.TimeFormat(time.Now(), "2006-01-02")
- } else {
- timerange += " 至 " + end_time
- }
- t1, _ := utils.TimeParse(begin_time+" 00:00:00", "2006-1-2 15:4:5")
- t2, _ := utils.TimeParse(end_time+" 23:59:59", "2006-1-2 15:4:5")
- start := t1.Unix()
- end := t2.Unix()
- u, p := this.GetuAndp()
- xlsx.PagePrintfooterContant = "第 &P 页"
- xlsx.PagePrintheadContant = ""
- f := xlsx.NewFile()
- if this.GetString("type") == "2" {
- where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (" + strings.Join(channelid, ",") + ")) and a.DataItem in (" + ChannelItem_Report + ") "
- _, channel := svc.GetPagingEntitiesWithOrderSearch(-1, 8, "c.sortcode,a.CreateOn desc", where, Uid)
- for i := 0; i < len(channel); i++ {
- name := channel[i].Title
- if name == "" {
- name = channel[i].Code
- }
- xlssheetname := utils.ToStr(i+1) + "." + name
- if DeviceItemContainint(ChannelItem_HaveO2, channel[i].DataItem) {
- this.Saveo2Xlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_HaveCO2, channel[i].DataItem) {
- this.Saveco2Xlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_Power, channel[i].DataItem) {
- this.SavepowerXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_Temperature, channel[i].DataItem) {
- this.SaveTemperatureXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_LiquidLevel, channel[i].DataItem) {
- this.SaveliquidlevelXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else {
- this.SaveXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- }
- }
- } else if this.GetString("serials") != "" {
- serials := strings.Split(this.GetString("serials"), ",")
- var codestring []string
- for i := 0; i < len(serials); i++ {
- codestring = append(codestring, "'c"+serials[i]+"'")
- }
- where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (" + strings.Join(channelid, ",") + ")) and a.DataItem in (" + ChannelItem_Report + ") and a.Code in(" + strings.Join(codestring, ",") + ")"
- _, channel := svc.GetPagingEntitiesWithOrderSearch(-1, 8, "c.sortcode,a.CreateOn desc", where, Uid)
- for i := 0; i < len(channel); i++ {
- name := channel[i].Title
- if name == "" {
- name = channel[i].Code
- }
- xlssheetname := utils.ToStr(i+1) + "." + name
- if DeviceItemContainint(ChannelItem_HaveO2, channel[i].DataItem) {
- this.Saveo2Xlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_HaveCO2, channel[i].DataItem) {
- this.Saveco2Xlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_Power, channel[i].DataItem) {
- this.SavepowerXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_Temperature, channel[i].DataItem) {
- this.SaveTemperatureXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else if DeviceItemContainint(ChannelItem_LiquidLevel, channel[i].DataItem) {
- this.SaveliquidlevelXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- } else {
- this.SaveXlsx(xlssheetname, channel[i].Code, timerange, u, p, f, start, end)
- }
- }
- }
- SaveDirectory("static/file/excel/report/" + this.GetAccode())
- f.Save("static/file/excel/report/" + this.GetAccode() + "/devicedata.xlsx")
- //this.Ctx.Output.Download("static/upload/excel/devicedata.xlsx")
- var errinfo ErrorInfo
- errinfo.Message = this.Ctx.Request.Host + "/static/file/excel/report/" + this.GetAccode() + "/devicedata.xlsx"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- func (this *DataExportsController) SaveTemperatureXlsx(name, code, timerange, u, p string, f *xlsx.File, start, end int64) {
- sheet, _ := f.AddSheet(name)
- rowname := sheet.AddRow()
- celln := rowname.AddCell()
- celln.Value = "名称:" + this.User.Realname
- rowhead := sheet.AddRow()
- _, cols, data := GetChannelInfov2(code, u, p, 1, start, end)
- headsname := headname{
- "时间",
- "温度",
- "电压",
- "",
- timerange,
- "",
- }
- rowhead.WriteStruct(&headsname, -1)
- indext := utils.SliceIndexOf(cols, "temperature")
- indexv := utils.SliceIndexOf(cols, "voltage")
- indextime := utils.SliceIndexOf(cols, "time")
- indexstate := utils.SliceIndexOf(cols, "devicestate") //设备状态
- for j, l := 0, len(data); j < l; j++ {
- row := sheet.AddRow()
- valuetime, _ := data[l-j-1][indextime].(json.Number).Float64()
- // valuetime, _ := data[l-j-1][indextime].(float64)
- tstr := ""
- if indext > -1 {
- tstr = utils.ToStr(data[l-j-1][indext])
- bbstate := ""
- if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "2" {
- bbstate = " (维修)"
- } else if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "3" {
- bbstate = " (停用)"
- } else if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "4" {
- bbstate = " (除霜)"
- }
- tstr += bbstate
- }
- vstr := ""
- if indexv > -1 {
- vstr = utils.ToStr(data[l-j-1][indexv])
- }
- testStruct := datas{
- time.Unix(int64(valuetime), 0).Format("2006-01-02 15:04:05"),
- tstr,
- vstr,
- "",
- }
- row.WriteStruct(&testStruct, -1)
- }
- sheet.Cols[0].Width = 20 //设置时间单元格的宽度
- }
- func (this *DataExportsController) SaveXlsx(name, code, timerange, u, p string, f *xlsx.File, start, end int64) {
- sheet, _ := f.AddSheet(name)
- rowname := sheet.AddRow()
- celln := rowname.AddCell()
- celln.Value = "名称:" + this.User.Realname
- rowhead := sheet.AddRow()
- _, cols, data := GetChannelInfov2(code, u, p, 1, start, end)
- headsname := headname{
- "时间",
- "温度",
- "湿度",
- "电压",
- "",
- timerange,
- }
- rowhead.WriteStruct(&headsname, -1)
- indext := utils.SliceIndexOf(cols, "temperature")
- indexh := utils.SliceIndexOf(cols, "humidity")
- indexv := utils.SliceIndexOf(cols, "voltage")
- indextime := utils.SliceIndexOf(cols, "time")
- indexstate := utils.SliceIndexOf(cols, "devicestate") //设备状态
- for j, l := 0, len(data); j < l; j++ {
- row := sheet.AddRow()
- valuetime, _ := data[l-j-1][indextime].(json.Number).Float64()
- // valuetime, _ := data[l-j-1][indextime].(float64)
- tstr := ""
- if indext > -1 {
- tstr = utils.ToStr(data[l-j-1][indext])
- bbstate := ""
- if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "2" {
- bbstate = " (维修)"
- } else if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "3" {
- bbstate = " (停用)"
- } else if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "4" {
- bbstate = " (除霜)"
- }
- tstr += bbstate
- }
- hstr := ""
- if indexh > -1 {
- hstr = utils.ToStr(data[l-j-1][indexh])
- }
- vstr := ""
- if indexv > -1 {
- vstr = utils.ToStr(data[l-j-1][indexv])
- }
- testStruct := datas{
- time.Unix(int64(valuetime), 0).Format("2006-01-02 15:04:05"),
- tstr,
- hstr,
- vstr,
- }
- row.WriteStruct(&testStruct, -1)
- }
- sheet.Cols[0].Width = 20 //设置时间单元格的宽度
- }
- func (this *DataExportsController) Saveo2Xlsx(name, code, timerange, u, p string, f *xlsx.File, start, end int64) {
- sheet, _ := f.AddSheet(name)
- rowname := sheet.AddRow()
- celln := rowname.AddCell()
- celln.Value = "名称:" + this.User.Realname
- rowhead := sheet.AddRow()
- _, cols, data := GetChannelInfov2(code, u, p, 1, start, end)
- headsname := headnameo2{
- "时间",
- "温度",
- "湿度",
- "电压",
- "氧气",
- "",
- timerange,
- }
- rowhead.WriteStruct(&headsname, -1)
- indext := utils.SliceIndexOf(cols, "temperature")
- indexh := utils.SliceIndexOf(cols, "humidity")
- indexv := utils.SliceIndexOf(cols, "voltage")
- indextime := utils.SliceIndexOf(cols, "time")
- indexo2 := utils.SliceIndexOf(cols, "o2")
- for j, l := 0, len(data); j < l; j++ {
- row := sheet.AddRow()
- valuetime, _ := data[l-j-1][indextime].(json.Number).Float64()
- //valuetime, _ := data[l-j-1][indextime].(float64)
- tstr := ""
- if indext > -1 {
- tstr = utils.ToStr(data[l-j-1][indext])
- }
- hstr := ""
- if indexh > -1 {
- hstr = utils.ToStr(data[l-j-1][indexh])
- }
- vstr := ""
- if indexv > -1 {
- vstr = utils.ToStr(data[l-j-1][indexv])
- }
- o2str := ""
- if indexo2 > -1 {
- o2str = utils.ToStr(data[l-j-1][indexo2])
- }
- testStruct := dataso2{
- time.Unix(int64(valuetime), 0).Format("2006-01-02 15:04:05"),
- tstr,
- hstr,
- vstr,
- o2str,
- }
- row.WriteStruct(&testStruct, -1)
- }
- sheet.Cols[0].Width = 20 //设置时间单元格的宽度
- }
- func (this *DataExportsController) Saveco2Xlsx(name, code, timerange, u, p string, f *xlsx.File, start, end int64) {
- sheet, _ := f.AddSheet(name)
- rowname := sheet.AddRow()
- celln := rowname.AddCell()
- celln.Value = "名称:" + this.User.Realname
- rowhead := sheet.AddRow()
- _, cols, data := GetChannelInfov2(code, u, p, 1, start, end)
- headsname := headnameo2{
- "时间",
- "温度",
- "湿度",
- "电压",
- "二氧化碳",
- "",
- timerange,
- }
- rowhead.WriteStruct(&headsname, -1)
- indext := utils.SliceIndexOf(cols, "temperature")
- indexh := utils.SliceIndexOf(cols, "humidity")
- indexv := utils.SliceIndexOf(cols, "voltage")
- indextime := utils.SliceIndexOf(cols, "time")
- indexco2 := utils.SliceIndexOf(cols, "co2")
- for j, l := 0, len(data); j < l; j++ {
- row := sheet.AddRow()
- valuetime, _ := data[l-j-1][indextime].(json.Number).Float64()
- // valuetime, _ := data[l-j-1][indextime].(float64)
- tstr := ""
- if indext > -1 {
- tstr = utils.ToStr(data[l-j-1][indext])
- }
- hstr := ""
- if indexh > -1 {
- hstr = utils.ToStr(data[l-j-1][indexh])
- }
- vstr := ""
- if indexv > -1 {
- vstr = utils.ToStr(data[l-j-1][indexv])
- }
- co2str := ""
- if indexco2 > -1 {
- co2str = utils.ToStr(data[l-j-1][indexco2])
- }
- testStruct := datasco2{
- time.Unix(int64(valuetime), 0).Format("2006-01-02 15:04:05"),
- tstr,
- hstr,
- vstr,
- co2str,
- }
- row.WriteStruct(&testStruct, -1)
- }
- sheet.Cols[0].Width = 20 //设置时间单元格的宽度
- }
- func (this *DataExportsController) SavepowerXlsx(name, code, timerange, u, p string, f *xlsx.File, start, end int64) {
- sheet, _ := f.AddSheet(name)
- rowname := sheet.AddRow()
- celln := rowname.AddCell()
- celln.Value = "名称:" + this.User.Realname
- rowhead := sheet.AddRow()
- _, cols, data := GetChannelInfov2(code, u, p, 1, start, end)
- headsname := headnamepower{
- "时间",
- "功率",
- "市电",
- "",
- timerange,
- }
- rowhead.WriteStruct(&headsname, -1)
- indexp := utils.SliceIndexOf(cols, "electricalpower")
- indexs := utils.SliceIndexOf(cols, "electricalsupply")
- indextime := utils.SliceIndexOf(cols, "time")
- for j, l := 0, len(data); j < l; j++ {
- row := sheet.AddRow()
- valuetime, _ := data[l-j-1][indextime].(json.Number).Float64()
- // valuetime, _ := data[l-j-1][indextime].(float64)
- pstr := ""
- if indexp > -1 {
- pstr = utils.ToStr(data[l-j-1][indexp])
- }
- sstr := ""
- if indexs > -1 {
- sstr = utils.ToStr(data[l-j-1][indexs])
- }
- testStruct := dataspower{
- time.Unix(int64(valuetime), 0).Format("2006-01-02 15:04:05"),
- pstr,
- sstr,
- }
- row.WriteStruct(&testStruct, -1)
- }
- sheet.Cols[0].Width = 20 //设置时间单元格的宽度
- }
- func (this *DataExportsController) SaveliquidlevelXlsx(name, code, timerange, u, p string, f *xlsx.File, start, end int64) {
- sheet, _ := f.AddSheet(name)
- rowname := sheet.AddRow()
- celln := rowname.AddCell()
- celln.Value = "名称:" + this.User.Realname
- rowhead := sheet.AddRow()
- _, cols, data := GetChannelInfov2(code, u, p, 1, start, end)
- headsname := headnameliquidlevel{
- "时间",
- "温度",
- "液位",
- "",
- timerange,
- }
- rowhead.WriteStruct(&headsname, -1)
- indext := utils.SliceIndexOf(cols, "temperature")
- indexl := utils.SliceIndexOf(cols, "liquidlevel")
- indextime := utils.SliceIndexOf(cols, "time")
- for j, l := 0, len(data); j < l; j++ {
- row := sheet.AddRow()
- valuetime, _ := data[l-j-1][indextime].(json.Number).Float64()
- // valuetime, _ := data[l-j-1][indextime].(float64)
- pstr := ""
- if indext > -1 {
- pstr = utils.ToStr(data[l-j-1][indext])
- }
- sstr := ""
- if indexl > -1 {
- sstr = utils.ToStr(data[l-j-1][indexl])
- }
- testStruct := dataspower{
- time.Unix(int64(valuetime), 0).Format("2006-01-02 15:04:05"),
- pstr,
- sstr,
- }
- row.WriteStruct(&testStruct, -1)
- }
- sheet.Cols[0].Width = 20 //设置时间单元格的宽度
- }
- // @Title 报表导出pdf
- // @Description 报表导出pdf
- // @Success 200 {object} business.device.DeviceChannels
- // @router /pdf [get]
- func (this *DataExportsController) GetPDF() {
- timerange := ""
- svc := device.GetDeviceService(utils.DBE)
- svcuc := userchannels.GetUserChannelService(utils.DBE)
- channelid := svcuc.GetChannelids(utils.ToStr(this.User.Id))
- Uid := utils.ToStr(this.User.Id)
- channel := make([]device.DeviceChannels, 0)
- if this.GetString("type") == "1" {
- serials := strings.Split(this.GetString("serials"), ",")
- var codestring []string
- for i := 0; i < len(serials); i++ {
- codestring = append(codestring, "'c"+serials[i]+"'")
- }
- where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (" + strings.Join(channelid, ",") + ")) and a.DataItem in (" + ChannelItem_Report + ") and a.Code in(" + strings.Join(codestring, ",") + ")"
- _, channel = svc.GetPagingEntitiesWithOrderSearch(-1, 8, "c.sortcode,a.CreateOn desc", where, Uid)
- } else {
- where := " (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (" + strings.Join(channelid, ",") + ")) and a.DataItem in (" + ChannelItem_Report + ") "
- _, channel = svc.GetPagingEntitiesWithOrderSearch(-1, 8, "c.sortcode,a.CreateOn desc", where, Uid)
- }
- start64, _ := this.GetInt64("start")
- end64, _ := this.GetInt64("end")
- begin_time := time.Unix(start64/1000, 0).Format("2006-01-02")
- end_time := time.Unix(end64/1000, 0).Format("2006-01-02")
- if begin_time == "" {
- this.Data["begin"] = utils.TimeFormat(time.Now().AddDate(0, 0, -7), "2006-01-02")
- timerange = utils.TimeFormat(time.Now().AddDate(0, 0, -7), "2006-01-02")
- } else {
- this.Data["begin"] = begin_time
- timerange = begin_time
- }
- if end_time == "" {
- this.Data["end"] = utils.TimeFormat(time.Now(), "2006-01-02")
- timerange += " 至 " + utils.TimeFormat(time.Now(), "2006-01-02")
- } else {
- this.Data["end"] = end_time
- timerange += " 至 " + end_time
- }
- t1, _ := utils.TimeParse(begin_time+" 00:00:00", "2006-1-2 15:4:5")
- t2, _ := utils.TimeParse(end_time+" 23:59:59", "2006-1-2 15:4:5")
- start := t1.Unix()
- end := t2.Unix()
- u, p := this.GetuAndp()
- pdf := gopdf.GoPdf{}
- pdf.Start(gopdf.Config{Unit: "pt", PageSize: gopdf.Rect{W: (200*4 + 600), H: (50*25 + 250)}})
- pdf.AddTTFFont("HDZB_5", "static/fonts/msyh.ttf")
- y := 0
- for k, v := range channel {
- if v.Code != "" {
- _, cols, data := GetChannelInfov2(v.Code, u, p, 1, start, end)
- indext := utils.SliceIndexOf(cols, "temperature") //温度
- indexh := utils.SliceIndexOf(cols, "humidity") //湿度
- indexv := utils.SliceIndexOf(cols, "voltage") //电压
- indextime := utils.SliceIndexOf(cols, "time") //时间
- indexco2 := utils.SliceIndexOf(cols, "co2") //二氧化碳
- indexo2 := utils.SliceIndexOf(cols, "o2") //氧气
- indexpower := utils.SliceIndexOf(cols, "electricalpower") //功率
- indexsupply := utils.SliceIndexOf(cols, "electricalsupply") //市电
- indexstate := utils.SliceIndexOf(cols, "devicestate") //设备状态
- indexliquidlevel := utils.SliceIndexOf(cols, "liquidlevel") //液位
- num := 0
- if len(cols) == 0 {
- if DeviceItemContainint(ChannelItem_TAndH, v.DataItem) {
- num = num + 3
- } else if DeviceItemContainint(ChannelItem_Temperature, v.DataItem) {
- num = num + 2
- } else if DeviceItemContainint(ChannelItem_O2, v.DataItem) {
- num = num + 4
- } else if DeviceItemContainint(ChannelItem_Co2, v.DataItem) {
- num = num + 4
- } else if DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- num = num + 2
- } else if DeviceItemContainint(ChannelItem_HaveLiquidLevel, v.DataItem) {
- num = num + 2
- }
- } else {
- if indexv > -1 && DeviceItemContainint(ChannelItem_HaveV, v.DataItem) {
- num = num + 1
- }
- if indext > -1 && DeviceItemContainint(ChannelItem_HaveT, v.DataItem) {
- num = num + 1
- }
- if indexh > -1 && DeviceItemContainint(ChannelItem_HaveH, v.DataItem) {
- num = num + 1
- }
- if indexco2 > -1 && DeviceItemContainint(ChannelItem_HaveCO2, v.DataItem) {
- num = num + 1
- }
- if indexo2 > -1 && DeviceItemContainint(ChannelItem_HaveO2, v.DataItem) {
- num = num + 1
- }
- if indexpower > -1 && DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- num = num + 1
- }
- if indexsupply > -1 && DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- num = num + 1
- }
- if indexliquidlevel > -1 && DeviceItemContainint(ChannelItem_LiquidLevel, v.DataItem) {
- num = num + 1
- }
- }
- var times float64
- var report float64
- var i float64
- report = float64(25)
- times = float64(num)
- //pdf.Start(gopdf.Config{Unit: "pt", PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
- pdf.AddPage()
- pdf.SetFont("HDZB_5", "B", 24) //字体
- pdf.Line(100, 100, 100, 50*report+150) //竖线
- pdf.Line(100, 100, 200*times+500, 100) //横线
- //页码
- y = y + 1
- yy := utils.ToStr(y)
- pdf.Curr.X = (200*times + 500) / 2
- pdf.Curr.Y = 1450
- pdf.Cell(nil, "第 "+yy+" 页")
- for i = 0; i <= times; i++ {
- pdf.Line(200*i+500, 100, 200*i+500, 50*report+150) //竖线
- }
- for i = 0; i <= report; i++ {
- pdf.Line(100, 50*i+150, 200*times+500, 50*i+150) //横线
- }
- pdf.Curr.X = 130
- pdf.Curr.Y = 30
- pdf.Cell(nil, "名称:"+this.User.Realname)
- pdf.Curr.X = 130
- pdf.Curr.Y = 70
- pdf.Cell(nil, "设备:"+channel[k].Title)
- pdf.Curr.X = 200*times + 200
- pdf.Curr.Y = 70
- pdf.Cell(nil, begin_time+"至"+end_time)
- pdf.Curr.X = 150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "时间")
- if len(cols) == 0 {
- if DeviceItemContainint(ChannelItem_TAndH, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- } else if DeviceItemContainint(ChannelItem_Temperature, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- } else if DeviceItemContainint(ChannelItem_O2, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "氧气")
- } else if DeviceItemContainint(ChannelItem_Co2, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "二氧化碳")
- } else if DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "功率")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "市电")
- } else if DeviceItemContainint(ChannelItem_HaveLiquidLevel, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "液位")
- }
- } else {
- if indexv > -1 && DeviceItemContainint(ChannelItem_HaveV, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- }
- if indext > -1 && DeviceItemContainint(ChannelItem_HaveT, v.DataItem) {
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- }
- if indexh > -1 && DeviceItemContainint(ChannelItem_HaveH, v.DataItem) {
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- }
- if indexco2 > -1 && DeviceItemContainint(ChannelItem_HaveCO2, v.DataItem) {
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "二氧化碳")
- }
- if indexo2 > -1 && DeviceItemContainint(ChannelItem_HaveO2, v.DataItem) {
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "氧气")
- }
- if indexpower > -1 && DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "功率")
- }
- if indexsupply > -1 && DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "市电")
- }
- if DeviceItemContainint(ChannelItem_LiquidLevel, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "液位")
- }
- }
- for j, l := 0, len(data); j < l; j++ {
- yu := j % 25
- if j != 0 && yu == 0 {
- pdf.AddPage()
- pdf.SetFont("HDZB_5", "B", 24) //字体
- pdf.Line(100, 100, 100, 50*report+150) //竖线
- pdf.Line(100, 100, 200*times+500, 100) //横线
- for i = 0; i <= times; i++ {
- pdf.Line(200*i+500, 100, 200*i+500, 50*report+150) //竖线
- }
- for i = 0; i <= report; i++ {
- pdf.Line(100, 50*i+150, 200*times+500, 50*i+150) //横线
- }
- //页码
- y = y + 1
- yy := utils.ToStr(y)
- pdf.Curr.X = (200*times + 500) / 2
- pdf.Curr.Y = 1450
- pdf.Cell(nil, "第 "+yy+" 页")
- pdf.Curr.X = 130
- pdf.Curr.Y = 30
- pdf.Cell(nil, "名称:"+this.User.Realname)
- pdf.Curr.X = 130
- pdf.Curr.Y = 70
- pdf.Cell(nil, "设备"+":"+channel[k].Title)
- pdf.Curr.X = 200*times + 200
- pdf.Curr.Y = 70
- pdf.Cell(nil, begin_time+"至"+end_time)
- pdf.Curr.X = 150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "时间")
- if len(cols) == 0 {
- if DeviceItemContainint(ChannelItem_TAndH, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- } else if DeviceItemContainint(ChannelItem_Temperature, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- } else if DeviceItemContainint(ChannelItem_O2, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "氧气")
- } else if DeviceItemContainint(ChannelItem_Co2, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "二氧化碳")
- } else if DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "功率")
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "市电")
- } else if DeviceItemContainint(ChannelItem_LiquidLevel, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "液位")
- }
- } else {
- if indexv > -1 && DeviceItemContainint(ChannelItem_HaveV, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "电压")
- }
- if indext > -1 && DeviceItemContainint(ChannelItem_HaveT, v.DataItem) {
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "温度")
- }
- if indexh > -1 && DeviceItemContainint(ChannelItem_HaveH, v.DataItem) {
- pdf.Curr.X = 950
- pdf.Curr.Y = 120
- pdf.Cell(nil, "湿度")
- }
- if indexco2 > -1 && DeviceItemContainint(ChannelItem_HaveCO2, v.DataItem) {
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "二氧化碳")
- }
- if indexo2 > -1 && DeviceItemContainint(ChannelItem_HaveO2, v.DataItem) {
- pdf.Curr.X = 1150
- pdf.Curr.Y = 120
- pdf.Cell(nil, "氧气")
- }
- if indexpower > -1 && DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "功率")
- }
- if indexsupply > -1 && DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- pdf.Curr.X = 750
- pdf.Curr.Y = 120
- pdf.Cell(nil, "市电")
- }
- if DeviceItemContainint(ChannelItem_LiquidLevel, v.DataItem) {
- pdf.Curr.X = 550
- pdf.Curr.Y = 120
- pdf.Cell(nil, "液位")
- }
- }
- }
- valuetime, _ := data[l-j-1][indextime].(json.Number).Float64()
- times := time.Unix(int64(valuetime), 0).Format("2006-01-02 15:04:05") //时间
- //时间
- pdf.Curr.X = 150
- pdf.Curr.Y = 50*float64(yu+1) + 120
- pdf.Cell(nil, times)
- voltage := ""
- if indexv > -1 && DeviceItemContainint(ChannelItem_HaveV, v.DataItem) {
- voltage = utils.ToStr(data[l-j-1][indexv])
- //电压
- pdf.Curr.X = 550
- pdf.Curr.Y = 50*float64(yu+1) + 120
- pdf.Cell(nil, voltage)
- }
- temperature := ""
- if indext > -1 && DeviceItemContainint(ChannelItem_HaveT, v.DataItem) {
- temperature = utils.ToStr(data[l-j-1][indext])
- //温度
- pdf.Curr.X = 750
- pdf.Curr.Y = 50*float64(yu+1) + 120
- bbstate := ""
- if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "2" {
- bbstate = " (维修)"
- } else if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "3" {
- bbstate = " (停用)"
- } else if indexstate > -1 && utils.ToStr(data[l-j-1][indexstate]) == "4" {
- bbstate = " (除霜)"
- }
- pdf.Cell(nil, temperature+bbstate)
- }
- humidity := ""
- if indexh > -1 && DeviceItemContainint(ChannelItem_HaveH, v.DataItem) {
- humidity = utils.ToStr(data[l-j-1][indexh])
- //湿度
- pdf.Curr.X = 950
- pdf.Curr.Y = 50*float64(yu+1) + 120
- pdf.Cell(nil, humidity)
- }
- co2 := ""
- if indexco2 > -1 && DeviceItemContainint(ChannelItem_HaveCO2, v.DataItem) {
- co2 = utils.ToStr(data[l-j-1][indexco2])
- //二氧化碳
- pdf.Curr.X = 1150
- pdf.Curr.Y = 50*float64(yu+1) + 120
- pdf.Cell(nil, co2)
- }
- o2 := ""
- if indexo2 > -1 && DeviceItemContainint(ChannelItem_HaveO2, v.DataItem) {
- o2 = utils.ToStr(data[l-j-1][indexo2])
- //氧气
- pdf.Curr.X = 1150
- pdf.Curr.Y = 50*float64(yu+1) + 120
- pdf.Cell(nil, o2)
- }
- if DeviceItemContainint(ChannelItem_Power, v.DataItem) {
- powerv, supplyv := "", ""
- powerv = utils.ToStr(data[l-j-1][indexpower])
- //功率
- pdf.Curr.X = 550
- pdf.Curr.Y = 50*float64(yu+1) + 120
- pdf.Cell(nil, powerv)
- supplyv = utils.ToStr(data[l-j-1][indexsupply])
- //市电
- pdf.Curr.X = 750
- pdf.Curr.Y = 50*float64(yu+1) + 120
- pdf.Cell(nil, supplyv)
- }
- if DeviceItemContainint(ChannelItem_LiquidLevel, v.DataItem) {
- liquidlevelv := ""
- pdf.Curr.X = 550
- pdf.Curr.Y = 50*float64(yu+1) + 120
- liquidlevelv = utils.ToStr(data[l-j-1][indexliquidlevel])
- //液位
- pdf.Cell(nil, liquidlevelv)
- }
- }
- }
- }
- SaveDirectory("static/file/pdf/report/" + this.GetAccode())
- pdf.WritePdf("static/file/pdf/report/" + this.GetAccode() + "/devicedata.pdf")
- var errinfo ErrorInfo
- errinfo.Message = this.Ctx.Request.Host + "/static/file/pdf/report/" + this.GetAccode() + "/devicedata.pdf"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
|