文章目录
库存管理系统
一、项目演示
库存管理系统
二、项目介绍
基于spingboot和vue前后端分离的库存管理系统
功能模块:用户管理、部门管理、岗位管理、供应商信息、商品信息管理、商品入库、商品出库、商品库存、库存不足预警、商品过期警告、操作日志、登录日志
语言:java
前端技术:Vue、Element-Plus
后端技术:SpringBoot、Mybatis、Redis、Ruoyi
数据库:MySQL
三、部分功能截图
四、部分代码展示
java
package com.ruoyi.web.controller.common;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.framework.config.ServerConfig;
/**
* 通用请求处理
*
*
*/
@RestController
public class CommonController
{
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired
private ServerConfig serverConfig;
/**
* 通用下载请求
*
* @param fileName 文件名称
* @param delete 是否删除
*/
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
try
{
if (!FileUtils.checkAllowDownload(fileName))
{
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = RuoYiConfig.getDownloadPath() + fileName;
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
FileUtils.writeBytes(filePath, response.getOutputStream());
if (delete)
{
FileUtils.deleteFile(filePath);
}
}
catch (Exception e)
{
log.error("下载文件失败", e);
}
}
/**
* 通用上传请求
*/
@PostMapping("/common/upload")
public AjaxResult uploadFile(MultipartFile file) throws Exception
{
try
{
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
AjaxResult ajax = AjaxResult.success();
ajax.put("fileName", fileName);
ajax.put("url", url);
return ajax;
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
/**
* 本地资源通用下载
*/
@GetMapping("/common/download/resource")
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
try
{
if (!FileUtils.checkAllowDownload(resource))
{
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
}
// 本地资源路径
String localPath = RuoYiConfig.getProfile();
// 数据库资源地址
String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
// 下载名称
String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, downloadName);
FileUtils.writeBytes(downloadPath, response.getOutputStream());
}
catch (Exception e)
{
log.error("下载文件失败", e);
}
}
}
java
package com.ruoyi.common.core.controller;
import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.sql.SqlUtil;
/**
* web层通用数据处理
*
*
*/
public class BaseController
{
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* 将前台传递过来的日期格式的字符串,自动转化为Date类型
*/
@InitBinder
public void initBinder(WebDataBinder binder)
{
// Date 类型转换
binder.registerCustomEditor(Date.class, new PropertyEditorSupport()
{
@Override
public void setAsText(String text)
{
setValue(DateUtils.parseDate(text));
}
});
}
/**
* 设置请求分页数据
*/
protected void startPage()
{
PageUtils.startPage();
}
/**
* 设置请求排序数据
*/
protected void startOrderBy()
{
PageDomain pageDomain = TableSupport.buildPageRequest();
if (StringUtils.isNotEmpty(pageDomain.getOrderBy()))
{
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
PageHelper.orderBy(orderBy);
}
}
/**
* 响应请求分页数据
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected TableDataInfo getDataTable(List<?> list)
{
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功");
rspData.setRows(list);
rspData.setTotal(new PageInfo(list).getTotal());
return rspData;
}
/**
* 返回成功
*/
public AjaxResult success()
{
return AjaxResult.success();
}
/**
* 返回失败消息
*/
public AjaxResult error()
{
return AjaxResult.error();
}
/**
* 返回成功消息
*/
public AjaxResult success(String message)
{
return AjaxResult.success(message);
}
/**
* 返回失败消息
*/
public AjaxResult error(String message)
{
return AjaxResult.error(message);
}
/**
* 响应返回结果
*
* @param rows 影响行数
* @return 操作结果
*/
protected AjaxResult toAjax(int rows)
{
return rows > 0 ? AjaxResult.success() : AjaxResult.error();
}
/**
* 响应返回结果
*
* @param result 结果
* @return 操作结果
*/
protected AjaxResult toAjax(boolean result)
{
return result ? success() : error();
}
/**
* 页面跳转
*/
public String redirect(String url)
{
return StringUtils.format("redirect:{}", url);
}
/**
* 获取用户缓存信息
*/
public LoginUser getLoginUser()
{
return SecurityUtils.getLoginUser();
}
/**
* 获取登录用户id
*/
public Long getUserId()
{
return getLoginUser().getUserId();
}
/**
* 获取登录部门id
*/
public Long getDeptId()
{
return getLoginUser().getDeptId();
}
/**
* 获取登录用户名
*/
public String getUsername()
{
return getLoginUser().getUsername();
}
}
java
package com.ruoyi.liuyb.controller;
import java.util.List;
import javax.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.liuyb.domain.DrugIn;
import com.ruoyi.liuyb.service.IDrugInService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 药品入库Controller
*
* @author liuyb
* @date 2022-02-23
*/
@RestController
@RequestMapping("/drug/drugin")
public class DrugInController extends BaseController
{
@Autowired
private IDrugInService drugInService;
/**
* 查询药品入库列表
*/
@PreAuthorize("@ss.hasPermi('drug:drugin:list')")
@GetMapping("/list")
public TableDataInfo list(DrugIn drugIn)
{
startPage();
List<DrugIn> list = drugInService.selectDrugInList(drugIn);
return getDataTable(list);
}
//查距离过保90天的
@PreAuthorize("@ss.hasPermi('drug:drugin:list')")
@GetMapping("/list1")
public TableDataInfo list1(DrugIn drugIn)
{
return getDataTable(drugInService.selectDrugInList1(drugIn));
}
//test
@GetMapping("/getname")
public AjaxResult getnameno(DrugIn drugIn){
return AjaxResult.success(drugInService.selectDrugInNoName(drugIn));
}
/**
* 查询本月的入库信息
*
* @param drugIn
* @return 药品入库集合
*/
@PreAuthorize("@ss.hasAnyPermi('drug:drugin:query')")
@GetMapping("/getdata")
public AjaxResult getdata(DrugIn drugIn){
return AjaxResult.success(drugInService.selectDrugInNameAndNum(drugIn));
}
@PreAuthorize("@ss.hasAnyPermi('drug:drugin:query')")
@GetMapping("/getmonthdata")
public AjaxResult GetMonthData(DrugIn drugIn) {
return AjaxResult.success(drugInService.selectDrugInNumByMonth(drugIn));
}
/**
* 查询入库批次
* @return
*/
@PreAuthorize("@ss.hasAnyPermi('drug:drugin:query')")
@GetMapping("/drunginbatch")
public AjaxResult GetBatch(){
return AjaxResult.success(drugInService.selectDrugInBatch());
}
/**
* 导出药品入库列表
*/
@PreAuthorize("@ss.hasPermi('drug:drugin:export')")
@Log(title = "药品入库", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, DrugIn drugIn)
{
List<DrugIn> list = drugInService.selectDrugInList(drugIn);
ExcelUtil<DrugIn> util = new ExcelUtil<DrugIn>(DrugIn.class);
util.exportExcel(response, list, "药品入库数据");
}
/**
* 获取药品入库详细信息
*/
@PreAuthorize("@ss.hasPermi('drug:drugin:query')")
@GetMapping(value = "/{druginid}")
public AjaxResult getInfo(@PathVariable("druginid") Long druginid)
{
return AjaxResult.success(drugInService.selectDrugInByDruginid(druginid));
}
/**
* 新增药品入库
*/
@PreAuthorize("@ss.hasPermi('drug:drugin:add')")
@Log(title = "药品入库", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DrugIn drugIn)
{
return toAjax(drugInService.insertDrugIn(drugIn));
}
/**
* 修改药品入库
*/
@PreAuthorize("@ss.hasPermi('drug:drugin:edit')")
@Log(title = "药品入库", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DrugIn drugIn)
{
return toAjax(drugInService.updateDrugIn(drugIn));
}
/**
* 删除药品入库
*/
@PreAuthorize("@ss.hasPermi('drug:drugin:remove')")
@Log(title = "药品入库", businessType = BusinessType.DELETE)
@DeleteMapping("/{druginids}")
public AjaxResult remove(@PathVariable Long[] druginids)
{
return toAjax(drugInService.deleteDrugInByDruginids(druginids));
}
}
五、底部获取项目源码(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以