|
@@ -5,6 +5,7 @@ import (
|
|
|
"math"
|
|
"math"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
+ "time"
|
|
|
|
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
jsoniter "github.com/json-iterator/go"
|
|
|
)
|
|
)
|
|
@@ -109,3 +110,1060 @@ func TransformType4(arg1 string) (string, error) {
|
|
|
resultJSON, err := jsoniter.Marshal(outer)
|
|
resultJSON, err := jsoniter.Marshal(outer)
|
|
|
return string(resultJSON), err
|
|
return string(resultJSON), err
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func TransformType5(arg1 string) (string, error) {
|
|
|
|
|
+ // 定义入参结构体(仅保留核心data字段)
|
|
|
|
|
+ type inputData struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Today float64 `json:"Today"`
|
|
|
|
|
+ Change float64 `json:"Change"`
|
|
|
|
|
+ Items []string `json:"Items"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var input inputData
|
|
|
|
|
+ if err := jsoniter.Unmarshal([]byte(arg1), &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理内层数据
|
|
|
|
|
+ inner := struct {
|
|
|
|
|
+ Today float64 `json:"today"`
|
|
|
|
|
+ Change string `json:"change"`
|
|
|
|
|
+ Items string `json:"items"`
|
|
|
|
|
+ }{
|
|
|
|
|
+ Today: math.Round(input.Data.Today*100) / 100,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理Change
|
|
|
|
|
+ switch {
|
|
|
|
|
+ case input.Data.Change > 0:
|
|
|
|
|
+ inner.Change = fmt.Sprintf("增加%.0f%%", input.Data.Change)
|
|
|
|
|
+ case input.Data.Change == 0:
|
|
|
|
|
+ inner.Change = "无变化"
|
|
|
|
|
+ default:
|
|
|
|
|
+ inner.Change = fmt.Sprintf("减少%.0f%%", math.Abs(input.Data.Change))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理Items
|
|
|
|
|
+ if len(input.Data.Items) > 0 {
|
|
|
|
|
+ inner.Items = strings.Join(input.Data.Items, "")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 外层包裹data
|
|
|
|
|
+ outer := struct {
|
|
|
|
|
+ Data interface{} `json:"data"`
|
|
|
|
|
+ }{Data: inner}
|
|
|
|
|
+ resultJSON, err := jsoniter.Marshal(outer)
|
|
|
|
|
+ return string(resultJSON), err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func TransformType6(arg1 string) (string, error) {
|
|
|
|
|
+
|
|
|
|
|
+ // 定义入参结构体(兼容code/msg,匹配真实入参格式)
|
|
|
|
|
+ type inputData struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Uf string `json:"uf"`
|
|
|
|
|
+ Ro string `json:"ro"`
|
|
|
|
|
+ Pump string `json:"pump"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 解析入参JSON(使用jsoniter替代标准库)
|
|
|
|
|
+ var input inputData
|
|
|
|
|
+ if err := jsoniter.Unmarshal([]byte(arg1), &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理ufStatus逻辑(对齐Python:默认良好,值为"0"则一般)
|
|
|
|
|
+ ufStatus := "良好"
|
|
|
|
|
+ if strings.TrimSpace(input.Data.Uf) == "0" {
|
|
|
|
|
+ ufStatus = "一般"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理roStatus逻辑
|
|
|
|
|
+ roStatus := "良好"
|
|
|
|
|
+ if strings.TrimSpace(input.Data.Ro) == "0" {
|
|
|
|
|
+ roStatus = "一般"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理pumpStatus逻辑
|
|
|
|
|
+ pumpStatus := "良好"
|
|
|
|
|
+ if strings.TrimSpace(input.Data.Pump) == "0" {
|
|
|
|
|
+ pumpStatus = "一般"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 定义内层结果结构体
|
|
|
|
|
+ inner := struct {
|
|
|
|
|
+ Uf string `json:"uf"`
|
|
|
|
|
+ Ro string `json:"ro"`
|
|
|
|
|
+ Pump string `json:"pump"`
|
|
|
|
|
+ }{
|
|
|
|
|
+ Uf: ufStatus,
|
|
|
|
|
+ Ro: roStatus,
|
|
|
|
|
+ Pump: pumpStatus,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 外层包裹data的结构体
|
|
|
|
|
+ outer := struct {
|
|
|
|
|
+ Data interface{} `json:"data"`
|
|
|
|
|
+ }{
|
|
|
|
|
+ Data: inner,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 序列化为JSON字符串(使用jsoniter)
|
|
|
|
|
+ resultJSON, err := jsoniter.Marshal(outer)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return string(resultJSON), nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// ProcessDeviceTime 解析设备和创建时间数据,入参为JSON字符串,返回带data包裹的JSON字符串
|
|
|
|
|
+func TransformType8(arg1 string) (string, error) {
|
|
|
|
|
+ // 定义入参结构体(匹配输入的code/msg/data格式)
|
|
|
|
|
+ type inputStruct struct {
|
|
|
|
|
+ Code int `json:"code"`
|
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Level string `json:"level"`
|
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 用jsoniter解析输入JSON字符串
|
|
|
|
|
+ var input inputStruct
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 清理msg中的无效占位符(修复%!s(MISSING))
|
|
|
|
|
+ cleanMsg := strings.ReplaceAll(input.Data.Msg, "%!s(MISSING)", "")
|
|
|
|
|
+ // 去除末尾多余的、号
|
|
|
|
|
+ cleanMsg = strings.TrimSuffix(cleanMsg, "、")
|
|
|
|
|
+
|
|
|
|
|
+ // 构造仅单层data包裹的输出结构
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Level string `json:"level"`
|
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Level = input.Data.Level
|
|
|
|
|
+ output.Data.Msg = cleanMsg
|
|
|
|
|
+
|
|
|
|
|
+ // 用jsoniter序列化为JSON字符串返回
|
|
|
|
|
+ result, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ return result, nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func TransformType15(arg1 string) (string, error) {
|
|
|
|
|
+ // 定义入参结构体(匹配Python解析的data数组结构)
|
|
|
|
|
+ type inputItem struct {
|
|
|
|
|
+ MetricCode string `json:"metric_code"`
|
|
|
|
|
+ TargetVal interface{} `json:"target_val"` // 兼容任意类型,后续转字符串
|
|
|
|
|
+ MetricVal string `json:"metric_val"`
|
|
|
|
|
+ MetricName string `json:"metric_name"`
|
|
|
|
|
+ }
|
|
|
|
|
+ type inputData struct {
|
|
|
|
|
+ Data []inputItem `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 解析输入JSON
|
|
|
|
|
+ var input inputData
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化默认值(对齐Python的初始值)
|
|
|
|
|
+ flowTarget := "0"
|
|
|
|
|
+ flowValue := "0"
|
|
|
|
|
+ elecValue := "0"
|
|
|
|
|
+ metricValue := "0"
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历数据处理逻辑(完全对齐Python)
|
|
|
|
|
+ for _, item := range input.Data {
|
|
|
|
|
+ if item.MetricCode == "plant_permeate_flow" {
|
|
|
|
|
+ // 将target_val转为字符串(对齐Python的str())
|
|
|
|
|
+ flowTarget, _ = jsoniter.MarshalToString(item.TargetVal)
|
|
|
|
|
+ flowValue = item.MetricVal
|
|
|
|
|
+ }
|
|
|
|
|
+ if item.MetricName == "电耗" {
|
|
|
|
|
+ elecValue = item.MetricVal
|
|
|
|
|
+ }
|
|
|
|
|
+ if item.MetricName == "药耗" {
|
|
|
|
|
+ metricValue = item.MetricVal
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 构造外层仅包data的输出结构
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ FlowTarget string `json:"flow_target"`
|
|
|
|
|
+ FlowValue string `json:"flow_value"`
|
|
|
|
|
+ ElecValue string `json:"elec_value"`
|
|
|
|
|
+ MetricValue string `json:"metric_value"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.FlowTarget = flowTarget
|
|
|
|
|
+ output.Data.FlowValue = flowValue
|
|
|
|
|
+ output.Data.ElecValue = elecValue
|
|
|
|
|
+ output.Data.MetricValue = metricValue
|
|
|
|
|
+
|
|
|
|
|
+ // 序列化为JSON字符串返回
|
|
|
|
|
+ result, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ return result, nil
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType17(arg1 string) (string, error) {
|
|
|
|
|
+ // 定义入参结构体(按需解析data中的字段)
|
|
|
|
|
+ type inputData struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ WorkOrderTotal int `json:"work_order_total"`
|
|
|
|
|
+ CommandTotal int `json:"command_total"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 解析输入JSON字符串
|
|
|
|
|
+ var input inputData
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化默认值(对齐Python的0值)
|
|
|
|
|
+ workOrderTotal := 0
|
|
|
|
|
+ commandTotal := 0
|
|
|
|
|
+
|
|
|
|
|
+ // 匹配Python的存在性判断逻辑
|
|
|
|
|
+ if input.Data.WorkOrderTotal != 0 { // JSON解析后不存在则为0,符合Python逻辑
|
|
|
|
|
+ workOrderTotal = input.Data.WorkOrderTotal
|
|
|
|
|
+ }
|
|
|
|
|
+ if input.Data.CommandTotal != 0 {
|
|
|
|
|
+ commandTotal = input.Data.CommandTotal
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 构造外层仅包data的输出结构
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ WorkOrderTotal int `json:"work_order_total"`
|
|
|
|
|
+ CommandTotal int `json:"command_total"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.WorkOrderTotal = workOrderTotal
|
|
|
|
|
+ output.Data.CommandTotal = commandTotal
|
|
|
|
|
+
|
|
|
|
|
+ // 序列化为JSON字符串返回
|
|
|
|
|
+ result, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ return result, nil
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType19(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(匹配嵌套的data.pagination结构)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Pagination struct {
|
|
|
|
|
+ Total int `json:"total"`
|
|
|
|
|
+ } `json:"pagination"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取total(不存在则为0,对齐Python的in判断)
|
|
|
|
|
+ result := input.Data.Pagination.Total
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 生成统计文本(对齐Python的format逻辑)
|
|
|
|
|
+ var detail string
|
|
|
|
|
+ if result == 0 {
|
|
|
|
|
+ detail = "暂无门禁设备"
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detail = fmt.Sprintf("共%d个门禁设备", result)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Result string `json:"result"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Result = detail
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType21(arg1 string) (string, error) {
|
|
|
|
|
+ // 定义入参结构体(匹配data数组结构)
|
|
|
|
|
+ type inputItem struct {
|
|
|
|
|
+ MetricEnCode string `json:"metric_en_code"`
|
|
|
|
|
+ MetricVal string `json:"metric_val"`
|
|
|
|
|
+ MetricName string `json:"metric_name"`
|
|
|
|
|
+ }
|
|
|
|
|
+ type inputData struct {
|
|
|
|
|
+ Data []inputItem `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 解析输入JSON字符串
|
|
|
|
|
+ var input inputData
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化默认值(对齐Python)
|
|
|
|
|
+ level := "良好"
|
|
|
|
|
+ var msgBuilder strings.Builder
|
|
|
|
|
+
|
|
|
|
|
+ // 获取上海时区当前时间(对齐Python的ZoneInfo("Asia/Shanghai"))
|
|
|
|
|
+ shanghaiLoc, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
|
|
+ now := time.Now().In(shanghaiLoc)
|
|
|
|
|
+ // 格式化时间为"HH时MM分"(对齐Python的strftime("%H时%M分"))
|
|
|
|
|
+ currTime := now.Format("15时04分")
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历数据处理逻辑(完全对齐Python)
|
|
|
|
|
+ for _, line := range input.Data {
|
|
|
|
|
+ if line.MetricEnCode == "water_quality" {
|
|
|
|
|
+ if line.MetricVal == "0" {
|
|
|
|
|
+ level = "一般"
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 仅过滤"外供水PH"和"外供水电导率"
|
|
|
|
|
+ if line.MetricName == "外供水PH" || line.MetricName == "外供水电导率" {
|
|
|
|
|
+ if msgBuilder.Len() > 0 {
|
|
|
|
|
+ msgBuilder.WriteString("、")
|
|
|
|
|
+ }
|
|
|
|
|
+ msgBuilder.WriteString(line.MetricName + "是" + line.MetricVal)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 构造外层仅包data的输出结构
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Level string `json:"level"`
|
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
|
+ Curr string `json:"curr"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Level = level
|
|
|
|
|
+ output.Data.Msg = msgBuilder.String() // 无需rstrip,Builder拼接无末尾多余符号
|
|
|
|
|
+ output.Data.Curr = currTime
|
|
|
|
|
+
|
|
|
|
|
+ // 序列化为JSON字符串返回
|
|
|
|
|
+ result, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ return result, nil
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType22(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 拆分双JSON字符串
|
|
|
|
|
+ parts := strings.Split(arg1, "#@#@#@")
|
|
|
|
|
+ if len(parts) != 2 {
|
|
|
|
|
+ return "", fmt.Errorf("输入格式错误,需2个JSON片段")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 解析并处理第一个JSON(流量/状态逻辑)
|
|
|
|
|
+ var first struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Dwa float64 `json:"dwa"`
|
|
|
|
|
+ Fwa float64 `json:"fwa"`
|
|
|
|
|
+ DwaStatus int `json:"dwa_status"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(parts[0], &first); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ // 状态判断+数值格式化
|
|
|
|
|
+ status := "均衡期"
|
|
|
|
|
+ switch first.Data.DwaStatus {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ status = "高峰期"
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ status = "均衡期"
|
|
|
|
|
+ default:
|
|
|
|
|
+ status = "低峰期"
|
|
|
|
|
+ }
|
|
|
|
|
+ dwaStr := fmt.Sprintf("%.2f立方米/小时", first.Data.Dwa)
|
|
|
|
|
+ fwaStr := fmt.Sprintf("%.2f立方米/小时", first.Data.Fwa)
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 解析并处理第二个JSON(产水/时间逻辑)
|
|
|
|
|
+ var second struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ TodayFeed float64 `json:"today_feed"`
|
|
|
|
|
+ TodayPermeate float64 `json:"today_permeate"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(parts[1], &second); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ // 小数处理+时间格式化
|
|
|
|
|
+ todayFeed := float64(int(second.Data.TodayFeed*100+0.5)) / 100
|
|
|
|
|
+ todayPermeate := float64(int(second.Data.TodayPermeate*100+0.5)) / 100
|
|
|
|
|
+ loc, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
|
|
+ curr := time.Now().In(loc).Format("15时04分")
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 合并结果并序列化(匿名结构体简化定义)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Dwa string `json:"dwa"`
|
|
|
|
|
+ Fwa string `json:"fwa"`
|
|
|
|
|
+ Status string `json:"status"`
|
|
|
|
|
+ TodayFeed float64 `json:"today_feed"`
|
|
|
|
|
+ TodayPermeate float64 `json:"today_permeate"`
|
|
|
|
|
+ Curr string `json:"curr"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Dwa = dwaStr
|
|
|
|
|
+ output.Data.Fwa = fwaStr
|
|
|
|
|
+ output.Data.Status = status
|
|
|
|
|
+ output.Data.TodayFeed = todayFeed
|
|
|
|
|
+ output.Data.TodayPermeate = todayPermeate
|
|
|
|
|
+ output.Data.Curr = curr
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 生成最终JSON
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType23(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 拆分双JSON字符串
|
|
|
|
|
+ parts := strings.Split(arg1, "#@#@#@")
|
|
|
|
|
+ if len(parts) != 2 {
|
|
|
|
|
+ return "", fmt.Errorf("输入需包含2个JSON片段(#@#@#@分隔)")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 解析处理第一个JSON(电耗/产水/水电比逻辑)
|
|
|
|
|
+ var first struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Electric float64 `json:"electric"`
|
|
|
|
|
+ WaterOut float64 `json:"waterOut"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(parts[0], &first); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ electric := first.Data.Electric
|
|
|
|
|
+ waterOut := first.Data.WaterOut
|
|
|
|
|
+ waterElec := 0.0
|
|
|
|
|
+ if waterOut != 0 {
|
|
|
|
|
+ waterElec = float64(int((electric/waterOut)*100+0.5)) / 100 // 保留2位小数
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 解析处理第二个JSON(小时/指标/数值逻辑)
|
|
|
|
|
+ var second struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Hour string `json:"hour"`
|
|
|
|
|
+ Metric string `json:"metric"`
|
|
|
|
|
+ Val float64 `json:"val"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(parts[1], &second); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 合并结果并序列化(匿名结构体极简定义)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Electric float64 `json:"electric"`
|
|
|
|
|
+ WaterElec float64 `json:"waterElec"`
|
|
|
|
|
+ Hour string `json:"hour"`
|
|
|
|
|
+ Metric string `json:"metric"`
|
|
|
|
|
+ Val float64 `json:"val"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Electric = electric
|
|
|
|
|
+ output.Data.WaterElec = waterElec
|
|
|
|
|
+ output.Data.Hour = second.Data.Hour
|
|
|
|
|
+ output.Data.Metric = second.Data.Metric
|
|
|
|
|
+ output.Data.Val = second.Data.Val
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 生成最终JSON字符串
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType24(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 拆分#@#@#@分隔的双JSON
|
|
|
|
|
+ parts := strings.Split(arg1, "#@#@#@")
|
|
|
|
|
+ if len(parts) != 2 {
|
|
|
|
|
+ return "", fmt.Errorf("输入需包含2个JSON片段(#@#@#@分隔)")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 解析处理第一个JSON(药剂使用量拼接逻辑)
|
|
|
|
|
+ var first struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ List []struct {
|
|
|
|
|
+ ChemicalAgents string `json:"chemical_agents"`
|
|
|
|
|
+ Value float64 `json:"value"`
|
|
|
|
|
+ } `json:"list"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(parts[0], &first); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ // 拼接msg(用Builder避免冗余逗号,替代rstrip)
|
|
|
|
|
+ var msgBuilder strings.Builder
|
|
|
|
|
+ for _, line := range first.Data.List {
|
|
|
|
|
+ if msgBuilder.Len() > 0 {
|
|
|
|
|
+ msgBuilder.WriteString(",")
|
|
|
|
|
+ }
|
|
|
|
|
+ // 保留2位小数,对齐Python的round(line["value"],2)
|
|
|
|
|
+ val := float64(int(line.Value*100+0.5)) / 100
|
|
|
|
|
+ msgBuilder.WriteString(fmt.Sprintf("%s使用%.2f kg", line.ChemicalAgents, val))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 解析处理第二个JSON(今日值/变化率/Items拼接逻辑)
|
|
|
|
|
+ var second struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Today float64 `json:"Today"`
|
|
|
|
|
+ Change float64 `json:"Change"`
|
|
|
|
|
+ Items []string `json:"Items"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(parts[1], &second); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+ // 处理今日值(保留2位小数)
|
|
|
|
|
+ today := float64(int(second.Data.Today*100+0.5)) / 100
|
|
|
|
|
+ // 处理变化率描述
|
|
|
|
|
+ change := "无变化"
|
|
|
|
|
+ if second.Data.Change > 0 {
|
|
|
|
|
+ change = fmt.Sprintf("增加%d%%", second.Data.Change)
|
|
|
|
|
+ } else if second.Data.Change < 0 {
|
|
|
|
|
+ change = fmt.Sprintf("减少%d%%", int(math.Abs(second.Data.Change)))
|
|
|
|
|
+ }
|
|
|
|
|
+ // 处理Items拼接(对齐Python的"".join)
|
|
|
|
|
+ items := strings.Join(second.Data.Items, "")
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 合并结果并序列化(匿名结构体极简定义)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
|
+ Today float64 `json:"today"`
|
|
|
|
|
+ Change string `json:"change"`
|
|
|
|
|
+ Items string `json:"items"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Msg = msgBuilder.String()
|
|
|
|
|
+ output.Data.Today = today
|
|
|
|
|
+ output.Data.Change = change
|
|
|
|
|
+ output.Data.Items = items
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 生成最终JSON字符串
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType25(arg1 string, isEnglish int) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(按需定义结构体,仅解析需要的字段)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Uf string `json:"uf"`
|
|
|
|
|
+ Ro string `json:"ro"`
|
|
|
|
|
+ Pump string `json:"pump"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 状态判断(对齐Python的默认值+字段存在性判断)
|
|
|
|
|
+ ufStatus := "良好"
|
|
|
|
|
+ if input.Data.Uf == "0" {
|
|
|
|
|
+ ufStatus = "一般"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ roStatus := "良好"
|
|
|
|
|
+ if input.Data.Ro == "0" {
|
|
|
|
|
+ roStatus = "一般"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ pumpStatus := "良好"
|
|
|
|
|
+ if input.Data.Pump == "0" {
|
|
|
|
|
+ pumpStatus = "一般"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 中英文切换(替代Python的内部函数)
|
|
|
|
|
+ replaceStatus := func(status string) string {
|
|
|
|
|
+ if isEnglish == 1 {
|
|
|
|
|
+ status = strings.ReplaceAll(status, "一般", "Acceptable")
|
|
|
|
|
+ status = strings.ReplaceAll(status, "良好", "Good")
|
|
|
|
|
+ }
|
|
|
|
|
+ return status
|
|
|
|
|
+ }
|
|
|
|
|
+ ufStatus = replaceStatus(ufStatus)
|
|
|
|
|
+ roStatus = replaceStatus(roStatus)
|
|
|
|
|
+ pumpStatus = replaceStatus(pumpStatus)
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 合并结果并序列化(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Uf string `json:"uf"`
|
|
|
|
|
+ Ro string `json:"ro"`
|
|
|
|
|
+ Pump string `json:"pump"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Uf = ufStatus
|
|
|
|
|
+ output.Data.Ro = roStatus
|
|
|
|
|
+ output.Data.Pump = pumpStatus
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 生成最终JSON字符串
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func TransformType28(arg1 string, isEnglish int) (string, error) {
|
|
|
|
|
+ // 1. 定义中英文状态映射(对齐Python的status_mapping)
|
|
|
|
|
+ statusMapping := map[string]string{
|
|
|
|
|
+ "优秀": "Excellent",
|
|
|
|
|
+ "良好": "Good",
|
|
|
|
|
+ "较好": "Fair",
|
|
|
|
|
+ "一般": "Average",
|
|
|
|
|
+ "较差": "Poor",
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 解析输入JSON(仅解析需要的字段)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Score float64 `json:"score"` // 兼容数字类型(int/float)
|
|
|
|
|
+ Grade string `json:"grade"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 初始化默认值+字段存在性判断(对齐Python)
|
|
|
|
|
+ result := 80.0
|
|
|
|
|
+ if input.Data.Score != 0 { // 不存在则为0,触发默认值逻辑
|
|
|
|
|
+ result = input.Data.Score
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ status := "较好"
|
|
|
|
|
+ if input.Data.Grade != "" { // 不存在则为空字符串,触发默认值逻辑
|
|
|
|
|
+ status = input.Data.Grade
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 中英文切换(对齐Python的映射判断逻辑)
|
|
|
|
|
+ if isEnglish == 1 {
|
|
|
|
|
+ if enStatus, ok := statusMapping[status]; ok {
|
|
|
|
|
+ status = enStatus
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Score float64 `json:"score"`
|
|
|
|
|
+ Status string `json:"status"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Score = result
|
|
|
|
|
+ output.Data.Status = status
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType29(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 拆分双JSON字符串
|
|
|
|
|
+ parts := strings.Split(arg1, "#@#@#@")
|
|
|
|
|
+ if len(parts) != 2 {
|
|
|
|
|
+ return "", nil // 或返回错误:fmt.Errorf("输入需包含2个JSON片段(#@#@#@分隔)")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 通用解析函数(提取list最后一个value,保留2位小数)
|
|
|
|
|
+ parseListValue := func(jsonStr string) float64 {
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ List []struct {
|
|
|
|
|
+ Value float64 `json:"value"`
|
|
|
|
|
+ } `json:"list"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ _ = jsoniter.UnmarshalFromString(jsonStr, &input) // 忽略解析错误,默认返回0
|
|
|
|
|
+
|
|
|
|
|
+ result := 0.0
|
|
|
|
|
+ // 遍历list,取最后一个value(对齐Python逻辑)
|
|
|
|
|
+ for _, row := range input.Data.List {
|
|
|
|
|
+ result = row.Value
|
|
|
|
|
+ }
|
|
|
|
|
+ // 保留2位小数(对齐Python的round(result,2))
|
|
|
|
|
+ return float64(int(result*100+0.5)) / 100
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 解析两个JSON片段
|
|
|
|
|
+ result := parseListValue(parts[0])
|
|
|
|
|
+ result1 := parseListValue(parts[1])
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Result float64 `json:"result"`
|
|
|
|
|
+ Result1 float64 `json:"result_1"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Result = result
|
|
|
|
|
+ output.Data.Result1 = result1
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType30(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(匹配Python的data结构)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Pagination struct {
|
|
|
|
|
+ Total int `json:"total"`
|
|
|
|
|
+ } `json:"pagination"`
|
|
|
|
|
+ List []struct {
|
|
|
|
|
+ Status int `json:"status"`
|
|
|
|
|
+ Reject int `json:"reject"`
|
|
|
|
|
+ } `json:"list"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 初始化默认值(对齐Python)
|
|
|
|
|
+ result := 0
|
|
|
|
|
+ end, accept, unAccept, submit, reject := 0, 0, 0, 0, 0
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 提取total(对齐Python的in判断)
|
|
|
|
|
+ if input.Data.Pagination.Total != 0 {
|
|
|
|
|
+ result = input.Data.Pagination.Total
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 遍历list统计工单状态(0未接单/1已提交/2已完成/3已拒绝/4已接单)
|
|
|
|
|
+ for _, wOrder := range input.Data.List {
|
|
|
|
|
+ switch wOrder.Status {
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ end++
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ unAccept++
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ accept++
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ submit++
|
|
|
|
|
+ }
|
|
|
|
|
+ // 处理reject=3的情况(已拒绝)
|
|
|
|
|
+ if wOrder.Reject == 3 {
|
|
|
|
|
+ reject++
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 拼接输出文本(用Builder避免冗余字符串拼接)
|
|
|
|
|
+ var outTextBuilder strings.Builder
|
|
|
|
|
+ if result == 0 {
|
|
|
|
|
+ outTextBuilder.WriteString("今天未下发工单。")
|
|
|
|
|
+ } else {
|
|
|
|
|
+ outTextBuilder.WriteString(fmt.Sprintf("今天下发%d条工单,", result))
|
|
|
|
|
+ }
|
|
|
|
|
+ if accept != 0 {
|
|
|
|
|
+ outTextBuilder.WriteString(fmt.Sprintf("%d条工单已接单,", accept))
|
|
|
|
|
+ }
|
|
|
|
|
+ if submit != 0 {
|
|
|
|
|
+ outTextBuilder.WriteString(fmt.Sprintf("%d条工单已提交,", submit))
|
|
|
|
|
+ }
|
|
|
|
|
+ if end != 0 {
|
|
|
|
|
+ outTextBuilder.WriteString(fmt.Sprintf("%d条工单已完成,", end))
|
|
|
|
|
+ }
|
|
|
|
|
+ if reject != 0 {
|
|
|
|
|
+ outTextBuilder.WriteString(fmt.Sprintf("%d条工单已拒绝,", reject))
|
|
|
|
|
+ }
|
|
|
|
|
+ outTextBuilder.WriteString("详细的智能工单列表已为您打开,请在右边的画面中查看,谢谢!")
|
|
|
|
|
+ outText := outTextBuilder.String()
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Total int `json:"total"`
|
|
|
|
|
+ End int `json:"end"`
|
|
|
|
|
+ Runing int `json:"runing"`
|
|
|
|
|
+ OutText string `json:"outText"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Total = result
|
|
|
|
|
+ output.Data.End = end
|
|
|
|
|
+ output.Data.Runing = result - end // 运行中=总数-已完成
|
|
|
|
|
+ output.Data.OutText = outText
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType35(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(仅定义需要的字段)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ TotalCount int `json:"total_count"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 初始化默认值+字段存在性判断(对齐Python)
|
|
|
|
|
+ result := 0
|
|
|
|
|
+ if input.Data.TotalCount != 0 { // 不存在则为0,等价Python的in判断
|
|
|
|
|
+ result = input.Data.TotalCount
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 生成详情文本(对齐Python的format逻辑)
|
|
|
|
|
+ var detail string
|
|
|
|
|
+ if result == 0 {
|
|
|
|
|
+ detail = "暂无照明设备"
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detail = fmt.Sprintf("共%d个照明设备", result)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Result string `json:"result"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Result = detail
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType36(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(仅定义核心字段)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ TotalCount int `json:"total_count"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 字段存在性判断(对齐Python的in逻辑)
|
|
|
|
|
+ result := 0
|
|
|
|
|
+ if input.Data.TotalCount != 0 { // 不存在则为0,等价Python的in判断
|
|
|
|
|
+ result = input.Data.TotalCount
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 生成统计文本(对齐Python的format逻辑)
|
|
|
|
|
+ var detail string
|
|
|
|
|
+ if result == 0 {
|
|
|
|
|
+ detail = "暂无空调设备"
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detail = fmt.Sprintf("共%d个空调设备", result)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Result string `json:"result"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Result = detail
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType38(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(仅定义需要的字段)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Remark string `json:"Remark"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取Remark(不存在则为空字符串,对齐Python逻辑)
|
|
|
|
|
+ result := input.Data.Remark
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Result string `json:"result"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Result = result
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType39(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 拆分双JSON字符串
|
|
|
|
|
+ parts := strings.Split(arg1, "#@#@#@")
|
|
|
|
|
+ if len(parts) != 2 {
|
|
|
|
|
+ return "", nil // 容错:非2段返回空(或改为返回错误:fmt.Errorf("输入需包含2个JSON片段"))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 解析第一个JSON(主工艺,默认值:超滤+反渗透(UF+RO))
|
|
|
|
|
+ var first struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ MainProcess string `json:"MainProcess"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ _ = jsoniter.UnmarshalFromString(parts[0], &first) // 忽略解析错误,使用默认值
|
|
|
|
|
+ result := "超滤+反渗透(UF+RO)"
|
|
|
|
|
+ if first.Data.MainProcess != "" { // 字段存在则覆盖默认值
|
|
|
|
|
+ result = first.Data.MainProcess
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 解析第二个JSON(拼接list中所有desc)
|
|
|
|
|
+ var second struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ List []struct {
|
|
|
|
|
+ Desc string `json:"desc"`
|
|
|
|
|
+ } `json:"list"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ _ = jsoniter.UnmarshalFromString(parts[1], &second) // 忽略解析错误,返回空字符串
|
|
|
|
|
+ var result1 strings.Builder
|
|
|
|
|
+ for _, item := range second.Data.List {
|
|
|
|
|
+ result1.WriteString(item.Desc) // 拼接所有desc
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Result string `json:"result"`
|
|
|
|
|
+ Result1 string `json:"result_1"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Result = result
|
|
|
|
|
+ output.Data.Result1 = result1.String()
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType42(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(仅定义核心字段)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ OnAmount int `json:"on_amount"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取on_amount(不存在则为0,对齐Python逻辑)
|
|
|
|
|
+ num := input.Data.OnAmount
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Num int `json:"num"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Num = num
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType51(arg1 string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(匹配嵌套的data.pagination结构)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Pagination struct {
|
|
|
|
|
+ Total int `json:"total"`
|
|
|
|
|
+ } `json:"pagination"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取total(不存在则为0,对齐Python的in判断逻辑)
|
|
|
|
|
+ result := input.Data.Pagination.Total
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Result int `json:"result"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Result = result
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|
|
|
|
|
+func TransformType59(arg1 string, isEnglish int, rq string) (string, error) {
|
|
|
|
|
+ // 1. 解析输入JSON(匹配Python的data结构)
|
|
|
|
|
+ var input struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ WaterLeakPoint []string `json:"water_leak_point"`
|
|
|
|
|
+ WorkOrderNum int `json:"work_order_num"`
|
|
|
|
|
+ Flag int `json:"flag"`
|
|
|
|
|
+ FeedFlow float64 `json:"feed_flow"`
|
|
|
|
|
+ PermeateFlow float64 `json:"permeate_flow"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := jsoniter.UnmarshalFromString(arg1, &input); err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 处理漏水点文本(中英文切换)
|
|
|
|
|
+ var waterLeakPoint string
|
|
|
|
|
+ if len(input.Data.WaterLeakPoint) > 0 {
|
|
|
|
|
+ points := strings.Join(input.Data.WaterLeakPoint, "、")
|
|
|
|
|
+ if isEnglish == 1 {
|
|
|
|
|
+ waterLeakPoint = fmt.Sprintf(", Water leakage occurred at %s", points)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ waterLeakPoint = fmt.Sprintf(",%s发生漏水", points)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 处理工单数量文本(中英文切换)
|
|
|
|
|
+ var workOrderNum string
|
|
|
|
|
+ if input.Data.WorkOrderNum != 0 {
|
|
|
|
|
+ if isEnglish == 1 {
|
|
|
|
|
+ workOrderNum = fmt.Sprintf(", completed %d work orders", input.Data.WorkOrderNum)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ workOrderNum = fmt.Sprintf(",完成%d个工单", input.Data.WorkOrderNum)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 保留2位小数(对齐Python的round)
|
|
|
|
|
+ feedFlow := float64(int(input.Data.FeedFlow*100+0.5)) / 100
|
|
|
|
|
+ permeateFlow := float64(int(input.Data.PermeateFlow*100+0.5)) / 100
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 构造输出(单层data包裹)
|
|
|
|
|
+ output := struct {
|
|
|
|
|
+ Data struct {
|
|
|
|
|
+ Flag int `json:"flag"`
|
|
|
|
|
+ FeedFlow float64 `json:"feed_flow"`
|
|
|
|
|
+ PermeateFlow float64 `json:"permeate_flow"`
|
|
|
|
|
+ WaterLeakPoint string `json:"water_leak_point"`
|
|
|
|
|
+ WorkOrderNum string `json:"work_order_num"`
|
|
|
|
|
+ Result string `json:"result"`
|
|
|
|
|
+ } `json:"data"`
|
|
|
|
|
+ }{}
|
|
|
|
|
+ output.Data.Flag = input.Data.Flag
|
|
|
|
|
+ output.Data.FeedFlow = feedFlow
|
|
|
|
|
+ output.Data.PermeateFlow = permeateFlow
|
|
|
|
|
+ output.Data.WaterLeakPoint = waterLeakPoint
|
|
|
|
|
+ output.Data.WorkOrderNum = workOrderNum
|
|
|
|
|
+
|
|
|
|
|
+ layout := "2006-01-02 15:04:05"
|
|
|
|
|
+ t, _ := time.Parse(layout, rq)
|
|
|
|
|
+ oneDayBefore := t.AddDate(0, 0, -1).Format("2006-01-02")
|
|
|
|
|
+ output.Data.Result = oneDayBefore
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 序列化为JSON字符串返回
|
|
|
|
|
+ res, err := jsoniter.MarshalToString(output)
|
|
|
|
|
+ return res, err
|
|
|
|
|
+}
|