代码生成:批量删除

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) {
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) {
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) {
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 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,8 +1,14 @@
<template>
<div class="index-lists">
<el-card class="!border-none" shadow="never">
<el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true" label-width="70px"
label-position="left">
<el-form
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-input v-model="queryParams.Title" />
</el-form-item>
@@ -26,7 +32,11 @@
</el-card>
<el-card class="!border-none mt-4" shadow="never">
<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>
<icon name="el-icon-Plus" />
</template>
@@ -53,13 +63,23 @@
</template>
导出
</el-button>
<el-button
v-perms="['admin:user_protocol:delBatch']"
type="danger"
@click="deleteBatch"
>
批量删除
</el-button>
</div>
<el-table
class="mt-4"
size="large"
v-loading="pager.loading"
: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="Content" min-width="130" />
<el-table-column label="排序" prop="Sort" min-width="130" />
@@ -90,27 +110,27 @@
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<edit-popup
v-if="showEdit"
ref="editRef"
@success="getLists"
@close="showEdit = false"
/>
<edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
</div>
</template>
<script lang="ts" setup>
import { user_protocol_delete, 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 {
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 { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
defineOptions({
name:"user_protocol"
name: 'user_protocol'
})
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
@@ -121,7 +141,7 @@ const queryParams = reactive<type_user_protocol_query>({
CreateTimeStart: null,
CreateTimeEnd: null,
UpdateTimeStart: null,
UpdateTimeEnd: null,
UpdateTimeEnd: null
})
const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol>({
@@ -129,7 +149,6 @@ const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol
params: queryParams
})
const handleAdd = async () => {
showEdit.value = true
await nextTick()
@@ -142,11 +161,30 @@ const handleEdit = async (data: any) => {
editRef.value?.open('edit')
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) => {
try {
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('删除成功')
getLists()
} 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 }}}))
}
// @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 }}}:edit
admin:{{{.ModuleName }}}:del
admin:{{{.ModuleName }}}:delBatch
admin:{{{.ModuleName }}}:list
admin:{{{.ModuleName }}}:listAll
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 }}}: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 }}}: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 }}}: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());
@@ -48,9 +50,13 @@ func {{{ toUpperCamelCase .ModuleName }}}Route(rg *gin.RouterGroup) {
r.GET("/{{{ .ModuleName }}}/list", handle.List)
r.GET("/{{{ .ModuleName }}}/listAll", handle.ListAll)
r.GET("/{{{ .ModuleName }}}/detail", handle.Detail)
r.POST("/{{{ .ModuleName }}}/add",middleware.RecordLog("{{{ .FunctionName }}}新增"), handle.Add)
r.POST("/{{{ .ModuleName }}}/edit",middleware.RecordLog("{{{ .FunctionName }}}编辑"), handle.Edit)
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.POST("/{{{ .ModuleName }}}/ImportFile", handle.ImportFile)
}

View File

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

View File

