|
@@ -7,9 +7,11 @@ import cn.hnthyy.thmz.enums.YesNoEnum;
|
|
import cn.hnthyy.thmz.vo.ChargeFeeVo;
|
|
import cn.hnthyy.thmz.vo.ChargeFeeVo;
|
|
import cn.hnthyy.thmz.vo.MzyReqrecVo;
|
|
import cn.hnthyy.thmz.vo.MzyReqrecVo;
|
|
import cn.hnthyy.thmz.vo.ReqrecVo;
|
|
import cn.hnthyy.thmz.vo.ReqrecVo;
|
|
|
|
+import cn.hnthyy.thmz.vo.YpZdBaseYfVo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
-import org.apache.poi.hssf.usermodel.*;
|
|
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDataFormat;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
@@ -18,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import static org.apache.poi.ss.usermodel.CellType.*;
|
|
import static org.apache.poi.ss.usermodel.CellType.*;
|
|
@@ -34,6 +37,7 @@ public class ExcelUtil {
|
|
private static final String HEAD_ARR_KEY = "headArr";
|
|
private static final String HEAD_ARR_KEY = "headArr";
|
|
private static final String HEAD_NUM_KEY = "headNum";
|
|
private static final String HEAD_NUM_KEY = "headNum";
|
|
private static final Integer YP_REPORT_COLUMNS_LENGTH = 13;
|
|
private static final Integer YP_REPORT_COLUMNS_LENGTH = 13;
|
|
|
|
+ private static final Integer YP_YFKCQD_REPORT_COLUMNS_LENGTH = 9;
|
|
private static final Integer VERSION_2007 = 2007;
|
|
private static final Integer VERSION_2007 = 2007;
|
|
private static final Integer VERSION_2003 = 2003;
|
|
private static final Integer VERSION_2003 = 2003;
|
|
|
|
|
|
@@ -100,7 +104,17 @@ public class ExcelUtil {
|
|
exportExcel(request, response, data, YP_REPORT_COLUMNS_LENGTH, VERSION_2007);
|
|
exportExcel(request, response, data, YP_REPORT_COLUMNS_LENGTH, VERSION_2007);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 将药房库存明细对象转换为导出Excel
|
|
|
|
+ *
|
|
|
|
+ * @param request
|
|
|
|
+ * @param response
|
|
|
|
+ * @param ypZdBaseYfVos
|
|
|
|
+ */
|
|
|
|
+ public static void exportExcelForYfInventoryList(HttpServletRequest request, HttpServletResponse response, List<YpZdBaseYfVo> ypZdBaseYfVos) {
|
|
|
|
+ Map<String, Object> data = fomartYfInventoryList(ypZdBaseYfVos);
|
|
|
|
+ exportYfInventoryListExcel(request, response, data, YP_YFKCQD_REPORT_COLUMNS_LENGTH, VERSION_2007);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 将门诊收入明细列表对象转换为导出Excel
|
|
* 将门诊收入明细列表对象转换为导出Excel
|
|
@@ -157,6 +171,45 @@ public class ExcelUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 方法名:exportYfInventoryListExcel
|
|
|
|
+ * 功能:导出Excel
|
|
|
|
+ */
|
|
|
|
+ public static byte[] exportYfInventoryListExcel(HttpServletRequest request, HttpServletResponse response, Map<String, Object> data, Integer columns, Integer version) {
|
|
|
|
+ if (data == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ log.info("导出解析开始,fileName:{}", data.get(FILE_NAME_KEY));
|
|
|
|
+ try {
|
|
|
|
+ //实例化HSSFWorkbook
|
|
|
|
+ //HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
|
+ Workbook workbook = null;
|
|
|
|
+ if (version.equals(VERSION_2007)) {
|
|
|
|
+ workbook = new XSSFWorkbook();// 创建 一个excel文档对象
|
|
|
|
+ } else if (version.equals(VERSION_2003)) {
|
|
|
|
+ workbook = new HSSFWorkbook();// 创建 一个excel文档对象
|
|
|
|
+ }
|
|
|
|
+ //创建一个Excel表单,参数为sheet的名字
|
|
|
|
+ Sheet sheet = workbook.createSheet(SHEET_NAME);
|
|
|
|
+ //设置表头
|
|
|
|
+ setYfInventoryListTitle(workbook, sheet, (List<Map<String, Object>>) data.get(HEAD_KEY), columns);
|
|
|
|
+ //设置单元格并赋值
|
|
|
|
+ setYfInventoryListData(workbook,sheet, (List<String[]>) data.get(DATA_KEY), ((List<Map<String, Object>>) data.get(HEAD_KEY)).size());
|
|
|
|
+ log.info("导出解析成功!");
|
|
|
|
+ if(request!=null && response!=null){
|
|
|
|
+ //设置浏览器下载
|
|
|
|
+ setBrowser(request, response, workbook, (String) data.get(FILE_NAME_KEY));
|
|
|
|
+ return null;
|
|
|
|
+ }else {
|
|
|
|
+ // return createFile(workbook,(String) data.get(FILE_NAME_KEY));
|
|
|
|
+ return createFile(workbook);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("导出解析失败!错误信息{}", e.getMessage());
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 方法名:setTitle
|
|
* 方法名:setTitle
|
|
* 功能:设置表头
|
|
* 功能:设置表头
|
|
@@ -216,6 +269,61 @@ public class ExcelUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 方法名:setYfInventoryListTitle
|
|
|
|
+ * 功能:药房库存清单设置表头
|
|
|
|
+ */
|
|
|
|
+ private static void setYfInventoryListTitle(Workbook workbook, Sheet sheet, List<Map<String, Object>> heads, Integer columns) {
|
|
|
|
+ try {
|
|
|
|
+ //设置列宽,setColumnWidth的第二个参数要乘以256,这个参数的单位是1/256个字符宽度
|
|
|
|
+ for (int i = 0; i <= columns; i++) {
|
|
|
|
+ sheet.setColumnWidth(i, 15 * 256);
|
|
|
|
+ }
|
|
|
|
+ //设置为居中加粗,格式化时间格式
|
|
|
|
+ CellStyle style = workbook.createCellStyle();
|
|
|
|
+ Font font = workbook.createFont();
|
|
|
|
+ font.setFontName("宋体");
|
|
|
|
+ font.setFontHeightInPoints((short) 12);// 字体大小
|
|
|
|
+ //font.setBold(true);
|
|
|
|
+ style.setFont(font);
|
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);// 左右居中
|
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
|
|
|
|
+ style.setLocked(true);
|
|
|
|
+ style.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
|
|
|
|
+ sheet.setColumnWidth((short) 2, (short) 6000);
|
|
|
|
+ sheet.setColumnWidth((short) 3, (short) 6000);
|
|
|
|
+ sheet.setColumnWidth((short) 8, (short) 6000);
|
|
|
|
+ for (int i = 0; i < heads.size(); i++) {
|
|
|
|
+ Map<String, Object> head = heads.get(i);
|
|
|
|
+ String[] str = (String[]) head.get(HEAD_ARR_KEY);
|
|
|
|
+ String[] headNum = (String[]) head.get(HEAD_NUM_KEY);
|
|
|
|
+ Row row = sheet.createRow(i);
|
|
|
|
+ row.setHeight((short) 850);
|
|
|
|
+ //创建表头名称
|
|
|
|
+ Cell cell;
|
|
|
|
+ for (int j = 0; j < str.length; j++) {
|
|
|
|
+ cell = row.createCell(j);
|
|
|
|
+ cell.setCellValue(str[j]);
|
|
|
|
+ cell.setCellStyle(style);
|
|
|
|
+ }
|
|
|
|
+ //动态合并单元格
|
|
|
|
+ for (int j = 0; j < headNum.length; j++) {
|
|
|
|
+ String[] temp = headNum[j].split(",");
|
|
|
|
+ Integer startRow = Integer.parseInt(temp[0]);
|
|
|
|
+ Integer overRow = Integer.parseInt(temp[1]);
|
|
|
|
+ Integer startCol = Integer.parseInt(temp[2]);
|
|
|
|
+ Integer overCol = Integer.parseInt(temp[3]);
|
|
|
|
+ if (overRow > startRow || overCol > startCol) {
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startRow, overRow,
|
|
|
|
+ startCol, overCol));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("导出时设置表头失败!,错误信息{}", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 方法名:setData
|
|
* 方法名:setData
|
|
* 功能:表格赋值
|
|
* 功能:表格赋值
|
|
@@ -242,6 +350,37 @@ public class ExcelUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 方法名:setYfInventoryListData
|
|
|
|
+ * 功能:药房库存清单表格赋值
|
|
|
|
+ */
|
|
|
|
+ private static void setYfInventoryListData(Workbook workbook,Sheet sheet, List<String[]> data, Integer rowNum) {
|
|
|
|
+ try {
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
+ Row row = sheet.createRow(rowNum);
|
|
|
|
+ row.setHeight((short) 350);
|
|
|
|
+ for (int j = 0; j < data.get(i).length; j++) {
|
|
|
|
+ Cell cell = row.createCell(j);
|
|
|
|
+ cell.setCellValue(data.get(i)[j]);
|
|
|
|
+ if(j==4 || j==5 || j==6 || j==7){
|
|
|
|
+ CellStyle cellStyle=workbook.createCellStyle(); //设置样式
|
|
|
|
+ Font font = workbook.createFont();
|
|
|
|
+ font.setFontName("宋体");
|
|
|
|
+ font.setFontHeightInPoints((short) 10);// 字体大小
|
|
|
|
+ cellStyle.setFont(font);
|
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.RIGHT); //设置水平方向的对其方式
|
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
|
|
|
|
+ cell.setCellStyle(cellStyle); //设置单元格样式
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rowNum++;
|
|
|
|
+ }
|
|
|
|
+ log.info("表格赋值成功!");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("表格赋值失败!错误信息{}", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 方法名:setBrowser
|
|
* 方法名:setBrowser
|
|
* 功能:使用浏览器下载
|
|
* 功能:使用浏览器下载
|
|
@@ -594,4 +733,45 @@ public class ExcelUtil {
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将药房库存清单对象转换为导出Excel 表格内容的格式
|
|
|
|
+ *
|
|
|
|
+ * @param ypZdBaseYfVos
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private static Map<String, Object> fomartYfInventoryList(List<YpZdBaseYfVo> ypZdBaseYfVos) {
|
|
|
|
+ if (ypZdBaseYfVos == null) {
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
+ }
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
+ data.put(FILE_NAME_KEY, "药房库存清单"+simpleDateFormat.format(new Date())+".xls");
|
|
|
|
+ List<Map<String, Object>> heads = new ArrayList<>();
|
|
|
|
+ Map<String, Object> map0 = new HashMap<>();
|
|
|
|
+ String[] head0 = {"货位号", "药品编码", "药品名称", "规格", "零售价", "库存量", "库存金额", "当前虚存", "生产厂家"};
|
|
|
|
+ String[] headNum0 = {"0,0,0,0"};
|
|
|
|
+ map0.put(HEAD_ARR_KEY, head0);
|
|
|
|
+ map0.put(HEAD_NUM_KEY, headNum0);
|
|
|
|
+ heads.add(map0);
|
|
|
|
+ data.put(HEAD_KEY, heads);
|
|
|
|
+ List<String[]> arr = new ArrayList<>();
|
|
|
|
+ ypZdBaseYfVos.forEach(ypZdBaseYfVo -> {
|
|
|
|
+ if (ypZdBaseYfVo != null) {
|
|
|
|
+ String[] temp = {ypZdBaseYfVo.getLocation(),
|
|
|
|
+ ypZdBaseYfVo.getCode(),
|
|
|
|
+ ypZdBaseYfVo.getName(),
|
|
|
|
+ ypZdBaseYfVo.getSpecification(),
|
|
|
|
+ String.format("%.3f", ypZdBaseYfVo.getPackRetprice()),
|
|
|
|
+ String.format("%.2f", ypZdBaseYfVo.getStockAmount()),
|
|
|
|
+ String.format("%.2f", ypZdBaseYfVo.getStockValue()),
|
|
|
|
+ ypZdBaseYfVo.getStockAmountVirtual().toString(),
|
|
|
|
+ ypZdBaseYfVo.getManufactoryName()
|
|
|
|
+ };
|
|
|
|
+ arr.add(temp);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ data.put(DATA_KEY, arr);
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
}
|
|
}
|