bigdecimal转换为integereasyexcel检查表头是否匹配_easyexcel导⼊获取表头并且表
头为不固定列
@Transactional(rollbackFor = Exception.class)
@Overridepublic List save(List>> list, int ztId, int year, int month, booleanhasErr) {
logger.info("--start---导⼊判断----");
List error = new ArrayList<>();
List newZwmxz = new ArrayList<>();
String pattern= "^[-]?\\d+(\\.\\d+)?$";//遍历传过来的数据集合
for(var item : list) {//每⼀⾏
for(var row : Set()) {//获取⾏的索引
Integer rowIndex =Key();//索引为0表⽰为表头
if (rowIndex == 0) {
String leftYear= Value().get(1);
String rightYear= Value().get(2);
logger.info("---leftYear={}--------rightYear={}----------", leftYear, rightYear);
String left= judgeYear(leftYear, year, "B");if (left != null) {
error.add(left);
}
String right= judgeYear(rightYear, year, "C");if (right != null) {
error.add(right);
}
}else{
rowIndex++;
logger.info("---rowIndex={}--------", rowIndex);
Zwmxz it= newZwmxz();//遍历每⼀⾏的每⼀列数据,并校验
for(var col : Value().entrySet()) {Key()) {case 1:if (Value() == null) {
error.add("序号为【" + rowIndex + "】的数据的B列【⽉份】不可为空!");
}else{if(Pattern.matches(pattern, Value().trim())) {if (Integer.Value().trim()) ==month) {
it.setMonth(month);
}else{
error.add("序号为【" + rowIndex + "】的数据的B列【⽉份】与当前期间的⽉份不⼀致!");
}
}else{
error.add("序号为【" + rowIndex + "】的数据的B列【⽉份】需要是正常的阿拉伯数字⽉份!");
}
}ase 16:if (Value() == null) {
it.setYe(BigDecimal.ZERO);
}else{if(Pattern.matches(pattern, Value().trim())) {
it.setYe(Value()));
}else{
it.setYe(BigDecimal.ZERO);
}
}break;case 17:
it.Value());break;default:break;
}
}
it.setZtId(ztId);
it.setYear(year);
Date date= newDate();
it.setUpdatedAt(date);
it.setCreatedAt(date);
newZwmxz.add(it);
}
}
}//以上数据 若存在⼀条报错的数据,则全部导⼊失败!
if (error.size() > 0 ||hasErr) {
zwmxzRepository.deleteAllByZtIdAndYearAndMonth(ztId, year, month);
}else{for(var it : newZwmxz) {
zwmxzRepository.save(it);
}
}returnerror;
}private String judgeYear(String year1, intyear2, String position) {
String pattern= "^[0-9]+$";if (year1 == null) {return "Excel的" + position + "列的表头年份不可为空!"; }else{
String im();if (trim.length() >= 4) {
String substring= trim.substring(0, 4);
logger.info("-----year1:{}", substring);if(Pattern.matches(pattern, substring)) {if (Integer.parseInt(substring) !=year2) {return "Excel的" + position + "列的表头年份与当前期间年份不⼀致!";
}
}else{return "Excel的" + position + "列的表头年份不规范!";
}
}else{return "Excel的" + position + "列的表头年份不规范!";
}
}return null;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。