提交 bf72882d 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

自动化代码增加 批量删除功能

上级 2ed231c4
......@@ -35,7 +35,7 @@ func CreateTemp(c *gin.Context) {
return
}
if a.AutoCreateApiToSql {
apiList := [5]model.SysApi{
apiList := [6]model.SysApi{
{
Path: "/" + a.Abbreviation + "/" + "create" + a.StructName,
Description: "新增" + a.Description,
......@@ -48,6 +48,12 @@ func CreateTemp(c *gin.Context) {
ApiGroup: a.Abbreviation,
Method: "DELETE",
},
{
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName+"ByIds",
Description: "批量删除" + a.Description,
ApiGroup: a.Abbreviation,
Method: "DELETE",
},
{
Path: "/" + a.Abbreviation + "/" + "update" + a.StructName,
Description: "更新" + a.Description,
......
......@@ -48,6 +48,25 @@ func DeleteSysOperationRecord(c *gin.Context) {
}
}
// @Tags SysOperationRecord
// @Summary 批量删除SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
func DeleteSysOperationRecordByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
err := service.DeleteSysOperationRecordByIds(IDS)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 更新SysOperationRecord
// @Security ApiKeyAuth
......
......@@ -11,8 +11,8 @@ jwt:
# mysql connect configuration
mysql:
username: root
password: 'wztxz19971029'
path: '47.103.196.252:3306'
password: 'Aa@6447985'
path: '127.0.0.1:3306'
db-name: 'qmPlus'
config: 'charset=utf8&parseTime=True&loc=Local'
max-idle-conns: 10
......
......@@ -22,6 +22,7 @@ func DBTables() {
model.ExaFileChunk{},
model.ExaCustomer{},
model.SysOperationRecord{},
model.TestMore{},
)
global.GVA_LOG.Debug("register table success")
}
......@@ -38,6 +38,7 @@ func Routers() *gin.Engine {
router.InitSysDictionaryDetailRouter(ApiGroup) // 字典详情管理
router.InitSysDictionaryRouter(ApiGroup) // 字典管理
router.InitSysOperationRecordRouter(ApiGroup)
router.InitTestMoreRouter(ApiGroup)
global.GVA_LOG.Info("router register success")
return Router
}
......@@ -10,3 +10,7 @@ type PageInfo struct {
type GetById struct {
Id float64 `json:"id" form:"id"`
}
type IdsReq struct {
Ids []int `json:"ids" form:"ids"`
}
\ No newline at end of file
......@@ -33,6 +33,22 @@ export const create{{.StructName}} = (data) => {
})
}
// @Tags {{.StructName}}
// @Summary 删除{{.StructName}}
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
export const delete{{.StructName}}ByIds = (data) => {
return service({
url: "/{{.Abbreviation}}/delete{{.StructName}}ByIds",
method: 'delete',
data
})
}
// @Tags {{.StructName}}
// @Summary 更新{{.StructName}}
// @Security ApiKeyAuth
......
......@@ -27,10 +27,21 @@
<el-form-item>
<el-button @click="openDialog" type="primary">新增{{.Description}}</el-button>
</el-form-item>
<el-form-item>
<el-popover placement="top" v-model="deleteVisible" width="160">
<p>确定要删除吗?</p>
<div style="text-align: right; margin: 0">
<el-button @click="deleteVisible = false" size="mini" type="text">取消</el-button>
<el-button @click="onDelete" size="mini" type="primary">确定</el-button>
</div>
<el-button icon="el-icon-delete" size="mini" slot="reference" type="danger">批量删除</el-button>
</el-popover>
</el-form-item>
</el-form>
</div>
<el-table
:data="tableData"
@selection-change="handleSelectionChange"
border
ref="multipleTable"
stripe
......@@ -87,6 +98,7 @@
import {
create{{.StructName}},
delete{{.StructName}},
delete{{.StructName}}ByIds,
update{{.StructName}},
find{{.StructName}},
get{{.StructName}}List
......@@ -103,6 +115,8 @@ export default {
dialogFormVisible: false,
visible: false,
type: "",
deleteVisible: false,
multipleSelection: [],
formData: {
{{range .Fields}}{{.FieldJson}}:null,{{ end }}
}
......@@ -136,6 +150,25 @@ export default {
} {{ end }} {{ end }}
this.getTableData()
},
handleSelectionChange(val) {
this.multipleSelection = val
},
async onDelete() {
const ids = []
this.multipleSelection &&
this.multipleSelection.map(item => {
ids.push(item.ID)
})
const res = await delete{{.StructName}}ByIds({ ids })
if (res.code == 0) {
this.$message({
type: 'success',
message: '删除成功'
})
this.deleteVisible = false
this.getTableData()
}
},
async update{{.StructName}}(row) {
const res = await find{{.StructName}}({ ID: row.ID });
this.type = "update";
......
......@@ -48,6 +48,25 @@ func Delete{{.StructName}}(c *gin.Context) {
}
}
// @Tags {{.StructName}}
// @Summary 批量删除{{.StructName}}
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
func Delete{{.StructName}}ByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
err := service.Delete{{.StructName}}ByIds(IDS)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags {{.StructName}}
// @Summary 更新{{.StructName}}
// @Security ApiKeyAuth
......
......@@ -9,9 +9,9 @@ import (
type {{.StructName}} struct {
gorm.Model {{- range .Fields}}
{{- if eq .FieldType "bool" }}
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"`
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}}"`
{{- else }}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"`
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}}"`
{{- end }} {{- end }}
}
......
......@@ -7,10 +7,11 @@ import (
)
func Init{{.StructName}}Router(Router *gin.RouterGroup) {
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()).Use(middleware.OperationRecord())
{
{{.StructName}}Router.POST("create{{.StructName}}", v1.Create{{.StructName}}) // 新建{{.StructName}}
{{.StructName}}Router.DELETE("delete{{.StructName}}", v1.Delete{{.StructName}}) // 删除{{.StructName}}
{{.StructName}}Router.DELETE("delete{{.StructName}}ByIds", v1.Delete{{.StructName}}ByIds) // 批量删除{{.StructName}}
{{.StructName}}Router.PUT("update{{.StructName}}", v1.Update{{.StructName}}) // 更新{{.StructName}}
{{.StructName}}Router.GET("find{{.StructName}}", v1.Find{{.StructName}}) // 根据ID获取{{.StructName}}
{{.StructName}}Router.GET("get{{.StructName}}List", v1.Get{{.StructName}}List) // 获取{{.StructName}}列表
......
......@@ -28,6 +28,17 @@ func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error)
return err
}
// @title Delete{{.StructName}}ByIds
// @description delete {{.StructName}}s
// @auth (2020/04/05 20:22)
// @param {{.Abbreviation}} model.{{.StructName}}
// @return error
func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in (?)",ids.Ids).Error
return err
}
// @title Update{{.StructName}}
// @description update a {{.StructName}}
// @param {{.Abbreviation}} *model.{{.StructName}}
......
......@@ -13,8 +13,10 @@ func InitSysOperationRecordRouter(Router *gin.RouterGroup) {
{
SysOperationRecordRouter.POST("createSysOperationRecord", v1.CreateSysOperationRecord) // 新建SysOperationRecord
SysOperationRecordRouter.DELETE("deleteSysOperationRecord", v1.DeleteSysOperationRecord) // 删除SysOperationRecord
SysOperationRecordRouter.DELETE("deleteSysOperationRecordByIds", v1.DeleteSysOperationRecordByIds) // 批量删除SysOperationRecord
SysOperationRecordRouter.PUT("updateSysOperationRecord", v1.UpdateSysOperationRecord) // 更新SysOperationRecord
SysOperationRecordRouter.GET("findSysOperationRecord", v1.FindSysOperationRecord) // 根据ID获取SysOperationRecord
SysOperationRecordRouter.GET("getSysOperationRecordList", v1.GetSysOperationRecordList) // 获取SysOperationRecord列表
}
}
......@@ -17,6 +17,17 @@ func CreateSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err
return err
}
// @title DeleteSysOperationRecord
// @description delete SysOperationRecords
// @auth (2020/04/05 20:22)
// @param sysOperationRecord request.IdsReq
// @return error
func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.SysOperationRecord{},"id in (?)",ids.Ids).Error
return err
}
// @title DeleteSysOperationRecord
// @description delete a SysOperationRecord
// @auth (2020/04/05 20:22)
......
......@@ -8,13 +8,29 @@ import service from '@/utils/request'
// @Param data body model.SysOperationRecord true "删除SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
export const deleteSysOperationRecord = (data) => {
return service({
url: "/sysOperationRecord/deleteSysOperationRecord",
method: 'delete',
data
})
}
export const deleteSysOperationRecord = (data) => {
return service({
url: "/sysOperationRecord/deleteSysOperationRecord",
method: 'delete',
data
})
}
// @Tags SysOperationRecord
// @Summary 批量删除SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "删除SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
export const deleteSysOperationRecordByIds = (data) => {
return service({
url: "/sysOperationRecord/deleteSysOperationRecordByIds",
method: 'delete',
data
})
}
// @Tags SysOperationRecord
// @Summary 分页获取SysOperationRecord列表
......@@ -24,10 +40,10 @@ import service from '@/utils/request'
// @Param data body request.PageInfo true "分页获取SysOperationRecord列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysOperationRecord/getSysOperationRecordList [get]
export const getSysOperationRecordList = (params) => {
return service({
url: "/sysOperationRecord/getSysOperationRecordList",
method: 'get',
params
})
}
\ No newline at end of file
export const getSysOperationRecordList = (params) => {
return service({
url: "/sysOperationRecord/getSysOperationRecordList",
method: 'get',
params
})
}
\ No newline at end of file
......@@ -14,10 +14,21 @@
<el-form-item>
<el-button @click="onSubmit" type="primary">查询</el-button>
</el-form-item>
<el-form-item>
<el-popover placement="top" v-model="deleteVisible" width="160">
<p>确定要删除吗?</p>
<div style="text-align: right; margin: 0">
<el-button @click="deleteVisible = false" size="mini" type="text">取消</el-button>
<el-button @click="onDelete" size="mini" type="primary">确定</el-button>
</div>
<el-button icon="el-icon-delete" size="mini" slot="reference" type="danger">批量删除</el-button>
</el-popover>
</el-form-item>
</el-form>
</div>
<el-table
:data="tableData"
@selection-change="handleSelectionChange"
border
ref="multipleTable"
stripe
......@@ -27,9 +38,7 @@
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column label="操作人" width="140">
<template slot-scope="scope">
<div>
{{scope.row.user.userName}}({{scope.row.user.nickName}})
</div>
<div>{{scope.row.user.userName}}({{scope.row.user.nickName}})</div>
</template>
</el-table-column>
<el-table-column label="日期" width="180">
......@@ -95,7 +104,8 @@
<script>
import {
deleteSysOperationRecord,
getSysOperationRecordList
getSysOperationRecordList,
deleteSysOperationRecordByIds
} from '@/api/sysOperationRecord' // 此处请自行替换地址
import { formatTimeToStr } from '@/utils/data'
import infoList from '@/components/mixins/infoList'
......@@ -109,6 +119,8 @@ export default {
dialogFormVisible: false,
visible: false,
type: '',
deleteVisible: false,
multipleSelection: [],
formData: {
ip: null,
method: null,
......@@ -145,6 +157,25 @@ export default {
this.pageSize = 10
this.getTableData()
},
handleSelectionChange(val) {
this.multipleSelection = val
},
async onDelete() {
const ids = []
this.multipleSelection &&
this.multipleSelection.map(item => {
ids.push(item.ID)
})
const res = await deleteSysOperationRecordByIds({ ids })
if (res.code == 0) {
this.$message({
type: 'success',
message: '删除成功'
})
this.deleteVisible = false
this.getTableData()
}
},
async deleteSysOperationRecord(row) {
this.visible = false
const res = await deleteSysOperationRecord({ ID: row.ID })
......@@ -177,13 +208,12 @@ export default {
}
}
}
.popover-box{
background:#112435;
color:#f08047;
height:600px;
width:420px;
overflow:auto;
.popover-box {
background: #112435;
color: #f08047;
height: 600px;
width: 420px;
overflow: auto;
}
.popover-box::-webkit-scrollbar {
display: none; /* Chrome Safari */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册