|
|
@@ -12,6 +12,7 @@ import com.usoftchina.saas.commons.service.ExcelService;
|
|
|
import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.utils.CollectionUtils;
|
|
|
+import com.usoftchina.saas.utils.DateUtils;
|
|
|
import com.usoftchina.saas.utils.StringUtils;
|
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
@@ -138,7 +139,6 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
StringBuilder err = new StringBuilder();
|
|
|
JSONArray mains = new JSONArray();
|
|
|
JSONArray details = new JSONArray();
|
|
|
- boolean flag = false;
|
|
|
//数据行循环
|
|
|
for (int i = 0; i < datas.size(); i++) {
|
|
|
Map<String,String> data = datas.get(i);
|
|
|
@@ -179,25 +179,21 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
if (difference) {
|
|
|
dd.setDd_codevalue(codeValue);
|
|
|
if ("true".equals(set.getNecessary()) && data.get("*" + set.getDescription()).equals("")) {
|
|
|
- err.append("第" + (i + 2) + "行 " + set.getDescription() + " 必填字段未填写! ");
|
|
|
+ err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
//检测日期类型是否规范
|
|
|
if ("date".equals(set.getType()) && !StringUtils.isEmpty(value)) {
|
|
|
- flag = validateDateFormat(value);
|
|
|
- if (!flag) {
|
|
|
- err.append("第" + (i + 2) + "行 " + set.getDescription() + " 日期格式不正确! ");
|
|
|
+ value = praseDate(value);
|
|
|
+ if (null == value) {
|
|
|
+ err.append("第" + (i + 3) + "行 " + set.getDescription() + " 日期格式不正确!<br/> ");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
//插入主表数据
|
|
|
if (null != mainData) {
|
|
|
- if ("true".equals(set.getNecessary())) {
|
|
|
- mainData.put(set.getField(), value);
|
|
|
- } else {
|
|
|
- mainData.put(set.getField(), value);
|
|
|
- }
|
|
|
+ mainData.put(set.getField(), value);
|
|
|
}
|
|
|
}
|
|
|
//所有主表数据进行分类
|
|
|
@@ -216,24 +212,20 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
} else {
|
|
|
value = data.get(set.getDescription());
|
|
|
}
|
|
|
- //拼从表数据
|
|
|
- if ("true".equals(set.getNecessary())) {
|
|
|
- detailData.put(set.getField(), data.get("*" + set.getDescription()));
|
|
|
- } else {
|
|
|
- detailData.put(set.getField(), data.get(set.getDescription()));
|
|
|
- }
|
|
|
- if ("true".equals(set.getNecessary()) && data.get("*" + set.getDescription()).equals("")) {
|
|
|
- err.append("第" + (i + 2) + "行 " + set.getDescription() + " 必填字段未填写! ");
|
|
|
+ if ("true".equals(set.getNecessary()) && value.equals("")) {
|
|
|
+ err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
|
|
|
break;
|
|
|
}
|
|
|
//检测日期类型是否规范
|
|
|
- if ("date".equals(set.getType())) {
|
|
|
- flag = validateDateFormat(value);
|
|
|
- if (!flag) {
|
|
|
- err.append("第" + (i + 2) + "行 " + set.getDescription() + " 日期格式不正确! ");
|
|
|
+ if ("date".equals(set.getType()) && !StringUtils.isEmpty(value)) {
|
|
|
+ value = praseDate(value);
|
|
|
+ if (null == value) {
|
|
|
+ err.append("第" + (i + 3) + "行 " + set.getDescription() + " 日期格式不正确!<br/> ");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ //拼从表数据
|
|
|
+ detailData.put(set.getField(), value);
|
|
|
}
|
|
|
if (detailData.size() > 0) {
|
|
|
dd.setDd_codevalue(codeValue);
|
|
|
@@ -273,6 +265,15 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+ private String praseDate(String num) {
|
|
|
+ try {
|
|
|
+ Integer days = Integer.valueOf(num);
|
|
|
+ return DateUtils.plusDay(days, "1899-12-30");
|
|
|
+ }catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//保证先遍历主表
|
|
|
private List<String> SetToList(Set<String> sets) {
|
|
|
List<String> list = new ArrayList<>();
|
|
|
@@ -294,7 +295,7 @@ public class ExcelServiceImpl implements ExcelService{
|
|
|
cellValue = String.valueOf(cell.getNumericCellValue());
|
|
|
//判断是否为INT类型
|
|
|
if (Double.valueOf(cellValue.toString()).intValue() - Double.valueOf(cellValue.toString()) == 0) {
|
|
|
- return Double.valueOf(cellValue.toString()).intValue();
|
|
|
+ return cellValue.toString().substring(0, cellValue.toString().indexOf("."));
|
|
|
}
|
|
|
break;
|
|
|
}
|