完美兼容RuoYi-Vue代码生成,生成的主子表mybatis代码运行正常

This commit is contained in:
dataprince 2023-07-11 16:48:26 +08:00
parent d6df81b326
commit 88d1974e2b
10 changed files with 1227 additions and 2 deletions

View File

@ -0,0 +1,104 @@
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.DemoCustomer;
import com.ruoyi.demo.service.IDemoCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 客户主表(mb)Controller
*
* @author 数据小王子
* @date 2023-07-11
*/
@RestController
@RequestMapping("/demo/customer")
public class DemoCustomerController extends BaseController
{
@Autowired
private IDemoCustomerService demoCustomerService;
/**
* 查询客户主表(mb)列表
*/
@PreAuthorize("@ss.hasPermi('demo:customer:list')")
@GetMapping("/list")
public TableDataInfo list(DemoCustomer demoCustomer)
{
startPage();
List<DemoCustomer> list = demoCustomerService.selectDemoCustomerList(demoCustomer);
return getDataTable(list);
}
/**
* 导出客户主表(mb)列表
*/
@PreAuthorize("@ss.hasPermi('demo:customer:export')")
@Log(title = "客户主表(mb)", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, DemoCustomer demoCustomer)
{
List<DemoCustomer> list = demoCustomerService.selectDemoCustomerList(demoCustomer);
ExcelUtil<DemoCustomer> util = new ExcelUtil<DemoCustomer>(DemoCustomer.class);
util.exportExcel(response, list, "客户主表(mb)数据");
}
/**
* 获取客户主表(mb)详细信息
*/
@PreAuthorize("@ss.hasPermi('demo:customer:query')")
@GetMapping(value = "/{customerId}")
public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
{
return success(demoCustomerService.selectDemoCustomerByCustomerId(customerId));
}
/**
* 新增客户主表(mb)
*/
@PreAuthorize("@ss.hasPermi('demo:customer:add')")
@Log(title = "客户主表(mb)", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DemoCustomer demoCustomer)
{
return toAjax(demoCustomerService.insertDemoCustomer(demoCustomer));
}
/**
* 修改客户主表(mb)
*/
@PreAuthorize("@ss.hasPermi('demo:customer:edit')")
@Log(title = "客户主表(mb)", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DemoCustomer demoCustomer)
{
return toAjax(demoCustomerService.updateDemoCustomer(demoCustomer));
}
/**
* 删除客户主表(mb)
*/
@PreAuthorize("@ss.hasPermi('demo:customer:remove')")
@Log(title = "客户主表(mb)", businessType = BusinessType.DELETE)
@DeleteMapping("/{customerIds}")
public AjaxResult remove(@PathVariable Long[] customerIds)
{
return toAjax(demoCustomerService.deleteDemoCustomerByCustomerIds(customerIds));
}
}

View File

@ -0,0 +1,112 @@
package com.ruoyi.demo.domain;
import java.util.List;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
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;
/**
* 客户主表(mb)对象 demo_customer
*
* @author 数据小王子
* @date 2023-07-11
*/
public class DemoCustomer extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 客户id */
private Long customerId;
/** 客户姓名 */
@Excel(name = "客户姓名")
private String customerName;
/** 手机号码 */
@Excel(name = "手机号码")
private String phonenumber;
/** 客户性别 */
@Excel(name = "客户性别")
private String sex;
/** 客户生日 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "客户生日", width = 30, dateFormat = "yyyy-MM-dd")
private Date birthday;
/** 商品子信息 */
private List<DemoGoods> demoGoodsList;
public void setCustomerId(Long customerId)
{
this.customerId = customerId;
}
public Long getCustomerId()
{
return customerId;
}
public void setCustomerName(String customerName)
{
this.customerName = customerName;
}
public String getCustomerName()
{
return customerName;
}
public void setPhonenumber(String phonenumber)
{
this.phonenumber = phonenumber;
}
public String getPhonenumber()
{
return phonenumber;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getSex()
{
return sex;
}
public void setBirthday(Date birthday)
{
this.birthday = birthday;
}
public Date getBirthday()
{
return birthday;
}
public List<DemoGoods> getDemoGoodsList()
{
return demoGoodsList;
}
public void setDemoGoodsList(List<DemoGoods> demoGoodsList)
{
this.demoGoodsList = demoGoodsList;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("customerId", getCustomerId())
.append("customerName", getCustomerName())
.append("phonenumber", getPhonenumber())
.append("sex", getSex())
.append("birthday", getBirthday())
.append("remark", getRemark())
.append("demoGoodsList", getDemoGoodsList())
.toString();
}
}

