User
func MetricReadStatusMapper(sReference interface{}, dataOld string, dataNew string) string {

	var sReferences []map[string]interface{}
	json.Unmarshal([]byte(sReference.(string)), &sReferences)
	userReadStatus := "true,true,true,true,true,true,true,true,true"

	split := strings.Split(userReadStatus, ",")
	for _, value := range sReferences{
		key := ShrimpEstateMetricKey[value["key"].(string)]

		statusDataOld := "good"
		statusDataNew := "wary"

		keyIndex := key.(int)
		splitDataOld := strings.Split(dataOld, ",")[keyIndex]
		for _, sReference := range sReferences {
			if key == sReference["key"].(string) {
				var reference []map[string]interface{}
				byteReference, _ := json.Marshal(sReference["reference"])
				json.Unmarshal(byteReference, &reference)

				checker := false
				for _, refValue := range reference {
					var parameter []map[string]interface{}
					byteParameter, _ := json.Marshal(refValue["parameter"])
					json.Unmarshal(byteParameter, &parameter)

					for _, parValue := range parameter {
						convRaw, _ := strconv.ParseFloat(splitDataOld, 64)
						if !checker {
							statusDataOld = refValue["status"].(string)
							switch parValue["type"] {
							case "greater-than":
								conv, _ := strconv.ParseFloat(parValue["value"].(string), 64)
								if conv < convRaw {
									checker = true
									break
								}
							case "lower-than":
								conv, _ := strconv.ParseFloat(parValue["value"].(string), 64)
								if conv > convRaw {
									checker = true
									break
								}
							case "between":
								splitVal := strings.Split(parValue["value"].(string), "-")
								fConv, _ := strconv.ParseFloat(splitVal[0], 64)
								sConv, _ := strconv.ParseFloat(splitVal[1], 64)
								if fConv <= convRaw && sConv >= convRaw {
									checker = true
									break
								}
							}
						}
					}
				}
			}
		}

		splitDataNew := strings.Split(dataNew, ",")[keyIndex]
		for _, sReference := range sReferences {
			if key == sReference["key"].(string) {
				var reference []map[string]interface{}
				byteReference, _ := json.Marshal(sReference["reference"])
				json.Unmarshal(byteReference, &reference)

				checker := false
				for _, refValue := range reference {
					var parameter []map[string]interface{}
					byteParameter, _ := json.Marshal(refValue["parameter"])
					json.Unmarshal(byteParameter, &parameter)

					for _, parValue := range parameter {
						convRaw, _ := strconv.ParseFloat(splitDataNew, 64)
						if !checker {
							statusDataNew = refValue["status"].(string)
							switch parValue["type"] {
							case "greater-than":
								conv, _ := strconv.ParseFloat(parValue["value"].(string), 64)
								if conv < convRaw {
									checker = true
									break
								}
							case "lower-than":
								conv, _ := strconv.ParseFloat(parValue["value"].(string), 64)
								if conv > convRaw {
									checker = true
									break
								}
							case "between":
								splitVal := strings.Split(parValue["value"].(string), "-")
								fConv, _ := strconv.ParseFloat(splitVal[0], 64)
								sConv, _ := strconv.ParseFloat(splitVal[1], 64)
								if fConv <= convRaw && sConv >= convRaw {
									checker = true
									break
								}
							}
						}
					}
				}
			}
		}

		if statusDataOld != statusDataNew {
			split[keyIndex] = "false"
		}
	}

	join := strings.Join(split, ",")
	userReadStatus = join
	return userReadStatus
}

var ShrimpEstateMetricKey = map[string]interface{}{
	"water-temperature": 0,
	"dissolved-oxygen":  1,
	"turbidity":         2,
	"water-ph":          3,
	"air-temperature":   4,
	"air-humidity":      5,
	"tds":               8,
}

