Commit ed434bba by wangweidong

hmhj原始记录优化

parent 901aa79b
package com.patzn.cloud.service.lims.hmhj.original;
import com.google.common.collect.Lists;
import com.patzn.cloud.service.hmhj.entity.Entrust;
import com.patzn.cloud.service.hmhj.entity.OriginalTemplate;
import com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO;
import com.patzn.cloud.service.hmhj.vo.EntrustSampleVO;
import com.patzn.cloud.service.lims.common.StringHandleUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -33,95 +33,160 @@ public class MoreItemMoreOperation implements Operation {
OriginalUtil.doReplace(xssfWorkbook,entrust);
XSSFSheet sheetOne = xssfWorkbook.getSheetAt(0);
sheetOne.setForceFormulaRecalculation(true);
Integer beginRow = template.getSampleBeginRow();
int sampleMergerNum = template.getSampleMergerNum();
int templateSampleNum = template.getTemplateSampleNum();
int insertRow = beginRow+sampleMergerNum*templateSampleNum;
XSSFRow zeroRow = sheetOne.getRow(beginRow);
XSSFRow zeroRow = sheetOne.getRow(template.getSampleBeginRow());
XSSFCellStyle cellStyle = zeroRow.getCell(0).getCellStyle();
int lastCellNum = zeroRow.getLastCellNum();
int insertCount = voList.size()-templateSampleNum;
for (int m = 0 ; m<insertCount ;m++) {
for (int i = 0; i < sampleMergerNum; i++) {
sheetOne.shiftRows(insertRow, sheetOne.getLastRowNum(), 1,true,false);
XSSFRow row = sheetOne.createRow(insertRow);
row.setHeight(zeroRow.getHeight());
for (int j = 0; j < lastCellNum; j++) {
XSSFCell xssfCell = row.createCell(j);
xssfCell.setCellStyle(cellStyle);
}
insertRow++;
if(template.getMoreSheet()==1){
//生成多个sheet的原始记录
//判断要生成几份sheet
int total = voList.size();
int totalSheetSize = (total+templateSampleNum-1)/templateSampleNum;
List<List<EntrustSampleVO>> listList = Lists.partition(voList,templateSampleNum);
for (int i = 1; i < totalSheetSize; i++) {
xssfWorkbook.cloneSheet(0,sheetOne.getSheetName()+(i+1));
}
}
int sn = 1;
for (int m = 0; m < listList.size(); m++) {
List<EntrustSampleVO> sampleVOListIndex = listList.get(m);
for (EntrustSampleVO vo:voList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
XSSFSheet sheetIndex= xssfWorkbook.getSheetAt(m);
Integer beginRow = template.getSampleBeginRow();
for (OriginalTemplateConfig config:configList) {
if (null == config.getColumnPlace()){
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())){
cell.setCellValue(sn);
}else{
cell.setCellValue(StringHandleUtils.getFieldValue(config.getDataAttribute(),vo));
}
}
beginRow+=sampleMergerNum;
sn++;
}
for (OriginalTemplateConfig config:configList) {
if (null==config.getMergeRowNum()){
config.setMergeRowNum(1);
}
if (StringUtils.isNotBlank(config.getFormula())&&null != config.getColumnPlace() && null != config.getMergeRowNum()){
for (EntrustSampleVO vo:sampleVOListIndex) {
XSSFRow xssfRow = sheetIndex.getRow(beginRow);
for (OriginalTemplateConfig config:configList) {
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())){
continue;
}
if (StringUtils.isBlank(config.getDataAttribute())){
continue;
}
cell.setCellValue(StringHandleUtils.getFieldValue(config.getDataAttribute(),vo));
}
beginRow+=sampleMergerNum;
}
Integer sampleBgMum = template.getSampleBeginRow();
Integer mergeRowNum = config.getMergeRowNum();
int formulaNum = template.getSampleBeginRow()+sampleMergerNum*voList.size()-1 ;
for (int i =sampleBgMum ; i <= formulaNum; i+=mergeRowNum) {
XSSFRow row = sheetOne.getRow(i);
if (null == row){
for (OriginalTemplateConfig config:configList) {
if (null == config.getMergeRowNum()){
config.setMergeRowNum(1);
}
String formula = config.getFormula();
if (StringUtils.isBlank(formula)){
continue;
}
XSSFCell cell = row.getCell(config.getColumnPlace());
if (null == cell){
Integer columnPlace = config.getColumnPlace();
if (null == config.getColumnPlace()){
continue;
}
String formula = config.getFormula();
cell.setCellFormula(OriginalUtil.initFormula(formula,i));
}
}
}
if (null == config.getMergeRowNum()){
continue;
}
Integer mergeRowNum = config.getMergeRowNum();
int formulaNum = template.getSampleBeginRow()+sampleMergerNum*templateSampleNum-1 ;
for (OriginalTemplateConfig config:configList) {
if (null==config.getMergeRowNum()){
config.setMergeRowNum(1);
for (int i =sampleBgMum ; i <= formulaNum; i+=mergeRowNum) {
XSSFRow row = sheetOne.getRow(i);
XSSFCell cell = row.getCell(columnPlace);
cell.setCellFormula(OriginalUtil.initFormula(formula,i));
}
}
}
if (null == config.getMergeBegin()){
continue;
}else{
Integer beginRow = template.getSampleBeginRow();
int insertRow = beginRow+sampleMergerNum*templateSampleNum;
int insertCount = voList.size()-templateSampleNum;
for (int m = 0 ; m<insertCount ;m++) {
for (int i = 0; i < sampleMergerNum; i++) {
sheetOne.shiftRows(insertRow, sheetOne.getLastRowNum(), 1,true,false);
XSSFRow row = sheetOne.createRow(insertRow);
row.setHeight(zeroRow.getHeight());
for (int j = 0; j < lastCellNum; j++) {
XSSFCell xssfCell = row.createCell(j);
xssfCell.setCellStyle(cellStyle);
}
insertRow++;
}
}
if (null == config.getMergeEnd()){
continue;
int sn = 1;
for (EntrustSampleVO vo:voList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (OriginalTemplateConfig config:configList) {
if (null == config.getColumnPlace()){
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())){
cell.setCellValue(sn);
}else{
cell.setCellValue(StringHandleUtils.getFieldValue(config.getDataAttribute(),vo));
}
}
beginRow+=sampleMergerNum;
sn++;
}
int step= config.getMergeRowNum();
if (step==1 && config.getMergeEnd() == config.getMergeBegin()){
continue;
for (OriginalTemplateConfig config:configList) {
if (null==config.getMergeRowNum()){
config.setMergeRowNum(1);
}
if (StringUtils.isNotBlank(config.getFormula())&&null != config.getColumnPlace() && null != config.getMergeRowNum()){
Integer sampleBgMum = template.getSampleBeginRow();
Integer mergeRowNum = config.getMergeRowNum();
int formulaNum = template.getSampleBeginRow()+sampleMergerNum*voList.size()-1 ;
for (int i =sampleBgMum ; i <= formulaNum; i+=mergeRowNum) {
XSSFRow row = sheetOne.getRow(i);
if (null == row){
continue;
}
XSSFCell cell = row.getCell(config.getColumnPlace());
if (null == cell){
continue;
}
String formula = config.getFormula();
cell.setCellFormula(OriginalUtil.initFormula(formula,i));
}
}
}
if (null != config.getColumnPlace() && null != config.getMergeRowNum()){
Integer sampleBgMum = template.getSampleBeginRow()+templateSampleNum*sampleMergerNum;
Integer sampleEnMum = template.getSampleBeginRow()+voList.size()*sampleMergerNum-1;
while (sampleBgMum<=sampleEnMum) {
sheetOne.addMergedRegion(new CellRangeAddress(sampleBgMum,sampleBgMum+step-1,config.getMergeBegin(),config.getMergeEnd()));
sampleBgMum=sampleBgMum+step;
for (OriginalTemplateConfig config:configList) {
if (null==config.getMergeRowNum()){
config.setMergeRowNum(1);
}
if (null == config.getMergeBegin()){
continue;
}
if (null == config.getMergeEnd()){
continue;
}
int step= config.getMergeRowNum();
if (step==1 && config.getMergeEnd() == config.getMergeBegin()){
continue;
}
if (null != config.getColumnPlace() && null != config.getMergeRowNum()){
Integer sampleBgMum = template.getSampleBeginRow()+templateSampleNum*sampleMergerNum;
Integer sampleEnMum = template.getSampleBeginRow()+voList.size()*sampleMergerNum-1;
while (sampleBgMum<=sampleEnMum) {
sheetOne.addMergedRegion(new CellRangeAddress(sampleBgMum,sampleBgMum+step-1,config.getMergeBegin(),config.getMergeEnd()));
sampleBgMum=sampleBgMum+step;
}
}
}
}
}
}
......@@ -237,12 +237,6 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
RestAssert.fail(StringUtils.isBlank(someParam) || 4 != someParam.split("&").length, "参数传递有误");
String[] arr = someParam.split("&");
Long businessId = Long.parseLong(arr[0]);
String userName = null;
try {
userName = java.net.URLDecoder.decode(arr[2], "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Long userId = Long.parseLong(arr[1]);
Long companyId = Long.parseLong(arr[3]);
OriginalRecord report = originalRecordService.getById(businessId);
......@@ -263,8 +257,6 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
return false;
}
XSSFSheet sheet = xssfWorkbook.getSheetAt(0);
if (null == report.getTemplateId()) {
return true;
}
......@@ -274,6 +266,13 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
if (null == template) {
return true;
}
int sheetSize = xssfWorkbook.getNumberOfSheets();
Integer moreSheet = template.getMoreSheet();
List<OriginalTemplateConfig> configList = originalTemplateConfigService.list(Condition.create().eq("template_id", template.getId()));
......@@ -308,8 +307,8 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
for (EntrustSampleItemIndexVO soilItemVO : indexList) {
stringMap.put(soilItemVO.getSampleCode() + soilItemVO.getEntrustSampleItemId() + soilItemVO.getName(), soilItemVO.getId());
}
if (null == moreSheet || 0 == moreSheet) {
for (int k = 0; k < sheetSize; k++) {
XSSFSheet sheet = xssfWorkbook.getSheetAt(k);
int sampleBeginRow = template.getSampleBeginRow();
int sampleMergerNum = template.getSampleMergerNum();
int lastRowNum = sheet.getLastRowNum();
......@@ -533,9 +532,8 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
if (CollectionUtils.isNotEmpty(updateList)) {
entrustSampleItemIndexService.updateBatchById(updateList);
}
}
return true;
}
......
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