@@ -192,6 +192,13 @@ func (service {{{ toCamelCase .EntityName }}}Service) Del({{{ toUpperCamelCase .
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的列
func (service {{{ toCamelCase .EntityName }}}Service) GetExcelCol() []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) {
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}}}导入
export const {{{.ModuleName}}}_import_file = '/{{{.ModuleName}}}/ImportFile'

View File

@@ -62,6 +62,7 @@
新增
</el-button>
<upload
v-perms="['admin:{{{ .ModuleName }}}:ImportFile']"
class="ml-3 mr-3"
:url="{{{.ModuleName}}}_import_file"
:data="{ cid: 0 }"
@@ -76,19 +77,28 @@
导入
</el-button>
</upload>
<el-button type="primary" @click="exportFile">
<el-button v-perms="['admin:{{{ .ModuleName }}}:ExportFile']" type="primary" @click="exportFile">
<template #icon>
<icon name="el-icon-Download" />
</template>
导出
</el-button>
<el-button
v-perms="['admin:{{{ .ModuleName }}}:delBatch']"
type="danger"
@click="deleteBatch"
>
批量删除
</el-button>
</div>
<el-table
class="mt-4"
size="large"
v-loading="pager.loading"
:data="pager.lists"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
{{{- range .Columns }}}
{{{- if .IsList }}}
{{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
@@ -162,7 +172,7 @@
</div>
</template>
<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 }}}";
@@ -230,6 +240,11 @@ const handleEdit = async (data: any) => {
editRef.value?.open('edit')
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) => {
try {
@@ -239,6 +254,22 @@ const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => {
getLists()
} 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 () => {
try {
await feedback.confirm('确定要导出?')

View File

@@ -3,16 +3,17 @@ package user_protocol
import (
"net/http"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
"x_admin/core/request"
"x_admin/core/response"
"x_admin/util"
"x_admin/util/excel2"
"github.com/gin-gonic/gin"
"golang.org/x/sync/singleflight"
)
type UserProtocolHandler struct {
requestGroup singleflight.Group
}
@@ -30,8 +31,9 @@ type UserProtocolHandler struct {
// @Param CreateTimeEnd query string false "创建时间"
// @Param UpdateTimeStart 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) {
var page request.PageReq
var listReq UserProtocolListReq
@@ -86,7 +88,6 @@ func (hd *UserProtocolHandler) Detail(c *gin.Context) {
response.CheckAndRespWithData(c, res, err)
}
// @Summary 用户协议新增
// @Tags user_protocol-用户协议
// @Produce json
@@ -102,8 +103,9 @@ func (hd *UserProtocolHandler) Add(c *gin.Context) {
return
}
createId, e := UserProtocolService.Add(addReq)
response.CheckAndRespWithData(c,createId, e)
response.CheckAndRespWithData(c, createId, e)
}
// @Summary 用户协议编辑
// @Tags user_protocol-用户协议
// @Produce json
@@ -119,8 +121,9 @@ func (hd *UserProtocolHandler) Edit(c *gin.Context) {
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &editReq)) {
return
}
response.CheckAndRespWithData(c,editReq.Id, UserProtocolService.Edit(editReq))
response.CheckAndRespWithData(c, editReq.Id, UserProtocolService.Edit(editReq))
}
// @Summary 用户协议删除
// @Tags user_protocol-用户协议
// @Produce json
@@ -136,9 +139,28 @@ func (hd *UserProtocolHandler) Del(c *gin.Context) {
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-用户协议
@@ -162,12 +184,12 @@ func (hd *UserProtocolHandler) ExportFile(c *gin.Context) {
response.FailWithMsg(c, response.SystemError, "查询信息失败")
return
}
f, err := excel2.Export(res,UserProtocolService.GetExcelCol(), "Sheet1", "用户协议")
f, err := excel2.Export(res, UserProtocolService.GetExcelCol(), "Sheet1", "用户协议")
if err != nil {
response.FailWithMsg(c, response.SystemError, "导出失败")
return
}
excel2.DownLoadExcel("用户协议" + time.Now().Format("20060102-150405"), c.Writer, f)
excel2.DownLoadExcel("用户协议"+time.Now().Format("20060102-150405"), c.Writer, f)
}
// @Summary 用户协议导入
@@ -182,7 +204,7 @@ func (hd *UserProtocolHandler) ImportFile(c *gin.Context) {
}
defer file.Close()
importList := []UserProtocolResp{}
err = excel2.GetExcelData(file, &importList,UserProtocolService.GetExcelCol())
err = excel2.GetExcelData(file, &importList, UserProtocolService.GetExcelCol())
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return

View File

@@ -1,10 +1,10 @@
package user_protocol
import (
"x_admin/core"
)
//UserProtocolListReq 用户协议列表参数
// UserProtocolListReq 用户协议列表参数
type UserProtocolListReq struct {
Title *string `` // 标题
Content *string `` // 协议内容
@@ -15,16 +15,14 @@ type UserProtocolListReq struct {
UpdateTimeEnd *string `` // 结束更新时间
}
//UserProtocolAddReq 用户协议新增参数
// UserProtocolAddReq 用户协议新增参数
type UserProtocolAddReq struct {
Title *string `` // 标题
Content *string `` // 协议内容
Sort core.NullFloat `` // 排序
}
//UserProtocolEditReq 用户协议编辑参数
// UserProtocolEditReq 用户协议编辑参数
type UserProtocolEditReq struct {
Id int `` //
Title *string `` // 标题
@@ -32,17 +30,20 @@ type UserProtocolEditReq struct {
Sort core.NullFloat `` // 排序
}
//UserProtocolDetailReq 用户协议详情参数
// UserProtocolDetailReq 用户协议详情参数
type UserProtocolDetailReq struct {
Id int `` //
}
//UserProtocolDelReq 用户协议删除参数
// UserProtocolDelReq 用户协议删除参数
type UserProtocolDelReq struct {
Id int `` //
}
type UserProtocolDelBatchReq struct {
Ids string `` //
}
//UserProtocolResp 用户协议返回信息
// UserProtocolResp 用户协议返回信息
type UserProtocolResp struct {
Id int `` //
Title string `` // 标题

View File

@@ -5,12 +5,13 @@ import (
"x_admin/core/request"
"x_admin/core/response"
"x_admin/model"
"gorm.io/gorm"
"x_admin/util"
"x_admin/util/excel2"
"gorm.io/gorm"
)
var UserProtocolService=NewUserProtocolService()
var UserProtocolService = NewUserProtocolService()
var cacheUtil = util.CacheUtil{
Name: UserProtocolService.Name,
}
@@ -23,42 +24,41 @@ func NewUserProtocolService() *userProtocolService {
}
}
//userProtocolService 用户协议服务实现类
// userProtocolService 用户协议服务实现类
type userProtocolService struct {
db *gorm.DB
Name string
}
// List 用户协议列表
func (service userProtocolService) GetModel(listReq UserProtocolListReq) *gorm.DB {
// 查询
dbModel := service.db.Model(&model.UserProtocol{})
if listReq.Title!= nil {
if listReq.Title != nil {
dbModel = dbModel.Where("title like ?", "%"+*listReq.Title+"%")
}
if listReq.Content!= nil {
if listReq.Content != nil {
dbModel = dbModel.Where("content = ?", *listReq.Content)
}
if listReq.Sort!= nil {
if listReq.Sort != nil {
dbModel = dbModel.Where("sort = ?", *listReq.Sort)
}
if listReq.CreateTimeStart!= nil {
if listReq.CreateTimeStart != nil {
dbModel = dbModel.Where("create_time >= ?", *listReq.CreateTimeStart)
}
if listReq.CreateTimeEnd!= nil {
if listReq.CreateTimeEnd != nil {
dbModel = dbModel.Where("create_time <= ?", *listReq.CreateTimeEnd)
}
if listReq.UpdateTimeStart!= nil {
if listReq.UpdateTimeStart != nil {
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("is_delete = ?", 0)
return dbModel
}
// List 用户协议列表
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,
}, nil
}
// ListAll 用户协议列表
func (service userProtocolService) ListAll(listReq UserProtocolListReq) (res []UserProtocolResp, e error) {
dbModel := service.GetModel(listReq)
@@ -120,13 +121,13 @@ func (service userProtocolService) Detail(Id int) (res UserProtocolResp, e error
}
// 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
util.ConvertUtil.StructToStruct(addReq,&obj)
util.ConvertUtil.StructToStruct(addReq, &obj)
err := service.db.Create(&obj).Error
e = response.CheckMysqlErr(err)
if e != nil {
return 0,e
return 0, e
}
cacheUtil.SetCache(obj.Id, obj)
createId = obj.Id
@@ -175,14 +176,21 @@ func (service userProtocolService) Del(Id int) (e error) {
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的列
func (service userProtocolService) GetExcelCol() []excel2.Col {
var cols = []excel2.Col{
{Name: "标题", Key: "Title", Width: 15},
{Name: "协议内容", Key: "Content", Width: 15},
{Name: "排序", Key: "Sort", Width: 15},
{Name: "创建时间", Key: "CreateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime },
{Name: "更新时间", Key: "UpdateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime },
{Name: "创建时间", Key: "CreateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime},
{Name: "更新时间", Key: "UpdateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime},
}
// 还可以考虑字典,请求下来加上 Replace 实现替换导出
return cols

View File

@@ -1,9 +1,10 @@
package admin
import (
"github.com/gin-gonic/gin"
"x_admin/middleware"
"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: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: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: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());
@@ -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());
*/
// UserProtocolRoute(rg)
func UserProtocolRoute(rg *gin.RouterGroup) {
handle := user_protocol.UserProtocolHandler{}
@@ -48,9 +49,12 @@ func UserProtocolRoute(rg *gin.RouterGroup) {
r.GET("/user_protocol/list", handle.List)
r.GET("/user_protocol/listAll", handle.ListAll)
r.GET("/user_protocol/detail", handle.Detail)
r.POST("/user_protocol/add",middleware.RecordLog("用户协议新增"), handle.Add)
r.POST("/user_protocol/edit",middleware.RecordLog("用户协议编辑"), handle.Edit)
r.POST("/user_protocol/add", middleware.RecordLog("用户协议新增"), handle.Add)
r.POST("/user_protocol/edit", middleware.RecordLog("用户协议编辑"), handle.Edit)
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.POST("/user_protocol/ImportFile", handle.ImportFile)
}

View File

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