Skip to content

Commit 0e93e57

Browse files
author
piexlMax(奇淼
committed
feat: 添加软删除过滤
1 parent 278cce5 commit 0e93e57

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

Diff for: server/resource/package/web/view/table.vue.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ getDataSourceFunc()
138138
<el-button {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.batchDelete"{{ end }} icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="onDelete">删除</el-button>
139139
{{ if .HasExcel -}}
140140
<ExportTemplate {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportTemplate"{{ end }} template-id="{{$templateID}}" />
141-
<ExportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportExcel"{{ end }} template-id="{{$templateID}}" />
141+
<ExportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportExcel"{{ end }} template-id="{{$templateID}}" filterDeleted/>
142142
<ImportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.importExcel"{{ end }} template-id="{{$templateID}}" @on-success="getTableData" />
143143
{{- end }}
144144
</div>

Diff for: server/resource/plugin/web/view/view.vue.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ getDataSourceFunc()
136136
<el-button {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.batchDelete"{{ end }} icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="onDelete">删除</el-button>
137137
{{ if .HasExcel -}}
138138
<ExportTemplate {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportTemplate"{{ end }} template-id="{{$templateID}}" />
139-
<ExportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportExcel"{{ end }} template-id="{{$templateID}}" />
139+
<ExportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportExcel"{{ end }} template-id="{{$templateID}}" filterDeleted/>
140140
<ImportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.importExcel"{{ end }} template-id="{{$templateID}}" @on-success="getTableData" />
141141
{{- end }}
142142
</div>

Diff for: server/service/system/sys_export_template.go

+30
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,29 @@ func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID
175175

176176
db = db.Select(selects).Table(template.TableName)
177177

178+
filterDeleted := false
179+
180+
filterParam := values.Get("filterDeleted")
181+
if filterParam == "true" {
182+
filterDeleted = true
183+
}
184+
185+
if filterDeleted {
186+
// 自动过滤主表的软删除
187+
db = db.Where(fmt.Sprintf("%s.deleted_at IS NULL", template.TableName))
188+
189+
// 过滤关联表的软删除(如果有)
190+
if len(template.JoinTemplate) > 0 {
191+
for _, join := range template.JoinTemplate {
192+
// 检查关联表是否有deleted_at字段
193+
hasDeletedAt := sysExportTemplateService.hasDeletedAtColumn(join.Table)
194+
if hasDeletedAt {
195+
db = db.Where(fmt.Sprintf("%s.deleted_at IS NULL", join.Table))
196+
}
197+
}
198+
}
199+
}
200+
178201
if len(template.Conditions) > 0 {
179202
for _, condition := range template.Conditions {
180203
sql := fmt.Sprintf("%s %s ?", condition.Column, condition.Operator)
@@ -344,6 +367,13 @@ func (sysExportTemplateService *SysExportTemplateService) ExportTemplate(templat
344367
return file, template.Name, nil
345368
}
346369

370+
// 辅助函数:检查表是否有deleted_at列
371+
func (s *SysExportTemplateService) hasDeletedAtColumn(tableName string) bool {
372+
var count int64
373+
global.GVA_DB.Raw("SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME = 'deleted_at'", tableName).Count(&count)
374+
return count > 0
375+
}
376+
347377
// ImportExcel 导入Excel
348378
// Author [piexlmax](https://github.com/piexlmax)
349379
func (sysExportTemplateService *SysExportTemplateService) ImportExcel(templateID string, file *multipart.FileHeader) (err error) {

Diff for: web/src/components/exportExcel/exportExcel.vue

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import { exportExcel } from '@/api/exportTemplate'
1010
1111
const props = defineProps({
12+
filterDeleted: {
13+
type: Boolean,
14+
default: true
15+
},
1216
templateId: {
1317
type: String,
1418
required: true
@@ -43,6 +47,11 @@ import { exportExcel } from '@/api/exportTemplate'
4347
baseUrl = ""
4448
}
4549
const paramsCopy = JSON.parse(JSON.stringify(props.condition))
50+
51+
if (props.filterDeleted) {
52+
paramsCopy.filterDeleted = 'true'
53+
}
54+
4655
if (props.limit) {
4756
paramsCopy.limit = props.limit
4857
}

0 commit comments

Comments
 (0)