zoie vor 1 Jahr
Ursprung
Commit
a99d42416a

+ 72 - 15
controllers/Data.go

@@ -756,6 +756,12 @@ func (c *DataController) Device_Sensor_Data_ChartShow_PDF() {
 	T_snid := c.GetString("T_snid")
 	Time_start := c.GetString("Time_start")
 	Time_end := c.GetString("Time_end")
+	T_forwarding_unit := c.GetString("T_forwarding_unit")
+	T_consignee_unit := c.GetString("T_consignee_unit")
+	T_remark := c.GetString("T_remark")
+	T_temp_show, _ := c.GetInt("T_temp_show")
+	T_Humidity_show, _ := c.GetInt("T_Humidity_show")
+
 	// 获取图片信息
 	//f, _, err := c.GetFile("file")
 	//if err != nil {
@@ -867,7 +873,7 @@ func (c *DataController) Device_Sensor_Data_ChartShow_PDF() {
 	pdf.SetY(y)
 	pdf.Text(title)
 
-	y += 40
+	y += 35
 	pdf.SetFont("wts", "", 18)
 	pdf.SetXY(10, y)
 	pdf.Text("记录概要信息")
@@ -885,35 +891,86 @@ func (c *DataController) Device_Sensor_Data_ChartShow_PDF() {
 	}
 	pdf.SetFont("wts", "", 10)
 	pdf.SetXY(10, y)
-	pdf.Text(fmt.Sprintf("记录开始时间: %s", s_time))
+	pdf.Text(fmt.Sprintf("记录开始时间%s", s_time))
 
 	pdf.SetXY(240, y)
-	pdf.Text(fmt.Sprintf("记录结束时间: %s", e_time))
+	pdf.Text(fmt.Sprintf("记录结束时间%s", e_time))
 
 	sTime, _ := lib.TimeStrToTime(s_time)
 	eTime, _ := lib.TimeStrToTime(e_time)
 	pdf.SetXY(470, y)
-	pdf.Text(fmt.Sprintf("记录总时间: %.2f", eTime.Sub(sTime).Minutes()))
+	pdf.Text(fmt.Sprintf("记录总时间:%.0f分钟", eTime.Sub(sTime).Minutes()))
 
-	y += 18
-	pdf.SetXY(10, y)
-	pdf.Text(fmt.Sprintf("最高温度: %.2f℃,%s", maxTemp, maxTempTime))
+	if T_temp_show == 1 {
+		y += 15
+		pdf.SetXY(10, y)
+		pdf.Text(fmt.Sprintf("最高温度:%.1f℃,%s", lib.RoundToDecimal(float64(maxTemp), 1), maxTempTime))
 
-	pdf.SetXY(240, y)
-	pdf.Text(fmt.Sprintf("最低温度: %.2f℃,%s", minTemp, minTempTime))
+		pdf.SetXY(240, y)
+		pdf.Text(fmt.Sprintf("最低温度:%.1f℃,%s", lib.RoundToDecimal(float64(minTemp), 1), minTempTime))
 
-	pdf.SetXY(470, y)
-	pdf.Text(fmt.Sprintf("平均温度: %.2f℃", avgTemp))
+		pdf.SetXY(470, y)
+		pdf.Text(fmt.Sprintf("平均温度:%.1f℃", lib.RoundToDecimal(float64(avgTemp), 1)))
+	}
 
-	y += 18
+	if T_Humidity_show == 1 {
+		y += 15
+		pdf.SetXY(10, y)
+		pdf.Text(fmt.Sprintf("最高湿度:%.1f%%RH,%s", lib.RoundToDecimal(float64(maxHumidity), 1), maxHumidityTime))
+
+		pdf.SetXY(240, y)
+		pdf.Text(fmt.Sprintf("最低湿度:%.1f%%RH,%s", lib.RoundToDecimal(float64(minHumidity), 1), minHumidityTime))
+
+		pdf.SetXY(470, y)
+		pdf.Text(fmt.Sprintf("平均湿度:%.1f%%RH", lib.RoundToDecimal(float64(avgHumidity), 1)))
+	}
+
+	y += 15
 	pdf.SetXY(10, y)
-	pdf.Text(fmt.Sprintf("最高湿度: %.2f%%RH,%s", maxHumidity, maxHumidityTime))
+	T_forwarding_unit_temp := []rune(T_forwarding_unit)
+	if len(T_forwarding_unit_temp) > 34 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "发货单位长度超过限制(34个字符)"}
+		c.ServeJSON()
+		return
+	}
+	if len(T_forwarding_unit_temp) > 17 {
+		pdf.Text(fmt.Sprintf("发货单位:%s", string(T_forwarding_unit_temp[0:17])))
+		pdf.SetXY(60, y+15)
+		pdf.Text(fmt.Sprintf("%s", string(T_forwarding_unit_temp[17:])))
+	} else {
+		pdf.Text(fmt.Sprintf("发货单位:%s", string(T_forwarding_unit_temp)))
+	}
 
 	pdf.SetXY(240, y)
