编辑代码

import groovy.json.JsonOutput;
import java.text.SimpleDateFormat;


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);
        // println("当前时间: " + _DataTime);
    
    } catch (NumberFormatException e) {
        println "_InpStatus 转换失败: ${e.message}"
    }
     

	def map = [
		TimeRead: TimeRead,
		WellName: WellName,
		WellStatus: _WellStatus,
		InpStatus: _InpStatus,
		AlarmCode: AlarmCode,
		DataTime: _DataTime
	]
	def json = JsonOutput.toJson(map)
	return json
};




  println transformValue("2025-01-09 14:32:34.0|镇322-733|2|0|16,|2025-01-09 14:33:57.71")