content: /**
   * DBSyncer Copyright 2020-2024 All Rights Reserved.
   */
  package org.dbsyncer.sdk.schema.support;
  
  import org.dbsyncer.common.util.DateFormatUtil;
  import org.dbsyncer.sdk.enums.DataTypeEnum;
  import org.dbsyncer.sdk.model.Field;
  import org.dbsyncer.sdk.schema.AbstractDataType;
  
  import java.sql.Date;
  import java.sql.Timestamp;
  import java.time.LocalDate;
  import java.time.LocalDateTime;
  
  /**
   * @Author 穿云
   * @Version 1.0.0
   * @Date 2024-11-21 23:56
   */
  public abstract class StringType extends AbstractDataType<String> {
  
      @Override
      public DataTypeEnum getType() {
          return DataTypeEnum.STRING;
      }
  
      @Override
      protected Object convert(Object val, Field field) {
          if (val instanceof String) {
              return val;
          }
          if (val instanceof byte[]) {
              return new String((byte[]) val);
          }
  
          if (val instanceof Number) {
              Number number = (Number) val;
              return number.toString();
          }
  
          if (val instanceof LocalDateTime) {
              return ((LocalDateTime) val).format(DateFormatUtil.CHINESE_STANDARD_TIME_FORMATTER);
          }
  
          if (val instanceof LocalDate) {
              return ((LocalDate) val).format(DateFormatUtil.DATE_FORMATTER);
          }
  
          if (val instanceof Timestamp) {
              return DateFormatUtil.timestampToString((Timestamp) val);
          }
  
          if (val instanceof Date) {
              return DateFormatUtil.dateToString((Date) val);
          }
  
          if (val instanceof java.util.Date) {
              return DateFormatUtil.dateToString((java.util.Date) val);
          }
  
          return throwUnsupportedException(val, field);
      }
  }