-	pdf.Text(fmt.Sprintf("最低湿度: %.2f%%RH,%s", minHumidity, minHumidityTime))
+	T_consignee_unit_temp := []rune(T_consignee_unit)
+	if len(T_consignee_unit_temp) > 34 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "收货单位长度超过限制(34个字符)"}
+		c.ServeJSON()
+		return
+	}
+	if len(T_consignee_unit_temp) > 17 {
+		pdf.Text(fmt.Sprintf("收货单位:%s", string(T_consignee_unit_temp[0:17])))
+		pdf.SetXY(290, y+15)
+		pdf.Text(fmt.Sprintf("%s", string(T_consignee_unit_temp[17:])))
+	} else {
+		pdf.Text(fmt.Sprintf("收货单位:%s", string(T_consignee_unit_temp)))
+
+	}
 
 	pdf.SetXY(470, y)
-	pdf.Text(fmt.Sprintf("平均湿度: %.2f%%RH", avgHumidity))
+	T_remark_temp := []rune(T_remark)
+	if len(T_remark_temp) > 34 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "备注长度超过限制(16个字符)"}
+		c.ServeJSON()
+		return
+	}
+	if len(T_remark) > 8 {
+		pdf.Text(fmt.Sprintf("备注:%s", string(T_remark_temp[0:8])))
+		pdf.SetXY(500, y+15)
+		pdf.Text(fmt.Sprintf("%s", string(T_remark_temp[8:])))
+	} else {
+		pdf.Text(fmt.Sprintf("备注: %s", string(T_remark_temp)))
+	}
 
 	y += 40
 	pdf.SetFont("wts", "", 18)

+ 7 - 5
controllers/Device.go

@@ -557,8 +557,8 @@ func (c *DeviceController) Device_Parameter_Pu() {
 	if v, err := c.GetInt("T_warnD"); err == nil {
 		DeviceParameter.T_warnD = v
 	}
-	if v, err := c.GetInt("T_speed"); err == nil {
-		DeviceParameter.T_speed = v
+	if v, err := c.GetInt("T_scan"); err == nil {
+		DeviceParameter.T_scan = v
 	}
 	if v, err := c.GetInt("T_dormancy"); err == nil {
 		DeviceParameter.T_dormancy = v
@@ -620,8 +620,11 @@ func (c *DeviceController) Device_Parameter_Sync() {
 		c.ServeJSON()
 		return
 	}
-	NatsServer.Read_DeviceParameter(T_SN, Device_r.T_mqttid)
-	NatsServer.Read_DeviceSensorParameter(T_SN, Device_r.T_mqttid)
+	go func() {
+		NatsServer.Read_DeviceParameter(T_SN, Device_r.T_mqttid)
+		time.Sleep(5 * time.Second)
+		NatsServer.Read_DeviceSensorParameter(T_SN, Device_r.T_mqttid)
+	}()
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
 	c.ServeJSON()
@@ -1065,7 +1068,6 @@ func (c *DeviceController) DeviceSensor_Manage_List() {
 		c.ServeJSON()
 		return
 	}
-
 	r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensorManageList(c.Admin_r, bindSN, c.T_pid, T_name, T_calss_id, T_en, T_free, T_datashow, T_sort, page, page_z)
 	r_jsons.Page = page
 	r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))

+ 7 - 0
controllers/lib/libString.go

@@ -4,6 +4,7 @@ import (
 	"crypto/md5"
 	"encoding/hex"
 	"fmt"
+	"math"
 	"math/rand"
 	"strconv"
 	"strings"
@@ -128,3 +129,9 @@ func StringListToQuotesDotStr(str []string) (r string) {
 	r = strings.TrimRight(r, ",")
 	return r
 }
+
+// 四舍五入保留小数点后几位
+func RoundToDecimal(num float64, decimalPlaces int) float64 {
+	shift := math.Pow(10, float64(decimalPlaces))
+	return math.Round(num*shift) / shift
+}

+ 4 - 4
models/Account/Admin.go

@@ -26,10 +26,10 @@ type Admin struct {
 	T_user  string `orm:"size(256);null"`      // 用户名 (唯一)
 	T_pass  string `orm:"size(256);null"`      // MD5
 
-	T_name  string `orm:"size(256);null"` // 姓名
-	T_phone string `orm:"size(256);null"` // 电话
-	T_mail  string `orm:"size(200);null"` // 邮箱
-	T_wx    string `orm:"size(256);null"` // 微信
+	T_name  string `orm:"size(256);null"`  // 姓名
+	T_phone string `orm:"size(256);null"`  // 电话
+	T_mail  string `orm:"size(200);null"`  // 邮箱
+	T_wx    string `orm:"type(text);null"` // 微信
 
 	T_State    int       `orm:"size(2);default(1)"`                                    //  0删除  1 正常
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新

+ 9 - 0
models/Account/Company.go

@@ -283,6 +283,7 @@ func Read_Company_Tree(admin_r Admin, T_name string) (CompanyList []Company_R) {
 				T_money:    maps[i].T_money,
 				T_warning:  maps[i].T_warning,
 				T_Charging: maps[i].T_Charging,
+				T_key:      maps[i].T_key,
 				Children:   nil,
 			}
 			info := CompanyCall(maps, r)
@@ -300,6 +301,7 @@ func Read_Company_Tree(admin_r Admin, T_name string) (CompanyList []Company_R) {
 				T_money:    maps[i].T_money,
 				T_warning:  maps[i].T_warning,
 				T_Charging: maps[i].T_Charging,
+				T_key:      maps[i].T_key,
 				Children:   nil,
 			}
 			info := CompanyCall(maps, r)
@@ -464,6 +466,13 @@ func CompanyCall(CompanyList []Company, company Company_R) Company_R {
 		mi.Id = list[j].Id
 		mi.T_mid = list[j].T_mid
 		mi.T_name = list[j].T_name
+		mi.T_plan = list[j].T_plan
+		mi.T_data = list[j].T_data
+		mi.T_v3d = list[j].T_v3d
+		mi.T_money = list[j].T_money
+		mi.T_warning = list[j].T_warning
+		mi.T_Charging = list[j].T_Charging
+		mi.T_key = list[j].T_key
 		mi.Children = []Company_R{}
 		ms := CompanyCall(CompanyList, mi)
 		min = append(min, ms)

+ 1 - 1
models/DataSource/DataSource.go

@@ -13,7 +13,7 @@ type DataSource struct {
 	Id         int       `orm:"column(ID);size(11);auto;pk"`
 	T_id       string    `orm:"size(256);null"`                                        // 数据源id
 	T_name     string    `orm:"size(256);null"`                                        // 数据源名称
-	T_sql      string    `orm:"text;null"`                                             // sql语句
+	T_sql      string    `orm:"type(text);null"`                                       // sql语句
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
 	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
 }

+ 2 - 2
models/Device/DeviceParameter.go

@@ -25,7 +25,7 @@ type DeviceParameter struct {
 
 	T_warn     int `orm:"size(5);null"`       // 超限预警触发间隔 s(0,60~600)为0时只触发一次 默认:60  *
 	T_warnD    int `orm:"size(5);null"`       // 超限预警延时   s(0~600) 默认:0 *
-	T_speed    int `orm:"size(5);null"`       // 传感器采样率   s(1~240) 默认:15 *
+	T_scan     int `orm:"size(5);null"`       // 传感器采样率   s(1~240) 默认:15 *
 	T_dormancy int `orm:"size(5);null"`       // 是否进入休眠  0:关闭 1:开启    默认:0
 	T_snum     int `orm:"size(5);default(0)"` // 【管理主机】 - 传感器数量  (范围0~255)
 
@@ -98,7 +98,7 @@ func DeviceParameter_T_text(r DeviceParameter) string {
 	s += " 电池电量下限:" + strconv.Itoa(r.T_bat)
 	s += " 超限预警触发间隔:" + strconv.Itoa(r.T_warn)
 	s += " 超限预警延时:" + strconv.Itoa(r.T_warnD)
-	s += " 传感器采样率:" + strconv.Itoa(r.T_speed)
+	s += " 轮播间隔:" + strconv.Itoa(r.T_scan)
 	s += " 是否进入休眠:" + strconv.Itoa(r.T_dormancy)
 	s += " 传感器数量:" + strconv.Itoa(r.T_snum)
 	s += " 蓝牙打印机名称:" + r.T_btname

+ 23 - 4
models/Device/DeviceSensor.go

@@ -129,9 +129,11 @@ type DeviceSensor_Company struct {
 
 // 传感器管理
 type DeviceSensor_P struct {
-	T_sn   string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
-	T_id   int    // 传感器编号
-	T_name string // 标题
+	T_sn        string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
+	T_id        int    // 传感器编号
+	T_name      string // 标题
+	T_type      int    // 类型
+	T_type_name string // 类型
 
 	T_sort     int // 排序
 	T_datashow int // 0 屏蔽数据展示  1 正常数据展示
@@ -362,6 +364,19 @@ func DeviceSensorToDeviceSensor_(r DeviceSensor) (t DeviceSensor_) {
 	return
 }
 
+func DeviceSensorToDeviceSensor_P(r DeviceSensor_P) (t DeviceSensor_P) {
+
+	t = r
+	if r.T_type == 0 {
+		t.T_type_name = "默认"
+	}
+	if r.T_type > 0 {
+		deviceSensorType := Read_DeviceSensorType_Get(r.T_type)
+		t.T_type_name = deviceSensorType.T_name
+	}
+	return t
+}
+
 // ---------------- 特殊方法 -------------------
 
 // 获取列表 - 总数
@@ -928,7 +943,11 @@ func Read_DeviceSensorManageList(admin_r *Account.Admin, bindSN []string, T_pid
 
 	key, _ := strconv.ParseInt(maps_z[0][0].(string), 10, 64)
 
-	return maps, key
+	for _, v := range maps {
+		DeviceSensor_p = append(DeviceSensor_p, DeviceSensorToDeviceSensor_P(v))
+	}
+
+	return DeviceSensor_p, key
 }
 
 // 数据展示菜单下 传感器参数列表