Index: ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManagerImpl.java =================================================================== diff -u -r26490 -r26534 --- ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManagerImpl.java (.../InventoryRecordManagerImpl.java) (revision 26490) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManagerImpl.java (.../InventoryRecordManagerImpl.java) (revision 26534) @@ -1974,6 +1974,16 @@ return importInventoryRecordJsonFromSheets(request,sheets,errInfos); } + //导入材料盘点单 + @Override + public JSONArray importMaterialInventoryRecordFromInputStreams_TRANS_REQUIRED(HttpServletRequest request,List inputStreams,List errInfos){ + List sheets = getSheetsFromStreams(inputStreams); + if(sheets.size() == 0){ + throw new RuntimeException("没有要导入的表格!"); + } + return importInventoryRecordJsonFromSheets(request,sheets,errInfos); + } + private List getSheetsFromStreams(List inputStreams) { List sheets = new LinkedList(); // 提取所有sheet @@ -2029,37 +2039,75 @@ boolean err = false; JSONArray importInventoryItemJsonArry = new JSONArray(); int lastRowNum = diposableSheet.getLastRowNum(); - for (int i = 2; i <= lastRowNum; i++) { - HSSFRow row = diposableSheet.getRow(i); - int currentRowNum = i + 1; - if (row == null || ParerUtils.isBlankRow(row)) { - continue; + // 根据盘点类型处理Excel表格的数据 + String type = request.getParameter("type"); + if ("disposableInventoryRecord".equals(type)) { + // 一次性物品盘点 + for (int i = 2; i <= lastRowNum; i++) { + HSSFRow row = diposableSheet.getRow(i); + int currentRowNum = i + 1; + if (row == null || ParerUtils.isBlankRow(row)) { + continue; + } + try { + //获得导入盘点单的数据的json + JSONObject importItemJson = getinventoryRecordJsonFromCurrentRow(row,currentRowNum,batchNumberList); + //是否有名字,规格,批号,价格同时相同的 + if(importInventoryItemJsonArry.size()>0){ + for (int j = 0; j < importInventoryItemJsonArry.size(); j++) { + JSONObject job = importInventoryItemJsonArry.getJSONObject(j); + String name = job.getString("name"); + String specification = job.getString("specification"); + String batchNumber = job.getString("batchNumber"); + String price = job.getString("price"); + if(importItemJson.getString("name").equals(name) + && importItemJson.getString("specification").equals(specification) + && importItemJson.getString("batchNumber").equals(batchNumber) + && importItemJson.getString("price").equals(price) + ){ + throw new RuntimeException(String.format("第" + currentRowNum + "行不能其他行同时有重复的物品名称,规格,批号,单价!")); + } + } + } + // + importInventoryItemJsonArry.add(importItemJson); + } catch (Exception e) { + err = true; + errInfos.add(e.getMessage()); + } } - try { - //获得导入盘点单的数据的json - JSONObject importItemJson = getinventoryRecordJsonFromCurrentRow(row,currentRowNum,batchNumberList); - //是否有名字,规格,批号,价格同时相同的 - if(importInventoryItemJsonArry.size()>0){ - for (int j = 0; j < importInventoryItemJsonArry.size(); j++) { - JSONObject job = importInventoryItemJsonArry.getJSONObject(j); - String name = job.getString("name"); - String specification = job.getString("specification"); - String batchNumber = job.getString("batchNumber"); - String price = job.getString("price"); - if(importItemJson.getString("name").equals(name) - && importItemJson.getString("specification").equals(specification) - && importItemJson.getString("batchNumber").equals(batchNumber) - && importItemJson.getString("price").equals(price) - ){ - throw new RuntimeException(String.format("第" + currentRowNum + "行不能其他行同时有重复的物品名称,规格,批号,单价!")); + } else if ("materialInventoryRecord".equals(type)) { + // 材料盘点 + for (int i = 2; i <= lastRowNum; i++) { + HSSFRow row = diposableSheet.getRow(i); + int currentRowNum = i + 1; + if (row == null || ParerUtils.isBlankRow(row)) { + continue; + } + try { + //获得导入盘点单的数据的json + JSONObject importItemJson = getMaterialInventoryRecordJsonFromCurrentRow(row,currentRowNum,batchNumberList); + //是否有名字,规格,价格同时相同的 + if(importInventoryItemJsonArry.size()>0){ + for (int j = 0; j < importInventoryItemJsonArry.size(); j++) { + JSONObject job = importInventoryItemJsonArry.getJSONObject(j); + String name = job.getString("name"); + String specification = job.getString("specification"); + String price = job.getString("price"); + if(importItemJson.getString("name").equals(name) + && importItemJson.getString("specification").equals(specification) + && importItemJson.getString("price").equals(price) + ){ + throw new RuntimeException(String.format("第" + currentRowNum + "行不能其他行同时有重复的物品名称,规格,单价!")); + } } } + // + importInventoryItemJsonArry.add(importItemJson); + } catch (Exception e) { + err = true; + errInfos.add(e.getMessage()); } - // - importInventoryItemJsonArry.add(importItemJson); - } catch (Exception e) { - err = true; - errInfos.add(e.getMessage()); } } if (importInventoryItemJsonArry.size() == 0){ @@ -2240,5 +2288,77 @@ } return findSql; } + /** + * 获取导入盘点单Excel表格的数据的json + */ + private JSONObject getMaterialInventoryRecordJsonFromCurrentRow(HSSFRow row,int currentRowNum,ListmaterialList){ + //序号 + String rowIndex = ParerUtils.getCellFormatValue(row, 0); + // 物品名称 + String name = ParerUtils.getCellFormatValue(row, 1); + if (StringUtils.isBlank(name)) { + throw new ImportDataException("第" + currentRowNum + "行物品名称不能为空!"); + } + //规格 + String specification = ParerUtils.getCellFormatValue(row, 2); + //页面盘点明细的批次号是否包括导入的批次号 + if(!materialList.contains(name + specification)){ + throw new ImportDataException("该盘点明细不包含第" + currentRowNum + "行物品的名称规格:" + name + "【" + specification + "】"); + } + //账面数量 + String storageStr = ParerUtils.getCellFormatValue(row, 3); + Integer storage = null; + if (StringUtils.isNotBlank(storageStr)) { + try{ + storage = Integer.parseInt(storageStr); + }catch(NumberFormatException e){ + } + if(storage == null || storage<0){ + throw new ImportDataException("第" + currentRowNum+ "行物品的账面数量必须是正整数!"); + } + }else{ + throw new ImportDataException("第" + currentRowNum + "行物品账面数量不能为空!"); + } + //盘点数量 + String amountStr = ParerUtils.getCellFormatValue(row, 4); + Integer amount = null; + if (StringUtils.isNotBlank(amountStr)) { + try{ + amount = Integer.parseInt(amountStr); + }catch(NumberFormatException e){ + } + if(amount == null || amount<0){ + throw new ImportDataException("第" + currentRowNum+ "行物品的盘点数量必须是正整数!"); + } + }else{ + throw new ImportDataException("第" + currentRowNum + "行物品盘点数量不能为空!"); + } + //单价 + String priceStr = ParerUtils.getCellFormatValue(row, 5); + Double price = null; + if (StringUtils.isNotBlank(priceStr)) { + try { + price = Double.parseDouble(priceStr); + } catch (NumberFormatException e) { + } + } + if (price == null) { + throw new ImportDataException("第" + currentRowNum+ "行的物品单价必须为有效数字!"); + } + // 供应商 + String supplierName = ParerUtils.getCellFormatValue(row, 6); + //返回json对象 + JSONObject importInventoryRecord = new JSONObject(); + importInventoryRecord.put("rowIndex", rowIndex); + importInventoryRecord.put("name", name); + importInventoryRecord.put("specification", specification); + importInventoryRecord.put("storage", storage); + importInventoryRecord.put("amount", amount); + importInventoryRecord.put("price", price); + importInventoryRecord.put("supplierName", supplierName); + + return importInventoryRecord; + } + } Index: ssts-web/src/main/webapp/disinfectsystem/basedatamanager/importbasedata/importInventoryRecord.jsp =================================================================== diff -u -r21235 -r26534 --- ssts-web/src/main/webapp/disinfectsystem/basedatamanager/importbasedata/importInventoryRecord.jsp (.../importInventoryRecord.jsp) (revision 21235) +++ ssts-web/src/main/webapp/disinfectsystem/basedatamanager/importbasedata/importInventoryRecord.jsp (.../importInventoryRecord.jsp) (revision 26534) @@ -3,7 +3,7 @@ -一次性物品盘点单导入 +${poName}导入 <%@ include file="/common/includeUploadFilesJSAndCSS.jsp"%> @@ -99,7 +99,7 @@ } } function importData(){ - //获得页面盘点明细的批次号 + //获得页面盘点明细的批次号/材料“名称+规格” var batchNumberList = window.dialogArguments if(batchNumberList){ document.getElementById("batchNumberList").value = batchNumberList; Index: ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManager.java =================================================================== diff -u -r22621 -r26534 --- ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManager.java (.../InventoryRecordManager.java) (revision 22621) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/service/InventoryRecordManager.java (.../InventoryRecordManager.java) (revision 26534) @@ -83,6 +83,16 @@ * @return JSONArray */ public JSONArray getGatherInventoryRecordItems(String id); + + /** + * 导入材料盘点明细单,返回导入单数据的json + * @param request + * @param inputStreams + * @param errInfos + */ + public JSONArray importMaterialInventoryRecordFromInputStreams_TRANS_REQUIRED( + HttpServletRequest request, List inputStreams, + List errInfos); } Index: ssts-web/src/main/webapp/disinfectsystem/basedatamanager/importbasedata/materialImportInventoryRecord.xls =================================================================== diff -u Binary files differ Index: ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/action/ImportInventoryRecordController.java =================================================================== diff -u -r21812 -r26534 --- ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/action/ImportInventoryRecordController.java (.../ImportInventoryRecordController.java) (revision 21812) +++ ssts-web/src/main/java/com/forgon/disinfectsystem/inventoryrecord/action/ImportInventoryRecordController.java (.../ImportInventoryRecordController.java) (revision 26534) @@ -79,10 +79,12 @@ //返回导入单数据的json importInventoryRecordJson = inventoryRecordManager.importDisposableInventoryRecordFromInputStreams_TRANS_REQUIRED(request,inputStreams,errInfos); break; -// case "material": -// // 材料 -// importBasedataManager.importMaterialEntrysFromInputStreams_TRANS_REQUIRED(inputStreams); -// break; + case "materialInventoryRecord": + // 材料 + poName = "材料盘点单"; + formatFile = "/disinfectsystem/basedatamanager/importbasedata/materialImportInventoryRecord.xls"; + importInventoryRecordJson = inventoryRecordManager.importMaterialInventoryRecordFromInputStreams_TRANS_REQUIRED(request,inputStreams,errInfos); + break; default: throw new RuntimeException("类型参数错误!"); } @@ -106,11 +108,15 @@ protected Object formBackingObject(HttpServletRequest request) throws Exception { boolean isDiposable = "disposableInventoryRecord".equals(request.getParameter("type")); + boolean isMaterial = "materialInventoryRecord".equals(request.getParameter("type")); // String batchNumbers = request.getParameter("batchNumberList"); String poName = "",formatFile=""; if(isDiposable){ poName = "一次性物品盘点单"; formatFile = "/disinfectsystem/basedatamanager/importbasedata/disposableImportInventoryRecord.xls"; + } else if(isMaterial){ + poName = "材料盘点单"; + formatFile = "/disinfectsystem/basedatamanager/importbasedata/materialImportInventoryRecord.xls"; } // request.setAttribute("batchNumberList", batchNumbers); request.setAttribute("poName", poName); Index: ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryMaterialForm.js =================================================================== diff -u -r23664 -r26534 --- ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryMaterialForm.js (.../inventoryMaterialForm.js) (revision 23664) +++ ssts-web/src/main/webapp/disinfectsystem/stocktakerecordmanager/inventoryMaterialForm.js (.../inventoryMaterialForm.js) (revision 26534) @@ -271,6 +271,12 @@ }] })], buttons : [{ + text : '导入盘点数量', + hidden:status=="已更新"?true:false, + handler : function() { + importInventoryMaterials(); + } + },{ text : '导出', hidden:(recordId == ""), handler : function() { @@ -317,3 +323,55 @@ window.show(); } + +function importInventoryMaterials(){ + //获得inventoryRecordForm的数据 + var itemsFromStore = top.Ext.getCmp('inventoryRecordForm').getStore(); + //页面盘点明细材料名称+规格数组 + var materialIdStr = new Array(); + itemsFromStore.each(function(record){ + // 通过材料名称+规格区分不同材料 + var materialStr = record.data.name + record.data.specification; + materialIdStr.push(materialStr.trim()); + }); + var url = WWWROOT+'/disinfectsystem/basedatamanager/importbasedata/importInventoryRecord.mhtml?type=materialInventoryRecord'; + //若导入成功则返回excel的导入数据 + var importItemsJsonStr = openModalWindow(url,materialIdStr,'760','400'); + if(importItemsJsonStr){ + //获得excel数据json对象 + var importJsObject = JSON.parse(importItemsJsonStr); + //循环匹配导入单并设盘点数量 + for(var i=0;i