项目介绍

管理员角色包含以下功能:
进货信息管理,员工信息管理,库存信息管理,销售信息管理,客户信息管理,供应商信息管理,系统信息管理,管理员登录等功能。

由于本程序规模不大,可供课程设计,毕业设计学习演示之用

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;

5.数据库:MySql 5.7版本;

技术栈

HTML+CSS+JavaScript+jsp+mysql

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;

4. 运行项目,输入localhost:8080/login.jsp 登录

运行截图

java项目中预警信息持久化存储方案 java库存预警_java

java项目中预警信息持久化存储方案 java库存预警_java项目中预警信息持久化存储方案_02

 

java项目中预警信息持久化存储方案 java库存预警_servlet_03

 

java项目中预警信息持久化存储方案 java库存预警_servlet_04

 

java项目中预警信息持久化存储方案 java库存预警_jvm_05

 

java项目中预警信息持久化存储方案 java库存预警_servlet_06

 

相关代码 

客户关系控制器

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

        }
    }
}

货物信息管理控制器

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

        }
    }
}

仓库管理控制器

@Controller
@RequestMapping(value = "/**/repositoryManage")
public class RepositoryManageHandler {

    @Autowired
    private RepositoryService repositoryService;

    private static final String SEARCH_BY_ID = "searchByID";
    private static final String SEARCH_BY_ADDRESS = "searchByAddress";
    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 RepositoryManageServiceException {
        Map<String, Object> queryResult = null;

        switch (searchType) {
            case SEARCH_BY_ID:
                if (StringUtils.isNumeric(keyword)) {
                    queryResult = repositoryService.selectById(Integer.valueOf(keyword));
                }
                break;
            case SEARCH_BY_ADDRESS:
                queryResult = repositoryService.selectByAddress(offset, limit, keyword);
                break;
            case SEARCH_ALL:
                queryResult = repositoryService.selectAll(offset, limit);
                break;
            default:
                // do other thing
                break;
        }

        return queryResult;
    }

