完美兼容RuoYi-Vue代码生成,生成的树表mybatis代码运行正常
This commit is contained in:
parent
5b84e109bf
commit
d6df81b326
@ -0,0 +1,102 @@
|
|||||||
|
package com.ruoyi.demo.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import jakarta.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.demo.domain.DemoProduct;
|
||||||
|
import com.ruoyi.demo.service.IDemoProductService;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品树表(mb)Controller
|
||||||
|
*
|
||||||
|
* @author 数据小王子
|
||||||
|
* @date 2023-07-09
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/demo/product")
|
||||||
|
public class DemoProductController extends BaseController
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private IDemoProductService demoProductService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询产品树表(mb)列表
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('demo:product:list')")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public AjaxResult list(DemoProduct demoProduct)
|
||||||
|
{
|
||||||
|
List<DemoProduct> list = demoProductService.selectDemoProductList(demoProduct);
|
||||||
|
return success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出产品树表(mb)列表
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('demo:product:export')")
|
||||||
|
@Log(title = "产品树表(mb)", businessType = BusinessType.EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response, DemoProduct demoProduct)
|
||||||
|
{
|
||||||
|
List<DemoProduct> list = demoProductService.selectDemoProductList(demoProduct);
|
||||||
|
ExcelUtil<DemoProduct> util = new ExcelUtil<DemoProduct>(DemoProduct.class);
|
||||||
|
util.exportExcel(response, list, "产品树表(mb)数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取产品树表(mb)详细信息
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('demo:product:query')")
|
||||||
|
@GetMapping(value = "/{productId}")
|
||||||
|
public AjaxResult getInfo(@PathVariable("productId") Long productId)
|
||||||
|
{
|
||||||
|
return success(demoProductService.selectDemoProductByProductId(productId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增产品树表(mb)
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('demo:product:add')")
|
||||||
|
@Log(title = "产品树表(mb)", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public AjaxResult add(@RequestBody DemoProduct demoProduct)
|
||||||
|
{
|
||||||
|
return toAjax(demoProductService.insertDemoProduct(demoProduct));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改产品树表(mb)
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('demo:product:edit')")
|
||||||
|
@Log(title = "产品树表(mb)", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public AjaxResult edit(@RequestBody DemoProduct demoProduct)
|
||||||
|
{
|
||||||
|
return toAjax(demoProductService.updateDemoProduct(demoProduct));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除产品树表(mb)
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('demo:product:remove')")
|
||||||
|
@Log(title = "产品树表(mb)", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{productIds}")
|
||||||
|
public AjaxResult remove(@PathVariable Long[] productIds)
|
||||||
|
{
|
||||||
|
return toAjax(demoProductService.deleteDemoProductByProductIds(productIds));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.ruoyi.demo.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.TreeEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品树表(mb)对象 demo_product
|
||||||
|
*
|
||||||
|
* @author 数据小王子
|
||||||
|
* @date 2023-07-09
|
||||||
|
*/
|
||||||
|
public class DemoProduct extends TreeEntity
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 产品id */
|
||||||
|
private Long productId;
|
||||||
|
|
||||||
|
/** 产品名称 */
|
||||||
|
@Excel(name = "产品名称")
|
||||||
|
private String productName;
|
||||||
|
|
||||||
|
/** 产品状态(0正常 1停用) */
|
||||||
|
@Excel(name = "产品状态", readConverterExp = "0=正常,1=停用")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
public void setProductId(Long productId)
|
||||||
|
{
|
||||||
|
this.productId = productId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getProductId()
|
||||||
|
{
|
||||||
|
return productId;
|
||||||
|
}
|
||||||
|
public void setProductName(String productName)
|
||||||
|
{
|
||||||
|
this.productName = productName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProductName()
|
||||||
|
{
|
||||||
|
return productName;
|
||||||
|
}
|
||||||
|
public void setStatus(String status)
|
||||||
|
{
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus()
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("productId", getProductId())
|
||||||
|
.append("parentId", getParentId())
|
||||||
|
.append("productName", getProductName())
|
||||||
|
.append("orderNum", getOrderNum())
|
||||||
|
.append("status", getStatus())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.demo.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.ruoyi.demo.domain.DemoProduct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品树表(mb)Mapper接口
|
||||||
|
*
|
||||||
|
* @author 数据小王子
|
||||||
|
* @date 2023-07-09
|
||||||
|
*/
|
||||||
|
public interface DemoProductMapper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param productId 产品树表(mb)主键
|
||||||
|
* @return 产品树表(mb)
|
||||||
|
*/
|
||||||
|
public DemoProduct selectDemoProductByProductId(Long productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询产品树表(mb)列表
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 产品树表(mb)集合
|
||||||
|
*/
|
||||||
|
public List<DemoProduct> selectDemoProductList(DemoProduct demoProduct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertDemoProduct(DemoProduct demoProduct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateDemoProduct(DemoProduct demoProduct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param productId 产品树表(mb)主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteDemoProductByProductId(Long productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param productIds 需要删除的数据主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteDemoProductByProductIds(Long[] productIds);
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.demo.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.ruoyi.demo.domain.DemoProduct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品树表(mb)Service接口
|
||||||
|
*
|
||||||
|
* @author 数据小王子
|
||||||
|
* @date 2023-07-09
|
||||||
|
*/
|
||||||
|
public interface IDemoProductService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param productId 产品树表(mb)主键
|
||||||
|
* @return 产品树表(mb)
|
||||||
|
*/
|
||||||
|
public DemoProduct selectDemoProductByProductId(Long productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询产品树表(mb)列表
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 产品树表(mb)集合
|
||||||
|
*/
|
||||||
|
public List<DemoProduct> selectDemoProductList(DemoProduct demoProduct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertDemoProduct(DemoProduct demoProduct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateDemoProduct(DemoProduct demoProduct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param productIds 需要删除的产品树表(mb)主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteDemoProductByProductIds(Long[] productIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除产品树表(mb)信息
|
||||||
|
*
|
||||||
|
* @param productId 产品树表(mb)主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteDemoProductByProductId(Long productId);
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
package com.ruoyi.demo.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.ruoyi.demo.mapper.DemoProductMapper;
|
||||||
|
import com.ruoyi.demo.domain.DemoProduct;
|
||||||
|
import com.ruoyi.demo.service.IDemoProductService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品树表(mb)Service业务层处理
|
||||||
|
*
|
||||||
|
* @author 数据小王子
|
||||||
|
* @date 2023-07-09
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DemoProductServiceImpl implements IDemoProductService
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private DemoProductMapper demoProductMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param productId 产品树表(mb)主键
|
||||||
|
* @return 产品树表(mb)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DemoProduct selectDemoProductByProductId(Long productId)
|
||||||
|
{
|
||||||
|
return demoProductMapper.selectDemoProductByProductId(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询产品树表(mb)列表
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 产品树表(mb)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DemoProduct> selectDemoProductList(DemoProduct demoProduct)
|
||||||
|
{
|
||||||
|
return demoProductMapper.selectDemoProductList(demoProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int insertDemoProduct(DemoProduct demoProduct)
|
||||||
|
{
|
||||||
|
return demoProductMapper.insertDemoProduct(demoProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param demoProduct 产品树表(mb)
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int updateDemoProduct(DemoProduct demoProduct)
|
||||||
|
{
|
||||||
|
return demoProductMapper.updateDemoProduct(demoProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除产品树表(mb)
|
||||||
|
*
|
||||||
|
* @param productIds 需要删除的产品树表(mb)主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteDemoProductByProductIds(Long[] productIds)
|
||||||
|
{
|
||||||
|
return demoProductMapper.deleteDemoProductByProductIds(productIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除产品树表(mb)信息
|
||||||
|
*
|
||||||
|
* @param productId 产品树表(mb)主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteDemoProductByProductId(Long productId)
|
||||||
|
{
|
||||||
|
return demoProductMapper.deleteDemoProductByProductId(productId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
<?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.demo.mapper.DemoProductMapper">
|
||||||
|
|
||||||
|
<resultMap type="DemoProduct" id="DemoProductResult">
|
||||||
|
<result property="productId" column="product_id" />
|
||||||
|
<result property="parentId" column="parent_id" />
|
||||||
|
<result property="productName" column="product_name" />
|
||||||
|
<result property="orderNum" column="order_num" />
|
||||||
|
<result property="status" column="status" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectDemoProductVo">
|
||||||
|
select product_id, parent_id, product_name, order_num, status from demo_product
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectDemoProductList" parameterType="DemoProduct" resultMap="DemoProductResult">
|
||||||
|
<include refid="selectDemoProductVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="productName != null and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
|
||||||
|
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectDemoProductByProductId" parameterType="Long" resultMap="DemoProductResult">
|
||||||
|
<include refid="selectDemoProductVo"/>
|
||||||
|
where product_id = #{productId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertDemoProduct" parameterType="DemoProduct" useGeneratedKeys="true" keyProperty="productId">
|
||||||
|
insert into demo_product
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="parentId != null">parent_id,</if>
|
||||||
|
<if test="productName != null">product_name,</if>
|
||||||
|
<if test="orderNum != null">order_num,</if>
|
||||||
|
<if test="status != null">status,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="parentId != null">#{parentId},</if>
|
||||||
|
<if test="productName != null">#{productName},</if>
|
||||||
|
<if test="orderNum != null">#{orderNum},</if>
|
||||||
|
<if test="status != null">#{status},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateDemoProduct" parameterType="DemoProduct">
|
||||||
|
update demo_product
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="parentId != null">parent_id = #{parentId},</if>
|
||||||
|
<if test="productName != null">product_name = #{productName},</if>
|
||||||
|
<if test="orderNum != null">order_num = #{orderNum},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
|
</trim>
|
||||||
|
where product_id = #{productId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteDemoProductByProductId" parameterType="Long">
|
||||||
|
delete from demo_product where product_id = #{productId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteDemoProductByProductIds" parameterType="String">
|
||||||
|
delete from demo_product where product_id in
|
||||||
|
<foreach item="productId" collection="array" open="(" separator="," close=")">
|
||||||
|
#{productId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
44
ruoyi-ui/src/api/demo/product.js
Normal file
44
ruoyi-ui/src/api/demo/product.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 查询产品树表(mb)列表
|
||||||
|
export function listProduct(query) {
|
||||||
|
return request({
|
||||||
|
url: '/demo/product/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询产品树表(mb)详细
|
||||||
|
export function getProduct(productId) {
|
||||||
|
return request({
|
||||||
|
url: '/demo/product/' + productId,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增产品树表(mb)
|
||||||
|
export function addProduct(data) {
|
||||||
|
return request({
|
||||||
|
url: '/demo/product',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改产品树表(mb)
|
||||||
|
export function updateProduct(data) {
|
||||||
|
return request({
|
||||||
|
url: '/demo/product',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除产品树表(mb)
|
||||||
|
export function delProduct(productId) {
|
||||||
|
return request({
|
||||||
|
url: '/demo/product/' + productId,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
285
ruoyi-ui/src/views/demo/product/index.vue
Normal file
285
ruoyi-ui/src/views/demo/product/index.vue
Normal file
@ -0,0 +1,285 @@
|
|||||||
|
<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="productName">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.productName"
|
||||||
|
placeholder="请输入产品名称"
|
||||||
|
clearable
|
||||||
|
@keyup.enter.native="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="产品状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="请选择产品状态" clearable>
|
||||||
|
<el-option
|
||||||
|
v-for="dict in dict.type.sys_common_status"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</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="['demo:product:add']"
|
||||||
|
>新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
type="info"
|
||||||
|
plain
|
||||||
|
icon="el-icon-sort"
|
||||||
|
size="mini"
|
||||||
|
@click="toggleExpandAll"
|
||||||
|
>展开/折叠</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar :showSearch.sync="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="status">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<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="['demo:product:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
size="mini"
|
||||||
|
type="text"
|
||||||
|
icon="el-icon-plus"
|
||||||
|
@click="handleAdd(scope.row)"
|
||||||
|
v-hasPermi="['demo:product:add']"
|
||||||
|
>新增</el-button>
|
||||||
|
<el-button
|
||||||
|
size="mini"
|
||||||
|
type="text"
|
||||||
|
icon="el-icon-delete"
|
||||||
|
@click="handleDelete(scope.row)"
|
||||||
|
v-hasPermi="['demo:product:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<!-- 添加或修改产品树表(mb)对话框 -->
|
||||||
|
<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="父产品id" prop="parentId">
|
||||||
|
<treeselect v-model="form.parentId" :options="productOptions" :normalizer="normalizer" placeholder="请选择父产品id" />
|
||||||
|
</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-select v-model="form.status" placeholder="请选择产品状态">
|
||||||
|
<el-option
|
||||||
|
v-for="dict in dict.type.sys_common_status"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
></el-option>
|
||||||
|
</el-select>
|
||||||
|
</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 { listProduct, getProduct, delProduct, addProduct, updateProduct } from "@/api/demo/product";
|
||||||
|
import Treeselect from "@riophae/vue-treeselect";
|
||||||
|
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "Product",
|
||||||
|
dicts: ['sys_common_status'],
|
||||||
|
components: {
|
||||||
|
Treeselect
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 遮罩层
|
||||||
|
loading: true,
|
||||||
|
// 显示搜索条件
|
||||||
|
showSearch: true,
|
||||||
|
// 产品树表(mb)表格数据
|
||||||
|
productList: [],
|
||||||
|
// 产品树表(mb)树选项
|
||||||
|
productOptions: [],
|
||||||
|
// 弹出层标题
|
||||||
|
title: "",
|
||||||
|
// 是否显示弹出层
|
||||||
|
open: false,
|
||||||
|
// 是否展开,默认全部展开
|
||||||
|
isExpandAll: true,
|
||||||
|
// 重新渲染表格状态
|
||||||
|
refreshTable: true,
|
||||||
|
// 查询参数
|
||||||
|
queryParams: {
|
||||||
|
productName: null,
|
||||||
|
status: null
|
||||||
|
},
|
||||||
|
// 表单参数
|
||||||
|
form: {},
|
||||||
|
// 表单校验
|
||||||
|
rules: {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/** 查询产品树表(mb)列表 */
|
||||||
|
getList() {
|
||||||
|
this.loading = true;
|
||||||
|
listProduct(this.queryParams).then(response => {
|
||||||
|
this.productList = this.handleTree(response.data, "productId", "parentId");
|
||||||
|
this.loading = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 转换产品树表(mb)数据结构 */
|
||||||
|
normalizer(node) {
|
||||||
|
if (node.children && !node.children.length) {
|
||||||
|
delete node.children;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id: node.productId,
|
||||||
|
label: node.productName,
|
||||||
|
children: node.children
|
||||||
|
};
|
||||||
|
},
|
||||||
|
/** 查询产品树表(mb)下拉树结构 */
|
||||||
|
getTreeselect() {
|
||||||
|
listProduct().then(response => {
|
||||||
|
this.productOptions = [];
|
||||||
|
const data = { productId: 0, productName: '顶级节点', children: [] };
|
||||||
|
data.children = this.handleTree(response.data, "productId", "parentId");
|
||||||
|
this.productOptions.push(data);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 取消按钮
|
||||||
|
cancel() {
|
||||||
|
this.open = false;
|
||||||
|
this.reset();
|
||||||
|
},
|
||||||
|
// 表单重置
|
||||||
|
reset() {
|
||||||
|
this.form = {
|
||||||
|
productId: null,
|
||||||
|
parentId: null,
|
||||||
|
productName: null,
|
||||||
|
orderNum: null,
|
||||||
|
status: null
|
||||||
|
};
|
||||||
|
this.resetForm("form");
|
||||||
|
},
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
handleQuery() {
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
resetQuery() {
|
||||||
|
this.resetForm("queryForm");
|
||||||
|
this.handleQuery();
|
||||||
|
},
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
handleAdd(row) {
|
||||||
|
this.reset();
|
||||||
|
this.getTreeselect();
|
||||||
|
if (row != null && row.productId) {
|
||||||
|
this.form.parentId = row.productId;
|
||||||
|
} else {
|
||||||
|
this.form.parentId = 0;
|
||||||
|
}
|
||||||
|
this.open = true;
|
||||||
|
this.title = "添加产品树表(mb)";
|
||||||
|
},
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
toggleExpandAll() {
|
||||||
|
this.refreshTable = false;
|
||||||
|
this.isExpandAll = !this.isExpandAll;
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.refreshTable = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 修改按钮操作 */
|
||||||
|
handleUpdate(row) {
|
||||||
|
this.reset();
|
||||||
|
this.getTreeselect();
|
||||||
|
if (row != null) {
|
||||||
|
this.form.parentId = row.productId;
|
||||||
|
}
|
||||||
|
getProduct(row.productId).then(response => {
|
||||||
|
this.form = response.data;
|
||||||
|
this.open = true;
|
||||||
|
this.title = "修改产品树表(mb)";
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 提交按钮 */
|
||||||
|
submitForm() {
|
||||||
|
this.$refs["form"].validate(valid => {
|
||||||
|
if (valid) {
|
||||||
|
if (this.form.productId != null) {
|
||||||
|
updateProduct(this.form).then(response => {
|
||||||
|
this.$modal.msgSuccess("修改成功");
|
||||||
|
this.open = false;
|
||||||
|
this.getList();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
addProduct(this.form).then(response => {
|
||||||
|
this.$modal.msgSuccess("新增成功");
|
||||||
|
this.open = false;
|
||||||
|
this.getList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
handleDelete(row) {
|
||||||
|
this.$modal.confirm('是否确认删除产品树表(mb)编号为"' + row.productId + '"的数据项?').then(function() {
|
||||||
|
return delProduct(row.productId);
|
||||||
|
}).then(() => {
|
||||||
|
this.getList();
|
||||||
|
this.$modal.msgSuccess("删除成功");
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -35,9 +35,38 @@ values('学生信息单表(mb)删除', @parentId, '4', '#', '', 1, 0, 'F', '0',
|
|||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('学生信息单表(mb)导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', 'demo:student:export', '#', 'admin', sysdate(), '', null, '');
|
values('学生信息单表(mb)导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', 'demo:student:export', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
|
-- 树表 demo_product 结构定义
|
||||||
|
CREATE TABLE IF NOT EXISTS `demo_product` (
|
||||||
|
`product_id` bigint NOT NULL AUTO_INCREMENT COMMENT '产品id',
|
||||||
|
`parent_id` bigint DEFAULT '0' COMMENT '父产品id',
|
||||||
|
`product_name` varchar(30) COLLATE utf8mb4_bin DEFAULT '' COMMENT '产品名称',
|
||||||
|
`order_num` int DEFAULT '0' COMMENT '显示顺序',
|
||||||
|
`status` char(1) COLLATE utf8mb4_bin DEFAULT '0' COMMENT '产品状态(0正常 1停用)',
|
||||||
|
PRIMARY KEY (`product_id`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='产品表';
|
||||||
|
|
||||||
|
-- 产品树表(mb)菜单 SQL
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('产品树表(mb)', '2018', '1', 'product', 'demo/product/index', 1, 0, 'C', '0', '0', 'demo:product:list', '#', 'admin', sysdate(), '', null, '产品树表(mb)菜单');
|
||||||
|
-- 按钮父菜单ID
|
||||||
|
SELECT @parentId := LAST_INSERT_ID();
|
||||||
|
-- 按钮 SQL
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('产品树表(mb)查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', 'demo:product:query', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('产品树表(mb)新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', 'demo:product:add', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('产品树表(mb)修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', 'demo:product:edit', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('产品树表(mb)删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', 'demo:product:remove', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values('产品树表(mb)导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', 'demo:product:export', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
|
|
||||||
-- 插入gen_table数据
|
-- 插入gen_table数据
|
||||||
INSERT INTO `gen_table` (`table_id`, `table_name`, `table_comment`, `sub_table_name`, `sub_table_fk_name`, `class_name`, `tpl_category`, `package_name`, `module_name`, `business_name`, `function_name`, `function_author`, `gen_type`, `gen_path`, `options`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES
|
INSERT INTO `gen_table` (`table_id`, `table_name`, `table_comment`, `sub_table_name`, `sub_table_fk_name`, `class_name`, `tpl_category`, `package_name`, `module_name`, `business_name`, `function_name`, `function_author`, `gen_type`, `gen_path`, `options`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES
|
||||||
(1, 'demo_student', '学生信息表', NULL, NULL, 'DemoStudent', 'crud', 'com.ruoyi.demo', 'demo', 'student', '学生信息单表(mb)', '数据小王子', '0', '/', '{"parentMenuId":"2018"}', 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53', '生成mybatis语法单表代码');
|
(1, 'demo_student', '学生信息表', NULL, NULL, 'DemoStudent', 'crud', 'com.ruoyi.demo', 'demo', 'student', '学生信息单表(mb)', '数据小王子', '0', '/', '{"parentMenuId":"2018"}', 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53', '生成mybatis语法单表代码'),
|
||||||
|
(2, 'demo_product', '产品树表', '', '', 'DemoProduct', 'tree', 'com.ruoyi.demo', 'demo', 'product', '产品树表(mb)', '数据小王子', '0', '/', '{"treeCode":"product_id","treeName":"product_name","treeParentCode":"parent_id","parentMenuId":"2018"}', 'admin', '2023-06-04 21:22:27', '', '2023-07-09 20:56:08', '生成mybatis语法树表代码');
|
||||||
|
|
||||||
-- 插入gen_table_column数据
|
-- 插入gen_table_column数据
|
||||||
INSERT INTO `gen_table_column` (`column_id`, `table_id`, `column_name`, `column_comment`, `column_type`, `java_type`, `java_field`, `is_pk`, `is_increment`, `is_required`, `is_insert`, `is_edit`, `is_list`, `is_query`, `query_type`, `html_type`, `dict_type`, `sort`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES
|
INSERT INTO `gen_table_column` (`column_id`, `table_id`, `column_name`, `column_comment`, `column_type`, `java_type`, `java_field`, `is_pk`, `is_increment`, `is_required`, `is_insert`, `is_edit`, `is_list`, `is_query`, `query_type`, `html_type`, `dict_type`, `sort`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES
|
||||||
@ -47,7 +76,12 @@ INSERT INTO `gen_table_column` (`column_id`, `table_id`, `column_name`, `column_
|
|||||||
(4, 1, 'student_hobby', '爱好(0代码 1音乐 2电影)', 'varchar(30)', 'String', 'studentHobby', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'select', 'sys_student_hobby', 4, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53'),
|
(4, 1, 'student_hobby', '爱好(0代码 1音乐 2电影)', 'varchar(30)', 'String', 'studentHobby', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'select', 'sys_student_hobby', 4, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53'),
|
||||||
(5, 1, 'student_sex', '性别(1男 2女 3未知)', 'char(1)', 'String', 'studentSex', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'select', 'sys_user_sex', 5, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53'),
|
(5, 1, 'student_sex', '性别(1男 2女 3未知)', 'char(1)', 'String', 'studentSex', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'select', 'sys_user_sex', 5, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53'),
|
||||||
(6, 1, 'student_status', '状态(0正常 1停用)', 'char(1)', 'String', 'studentStatus', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'radio', 'sys_student_status', 6, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53'),
|
(6, 1, 'student_status', '状态(0正常 1停用)', 'char(1)', 'String', 'studentStatus', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'radio', 'sys_student_status', 6, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53'),
|
||||||
(7, 1, 'student_birthday', '生日', 'datetime', 'Date', 'studentBirthday', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'datetime', '', 7, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53');
|
(7, 1, 'student_birthday', '生日', 'datetime', 'Date', 'studentBirthday', '0', '0', '1', '1', '1', '1', '0', 'EQ', 'datetime', '', 7, 'admin', '2023-06-03 21:44:19', '', '2023-07-09 12:14:53'),
|
||||||
|
(8, 2, 'product_id', '产品id', 'bigint', 'Long', 'productId', '1', '1', NULL, '1', NULL, NULL, NULL, 'EQ', 'input', '', 1, 'admin', '2023-06-04 21:22:27', '', '2023-07-09 20:56:08'),
|
||||||
|
(9, 2, 'parent_id', '父产品id', 'bigint', 'Long', 'parentId', '0', '0', NULL, '1', '1', '0', '0', 'EQ', 'input', '', 2, 'admin', '2023-06-04 21:22:27', '', '2023-07-09 20:56:08'),
|
||||||
|
(10, 2, 'product_name', '产品名称', 'varchar(30)', 'String', 'productName', '0', '0', NULL, '1', '1', '1', '1', 'LIKE', 'input', '', 3, 'admin', '2023-06-04 21:22:27', '', '2023-07-09 20:56:08'),
|
||||||
|
(11, 2, 'order_num', '显示顺序', 'int', 'Long', 'orderNum', '0', '0', NULL, '1', '1', '0', '0', 'EQ', 'input', '', 4, 'admin', '2023-06-04 21:22:27', '', '2023-07-09 20:56:08'),
|
||||||
|
(12, 2, 'status', '产品状态(0正常 1停用)', 'char(1)', 'String', 'status', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'select', 'sys_common_status', 5, 'admin', '2023-06-04 21:22:27', '', '2023-07-09 20:56:08');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user