Commit ed434bba by wangweidong

hmhj原始记录优化

parent 901aa79b
package com.patzn.cloud.service.lims.hmhj.original; 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.Entrust;
import com.patzn.cloud.service.hmhj.entity.OriginalTemplate; import com.patzn.cloud.service.hmhj.entity.OriginalTemplate;
import com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig; 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.hmhj.vo.EntrustSampleVO;
import com.patzn.cloud.service.lims.common.StringHandleUtils; import com.patzn.cloud.service.lims.common.StringHandleUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -33,14 +33,80 @@ public class MoreItemMoreOperation implements Operation { ...@@ -33,14 +33,80 @@ public class MoreItemMoreOperation implements Operation {
OriginalUtil.doReplace(xssfWorkbook,entrust); OriginalUtil.doReplace(xssfWorkbook,entrust);
XSSFSheet sheetOne = xssfWorkbook.getSheetAt(0); XSSFSheet sheetOne = xssfWorkbook.getSheetAt(0);
sheetOne.setForceFormulaRecalculation(true); sheetOne.setForceFormulaRecalculation(true);
Integer beginRow = template.getSampleBeginRow();
int sampleMergerNum = template.getSampleMergerNum(); int sampleMergerNum = template.getSampleMergerNum();
int templateSampleNum = template.getTemplateSampleNum(); 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(); XSSFCellStyle cellStyle = zeroRow.getCell(0).getCellStyle();
int lastCellNum = zeroRow.getLastCellNum(); int lastCellNum = zeroRow.getLastCellNum();
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));
}
for (int m = 0; m < listList.size(); m++) {
List<EntrustSampleVO> sampleVOListIndex = listList.get(m);
XSSFSheet sheetIndex= xssfWorkbook.getSheetAt(m);
Integer beginRow = template.getSampleBeginRow();
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();
for (OriginalTemplateConfig config:configList) {
if (null == config.getMergeRowNum()){
config.setMergeRowNum(1);
}
String formula = config.getFormula();
if (StringUtils.isBlank(formula)){
continue;
}
Integer columnPlace = config.getColumnPlace();
if (null == config.getColumnPlace()){
continue;
}
if (null == config.getMergeRowNum()){
continue;
}
Integer mergeRowNum = config.getMergeRowNum();
int formulaNum = template.getSampleBeginRow()+sampleMergerNum*templateSampleNum-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));
}
}
}
}else{
Integer beginRow = template.getSampleBeginRow();
int insertRow = beginRow+sampleMergerNum*templateSampleNum;
int insertCount = voList.size()-templateSampleNum; int insertCount = voList.size()-templateSampleNum;
for (int m = 0 ; m<insertCount ;m++) { for (int m = 0 ; m<insertCount ;m++) {
for (int i = 0; i < sampleMergerNum; i++) { for (int i = 0; i < sampleMergerNum; i++) {
...@@ -56,11 +122,8 @@ public class MoreItemMoreOperation implements Operation { ...@@ -56,11 +122,8 @@ public class MoreItemMoreOperation implements Operation {
} }
} }
int sn = 1; int sn = 1;
for (EntrustSampleVO vo:voList) { for (EntrustSampleVO vo:voList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow); XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (OriginalTemplateConfig config:configList) { for (OriginalTemplateConfig config:configList) {
if (null == config.getColumnPlace()){ if (null == config.getColumnPlace()){
continue; continue;
...@@ -124,4 +187,6 @@ public class MoreItemMoreOperation implements Operation { ...@@ -124,4 +187,6 @@ public class MoreItemMoreOperation implements Operation {
} }
} }
} }
}
} }
...@@ -237,12 +237,6 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat ...@@ -237,12 +237,6 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
RestAssert.fail(StringUtils.isBlank(someParam) || 4 != someParam.split("&").length, "参数传递有误"); RestAssert.fail(StringUtils.isBlank(someParam) || 4 != someParam.split("&").length, "参数传递有误");
String[] arr = someParam.split("&"); String[] arr = someParam.split("&");
Long businessId = Long.parseLong(arr[0]); 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 userId = Long.parseLong(arr[1]);
Long companyId = Long.parseLong(arr[3]); Long companyId = Long.parseLong(arr[3]);
OriginalRecord report = originalRecordService.getById(businessId); OriginalRecord report = originalRecordService.getById(businessId);
...@@ -263,8 +257,6 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat ...@@ -263,8 +257,6 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
return false; return false;
} }
XSSFSheet sheet = xssfWorkbook.getSheetAt(0);
if (null == report.getTemplateId()) { if (null == report.getTemplateId()) {
return true; return true;
} }
...@@ -274,6 +266,13 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat ...@@ -274,6 +266,13 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
if (null == template) { if (null == template) {
return true; return true;
} }
int sheetSize = xssfWorkbook.getNumberOfSheets();
Integer moreSheet = template.getMoreSheet(); Integer moreSheet = template.getMoreSheet();
List<OriginalTemplateConfig> configList = originalTemplateConfigService.list(Condition.create().eq("template_id", template.getId())); List<OriginalTemplateConfig> configList = originalTemplateConfigService.list(Condition.create().eq("template_id", template.getId()));
...@@ -308,8 +307,8 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat ...@@ -308,8 +307,8 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
for (EntrustSampleItemIndexVO soilItemVO : indexList) { for (EntrustSampleItemIndexVO soilItemVO : indexList) {
stringMap.put(soilItemVO.getSampleCode() + soilItemVO.getEntrustSampleItemId() + soilItemVO.getName(), soilItemVO.getId()); stringMap.put(soilItemVO.getSampleCode() + soilItemVO.getEntrustSampleItemId() + soilItemVO.getName(), soilItemVO.getId());
} }
for (int k = 0; k < sheetSize; k++) {
if (null == moreSheet || 0 == moreSheet) { XSSFSheet sheet = xssfWorkbook.getSheetAt(k);
int sampleBeginRow = template.getSampleBeginRow(); int sampleBeginRow = template.getSampleBeginRow();
int sampleMergerNum = template.getSampleMergerNum(); int sampleMergerNum = template.getSampleMergerNum();
int lastRowNum = sheet.getLastRowNum(); int lastRowNum = sheet.getLastRowNum();
...@@ -533,9 +532,8 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat ...@@ -533,9 +532,8 @@ public class OriginalTemplateServiceImpl extends BaseServiceImpl<OriginalTemplat
if (CollectionUtils.isNotEmpty(updateList)) { if (CollectionUtils.isNotEmpty(updateList)) {
entrustSampleItemIndexService.updateBatchById(updateList); entrustSampleItemIndexService.updateBatchById(updateList);
} }
} }
return true; 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