|
@@ -91,7 +91,7 @@ func (c *TaskDataController) TaskData_List() {
|
|
c.ServeJSON()
|
|
c.ServeJSON()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-func (c *TaskDataController) TaskData_Pdf() {
|
|
|
|
|
|
+func (c *TaskDataController) TaskData_Temperature_Pdf() {
|
|
|
|
|
|
Time_start := c.GetString("Time_start")
|
|
Time_start := c.GetString("Time_start")
|
|
Time_end := c.GetString("Time_end")
|
|
Time_end := c.GetString("Time_end")
|
|
@@ -171,7 +171,7 @@ func (c *TaskDataController) TaskData_Pdf() {
|
|
pdf.Text(name)
|
|
pdf.Text(name)
|
|
|
|
|
|
y += 20
|
|
y += 20
|
|
- title := Task_r.T_name + "验证数据"
|
|
|
|
|
|
+ title := Task_r.T_name + "温度验证数据"
|
|
textw, _ = pdf.MeasureTextWidth(title)
|
|
textw, _ = pdf.MeasureTextWidth(title)
|
|
pdf.SetX((595 / 2) - (textw / 2))
|
|
pdf.SetX((595 / 2) - (textw / 2))
|
|
pdf.SetY(y)
|
|
pdf.SetY(y)
|
|
@@ -246,7 +246,179 @@ func (c *TaskDataController) TaskData_Pdf() {
|
|
y += 20
|
|
y += 20
|
|
}
|
|
}
|
|
filename := time.Now().Format("20060102150405") + ".pdf"
|
|
filename := time.Now().Format("20060102150405") + ".pdf"
|
|
- timeStr := "ofile/" + filename
|
|
|
|
|
|
+ timeStr := "ofile/温度" + filename
|
|
|
|
+
|
|
|
|
+ err = pdf.WritePdf(timeStr)
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ defer func() {
|
|
|
|
+ //删除目录
|
|
|
|
+ os.Remove(timeStr)
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ c.Ctx.Output.Download(timeStr)
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+func (c *TaskDataController) TaskData_Humidity_Pdf() {
|
|
|
|
+
|
|
|
|
+ Time_start := c.GetString("Time_start")
|
|
|
|
+ Time_end := c.GetString("Time_end")
|
|
|
|
+ T_snid := c.GetString("T_snid")
|
|
|
|
+
|
|
|
|
+ T_task_id := c.GetString("T_task_id")
|
|
|
|
+ Task_r, err := NatsServer.Read_Task(T_task_id)
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if Task_r.T_collection_state == 2 {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ user, err := NatsServer.Read_User(Task_r.T_uuid)
|
|
|
|
+ var T_snid_list []string
|
|
|
|
+ if len(T_snid) > 0 {
|
|
|
|
+ T_snid_list = strings.Split(strings.Trim(T_snid, "|"), "|")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dataMap := make(map[string]string)
|
|
|
|
+ timeMap := make(map[string]bool)
|
|
|
|
+ //classList := Task.Read_TaskData_ById_ClassList(Task_r.T_task_id)
|
|
|
|
+ //for _, i2 := range classList {
|
|
|
|
+ // T_snid_list = append(T_snid_list, fmt.Sprintf("%s,%s", i2.T_sn, i2.T_id))
|
|
|
|
+ //}
|
|
|
|
+ for _, v := range T_snid_list {
|
|
|
|
+ sn_id := strings.Split(v, ",")
|
|
|
|
+ if len(sn_id) == 2 {
|
|
|
|
+ List, _ := Task.Read_TaskData_ById_List(Task_r.T_task_id, sn_id[0], sn_id[1], Time_start, Time_end, 0, 9999)
|
|
|
|
+
|
|
|
|
+ for _, data := range List {
|
|
|
|
+ k := fmt.Sprintf("%s,%s", data.T_time, data.T_id)
|
|
|
|
+ dataMap[k] = fmt.Sprintf("%.1f", data.T_rh)
|
|
|
|
+ if _, ok := timeMap[data.T_time]; !ok {
|
|
|
|
+ timeMap[data.T_time] = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var timeList []string
|
|
|
|
+ for k, _ := range timeMap {
|
|
|
|
+ timeList = append(timeList, k)
|
|
|
|
+ }
|
|
|
|
+ sort.Slice(timeList, func(i, j int) bool {
|
|
|
|
+ return timeList[i] < timeList[j]
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ pdf := &gopdf.GoPdf{}
|
|
|
|
+ pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
|
|
|
|
+
|
|
|
|
+ err = pdf.AddTTFFont("wts", "static/fonts/MiSans-Medium.ttf")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ err = pdf.SetFont("wts", "", 15)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pdf.SetGrayFill(0.5)
|
|
|
|
+
|
|
|
|
+ pdf.SetMargins(0, 20, 0, 20)
|
|
|
|
+ pdf.AddPage()
|
|
|
|
+ imgH, _ := gopdf.ImageHolderByPath("./ofile/logo.jpg")
|
|
|
|
+ err = pdf.ImageByHolder(imgH, 10, 10, &gopdf.Rect{W: 93, H: 32})
|
|
|
|
+ name := user.T_name
|
|
|
|
+
|
|
|
|
+ var y float64 = 40
|
|
|
|
+ textw, _ := pdf.MeasureTextWidth(name)
|
|
|
|
+ pdf.SetX((595 / 2) - (textw / 2))
|
|
|
|
+ pdf.SetY(y)
|
|
|
|
+ pdf.Text(name)
|
|
|
|
+
|
|
|
|
+ y += 20
|
|
|
|
+ title := Task_r.T_name + "湿度验证数据"
|
|
|
|
+ textw, _ = pdf.MeasureTextWidth(title)
|
|
|
|
+ pdf.SetX((595 / 2) - (textw / 2))
|
|
|
|
+ pdf.SetY(y)
|
|
|
|
+ pdf.Text(title)
|
|
|
|
+
|
|
|
|
+ if len(timeList) > 0 {
|
|
|
|
+ y += 20
|
|
|
|
+ timeStr := fmt.Sprintf("%s - %s", timeList[0], timeList[len(timeList)-1])
|
|
|
|
+ textw, _ = pdf.MeasureTextWidth(timeStr)
|
|
|
|
+ pdf.SetX((595 / 2) - (textw / 2))
|
|
|
|
+ pdf.SetY(y)
|
|
|
|
+ pdf.Text(timeStr)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = pdf.SetFont("wts", "", 10)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ y += 20
|
|
|
|
+ var x float64 = 10
|
|
|
|
+ var w float64 = 120
|
|
|
|
+
|
|
|
|
+ chunks := chunkBy(T_snid_list, 15)
|
|
|
|
+ for _, list := range chunks {
|
|
|
|
+ x = 10
|
|
|
|
+ w = 120
|
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
|
+ x += w
|
|
|
|
+ w = 30
|
|
|
|
+ for _, v2 := range list {
|
|
|
|
+ sn_id2 := strings.Split(v2, ",")
|
|
|
|
+ id2 := sn_id2[1]
|
|
|
|
+ lib.RectFillColor(pdf, id2, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
|
+ x += w
|
|
|
|
+ }
|
|
|
|
+ y += 20
|
|
|
|
+
|
|
|
|
+ for _, t := range timeList {
|
|
|
|
+ x = 10
|
|
|
|
+ var textH float64 = 20 // if text height is 25px.
|
|
|
|
+ pdf.SetNewY(y, textH)
|
|
|
|
+ y = pdf.GetY()
|
|
|
|
+ if y == 20 {
|
|
|
|
+ w = 120
|
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
|
+ x += w
|
|
|
|
+ w = 30
|
|
|
|
+ for _, v2 := range list {
|
|
|
|
+ sn_id2 := strings.Split(v2, ",")
|
|
|
|
+ id2 := sn_id2[1]
|
|
|
|
+ lib.RectFillColor(pdf, id2, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
|
+ x += w
|
|
|
|
+ }
|
|
|
|
+ y += 20
|
|
|
|
+ x = 10
|
|
|
|
+ }
|
|
|
|
+ w = 120
|
|
|
|
+ lib.RectFillColor(pdf, t, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
|
+ x += w
|
|
|
|
+ w = 30
|
|
|
|
+ for _, v := range list {
|
|
|
|
+ sn_id := strings.Split(v, ",")
|
|
|
|
+ id := sn_id[1]
|
|
|
|
+ t_t := dataMap[fmt.Sprintf("%s,%s", t, id)]
|
|
|
|
+ lib.RectFillColor(pdf, t_t, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
|
+ x += w
|
|
|
|
+ }
|
|
|
|
+ y += 20
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ y += 20
|
|
|
|
+ }
|
|
|
|
+ filename := time.Now().Format("20060102150405") + ".pdf"
|
|
|
|
+ timeStr := "ofile/湿度" + filename
|
|
|
|
|
|
err = pdf.WritePdf(timeStr)
|
|
err = pdf.WritePdf(timeStr)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -326,18 +498,12 @@ func (c *TaskDataController) TaskDataClass_Edit() {
|
|
c.ServeJSON()
|
|
c.ServeJSON()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- //id, err := Task.Read_TaskData_ByT_sn(Task_r.T_task_id, T_sn)
|
|
|
|
- //if err != nil && !errors.Is(err, orm.ErrNoRows) {
|
|
|
|
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
|
|
|
|
- // c.ServeJSON()
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
- //if len(id) > 0 && id != T_id {
|
|
|
|
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("sn[%s]已被编号[%s]关联,请修改后重试!", T_sn, id)}
|
|
|
|
- // c.ServeJSON()
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
-
|
|
|
|
|
|
+ err = NatsServer.Edit_DeviceClassList(T_task_id, T_sn, T_id)
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
err = Task.Update_TaskData_ByT_sn(Task_r.T_task_id, T_sn, T_id)
|
|
err = Task.Update_TaskData_ByT_sn(Task_r.T_task_id, T_sn, T_id)
|
|
if err != nil {
|
|
if err != nil {
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
|
|
@@ -446,6 +612,15 @@ func (c *TaskDataController) TaskData_AddS() {
|
|
c.ServeJSON()
|
|
c.ServeJSON()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 同步设备到线上
|
|
|
|
+ err = NatsServer.Add_DeviceClassList(T_task_id, T_sn, T_id)
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
for _, v := range T_Data_list {
|
|
for _, v := range T_Data_list {
|
|
@@ -621,6 +796,16 @@ func (c *TaskDataController) TaskData_Add() {
|
|
T_t, _ := c.GetFloat("T_t")
|
|
T_t, _ := c.GetFloat("T_t")
|
|
T_rh, _ := c.GetFloat("T_rh")
|
|
T_rh, _ := c.GetFloat("T_rh")
|
|
T_time := c.GetString("T_time")
|
|
T_time := c.GetString("T_time")
|
|
|
|
+ if len(T_sn) == 0 {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn 不能为空!"}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if len(T_id) == 0 {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id 不能为空!"}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
T_task_id := c.GetString("T_task_id")
|
|
T_task_id := c.GetString("T_task_id")
|
|
Task_r, err := NatsServer.Read_Task(T_task_id)
|
|
Task_r, err := NatsServer.Read_Task(T_task_id)
|
|
@@ -652,6 +837,15 @@ func (c *TaskDataController) TaskData_Add() {
|
|
c.ServeJSON()
|
|
c.ServeJSON()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ // 同步设备到线上
|
|
|
|
+ if T_t == 0 && T_rh == 0 {
|
|
|
|
+ err = NatsServer.Add_DeviceClassList(T_task_id, T_sn, T_id)
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
|
+ c.ServeJSON()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
is := Task.Add_TaskData(Task_r.T_task_id, T_sn, T_id, fmt.Sprintf("%.2f", T_t), fmt.Sprintf("%.2f", T_rh), T_time)
|
|
is := Task.Add_TaskData(Task_r.T_task_id, T_sn, T_id, fmt.Sprintf("%.2f", T_t), fmt.Sprintf("%.2f", T_rh), T_time)
|
|
if !is {
|
|
if !is {
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
|