Index: ssts-web/src/main/java/com/forgon/disinfectsystem/systemexamination/action/DisposableGoodsStockExaminationAction.java =================================================================== diff -u -r29362 -r29377 --- ssts-web/src/main/java/com/forgon/disinfectsystem/systemexamination/action/DisposableGoodsStockExaminationAction.java (.../DisposableGoodsStockExaminationAction.java) (revision 29362) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/systemexamination/action/DisposableGoodsStockExaminationAction.java (.../DisposableGoodsStockExaminationAction.java) (revision 29377) @@ -1,7 +1,11 @@ package com.forgon.disinfectsystem.systemexamination.action; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import net.sf.json.JSONArray; @@ -71,35 +75,88 @@ * 异常情况2:批次库存的数量不等于属于该批次的所有标识号的库存数量总和 * 异常情况3:一次性物品库存的数量不等于属于该一次性物品的所有批次的库存数量总和 */ + @SuppressWarnings("unchecked") public void disposableGoodsStockExamination(){ JSONArray data = new JSONArray(); - List disposableGoodsList = diposableGoodsManager.getAll("sequence"); + //一次性物品定义 + String disposableGoodsHql = String.format(" po.goodsType = '%s' order by po.sequence ", DisposableGoods.TYPE_DIPOSABLEGOODS); + List disposableGoodsList = diposableGoodsManager.getByHql(disposableGoodsHql); if(CollectionUtils.isNotEmpty(disposableGoodsList)){ + Map idToDisposableGoodsMap = new LinkedHashMap(); + for (DisposableGoods disposableGoods : disposableGoodsList) { + idToDisposableGoodsMap.put(disposableGoods.getId(), disposableGoods); + } + + //一次性物品库存 + List disposableGoodsStockList = objectDao.findAllObjects(DisposableGoodsStock.class.getSimpleName()); + Map idToDisposableGoodsStockMap = new HashMap(); + Map> disposableGoodsIdToStockMap = new HashMap>(); + for (DisposableGoodsStock disposableGoodsStock : disposableGoodsStockList) { + idToDisposableGoodsStockMap.put(disposableGoodsStock.getId(), disposableGoodsStock); + List list = disposableGoodsIdToStockMap.get(disposableGoodsStock.getDisposableGoodsID()); + if(list == null){ + list = new ArrayList(); + } + list.add(disposableGoodsStock); + disposableGoodsIdToStockMap.put(disposableGoodsStock.getDisposableGoodsID(), list); + } + //一次性物品批次 + List disposableGoodsBatchList = objectDao.findAllObjects(DisposableGoodsBatch.class.getSimpleName()); + Map idToDisposableGoodsBatchMap = new HashMap(); + for (DisposableGoodsBatch disposableGoodsBatch : disposableGoodsBatchList) { + idToDisposableGoodsBatchMap.put(disposableGoodsBatch.getId(), disposableGoodsBatch); + } + //一次性物品批次库存 + List disposableGoodsBatchStockList = objectDao.findAllObjects(DisposableGoodsBatchStock.class.getSimpleName()); + Map> disposableGoodsStockIdToBatchStockMap = new HashMap>(); + for (DisposableGoodsBatchStock disposableGoodsBatchStock : disposableGoodsBatchStockList) { + List list = disposableGoodsStockIdToBatchStockMap.get(disposableGoodsBatchStock.getDisposableGoodsStockId()); + if(list == null){ + list = new ArrayList(); + } + list.add(disposableGoodsBatchStock); + disposableGoodsStockIdToBatchStockMap.put(disposableGoodsBatchStock.getDisposableGoodsStockId(), list); + } + //一次性物品标识号 + List identifications = objectDao.findAllObjects(DisposableGoodsIdentification.class.getSimpleName()); + Map> disposableGoodsBatchStockIdToIDMap = new HashMap>(); + for (DisposableGoodsIdentification disposableGoodsIdentification : identifications) { + List list = disposableGoodsBatchStockIdToIDMap.get(disposableGoodsIdentification.getDisposableGoodsStockID()); + if(list == null){ + list = new ArrayList(); + } + list.add(disposableGoodsIdentification); + disposableGoodsBatchStockIdToIDMap.put(disposableGoodsIdentification.getDisposableGoodsStockID(), list); + } + // 异常情况1检查 // 一次性物品标识号的数据引用错误 // 标识号所引用的一次性物品id不存在 // 标识号所引用的一次性物品库存id不存在 // 标识号所引用的一次性物品批次id不存在 - @SuppressWarnings("unchecked") - List identifications = objectDao.findAllObjects(DisposableGoodsIdentification.class.getSimpleName()); List tempDisposableGoodsList = new ArrayList(); JSONArray data1 = new JSONArray(); if(CollectionUtils.isNotEmpty(identifications)){ + Set checkedDisposableGoods = new HashSet(); for (DisposableGoodsIdentification disposableGoodsIdentification : identifications) { Long disposableGoodsID = disposableGoodsIdentification.getDisposableGoodsID(); Long disposableGoodsStockID = disposableGoodsIdentification.getDisposableGoodsStockID(); Long disposableGoodsBatchID = disposableGoodsIdentification.getDisposableGoodsBatchID(); - DisposableGoods disposableGoods = (DisposableGoods) objectDao.getById(DisposableGoods.class.getSimpleName(), disposableGoodsID == null ? 0l : disposableGoodsID); - DisposableGoodsStock disposableGoodsStock = (DisposableGoodsStock) objectDao.getById(DisposableGoodsStock.class.getSimpleName(), disposableGoodsStockID == null ? 0l : disposableGoodsStockID); - DisposableGoodsBatch disposableGoodsBatch = (DisposableGoodsBatch) objectDao.getById(DisposableGoodsBatch.class.getSimpleName(), disposableGoodsBatchID == null ? 0l : disposableGoodsBatchID); + DisposableGoods disposableGoods = idToDisposableGoodsMap.get(disposableGoodsID); + if(checkedDisposableGoods.contains(disposableGoods)){ + continue; + } + DisposableGoodsStock disposableGoodsStock = idToDisposableGoodsStockMap.get(disposableGoodsStockID); + DisposableGoodsBatch disposableGoodsBatch = idToDisposableGoodsBatchMap.get(disposableGoodsBatchID); JSONObject json = null; if(disposableGoods == null){ json = buildDisposableGoodsIdentificationJson(disposableGoodsIdentification, disposableGoodsStock, disposableGoodsBatch); }else if(disposableGoodsStock == null || disposableGoodsBatch == null){ tempDisposableGoodsList.add(disposableGoods); - List disposableGoodsStockList = diposableGoodsManager.getDisposableGoodsStockByDisposableGoodsId(disposableGoods.getId()); - json = bulidDisposableGoodsJson(disposableGoods, disposableGoodsStockList, IDENTIFICATIONERROR); + List disposableGoodsStockList1 = disposableGoodsIdToStockMap.get(disposableGoodsID); + json = bulidDisposableGoodsJson(disposableGoods, disposableGoodsStockList1, IDENTIFICATIONERROR, disposableGoodsStockIdToBatchStockMap, disposableGoodsBatchStockIdToIDMap); + checkedDisposableGoods.add(disposableGoods); } if(json != null){ data1.add(json); @@ -111,9 +168,9 @@ disposableGoodsList.removeAll(tempDisposableGoodsList); for (DisposableGoods disposableGoods : disposableGoodsList) { String type = DisposableGoodsStockExaminationAction.NORMAL; - List disposableGoodsStockList = diposableGoodsManager.getDisposableGoodsStockByDisposableGoodsId(disposableGoods.getId()); - type = checkDisposableGoodsStock(disposableGoodsStockList); - JSONObject json = bulidDisposableGoodsJson(disposableGoods, disposableGoodsStockList, type); + List disposableGoodsStockList1 = disposableGoodsIdToStockMap.get(disposableGoods.getId()); + type = checkDisposableGoodsStock(disposableGoodsStockList1, disposableGoodsStockIdToBatchStockMap, disposableGoodsBatchStockIdToIDMap); + JSONObject json = bulidDisposableGoodsJson(disposableGoods, disposableGoodsStockList1, type, disposableGoodsStockIdToBatchStockMap, disposableGoodsBatchStockIdToIDMap); if(json != null){ data.add(json); } @@ -175,9 +232,13 @@ /** * 检查一次性物品库存 * @param disposableGoodsStockList + * @param disposableGoodsBatchStockIdToIDMap + * @param disposableGoodsStockIdToBatchStockMap * @return */ - private String checkDisposableGoodsStock(List disposableGoodsStockList) { + private String checkDisposableGoodsStock(List disposableGoodsStockList, + Map> disposableGoodsStockIdToBatchStockMap, + Map> disposableGoodsBatchStockIdToIDMap) { String type = DisposableGoodsStockExaminationAction.NORMAL; if(CollectionUtils.isEmpty(disposableGoodsStockList)){ return type; @@ -186,24 +247,30 @@ Long stock = disposableGoodsStock.getAmount(); stock = stock == null ? 0L : stock; Long totalBatchStock = 0L; - Set batchStockSet = disposableGoodsStock.getGoodsBatchs(); - for (DisposableGoodsBatchStock disposableGoodsBatchStock : batchStockSet) { - totalBatchStock += disposableGoodsBatchStock.getStorage(); + List batchStockList = disposableGoodsStockIdToBatchStockMap.get(disposableGoodsStock.getId()); + if(CollectionUtils.isNotEmpty(batchStockList)){ + for (DisposableGoodsBatchStock disposableGoodsBatchStock : batchStockList) { + totalBatchStock += disposableGoodsBatchStock.getStorage(); + } } if(stock.longValue() != totalBatchStock.longValue()){ return DisposableGoodsStockExaminationAction.STOCKNOTEQUALBATCHSTOCK; } - for (DisposableGoodsBatchStock disposableGoodsBatchStock : batchStockSet) { - Long storage = disposableGoodsBatchStock.getStorage(); - storage = storage == null ? 0L : storage; - Long totalStorage = 0L; - List identifications = disposableGoodsBatchStock.getIdentifications(); - for (DisposableGoodsIdentification disposableGoodsIdentification : identifications) { - totalStorage += disposableGoodsIdentification.getAmount(); + if(CollectionUtils.isNotEmpty(batchStockList)){ + for (DisposableGoodsBatchStock disposableGoodsBatchStock : batchStockList) { + Long storage = disposableGoodsBatchStock.getStorage(); + storage = storage == null ? 0L : storage; + Long totalStorage = 0L; + List identifications = disposableGoodsBatchStockIdToIDMap.get(disposableGoodsBatchStock.getId()); + if(CollectionUtils.isNotEmpty(identifications)){ + for (DisposableGoodsIdentification disposableGoodsIdentification : identifications) { + totalStorage += disposableGoodsIdentification.getAmount(); + } + } + if(storage.longValue() != totalStorage.longValue()){ + return DisposableGoodsStockExaminationAction.BATCHSTOCKNOTEQUALIDSTOCK; + } } - if(storage.longValue() != totalStorage.longValue()){ - return DisposableGoodsStockExaminationAction.BATCHSTOCKNOTEQUALIDSTOCK; - } } } return type; @@ -214,9 +281,13 @@ * @param disposableGoods * @param disposableGoodsStockList * @param type + * @param disposableGoodsBatchStockIdToIDMap + * @param disposableGoodsStockIdToBatchStockMap * @return */ - private JSONObject bulidDisposableGoodsJson(DisposableGoods disposableGoods, List disposableGoodsStockList, String type) { + private JSONObject bulidDisposableGoodsJson(DisposableGoods disposableGoods, List disposableGoodsStockList, + String type, Map> disposableGoodsStockIdToBatchStockMap, + Map> disposableGoodsBatchStockIdToIDMap) { if(disposableGoods == null){ return null; } @@ -250,29 +321,32 @@ return json; } for (DisposableGoodsStock disposableGoodsStock : disposableGoodsStockList) { - for (DisposableGoodsBatchStock batchStock : disposableGoodsStock.getGoodsBatchs()) { - JSONObject batchStockJson = new JSONObject(); - List identifications = batchStock.getIdentifications(); - JSONArray identificationJsonArr = new JSONArray(); - if(CollectionUtils.isNotEmpty(identifications)){ - for (DisposableGoodsIdentification identification : identifications) { - JSONObject identificationJson = new JSONObject(); - identificationJson.put("id", identification.getId()); - identificationJson.put("stock", identification.getAmount() == null ? "" : identification.getAmount()); - identificationJson.put("disposableGoodsId", identification.getDisposableGoodsID() == null ? "" : identification.getDisposableGoodsID()); - identificationJson.put("stockId", identification.getDisposableGoodsStockID() == null ? "" : identification.getDisposableGoodsStockID()); - identificationJson.put("batchId", identification.getDisposableGoodsBatchID() == null ? "" : identification.getDisposableGoodsBatchID()); - identificationJsonArr.add(identificationJson); + List goodsBatchs = disposableGoodsStockIdToBatchStockMap.get(disposableGoodsStock.getId()); + if(CollectionUtils.isNotEmpty(goodsBatchs)){ + for (DisposableGoodsBatchStock batchStock : goodsBatchs) { + JSONObject batchStockJson = new JSONObject(); + List identifications = disposableGoodsBatchStockIdToIDMap.get(batchStock.getId()); + JSONArray identificationJsonArr = new JSONArray(); + if(CollectionUtils.isNotEmpty(identifications)){ + for (DisposableGoodsIdentification identification : identifications) { + JSONObject identificationJson = new JSONObject(); + identificationJson.put("id", identification.getId()); + identificationJson.put("stock", identification.getAmount() == null ? "" : identification.getAmount()); + identificationJson.put("disposableGoodsId", identification.getDisposableGoodsID() == null ? "" : identification.getDisposableGoodsID()); + identificationJson.put("stockId", identification.getDisposableGoodsStockID() == null ? "" : identification.getDisposableGoodsStockID()); + identificationJson.put("batchId", identification.getDisposableGoodsBatchID() == null ? "" : identification.getDisposableGoodsBatchID()); + identificationJsonArr.add(identificationJson); + } } + batchStockJson.put("batchId", batchStock.getDisposableGoodsBatchId() == null ? "" : batchStock.getDisposableGoodsBatchId()); + batchStockJson.put("batchNumber", batchStock.getBatchNumber() == null ? "" : batchStock.getBatchNumber()); + batchStockJson.put("batchStock", batchStock.getStorage() == null ? "" : batchStock.getStorage()); + batchStockJson.put("expDate", batchStock.getExpDateStr()); + batchStockJson.put("disposableGoodsIdentification", identificationJsonArr); + batchStockJson.put("sum", identificationJsonArr.size()); + sum += identificationJsonArr.size(); + disposableGoodsBatchStock.add(batchStockJson); } - batchStockJson.put("batchId", batchStock.getDisposableGoodsBatchId() == null ? "" : batchStock.getDisposableGoodsBatchId()); - batchStockJson.put("batchNumber", batchStock.getBatchNumber() == null ? "" : batchStock.getBatchNumber()); - batchStockJson.put("batchStock", batchStock.getStorage() == null ? "" : batchStock.getStorage()); - batchStockJson.put("expDate", batchStock.getExpDateStr()); - batchStockJson.put("disposableGoodsIdentification", identificationJsonArr); - batchStockJson.put("sum", identificationJsonArr.size()); - sum += identificationJsonArr.size(); - disposableGoodsBatchStock.add(batchStockJson); } } json.put("disposableGoodsBatchStock", disposableGoodsBatchStock);