mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 18:53:12 +08:00
optimize MysqlYearProcessor
This commit is contained in:
@ -4,9 +4,6 @@ import ai.chat2db.spi.jdbc.DefaultValueProcessor;
|
||||
import ai.chat2db.spi.model.JDBCDataValue;
|
||||
import ai.chat2db.spi.model.SQLDataValue;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* 功能描述
|
||||
*
|
||||
@ -23,40 +20,12 @@ public class MysqlYearProcessor extends DefaultValueProcessor {
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueByType(JDBCDataValue dataValue) {
|
||||
Date date = dataValue.getDate();
|
||||
if (!isValidYear(dataValue)) {
|
||||
return "0000";
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
String yStr;
|
||||
String yZerosPadding = "0000";
|
||||
if (year < 1000) {
|
||||
yStr = "" + year;
|
||||
yStr = yZerosPadding.substring(0, (4 - yStr.length())) + yStr;
|
||||
} else {
|
||||
yStr = "" + year;
|
||||
}
|
||||
return yStr;
|
||||
}
|
||||
|
||||
private boolean isValidYear(JDBCDataValue data) {
|
||||
byte[] buffer = data.getBytes();
|
||||
String stringValue = new String(buffer);
|
||||
return stringValue.length() <= 0
|
||||
|| stringValue.charAt(0) != '0'
|
||||
|| !"0000-00-00".equals(stringValue)
|
||||
&& !"0000-00-00 00:00:00".equals(stringValue)
|
||||
&& !"00000000000000".equals(stringValue)
|
||||
&& !"0".equals(stringValue)
|
||||
&& !"00000000".equals(stringValue)
|
||||
&& !"0000".equals(stringValue);
|
||||
return new String(dataValue.getBytes());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueStrByType(JDBCDataValue dataValue) {
|
||||
return getJdbcValue(dataValue);
|
||||
return new String(dataValue.getBytes());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user