编辑代码

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 = StringEscapeUtils.escapeJava( parts[1]); 
    def WellName =  parts[1]; 
	def WellStatus = parts[2]
	def InpStatus = parts[3]
	def AlarmCode = parts[4]
	def DataTime = parts[5]

  // def a0 =  StringEscapeUtils.escapeJava(WellName);//编码 
  //  def aa = StringEscapeUtils.unescapeJava(WellName);

 


   // WellName = StringEscapeUtils.unescapeJava(WellName); 
   // println "import groovy.json.StringEscapeUtils";
   
    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 (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);
	//return StringEscapeUtils.unescapeJava(json)
   //return StringEscapeUtils.unescapeHtml3(json);

   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")