代码生成:批量删除

This commit is contained in:
xiangheng
2024-09-12 13:43:18 +08:00
parent 79fb646900
commit 537efc0e50
13 changed files with 360 additions and 203 deletions

View File

@@ -36,11 +36,17 @@ export type type_user_protocol_edit = {
// 用户协议列表 // 用户协议列表
export function user_protocol_list(params?: type_user_protocol_query) { export function user_protocol_list(params?: type_user_protocol_query) {
return request.get<Pages<type_user_protocol>>({ url: '/user_protocol/list', params: clearEmpty(params) }) return request.get<Pages<type_user_protocol>>({
url: '/user_protocol/list',
params: clearEmpty(params)
})
} }
// 用户协议列表-所有 // 用户协议列表-所有
export function user_protocol_list_all(params?: type_user_protocol_query) { export function user_protocol_list_all(params?: type_user_protocol_query) {
return request.get<type_user_protocol[]>({ url: '/user_protocol/listAll', params: clearEmpty(params) }) return request.get<type_user_protocol[]>({
url: '/user_protocol/listAll',
params: clearEmpty(params)
})
} }
// 用户协议详情 // 用户协议详情
@@ -62,11 +68,17 @@ export function user_protocol_edit(data: type_user_protocol_edit) {
export function user_protocol_delete(Id: number | string) { export function user_protocol_delete(Id: number | string) {
return request.post<null>({ url: '/user_protocol/del', data: { Id } }) return request.post<null>({ url: '/user_protocol/del', data: { Id } })
} }
// 用户协议批量删除
export function user_protocol_delete_batch(data: { Ids: string }) {
return request.post<null>({ url: '/user_protocol/delBatch', data })
}
// 用户协议导入 // 用户协议导入
export const user_protocol_import_file = '/user_protocol/ImportFile' export const user_protocol_import_file = '/user_protocol/ImportFile'
// 用户协议导出 // 用户协议导出
export function user_protocol_export_file(params: any) { export function user_protocol_export_file(params: any) {
return (window.location.href =`${config.baseUrl}${config.urlPrefix}/user_protocol/ExportFile?token=${getToken()}&` + queryString.stringify(clearEmpty(params))) return (window.location.href =
`${config.baseUrl}${config.urlPrefix}/user_protocol/ExportFile?token=${getToken()}&` +
queryString.stringify(clearEmpty(params)))
} }

View File

@@ -1,10 +1,16 @@
<template> <template>
<div class="index-lists"> <div class="index-lists">
<el-card class="!border-none" shadow="never"> <el-card class="!border-none" shadow="never">
<el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true" label-width="70px" <el-form
label-position="left"> ref="formRef"
class="mb-[-16px]"
:model="queryParams"
:inline="true"
label-width="70px"
label-position="left"
>
<el-form-item label="标题" prop="Title" class="w-[280px]"> <el-form-item label="标题" prop="Title" class="w-[280px]">
<el-input v-model="queryParams.Title" /> <el-input v-model="queryParams.Title" />
</el-form-item> </el-form-item>
<el-form-item label="创建时间" prop="CreateTime" class="w-[280px]"> <el-form-item label="创建时间" prop="CreateTime" class="w-[280px]">
<daterange-picker <daterange-picker
@@ -26,13 +32,17 @@
</el-card> </el-card>
<el-card class="!border-none mt-4" shadow="never"> <el-card class="!border-none mt-4" shadow="never">
<div> <div>
<el-button v-perms="['admin:user_protocol:add']" type="primary" @click="handleAdd()"> <el-button
v-perms="['admin:user_protocol:add']"
type="primary"
@click="handleAdd()"
>
<template #icon> <template #icon>
<icon name="el-icon-Plus" /> <icon name="el-icon-Plus" />
</template> </template>
新增 新增
</el-button> </el-button>
<upload <upload
class="ml-3 mr-3" class="ml-3 mr-3"
:url="user_protocol_import_file" :url="user_protocol_import_file"
:data="{ cid: 0 }" :data="{ cid: 0 }"
@@ -53,13 +63,23 @@
</template> </template>
导出 导出
</el-button> </el-button>
<el-button
v-perms="['admin:user_protocol:delBatch']"
type="danger"
@click="deleteBatch"
>
批量删除
</el-button>
</div> </div>
<el-table <el-table
class="mt-4" class="mt-4"
size="large" size="large"
v-loading="pager.loading" v-loading="pager.loading"
:data="pager.lists" :data="pager.lists"
@selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55" />
<el-table-column label="标题" prop="Title" min-width="130" /> <el-table-column label="标题" prop="Title" min-width="130" />
<el-table-column label="协议内容" prop="Content" min-width="130" /> <el-table-column label="协议内容" prop="Content" min-width="130" />
<el-table-column label="排序" prop="Sort" min-width="130" /> <el-table-column label="排序" prop="Sort" min-width="130" />
@@ -90,27 +110,27 @@
<pagination v-model="pager" @change="getLists" /> <pagination v-model="pager" @change="getLists" />
</div> </div>
</el-card> </el-card>
<edit-popup <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
v-if="showEdit"
ref="editRef"
@success="getLists"
@close="showEdit = false"
/>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { user_protocol_delete, user_protocol_list,user_protocol_import_file, user_protocol_export_file } from '@/api/user/protocol' import {
import type { type_user_protocol,type_user_protocol_query } from "@/api/user/protocol"; user_protocol_delete,
user_protocol_delete_batch,
user_protocol_list,
user_protocol_import_file,
user_protocol_export_file
} from '@/api/user/protocol'
import type { type_user_protocol, type_user_protocol_query } from '@/api/user/protocol'
import { useDictData, useListAllData } from '@/hooks/useDictOptions'
import { useDictData,useListAllData } from '@/hooks/useDictOptions'
import type { type_dict } from '@/hooks/useDictOptions' import type { type_dict } from '@/hooks/useDictOptions'
import { usePaging } from '@/hooks/usePaging' import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback' import feedback from '@/utils/feedback'
import EditPopup from './edit.vue' import EditPopup from './edit.vue'
defineOptions({ defineOptions({
name:"user_protocol" name: 'user_protocol'
}) })
const editRef = shallowRef<InstanceType<typeof EditPopup>>() const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false) const showEdit = ref(false)
@@ -121,7 +141,7 @@ const queryParams = reactive<type_user_protocol_query>({
CreateTimeStart: null, CreateTimeStart: null,
CreateTimeEnd: null, CreateTimeEnd: null,
UpdateTimeStart: null, UpdateTimeStart: null,
UpdateTimeEnd: null, UpdateTimeEnd: null
}) })
const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol>({ const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol>({
@@ -129,7 +149,6 @@ const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol
params: queryParams params: queryParams
}) })
const handleAdd = async () => { const handleAdd = async () => {
showEdit.value = true showEdit.value = true
await nextTick() await nextTick()
@@ -142,11 +161,30 @@ const handleEdit = async (data: any) => {
editRef.value?.open('edit') editRef.value?.open('edit')
editRef.value?.getDetail(data) editRef.value?.getDetail(data)
} }
const multipleSelection = ref<type_user_protocol[]>([])
const handleSelectionChange = (val: type_user_protocol[]) => {
console.log(val)
multipleSelection.value = val
}
const handleDelete = async (Id: number) => { const handleDelete = async (Id: number) => {
try { try {
await feedback.confirm('确定要删除?') await feedback.confirm('确定要删除?')
await user_protocol_delete( Id ) await user_protocol_delete(Id)
feedback.msgSuccess('删除成功')
getLists()
} catch (error) {}
}
// 批量删除
const deleteBatch = async () => {
if (multipleSelection.value.length === 0) {
feedback.msgError('请选择要删除的数据')
return
}
try {
await feedback.confirm('确定要删除?')
await user_protocol_delete_batch({
Ids: multipleSelection.value.map((item) => item.Id).join(',')
})
feedback.msgSuccess('删除成功') feedback.msgSuccess('删除成功')
getLists() getLists()
} catch (error) {} } catch (error) {}

View File

@@ -153,7 +153,26 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) Del(c *gin.Context) {
response.CheckAndResp(c, {{{ toUpperCamelCase .EntityName }}}Service.Del(delReq.{{{ toUpperCamelCase .PrimaryKey }}})) response.CheckAndResp(c, {{{ toUpperCamelCase .EntityName }}}Service.Del(delReq.{{{ toUpperCamelCase .PrimaryKey }}}))
} }
// @Summary {{{ .FunctionName }}}删除-批量
// @Tags {{{ .ModuleName }}}-{{{ .FunctionName }}}
// @Produce json
// @Param Token header string true "token"
// @Param Ids body string false "逗号分割的id"
// @Success 200 {object} response.Response "成功"
// @Router /api/admin/{{{ .ModuleName }}}/delBatch [post]
func (hd *UserProtocolHandler) DelBatch(c *gin.Context) {
var delReq {{{ toUpperCamelCase .EntityName }}}DelBatchReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
return
}
if delReq.Ids == "" {
response.FailWithMsg(c, response.SystemError, "请选择要删除的数据")
return
}
var Ids = strings.Split(delReq.Ids, ",")
response.CheckAndResp(c, {{{ toUpperCamelCase .EntityName }}}Service.DelBatch(Ids))
}