View File

@ -0,0 +1,125 @@
package com.ruoyi.demo.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
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;
/**
* 商品子对象 demo_goods
*
* @author 数据小王子
* @date 2023-07-11
*/
public class DemoGoods extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 商品id */
private Long goodsId;
/** 客户id */
@Excel(name = "客户id")
private Long customerId;
/** 商品名称 */
@Excel(name = "商品名称")
private String name;
/** 商品重量 */
@Excel(name = "商品重量")
private Long weight;
/** 商品价格 */
@Excel(name = "商品价格")
private BigDecimal price;
/** 商品时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "商品时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date date;
/** 商品种类 */
@Excel(name = "商品种类")
private String type;
public void setGoodsId(Long goodsId)
{
this.goodsId = goodsId;
}
public Long getGoodsId()
{
return goodsId;
}
public void setCustomerId(Long customerId)
{
this.customerId = customerId;
}
public Long getCustomerId()
{
return customerId;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setWeight(Long weight)
{
this.weight = weight;
}
public Long getWeight()
{
return weight;
}
public void setPrice(BigDecimal price)
{
this.price = price;
}
public BigDecimal getPrice()
{
return price;
}
public void setDate(Date date)
{
this.date = date;
}
public Date getDate()
{
return date;
}
public void setType(String type)
{
this.type = type;
}
public String getType()
{
return type;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("goodsId", getGoodsId())
.append("customerId", getCustomerId())
.append("name", getName())
.append("weight", getWeight())
.append("price", getPrice())
.append("date", getDate())
.append("type", getType())
.toString();
}
}

View File

@ -0,0 +1,87 @@
package com.ruoyi.demo.mapper;
import java.util.List;
import com.ruoyi.demo.domain.DemoCustomer;
import com.ruoyi.demo.domain.DemoGoods;
/**
* 客户主表(mb)Mapper接口
*
* @author 数据小王子
* @date 2023-07-11
*/
public interface DemoCustomerMapper
{
/**
* 查询客户主表(mb)
*
* @param customerId 客户主表(mb)主键
* @return 客户主表(mb)
*/
public DemoCustomer selectDemoCustomerByCustomerId(Long customerId);
/**
* 查询客户主表(mb)列表
*
* @param demoCustomer 客户主表(mb)
* @return 客户主表(mb)集合
*/
public List<DemoCustomer> selectDemoCustomerList(DemoCustomer demoCustomer);
/**
* 新增客户主表(mb)
*
* @param demoCustomer 客户主表(mb)
* @return 结果
*/
public int insertDemoCustomer(DemoCustomer demoCustomer);
/**
* 修改客户主表(mb)
*
* @param demoCustomer 客户主表(mb)
* @return 结果
*/
public int updateDemoCustomer(DemoCustomer demoCustomer);
/**
* 删除客户主表(mb)
*
* @param customerId 客户主表(mb)主键
* @return 结果
*/
public int deleteDemoCustomerByCustomerId(Long customerId);
/**
* 批量删除客户主表(mb)
*
* @param customerIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteDemoCustomerByCustomerIds(Long[] customerIds);
/**
* 批量删除商品子
*
* @param customerIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteDemoGoodsByCustomerIds(Long[] customerIds);
/**
* 批量新增商品子
*
* @param demoGoodsList 商品子列表
* @return 结果
*/
public int batchDemoGoods(List<DemoGoods> demoGoodsList);
/**
* 通过客户主表(mb)主键删除商品子信息
*
* @param customerId 客户主表(mb)ID
* @return 结果
*/
public int deleteDemoGoodsByCustomerId(Long customerId);
}

View File

