Index: ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/service/TousseInstanceManagerImpl.java =================================================================== diff -u -r29242 -r29243 --- ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/service/TousseInstanceManagerImpl.java (.../TousseInstanceManagerImpl.java) (revision 29242) +++ ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/service/TousseInstanceManagerImpl.java (.../TousseInstanceManagerImpl.java) (revision 29243) @@ -6801,19 +6801,56 @@ ClassifyBasket.class.getSimpleName(),WashAndDisinfectRecord.class.getSimpleName(),DepartmentStock.class.getSimpleName(), PackingTask.class.getSimpleName(),RecyclingRecord.class.getSimpleName(), tousseName, departCode, disinfectedDateSql); }else if(TousseInstance.STATUS_SIGNED.equals(status)){ - sql = String.format("select ti.id,ti.signedDate,ti.signedUser,bd.barcode,ti.validUntil from %s ti " - + "inner join %s i on i.id=ti.invoice_id inner join %s td on td.id =ti.tousseDefinition_id " - + "inner join %s ds on ds.tousseDefinition_id=ti.tousseDefinition_id inner join %s bd on bd.id=ti.id " - + "where tousseFixedBarcode=0 and i.departCoding=ds.departCoding and i.departCoding='%s' " - + "and ( td.isCommonTousse is null or td.isCommonTousse !=1) and comboTousseInstanceId is null " - + "and ti.status='%s' and td.name='%s' %s", - TousseInstance.class.getSimpleName(), - Invoice.class.getSimpleName(), - TousseDefinition.class.getSimpleName(), - DepartmentStock.class.getSimpleName(), - BarcodeDevice.class.getSimpleName(), - departCode,status,tousseName, - tiDateSql); + boolean isFirst = supplyRoomConfigManager.isFirstSupplyRoomOrgUnit(departCode); + if(isFirst){ + OrgUnit orgUnit = new OrgUnit(); + orgUnit.setOrgUnitCoding(departCode); + List wareHouselist = wareHouseManager.getWareHouseListByOrgUnit(orgUnit); + if(CollectionUtils.isEmpty(wareHouselist)){ + throw new RuntimeException("该一级供应室没有仓库,不能计算库存数量"); + } + String wareHouseIdSql = null; + if(wareHouselist.size() == 1){ + Long wareHouseId = wareHouselist.get(0).getId(); + wareHouseIdSql = String.format("and ((wareHouseId2 is null and wareHouseId =%s) or (wareHouseId2 is not null and wareHouseId2=%s)) ", wareHouseId,wareHouseId); + }else{ + Set wareHouseIds = new HashSet(); + for(WareHouse wareHouse : wareHouselist){ + wareHouseIds.add(wareHouse.getId()); + } + wareHouseIdSql = String.format("and ((wareHouseId2 is null and %s ) or (wareHouseId2 is not null and %s)) ", + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("ti.wareHouseId", wareHouseIds), + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("ti.wareHouseId2", wareHouseIds)); + } + sql = String.format("select ti.id,ti.signedDate,ti.signedUser,bd.barcode,ti.validUntil from %s ti " + + "inner join %s td on td.id =ti.tousseDefinition_id " + + "inner join %s bd on bd.id=ti.id " + + "where tousseFixedBarcode=0 %s %s" + + "and td.name='%s' and comboTousseInstanceId is null " + + "and (ti.status='%s' or ti.status='%s') ", + TousseInstance.class.getSimpleName(), + TousseDefinition.class.getSimpleName(), + BarcodeDevice.class.getSimpleName(), + wareHouseIdSql, + tiDateSql, + tousseName, + TousseInstance.STATUS_DISINFECTED, + TousseInstance.STATUS_STERILED); + }else{ + sql = String.format("select ti.id,ti.signedDate,ti.signedUser,bd.barcode,ti.validUntil from %s ti " + + "inner join %s i on i.id=ti.invoice_id inner join %s td on td.id =ti.tousseDefinition_id " + + "inner join %s ds on ds.tousseDefinition_id=ti.tousseDefinition_id inner join %s bd on bd.id=ti.id " + + "where tousseFixedBarcode=0 and i.departCoding=ds.departCoding and i.departCoding='%s' " + + "and ( td.isCommonTousse is null or td.isCommonTousse !=1) and comboTousseInstanceId is null " + + "and ti.status='%s' and td.name='%s' %s", + TousseInstance.class.getSimpleName(), + Invoice.class.getSimpleName(), + TousseDefinition.class.getSimpleName(), + DepartmentStock.class.getSimpleName(), + BarcodeDevice.class.getSimpleName(), + departCode,status,tousseName, + tiDateSql); + } }else{ String joinSql = String.format(" inner join %s bd on ti.id=bd.id inner join %s ds on ds.tousseDefinition_id=ti.tousseDefinition_id ", BarcodeDevice.class.getSimpleName(),DepartmentStock.class.getSimpleName()); @@ -7131,7 +7168,6 @@ TousseInstance.STATUS_SIGNED,//页面库存数量显示别名为已签收的数量,所以此处虽然包实例状态是已灭菌或已消毒,但为了显示在库存数量的位置,固定别名为已签收 TousseInstance.class.getSimpleName(), TousseDefinition.class.getSimpleName(), - departCode,departCode, TousseInstance.STATUS_DISINFECTED, TousseInstance.STATUS_STERILED, SqlUtils.getStringFieldInLargeCollectionsPredicate("td.name", tousseNameSet),