添加:树表演示程序,支持mybatis-flex

This commit is contained in:
dataprince 2023-11-23 11:18:21 +08:00
parent c788f88216
commit 5e2c826595
11 changed files with 776 additions and 0 deletions

View File

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 查询产品树列表
export function listProduct(query) {
return request({
url: '/mf/product/list',
method: 'get',
params: query
})
}
// 查询产品树详细
export function getProduct(productId) {
return request({
url: '/mf/product/' + productId,
method: 'get'
})
}
// 新增产品树
export function addProduct(data) {
return request({
url: '/mf/product',
method: 'post',
data: data
})
}
// 修改产品树
export function updateProduct(data) {
return request({
url: '/mf/product',
method: 'put',
data: data
})
}
// 删除产品树
export function delProduct(productId) {
return request({
url: '/mf/product/' + productId,
method: 'delete'
})
}

View File

@ -0,0 +1,289 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="产品名称" prop="productName">
<el-input
v-model="queryParams.productName"
placeholder="请输入产品名称"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="产品状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择产品状态" clearable>
<el-option
v-for="dict in sys_student_status"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @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="Plus"
@click="handleAdd"
v-hasPermi="['mf:product:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="info"
plain
icon="Sort"
@click="toggleExpandAll"
>展开/折叠</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
@click="handleExport"
v-hasPermi="['mf:product:export']"
>导出</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table
v-if="refreshTable"
v-loading="loading"
:data="productList"
row-key="productId"
:default-expand-all="isExpandAll"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
<el-table-column label="产品名称" align="center" prop="productName" />
<el-table-column label="显示顺序" align="center" prop="orderNum" />
<el-table-column label="产品状态" align="center" prop="status">
<template #default="scope">
<dict-tag :options="sys_student_status" :value="scope.row.status"/>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['mf:product:edit']">修改</el-button>
<el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['mf:product:add']">新增</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['mf:product:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改产品树对话框 -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="productRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="父产品id" prop="parentId">
<el-tree-select
v-model="form.parentId"
:data="productOptions"
:props="{ value: 'productId', label: 'productName', children: 'children' }"
value-key="productId"
placeholder="请选择父产品id"
check-strictly
/>
</el-form-item>
<el-form-item label="产品名称" prop="productName">
<el-input v-model="form.productName" placeholder="请输入产品名称" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
</el-form-item>
<el-form-item label="产品状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio
v-for="dict in sys_student_status"
:key="dict.value"
:label="dict.value"
>{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="Product">
import { listProduct, getProduct, delProduct, addProduct, updateProduct } from "@/api/mf/product";
const { proxy } = getCurrentInstance();
const { sys_student_status } = proxy.useDict('sys_student_status');
//
const productList = ref([]);
//
const productOptions = ref([]);
//
const open = ref(false);
//
const loading = ref(true);
//
const showSearch = ref(true);
//
const title = ref("");
//
const isExpandAll = ref(true);
//
const refreshTable = ref(true);
const data = reactive({
form: {},
queryParams: {
productName: null,
status: null,
},
rules: {
parentId: [
{ required: true, message: "父产品id不能为空", trigger: "blur" }
],
productName: [
{ required: true, message: "产品名称不能为空", trigger: "blur" }
],
orderNum: [
{ required: true, message: "显示顺序不能为空", trigger: "blur" }
],
status: [
{ required: true, message: "产品状态不能为空", trigger: "change" }
],
}
});
const { queryParams, form, rules } = toRefs(data);
/** 查询产品树列表 */
function getList() {
loading.value = true;
listProduct(queryParams.value).then(response => {
productList.value = proxy.handleTree(response.data, "productId", "parentId");
loading.value = false;
});
}
//
function cancel() {
open.value = false;
reset();
}
//
function reset() {
form.value = {
productId: null,
parentId: null,
productName: null,
orderNum: null,
status: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null
};
proxy.resetForm("productRef");
}
/** 搜索按钮操作 */
function handleQuery() {
getList();
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef");
handleQuery();
}
/** 新增按钮操作 */
async function handleAdd(row) {
reset();
await listProduct().then(response => {
productOptions.value = proxy.handleTree(response.data, "productId");
});
if (row != null && row.productId) {
form.value.parentId = row.productId;
} else {
form.value.parentId = 0;
}
open.value = true;
title.value = "添加产品树";
}
/** 展开/折叠操作 */
function toggleExpandAll() {
refreshTable.value = false;
isExpandAll.value = !isExpandAll.value;
nextTick(() => {
refreshTable.value = true;
});
}
/** 修改按钮操作 */
async function handleUpdate(row) {
reset();
await listProduct().then(response => {
productOptions.value = proxy.handleTree(response.data, "productId");
});
if (row != null) {
form.value.parentId = row.productId;
}
getProduct(row.productId).then(response => {
form.value = response.data;
open.value = true;
title.value = "修改产品树";
});
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["productRef"].validate(valid => {
if (valid) {
if (form.value.productId != null) {
updateProduct(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();
});
} else {
addProduct(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
open.value = false;
getList();
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
proxy.$modal.confirm('是否确认删除产品树编号为"' + row.productId + '"的数据项?').then(function() {
return delProduct(row.productId);
}).then(() => {
getList();
proxy.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
/** 导出按钮操作 */
function handleExport() {
proxy.download('mf/product/export', {
...queryParams.value
}, `product_${new Date().getTime()}.xlsx`)
}
getList();
</script>

View File

@ -0,0 +1,116 @@
package com.ruoyi.mf.controller;
import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.web.annotation.RepeatSubmit;
import com.ruoyi.common.web.core.BaseController;
import jakarta.annotation.Resource;
import com.ruoyi.mf.domain.vo.MfProductVo;
import com.ruoyi.mf.domain.bo.MfProductBo;
import com.ruoyi.mf.service.IMfProductService;
/**
* 产品树Controller
*
* @author 数据小王子
* 2023-11-23
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mf/product")
public class MfProductController extends BaseController
{
@Resource
private IMfProductService mfProductService;
/**
* 查询产品树列表
*/
@SaCheckPermission("mf:product:list")
@GetMapping("/list")
public R<List<MfProductVo>> list(MfProductBo mfProductBo)
{
List<MfProductVo> list = mfProductService.selectList(mfProductBo);
return R.ok(list);
}
/**
* 导出产品树列表
*/
@SaCheckPermission("mf:product:export")
@Log(title = "产品树", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, MfProductBo mfProductBo)
{
List<MfProductVo> list = mfProductService.selectList(mfProductBo);
ExcelUtil.exportExcel(list, "产品树", MfProductVo.class, response);
}
/**
* 获取产品树详细信息
*/
@SaCheckPermission("mf:product:query")
@GetMapping(value = "/{productId}")
public R<MfProductVo> getInfo(@PathVariable Long productId)
{
return R.ok(mfProductService.selectById(productId));
}
/**
* 新增产品树
*/
@SaCheckPermission("mf:product:add")
@Log(title = "产品树", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping
public R<Void> add(@Validated @RequestBody MfProductBo mfProductBo)
{
boolean inserted = mfProductService.insert(mfProductBo);
if (!inserted) {
return R.fail("新增产品树记录失败!");
}
return R.ok();
}
/**
* 修改产品树
*/
@SaCheckPermission("mf:product:edit")
@Log(title = "产品树", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping
public R<Void> edit(@Validated @RequestBody MfProductBo mfProductBo)
{
Boolean updated = mfProductService.update(mfProductBo);
if (!updated) {
R.fail("修改产品树记录失败!");
}
return R.ok();
}
/**
* 删除产品树
*/
@SaCheckPermission("mf:product:remove")
@Log(title = "产品树", businessType = BusinessType.DELETE)
@DeleteMapping("/{productIds}")
public R<Void> remove(@PathVariable Long[] productIds)
{
boolean deleted = mfProductService.deleteByIds(productIds);
if (!deleted) {
R.fail("删除产品树记录失败!");
}
return R.ok();
}
}

View File

@ -0,0 +1,30 @@
package com.ruoyi.mf.domain;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.ruoyi.common.orm.core.domain.TreeEntity;
/**
* 产品树对象 mf_product
*
* @author 数据小王子
* 2023-11-23
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "mf_product")
public class MfProduct extends TreeEntity
{
/** 产品id */
@Id
private Long productId;
/** 产品名称 */
private String productName;
/** 产品状态0正常 1停用 */
private String status;
}

View File

@ -0,0 +1,40 @@
package com.ruoyi.mf.domain.bo;
import com.ruoyi.mf.domain.MfProduct;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import com.ruoyi.common.orm.core.domain.TreeEntity;
/**
* 产品树业务对象 mf_product
*
* @author 数据小王子
* @date 2023-11-23
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MfProduct.class, reverseConvertGenerate = false)
public class MfProductBo extends TreeEntity
{
/**
* 产品id
*/
private Long productId;
/**
* 产品名称
*/
@NotBlank(message = "产品名称不能为空")
private String productName;
/**
* 产品状态0正常 1停用
*/
@NotBlank(message = "产品状态0正常 1停用不能为空")
private String status;
}

View File

@ -0,0 +1,46 @@
package com.ruoyi.mf.domain.vo;
import com.ruoyi.mf.domain.MfProduct;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.common.excel.annotation.ExcelDictFormat;
import com.ruoyi.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import com.ruoyi.common.orm.core.domain.TreeEntity;
/**
* 产品树视图对象 mf_product
*
* @author 数据小王子
* @date 2023-11-23
*/
@Data
@ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MfProduct.class)
public class MfProductVo extends TreeEntity implements Serializable
{
@Serial
private static final long serialVersionUID = 1L;
/** 产品id */
@ExcelProperty(value = "产品id")
private Long productId;
/** 产品名称 */
@ExcelProperty(value = "产品名称")
private String productName;
/** 产品状态0正常 1停用 */
@ExcelProperty(value = "产品状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(dictType = "sys_student_status")
private String status;
}

View File

@ -14,6 +14,7 @@ import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import com.ruoyi.common.orm.core.domain.BaseEntity;
import lombok.EqualsAndHashCode;
/**
@ -24,6 +25,7 @@ import com.ruoyi.common.orm.core.domain.BaseEntity;
*/
@Data
@ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MfStudent.class)
public class MfStudentVo extends BaseEntity implements Serializable
{

View File

@ -0,0 +1,17 @@
package com.ruoyi.mf.mapper;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.ruoyi.mf.domain.MfProduct;
/**
* 产品树Mapper接口
*
* @author 数据小王子
* 2023-11-23
*/
@Mapper
public interface MfProductMapper extends BaseMapper<MfProduct>
{
}

View File

@ -0,0 +1,58 @@
package com.ruoyi.mf.service;
import java.util.List;
import com.ruoyi.mf.domain.MfProduct;
import com.ruoyi.mf.domain.vo.MfProductVo;
import com.ruoyi.mf.domain.bo.MfProductBo;
import com.ruoyi.common.orm.core.service.IBaseService;
/**
* 产品树Service接口
*
* @author 数据小王子
* 2023-11-23
*/
public interface IMfProductService extends IBaseService<MfProduct>
{
/**
* 查询产品树
*
* @param productId 产品树主键
* @return 产品树
*/
MfProductVo selectById(Long productId);
/**
* 查询产品树列表
*
* @param mfProductBo 产品树Bo
* @return 产品树集合
*/
List<MfProductVo> selectList(MfProductBo mfProductBo);
/**
* 新增产品树
*
* @param mfProductBo 产品树Bo
* @return 结果:true 操作成功false 操作失败
*/
boolean insert(MfProductBo mfProductBo);
/**
* 修改产品树
*
* @param mfProductBo 产品树Bo
* @return 结果:true 更新成功false 更新失败
*/
boolean update(MfProductBo mfProductBo);
/**
* 批量删除产品树
*
* @param productIds 需要删除的产品树主键集合
* @return 结果:true 删除成功false 删除失败
*/
boolean deleteByIds(Long[] productIds);
}

View File

@ -0,0 +1,127 @@
package com.ruoyi.mf.service.impl;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import cn.hutool.core.util.ObjectUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.orm.core.page.PageQuery;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.mf.mapper.MfProductMapper;
import com.ruoyi.mf.domain.MfProduct;
import com.ruoyi.mf.domain.bo.MfProductBo;
import com.ruoyi.mf.domain.vo.MfProductVo;
import com.ruoyi.mf.service.IMfProductService;
import static com.ruoyi.mf.domain.table.MfProductTableDef.MF_PRODUCT;
/**
* 产品树Service业务层处理
*
* @author 数据小王子
* 2023-11-23
*/
@Service
public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfProduct> implements IMfProductService
{
@Resource
private MfProductMapper mfProductMapper;
@Override
public QueryWrapper query() {
return super.query().from(MF_PRODUCT);
}
private QueryWrapper buildQueryWrapper(MfProductBo mfProductBo) {
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
if (StringUtils.isNotBlank(mfProductBo.getProductName())) {
queryWrapper.and(MF_PRODUCT.PRODUCT_NAME.like(mfProductBo.getProductName()));
}
if (mfProductBo.getOrderNum() != null) {
queryWrapper.and(MF_PRODUCT.ORDER_NUM.eq(mfProductBo.getOrderNum()));
}
if (StringUtils.isNotBlank(mfProductBo.getStatus())) {
queryWrapper.and(MF_PRODUCT.STATUS.eq(mfProductBo.getStatus()));
}
return queryWrapper;
}
/**
* 查询产品树
*
* @param productId 产品树主键
* @return 产品树
*/
@Override
public MfProductVo selectById(Long productId)
{
return this.getOneAs(query().where(MF_PRODUCT.PRODUCT_ID.eq(productId)), MfProductVo.class);
}
/**
* 查询产品树列表
*
* @param mfProductBo 产品树Bo
* @return 产品树集合
*/
@Override
public List<MfProductVo> selectList(MfProductBo mfProductBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(mfProductBo);
return this.listAs(queryWrapper, MfProductVo.class);
}
/**
* 新增产品树
*
* @param mfProductBo 产品树Bo
* @return 结果:true 操作成功false 操作失败
*/
@Override
public boolean insert(MfProductBo mfProductBo)
{
MfProduct mfProduct = MapstructUtils.convert(mfProductBo, MfProduct.class);
return this.save(mfProduct);//使用全局配置的雪花算法主键生成器生成ID值
}
/**
* 修改产品树
*
* @param mfProductBo 产品树Bo
* @return 结果:true 更新成功false 更新失败
*/
@Override
public boolean update(MfProductBo mfProductBo)
{
MfProduct mfProduct = MapstructUtils.convert(mfProductBo, MfProduct.class);
boolean updated = this.updateById(mfProduct);
return updated;
}
/**
* 批量删除产品树
*
* @param productIds 需要删除的产品树主键集合
* @return 结果:true 删除成功false 删除失败
*/
@Transactional
@Override
public boolean deleteByIds(Long[] productIds)
{
return this.removeByIds(Arrays.asList(productIds));
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.mf.mapper.MfProductMapper">
</mapper>