溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)

發(fā)布時(shí)間:2022-01-24 13:41:36 來(lái)源:億速云 閱讀:165 作者:柒染 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要為大家分析了Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì)易懂,操作細(xì)節(jié)合理,具有一定參考價(jià)值。如果感興趣的話,不妨跟著跟隨小編一起來(lái)看看,下面跟著小編一起深入學(xué)習(xí)“Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)”的知識(shí)吧。

基于SSM框架的倉(cāng)庫(kù)管理系統(tǒng)

功能:

  • 系統(tǒng)操作權(quán)限管理。系統(tǒng)提供基本的登入登出功能,同時(shí)系統(tǒng)包含兩個(gè)角色:系統(tǒng)超級(jí)管理員和普通管理員,超級(jí)管理員具有最高的操作權(quán)限,而普通管理員僅具有最基本的操作權(quán)限,而且僅能操作自己被指派的倉(cāng)庫(kù)。

  • 請(qǐng)求URL鑒權(quán)。對(duì)于系統(tǒng)使用者登陸后進(jìn)行操作發(fā)送請(qǐng)求的URL,后臺(tái)會(huì)根據(jù)當(dāng)前用戶(hù)的角色判斷是否擁有請(qǐng)求該URL的權(quán)限。

  • 基礎(chǔ)數(shù)據(jù)信息管理。對(duì)包括:貨物信息、供應(yīng)商信息、客戶(hù)信息、倉(cāng)庫(kù)信息在內(nèi)的基礎(chǔ)數(shù)據(jù)信息進(jìn)行管理,提供的操作有:添加、刪除、修改、條件查詢(xún)、導(dǎo)出為Excel和到從Excel導(dǎo)入。

  • 倉(cāng)庫(kù)管理員管理。對(duì)倉(cāng)庫(kù)管理員信息CRUD操作,或者為指定的倉(cāng)庫(kù)管理員指派所管理的倉(cāng)庫(kù)。上述中的倉(cāng)庫(kù)管理員可以以普通管理員身份登陸到系統(tǒng)。

  • 庫(kù)存信息管理。對(duì)庫(kù)存信息的CRUD操作,導(dǎo)入導(dǎo)出操作,同時(shí)查詢(xún)的時(shí)候可以根據(jù)倉(cāng)庫(kù)以及商品ID等信息進(jìn)行多條件查詢(xún)。

  • 基本倉(cāng)庫(kù)事務(wù)操作。執(zhí)行貨物的入庫(kù)與出庫(kù)操作。

  • 系統(tǒng)登陸日志查詢(xún)。超級(jí)管理員可以查詢(xún)某一用戶(hù)在特定時(shí)間段內(nèi)的系統(tǒng)登陸日志。

  • 系統(tǒng)操作日志查詢(xún)。超級(jí)管理員可以查詢(xún)某一用戶(hù)在特定時(shí)間段內(nèi)對(duì)系統(tǒng)進(jìn)行操作的操作記錄。

  • 密碼修改。

使用到的框架和庫(kù):

  • Apache POI

  • MyBatis

  • Spring Framework

  • Spring MVC

  • Apache Shiro

  • Ehcache

  • Apache Commons

  • Log4j

  • Slf4j

  • Jackson

  • C3P0

  • Junit

  • MySQL-Connector

  • jQuery

  • Bootstrap

Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)

Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)

Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)

Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)

Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)

Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)

倉(cāng)庫(kù)管理員管理請(qǐng)求:

/**
 * 倉(cāng)庫(kù)管理員管理請(qǐng)求 Handler
 *
 * @author yy
 */
@Controller
@RequestMapping(value = "/**/repositoryAdminManage")
public class RepositoryAdminManageHandler {
 
    @Autowired
    private RepositoryAdminManageService repositoryAdminManageService;
 
    // 查詢(xún)類(lèi)型
    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";
 