View File

@@ -19,6 +19,7 @@ import (
admin:{{{ .ModuleName }}}:add admin:{{{ .ModuleName }}}:add
admin:{{{.ModuleName }}}:edit admin:{{{.ModuleName }}}:edit
admin:{{{.ModuleName }}}:del admin:{{{.ModuleName }}}:del
admin:{{{.ModuleName }}}:delBatch
admin:{{{.ModuleName }}}:list admin:{{{.ModuleName }}}:list
admin:{{{.ModuleName }}}:listAll admin:{{{.ModuleName }}}:listAll
admin:{{{.ModuleName }}}:detail admin:{{{.ModuleName }}}:detail
@@ -32,6 +33,7 @@ INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, paths, component, is
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}添加','admin:{{{ .ModuleName }}}:add', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}添加','admin:{{{ .ModuleName }}}:add', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}编辑','admin:{{{ .ModuleName }}}:edit', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}编辑','admin:{{{ .ModuleName }}}:edit', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除','admin:{{{ .ModuleName }}}:del', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除','admin:{{{ .ModuleName }}}:del', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除-批量','admin:{{{ .ModuleName }}}:delBatch', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}列表','admin:{{{ .ModuleName }}}:list', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}列表','admin:{{{ .ModuleName }}}:list', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}全部列表','admin:{{{ .ModuleName }}}:listAll', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}全部列表','admin:{{{ .ModuleName }}}:listAll', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}详情','admin:{{{ .ModuleName }}}:detail', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}详情','admin:{{{ .ModuleName }}}:detail', 0, 1, 0, now(), now());
@@ -48,9 +50,13 @@ func {{{ toUpperCamelCase .ModuleName }}}Route(rg *gin.RouterGroup) {
r.GET("/{{{ .ModuleName }}}/list", handle.List) r.GET("/{{{ .ModuleName }}}/list", handle.List)
r.GET("/{{{ .ModuleName }}}/listAll", handle.ListAll) r.GET("/{{{ .ModuleName }}}/listAll", handle.ListAll)
r.GET("/{{{ .ModuleName }}}/detail", handle.Detail) r.GET("/{{{ .ModuleName }}}/detail", handle.Detail)
r.POST("/{{{ .ModuleName }}}/add",middleware.RecordLog("{{{ .FunctionName }}}新增"), handle.Add) r.POST("/{{{ .ModuleName }}}/add",middleware.RecordLog("{{{ .FunctionName }}}新增"), handle.Add)
r.POST("/{{{ .ModuleName }}}/edit",middleware.RecordLog("{{{ .FunctionName }}}编辑"), handle.Edit) r.POST("/{{{ .ModuleName }}}/edit",middleware.RecordLog("{{{ .FunctionName }}}编辑"), handle.Edit)
r.POST("/{{{ .ModuleName }}}/del", middleware.RecordLog("{{{ .FunctionName }}}删除"), handle.Del) r.POST("/{{{ .ModuleName }}}/del", middleware.RecordLog("{{{ .FunctionName }}}删除"), handle.Del)
r.POST("/{{{ .ModuleName }}}/delBatch", middleware.RecordLog("{{{ .FunctionName }}}删除-批量"), handle.DelBatch)
r.GET("/{{{ .ModuleName }}}/ExportFile", middleware.RecordLog("{{{ .FunctionName }}}导出"), handle.ExportFile) r.GET("/{{{ .ModuleName }}}/ExportFile", middleware.RecordLog("{{{ .FunctionName }}}导出"), handle.ExportFile)
r.POST("/{{{ .ModuleName }}}/ImportFile", handle.ImportFile) r.POST("/{{{ .ModuleName }}}/ImportFile", handle.ImportFile)
} }

