添加投票项模块

main 13
hshansha 6 months ago
parent adb09d37e4
commit 2b49e8519d

@ -0,0 +1,104 @@
package com.ruoyi.kaohe.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kaohe.domain.KhVoteItems;
import com.ruoyi.kaohe.service.IKhVoteItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* Controller
*
* @author hs
* @date 2025-06-24
*/
@RestController
@RequestMapping("/kaohe/vote_items")
public class KhVoteItemsController extends BaseController
{
@Autowired
private IKhVoteItemsService khVoteItemsService;
/**
*
*/
@PreAuthorize("@ss.hasPermi('kaohe:vote_items:list')")
@GetMapping("/list")
public TableDataInfo list(KhVoteItems khVoteItems)
{
startPage();
List<KhVoteItems> list = khVoteItemsService.selectKhVoteItemsList(khVoteItems);
return getDataTable(list);
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('kaohe:vote_items:export')")
@Log(title = "投票项", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, KhVoteItems khVoteItems)
{
List<KhVoteItems> list = khVoteItemsService.selectKhVoteItemsList(khVoteItems);
ExcelUtil<KhVoteItems> util = new ExcelUtil<KhVoteItems>(KhVoteItems.class);
util.exportExcel(response, list, "投票项数据");
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('kaohe:vote_items:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(khVoteItemsService.selectKhVoteItemsById(id));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('kaohe:vote_items:add')")
@Log(title = "投票项", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody KhVoteItems khVoteItems)
{
return toAjax(khVoteItemsService.insertKhVoteItems(khVoteItems));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('kaohe:vote_items:edit')")
@Log(title = "投票项", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody KhVoteItems khVoteItems)
{
return toAjax(khVoteItemsService.updateKhVoteItems(khVoteItems));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('kaohe:vote_items:remove')")
@Log(title = "投票项", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(khVoteItemsService.deleteKhVoteItemsByIds(ids));
}
}

@ -0,0 +1,57 @@
package com.ruoyi.kaohe.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* kh_vote_items
*
* @author hs
* @date 2025-06-24
*/
public class KhVoteItems extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 投票选项名称 */
@Excel(name = "投票选项名称")
private String vitemName;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setVitemName(String vitemName)
{
this.vitemName = vitemName;
}
public String getVitemName()
{
return vitemName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("vitemName", getVitemName())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
}

@ -0,0 +1,61 @@
package com.ruoyi.kaohe.mapper;
import java.util.List;
import com.ruoyi.kaohe.domain.KhVoteItems;
/**
* Mapper
*
* @author hs
* @date 2025-06-24
*/
public interface KhVoteItemsMapper
{
/**
*
*
* @param id
* @return
*/
public KhVoteItems selectKhVoteItemsById(Long id);
/**
*
*
* @param khVoteItems
* @return
*/
public List<KhVoteItems> selectKhVoteItemsList(KhVoteItems khVoteItems);
/**
*
*
* @param khVoteItems
* @return
*/
public int insertKhVoteItems(KhVoteItems khVoteItems);
/**
*
*
* @param khVoteItems
* @return
*/
public int updateKhVoteItems(KhVoteItems khVoteItems);
/**
*
*
* @param id
* @return
*/
public int deleteKhVoteItemsById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteKhVoteItemsByIds(Long[] ids);
}

@ -0,0 +1,61 @@
package com.ruoyi.kaohe.service;
import java.util.List;
import com.ruoyi.kaohe.domain.KhVoteItems;
/**
* Service
*
* @author hs
* @date 2025-06-24
*/
public interface IKhVoteItemsService
{
/**
*
*
* @param id
* @return
*/
public KhVoteItems selectKhVoteItemsById(Long id);
/**
*
*
* @param khVoteItems
* @return
*/
public List<KhVoteItems> selectKhVoteItemsList(KhVoteItems khVoteItems);
/**
*
*
* @param khVoteItems
* @return
*/
public int insertKhVoteItems(KhVoteItems khVoteItems);
/**
*
*
* @param khVoteItems
* @return
*/
public int updateKhVoteItems(KhVoteItems khVoteItems);
/**
*
*
* @param ids
* @return
*/
public int deleteKhVoteItemsByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteKhVoteItemsById(Long id);
}

@ -0,0 +1,96 @@
package com.ruoyi.kaohe.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.kaohe.mapper.KhVoteItemsMapper;
import com.ruoyi.kaohe.domain.KhVoteItems;
import com.ruoyi.kaohe.service.IKhVoteItemsService;
/**
* Service
*
* @author hs
* @date 2025-06-24
*/
@Service
public class KhVoteItemsServiceImpl implements IKhVoteItemsService
{
@Autowired
private KhVoteItemsMapper khVoteItemsMapper;
/**
*
*
* @param id
* @return
*/
@Override
public KhVoteItems selectKhVoteItemsById(Long id)
{
return khVoteItemsMapper.selectKhVoteItemsById(id);
}
/**
*
*
* @param khVoteItems
* @return
*/
@Override
public List<KhVoteItems> selectKhVoteItemsList(KhVoteItems khVoteItems)
{
return khVoteItemsMapper.selectKhVoteItemsList(khVoteItems);
}
/**
*
*
* @param khVoteItems
* @return
*/
@Override
public int insertKhVoteItems(KhVoteItems khVoteItems)
{
khVoteItems.setCreateTime(DateUtils.getNowDate());
return khVoteItemsMapper.insertKhVoteItems(khVoteItems);
}
/**
*
*
* @param khVoteItems
* @return
*/
@Override
public int updateKhVoteItems(KhVoteItems khVoteItems)
{
khVoteItems.setUpdateTime(DateUtils.getNowDate());
return khVoteItemsMapper.updateKhVoteItems(khVoteItems);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteKhVoteItemsByIds(Long[] ids)
{
return khVoteItemsMapper.deleteKhVoteItemsByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteKhVoteItemsById(Long id)
{
return khVoteItemsMapper.deleteKhVoteItemsById(id);
}
}

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 查询投票项列表
export function listVote_items(query) {
return request({
url: '/kaohe/vote_items/list',
method: 'get',
params: query
})
}
// 查询投票项详细
export function getVote_items(id) {
return request({
url: '/kaohe/vote_items/' + id,
method: 'get'
})
}
// 新增投票项
export function addVote_items(data) {
return request({
url: '/kaohe/vote_items',
method: 'post',
data: data
})
}
// 修改投票项
export function updateVote_items(data) {
return request({
url: '/kaohe/vote_items',
method: 'put',
data: data
})
}
// 删除投票项
export function delVote_items(id) {
return request({
url: '/kaohe/vote_items/' + id,
method: 'delete'
})
}

@ -0,0 +1,254 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="投票选项名称" prop="vitemName">
<el-input
v-model="queryParams.vitemName"
placeholder="请输入投票选项名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['kaohe:vote_items:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['kaohe:vote_items:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['kaohe:vote_items:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['kaohe:vote_items:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="vote_itemsList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="主键" align="center" prop="id" />
<el-table-column label="投票选项名称" align="center" prop="vitemName" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['kaohe:vote_items:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['kaohe:vote_items:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改投票项对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="投票选项名称" prop="vitemName">
<el-input v-model="form.vitemName" placeholder="请输入投票选项名称" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listVote_items, getVote_items, delVote_items, addVote_items, updateVote_items } from "@/api/kaohe/vote_items"
export default {
name: "Vote_items",
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
vote_itemsList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
vitemName: null,
},
//
form: {},
//
rules: {
}
}
},
created() {
this.getList()
},
methods: {
/** 查询投票项列表 */
getList() {
this.loading = true
listVote_items(this.queryParams).then(response => {
this.vote_itemsList = response.rows
this.total = response.total
this.loading = false
})
},
//
cancel() {
this.open = false
this.reset()
},
//
reset() {
this.form = {
id: null,
vitemName: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null
}
this.resetForm("form")
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm")
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.open = true
this.title = "添加投票项"
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const id = row.id || this.ids
getVote_items(id).then(response => {
this.form = response.data
this.open = true
this.title = "修改投票项"
})
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateVote_items(this.form).then(response => {
this.$modal.msgSuccess("修改成功")
this.open = false
this.getList()
})
} else {
addVote_items(this.form).then(response => {
this.$modal.msgSuccess("新增成功")
this.open = false
this.getList()
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids
this.$modal.confirm('是否确认删除投票项编号为"' + ids + '"的数据项?').then(function() {
return delVote_items(ids)
}).then(() => {
this.getList()
this.$modal.msgSuccess("删除成功")
}).catch(() => {})
},
/** 导出按钮操作 */
handleExport() {
this.download('kaohe/vote_items/export', {
...this.queryParams
}, `vote_items_${new Date().getTime()}.xlsx`)
}
}
}
</script>
Loading…
Cancel
Save