fix: 修复年份过滤不生效的问题

This commit is contained in:
junjun 2023-07-31 11:29:31 +08:00
parent c2ad53c04a
commit 5f5f676a5c

View File

@ -1065,10 +1065,15 @@ public class MysqlQueryProvider extends QueryProvider {
if (field.getDeType() == 1) { if (field.getDeType() == 1) {
String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); String format = transDateFormat(request.getDateStyle(), request.getDatePattern());
if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5 || field.getDeExtractType() == 1) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5 || field.getDeExtractType() == 1) {
String date = String.format(MySQLConstants.DATE_FORMAT, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : MysqlConstants.DEFAULT_DATE_FORMAT); String date;
if(request.getOperator().equals("between")){ if (field.getType().equalsIgnoreCase("YEAR")) {
date = String.format(MySQLConstants.DATE_FORMAT, "CONCAT(" + originName + ",'-01-01')", StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : MysqlConstants.DEFAULT_DATE_FORMAT);
} else {
date = String.format(MySQLConstants.DATE_FORMAT, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : MysqlConstants.DEFAULT_DATE_FORMAT);
}
if (request.getOperator().equals("between")) {
whereName = date; whereName = date;
}else { } else {
if (StringUtils.equalsIgnoreCase(request.getDateStyle(), "y_Q")) { if (StringUtils.equalsIgnoreCase(request.getDateStyle(), "y_Q")) {
whereName = String.format(format, whereName = String.format(format,
String.format(MysqlConstants.DATE_FORMAT, originName, "%Y"), String.format(MysqlConstants.DATE_FORMAT, originName, "%Y"),
@ -1080,11 +1085,11 @@ public class MysqlQueryProvider extends QueryProvider {
} }
if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
if(request.getOperator().equals("between")){ if (request.getOperator().equals("between")) {
whereName = originName; whereName = originName;
}else { } else {
String cast = String.format(MySQLConstants.CAST, originName, MySQLConstants.DEFAULT_INT_FORMAT) + "/1000"; String cast = String.format(MySQLConstants.CAST, originName, MySQLConstants.DEFAULT_INT_FORMAT) + "/1000";
if (StringUtils.equalsIgnoreCase(request.getDateStyle(),"y_Q")){ if (StringUtils.equalsIgnoreCase(request.getDateStyle(), "y_Q")) {
whereName = String.format(format, whereName = String.format(format,
String.format(MysqlConstants.DATE_FORMAT, cast, "%Y"), String.format(MysqlConstants.DATE_FORMAT, cast, "%Y"),
String.format(MysqlConstants.QUARTER, String.format(MysqlConstants.DATE_FORMAT, field, MysqlConstants.DEFAULT_DATE_FORMAT))); String.format(MysqlConstants.QUARTER, String.format(MysqlConstants.DATE_FORMAT, field, MysqlConstants.DEFAULT_DATE_FORMAT)));