    /**
     * 查询仓库信息
     *
     * @param searchType 查询类型
     * @param offset     分页偏移值
     * @param limit      分页大小
     * @param keyWord    查询关键字
     * @return 返回一个Map,其中key=rows,表示查询出来的记录;key=total,表示记录的总条数
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "getRepositoryList", method = RequestMethod.GET)
    public
    @ResponseBody
    Map<String, Object> getRepositoryList(@RequestParam("searchType") String searchType,
                                          @RequestParam("offset") int offset, @RequestParam("limit") int limit,
                                          @RequestParam("keyWord") String keyWord) throws RepositoryManageServiceException {
        // 初始化 Response
        Response responseContent = ResponseFactory.newInstance();

        List<Repository> rows = null;
        long total = 0;

        // 查询
        Map<String, Object> queryResult = query(searchType, keyWord, offset, limit);

        if (queryResult != null) {
            rows = (List<Repository>) queryResult.get("data");
            total = (long) queryResult.get("total");
        }

        // 设置 Response
        responseContent.setCustomerInfo("rows", rows);
        responseContent.setResponseTotal(total);
        return responseContent.generateResponse();
    }

    /**
     * 查询所有未指派管理员的仓库
     *
     * @return 返回一个 map,其中key=data表示查询的记录,key=total表示记录的条数
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "getUnassignRepository", method = RequestMethod.GET)
    public
    @ResponseBody
    Map<String, Object> getUnassignRepository() throws RepositoryManageServiceException {
        // 初始化结果集
        Map<String, Object> resultSet = new HashMap<>();
        List<Repository> data;
        long total = 0;

        // 查询
        Map<String, Object> queryResult = repositoryService.selectUnassign();
        if (queryResult != null) {
            data = (List<Repository>) queryResult.get("data");
            total = (long) queryResult.get("total");
        } else
            data = new ArrayList<>();

        resultSet.put("data", data);
        resultSet.put("total", total);
        return resultSet;
    }

    /**
     * 添加一条仓库信息
     *
     * @param repository 仓库信息
     * @return 返回一个map,其中:key 为 result表示操作的结果,包括:success 与 error
     */
    @RequestMapping(value = "addRepository", method = RequestMethod.POST)
    public
    @ResponseBody
    Map<String, Object> addRepository(@RequestBody Repository repository) throws RepositoryManageServiceException {
        // 初始化 Response
        Response responseContent = ResponseFactory.newInstance();

        // 添加记录
        String result = repositoryService.addRepository(repository) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR;

        // 设置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }

    /**
     * 查询指定 ID 的仓库信息
     *
     * @param repositoryID 仓库ID
     * @return 返回一个map,其中:key 为 result 的值为操作的结果,包括:success 与 error;key 为 data
     * 的值为仓库信息
     */
    @RequestMapping(value = "getRepositoryInfo", method = RequestMethod.GET)
    public
    @ResponseBody
    Map<String, Object> getRepositoryInfo(@RequestParam("repositoryID") Integer repositoryID) throws RepositoryManageServiceException {
        // 初始化 Response
        Response responseContent = ResponseFactory.newInstance();
        String result = Response.RESPONSE_RESULT_ERROR;

        // 查询
        Repository repository = null;
        Map<String, Object> queryResult = repositoryService.selectById(repositoryID);
        if (queryResult != null) {
            repository = (Repository) queryResult.get("data");
            if (repository != null)
                result = Response.RESPONSE_RESULT_SUCCESS;
        }

        // 设置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseData(repository);
        return responseContent.generateResponse();
    }

    /**
     * 更新仓库信息
     *
     * @param repository 仓库信息
     * @return 返回一个map,其中:key 为 result 的值为操作的结果,包括:success 与 error;key 为 data
     * 的值为仓库信息
     */
    @RequestMapping(value = "updateRepository", method = RequestMethod.POST)
    public
    @ResponseBody
    Map<String, Object> updateRepository(@RequestBody Repository repository) throws RepositoryManageServiceException {
        // 初始化 Response
        Response responseContent = ResponseFactory.newInstance();

        // 更新
        String result = repositoryService.updateRepository(repository) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR;

        // 设置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }

    /**
     * 删除指定 ID 的仓库信息
     *
     * @param repositoryID 仓库ID
     * @return 返回一个map,其中:key 为 result 的值为操作的结果,包括:success 与 error;key 为 data
     * 的值为仓库信息
     */
    @RequestMapping(value = "deleteRepository", method = RequestMethod.GET)
    public
    @ResponseBody
    Map<String, Object> deleteRepository(@RequestParam("repositoryID") Integer repositoryID) throws RepositoryManageServiceException {
        // 初始化 Response
        Response responseContent = ResponseFactory.newInstance();

        // 删除记录
        String result = repositoryService.deleteRepository(repositoryID) ? 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 = "importRepository", method = RequestMethod.POST)
    public
    @ResponseBody
    Map<String, Object> importRepository(MultipartFile file) throws RepositoryManageServiceException {
        // 初始化 Response
        Response responseContent = ResponseFactory.newInstance();
        String result = Response.RESPONSE_RESULT_ERROR;

        // 读取文件
        int total = 0;
        int available = 0;
        if (file != null) {
            Map<String, Object> importInfo = repositoryService.importRepository(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 = "exportRepository", method = RequestMethod.GET)
    public void exportRepository(@RequestParam("searchType") String searchType, @RequestParam("keyWord") String keyWord,
                                 HttpServletResponse response) throws RepositoryManageServiceException, IOException {

        // 导出文件名
        String fileName = "repositoryInfo.xlsx";

        // 查询
        List<Repository> repositories;

        Map<String, Object> queryResult = query(searchType, keyWord, -1, -1);

        if (queryResult != null)
            repositories = (List<Repository>) queryResult.get("data");
        else
            repositories = new ArrayList<>();

        // 生成文件
        File file = repositoryService.exportRepository(repositories);

        // 输出文件
        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();
        }
    }
}