最近把java升级到了java21了,为了快速掌握一门编辑技术,肯定要多写一些完整的项目来巩固知识,这篇文章给大家分享一个我使用springboot框架和vue2 + element-ui 开发的一个前后端分离项目- 进销存管理系统。
先说一下使用的技术:
java版本:21
后端框架:springboot
前端:vue2 + element-ui
数据库:mysql8
这个系统主要实现的功能菜单如下:
系统管理、菜单管理、角色管理、账号管理、基础资料、商品档案、客户档案、供应商档案、仓库信息、员工管理、部门管理、报表分析、销售报表、采购报表、库存管理、出入库记录、采购管理、采购订单、采购入库、采购退货、销售管理、销售订单、销售出库、销售退货、首页、登录
这次给大家分享的这个项目,融入了系统权限分配,因为有很多小伙伴向我反馈,不太会设计项目权限这类 的功能,这个项目就设计了管理系统的权限功能,完整的实现类一个管理系统的权限控制功能。希望能帮助到一些小伙伴。
系统部分功能截图:
角色管理:
采购订单:
销售订单:
库存记录:
部分代码:
package com.jsonll.base.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsonll.base.core.R;
import com.jsonll.base.entity.Product;
import com.jsonll.base.entity.Warehouse;
import com.jsonll.base.entity.WarehousePosition;
import com.jsonll.base.mapper.ProductMapper;
import com.jsonll.base.request.ProductRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
/**
* 商品表 接口实现类
*/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
@Autowired
private IWarehouseService iWarehouseService;
@Autowired
private IWarehousePositionService iWarehousePositionService;
@Override
public R pageList(ProductRequest request) {
Page<Product> page = new Page<>(request.getPageNum() == null ? 1 : request.getPageNum(), request.getPageSize() == null ? 10 : request.getPageSize());
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
if (!StringUtils.isEmpty(request.getProductName())) {
queryWrapper.like(Product::getProductName, request.getProductName());
}
page(page, queryWrapper.orderByDesc(Product::getId));
// 关联查询仓库名称和库位名称
page.getRecords().forEach(product -> {
if (product.getWarehouseId() != null) {
Warehouse warehouse = iWarehouseService.getById(product.getWarehouseId());
if (warehouse != null) {
product.setWarehouseName(warehouse.getWarehouseName());
}
}
if (product.getWarehousePositionId() != null) {
WarehousePosition warehousePosition = iWarehousePositionService.getById(product.getWarehousePositionId());
if (warehousePosition != null) {
product.setWarehousePositionName(warehousePosition.getPositionName());
}
}
});
return R.successData(page);
}
@Override
public R listAll() {
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(Product::getId);
List<Product> list = list(queryWrapper);
// 关联查询仓库名称和库位名称
list.forEach(product -> {
if (product.getWarehouseId() != null) {
Warehouse warehouse = iWarehouseService.getById(product.getWarehouseId());
if (warehouse != null) {
product.setWarehouseName(warehouse.getWarehouseName());
}
}
if (product.getWarehousePositionId() != null) {
WarehousePosition warehousePosition = iWarehousePositionService.getById(product.getWarehousePositionId());
if (warehousePosition != null) {
product.setWarehousePositionName(warehousePosition.getPositionName());
}
}
});
return R.successData(list);
}
@Override
public R add(Product product) {
if (StringUtils.isEmpty(product.getProductName())) {
return R.error("商品名称不能为空");
}
if (StringUtils.isEmpty(product.getProductCode())) {
return R.error("商品编号不能为空");
}
// 检查商品编号是否已存在
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Product::getProductCode, product.getProductCode());
if (count(queryWrapper) > 0) {
return R.error("商品编号已存在");
}
save(product);
return R.success();
}
@Override
public R updateProduct(Product product) {
if (product.getId() == null) {
return R.error("商品ID不能为空");
}
if (StringUtils.isEmpty(product.getProductName())) {
return R.error("商品名称不能为空");
}
if (StringUtils.isEmpty(product.getProductCode())) {
return R.error("商品编号不能为空");
}
// 获取原商品信息
Product existProduct = getById(product.getId());
if (existProduct == null) {
return R.error("商品不存在");
}
// 如果修改了商品编号,检查是否已存在
if (product.getProductCode() != null && !product.getProductCode().equals(existProduct.getProductCode())) {
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Product::getProductCode, product.getProductCode());
queryWrapper.ne(Product::getId, product.getId());
if (count(queryWrapper) > 0) {
return R.error("商品编号已存在");
}
}
updateById(product);
return R.success();
}
@Override
public R deleteProduct(Integer id) {
if (id == null) {
return R.error("商品ID不能为空");
}
removeById(id);
return R.success();
}
}
package com.jsonll.base.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsonll.base.core.R;
import com.jsonll.base.entity.Employee;
import com.jsonll.base.entity.InventoryRecord;
import com.jsonll.base.entity.Product;
import com.jsonll.base.entity.PurchaseInbound;
import com.jsonll.base.entity.PurchaseReturn;
import com.jsonll.base.entity.PurchaseReturnDetail;
import com.jsonll.base.entity.Supplier;
import com.jsonll.base.mapper.PurchaseReturnDetailMapper;
import com.jsonll.base.mapper.PurchaseReturnMapper;
import com.jsonll.base.request.PurchaseReturnRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* 采购退货表 接口实现类
*/
@Service
public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper, PurchaseReturn> implements IPurchaseReturnService {
@Autowired
private ISupplierService iSupplierService;
@Autowired
private IEmployeeService iEmployeeService;
@Autowired
private IProductService iProductService;
@Autowired
private IPurchaseInboundService iPurchaseInboundService;
@Autowired
private IInventoryRecordService iInventoryRecordService;
@Autowired
private PurchaseReturnDetailMapper purchaseReturnDetailMapper;
@Override
public R pageList(PurchaseReturnRequest request) {
Page<PurchaseReturn> page = new Page<>(request.getPageNum() == null ? 1 : request.getPageNum(), request.getPageSize() == null ? 10 : request.getPageSize());
LambdaQueryWrapper<PurchaseReturn> queryWrapper = new LambdaQueryWrapper<>();
if (!StringUtils.isEmpty(request.getReturnNo())) {
queryWrapper.like(PurchaseReturn::getReturnNo, request.getReturnNo());
}
page(page, queryWrapper.orderByDesc(PurchaseReturn::getId));
// 关联查询采购入库单编号、供应商名称、员工姓名
page.getRecords().forEach(purchaseReturn -> {
if (purchaseReturn.getPurchaseInboundId() != null) {
PurchaseInbound purchaseInbound = iPurchaseInboundService.getById(purchaseReturn.getPurchaseInboundId());
if (purchaseInbound != null) {
purchaseReturn.setPurchaseInboundNo(purchaseInbound.getInboundNo());
}
}
if (purchaseReturn.getSupplierId() != null) {
Supplier supplier = iSupplierService.getById(purchaseReturn.getSupplierId());
if (supplier != null) {
purchaseReturn.setSupplierName(supplier.getSupplierName());
}
}
if (purchaseReturn.getEmployeeId() != null) {
Employee employee = iEmployeeService.getById(purchaseReturn.getEmployeeId());
if (employee != null) {
purchaseReturn.setEmployeeName(employee.getEmployeeName());
}
}
// 设置退货状态名称
purchaseReturn.setReturnStatusName(getReturnStatusName(purchaseReturn.getReturnStatus()));
// 设置退款状态名称
purchaseReturn.setRefundStatusName(getRefundStatusName(purchaseReturn.getRefundStatus()));
});
return R.successData(page);
}
@Override
public R listAll() {
LambdaQueryWrapper<PurchaseReturn> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(PurchaseReturn::getId);
List<PurchaseReturn> list = list(queryWrapper);
// 关联查询采购入库单编号、供应商名称、员工姓名
list.forEach(purchaseReturn -> {
if (purchaseReturn.getPurchaseInboundId() != null) {
PurchaseInbound purchaseInbound = iPurchaseInboundService.getById(purchaseReturn.getPurchaseInboundId());
if (purchaseInbound != null) {
purchaseReturn.setPurchaseInboundNo(purchaseInbound.getInboundNo());
}
}
if (purchaseReturn.getSupplierId() != null) {
Supplier supplier = iSupplierService.getById(purchaseReturn.getSupplierId());
if (supplier != null) {
purchaseReturn.setSupplierName(supplier.getSupplierName());
}
}
if (purchaseReturn.getEmployeeId() != null) {
Employee employee = iEmployeeService.getById(purchaseReturn.getEmployeeId());
if (employee != null) {
purchaseReturn.setEmployeeName(employee.getEmployeeName());
}
}
// 设置退货状态名称
purchaseReturn.setReturnStatusName(getReturnStatusName(purchaseReturn.getReturnStatus()));
// 设置退款状态名称
purchaseReturn.setRefundStatusName(getRefundStatusName(purchaseReturn.getRefundStatus()));
});
return R.successData(list);
}
@Override
public R getByIdWithDetail(Integer id) {
PurchaseReturn purchaseReturn = getById(id);
if (purchaseReturn == null) {
return R.error("采购退货不存在");
}
// 关联查询采购入库单编号、供应商名称、员工姓名
if (purchaseReturn.getPurchaseInboundId() != null) {
PurchaseInbound purchaseInbound = iPurchaseInboundService.getById(purchaseReturn.getPurchaseInboundId());
if (purchaseInbound != null) {
purchaseReturn.setPurchaseInboundNo(purchaseInbound.getInboundNo());
}
}
if (purchaseReturn.getSupplierId() != null) {
Supplier supplier = iSupplierService.getById(purchaseReturn.getSupplierId());
if (supplier != null) {
purchaseReturn.setSupplierName(supplier.getSupplierName());
}
}
if (purchaseReturn.getEmployeeId() != null) {
Employee employee = iEmployeeService.getById(purchaseReturn.getEmployeeId());
if (employee != null) {
purchaseReturn.setEmployeeName(employee.getEmployeeName());
}
}
// 查询采购退货明细
LambdaQueryWrapper<PurchaseReturnDetail> detailWrapper = new LambdaQueryWrapper<>();
detailWrapper.eq(PurchaseReturnDetail::getPurchaseReturnId, id);
List<PurchaseReturnDetail> detailList = purchaseReturnDetailMapper.selectList(detailWrapper);
// 关联查询商品信息
if (detailList != null && !detailList.isEmpty()) {
detailList.forEach(detail -> {
if (detail.getProductId() != null) {
Product product = iProductService.getById(detail.getProductId());
if (product != null) {
detail.setProductName(product.getProductName());
detail.setProductCode(product.getProductCode());
detail.setSpecModel(product.getSpecModel());
detail.setUnit(product.getUnit());
}
}
});
}
purchaseReturn.setDetailList(detailList);
return R.successData(purchaseReturn);
}
@Override
@Transactional(rollbackFor = Exception.class)
public R add(PurchaseReturn purchaseReturn) {
if (StringUtils.isEmpty(purchaseReturn.getReturnNo())) {
return R.error("退货单编号不能为空");
}
if (purchaseReturn.getPurchaseInboundId() == null) {
return R.error("采购入库不能为空");
}
if (purchaseReturn.getSupplierId() == null) {
return R.error("供应商不能为空");
}
if (purchaseReturn.getEmployeeId() == null) {
return R.error("员工不能为空");
}
// 设置默认退货状态为未退货
if (purchaseReturn.getReturnStatus() == null) {
purchaseReturn.setReturnStatus(0);
}
// 设置默认退款状态为待退款
if (purchaseReturn.getRefundStatus() == null) {
purchaseReturn.setRefundStatus(1);
}
// 保存采购退货主表
save(purchaseReturn);
// 保存采购退货明细
if (purchaseReturn.getDetailList() != null && !purchaseReturn.getDetailList().isEmpty()) {
for (PurchaseReturnDetail detail : purchaseReturn.getDetailList()) {
detail.setPurchaseReturnId(purchaseReturn.getId());
purchaseReturnDetailMapper.insert(detail);
}
}
return R.success();
}
@Override
@Transactional(rollbackFor = Exception.class)
public R updatePurchaseReturn(PurchaseReturn purchaseReturn) {
if (purchaseReturn.getId() == null) {
return R.error("采购退货ID不能为空");
}
if (StringUtils.isEmpty(purchaseReturn.getReturnNo())) {
return R.error("退货单编号不能为空");
}
if (purchaseReturn.getPurchaseInboundId() == null) {
return R.error("采购入库不能为空");
}
if (purchaseReturn.getSupplierId() == null) {
return R.error("供应商不能为空");
}
if (purchaseReturn.getEmployeeId() == null) {
return R.error("员工不能为空");
}
// 更新采购退货主表
updateById(purchaseReturn);
// 处理采购退货明细
if (purchaseReturn.getDetailList() != null && !purchaseReturn.getDetailList().isEmpty()) {
// 获取当前采购退货的所有明细ID
List<Integer> currentDetailIds = new ArrayList<>();
for (PurchaseReturnDetail detail : purchaseReturn.getDetailList()) {
detail.setPurchaseReturnId(purchaseReturn.getId());
if (detail.getId() != null) {
// 更新已有明细
purchaseReturnDetailMapper.updateById(detail);
currentDetailIds.add(detail.getId());
} else {
// 新增明细
purchaseReturnDetailMapper.insert(detail);
// 将新增明细的ID加入列表,避免被误删
currentDetailIds.add(detail.getId());
}
}
// 删除不在当前明细列表中的旧明细
LambdaQueryWrapper<PurchaseReturnDetail> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PurchaseReturnDetail::getPurchaseReturnId, purchaseReturn.getId());
if (!currentDetailIds.isEmpty()) {
queryWrapper.notIn(PurchaseReturnDetail::getId, currentDetailIds);
}
purchaseReturnDetailMapper.delete(queryWrapper);
} else {
// 如果没有明细,删除所有明细
LambdaQueryWrapper<PurchaseReturnDetail> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(PurchaseReturnDetail::getPurchaseReturnId, purchaseReturn.getId());
purchaseReturnDetailMapper.delete(deleteWrapper);
}
return R.success();
}
@Override
@Transactional(rollbackFor = Exception.class)
public R deletePurchaseReturn(Integer id) {
if (id == null) {
return R.error("采购退货ID不能为空");
}
// 删除采购退货明细
LambdaQueryWrapper<PurchaseReturnDetail> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(PurchaseReturnDetail::getPurchaseReturnId, id);
purchaseReturnDetailMapper.delete(deleteWrapper);
// 删除采购退货主表
removeById(id);
return R.success();
}
@Override
@Transactional(rollbackFor = Exception.class)
public R confirmReturn(Integer id) {
if (id == null) {
return R.error("采购退货ID不能为空");
}
PurchaseReturn purchaseReturn = getById(id);
if (purchaseReturn == null) {
return R.error("采购退货不存在");
}
// 查询采购退货明细
LambdaQueryWrapper<PurchaseReturnDetail> detailWrapper = new LambdaQueryWrapper<>();
detailWrapper.eq(PurchaseReturnDetail::getPurchaseReturnId, id);
List<PurchaseReturnDetail> detailList = purchaseReturnDetailMapper.selectList(detailWrapper);
if (detailList == null || detailList.isEmpty()) {
return R.error("采购退货明细为空,无法确认退货");
}
// 查询采购入库信息,获取仓库ID
PurchaseInbound purchaseInbound = iPurchaseInboundService.getById(purchaseReturn.getPurchaseInboundId());
if (purchaseInbound == null) {
return R.error("采购入库不存在");
}
// 创建出入库记录(出库)
for (PurchaseReturnDetail detail : detailList) {
InventoryRecord inventoryRecord = new InventoryRecord();
inventoryRecord.setDocumentNo(purchaseReturn.getReturnNo());
inventoryRecord.setBusinessType("purchase_return");
inventoryRecord.setSourceDocumentId(purchaseReturn.getId());
inventoryRecord.setProductId(detail.getProductId());
inventoryRecord.setWarehouseId(purchaseInbound.getWarehouseId());
inventoryRecord.setDirection(2);
inventoryRecord.setQuantity(detail.getReturnQuantity());
inventoryRecord.setPrice(detail.getPurchasePrice());
// 计算金额
java.math.BigDecimal amount = detail.getPurchasePrice().multiply(new java.math.BigDecimal(detail.getReturnQuantity()));
inventoryRecord.setAmount(amount);
inventoryRecord.setRecordDate(purchaseReturn.getReturnDate());
inventoryRecord.setRemark(purchaseReturn.getRemark());
iInventoryRecordService.save(inventoryRecord);
}
// 更新退货状态为已退货
purchaseReturn.setReturnStatus(1);
updateById(purchaseReturn);
return R.success();
}
private String getReturnStatusName(Integer returnStatus) {
if (returnStatus == null) {
return "-";
}
switch (returnStatus) {
case 0:
return "未退货";
case 1:
return "已退货";
default:
return "-";
}
}
private String getRefundStatusName(Integer refundStatus) {
if (refundStatus == null) {
return "-";
}
switch (refundStatus) {
case 1:
return "待退款";
case 2:
return "已退款";
default:
return "-";
}
}
}
项目源码一篇文章分享不完,只能给大家展示一部分,如果有兴趣学习java技术的小伙伴,不知道拿什么项目来练习,可以仿照着这个项目自己尝试着写写看。我也搭建了预览地址,有兴趣的可以去看看: test.wwwoop.com/?s=jin-xiao…