Commit 41356749 by wangweidong

土工优化

parent 147474df
...@@ -300,9 +300,7 @@ public class HSSFWorkbookUtil { ...@@ -300,9 +300,7 @@ public class HSSFWorkbookUtil {
anchor.setRow1(i); anchor.setRow1(i);
System.out.println("setCol1:"+j); System.out.println("setCol1:"+j);
System.out.println("setRow1:"+i); System.out.println("setRow1:"+i);
Picture pict = drawing.createPicture(anchor, nameIndex.get(qrcodeName)); drawing.createPicture(anchor, nameIndex.get(qrcodeName));
// // 计算单元格的长宽
// pict.resize();
} }
} }
} }
......
...@@ -13,6 +13,7 @@ import org.slf4j.Logger; ...@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
import java.util.Map; import java.util.Map;
public final class InitMapReplace { public final class InitMapReplace {
...@@ -214,7 +215,7 @@ public final class InitMapReplace { ...@@ -214,7 +215,7 @@ public final class InitMapReplace {
public final static void initFormula(SoilOriginalTemplateConfig config, SoilOriginalTemplate template, int sampleMergerNum, int templateSampleNum, XSSFSheet sheetOne) { public final static void initFormula(SoilOriginalTemplateConfig config, SoilOriginalTemplate template, XSSFSheet sheetOne,int formulaNum) {
if (null == config.getMergeRowNum()){ if (null == config.getMergeRowNum()){
config.setMergeRowNum(1); config.setMergeRowNum(1);
} }
...@@ -223,7 +224,7 @@ public final class InitMapReplace { ...@@ -223,7 +224,7 @@ public final class InitMapReplace {
} }
Integer sampleBgMum = template.getSampleBeginRow(); Integer sampleBgMum = template.getSampleBeginRow();
Integer mergeRowNum = config.getMergeRowNum(); Integer mergeRowNum = config.getMergeRowNum();
int formulaNum = template.getSampleBeginRow()+sampleMergerNum*templateSampleNum-1 ; // int formulaNum = template.getSampleBeginRow()+sampleMergerNum*templateSampleNum-1 ;
for (int i =sampleBgMum ; i <= formulaNum; i+=mergeRowNum) { for (int i =sampleBgMum ; i <= formulaNum; i+=mergeRowNum) {
XSSFRow row = sheetOne.getRow(i); XSSFRow row = sheetOne.getRow(i);
if (null == row){ if (null == row){
...@@ -240,4 +241,7 @@ public final class InitMapReplace { ...@@ -240,4 +241,7 @@ public final class InitMapReplace {
} }
...@@ -83,7 +83,7 @@ public class SingleLessOperation implements Operation { ...@@ -83,7 +83,7 @@ public class SingleLessOperation implements Operation {
beginRow+=sampleMergerNum; beginRow+=sampleMergerNum;
} }
for (SoilOriginalTemplateConfig config:configList) { for (SoilOriginalTemplateConfig config:configList) {
InitMapReplace.initFormula(config,template,sampleMergerNum,templateSampleNum,sheetOne); InitMapReplace.initFormula(config,template,sheetOne, template.getSampleBeginRow()+sampleMergerNum*templateSampleNum-1);
} }
logger.error("----------------------7"); logger.error("----------------------7");
} }
......
...@@ -117,8 +117,9 @@ public class SingleMoreOperation implements Operation{ ...@@ -117,8 +117,9 @@ public class SingleMoreOperation implements Operation{
beginRow+=sampleMergerNum; beginRow+=sampleMergerNum;
sn++; sn++;
} }
int formulaNum = template.getSampleBeginRow()+sampleMergerNum*voList.size()-1 ;
for (SoilOriginalTemplateConfig config:configList) { for (SoilOriginalTemplateConfig config:configList) {
InitMapReplace.initFormula(config,template,sampleMergerNum,templateSampleNum,sheetOne); InitMapReplace.initFormula(config,template,sheetOne,formulaNum);
} }
......
...@@ -1630,10 +1630,11 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1630,10 +1630,11 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
FileOutputStream fos=null; FileOutputStream fos=null;
XSSFWorkbook xssfWorkbook= null; XSSFWorkbook xssfWorkbook= null;
FileOutputStream os=null; FileOutputStream os=null;
File file=null;
try { try {
is= smbFile.getInputStream(); is= smbFile.getInputStream();
File file = File.createTempFile(StringHandleUtils.getFileNameNoEx(smbFile.getOriginalFilename()),smbFile.getOriginalFilename().replace(StringHandleUtils.getFileNameNoEx(smbFile.getOriginalFilename()),"")); file= File.createTempFile(StringHandleUtils.getFileNameNoEx(smbFile.getOriginalFilename()),smbFile.getOriginalFilename().replace(StringHandleUtils.getFileNameNoEx(smbFile.getOriginalFilename()),""));
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
byte[] bytes = new byte[1024*1024]; byte[] bytes = new byte[1024*1024];
int index; int index;
...@@ -1750,10 +1751,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1750,10 +1751,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
collectFile.setVersionId(result.getVersionId()); collectFile.setVersionId(result.getVersionId());
collectFile.setFileName(result.getName()); collectFile.setFileName(result.getName());
soilExperimentCollectFileService.save(collectFile); soilExperimentCollectFileService.save(collectFile);
FileUtils.deleteFiles(file);
if (null!=fileNew){
FileUtils.deleteFiles(fileNew);
}
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
}finally { }finally {
...@@ -1779,6 +1777,11 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1779,6 +1777,11 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
e.printStackTrace(); e.printStackTrace();
} }
FileUtils.deleteFiles(file);
if (null!=fileNew){
FileUtils.deleteFiles(fileNew);
}
} }
} }
System.out.println(smbFile.getName()); System.out.println(smbFile.getName());
...@@ -1786,17 +1789,22 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1786,17 +1789,22 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
} }
public void uploadCollectPng(MultipartFile smbFile, CollectDataType type) {
public void doCollectPng(InputStream is ,String originalFilename, CollectDataType type) {
if (type.getExpId()!=null){ if (type.getExpId()!=null){
SoilExperimentCollectFile collectFile = new SoilExperimentCollectFile(); SoilExperimentCollectFile collectFile = new SoilExperimentCollectFile();
collectFile.setExpId(type.getExpId()); collectFile.setExpId(type.getExpId());
InputStream is = null;
File fileNew = null; File fileNew = null;
FileOutputStream fos = null;
XSSFWorkbook xssfWorkbook=null;
FileOutputStream os=null;
File file=null;
try { try {
is= smbFile.getInputStream();
File file = File.createTempFile(StringHandleUtils.getFileNameNoEx(smbFile.getOriginalFilename()),smbFile.getOriginalFilename().replace(StringHandleUtils.getFileNameNoEx(smbFile.getOriginalFilename()),"")); file = File.createTempFile(StringHandleUtils.getFileNameNoEx(originalFilename),originalFilename.replace(StringHandleUtils.getFileNameNoEx(originalFilename),""));
FileOutputStream fos = new FileOutputStream(file); fos = new FileOutputStream(file);
byte[] bytes = new byte[1024*1024]; byte[] bytes = new byte[1024*1024];
int index; int index;
while ((index = is.read(bytes)) != -1) { while ((index = is.read(bytes)) != -1) {
...@@ -1805,7 +1813,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1805,7 +1813,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
} }
String name = smbFile.getOriginalFilename(); String name = originalFilename;
String expname= type.getExperiment(); String expname= type.getExperiment();
if (expname.contains("三轴压缩")&&(!expname.contains("重塑"))){ if (expname.contains("三轴压缩")&&(!expname.contains("重塑"))){
expname="三轴压缩"; expname="三轴压缩";
...@@ -1823,7 +1831,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1823,7 +1831,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
if (name.contains(expname)){ if (name.contains(expname)){
SoilSample sample = soilSampleService.getBySampleCode(type.getSampleCode()); SoilSample sample = soilSampleService.getBySampleCode(type.getSampleCode());
if (null !=sample){ if (null !=sample){
XSSFWorkbook xssfWorkbook= exportService.getXSSFWorkbook("AttachmentTemplateSZYS.xlsx"); xssfWorkbook=exportService.getXSSFWorkbook("AttachmentTemplateSZYS.xlsx");
Map<String,File> fileMap=new HashMap<>(); Map<String,File> fileMap=new HashMap<>();
fileMap.put("${picTest}",file); fileMap.put("${picTest}",file);
...@@ -1851,17 +1859,12 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1851,17 +1859,12 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
} }
xssfWorkbook.setSheetName(0,"附录"+sample.getSiteNo()+type.getExperiment()); xssfWorkbook.setSheetName(0,"附录"+sample.getSiteNo()+type.getExperiment());
FileOutputStream os;
fileNew = File.createTempFile(type.getSampleCode()+type.getExperiment(), ".xlsx"); fileNew = File.createTempFile(type.getSampleCode()+type.getExperiment(), ".xlsx");
os = new FileOutputStream(fileNew); os = new FileOutputStream(fileNew);
xssfWorkbook.write(os); xssfWorkbook.write(os);
os.flush(); os.flush();
os.close();
xssfWorkbook.close();
OssFileResult result = ossClient.upload(fileNew);
OssFileResult result = ossClient.upload(fileNew);
SoilAppendix appendix = new SoilAppendix(); SoilAppendix appendix = new SoilAppendix();
appendix.setSampleId(sample.getId()); appendix.setSampleId(sample.getId());
appendix.setEntrustId(sample.getEntrustId()); appendix.setEntrustId(sample.getEntrustId());
...@@ -1882,36 +1885,60 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -1882,36 +1885,60 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
}else{ }else{
appendix.setRemark(type.getExperiment()); appendix.setRemark(type.getExperiment());
} }
appendix.setEntrustCode(type.getEntrustCode()); appendix.setEntrustCode(type.getEntrustCode());
soilAppendixService.save(appendix); soilAppendixService.save(appendix);
} }
} }
is.close();
fos.close();
OssFileResult result = ossClient.upload(file); OssFileResult result = ossClient.upload(file);
collectFile.setObjectKey(result.getObjectKey()); collectFile.setObjectKey(result.getObjectKey());
collectFile.setBucketName(result.getBucketName()); collectFile.setBucketName(result.getBucketName());
collectFile.setVersionId(result.getVersionId()); collectFile.setVersionId(result.getVersionId());
collectFile.setFileName(result.getName()); collectFile.setFileName(result.getName());
soilExperimentCollectFileService.save(collectFile); soilExperimentCollectFileService.save(collectFile);
}catch (Exception e){
e.printStackTrace();
}finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
xssfWorkbook.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
FileUtils.deleteFiles(file); FileUtils.deleteFiles(file);
if (null!=fileNew){ if (null!=fileNew){
FileUtils.deleteFiles(fileNew); FileUtils.deleteFiles(fileNew);
} }
}catch (Exception e){
e.printStackTrace();
} }
} }
System.out.println(smbFile.getName()); }
System.out.println(type.getEntrustCode());
public void uploadCollectPng(MultipartFile smbFile, CollectDataType type) {
try {
doCollectPng(smbFile.getInputStream(),smbFile.getOriginalFilename(),type);
} catch (IOException e) {
e.printStackTrace();
}
} }
...@@ -2130,127 +2157,13 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap ...@@ -2130,127 +2157,13 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
@Override @Override
public void uploadCollectPng(SmbFile smbFile, CollectDataType type) { public void uploadCollectPng(SmbFile smbFile, CollectDataType type) {
if (type.getExpId()!=null){ try {
SoilExperimentCollectFile collectFile = new SoilExperimentCollectFile(); doCollectPng(smbFile.getInputStream(),smbFile.getName(),type);
collectFile.setEquipId(type.getEquipId()); } catch (IOException e) {
collectFile.setExpId(type.getExpId()); e.printStackTrace();
collectFile.setEquipNum(type.getEquipNum());
collectFile.setEquipName(type.getEquipName());
collectFile.setLabNum(type.getLabNum());
collectFile.setBrand(type.getBrand());
collectFile.setSpec(type.getSpec());
InputStream is = null;
File fileNew = null;
try {
is= smbFile.getInputStream();
File file = File.createTempFile(StringHandleUtils.getFileNameNoEx(smbFile.getName()),smbFile.getName().replace(StringHandleUtils.getFileNameNoEx(smbFile.getName()),""));
FileOutputStream fos = new FileOutputStream(file);
byte[] bytes = new byte[1024*1024];
int index;
while ((index = is.read(bytes)) != -1) {
fos.write(bytes, 0, index);
fos.flush();
}
String name = smbFile.getName();
SoilSample sample = soilSampleService.getBySampleCode(type.getSampleCode());
if (null !=sample){
XSSFWorkbook xssfWorkbook= exportService.getXSSFWorkbook("AttachmentTemplateSZYS.xlsx");
Map<String,File> fileMap=new HashMap<>();
fileMap.put("${picTest}",file);
Map<String,String> replaceMap=new HashMap<>();
String testEnglish = "";
if("三轴压缩".equals(type.getExperiment())||type.getExperiment().contains("三轴压缩")){
testEnglish = "FIGURE OF TRIAXIAL COMPRESSION TEST";
}else if("直接剪切".equals(type.getExperiment())||"直剪".equals(type.getExperiment())){
testEnglish = "FIGURE OF DIRECT SHEAR TEST";
}else if("固结".equals(type.getExperiment())||"固结试验".equals(type.getExperiment())){
testEnglish = "FIGURE OF CONSOLIDATION TEST";
}else{
testEnglish = "FIGURE OF TRIAXIAL COMPRESSION TEST";
}
replaceMap.put("#{title}","附录"+sample.getSiteNo()+" "+type.getExperiment()+"试验成果图\n" +
"APPENDIX "+sample.getSiteNo()+" "+testEnglish);
replaceMap.put("#{reportCode}",StringHandleUtils.getString(type.getEntrustCode()));
try {
HSSFWorkbookUtil.replaceModel(replaceMap,xssfWorkbook);
HSSFWorkbookUtil.insertImage(xssfWorkbook,fileMap,true);
}catch (Exception e){
logger.error("generateExcelReport错误"+e.getMessage());
}
xssfWorkbook.setSheetName(0,"附录"+sample.getSiteNo()+type.getExperiment());
FileOutputStream os;
fileNew = File.createTempFile(type.getSampleCode()+type.getExperiment(), ".xlsx");
os = new FileOutputStream(fileNew);
xssfWorkbook.write(os);
os.flush();
os.close();
xssfWorkbook.close();
OssFileResult result = ossClient.upload(fileNew);
SoilAppendix appendix = new SoilAppendix();
appendix.setSampleId(sample.getId());
appendix.setEntrustId(sample.getEntrustId());
appendix.setUname(LoginHelper.getAccount().getUserName());
appendix.setObjectKey(result.getObjectKey());
appendix.setName("附录"+sample.getSiteNo()+" "+type.getExperiment()+"试验成果图");
appendix.setTitle("附录"+sample.getSiteNo());
appendix.setExpId(type.getExpId());
appendix.setSampleCode(type.getSiteNo());
appendix.setEntrustCode(type.getEntrustCode());
if (name.contains("三轴")){
appendix.setRemark("三轴");
}else if (name.contains("固结")){
appendix.setRemark("固结");
}else if (name.contains("直剪")||name.contains("直接剪切")){
appendix.setRemark("直剪");
}else if (name.contains("无侧限")){
appendix.setRemark("无侧限");
}else{
appendix.setRemark(type.getExperiment());
}
soilAppendixService.save(appendix);
}
is.close();
fos.close();
OssFileResult result = ossClient.upload(file);
collectFile.setObjectKey(result.getObjectKey());
collectFile.setBucketName(result.getBucketName());
collectFile.setVersionId(result.getVersionId());
collectFile.setFileName(result.getName());
soilExperimentCollectFileService.save(collectFile);
FileUtils.deleteFiles(file);
if (null!=fileNew){
FileUtils.deleteFiles(fileNew);
}
}catch (Exception e){
logger.error("uploadCollectPng采集失败,原因:"+e.getMessage());
e.printStackTrace();
}
} }
System.out.println(smbFile.getName());
System.out.println(type.getEntrustCode());
} }
public static void main(String[] args) { public static void main(String[] args) {
compressPic("D://ZJ-Z13-25.bmp","D://aaa.bmp"); compressPic("D://ZJ-Z13-25.bmp","D://aaa.bmp");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment