Browse Source

ADD:更新校准证书与布局编号关联

zoie 8 months ago
parent
commit
c98f092b75

+ 24 - 0
Nats/Nats.go

@@ -5,6 +5,7 @@ import (
 	"ColdVerify_server/conf"
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
+	"ColdVerify_server/models/Account"
 	"ColdVerify_server/models/Device"
 	"ColdVerify_server/models/System"
 	"ColdVerify_server/models/Task"
@@ -191,4 +192,27 @@ func NatsInit() {
 
 	})
 
+	_, _ = lib.Nats.QueueSubscribe("ColdVerify_Server_Read_User", "Read_User", func(m *nats.Msg) {
+		logs.Println("ColdVerify_Server_Read_User message: %+v\n", string(m.Data))
+
+		var t_R lib.JSONS
+		err, user := Account.Read_User_ByT_uuid(string(m.Data))
+		if err != nil {
+			logs.Error("Mats", lib.FuncName())
+			t_R.Code = 202
+			t_R.Msg = "查询失败"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+
+		t_R.Code = 200
+		t_R.Msg = "ok"
+		t_R.Data = user
+
+		b, _ := msgpack.Marshal(&t_R)
+		_ = lib.Nats.Publish(m.Reply, b)
+
+	})
+
 }

+ 16 - 2
controllers/Certificate.go

@@ -162,7 +162,7 @@ func (c *CertificateController) Edit() {
 		c.ServeJSON()
 		return
 	}
-
+	old_T_layout_no := r.T_layout_no
 	T_layout_no := c.GetString("T_layout_no")
 
 	if _, is = Certificate.Read_Certificate(T_layout_no); is && r.T_layout_no != T_layout_no {
@@ -173,10 +173,24 @@ func (c *CertificateController) Edit() {
 	r.T_layout_no = T_layout_no
 	is = Certificate.Update_Certificate(r, "T_layout_no")
 	if !is {
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
 		c.ServeJSON()
 		return
 	}
+	pdfList, _ := Certificate.Read_CertificatePdf_List(old_T_layout_no, 0, 9999)
+	for _, pdf := range pdfList {
+		// 修改pdf
+		var_ := Certificate.CertificatePdf{
+			Id:          pdf.Id,
+			T_layout_no: T_layout_no,
+		}
+		if !Certificate.Update_CertificatePdf(var_, "T_layout_no") {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
+			c.ServeJSON()
+			return
+		}
+	}
+
 	System.Add_UserLogs_T(user_r.T_uuid, "校准证书管理", "编辑", r)
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
 	c.ServeJSON()

+ 6 - 6
controllers/DeviceClass.go

@@ -197,12 +197,12 @@ func (c *DeviceClassController) Del() {
 // 列表 -
 func (c *DeviceClassController) List_List() {
 	// 验证登录 User_is, User_r
-	_, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
-	if !User_is {
-		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
-		c.ServeJSON()
-		return
-	}
+	//_, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
+	//if !User_is {
+	//	c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
+	//	c.ServeJSON()
+	//	return
+	//}
 
 	var r_jsons lib.R_JSONS
 	page, _ := c.GetInt("page")

+ 14 - 4
controllers/TaskData.go

@@ -631,12 +631,22 @@ func (c *TaskDataController) Export_Data_PDF() {
 		c.ServeJSON()
 		return
 	}
+	dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", 0, 9999)
+	// 查询设备列表
+	// 保存布局编号和校准证书对应关系
+	var deviceCertificateMap = make(map[string]string) // t_id, T_Certificate_sn
+	for _, v := range dcList {
+		deviceCertificateMap[v.T_id] = v.T_Certificate_sn
+	}
 
 	T_sn_list := strings.Split(T_sn_str, ",")
 	DeviceSensor_data_list := []Task.TaskData_{}
 	for _, v := range T_sn_list {
 		DeviceSensor_data, _ := Task.Read_TaskData_ById_List(Task_r.T_task_id, v, -1, Time_start, Time_end, 1, 9999)
 		DeviceSensor_data_list = append(DeviceSensor_data_list, DeviceSensor_data...)
+		for i := 0; i < len(DeviceSensor_data_list); i++ {
+			DeviceSensor_data_list[i].T_Certificate_sn = deviceCertificateMap[DeviceSensor_data_list[i].T_id]
+		}
 	}
 
 	//------
@@ -701,10 +711,10 @@ func (c *TaskDataController) Export_Data_PDF() {
 		t_ = "所有数据"
 	}
 	//fmt.Sprintf(" %.1f ", v.T_t)
-	lib.RectFillColor(pdf, "提数据时间段["+t_+"]", 14, 22, 80, 550, 40, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	lib.RectFillColor(pdf, "提数据时间段["+t_+"]", 14, 22, 80, 550, 40, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 
-	lib.RectFillColor(pdf, "编号", 12, 22, 120, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-	lib.RectFillColor(pdf, "SN", 12, 92, 120, 150, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	lib.RectFillColor(pdf, "布局编号", 12, 22, 120, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	lib.RectFillColor(pdf, "证书编号", 12, 92, 120, 150, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 	lib.RectFillColor(pdf, "温度℃", 12, 242, 120, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 	lib.RectFillColor(pdf, "湿度%", 12, 342, 120, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 
@@ -736,7 +746,7 @@ func (c *TaskDataController) Export_Data_PDF() {
 		T_time := fmt.Sprintf("%s", v.T_time)
 
 		lib.RectFillColor(pdf, v.T_id, 10, 22, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-		lib.RectFillColor(pdf, v.T_sn, 10, 92, y, 150, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		lib.RectFillColor(pdf, v.T_Certificate_sn, 10, 92, y, 150, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 		lib.RectFillColor(pdf, T_t, 10, 242, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 		lib.RectFillColor(pdf, T_rh, 10, 342, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 		lib.RectFillColor(pdf, T_time, 10, 442, y, 130, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)

+ 2 - 0
controllers/VerifyTemplate.go

@@ -525,6 +525,8 @@ func (c *VerifyTemplateController) Map_Data_Pu() {
 
 	User_r, User_is := Account.Verification_Admin(body.User_tokey, "")
 	if !User_is {
+		System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "未登录-保存", body)
+
 		c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
 		c.ServeJSON()
 		return

+ 1 - 1
models/Account/Tokey.go

@@ -30,7 +30,7 @@ func init() {
 // ---------------- Redis -------------------
 // Redis_Set(m.T_sn,m) // Redis 更新缓存
 func Redis_Tokey_Set(key string, r string) (err error) {
-	err = redisCache_Tokey.Put(key, r, 24*time.Hour)
+	err = redisCache_Tokey.Put(key, r, 24*7*time.Hour)
 	if err != nil {
 		fmt.Println("set key:", key, ",value:", r, err)
 	}

+ 5 - 1
models/Certificate/CertificatePdf.go

@@ -180,7 +180,11 @@ func Read_CertificatePdf_List(T_layout_no string, page int, page_z int) ([]Certi
 	}
 	cond := orm.NewCondition()
 	cond1 := cond.And("T_layout_no", T_layout_no).And("T_State", 1)
-	qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
+	if page_z == 9999 {
+		qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
+	} else {
+		qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
+	}
 	cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
 	// 转换
 	var CertificatePdf_r []CertificatePdf_R

+ 37 - 1
models/Device/DeviceData.go

@@ -228,11 +228,16 @@ type DeviceData_New struct {
 }
 
 func Read_DeviceSensorData_ById_List(SN string, Time_start_ string, Time_end_ string, page int, page_z int) ([]DeviceData_, int) {
+
 	o := orm.NewOrm()
 	var maps []DeviceData_
 	var maps_z []orm2.ParamsList
 	pagez := page_z
 
+	if len(SN) == 0 {
+		return maps, 0
+	}
+
 	var offset int
 	if page <= 1 {
 		offset = 0
@@ -290,8 +295,12 @@ func Read_DeviceSensorData_ById_List(SN string, Time_start_ string, Time_end_ st
 }
 
 func Read_DeviceData_By_snid(SN string, T_id int, Time_start_ string, Time_end_ string, offset, limit int) ([]DeviceData_, int) {
-	o := orm.NewOrm()
 	var maps []DeviceData_
+	o := orm.NewOrm()
+
+	if len(SN) == 0 {
+		return maps, 0
+	}
 
 	sql_time := ""
 
@@ -316,6 +325,9 @@ func Read_DeviceData_By_snid(SN string, T_id int, Time_start_ string, Time_end_
 }
 
 func Read_DeviceData_Count_By_snid(SN string, T_id int, Time_start_ string, Time_end_ string) int {
+	if len(SN) == 0 {
+		return 0
+	}
 	o := orm.NewOrm()
 	var maps_z []orm2.ParamsList
 
@@ -347,6 +359,9 @@ func Read_DeviceSensorData_List(SN string, Time_start_ string, Time_end_ string,
 	var maps []DeviceData_
 	var maps_z []orm2.ParamsList
 	pagez := page_z
+	if len(SN) == 0 {
+		return maps, 0
+	}
 
 	var offset int
 	if page <= 1 {
@@ -392,6 +407,9 @@ func Read_DeviceSensorData_List(SN string, Time_start_ string, Time_end_ string,
 }
 
 func Read_DeviceSensorData_List_z(SN string, Time_start_ string) int {
+	if len(SN) == 0 {
+		return 0
+	}
 	o := orm.NewOrm()
 	var maps_z []orm2.ParamsList
 
@@ -419,6 +437,9 @@ func Read_DeviceSensorData_List_z(SN string, Time_start_ string) int {
 func Read_DeviceSensorData_ById_New(SN string, T_id int) (DeviceData_New, bool) {
 	o := orm.NewOrm()
 	var maps DeviceData_New
+	if len(SN) == 0 {
+		return maps, false
+	}
 
 	key_data := SN + "|" + strconv.Itoa(T_id)
 	if redisCache_DeviceData.IsExist(key_data) {
@@ -482,6 +503,9 @@ func Read_DeviceData_ById_Year_List(SN string) []orm2.ParamsList {
 	o := orm.NewOrm()
 
 	var maps_z []orm2.ParamsList
+	if len(SN) == 0 {
+		return maps_z
+	}
 
 	//sql = "SELECT t_name,t_t,t_rh,t_tl,t_tu,t_rhl,t_rhu,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_"+SN+" WHERE "+sql_time+" t_id = "+ strconv.Itoa(T_id) +" ORDER BY t_time DESC "
 	sql := "SELECT DATE_FORMAT(t_time,\"%m\") AS m ,DATE_FORMAT(t_time,\"%d\") AS d FROM z_devicedata_" + SN + "  WHERE t_time > '" + strconv.Itoa(time.Now().Year()) + "-0-0 00:00:00' GROUP BY DATE_FORMAT(t_time,\"%m\");"
@@ -498,6 +522,9 @@ func Read_DeviceData_ById_Month_List(SN string) []orm2.ParamsList {
 	o := orm.NewOrm()
 
 	var maps_z []orm2.ParamsList
+	if len(SN) == 0 {
+		return maps_z
+	}
 	currentTime := time.Now() //获取当前时间,类型是Go的时间类型Time
 
 	time_x := currentTime.Format("2006-01") + "-00 00:00:00"
@@ -515,6 +542,9 @@ func Read_DeviceSensorData_ById_Day_List(SN string) []orm2.ParamsList {
 	o := orm.NewOrm()
 
 	var maps_z []orm2.ParamsList
+	if len(SN) == 0 {
+		return maps_z
+	}
 	currentTime := time.Now() //获取当前时间,类型是Go的时间类型Time
 
 	time_x := currentTime.Format("2006-01-02") + " 00:00:00"
@@ -533,6 +563,9 @@ func Read_DeviceSensorData_List_GROUP_BY_t_time(SN string, Time_start_ string, T
 	o := orm.NewOrm()
 
 	var maps_z []orm2.ParamsList
+	if len(SN) == 0 {
+		return maps_z
+	}
 
 	sql_time := ""
 	if len(Time_start_) > 1 {
@@ -547,6 +580,9 @@ func Read_DeviceSensorData_List_GROUP_BY_t_time(SN string, Time_start_ string, T
 
 func Read_DeviceData_T_Min_Max_Time_Min_Max(SN string, Time_start_ string, Time_end_ string) (minT, maxT float64, minTime, maxTime time.Time) {
 	o := orm.NewOrm()
+	if len(SN) == 0 {
+		return
+	}
 
 	sql_condition := ""
 

+ 7 - 0
models/Task/TaskData.go

@@ -3,6 +3,7 @@ package Task
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
+	"errors"
 	"fmt"
 	_ "github.com/astaxie/beego/cache/redis"
 	"github.com/beego/beego/v2/adapter/orm"
@@ -89,6 +90,9 @@ func Import_TaskData(Sn string, T_id string, T_task_id string, Time_start string
 	//if conf.Server_test {
 	//	return true
 	//}
+	if len(Sn) == 0 {
+		return false
+	}
 	o := orm.NewOrm()
 
 	// 开始插入数据
@@ -118,6 +122,9 @@ func Import_TaskData(Sn string, T_id string, T_task_id string, Time_start string
 }
 
 func Import_TaskData_Back(Sn string, T_id string, T_task_id string, Time_start string, Time_end string) error {
+	if len(Sn) == 0 {
+		return errors.New("sn不能为空")
+	}
 	o := orm.NewOrm()
 	// 开始插入数据
 	sql := "insert into z_task_data_" + T_task_id + "(t_sn,t_id,t_t,t_rh,t_time) select '" + Sn + "','" + T_id + "',t_t,t_rh,t_time from z_devicedata_" + Sn

File diff suppressed because it is too large
+ 0 - 406
nohup.out


+ 7 - 6
routers/Task.go

@@ -9,12 +9,13 @@ func init() {
 
 	beego.Router("/UpFileToken", &controllers.UpFileController{}, "*:ConfigUpFileToken") // 上传文件
 
-	beego.Router("/Task/List", &controllers.TaskController{}, "*:List")                 // 任务列表
-	beego.Router("/Task/Get", &controllers.TaskController{}, "*:Get")                   // 获取任务
-	beego.Router("/Task/Add", &controllers.TaskController{}, "*:Add")                   // 添加任务
-	beego.Router("/Task/Up", &controllers.TaskController{}, "*:Up")                     // 编辑任务
-	beego.Router("/Task/Del", &controllers.TaskController{}, "*:Del")                   // 删除任务
-	beego.Router("/Task/AddData_Tool", &controllers.TaskController{}, "*:AddData_Tool") // 1.0 添加任务数据
+	beego.Router("/Task/List", &controllers.TaskController{}, "*:List")                           // 任务列表
+	beego.Router("/Task/Get", &controllers.TaskController{}, "*:Get")                             // 获取任务
+	beego.Router("/Task/Add", &controllers.TaskController{}, "*:Add")                             // 添加任务
+	beego.Router("/Task/Up", &controllers.TaskController{}, "*:Up")                               // 编辑任务
+	beego.Router("/Task/Del", &controllers.TaskController{}, "*:Del")                             // 删除任务
+	beego.Router("/Task/UpCollectionState", &controllers.TaskController{}, "*:UpCollectionState") // 修改任务状态
+	beego.Router("/Task/AddData_Tool", &controllers.TaskController{}, "*:AddData_Tool")           // 1.0 添加任务数据
 
 	// 日志
 	beego.Router("/TaskLogs/List", &controllers.TaskController{}, "*:Logs_List")

Some files were not shown because too many files changed in this diff