|
@@ -9,6 +9,7 @@ import (
|
|
|
"ColdVerify_server/models/Device"
|
|
|
"ColdVerify_server/models/System"
|
|
|
"ColdVerify_server/models/Task"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
"github.com/signintech/gopdf"
|
|
@@ -16,6 +17,7 @@ import (
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
"math"
|
|
|
"os"
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -157,11 +159,7 @@ func (c *TaskDataController) TaskData_List() {
|
|
|
Time_start := c.GetString("Time_start")
|
|
|
Time_end := c.GetString("Time_end")
|
|
|
T_sn := c.GetString("T_sn")
|
|
|
- T_id, err := c.GetInt("T_id")
|
|
|
- if err != nil {
|
|
|
- T_id = -1
|
|
|
-
|
|
|
- }
|
|
|
+ T_id := c.GetString("T_id")
|
|
|
|
|
|
T_task_id := c.GetString("T_task_id")
|
|
|
Task_r, is := Task.Read_Task(T_task_id)
|
|
@@ -176,7 +174,7 @@ func (c *TaskDataController) TaskData_List() {
|
|
|
return
|
|
|
}
|
|
|
// 查询设备列表
|
|
|
- dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, T_sn, "", page, 9999)
|
|
|
+ dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, T_sn, "", "", page, 9999)
|
|
|
// 保存布局编号和校准证书对应关系
|
|
|
var deviceCertificateMap = make(map[string]string) // t_id, T_Certificate_sn
|
|
|
for _, v := range dcList {
|
|
@@ -223,11 +221,7 @@ func (c *TaskDataController) UserTaskData_List() {
|
|
|
Time_start := c.GetString("Time_start")
|
|
|
Time_end := c.GetString("Time_end")
|
|
|
T_sn := c.GetString("T_sn")
|
|
|
- T_id, err := c.GetInt("T_id")
|
|
|
- if err != nil {
|
|
|
- T_id = -1
|
|
|
-
|
|
|
- }
|
|
|
+ T_id := c.GetString("T_id")
|
|
|
|
|
|
T_task_id := c.GetString("T_task_id")
|
|
|
Task_r, is := Task.Read_Task(T_task_id)
|
|
@@ -248,9 +242,15 @@ func (c *TaskDataController) UserTaskData_List() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
+ if len(Time_start) == 0 {
|
|
|
+ Time_start = Task_r.T_VerifyDeviceDataStartTime
|
|
|
+ }
|
|
|
+ if len(Time_end) == 0 {
|
|
|
+ Time_end = Task_r.T_VerifyDeviceDataEndTime
|
|
|
+ }
|
|
|
|
|
|
// 查询设备列表
|
|
|
- dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, T_sn, "", page, 9999)
|
|
|
+ dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, T_sn, "", "", page, 9999)
|
|
|
// 保存布局编号和校准证书对应关系
|
|
|
var deviceCertificateMap = make(map[string]string) // t_id, T_Certificate_sn
|
|
|
for _, v := range dcList {
|
|
@@ -549,7 +549,7 @@ func (c *TaskDataController) Export_Data_Excel() {
|
|
|
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, _ := Task.Read_TaskData_ById_List(Task_r.T_task_id, v, "", Time_start, Time_end, 1, 9999)
|
|
|
DeviceSensor_data_list = append(DeviceSensor_data_list, DeviceSensor_data...)
|
|
|
}
|
|
|
|
|
@@ -631,7 +631,7 @@ func (c *TaskDataController) Export_Data_PDF() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", 0, 9999)
|
|
|
+ dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, "", "", "", 0, 9999)
|
|
|
// 查询设备列表
|
|
|
// 保存布局编号和校准证书对应关系
|
|
|
var deviceCertificateMap = make(map[string]string) // t_id, T_Certificate_sn
|
|
@@ -642,7 +642,7 @@ func (c *TaskDataController) Export_Data_PDF() {
|
|
|
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, _ := Task.Read_TaskData_ById_List(Task_r.T_task_id, v, "", 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]
|
|
@@ -873,3 +873,428 @@ func (c *TaskDataController) Check() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func (c *TaskDataController) TaskData_Temperature_Pdf() {
|
|
|
+ // 验证登录管理员 User_is, User_r
|
|
|
+ _, User_Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+
|
|
|
+ // 验证登录用户 User_is, User_r
|
|
|
+ _, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+
|
|
|
+ if !User_Admin_is && !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Time_start := c.GetString("Time_start")
|
|
|
+ Time_end := c.GetString("Time_end")
|
|
|
+ T_sn := c.GetString("T_sn")
|
|
|
+ T_id := c.GetString("T_id")
|
|
|
+
|
|
|
+ T_task_id := c.GetString("T_task_id")
|
|
|
+
|
|
|
+ err := c.TaskData_Pdf(Time_start, Time_end, T_task_id, T_sn, T_id, Task.Temperature)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+func (c *TaskDataController) TaskData_Humidity_Pdf() {
|
|
|
+ // 验证登录管理员 User_is, User_r
|
|
|
+ _, User_Admin_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+
|
|
|
+ // 验证登录用户 User_is, User_r
|
|
|
+ _, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
|
|
|
+
|
|
|
+ if !User_Admin_is && !User_is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ Time_start := c.GetString("Time_start")
|
|
|
+ Time_end := c.GetString("Time_end")
|
|
|
+ T_sn := c.GetString("T_sn")
|
|
|
+ T_id := c.GetString("T_id")
|
|
|
+
|
|
|
+ T_task_id := c.GetString("T_task_id")
|
|
|
+
|
|
|
+ err := c.TaskData_Pdf(Time_start, Time_end, T_task_id, T_sn, T_id, Task.Humidity)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+func (c *TaskDataController) TaskData_Pdf(Time_start, Time_end, T_task_id, T_sn, T_id, T_type string) (err error) {
|
|
|
+
|
|
|
+ Task_r, is := Task.Read_Task(T_task_id)
|
|
|
+ if !is {
|
|
|
+ return errors.New("T_task_id 错误!")
|
|
|
+ }
|
|
|
+ user, is := Account.Read_User(Task_r.T_uuid)
|
|
|
+ if !is {
|
|
|
+ return errors.New("Task uuid 错误!")
|
|
|
+ }
|
|
|
+
|
|
|
+ if Task_r.T_delivery_state == 2 {
|
|
|
+ return errors.New("数据采集中,请稍后!")
|
|
|
+ }
|
|
|
+
|
|
|
+ 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("./static/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
|
|
|
+ T_type_name := ""
|
|
|
+ if T_type == Task.Temperature {
|
|
|
+ T_type_name = "温度"
|
|
|
+ }
|
|
|
+ if T_type == Task.Humidity {
|
|
|
+ T_type_name = "湿度"
|
|
|
+ }
|
|
|
+ title := Task_r.T_name + T_type_name + "验证数据"
|
|
|
+ textw, _ = pdf.MeasureTextWidth(title)
|
|
|
+ pdf.SetX((595 / 2) - (textw / 2))
|
|
|
+ pdf.SetY(y)
|
|
|
+ pdf.Text(title)
|
|
|
+
|
|
|
+ // 查询设备列表
|
|
|
+ //dcList, _ := Device.Read_DeviceClassList_OrderList(Task_r.T_class, T_sn, T_id, "", 0, 9999)
|
|
|
+ dcList := []Device.DeviceClassList{}
|
|
|
+ dataList, _ := Task.Read_TaskData_ById_List(Task_r.T_task_id, T_sn, T_id, Time_start, Time_end, 0, 9999)
|
|
|
+ dataListMap := make(map[string][]Task.TaskData_)
|
|
|
+ dcListMap := make(map[string]string)
|
|
|
+ for _, data := range dataList {
|
|
|
+ dataListMap[data.T_id] = append(dataListMap[data.T_id], data)
|
|
|
+ if _, ok := dcListMap[data.T_id]; !ok {
|
|
|
+ dcListMap[data.T_id] = data.T_sn
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for id, sn := range dcListMap {
|
|
|
+ dcList = append(dcList, Device.DeviceClassList{T_id: id, T_sn: sn})
|
|
|
+ }
|
|
|
+ for id, list := range dataListMap {
|
|
|
+ sort.Slice(list, func(i, j int) bool {
|
|
|
+ return list[i].T_time < list[j].T_time
|
|
|
+ })
|
|
|
+ dataListMap[id] = list
|
|
|
+ }
|
|
|
+
|
|
|
+ dataMap := make(map[string]string)
|
|
|
+ timeMap := make(map[string]bool)
|
|
|
+ for _, data := range dataList {
|
|
|
+ k := fmt.Sprintf("%s,%s", data.T_time, data.T_id)
|
|
|
+ if T_type == Task.Temperature {
|
|
|
+ dataMap[k] = fmt.Sprintf("%.1f", data.T_t)
|
|
|
+ }
|
|
|
+ if T_type == Task.Humidity {
|
|
|
+ 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]
|
|
|
+ })
|
|
|
+ err = pdf.SetFont("wts", "", 12)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ y += 20
|
|
|
+ var x float64 = 10
|
|
|
+ var w float64 = 120
|
|
|
+
|
|
|
+ err = pdf.SetFont("wts", "", 10)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ idWidthMap := make(map[string]float64)
|
|
|
+ dcList1 := make([]Device.DeviceClassList, 0)
|
|
|
+ for _, list := range dcList {
|
|
|
+ idw, _ := pdf.MeasureTextWidth(list.T_id)
|
|
|
+ if !lib.IsNumeric(list.T_id) {
|
|
|
+ dcList1 = append(dcList1, list)
|
|
|
+ }
|
|
|
+ if idw > 20 {
|
|
|
+ idWidthMap[list.T_id] = idw + 12
|
|
|
+ } else {
|
|
|
+ idWidthMap[list.T_id] = 30.3
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort.Slice(dcList1, func(i, j int) bool {
|
|
|
+ return dcList1[i].T_id < dcList1[j].T_id
|
|
|
+ })
|
|
|
+ for _, dc := range dcList1 {
|
|
|
+
|
|
|
+ dataList2, _ := dataListMap[dc.T_id]
|
|
|
+
|
|
|
+ err = pdf.SetFont("wts", "", 15)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var textH float64 = 20 // if text height is 25px.
|
|
|
+ y += 20
|
|
|
+ pdf.SetNewY(y, textH)
|
|
|
+ y = pdf.GetY()
|
|
|
+ if y > 790 {
|
|
|
+ pdf.AddPage()
|
|
|
+ y = 30
|
|
|
+ }
|
|
|
+
|
|
|
+ textw, _ = pdf.MeasureTextWidth(dc.T_id)
|
|
|
+ pdf.SetX((595 / 2) - (textw / 2))
|
|
|
+ pdf.SetY(y)
|
|
|
+ pdf.Text(dc.T_id)
|
|
|
+ y += 10
|
|
|
+
|
|
|
+ err = pdf.SetFont("wts", "", 10)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pdf.SetNewY(y, textH)
|
|
|
+ y = pdf.GetY()
|
|
|
+ if y < 790 {
|
|
|
+ x = 10
|
|
|
+ for i := 0; i < 4; i++ {
|
|
|
+ w = 113.8
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ w = 30
|
|
|
+ lib.RectFillColor(pdf, T_type_name, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ }
|
|
|
+ y += 20
|
|
|
+ } else {
|
|
|
+ pdf.AddPage()
|
|
|
+ y = 20
|
|
|
+ x = 10
|
|
|
+ for i := 0; i < 4; i++ {
|
|
|
+ w = 113.8
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ w = 30
|
|
|
+ lib.RectFillColor(pdf, T_type_name, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ }
|
|
|
+ y += 20
|
|
|
+ }
|
|
|
+ for i := 0; i < len(dataList2); i++ {
|
|
|
+ temp := i % 4
|
|
|
+ x = 10 + 143.8*float64(temp)
|
|
|
+ w = 113.8
|
|
|
+
|
|
|
+ lib.RectFillColor(pdf, dataList2[i].T_time, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ w = 30
|
|
|
+ if T_type == Task.Temperature {
|
|
|
+ lib.RectFillColor(pdf, fmt.Sprintf("%.1f", dataList2[i].T_t), 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_type == Task.Humidity {
|
|
|
+ lib.RectFillColor(pdf, fmt.Sprintf("%.1f", dataList2[i].T_rh), 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if temp == 3 {
|
|
|
+ y += 20
|
|
|
+ pdf.SetNewY(y, textH)
|
|
|
+ y = pdf.GetY()
|
|
|
+ // 每页添加表头
|
|
|
+ if y == 20 {
|
|
|
+ x = 10
|
|
|
+ for k := 0; k < 4; k++ {
|
|
|
+ w = 113.8
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ w = 30
|
|
|
+ lib.RectFillColor(pdf, T_type_name, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ }
|
|
|
+ y += 20
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ y += 25
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //chunks := chunkBy(dcList, 15)
|
|
|
+ y += 20
|
|
|
+ dcList2 := listSubtract(dcList, dcList1)
|
|
|
+ sort.Slice(dcList2, func(i, j int) bool {
|
|
|
+ return dcList2[i].T_id < dcList2[j].T_id
|
|
|
+ })
|
|
|
+ chunks := splitData(dcList2, 454.5, idWidthMap)
|
|
|
+ for _, list := range chunks {
|
|
|
+ var textH float64 = 20 // if text height is 25px.
|
|
|
+ pdf.SetNewY(y, textH)
|
|
|
+ y = pdf.GetY()
|
|
|
+ if y < 790 {
|
|
|
+ x = 10
|
|
|
+ w = 120.7
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ w = 30.3
|
|
|
+ for _, v2 := range list {
|
|
|
+ w = idWidthMap[v2.T_id]
|
|
|
+ lib.RectFillColor(pdf, v2.T_id, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ }
|
|
|
+ y += 20
|
|
|
+ } else {
|
|
|
+ pdf.AddPage()
|
|
|
+ y = 20
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, t := range timeList {
|
|
|
+ x = 10
|
|
|
+ textH = 20 // if text height is 25px.
|
|
|
+ pdf.SetNewY(y, textH)
|
|
|
+ y = pdf.GetY()
|
|
|
+ if y == 20 {
|
|
|
+ w = 120.7
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ w = 30.3
|
|
|
+ for _, v2 := range list {
|
|
|
+ w = idWidthMap[v2.T_id]
|
|
|
+ lib.RectFillColor(pdf, v2.T_id, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ }
|
|
|
+ y += 20
|
|
|
+ x = 10
|
|
|
+ }
|
|
|
+ w = 120.7
|
|
|
+ lib.RectFillColor(pdf, t, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x += w
|
|
|
+ w = 30.3
|
|
|
+ for _, v := range list {
|
|
|
+ t_t := dataMap[fmt.Sprintf("%s,%s", t, v.T_id)]
|
|
|
+ w = idWidthMap[v.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/" + T_type_name + filename
|
|
|
+
|
|
|
+ err = pdf.WritePdf(timeStr)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传 OSS
|
|
|
+ //url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr, timeStr)
|
|
|
+ //url, is := NatsServer.Qiniu_UploadFile("/Users/zoie/work/bzd_project/ColdVerify_server/"+timeStr, timeStr)
|
|
|
+ //if !is {
|
|
|
+ // err = errors.New("oss!")
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ //删除目录
|
|
|
+ os.Remove(timeStr)
|
|
|
+ }()
|
|
|
+
|
|
|
+ c.Ctx.Output.Download(timeStr)
|
|
|
+ //c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
|
|
|
+ //c.ServeJSON()
|
|
|
+ //return
|
|
|
+ return nil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func listSubtract(sliceA, sliceB []Device.DeviceClassList) []Device.DeviceClassList {
|
|
|
+ // 创建一个集合用于存储 sliceB 的元素
|
|
|
+ elementsToRemove := make(map[string]Device.DeviceClassList)
|
|
|
+ for _, item := range sliceB {
|
|
|
+ elementsToRemove[item.T_id] = item
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建新切片,包含 sliceA 中不在 elementsToRemove 中的元素
|
|
|
+ var result []Device.DeviceClassList
|
|
|
+ for _, item := range sliceA {
|
|
|
+ if _, found := elementsToRemove[item.T_id]; !found {
|
|
|
+ result = append(result, item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result
|
|
|
+}
|
|
|
+func chunkBy1[T any](list []T, size int) [][]T {
|
|
|
+ var chunks [][]T
|
|
|
+ for size < len(list) {
|
|
|
+ list, chunks = list[size:], append(chunks, list[0:size:size])
|
|
|
+ }
|
|
|
+ return append(chunks, list)
|
|
|
+}
|
|
|
+func splitData(data []Device.DeviceClassList, threshold float64, idWidthMap map[string]float64) [][]Device.DeviceClassList {
|
|
|
+ var result [][]Device.DeviceClassList
|
|
|
+ var currentBatch []Device.DeviceClassList
|
|
|
+ var currentSum float64
|
|
|
+
|
|
|
+ for _, item := range data {
|
|
|
+ wd := idWidthMap[item.T_id]
|
|
|
+ if currentSum+wd > threshold+0.1 {
|
|
|
+ // 当前批次超过阈值,切分
|
|
|
+ result = append(result, currentBatch)
|
|
|
+ // 重置当前批次和当前总和
|
|
|
+ currentBatch = []Device.DeviceClassList{}
|
|
|
+ currentSum = 0
|
|
|
+ }
|
|
|
+ currentBatch = append(currentBatch, item)
|
|
|
+ currentSum += wd
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加最后一批
|
|
|
+ if len(currentBatch) > 0 {
|
|
|
+ result = append(result, currentBatch)
|
|
|
+ }
|
|
|
+
|
|
|
+ return result
|
|
|
+}
|