fix(exportTemplate): 添加IN和NOT IN操作符并修复参数解析问题
在导出模板功能中添加IN和NOT IN操作符,以支持更复杂的查询条件。同时修复了参数解析逻辑,确保从params参数中正确提取过滤条件、分页和排序等参数,避免直接使用values导致的解析错误。
This commit is contained in:
@@ -128,6 +128,11 @@ func (sysExportTemplateService *SysExportTemplateService) GetSysExportTemplateIn
|
|||||||
// ExportExcel 导出Excel
|
// ExportExcel 导出Excel
|
||||||
// Author [piexlmax](https://github.com/piexlmax)
|
// Author [piexlmax](https://github.com/piexlmax)
|
||||||
func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID string, values url.Values) (file *bytes.Buffer, name string, err error) {
|
func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID string, values url.Values) (file *bytes.Buffer, name string, err error) {
|
||||||
|
var params = values.Get("params")
|
||||||
|
paramsValues, err := url.ParseQuery(params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", fmt.Errorf("解析 params 参数失败: %v", err)
|
||||||
|
}
|
||||||
var template system.SysExportTemplate
|
var template system.SysExportTemplate
|
||||||
err = global.GVA_DB.Preload("Conditions").Preload("JoinTemplate").First(&template, "template_id = ?", templateID).Error
|
err = global.GVA_DB.Preload("Conditions").Preload("JoinTemplate").First(&template, "template_id = ?", templateID).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -178,7 +183,7 @@ func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID
|
|||||||
|
|
||||||
filterDeleted := false
|
filterDeleted := false
|
||||||
|
|
||||||
filterParam := values.Get("filterDeleted")
|
filterParam := paramsValues.Get("filterDeleted")
|
||||||
if filterParam == "true" {
|
if filterParam == "true" {
|
||||||
filterDeleted = true
|
filterDeleted = true
|
||||||
}
|
}
|
||||||
@@ -202,7 +207,7 @@ func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID
|
|||||||
if len(template.Conditions) > 0 {
|
if len(template.Conditions) > 0 {
|
||||||
for _, condition := range template.Conditions {
|
for _, condition := range template.Conditions {
|
||||||
sql := fmt.Sprintf("%s %s ?", condition.Column, condition.Operator)
|
sql := fmt.Sprintf("%s %s ?", condition.Column, condition.Operator)
|
||||||
value := values.Get(condition.From)
|
value := paramsValues.Get(condition.From)
|
||||||
if value != "" {
|
if value != "" {
|
||||||
if condition.Operator == "LIKE" {
|
if condition.Operator == "LIKE" {
|
||||||
value = "%" + value + "%"
|
value = "%" + value + "%"
|
||||||
@@ -212,7 +217,7 @@ func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 通过参数传入limit
|
// 通过参数传入limit
|
||||||
limit := values.Get("limit")
|
limit := paramsValues.Get("limit")
|
||||||
if limit != "" {
|
if limit != "" {
|
||||||
l, e := strconv.Atoi(limit)
|
l, e := strconv.Atoi(limit)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
@@ -225,7 +230,7 @@ func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 通过参数传入offset
|
// 通过参数传入offset
|
||||||
offset := values.Get("offset")
|
offset := paramsValues.Get("offset")
|
||||||
if offset != "" {
|
if offset != "" {
|
||||||
o, e := strconv.Atoi(offset)
|
o, e := strconv.Atoi(offset)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
@@ -248,7 +253,7 @@ func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 通过参数传入order
|
// 通过参数传入order
|
||||||
order := values.Get("order")
|
order := paramsValues.Get("order")
|
||||||
|
|
||||||
if order == "" && template.Order != "" {
|
if order == "" && template.Order != "" {
|
||||||
// 如果没有order入参,这里会使用模板的默认排序
|
// 如果没有order入参,这里会使用模板的默认排序
|
||||||
|
@@ -509,7 +509,15 @@ JOINS模式下不支持导入
|
|||||||
{
|
{
|
||||||
label: 'NOT BETWEEN',
|
label: 'NOT BETWEEN',
|
||||||
value: 'NOT BETWEEN'
|
value: 'NOT BETWEEN'
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
label: 'IN',
|
||||||
|
value: 'IN'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'NOT IN',
|
||||||
|
value: 'NOT IN'
|
||||||
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const addCondition = () => {
|
const addCondition = () => {
|
||||||
|
Reference in New Issue
Block a user