    /**
     * 通用記錄查詢(xún)
     *
     * @param keyWord    查詢(xún)關(guān)鍵字
     * @param searchType 查詢(xún)類(lèi)型
     * @param offset     分頁(yè)偏移值
     * @param limit      分頁(yè)大小
     * @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;
    }
 
    /**
     * 查詢(xún)倉(cāng)庫(kù)管理員信息
     *
     * @param searchType 查詢(xún)類(lèi)型
     * @param offset     分頁(yè)偏移值
     * @param limit      分頁(yè)大小
     * @param keyWord    查詢(xún)關(guān)鍵字
     * @return 返回一個(gè)Map,其中key=rows,表示查詢(xún)出來(lái)的記錄;key=total,表示記錄的總條數(shù)
     */
    @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;
 
        // 查詢(xún)
        Map<String, Object> queryResult = query(keyWord, searchType, offset, limit);
 
        if (queryResult != null) {
            rows = (List<RepositoryAdmin>) queryResult.get("data");
            total = (long) queryResult.get("total");
        }
 
        // 設(shè)置 Response
        responseContent.setCustomerInfo("rows", rows);
        responseContent.setResponseTotal(total);
        return responseContent.generateResponse();
    }
 
    /**
     * 添加一條倉(cāng)庫(kù)管理員信息
     *
     * @param repositoryAdmin 倉(cāng)庫(kù)管理員信息
     * @return 返回一個(gè)map,其中:key 為 result表示操作的結(jié)果,包括:success 與 error
     */
    @RequestMapping(value = "addRepositoryAdmin", method = RequestMethod.POST)
    public
    @ResponseBody
    Map<String, Object> addRepositoryAdmin(@RequestBody RepositoryAdmin repositoryAdmin) throws RepositoryAdminManageServiceException {
        // 初始化 Response
        Response responseContent = ResponseFactory.newInstance();
 
        // 添加結(jié)果
        String result = repositoryAdminManageService.addRepositoryAdmin(repositoryAdmin)
                ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR;
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    /**
     * 查詢(xún)指定 ID 的倉(cāng)庫(kù)管理員信息
     *
     * @param repositoryAdminID 倉(cāng)庫(kù)管理員ID
     * @return 返回一個(gè)map,其中:key 為 result 的值為操作的結(jié)果,包括:success 與 error;key 為 data
     * 的值為倉(cāng)庫(kù)管理員信息
     */
    @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;
 
        // 查詢(xún)
        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;
        }
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseData(repositoryAdmin);
        return responseContent.generateResponse();
    }
 
    /**
     * 更新倉(cāng)庫(kù)管理員信息
     *
     * @param repositoryAdmin 倉(cāng)庫(kù)管理員信息
     * @return 返回一個(gè)map,其中:key 為 result 的值為操作的結(jié)果,包括:success 與 error;key 為 data
     * 的值為倉(cāng)庫(kù)管理員信息
     */
    @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;
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    /**
     * 刪除指定 ID 的倉(cāng)庫(kù)管理員信息
     *
     * @param repositoryAdminID 倉(cāng)庫(kù)ID
     * @return 返回一個(gè)map,其中:key 為 result 的值為操作的結(jié)果,包括:success 與 error;key 為 data
     * 的值為倉(cāng)庫(kù)管理員信息
     */
    @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;
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    /**
     * 從文件中導(dǎo)入倉(cāng)庫(kù)管理員信息
     *
     * @param file 保存有倉(cāng)庫(kù)管理員信息的文件
     * @return 返回一個(gè)map,其中:key 為 result表示操作的結(jié)果,包括:success 與
     * error;key為total表示導(dǎo)入的總條數(shù);key為available表示有效的條數(shù)
     */
    @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;
            }
        }
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseTotal(total);
        responseContent.setCustomerInfo("available", available);
        return responseContent.generateResponse();
    }
 
    /**
     * 導(dǎo)出倉(cāng)庫(kù)管理員信息到文件中
     *
     * @param searchType 查詢(xún)類(lèi)型
     * @param keyWord    查詢(xún)關(guān)鍵字
     * @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 {
 
        // 導(dǎo)出文件名
        String fileName = "repositoryAdminInfo.xlsx";
 
        // 查詢(xún)
        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) {
            // 設(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();
        }
    }
}

貨物信息管理請(qǐng)求: 

/**
 * 貨物信息管理請(qǐng)求 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";
 
    /**
     * 通用的記錄查詢(xún)
     *
     * @param searchType 查詢(xún)類(lèi)型
     * @param keyWord    查詢(xún)關(guān)鍵字
     * @param offset     分頁(yè)偏移值
     * @param limit      分頁(yè)大小
     * @return 返回一個(gè) Map ,包含所有符合要求的查詢(xún)結(jié)果,以及記錄的條數(shù)
     */
    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 搜索類(lèi)型
     * @param offset     如有多條記錄時(shí)分頁(yè)的偏移值
     * @param limit      如有多條記錄時(shí)分頁(yè)的大小
     * @param keyWord    搜索的關(guān)鍵字
     * @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;
 
        // 查詢(xún)
        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);
        return responseContent.generateResponse();
    }
 
    /**
     * 添加一條貨物信息
     *
     * @param goods 貨物信息
     * @return 返回一個(gè)map,其中:key 為 result表示操作的結(jié)果,包括: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;
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
 
        return responseContent.generateResponse();
    }
 
    /**
     * 查詢(xún)指定 goods ID 貨物的信息
     *
     * @param goodsID 貨物ID
     * @return 返回一個(gè)map,其中:key 為 result 的值為操作的結(jié)果,包括: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;
            }
        }
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseData(goods);
        return responseContent.generateResponse();
    }
 
    /**
     * 更新貨物信息
     *
     * @param goods 貨物信息
     * @return 返回一個(gè)map,其中:key 為 result表示操作的結(jié)果,包括: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;
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    /**
     * 刪除貨物記錄
     *
     * @param goodsID 貨物ID
     * @return 返回一個(gè)map,其中:key 為 result表示操作的結(jié)果,包括: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;
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    /**
     * 導(dǎo)入貨物信息
     *
     * @param file 保存有貨物信息的文件
     * @return 返回一個(gè)map,其中:key 為 result表示操作的結(jié)果,包括:success 與
     * error;key為total表示導(dǎo)入的總條數(shù);key為available表示有效的條數(shù)
     */
    @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;
 
        // 讀取文件內(nèi)容
        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;
            }
        }
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        responseContent.setResponseTotal(total);
        responseContent.setCustomerInfo("available", available);
        return responseContent.generateResponse();
    }
 
    /**
     * 導(dǎo)出貨物信息
     *
     * @param searchType 查找類(lèi)型
     * @param keyWord    查找關(guān)鍵字
     * @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);
 
        // 寫(xiě)出文件
        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();
 
        }
    }
}

客戶(hù)信息管理請(qǐng)求:

/**
 * 客戶(hù)信息管理請(qǐng)求 
 *
 * @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";
 
    /**
     * 通用的結(jié)果查詢(xún)方法
     *
     * @param searchType 查詢(xún)方式
     * @param keyWord    查詢(xún)關(guān)鍵字
     * @param offset     分頁(yè)偏移值
     * @param limit      分頁(yè)大小
     * @return 返回指定條件查詢(xún)的結(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;
    }
 
    /**
     * 搜索客戶(hù)信息
     *
     * @param searchType 搜索類(lèi)型
     * @param offset     如有多條記錄時(shí)分頁(yè)的偏移值
     * @param limit      如有多條記錄時(shí)分頁(yè)的大小
     * @param keyWord    搜索的關(guān)鍵字
     * @return 返回查詢(xún)的結(jié)果,其中鍵值為 rows 的代表查詢(xún)到的每一記錄,若有分頁(yè)則為分頁(yè)大小的記錄;鍵值為 total 代表查詢(xún)到的符合要求的記錄總條數(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();
    }
 
    /**
     * 添加一條客戶(hù)信息
     *
     * @param customer 客戶(hù)信息
     * @return 返回一個(gè)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();
    }
 
    /**
     * 查詢(xún)指定 customer ID 客戶(hù)的信息
     *
     * @param customerID 客戶(hù)ID
     * @return 返回一個(gè)map,其中:key 為 result 的值為操作的結(jié)果,包括:success 與 error;key 為 data
     * 的值為客戶(hù)信息
     */
    @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;
 
        // 獲取客戶(hù)信息
        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();
    }
 
    /**
     * 更新客戶(hù)信息
     *
     * @param customer 客戶(hù)信息
     * @return 返回一個(gè)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();
    }
 
    /**
     * 刪除客戶(hù)記錄
     *
     * @param customerIDStr 客戶(hù)ID
     * @return 返回一個(gè)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)入客戶(hù)信息
     *
     * @param file 保存有客戶(hù)信息的文件
     * @return 返回一個(gè)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)出客戶(hù)信息
     *
     * @param searchType 查找類(lèi)型
     * @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);
 
        // 寫(xiě)出文件
        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();
 
        }
    }
}

商品出入庫(kù)管理請(qǐng)求:

/**
 * 商品出入庫(kù)管理請(qǐng)求
 *
 * @author yy
 */
