Java 實戰(zhàn)項目之倉庫管理系統(tǒng)的實現(xiàn)流程
一、項目簡述
功能包括: 倉庫管理,出入庫管理,倉庫人員管理,基本信息管理, 供應(yīng)商信息,系統(tǒng)管理等等。
二、項目運行
環(huán)境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
項目技術(shù): JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
客戶信息管理請求:
/** * 客戶信息管理請求 Handler */ @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"; /** * 通用的結(jié)果查詢方法 * * @param searchType 查詢方式 * @param keyWord 查詢關(guān)鍵字 * @param offset 分頁偏移值 * @param limit 分頁大小 * @return 返回指定條件查詢的結(jié)果 */ 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 搜索的關(guān)鍵字 * @return 返回查詢的結(jié)果,其中鍵值為 rows 的代表查詢到的每一記錄,若有分頁則為分頁大小的記錄;鍵值為 total 代表查詢到的符合要求的記錄總條數(shù) */ @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"); } // 設(shè)置 Response responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); responseContent.setResponseResult(Response.RESPONSE_RESULT_SUCCESS); return responseContent.generateResponse(); } /** * 添加一條客戶信息 * * @param customer 客戶信息 * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括: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 的值為操作的結(jié)果,包括: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; } } // 設(shè)置 Response responseContent.setResponseResult(result); responseContent.setResponseData(customer); return responseContent.generateResponse(); } /** * 更新客戶信息 * * @param customer 客戶信息 * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括: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表示操作的結(jié)果,包括: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(); // 參數(shù)檢查 if (StringUtils.isNumeric(customerIDStr)) { // 轉(zhuǎn)換為 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(); } /** * 導(dǎo)入客戶信息 * * @param file 保存有客戶信息的文件 * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 * error;key為total表示導(dǎo)入的總條數(shù);key為available表示有效的條數(shù) */ @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; // 讀取文件內(nèi)容 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(); } /** * 導(dǎo)出客戶信息 * * @param searchType 查找類型 * @param keyWord 查找關(guān)鍵字 * @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) { // 設(shè)置響應(yīng)頭 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(); } } }
庫存管理請求處理:
/** * 庫存管理請求處理 */ @Controller @RequestMapping(value = "/**/storageManage") public class StorageManageHandler { @Autowired private StorageManageService storageManageService; @Autowired private StockRecordManageService stockRecordManageService; private static final String SEARCH_BY_GOODS_ID = "searchByGoodsID"; private static final String SEARCH_BY_GOODS_NAME = "searchByGoodsName"; private static final String SEARCH_BY_GOODS_TYPE = "searchByGoodsType"; private static final String SEARCH_ALL = "searchAll"; /** * 查詢庫存信息 * * @param searchType 查詢類型 * @param keyword 查詢關(guān)鍵字 * @param repositoryBelong 查詢倉庫 * @param offset 分頁偏移值 * @param limit 分頁大小 * @return 結(jié)果的一個Map,其中: key為 data 的代表記錄數(shù)據(jù);key 為 total 代表結(jié)果記錄的數(shù)量 */ private Map<String, Object> query(String searchType, String keyword, String repositoryBelong, int offset, int limit) throws StorageManageServiceException { Map<String, Object> queryResult = null; switch (searchType) { case SEARCH_ALL: if (StringUtils.isNumeric(repositoryBelong)) { Integer repositoryID = Integer.valueOf(repositoryBelong); queryResult = storageManageService.selectAll(repositoryID, offset, limit); } else { queryResult = storageManageService.selectAll(-1, offset, limit); } break; case SEARCH_BY_GOODS_ID: if (StringUtils.isNumeric(keyword)) { Integer goodsID = Integer.valueOf(keyword); if (StringUtils.isNumeric(repositoryBelong)) { Integer repositoryID = Integer.valueOf(repositoryBelong); queryResult = storageManageService.selectByGoodsID(goodsID, repositoryID, offset, limit); } else queryResult = storageManageService.selectByGoodsID(goodsID, -1, offset, limit); } break; case SEARCH_BY_GOODS_TYPE: if (StringUtils.isNumeric(repositoryBelong)) { Integer repositoryID = Integer.valueOf(repositoryBelong); queryResult = storageManageService.selectByGoodsType(keyword, repositoryID, offset, limit); } else queryResult = storageManageService.selectByGoodsType(keyword, -1, offset, limit); break; case SEARCH_BY_GOODS_NAME: if (StringUtils.isNumeric(repositoryBelong)) { Integer repositoryID = Integer.valueOf(repositoryBelong); queryResult = storageManageService.selectByGoodsName(keyword, repositoryID, offset, limit); } else queryResult = storageManageService.selectByGoodsName(keyword, -1, offset, limit); break; default: // do other thing break; } return queryResult; } /** * 可指定倉庫對庫存信息查詢 * * @param keyword 查詢關(guān)鍵字 * @param searchType 查詢類型 * @param repositoryBelong 查詢所屬的倉庫 * @param offset 分頁偏移值 * @param limit 分頁大小 * @return 結(jié)果的一個Map,其中: key為 rows 的代表記錄數(shù)據(jù);key 為 total 代表結(jié)果記錄的數(shù)量 */ @SuppressWarnings("unchecked") @RequestMapping(value = "getStorageListWithRepository", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getStorageListWithRepoID(@RequestParam("keyword") String keyword, @RequestParam("searchType") String searchType, @RequestParam("repositoryBelong") String repositoryBelong, @RequestParam("offset") int offset, @RequestParam("limit") int limit) throws StorageManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); List<Storage> rows; long total = 0; // query Map<String, Object> queryResult = query(searchType, keyword, repositoryBelong, offset, limit); if (queryResult != null) { rows = (List<Storage>) queryResult.get("data"); total = (long) queryResult.get("total"); } else rows = new ArrayList<>(); // 設(shè)置 Response responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); return responseContent.generateResponse(); } /** * 查詢庫存信息,查詢所屬的倉庫為session保存的信息 * * @param keyword 查詢關(guān)鍵字 * @param searchType 查詢類型 * @param offset 分頁偏移值 * @param limit 分頁大小 * @param request 請求 * @return 結(jié)果的一個Map,其中: key為 rows 的代表記錄數(shù)據(jù);key 為 total 代表結(jié)果記錄的數(shù)量 */ @SuppressWarnings("unchecked") @RequestMapping(value = "getStorageList", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getStorageList(@RequestParam("keyword") String keyword, @RequestParam("searchType") String searchType, @RequestParam("offset") int offset, @RequestParam("limit") int limit, HttpServletRequest request) throws StorageManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); List<Storage> rows = null; long total = 0; HttpSession session = request.getSession(); UserInfoDTO userInfo = (UserInfoDTO) session.getAttribute("userInfo"); Integer repositoryID = userInfo.getRepositoryBelong(); if (repositoryID > 0) { Map<String, Object> queryResult = query(searchType, keyword, repositoryID.toString(), offset, limit); if (queryResult != null) { rows = (List<Storage>) queryResult.get("data"); total = (long) queryResult.get("total"); } } if (rows == null) rows = new ArrayList<>(); // 設(shè)置 Response responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); return responseContent.generateResponse(); } /** * 添加一條庫存信息 * * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 error */ @RequestMapping(value = "addStorageRecord", method = RequestMethod.POST) public @ResponseBody Map<String, Object> addStorageRecord(@RequestBody Map<String, Object> params) throws StorageManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String isSuccess = Response.RESPONSE_RESULT_ERROR; boolean isAvailable = true; String goodsID = (String) params.get("goodsID"); String repositoryID = (String) params.get("repositoryID"); String number = (String) params.get("number"); if (StringUtils.isBlank(goodsID) || !StringUtils.isNumeric(goodsID)) isAvailable = false; if (StringUtils.isBlank(repositoryID) || !StringUtils.isNumeric(repositoryID)) isAvailable = false; if (StringUtils.isBlank(number) || !StringUtils.isNumeric(number)) isAvailable = false; if (isAvailable) { isSuccess = storageManageService.addNewStorage(Integer.valueOf(goodsID), Integer.valueOf(repositoryID), Integer.valueOf(number)) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; } // 設(shè)置 Response responseContent.setResponseResult(isSuccess); return responseContent.generateResponse(); } /** * 更新庫存信息 * * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 error */ @RequestMapping(value = "updateStorageRecord", method = RequestMethod.POST) public @ResponseBody Map<String, Object> updateStorageRecord(@RequestBody Map<String, Object> params) throws StorageManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); boolean isAvailable = true; String result = Response.RESPONSE_RESULT_ERROR; String goodsID = (String) params.get("goodsID"); String repositoryID = (String) params.get("repositoryID"); String number = (String) params.get("number"); if (StringUtils.isBlank(goodsID) || !StringUtils.isNumeric(goodsID)) isAvailable = false; if (StringUtils.isBlank(repositoryID) || !StringUtils.isNumeric(repositoryID)) isAvailable = false; if (StringUtils.isBlank(number) || !StringUtils.isNumeric(number)) isAvailable = false; if (isAvailable) { result = storageManageService.updateStorage(Integer.valueOf(goodsID), Integer.valueOf(repositoryID), Integer.valueOf(number)) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; } // 設(shè)置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 刪除一條庫存信息 * * @param goodsID 貨物ID * @param repositoryID 倉庫ID * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 error */ @RequestMapping(value = "deleteStorageRecord", method = RequestMethod.GET) public @ResponseBody Map<String, Object> deleteStorageRecord(@RequestParam("goodsID") String goodsID, @RequestParam("repositoryID") String repositoryID) throws StorageManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; boolean isAvailable = true; if (StringUtils.isBlank(goodsID) || !StringUtils.isNumeric(goodsID)) isAvailable = false; if (StringUtils.isBlank(repositoryID) || !StringUtils.isNumeric(repositoryID)) isAvailable = false; if (isAvailable) { result = storageManageService.deleteStorage(Integer.valueOf(goodsID), Integer.valueOf(repositoryID)) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; } // 設(shè)置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 導(dǎo)入庫存信息 * * @param file 保存有庫存信息的文件 * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 * error;key為total表示導(dǎo)入的總條數(shù);key為available表示有效的條數(shù) */ @RequestMapping(value = "importStorageRecord", method = RequestMethod.POST) public @ResponseBody Map<String, Object> importStorageRecord(@RequestParam("file") MultipartFile file) throws StorageManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; int total = 0; int available = 0; if (file != null) { Map<String, Object> importInfo = storageManageService.importStorage(file); if (importInfo != null) { total = (int) importInfo.get("total"); available = (int) importInfo.get("available"); result = Response.RESPONSE_RESULT_SUCCESS; } } // 設(shè)置 Response responseContent.setResponseResult(result); responseContent.setResponseTotal(total); responseContent.setCustomerInfo("available", available); return responseContent.generateResponse(); } /** * 導(dǎo)出庫存信息 * * @param searchType 查詢類型 * @param keyword 查詢關(guān)鍵字 * @param repositoryBelong 查詢所屬倉庫 * @param request 請求 * @param response 響應(yīng) */ @SuppressWarnings("unchecked") @RequestMapping(value = "exportStorageRecord", method = RequestMethod.GET) public void exportStorageRecord(@RequestParam("searchType") String searchType, @RequestParam("keyword") String keyword, @RequestParam(value = "repositoryBelong", required = false) String repositoryBelong, HttpServletRequest request, HttpServletResponse response) throws StorageManageServiceException, IOException { String fileName = "storageRecord.xlsx"; HttpSession session = request.getSession(); UserInfoDTO userInfo = (UserInfoDTO) session.getAttribute("userInfo"); Integer sessionRepositoryBelong = userInfo.getRepositoryBelong(); if (sessionRepositoryBelong > 0) repositoryBelong = sessionRepositoryBelong.toString(); List<Storage> storageList = null; Map<String, Object> queryResult = query(searchType, keyword, repositoryBelong, -1, -1); if (queryResult != null) storageList = (List<Storage>) queryResult.get("data"); File file = storageManageService.exportStorage(storageList); if (file != null) { // 設(shè)置響應(yīng)頭 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(); } } }
供應(yīng)商信息管理請求:
/** * 供應(yīng)商信息管理請求 Handler * */ @RequestMapping(value = "/**/supplierManage") @Controller public class SupplierManageHandler { @Autowired private SupplierManageService supplierManageService; 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 查詢關(guān)鍵字 * @param offset 分頁偏移值 * @param limit 分頁大小 * @return 返回所有符合條件的記錄 */ private Map<String, Object> query(String searchType, String keyWord, int offset, int limit) throws SupplierManageServiceException { Map<String, Object> queryResult = null; switch (searchType) { case SEARCH_BY_ID: if (StringUtils.isNumeric(keyWord)) { queryResult = supplierManageService.selectById(Integer.valueOf(keyWord)); } break; case SEARCH_BY_NAME: queryResult = supplierManageService.selectByName(offset, limit, keyWord); break; case SEARCH_ALL: queryResult = supplierManageService.selectAll(offset, limit); break; default: // do other thing break; } return queryResult; } /** * 搜索供應(yīng)商信息 * * @param searchType 搜索類型 * @param offset 如有多條記錄時分頁的偏移值 * @param limit 如有多條記錄時分頁的大小 * @param keyWord 搜索的關(guān)鍵字 * @return */ @RequestMapping(value = "getSupplierList", method = RequestMethod.GET) @ResponseBody public Map<String, Object> getSupplierList(@RequestParam("searchType") String searchType, @RequestParam("offset") int offset, @RequestParam("limit") int limit, @RequestParam("keyWord") String keyWord) throws SupplierManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); List<Supplier> rows = null; long total = 0; Map<String, Object> queryResult = query(searchType, keyWord, offset, limit); // 結(jié)果轉(zhuǎn)換 if (queryResult != null) { rows = (List<Supplier>) queryResult.get("data"); total = (long) queryResult.get("total"); } responseContent.setCustomerInfo("rows", rows); responseContent.setResponseTotal(total); return responseContent.generateResponse(); } /** * 添加一條供應(yīng)商信息 * * @param supplier 供應(yīng)商信息 * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 error */ @RequestMapping(value = "addSupplier", method = RequestMethod.POST) public @ResponseBody Map<String, Object> addSupplier(@RequestBody Supplier supplier) throws SupplierManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 添加記錄 String result = supplierManageService.addSupplier(supplier) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設(shè)置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 查詢指定 supplierID 供應(yīng)商的信息 * * @param supplierID 供應(yīng)商ID * @return 返回一個map,其中:key 為 result 的值為操作的結(jié)果,包括:success 與 error;key 為 data * 的值為供應(yīng)商信息 */ @RequestMapping(value = "getSupplierInfo", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getSupplierInfo(@RequestParam("supplierID") int supplierID) throws SupplierManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_ERROR; // 獲取供應(yīng)點信息 Supplier supplier = null; Map<String, Object> queryResult = supplierManageService.selectById(supplierID); if (queryResult != null) { supplier = (Supplier) queryResult.get("data"); if (supplier != null) result = Response.RESPONSE_RESULT_SUCCESS; } // 設(shè)置 Response responseContent.setResponseResult(result); responseContent.setResponseData(supplier); return responseContent.generateResponse(); } /** * 更新供應(yīng)商信息 * * @param supplier 供應(yīng)商信息 * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 error */ @RequestMapping(value = "updateSupplier", method = RequestMethod.POST) public @ResponseBody Map<String, Object> updateSupplier(@RequestBody Supplier supplier) throws SupplierManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 更新 String result = supplierManageService.updateSupplier(supplier) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設(shè)置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 刪除供應(yīng)商記錄 * * @param supplierID 供應(yīng)商ID * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 error */ @RequestMapping(value = "deleteSupplier", method = RequestMethod.GET) public @ResponseBody Map<String, Object> deleteSupplier(@RequestParam("supplierID") Integer supplierID) { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); // 刪除 String result = supplierManageService.deleteSupplier(supplierID) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR; // 設(shè)置 Response responseContent.setResponseResult(result); return responseContent.generateResponse(); } /** * 導(dǎo)入供應(yīng)商信息 * * @param file 保存有供應(yīng)商信息的文件 * @return 返回一個map,其中:key 為 result表示操作的結(jié)果,包括:success 與 * error;key為total表示導(dǎo)入的總條數(shù);key為available表示有效的條數(shù) */ @RequestMapping(value = "importSupplier", method = RequestMethod.POST) public @ResponseBody Map<String, Object> importSupplier(@RequestParam("file") MultipartFile file) throws SupplierManageServiceException { // 初始化 Response Response responseContent = ResponseFactory.newInstance(); String result = Response.RESPONSE_RESULT_SUCCESS; // 讀取文件內(nèi)容 int total = 0; int available = 0; if (file == null) result = Response.RESPONSE_RESULT_ERROR; Map<String, Object> importInfo = supplierManageService.importSupplier(file); if (importInfo != null) { total = (int) importInfo.get("total"); available = (int) importInfo.get("available"); } // 設(shè)置 Response responseContent.setResponseResult(result); responseContent.setResponseTotal(total); responseContent.setCustomerInfo("available", available); return responseContent.generateResponse(); } /** * 導(dǎo)出供應(yīng)商信息 * * @param searchType 查找類型 * @param keyWord 查找關(guān)鍵字 * @param response HttpServletResponse */ @SuppressWarnings("unchecked") @RequestMapping(value = "exportSupplier", method = RequestMethod.GET) public void exportSupplier(@RequestParam("searchType") String searchType, @RequestParam("keyWord") String keyWord, HttpServletResponse response) throws SupplierManageServiceException, IOException { String fileName = "supplierInfo.xlsx"; // 根據(jù)查詢類型進行查詢 List<Supplier> suppliers = null; Map<String, Object> queryResult; queryResult = query(searchType, keyWord, -1, -1); if (queryResult != null) { suppliers = (List<Supplier>) queryResult.get("data"); } // 獲取生成的文件 File file = supplierManageService.exportSupplier(suppliers); // 寫出文件 if (file != null) { // 設(shè)置響應(yīng)頭 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(); } } }
系統(tǒng)操作日志請求:
/** * 系統(tǒng)操作日志請求 Handler */ @Controller @RequestMapping(value = "/systemLog") public class SystemLogHandler { @Autowired private SystemLogService systemLogService; /** * 查詢系統(tǒng)的登入登出日志 * * @param userIDStr 用戶ID * @param accessType 記錄類型(登入、登出或全部) * @param startDateStr 記錄的起始日期 * @param endDateStr 記錄的結(jié)束日期 * @param offset 分頁的偏移值 * @param limit 分頁的大小 * @return 返回 JSON 數(shù)據(jù) 其中:Key為rows的值代表所有記錄數(shù)據(jù),Key為total的值代表記錄的總條數(shù) * @throws SystemLogServiceException SystemLogServiceException */ @SuppressWarnings("unchecked") @RequestMapping(value = "getAccessRecords", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getAccessRecords(@RequestParam("userID") String userIDStr, @RequestParam("accessType") String accessType, @RequestParam("startDate") String startDateStr, @RequestParam("endDate") String endDateStr, @RequestParam("offset") int offset, @RequestParam("limit") int limit) throws SystemLogServiceException { // 創(chuàng)建 Response 對象 Response response = ResponseFactory.newInstance(); List<AccessRecordDO> rows = null; long total = 0; // 檢查參數(shù) 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 userIDCheck = (StringUtils.isEmpty(userIDStr) || StringUtils.isNumeric(userIDStr)); if (startDateFormatCheck && endDateFormatCheck && userIDCheck) { // 轉(zhuǎn)到 Service 執(zhí)行查詢 Integer userID = -1; if (StringUtils.isNumeric(userIDStr)) userID = Integer.valueOf(userIDStr); Map<String, Object> queryResult = systemLogService.selectAccessRecord(userID, accessType, startDateStr, endDateStr, offset, limit); if (queryResult != null) { rows = (List<AccessRecordDO>) queryResult.get("data"); total = (long) queryResult.get("total"); } } else response.setResponseMsg("Request Argument Error"); if (rows == null) rows = new ArrayList<>(0); // 返回 Response response.setCustomerInfo("rows", rows); response.setResponseTotal(total); return response.generateResponse(); } /** * 查詢系統(tǒng)的操作日志 * * @param userIDStr 用戶ID * @param startDateStr 記錄的起始日期 * @param endDateStr 記錄的結(jié)束日期 * @param offset 分頁的偏移值 * @param limit 分頁的大小 * @return 返回 JSON 數(shù)據(jù) 其中:Key為rows的值代表所有記錄數(shù)據(jù),Key為total的值代表記錄的總條數(shù) * @throws SystemLogServiceException SystemLogServiceException */ @SuppressWarnings("unchecked") @RequestMapping(value = "getUserOperationRecords") public @ResponseBody Map<String, Object> selectUserOperationRecords(@RequestParam("userID") String userIDStr, @RequestParam("startDate") String startDateStr, @RequestParam("endDate") String endDateStr, @RequestParam("offset") int offset, @RequestParam("limit") int limit) throws SystemLogServiceException { // 創(chuàng)建 Response Response response = ResponseFactory.newInstance(); List<UserOperationRecordDTO> rows = null; long total = 0; // 檢查參數(shù) 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 userIDCheck = (StringUtils.isEmpty(userIDStr) || StringUtils.isNumeric(userIDStr)); if (startDateFormatCheck && endDateFormatCheck && userIDCheck) { // 轉(zhuǎn)到 Service 進行查詢 Integer userID = -1; if (StringUtils.isNumeric(userIDStr)) userID = Integer.valueOf(userIDStr); Map<String, Object> queryResult = systemLogService.selectUserOperationRecord(userID, startDateStr, endDateStr, offset, limit); if (queryResult != null) { rows = (List<UserOperationRecordDTO>) queryResult.get("data"); total = (long) queryResult.get("total"); } } else response.setResponseMsg("Request argument error"); if (rows == null) rows = new ArrayList<>(0); response.setCustomerInfo("rows", rows); response.setResponseTotal(total); return response.generateResponse(); } }
以上就是Java 實戰(zhàn)項目之倉庫管理系統(tǒng)的實現(xiàn)流程的詳細(xì)內(nèi)容,更多關(guān)于Java 倉庫管理系統(tǒng)的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java網(wǎng)絡(luò)編程之TCP程序設(shè)計
這篇文章主要為大家詳細(xì)介紹了Java網(wǎng)絡(luò)編程之TCP程序設(shè)計,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08Java實現(xiàn)給網(wǎng)站上傳圖片蓋章的方法
這篇文章主要介紹了Java實現(xiàn)給網(wǎng)站上傳圖片蓋章的方法,涉及java針對圖片的合成操作技巧,類似水印功能,需要的朋友可以參考下2015-07-07關(guān)于springboot配置druid數(shù)據(jù)源不生效問題(踩坑記)
今天日常跟著網(wǎng)課學(xué)習(xí),學(xué)到了整合druid數(shù)據(jù)源,遇到了好幾個坑,希望這篇文章可以幫助一些和我一樣踩坑的人2021-09-09Spring init-method與destroy-method屬性的用法解析
這篇文章主要介紹了Spring init-method與destroy-method屬性的用法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08SpringBoot+WebSocket實現(xiàn)多人在線聊天案例實例
本文主要介紹了SpringBoot+WebSocket實現(xiàn)多人在線聊天案例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02