文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Java 实战项目之仓库管理系统的实现流程

2024-04-02 19:55

关注

一、项目简述

功能包括: 仓库管理,出入库管理,仓库人员管理,基本信息管理, 供应商信息,系统管理等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。

客户信息管理请求:



@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";
 
    
    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;
    }
 
    
    @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();
    }
 
    
    @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();
    }
 
    
    @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();
    }
 
    
    @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();
    }
 
    
    @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();
    }
 
    
    @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();
    }
 
    
    @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();
 
        }
    }
}

库存管理请求处理:



@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";
 
    
    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;
    }
 
    
    @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<>();
 
        // 设置 Response
        responseContent.setCustomerInfo("rows", rows);
        responseContent.setResponseTotal(total);
        return responseContent.generateResponse();
    }
 
    
    @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<>();
 
        // 设置 Response
        responseContent.setCustomerInfo("rows", rows);
        responseContent.setResponseTotal(total);
        return responseContent.generateResponse();
    }
 
    
    @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;
        }
 
        // 设置 Response
        responseContent.setResponseResult(isSuccess);
        return responseContent.generateResponse();
    }
 
    
    @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;
        }
 
        // 设置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    
    @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;
        }
 
        // 设置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    
    @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;
            }
        }
 
        // 设置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseTotal(total);
        responseContent.setCustomerInfo("available", available);
        return responseContent.generateResponse();
    }
 
    
    @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) {
            // 设置响应头
            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();
 
        }
    }
}

供应商信息管理请求:



@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";
 
    
    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;
    }
 
    
    @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);
 
        // 结果转换
        if (queryResult != null) {
            rows = (List<Supplier>) queryResult.get("data");
            total = (long) queryResult.get("total");
        }
 
        responseContent.setCustomerInfo("rows", rows);
        responseContent.setResponseTotal(total);
        return responseContent.generateResponse();
    }
 
    
    @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;
 
        // 设置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    
    @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;
 
        // 获取供应点信息
        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;
        }
 
        // 设置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseData(supplier);
        return responseContent.generateResponse();
    }
 
    
    @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;
 
        // 设置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    
    @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;
 
        // 设置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    
    @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;
 
        // 读取文件内容
        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");
        }
 
        // 设置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseTotal(total);
        responseContent.setCustomerInfo("available", available);
        return responseContent.generateResponse();
    }
 
    
    @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";
 
        // 根据查询类型进行查询
        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) {
            // 设置响应头
            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 = "/systemLog")
public class SystemLogHandler {
 
    @Autowired
    private SystemLogService systemLogService;
 
    
    @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 {
        // 创建 Response 对象
        Response response = ResponseFactory.newInstance();
        List<AccessRecordDO> 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 userIDCheck = (StringUtils.isEmpty(userIDStr) || StringUtils.isNumeric(userIDStr));
 
        if (startDateFormatCheck && endDateFormatCheck && userIDCheck) {
            // 转到 Service 执行查询
            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();
    }
 
    
    @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 {
        // 创建 Response
        Response response = ResponseFactory.newInstance();
        List<UserOperationRecordDTO> 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 userIDCheck = (StringUtils.isEmpty(userIDStr) || StringUtils.isNumeric(userIDStr));
 
        if (startDateFormatCheck && endDateFormatCheck && userIDCheck) {
            // 转到 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 实战项目之仓库管理系统的实现流程的详细内容,更多关于Java 仓库管理系统的资料请关注编程网其它相关文章!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