@ -0,0 +1,61 @@
package com.ruoyi.demo.service;
import java.util.List;
import com.ruoyi.demo.domain.DemoCustomer;
/**
* 客户主表(mb)Service接口
*
* @author 数据小王子
* @date 2023-07-11
*/
public interface IDemoCustomerService
{
/**
* 查询客户主表(mb)
*
* @param customerId 客户主表(mb)主键
* @return 客户主表(mb)
*/
public DemoCustomer selectDemoCustomerByCustomerId(Long customerId);
/**
* 查询客户主表(mb)列表
*
* @param demoCustomer 客户主表(mb)
* @return 客户主表(mb)集合
*/
public List<DemoCustomer> selectDemoCustomerList(DemoCustomer demoCustomer);
/**
* 新增客户主表(mb)
*
* @param demoCustomer 客户主表(mb)
* @return 结果
*/
public int insertDemoCustomer(DemoCustomer demoCustomer);
/**
* 修改客户主表(mb)
*
* @param demoCustomer 客户主表(mb)
* @return 结果
*/
public int updateDemoCustomer(DemoCustomer demoCustomer);
/**
* 批量删除客户主表(mb)
*
* @param customerIds 需要删除的客户主表(mb)主键集合
* @return 结果
*/
public int deleteDemoCustomerByCustomerIds(Long[] customerIds);
/**
* 删除客户主表(mb)信息
*
* @param customerId 客户主表(mb)主键
* @return 结果
*/
public int deleteDemoCustomerByCustomerId(Long customerId);
}

View File

@ -0,0 +1,131 @@
package com.ruoyi.demo.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.demo.domain.DemoGoods;
import com.ruoyi.demo.mapper.DemoCustomerMapper;
import com.ruoyi.demo.domain.DemoCustomer;
import com.ruoyi.demo.service.IDemoCustomerService;
/**
* 客户主表(mb)Service业务层处理
*
* @author 数据小王子
* @date 2023-07-11
*/
@Service
public class DemoCustomerServiceImpl implements IDemoCustomerService
{
@Autowired
private DemoCustomerMapper demoCustomerMapper;
/**
* 查询客户主表(mb)
*
* @param customerId 客户主表(mb)主键
* @return 客户主表(mb)
*/
@Override
public DemoCustomer selectDemoCustomerByCustomerId(Long customerId)
{
return demoCustomerMapper.selectDemoCustomerByCustomerId(customerId);
}
/**
* 查询客户主表(mb)列表
*
* @param demoCustomer 客户主表(mb)
* @return 客户主表(mb)
*/
@Override
public List<DemoCustomer> selectDemoCustomerList(DemoCustomer demoCustomer)
{
return demoCustomerMapper.selectDemoCustomerList(demoCustomer);
}
/**
* 新增客户主表(mb)
*
* @param demoCustomer 客户主表(mb)
* @return 结果
*/
@Transactional
@Override
public int insertDemoCustomer(DemoCustomer demoCustomer)
{
int rows = demoCustomerMapper.insertDemoCustomer(demoCustomer);
insertDemoGoods(demoCustomer);
return rows;
}
/**
* 修改客户主表(mb)
*
* @param demoCustomer 客户主表(mb)
* @return 结果
*/
@Transactional
@Override
public int updateDemoCustomer(DemoCustomer demoCustomer)
{
demoCustomerMapper.deleteDemoGoodsByCustomerId(demoCustomer.getCustomerId());
insertDemoGoods(demoCustomer);
return demoCustomerMapper.updateDemoCustomer(demoCustomer);
}
/**
* 批量删除客户主表(mb)
*
* @param customerIds 需要删除的客户主表(mb)主键
* @return 结果
*/
@Transactional
@Override
public int deleteDemoCustomerByCustomerIds(Long[] customerIds)
{
demoCustomerMapper.deleteDemoGoodsByCustomerIds(customerIds);
return demoCustomerMapper.deleteDemoCustomerByCustomerIds(customerIds);
}
/**
* 删除客户主表(mb)信息
*
* @param customerId 客户主表(mb)主键
* @return 结果
*/
@Transactional
@Override
public int deleteDemoCustomerByCustomerId(Long customerId)
{
demoCustomerMapper.deleteDemoGoodsByCustomerId(customerId);
return demoCustomerMapper.deleteDemoCustomerByCustomerId(customerId);
}
/**
* 新增商品子信息
*
* @param demoCustomer 客户主表(mb)对象
*/
public void insertDemoGoods(DemoCustomer demoCustomer)
{
List<DemoGoods> demoGoodsList = demoCustomer.getDemoGoodsList();
Long customerId = demoCustomer.getCustomerId();
if (StringUtils.isNotNull(demoGoodsList))
{
List<DemoGoods> list = new ArrayList<DemoGoods>();
for (DemoGoods demoGoods : demoGoodsList)
{
demoGoods.setCustomerId(customerId);
list.add(demoGoods);
}
if (list.size() > 0)
{
demoCustomerMapper.batchDemoGoods(list);
}
}
}
}

