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

This commit is contained in:
dataprince 2023-12-06 11:20:05 +08:00
parent 5a9e023985
commit 47ed943d61
17 changed files with 1084 additions and 1 deletions

View File

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

View File

@ -41,7 +41,7 @@
<el-col :sm="24" :lg="12" style="padding-left: 20px"> <el-col :sm="24" :lg="12" style="padding-left: 20px">
<h2>Ruoyi-Flex后台管理框架</h2> <h2>Ruoyi-Flex后台管理框架</h2>
<p> <p>
Ruoyi-Flex是基于RuoYi-Vue v3.8.6RuoYi-Vue-Plus进行的扩展集成MyBatis-FlexJDK17SpringBootV3LombokSa-TokenHutoolSpringBoot AdminPowerJobVue3element-plus等优秀开源软件准备作为未来5年软件开发的底座本系统可以用于所有的Web应用程序如网站管理后台网站会员中心CMSCRMOAERP等等当然您也可以对她进行深度定制以做出更强系统所有前端后台代码封装过后十分精简易上手出错概率低同时支持移动客户端访问系统会陆续更新一些实用功能 Ruoyi-Flex是基于RuoYi-Vue v3.8.6RuoYi-Vue-Plus进行的扩展集成MyBatis-FlexJDK17SpringBootV3LombokSa-TokenHutoolSpringBoot AdminPowerJobVue3element-plusMinIO等优秀开源软件准备作为未来5年软件开发的底座本系统可以用于所有的Web应用程序如网站管理后台网站会员中心CMSCRMOAERP等等当然您也可以对她进行深度定制以做出更强系统所有前端后台代码封装过后十分精简易上手出错概率低同时支持移动客户端访问系统会陆续更新一些实用功能
</p> </p>
<p> <p>
<b>当前版本:</b> <span>v{{ version }}</span> <b>当前版本:</b> <span>v{{ version }}</span>

View File

