Index: ssts-web/src/main/webapp/systemmanage/system/disposableGoodsStockCheck.jsp =================================================================== diff -u -r29409 -r29451 --- ssts-web/src/main/webapp/systemmanage/system/disposableGoodsStockCheck.jsp (.../disposableGoodsStockCheck.jsp) (revision 29409) +++ ssts-web/src/main/webapp/systemmanage/system/disposableGoodsStockCheck.jsp (.../disposableGoodsStockCheck.jsp) (revision 29451) @@ -71,6 +71,7 @@ $('#disposableGoodsAmount').text(result.disposableGoodsAmount); $('#disposableGoodsBatchAmount').text(result.disposableGoodsBatchAmount); $('#disposableGoodsIdentificationAmount').text(result.disposableGoodsIdentificationAmount); + $('#disposableGoodsIds').text(result.type2DisposableGoodsIds); var typeAmount = result.typeAmount || 0; var type1Amount = result.type1Amount || 0; var type2Amount = result.type2Amount || 0; @@ -88,6 +89,22 @@ } }) }); + + function modifyClick() { + var disposableGoodsIds = $('#disposableGoodsIds').html(); + $.ajax({ + url: WWWROOT + '/disinfectSystem/DisposableGoodsStockExaminationAction!modifyDisposableGoodsStock.do', + data: { disposableGoodsIds: disposableGoodsIds}, + type: "post", + dataType: "json", + success: function (result) { + alert(result.message); + }, + error: function (msg) { + alert("ajax连接异常:" + msg); + } + }); + } @@ -101,6 +118,8 @@

1.一次性物品标识号的数据引用错误

2.批次库存的数量不等于属于该批次的所有标识号的库存数量总和

3.一次性物品库存的数量不等于属于该一次性物品的所有批次的库存数量总和

