mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
(feature)(chat) If the unit is set to less than 0, then do not add relative date (#249)
This commit is contained in:
@@ -73,9 +73,11 @@ public class WhereCorrector extends BaseSemanticCorrector {
|
|||||||
List<String> whereFields = SqlParserSelectHelper.getWhereFields(sql);
|
List<String> whereFields = SqlParserSelectHelper.getWhereFields(sql);
|
||||||
if (CollectionUtils.isEmpty(whereFields) || !whereFields.contains(DateUtils.DATE_FIELD)) {
|
if (CollectionUtils.isEmpty(whereFields) || !whereFields.contains(DateUtils.DATE_FIELD)) {
|
||||||
String currentDate = DSLDateHelper.getReferenceDate(semanticCorrectInfo.getParseInfo().getModelId());
|
String currentDate = DSLDateHelper.getReferenceDate(semanticCorrectInfo.getParseInfo().getModelId());
|
||||||
|
if (StringUtils.isNotBlank(currentDate)) {
|
||||||
sql = SqlParserAddHelper.addParenthesisToWhere(sql);
|
sql = SqlParserAddHelper.addParenthesisToWhere(sql);
|
||||||
sql = SqlParserAddHelper.addWhere(sql, DateUtils.DATE_FIELD, currentDate);
|
sql = SqlParserAddHelper.addWhere(sql, DateUtils.DATE_FIELD, currentDate);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
semanticCorrectInfo.setSql(sql);
|
semanticCorrectInfo.setSql(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,39 +10,35 @@ import com.tencent.supersonic.common.util.DateUtils;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
public class DSLDateHelper {
|
public class DSLDateHelper {
|
||||||
|
|
||||||
public static String getReferenceDate(Long modelId) {
|
public static String getReferenceDate(Long modelId) {
|
||||||
String chatDetailDate = getChatDetailDate(modelId);
|
String defaultDate = DateUtils.getBeforeDate(0);
|
||||||
if (StringUtils.isNotBlank(chatDetailDate)) {
|
|
||||||
return chatDetailDate;
|
|
||||||
}
|
|
||||||
return DateUtils.getBeforeDate(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getChatDetailDate(Long modelId) {
|
|
||||||
if (Objects.isNull(modelId)) {
|
if (Objects.isNull(modelId)) {
|
||||||
return null;
|
return defaultDate;
|
||||||
}
|
}
|
||||||
ChatConfigFilter filter = new ChatConfigFilter();
|
ChatConfigFilter filter = new ChatConfigFilter();
|
||||||
filter.setModelId(modelId);
|
filter.setModelId(modelId);
|
||||||
|
|
||||||
List<ChatConfigResp> configResps = ContextUtils.getBean(ConfigService.class).search(filter, null);
|
List<ChatConfigResp> configResps = ContextUtils.getBean(ConfigService.class).search(filter, null);
|
||||||
if (CollectionUtils.isEmpty(configResps)) {
|
if (CollectionUtils.isEmpty(configResps)) {
|
||||||
return null;
|
return defaultDate;
|
||||||
}
|
}
|
||||||
ChatConfigResp chatConfigResp = configResps.get(0);
|
ChatConfigResp chatConfigResp = configResps.get(0);
|
||||||
if (Objects.isNull(chatConfigResp.getChatDetailConfig()) || Objects.isNull(
|
if (Objects.isNull(chatConfigResp.getChatDetailConfig()) || Objects.isNull(
|
||||||
chatConfigResp.getChatDetailConfig().getChatDefaultConfig())) {
|
chatConfigResp.getChatDetailConfig().getChatDefaultConfig())) {
|
||||||
return null;
|
return defaultDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatDefaultConfigReq chatDefaultConfig = chatConfigResp.getChatDetailConfig().getChatDefaultConfig();
|
ChatDefaultConfigReq chatDefaultConfig = chatConfigResp.getChatDetailConfig().getChatDefaultConfig();
|
||||||
Integer unit = chatDefaultConfig.getUnit();
|
Integer unit = chatDefaultConfig.getUnit();
|
||||||
String period = chatDefaultConfig.getPeriod();
|
String period = chatDefaultConfig.getPeriod();
|
||||||
if (Objects.nonNull(unit)) {
|
if (Objects.nonNull(unit)) {
|
||||||
|
// If the unit is set to less than 0, then do not add relative date.
|
||||||
|
if (unit < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
DatePeriodEnum datePeriodEnum = DatePeriodEnum.get(period);
|
DatePeriodEnum datePeriodEnum = DatePeriodEnum.get(period);
|
||||||
if (Objects.isNull(datePeriodEnum)) {
|
if (Objects.isNull(datePeriodEnum)) {
|
||||||
return DateUtils.getBeforeDate(unit);
|
return DateUtils.getBeforeDate(unit);
|
||||||
@@ -50,6 +46,7 @@ public class DSLDateHelper {
|
|||||||
return DateUtils.getBeforeDate(unit, datePeriodEnum);
|
return DateUtils.getBeforeDate(unit, datePeriodEnum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return defaultDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user