Index: ssts-web/src/main/webapp/disinfectsystem/assestManagement/godownEntry/goodPurchasePlanView.js =================================================================== diff -u -r12973 -r13059 --- ssts-web/src/main/webapp/disinfectsystem/assestManagement/godownEntry/goodPurchasePlanView.js (.../goodPurchasePlanView.js) (revision 12973) +++ ssts-web/src/main/webapp/disinfectsystem/assestManagement/godownEntry/goodPurchasePlanView.js (.../goodPurchasePlanView.js) (revision 13059) @@ -1179,6 +1179,30 @@ } }); } + },'-',{ + text : '导出', + hidden : false, + iconCls:'btn_ext_download', + handler : function() { + var records = grid.getSelectionModel().getSelections(); + if (records.length == 0) { + showResult("请选择要导出的采购计划单!"); + return; + } + if (records.length != 1) { + showResult("一次只能导出1个采购计划单!"); + return; + } + var ids = null; + for ( var i = 0, len = records.length; i < len; i++) { + if (ids == null) { + ids = records[i].data['id']; + } else { + ids = ids + ',' + records[i].data['id']; + } + } + location.href = WWWROOT + "/disinfectsystem/assestManagement/godownEntry/exportGoodPurchasePlan.jsp?ids=" + ids; + } }]; grid = new Ext.ux.ForgonPageGrid( { Index: ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GoodPurchasePlanManager.java =================================================================== diff -u -r12972 -r13059 --- ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GoodPurchasePlanManager.java (.../GoodPurchasePlanManager.java) (revision 12972) +++ ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GoodPurchasePlanManager.java (.../GoodPurchasePlanManager.java) (revision 13059) @@ -1,5 +1,6 @@ package com.forgon.disinfectsystem.diposablegoods.service; +import java.io.OutputStream; import java.util.Map; import net.sf.json.JSONObject; @@ -44,4 +45,10 @@ * @return */ public GoodPurchaseItem getLastGoodPurchaseItemByNameAndSpecification(String name , String specification); + /** + * 导出采购计划单,可能有多张单,合并导出明细 + * @param ops + * @param ids 要导出的采购计划单的id + */ + public void exportGoodPurchasePlan(OutputStream ops,String ids); } Index: ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GoodPurchasePlanManagerImpl.java =================================================================== diff -u -r13036 -r13059 --- ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GoodPurchasePlanManagerImpl.java (.../GoodPurchasePlanManagerImpl.java) (revision 13036) +++ ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GoodPurchasePlanManagerImpl.java (.../GoodPurchasePlanManagerImpl.java) (revision 13059) @@ -1,6 +1,10 @@ package com.forgon.disinfectsystem.diposablegoods.service; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -12,17 +16,26 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ArrayUtils; - +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFFont; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.RichTextString; import com.forgon.Constants; import com.forgon.disinfectsystem.common.CssdUtils; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; -import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsStock; import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntry; import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchaseItem; import com.forgon.disinfectsystem.entity.assestmanagement.GoodPurchasePlan; import com.forgon.disinfectsystem.vo.GodownEntryItemPrintVO; import com.forgon.serialnumber.model.SerialNum; import com.forgon.serialnumber.service.SerialNumManager; +import com.forgon.tools.Path; +import com.forgon.tools.excel.ExcelCellStyle; +import com.forgon.tools.excel.ExcelHelper; import com.forgon.tools.hibernate.ObjectDao; import com.forgon.tools.util.ForgonDateUtils; @@ -51,26 +64,6 @@ objectDao.saveOrUpdate(godownEntry); } - /** - * @param original - * @param entry - * @param curGodownEntry - */ - private void updateGodownEntryProperties(GodownEntry original, - GodownEntry entry, GodownEntry curGodownEntry) { - // 备注 - String originalRemark = original.getRemark(); - String remark = entry.getRemark(); - if(!StringUtils.equals(originalRemark, remark)){ - curGodownEntry.setRemark(remark); - } - // 时间 - Date originalTime = original.getTime(); - Date time = entry.getTime(); - if(!originalTime.equals(time)){ - curGodownEntry.setTime(time); - } - } @Override public void saveGoodPurchasePlan(GoodPurchasePlan goodPurchasePlan, Map result) { @@ -392,4 +385,111 @@ goodPurchaseItem = CollectionUtils.isNotEmpty(list) ? list.get(0) : null; return goodPurchaseItem; } + + @Override + public void exportGoodPurchasePlan(OutputStream ops, String ids) { + String sql = String.format(" where po.id in (%s)", ids); + + @SuppressWarnings("unchecked") + List list = objectDao.findBySql( + GoodPurchasePlan.class.getSimpleName(), sql); + Collection itemVos = loadToussePrintData(list); + createExportFile(itemVos, ops); + + } + private void createExportFile(Collection itemVos, + OutputStream ops) { + String inputFile = Path.getWebAppRoot() + + "/disinfectsystem/reportforms/receiveDetail.xls"; + FileInputStream fos = null; + POIFSFileSystem fs = null; + HSSFWorkbook wb = null; + try { + fos = new FileInputStream(inputFile); + fs = new POIFSFileSystem(fos); + wb = new HSSFWorkbook(fs); + ExcelHelper.setWorkbook(wb); + ExcelCellStyle.iniAllStyles(); + HSSFSheet sheet = wb.getSheetAt(0); + + HSSFCellStyle cellStyle = wb.createCellStyle(); // 数据单元格格式 + cellStyle.setWrapText(true); + cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); + cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); + HSSFFont font = wb.createFont(); + font.setFontHeightInPoints((short) 10); // 设置字体大小为10 + font.setFontName("宋体"); + cellStyle.setFont(font); + + HSSFRow operatingRow1 = sheet.createRow(0); + createCell(operatingRow1, cellStyle, 0, "编码"); + createCell(operatingRow1, cellStyle, 1, "名称"); + createCell(operatingRow1, cellStyle, 2, "规格"); + createCell(operatingRow1, cellStyle, 3, "单位"); + createCell(operatingRow1, cellStyle, 4, "数量"); + createCell(operatingRow1, cellStyle, 5, "进价"); + createCell(operatingRow1, cellStyle, 6, "进价金额"); + createCell(operatingRow1, cellStyle, 7, "产地"); + createCell(operatingRow1, cellStyle, 8, "供应商"); + createCell(operatingRow1, cellStyle, 9, "注册证号"); + + int row = 1; + for (GodownEntryItemPrintVO item : itemVos) { + HSSFRow operatingRow = sheet.createRow(row); + createCell(operatingRow, cellStyle, 0, item.getCode()); + createCell(operatingRow, cellStyle, 1,item.getName()); + createCell(operatingRow, cellStyle, 2, item.getSpecification()); + createCell(operatingRow, cellStyle, 3, item.getUnit()); + Long storage = item.getAmount(); + if (storage != null) { + createCell(operatingRow, cellStyle, 4, + Integer.parseInt("" + storage)); + } else { + createCell(operatingRow, cellStyle, 4, 0); + } + + createCell(operatingRow, cellStyle, 5, item.getPrice()); + createCell(operatingRow, cellStyle, 6,item.getTotalPrice()); + createCell(operatingRow, cellStyle, 7,item.getProducingArea()); + createCell(operatingRow, cellStyle, 8,item.getSupplierName()); + createCell(operatingRow, cellStyle, 9,item.getCertification()); + row++; + } + wb.write(ops); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + ops.close(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + private void createCell(HSSFRow row, HSSFCellStyle cellStyle, + int cellIndex,Object value){ + HSSFCell cell = row.createCell(cellIndex); + cell.setCellStyle(cellStyle); + if(value != null){ + if(value instanceof Double){ + cell.setCellValue((Double) value); + }else if(value instanceof Integer){ + cell.setCellValue((Integer)value); + }else if(value instanceof Boolean){ + cell.setCellValue((Boolean)value); + }else if(value instanceof Date){ + cell.setCellValue((Date)value); + }else if(value instanceof Calendar){ + cell.setCellValue((Calendar)value); + }else if(value instanceof RichTextString){ + cell.setCellValue((RichTextString)value); + }else{ + cell.setCellValue(value.toString()); + } + } + } } Index: ssts-web/src/main/webapp/disinfectsystem/assestManagement/godownEntry/exportGoodPurchasePlan.jsp =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/assestManagement/godownEntry/exportGoodPurchasePlan.jsp (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/assestManagement/godownEntry/exportGoodPurchasePlan.jsp (revision 13059) @@ -0,0 +1,17 @@ +<%@page import="com.forgon.disinfectsystem.diposablegoods.service.GoodPurchasePlanManager"%> +<%@ page contentType="text/html; charset=UTF-8"%><%@ page + import="com.forgon.tools.*,org.apache.commons.lang.*,com.forgon.directory.service.*"%> +<% +String fileName="一次性物品采购计划单1.xls"; +ServletOutputStream servletOutputStream = response.getOutputStream(); +response.setContentType("application/octet-stream"); +response.addHeader("Content-Disposition","attachment;filename=" + new String(fileName.getBytes("GBK"), "ISO8859_1")); +String ids = request.getParameter("ids"); +GoodPurchasePlanManager goodPurchasePlanManager = (GoodPurchasePlanManager)SpringBeanManger.getBean("goodPurchasePlanManager"); +goodPurchasePlanManager.exportGoodPurchasePlan(servletOutputStream,ids); +out.clear(); +response.flushBuffer(); +out = pageContext.pushBody(); +servletOutputStream.flush(); +servletOutputStream.close(); +%> \ No newline at end of file