View File

@@ -9,10 +9,10 @@ type {{{ toUpperCamelCase .EntityName }}}ListReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsQuery }}} {{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}} {{{- if eq .HtmlType "datetime" }}}
{{{ toUpperCamelCase .GoField }}}Start *string `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}}Start *string // {{{ .ColumnComment }}}
{{{ toUpperCamelCase .GoField }}}End *string `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}}End *string // {{{ .ColumnComment }}}
{{{- else }}} {{{- else }}}
{{{ toUpperCamelCase .GoField }}} *{{{.GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} *{{{.GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
@@ -24,7 +24,7 @@ type {{{ toUpperCamelCase .EntityName }}}ListReq struct {
type {{{ toUpperCamelCase .EntityName }}}AddReq struct { type {{{ toUpperCamelCase .EntityName }}}AddReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsInsert }}} {{{- if .IsInsert }}}
{{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
} }
@@ -34,9 +34,9 @@ type {{{ toUpperCamelCase .EntityName }}}EditReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsEdit }}} {{{- if .IsEdit }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} // {{{ .ColumnComment }}}
{{{- else }}} {{{- else }}}
{{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
@@ -46,7 +46,7 @@ type {{{ toUpperCamelCase .EntityName }}}EditReq struct {
type {{{ toUpperCamelCase .EntityName }}}DetailReq struct { type {{{ toUpperCamelCase .EntityName }}}DetailReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
} }
@@ -55,19 +55,24 @@ type {{{ toUpperCamelCase .EntityName }}}DetailReq struct {
type {{{ toUpperCamelCase .EntityName }}}DelReq struct { type {{{ toUpperCamelCase .EntityName }}}DelReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
} }
//{{{ toUpperCamelCase .EntityName }}}DelReq {{{ .FunctionName }}}批量删除参数
type {{{ toUpperCamelCase .EntityName }}}DelBatchReq struct {
Ids string
}
//{{{ toUpperCamelCase .EntityName }}}Resp {{{ .FunctionName }}}返回信息 //{{{ toUpperCamelCase .EntityName }}}Resp {{{ .FunctionName }}}返回信息
type {{{ toUpperCamelCase .EntityName }}}Resp struct { type {{{ toUpperCamelCase .EntityName }}}Resp struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if or .IsList .IsPk }}} {{{- if or .IsList .IsPk }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} // {{{ .ColumnComment }}}
{{{- else }}} {{{- else }}}
{{{ toUpperCamelCase .GoField }}} {{{goWithRespType .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{goWithRespType .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}

View File

@@ -179,9 +179,9 @@ func (service {{{ toCamelCase .EntityName }}}Service) Del({{{ toUpperCamelCase .
// //
{{{- if contains .AllFields "is_delete" }}} {{{- if contains .AllFields "is_delete" }}}
obj.IsDelete = 1 obj.IsDelete = 1
{{{- if contains .AllFields "delete_time" }}} {{{- if contains .AllFields "delete_time" }}}
obj.DeleteTime = util.NullTimeUtil.Now() obj.DeleteTime = util.NullTimeUtil.Now()
{{{- end }}} {{{- end }}}
err = service.db.Save(&obj).Error err = service.db.Save(&obj).Error
e = response.CheckErr(err, "删除失败") e = response.CheckErr(err, "删除失败")
{{{- else }}} {{{- else }}}
@@ -192,6 +192,13 @@ func (service {{{ toCamelCase .EntityName }}}Service) Del({{{ toUpperCamelCase .
return return
} }
// DelBatch 用户协议-批量删除
func (service {{{ toCamelCase .EntityName }}}Service) DelBatch(Ids []string) (e error) {
var obj model.{{{ toUpperCamelCase .EntityName }}}
err := service.db.Where("{{{ $.PrimaryKey }}} in (?)", Ids).Delete(&obj).Error
return err
}
// 获取Excel的列 // 获取Excel的列
func (service {{{ toCamelCase .EntityName }}}Service) GetExcelCol() []excel2.Col { func (service {{{ toCamelCase .EntityName }}}Service) GetExcelCol() []excel2.Col {
var cols = []excel2.Col{ var cols = []excel2.Col{

View File

@@ -61,6 +61,10 @@ export function {{{.ModuleName}}}_edit(data: type_{{{.ModuleName}}}_edit) {
export function {{{.ModuleName}}}_delete({{{toUpperCamelCase .PrimaryKey }}}: number | string) { export function {{{.ModuleName}}}_delete({{{toUpperCamelCase .PrimaryKey }}}: number | string) {
return request.post<null>({ url: '/{{{.ModuleName}}}/del', data: { {{{toUpperCamelCase .PrimaryKey }}} } }) return request.post<null>({ url: '/{{{.ModuleName}}}/del', data: { {{{toUpperCamelCase .PrimaryKey }}} } })
} }
// {{{.FunctionName}}}删除-批量
export function {{{.ModuleName}}}_delete_batch(data: { Ids: string }) {
return request.post<null>({ url: '/{{{.ModuleName}}}/delBatch', data })
}
// {{{.FunctionName}}}导入 // {{{.FunctionName}}}导入
export const {{{.ModuleName}}}_import_file = '/{{{.ModuleName}}}/ImportFile' export const {{{.ModuleName}}}_import_file = '/{{{.ModuleName}}}/ImportFile'

View File

@@ -62,6 +62,7 @@
新增 新增
</el-button> </el-button>
<upload <upload
v-perms="['admin:{{{ .ModuleName }}}:ImportFile']"
class="ml-3 mr-3" class="ml-3 mr-3"
:url="{{{.ModuleName}}}_import_file" :url="{{{.ModuleName}}}_import_file"
:data="{ cid: 0 }" :data="{ cid: 0 }"
@@ -76,19 +77,28 @@
导入 导入
</el-button> </el-button>
</upload> </upload>
<el-button type="primary" @click="exportFile"> <el-button v-perms="['admin:{{{ .ModuleName }}}:ExportFile']" type="primary" @click="exportFile">
<template #icon> <template #icon>
<icon name="el-icon-Download" /> <icon name="el-icon-Download" />
</template> </template>
导出 导出
</el-button> </el-button>
<el-button
v-perms="['admin:{{{ .ModuleName }}}:delBatch']"
type="danger"
@click="deleteBatch"
>
批量删除
</el-button>
</div> </div>
<el-table <el-table
class="mt-4" class="mt-4"
size="large" size="large"
v-loading="pager.loading" v-loading="pager.loading"
:data="pager.lists" :data="pager.lists"
@selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55" />
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsList }}} {{{- if .IsList }}}
{{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}} {{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
@@ -162,7 +172,7 @@
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { {{{ .ModuleName }}}_delete, {{{ .ModuleName }}}_list,{{{.ModuleName}}}_import_file, {{{.ModuleName}}}_export_file } from '@/api/{{{nameToPath .ModuleName }}}' import { {{{ .ModuleName }}}_delete,{{{ .ModuleName }}}_delete_batch, {{{ .ModuleName }}}_list,{{{.ModuleName}}}_import_file, {{{.ModuleName}}}_export_file } from '@/api/{{{nameToPath .ModuleName }}}'
import type { type_{{{ .ModuleName }}},type_{{{.ModuleName}}}_query } from "@/api/{{{nameToPath .ModuleName }}}"; import type { type_{{{ .ModuleName }}},type_{{{.ModuleName}}}_query } from "@/api/{{{nameToPath .ModuleName }}}";
@@ -230,6 +240,11 @@ const handleEdit = async (data: any) => {
editRef.value?.open('edit') editRef.value?.open('edit')
editRef.value?.getDetail(data) editRef.value?.getDetail(data)
} }
const multipleSelection = ref<type_{{{ .ModuleName }}}[]>([])
const handleSelectionChange = (val: type_{{{ .ModuleName }}}[]) => {
console.log(val)
multipleSelection.value = val
}
const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => { const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => {
try { try {
@@ -239,6 +254,22 @@ const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => {
getLists() getLists()
} catch (error) {} } catch (error) {}
} }
// 批量删除
const deleteBatch = async () => {
if (multipleSelection.value.length === 0) {
feedback.msgError('请选择要删除的数据')
return
}
try {
await feedback.confirm('确定要删除?')
await {{{ .ModuleName }}}_delete_batch({
Ids: multipleSelection.value.map((item) => item.{{{toUpperCamelCase .PrimaryKey }}}).join(',')
})
feedback.msgSuccess('删除成功')
getLists()
} catch (error) {}
}
const exportFile = async () => { const exportFile = async () => {
try { try {
await feedback.confirm('确定要导出?') await feedback.confirm('确定要导出?')

View File

@@ -3,35 +3,37 @@ package user_protocol
import ( import (
"net/http" "net/http"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/gin-gonic/gin"
"x_admin/core/request" "x_admin/core/request"
"x_admin/core/response" "x_admin/core/response"
"x_admin/util" "x_admin/util"
"x_admin/util/excel2" "x_admin/util/excel2"
"github.com/gin-gonic/gin"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
) )
type UserProtocolHandler struct { type UserProtocolHandler struct {
requestGroup singleflight.Group requestGroup singleflight.Group
} }
// @Summary 用户协议列表 // @Summary 用户协议列表
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议
// @Produce json // @Produce json
// @Param Token header string true "token" // @Param Token header string true "token"
// @Param PageNo query int true "页码" // @Param PageNo query int true "页码"
// @Param PageSize query int true "每页数量" // @Param PageSize query int true "每页数量"
// @Param Title query string false "标题" // @Param Title query string false "标题"
// @Param Content query string false "协议内容" // @Param Content query string false "协议内容"
// @Param Sort query number false "排序" // @Param Sort query number false "排序"
// @Param CreateTimeStart query string false "创建时间" // @Param CreateTimeStart query string false "创建时间"
// @Param CreateTimeEnd query string false "创建时间" // @Param CreateTimeEnd query string false "创建时间"
// @Param UpdateTimeStart query string false "更新时间" // @Param UpdateTimeStart query string false "更新时间"
// @Param UpdateTimeEnd query string false "更新时间" // @Param UpdateTimeEnd query string false "更新时间"
//@Success 200 {object} response.Response{ data=response.PageResp{ lists=[]UserProtocolResp}} "成功" //
//@Router /api/admin/user_protocol/list [get] // @Success 200 {object} response.Response{ data=response.PageResp{ lists=[]UserProtocolResp}} "成功"
// @Router /api/admin/user_protocol/list [get]
func (hd *UserProtocolHandler) List(c *gin.Context) { func (hd *UserProtocolHandler) List(c *gin.Context) {
var page request.PageReq var page request.PageReq
var listReq UserProtocolListReq var listReq UserProtocolListReq
@@ -45,18 +47,18 @@ func (hd *UserProtocolHandler) List(c *gin.Context) {
response.CheckAndRespWithData(c, res, err) response.CheckAndRespWithData(c, res, err)
} }
// @Summary 用户协议列表-所有 // @Summary 用户协议列表-所有
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议
// @Produce json // @Produce json
// @Param Title query string false "标题" // @Param Title query string false "标题"
// @Param Content query string false "协议内容" // @Param Content query string false "协议内容"
// @Param Sort query number false "排序" // @Param Sort query number false "排序"
// @Param CreateTimeStart query string false "创建时间" // @Param CreateTimeStart query string false "创建时间"
// @Param CreateTimeEnd query string false "创建时间" // @Param CreateTimeEnd query string false "创建时间"
// @Param UpdateTimeStart query string false "更新时间" // @Param UpdateTimeStart query string false "更新时间"
// @Param UpdateTimeEnd query string false "更新时间" // @Param UpdateTimeEnd query string false "更新时间"
// @Success 200 {object} response.Response{ data=[]UserProtocolResp} "成功" // @Success 200 {object} response.Response{ data=[]UserProtocolResp} "成功"
// @Router /api/admin/user_protocol/listAll [get] // @Router /api/admin/user_protocol/listAll [get]
func (hd *UserProtocolHandler) ListAll(c *gin.Context) { func (hd *UserProtocolHandler) ListAll(c *gin.Context) {
var listReq UserProtocolListReq var listReq UserProtocolListReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
@@ -66,13 +68,13 @@ func (hd *UserProtocolHandler) ListAll(c *gin.Context) {
response.CheckAndRespWithData(c, res, err) response.CheckAndRespWithData(c, res, err)
} }
// @Summary 用户协议详情 // @Summary 用户协议详情
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议
// @Produce json // @Produce json
// @Param Token header string true "token" // @Param Token header string true "token"
// @Param Id query number false "" // @Param Id query number false ""
// @Success 200 {object} response.Response{ data=UserProtocolResp} "成功" // @Success 200 {object} response.Response{ data=UserProtocolResp} "成功"
// @Router /api/admin/user_protocol/detail [get] // @Router /api/admin/user_protocol/detail [get]
func (hd *UserProtocolHandler) Detail(c *gin.Context) { func (hd *UserProtocolHandler) Detail(c *gin.Context) {
var detailReq UserProtocolDetailReq var detailReq UserProtocolDetailReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
@@ -86,48 +88,49 @@ func (hd *UserProtocolHandler) Detail(c *gin.Context) {
response.CheckAndRespWithData(c, res, err) response.CheckAndRespWithData(c, res, err)
} }
// @Summary 用户协议新增
// @Summary 用户协议新增 // @Tags user_protocol-用户协议
// @Tags user_protocol-用户协议 // @Produce json
// @Produce json // @Param Token header string true "token"
// @Param Token header string true "token" // @Param Title body string false "标题"
// @Param Title body string false "标题" // @Param Content body string false "协议内容"
// @Param Content body string false "协议内容" // @Param Sort body number false "排序"
// @Param Sort body number false "排序" // @Success 200 {object} response.Response "成功"
// @Success 200 {object} response.Response "成功" // @Router /api/admin/user_protocol/add [post]
// @Router /api/admin/user_protocol/add [post]
func (hd *UserProtocolHandler) Add(c *gin.Context) { func (hd *UserProtocolHandler) Add(c *gin.Context) {
var addReq UserProtocolAddReq var addReq UserProtocolAddReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &addReq)) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &addReq)) {
return return
} }
createId, e := UserProtocolService.Add(addReq) createId, e := UserProtocolService.Add(addReq)
response.CheckAndRespWithData(c,createId, e) response.CheckAndRespWithData(c, createId, e)
} }
// @Summary 用户协议编辑
// @Tags user_protocol-用户协议 // @Summary 用户协议编辑
// @Produce json // @Tags user_protocol-用户协议
// @Param Token header string true "token" // @Produce json
// @Param Id body number false "" // @Param Token header string true "token"
// @Param Title body string false "标题" // @Param Id body number false ""
// @Param Content body string false "协议内容" // @Param Title body string false "标题"
// @Param Sort body number false "排序" // @Param Content body string false "协议内容"
// @Success 200 {object} response.Response "成功" // @Param Sort body number false "排序"
// @Router /api/admin/user_protocol/edit [post] // @Success 200 {object} response.Response "成功"
// @Router /api/admin/user_protocol/edit [post]
func (hd *UserProtocolHandler) Edit(c *gin.Context) { func (hd *UserProtocolHandler) Edit(c *gin.Context) {
var editReq UserProtocolEditReq var editReq UserProtocolEditReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &editReq)) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &editReq)) {
return return
} }
response.CheckAndRespWithData(c,editReq.Id, UserProtocolService.Edit(editReq)) response.CheckAndRespWithData(c, editReq.Id, UserProtocolService.Edit(editReq))
} }
// @Summary 用户协议删除
// @Tags user_protocol-用户协议 // @Summary 用户协议删除
// @Produce json // @Tags user_protocol-用户协议
// @Param Token header string true "token" // @Produce json
// @Param Id body number false "" // @Param Token header string true "token"
// @Success 200 {object} response.Response "成功" // @Param Id body number false ""
// @Router /api/admin/user_protocol/del [post] // @Success 200 {object} response.Response "成功"
// @Router /api/admin/user_protocol/del [post]
func (hd *UserProtocolHandler) Del(c *gin.Context) { func (hd *UserProtocolHandler) Del(c *gin.Context) {
var delReq UserProtocolDelReq var delReq UserProtocolDelReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
@@ -136,22 +139,41 @@ func (hd *UserProtocolHandler) Del(c *gin.Context) {
response.CheckAndResp(c, UserProtocolService.Del(delReq.Id)) response.CheckAndResp(c, UserProtocolService.Del(delReq.Id))
} }
// @Summary 用户协议批量删除
// @Tags user_protocol-用户协议
// @Produce json
// @Param Token header string true "token"
// @Param Ids body string false "逗号分割的id"
// @Success 200 {object} response.Response "成功"
// @Router /api/admin/user_protocol/delBatch [post]
func (hd *UserProtocolHandler) DelBatch(c *gin.Context) {
var delReq UserProtocolDelBatchReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
return
}
if delReq.Ids == "" {
response.FailWithMsg(c, response.SystemError, "请选择要删除的数据")
return
}
var Ids = strings.Split(delReq.Ids, ",")
// if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
// return
// }
response.CheckAndResp(c, UserProtocolService.DelBatch(Ids))
}
// @Summary 用户协议导出
// @Tags user_protocol-用户协议
// @Produce json
// @Summary 用户协议导出 // @Param Token header string true "token"
// @Tags user_protocol-用户协议 // @Param Title query string false "标题"
// @Produce json // @Param Content query string false "协议内容"
// @Param Token header string true "token" // @Param Sort query number false "排序"
// @Param Title query string false "标题" // @Param CreateTimeStart query string false "创建时间"
// @Param Content query string false "协议内容" // @Param CreateTimeEnd query string false "创建时间"
// @Param Sort query number false "排序" // @Param UpdateTimeStart query string false "更新时间"
// @Param CreateTimeStart query string false "创建时间" // @Param UpdateTimeEnd query string false "更新时间"
// @Param CreateTimeEnd query string false "创建时间" // @Router /api/admin/user_protocol/ExportFile [get]
// @Param UpdateTimeStart query string false "更新时间"
// @Param UpdateTimeEnd query string false "更新时间"
// @Router /api/admin/user_protocol/ExportFile [get]
func (hd *UserProtocolHandler) ExportFile(c *gin.Context) { func (hd *UserProtocolHandler) ExportFile(c *gin.Context) {
var listReq UserProtocolListReq var listReq UserProtocolListReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
@@ -162,18 +184,18 @@ func (hd *UserProtocolHandler) ExportFile(c *gin.Context) {
response.FailWithMsg(c, response.SystemError, "查询信息失败") response.FailWithMsg(c, response.SystemError, "查询信息失败")
return return
} }
f, err := excel2.Export(res,UserProtocolService.GetExcelCol(), "Sheet1", "用户协议") f, err := excel2.Export(res, UserProtocolService.GetExcelCol(), "Sheet1", "用户协议")
if err != nil { if err != nil {
response.FailWithMsg(c, response.SystemError, "导出失败") response.FailWithMsg(c, response.SystemError, "导出失败")
return return
} }
excel2.DownLoadExcel("用户协议" + time.Now().Format("20060102-150405"), c.Writer, f) excel2.DownLoadExcel("用户协议"+time.Now().Format("20060102-150405"), c.Writer, f)
} }
// @Summary 用户协议导入 // @Summary 用户协议导入
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议
// @Produce json // @Produce json
// @Router /api/admin/user_protocol/ImportFile [post] // @Router /api/admin/user_protocol/ImportFile [post]
func (hd *UserProtocolHandler) ImportFile(c *gin.Context) { func (hd *UserProtocolHandler) ImportFile(c *gin.Context) {
file, _, err := c.Request.FormFile("file") file, _, err := c.Request.FormFile("file")
if err != nil { if err != nil {
@@ -182,7 +204,7 @@ func (hd *UserProtocolHandler) ImportFile(c *gin.Context) {
} }
defer file.Close() defer file.Close()
importList := []UserProtocolResp{} importList := []UserProtocolResp{}
err = excel2.GetExcelData(file, &importList,UserProtocolService.GetExcelCol()) err = excel2.GetExcelData(file, &importList, UserProtocolService.GetExcelCol())
if err != nil { if err != nil {
c.String(http.StatusInternalServerError, err.Error()) c.String(http.StatusInternalServerError, err.Error())
return return
@@ -190,4 +212,4 @@ func (hd *UserProtocolHandler) ImportFile(c *gin.Context) {
err = UserProtocolService.ImportFile(importList) err = UserProtocolService.ImportFile(importList)
response.CheckAndResp(c, err) response.CheckAndResp(c, err)
} }

View File

@@ -1,53 +1,54 @@
package user_protocol package user_protocol
import ( import (
"x_admin/core" "x_admin/core"
) )
//UserProtocolListReq 用户协议列表参数 // UserProtocolListReq 用户协议列表参数
type UserProtocolListReq struct { type UserProtocolListReq struct {
Title *string `` // 标题 Title *string `` // 标题
Content *string `` // 协议内容 Content *string `` // 协议内容
Sort *float64 `` // 排序 Sort *float64 `` // 排序
CreateTimeStart *string `` // 开始创建时间 CreateTimeStart *string `` // 开始创建时间
CreateTimeEnd *string `` // 结束创建时间 CreateTimeEnd *string `` // 结束创建时间
UpdateTimeStart *string `` // 开始更新时间 UpdateTimeStart *string `` // 开始更新时间
UpdateTimeEnd *string `` // 结束更新时间 UpdateTimeEnd *string `` // 结束更新时间
} }
// UserProtocolAddReq 用户协议新增参数
//UserProtocolAddReq 用户协议新增参数
type UserProtocolAddReq struct { type UserProtocolAddReq struct {
Title *string `` // 标题 Title *string `` // 标题
Content *string `` // 协议内容 Content *string `` // 协议内容
Sort core.NullFloat `` // 排序 Sort core.NullFloat `` // 排序
} }
//UserProtocolEditReq 用户协议编辑参数 // UserProtocolEditReq 用户协议编辑参数
type UserProtocolEditReq struct { type UserProtocolEditReq struct {
Id int `` // Id int `` //
Title *string `` // 标题 Title *string `` // 标题
Content *string `` // 协议内容 Content *string `` // 协议内容
Sort core.NullFloat `` // 排序 Sort core.NullFloat `` // 排序
} }
//UserProtocolDetailReq 用户协议详情参数 // UserProtocolDetailReq 用户协议详情参数
type UserProtocolDetailReq struct { type UserProtocolDetailReq struct {
Id int `` // Id int `` //
} }
//UserProtocolDelReq 用户协议删除参数 // UserProtocolDelReq 用户协议删除参数
type UserProtocolDelReq struct { type UserProtocolDelReq struct {
Id int `` // Id int `` //
}
type UserProtocolDelBatchReq struct {
Ids string `` //
} }
//UserProtocolResp 用户协议返回信息 // UserProtocolResp 用户协议返回信息
type UserProtocolResp struct { type UserProtocolResp struct {
Id int `` // Id int `` //
Title string `` // 标题 Title string `` // 标题
Content string `` // 协议内容 Content string `` // 协议内容
Sort core.NullFloat `` // 排序 Sort core.NullFloat `` // 排序
CreateTime core.NullTime `` // 创建时间 CreateTime core.NullTime `` // 创建时间
UpdateTime core.NullTime `` // 更新时间 UpdateTime core.NullTime `` // 更新时间
} }

View File

@@ -5,12 +5,13 @@ import (
"x_admin/core/request" "x_admin/core/request"
"x_admin/core/response" "x_admin/core/response"
"x_admin/model" "x_admin/model"
"gorm.io/gorm"
"x_admin/util" "x_admin/util"
"x_admin/util/excel2" "x_admin/util/excel2"
"gorm.io/gorm"
) )
var UserProtocolService=NewUserProtocolService() var UserProtocolService = NewUserProtocolService()
var cacheUtil = util.CacheUtil{ var cacheUtil = util.CacheUtil{
Name: UserProtocolService.Name, Name: UserProtocolService.Name,
} }
@@ -23,42 +24,41 @@ func NewUserProtocolService() *userProtocolService {
} }
} }
//userProtocolService 用户协议服务实现类 // userProtocolService 用户协议服务实现类
type userProtocolService struct { type userProtocolService struct {
db *gorm.DB db *gorm.DB
Name string Name string
} }
// List 用户协议列表 // List 用户协议列表
func (service userProtocolService) GetModel(listReq UserProtocolListReq) *gorm.DB { func (service userProtocolService) GetModel(listReq UserProtocolListReq) *gorm.DB {
// 查询 // 查询
dbModel := service.db.Model(&model.UserProtocol{}) dbModel := service.db.Model(&model.UserProtocol{})
if listReq.Title!= nil { if listReq.Title != nil {
dbModel = dbModel.Where("title like ?", "%"+*listReq.Title+"%") dbModel = dbModel.Where("title like ?", "%"+*listReq.Title+"%")
} }
if listReq.Content!= nil { if listReq.Content != nil {
dbModel = dbModel.Where("content = ?", *listReq.Content) dbModel = dbModel.Where("content = ?", *listReq.Content)
} }
if listReq.Sort!= nil { if listReq.Sort != nil {
dbModel = dbModel.Where("sort = ?", *listReq.Sort) dbModel = dbModel.Where("sort = ?", *listReq.Sort)
} }
if listReq.CreateTimeStart!= nil { if listReq.CreateTimeStart != nil {
dbModel = dbModel.Where("create_time >= ?", *listReq.CreateTimeStart) dbModel = dbModel.Where("create_time >= ?", *listReq.CreateTimeStart)
} }
if listReq.CreateTimeEnd!= nil { if listReq.CreateTimeEnd != nil {
dbModel = dbModel.Where("create_time <= ?", *listReq.CreateTimeEnd) dbModel = dbModel.Where("create_time <= ?", *listReq.CreateTimeEnd)
} }
if listReq.UpdateTimeStart!= nil { if listReq.UpdateTimeStart != nil {
dbModel = dbModel.Where("update_time >= ?", *listReq.UpdateTimeStart) dbModel = dbModel.Where("update_time >= ?", *listReq.UpdateTimeStart)
} }
if listReq.UpdateTimeEnd!= nil { if listReq.UpdateTimeEnd != nil {
dbModel = dbModel.Where("update_time <= ?", *listReq.UpdateTimeEnd) dbModel = dbModel.Where("update_time <= ?", *listReq.UpdateTimeEnd)
} }
dbModel = dbModel.Where("is_delete = ?", 0) dbModel = dbModel.Where("is_delete = ?", 0)
return dbModel return dbModel
} }
// List 用户协议列表 // List 用户协议列表
func (service userProtocolService) List(page request.PageReq, listReq UserProtocolListReq) (res response.PageResp, e error) { func (service userProtocolService) List(page request.PageReq, listReq UserProtocolListReq) (res response.PageResp, e error) {
// 分页信息 // 分页信息
@@ -86,6 +86,7 @@ func (service userProtocolService) List(page request.PageReq, listReq UserProtoc
Lists: result, Lists: result,
}, nil }, nil
} }
// ListAll 用户协议列表 // ListAll 用户协议列表
func (service userProtocolService) ListAll(listReq UserProtocolListReq) (res []UserProtocolResp, e error) { func (service userProtocolService) ListAll(listReq UserProtocolListReq) (res []UserProtocolResp, e error) {
dbModel := service.GetModel(listReq) dbModel := service.GetModel(listReq)
@@ -120,13 +121,13 @@ func (service userProtocolService) Detail(Id int) (res UserProtocolResp, e error
} }
// Add 用户协议新增 // Add 用户协议新增
func (service userProtocolService) Add(addReq UserProtocolAddReq) (createId int,e error) { func (service userProtocolService) Add(addReq UserProtocolAddReq) (createId int, e error) {
var obj model.UserProtocol var obj model.UserProtocol
util.ConvertUtil.StructToStruct(addReq,&obj) util.ConvertUtil.StructToStruct(addReq, &obj)
err := service.db.Create(&obj).Error err := service.db.Create(&obj).Error
e = response.CheckMysqlErr(err) e = response.CheckMysqlErr(err)
if e != nil { if e != nil {
return 0,e return 0, e
} }
cacheUtil.SetCache(obj.Id, obj) cacheUtil.SetCache(obj.Id, obj)
createId = obj.Id createId = obj.Id
@@ -166,23 +167,30 @@ func (service userProtocolService) Del(Id int) (e error) {
if e = response.CheckErr(err, "查询数据失败"); e != nil { if e = response.CheckErr(err, "查询数据失败"); e != nil {
return return
} }
// 删除 // 删除
obj.IsDelete = 1 obj.IsDelete = 1
obj.DeleteTime = util.NullTimeUtil.Now() obj.DeleteTime = util.NullTimeUtil.Now()
err = service.db.Save(&obj).Error err = service.db.Save(&obj).Error
e = response.CheckErr(err, "删除失败") e = response.CheckErr(err, "删除失败")
cacheUtil.RemoveCache(obj.Id) cacheUtil.RemoveCache(obj.Id)
return return
} }
// DelBatch 用户协议-批量删除
func (service userProtocolService) DelBatch(IdsArr []string) (e error) {
var obj model.UserProtocol
err := service.db.Where("id in (?)", IdsArr).Delete(&obj).Error
return err
}
// 获取Excel的列 // 获取Excel的列
func (service userProtocolService) GetExcelCol() []excel2.Col { func (service userProtocolService) GetExcelCol() []excel2.Col {
var cols = []excel2.Col{ var cols = []excel2.Col{
{Name: "标题", Key: "Title", Width: 15}, {Name: "标题", Key: "Title", Width: 15},
{Name: "协议内容", Key: "Content", Width: 15}, {Name: "协议内容", Key: "Content", Width: 15},
{Name: "排序", Key: "Sort", Width: 15}, {Name: "排序", Key: "Sort", Width: 15},
{Name: "创建时间", Key: "CreateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime }, {Name: "创建时间", Key: "CreateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime},
{Name: "更新时间", Key: "UpdateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime }, {Name: "更新时间", Key: "UpdateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime},
} }
// 还可以考虑字典,请求下来加上 Replace 实现替换导出 // 还可以考虑字典,请求下来加上 Replace 实现替换导出
return cols return cols
@@ -211,4 +219,4 @@ func (service userProtocolService) ImportFile(importReq []UserProtocolResp) (e e
err := service.db.Create(&importData).Error err := service.db.Create(&importData).Error
e = response.CheckErr(err, "添加失败") e = response.CheckErr(err, "添加失败")
return e return e
} }

View File

@@ -1,9 +1,10 @@
package admin package admin
import ( import (
"github.com/gin-gonic/gin"
"x_admin/middleware"
"x_admin/admin/user_protocol" "x_admin/admin/user_protocol"
"x_admin/middleware"
"github.com/gin-gonic/gin"
) )
/** /**
@@ -32,6 +33,7 @@ INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, paths, component, is
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议添加','admin:user_protocol:add', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议添加','admin:user_protocol:add', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议编辑','admin:user_protocol:edit', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议编辑','admin:user_protocol:edit', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议删除','admin:user_protocol:del', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议删除','admin:user_protocol:del', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议批量删除','admin:user_protocol:delBatch', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议列表','admin:user_protocol:list', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议列表','admin:user_protocol:list', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议全部列表','admin:user_protocol:listAll', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议全部列表','admin:user_protocol:listAll', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议详情','admin:user_protocol:detail', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议详情','admin:user_protocol:detail', 0, 1, 0, now(), now());
@@ -39,7 +41,6 @@ INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_sh
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议导入excel','admin:user_protocol:ImportFile', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议导入excel','admin:user_protocol:ImportFile', 0, 1, 0, now(), now());
*/ */
// UserProtocolRoute(rg) // UserProtocolRoute(rg)
func UserProtocolRoute(rg *gin.RouterGroup) { func UserProtocolRoute(rg *gin.RouterGroup) {
handle := user_protocol.UserProtocolHandler{} handle := user_protocol.UserProtocolHandler{}
@@ -48,9 +49,12 @@ func UserProtocolRoute(rg *gin.RouterGroup) {
r.GET("/user_protocol/list", handle.List) r.GET("/user_protocol/list", handle.List)
r.GET("/user_protocol/listAll", handle.ListAll) r.GET("/user_protocol/listAll", handle.ListAll)
r.GET("/user_protocol/detail", handle.Detail) r.GET("/user_protocol/detail", handle.Detail)
r.POST("/user_protocol/add",middleware.RecordLog("用户协议新增"), handle.Add) r.POST("/user_protocol/add", middleware.RecordLog("用户协议新增"), handle.Add)
r.POST("/user_protocol/edit",middleware.RecordLog("用户协议编辑"), handle.Edit) r.POST("/user_protocol/edit", middleware.RecordLog("用户协议编辑"), handle.Edit)
r.POST("/user_protocol/del", middleware.RecordLog("用户协议删除"), handle.Del) r.POST("/user_protocol/del", middleware.RecordLog("用户协议删除"), handle.Del)
r.POST("/user_protocol/delBatch", middleware.RecordLog("用户协议批量删除"), handle.DelBatch)
r.GET("/user_protocol/ExportFile", middleware.RecordLog("用户协议导出"), handle.ExportFile) r.GET("/user_protocol/ExportFile", middleware.RecordLog("用户协议导出"), handle.ExportFile)
r.POST("/user_protocol/ImportFile", handle.ImportFile) r.POST("/user_protocol/ImportFile", handle.ImportFile)
} }

View File

@@ -18,8 +18,8 @@ type Col struct {
Key string Key string
Width int // 宽度 Width int // 宽度
Replace map[string]any //实现值的替换 Replace map[string]any //实现值的替换
Encode func(value any) any //暂未使用 Encode func(value any) any //编码函数-导出先Encode后Replace
Decode func(value any) (any, error) //实现类型、值的替换 Decode func(value any) (any, error) //解码函数-导入先Replace后Decode
} }
// 定义编码接口 // 定义编码接口