Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakemanager/InventoryItem.java =================================================================== diff -u -r13124 -r13948 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakemanager/InventoryItem.java (.../InventoryItem.java) (revision 13124) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakemanager/InventoryItem.java (.../InventoryItem.java) (revision 13948) @@ -3,14 +3,26 @@ */ package com.forgon.disinfectsystem.entity.stocktakemanager; +import java.util.ArrayList; import java.util.Date; +import java.util.List; + import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Transient; + import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Cascade; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; +import com.forgon.tools.hibernate.ObjectDao; + /** * 盘点物品明细 * @author qjw @@ -41,6 +53,10 @@ private Integer storageDifference;//差值 + private String goodsType; + + private List items = new ArrayList(); + // private DisposableGoodsBatchStock diposableGoodBatchStock;//一次性物品库存(按批次区分) // private MaterialDefinition materialDefinition;//材料库存 @@ -119,27 +135,6 @@ this.storageDifference = storageDifference; } - /*@OneToOne(cascade = {CascadeType.REFRESH}) - @JoinColumn(name="diposableGoodBatchStock_id",referencedColumnName="id") - public DisposableGoodsBatchStock getDiposableGoodBatchStock() { - return diposableGoodBatchStock; - } - - public void setDiposableGoodBatchStock( - DisposableGoodsBatchStock disposableGoodsBatchStock) { - this.diposableGoodBatchStock = disposableGoodsBatchStock; - } - - @OneToOne(cascade = {CascadeType.REFRESH}) - @JoinColumn(name="materialDefinition_id",referencedColumnName="id") - public MaterialDefinition getMaterialDefinition() { - return materialDefinition; - } - - public void setMaterialDefinition(MaterialDefinition materialDefinition) { - this.materialDefinition = materialDefinition; - }*/ - public String getRemarkCause() { return remarkCause; } @@ -267,5 +262,38 @@ public void setExternalCode(String externalCode) { this.externalCode = externalCode; } + + public String getGoodsType() { + return goodsType; + } + + public void setGoodsType(String goodsType) { + this.goodsType = goodsType; + } + /*@SuppressWarnings("unchecked") + @Transient + public List findExpensiveGoodsItem( + ObjectDao objectDao) { + if (DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS.equals(this.goodsType)) { + return objectDao.findBySql( + InventoryExpensiveGoodsItem.class.getSimpleName(), + "where po.inventoryItemId = " + this.getId()); + } + return null; + }*/ + + @OneToMany(fetch = FetchType.LAZY) + @Cascade(value = { org.hibernate.annotations.CascadeType.ALL }) + @JoinColumn(name = "inventoryItem_id") + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + + } Index: ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GodownEntryManagerImpl.java =================================================================== diff -u -r13822 -r13948 --- ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GodownEntryManagerImpl.java (.../GodownEntryManagerImpl.java) (revision 13822) +++ ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GodownEntryManagerImpl.java (.../GodownEntryManagerImpl.java) (revision 13948) @@ -563,6 +563,9 @@ expensiveDisposablegoods.setEntryDate(new Date()); objectDao.saveOrUpdate(expensiveDisposablegoods); } + }else{ + //盘盈入库处理 + diposableGoodsManager.newExpensivediposablegoods(disposableGoodsBatchStock, godownEntryItem.getAmount(),godownEntryItem.getConclusion(), godownEntryItem.getGodownEntry().getTime(), godownEntryItem.getIdentification()); } } @@ -730,7 +733,9 @@ if(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS.equals(disposableGoods.getGoodsType())){ //根据条码设置高值耗所属仓库及一次性物品定义、批次定义、库存、批次库存id setExpensiveGoodsWarehouse(godownEntryItem , warehouseID, warehouseName , disposableGoodsStock.getId(),disposableGoodsBatch.getId(),disposableGoodsBatchStock); - disposableGoodsBatchStock.adjustAmount(1);//数量加1 + if(StringUtils.isNotBlank(godownEntryItem.getBarcode())){ + disposableGoodsBatchStock.adjustAmount(1);//数量加1 + } }else{ // 新建标识号对象 Index: ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/action/InventoryRecordAction.java =================================================================== diff -u -r13179 -r13948 --- ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/action/InventoryRecordAction.java (.../InventoryRecordAction.java) (revision 13179) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/action/InventoryRecordAction.java (.../InventoryRecordAction.java) (revision 13948) @@ -17,6 +17,8 @@ import org.apache.struts2.convention.annotation.ParentPackage; import com.forgon.Constants; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; +import com.forgon.disinfectsystem.entity.stocktakemanager.InventoryExpensiveGoodsItem; import com.forgon.disinfectsystem.entity.stocktakemanager.InventoryItem; import com.forgon.disinfectsystem.entity.stocktakemanager.InventoryRecord; import com.forgon.disinfectsystem.inventoryrecord.service.InventoryRecordManager; @@ -120,6 +122,23 @@ obj.put("supplierName", goods.getSupplierName()); obj.put("cost", goods.getPrice()); obj.put("externalCode", goods.getExternalCode()); + obj.put("goodsType", goods.getGoodsType()); + if(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS.equals(goods.getGoodsType())){ + List expensiveGoodsItems = goods.getItems(); + JSONArray expensiveGoodsArray = new JSONArray(); + if(expensiveGoodsItems != null){ + for (InventoryExpensiveGoodsItem inventoryExpensiveGoodsItem : expensiveGoodsItems) { + if("是".equals(inventoryExpensiveGoodsItem.getIsDecreaseGoods())){ + JSONObject expensiveGoodsObj = new JSONObject(); + expensiveGoodsObj.put("id", inventoryExpensiveGoodsItem.getId()); + expensiveGoodsArray.add(expensiveGoodsObj); + } + } + } + obj.put("expensiveGoodsInfo",expensiveGoodsArray.toString()); + }else{ + obj.put("expensiveGoodsInfo",""); + } array.add(obj); } } @@ -136,6 +155,34 @@ } } + public void loadExpensiveGoodsItem(){ + String inventoryItemId = StrutsParamUtils.getPraramValue("id", null); + JSONObject json = new JSONObject(); + JSONArray array = new JSONArray(); + if(StringUtils.isNotBlank(inventoryItemId)){ + InventoryItem item = inventoryRecordManager.getInventoryItem(inventoryItemId); + if(item != null){ + for (InventoryExpensiveGoodsItem goods : item.getItems()) { + JSONObject obj = new JSONObject(); + obj.put("id", goods.getId()); + obj.put("barcode", goods.getBarcode()); + obj.put("isDecreaseGoods", goods.getIsDecreaseGoods()); + array.add(obj); + } + } + } + json.put("success", true); + json.put("data", array); + try { + HttpServletResponse response = StrutsParamUtils.getResponse(); + response.setCharacterEncoding("utf-8"); + response.getWriter().write(json.toString()); + response.getWriter().close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public String deleteStockTakeInfo() { String idStr = StrutsParamUtils.getPraramValue("ids", ""); Index: ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryDisposableGoodsForm.js =================================================================== diff -u -r13916 -r13948 --- ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryDisposableGoodsForm.js (.../inventoryDisposableGoodsForm.js) (revision 13916) +++ ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryDisposableGoodsForm.js (.../inventoryDisposableGoodsForm.js) (revision 13948) @@ -166,7 +166,25 @@ regexText:'只能输入数字', allowBlank : false }) - }, + }, + {header : "高值耗材操作",dataIndex : 'goodsType',width : 60,menuDisabled : true, + renderer: function(v,p,record,rowIndex, columnIndex, store){ + if(v == '高值耗材'){ + var id = record.get('id'); + var amount = record.get('amount'); + var inventoryAmount = record.get('inventoryAmount'); + var isCanEdit = false; + var storageDifference = 0; + if(inventoryAmount != null && inventoryAmount != ""){ + if(inventoryAmount < amount){ + isCanEdit = true; + storageDifference = (amount - inventoryAmount); + } + } + return ""; + } + } + }, {header : "单价",dataIndex : 'cost',width : 30,menuDisabled : true}, {id : 'expandColumn',header : "供应商",width : 120,dataIndex : 'supplierName',menuDisabled : true} ]), Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakemanager/InventoryExpensiveGoodsItem.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakemanager/InventoryExpensiveGoodsItem.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakemanager/InventoryExpensiveGoodsItem.java (revision 13948) @@ -0,0 +1,57 @@ +package com.forgon.disinfectsystem.entity.stocktakemanager; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; + +@Entity +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class InventoryExpensiveGoodsItem { + + private Long id; + + private Long expensiveGoodsId;//高值耗材ID + + private String barcode;//条码 + + private String isDecreaseGoods; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getExpensiveGoodsId() { + return expensiveGoodsId; + } + + public void setExpensiveGoodsId(Long expensiveGoodsId) { + this.expensiveGoodsId = expensiveGoodsId; + } + + public String getBarcode() { + return barcode; + } + + public void setBarcode(String barcode) { + this.barcode = barcode; + } + + public String getIsDecreaseGoods() { + return isDecreaseGoods; + } + + public void setIsDecreaseGoods(String isDecreaseGoods) { + this.isDecreaseGoods = isDecreaseGoods; + } + +} Index: ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryrecordView.js =================================================================== diff -u -r13916 -r13948 --- ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryrecordView.js (.../inventoryrecordView.js) (revision 13916) +++ ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryrecordView.js (.../inventoryrecordView.js) (revision 13948) @@ -52,14 +52,143 @@ {name : 'cost'}, {name : 'specification'}, {name : 'supplierName'}, - {name : 'externalCode'} + {name : 'externalCode'}, + {name : 'goodsType'}, + {name : 'expensiveGoodsInfo'} ] ) }); +function showInventoryExpensiveGoods(inventoryItemId,storeRowIndex,isCanEdit,storageDifference){ + var rd = new Ext.data.JsonReader({ + root : 'data' + }, [ + {name : 'id'}, + {name : 'barcode'}, + {name : 'isDecreaseGoods'} + ]); + store = new top.Ext.data.Store({ + proxy : new Ext.data.HttpProxy({ + url : WWWROOT + '/disinfectSystem/inventoryRecordAction!loadExpensiveGoodsItem.do', + method : 'POST' + }), + baseParams : {id : inventoryItemId}, + reader : rd + }); + store.load(); + + var expensiveGoodsCm = new top.Ext.grid.ColumnModel([new Ext.grid.RowNumberer({header:'序号',width:40}), + { + name:'id', + hidden :true, + dataIndex : 'id' + },{ + header : "高值耗材条码", + width:100, + dataIndex : 'barcode' + },{ + header : "盘亏扣减物品", + width : 50, + dataIndex : 'isDecreaseGoods', + editor : new top.Ext.form.ComboBox({ + valueField : 'result', + displayField : 'result', + listWidth : 160, + store : new Ext.data.SimpleStore( { + fields : ['result'], + data : [['是'],['否']] + }), + forceSelection : true, + allowBlank : false, + triggerAction : 'all', + mode : 'local', + anchor : '97%' + }) + }]); + + var formObj = new top.Ext.FormPanel({ + frame : true, + labelAlign:'right', + labelSeparator : ':', + bodyStyle : 'padding:5px 5px 0px 5px', + autoWidth : true, + autoHeight : true, + autoScroll : true, + items:[{ + layout : 'column', + items : [{ + columnWidth : 1, + layout: 'form', + items : [ + new top.Ext.grid.EditorGridPanel({ + id : 'splitMaterialGrid', + height : 200, + width : 560, + store : store, + cm : expensiveGoodsCm, + frame : false, + border : true, + selModel : new top.Ext.grid.RowSelectionModel({ + singleSelect : false + }), + viewConfig: { + forceFit:true + }, + stripeRows : true, + bodyStyle : 'border:1px solid #afd7af;padding-left:5px' + }) + ] + }] + }], + buttons : [{ + id : 'saveBtn', + text : '确定', + hidden:(isCanEdit?false:true), + handler : function(){ + var array = new Array(); + for(var i = 0;i < store.getCount();i++){ + var record = store.getAt(i); + if(record.get("isDecreaseGoods") == "是"){ + array.push({id:record.get("id")}); + } + } + if(array.length == storageDifference){ + var record = top.Ext.getCmp('inventoryRecordForm').getStore().getAt(storeRowIndex); + if(record != null){ + record.set('expensiveGoodsInfo',array); + formWindow.close(); + } + }else{ + showResult("盘亏够减物品不等于" + storageDifference); + + } + } + },{ + id : 'cancleBtn', + text : '取消', + handler : function() { + formWindow.close(); + } + }] + }); + + var formWindow = new top.Ext.Window( { + layout : 'fit', + title : '查看高值耗材明细', + width : 600, + modal : true, + autoHeight : true, + border : false, + plain : true, + items : [formObj] + }); + formWindow.show(); +} + function saveInventoryItem(recordId){ - top.Ext.getCmp('button1').disable(); var array = new Array(); + var expensiveValidPass = true; + var goodsName = ""; for ( var i = 0; i < itemsStore.getCount(); i++) { var record = itemsStore.getAt(i); var id = record.get("id"); @@ -70,16 +199,42 @@ if(amount == "" || amount < 0){ continue; } + + var expensiveGoodsInfo = record.get("expensiveGoodsInfo"); + var storeageAmount = record.get("amount"); + if("高值耗材" == record.get("goodsType")){ + if(amount < storeageAmount){ + if(expensiveGoodsInfo != ""){ + var jsonArray = JSON.parse(expensiveGoodsInfo); + if(jsonArray.length != (storeageAmount - amount)){ + expensiveValidPass = false; + goodsName = record.get("name"); + break; + } + }else{ + expensiveValidPass = false; + goodsName = record.get("name"); + break; + } + } + } + var obj = { itemId : id, amount : amount, name : name, specification:specification, - batchNumber:batchNumber + batchNumber:batchNumber, + expensiveGoodsInfo:expensiveGoodsInfo }; array.push(obj); } + if(!expensiveValidPass){ + showResult(goodsName + ",请确认盘亏数量是否关联上相应的条码!"); + return; + } + form.form.submit( { url : WWWROOT + '/disinfectSystem/inventoryRecordAction!saveInventoryRecord.do', method : 'POST', @@ -104,15 +259,34 @@ var array = new Array(); var isNullAmount = false; var goodsName = ""; + var expensiveValidPass = true; for ( var i = 0; i < itemsStore.getCount(); i++) { var record = itemsStore.getAt(i); var id = record.get("id"); + var amount = record.get("amount"); var inventoryAmount = record.get("inventoryAmount"); if(inventoryAmount == "" && inventoryAmount != '0'){ isNullAmount = true; goodsName = record.get("name"); break; } + var expensiveGoodsInfo = record.get("expensiveGoodsInfo"); + if("高值耗材" == record.get("goodsType")){ + if(inventoryAmount < amount){ + if(expensiveGoodsInfo != ""){ + if(expensiveGoodsInfo.length != (amount - inventoryAmount)){ + expensiveValidPass = false; + goodsName = record.get("name"); + break; + } + }else{ + expensiveValidPass = false; + goodsName = record.get("name"); + break; + } + } + } + var name = record.get("name"); var specification = record.get("specification"); var batchNumber = record.get("batchNumber"); @@ -121,14 +295,20 @@ amount : inventoryAmount, name : name, specification:specification, - batchNumber:batchNumber + batchNumber:batchNumber, + expensiveGoodsInfo:expensiveGoodsInfo }; array.push(obj); } if(isNullAmount){ showResult(goodsName + ",盘点数量不能为空!"); return; } + + if(!expensiveValidPass){ + showResult(goodsName + ",请确认盘亏数量是否关联上相应的条码!"); + return; + } top.Ext.getCmp('button2').disable(); form.form.submit( { url : WWWROOT + '/disinfectSystem/inventoryRecordAction!updateGoodsStock.do', Index: ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManagerImpl.java =================================================================== diff -u -r13916 -r13948 --- ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManagerImpl.java (.../InventoryRecordManagerImpl.java) (revision 13916) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManagerImpl.java (.../InventoryRecordManagerImpl.java) (revision 13948) @@ -23,20 +23,24 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.bouncycastle.crypto.RuntimeCryptoException; import com.forgon.directory.acegi.tools.AcegiHelper; import com.forgon.directory.vo.LoginUserData; import com.forgon.disinfectsystem.basedatamanager.warehouse.service.WareHouseManager; import com.forgon.disinfectsystem.diposablegoods.service.DiposableGoodBatchStockManager; import com.forgon.disinfectsystem.diposablegoods.service.GodownEntryManager; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; 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.ExpensiveDisposablegoods; import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntry; import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntryItem; import com.forgon.disinfectsystem.entity.basedatamanager.materialdefinition.MaterialDefinition; import com.forgon.disinfectsystem.entity.basedatamanager.warehouse.WareHouse; import com.forgon.disinfectsystem.entity.materialmanager.MaterialEntry; +import com.forgon.disinfectsystem.entity.stocktakemanager.InventoryExpensiveGoodsItem; import com.forgon.disinfectsystem.entity.stocktakemanager.InventoryItem; import com.forgon.disinfectsystem.entity.stocktakemanager.InventoryRecord; import com.forgon.disinfectsystem.stocktakerecordmanager.service.StockTakeRecordManager; @@ -50,6 +54,7 @@ import com.forgon.tools.excel.ExcelCellStyle; import com.forgon.tools.excel.ExcelHelper; import com.forgon.tools.hibernate.ObjectDao; +import com.sun.xml.internal.ws.client.dispatch.DispatchImpl; /** * @author qjw @@ -138,22 +143,29 @@ throw new RuntimeException("批次已被删除!"); } - JSONObject obj = new JSONObject(); - obj.put("wareHouseId", inventoryRecord.getWareHouseId()); - obj.put("diposableGoodsID", inventoryItem.getDiposableGoodsID()); - obj.put("batchID", inventoryItem.getBatchID()); - obj.put("diposableGoodsStockID", inventoryItem.getDisposableGoodsStockId()); - obj.put("diposableGoodsBatchStockID", inventoryItem.getDisposableGoodsBatchStockId()); - obj.put("batchNumber", inventoryItem.getBatchNumber()); - obj.put("price", inventoryItem.getPrice()); - obj.put("expDate", sdf.format(inventoryItem.getExpDate())); if(inventoryItem.getStorageDifference() != null){ if(inventoryItem.getStorageDifference() > 0){ + JSONObject obj = newGodownEntryJsonItem(inventoryRecord, sdf,inventoryItem); obj.put("amount", inventoryItem.getStorageDifference()); in_array.add(obj); }else if(inventoryItem.getStorageDifference() < 0){ - obj.put("amount", -(inventoryItem.getStorageDifference())); - out_array.add(obj); + if(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS.equals(inventoryItem.getGoodsType())){ + List expensiveGoodsItems = inventoryItem.getItems(); + if(expensiveGoodsItems != null){ + for (InventoryExpensiveGoodsItem item : expensiveGoodsItems) { + if("是".equals(item.getIsDecreaseGoods())){ + JSONObject obj = newGodownEntryJsonItem(inventoryRecord, sdf,inventoryItem); + obj.put("amount", 1); + obj.put("expensiveDisposableGoodsId", item.getExpensiveGoodsId()); + out_array.add(obj); + } + } + } + }else{ + JSONObject obj = newGodownEntryJsonItem(inventoryRecord, sdf,inventoryItem); + obj.put("amount", -(inventoryItem.getStorageDifference())); + out_array.add(obj); + } } } } @@ -177,6 +189,20 @@ } } + private JSONObject newGodownEntryJsonItem(InventoryRecord inventoryRecord, + SimpleDateFormat sdf, InventoryItem inventoryItem) { + JSONObject obj = new JSONObject(); + obj.put("wareHouseId", inventoryRecord.getWareHouseId()); + obj.put("diposableGoodsID", inventoryItem.getDiposableGoodsID()); + obj.put("batchID", inventoryItem.getBatchID()); + obj.put("diposableGoodsStockID", inventoryItem.getDisposableGoodsStockId()); + obj.put("diposableGoodsBatchStockID", inventoryItem.getDisposableGoodsBatchStockId()); + obj.put("batchNumber", inventoryItem.getBatchNumber()); + obj.put("price", inventoryItem.getPrice()); + obj.put("expDate", sdf.format(inventoryItem.getExpDate())); + return obj; + } + private GodownEntry newGodownEntry(InventoryRecord inventoryRecord,String type,String subType,JSONArray array) { GodownEntry entry = new GodownEntry(); entry.setType(type); @@ -201,6 +227,7 @@ entryItem.setBatchNumber(jsonObject.optString("batchNumber")); entryItem.setCost(jsonObject.optDouble("price")); entryItem.setGodownEntry(entry); + entryItem.setExpensiveDisposableGoodsId(jsonObject.optLong("expensiveDisposableGoodsId")); entry.getItemsList().add(entryItem); } return entry; @@ -363,54 +390,83 @@ record.setWareHouseName(warehouse.getName()); objectDao.saveOrUpdate(record); List items = new ArrayList(); - for (DisposableGoodsStock disposableGoods : goodsStockList) { - for (DisposableGoodsBatchStock disposableGoodsBatchStock : disposableGoods.getGoodsBatchs()) { + for (DisposableGoodsStock disposableGoodsStock : goodsStockList) { + DisposableGoods disposableGoods = (DisposableGoods) objectDao + .getByProperty(DisposableGoods.class.getSimpleName(), "id", + disposableGoodsStock.getDisposableGoodsID()); + if(disposableGoods == null){ + throw new RuntimeException(String.format("一次性物品[%s]定义不存在!",disposableGoodsStock.getShowName())); + } + for (DisposableGoodsBatchStock disposableGoodsBatchStock : disposableGoodsStock.getGoodsBatchs()) { if(disposableGoodsBatchStock.getStorage() <= 0){ continue; } - // 按价格分类 - List identifications = disposableGoodsBatchStock.getIdentifications(); - if(identifications == null){ - continue; + + if(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS.equals(disposableGoods.getGoodsType())){ + @SuppressWarnings("unchecked") + List expensiveDisposablegoodsList = objectDao + .findBySql(ExpensiveDisposablegoods.class.getSimpleName(), + "where po.status = '"+ ExpensiveDisposablegoods.STATUS_IN_WAREHOUSE + + "' and po.disposableGoodsBatchStock.id = "+ disposableGoodsBatchStock.getId()); + if(expensiveDisposablegoodsList != null){ + Map> itemsGroupedByPriceMap = new HashMap>(); + for (ExpensiveDisposablegoods expensiveGoods : expensiveDisposablegoodsList) { + Double price = expensiveGoods.getPrice(); + if(price == null){ + throw new RuntimeException(String.format("条码为[%s]的物品[%s]有价格为空的库存数据!", expensiveGoods.getBarcode(),disposableGoodsStock.getShowName())); + } + List itemsGroupedByPrice = itemsGroupedByPriceMap.get(price); + if(itemsGroupedByPrice == null){ + itemsGroupedByPrice = new LinkedList(); + itemsGroupedByPriceMap.put(price, itemsGroupedByPrice); + } + InventoryItem item = null; + if(itemsGroupedByPrice.size() > 0){ + item = itemsGroupedByPrice.get(0); + item.setStorage(item.getStorage() + 1); + }else{ + item = newInventoryItem(record, warehouse,disposableGoodsStock,disposableGoodsBatchStock,price,disposableGoods.getGoodsType()); + itemsGroupedByPrice.add(item); + item.setStorage(1); + } + InventoryExpensiveGoodsItem expensiveGoodsItem = new InventoryExpensiveGoodsItem(); + expensiveGoodsItem.setBarcode(expensiveGoods.getBarcode()); + expensiveGoodsItem.setExpensiveGoodsId(expensiveGoods.getId()); + item.getItems().add(expensiveGoodsItem); + } + for (List itemsGroupedByPrice : itemsGroupedByPriceMap.values()) { + items.addAll(itemsGroupedByPrice); + } + } + }else{ + // 按价格分类 + List identifications = disposableGoodsBatchStock.getIdentifications(); + if(identifications == null){ + continue; + } + Map> itemsGroupedByPriceMap = new HashMap>(); + for (DisposableGoodsIdentification identification : identifications) { + Double price = identification.getPrice(); + if(price == null){ + throw new RuntimeException(String.format("批次号为[%s]的物品[%s]有价格为空的库存数据!", disposableGoodsBatchStock.getBatchNumber(),disposableGoodsStock.getShowName())); + } + Long amount = identification.getAmount(); + if(amount == null || amount.intValue() == 0){ + continue; + } + List itemsGroupedByPrice = itemsGroupedByPriceMap.get(price); + if(itemsGroupedByPrice == null){ + itemsGroupedByPrice = new LinkedList(); + itemsGroupedByPriceMap.put(price, itemsGroupedByPrice); + } + InventoryItem item = newInventoryItem(record,warehouse,disposableGoodsStock,disposableGoodsBatchStock,price,disposableGoods.getGoodsType()); + item.setStorage(Integer.valueOf(""+identification.getAmount())); + itemsGroupedByPrice.add(item); + } + for (List itemsGroupedByPrice : itemsGroupedByPriceMap.values()) { + items.addAll(itemsGroupedByPrice); + } } - Map> itemsGroupedByPriceMap = new HashMap>(); - for (DisposableGoodsIdentification identification : identifications) { - Double price = identification.getPrice(); - if(price == null){ - throw new RuntimeException(String.format("批次号为[%s]的物品[%s]有价格为空的库存数据!", disposableGoodsBatchStock.getBatchNumber(),disposableGoods.getShowName())); - } - Long amount = identification.getAmount(); - if(amount == null || amount.intValue() == 0){ - continue; - } - List itemsGroupedByPrice = itemsGroupedByPriceMap.get(price); - if(itemsGroupedByPrice == null){ - itemsGroupedByPrice = new LinkedList(); - itemsGroupedByPriceMap.put(price, itemsGroupedByPrice); - } - InventoryItem item = new InventoryItem(); - item.setBatchID(disposableGoodsBatchStock.getDisposableGoodsBatchId()); - item.setBatchNumber(disposableGoodsBatchStock.getBatchNumber()); - item.setDiposableGoodsID(disposableGoodsBatchStock.getDisposableGoodsId()); - item.setDisposableGoodsBatchId(disposableGoodsBatchStock.getDisposableGoodsBatchId()); - item.setDisposableGoodsBatchStockId(disposableGoodsBatchStock.getDisposableGoodsBatchStockId()); - item.setDisposableGoodsId(disposableGoodsBatchStock.getDisposableGoodsId()); - item.setDisposableGoodsStockId(disposableGoodsBatchStock.getDisposableGoodsStockId()); - item.setMaterialName(disposableGoodsBatchStock.getDiposableGoods().getName()); - item.setPrice(price); - item.setSpecification(disposableGoodsBatchStock.getDiposableGoods().getSpecification()); - item.setInventoryRecordId(record.getId()); - item.setStorage(Integer.valueOf(""+identification.getAmount())); - item.setSupplierName(disposableGoodsBatchStock.getSupplierName()); - item.setWareHouseId(wareHouseId); - item.setWareHouseName(warehouse.getName()); - item.setExternalCode(disposableGoods.getExternalCode()); - item.setExpDate(disposableGoodsBatchStock.getExpDate()); - itemsGroupedByPrice.add(item); - } - for (List itemsGroupedByPrice : itemsGroupedByPriceMap.values()) { - items.addAll(itemsGroupedByPrice); - } } } record.setItems(items); @@ -422,6 +478,30 @@ } } + private InventoryItem newInventoryItem(InventoryRecord record, WareHouse warehouse, + DisposableGoodsStock disposableGoodsStock, + DisposableGoodsBatchStock disposableGoodsBatchStock, Double price,String goodsType) { + InventoryItem item = new InventoryItem(); + item.setBatchID(disposableGoodsBatchStock.getDisposableGoodsBatchId()); + item.setBatchNumber(disposableGoodsBatchStock.getBatchNumber()); + item.setDiposableGoodsID(disposableGoodsBatchStock.getDisposableGoodsId()); + item.setDisposableGoodsBatchId(disposableGoodsBatchStock.getDisposableGoodsBatchId()); + item.setDisposableGoodsBatchStockId(disposableGoodsBatchStock.getDisposableGoodsBatchStockId()); + item.setDisposableGoodsId(disposableGoodsBatchStock.getDisposableGoodsId()); + item.setDisposableGoodsStockId(disposableGoodsBatchStock.getDisposableGoodsStockId()); + item.setMaterialName(disposableGoodsBatchStock.getDiposableGoods().getName()); + item.setPrice(price); + item.setSpecification(disposableGoodsBatchStock.getDiposableGoods().getSpecification()); + item.setInventoryRecordId(record.getId()); + item.setSupplierName(disposableGoodsBatchStock.getSupplierName()); + item.setWareHouseId(warehouse.getId()); + item.setWareHouseName(warehouse.getName()); + item.setExternalCode(disposableGoodsStock.getExternalCode()); + item.setExpDate(disposableGoodsBatchStock.getExpDate()); + item.setGoodsType(goodsType); + return item; + } + @Override public InventoryItem getInventoryItem(String itemId) { if (StringUtils.isNotBlank(itemId)) { @@ -449,8 +529,32 @@ InventoryItem inventoryItem = map.get(itemId); if(inventoryItem != null){ inventoryItem.setAmount(amount); - inventoryItem.setStorageDifference(amount - - inventoryItem.getStorage()); + inventoryItem.setStorageDifference(amount- inventoryItem.getStorage()); + //高值耗材处理 + if(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS.equals(inventoryItem.getGoodsType())){ + if(inventoryItem.getStorageDifference() < 0){ + String expensiveGoodsInfo = obj.optString("expensiveGoodsInfo"); + if(StringUtils.isNotBlank(expensiveGoodsInfo)){ + JSONArray jsonArray = JSONArray.fromObject(expensiveGoodsInfo); + if(jsonArray.size() > 0){ + for (int j = 0; j < jsonArray.size();j++) { + Long id = jsonArray.getJSONObject(j).optLong("id"); + if(id != null){ + InventoryExpensiveGoodsItem inventoryExpensiveGoodsItem = (InventoryExpensiveGoodsItem)objectDao.getByProperty(InventoryExpensiveGoodsItem.class.getSimpleName(), "id", id); + if(inventoryExpensiveGoodsItem != null){ + inventoryExpensiveGoodsItem.setIsDecreaseGoods("是"); + } + }else{ + throw new RuntimeException("参数错误!"); + } + } + } + }else{ + throw new RuntimeException("参数错误!"); + } + } + + } } }else if(InventoryRecord.TYPE_DISPOSABLEGOOD.equals(record.getType())){ String goodsName = obj.optString("name");