@Controller
@RequestMapping(value = "stockRecordManage")
public class StockRecordManageHandler {
 
    @Autowired
    private StockRecordManageService stockRecordManageService;
 
    /**
     * 貨物出庫(kù)操作
     *
     * @param customerID      客戶(hù)ID
     * @param goodsID         貨物ID
     * @param repositoryIDStr 倉(cāng)庫(kù)ID
     * @param number          出庫(kù)數(shù)量
     * @return 返回一個(gè)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;
 
        // 參數(shù)檢查
        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();
 
        // 設(shè)置非管理員請(qǐng)求的倉(cāng)庫(kù)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;
        }
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    /**
     * 貨物入庫(kù)操作
     *
     * @param supplierID      供應(yīng)商ID
     * @param goodsID         貨物ID
     * @param repositoryIDStr 倉(cāng)庫(kù)ID
     * @param number          入庫(kù)數(shù)目
     * @return 返回一個(gè)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;
 
        // 參數(shù)檢查
        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();
 
        // 設(shè)置非管理員請(qǐng)求的倉(cāng)庫(kù)ID
        if (!currentUser.hasRole("systemAdmin")) {
            if (repositoryIDBelong < 0) {
                authorizeCheck = false;
                responseContent.setResponseMsg("You are not authorized");
            } else {
                repositoryID = repositoryIDBelong;
            }
        }
 
        // 執(zhí)行 Service
        if (authorizeCheck && argumentCheck) {
            if (stockRecordManageService.stockInOperation(supplierID, goodsID, repositoryID, number, personInCharge)) {
                result = Response.RESPONSE_RESULT_SUCCESS;
            }
        }
 
        // 設(shè)置 Response
        responseContent.setResponseResult(result);
        return responseContent.generateResponse();
    }
 
    /**
     * 查詢(xún)出入庫(kù)記錄
     *
     * @param searchType      查詢(xún)類(lèi)型(查詢(xún)所有或僅查詢(xún)?nèi)霂?kù)記錄或僅查詢(xún)出庫(kù)記錄)
     * @param repositoryIDStr 查詢(xún)記錄所對(duì)應(yīng)的倉(cāng)庫(kù)ID
     * @param endDateStr      查詢(xún)的記錄起始日期
     * @param startDateStr    查詢(xún)的記錄結(jié)束日期
     * @param limit           分頁(yè)大小
     * @param offset          分頁(yè)偏移值
     * @return 返回一個(gè)Map,其中:Key為rows的值代表所有記錄數(shù)據(jù),Key為total的值代表記錄的總條數(shù)
     */
    @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;
 
        // 參數(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 repositoryIDCheck = (StringUtils.isEmpty(repositoryIDStr) || StringUtils.isNumeric(repositoryIDStr));
 
        if (startDateFormatCheck && endDateFormatCheck && repositoryIDCheck) {
            Integer repositoryID = -1;
            if (StringUtils.isNumeric(repositoryIDStr)) {
                repositoryID = Integer.valueOf(repositoryIDStr);
            }
 
            // 轉(zhuǎn)到 Service 執(zhí)行查詢(xún)
            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();
    }
}

關(guān)于“Java實(shí)戰(zhàn)中怎樣進(jìn)行倉(cāng)庫(kù)管理系統(tǒng)的實(shí)現(xiàn)”就介紹到這了,更多相關(guān)內(nèi)容可以搜索億速云以前的文章,希望能夠幫助大家答疑解惑,請(qǐng)多多支持億速云網(wǎng)站!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI