Java畢業設計實戰項目之倉庫管理系統的實現流程
基於SSM框架的倉庫管理系統
功能:
- 系統操作權限管理。系統提供基本的登入登出功能,同時系統包含兩個角色:系統超級管理員和普通管理員,超級管理員具有最高的操作權限,而普通管理員僅具有最基本的操作權限,而且僅能操作自己被指派的倉庫。
- 請求URL鑒權。對於系統使用者登陸後進行操作發送請求的URL,後臺會根據當前用戶的角色判斷是否擁有請求該URL的權限。
- 基礎數據信息管理。對包括:貨物信息、供應商信息、客戶信息、倉庫信息在內的基礎數據信息進行管理,提供的操作有:添加、刪除、修改、條件查詢、導出為Excel和到從Excel導入。
- 倉庫管理員管理。對倉庫管理員信息CRUD操作,或者為指定的倉庫管理員指派所管理的倉庫。上述中的倉庫管理員可以以普通管理員身份登陸到系統。
- 庫存信息管理。對庫存信息的CRUD操作,導入導出操作,同時查詢的時候可以根據倉庫以及商品ID等信息進行多條件查詢。
- 基本倉庫事務操作。執行貨物的入庫與出庫操作。
- 系統登陸日志查詢。超級管理員可以查詢某一用戶在特定時間段內的系統登陸日志。
- 系統操作日志查詢。超級管理員可以查詢某一用戶在特定時間段內對系統進行操作的操作記錄。
- 密碼修改。
使用到的框架和庫:
- Apache POI
- MyBatis
- Spring Framework
- Spring MVC
- Apache Shiro
- Ehcache
- Apache Commons
- Log4j
- Slf4j
- Jackson
- C3P0
- Junit
- MySQL-Connector
- jQuery
- Bootstrap
倉庫管理員管理請求:
/** * 倉庫管理員管理請求 Handler * * @author yy */ @Controller @RequestMapping(value = "/**/repositoryAdminManage") public class RepositoryAdminManageHandler { @Autowired private RepositoryAdminManageService repositoryAdminManageService; // 查詢類型 private static final String SEARCH_BY_ID = "searchByID"; private static final String SEARCH_BY_NAME = "searchByName"; private static final String SEARCH_BY_REPOSITORY_ID = "searchByRepositoryID"; private static final String SEARCH_ALL = "searchAll"; /** * 通用記錄查詢 * * @param keyWord 查詢關鍵字 * @param searchType 查詢類型 * @param offset 分頁偏移值 * @param limit 分頁大小 * @return 返回所有符合條件的記錄 */ private Map<String, Object> query(String keyWord, String searchType, int offset, int limit) throws RepositoryAdminManageServiceException { Map<String, Object> queryResult = null; // query switch (searchType) { case SEARCH_ALL: queryResult = repositoryAdminManageService.selectAll(offset, limit); break; case SEARCH_BY_ID: if (StringUtils.isNumeric(keyWord)) queryResult = repositoryAdminManageService.selectByID(Integer.valueOf(keyWord)); break; case SEARCH_BY_NAME: queryResult = repositoryAdminManageService.selectByName(offset, limit, keyWord); break; case SEARCH_BY_REPOSITORY_ID: if (StringUtils.isNumeric(keyWord)) queryResult = repositoryAdminManageService.selectByRepositoryID(Integer.valueOf(keyWord)); break; default: // do other things break; } return queryResult; } /** * 查詢倉庫管理員信息 * * @param searchType 查詢類型 * @param offset 分頁偏移值 * @param limit 分頁大小 * @param keyWord 查詢關鍵字 * @return 返回一個Map,其中key=rows,表示查詢出來的記錄;key=total,表示記錄的總條數 */ @SuppressWarnings("unchecked") @RequestMapping(value = "getRepositoryAdminList", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getRepositoryAdmin(@RequestParam("searchType") String searchType, @RequestParam("keyWord") String keyWord, @RequestParam("offset") int offset, @RequestParam("limit") int limit) throws RepositoryAdminManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); List<RepositoryAdmin> rows = null; long total = 0; // 查詢 Map<String, Object> queryResult = query(keyWord, searchType, offset, limit); if (queryResult != null) { rows = (List<RepositoryAdmin>) queryResult.get("data"); total = (long) queryResult.get("total"); } // 設置 Response responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); return responseContent.generateResponse(); } /** * 添加一條倉庫管理員信息 * * @param repositoryAdmin 倉庫管理員信息 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 error */ @RequestMapping(value = "addRepositoryAdmin", method = RequestMethod.POST) public @ResponseBody Map<String, Object> addRepositoryAdmin(@RequestBody RepositoryAdmin repositoryAdmin) throws RepositoryAdminManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 添加結果 String result = repositoryAdminManageService.addRepositoryAdmin(repositoryAdmin) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 查詢指定 ID 的倉庫管理員信息 * * @param repositoryAdminID 倉庫管理員ID * @return 返回一個map,其中:key 為 result 的值為操作的結果,包括:success 與 error;key 為 data * 的值為倉庫管理員信息 */ @RequestMapping(value = "getRepositoryAdminInfo", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getRepositoryAdminInfo(Integer repositoryAdminID) throws RepositoryAdminManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; // 查詢 RepositoryAdmin repositoryAdmin = null; Map<String, Object> queryResult = repositoryAdminManageService.selectByID(repositoryAdminID); if (queryResult != null) { if ((repositoryAdmin = (RepositoryAdmin) queryResult.get("data")) != null) result = Response.RESPONSE_RESULT_SUCCESS; } // 設置 Response responseContent.setResponseResult(result); responseContent.setResponseData(repositoryAdmin); return responseContent.generateResponse(); } /** * 更新倉庫管理員信息 * * @param repositoryAdmin 倉庫管理員信息 * @return 返回一個map,其中:key 為 result 的值為操作的結果,包括:success 與 error;key 為 data * 的值為倉庫管理員信息 */ @RequestMapping(value = "updateRepositoryAdmin", method = RequestMethod.POST) public @ResponseBody Map<String, Object> updateRepositoryAdmin(@RequestBody RepositoryAdmin repositoryAdmin) throws RepositoryAdminManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 更新 String result = repositoryAdminManageService.updateRepositoryAdmin(repositoryAdmin) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 刪除指定 ID 的倉庫管理員信息 * * @param repositoryAdminID 倉庫ID * @return 返回一個map,其中:key 為 result 的值為操作的結果,包括:success 與 error;key 為 data * 的值為倉庫管理員信息 */ @RequestMapping(value = "deleteRepositoryAdmin", method = RequestMethod.GET) public @ResponseBody Map<String, Object> deleteRepositoryAdmin(Integer repositoryAdminID) throws RepositoryAdminManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 刪除記錄 String result = repositoryAdminManageService.deleteRepositoryAdmin(repositoryAdminID) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 從文件中導入倉庫管理員信息 * * @param file 保存有倉庫管理員信息的文件 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 * error;key為total表示導入的總條數;key為available表示有效的條數 */ @RequestMapping(value = "importRepositoryAdmin", method = RequestMethod.POST) public @ResponseBody Map<String, Object> importRepositoryAdmin(MultipartFile file) throws RepositoryAdminManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; // 讀取文件 long total = 0; long available = 0; if (file != null) { Map<String, Object> importInfo = repositoryAdminManageService.importRepositoryAdmin(file); if (importInfo != null) { total = (long) importInfo.get("total"); available = (long) importInfo.get("available"); result = Response.RESPONSE_RESULT_SUCCESS; } } // 設置 Response responseContent.setResponseResult(result); responseContent.setResponseTotal(total); responseContent.setCustomerInfo("available", available); return responseContent.generateResponse(); } /** * 導出倉庫管理員信息到文件中 * * @param searchType 查詢類型 * @param keyWord 查詢關鍵字 * @param response HttpServletResponse */ @SuppressWarnings("unchecked") @RequestMapping(value = "exportRepositoryAdmin", method = RequestMethod.GET) public void exportRepositoryAdmin(@RequestParam("searchType") String searchType, @RequestParam("keyWord") String keyWord, HttpServletResponse response) throws RepositoryAdminManageServiceException, IOException { // 導出文件名 String fileName = "repositoryAdminInfo.xlsx"; // 查詢 List<RepositoryAdmin> repositoryAdmins; Map<String, Object> queryResult = query(keyWord, searchType, -1, -1); if (queryResult != null) repositoryAdmins = (List<RepositoryAdmin>) queryResult.get("data"); else repositoryAdmins = new ArrayList<>(); // 生成文件 File file = repositoryAdminManageService.exportRepositoryAdmin(repositoryAdmins); // 輸出文件 if (file != null) { // 設置響應頭 response.addHeader("Content-Disposition", "attachment;filename=" + fileName); FileInputStream inputStream = new FileInputStream(file); OutputStream outputStream = response.getOutputStream(); byte[] buffer = new byte[8192]; int len; while ((len = inputStream.read(buffer, 0, buffer.length)) > 0) { outputStream.write(buffer, 0, len); outputStream.flush(); } inputStream.close(); outputStream.close(); } } }
貨物信息管理請求:
/** * 貨物信息管理請求 Handler * * @author yy */ @RequestMapping(value = "/**/goodsManage") @Controller public class GoodsManageHandler { @Autowired private GoodsManageService goodsManageService; private static final String SEARCH_BY_ID = "searchByID"; private static final String SEARCH_BY_NAME = "searchByName"; private static final String SEARCH_ALL = "searchAll"; /** * 通用的記錄查詢 * * @param searchType 查詢類型 * @param keyWord 查詢關鍵字 * @param offset 分頁偏移值 * @param limit 分頁大小 * @return 返回一個 Map ,包含所有符合要求的查詢結果,以及記錄的條數 */ private Map<String, Object> query(String searchType, String keyWord, int offset, int limit) throws GoodsManageServiceException { Map<String, Object> queryResult = null; switch (searchType) { case SEARCH_BY_ID: if (StringUtils.isNumeric(keyWord)) queryResult = goodsManageService.selectById(Integer.valueOf(keyWord)); break; case SEARCH_BY_NAME: queryResult = goodsManageService.selectByName(keyWord); break; case SEARCH_ALL: queryResult = goodsManageService.selectAll(offset, limit); break; default: // do other thing break; } return queryResult; } /** * 搜索貨物信息 * * @param searchType 搜索類型 * @param offset 如有多條記錄時分頁的偏移值 * @param limit 如有多條記錄時分頁的大小 * @param keyWord 搜索的關鍵字 * @return 返回所有符合要求的記錄 */ @SuppressWarnings("unchecked") @RequestMapping(value = "getGoodsList", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getGoodsList(@RequestParam("searchType") String searchType, @RequestParam("offset") int offset, @RequestParam("limit") int limit, @RequestParam("keyWord") String keyWord) throws GoodsManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); List<Supplier> rows = null; long total = 0; // 查詢 Map<String, Object> queryResult = query(searchType, keyWord, offset, limit); if (queryResult != null) { rows = (List<Supplier>) queryResult.get("data"); total = (long) queryResult.get("total"); } // 設置 Response responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); return responseContent.generateResponse(); } /** * 添加一條貨物信息 * * @param goods 貨物信息 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 error */ @RequestMapping(value = "addGoods", method = RequestMethod.POST) public @ResponseBody Map<String, Object> addGoods(@RequestBody Goods goods) throws GoodsManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 添加記錄 String result = goodsManageService.addGoods(goods) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 查詢指定 goods ID 貨物的信息 * * @param goodsID 貨物ID * @return 返回一個map,其中:key 為 result 的值為操作的結果,包括:success 與 error;key 為 data * 的值為貨物信息 */ @RequestMapping(value = "getGoodsInfo", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getGoodsInfo(@RequestParam("goodsID") Integer goodsID) throws GoodsManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; // 獲取貨物信息 Goods goods = null; Map<String, Object> queryResult = goodsManageService.selectById(goodsID); if (queryResult != null) { goods = (Goods) queryResult.get("data"); if (goods != null) { result = Response.RESPONSE_RESULT_SUCCESS; } } // 設置 Response responseContent.setResponseResult(result); responseContent.setResponseData(goods); return responseContent.generateResponse(); } /** * 更新貨物信息 * * @param goods 貨物信息 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 error */ @RequestMapping(value = "updateGoods", method = RequestMethod.POST) public @ResponseBody Map<String, Object> updateGoods(@RequestBody Goods goods) throws GoodsManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 更新 String result = goodsManageService.updateGoods(goods) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 刪除貨物記錄 * * @param goodsID 貨物ID * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 error */ @RequestMapping(value = "deleteGoods", method = RequestMethod.GET) public @ResponseBody Map<String, Object> deleteGoods(@RequestParam("goodsID") Integer goodsID) throws GoodsManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 刪除 String result = goodsManageService.deleteGoods(goodsID) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 導入貨物信息 * * @param file 保存有貨物信息的文件 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 * error;key為total表示導入的總條數;key為available表示有效的條數 */ @RequestMapping(value = "importGoods", method = RequestMethod.POST) public @ResponseBody Map<String, Object> importGoods(@RequestParam("file") MultipartFile file) throws GoodsManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; // 讀取文件內容 int total = 0; int available = 0; if (file != null) { Map<String, Object> importInfo = goodsManageService.importGoods(file); if (importInfo != null) { total = (int) importInfo.get("total"); available = (int) importInfo.get("available"); result = Response.RESPONSE_RESULT_SUCCESS; } } // 設置 Response responseContent.setResponseResult(result); responseContent.setResponseTotal(total); responseContent.setCustomerInfo("available", available); return responseContent.generateResponse(); } /** * 導出貨物信息 * * @param searchType 查找類型 * @param keyWord 查找關鍵字 * @param response HttpServletResponse */ @SuppressWarnings("unchecked") @RequestMapping(value = "exportGoods", method = RequestMethod.GET) public void exportGoods(@RequestParam("searchType") String searchType, @RequestParam("keyWord") String keyWord, HttpServletResponse response) throws GoodsManageServiceException, IOException { String fileName = "goodsInfo.xlsx"; List<Goods> goodsList = null; Map<String, Object> queryResult = query(searchType, keyWord, -1, -1); if (queryResult != null) { goodsList = (List<Goods>) queryResult.get("data"); } // 獲取生成的文件 File file = goodsManageService.exportGoods(goodsList); // 寫出文件 if (file != null) { // 設置響應頭 response.addHeader("Content-Disposition", "attachment;filename=" + fileName); FileInputStream inputStream = new FileInputStream(file); OutputStream outputStream = response.getOutputStream(); byte[] buffer = new byte[8192]; int len; while ((len = inputStream.read(buffer, 0, buffer.length)) > 0) { outputStream.write(buffer, 0, len); outputStream.flush(); } inputStream.close(); outputStream.close(); } } }
客戶信息管理請求:
/** * 客戶信息管理請求 * * @author yy */ @RequestMapping(value = "/**/customerManage") @Controller public class CustomerManageHandler { @Autowired private CustomerManageService customerManageService; private static final String SEARCH_BY_ID = "searchByID"; private static final String SEARCH_BY_NAME = "searchByName"; private static final String SEARCH_ALL = "searchAll"; /** * 通用的結果查詢方法 * * @param searchType 查詢方式 * @param keyWord 查詢關鍵字 * @param offset 分頁偏移值 * @param limit 分頁大小 * @return 返回指定條件查詢的結果 */ private Map<String, Object> query(String searchType, String keyWord, int offset, int limit) throws CustomerManageServiceException { Map<String, Object> queryResult = null; switch (searchType) { case SEARCH_BY_ID: if (StringUtils.isNumeric(keyWord)) queryResult = customerManageService.selectById(Integer.valueOf(keyWord)); break; case SEARCH_BY_NAME: queryResult = customerManageService.selectByName(offset, limit, keyWord); break; case SEARCH_ALL: queryResult = customerManageService.selectAll(offset, limit); break; default: // do other thing break; } return queryResult; } /** * 搜索客戶信息 * * @param searchType 搜索類型 * @param offset 如有多條記錄時分頁的偏移值 * @param limit 如有多條記錄時分頁的大小 * @param keyWord 搜索的關鍵字 * @return 返回查詢的結果,其中鍵值為 rows 的代表查詢到的每一記錄,若有分頁則為分頁大小的記錄;鍵值為 total 代表查詢到的符合要求的記錄總條數 */ @SuppressWarnings("unchecked") @RequestMapping(value = "getCustomerList", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getCustomerList(@RequestParam("searchType") String searchType, @RequestParam("offset") int offset, @RequestParam("limit") int limit, @RequestParam("keyWord") String keyWord) throws CustomerManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); List<Supplier> rows = null; long total = 0; Map<String, Object> queryResult = query(searchType, keyWord, offset, limit); if (queryResult != null) { rows = (List<Supplier>) queryResult.get("data"); total = (long) queryResult.get("total"); } // 設置 Response responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); responseContent.setResponseResult(Response.RESPONSE_RESULT_SUCCESS); return responseContent.generateResponse(); } /** * 添加一條客戶信息 * * @param customer 客戶信息 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 error */ @RequestMapping(value = "addCustomer", method = RequestMethod.POST) public @ResponseBody Map<String, Object> addCustomer(@RequestBody Customer customer) throws CustomerManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 添加記錄 String result = customerManageService.addCustomer(customer) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 查詢指定 customer ID 客戶的信息 * * @param customerID 客戶ID * @return 返回一個map,其中:key 為 result 的值為操作的結果,包括:success 與 error;key 為 data * 的值為客戶信息 */ @RequestMapping(value = "getCustomerInfo", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getCustomerInfo(@RequestParam("customerID") String customerID) throws CustomerManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; // 獲取客戶信息 Customer customer = null; Map<String, Object> queryResult = query(SEARCH_BY_ID, customerID, -1, -1); if (queryResult != null) { customer = (Customer) queryResult.get("data"); if (customer != null) { result = Response.RESPONSE_RESULT_SUCCESS; } } // 設置 Response responseContent.setResponseResult(result); responseContent.setResponseData(customer); return responseContent.generateResponse(); } /** * 更新客戶信息 * * @param customer 客戶信息 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 error */ @RequestMapping(value = "updateCustomer", method = RequestMethod.POST) public @ResponseBody Map<String, Object> updateCustomer(@RequestBody Customer customer) throws CustomerManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 更新 String result = customerManageService.updateCustomer(customer) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 刪除客戶記錄 * * @param customerIDStr 客戶ID * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 error */ @RequestMapping(value = "deleteCustomer", method = RequestMethod.GET) public @ResponseBody Map<String, Object> deleteCustomer(@RequestParam("customerID") String customerIDStr) throws CustomerManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 參數檢查 if (StringUtils.isNumeric(customerIDStr)) { // 轉換為 Integer Integer customerID = Integer.valueOf(customerIDStr); // 刪除 String result = customerManageService.deleteCustomer(customerID) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; responseContent.setResponseResult(result); } else responseContent.setResponseResult(Response.RESPONSE_RESULT_ERROR); return responseContent.generateResponse(); } /** * 導入客戶信息 * * @param file 保存有客戶信息的文件 * @return 返回一個map,其中:key 為 result表示操作的結果,包括:success 與 * error;key為total表示導入的總條數;key為available表示有效的條數 */ @RequestMapping(value = "importCustomer", method = RequestMethod.POST) public @ResponseBody Map<String, Object> importCustomer(@RequestParam("file") MultipartFile file) throws CustomerManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_SUCCESS; // 讀取文件內容 int total = 0; int available = 0; if (file == null) result = Response.RESPONSE_RESULT_ERROR; Map<String, Object> importInfo = customerManageService.importCustomer(file); if (importInfo != null) { total = (int) importInfo.get("total"); available = (int) importInfo.get("available"); } responseContent.setResponseResult(result); responseContent.setResponseTotal(total); responseContent.setCustomerInfo("available", available); return responseContent.generateResponse(); } /** * 導出客戶信息 * * @param searchType 查找類型 * @param keyWord 查找關鍵字 * @param response HttpServletResponse */ @SuppressWarnings("unchecked") @RequestMapping(value = "exportCustomer", method = RequestMethod.GET) public void exportCustomer(@RequestParam("searchType") String searchType, @RequestParam("keyWord") String keyWord, HttpServletResponse response) throws CustomerManageServiceException, IOException { String fileName = "customerInfo.xlsx"; List<Customer> customers = null; Map<String, Object> queryResult = query(searchType, keyWord, -1, -1); if (queryResult != null) { customers = (List<Customer>) queryResult.get("data"); } // 獲取生成的文件 File file = customerManageService.exportCustomer(customers); // 寫出文件 if (file != null) { // 設置響應頭 response.addHeader("Content-Disposition", "attachment;filename=" + fileName); FileInputStream inputStream = new FileInputStream(file); OutputStream outputStream = response.getOutputStream(); byte[] buffer = new byte[8192]; int len; while ((len = inputStream.read(buffer, 0, buffer.length)) > 0) { outputStream.write(buffer, 0, len); outputStream.flush(); } inputStream.close(); outputStream.close(); } } }
商品出入庫管理請求:
/** * 商品出入庫管理請求 * * @author yy */ @Controller @RequestMapping(value = "stockRecordManage") public class StockRecordManageHandler { @Autowired private StockRecordManageService stockRecordManageService; /** * 貨物出庫操作 * * @param customerID 客戶ID * @param goodsID 貨物ID * @param repositoryIDStr 倉庫ID * @param number 出庫數量 * @return 返回一個map,key為result的值表示操作是否成功 */ @RequestMapping(value = "stockOut", method = RequestMethod.POST) public @ResponseBody Map<String, Object> stockOut(@RequestParam("customerID") Integer customerID, @RequestParam("goodsID") Integer goodsID, @RequestParam(value = "repositoryID", required = false) String repositoryIDStr, @RequestParam("number") long number) throws StockRecordManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; boolean authorizeCheck = true; boolean argumentCheck = true; Integer repositoryID = null; // 參數檢查 if (repositoryIDStr != null) { if (StringUtils.isNumeric(repositoryIDStr)) { repositoryID = Integer.valueOf(repositoryIDStr); } else { argumentCheck = false; responseContent.setResponseMsg("request argument error"); } } // 獲取 session 中的信息 Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); UserInfoDTO userInfo = (UserInfoDTO) session.getAttribute("userInfo"); String personInCharge = userInfo == null ? "none" : userInfo.getUserName(); Integer repositoryIDBelong = userInfo == null ? -1 : userInfo.getRepositoryBelong(); // 設置非管理員請求的倉庫ID if (!currentUser.hasRole("systemAdmin")) { if (repositoryIDBelong < 0) { authorizeCheck = false; responseContent.setResponseMsg("You are not authorized"); } else { repositoryID = repositoryIDBelong; } } if (authorizeCheck && argumentCheck) { if (stockRecordManageService.stockOutOperation(customerID, goodsID, repositoryID, number, personInCharge)) result = Response.RESPONSE_RESULT_SUCCESS; } // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 貨物入庫操作 * * @param supplierID 供應商ID * @param goodsID 貨物ID * @param repositoryIDStr 倉庫ID * @param number 入庫數目 * @return 返回一個map,key為result的值表示操作是否成功 */ @RequestMapping(value = "stockIn", method = RequestMethod.POST) public @ResponseBody Map<String, Object> stockIn(@RequestParam("supplierID") Integer supplierID, @RequestParam("goodsID") Integer goodsID, @RequestParam(value = "repositoryID", required = false) String repositoryIDStr, @RequestParam("number") long number) throws StockRecordManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; boolean authorizeCheck = true; boolean argumentCheck = true; Integer repositoryID = null; // 參數檢查 if (repositoryIDStr != null) { if (StringUtils.isNumeric(repositoryIDStr)) { repositoryID = Integer.valueOf(repositoryIDStr); } else { argumentCheck = false; responseContent.setResponseMsg("request argument error"); } } // 獲取session中的信息 Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); UserInfoDTO userInfo = (UserInfoDTO) session.getAttribute("userInfo"); String personInCharge = userInfo == null ? "none" : userInfo.getUserName(); Integer repositoryIDBelong = userInfo == null ? -1 : userInfo.getRepositoryBelong(); // 設置非管理員請求的倉庫ID if (!currentUser.hasRole("systemAdmin")) { if (repositoryIDBelong < 0) { authorizeCheck = false; responseContent.setResponseMsg("You are not authorized"); } else { repositoryID = repositoryIDBelong; } } // 執行 Service if (authorizeCheck && argumentCheck) { if (stockRecordManageService.stockInOperation(supplierID, goodsID, repositoryID, number, personInCharge)) { result = Response.RESPONSE_RESULT_SUCCESS; } } // 設置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 查詢出入庫記錄 * * @param searchType 查詢類型(查詢所有或僅查詢入庫記錄或僅查詢出庫記錄) * @param repositoryIDStr 查詢記錄所對應的倉庫ID * @param endDateStr 查詢的記錄起始日期 * @param startDateStr 查詢的記錄結束日期 * @param limit 分頁大小 * @param offset 分頁偏移值 * @return 返回一個Map,其中:Key為rows的值代表所有記錄數據,Key為total的值代表記錄的總條數 */ @SuppressWarnings({"SingleStatementInBlock", "unchecked"}) @RequestMapping(value = "searchStockRecord", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getStockRecord(@RequestParam("searchType") String searchType, @RequestParam("repositoryID") String repositoryIDStr, @RequestParam("startDate") String startDateStr, @RequestParam("endDate") String endDateStr, @RequestParam("limit") int limit, @RequestParam("offset") int offset) throws ParseException, StockRecordManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); List<StockRecordDTO> rows = null; long total = 0; // 參數檢查 String regex = "([0-9]{4})-([0-9]{2})-([0-9]{2})"; boolean startDateFormatCheck = (StringUtils.isEmpty(startDateStr) || startDateStr.matches(regex)); boolean endDateFormatCheck = (StringUtils.isEmpty(endDateStr) || endDateStr.matches(regex)); boolean repositoryIDCheck = (StringUtils.isEmpty(repositoryIDStr) || StringUtils.isNumeric(repositoryIDStr)); if (startDateFormatCheck && endDateFormatCheck && repositoryIDCheck) { Integer repositoryID = -1; if (StringUtils.isNumeric(repositoryIDStr)) { repositoryID = Integer.valueOf(repositoryIDStr); } // 轉到 Service 執行查詢 Map<String, Object> queryResult = stockRecordManageService.selectStockRecord(repositoryID, startDateStr, endDateStr, searchType, offset, limit); if (queryResult != null) { rows = (List<StockRecordDTO>) queryResult.get("data"); total = (long) queryResult.get("total"); } } else responseContent.setResponseMsg("Request argument error"); if (rows == null) rows = new ArrayList<>(0); responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); return responseContent.generateResponse(); } }
到此這篇關於Java畢業設計實戰項目之倉庫管理系統的實現流程的文章就介紹到這瞭,更多相關Java 倉庫管理系統內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- SpringBoot 統一公共返回類的實現
- Java 實戰范例之員工管理系統的實現
- 關於postman傳參的幾種格式 list,map 等
- Java實戰之在線寄查快遞系統的實現
- Spring Boot中@RequestParam參數的5種情況說明