|
@@ -3,12 +3,14 @@ package com.sprivacy.pms.util;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.sprivacy.pms.form.per.PerForm;
|
|
|
import com.sprivacy.pms.mapper.PerMapper;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -185,17 +187,16 @@ public class ExportExcelUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
HSSFSheet sheetAnother = wbs.getSheetAt(1);
|
|
|
int totalRowAnother = sheetAnother.getLastRowNum();
|
|
|
|
|
|
-
|
|
|
for (int i = 0; i < totalRowAnother; i++) {
|
|
|
for (PerForm perForm : perForms) {
|
|
|
if (null != perForm.getFamRelations()){
|
|
|
int famRelationsNum = perForm.getFamRelations().size();
|
|
|
if (famRelationsNum > 0){
|
|
|
if (perForm.getFamRelations().get(0).getRelation().equals("配偶")){
|
|
|
+ System.err.println("配偶来了。。。");
|
|
|
for (int i1 = 1; i1 < famRelationsNum; i1++) {
|
|
|
if (i == (0 + i1) && perForm.getFamRelations().get(i1-1).getRelation().equals("配偶")) {
|
|
|
sheetAnother.getRow(i).getCell(2).setCellValue(perForm.getFamRelations().get(0).getName());
|
|
@@ -304,10 +305,6 @@ public class ExportExcelUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if (null != perForm.getSocRelations()){
|
|
|
int socRelationsNum = perForm.getSocRelations().size();
|
|
|
if (socRelationsNum > 0){
|
|
@@ -389,23 +386,28 @@ public class ExportExcelUtil {
|
|
|
String currDateStr = DateUtils.getCurrentFromatTimeBySelf();
|
|
|
// // 获取重复文件
|
|
|
List<String> fileNames = getFileNames(path,Long.valueOf(StringUtils.substringBefore(excelFileName,"_")));
|
|
|
- for (String fileName : fileNames) {
|
|
|
- File file = new File(path + fileName);
|
|
|
- log.info("fileName<>"+fileName);
|
|
|
-
|
|
|
- log.info(fileName+","+checkSameName);
|
|
|
- if (fileName.contains(checkSameName)){
|
|
|
- log.info("file 存在>"+ JSON.toJSONString(file));
|
|
|
- if (file.exists()) {
|
|
|
- if (!fileName.equals(checkSameName+currDateStr+".xls")){
|
|
|
- boolean d = file.delete();
|
|
|
- log.info("重复文件是否删除成功>" + d);
|
|
|
- }
|
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(fileNames)){
|
|
|
+ System.err.println(fileNames.size() + ","+JSON.toJSONString(fileNames));
|
|
|
+ for (String fileName : fileNames) {
|
|
|
+ File file = new File(path + fileName);
|
|
|
+ log.info("fileName<>"+fileName);
|
|
|
+
|
|
|
+ log.info(fileName+","+checkSameName);
|
|
|
+ if (fileName.contains(checkSameName)){
|
|
|
+ log.info("file 存在>"+ JSON.toJSONString(file));
|
|
|
+ if (file.exists()) {
|
|
|
+ if (!fileName.equals(checkSameName+currDateStr+".xls")){
|
|
|
+ boolean d = file.delete();
|
|
|
+ log.info("重复文件是否删除成功>" + d);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
wbs.write(fileOutputStream);
|
|
|
+ System.err.println(path + excelFileName + ".xls");
|
|
|
try {
|
|
|
fileOutputStream.close(); // 关闭流
|
|
|
fileOutputStream.close(); // 关闭工作簿
|
|
@@ -426,22 +428,25 @@ public class ExportExcelUtil {
|
|
|
*/
|
|
|
private static void drawPictureInfoExcel(String pictureUrl,HSSFWorkbook wb,HSSFPatriarch patriarch,int rowIndex){
|
|
|
try {
|
|
|
- URL url = new URL(pictureUrl);
|
|
|
- BufferedImage bufferImg = ImageIO.read(url);
|
|
|
- ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
-
|
|
|
- // 构建图片格式
|
|
|
- String tempedFormatName = StringUtils.substringAfter(pictureUrl,"/pms/img/");
|
|
|
- String formatName = StringUtils.substringAfter(tempedFormatName,".");
|
|
|
-
|
|
|
- ImageIO.write(bufferImg, formatName, byteArrayOut);
|
|
|
- byte[] data = byteArrayOut.toByteArray();
|
|
|
-
|
|
|
- HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 250,(short) rowIndex, 2, (short) rowIndex, 6);
|
|
|
- // Sets the anchor type (图片在单元格的位置)
|
|
|
- // 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
|
|
- anchor.setAnchorType(ClientAnchor.AnchorType.byId(0));
|
|
|
- patriarch.createPicture(anchor, wb.addPicture(data, HSSFWorkbook.PICTURE_TYPE_JPEG));
|
|
|
+ // pictureUrl = "http://mms.s-privacy.cn:8087/pms/img/3734fd40-6521-4fb5-91d7-651f78028ad4.png";
|
|
|
+ if (null != pictureUrl && !StringUtils.isEmpty(pictureUrl)){
|
|
|
+ URL url = new URL(pictureUrl);
|
|
|
+ BufferedImage bufferImg = ImageIO.read(url);
|
|
|
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ // 构建图片格式
|
|
|
+ String tempedFormatName = StringUtils.substringAfter(pictureUrl,"/pms/img/");
|
|
|
+ String formatName = StringUtils.substringAfter(tempedFormatName,".");
|
|
|
+
|
|
|
+ ImageIO.write(bufferImg, formatName, byteArrayOut);
|
|
|
+ byte[] data = byteArrayOut.toByteArray();
|
|
|
+
|
|
|
+ HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 250,(short) rowIndex, 2, (short) rowIndex, 6);
|
|
|
+ // Sets the anchor type (图片在单元格的位置)
|
|
|
+ // 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
|
|
+ anchor.setAnchorType(ClientAnchor.AnchorType.byId(0));
|
|
|
+ patriarch.createPicture(anchor, wb.addPicture(data, HSSFWorkbook.PICTURE_TYPE_JPEG));
|
|
|
+ }
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (Exception e) {
|
|
@@ -502,9 +507,11 @@ public class ExportExcelUtil {
|
|
|
String zipFileName = DateUtils.getCurrentFromatTimeBySelf();
|
|
|
for (Long id : ids) {
|
|
|
fileName = getFileName(path,id);
|
|
|
+ System.out.println(fileName);
|
|
|
+ System.err.println(path + fileName);
|
|
|
FileInputStream is = new FileInputStream(path + fileName);
|
|
|
- HSSFWorkbook wbs = new HSSFWorkbook(is);
|
|
|
-
|
|
|
+ // HSSFWorkbook wbs = new HSSFWorkbook(is);
|
|
|
+ XSSFWorkbook wbs = new XSSFWorkbook(is);
|
|
|
ZipEntry entry = new ZipEntry(fileName);
|
|
|
zip.putNextEntry(entry);
|
|
|
|
|
@@ -521,14 +528,11 @@ public class ExportExcelUtil {
|
|
|
response.addHeader("Content-Disposition", "attachment;filename=" + zipFileName + ".zip");
|
|
|
}
|
|
|
response.flushBuffer();
|
|
|
-
|
|
|
wbs.write(zip);
|
|
|
}
|
|
|
zip.flush();
|
|
|
zip.close();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static String getFileName(String path,Long id){
|
|
@@ -556,7 +560,9 @@ public class ExportExcelUtil {
|
|
|
if (tempList[i].isFile()) {
|
|
|
System.out.println("文 件:" + tempList[i]);
|
|
|
String tempStr = StringUtils.substringBefore(tempList[i].getName(),"_");
|
|
|
+ System.err.println(tempStr+","+id);
|
|
|
if (tempStr.equals(String.valueOf(id))){
|
|
|
+ System.err.println("same");
|
|
|
fileStrs.add(tempList[i].getName());
|
|
|
return fileStrs;
|
|
|
}
|