Commit 67a296cf by wangweidong

土工平台修改

parent 0e3e8b3f
......@@ -21,6 +21,8 @@ import java.util.regex.Pattern;
* @author wwd
*/
public class StringHandleUtils {
public static String getContinuousStringData(String[] intString, String stringPre) {
StringBuffer result = new StringBuffer();
......@@ -65,6 +67,14 @@ public class StringHandleUtils {
}
public static boolean is_alpha(String str) {
if(str==null) return false;
String regex = "[\u4e00-\u9fa5]"; //汉字的Unicode取值范围
Pattern pattern = Pattern.compile(regex);
Matcher match = pattern.matcher(str);
return !match.find();
}
public static String getNumFromString(String str) {
String regEx = "[^0-9]";
......@@ -565,9 +575,5 @@ public class StringHandleUtils {
}
public boolean is_alpha(String str) {
if(str==null) return false;
return str.matches("[a-zA-Z]+");
}
}
......@@ -84,6 +84,10 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
@Autowired
private ISoilItemService soilItemService;
@Autowired
private ISoilExpReportTemplateConfigService soilExpReportTemplateConfigService;
......@@ -530,6 +534,24 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
RestAssert.fail("试验项目不存在");
}
List<Long> expIdsList = expVOList.stream().map(e->{
return e.getId();
}).collect(Collectors.toList());
List<SoilItem> soilItemList = soilItemService.list(Condition.create().in("experiment_id",expIdsList));
if (CollectionUtils.isNotEmpty(soilItemList)){
for (SoilExperimentVO experimentVO:expVOList) {
List<SoilItem> itemList = new ArrayList<>();
Long expId = experimentVO.getId();
for (SoilItem soilItem:soilItemList) {
if (expId.equals(soilItem.getExperimentId())){
itemList.add(soilItem);
}
}
experimentVO.setItemList(itemList);
}
}
InputStream io = ossClient.download(template.getObjectKey());
RestAssert.fail(null == io,"模板不存在");
......@@ -562,11 +584,34 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
int rowBegin = sampleBeginRow;
for (SoilExperimentVO vo:expVOList) {
XSSFRow row = xssfSheet.getRow(rowBegin);
List<SoilItem> itemList = vo.getItemList();
for (SoilExpReportTemplateConfig config:configList) {
XSSFCell cell = row.getCell(config.getColumnPlace());
cell.setCellValue(StringHandleUtils.getFieldIfNummReturnBlankValueByFieldName(config.getDataAttribute(),vo));
String prepory = config.getDataAttribute();
if (StringUtils.isNotBlank(prepory)){
if (StringHandleUtils.is_alpha(prepory)){
cell.setCellValue(StringHandleUtils.getFieldIfNummReturnBlankValueByFieldName(prepory,vo));
}else{
if (CollectionUtils.isNotEmpty(itemList)){
for (SoilItem item:itemList) {
if (prepory.equals(item.getName())){
cell.setCellValue(item.getTestValue());
break;
}
}
}
}
}
}
rowBegin+=dataTotalRow;
}
}else{
int insertRowNum = expVOList.size() - templateSampleNum;
......@@ -621,9 +666,28 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
int rowBegin = sampleBeginRow;
for (SoilExperimentVO vo:expVOList) {
XSSFRow row = xssfSheet.getRow(rowBegin);
List<SoilItem> itemList = vo.getItemList();
for (SoilExpReportTemplateConfig config:configList) {
XSSFCell cell = row.getCell(config.getColumnPlace());
cell.setCellValue(StringHandleUtils.getFieldIfNummReturnBlankValueByFieldName(config.getDataAttribute(),vo));
String prepory = config.getDataAttribute();
if (StringUtils.isNotBlank(prepory)){
if (StringHandleUtils.is_alpha(prepory)){
cell.setCellValue(StringHandleUtils.getFieldIfNummReturnBlankValueByFieldName(prepory,vo));
}else{
if (CollectionUtils.isNotEmpty(itemList)){
for (SoilItem item:itemList) {
if (prepory.equals(item.getName())){
cell.setCellValue(item.getTestValue());
break;
}
}
}
}
}
}
rowBegin+=dataTotalRow;
}
......
......@@ -15,6 +15,8 @@ import com.patzn.poibox.xwpf.HSSFWorkbookUtil;
import org.apache.bcel.generic.IF_ACMPEQ;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
......@@ -307,6 +309,8 @@ public class SoilOriginalTemplateServiceImpl extends BaseServiceImpl<SoilOrigina
List<SoilItemCollectData> soilItemList = new ArrayList<>();
DataFormatter formatter = new DataFormatter();
FormulaEvaluator evaluator = xssfWorkbook.getCreationHelper().createFormulaEvaluator();
for (int i = sampleBeginRow;i<lastRowNum;i+=sampleMergerNum) {
XSSFRow xssfRow = sheet.getRow(i);
XSSFCell sampleCodeCell = xssfRow.getCell(sampleCol);
......@@ -314,8 +318,7 @@ public class SoilOriginalTemplateServiceImpl extends BaseServiceImpl<SoilOrigina
for (ItemCollectEntity collectEntity:collectEntitiesList) {
XSSFCell itemCell = xssfRow.getCell(collectEntity.getColumnPlace());
String value = HSSFWorkbookUtil.getJavaValue(itemCell).toString();
String value = formatter.formatCellValue(itemCell, evaluator);
String itemName = collectEntity.getItemName();
if (StringUtils.isBlank(value)){
continue;
......
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