|
@@ -0,0 +1,721 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "Cold_GoodsOrder/Nats/NatsServer"
|
|
|
+ "Cold_GoodsOrder/conf"
|
|
|
+ "Cold_GoodsOrder/lib"
|
|
|
+ "Cold_GoodsOrder/models/Account"
|
|
|
+ "Cold_GoodsOrder/models/Device"
|
|
|
+ "Cold_GoodsOrder/models/Function"
|
|
|
+ "encoding/base64"
|
|
|
+ "fmt"
|
|
|
+ "image"
|
|
|
+ "log"
|
|
|
+ "math"
|
|
|
+ "net/url"
|
|
|
+ "os"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ beego "github.com/beego/beego/v2/server/web"
|
|
|
+ "github.com/qiniu/go-sdk/v7/sms/bytes"
|
|
|
+ "github.com/signintech/gopdf"
|
|
|
+)
|
|
|
+
|
|
|
+// Handle
|
|
|
+type OrderController struct {
|
|
|
+ beego.Controller
|
|
|
+ User_r Account.User // 登陆的用户
|
|
|
+ T_pid int // 公司id
|
|
|
+}
|
|
|
+
|
|
|
+func (c *OrderController) Prepare() {
|
|
|
+ c.User_r = *Account.User_r
|
|
|
+ c.T_pid = *Account.T_pid
|
|
|
+}
|
|
|
+
|
|
|
+func (c *OrderController) Order_List() {
|
|
|
+ type R_JSONS struct {
|
|
|
+ //必须的大写开头
|
|
|
+ Data []Function.OrderR
|
|
|
+ Num int64
|
|
|
+ Page int
|
|
|
+ Page_size int
|
|
|
+ }
|
|
|
+
|
|
|
+ var r_jsons R_JSONS
|
|
|
+
|
|
|
+ page, _ := c.GetInt("page")
|
|
|
+ if page < 1 {
|
|
|
+ page = 1
|
|
|
+ }
|
|
|
+ page_z, _ := c.GetInt("page_z")
|
|
|
+ if page_z < 1 {
|
|
|
+ page_z = conf.Page_size
|
|
|
+ }
|
|
|
+ t_sn := c.GetString("t_sn")
|
|
|
+ orderid := c.GetString("t_orderid")
|
|
|
+ startTime := c.GetString("startTime")
|
|
|
+ endTime := c.GetString("endTime")
|
|
|
+ c.Data["Name"] = t_sn
|
|
|
+
|
|
|
+ r_jsons.Data, r_jsons.Num = Function.Read_Order_List(c.User_r.T_pid, page, page_z, orderid, t_sn, startTime, endTime)
|
|
|
+ r_jsons.Page = page
|
|
|
+ r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+func (c *OrderController) CreateOrderNo() {
|
|
|
+ format := time.Now().Format("20060102")
|
|
|
+ unix := time.Now().Unix()
|
|
|
+ OrderNo := fmt.Sprintf("%v%v", format, unix)
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: OrderNo}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+func (c *OrderController) Order_Add() {
|
|
|
+ T_orderid := c.GetString("T_orderid")
|
|
|
+ WaybillNo := c.GetString("WaybillNo")
|
|
|
+ T_sn := c.GetString("T_sn")
|
|
|
+ T_receiving := c.GetString("T_receiving")
|
|
|
+ ShippingUnit := c.GetString("ShippingUnit")
|
|
|
+ EstimateStartTime := c.GetString("EstimateStartTime")
|
|
|
+ EstimateEndTime := c.GetString("EstimateEndTime")
|
|
|
+ T_text := c.GetString("T_text")
|
|
|
+ PeerList := c.GetString("PeerList")
|
|
|
+ DeviceType := c.GetString("DeviceType")
|
|
|
+ IsExpatriate, _ := c.GetInt("IsExpatriate")
|
|
|
+ Phone := c.GetString("Phone")
|
|
|
+ ChildPid := c.GetString("ChildPid")
|
|
|
+ if len(EstimateStartTime) <= 0 || len(EstimateEndTime) <= 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "时间参数异常!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ start, err := time.Parse("2006-01-02", EstimateStartTime)
|
|
|
+ endtime, err := time.Parse("2006-01-02", EstimateEndTime)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "时间参数异常!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var_ := Function.Order{
|
|
|
+ T_pid: c.User_r.T_pid,
|
|
|
+ T_orderid: T_orderid,
|
|
|
+ WaybillNo: WaybillNo,
|
|
|
+ ShippingUnit: ShippingUnit,
|
|
|
+ T_sn: T_sn,
|
|
|
+ T_receiving: T_receiving,
|
|
|
+ EstimateStartTime: start,
|
|
|
+ EstimateEndTime: endtime,
|
|
|
+ T_text: T_text,
|
|
|
+ T_State: 1,
|
|
|
+ PeerList: PeerList,
|
|
|
+ DeviceType: DeviceType,
|
|
|
+ IsExpatriate: IsExpatriate,
|
|
|
+ Phone: Phone,
|
|
|
+ ChildPid: ChildPid,
|
|
|
+ }
|
|
|
+ id, err := Function.Add_Order(var_)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if var_.IsExpatriate == 2 {
|
|
|
+ if len(var_.Phone) < 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "电话号码不能为空!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ s, _ := beego.AppConfig.String("orderUrl")
|
|
|
+ addr := s + url.QueryEscape(lib.AesEncryptCBC(var_.T_orderid, lib.AesKey))
|
|
|
+ log.Println(addr)
|
|
|
+ sprintf := fmt.Sprintf("【冷链订单配送】您的订单正在配送中点击下方链接查看%v", addr)
|
|
|
+ err = lib.SendModel(Phone, sprintf)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "发送短信失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var_.ExpatriateReceiving = T_receiving
|
|
|
+ }
|
|
|
+ NatsServer.AddUserLogs(Account.User_r.T_uuid, "订单系统", "添加", var_)
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
|
|
|
+ c.ServeJSON()
|
|
|
+}
|
|
|
+func (c *OrderController) Order_Get() {
|
|
|
+
|
|
|
+ id, _ := c.GetInt("T_id")
|
|
|
+ r := Function.Read_Order_ById(id)
|
|
|
+ // 记录不存在
|
|
|
+ if r.Id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if c.User_r.T_pid != r.T_pid {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 205, Msg: "没有权限!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Function.OrderToOrderR(r)}
|
|
|
+ c.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+func (c *OrderController) Order_Edit() {
|
|
|
+ id, _ := c.GetInt("T_id")
|
|
|
+ r := Function.Read_Order_ById(id)
|
|
|
+
|
|
|
+ if r.Id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id !"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if c.User_r.T_pid != r.T_pid {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 205, Msg: "没有权限!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ WaybillNo := c.GetString("WaybillNo")
|
|
|
+ T_sn := c.GetString("T_sn")
|
|
|
+ T_receiving := c.GetString("T_receiving")
|
|
|
+ ShippingUnit := c.GetString("ShippingUnit")
|
|
|
+ EstimateStartTime := c.GetString("EstimateStartTime")
|
|
|
+ EstimateEndTime := c.GetString("EstimateEndTime")
|
|
|
+ T_text := c.GetString("T_text")
|
|
|
+ PeerList := c.GetString("PeerList")
|
|
|
+ DeviceType := c.GetString("DeviceType")
|
|
|
+ IsExpatriate, _ := c.GetInt("IsExpatriate")
|
|
|
+ Phone := c.GetString("Phone")
|
|
|
+ ChildPid := c.GetString("ChildPid")
|
|
|
+ T_State, _ := c.GetInt("T_State")
|
|
|
+ if len(EstimateStartTime) <= 0 || len(EstimateEndTime) <= 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "时间参数异常!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ start, err := time.Parse("2006-01-02", EstimateStartTime)
|
|
|
+ endtime, err := time.Parse("2006-01-02", EstimateEndTime)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "时间参数异常!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(WaybillNo) > 0 {
|
|
|
+ r.WaybillNo = WaybillNo
|
|
|
+ }
|
|
|
+ if len(T_sn) > 0 {
|
|
|
+ r.T_sn = T_sn
|
|
|
+ }
|
|
|
+ if len(T_receiving) > 0 {
|
|
|
+ r.T_receiving = T_receiving
|
|
|
+ }
|
|
|
+ if len(T_text) > 0 {
|
|
|
+ r.T_text = T_text
|
|
|
+ }
|
|
|
+ if len(ShippingUnit) > 0 {
|
|
|
+ r.ShippingUnit = ShippingUnit
|
|
|
+ }
|
|
|
+ if len(EstimateStartTime) > 0 {
|
|
|
+ r.EstimateStartTime = start
|
|
|
+ }
|
|
|
+ if len(EstimateEndTime) > 0 {
|
|
|
+ r.EstimateEndTime = endtime
|
|
|
+ }
|
|
|
+ if len(PeerList) > 0 {
|
|
|
+ r.PeerList = PeerList
|
|
|
+ }
|
|
|
+ if len(DeviceType) > 0 {
|
|
|
+ r.DeviceType = DeviceType
|
|
|
+ }
|
|
|
+ if IsExpatriate != r.IsExpatriate {
|
|
|
+ r.IsExpatriate = IsExpatriate
|
|
|
+ }
|
|
|
+ if len(Phone) > 0 {
|
|
|
+ r.Phone = Phone
|
|
|
+ }
|
|
|
+ if len(ChildPid) > 0 {
|
|
|
+ r.ChildPid = ChildPid
|
|
|
+ }
|
|
|
+ if T_State != 0 {
|
|
|
+ r.T_State = T_State
|
|
|
+ }
|
|
|
+ is := Function.Update_Order(r, "waybill_no", "t_sn", "t_receiving", "shipping_unit", "estimate_start_time", "estimate_end_time", "peer_list", "device_type", "is_expatriate", "phone", "child_pid", "t__state", "t_text")
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ NatsServer.AddUserLogs(Account.User_r.T_uuid, "订单系统", "修改", r)
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+func (c *OrderController) GetDeviceData() {
|
|
|
+ var err error
|
|
|
+ Id, _ := c.GetInt("T_id")
|
|
|
+ if Id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Order_r := Function.Read_Order_ById(Id)
|
|
|
+ if Order_r.Id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "Id Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, err = NatsServer.ReadDeviceByT_sn(Order_r.T_sn)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sn Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ DeviceSensor_r := NatsServer.ReadDeviceSensorALLByT_sn(Order_r.T_sn)
|
|
|
+ if len(DeviceSensor_r) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: Order_r.T_sn + "设备没有数据!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var DeviceSensor_data []Device.DeviceData_R
|
|
|
+ if Order_r.T_start_Ut.IsZero() {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: Order_r.T_sn + "未开启配送"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if Order_r.T_end_Ut.IsZero() {
|
|
|
+ Order_r.T_end_Ut = time.Now()
|
|
|
+ }
|
|
|
+ DeviceSensor_data, _ = NatsServer.ReadDeviceDataListBy_T_snid(Order_r.T_sn+","+strconv.Itoa(DeviceSensor_r[0].T_id), Order_r.T_start_Ut.Format("2006-01-02 15:04:05"), Order_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: Order_r.T_sn + "设备没有数据!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lastValidTsite := ""
|
|
|
+ for i, sensor := range DeviceSensor_data {
|
|
|
+ if len(sensor.T_site) <= 0 || sensor.T_site == "0,0" {
|
|
|
+ DeviceSensor_data[i].T_site = lastValidTsite
|
|
|
+ } else {
|
|
|
+ lastValidTsite = sensor.T_site
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "成功", Data: DeviceSensor_data}
|
|
|
+ c.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+func (c *OrderController) Order_Del() {
|
|
|
+
|
|
|
+ Id, _ := c.GetInt("T_id")
|
|
|
+ r := Function.Read_Order_ById(Id)
|
|
|
+
|
|
|
+ if r.Id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if c.User_r.T_pid != r.T_pid {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if is := Function.Delete_Order(r); !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ NatsServer.AddUserLogs(Account.User_r.T_uuid, "订单系统", "删除", r)
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// Order_PDF 列表 - 接口
|
|
|
+func (c *OrderController) Order_PDF() {
|
|
|
+ var err error
|
|
|
+ Id, _ := c.GetInt("T_id")
|
|
|
+ if Id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Order_r := Function.Read_Order_ById(Id)
|
|
|
+ if Order_r.Id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "Id Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Device_r, err := NatsServer.ReadDeviceByT_sn(Order_r.T_sn)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sn Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ DeviceSensor_r := NatsServer.ReadDeviceSensorALLByT_sn(Order_r.T_sn)
|
|
|
+ if len(DeviceSensor_r) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: Order_r.T_sn + "设备没有数据!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var DeviceSensor_data []Device.DeviceData_R
|
|
|
+ DeviceSensor_data, _ = NatsServer.ReadDeviceDataListBy_T_snid(Order_r.T_sn+","+strconv.Itoa(DeviceSensor_r[0].T_id), Order_r.T_start_Ut.Format("2006-01-02 15:04:05"), Order_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: Order_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 = pdf.AddTTFFont("simsun", "static/fonts/三极行楷简体-粗.ttf")
|
|
|
+ if err != nil {
|
|
|
+ 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: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ pdf.SetGrayFill(0.5)
|
|
|
+
|
|
|
+ pdf.SetMargins(0, 20, 0, 20)
|
|
|
+ pdf.AddPage()
|
|
|
+
|
|
|
+ company, _ := NatsServer.Read_Company_ById(c.T_pid)
|
|
|
+ log.Println(c.T_pid, c.User_r.T_pid)
|
|
|
+ textw, _ := pdf.MeasureTextWidth(company.T_name + "-货单详情")
|
|
|
+ pdf.SetX((595 / 2) - (textw / 2))
|
|
|
+ pdf.SetY(40)
|
|
|
+ pdf.Text(company.T_name + "-货单详情")
|
|
|
+
|
|
|
+ // 线
|
|
|
+ pdf.SetLineWidth(2)
|
|
|
+ pdf.SetLineType("dashed")
|
|
|
+ pdf.Line(10, 60, 585, 60)
|
|
|
+
|
|
|
+ err = pdf.AddTTFFont("wts", "static/fonts/MiSans-Medium.ttf")
|
|
|
+ if err != nil {
|
|
|
+ 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: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ // -------------
|
|
|
+ x := 22.0
|
|
|
+ w1 := 80.0
|
|
|
+ w2 := 195.0
|
|
|
+
|
|
|
+ lib.RectFillColor(pdf, "订单号:", 12, x, 80, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, Order_r.T_orderid, 12, x, 80, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ lib.RectFillColor(pdf, "运单号:", 12, x, 80, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, Order_r.T_outorderid, 12, x, 80, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ // -------------
|
|
|
+ x = 22.0
|
|
|
+ w1 = 80.0
|
|
|
+ w2 = 195.0
|
|
|
+
|
|
|
+ lib.RectFillColor(pdf, "设备名称:", 12, x, 100, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, Device_r.T_devName, 12, x, 100, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ lib.RectFillColor(pdf, "设备编号:", 12, x, 100, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, Device_r.T_sn, 12, x, 100, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ // -------------
|
|
|
+ x = 22.0
|
|
|
+ w1 = 80.0
|
|
|
+ w2 = 240.0
|
|
|
+ T_time := fmt.Sprintf("%s", Order_r.T_start_Ut.Format("2006-01-02 15:04:05")+" - "+Order_r.T_end_Ut.Format("2006-01-02 15:04:05"))
|
|
|
+ lib.RectFillColor(pdf, "送货时间:", 12, x, 120, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_time, 12, x, 120, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ T_time = fmt.Sprintf("%s", Order_r.CreateTime.Format("2006-01-02 15:04:05"))
|
|
|
+ lib.RectFillColor(pdf, "订单时间:", 12, x, 120, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_time, 12, x, 120, 150, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+
|
|
|
+ // -------------
|
|
|
+ x = 22.0
|
|
|
+ w1 = 80.0
|
|
|
+ w2 = 195.0*2 + 80
|
|
|
+ ShippingUnit := fmt.Sprintf("%s", Order_r.ShippingUnit)
|
|
|
+ lib.RectFillColor(pdf, "发货单位:", 12, x, 140, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, ShippingUnit, 12, x, 140, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ x = 22.0
|
|
|
+ T_text := fmt.Sprintf("%s", Order_r.T_receiving)
|
|
|
+ lib.RectFillColor(pdf, "收货单位:", 12, x, 160, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_text, 12, x, 160, 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 = 180
|
|
|
+ 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
|
|
|
+ var height int
|
|
|
+ getString := c.GetString("images")
|
|
|
+ split := strings.Split(getString, ",")
|
|
|
+ if len(split) >= 2 {
|
|
|
+ imageBytes, err := base64.StdEncoding.DecodeString(split[1])
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "无效的图像数据"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ decode, _, err := image.Decode(bytes.NewReader(imageBytes))
|
|
|
+ // 获取图片的高度
|
|
|
+ bounds := decode.Bounds()
|
|
|
+ height = bounds.Dy()
|
|
|
+ if height >= 500 {
|
|
|
+ height = 500
|
|
|
+ }
|
|
|
+
|
|
|
+ with := bounds.Dx()
|
|
|
+ log.Println("图片宽高", with, height)
|
|
|
+ y = 220
|
|
|
+ imgH, err := gopdf.ImageHolderByBytes(imageBytes)
|
|
|
+ err = pdf.ImageByHolder(imgH, 10, y, &gopdf.Rect{W: 575, H: float64(height)})
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "添加图片失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: "无效的图像数据"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // -----------
|
|
|
+ textw, _ = pdf.MeasureTextWidth("历史数据")
|
|
|
+ pdf.SetX(20)
|
|
|
+ pdf.SetY(float64(230 + height))
|
|
|
+ pdf.Text("历史数据:")
|
|
|
+
|
|
|
+ // 数据展示--------------------------------
|
|
|
+ //var y float64 = 220
|
|
|
+ y = float64(240 + height)
|
|
|
+ x = 22.0
|
|
|
+ w1 = 94.0
|
|
|
+ w2 = 43.0
|
|
|
+
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ // 数据展示--------------------------------
|
|
|
+
|
|
|
+ y = float64(260 + height)
|
|
|
+
|
|
|
+ err = pdf.SetFont("wts", "", 8)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ nln := 0
|
|
|
+ x = 22.0
|
|
|
+ for n := 0; len(DeviceSensor_data) > n; n++ {
|
|
|
+ var textH float64 = 25 // if text height is 25px.
|
|
|
+ pdf.SetNewY(y, textH)
|
|
|
+ y = pdf.GetY()
|
|
|
+
|
|
|
+ nln++
|
|
|
+ if nln > 4 {
|
|
|
+ nln = 1
|
|
|
+ x = 22.0
|
|
|
+ y += 18
|
|
|
+ }
|
|
|
+
|
|
|
+ if y >= 794 {
|
|
|
+ err = pdf.SetFont("wts", "", 10)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pdf.AddPage()
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ x = 22.0
|
|
|
+ y = 20
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ lib.RectFillColor(pdf, "记录时间", 10, x, y, w1, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 10, x, y, w2, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+ x = 22.0
|
|
|
+ y += 20
|
|
|
+
|
|
|
+ }
|
|
|
+ err = pdf.SetFont("wts", "", 8)
|
|
|
+
|
|
|
+ // ------------------
|
|
|
+ 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)
|
|
|
+ x += w1
|
|
|
+ lib.RectFillColor(pdf, T_t, 10, x, y, w2, 18, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w2
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ err = pdf.SetFont("wts", "", 10)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //----------------
|
|
|
+ timeStr := "ofile/" + time.Now().Format("20060102150405") + ".pdf"
|
|
|
+
|
|
|
+ err = pdf.WritePdf(timeStr)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 207, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传 OSS
|
|
|
+ //url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/"+timeStr, timeStr)
|
|
|
+ url, is := NatsServer.Qiniu_UploadFile(timeStr, timeStr)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //删除目录
|
|
|
+ err = os.Remove(timeStr)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+
|
|
|
+}
|