View File

@ -0,0 +1,110 @@
<?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.DemoCustomerMapper">
<resultMap type="DemoCustomer" id="DemoCustomerResult">
<result property="customerId" column="customer_id" />
<result property="customerName" column="customer_name" />
<result property="phonenumber" column="phonenumber" />
<result property="sex" column="sex" />
<result property="birthday" column="birthday" />
<result property="remark" column="remark" />
</resultMap>
<resultMap id="DemoCustomerDemoGoodsResult" type="DemoCustomer" extends="DemoCustomerResult">
<collection property="demoGoodsList" notNullColumn="sub_goods_id" javaType="java.util.List" resultMap="DemoGoodsResult" />
</resultMap>
<resultMap type="DemoGoods" id="DemoGoodsResult">
<result property="goodsId" column="sub_goods_id" />
<result property="customerId" column="sub_customer_id" />
<result property="name" column="sub_name" />
<result property="weight" column="sub_weight" />
<result property="price" column="sub_price" />
<result property="date" column="sub_date" />
<result property="type" column="sub_type" />
</resultMap>
<sql id="selectDemoCustomerVo">
select customer_id, customer_name, phonenumber, sex, birthday, remark from demo_customer
</sql>
<select id="selectDemoCustomerList" parameterType="DemoCustomer" resultMap="DemoCustomerResult">
<include refid="selectDemoCustomerVo"/>
<where>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
<if test="phonenumber != null and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
<if test="sex != null and sex != ''"> and sex = #{sex}</if>
<if test="birthday != null "> and birthday = #{birthday}</if>
</where>
</select>
<select id="selectDemoCustomerByCustomerId" parameterType="Long" resultMap="DemoCustomerDemoGoodsResult">
select a.customer_id, a.customer_name, a.phonenumber, a.sex, a.birthday, a.remark,
b.goods_id as sub_goods_id, b.customer_id as sub_customer_id, b.name as sub_name, b.weight as sub_weight, b.price as sub_price, b.date as sub_date, b.type as sub_type
from demo_customer a
left join demo_goods b on b.customer_id = a.customer_id
where a.customer_id = #{customerId}
</select>
<insert id="insertDemoCustomer" parameterType="DemoCustomer" useGeneratedKeys="true" keyProperty="customerId">
insert into demo_customer
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="customerName != null">customer_name,</if>
<if test="phonenumber != null">phonenumber,</if>
<if test="sex != null">sex,</if>
<if test="birthday != null">birthday,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="customerName != null">#{customerName},</if>
<if test="phonenumber != null">#{phonenumber},</if>
<if test="sex != null">#{sex},</if>
<if test="birthday != null">#{birthday},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateDemoCustomer" parameterType="DemoCustomer">
update demo_customer
<trim prefix="SET" suffixOverrides=",">
<if test="customerName != null">customer_name = #{customerName},</if>
<if test="phonenumber != null">phonenumber = #{phonenumber},</if>
<if test="sex != null">sex = #{sex},</if>
<if test="birthday != null">birthday = #{birthday},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where customer_id = #{customerId}
</update>
<delete id="deleteDemoCustomerByCustomerId" parameterType="Long">
delete from demo_customer where customer_id = #{customerId}
</delete>
<delete id="deleteDemoCustomerByCustomerIds" parameterType="String">
delete from demo_customer where customer_id in
<foreach item="customerId" collection="array" open="(" separator="," close=")">
#{customerId}
</foreach>
</delete>
<delete id="deleteDemoGoodsByCustomerIds" parameterType="String">
delete from demo_goods where customer_id in
<foreach item="customerId" collection="array" open="(" separator="," close=")">
#{customerId}
</foreach>
</delete>
<delete id="deleteDemoGoodsByCustomerId" parameterType="Long">
delete from demo_goods where customer_id = #{customerId}
</delete>
<insert id="batchDemoGoods">
insert into demo_goods( goods_id, customer_id, name, weight, price, date, type) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.goodsId}, #{item.customerId}, #{item.name}, #{item.weight}, #{item.price}, #{item.date}, #{item.type})
</foreach>
</insert>
</mapper>

