文章目錄
- 庫存管理系統
- 一、項目演示
- 二、項目介紹
- 三、部分功能截圖
- 四、部分代碼展示
- 五、底部獲取項目源碼(9.9¥帶走)
庫存管理系統
一、項目演示
庫存管理系統
二、項目介紹
基于spingboot和vue前后端分離的庫存管理系統
功能模塊:用戶管理、部門管理、崗位管理、供應商信息、商品信息管理、商品入庫、商品出庫、商品庫存、庫存不足預警、商品過期警告、操作日志、登錄日志
語言:java
前端技術:Vue、Element-Plus
后端技術:SpringBoot、Mybatis、Redis、Ruoyi
數據庫:MySQL
三、部分功能截圖
四、部分代碼展示
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);@Autowiredprivate 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);}}
}
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類型*/@InitBinderpublic void initBinder(WebDataBinder binder){// Date 類型轉換binder.registerCustomEditor(Date.class, new PropertyEditorSupport(){@Overridepublic 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();}
}
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
{@Autowiredprivate 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)@PostMappingpublic AjaxResult add(@RequestBody DrugIn drugIn){return toAjax(drugInService.insertDrugIn(drugIn));}/*** 修改藥品入庫*/@PreAuthorize("@ss.hasPermi('drug:drugin:edit')")@Log(title = "藥品入庫", businessType = BusinessType.UPDATE)@PutMappingpublic 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¥帶走)
有問題,或者需要協助調試運行項目的也可以