import groovy.json.JsonOutput;
import java.text.SimpleDateFormat;
import groovy.json.JsonSlurper;
def transformValue (recordValue) {
def parts = recordValue.split("\\|")
def TimeRead = parts[0]
def WellName = parts[1];
def WellStatus = parts[2]
def InpStatus = parts[3]
def AlarmCode = parts[4]
def DataTime = parts[5]
int _WellStatus =0;
try {
WellStatus = WellStatus.toInteger()
} catch (NumberFormatException e) {
println "WellStatus 转换失败: ${e.message}"
}
int _InpStatus =0;
try {
_InpStatus = InpStatus.toInteger()
} catch (NumberFormatException e) {
println "_InpStatus 转换失败: ${e.message}"
}
def _DataTime ="";
try {
def v = Date.parse("yyyy-MM-dd HH:mm:ss", DataTime);
_DataTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(v);
} catch (Exception e) {
println "_InpStatus 转换失败: ${e.message}"
}
def map = [
TimeRead: TimeRead,
WellName: WellName,
WellStatus: _WellStatus,
InpStatus: _InpStatus,
AlarmCode: AlarmCode,
DataTime: _DataTime
]
def json = JsonOutput.toJson(map);
def json = new JsonSlurper().parseText(json)
String correctName = new String(json.WellName.getBytes("ISO-8859-1"), "UTF-8")
println " 测试:"+ correctName
return json;
};
println transformValue("2025-01-09 14:32:34.0|镇2025|2|0|16,|2025-01-09 14:33:57.71")