View File

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 查询客户主表(mb)列表
export function listCustomer(query) {
return request({
url: '/demo/customer/list',
method: 'get',
params: query
})
}
// 查询客户主表(mb)详细
export function getCustomer(customerId) {
return request({
url: '/demo/customer/' + customerId,
method: 'get'
})
}
// 新增客户主表(mb)
export function addCustomer(data) {
return request({
url: '/demo/customer',
method: 'post',
data: data
})
}
// 修改客户主表(mb)
export function updateCustomer(data) {
return request({
url: '/demo/customer',
method: 'put',
data: data
})
}
// 删除客户主表(mb)
export function delCustomer(customerId) {
return request({
url: '/demo/customer/' + customerId,
method: 'delete'
})
}

View File

@ -0,0 +1,397 @@
<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="customerName">
<el-input
v-model="queryParams.customerName"
placeholder="请输入客户姓名"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="手机号码" prop="phonenumber">
<el-input
v-model="queryParams.phonenumber"
placeholder="请输入手机号码"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="客户性别" prop="sex">
<el-select v-model="queryParams.sex" placeholder="请选择客户性别" clearable>
<el-option
v-for="dict in dict.type.sys_user_sex"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="客户生日" prop="birthday">
<el-date-picker clearable
v-model="queryParams.birthday"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择客户生日">
</el-date-picker>
</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:customer: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="['demo:customer: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="['demo:customer: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="['demo:customer:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="customerList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="客户id" align="center" prop="customerId" />
<el-table-column label="客户姓名" align="center" prop="customerName" />
<el-table-column label="手机号码" align="center" prop="phonenumber" />
<el-table-column label="客户性别" align="center" prop="sex">
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
</template>
</el-table-column>
<el-table-column label="客户生日" align="center" prop="birthday" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<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="['demo:customer:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['demo:customer: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"
/>
<!-- 添加或修改客户主表(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="客户姓名" prop="customerName">
<el-input v-model="form.customerName" placeholder="请输入客户姓名" />
</el-form-item>
<el-form-item label="手机号码" prop="phonenumber">
<el-input v-model="form.phonenumber" placeholder="请输入手机号码" />
</el-form-item>
<el-form-item label="客户性别" prop="sex">
<el-select v-model="form.sex" placeholder="请选择客户性别">
<el-option
v-for="dict in dict.type.sys_user_sex"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="客户生日" prop="birthday">
<el-date-picker clearable
v-model="form.birthday"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择客户生日">
</el-date-picker>
</el-form-item>
<el-form-item label="客户描述" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
<el-divider content-position="center">商品子信息</el-divider>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddDemoGoods">添加</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteDemoGoods">删除</el-button>
</el-col>
</el-row>
<el-table :data="demoGoodsList" :row-class-name="rowDemoGoodsIndex" @selection-change="handleDemoGoodsSelectionChange" ref="demoGoods">
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="序号" align="center" prop="index" width="50"/>
<el-table-column label="商品名称" prop="name" width="150">
<template slot-scope="scope">
<el-input v-model="scope.row.name" placeholder="请输入商品名称" />
</template>
</el-table-column>
<el-table-column label="商品重量" prop="weight" width="150">
<template slot-scope="scope">
<el-input v-model="scope.row.weight" placeholder="请输入商品重量" />
</template>
</el-table-column>
<el-table-column label="商品价格" prop="price" width="150">
<template slot-scope="scope">
<el-input v-model="scope.row.price" placeholder="请输入商品价格" />
</template>
</el-table-column>
<el-table-column label="商品时间" prop="date" width="240">
<template slot-scope="scope">
<el-date-picker clearable v-model="scope.row.date" type="date" value-format="yyyy-MM-dd" placeholder="请选择商品时间" />
</template>
</el-table-column>
<el-table-column label="商品种类" prop="type" width="150">
<template slot-scope="scope">
<el-select v-model="scope.row.type" placeholder="请选择商品种类">
<el-option
v-for="dict in dict.type.sys_goods_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
</el-select>
</template>
</el-table-column>
</el-table>
</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 { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from "@/api/demo/customer";
export default {
name: "Customer",
dicts: ['sys_goods_type', 'sys_user_sex'],
data() {
return {
//
loading: true,
//
ids: [],
//
checkedDemoGoods: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
// (mb)
customerList: [],
//
demoGoodsList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
customerName: null,
phonenumber: null,
sex: null,
birthday: null,
},
//
form: {},
//
rules: {
}
};
},
created() {
this.getList();
},
methods: {
/** 查询客户主表(mb)列表 */
getList() {
this.loading = true;
listCustomer(this.queryParams).then(response => {
this.customerList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
customerId: null,
customerName: null,
phonenumber: null,
sex: null,
birthday: null,
remark: null
};
this.demoGoodsList = [];
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.customerId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加客户主表(mb)";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const customerId = row.customerId || this.ids
getCustomer(customerId).then(response => {
this.form = response.data;
this.demoGoodsList = response.data.demoGoodsList;
this.open = true;
this.title = "修改客户主表(mb)";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.form.demoGoodsList = this.demoGoodsList;
if (this.form.customerId != null) {
updateCustomer(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addCustomer(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const customerIds = row.customerId || this.ids;
this.$modal.confirm('是否确认删除客户主表(mb)编号为"' + customerIds + '"的数据项?').then(function() {
return delCustomer(customerIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 商品子序号 */
rowDemoGoodsIndex({ row, rowIndex }) {
row.index = rowIndex + 1;
},
/** 商品子添加按钮操作 */
handleAddDemoGoods() {
let obj = {};
obj.name = "";
obj.weight = "";
obj.price = "";
obj.date = "";
obj.type = "";
this.demoGoodsList.push(obj);
},
/** 商品子删除按钮操作 */
handleDeleteDemoGoods() {
if (this.checkedDemoGoods.length == 0) {
this.$modal.msgError("请先选择要删除的商品子数据");
} else {
const demoGoodsList = this.demoGoodsList;
const checkedDemoGoods = this.checkedDemoGoods;
this.demoGoodsList = demoGoodsList.filter(function(item) {
return checkedDemoGoods.indexOf(item.index) == -1
});
}
},
/** 复选框选中数据 */
handleDemoGoodsSelectionChange(selection) {
this.checkedDemoGoods = selection.map(item => item.index)
},
/** 导出按钮操作 */
handleExport() {
this.download('demo/customer/export', {
...this.queryParams
}, `customer_${new Date().getTime()}.xlsx`)
}
}
};
</script>

View File

@ -62,11 +62,52 @@ 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)
values('产品树表mb导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', 'demo:product:export', '#', 'admin', sysdate(), '', null, '');
-- 客户主表 demo_customer 结构定义
CREATE TABLE IF NOT EXISTS `demo_customer` (
`customer_id` bigint NOT NULL AUTO_INCREMENT COMMENT '客户id',
`customer_name` varchar(30) COLLATE utf8mb4_bin DEFAULT '' COMMENT '客户姓名',
`phonenumber` varchar(11) COLLATE utf8mb4_bin DEFAULT '' COMMENT '手机号码',
`sex` varchar(20) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '客户性别',
`birthday` datetime DEFAULT NULL COMMENT '客户生日',
`remark` varchar(500) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '客户描述',
PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='客户主表';
-- 商品子表 demo_goods 结构定义
CREATE TABLE IF NOT EXISTS `demo_goods` (
`goods_id` bigint NOT NULL AUTO_INCREMENT COMMENT '商品id',
`customer_id` bigint NOT NULL COMMENT '客户id',
`name` varchar(30) COLLATE utf8mb4_bin DEFAULT '' COMMENT '商品名称',
`weight` int DEFAULT NULL COMMENT '商品重量',
`price` decimal(6,2) DEFAULT NULL COMMENT '商品价格',
`date` datetime DEFAULT NULL COMMENT '商品时间',
`type` char(1) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '商品种类',
PRIMARY KEY (`goods_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', 'customer', 'demo/customer/index', 1, 0, 'C', '0', '0', 'demo:customer: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:customer: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:customer: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:customer: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:customer: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:customer:export', '#', 'admin', sysdate(), '', null, '');
-- 插入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
(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语法树表代码');
(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语法树表代码'),
(3, 'demo_customer', '客户主表', 'demo_goods', 'customer_id', 'DemoCustomer', 'sub', 'com.ruoyi.demo', 'demo', 'customer', '客户主表(mb)', '数据小王子', '0', '/', '{"parentMenuId":"2018"}', 'admin', '2023-06-04 21:43:20', '', '2023-07-11 15:49:51', '生成mybatis语法主子表代码'),
(12, 'demo_goods', '商品子表', NULL, NULL, 'DemoGoods', 'crud', 'com.ruoyi.demo', 'demo', 'goods', '商品子', '数据小王子', '0', '/', NULL, 'admin', '2023-07-11 15:52:15', '', NULL, NULL);
-- 插入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
@ -81,7 +122,20 @@ INSERT INTO `gen_table_column` (`column_id`, `table_id`, `column_name`, `column_
(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');
(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'),
(13, 3, 'customer_id', '客户id', 'bigint', 'Long', 'customerId', '1', '1', NULL, '1', NULL, NULL, NULL, 'EQ', 'input', '', 1, 'admin', '2023-06-04 21:43:20', '', '2023-07-11 15:49:51'),
(14, 3, 'customer_name', '客户姓名', 'varchar(30)', 'String', 'customerName', '0', '0', NULL, '1', '1', '1', '1', 'LIKE', 'input', '', 2, 'admin', '2023-06-04 21:43:20', '', '2023-07-11 15:49:51'),
(15, 3, 'phonenumber', '手机号码', 'varchar(11)', 'String', 'phonenumber', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'input', '', 3, 'admin', '2023-06-04 21:43:20', '', '2023-07-11 15:49:51'),
(16, 3, 'sex', '客户性别', 'varchar(20)', 'String', 'sex', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'select', 'sys_user_sex', 4, 'admin', '2023-06-04 21:43:20', '', '2023-07-11 15:49:51'),
(17, 3, 'birthday', '客户生日', 'datetime', 'Date', 'birthday', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'datetime', '', 5, 'admin', '2023-06-04 21:43:20', '', '2023-07-11 15:49:51'),
(18, 3, 'remark', '客户描述', 'varchar(500)', 'String', 'remark', '0', '0', NULL, '1', '1', '1', NULL, 'EQ', 'textarea', '', 6, 'admin', '2023-06-04 21:43:20', '', '2023-07-11 15:49:51'),
(67, 12, 'goods_id', '商品id', 'bigint', 'Long', 'goodsId', '1', '1', NULL, NULL, NULL, NULL, NULL, 'EQ', 'input', '', 1, 'admin', '2023-07-11 15:52:15', '', NULL),
(68, 12, 'customer_id', '客户id', 'bigint', 'Long', 'customerId', '0', '0', '1', '1', '1', '1', '1', 'EQ', 'input', '', 2, 'admin', '2023-07-11 15:52:15', '', NULL),
(69, 12, 'name', '商品名称', 'varchar(30)', 'String', 'name', '0', '0', NULL, '1', '1', '1', '1', 'LIKE', 'input', '', 3, 'admin', '2023-07-11 15:52:15', '', NULL),
(70, 12, 'weight', '商品重量', 'int', 'Long', 'weight', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'input', '', 4, 'admin', '2023-07-11 15:52:15', '', NULL),
(71, 12, 'price', '商品价格', 'decimal(6,2)', 'BigDecimal', 'price', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'input', '', 5, 'admin', '2023-07-11 15:52:15', '', NULL),
(72, 12, 'date', '商品时间', 'datetime', 'Date', 'date', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'datetime', '', 6, 'admin', '2023-07-11 15:52:15', '', NULL),
(73, 12, 'type', '商品种类', 'char(1)', 'String', 'type', '0', '0', NULL, '1', '1', '1', '1', 'EQ', 'select', '', 7, 'admin', '2023-07-11 15:52:15', '', NULL);