@ -0,0 +1,391 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="客户姓名" prop="customerName">
<el-input
v-model="queryParams.customerName"
placeholder="请输入客户姓名"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="手机号码" prop="phonenumber">
<el-input
v-model="queryParams.phonenumber"
placeholder="请输入手机号码"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="客户性别" prop="gender">
<el-select v-model="queryParams.gender" placeholder="请选择客户性别" clearable>
<el-option
v-for="dict in sys_user_gender"
: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:customer:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['mf:customer:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['mf:customer:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
@click="handleExport"
v-hasPermi="['mf:customer:export']"
>导出</el-button>
</el-col>
<right-toolbar v-model:showSearch="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="gender">
<template #default="scope">
<dict-tag :options="sys_user_gender" :value="scope.row.gender"/>
</template>
</el-table-column>
<el-table-column label="客户生日" align="center" prop="birthday" width="180">
<template #default="scope">
<span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
</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:customer:edit']">修改</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['mf:customer:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改客户主表对话框 -->
<el-dialog :title="title" v-model="open" width="780px" append-to-body>
<el-form ref="customerRef" :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="gender">
<el-select v-model="form.gender" placeholder="请选择客户性别">
<el-option
v-for="dict in sys_user_gender"
: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="Plus" @click="handleAddGoods">添加</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" icon="Delete" @click="handleDeleteGoods">删除</el-button>
</el-col>
</el-row>
<el-table :data="goodsList" :row-class-name="rowGoodsIndex" @selection-change="handleGoodsSelectionChange" ref="goods">
<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 #default="scope">
<el-input v-model="scope.row.name" placeholder="请输入商品名称" />
</template>
</el-table-column>
<el-table-column label="商品重量" prop="weight" width="150">
<template #default="scope">
<el-input v-model="scope.row.weight" placeholder="请输入商品重量" />
</template>
</el-table-column>
<el-table-column label="商品价格" prop="price" width="150">
<template #default="scope">
<el-input v-model="scope.row.price" placeholder="请输入商品价格" />
</template>
</el-table-column>
<el-table-column label="商品时间" prop="date" width="240">
<template #default="scope">
<el-date-picker clearable
v-model="scope.row.date"
type="date"
value-format="YYYY-MM-DD"
placeholder="请选择商品时间">
</el-date-picker>
</template>
</el-table-column>
<el-table-column label="商品种类" prop="type" width="150">
<template #default="scope">
<el-select v-model="scope.row.type" placeholder="请选择商品种类">
<el-option
v-for="dict in sys_goods_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
</el-select>
</template>
</el-table-column>
</el-table>
</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="Customer">
import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from "@/api/mf/customer";
const { proxy } = getCurrentInstance();
const { sys_goods_type, sys_user_gender } = proxy.useDict('sys_goods_type', 'sys_user_gender');
//
const customerList = ref([]);
//
const goodsList = ref([]);
//
const open = ref(false);
//
const loading = ref(true);
//
const showSearch = ref(true);
//
const ids = ref([]);
//
const checkedGoods = ref([]);
//
const single = ref(true);
//
const multiple = ref(true);
//
const total = ref(0);
//
const title = ref("");
const data = reactive({
form: {},
queryParams: {
pageNum: 1,
pageSize: 10,
customerName: null,
phonenumber: null,
gender: null,
},
rules: {
}
});
const { queryParams, form, rules } = toRefs(data);
/** 查询客户主表列表 */
function getList() {
loading.value = true;
listCustomer(queryParams.value).then(response => {
customerList.value = response.rows;
total.value = response.total;
loading.value = false;
});
}
//
function cancel() {
open.value = false;
reset();
}
//
function reset() {
form.value = {
customerId: null,
customerName: null,
phonenumber: null,
gender: null,
birthday: null,
remark: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null
};
goodsList.value = [];
proxy.resetForm("customerRef");
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef");
handleQuery();
}
//
function handleSelectionChange(selection) {
ids.value = selection.map(item => item.customerId);
single.value = selection.length != 1;
multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
reset();
open.value = true;
title.value = "添加客户主表";
}
/** 修改按钮操作 */
function handleUpdate(row) {
reset();
const _customerId = row.customerId || ids.value
getCustomer(_customerId).then(response => {
form.value = response.data;
goodsList.value = response.data.goodsList;
open.value = true;
title.value = "修改客户主表";
});
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["customerRef"].validate(valid => {
if (valid) {
form.value.goodsList = goodsList.value;
if (form.value.customerId != null) {
updateCustomer(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();
});
} else {
addCustomer(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
open.value = false;
getList();
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
const _customerIds = row.customerId || ids.value;
proxy.$modal.confirm('是否确认删除客户主表编号为"' + _customerIds + '"的数据项?').then(function() {
return delCustomer(_customerIds);
}).then(() => {
getList();
proxy.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
/** 商品子表序号 */
function rowGoodsIndex({ row, rowIndex }) {
row.index = rowIndex + 1;
}
/** 商品子表添加按钮操作 */
function handleAddGoods() {
let obj = {};
obj.name = "";
obj.weight = "";
obj.price = "";
obj.date = "";
obj.type = "";
goodsList.value.push(obj);
}
/** 商品子表删除按钮操作 */
function handleDeleteGoods() {
if (checkedGoods.value.length == 0) {
proxy.$modal.msgError("请先选择要删除的商品子表数据");
} else {
const goodss = goodsList.value;
const checkedGoodss = checkedGoods.value;
goodsList.value = goodss.filter(function(item) {
return checkedGoodss.indexOf(item.index) == -1
});
}
}
/** 复选框选中数据 */
function handleGoodsSelectionChange(selection) {
checkedGoods.value = selection.map(item => item.index)
}
/** 导出按钮操作 */
function handleExport() {
proxy.download('mf/customer/export', {
...queryParams.value
}, `customer_${new Date().getTime()}.xlsx`)
}
getList();
</script>

BIN
image/dataprice.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

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.CustomerVo;
import com.ruoyi.mf.domain.bo.CustomerBo;
import com.ruoyi.mf.service.ICustomerService;
import com.ruoyi.common.orm.core.page.TableDataInfo;
/**
* 客户主表Controller
*
* @author 数据小王子
* 2023-12-06
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mf/customer")
public class CustomerController extends BaseController
{
@Resource
private ICustomerService customerService;
/**
* 查询客户主表列表
*/
@SaCheckPermission("mf:customer:list")
@GetMapping("/list")
public TableDataInfo<CustomerVo> list(CustomerBo customerBo)
{
return customerService.selectPage(customerBo);
}
/**
* 导出客户主表列表
*/
@SaCheckPermission("mf:customer:export")
@Log(title = "客户主表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, CustomerBo customerBo)
{
List<CustomerVo> list = customerService.selectList(customerBo);
ExcelUtil.exportExcel(list, "客户主表", CustomerVo.class, response);
}
/**
* 获取客户主表详细信息
*/
@SaCheckPermission("mf:customer:query")
@GetMapping(value = "/{customerId}")
public R<CustomerVo> getInfo(@PathVariable Long customerId)
{
return R.ok(customerService.selectById(customerId));
}
/**
* 新增客户主表
*/
@SaCheckPermission("mf:customer:add")
@Log(title = "客户主表", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping
public R<Void> add(@Validated @RequestBody CustomerBo customerBo)
{
boolean inserted = customerService.insert(customerBo);
if (!inserted) {
return R.fail("新增客户主表记录失败!");
}
return R.ok();
}
/**
* 修改客户主表
*/
@SaCheckPermission("mf:customer:edit")
@Log(title = "客户主表", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping
public R<Void> edit(@Validated @RequestBody CustomerBo customerBo)
{
Boolean updated = customerService.update(customerBo);
if (!updated) {
R.fail("修改客户主表记录失败!");
}
return R.ok();
}
/**
* 删除客户主表
*/
@SaCheckPermission("mf:customer:remove")
@Log(title = "客户主表", businessType = BusinessType.DELETE)
@DeleteMapping("/{customerIds}")
public R<Void> remove(@PathVariable Long[] customerIds)
{
boolean deleted = customerService.deleteByIds(customerIds);
if (!deleted) {
R.fail("删除客户主表记录失败!");
}
return R.ok();
}
}

View File

@ -0,0 +1,46 @@
package com.ruoyi.mf.domain;
import java.util.List;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.mf.domain.Goods;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 客户主表对象 mf_customer
*
* @author 数据小王子
* 2023-12-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "mf_customer")
public class Customer extends BaseEntity
{
/** 客户id */
@Id
private Long customerId;
/** 客户姓名 */
private String customerName;
/** 手机号码 */
private String phonenumber;
/** 客户性别 */
private String gender;
/** 客户生日 */
private Date birthday;
/** 客户描述 */
private String remark;
/** 商品子表信息 */
private List<Goods> goodsList;
}

View File

@ -0,0 +1,52 @@
package com.ruoyi.mf.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 商品子表对象 mf_goods
*
* @author 数据小王子
* 2023-12-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "mf_goods")
public class Goods extends BaseEntity
{
@Serial
private static final long serialVersionUID = 1L;
/** 商品id */
@Id
private Long goodsId;
/** 客户id */
private Long customerId;
/** 商品名称 */
private String name;
/** 商品重量 */
private Long weight;
/** 商品价格 */
private BigDecimal price;
/** 商品时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date date;
/** 商品种类 */
private String type;
}

View File

@ -0,0 +1,60 @@
package com.ruoyi.mf.domain.bo;
import com.ruoyi.mf.domain.Customer;
import com.ruoyi.mf.domain.Goods;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import java.util.List;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 客户主表业务对象 mf_customer
*
* @author 数据小王子
* @date 2023-12-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = Customer.class, reverseConvertGenerate = false)
public class CustomerBo extends BaseEntity
{
/**
* 客户id
*/
private Long customerId;
/**
* 客户姓名
*/
private String customerName;
/**
* 手机号码
*/
private String phonenumber;
/**
* 客户性别
*/
private String gender;
/**
* 客户生日
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date birthday;
/**
* 客户描述
*/
private String remark;
/** 商品子表信息 */
private List<Goods> goodsList;
}

View File

@ -0,0 +1,67 @@
package com.ruoyi.mf.domain.vo;
import java.util.List;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.mf.domain.Customer;
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 com.mybatisflex.annotation.RelationOneToMany;
import com.ruoyi.mf.domain.Goods;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 客户主表视图对象 mf_customer
*
* @author 数据小王子
* @date 2023-12-06
*/
@Data
@ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = Customer.class)
public class CustomerVo extends BaseEntity implements Serializable
{
@Serial
private static final long serialVersionUID = 1L;
/** 客户id */
@ExcelProperty(value = "客户id")
private Long customerId;
/** 客户姓名 */
@ExcelProperty(value = "客户姓名")
private String customerName;
/** 手机号码 */
@ExcelProperty(value = "手机号码")
private String phonenumber;
/** 客户性别 */
@ExcelProperty(value = "客户性别", converter = ExcelDictConvert.class)
@ExcelDictFormat(dictType = "sys_user_gender")
private String gender;
/** 客户生日 */
@ExcelProperty(value = "客户生日")
private Date birthday;
/** 客户描述 */
@ExcelProperty(value = "客户描述")
private String remark;
/** 商品子表信息 */
@RelationOneToMany(selfField = "customerId", targetField = "customerId")
private List<Goods> goodsList;
}

View File

@ -0,0 +1,18 @@
package com.ruoyi.mf.mapper;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.ruoyi.mf.domain.Customer;
import com.ruoyi.mf.domain.Goods;
/**
* 客户主表Mapper接口
*
* @author 数据小王子
* 2023-12-06
*/
@Mapper
public interface CustomerMapper extends BaseMapper<Customer>
{
}

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.Goods;
/**
* 商品子表Mapper接口
*
* @author 数据小王子
* 2023-12-06
*/
@Mapper
public interface GoodsMapper extends BaseMapper<Goods>
{
}

View File

@ -0,0 +1,66 @@
package com.ruoyi.mf.service;
import java.util.List;
import com.ruoyi.mf.domain.Customer;
import com.ruoyi.mf.domain.vo.CustomerVo;
import com.ruoyi.mf.domain.bo.CustomerBo;
import com.ruoyi.common.orm.core.service.IBaseService;
import com.ruoyi.common.orm.core.page.TableDataInfo;
/**
* 客户主表Service接口
*
* @author 数据小王子
* 2023-12-06
*/
public interface ICustomerService extends IBaseService<Customer>
{
/**
* 查询客户主表
*
* @param customerId 客户主表主键
* @return 客户主表
*/
CustomerVo selectById(Long customerId);
/**
* 查询客户主表列表
*
* @param customerBo 客户主表Bo
* @return 客户主表集合
*/
List<CustomerVo> selectList(CustomerBo customerBo);
/**
* 分页查询客户主表列表
*
* @param customerBo 客户主表Bo
* @return 分页客户主表集合
*/
TableDataInfo<CustomerVo> selectPage(CustomerBo customerBo);
/**
* 新增客户主表
*
* @param customerBo 客户主表Bo
* @return 结果:true 操作成功false 操作失败
*/
boolean insert(CustomerBo customerBo);
/**
* 修改客户主表
*
* @param customerBo 客户主表Bo
* @return 结果:true 更新成功false 更新失败
*/
boolean update(CustomerBo customerBo);
/**
* 批量删除客户主表
*
* @param customerIds 需要删除的客户主表主键集合
* @return 结果:true 删除成功false 删除失败
*/
boolean deleteByIds(Long[] customerIds);
}

View File

@ -0,0 +1,185 @@
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 java.util.ArrayList;
import java.util.Arrays;
import com.ruoyi.mf.domain.Goods;
import com.ruoyi.mf.mapper.GoodsMapper;
import static com.ruoyi.mf.domain.table.GoodsTableDef.GOODS;
import com.ruoyi.mf.mapper.CustomerMapper;
import com.ruoyi.mf.domain.Customer;
import com.ruoyi.mf.domain.bo.CustomerBo;
import com.ruoyi.mf.domain.vo.CustomerVo;
import com.ruoyi.mf.service.ICustomerService;
import static com.ruoyi.mf.domain.table.CustomerTableDef.CUSTOMER;
/**
* 客户主表Service业务层处理
*
* @author 数据小王子
* 2023-12-06
*/
@Service
public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Customer> implements ICustomerService
{
@Resource
private CustomerMapper customerMapper;
@Resource
private GoodsMapper goodsMapper;
@Override
public QueryWrapper query() {
return super.query().from(CUSTOMER);
}
private QueryWrapper buildQueryWrapper(CustomerBo customerBo) {
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
if (StringUtils.isNotBlank(customerBo.getCustomerName())) {
queryWrapper.and(CUSTOMER.CUSTOMER_NAME.like(customerBo.getCustomerName()));
}
if (StringUtils.isNotBlank(customerBo.getPhonenumber())) {
queryWrapper.and(CUSTOMER.PHONENUMBER.eq(customerBo.getPhonenumber()));
}
if (StringUtils.isNotBlank(customerBo.getGender())) {
queryWrapper.and(CUSTOMER.GENDER.eq(customerBo.getGender()));
}
return queryWrapper;
}
/**
* 查询客户主表
*
* @param customerId 客户主表主键
* @return 客户主表
*/
@Override
public CustomerVo selectById(Long customerId)
{
return customerMapper.selectOneWithRelationsByQueryAs(query().where(CUSTOMER.CUSTOMER_ID.eq(customerId)), CustomerVo.class);
}
/**
* 查询客户主表列表
*
* @param customerBo 客户主表Bo
* @return 客户主表集合
*/
@Override
public List<CustomerVo> selectList(CustomerBo customerBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(customerBo);
return customerMapper.selectListWithRelationsByQueryAs(queryWrapper, CustomerVo.class);
}
/**
* 分页查询客户主表列表
*
* @param customerBo 客户主表Bo
* @return 分页客户主表集合
*/
@Override
public TableDataInfo<CustomerVo> selectPage(CustomerBo customerBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(customerBo);
Page<CustomerVo> page = customerMapper.paginateWithRelationsAs(PageQuery.build(), queryWrapper, CustomerVo.class);
return TableDataInfo.build(page);
}
/**
* 新增客户主表
*
* @param customerBo 客户主表Bo
* @return 结果:true 操作成功false 操作失败
*/
@Transactional
@Override
public boolean insert(CustomerBo customerBo)
{
Customer customer = MapstructUtils.convert(customerBo, Customer.class);
boolean inserted = this.save(customer);//使用全局配置的雪花算法主键生成器生成ID值
if (inserted && ObjectUtil.isNotNull(customer)) {
return insertGoods(customer);
}
return false;
}
/**
* 修改客户主表
*
* @param customerBo 客户主表Bo
* @return 结果:true 更新成功false 更新失败
*/
@Transactional
@Override
public boolean update(CustomerBo customerBo)
{
Customer customer = MapstructUtils.convert(customerBo, Customer.class);
if(ObjectUtil.isNotNull(customer) && ObjectUtil.isNotNull(customer.getCustomerId())) {
boolean updated = this.updateById(customer);
if (updated) {
QueryWrapper queryWrapper = QueryWrapper.create().from(GOODS).where(GOODS.CUSTOMER_ID.eq(customer.getCustomerId()));
goodsMapper.deleteByQuery(queryWrapper);
return insertGoods(customer);
}
}
return false;
}
/**
* 批量删除客户主表
*
* @param customerIds 需要删除的客户主表主键集合
* @return 结果:true 删除成功false 删除失败
*/
@Transactional
@Override
public boolean deleteByIds(Long[] customerIds)
{
QueryWrapper queryWrapper = QueryWrapper.create().from(GOODS).where(GOODS.CUSTOMER_ID.in(Arrays.asList(customerIds)));
goodsMapper.deleteByQuery(queryWrapper);
return this.removeByIds(Arrays.asList(customerIds));
}
/**
* 新增商品子表信息
*
* @param customer 客户主表对象
*/
private boolean insertGoods(Customer customer)
{
List<Goods> goodsList = customer.getGoodsList();
Long customerId = customer.getCustomerId();
if (StringUtils.isNotNull(goodsList))
{
List<Goods> list = new ArrayList<>();
for (Goods goods : goodsList)
{
goods.setCustomerId(customerId);
list.add(goods);
}
if (list.size() > 0)
{
return goodsMapper.insertBatch(list)>0;
}
}
return true;
}
}

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.CustomerMapper">
</mapper>

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.GoodsMapper">
</mapper>

View File

@ -1,6 +1,9 @@
package ${packageName}.domain.bo; package ${packageName}.domain.bo;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain.${ClassName};
#if($table.sub)
import ${packageName}.domain.${subClassName};
#end
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -51,4 +54,8 @@ public class ${ClassName}Bo extends ${Entity}
#end #end
#end #end
#if($table.sub)
/** $table.subTable.functionName信息 */
private List<${subClassName}> ${subclassName}List;
#end
} }