+ + Index: ssts-web/src/main/java/com/forgon/disinfectsystem/systemexamination/action/DisposableGoodsStockExaminationAction.java =================================================================== diff -u -r29391 -r29451 --- ssts-web/src/main/java/com/forgon/disinfectsystem/systemexamination/action/DisposableGoodsStockExaminationAction.java (.../DisposableGoodsStockExaminationAction.java) (revision 29391) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/systemexamination/action/DisposableGoodsStockExaminationAction.java (.../DisposableGoodsStockExaminationAction.java) (revision 29451) @@ -1,5 +1,6 @@ package com.forgon.disinfectsystem.systemexamination.action; +import java.sql.ResultSet; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -23,10 +24,18 @@ import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsBatchStock; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsIdentification; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsStock; +import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntry; +import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntryItem; +import com.forgon.disinfectsystem.entity.invoicemanager.DiposableGoodsItem; +import com.forgon.tools.StrutsParamUtils; import com.forgon.tools.StrutsResponseUtils; +import com.forgon.tools.db.DatabaseUtil; import com.forgon.tools.hibernate.ObjectDao; import com.forgon.tools.json.JSONUtil; +import com.forgon.tools.util.SqlUtils; +import edu.emory.mathcs.backport.java.util.Arrays; + /** * 一次性物品库存、批次库存以及标识号的数据体检功能 * @author ZhouPeiMian @@ -86,8 +95,11 @@ int type2Amount = 0; int type3Amount = 0; + List type2DisposableGoodsIdList = new ArrayList(); + List type3DisposableGoodsIdList = new ArrayList(); + //一次性物品定义 - String disposableGoodsHql = String.format(" po.goodsType = '%s' order by po.sequence ", DisposableGoods.TYPE_DIPOSABLEGOODS); + String disposableGoodsHql = String.format(" po.goodsType <> '%s' order by po.sequence ", DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS); List disposableGoodsList = diposableGoodsManager.getByHql(disposableGoodsHql); if(CollectionUtils.isNotEmpty(disposableGoodsList)){ disposableGoodsAmount = disposableGoodsList.size(); @@ -192,10 +204,12 @@ String type = DisposableGoodsStockExaminationAction.NORMAL; List disposableGoodsStockList1 = disposableGoodsIdToStockMap.get(disposableGoods.getId()); type = checkDisposableGoodsStock(disposableGoodsStockList1, disposableGoodsStockIdToBatchStockMap, disposableGoodsBatchStockIdToIDMap); - if(StringUtils.equals(type, STOCKNOTEQUALBATCHSTOCK)){ + if(StringUtils.equals(type, BATCHSTOCKNOTEQUALIDSTOCK)){ type2Amount++; - }else if(StringUtils.equals(type, BATCHSTOCKNOTEQUALIDSTOCK)){ + type2DisposableGoodsIdList.add(disposableGoods.getId()); + }else if(StringUtils.equals(type, STOCKNOTEQUALBATCHSTOCK)){ type3Amount++; + type3DisposableGoodsIdList.add(disposableGoods.getId()); } JSONObject json = bulidDisposableGoodsJson(disposableGoods, disposableGoodsStockList1, type, disposableGoodsStockIdToBatchStockMap, disposableGoodsBatchStockIdToIDMap); if(json != null){ @@ -213,10 +227,225 @@ result.put("type2Amount", type2Amount); result.put("type3Amount", type3Amount); result.put("typeAmount", type1Amount+type2Amount+type3Amount); + result.put("type2DisposableGoodsIds", type2DisposableGoodsIdList.addAll(type3DisposableGoodsIdList)); + result.put("type3DisposableGoodsIds", type3DisposableGoodsIdList); StrutsResponseUtils.output(result); } + + @SuppressWarnings("unchecked") + public void modifyDisposableGoodsStock(){ + String disposableGoodsIds = StrutsParamUtils.getPraramValue("disposableGoodsIds", ""); + JSONObject result = JSONUtil.buildJsonObject(true, "修改成功"); + if(StringUtils.isNotBlank(disposableGoodsIds)){ + List disposableGoodsIdList = Arrays.asList(disposableGoodsIds.split(",")); + // 查找一次性物品批次库存及一次性物品标识号 + String sql = String.format("select po, r from %s po left join po.identifications r where %s order by r.entryDate ", DisposableGoodsBatchStock.class.getSimpleName(), + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("po.disposableGoodsId", disposableGoodsIdList)); + List resultList = objectDao.findByHql(sql); + Map> disposableGoodsBatchStockIdToIDMap = new HashMap>(); + if(CollectionUtils.isNotEmpty(resultList)){ + for (int i=0; i list = disposableGoodsBatchStockIdToIDMap.get(batchStock); + if(list == null){ + list = new ArrayList(); + } + list.add(identification); + disposableGoodsBatchStockIdToIDMap.put(batchStock, list); + } + } + if(!disposableGoodsBatchStockIdToIDMap.isEmpty()){ + List identificationList = new ArrayList(); + for (List identifications : disposableGoodsBatchStockIdToIDMap.values()) { + // 1、查询一次性物品标识号库存对象对应的入库初始数量 + Map godownEntryAmountMap = new HashMap(); + godownEntryAmountMap = getGodownEntryAmont(identifications); + // 2、查询一次性物品标识号库存对象对应的累计发货数量 + Map invoiceAmountMap = new HashMap(); + invoiceAmountMap = getInvoiceAmont(identifications); + // 3、累计退货数量 + Map returnAmountMap = new HashMap(); + returnAmountMap = getReturnAmount(identifications); + for (DisposableGoodsIdentification disposableGoodsIdentification : identifications) { + Long godownEntryAmount = godownEntryAmountMap.get(disposableGoodsIdentification.getId()); + godownEntryAmount = godownEntryAmount == null ? 0 : godownEntryAmount; + Long invoiceAmount = invoiceAmountMap.get(disposableGoodsIdentification.getId()); + invoiceAmount = invoiceAmount == null ? 0 : invoiceAmount; + Long returnAmount = returnAmountMap.get(disposableGoodsIdentification.getId()); + returnAmount = returnAmount == null ? 0 : returnAmount; + Long curAmount = disposableGoodsIdentification.getAmount(); + curAmount = curAmount == null ? 0 : curAmount; + if(godownEntryAmount.longValue() != 0){ + curAmount = godownEntryAmount - invoiceAmount + returnAmount; + } + disposableGoodsIdentification.setAmount(curAmount); + } + } + // 4、累计退库数量(退库单和标识号没有关联,按照先进先出原则扣减标识号库存) + modifyIdentificationAmount(disposableGoodsBatchStockIdToIDMap); + for (List identifications : disposableGoodsBatchStockIdToIDMap.values()) { + identificationList.addAll(identifications); + } + objectDao.batchSaveOrUpdate(identificationList); + + // 根据一次性物品标识号库存数量,更新一次性物品批次库存和一次性物品库存 + String sql1 = "update DisposableGoodsBatchStock set storage = (select sum(amount) from DisposableGoodsIdentification po where po.batch_id = DisposableGoodsBatchStock.id)"; + String sql2 = "update DisposableGoodsStock set amount = (select sum(po.storage) from DisposableGoodsBatchStock po where po.diposablegoods_id = DisposableGoodsStock.id)"; + objectDao.excuteSQL(sql1); + objectDao.excuteSQL(sql2); + } + } + StrutsResponseUtils.output(result); + + } + + /** + * 扣减退库数量,按照先进先出原则扣减标识号库存 + * @param disposableGoodsBatchStockIdToIDMap + */ + private void modifyIdentificationAmount(Map> disposableGoodsBatchStockIdToIDMap) { + for (DisposableGoodsBatchStock disposableGoodsBatchStock : disposableGoodsBatchStockIdToIDMap.keySet()) { + String sql = String.format("select sum(po.amount) outAmount from %s po join %s ge on ge.id = po.godownEntry_id " + + " where ge.type = '%s' and po.disposableGoodsBatchStockID = %s ", + GodownEntryItem.class.getSimpleName(), GodownEntry.class.getSimpleName(), + GodownEntry.TYPE_OUT, + disposableGoodsBatchStock.getId()); + System.out.println(sql); + ResultSet rs = null; + Long outAmount = 0l; + try { + rs = objectDao.executeSql(sql); + while(rs.next()){ + outAmount = rs.getLong("outAmount"); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + List identifications = disposableGoodsBatchStockIdToIDMap.get(disposableGoodsBatchStock); + for (DisposableGoodsIdentification identification : identifications) { + if(outAmount.longValue() == 0){ + break; + } + Long amount = identification.getAmount(); + if(amount.longValue() > outAmount.longValue()){ + identification.setAmount(amount - outAmount); + break; + }else{ + identification.setAmount(0L); + outAmount -= amount; + } + } + } + + } /** + * 累计退货数量 + * @param identifications + * @return + */ + private Map getReturnAmount(List identifications) { + Map returnAmountMap = new HashMap(); + List identificationIds = new ArrayList(); + for (DisposableGoodsIdentification identification : identifications) { + identificationIds.add(identification.getId()); + } + String sql = String.format("select dgi.id id, sum(di.returnedAmount) returnedAmount from %s di join %s dgi on dgi.id = di.identificationID " + + " where di.returnGoodsItemID is not null " + + " and %s group by dgi.id ", DiposableGoodsItem.class.getSimpleName(), DisposableGoodsIdentification.class.getSimpleName(), + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("dgi.id", identificationIds)); + System.out.println(sql); + ResultSet rs = null; + Long amount = 0l; + try { + rs = objectDao.executeSql(sql); + while(rs.next()){ + Long id = rs.getLong("id"); + amount = rs.getLong("returnedAmount"); + returnAmountMap.put(id, amount); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return returnAmountMap; + } + + /** + * 查询一次性物品标识号库存对象对应的累计发货数量 + * @param identifications + * @return + */ + private Map getInvoiceAmont(List identifications) { + Map invoiceAmontMap = new HashMap(); + List identificationIds = new ArrayList(); + for (DisposableGoodsIdentification identification : identifications) { + identificationIds.add(identification.getId()); + } + String sql = String.format("select dgi.id id, sum(di.amount) invoiceAmont from %s di join %s dgi on dgi.id = di.identificationID " + + " where di.invoiceItemID is not null " + + " and %s group by dgi.id ", DiposableGoodsItem.class.getSimpleName(), + DisposableGoodsIdentification.class.getSimpleName(), + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("dgi.id", identificationIds)); + ResultSet rs = null; + System.out.println(sql); + Long amount = 0l; + try { + rs = objectDao.executeSql(sql); + while(rs.next()){ + Long id = rs.getLong("id"); + amount = rs.getLong("invoiceAmont"); + invoiceAmontMap.put(id, amount); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return invoiceAmontMap; + } + + /** + * 查询一次性物品标识号库存对象对应的入库初始数量 + * @param identifications + * @return + */ + private Map getGodownEntryAmont(List identifications) { + Map godownEntryAmontMap = new HashMap(); + List identificationIds = new ArrayList(); + for (DisposableGoodsIdentification identification : identifications) { + identificationIds.add(identification.getId()); + } + String sql = String.format("select dgi.id id, sum(gei.amount) entryAmount from %s dgi left join %s gei on gei.disposableGoodsBatchStockID = dgi.batch_id " + + " join %s ge on ge.id = gei.godownEntry_id " + + " where ge.time = dgi.entryDate " + + " and %s group by dgi.id ", DisposableGoodsIdentification.class.getSimpleName(), + GodownEntryItem.class.getSimpleName(), GodownEntry.class.getSimpleName(), + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("dgi.id", identificationIds)); + System.out.println(sql); + ResultSet rs = null; + Long amount = 0l; + try { + rs = objectDao.executeSql(sql); + while(rs.next()){ + Long id = rs.getLong("id"); + amount = rs.getLong("entryAmount"); + godownEntryAmontMap.put(id, amount); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return godownEntryAmontMap; + } + + /** * 根据DisposableGoodsIdentification构建一次性物品库存信息 * @param identification * @param disposableGoodsBatch