|
@@ -26,16 +26,8 @@ type GoodsOrderController struct {
|
|
|
}
|
|
|
|
|
|
func (c *GoodsOrderController) Prepare() {
|
|
|
- GetCookie := c.Ctx.GetCookie("User_tokey")
|
|
|
- GetString := c.GetString("User_tokey")
|
|
|
-
|
|
|
- User_tokey := GetCookie
|
|
|
- if len(User_tokey) == 0 {
|
|
|
- User_tokey = GetString
|
|
|
- }
|
|
|
-
|
|
|
- c.User_r = Account.User_r
|
|
|
- c.T_pid = Account.T_pid
|
|
|
+ c.User_r = *Account.User_r
|
|
|
+ c.T_pid = *Account.T_pid
|
|
|
}
|
|
|
|
|
|
func (c *GoodsOrderController) GoodsOrder_List() {
|
|
@@ -280,6 +272,12 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
var DeviceSensor_data []Device.DeviceData_R
|
|
|
DeviceSensor_data, _ = NatsServer.ReadDeviceDataListBy_T_snid(GoodsOrder_r.T_sn+","+strconv.Itoa(DeviceSensor_r[0].T_id), GoodsOrder_r.T_start_Ut.Format("2006-01-02 15:04:05"), GoodsOrder_r.T_end_Ut.Format("2006-01-02 15:04:05"), 0, 9999)
|
|
|
|
|
|
+ if len(DeviceSensor_data) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: GoodsOrder_r.T_sn + "设备没有数据!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
pdf := &gopdf.GoPdf{}
|
|
|
pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
|
|
|
//err = GetFont(pdf, "LiberationSerif-Regular.ttf")
|
|
@@ -293,13 +291,13 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
|
|
|
err = pdf.AddTTFFont("simsun", "static/fonts/三极行楷简体-粗.ttf")
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!", Data: err}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 204, Msg: err.Error()}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
err = pdf.SetFont("simsun", "", 24)
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "ok!", Data: err}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 205, Msg: err.Error()}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
@@ -324,13 +322,13 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
|
|
|
err = pdf.AddTTFFont("wts", "static/fonts/MiSans-Medium.ttf")
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "ok!", Data: err}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 206, Msg: err.Error()}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
err = pdf.SetFont("wts", "", 10)
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
@@ -390,6 +388,65 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
lib.RectFillColor(pdf, T_text, 12, x, 140, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
x += w2
|
|
|
|
|
|
+ // 数据汇总--------------------------------
|
|
|
+
|
|
|
+ // 最低温度
|
|
|
+ var T_t_l float32 = 100.0
|
|
|
+ // 最高温度
|
|
|
+ var T_t_u float32 = 0.0
|
|
|
+ var T_t_v float32 = 0.0
|
|
|
+ for n := 0; len(DeviceSensor_data) > n; n++ {
|
|
|
+ // -计算温度
|
|
|
+ if DeviceSensor_data[n].T_t < T_t_l {
|
|
|
+ T_t_l = DeviceSensor_data[n].T_t
|
|
|
+ }
|
|
|
+ if DeviceSensor_data[n].T_t > T_t_u {
|
|
|
+ T_t_u = DeviceSensor_data[n].T_t
|
|
|
+ }
|
|
|
+ T_t_v += DeviceSensor_data[n].T_t
|
|
|
+ }
|
|
|
+
|
|
|
+ var y float64 = 160
|
|
|
+ x = 22.0
|
|
|
+ w1 = 60.0
|
|
|
+ w2 = 50.0
|
|
|
+
|
|
|
+ err = pdf.SetFont("wts", "", 10)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ T_t := fmt.Sprintf(" %.1f℃ ", DeviceSensor_data[len(DeviceSensor_data)-1].T_t)
|
|
|
+ lib.RectFillColor(pdf, "起送温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ T_t = fmt.Sprintf(" %.1f℃ ", DeviceSensor_data[0].T_t)
|
|
|
+ lib.RectFillColor(pdf, "送达温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ T_t = fmt.Sprintf(" %.1f℃ ", T_t_l)
|
|
|
+ lib.RectFillColor(pdf, "最低温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ T_t = fmt.Sprintf(" %.1f℃ ", T_t_v/float32(len(DeviceSensor_data)))
|
|
|
+ lib.RectFillColor(pdf, "平均温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ T_t = fmt.Sprintf(" %.1f℃ ", T_t_u)
|
|
|
+ lib.RectFillColor(pdf, "最高温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
// -----------
|
|
|
textw, _ = pdf.MeasureTextWidth("历史数据")
|
|
|
pdf.SetX(20)
|
|
@@ -397,7 +454,8 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
pdf.Text("历史数据:")
|
|
|
|
|
|
// 数据展示--------------------------------
|
|
|
- var y float64 = 220
|
|
|
+ //var y float64 = 220
|
|
|
+ y = 220
|
|
|
x = 22.0
|
|
|
w1 = 94.0
|
|
|
w2 = 43.0
|
|
@@ -424,26 +482,13 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
|
|
|
err = pdf.SetFont("wts", "", 8)
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
nln := 0
|
|
|
x = 22.0
|
|
|
- var T_t_l float32 = 100.0
|
|
|
- var T_t_u float32 = 0.0
|
|
|
- var T_t_v float32 = 0.0
|
|
|
for n := 0; len(DeviceSensor_data) > n; n++ {
|
|
|
- // -计算温度
|
|
|
- if DeviceSensor_data[n].T_t < T_t_l {
|
|
|
- T_t_l = DeviceSensor_data[n].T_t
|
|
|
- }
|
|
|
- if DeviceSensor_data[n].T_t > T_t_u {
|
|
|
- T_t_u = DeviceSensor_data[n].T_t
|
|
|
- }
|
|
|
- T_t_v += DeviceSensor_data[n].T_t
|
|
|
-
|
|
|
- //text := fmt.Sprintf(" %d ", i+1)
|
|
|
var textH float64 = 25 // if text height is 25px.
|
|
|
pdf.SetNewY(y, textH)
|
|
|
y = pdf.GetY()
|
|
@@ -455,8 +500,14 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
y += 18
|
|
|
}
|
|
|
|
|
|
+ if y >= 794 {
|
|
|
+ pdf.AddPage()
|
|
|
+ x = 22.0
|
|
|
+ y = 20
|
|
|
+ }
|
|
|
+
|
|
|
// ------------------
|
|
|
- T_t := fmt.Sprintf(" %.1f ", DeviceSensor_data[n].T_t)
|
|
|
+ T_t = fmt.Sprintf(" %.1f ", DeviceSensor_data[n].T_t)
|
|
|
T_time = fmt.Sprintf("%s", DeviceSensor_data[n].T_time)
|
|
|
|
|
|
lib.RectFillColor(pdf, T_time, 10, x, y, w1, 18, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
@@ -468,57 +519,22 @@ func (c *GoodsOrderController) GoodsOrder_PDF() {
|
|
|
|
|
|
err = pdf.SetFont("wts", "", 10)
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- // 数据汇总--------------------------------
|
|
|
- y = 160
|
|
|
- x = 22.0
|
|
|
- w1 = 60.0
|
|
|
- w2 = 50.0
|
|
|
-
|
|
|
- T_t := fmt.Sprintf(" %.1f℃ ", DeviceSensor_data[len(DeviceSensor_data)-1].T_t)
|
|
|
- lib.RectFillColor(pdf, "起送温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w1
|
|
|
- lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w2
|
|
|
-
|
|
|
- T_t = fmt.Sprintf(" %.1f℃ ", DeviceSensor_data[0].T_t)
|
|
|
- lib.RectFillColor(pdf, "送达温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w1
|
|
|
- lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w2
|
|
|
-
|
|
|
- T_t = fmt.Sprintf(" %.1f℃ ", T_t_l)
|
|
|
- lib.RectFillColor(pdf, "最低温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w1
|
|
|
- lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w2
|
|
|
-
|
|
|
- T_t = fmt.Sprintf(" %.1f℃ ", float32(T_t_v/float32(len(DeviceSensor_data)-1)))
|
|
|
- lib.RectFillColor(pdf, "平均温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w1
|
|
|
- lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w2
|
|
|
-
|
|
|
- T_t = fmt.Sprintf(" %.1f℃ ", T_t_u)
|
|
|
- lib.RectFillColor(pdf, "最高温度", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w1
|
|
|
- lib.RectFillColor(pdf, T_t, 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
- x += w2
|
|
|
|
|
|
//----------------
|
|
|
timeStr := "ofile/" + time.Now().Format("20060102150405") + ".pdf"
|
|
|
|
|
|
err = pdf.WritePdf(timeStr)
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 207, Msg: "ok!", Data: err}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 上传 OSS
|
|
|
+ //上传 OSS
|
|
|
url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/"+timeStr, timeStr)
|
|
|
if !is {
|
|
|
c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
|