fix(文档拆分): 动态字段多日期范围查询完善
This commit is contained in:
+7
-3
@@ -25,13 +25,17 @@ public class DocumentSplitCommon {
|
||||
*/
|
||||
public static final String DATE_FORMAT_END = " , '%Y-%m-%d') ";
|
||||
/**
|
||||
* 模糊匹配
|
||||
* between
|
||||
*/
|
||||
public static final String CONCAT_LIKE_BEGIN = " concat('%', ' ";
|
||||
public static final String BETWEEN = "between ";
|
||||
/**
|
||||
* 模糊匹配
|
||||
*/
|
||||
public static final String CONCAT_LIKE_END = " ', '%') ";
|
||||
public static final String CONCAT_LIKE_BEGIN = " concat('%', '";
|
||||
/**
|
||||
* 模糊匹配
|
||||
*/
|
||||
public static final String CONCAT_LIKE_END = "', '%') ";
|
||||
/**
|
||||
* and
|
||||
*/
|
||||
|
||||
+18
-15
@@ -21,27 +21,30 @@ public class DateManyConditionImpl extends AbstractConditionBase {
|
||||
public String buildCondition(String fieldName, String value){
|
||||
// 多日期查询
|
||||
String substringBegin = "SUBSTRING_INDEX(";
|
||||
String substringEnd = ", ',', 1)";
|
||||
String substringEndFirst = ", ',', 1)";
|
||||
String substringEndLast = ", ',', -1)";
|
||||
String dateMany = DocumentSplitCommon.AND;
|
||||
if (value.contains(",")) {
|
||||
// 范围查询
|
||||
String[] split = value.split(",");
|
||||
dateMany += "((";
|
||||
dateMany += "(";
|
||||
String startDate = DocumentSplitCommon.DATE_FORMAT_BEGIN + "'" + split[0] + "'" + DocumentSplitCommon.DATE_FORMAT_END;
|
||||
String endDate = DocumentSplitCommon.DATE_FORMAT_BEGIN + "'" + split[1] + "'" + DocumentSplitCommon.DATE_FORMAT_END;
|
||||
dateMany +=
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEnd + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.GT + startDate +
|
||||
DocumentSplitCommon.AND +
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEnd + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.LT + endDate + ")" +
|
||||
DocumentSplitCommon.OR + "(" +
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEnd + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.GT + startDate +
|
||||
DocumentSplitCommon.AND +
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEnd + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.LT + endDate + ")" +
|
||||
DocumentSplitCommon.OR + "(" +
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + ", ',', -1)" + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.GT + startDate +
|
||||
DocumentSplitCommon.AND +
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + ", ',', -1)" + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.LT + endDate + "))";
|
||||
|
||||
dateMany += "(" +
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEndFirst + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.BETWEEN + startDate + DocumentSplitCommon.AND + endDate +
|
||||
")" +
|
||||
DocumentSplitCommon.OR +
|
||||
"(" +
|
||||
DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEndLast + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.BETWEEN + startDate + DocumentSplitCommon.AND + endDate +
|
||||
")" +
|
||||
DocumentSplitCommon.OR +
|
||||
"(" +
|
||||
startDate + DocumentSplitCommon.BETWEEN + DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEndFirst + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.AND + DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEndLast + DocumentSplitCommon.DATE_FORMAT_END +
|
||||
")" +
|
||||
DocumentSplitCommon.OR +
|
||||
"(" +
|
||||
endDate + DocumentSplitCommon.BETWEEN + DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEndFirst + DocumentSplitCommon.DATE_FORMAT_END + DocumentSplitCommon.AND + DocumentSplitCommon.DATE_FORMAT_BEGIN + substringBegin + fieldName + substringEndLast + DocumentSplitCommon.DATE_FORMAT_END +
|
||||
")" + ")";
|
||||
} else {
|
||||
dateMany += fieldName + DocumentSplitCommon.LIKE + DocumentSplitCommon.CONCAT_LIKE_BEGIN + value + DocumentSplitCommon.CONCAT_LIKE_END;
|
||||
}
|
||||
|
||||
+2
-2
@@ -960,7 +960,7 @@ public class DocumentSplitServiceImpl implements IDocumentSplitService {
|
||||
Optional<LawsTag> lawsTag = fieldListCondition.stream().filter(o -> k.equals(o.getDbFieldName())).findFirst();
|
||||
lawsTag.ifPresent(l -> {
|
||||
// 构建查询条件 (工厂 + 策略 设计模式)
|
||||
String sqlCondition = ConditionMapFactory.getInvokeStrategy(l.getDbFieldName()).buildCondition(l.getDbFieldName(), (String) v);
|
||||
String sqlCondition = ConditionMapFactory.getInvokeStrategy(l.getFieldShowType()).buildCondition(l.getDbFieldName(), (String) v);
|
||||
selectCondition.append(sqlCondition);
|
||||
});
|
||||
});
|
||||
@@ -1035,7 +1035,7 @@ public class DocumentSplitServiceImpl implements IDocumentSplitService {
|
||||
// 拆分状态
|
||||
queryWrapper.eq(StringUtils.isNotBlank(documentSplitInfo.getSplitStatus()), "split_status", documentSplitInfo.getSplitStatus());
|
||||
// 编辑人
|
||||
queryWrapper.eq(StringUtils.isNotBlank(documentSplitInfo.getAuthor()), "username", documentSplitInfo.getAuthor());
|
||||
queryWrapper.like(StringUtils.isNotBlank(documentSplitInfo.getAuthor()), "username", documentSplitInfo.getAuthor());
|
||||
// 发布前id
|
||||
if (StringUtils.isNotBlank(documentSplitInfo.getPublishBeforeId())){
|
||||
queryWrapper.eq("publish_before_id", documentSplitInfo.getPublishBeforeId());
|
||||
|
||||
Reference in New Issue
Block a user