func (u commandUsecase) Create(ctx context.Context, payload map[string]interface{}) utils.Result {
	var result utils.Result

	var data = make(map[string]interface{})
	var dataReadStatus string

	if payload["platform"] == "antares" {
		if payload["m2m:sgn"].(map[string]interface{})["m2m:nev"] != nil {
			con := payload["m2m:sgn"].(map[string]interface{})["m2m:nev"].(map[string]interface{})["m2m:rep"].(map[string]interface{})["m2m:cin"].(map[string]interface{})["con"].(string)
			json.Unmarshal([]byte(con), &data)
		}
	} else if payload["platform"] == "itdri" {
		queryDeviceRes := <-u.postgreQuery.FindOne(&queries.QueryPayload{
			Table:  "smartfarm_partner_devices",
			Select: "id",
			Where: map[string]interface{}{
				"integration_id": payload["deviceId"],
			},
		})
		if queryDeviceRes.Error != nil {
			errObj := httpError.NewNotFound()
			errObj.Message = "Device tidak terdaftar pada database"
			result.Error = errObj
			return result
		}
		if payload["payload"] != nil {
			data = payload["payload"].(map[string]interface{})
		}
		payload["device_id"] = queryDeviceRes.Data.(map[string]interface{})["id"]

		query := <-u.postgreQuery.FindOne(&queries.QueryPayload{
			Table:  "smartfarm_partner_device_metrics",
			Select: "smartfarm_partner_device_id, value->'data' AS value",
			Where: map[string]interface{}{
				"smartfarm_partner_device_id": payload["device_id"],
			},
			Order: "created_at desc",
		})

		if query.Data == nil {
			dataReadStatus = strings.Repeat("false,", 9) + "false"
		}

		queryRes := <-u.postgreQuery.FindOne(&queries.QueryPayload{
			Table: "smartfarm_partner_device_metrics spdm",
			Select: `subvessels.commodity_variety_id,spdm.data->'user_read_status'->>'data' AS user_read_status_data,
			cv.data->>'smartfarm_references' AS smartfarm_references`,
			Join: `LEFT JOIN subvessel_devices sd ON spdm.smartfarm_partner_device_id  = sd.smartfarm_partner_device_id
			LEFT JOIN subvessels ON sd.subvessel_id = subvessels.id 
			LEFT JOIN commodity_varieties cv ON subvessels.commodity_variety_id = cv.id`,
			Order: "spdm.created_at desc",
			Where: map[string]interface{}{
				"spdm.smartfarm_partner_device_id": payload["device_id"],
			},
		})

		// fmt.Println(data["data"].(string))

		if query.Data != nil {
			dataOld := query.Data.(map[string]interface{})["value"].(string)
			sReference := queryRes.Data.(map[string]interface{})
			dataNew := payload["payload"].(map[string]interface{})["data"].(string)
			// fmt.Println(payload["data"].(string))
			fmt.Println(sReference)
			// fmt.Println(sReference["smartfarm_references"])
			// fmt.Println(dataOld["value"].(string))
			fmt.Println(dataOld)
			// compareData["smartfarm_references"] = helpers.MetricReadStatusMapper(compareData, compareData["smartfarm_references"], dataOld["value"].(string), dataReadStatus, dataNew)
			dataReadStatus = helpers.MetricReadStatusMapper(sReference["smartfarm_references"], dataOld, dataNew)
			// if len(schema) > 0 {
			// 	dataReadStatus = schema[0]["user_read_status"].(string)
			// 	fmt.Println(schema[0]["user_read_status"].(string))
			// 	fmt.Println(dataReadStatus)
			// }

			// if query.Data != nil {
			// 	hasData := query.Data.(map[string]interface{})
			// 	compareData := queryRes.Data.(map[string]interface{})
			// 	schema := helpers.MetricReadStatusMapper(compareData, compareData["smartfarm_references"], hasData["value"].(string), dataReadStatus, data["data"].(string))
			// 	if len(schema) > 0 {
			// 		dataReadStatus = schema[0]["user_read_status"].(string)
			// 		fmt.Println(schema[0]["user_read_status"].(string))
			// 	}
			// fmt.Println(compareData["smartfarm_references"])
			// fmt.Println(data)
			// fmt.Println(schema)
			// fmt.Println(dataReadStatus)
			// fmt.Println(hasData["value"].(string))
			// fmt.Println(data["data"].(string))
		}

		// fmt.Println(queryRes)       // old data status
		// fmt.Println(query.Data)     // old data value
		// fmt.Println(dataReadStatus) // new data status
		// fmt.Println(payload["data"].(string))          // new data value

	} else {
		for key, value := range payload {
			if key != "connection" && key != "device_id" {
				data[key] = value
			}
		}
	}

	commandPayload := commands.CommandPayload{
		Table: "smartfarm_partner_device_metrics",
		Document: map[string]interface{}{
			"id":                          uuid.NewString(),
			"name":                        "",
			"type":                        "",
			"timestamp":                   "",
			"value":                       data,
			"created_at":                  time.Now(),
			"created_by":                  payload["connection"].(string),
			"smartfarm_partner_device_id": payload["device_id"],
			"data":                        map[string]interface{}{"user_read_status": map[string]interface{}{"data": dataReadStatus}},
		},
	}

	commandResult := <-u.postgreCommand.InsertOne(&commandPayload)
	if commandResult.Error != nil {
		errObj := httpError.NewInternalServerError()
		errObj.Message = "Gagal menerima data device"
		result.Error = errObj
		return result
	}

	result.Data = commandResult.Data

	return result
}

kenapa saat create data hasilnya malah seperti ini:
"data": {
            "user_read_status": {
                "data": "false,false,false,false,true,false,true,true,false"
            }
        },

seharusnya false semua karena pada data baru tidak ada perubahan data. tapi jika ada perubahan data pada salah satu data, maka hanya salah satu data tersebut yang berubah menjadi false, jika pada data old status datanya true. tapi jika pada status data old status datanya false, meskipun ada perubahan data. maka tetap status datanya false